Skip to content

Commit

Permalink
scsi: ufs: ufshpb: Verify that 'num_inflight_map_req' is non-negative
Browse files Browse the repository at this point in the history
'num_inflight_map_req' should not be negative.  It is incremented and
decremented without any protection, allowing it theoretically to be
negative, should some weird unbalanced count occur.

Verify that the those calls are properly serialized.

Link: https://lore.kernel.org/r/20210808090024.21721-4-avri.altman@wdc.com
Fixes: 33845a2 (scsi: ufs: ufshpb: Limit the number of in-flight map requests)
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Avri Altman authored and Martin K. Petersen committed Aug 12, 2021
1 parent 07106f8 commit 22aede9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions drivers/scsi/ufs/ufshpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb,
{
struct ufshpb_req *map_req;
struct bio *bio;
unsigned long flags;

if (hpb->is_hcm &&
hpb->num_inflight_map_req >= hpb->params.inflight_map_req) {
Expand All @@ -780,17 +781,25 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb,

map_req->rb.srgn_idx = srgn->srgn_idx;
map_req->rb.mctx = srgn->mctx;

spin_lock_irqsave(&hpb->param_lock, flags);
hpb->num_inflight_map_req++;
spin_unlock_irqrestore(&hpb->param_lock, flags);

return map_req;
}

static void ufshpb_put_map_req(struct ufshpb_lu *hpb,
struct ufshpb_req *map_req)
{
unsigned long flags;

bio_put(map_req->bio);
ufshpb_put_req(hpb, map_req);

spin_lock_irqsave(&hpb->param_lock, flags);
hpb->num_inflight_map_req--;
spin_unlock_irqrestore(&hpb->param_lock, flags);
}

static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb,
Expand Down Expand Up @@ -2387,6 +2396,7 @@ static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb)

spin_lock_init(&hpb->rgn_state_lock);
spin_lock_init(&hpb->rsp_list_lock);
spin_lock_init(&hpb->param_lock);

INIT_LIST_HEAD(&hpb->lru_info.lh_lru_rgn);
INIT_LIST_HEAD(&hpb->lh_act_srgn);
Expand Down
4 changes: 3 additions & 1 deletion drivers/scsi/ufs/ufshpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ struct ufshpb_lu {
struct ufshpb_req *pre_req;
int num_inflight_pre_req;
int throttle_pre_req;
int num_inflight_map_req;
int num_inflight_map_req; /* hold param_lock */
spinlock_t param_lock;

struct list_head lh_pre_req_free;
int cur_read_id;
int pre_req_min_tr_len;
Expand Down

0 comments on commit 22aede9

Please sign in to comment.