From patchwork Thu May 18 09:29:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100066 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp628895qge; Thu, 18 May 2017 02:29:49 -0700 (PDT) X-Received: by 10.99.120.206 with SMTP id t197mr3523161pgc.64.1495099789582; Thu, 18 May 2017 02:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495099789; cv=none; d=google.com; s=arc-20160816; b=IxT6KmyyL85ilTeXAQWgaKNuvpv9I8AMPRRTx/Nh0mPwNvTuYoeRu2lbdvI753/lBf C+skOGSC8nTedohzUepWIh2zbKMFysJmLV9PzbmxP42yWI+FsZQw4IEq3Oyd8P+AXYHw Cp6uBC3inPC8Auq8TgsrNwwiXScazSRlSRsrrcsi0TwVYjy8DegcvhDZ8MepSWP3o57u co1pOaNBjzjXa1OnueSiudL7iF2h2nKotUk2tVo/p82fzN8/4xRBNSjmrruFQh1bBwQy +qLWARvVlswBnT8tYU822lNHcYJ4U5PRUOyPZ9QMWCNqUEHdCnhj1k2gy79l88VIFnJV vVIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=CrD/WjXmTjmCkyvtHbQoGNXPeH8tqXkrWeXOMUyBC2I=; b=GWw9TA2nd7t3CbkyNPVcYqxy8jvtlUBvUwT8u2HW/IQQptfRpj6VJLgfjVt5yrKeNp LgIWj+/sLQ2Sstwk30LfVo2nz32zkT5y/wgk1DdcubEz178XyI02MGCBs6fTv9e7mNxp zc3F8whS80N2uX87xZ54HmvOG9O4yqtJcrjClqKSNr4nAgQIrk1mrFKmNtjenmbM9t6y 7WJZcvJj8FescV+m2J+ESR0tLaF4XKxfqcRwv5miRBHiGRy4oX6TkoDz0CiuVNH6zoD3 cPoQ0UGpGxAPgIbkZYb47nGqF3VsgfCltX3+MMTvUtHj6km1U7s3obcCmK0yefJWe3JJ p8mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 t18si4758743pgn.128.2017.05.18.02.29.49; Thu, 18 May 2017 02:29:49 -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; 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 S1754799AbdERJ3s (ORCPT + 6 others); Thu, 18 May 2017 05:29:48 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:38807 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754011AbdERJ3q (ORCPT ); Thu, 18 May 2017 05:29:46 -0400 Received: by mail-wm0-f43.google.com with SMTP id v15so45462632wmv.1 for ; Thu, 18 May 2017 02:29:45 -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; bh=Z1YDB1LTmRVSdocNF0Z21zMd4o4Y/HtRr8xUmlXo70Q=; b=O5f7YNBnnktCANKdfQsSBBpslhBlHp56HHC1bKJYyj6g6lGmIoJv8kP9VlGCEPGrMk aZg3CbdlAGs0AahqtTfC7u0AhBBRefAgl28tETGeNVhhxlkpqEH8m3+M3VY7hRpdPb8S NHK0LOqyj3o+WbVx9qzmyB6VqWap0sg1o6Kac= 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; bh=Z1YDB1LTmRVSdocNF0Z21zMd4o4Y/HtRr8xUmlXo70Q=; b=fuIT3YWYvsC3B8AvCJTFCWNYOg7h7Phs0+lV+fCb03ugLpDXwBnCpDSA2+0eGpkb+E xF7qAWlZBt5rp6RPjvtQEB/jiJnDebJ0NthSO0b18lgSHMGw/vacQpPdW/7Di92Tbxsb 5u5PNryKE+XQFfVcgdTgYo/OUsMQtcCVozxQ4TCFgVMjknpiN3CThGMgLhksxQ8Poq+t D9yzeoH7fULasdKvqkKdhRpAU9dFmqh4Omw8bnlfYT1jZBmFprc4nzG0OzNvAq1m65wJ jh3gWyNhuBM2FkZXT9Izjv7XlTkQy+cldcxVNLipYDeiH8L0s12P9oRtQAChedpiiILe Kphw== X-Gm-Message-State: AODbwcBM64tIf7hFMyy1Wm26w9EAgAtW4DOBYBYOCBOgPb9SEk7ijRdK HE4ckyKuQ7CjjwLn X-Received: by 10.25.196.204 with SMTP id u195mr738542lff.9.1495099784809; Thu, 18 May 2017 02:29:44 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u24sm829895ljd.34.2017.05.18.02.29.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 02:29:43 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Linus Walleij Subject: [PATCH 1/6 v2] mmc: core: Delete bounce buffer Kconfig option Date: Thu, 18 May 2017 11:29:31 +0200 Message-Id: <20170518092936.9277-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This option is activated by all multiplatform configs and what not so we almost always have it turned on, and the memory it saves is negligible, even more so moving forward. The actual bounce buffer only gets allocated only when used, the only thing the ifdefs are saving is a little bit of code. It is highly improper to have this as a Kconfig option that get turned on by Kconfig, make this a pure runtime-thing and let the host decide whether we use bounce buffers. We add a new property "disable_bounce" to the host struct. Notice that mmc_queue_calc_bouncesz() already disables the bounce buffers if host->max_segs != 1, so any arch that has a maximum number of segments higher than 1 will have bounce buffers disabled. The option CONFIG_MMC_BLOCK_BOUNCE is default y so the majority of platforms in the kernel already have it on, and it then gets turned off at runtime since most of these have a host->max_segs > 1. The few exceptions that have host->max_segs == 1 and still turn off the bounce buffering are those that disable it in their defconfig. Those are the following: arch/arm/configs/colibri_pxa300_defconfig arch/arm/configs/zeus_defconfig - Uses MMC_PXA, drivers/mmc/host/pxamci.c - Sets host->max_segs = NR_SG, which is 1 - This needs its bounce buffer deactivated so we set host->disable_bounce to true in the host driver arch/arm/configs/davinci_all_defconfig - Uses MMC_DAVINCI, drivers/mmc/host/davinci_mmc.c - This driver sets host->max_segs to MAX_NR_SG, which is 16 - That means this driver anyways disabled bounce buffers - No special action needed for this platform arch/arm/configs/lpc32xx_defconfig arch/arm/configs/nhk8815_defconfig arch/arm/configs/u300_defconfig - Uses MMC_ARMMMCI, drivers/mmc/host/mmci.[c|h] - This driver by default sets host->max_segs to NR_SG, which is 128, unless a DMA engine is used, and in that case the number of segments are also > 1 - That means this driver already disables bounce buffers - No special action needed for these platforms arch/arm/configs/sama5_defconfig - Uses MMC_SDHCI, MMC_SDHCI_PLTFM, MMC_SDHCI_OF_AT91, MMC_ATMELMCI - Uses drivers/mmc/host/sdhci.c - Normally sets host->max_segs to SDHCI_MAX_SEGS which is 128 and thus disables bounce buffers - Sets host->max_segs to 1 if SDHCI_USE_SDMA is set - SDHCI_USE_SDMA is only set by SDHCI on PCI adapers - That means that for this platform bounce buffers are already disabled at runtime - No special action needed for this platform arch/blackfin/configs/CM-BF533_defconfig arch/blackfin/configs/CM-BF537E_defconfig - Uses MMC_SPI (a simple MMC card connected on SPI pins) - Uses drivers/mmc/host/mmc_spi.c - Sets host->max_segs to MMC_SPI_BLOCKSATONCE which is 128 - That means this platform already disables bounce buffers at runtime - No special action needed for these platforms arch/mips/configs/cavium_octeon_defconfig - Uses MMC_CAVIUM_OCTEON, drivers/mmc/host/cavium.c - Sets host->max_segs to 16 or 1 - Setting host->disable_bounce to be sure for the 1 case arch/mips/configs/qi_lb60_defconfig - Uses MMC_JZ4740, drivers/mmc/host/jz4740_mmc.c - This sets host->max_segs to 128 so bounce buffers are already runtime disabled - No action needed for this platform It would be interesting to come up with a list of the platforms that actually end up using bounce buffers. I have not been able to infer such a list, but it occurs when host->max_segs == 1 and the bounce buffering is not explicitly disabled. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Instead of adding a new bool "disable_bounce" we use the host caps variable, reuse the free bit 21 to indicate that bounce buffers should be disabled on the host. --- drivers/mmc/core/Kconfig | 18 ------------------ drivers/mmc/core/queue.c | 15 +-------------- drivers/mmc/host/cavium.c | 4 +++- drivers/mmc/host/pxamci.c | 6 +++++- include/linux/mmc/host.h | 1 + 5 files changed, 10 insertions(+), 34 deletions(-) -- 2.9.3 -- 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/Kconfig b/drivers/mmc/core/Kconfig index fc1ecdaaa9ca..42e89060cd41 100644 --- a/drivers/mmc/core/Kconfig +++ b/drivers/mmc/core/Kconfig @@ -61,24 +61,6 @@ config MMC_BLOCK_MINORS If unsure, say 8 here. -config MMC_BLOCK_BOUNCE - bool "Use bounce buffer for simple hosts" - depends on MMC_BLOCK - default y - help - SD/MMC is a high latency protocol where it is crucial to - send large requests in order to get high performance. Many - controllers, however, are restricted to continuous memory - (i.e. they can't do scatter-gather), something the kernel - rarely can provide. - - Say Y here to help these restricted hosts by bouncing - requests back and forth from a large buffer. You will get - a big performance gain at the cost of up to 64 KiB of - physical memory. - - If unsure, say Y here. - config SDIO_UART tristate "SDIO UART/GPS class support" depends on TTY diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index 5c37b6be3e7b..70ba7f94c706 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -219,7 +219,6 @@ static struct mmc_queue_req *mmc_queue_alloc_mqrqs(int qdepth) return mqrq; } -#ifdef CONFIG_MMC_BLOCK_BOUNCE static int mmc_queue_alloc_bounce_bufs(struct mmc_queue_req *mqrq, int qdepth, unsigned int bouncesz) { @@ -258,7 +257,7 @@ static unsigned int mmc_queue_calc_bouncesz(struct mmc_host *host) { unsigned int bouncesz = MMC_QUEUE_BOUNCESZ; - if (host->max_segs != 1) + if (host->max_segs != 1 || (host->caps & MMC_CAP_NO_BOUNCE_BUFF)) return 0; if (bouncesz > host->max_req_size) @@ -273,18 +272,6 @@ static unsigned int mmc_queue_calc_bouncesz(struct mmc_host *host) return bouncesz; } -#else -static inline bool mmc_queue_alloc_bounce(struct mmc_queue_req *mqrq, - int qdepth, unsigned int bouncesz) -{ - return false; -} - -static unsigned int mmc_queue_calc_bouncesz(struct mmc_host *host) -{ - return 0; -} -#endif static int mmc_queue_alloc_sgs(struct mmc_queue_req *mqrq, int qdepth, int max_segs) diff --git a/drivers/mmc/host/cavium.c b/drivers/mmc/host/cavium.c index 58b51ba6aabd..9c1575f7c1fb 100644 --- a/drivers/mmc/host/cavium.c +++ b/drivers/mmc/host/cavium.c @@ -1040,10 +1040,12 @@ int cvm_mmc_of_slot_probe(struct device *dev, struct cvm_mmc_host *host) * We only have a 3.3v supply, we cannot support any * of the UHS modes. We do support the high speed DDR * modes up to 52MHz. + * + * Disable bounce buffers for max_segs = 1 */ mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | MMC_CAP_ERASE | MMC_CAP_CMD23 | MMC_CAP_POWER_OFF_CARD | - MMC_CAP_3_3V_DDR; + MMC_CAP_3_3V_DDR | MMC_CAP_NO_BOUNCE_BUFF; if (host->use_sg) mmc->max_segs = 16; diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c index c763b404510f..59ab194cb009 100644 --- a/drivers/mmc/host/pxamci.c +++ b/drivers/mmc/host/pxamci.c @@ -702,7 +702,11 @@ static int pxamci_probe(struct platform_device *pdev) pxamci_init_ocr(host); - mmc->caps = 0; + /* + * This architecture used to disable bounce buffers through its + * defconfig, now it is done at runtime as a host property. + */ + mmc->caps = MMC_CAP_NO_BOUNCE_BUFF; host->cmdat = 0; if (!cpu_is_pxa25x()) { mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ; diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 21385ac0c9b1..67f6abe5c3af 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -270,6 +270,7 @@ struct mmc_host { #define MMC_CAP_UHS_SDR50 (1 << 18) /* Host supports UHS SDR50 mode */ #define MMC_CAP_UHS_SDR104 (1 << 19) /* Host supports UHS SDR104 mode */ #define MMC_CAP_UHS_DDR50 (1 << 20) /* Host supports UHS DDR50 mode */ +#define MMC_CAP_NO_BOUNCE_BUFF (1 << 21) /* Disable bounce buffers on host */ #define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */ #define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */ #define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */ From patchwork Thu May 18 09:29:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100067 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp628942qge; Thu, 18 May 2017 02:29:58 -0700 (PDT) X-Received: by 10.99.126.67 with SMTP id o3mr3410569pgn.36.1495099798499; Thu, 18 May 2017 02:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495099798; cv=none; d=google.com; s=arc-20160816; b=KXdEFNYI28Raiyo4KC7kglb77mxSMIe0dRTzLMRCDDf1VVRibKB292AmqvoUbz1QFd WcwGH0H5ico27irQAVdqAJQqSWtBYCJ+eXoEvK64YyV5+D07GF5QTTImy5poTc+z9H9d t0MzV72yzn3vZIuwJjpG0vqIshcJuQZ4H/tLVVuUMfDdN23MyLgq0/ZvwdWpAopGoZ9J SDl/zJEg7fnB2nqSqsqcnYqdgLj1eDFc2nVru3V9WUTptEIMZMTnTI8oh9N9s9mTnGut BfnhdCyqmvB2EbZB8c9yjXTlKYNB6NNGP4+fgStVXeHqQQvBIyWvVF3fqAE3GCyJzwCz YfEQ== 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=zYsEomzCZ2aALuzoeahSsGzXnDEn684OUULAGY61+H8=; b=l91YTvBDNGvbmQfuJW/j2ldjoosDYbf8oWZnAxwrsMMzDLG4NWmqaNN7CHlJjLk0SF qyZuYL2Lyt2B71iSlJuKzRqTo0S3tHW+3T9JRmsOPzUDRqlP//hRiL+HjbhFbamSbP2R RDdErdDWaopNYX2Rm/SgTjsELg3r2f1PxmlpdJsfe/ReJVNF4D64RBZ3g26tyMwxozow KSPLxkOU2Zwvi63ADruVB/RUCS5rAp6t8YyQ8qXMhYzRC+DG9GrCzHofC7wwJynKslmq TXMBiV8qIn3vZJIuMhdzLucyK+/gMC0Cblu9j/8uEtB9D1ux5cfRnAa4Oikh4p12SCy7 O9Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 t18si4758743pgn.128.2017.05.18.02.29.58; Thu, 18 May 2017 02:29:58 -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; 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 S1754236AbdERJ35 (ORCPT + 6 others); Thu, 18 May 2017 05:29:57 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36992 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753712AbdERJ3z (ORCPT ); Thu, 18 May 2017 05:29:55 -0400 Received: by mail-wm0-f50.google.com with SMTP id d127so45278695wmf.0 for ; Thu, 18 May 2017 02:29:54 -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=sy0QUDeQEiysJG7KwaBzwWR42423H2P1LJoeEz98mk8=; b=Y5Ku+OTivJc2NFvXVMqMV1t+ViNc9PSZsciW9oyc4EdrBhhsHtsaoU4L5BnOiv2U0N D0zRTBOy82/68XRh9c/5bBRm1ZsclCCKxKhHlAvQTg8H3hq8gH4hwwb0gHqUTC07fS0V 2OV9GCec3LEd9wfWNxzjAfMQLoiM4x8IE1CV0= 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=sy0QUDeQEiysJG7KwaBzwWR42423H2P1LJoeEz98mk8=; b=JGCCVyxojI8xDS4noZVcPhMx9sQfwpY3olCvUtpFkDcUiYH8J/Y9biPOLxZJxyb/5u d9Egn1v9b5QNDzXQ25cxy3AGtyHUWQoKPj0SJQmZXh1Ekm7gtbCIQfLAjv5q/GzycEuJ gkLFo06LS9g/GE4fIIF8WvKGpmR6HP8fUQ2X6dZkdVHHqwEEbECUM5QKa3+D+ffba8SG MsY4YYhDXpZnPPDu9B9FrEsnPnzlk1AcmanY8GAUg1QJjKgq45+BU1i2My0ZWyHWAOtk Pdmt/3fB+xU4CkP0X5mIj+exL4YmgkJeHRAh5kZF+ocjO61RCdsn4/6m7wMHJ0y9y6F6 ATHA== X-Gm-Message-State: AODbwcCmsNwepl3VfLfIoRRczzFQ1SEkUkQE+6Nb5Gtszq8DPnoT79yy oi+hGgk7p6HW+fqA X-Received: by 10.25.67.18 with SMTP id q18mr721286lfa.166.1495099793819; Thu, 18 May 2017 02:29:53 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u24sm829895ljd.34.2017.05.18.02.29.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 02:29:51 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Linus Walleij Subject: [PATCH 2/6 v2] mmc: core: Allocate per-request data using the block layer core Date: Thu, 18 May 2017 11:29:32 +0200 Message-Id: <20170518092936.9277-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170518092936.9277-1-linus.walleij@linaro.org> References: <20170518092936.9277-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 mmc_queue_req is a per-request state container the MMC core uses to carry bounce buffers, pointers to asynchronous requests and so on. Currently allocated as a static array of objects, then as a request comes in, a mmc_queue_req is assigned to it, and used during the lifetime of the request. This is backwards compared to how other block layer drivers work: they usally let the block core provide a per-request struct that get allocated right beind the struct request, and which can be obtained using the blk_mq_rq_to_pdu() helper. (The _mq_ infix in this function name is misleading: it is used by both the old and the MQ block layer.) The per-request struct gets allocated to the size stored in the queue variable .cmd_size initialized using the .init_rq_fn() and cleaned up using .exit_rq_fn(). The block layer code makes the MMC core rely on this mechanism to allocate the per-request mmc_queue_req state container. Doing this make a lot of complicated queue handling go away. We only need to keep the .qnct that keeps count of how many request are currently being processed by the MMC layer. The MQ block layer will replace also this once we transition to it. Doing this refactoring is necessary to move the ioctl() operations into custom block layer requests tagged with REQ_OP_DRV_[IN|OUT] instead of the custom code using the BigMMCHostLock that we have today: those require that per-request data be obtainable easily from a request after creating a custom request with e.g.: struct request *rq = blk_get_request(q, REQ_OP_DRV_IN, __GFP_RECLAIM); struct mmc_queue_req *mq_rq = req_to_mq_rq(rq); And this is not possible with the current construction, as the request is not immediately assigned the per-request state container, but instead it gets assigned when the request finally enters the MMC queue, which is way too late for custom requests. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rename req_to_mq_rq() to req_to_mmc_queue_req() - Drop irrelevant FIXME comment. --- drivers/mmc/core/block.c | 38 ++------ drivers/mmc/core/queue.c | 221 +++++++++++++---------------------------------- drivers/mmc/core/queue.h | 22 ++--- include/linux/mmc/card.h | 2 - 4 files changed, 79 insertions(+), 204 deletions(-) -- 2.9.3 -- 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 8273b078686d..5f29b5625216 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -129,13 +129,6 @@ static inline int mmc_blk_part_switch(struct mmc_card *card, struct mmc_blk_data *md); static int get_card_status(struct mmc_card *card, u32 *status, int retries); -static void mmc_blk_requeue(struct request_queue *q, struct request *req) -{ - spin_lock_irq(q->queue_lock); - blk_requeue_request(q, req); - spin_unlock_irq(q->queue_lock); -} - static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) { struct mmc_blk_data *md; @@ -1642,7 +1635,7 @@ static void mmc_blk_rw_cmd_abort(struct mmc_queue *mq, struct mmc_card *card, if (mmc_card_removed(card)) req->rq_flags |= RQF_QUIET; while (blk_end_request(req, -EIO, blk_rq_cur_bytes(req))); - mmc_queue_req_free(mq, mqrq); + mq->qcnt--; } /** @@ -1662,7 +1655,7 @@ static void mmc_blk_rw_try_restart(struct mmc_queue *mq, struct request *req, if (mmc_card_removed(mq->card)) { req->rq_flags |= RQF_QUIET; blk_end_request_all(req, -EIO); - mmc_queue_req_free(mq, mqrq); + mq->qcnt--; /* FIXME: just set to 0? */ return; } /* Else proceed and try to restart the current async request */ @@ -1685,12 +1678,8 @@ static void mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *new_req) bool req_pending = true; if (new_req) { - mqrq_cur = mmc_queue_req_find(mq, new_req); - if (!mqrq_cur) { - WARN_ON(1); - mmc_blk_requeue(mq->queue, new_req); - new_req = NULL; - } + mqrq_cur = req_to_mmc_queue_req(new_req); + mq->qcnt++; } if (!mq->qcnt) @@ -1764,12 +1753,12 @@ static void mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *new_req) if (req_pending) mmc_blk_rw_cmd_abort(mq, card, old_req, mq_rq); else - mmc_queue_req_free(mq, mq_rq); + mq->qcnt--; mmc_blk_rw_try_restart(mq, new_req, mqrq_cur); return; } if (!req_pending) { - mmc_queue_req_free(mq, mq_rq); + mq->qcnt--; mmc_blk_rw_try_restart(mq, new_req, mqrq_cur); return; } @@ -1814,7 +1803,7 @@ static void mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *new_req) req_pending = blk_end_request(old_req, -EIO, brq->data.blksz); if (!req_pending) { - mmc_queue_req_free(mq, mq_rq); + mq->qcnt--; mmc_blk_rw_try_restart(mq, new_req, mqrq_cur); return; } @@ -1844,7 +1833,7 @@ static void mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *new_req) } } while (req_pending); - mmc_queue_req_free(mq, mq_rq); + mq->qcnt--; } void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) @@ -2166,7 +2155,6 @@ static int mmc_blk_probe(struct mmc_card *card) { struct mmc_blk_data *md, *part_md; char cap_str[10]; - int ret; /* * Check that the card supports the command class(es) we need. @@ -2176,15 +2164,9 @@ static int mmc_blk_probe(struct mmc_card *card) mmc_fixup_device(card, mmc_blk_fixups); - ret = mmc_queue_alloc_shared_queue(card); - if (ret) - return ret; - md = mmc_blk_alloc(card); - if (IS_ERR(md)) { - mmc_queue_free_shared_queue(card); + if (IS_ERR(md)) return PTR_ERR(md); - } string_get_size((u64)get_capacity(md->disk), 512, STRING_UNITS_2, cap_str, sizeof(cap_str)); @@ -2222,7 +2204,6 @@ static int mmc_blk_probe(struct mmc_card *card) out: mmc_blk_remove_parts(card, md); mmc_blk_remove_req(md); - mmc_queue_free_shared_queue(card); return 0; } @@ -2240,7 +2221,6 @@ static void mmc_blk_remove(struct mmc_card *card) pm_runtime_put_noidle(&card->dev); mmc_blk_remove_req(md); dev_set_drvdata(&card->dev, NULL); - mmc_queue_free_shared_queue(card); } static int _mmc_blk_suspend(struct mmc_card *card) diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index 70ba7f94c706..c18c41289ecf 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -40,35 +40,6 @@ static int mmc_prep_request(struct request_queue *q, struct request *req) return BLKPREP_OK; } -struct mmc_queue_req *mmc_queue_req_find(struct mmc_queue *mq, - struct request *req) -{ - struct mmc_queue_req *mqrq; - int i = ffz(mq->qslots); - - if (i >= mq->qdepth) - return NULL; - - mqrq = &mq->mqrq[i]; - WARN_ON(mqrq->req || mq->qcnt >= mq->qdepth || - test_bit(mqrq->task_id, &mq->qslots)); - mqrq->req = req; - mq->qcnt += 1; - __set_bit(mqrq->task_id, &mq->qslots); - - return mqrq; -} - -void mmc_queue_req_free(struct mmc_queue *mq, - struct mmc_queue_req *mqrq) -{ - WARN_ON(!mqrq->req || mq->qcnt < 1 || - !test_bit(mqrq->task_id, &mq->qslots)); - mqrq->req = NULL; - mq->qcnt -= 1; - __clear_bit(mqrq->task_id, &mq->qslots); -} - static int mmc_queue_thread(void *d) { struct mmc_queue *mq = d; @@ -149,11 +120,11 @@ static void mmc_request_fn(struct request_queue *q) wake_up_process(mq->thread); } -static struct scatterlist *mmc_alloc_sg(int sg_len) +static struct scatterlist *mmc_alloc_sg(int sg_len, gfp_t gfp) { struct scatterlist *sg; - sg = kmalloc_array(sg_len, sizeof(*sg), GFP_KERNEL); + sg = kmalloc_array(sg_len, sizeof(*sg), gfp); if (sg) sg_init_table(sg, sg_len); @@ -179,80 +150,6 @@ static void mmc_queue_setup_discard(struct request_queue *q, queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q); } -static void mmc_queue_req_free_bufs(struct mmc_queue_req *mqrq) -{ - kfree(mqrq->bounce_sg); - mqrq->bounce_sg = NULL; - - kfree(mqrq->sg); - mqrq->sg = NULL; - - kfree(mqrq->bounce_buf); - mqrq->bounce_buf = NULL; -} - -static void mmc_queue_reqs_free_bufs(struct mmc_queue_req *mqrq, int qdepth) -{ - int i; - - for (i = 0; i < qdepth; i++) - mmc_queue_req_free_bufs(&mqrq[i]); -} - -static void mmc_queue_free_mqrqs(struct mmc_queue_req *mqrq, int qdepth) -{ - mmc_queue_reqs_free_bufs(mqrq, qdepth); - kfree(mqrq); -} - -static struct mmc_queue_req *mmc_queue_alloc_mqrqs(int qdepth) -{ - struct mmc_queue_req *mqrq; - int i; - - mqrq = kcalloc(qdepth, sizeof(*mqrq), GFP_KERNEL); - if (mqrq) { - for (i = 0; i < qdepth; i++) - mqrq[i].task_id = i; - } - - return mqrq; -} - -static int mmc_queue_alloc_bounce_bufs(struct mmc_queue_req *mqrq, int qdepth, - unsigned int bouncesz) -{ - int i; - - for (i = 0; i < qdepth; i++) { - mqrq[i].bounce_buf = kmalloc(bouncesz, GFP_KERNEL); - if (!mqrq[i].bounce_buf) - return -ENOMEM; - - mqrq[i].sg = mmc_alloc_sg(1); - if (!mqrq[i].sg) - return -ENOMEM; - - mqrq[i].bounce_sg = mmc_alloc_sg(bouncesz / 512); - if (!mqrq[i].bounce_sg) - return -ENOMEM; - } - - return 0; -} - -static bool mmc_queue_alloc_bounce(struct mmc_queue_req *mqrq, int qdepth, - unsigned int bouncesz) -{ - int ret; - - ret = mmc_queue_alloc_bounce_bufs(mqrq, qdepth, bouncesz); - if (ret) - mmc_queue_reqs_free_bufs(mqrq, qdepth); - - return !ret; -} - static unsigned int mmc_queue_calc_bouncesz(struct mmc_host *host) { unsigned int bouncesz = MMC_QUEUE_BOUNCESZ; @@ -273,71 +170,61 @@ static unsigned int mmc_queue_calc_bouncesz(struct mmc_host *host) return bouncesz; } -static int mmc_queue_alloc_sgs(struct mmc_queue_req *mqrq, int qdepth, - int max_segs) +/** + * mmc_init_request() - initialize the MMC-specific per-request data + * @q: the request queue + * @req: the request + * @gfp: memory allocation policy + */ +static int mmc_init_request(struct request_queue *q, struct request *req, + gfp_t gfp) { - int i; + struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req); + struct mmc_queue *mq = q->queuedata; + struct mmc_card *card = mq->card; + struct mmc_host *host = card->host; - for (i = 0; i < qdepth; i++) { - mqrq[i].sg = mmc_alloc_sg(max_segs); - if (!mqrq[i].sg) + mq_rq->req = req; + + if (card->bouncesz) { + mq_rq->bounce_buf = kmalloc(card->bouncesz, gfp); + if (!mq_rq->bounce_buf) + return -ENOMEM; + if (card->bouncesz > 512) { + mq_rq->sg = mmc_alloc_sg(1, gfp); + if (!mq_rq->sg) + return -ENOMEM; + mq_rq->bounce_sg = mmc_alloc_sg(card->bouncesz / 512, + gfp); + if (!mq_rq->bounce_sg) + return -ENOMEM; + } + } else { + mq_rq->bounce_buf = NULL; + mq_rq->bounce_sg = NULL; + mq_rq->sg = mmc_alloc_sg(host->max_segs, gfp); + if (!mq_rq->sg) return -ENOMEM; } return 0; } -void mmc_queue_free_shared_queue(struct mmc_card *card) +static void mmc_exit_request(struct request_queue *q, struct request *req) { - if (card->mqrq) { - mmc_queue_free_mqrqs(card->mqrq, card->qdepth); - card->mqrq = NULL; - } -} + struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req); -static int __mmc_queue_alloc_shared_queue(struct mmc_card *card, int qdepth) -{ - struct mmc_host *host = card->host; - struct mmc_queue_req *mqrq; - unsigned int bouncesz; - int ret = 0; - - if (card->mqrq) - return -EINVAL; - - mqrq = mmc_queue_alloc_mqrqs(qdepth); - if (!mqrq) - return -ENOMEM; + /* It is OK to kfree(NULL) so this will be smooth */ + kfree(mq_rq->bounce_sg); + mq_rq->bounce_sg = NULL; - card->mqrq = mqrq; - card->qdepth = qdepth; + kfree(mq_rq->bounce_buf); + mq_rq->bounce_buf = NULL; - bouncesz = mmc_queue_calc_bouncesz(host); - - if (bouncesz && !mmc_queue_alloc_bounce(mqrq, qdepth, bouncesz)) { - bouncesz = 0; - pr_warn("%s: unable to allocate bounce buffers\n", - mmc_card_name(card)); - } - - card->bouncesz = bouncesz; - - if (!bouncesz) { - ret = mmc_queue_alloc_sgs(mqrq, qdepth, host->max_segs); - if (ret) - goto out_err; - } + kfree(mq_rq->sg); + mq_rq->sg = NULL; - return ret; - -out_err: - mmc_queue_free_shared_queue(card); - return ret; -} - -int mmc_queue_alloc_shared_queue(struct mmc_card *card) -{ - return __mmc_queue_alloc_shared_queue(card, 2); + mq_rq->req = NULL; } /** @@ -360,13 +247,21 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT; mq->card = card; - mq->queue = blk_init_queue(mmc_request_fn, lock); + mq->queue = blk_alloc_queue(GFP_KERNEL); if (!mq->queue) return -ENOMEM; - - mq->mqrq = card->mqrq; - mq->qdepth = card->qdepth; + mq->queue->queue_lock = lock; + mq->queue->request_fn = mmc_request_fn; + mq->queue->init_rq_fn = mmc_init_request; + mq->queue->exit_rq_fn = mmc_exit_request; + mq->queue->cmd_size = sizeof(struct mmc_queue_req); mq->queue->queuedata = mq; + mq->qcnt = 0; + ret = blk_init_allocated_queue(mq->queue); + if (ret) { + blk_cleanup_queue(mq->queue); + return ret; + } blk_queue_prep_rq(mq->queue, mmc_prep_request); queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); @@ -374,6 +269,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, if (mmc_can_erase(card)) mmc_queue_setup_discard(mq->queue, card); + card->bouncesz = mmc_queue_calc_bouncesz(host); if (card->bouncesz) { blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY); blk_queue_max_hw_sectors(mq->queue, card->bouncesz / 512); @@ -400,7 +296,6 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, return 0; cleanup_queue: - mq->mqrq = NULL; blk_cleanup_queue(mq->queue); return ret; } @@ -421,8 +316,8 @@ void mmc_cleanup_queue(struct mmc_queue *mq) q->queuedata = NULL; blk_start_queue(q); spin_unlock_irqrestore(q->queue_lock, flags); + blk_cleanup_queue(mq->queue); - mq->mqrq = NULL; mq->card = NULL; } EXPORT_SYMBOL(mmc_cleanup_queue); diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index 871796c3f406..dae31bc0c2d3 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -3,9 +3,15 @@ #include #include +#include #include #include +static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq) +{ + return blk_mq_rq_to_pdu(rq); +} + static inline bool mmc_req_is_special(struct request *req) { return req && @@ -34,7 +40,6 @@ struct mmc_queue_req { struct scatterlist *bounce_sg; unsigned int bounce_sg_len; struct mmc_async_req areq; - int task_id; }; struct mmc_queue { @@ -45,14 +50,15 @@ struct mmc_queue { bool asleep; struct mmc_blk_data *blkdata; struct request_queue *queue; - struct mmc_queue_req *mqrq; - int qdepth; + /* + * FIXME: this counter is not a very reliable way of keeping + * track of how many requests that are ongoing. Switch to just + * letting the block core keep track of requests and per-request + * associated mmc_queue_req data. + */ int qcnt; - unsigned long qslots; }; -extern int mmc_queue_alloc_shared_queue(struct mmc_card *card); -extern void mmc_queue_free_shared_queue(struct mmc_card *card); extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *, const char *); extern void mmc_cleanup_queue(struct mmc_queue *); @@ -66,8 +72,4 @@ extern void mmc_queue_bounce_post(struct mmc_queue_req *); extern int mmc_access_rpmb(struct mmc_queue *); -extern struct mmc_queue_req *mmc_queue_req_find(struct mmc_queue *, - struct request *); -extern void mmc_queue_req_free(struct mmc_queue *, struct mmc_queue_req *); - #endif diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index aad015e0152b..46c73e97e61f 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -305,9 +305,7 @@ struct mmc_card { struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */ unsigned int nr_parts; - struct mmc_queue_req *mqrq; /* Shared queue structure */ unsigned int bouncesz; /* Bounce buffer size */ - int qdepth; /* Shared queue depth */ }; static inline bool mmc_large_sector(struct mmc_card *card) From patchwork Thu May 18 09:29:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100069 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp629094qge; Thu, 18 May 2017 02:30:18 -0700 (PDT) X-Received: by 10.99.109.9 with SMTP id i9mr3395666pgc.56.1495099818540; Thu, 18 May 2017 02:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495099818; cv=none; d=google.com; s=arc-20160816; b=cF/b+Fyw6PXGvcD1Y8K0qgmqGVe/b5wKwlGBeQft5QZiHVswRheZErG07bBBYWBW7A PEOfA3wlc9klktt2NzMKHGcNzjSxmupkdSyU1c7pCWUSwMkWfHcGGjFrIL8eySbbWtjD 1wK/DkLePUYP4MNo5tgouU5kmLx69a7qzIgobF70MKpTDFm/ui3kAeRGdKdJziAcuGCN zLI5mCK4b+sa/QLeXqHVf1nwZZKS1F4FtwXlFs5gTeNX6idrjoceimzYmRjNcHkjCOAR MDUyDfexs1iwUac/d7OQwcNtvdqZaysZVFZYT71MVeF840KYWkE9OKyM/Pmfupv2JmfZ atkw== 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=VcrjJJoIBtfaQPSebT6TFPgFuU//b4gtlxoDDj+3dns=; b=Gl/MOxI/EpSwGWmksQizajuVxtNdrz7vIGzo7sZYezNFGrpbGo0auPdoCeDNbiy2Fh eiA8zI5z1i1uhyHFjTsad9CTe1hI+vHOgiIuM/K00+uDIvxC2ESrzdoj0EH9vTrnUzoK SFGbT9hpVzvKVXemLBS6mll5reh5xaSEnKrjvLYVhig8nmllAdYLbEoyI7OogyXChXHF iXi7alIZFaPdHkHWOpTcLiknBeG/Znt7kon2h5sbi6bCqpuUaUKmeSwmaBQIuavgSRSq ZhnSwZj8ngtKbzHr/r/1IOeOiVSOgkGBT7x2IH1GVR4Re7oLW1hhouoTg/i9FioBkG8G GptQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 33si4553082plk.96.2017.05.18.02.30.18; Thu, 18 May 2017 02:30:18 -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; 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 S1754827AbdERJaD (ORCPT + 6 others); Thu, 18 May 2017 05:30:03 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:33583 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754689AbdERJaB (ORCPT ); Thu, 18 May 2017 05:30:01 -0400 Received: by mail-wr0-f173.google.com with SMTP id w50so29178990wrc.0 for ; Thu, 18 May 2017 02:30:00 -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=nfCXMWV/+lmiqbuVI9/ZXhXFO3BYey7DcJf3Rn6c1sY=; b=K1brLiE03j4ruSX5ULj7gMwMyJfhwGzD+7vLF1SR6IBpEj+4mdfsrIKOSUwlQZ8V2P 6sGvBtzrH9bmVUdEZ/z7imx9FL4sKNwXqv+P8cAqrpW26M067oES452pckxYgQDX7Py8 S3XJQ+0eNTDInuG5Xe/biSX9IfO3u+QhY0Gx4= 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=nfCXMWV/+lmiqbuVI9/ZXhXFO3BYey7DcJf3Rn6c1sY=; b=ct3eCpUwm5yyKKrN2giVwrBxOpYyV/EPiV2kbtNalDWg1SomyKSwXEK5TRZ4Gqvi9V MLUvq6a/sAjiS9VgSmQFPVAnCSVUoFhUkG1Xxb5zVQVcm4aKludmS1VpAxVy+3WLiZww 9liiUkKRQVT2kGpPb8AsgFqYOCKymfiDX4qLGmxsiO53h2z2kCfKzU0KE4mA+q39AVW+ WDKeiDcdW44AT6YEg1T5EvP9B+lgRbtnnb+Br6yUi/u7gQokygngLtMJaPkrBR7vNi5a 0XC77vIc/C1QVoIfoUlNm8LP14IFX8ApFLbhgX4UCftwb4v7BFWtE7RA0L9lgynFu0RF abUA== X-Gm-Message-State: AODbwcCmZTjRjDGTvYBmeYy9hMjUUpoaYZjokwZQRiGHhmQ4xS+p2jmO zik1zxpVHnFdkXIa X-Received: by 10.46.97.26 with SMTP id v26mr886745ljb.22.1495099799632; Thu, 18 May 2017 02:29:59 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u24sm829895ljd.34.2017.05.18.02.29.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 02:29:58 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Linus Walleij Subject: [PATCH 3/6 v2] mmc: block: Tag is_rpmb as bool Date: Thu, 18 May 2017 11:29:33 +0200 Message-Id: <20170518092936.9277-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170518092936.9277-1-linus.walleij@linaro.org> References: <20170518092936.9277-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 variable is_rpmb is clearly a bool and even assigned true and false, yet declared as an int. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - No changes, just resending --- drivers/mmc/core/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.9.3 -- 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 5f29b5625216..f4dab1dfd2ab 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -443,7 +443,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, struct mmc_request mrq = {}; struct scatterlist sg; int err; - int is_rpmb = false; + bool is_rpmb = false; u32 status = 0; if (!card || !md || !idata) From patchwork Thu May 18 09:29:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100068 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp629089qge; Thu, 18 May 2017 02:30:18 -0700 (PDT) X-Received: by 10.99.218.69 with SMTP id l5mr3556229pgj.88.1495099817929; Thu, 18 May 2017 02:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495099817; cv=none; d=google.com; s=arc-20160816; b=y7LFnB1WJyWRQru1/vhlA+RJRd/twg++JhJvFHybqUub4KunmtQtUJn5JqJssQ4rT+ uW30ZHE1xs/jQD+oTRMA1Q326C/eIVrqbgG+b27VJG5GKYSGA+c3MhRgsLOn3LVNcCS9 DkcLgXHcezlZXnVdjsf/Iaam+QQAf+xeG9BFs6ddbN7W7JqIHjpOXs2Ev/LIO3Aggd6L 4ipjMYYiK0WjIydVflQGOcyVFappv9QIs4kP4KdBFF5azUlEsNm2YQAmrIjc16fliKJu plQxglN53LGwADz9cH1QaaoIuVg6H64s4gtIdDv+/wkx2CmvBP9iQmUkWr2AATU9zJXG 1sLw== 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=5Arw0yfDKRi4ur3ZCkGjhkTrxn3SMx4QNPSM7pbZ6I4=; b=zMni+Oj0+j6R4XRVNB57xjxCnKjLBjGnRYw2I8vut8yATorn1q8rvxPmAOJXcDbpqg M8Og4jSpQ0KCvTefPepu1iKcgH5RRBcA39d0mG2SiSI6DgALgNLutaKxxc+WGMRlQQ/w eklsm5wEdIv+1zGvLNLubzghL3lV8uTMKHp0knRnnl7D6IfG98bt/bSjud40bpWbl6Ko pj8dd08AlRWE0dMqgpva/sKfN/cwxGaGWCz6xUDXPUcV3yO+1Zq0qlQ9/tWH9HAZH9bf idQ5kvZZqS+2iw6oKwAKYTHFqi3N0Yeyei87D1GpVRU8dq9+vG+FStrRPF9BmL63aea6 9r3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 33si4553082plk.96.2017.05.18.02.30.17; Thu, 18 May 2017 02:30: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; 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 S1754909AbdERJaL (ORCPT + 6 others); Thu, 18 May 2017 05:30:11 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:35376 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755158AbdERJaH (ORCPT ); Thu, 18 May 2017 05:30:07 -0400 Received: by mail-wr0-f172.google.com with SMTP id z52so29200240wrc.2 for ; Thu, 18 May 2017 02:30:07 -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=G/IwQ9U0Dm3V+tLyi17MZe4FoulPw25GUV9IuuABn5s=; b=iuLw3v1ICojI/ZO30qpBr6bwD2BuVa5zZ2KI1qjpGUqsWpbLVUhNnFvXR2aqJpI3Ot wbK/HB0RxSsFKKDONhUNQx8e4Wr81ARiOpmR0McEcHMN6Xgi+I7as3hpfQQPtU6/fzW8 coqfawW+jeD7bUsWhXTXg7aayOlmHSNT3qmg8= 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=G/IwQ9U0Dm3V+tLyi17MZe4FoulPw25GUV9IuuABn5s=; b=babvxPQiUPI9qbEQK4Pahmk2dASRKntDqFRU4b2pO0bXdsveEO/gu9RLIck/VK8GD9 cFLywzWn5ye3qr/P6IaTUL+3b+CCoMPHfU2oCJ6FkREzhWh3UBitBEgUGuP0Z4H0gMxo TR/rfDdAbfqluOkIT6OvoqKSNAkLKswUIoY5rdCQsekdeIC+ODi5siGe2L7eauCyT0x6 blglHic/63zSTjtGoqURQvxWfHbVJxoZGmcSwzL7Ga5QrYaBrko9mZ/LbeBGsq6qthne yjgO6a/F1Z9Zqp+ZTt9eCHm6JuHeFrAOGaNUSiV6d2f+7WvN5Qpr4wA3qvmcEOUbPcpC fBdQ== X-Gm-Message-State: AODbwcBBxIew0xHF20UYa97f+iSoS5iUm6aBa2JSEV2HNd8kol4CEu+T I71dL+lB//WwQKRO X-Received: by 10.46.5.147 with SMTP id 141mr953519ljf.108.1495099806166; Thu, 18 May 2017 02:30:06 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u24sm829895ljd.34.2017.05.18.02.30.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 02:30:05 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Linus Walleij Subject: [PATCH 4/6 v2] mmc: block: move single ioctl() commands to block requests Date: Thu, 18 May 2017 11:29:34 +0200 Message-Id: <20170518092936.9277-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170518092936.9277-1-linus.walleij@linaro.org> References: <20170518092936.9277-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 wraps single ioctl() commands into block requests using the custom block layer request types REQ_OP_DRV_IN and REQ_OP_DRV_OUT. By doing this we are loosening the grip on the big host lock, since two calls to mmc_get_card()/mmc_put_card() are removed. We are storing the ioctl() in/out argument as a pointer in the per-request struct mmc_blk_request container. Since we now let the block layer allocate this data, blk_get_request() will allocate it for us and we can immediately dereference it and use it to pass the argument into the block layer. We refactor the if/else/if/else ladder in mmc_blk_issue_rq() as part of the job, keeping some extra attention to the case when a NULL req is passed into this function and making that pipeline flush more explicit. Tested on the ux500 with the userspace: mmc extcsd read /dev/mmcblk3 resulting in a successful EXTCSD info dump back to the console. This commit fixes a starvation issue in the MMC/SD stack that can be easily provoked in the following way by issueing the following commands in sequence: > dd if=/dev/mmcblk3 of=/dev/null bs=1M & > mmc extcs read /dev/mmcblk3 Before this patch, the extcsd read command would hang (starve) while waiting for the dd command to finish since the block layer was holding the card/host lock. After this patch, the extcsd ioctl() command is nicely interpersed with the rest of the block commands and we can issue a bunch of ioctl()s from userspace while there is some busy block IO going on without any problems. Conversely userspace ioctl()s can no longer starve the block layer by holding the card/host lock. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Replace the if/else/if/else nest in mmc_blk_issue_rq() with a switch() clause at Ulf's request. - Update to the API change for req_to_mmc_queue_req() --- drivers/mmc/core/block.c | 111 ++++++++++++++++++++++++++++++++++++----------- drivers/mmc/core/queue.h | 3 ++ 2 files changed, 88 insertions(+), 26 deletions(-) -- 2.9.3 -- 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 f4dab1dfd2ab..9fb2bd529156 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -564,8 +564,10 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, { struct mmc_blk_ioc_data *idata; struct mmc_blk_data *md; + struct mmc_queue *mq; struct mmc_card *card; int err = 0, ioc_err = 0; + struct request *req; /* * The caller must have CAP_SYS_RAWIO, and must be calling this on the @@ -591,17 +593,18 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, goto cmd_done; } - mmc_get_card(card); - - ioc_err = __mmc_blk_ioctl_cmd(card, md, idata); - - /* 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_put_card(card); - + /* + * Dispatch the ioctl() into the block request queue. + */ + mq = &md->queue; + req = blk_get_request(mq->queue, + idata->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, + __GFP_RECLAIM); + req_to_mmc_queue_req(req)->idata = idata; + blk_execute_rq(mq->queue, NULL, req, 0); + ioc_err = req_to_mmc_queue_req(req)->ioc_result; err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata); + blk_put_request(req); cmd_done: mmc_blk_put(md); @@ -611,6 +614,31 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, return ioc_err ? ioc_err : err; } +/* + * The ioctl 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 + * function. + */ +static void mmc_blk_ioctl_cmd_issue(struct mmc_queue *mq, struct request *req) +{ + struct mmc_queue_req *mq_rq; + struct mmc_blk_ioc_data *idata; + struct mmc_card *card = mq->card; + struct mmc_blk_data *md = mq->blkdata; + int ioc_err; + + mq_rq = req_to_mmc_queue_req(req); + idata = mq_rq->idata; + ioc_err = __mmc_blk_ioctl_cmd(card, md, idata); + mq_rq->ioc_result = ioc_err; + + /* 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)); + + blk_end_request_all(req, ioc_err); +} + static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, struct mmc_ioc_multi_cmd __user *user) { @@ -1854,23 +1882,54 @@ void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) goto out; } - if (req && req_op(req) == REQ_OP_DISCARD) { - /* complete ongoing async transfer before issuing discard */ - if (mq->qcnt) - mmc_blk_issue_rw_rq(mq, NULL); - mmc_blk_issue_discard_rq(mq, req); - } else if (req && req_op(req) == REQ_OP_SECURE_ERASE) { - /* complete ongoing async transfer before issuing secure erase*/ - if (mq->qcnt) - mmc_blk_issue_rw_rq(mq, NULL); - mmc_blk_issue_secdiscard_rq(mq, req); - } else if (req && req_op(req) == REQ_OP_FLUSH) { - /* complete ongoing async transfer before issuing flush */ - if (mq->qcnt) - mmc_blk_issue_rw_rq(mq, NULL); - mmc_blk_issue_flush(mq, req); + if (req) { + switch (req_op(req)) { + case REQ_OP_DRV_IN: + case REQ_OP_DRV_OUT: + /* + * Complete ongoing async transfer before issuing + * ioctl()s + */ + if (mq->qcnt) + mmc_blk_issue_rw_rq(mq, NULL); + mmc_blk_ioctl_cmd_issue(mq, req); + break; + case REQ_OP_DISCARD: + /* + * Complete ongoing async transfer before issuing + * discard. + */ + if (mq->qcnt) + mmc_blk_issue_rw_rq(mq, NULL); + mmc_blk_issue_discard_rq(mq, req); + break; + case REQ_OP_SECURE_ERASE: + /* + * Complete ongoing async transfer before issuing + * secure erase. + */ + if (mq->qcnt) + mmc_blk_issue_rw_rq(mq, NULL); + mmc_blk_issue_secdiscard_rq(mq, req); + break; + case REQ_OP_FLUSH: + /* + * Complete ongoing async transfer before issuing + * flush. + */ + if (mq->qcnt) + mmc_blk_issue_rw_rq(mq, NULL); + mmc_blk_issue_flush(mq, req); + break; + default: + /* Normal request, just issue it */ + mmc_blk_issue_rw_rq(mq, req); + card->host->context_info.is_waiting_last_req = false; + break; + }; } else { - mmc_blk_issue_rw_rq(mq, req); + /* No request, flushing the pipeline with NULL */ + mmc_blk_issue_rw_rq(mq, NULL); card->host->context_info.is_waiting_last_req = false; } diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index dae31bc0c2d3..005ece9ac7cb 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -22,6 +22,7 @@ static inline bool mmc_req_is_special(struct request *req) struct task_struct; struct mmc_blk_data; +struct mmc_blk_ioc_data; struct mmc_blk_request { struct mmc_request mrq; @@ -40,6 +41,8 @@ struct mmc_queue_req { struct scatterlist *bounce_sg; unsigned int bounce_sg_len; struct mmc_async_req areq; + int ioc_result; + struct mmc_blk_ioc_data *idata; }; struct mmc_queue { From patchwork Thu May 18 09:29:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100070 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp629121qge; Thu, 18 May 2017 02:30:22 -0700 (PDT) X-Received: by 10.84.215.15 with SMTP id k15mr3655044pli.104.1495099822299; Thu, 18 May 2017 02:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495099822; cv=none; d=google.com; s=arc-20160816; b=h8ItPKYQUwJNuVyFwtCieAKOqpr3dQINsQ3QjEk+sp0soVLIEntUwTAhAM3zH1DYze 1gvainOleGku35VJImVfq5bWcQtOGyntM6y0CcXovHNjlHBIN90vyxVtn7qH3AK5ONwK pfTci1Ye5xQiA+XCfk8xFdoZeh4fE6VQMBPRfwKy4tDAaAKHo8ctFdK5yPJxklJRqiRY 5UIjG6jBorS/AE1IKxaG1PAtl3slqAncc2xBQwjja2jVxpr8VhpsjRny+W6wf80X4mKF IvoH84McsXzWorQvkkzTVdY25W+lcpaN+BNwt9ImCbYz32a4PHBcdDXZ037v66FoVIZc IVSw== 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=ldH0EG8RhovDyQb13BGwLKWx4tDXSwVrZB2seHddAy0=; b=Z27UE4ABKMLy6reHOBth7ZIj06e66B14LbC0Vlx+bMwDK3SZyKHPR7/0NDQIHiOJzb xr+F/DCJJMr6W9WVHqVJPAgPdJiDqyZ6MQz+GFDYJswtIfRPBICJdwoLGRq8/umIjqCs UXoXri4+dwDrRyIxSyYB82wM0CU9DLeSALKBCQ6b1oslQcktIojs3sah1ABaO2vvbCzZ rjnlve7pjs93X54BcYCZuoG6j+43btfYBXcjB23owHkSVzy66iuggm11lmz1O/n2ICQR QDzLhxX/FSSVIYn5Yo+vwag7Zn5S2Fem2JR5SQ8Hy09udbVqSduC8U6ZQ8feVnWvgGfm xbpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 33si4553082plk.96.2017.05.18.02.30.22; Thu, 18 May 2017 02:30:22 -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; 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 S1755188AbdERJaV (ORCPT + 6 others); Thu, 18 May 2017 05:30:21 -0400 Received: from mail-wr0-f177.google.com ([209.85.128.177]:33713 "EHLO mail-wr0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755158AbdERJaU (ORCPT ); Thu, 18 May 2017 05:30:20 -0400 Received: by mail-wr0-f177.google.com with SMTP id w50so29184539wrc.0 for ; Thu, 18 May 2017 02:30:19 -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=kc0kJnDTHe3yqRVoOtCy+1DK2r5Mgt3aJsgeV8GakYA=; b=JscGuDs5ZhibB5i0YhdCJ2ieOnGCAvM4m2ZU/Y9/gkrB3o5ab52/jP1RhGuhdevoWy D0lKh/qcvG1vvtKW+JTV5zXVIGS/QnmKDFSYZc8Kowr9vBbf0nHO7JBxdN7lsvxdVzmt 2QW3yqp8TmRq748f7uInf3BPG15KFnMvJsnG0= 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=kc0kJnDTHe3yqRVoOtCy+1DK2r5Mgt3aJsgeV8GakYA=; b=CtfgzOzp/Ju6iv7sCx88+1vAocNq0R+KxeeOdGlr5yDxcACOtwnV5Mgv9F5tF9Y9f5 YHQ9bZ0do2O6HuxnwXzXMriJRPp0ilqPg8kLyOLH4SzkpGMNtFrPaqUxqbjlWsBjGAcU KDbmM2fHFf1OZtkJh3UT0ZPVZeR8VYZQC17B0R5Ua/mMQ8ZuehybAzWbcxIIkqId64mI o2eQVm5tu2iHuJaEITB8QO8g0O41s2RgavOIZwPjhzlR3Oe7/hdAxNlN7R+6Ad/p4qN4 N5rU8XYhIqfXsgftusSd7uIl/hBI3bwgHPoIV7ZOF2Ptyy3fWAUTWBAeX6NO0BUjVWF3 G1wg== X-Gm-Message-State: AODbwcCGs8PRbUtQkyGif+AvQXbkwBQ7I01CH2p65XSKRrD/+a8hT/OM lPWgGVX/auDOSOM9 X-Received: by 10.46.76.25 with SMTP id z25mr82593lja.1.1495099813831; Thu, 18 May 2017 02:30:13 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u24sm829895ljd.34.2017.05.18.02.30.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 02:30:11 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Linus Walleij Subject: [PATCH 5/6 v2] mmc: block: move multi-ioctl() to use block layer Date: Thu, 18 May 2017 11:29:35 +0200 Message-Id: <20170518092936.9277-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170518092936.9277-1-linus.walleij@linaro.org> References: <20170518092936.9277-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 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 --- ChangeLog v1->v2: - - Update to the API change for req_to_mmc_queue_req() --- drivers/mmc/core/block.c | 38 +++++++++++++++++++++++++------------- drivers/mmc/core/queue.h | 3 ++- 2 files changed, 27 insertions(+), 14 deletions(-) -- 2.9.3 -- 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 9fb2bd529156..e9737987956f 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -563,6 +563,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, 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; @@ -600,7 +601,9 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, req = blk_get_request(mq->queue, idata->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, __GFP_RECLAIM); - req_to_mmc_queue_req(req)->idata = idata; + idatas[0] = idata; + req_to_mmc_queue_req(req)->idata = idatas; + req_to_mmc_queue_req(req)->ioc_count = 1; blk_execute_rq(mq->queue, NULL, req, 0); ioc_err = req_to_mmc_queue_req(req)->ioc_result; err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata); @@ -622,14 +625,17 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, static void mmc_blk_ioctl_cmd_issue(struct mmc_queue *mq, struct request *req) { struct mmc_queue_req *mq_rq; - struct mmc_blk_ioc_data *idata; struct mmc_card *card = mq->card; struct mmc_blk_data *md = mq->blkdata; int ioc_err; + int i; mq_rq = req_to_mmc_queue_req(req); - idata = mq_rq->idata; - ioc_err = __mmc_blk_ioctl_cmd(card, md, idata); + for (i = 0; i < mq_rq->ioc_count; i++) { + ioc_err = __mmc_blk_ioctl_cmd(card, md, mq_rq->idata[i]); + if (ioc_err) + break; + } mq_rq->ioc_result = ioc_err; /* Always switch back to main area after RPMB access */ @@ -646,8 +652,10 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, 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; + struct request *req; /* * 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, goto cmd_done; } - mmc_get_card(card); - - for (i = 0; i < num_of_cmds && !ioc_err; i++) - ioc_err = __mmc_blk_ioctl_cmd(card, md, idata[i]); - - /* 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_put_card(card); + /* + * Dispatch the ioctl()s into the block request queue. + */ + mq = &md->queue; + 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)->idata = idata; + req_to_mmc_queue_req(req)->ioc_count = num_of_cmds; + blk_execute_rq(mq->queue, NULL, req, 0); + ioc_err = req_to_mmc_queue_req(req)->ioc_result; /* copy to user if data and response */ for (i = 0; i < num_of_cmds && !err; i++) err = mmc_blk_ioctl_copy_to_user(&cmds[i], idata[i]); + blk_put_request(req); + cmd_done: mmc_blk_put(md); cmd_err: diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index 005ece9ac7cb..8c76e7118c95 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -42,7 +42,8 @@ struct mmc_queue_req { unsigned int bounce_sg_len; struct mmc_async_req areq; int ioc_result; - struct mmc_blk_ioc_data *idata; + struct mmc_blk_ioc_data **idata; + unsigned int ioc_count; }; struct mmc_queue { From patchwork Thu May 18 09:29:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100071 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp629126qge; Thu, 18 May 2017 02:30:23 -0700 (PDT) X-Received: by 10.98.147.67 with SMTP id b64mr3396610pfe.145.1495099823450; Thu, 18 May 2017 02:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495099823; cv=none; d=google.com; s=arc-20160816; b=VFiMc8VMm5mSAL8FGOrgDaTBD9nJXNLD3NWlSvG9Mcsn+ixLZhirjwVj7N5whx613h WKhxZ3Ybd7I0aFKaxYtH7sBG8lS/qXeioc0B7alw6a0pXqQa3zD8/cKA8Fg1DLLj/E08 v095cF4YCJX++WVVW4jpIg37hgJe7GiDSVtO9fXYCZucUkOZId07vtyUZScnbhjLcwQX rT1kXkNdtDKVFznqXjtS7a+f7CoG3LhWa/hNRxyaNouBNFLh2Ei9I9zqxyI87gZalAme 4+zH/XsiaaZKqdZbjgANw7XVJlgUQEhvznHB3nDlKmUgWbcQJQBv0oUTsDGdpcBO/eDI 12wQ== 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=1tsnuNNvXKDovNue3R/hOd62XvQ+5417TMd5sYdxCLc=; b=KVsozxNbAgHkhhmnz7CFMEFp1h3wyzXtDdqQDvyLw7u0BYG/8ei10Htx12NuZuEeEG oIdDyBiYjHQzGqV0nRj59ORMPZ/G1Hy2HEqeBoIbdWBlz+tmf3uNXiELm15L8tiltw3Z sXWkZm/rz9CKlYHQCLvG7SBQ3PxmvWQHdu1Oq6RopOUS5uHRs1LcTs++UuecQRwWiwMp DeDGolVkgDChREJndEOLlBTRgu4dzj3baNJ2PJQkwSFWR4Dzg0BSatHo7RzGkAxFP1xU /QYg0Fmjq8PQ5Cht1D1jpuTaHXcKkPTVYv/b9uietv85LvfAKsF8gsl5DuzmRcHSfbDg k1Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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 33si4553082plk.96.2017.05.18.02.30.23; Thu, 18 May 2017 02:30:23 -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; 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 S1755254AbdERJaW (ORCPT + 6 others); Thu, 18 May 2017 05:30:22 -0400 Received: from mail-wr0-f175.google.com ([209.85.128.175]:36484 "EHLO mail-wr0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754929AbdERJaU (ORCPT ); Thu, 18 May 2017 05:30:20 -0400 Received: by mail-wr0-f175.google.com with SMTP id l50so29199367wrc.3 for ; Thu, 18 May 2017 02:30: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=04xPwC6CCgFAYb80CddG+F+yddsafZqB1vLfTf0QAHs=; b=aQxXgQJF2iGvnrzyZA+ThzahBwne5sRqoeb92XDPAC/K2ssW8xUj/IP0u4dn5GvXNI CSHzoYHJXxhhIa2jmv+Agq7zgQxxpa/mxmQt9UjWMDXvE7VREHTvRUsYk1z6MEBnqLLr jhgKPfjyBBx+kR2MoP/Z7baWkXdci759d5o2U= 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=04xPwC6CCgFAYb80CddG+F+yddsafZqB1vLfTf0QAHs=; b=cInefEdcHt1SyYmSSq0i57pocDxJMeN1fXTyqW3xYon+E5InQIxyAkGMDUtn7FiLyi zYw0G4ffpD/K224iv9gOn90+TwpV2sDGLL+PG5s7kncPPzh2djSZbfUzZpmnotpLQ/U4 VDu12fLiJ3kpewNvl0Z9BPMSF6sN4rG7biBJ2L3YZyyfcRVD1hPXrWEkjfefnYKtjDD5 6KjqvmugO9kVUry46koaLmv3ohIVydw39xI7Zs04gvCWW144duq1XHvbKTFJcbK3d8AP STlOK8ov18CF4rQHnHR078SbjKi5cLooHRydiTub7wO3qEEzd+RzddC7n0jFdJqrX3MO XEMA== X-Gm-Message-State: AODbwcBukJ+qWCxra586OE4+FxaeGn3p0iPiHER8YoMHP3gAjk0h36Ke e/ydpnH8JK+BecHQ X-Received: by 10.46.7.1 with SMTP id 1mr775154ljh.27.1495099819342; Thu, 18 May 2017 02:30:19 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u24sm829895ljd.34.2017.05.18.02.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 02:30:17 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Linus Walleij Subject: [PATCH 6/6 v2] mmc: queue: delete mmc_req_is_special() Date: Thu, 18 May 2017 11:29:36 +0200 Message-Id: <20170518092936.9277-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170518092936.9277-1-linus.walleij@linaro.org> References: <20170518092936.9277-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org commit cdf8a6fb48882651049e468e6b16956fb83db86c "mmc: block: Introduce queue semantics" deleted the last user of mmc_req_is_special() and it was a horrible hack to classify requests as "special" or "not special" to begin with, so delete the helper. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - No changes, just include this patch with in my series. --- drivers/mmc/core/queue.h | 8 -------- 1 file changed, 8 deletions(-) -- 2.9.3 -- 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/queue.h b/drivers/mmc/core/queue.h index 8c76e7118c95..dfe481a8b5ed 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -12,14 +12,6 @@ static inline struct mmc_queue_req *req_to_mmc_queue_req(struct request *rq) return blk_mq_rq_to_pdu(rq); } -static inline bool mmc_req_is_special(struct request *req) -{ - return req && - (req_op(req) == REQ_OP_FLUSH || - req_op(req) == REQ_OP_DISCARD || - req_op(req) == REQ_OP_SECURE_ERASE); -} - struct task_struct; struct mmc_blk_data; struct mmc_blk_ioc_data;