Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3519895pxf; Mon, 15 Mar 2021 11:22:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNK0PgS0ieARLAL+BFfdM67Tr4fodzs8YzycPiWTyYLoUmsSqDkCYqGlVwvs9SGpAFqloS X-Received: by 2002:a17:906:801:: with SMTP id e1mr24552026ejd.465.1615832527828; Mon, 15 Mar 2021 11:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832527; cv=none; d=google.com; s=arc-20160816; b=xx8G8saCZzUQuaYf99IumBAnx8W+n4KM9VTrzDYuiB/YHWjIwcCMx4zm/1zZUAslSe qO5oBhLkRSxq94GuYA4iBr50/vdfIitazj9BsKW+EJ2TEiSEVdQjrLmkTvnn7n8mUsAO maGN9uYnzdxfFGDwRPdS8crU9bAnt6j9Una1RnwQxeTPeusEXUS3Khd4zmHXvIGA/V3f mRxwgqyN+G/Ub4mvh+44sEabyS4j10wXxhGdojgC3c9/kkUVgDkYcnM/A0zRRWQzDGf+ D6mwv23SK/SPR7VQWNuTFK+5LmntCkRCL3uIahAtbNigrT8Z5v4kc+mmUuGwc7ZIzTx1 prlQ== 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=sCNnJlZcECKUmIoiYCYzmpC9SYz+ex6DmI23M8NOsU0=; b=ZbalK4vmZtmpw02IbV1wkmUr5p/rxgD7IAw0XdCNO4RobIuDRf7S59g56NImGHBfhM YW7L8vfZBJU6XrxRFNUZYMHHjDAtPnJsnZNtr10mKXwYLDidHFoHNntuySeyKA9tvGUo U0b+VkCRmLiXFBD4effmll5Q5MBQ8bGF153mxEqHrM68Y5LK7ZMm3odJTuMN1TnrXceW f0ddfPyB2K91pvcrdK41fYK4f2/VJrhBw8CrCLu5QZJul4LxB1umJDrPaeyke3ALs2OP 1grltnKw/OhSh/Oer94LDRE7oKaJ7i8oDHNYunpTbw+JoZWN10LfyLSpB4FuIAXkgzwp nDdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H9LFueYV; 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 d5si11261734edr.381.2021.03.15.11.21.45; Mon, 15 Mar 2021 11:22:07 -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=H9LFueYV; 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 S229805AbhCOOVK (ORCPT + 99 others); Mon, 15 Mar 2021 10:21:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232790AbhCON74 (ORCPT ); Mon, 15 Mar 2021 09:59:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 598C464F0C; Mon, 15 Mar 2021 13:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816777; bh=pzoWsmL7VIyHDrq2fn/nkEgzivR3lET1aNWpEzDK7mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H9LFueYVXGEIz53SEUmuelu7aAc+tJm7PQR+2gGqKncuI3fM0h+4IgShpl8t6CrTz A0Occ7jONzVwMIOpndzrpTTrTe/HGhhqcN2GoC0HaUmBfSLPJvL62e0s4X/mm+sGok QZBhnKZ3GfVDGyfA/ln4u+Gf+JE4DPL9PYiGOQD0= 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 5.4 102/168] mmc: cqhci: Fix random crash when remove mmc module/card Date: Mon, 15 Mar 2021 14:55:34 +0100 Message-Id: <20210315135553.724688511@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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 @@ -373,11 +373,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", @@ -390,6 +385,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); } -