Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565538lkm; Mon, 20 Sep 2021 18:51:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylUpmE/p/y+Cj3EHef1iW1MfzQpHxiCDhvGYw2aT2g+3KylzBmgbMlaleqNjfdoxXbFU8h X-Received: by 2002:a5d:8d1a:: with SMTP id p26mr21149152ioj.141.1632188996150; Mon, 20 Sep 2021 18:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188996; cv=none; d=google.com; s=arc-20160816; b=gM+vrPnD8VCHOZe4xvQgWQ3RDlbx0pT2q0KIxoHsyjwKQkgPJAzJ6n6UM06UZU7Fwl 2vrm4gw5L8r+u3QF5W9yHR0w/toFfLZCRNISUanqZbpnXa41yslIgH1T5Is2GWRNKt5s 6rmJkAXUpXrxzoPbmuOBiUU2uRxLSC/9hlwY+ZvcZmByDob7YbYwuHo8Hv0KUGU0YVKp oi3NBjrA0BJ2JfelHfP6+5JR85Ab1+3Y2F95QeDQjkr+x2fLVQF6gr1HILOePRcyc4M6 x1pvsbPb31b/6q0H0wx3SOu2FPDEeStgyMZ8GYTnQYnaS8oQ5vyXGlIzISozb52zExpN 4yIw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=95lKQmI0N8+1RDIS2JXZaccyotTqvk1hevMiwG/jgdI=; b=pk3nV4FKNasjiWxdLq7KbFSKlL9Mf8NvtoLgKILH1Idya87zLq9c104BktQcDfeQU9 h0dwca/qQzo0cxB3eoC6E9wtgAtt6VEXRDlRbQoHg0Ot7vHRe86QiM3h1PcMSQEHXZpB +eqvVS0KUMWAnaUAH/shm1QnyaunQbCWFnT9d/UJyDHAey1m8h5178zg+ZLaXHUqMT40 suIA/Ix1fkwCbCfANpyeJjFq3A7RORbS0yk28e1msdvqfUe+VoOFm8zt7nqcjDDf5EBG eQ9o1FUkfenD7Z0vm20JmzrQ96rHlXy4MQMxdOEhRbLfFQXQa6tglJOEikDaoRaQ6RTT yBMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q3PALjab; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si360249ilu.166.2021.09.20.18.49.45; Mon, 20 Sep 2021 18:49:56 -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=@linuxfoundation.org header.s=korg header.b=q3PALjab; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347715AbhITR6O (ORCPT + 99 others); Mon, 20 Sep 2021 13:58:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:54542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354924AbhITRwO (ORCPT ); Mon, 20 Sep 2021 13:52:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DCB2F61BE6; Mon, 20 Sep 2021 17:12:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157955; bh=MkRrwpA1NkbgaRmTQtUIZgPFnFVbhsKD2oo50eySxws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q3PALjabmI6hind4Kf0ngP7WzJXa+MPcoG1Fnchecci3ZLGa3npLnvoUH3bCL26di jLFEwd/ELakFbYHsesNhiNeXd7/u/rGmVsDaxgcm0CE9pRAUFpTfnt5/G8ltLikKX5 +6LUUBlpQE/J8OIt2GBKUPQrj25H+QZ0Hcevqt3Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nishad Kamdar , Avri Altman , Ulf Hansson , Sasha Levin Subject: [PATCH 4.19 228/293] mmc: core: Return correct emmc response in case of ioctl error Date: Mon, 20 Sep 2021 18:43:10 +0200 Message-Id: <20210920163941.195926479@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 7b2bb32e3555..d1cc0fdbc51c 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -592,6 +592,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", @@ -641,8 +642,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