Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3520264pxf; Mon, 15 Mar 2021 11:22:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfH+I1mtauidJzIabKWmRYXoxGdgjU2ISviIhqdem6Qd1U8ZYaqpRFaZ9lzquARGiab2Wq X-Received: by 2002:a17:906:a155:: with SMTP id bu21mr25207339ejb.400.1615832565700; Mon, 15 Mar 2021 11:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832565; cv=none; d=google.com; s=arc-20160816; b=YL03TKgwCwbFJFUY9Fb4OD1fUxfJ3Pm26m7SGj17DIXQScBSIYh0lzxRKgRDDIeCyB JBHHh/voG1AciitL5fT1/KCW/drFvcP98KxsD2yM3vOp4lZ4sR42VVyVaFJTInMsGDgx s8i3GrtMmWENJ3+6+PekH5sYmifIqyZt2A/16dubnKZ8rQcLnuCuPG8YmQowbRmF6yKs GgVIAWKnckkdLdAa5nyc5jMXgCg45A4YSCxQrG86lqNAUk1jF7fruTBUbeZ5fnUEdG2j rDSrG9GWAaGUCOuZT7cJbQ6PoyrglDfdozz+iXk7V046c3cwNEHRYIdO6qI75BY/fZ3b MijQ== 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=8ISXefpjuZDO5mFJBKCn3Y+3DK+MP1mMiQuJtD/ToTU=; b=DtuZuNTBtBo7MkzDuWuVvguJUdRlL0cbVg8Xu/3inRmxg3qs1fMjjt9wgCiKyP9gRQ YSAPrq+mtF7HJoGP60CJ6EGUsEFXVuRGsUvJu/QfB7TN/umgDElnJFaz6Jh3lqY8Q0oB j9jKLk+thjjJW4aHCgiY68SBaNYuaJcSZ9rKY1klxBwut5ytVLgYCCLzAzAor4aIeuK/ NtmoJPlG/Jaaq4iOINezzhKvtLUXnrJHqIMPljQ2d4zGK4UEjsv5uP0kn4IrS+yXM55Z fgZBy95Wtpb103CDZ3zc7vHUocXiOBI251bagjXzq8Oxiffbx1cPizVnMfW3qHQ+WL/c eGog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d35BFcnw; 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 bd28si10891416edb.570.2021.03.15.11.22.23; Mon, 15 Mar 2021 11:22:45 -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=d35BFcnw; 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 S233918AbhCOOV4 (ORCPT + 99 others); Mon, 15 Mar 2021 10:21:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231701AbhCOOAG (ORCPT ); Mon, 15 Mar 2021 10:00:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A20964F72; Mon, 15 Mar 2021 13:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816790; bh=HIP0kVB6XTJ9YLvpV/tqOOuYwW3vQoTO8MqPM6KL5C0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d35BFcnw9z/hMh/Vrh86RAv//fmlkW9sBVWOjmBA/no2zusZqA+Gvd+HDuZswh39m GKtF3YsDo3s7EC/lF61+opU6jXoyF1gZqroPuveJ1NrvBnGRRcw4qohZ+AalttzXjL cklbiC/ud9umU+zLH6QsP0Uy0/kT8cBWm9OIgegA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Frank Li , Adrian Hunter , Ulf Hansson Subject: [PATCH 4.19 069/120] mmc: cqhci: Fix random crash when remove mmc module/card Date: Mon, 15 Mar 2021 14:57:00 +0100 Message-Id: <20210315135722.236902589@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135720.002213995@linuxfoundation.org> References: <20210315135720.002213995@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: Greg Kroah-Hartman From: Frank Li commit f06391c45e83f9a731045deb23df7cc3814fd795 upstream. [ 6684.493350] Unable to handle kernel paging request at virtual address ffff800011c5b0f0 [ 6684.498531] mmc0: card 0001 removed [ 6684.501556] Mem abort info: [ 6684.509681] ESR = 0x96000047 [ 6684.512786] EC = 0x25: DABT (current EL), IL = 32 bits [ 6684.518394] SET = 0, FnV = 0 [ 6684.521707] EA = 0, S1PTW = 0 [ 6684.524998] Data abort info: [ 6684.528236] ISV = 0, ISS = 0x00000047 [ 6684.532986] CM = 0, WnR = 1 [ 6684.536129] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000081b22000 [ 6684.543923] [ffff800011c5b0f0] pgd=00000000bffff003, p4d=00000000bffff003, pud=00000000bfffe003, pmd=00000000900e1003, pte=0000000000000000 [ 6684.557915] Internal error: Oops: 96000047 [#1] PREEMPT SMP [ 6684.564240] Modules linked in: sdhci_esdhc_imx(-) sdhci_pltfm sdhci cqhci mmc_block mmc_core fsl_jr_uio caam_jr caamkeyblob_desc caamhash_desc caamalg_desc crypto_engine rng_core authenc libdes crct10dif_ce flexcan can_dev caam error [last unloaded: mmc_core] [ 6684.587281] CPU: 0 PID: 79138 Comm: kworker/0:3H Not tainted 5.10.9-01410-g3ba33182767b-dirty #10 [ 6684.596160] Hardware name: Freescale i.MX8DXL EVK (DT) [ 6684.601320] Workqueue: kblockd blk_mq_run_work_fn [ 6684.606094] pstate: 40000005 (nZcv daif -PAN -UAO -TCO BTYPE=--) [ 6684.612286] pc : cqhci_request+0x148/0x4e8 [cqhci] ^GMessage from syslogd@ at Thu Jan 1 01:51:24 1970 ...[ 6684.617085] lr : cqhci_request+0x314/0x4e8 [cqhci] [ 6684.626734] sp : ffff80001243b9f0 [ 6684.630049] x29: ffff80001243b9f0 x28: ffff00002c3dd000 [ 6684.635367] x27: 0000000000000001 x26: 0000000000000001 [ 6684.640690] x25: ffff00002c451000 x24: 000000000000000f [ 6684.646007] x23: ffff000017e71c80 x22: ffff00002c451000 [ 6684.651326] x21: ffff00002c0f3550 x20: ffff00002c0f3550 [ 6684.656651] x19: ffff000017d46880 x18: ffff00002cea1500 [ 6684.661977] x17: 0000000000000000 x16: 0000000000000000 [ 6684.667294] x15: 000001ee628e3ed1 x14: 0000000000000278 [ 6684.672610] x13: 0000000000000001 x12: 0000000000000001 [ 6684.677927] x11: 0000000000000000 x10: 0000000000000000 [ 6684.683243] x9 : 000000000000002b x8 : 0000000000001000 [ 6684.688560] x7 : 0000000000000010 x6 : ffff00002c0f3678 [ 6684.693886] x5 : 000000000000000f x4 : ffff800011c5b000 [ 6684.699211] x3 : 000000000002d988 x2 : 0000000000000008 [ 6684.704537] x1 : 00000000000000f0 x0 : 0002d9880008102f [ 6684.709854] Call trace: [ 6684.712313] cqhci_request+0x148/0x4e8 [cqhci] [ 6684.716803] mmc_cqe_start_req+0x58/0x68 [mmc_core] [ 6684.721698] mmc_blk_mq_issue_rq+0x460/0x810 [mmc_block] [ 6684.727018] mmc_mq_queue_rq+0x118/0x2b0 [mmc_block] The problem occurs when cqhci_request() get called after cqhci_disable() as it leads to access of allocated memory that has already been freed. Let's fix the problem by calling cqhci_disable() a bit later in the remove path. Signed-off-by: Frank Li Diagnosed-by: Adrian Hunter Acked-by: Adrian Hunter Link: https://lore.kernel.org/r/20210303174248.542175-1-Frank.Li@nxp.com Fixes: f690f4409ddd ("mmc: mmc: Enable CQE's") Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/bus.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -376,11 +376,6 @@ void mmc_remove_card(struct mmc_card *ca mmc_remove_card_debugfs(card); #endif - if (host->cqe_enabled) { - host->cqe_ops->cqe_disable(host); - host->cqe_enabled = false; - } - if (mmc_card_present(card)) { if (mmc_host_is_spi(card->host)) { pr_info("%s: SPI card removed\n", @@ -393,6 +388,10 @@ void mmc_remove_card(struct mmc_card *ca of_node_put(card->dev.of_node); } + if (host->cqe_enabled) { + host->cqe_ops->cqe_disable(host); + host->cqe_enabled = false; + } + put_device(&card->dev); } -