Skip to content

Commit f5d72c5

Browse files
Christoph Hellwigaxboe
authored andcommitted
mmc: stop abusing the request queue_lock pointer
Replace the lock in mmc_blk_data that is only used through a pointer in struct mmc_queue and to protect fields in that structure with an actual lock in struct mmc_queue. Suggested-by: Ulf Hansson <ulf.hansson@linaro.org> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f048427 commit f5d72c5

3 files changed

Lines changed: 28 additions & 31 deletions

File tree

‎drivers/mmc/core/block.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static DEFINE_IDA(mmc_rpmb_ida);
100100
* There is one mmc_blk_data per slot.
101101
*/
102102
struct mmc_blk_data {
103-
spinlock_t lock;
104103
struct device *parent;
105104
struct gendisk *disk;
106105
struct mmc_queue queue;
@@ -1483,15 +1482,15 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
14831482
blk_mq_end_request(req, BLK_STS_OK);
14841483
}
14851484

1486-
spin_lock_irqsave(mq->lock, flags);
1485+
spin_lock_irqsave(&mq->lock, flags);
14871486

14881487
mq->in_flight[mmc_issue_type(mq, req)] -= 1;
14891488

14901489
put_card = (mmc_tot_in_flight(mq) == 0);
14911490

14921491
mmc_cqe_check_busy(mq);
14931492

1494-
spin_unlock_irqrestore(mq->lock, flags);
1493+
spin_unlock_irqrestore(&mq->lock, flags);
14951494

14961495
if (!mq->cqe_busy)
14971496
blk_mq_run_hw_queues(q, true);
@@ -1991,13 +1990,13 @@ static void mmc_blk_mq_dec_in_flight(struct mmc_queue *mq, struct request *req)
19911990
unsigned long flags;
19921991
bool put_card;
19931992

1994-
spin_lock_irqsave(mq->lock, flags);
1993+
spin_lock_irqsave(&mq->lock, flags);
19951994

19961995
mq->in_flight[mmc_issue_type(mq, req)] -= 1;
19971996

19981997
put_card = (mmc_tot_in_flight(mq) == 0);
19991998

2000-
spin_unlock_irqrestore(mq->lock, flags);
1999+
spin_unlock_irqrestore(&mq->lock, flags);
20012000

20022001
if (put_card)
20032002
mmc_put_card(mq->card, &mq->ctx);
@@ -2093,11 +2092,11 @@ static void mmc_blk_mq_req_done(struct mmc_request *mrq)
20932092
* request does not need to wait (although it does need to
20942093
* complete complete_req first).
20952094
*/
2096-
spin_lock_irqsave(mq->lock, flags);
2095+
spin_lock_irqsave(&mq->lock, flags);
20972096
mq->complete_req = req;
20982097
mq->rw_wait = false;
20992098
waiting = mq->waiting;
2100-
spin_unlock_irqrestore(mq->lock, flags);
2099+
spin_unlock_irqrestore(&mq->lock, flags);
21012100

21022101
/*
21032102
* If 'waiting' then the waiting task will complete this
@@ -2116,10 +2115,10 @@ static void mmc_blk_mq_req_done(struct mmc_request *mrq)
21162115
/* Take the recovery path for errors or urgent background operations */
21172116
if (mmc_blk_rq_error(&mqrq->brq) ||
21182117
mmc_blk_urgent_bkops_needed(mq, mqrq)) {
2119-
spin_lock_irqsave(mq->lock, flags);
2118+
spin_lock_irqsave(&mq->lock, flags);
21202119
mq->recovery_needed = true;
21212120
mq->recovery_req = req;
2122-
spin_unlock_irqrestore(mq->lock, flags);
2121+
spin_unlock_irqrestore(&mq->lock, flags);
21232122
wake_up(&mq->wait);
21242123
schedule_work(&mq->recovery_work);
21252124
return;
@@ -2142,15 +2141,15 @@ static bool mmc_blk_rw_wait_cond(struct mmc_queue *mq, int *err)
21422141
* Wait while there is another request in progress, but not if recovery
21432142
* is needed. Also indicate whether there is a request waiting to start.
21442143
*/
2145-
spin_lock_irqsave(mq->lock, flags);
2144+
spin_lock_irqsave(&mq->lock, flags);
21462145
if (mq->recovery_needed) {
21472146
*err = -EBUSY;
21482147
done = true;
21492148
} else {
21502149
done = !mq->rw_wait;
21512150
}
21522151
mq->waiting = !done;
2153-
spin_unlock_irqrestore(mq->lock, flags);
2152+
spin_unlock_irqrestore(&mq->lock, flags);
21542153

21552154
return done;
21562155
}
@@ -2327,12 +2326,11 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
23272326
goto err_kfree;
23282327
}
23292328

2330-
spin_lock_init(&md->lock);
23312329
INIT_LIST_HEAD(&md->part);
23322330
INIT_LIST_HEAD(&md->rpmbs);
23332331
md->usage = 1;
23342332

2335-
ret = mmc_init_queue(&md->queue, card, &md->lock);
2333+
ret = mmc_init_queue(&md->queue, card);
23362334
if (ret)
23372335
goto err_putdisk;
23382336

