Skip to content

Commit 3ecd8cf

Browse files
Linus WalleijUlf Hansson
authored andcommitted
mmc: block: move multi-ioctl() to use block layer
This switches also the multiple-command ioctl() call to issue all ioctl()s through the block layer instead of going directly to the device. We extend the passed argument with an argument count and loop over all passed commands in the ioctl() issue function called from the block layer. By doing this we are again loosening the grip on the big host lock, since two calls to mmc_get_card()/mmc_put_card() are removed. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Tested-by: Avri Altman <Avri.Altman@sandisk.com>
1 parent 614f038 commit 3ecd8cf

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎drivers/mmc/core/block.c‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
563563
struct mmc_ioc_cmd __user *ic_ptr)
564564
{
565565
struct mmc_blk_ioc_data *idata;
566+
struct mmc_blk_ioc_data *idatas[1];
566567
struct mmc_blk_data *md;
567568
struct mmc_queue *mq;
568569
struct mmc_card *card;
@@ -600,7 +601,9 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
600601
req = blk_get_request(mq->queue,
601602
idata->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN,
602603
__GFP_RECLAIM);
603-
req_to_mmc_queue_req(req)->idata = idata;
604+
idatas[0] = idata;
605+
req_to_mmc_queue_req(req)->idata = idatas;
606+
req_to_mmc_queue_req(req)->ioc_count = 1;
604607
blk_execute_rq(mq->queue, NULL, req, 0);
605608
ioc_err = req_to_mmc_queue_req(req)->ioc_result;
606609
err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata);
@@ -622,14 +625,17 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
622625
static void mmc_blk_ioctl_cmd_issue(struct mmc_queue *mq, struct request *req)
623626
{
624627
struct mmc_queue_req *mq_rq;
625-
struct mmc_blk_ioc_data *idata;
626628
struct mmc_card *card = mq->card;
627629
struct mmc_blk_data *md = mq->blkdata;
628630
int ioc_err;
631+
int i;
629632

630633
mq_rq = req_to_mmc_queue_req(req);
631-
idata = mq_rq->idata;
632-
ioc_err = __mmc_blk_ioctl_cmd(card, md, idata);
634+
for (i = 0; i < mq_rq->ioc_count; i++) {
635+
ioc_err = __mmc_blk_ioctl_cmd(card, md, mq_rq->idata[i]);
636+
if (ioc_err)
637+
break;
638+
}
633639
mq_rq->ioc_result = ioc_err;
634640

635641
/* Always switch back to main area after RPMB access */
@@ -646,8 +652,10 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
646652
struct mmc_ioc_cmd __user *cmds = user->cmds;
647653
struct mmc_card *card;
648654
struct mmc_blk_data *md;
655+
struct mmc_queue *mq;
649656
int i, err = 0, ioc_err = 0;
650657
__u64 num_of_cmds;
658+
struct request *req;
651659

652660
/*
653661
* The caller must have CAP_SYS_RAWIO, and must be calling this on the
@@ -689,21 +697,25 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
689697
goto cmd_done;
690698
}
691699

692-
mmc_get_card(card);
693-
694-
for (i = 0; i < num_of_cmds && !ioc_err; i++)
695-
ioc_err = __mmc_blk_ioctl_cmd(card, md, idata[i]);
696-
697-
/* Always switch back to main area after RPMB access */
698-
if (md->area_type & MMC_BLK_DATA_AREA_RPMB)
699-
mmc_blk_part_switch(card, dev_get_drvdata(&card->dev));
700700

701-
mmc_put_card(card);
701+
/*
702+
* Dispatch the ioctl()s into the block request queue.
703+
*/
704+
mq = &md->queue;
705+
req = blk_get_request(mq->queue,
706+
idata[0]->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN,
707+
__GFP_RECLAIM);
708+
req_to_mmc_queue_req(req)->idata = idata;
709+
req_to_mmc_queue_req(req)->ioc_count = num_of_cmds;
710+
blk_execute_rq(mq->queue, NULL, req, 0);
711+
ioc_err = req_to_mmc_queue_req(req)->ioc_result;
702712

703713
/* copy to user if data and response */
704714
for (i = 0; i < num_of_cmds && !err; i++)
705715
err = mmc_blk_ioctl_copy_to_user(&cmds[i], idata[i]);
706716

717+
blk_put_request(req);
718+
707719
cmd_done:
708720
mmc_blk_put(md);
709721
cmd_err:

‎drivers/mmc/core/queue.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct mmc_queue_req {
4242
unsigned int bounce_sg_len;
4343
struct mmc_async_req areq;
4444
int ioc_result;
45-
struct mmc_blk_ioc_data *idata;
45+
struct mmc_blk_ioc_data **idata;
46+
unsigned int ioc_count;
4647
};
4748

4849
struct mmc_queue {

0 commit comments

Comments
 (0)