Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp509760pxb; Thu, 9 Sep 2021 06:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaDXZa8NrT6Za6gkwf6cgQRO5g4cl9vO/PFfkTacWz7C8NygIEwn3DH9PlUjFMuwpuXSlE X-Received: by 2002:a05:6602:117:: with SMTP id s23mr2654000iot.124.1631192921191; Thu, 09 Sep 2021 06:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631192921; cv=none; d=google.com; s=arc-20160816; b=eE5HwJzlqQ3St5eFhozz6tAi9sizVMCxZxFUF5QSC0k08SuAkJ1bYgZ1YwzpzX4n47 2sYXcXidi1BOeQvf/55UpnwDcbsBV3iU6xREYIlrw4qOvFMems2+1StK0e063ziTxC9h EMY1nbnonLqjpWhWVhbsBbJSI68h8vJoRiSl+T2kn3cTBVB5Tstqnq22JRGPYvQcUdwq ZVsG5Yjr9gehbokH09YxH48VbioO6KlQxOMt2X9UAv0690lW4F5/qjpU1YCfogUKHtoY GEJ7cZN02hmg2+WPuQIWkr7PCrjXzyzUSW5za+3+3zWJAA6sHE5BYblpmGz+gO2L3fsv fXHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=usk4VQsEpU6YWfdM6AHG+pPWAYWL+zR+NRfFWbiBdBU=; b=ySKjj1iA4xvkC14D47jhN5J1wdPHp8M73Fc9QYkc+db+C2hkRgKPcpX7aMpHi11e75 L7e6CFYCnd7ybSsMS926G7ogtumHCJ3NkEa/B7+FpgGxDK0qWQEzBM+XhEhAvV2LeSjI hgsofr8ib5kKPPU+Hazgdj8iklIC/ZcM0sOJKQQwf75vfCxwPKltUZv+1gs/UL3mIvoO Bb0Z1iAaGWgpXxs9KPAJvy5CbuQ39kKGg7y3AQoftFw9lYkfPh7Fw9R6u9twqGQUMhjY KMwyJcH39ihyrPR2K0PHmKHK0DFnhLvE80hef8EQh/VtaGwJRVt7imi7ZSzj7CrA2gWj 2zVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y4Dfg9+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i18si1846074jan.99.2021.09.09.06.08.17; Thu, 09 Sep 2021 06:08:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y4Dfg9+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358468AbhIINH3 (ORCPT + 99 others); Thu, 9 Sep 2021 09:07:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:46028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354385AbhIIMvK (ORCPT ); Thu, 9 Sep 2021 08:51:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3BEB3630EC; Thu, 9 Sep 2021 11:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188623; bh=MNDJKkMWKeuUgMR/lKQ0034otoLWBNEIf4WXmOHLp1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y4Dfg9+kA9yt0so/Ia3c4RTHM79Oo+JOycNHtdhrySQlgR0K+jtHX4zerIvQqvgOp eaK07dJNrGSKOxLcPuDdiTDbpetAMjsSZC0E8GBkDOZ+vawiJbbo6xlsHCRlgK6ARw NKPmcq7wuXsZmdGXe3nuT5Y/YUGetp2tbCB6ykGza46gXga2wjFp0SLjj97eYWbJ7a c4XJ82GtwzX+AaRe/eoGtec8s8vp7BtI7fD396VCfsUYyaR9dtc5mBPEqVBNaSFMFo n2H1ViZFD+PqOs3ZMqXtroXV+nkPvKIAKShpqRWbDKuP1cc5SU2W9Sot77JeF+Tmsa lPS96+aERpv2w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nishad Kamdar , Avri Altman , Ulf Hansson , Sasha Levin , linux-mmc@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 091/109] mmc: core: Return correct emmc response in case of ioctl error Date: Thu, 9 Sep 2021 07:54:48 -0400 Message-Id: <20210909115507.147917-91-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115507.147917-1-sashal@kernel.org> References: <20210909115507.147917-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nishad Kamdar [ Upstream commit e72a55f2e5ddcfb3dce0701caf925ce435b87682 ] When a read/write command is sent via ioctl to the kernel, and the command fails, the actual error response of the emmc is not sent to the user. IOCTL read/write tests are carried out using commands 17 (Single BLock Read), 24 (Single Block Write), 18 (Multi Block Read), 25 (Multi Block Write) The tests are carried out on a 64Gb emmc device. All of these tests try to access an "out of range" sector address (0x09B2FFFF). It is seen that without the patch the response received by the user is not OUT_OF_RANGE error (R1 response 31st bit is not set) as per JEDEC specification. After applying the patch proper response is seen. This is because the function returns without copying the response to the user in case of failure. This patch fixes the issue. Hence, this memcpy is required whether we get an error response or not. Therefor it is moved up from the current position up to immediately after we have called mmc_wait_for_req(). The test code and the output of only the CMD17 is included in the commit to limit the message length. CMD17 (Test Code Snippet): ========================== printf("Forming CMD%d\n", opt_idx); /* single block read */ cmd.blksz = 512; cmd.blocks = 1; cmd.write_flag = 0; cmd.opcode = 17; //cmd.arg = atoi(argv[3]); cmd.arg = 0x09B2FFFF; /* Expecting response R1B */ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; memset(data, 0, sizeof(__u8) * 512); mmc_ioc_cmd_set_data(cmd, data); printf("Sending CMD%d: ARG[0x%08x]\n", opt_idx, cmd.arg); if(ioctl(fd, MMC_IOC_CMD, &cmd)) perror("Error"); printf("\nResponse: %08x\n", cmd.response[0]); CMD17 (Output without patch): ============================= test@test-LIVA-Z:~$ sudo ./mmc cmd_test /dev/mmcblk0 17 Entering the do_mmc_commands:Device: /dev/mmcblk0 nargs:4 Entering the do_mmc_commands:Device: /dev/mmcblk0 options[17, 0x09B2FFF] Forming CMD17 Sending CMD17: ARG[0x09b2ffff] Error: Connection timed out Response: 00000000 (Incorrect response) CMD17 (Output with patch): ========================== test@test-LIVA-Z:~$ sudo ./mmc cmd_test /dev/mmcblk0 17 [sudo] password for test: Entering the do_mmc_commands:Device: /dev/mmcblk0 nargs:4 Entering the do_mmc_commands:Device: /dev/mmcblk0 options[17, 09B2FFFF] Forming CMD17 Sending CMD17: ARG[0x09b2ffff] Error: Connection timed out Response: 80000900 (Correct OUT_OF_ERROR response as per JEDEC specification) Signed-off-by: Nishad Kamdar Reviewed-by: Avri Altman Link: https://lore.kernel.org/r/20210824191726.8296-1-nishadkamdar@gmail.com Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/core/block.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 8322d22a59c4..e92f9373e227 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -591,6 +591,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, } mmc_wait_for_req(card->host, &mrq); + memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp)); if (cmd.error) { dev_err(mmc_dev(card->host), "%s: cmd error %d\n", @@ -640,8 +641,6 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, if (idata->ic.postsleep_min_us) usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us); - memcpy(&(idata->ic.response), cmd.resp, sizeof(cmd.resp)); - if (idata->rpmb || (cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) { /* * Ensure RPMB/R1B command has completed by polling CMD13 -- 2.30.2