From patchwork Thu Jun 15 12:12:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105643 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp772124qgd; Thu, 15 Jun 2017 05:13:11 -0700 (PDT) X-Received: by 10.84.231.141 with SMTP id g13mr5851878plk.157.1497528791476; Thu, 15 Jun 2017 05:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497528791; cv=none; d=google.com; s=arc-20160816; b=GVbGDkVlnbTSegYgQb6GUiXCrLh4HUchaoAN+J1VlNEFbPNugs15sa/zISN5FaPe6O zUw4LxS0zYK2I5HDji/euxsgYIJMRcVpOv5pwT9+uKc9NiKKn1nbebGmIK4xhpPP4JZw zAy+TtwKu3PRYKRhlW5TEibQfaa/eWK0kNMLretGdn05Rr46mKs2UnP8q21hHEkguYlP O7M/AZiLTz8kCaXJmqM4BzpAIXqf4KjoDzDClHHoPcAS3dDrvxu/g5cc6MJK8o1k7M1F 0mV0+uBv9IXpyquCBvjw9IaqmbzpkV0EHL3pDxF8WJUeHeWbO/aAtGJUnkZJIRALDMbq ELTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=CGdZOq8LiLgOTOYeFls05XHSAOKXY5tNJK6yC7wa0Xc=; b=iEXsluSrObq+241BC84cHI9J7RwWfi+PNkTGqxOHG/ZY/1gGygnXN57vkb8VwXtV2d uUDq/UkMLUSDgi0lWccrFetVQMjTSCAj+Y6BxYQhJXJf/kT3e79ZWhGMWzcz5GD++FPC gCQ2+W7H66+XEFUsil+JNuX0yb5okVnPn3FUi+khZ4pJkyiJ9lcTYYX0KaIIWb3Snc0Z P2Uqp9iR1e3rnlLqirMy/N6GITq/LfM1QAqR3ZCDg/RkVcAJ6qHj5kkeDzZoKwWXe6ua s0SENd+K03CBjWZ0iW1/kP8ugT9j7cKRQHRNKstd1fEI2GI1+dZlH/4/Dq5AIEvA7u/Y rn3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=coBxgzNt; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92si2162397plb.230.2017.06.15.05.13.11; Thu, 15 Jun 2017 05:13:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=coBxgzNt; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752449AbdFOMNK (ORCPT + 6 others); Thu, 15 Jun 2017 08:13:10 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:34035 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752393AbdFOMNJ (ORCPT ); Thu, 15 Jun 2017 08:13:09 -0400 Received: by mail-lf0-f44.google.com with SMTP id v20so7981796lfa.1 for ; Thu, 15 Jun 2017 05:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FhFz325leF5yGr9DvrBoDl0BnYNQtAqp219xvuB/5cM=; b=coBxgzNtzQSYG9lp5lRBzJ12EY80xsP9X05kN9BebMz/z83T9E1vlJMmAGkwNga60+ xn/ic59QRsWnbImZ+0Q64XNi49K00t2IfMb2A/B8CtvVDhjhPQneOhoMq4snQR8BGR4B mH6l9AhsfJA98Nxrd51mg4f6mQShCIhuo/yZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FhFz325leF5yGr9DvrBoDl0BnYNQtAqp219xvuB/5cM=; b=l3ZXrKxbA/H42caB+t2+BpetqIxuJwi1G70S6nlAX58944PQ5q2VN9hsPdv7ddtjOP GsiwSkQ4UR8qfBxWcJ20Y/0qRmEd3nmAzkXGSm+1ifqgeToSJ4xgN3k+Al8JSv8bfwpS j4OHZNGJhXlPxKioNIXUFZ1FKst/FWHqRU2Z3hPljT4xHMmjtDQVDmzKkL72TCHDqqRZ YYDKZ/dFyQhMi/JjQoxd+RKTlcnPNAinPoTouUeCAXJxSYl9I+eS6Wk7IODuke3UwlR3 nbPo8oFHp1omBnlel6Sg1iGNmb15QnQ5/tz48Nmy/y3dLGFCGQWgsYVPa6s+83ki/GKv BZsg== X-Gm-Message-State: AKS2vOxOewmOk15j+gCAC8zBqU2bRvYngPlpqM0S36E2oTh/jCaF5Y9N CaTtSwBqhKKT/hzGw8gqxg== X-Received: by 10.25.115.134 with SMTP id h6mr1872063lfk.163.1497528787202; Thu, 15 Jun 2017 05:13:07 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v1sm597574lja.18.2017.06.15.05.13.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 05:13:05 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Adrian Hunter , Linus Walleij , Shawn Lin Subject: [PATCH 1/5] mmc: block: Move duplicate check Date: Thu, 15 Jun 2017 14:12:55 +0200 Message-Id: <20170615121259.8281-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615121259.8281-1-linus.walleij@linaro.org> References: <20170615121259.8281-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org mmc_blk_ioctl() calls either mmc_blk_ioctl_cmd() or mmc_blk_ioctl_multi_cmd() and each of these make the same check. Factor it into a new helper function, call it on both branches of the switch() statement and save a chunk of duplicate code. Cc: Shawn Lin Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - We need to check the block device only if an actual well-known ioctl() is coming in, on the path of the switch() statments, only those branches that handle actual ioctl()s. Create a new helper function to check the block device and call that. --- drivers/mmc/core/block.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Shawn Lin diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 1ce6012ce3c1..d1b824e65590 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -566,14 +566,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, int err = 0, ioc_err = 0; struct request *req; - /* - * The caller must have CAP_SYS_RAWIO, and must be calling this on the - * whole block device, not on a partition. This prevents overspray - * between sibling partitions. - */ - if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) - return -EPERM; - idata = mmc_blk_ioctl_copy_from_user(ic_ptr); if (IS_ERR(idata)) return PTR_ERR(idata); @@ -626,14 +618,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, __u64 num_of_cmds; struct request *req; - /* - * The caller must have CAP_SYS_RAWIO, and must be calling this on the - * whole block device, not on a partition. This prevents overspray - * between sibling partitions. - */ - if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) - return -EPERM; - if (copy_from_user(&num_of_cmds, &user->num_of_cmds, sizeof(num_of_cmds))) return -EFAULT; @@ -697,14 +681,34 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, return ioc_err ? ioc_err : err; } +static int mmc_blk_check_blkdev(struct block_device *bdev) +{ + /* + * The caller must have CAP_SYS_RAWIO, and must be calling this on the + * whole block device, not on a partition. This prevents overspray + * between sibling partitions. + */ + if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) + return -EPERM; + return 0; +} + static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { + int ret; + switch (cmd) { case MMC_IOC_CMD: + ret = mmc_blk_check_blkdev(bdev); + if (ret) + return ret; return mmc_blk_ioctl_cmd(bdev, (struct mmc_ioc_cmd __user *)arg); case MMC_IOC_MULTI_CMD: + ret = mmc_blk_check_blkdev(bdev); + if (ret) + return ret; return mmc_blk_ioctl_multi_cmd(bdev, (struct mmc_ioc_multi_cmd __user *)arg); default: From patchwork Thu Jun 15 12:12:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105644 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp772154qgd; Thu, 15 Jun 2017 05:13:14 -0700 (PDT) X-Received: by 10.84.137.3 with SMTP id 3mr5832824plm.68.1497528794541; Thu, 15 Jun 2017 05:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497528794; cv=none; d=google.com; s=arc-20160816; b=LqDFC4i3/y8ZSOxWE7bL61FPORB7wPiEBSD5ofcyC3SD0KJf3r6SrcJJ4OFpcZzGSj 94IbdfTP2NN92A7Xc8KCMsw6rkmnZtz1A9ezLGmGNPWDjTT6jgjBkQCkIvHjGZCGyH1Z xb66BV0pD8TzVxYmyE7mU1xmLkv9ysbEV3h5zH90eIKLA5Jn82yJ4K6eNwJi7AeWZDLG V7amx/1Afb9lLuox+/GRDkQkAqzDS+W2y2jpZrniCC5waz1+P/vmtQqa1Xcyu4q0xhlI l1XacCjnupHVWqfqA3SCUez96P2q38i2EyNN6xl5xLQAqP18khGhpP0lzf/cNXd9Ul0Z N/HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=dpbEj9tpANba7R+nROqHNaS4s6BiDzMfTvvMDd4JIh0=; b=Lm4ypjDc4vMnm6qEUUY1nT9MVWY0cizsqMxawAgP02JTA0Eg+4ykWllUzZd7nErK/2 7Co6SBZZp/ZpwrfJm5Z4Ti7albJyEL0WYn+NkahjL/3K9/2SyW3gjirniW5WUckSQkOs 2Khi2NxduPyE00qQj39ye91h9GUMLBT21iTyTkqNXCfAkKRgERs6CKb35nBzUvODh5M0 pUjFBz+ZsdkuS9F6p0dnHwzN/TZWTSxzoksUbFIZ/10XSRyC9wGsjXNFYsvSGiWR/CCB i3DdDgwhxAyqL4jjVjakfFd4BAoShfYO4AuVNvVxnqZlo2uvsfwPPN7XamcIxQGBLCFD ZsRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=EjMg9Je7; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92si2162397plb.230.2017.06.15.05.13.14; Thu, 15 Jun 2017 05:13:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=EjMg9Je7; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752507AbdFOMNN (ORCPT + 6 others); Thu, 15 Jun 2017 08:13:13 -0400 Received: from mail-lf0-f42.google.com ([209.85.215.42]:36701 "EHLO mail-lf0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752409AbdFOMNM (ORCPT ); Thu, 15 Jun 2017 08:13:12 -0400 Received: by mail-lf0-f42.google.com with SMTP id o83so7922801lff.3 for ; Thu, 15 Jun 2017 05:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T72D9tBaOA7k78XghoqV4YAVi8fZHCU66BpnG+YE40k=; b=EjMg9Je7Wl0q1eLCKt1GlDIlApUdeYLp9kBxL5wVEGa/NzyllXueySC3JLaieUo7Wc kgjEWmASA2hEG4KEsEe7W4IwyWhERkJEFmHdh3X/6rK/F2MPm3ZQM9ow32Unr1zRgn47 IsmRbn7iYnHAU5WREe6INON5U3jCa/v8E4VwA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T72D9tBaOA7k78XghoqV4YAVi8fZHCU66BpnG+YE40k=; b=NRHSH94TvqpKIsP/w7O22hzUOPDr8KHK0efUwBjqTouqcDMOdB9G+oVs0sacxnzxVn DFDnMjPaW1iARi4YXOBpimWAa/VJEUFZVsiuzYvyIA1mw/bEqe7co+EmnSHLsFyk20lJ 2uId63HX+Eg/GV/p7whByMved/1mJQx6UbltHJDqRMS2U3jyVWxlNXq+YGJR1HpnUfgL 7fewCtUps96xc2CpbgjULhGHG55FBuf3EsiLcdISqFIDc1VcjMfqjPgXueUAgYnFWz3l XhCbGAqld4tT6gTwqVaP4zJiXPCohivffDNHxELDyyiIGeIBybXZSusJdn52dkox2gTU RaaQ== X-Gm-Message-State: AKS2vOyaHGVeYxF7LguN18NVsJZFnExry0fWVGL/B0AKwjs2KSkecWx9 Ou70MTiDTPKcQ9cPcIvreQ== X-Received: by 10.46.33.164 with SMTP id h36mr1408922lji.86.1497528790836; Thu, 15 Jun 2017 05:13:10 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v1sm597574lja.18.2017.06.15.05.13.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 05:13:08 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Adrian Hunter , Linus Walleij Subject: [PATCH 2/5] mmc: block: Refactor mmc_blk_part_switch() Date: Thu, 15 Jun 2017 14:12:56 +0200 Message-Id: <20170615121259.8281-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615121259.8281-1-linus.walleij@linaro.org> References: <20170615121259.8281-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Instead of passing a struct mmc_blk_data * to mmc_blk_part_switch() let's pass the actual partition type we want to switch to. This is necessary in order not to have a block device with a backing mmc_blk_data and request queue and all for every hardware partition, such as RPMB. Signed-off-by: Linus Walleij --- drivers/mmc/core/block.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index d1b824e65590..94b97f97be1a 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -127,7 +127,7 @@ module_param(perdev_minors, int, 0444); MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device"); static inline int mmc_blk_part_switch(struct mmc_card *card, - struct mmc_blk_data *md); + unsigned int part_type); static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) { @@ -490,7 +490,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, mrq.cmd = &cmd; - err = mmc_blk_part_switch(card, md); + err = mmc_blk_part_switch(card, md->part_type); if (err) return err; @@ -767,29 +767,29 @@ static int mmc_blk_part_switch_post(struct mmc_card *card, } static inline int mmc_blk_part_switch(struct mmc_card *card, - struct mmc_blk_data *md) + unsigned int part_type) { int ret = 0; struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev); - if (main_md->part_curr == md->part_type) + if (main_md->part_curr == part_type) return 0; if (mmc_card_mmc(card)) { u8 part_config = card->ext_csd.part_config; - ret = mmc_blk_part_switch_pre(card, md->part_type); + ret = mmc_blk_part_switch_pre(card, part_type); if (ret) return ret; part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; - part_config |= md->part_type; + part_config |= part_type; ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, part_config, card->ext_csd.part_time); if (ret) { - mmc_blk_part_switch_post(card, md->part_type); + mmc_blk_part_switch_post(card, part_type); return ret; } @@ -798,7 +798,7 @@ static inline int mmc_blk_part_switch(struct mmc_card *card, ret = mmc_blk_part_switch_post(card, main_md->part_curr); } - main_md->part_curr = md->part_type; + main_md->part_curr = part_type; return ret; } @@ -1141,7 +1141,7 @@ static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host, int part_err; main_md->part_curr = main_md->part_type; - part_err = mmc_blk_part_switch(host->card, md); + part_err = mmc_blk_part_switch(host->card, md->part_type); if (part_err) { /* * We have failed to get back into the correct @@ -1180,6 +1180,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req) struct mmc_queue_req *mq_rq; struct mmc_card *card = mq->card; struct mmc_blk_data *md = mq->blkdata; + struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev); struct mmc_blk_ioc_data **idata; u8 **ext_csd; u32 status; @@ -1198,7 +1199,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req) } /* Always switch back to main area after RPMB access */ if (md->area_type & MMC_BLK_DATA_AREA_RPMB) - mmc_blk_part_switch(card, dev_get_drvdata(&card->dev)); + mmc_blk_part_switch(card, main_md->part_type); break; case MMC_DRV_OP_BOOT_WP: ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, @@ -1906,7 +1907,7 @@ void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) /* claim host only for the first request */ mmc_get_card(card); - ret = mmc_blk_part_switch(card, md); + ret = mmc_blk_part_switch(card, md->part_type); if (ret) { if (req) { blk_end_request_all(req, -EIO); @@ -2436,7 +2437,7 @@ static void mmc_blk_remove(struct mmc_card *card) mmc_blk_remove_parts(card, md); pm_runtime_get_sync(&card->dev); mmc_claim_host(card->host); - mmc_blk_part_switch(card, md); + mmc_blk_part_switch(card, md->part_type); mmc_release_host(card->host); if (card->type != MMC_TYPE_SD_COMBO) pm_runtime_disable(&card->dev); From patchwork Thu Jun 15 12:12:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105645 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp772170qgd; Thu, 15 Jun 2017 05:13:17 -0700 (PDT) X-Received: by 10.99.64.199 with SMTP id n190mr5080723pga.281.1497528797422; Thu, 15 Jun 2017 05:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497528797; cv=none; d=google.com; s=arc-20160816; b=nnWwcdTvKSRwkn7BiVTYKtDYAm2AdypMWb/oTRRc5RzoF6SNi2Dd8G2Pn1llTY22RM D9X66PTOaq63yZkeSmnD8IvuBSbGmRMziL+9MEFy5F0GRs6wqSHHUGneCZBZRv8SHDD5 Ctfs7qGkzY/cSkO3bMMHiniEorjzHM6PC3Y+9U1vhQSbLSD4AijYqu3CpiNSleK4ycb7 3IbqiUXfDtoLQ94azpV1365WgqZcVCFx0GPZfslm5OIsHLW9LwSdL5wn53p5npqMf/at MoGtB9brH0YJsIzpw10SODQMgyi2Iw/V9DqqN78g6u5w8ULANzBavIqC78KKauLGfx8h Noxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=N4u3lCNoqSUfdQTU/FCtXImwoZQ60VMNDEWrIrno8+E=; b=AmAMdzi3EF4E4tYCinfY71aPt1iDS0sBzIVW2MMn7YcSZn4iYKANY0to9ElfvVIpmQ bCD9OAp3otjeXZNzFpYB/N/V/ok+WhTfHugK3MsO+pygUap2PbfjLxgfhrZR0h+vzQPU qIdY9vUWe/sy4L3RfR/Yz62IND4SjQBcnkArPWYqu9MoLsKpxV4r5RVqvyYexb/0R+Na 73WBo0boKLwXbB8FFKdYAZaRBeaE8TTtcS3RhZxHY2jlubIWRLGoB2yuKFgbuzAp8nVw kkn3h1jRchgZPCkbGcxkBqWXMQ7U62W0AaGjDIZUXw7FwKvfQ+xO4NWGRqB/v0/NSlVX IfXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=R+PoxeMy; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92si2162397plb.230.2017.06.15.05.13.17; Thu, 15 Jun 2017 05:13:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=R+PoxeMy; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752393AbdFOMNQ (ORCPT + 6 others); Thu, 15 Jun 2017 08:13:16 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:34937 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752409AbdFOMNP (ORCPT ); Thu, 15 Jun 2017 08:13:15 -0400 Received: by mail-lf0-f45.google.com with SMTP id p189so7957265lfe.2 for ; Thu, 15 Jun 2017 05:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IX/yk2insXLJGd9W+DztI3NvuJFrctf+aXL99tzEFRM=; b=R+PoxeMyohpDpMkQpYhCQR1CtdqwTHAYcOAsc8UsrvS8lT0r7bUvdFWL3tOZfZO9xC KB4djdjXoXlFSK1c7IA2ZhFDsmdvzSQ+YPqqAuFtAYVgaw7sIOP1NNQaa1A+ahPAlN9B HjZtbDgm7RMxVEY074uazPEwq+ZzPGe2cUqYA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IX/yk2insXLJGd9W+DztI3NvuJFrctf+aXL99tzEFRM=; b=RpjJBAzhT9hlR24h3i2PiTPRTCTOfdZbhmP+HjIS37F6km4ZDdPHxxUv6KpcnF0Gy8 HNnQoc40rgCV64OtUqxmyjrzovSXP1h8H1Sx8Jj+Q88FHObCPJRpkqFAlXNFEDQ5/ndr 8MFgmS+U323VNkQ4AYh2k9/6qGSKshCvqxeNRp+uylWcBJMtiL4OFRcBxQdl/sba3Tvt 5FD7vMsbSuFoQxjPFaa3ZMKhCFzOLnFnjkwgQzNMoBNoyTpREXbe0wDLriJjm3IE3y7B DJMGySp1UiGh4xngoxM5xoUoZkligfnVzMVbXmB7qduLDmdyjEko97wRDeHgWMQUFsrI gWBA== X-Gm-Message-State: AKS2vOwlsNaqNsdiHzmO67WL2jU5d4iqVvbNC89Xart50SYL4vg1lDe7 ID7FJW5LWm8oc9GvwOXFmA== X-Received: by 10.25.99.201 with SMTP id v70mr1454759lfi.63.1497528793496; Thu, 15 Jun 2017 05:13:13 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v1sm597574lja.18.2017.06.15.05.13.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 05:13:12 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Adrian Hunter , Linus Walleij Subject: [PATCH 3/5] mmc: block: Reparametrize mmc_blk_ioctl_[multi]_cmd() Date: Thu, 15 Jun 2017 14:12:57 +0200 Message-Id: <20170615121259.8281-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615121259.8281-1-linus.walleij@linaro.org> References: <20170615121259.8281-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Instead of passing a block device to mmc_blk_ioctl[_multi]_cmd(), let's pass struct mmc_blk_data() so we operate ioctl()s on the MMC block device representation rather than the vanilla block device. This saves a little duplicated code and makes it possible to issue ioctl()s not targeted for a specific block device but rather for a specific partition/area. Signed-off-by: Linus Walleij --- drivers/mmc/core/block.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 94b97f97be1a..b8c71fdb6ed4 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -555,12 +555,11 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, return err; } -static int mmc_blk_ioctl_cmd(struct block_device *bdev, +static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, struct mmc_ioc_cmd __user *ic_ptr) { struct mmc_blk_ioc_data *idata; struct mmc_blk_ioc_data *idatas[1]; - struct mmc_blk_data *md; struct mmc_queue *mq; struct mmc_card *card; int err = 0, ioc_err = 0; @@ -570,12 +569,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, if (IS_ERR(idata)) return PTR_ERR(idata); - md = mmc_blk_get(bdev->bd_disk); - if (!md) { - err = -EINVAL; - goto cmd_err; - } - card = md->queue.card; if (IS_ERR(card)) { err = PTR_ERR(card); @@ -599,20 +592,17 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, blk_put_request(req); cmd_done: - mmc_blk_put(md); -cmd_err: kfree(idata->buf); kfree(idata); return ioc_err ? ioc_err : err; } -static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, +static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md, struct mmc_ioc_multi_cmd __user *user) { struct mmc_blk_ioc_data **idata = NULL; struct mmc_ioc_cmd __user *cmds = user->cmds; struct mmc_card *card; - struct mmc_blk_data *md; struct mmc_queue *mq; int i, err = 0, ioc_err = 0; __u64 num_of_cmds; @@ -638,16 +628,10 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, } } - md = mmc_blk_get(bdev->bd_disk); - if (!md) { - err = -EINVAL; - goto cmd_err; - } - card = md->queue.card; if (IS_ERR(card)) { err = PTR_ERR(card); - goto cmd_done; + goto cmd_err; } @@ -670,8 +654,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, blk_put_request(req); -cmd_done: - mmc_blk_put(md); cmd_err: for (i = 0; i < num_of_cmds; i++) { kfree(idata[i]->buf); @@ -696,6 +678,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev) static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { + struct mmc_blk_data *md; int ret; switch (cmd) { @@ -703,14 +686,24 @@ static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, ret = mmc_blk_check_blkdev(bdev); if (ret) return ret; - return mmc_blk_ioctl_cmd(bdev, - (struct mmc_ioc_cmd __user *)arg); + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return -EINVAL; + ret = mmc_blk_ioctl_cmd(md, + (struct mmc_ioc_cmd __user *)arg); + mmc_blk_put(md); + return ret; case MMC_IOC_MULTI_CMD: ret = mmc_blk_check_blkdev(bdev); if (ret) return ret; - return mmc_blk_ioctl_multi_cmd(bdev, - (struct mmc_ioc_multi_cmd __user *)arg); + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return -EINVAL; + ret = mmc_blk_ioctl_multi_cmd(md, + (struct mmc_ioc_multi_cmd __user *)arg); + mmc_blk_put(md); + return ret; default: return -EINVAL; } From patchwork Thu Jun 15 12:12:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105646 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp772210qgd; Thu, 15 Jun 2017 05:13:21 -0700 (PDT) X-Received: by 10.98.198.2 with SMTP id m2mr4906101pfg.215.1497528801370; Thu, 15 Jun 2017 05:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497528801; cv=none; d=google.com; s=arc-20160816; b=sKMVw+tms2UFfpV7qKpS5KbRuS3xFtANf0+RRf80uB6WwIjm472sO273cx8+q/ocJy EVA8yW7DN7pX9EvyT7eLKbhwpSMsmlEeFlmAPxsBH7NZ2gbFReyjO7P0dUuyYf63VgxQ 1WgkzMpqkb6QGoXXXWryqKpYZK85TrIVpVEwevlHp2x3NOVWTwhXEfFHM22YLg2nj62j MVgxmcDYlr2GsiHngFRgk498hoIGNYk8HvORVvW4gb1Sckr+SzCVCnBx0Ag1zSAvSfZp KmXWF9NF7W9levESnUYqwlmkitJnpFWumSUVJKJVH7mZR/mpTA6AXlaAQO8132AnlFqE WT+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=KgzhzbZvHQkmKAambEdQzZSvP9FIqDh8UjmDsfMawj8=; b=wUmwyweMrhvgOZIvUeY5fEB1+pn/vrwZHN9FLd8Xju+Afr99G3zEulCdEyYS6qe4v1 rtiSXxEc+j+v56pw5XAno7hTZsWkvRI8oIyxS9AUqz2YX2kS3k/foJQw7YRJ3355BN5u N6valwISZErnbR+P9SkWxIzRJ2BZVVJwXcSCqjmGFgb8zdy0zB4g1ACRz9qPKcSmzHVw LMk2+RKUh+06kPDMRrVxGDbHRimHa9F/rrMX1S4tXY+bN+161geW0sfqp5kfx9vhplNv 5ugh6B2AJZw9qiE82nD3FMqTvsD4VijtxSHVXf2DFtvMjuxQDKzpoMvcgGQngLnjZlDu 3bhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=GopvptXA; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92si2162397plb.230.2017.06.15.05.13.21; Thu, 15 Jun 2017 05:13:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=GopvptXA; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752481AbdFOMNU (ORCPT + 6 others); Thu, 15 Jun 2017 08:13:20 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:34963 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752498AbdFOMNT (ORCPT ); Thu, 15 Jun 2017 08:13:19 -0400 Received: by mail-lf0-f43.google.com with SMTP id p189so7958353lfe.2 for ; Thu, 15 Jun 2017 05:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q4rK0C9K2xkqJk/VSTHMpOXN/q6betCnuEaE+s0hkt4=; b=GopvptXAY59HSeyl0i1Dmphq3PKxaLhcrU0jPFe8qXAh4jabrJoFwOlwViJQb/9hsM WQbSYszgqvR5qTcz4pvtD1sMtYXXL9r92BA/cHjOlTZf3Rtdzf3aMImbmiJJVOWWOz/L h7psIlbHEX8XIT1qHVhgcYJFOak7SOn1J7gzE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q4rK0C9K2xkqJk/VSTHMpOXN/q6betCnuEaE+s0hkt4=; b=dlDCliQDFzCKlm1MvjFjISPy5laxncKUcVmmgVSKkpT/Dx+KLkbvAR6oahM1mdkyjb ouk4bz2ZUJ3V2hiVugo6VUaLkW3oIL0glJjdqv1YbDt464IcxARILpV4Ft/CxWD45HaF RTMpWFfF96f1IygtUSFCJAMv1WnqdICfG9bjeVmjDrsDqDlSNxhAHiPjJTxtw2oXAY4s oVqFD/4Iyon489YDOvWeIYbeGZ1iqW7SrrLLXrEb8VIOaJZrlqD11Km9y6q5w+qqOYH+ 4y1YFRMzia7+qNB0EK9Nm9adiZvuhzXA3pejlug/1GS5gEiZiSs9ObBa+pcTagk3CUyz hT6Q== X-Gm-Message-State: AKS2vOx8nHjlO/Zl6RBwWor66BSUh0SlT+mujG3mgTPQUQnlFHIRE5zS uZwShHPG7+lOdoU0rzdAOA== X-Received: by 10.25.215.74 with SMTP id o71mr1805757lfg.105.1497528796665; Thu, 15 Jun 2017 05:13:16 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v1sm597574lja.18.2017.06.15.05.13.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 05:13:15 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Adrian Hunter , Linus Walleij Subject: [PATCH 4/5] RFC: mmc: block: Convert RPMB to a character device Date: Thu, 15 Jun 2017 14:12:58 +0200 Message-Id: <20170615121259.8281-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615121259.8281-1-linus.walleij@linaro.org> References: <20170615121259.8281-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The RPMB partition on the eMMC devices is a special area used for storing cryptographically safe information signed by a special secret key. To write and read records from this special area, authentication is needed. The RPMB area is *only* and *exclusively* accessed using ioctl():s from userspace. It is not really a block device, as blocks cannot be read or written from the device, also the signed chunks that can be stored on the RPMB are actually 256 bytes, not 512 making a block device a real bad fit. Currently the RPMB partition spawns a separate block device named /dev/mmcblkNrpmb for each device with an RPMB partition, including the creation of a block queue with its own kernel thread and all overhead associated with this. On the Ux500 HREFv60 platform, for example, the two eMMCs means that two block queues with separate threads are created for no use whatsoever. I have concluded that this block device design for RPMB is actually pretty wrong. The RPMB area should have been designed to be accessed from /dev/mmcblkN directly, using ioctl()s on the main block device. It is however way too late to change that, since userspace expects to open an RPMB device in /dev/mmcblkNrpmb and we cannot break userspace. This patch tries to amend the situation using the following strategy: - Stop creating a block device for the RPMB partition/area - Instead create a custom, dynamic character device with the same name. - Make this new character device support exactly the same set of ioctl()s as the old block device. - Wrap the requests back to the same ioctl() handlers, but issue them on the block queue of the main partition/area, i.e. /dev/mmcblkN We need to create a special "rpmb" bus type in order to get udev and/or busybox hot/coldplug to instantiate the device node properly. Before the patch, this appears in 'ps aux': 101 root 0:00 [mmcqd/2rpmb] 123 root 0:00 [mmcqd/3rpmb] After applying the patch these surplus block queue threads are gone, but RPMB is as usable as ever using the userspace MMC tools, such as 'mmc rpmb read-counter'. We get instead those dynamice devices in /dev: brw-rw---- 1 root root 179, 0 Jan 1 2000 mmcblk0 brw-rw---- 1 root root 179, 1 Jan 1 2000 mmcblk0p1 brw-rw---- 1 root root 179, 2 Jan 1 2000 mmcblk0p2 brw-rw---- 1 root root 179, 5 Jan 1 2000 mmcblk0p5 brw-rw---- 1 root root 179, 8 Jan 1 2000 mmcblk2 brw-rw---- 1 root root 179, 16 Jan 1 2000 mmcblk2boot0 brw-rw---- 1 root root 179, 24 Jan 1 2000 mmcblk2boot1 crw-rw---- 1 root root 248, 0 Jan 1 2000 mmcblk2rpmb brw-rw---- 1 root root 179, 32 Jan 1 2000 mmcblk3 brw-rw---- 1 root root 179, 40 Jan 1 2000 mmcblk3boot0 brw-rw---- 1 root root 179, 48 Jan 1 2000 mmcblk3boot1 brw-rw---- 1 root root 179, 33 Jan 1 2000 mmcblk3p1 crw-rw---- 1 root root 248, 1 Jan 1 2000 mmcblk3rpmb Notice the (248,0) and (248,1) character devices for RPMB. Tomas Winkler Signed-off-by: Linus Walleij --- Some discussion points: I am aware of Tomas Winklers attempts to make RPMB handling into its own subsystem. I have no such ambitions whatsoever, I am only trying to sensibly accomodate what we already have and handle our RPMB in a way that is not littering the place with weirdo block devices. The patch is a lot of "that should have been done differently from the outset" and "it is not a perfect solution", I'd appreciate if you take a look at the kernel before and after this patch and think of it as a path forward, are things better or worse like this, thinking toward the future. I guess it would be nicer if I could (from the KERNEL) create a symlink from mmcblk2rpmb -> mmcblk2 or a second mknod creating mmcblk2rpmb with the same major/minor numbers as the main device. I guess that can be done with udev scripts, but that breaks all setups with old udev scripts, busybox, Android etc. So creating a proper device seems necessary to satisfy userspace. I haven't been able to do much testing as my RPMB-capable device seems to be failing to do anything sensible, but I atleast get the same error codes from "mmc rpmb read-counter /deb/mmcblkNrpmb" before/after the patch. --- drivers/mmc/core/block.c | 278 +++++++++++++++++++++++++++++++++++++++++++---- drivers/mmc/core/queue.h | 2 + 2 files changed, 256 insertions(+), 24 deletions(-) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index b8c71fdb6ed4..0a226bc23429 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -86,6 +87,7 @@ static int max_devices; #define MAX_DEVICES 256 static DEFINE_IDA(mmc_blk_ida); +static DEFINE_IDA(mmc_rpmb_ida); /* * There is one mmc_blk_data per slot. @@ -96,6 +98,7 @@ struct mmc_blk_data { struct gendisk *disk; struct mmc_queue queue; struct list_head part; + struct list_head rpmbs; unsigned int flags; #define MMC_BLK_CMD23 (1 << 0) /* Can do SET_BLOCK_COUNT for multiblock */ @@ -121,6 +124,30 @@ struct mmc_blk_data { int area_type; }; +/* Device type for RPMB character devices */ +static dev_t rpmb_devt; + +/* Bus type for RPMB character devices */ +static struct bus_type rpmb_bus_type = { + .name = "rpmb", +}; + +/** + * struct mmc_rpmb_data - special RPMB device type for these areas + * @dev: the device for the RPMB area + * @chrdev: character device for the RPMB area + * @id: unique device ID number + * @md: parent MMC block device + * @node: list item, so we can put this device on a list + */ +struct mmc_rpmb_data { + struct device dev; + struct cdev chrdev; + int id; + struct mmc_blk_data *md; + struct list_head node; +}; + static DEFINE_MUTEX(open_lock); module_param(perdev_minors, int, 0444); @@ -432,21 +459,29 @@ static int ioctl_do_sanitize(struct mmc_card *card) } static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, - struct mmc_blk_ioc_data *idata) + struct mmc_blk_ioc_data *idata, bool rpmb_ioctl) { struct mmc_command cmd = {}; struct mmc_data data = {}; struct mmc_request mrq = {}; struct scatterlist sg; int err; - bool is_rpmb = false; + unsigned int target_part; u32 status = 0; if (!card || !md || !idata) return -EINVAL; - if (md->area_type & MMC_BLK_DATA_AREA_RPMB) - is_rpmb = true; + /* + * The RPMB accesses comes in from the character device, so we + * need to target these explicitly. Else we just target the + * partition type for the block device the ioctl() was issued + * on. + */ + if (rpmb_ioctl) + target_part = EXT_CSD_PART_CONFIG_ACC_RPMB; + else + target_part = md->part_type; cmd.opcode = idata->ic.opcode; cmd.arg = idata->ic.arg; @@ -490,7 +525,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, mrq.cmd = &cmd; - err = mmc_blk_part_switch(card, md->part_type); + err = mmc_blk_part_switch(card, target_part); if (err) return err; @@ -500,7 +535,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, return err; } - if (is_rpmb) { + if (rpmb_ioctl) { err = mmc_set_blockcount(card, data.blocks, idata->ic.write_flag & (1 << 31)); if (err) @@ -540,7 +575,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, memcpy(&(idata->ic.response), cmd.resp, sizeof(cmd.resp)); - if (is_rpmb) { + if (rpmb_ioctl) { /* * Ensure RPMB command has completed by polling CMD13 * "Send Status". @@ -556,7 +591,8 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, } static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, - struct mmc_ioc_cmd __user *ic_ptr) + struct mmc_ioc_cmd __user *ic_ptr, + bool rpmb_ioctl) { struct mmc_blk_ioc_data *idata; struct mmc_blk_ioc_data *idatas[1]; @@ -583,7 +619,10 @@ static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, idata->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, __GFP_RECLAIM); idatas[0] = idata; - req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_IOCTL; + if (rpmb_ioctl) + req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_IOCTL_RPMB; + else + req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_IOCTL; req_to_mmc_queue_req(req)->drv_op_data = idatas; req_to_mmc_queue_req(req)->ioc_count = 1; blk_execute_rq(mq->queue, NULL, req, 0); @@ -598,7 +637,8 @@ static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, } static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md, - struct mmc_ioc_multi_cmd __user *user) + struct mmc_ioc_multi_cmd __user *user, + bool rpmb_ioctl) { struct mmc_blk_ioc_data **idata = NULL; struct mmc_ioc_cmd __user *cmds = user->cmds; @@ -642,7 +682,10 @@ static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md, req = blk_get_request(mq->queue, idata[0]->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, __GFP_RECLAIM); - req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_IOCTL; + if (rpmb_ioctl) + req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_IOCTL_RPMB; + else + req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_IOCTL; req_to_mmc_queue_req(req)->drv_op_data = idata; req_to_mmc_queue_req(req)->ioc_count = num_of_cmds; blk_execute_rq(mq->queue, NULL, req, 0); @@ -690,7 +733,8 @@ static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, if (!md) return -EINVAL; ret = mmc_blk_ioctl_cmd(md, - (struct mmc_ioc_cmd __user *)arg); + (struct mmc_ioc_cmd __user *)arg, + false); mmc_blk_put(md); return ret; case MMC_IOC_MULTI_CMD: @@ -701,7 +745,8 @@ static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode, if (!md) return -EINVAL; ret = mmc_blk_ioctl_multi_cmd(md, - (struct mmc_ioc_multi_cmd __user *)arg); + (struct mmc_ioc_multi_cmd __user *)arg, + false); mmc_blk_put(md); return ret; default: @@ -1173,26 +1218,29 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req) struct mmc_queue_req *mq_rq; struct mmc_card *card = mq->card; struct mmc_blk_data *md = mq->blkdata; - struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev); struct mmc_blk_ioc_data **idata; + bool rpmb_ioctl; u8 **ext_csd; u32 status; int ret; int i; mq_rq = req_to_mmc_queue_req(req); + rpmb_ioctl = (mq_rq->drv_op == MMC_DRV_OP_IOCTL_RPMB); switch (mq_rq->drv_op) { case MMC_DRV_OP_IOCTL: + case MMC_DRV_OP_IOCTL_RPMB: idata = mq_rq->drv_op_data; for (i = 0; i < mq_rq->ioc_count; i++) { - ret = __mmc_blk_ioctl_cmd(card, md, idata[i]); + ret = __mmc_blk_ioctl_cmd(card, md, idata[i], + rpmb_ioctl); if (ret) break; } /* Always switch back to main area after RPMB access */ - if (md->area_type & MMC_BLK_DATA_AREA_RPMB) - mmc_blk_part_switch(card, main_md->part_type); + if (rpmb_ioctl) + mmc_blk_part_switch(card, 0); break; case MMC_DRV_OP_BOOT_WP: ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, @@ -2006,6 +2054,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, spin_lock_init(&md->lock); INIT_LIST_HEAD(&md->part); + INIT_LIST_HEAD(&md->rpmbs); md->usage = 1; ret = mmc_init_queue(&md->queue, card, &md->lock, subname); @@ -2124,6 +2173,151 @@ static int mmc_blk_alloc_part(struct mmc_card *card, return 0; } +/** + * rpmb_ioctl() - ioctl handler for the RPMB chardev + * @filp: the character device file + * @cmd: the ioctl() command + * @arg: the argument from userspace + * + * This will essentially just redirect the ioctl()s coming in over to + * the main block device spawning the RPMB character device. + */ +static long rpmb_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct mmc_rpmb_data *rpmb = filp->private_data; + int ret; + + switch (cmd) { + case MMC_IOC_CMD: + ret = mmc_blk_ioctl_cmd(rpmb->md, + (struct mmc_ioc_cmd __user *)arg, + true); + break; + case MMC_IOC_MULTI_CMD: + ret = mmc_blk_ioctl_multi_cmd(rpmb->md, + (struct mmc_ioc_multi_cmd __user *)arg, + true); + break; + default: + ret = -EINVAL; + break; + } + + return 0; +} + +#ifdef CONFIG_COMPAT +static long rpmb_ioctl_compat(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + return rpmb_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)); +} +#endif + +static int rpmb_chrdev_open(struct inode *inode, struct file *filp) +{ + struct mmc_rpmb_data *rpmb = container_of(inode->i_cdev, + struct mmc_rpmb_data, chrdev); + + get_device(&rpmb->dev); + filp->private_data = rpmb; + mutex_lock(&open_lock); + rpmb->md->usage++; + mutex_unlock(&open_lock); + + return nonseekable_open(inode, filp); +} + +static int rpmb_chrdev_release(struct inode *inode, struct file *filp) +{ + struct mmc_rpmb_data *rpmb = container_of(inode->i_cdev, + struct mmc_rpmb_data, chrdev); + + put_device(&rpmb->dev); + mutex_lock(&open_lock); + rpmb->md->usage--; + mutex_unlock(&open_lock); + + return 0; +} + +static const struct file_operations rpmb_fileops = { + .release = rpmb_chrdev_release, + .open = rpmb_chrdev_open, + .owner = THIS_MODULE, + .llseek = no_llseek, + .unlocked_ioctl = rpmb_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = rpmb_ioctl_compat, +#endif +}; + + +static int mmc_blk_alloc_rpmb_part(struct mmc_card *card, + struct mmc_blk_data *md, + sector_t size, + const char *subname) +{ + int devidx, ret; + char rpmb_name[DISK_NAME_LEN]; + char cap_str[10]; + struct mmc_rpmb_data *rpmb; + + /* This creates the minor number for the RPMB char device */ + devidx = ida_simple_get(&mmc_rpmb_ida, 0, max_devices, GFP_KERNEL); + if (devidx < 0) + return devidx; + + rpmb = kzalloc(sizeof(*rpmb), GFP_KERNEL); + if (!rpmb) + return -ENOMEM; + + snprintf(rpmb_name, sizeof(rpmb_name), + "mmcblk%u%s", card->host->index, subname ? subname : ""); + + rpmb->id = devidx; + rpmb->dev.init_name = rpmb_name; + rpmb->dev.bus = &rpmb_bus_type; + rpmb->dev.devt = MKDEV(MAJOR(rpmb_devt), rpmb->id); + rpmb->dev.parent = &card->dev; + device_initialize(&rpmb->dev); + dev_set_drvdata(&rpmb->dev, rpmb); + rpmb->md = md; + + cdev_init(&rpmb->chrdev, &rpmb_fileops); + rpmb->chrdev.owner = THIS_MODULE; + ret = cdev_device_add(&rpmb->chrdev, &rpmb->dev); + if (ret) { + pr_err("%s: could not add character device\n", rpmb_name); + goto out_remove_ida; + } + + list_add(&rpmb->node, &md->rpmbs); + + string_get_size((u64)size, 512, STRING_UNITS_2, + cap_str, sizeof(cap_str)); + + pr_info("%s: %s %s partition %u %s, chardev (%d:%d)\n", + rpmb_name, mmc_card_id(card), + mmc_card_name(card), EXT_CSD_PART_CONFIG_ACC_RPMB, cap_str, + MAJOR(rpmb_devt), rpmb->id); + + return 0; + +out_remove_ida: + ida_simple_remove(&mmc_rpmb_ida, rpmb->id); + kfree(rpmb); + return ret; +} + +static void mmc_blk_remove_rpmb_part(struct mmc_rpmb_data *rpmb) +{ + cdev_device_del(&rpmb->chrdev, &rpmb->dev); + device_del(&rpmb->dev); + ida_simple_remove(&mmc_rpmb_ida, rpmb->id); + kfree(rpmb); +} + /* MMC Physical partitions consist of two boot partitions and * up to four general purpose partitions. * For each partition enabled in EXT_CSD a block device will be allocatedi @@ -2132,13 +2326,25 @@ static int mmc_blk_alloc_part(struct mmc_card *card, static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md) { - int idx, ret = 0; + int idx, ret; if (!mmc_card_mmc(card)) return 0; for (idx = 0; idx < card->nr_parts; idx++) { - if (card->part[idx].size) { + if (card->part[idx].area_type & MMC_BLK_DATA_AREA_RPMB) { + /* + * RPMB partitions does not provide block access, they + * are only accessed using ioctl():s. Thus create + * special RPMB block devices that do not have a + * backing block queue for these. + */ + ret = mmc_blk_alloc_rpmb_part(card, md, + card->part[idx].size >> 9, + card->part[idx].name); + if (ret) + return ret; + } else if (card->part[idx].size) { ret = mmc_blk_alloc_part(card, md, card->part[idx].part_cfg, card->part[idx].size >> 9, @@ -2150,7 +2356,7 @@ static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md) } } - return ret; + return 0; } static void mmc_blk_remove_req(struct mmc_blk_data *md) @@ -2183,7 +2389,15 @@ static void mmc_blk_remove_parts(struct mmc_card *card, { struct list_head *pos, *q; struct mmc_blk_data *part_md; + struct mmc_rpmb_data *rpmb; + /* Remove RPMB partitions */ + list_for_each_safe(pos, q, &md->rpmbs) { + rpmb = list_entry(pos, struct mmc_rpmb_data, node); + list_del(pos); + mmc_blk_remove_rpmb_part(rpmb); + } + /* Remove block partitions */ list_for_each_safe(pos, q, &md->part) { part_md = list_entry(pos, struct mmc_blk_data, part); list_del(pos); @@ -2502,6 +2716,17 @@ static int __init mmc_blk_init(void) { int res; + res = bus_register(&rpmb_bus_type); + if (res < 0) { + pr_err("mmcblk: could not register RPMB bus type\n"); + return res; + } + res = alloc_chrdev_region(&rpmb_devt, 0, MAX_DEVICES, "rpmb"); + if (res < 0) { + pr_err("mmcblk: failed to allocate rpmb chrdev region\n"); + goto out_bus_unreg; + } + if (perdev_minors != CONFIG_MMC_BLOCK_MINORS) pr_info("mmcblk: using %d minors per device\n", perdev_minors); @@ -2509,16 +2734,20 @@ static int __init mmc_blk_init(void) res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); if (res) - goto out; + goto out_chrdev_unreg; res = mmc_register_driver(&mmc_driver); if (res) - goto out2; + goto out_blkdev_unreg; return 0; - out2: + +out_blkdev_unreg: unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); - out: +out_chrdev_unreg: + unregister_chrdev_region(rpmb_devt, MAX_DEVICES); +out_bus_unreg: + bus_unregister(&rpmb_bus_type); return res; } @@ -2526,6 +2755,7 @@ static void __exit mmc_blk_exit(void) { mmc_unregister_driver(&mmc_driver); unregister_blkdev(MMC_BLOCK_MAJOR, "mmc"); + unregister_chrdev_region(rpmb_devt, MAX_DEVICES); } module_init(mmc_blk_init); diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index 04fc89360a7a..a2b6a9fcab01 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -35,12 +35,14 @@ struct mmc_blk_request { /** * enum mmc_drv_op - enumerates the operations in the mmc_queue_req * @MMC_DRV_OP_IOCTL: ioctl operation + * @MMC_DRV_OP_IOCTL_RPMB: RPMB-oriented ioctl operation * @MMC_DRV_OP_BOOT_WP: write protect boot partitions * @MMC_DRV_OP_GET_CARD_STATUS: get card status * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card */ enum mmc_drv_op { MMC_DRV_OP_IOCTL, + MMC_DRV_OP_IOCTL_RPMB, MMC_DRV_OP_BOOT_WP, MMC_DRV_OP_GET_CARD_STATUS, MMC_DRV_OP_GET_EXT_CSD, From patchwork Thu Jun 15 12:12:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 105647 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp772356qgd; Thu, 15 Jun 2017 05:13:40 -0700 (PDT) X-Received: by 10.84.253.2 with SMTP id z2mr6076882pll.114.1497528820664; Thu, 15 Jun 2017 05:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497528820; cv=none; d=google.com; s=arc-20160816; b=hXRARBv+0RwDVwAfsC6Ns3N4Mb1JrXKbmqQA7qf/dtSlrb5ncMIJY4zgm6Y9RIjsWe j+IxhEkuib5/+I2ASgzSp8YDfivHRZJn+Tn8QC1Acpox5NrlqPrVaIlRXr6iYMzqdPFI 8x+3ttRkGAxcwVDk0Fgp71tuhE/nVPjxW+mLDMgj90+A1ieQdz7EJEn0jmx0NhbKNjmx 9nHwcXsvGfskfv56YG2FvBaRy5a2VIlplOmR8ssfvpW8mePkcnQcbRNaXsBF6LoOnp7K vTHclK6zy28H7lfznn3nfFguAnxK0YPci+QC7Gxuw25E8A+8+XpbPaF/sHF4ycj80IU6 Y5QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=NTsvMRtWRvZoHkGOId6sd2POOmLSjRKqqHgeYaai2cU=; b=S+AOzA+LRclCJOMRUIax9IzGzavlH+BMyo8E0wubRv/7zJZ/c+ulHR/hu7ZGPpMPoU oAoLSD/IcB/EZ1OOy0pmDT1ddcor0X8kZu+Qd9miDJt6ZydShyMN9pR+My3whh6fRFjR vnRrdLW/ZBv89SgaqsZW5pQFOWdPwb+6LZ2pE6+y4O4uOHh8ZMFgNcP6CZ7qNey5BeST +X7kP9R/HUiw5pm3gjvKRLQlKRGUbhKZkrU/myI1+nijbbjMYgBJm+pi4C8/4fFOwLyS 8VEwz6pnxAb7xXocUQZRrsJ1c4k15+IBkm9NZlcdwWOv3z4vLHBta9cAUyce54hfjZsD 8trQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=GLOJxd79; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si2148803pfb.416.2017.06.15.05.13.40; Thu, 15 Jun 2017 05:13:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=GLOJxd79; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752387AbdFOMN1 (ORCPT + 6 others); Thu, 15 Jun 2017 08:13:27 -0400 Received: from mail-lf0-f52.google.com ([209.85.215.52]:34120 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752498AbdFOMNV (ORCPT ); Thu, 15 Jun 2017 08:13:21 -0400 Received: by mail-lf0-f52.google.com with SMTP id v20so7985617lfa.1 for ; Thu, 15 Jun 2017 05:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6q6I3xJhWga1oMui928GQbok6fmtkANH/+gYZOt5sd0=; b=GLOJxd79OXTtCbJaE/X4kZYFuA7it+XVSHSF4G4Y45LaLU9bYjF/fRjUkTzuc2UtNy 456n4OZORlhNkTrBlqpY6DPa24s9RsKOEfv2pUvOUreWGiTBztyYj/Ur+IvDL/0cGfVT +E8Naq7hLoDrhgpAIYnUPPDGMhqUI39sfQCJQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6q6I3xJhWga1oMui928GQbok6fmtkANH/+gYZOt5sd0=; b=c90BjuwS7IDGFKH+eksArcQlD5jlEBhs+BA21ZnNnXE6DTp8Aq6jhHpNeJP/694Yzr zCKj7FTpsiKihbkz7+DJZyLD5WR8r0zfCI4dlXSVrB+vzCHL3psQwIT/ylTedx+1z3G8 D5d8Y2LvBhr0ARcTUPe9dWYBR6U2DIw31+PWrk6F6rTpOkoE9HTzqJw2p9irI2JBEqq+ 4/W3idzsVS+Q6iy2rwknDMcWpq34dPtVUX/WFBsdQ+U842LHfhGkI1mYZihH4pyAaarV Y4VHFB6vE4QIRPqLLVAZYcb5DswnVxxfPjhCJmASmvDmLDJES6n7xQe3xp28czI4KLh4 eNuw== X-Gm-Message-State: AKS2vOyXQOm6w12Fempn95mHgJKwZrlVwQiAAD4MsFKhwK2oasbrXW0g nY3clBmRdPTM6cNGhkMwLQ== X-Received: by 10.25.205.80 with SMTP id d77mr1740085lfg.131.1497528799201; Thu, 15 Jun 2017 05:13:19 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v1sm597574lja.18.2017.06.15.05.13.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 05:13:18 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Adrian Hunter , Linus Walleij Subject: [PATCH 5/5] mmc: block: Delete mmc_access_rpmb() Date: Thu, 15 Jun 2017 14:12:59 +0200 Message-Id: <20170615121259.8281-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615121259.8281-1-linus.walleij@linaro.org> References: <20170615121259.8281-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This function is used by the block layer queue to bail out of requests if the current request is an RPMB request. However this makes no sense: RPMB is only used from ioctl():s, there are no RPMB accesses coming from the block layer. An RPMB ioctl() always switches to the RPMB partition and then back to the main partition before completing. The only (possible) use of this check must have been to duct-tape over a race between RPMB ioctl()s colliding with concurrent non-RPMB accesses to the same device. This could happen in the past because the RPMB device was created as a separate block device/disk with its own submit queue competing with the main partition, and submitting requests in parallel. This is now gone as we removed the offending RPMB block device in another patch. Signed-off-by: Linus Walleij --- This patch is not an RFC since it is a logical consequence of the RFC patch, not really much to discuss about it. --- drivers/mmc/core/block.c | 12 ------------ drivers/mmc/core/queue.c | 2 +- drivers/mmc/core/queue.h | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 0a226bc23429..8bb97ac3be08 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1196,18 +1196,6 @@ static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type) md->reset_done &= ~type; } -int mmc_access_rpmb(struct mmc_queue *mq) -{ - struct mmc_blk_data *md = mq->blkdata; - /* - * If this is a RPMB partition access, return ture - */ - if (md && md->part_type == EXT_CSD_PART_CONFIG_ACC_RPMB) - return true; - - return false; -} - /* * The non-block commands come back from the block layer after it queued it and * processed it with all other requests and then they get issued in this diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index ba689a2ffc51..9d3de2859c33 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -32,7 +32,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req) { struct mmc_queue *mq = q->queuedata; - if (mq && (mmc_card_removed(mq->card) || mmc_access_rpmb(mq))) + if (mq && mmc_card_removed(mq->card)) return BLKPREP_KILL; req->rq_flags |= RQF_DONTPREP; diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index a2b6a9fcab01..7649ed6cbef7 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -89,6 +89,4 @@ extern unsigned int mmc_queue_map_sg(struct mmc_queue *, extern void mmc_queue_bounce_pre(struct mmc_queue_req *); extern void mmc_queue_bounce_post(struct mmc_queue_req *); -extern int mmc_access_rpmb(struct mmc_queue *); - #endif