‎drivers/mmc/core/queue.c‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ void mmc_cqe_recovery_notifier(struct mmc_request *mrq)
8989
struct mmc_queue *mq = q->queuedata;
9090
unsigned long flags;
9191

92-
spin_lock_irqsave(mq->lock, flags);
92+
spin_lock_irqsave(&mq->lock, flags);
9393
__mmc_cqe_recovery_notifier(mq);
94-
spin_unlock_irqrestore(mq->lock, flags);
94+
spin_unlock_irqrestore(&mq->lock, flags);
9595
}
9696

9797
static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req)
@@ -128,14 +128,14 @@ static enum blk_eh_timer_return mmc_mq_timed_out(struct request *req,
128128
unsigned long flags;
129129
int ret;
130130

131-
spin_lock_irqsave(mq->lock, flags);
131+
spin_lock_irqsave(&mq->lock, flags);
132132

133133
if (mq->recovery_needed || !mq->use_cqe)
134134
ret = BLK_EH_RESET_TIMER;
135135
else
136136
ret = mmc_cqe_timed_out(req);
137137

138-
spin_unlock_irqrestore(mq->lock, flags);
138+
spin_unlock_irqrestore(&mq->lock, flags);
139139

140140
return ret;
141141
}
@@ -157,9 +157,9 @@ static void mmc_mq_recovery_handler(struct work_struct *work)
157157

158158
mq->in_recovery = false;
159159

160-
spin_lock_irq(mq->lock);
160+
spin_lock_irq(&mq->lock);
161161
mq->recovery_needed = false;
162-
spin_unlock_irq(mq->lock);
162+
spin_unlock_irq(&mq->lock);
163163

164164
mmc_put_card(mq->card, &mq->ctx);
165165

@@ -258,18 +258,18 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
258258

259259
issue_type = mmc_issue_type(mq, req);
260260

261-
spin_lock_irq(mq->lock);
261+
spin_lock_irq(&mq->lock);
262262

263263
if (mq->recovery_needed || mq->busy) {
264-
spin_unlock_irq(mq->lock);
264+
spin_unlock_irq(&mq->lock);
265265
return BLK_STS_RESOURCE;
266266
}
267267

268268
switch (issue_type) {
269269
case MMC_ISSUE_DCMD:
270270
if (mmc_cqe_dcmd_busy(mq)) {
271271
mq->cqe_busy |= MMC_CQE_DCMD_BUSY;
272-
spin_unlock_irq(mq->lock);
272+
spin_unlock_irq(&mq->lock);
273273
return BLK_STS_RESOURCE;
274274
}
275275
break;
@@ -294,7 +294,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
294294
get_card = (mmc_tot_in_flight(mq) == 1);
295295
cqe_retune_ok = (mmc_cqe_qcnt(mq) == 1);
296296

297-
spin_unlock_irq(mq->lock);
297+
spin_unlock_irq(&mq->lock);
298298

299299
if (!(req->rq_flags & RQF_DONTPREP)) {
300300
req_to_mmc_queue_req(req)->retries = 0;
@@ -328,12 +328,12 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
328328
if (issued != MMC_REQ_STARTED) {
329329
bool put_card = false;
330330

331-
spin_lock_irq(mq->lock);
331+
spin_lock_irq(&mq->lock);
332332
mq->in_flight[issue_type] -= 1;
333333
if (mmc_tot_in_flight(mq) == 0)
334334
put_card = true;
335335
mq->busy = false;
336-
spin_unlock_irq(mq->lock);
336+
spin_unlock_irq(&mq->lock);
337337
if (put_card)
338338
mmc_put_card(card, &mq->ctx);
339339
} else {
@@ -385,19 +385,18 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
385385
* mmc_init_queue - initialise a queue structure.
386386
* @mq: mmc queue
387387
* @card: mmc card to attach this queue
388-
* @lock: queue lock
389388
*
390389
* Initialise a MMC card request queue.
391390
*/
392-
int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
393-
spinlock_t *lock)
391+
int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card)
394392
{
395393
struct mmc_host *host = card->host;
396394
int ret;
397395

398396
mq->card = card;
399-
mq->lock = lock;
400397
mq->use_cqe = host->cqe_enabled;
398+
399+
spin_lock_init(&mq->lock);
401400

402401
memset(&mq->tag_set, 0, sizeof(mq->tag_set));
403402
mq->tag_set.ops = &mmc_mq_ops;

‎drivers/mmc/core/queue.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ struct mmc_queue_req {
7373

7474
struct mmc_queue {
7575
struct mmc_card *card;
76-
spinlock_t *lock;
7776
struct mmc_ctx ctx;
7877
struct blk_mq_tag_set tag_set;
7978
struct mmc_blk_data *blkdata;
8079
struct request_queue *queue;
80+
spinlock_t lock;
8181
int in_flight[MMC_ISSUE_MAX];
8282
unsigned int cqe_busy;
8383
#define MMC_CQE_DCMD_BUSY BIT(0)
@@ -96,7 +96,7 @@ struct mmc_queue {
9696
struct work_struct complete_work;
9797
};
9898

99-
extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *);
99+
extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *);
100100
extern void mmc_cleanup_queue(struct mmc_queue *);
101101
extern void mmc_queue_suspend(struct mmc_queue *);
102102
extern void mmc_queue_resume(struct mmc_queue *);

0 commit comments

Comments
 (0)