From patchwork Thu Dec 19 18:33:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 182180 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp874359iln; Thu, 19 Dec 2019 10:58:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyCZfeasYQqTjolHkpG47HonrQXmlwIfZbiBruaTxZ0zIWC0mVc9nmOjONhtcPsRJ6+MEIS X-Received: by 2002:a9d:73ca:: with SMTP id m10mr10251953otk.289.1576781915968; Thu, 19 Dec 2019 10:58:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781915; cv=none; d=google.com; s=arc-20160816; b=QQAEnO645PIt9YEdDyFefcwBGqOqiyjLl8WQLR6YiZHUFblb/8Sl5XwxRMP1wz64qd rdpmf8i3qEstkuJbqH/K9wSh2Dgqkx8lzXecS5mIZ1m8+Y3Re4eCo70JpVlJfv5wnMna XgbFSZddfV3Tfwiix6hyFavcBcQJT5qaNyqZdi1dTZl6uH1TVVdpvlt1/R506+Ii53v8 3mK+dMINJnDB+W+Rsd1Kk1Ef4YPEJSkHPtZ0uK2KHRMfXfhu5OEE5KbNLTohBvgIJdlp Ult7UR0yDtgy2iOvPAytC8WCwVvhCALtQ5kV9hYFgz1aloUsLH6VZ/dOgN96geHRBz/M kRZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YBdpSbblwCs/ZDeCVtuCVZ8oRM+y/qhNj8MraIHMXCU=; b=ovIJ0kzcvvXawyvY02mokjX+HqjMQiBgF+sl0ZWcd4R+p3baihW1BSQynVpu+at0Hl 7KZqcDBwNB+/CRcvLQRuXdi79BLsjGwa2MLVd8ljsxZEQctEElrs65XbzZBnA+cpsNRJ AQgy/xVAUBxu7sGPSa7Dx/rpjEqu8KR/2defKZqED9wQNVHezdJf3IlpXR5I3piTYyLo 3Qp4upqHbsGde0IqV/VTh43HmyUyyGEvLYFSNVzmGiMkSxYDoFFiRHcu5fPekKL0k8ub 835Yhwlqa5aHgF+33vRNRZplEspGoKqZ7DPt9bLAdmhqwIyDrU6yPaiIykaI5SRzsZht a6UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=piQs8L6R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si3692204otq.35.2019.12.19.10.58.35; Thu, 19 Dec 2019 10:58:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=piQs8L6R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730525AbfLSSyg (ORCPT + 27 others); Thu, 19 Dec 2019 13:54:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:50054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729431AbfLSSyd (ORCPT ); Thu, 19 Dec 2019 13:54:33 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 93843227BF; Thu, 19 Dec 2019 18:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781673; bh=1cRpwCqdems5pgPypXH00pHUKyYW+gGiZGNNdSfvfJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=piQs8L6R/oOwRHt4K1ZKtyyirKduH/wAiT0NBxHYqByKvZsYVhuXE/qo1I//XbY+q 6BPEq7M9iL2nZ/l9oB8mwLhB3EFqbttGIESenRjnxMuWEoiT9jLQLhv2MHaRWWJWJd F8EuMy40bt2O/gYIUpK4thJkkKw1QqYZGav0kq40= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Douglas Anderson , Ulf Hansson Subject: [PATCH 5.4 04/80] mmc: core: Drop check for mmc_card_is_removable() in mmc_rescan() Date: Thu, 19 Dec 2019 19:33:56 +0100 Message-Id: <20191219183034.205788544@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ulf Hansson commit 99b4ddd8b76a6f60a8c2b3775849d65d21a418fc upstream. Upfront in mmc_rescan() we use the host->rescan_entered flag, to allow scanning only once for non-removable cards. Therefore, it's also not possible that we can have a corresponding card bus attached (host->bus_ops is NULL), when we are scanning non-removable cards. For this reason, let' drop the check for mmc_card_is_removable() as it's redundant. Reviewed-by: Douglas Anderson Tested-by: Douglas Anderson Cc: stable@vger.kernel.org # v5.4+ Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2297,11 +2297,8 @@ void mmc_rescan(struct work_struct *work mmc_bus_get(host); - /* - * if there is a _removable_ card registered, check whether it is - * still present - */ - if (host->bus_ops && !host->bus_dead && mmc_card_is_removable(host)) + /* Verify a registered card to be functional, else remove it. */ + if (host->bus_ops && !host->bus_dead) host->bus_ops->detect(host); host->detect_change = 0; From patchwork Thu Dec 19 18:33:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 182179 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp874332iln; Thu, 19 Dec 2019 10:58:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxK8SEPTraPYNAo7zMpwMN+h2DXyvCpVT9wvTvckGcrCWvWo4hjQEDfCLPL5L5skwfI1Yav X-Received: by 2002:a05:6830:1c89:: with SMTP id v9mr2995338otf.232.1576781914971; Thu, 19 Dec 2019 10:58:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781914; cv=none; d=google.com; s=arc-20160816; b=TxO/rLwK7ym+mlztlk0D51vGiU3vNqU88gaEQgyRFZEmAXdPR2mHQsFsWRsCfDUwkJ QoswQMk/fSHBZwt75WFIum2Bd7pVGsqlFs40IcPoU0MeNfRkVeIhivcOEJFZJDjQyxIm ylsPIy4a2W887CsO0Csu+Rz258Xndu25pTkT5arkiGhEuGbdMSRIvrW5QNVq2C67rYRS h3E6AMnD2Oo5vm6ZVLkYOYIJBlBAAblpvTrmI8wX7FPBNJGyrTpOj1KfL1GBVgqREfQi SKnwiiyy/Zl1JLlQ7y6Z2Rt6UAdEgrPguM8w3zC4sDjUzWLWKZ6bhq1oYasnmtK2u9xa C9ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5zyRqrvz/jJ3HOv8uzr3XidryoCuCJYmHaPoRuSB/6s=; b=E5fAH9+cNyIAMP3jja8Zp7VoXfR/5bro2W1T7ob4zaFW2svmLc2u0Mq6IIWmKqsBL/ W2pnYLRf3Z11fJdkhiBftGbZoHNCfn1Nmedy5F5tAWarswPjjnp/HE+2oWnV3gKkaMAH zxn6Vx5uzvWcOrstfUFULT+JMGzdxIHNflxgrJPvu9Th87N17Au835Kk1ui80GriOHUf QfKTgoalPjjLwiZ29tCDR3g8ItA1tAVWOM7J+hqxK5Vv8Xgm27z2X/g7xG3LN7a4Rqxh kvnbmKxolncWSYITOs+td9dTwVovggm45rHs3p2/MeAWpc4fNR4tx6uSPONtslznGTu2 9Jng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2XlCL8x7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si3822829otk.226.2019.12.19.10.58.34; Thu, 19 Dec 2019 10:58:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2XlCL8x7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730533AbfLSSyj (ORCPT + 27 others); Thu, 19 Dec 2019 13:54:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:50114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730521AbfLSSyg (ORCPT ); Thu, 19 Dec 2019 13:54:36 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07DF9206EC; Thu, 19 Dec 2019 18:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781675; bh=3ES9370mW67huKRscDNwlyDxGs8a4q6eF+E6RqcTyrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2XlCL8x7IFq49zl/+HVAk8PKirimZTIWJk9bceNBc/+WUR4dp1FCePKAH26hcBRCA LmO+akUWm2Z9A/v0D7n/nyYGvbcsh10anuqlWJK0Ma5OkoIlObsneOOA1B1N9SYlPF vyO25S8n+O5SKMGYpTS3ZKWRAxtTLvYusrJC3h0I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Douglas Anderson , Ulf Hansson Subject: [PATCH 5.4 05/80] mmc: core: Re-work HW reset for SDIO cards Date: Thu, 19 Dec 2019 19:33:57 +0100 Message-Id: <20191219183034.971092272@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ulf Hansson commit 2ac55d5e5ec9ad0a07e194f0eaca865fe5aa3c40 upstream. It have turned out that it's not a good idea to unconditionally do a power cycle and then to re-initialize the SDIO card, as currently done through mmc_hw_reset() -> mmc_sdio_hw_reset(). This because there may be multiple SDIO func drivers probed, who also shares the same SDIO card. To address these scenarios, one may be tempted to use a notification mechanism, as to allow the core to inform each of the probed func drivers, about an ongoing HW reset. However, supporting such an operation from the func driver point of view, may not be entirely trivial. Therefore, let's use a more simplistic approach to solve the problem, by instead forcing the card to be removed and re-detected, via scheduling a rescan-work. In this way, we can rely on existing infrastructure, as the func driver's ->remove() and ->probe() callbacks, becomes invoked to deal with the cleanup and the re-initialization. This solution may be considered as rather heavy, especially if a func driver doesn't share its card with other func drivers. To address this, let's keep the current immediate HW reset option as well, but run it only when there is one func driver probed for the card. Finally, to allow the caller of mmc_hw_reset(), to understand if the reset is being asynchronously managed from a scheduled work, it returns 1 (propagated from mmc_sdio_hw_reset()). If the HW reset is executed successfully and synchronously it returns 0, which maintains the existing behaviour. Reviewed-by: Douglas Anderson Tested-by: Douglas Anderson Cc: stable@vger.kernel.org # v5.4+ Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/core.c | 5 ++--- drivers/mmc/core/core.h | 2 ++ drivers/mmc/core/sdio.c | 28 +++++++++++++++++++++++++++- drivers/mmc/core/sdio_bus.c | 9 ++++++++- include/linux/mmc/card.h | 1 + 5 files changed, 40 insertions(+), 5 deletions(-) --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1469,8 +1469,7 @@ void mmc_detach_bus(struct mmc_host *hos mmc_bus_put(host); } -static void _mmc_detect_change(struct mmc_host *host, unsigned long delay, - bool cd_irq) +void _mmc_detect_change(struct mmc_host *host, unsigned long delay, bool cd_irq) { /* * If the device is configured as wakeup, we prevent a new sleep for @@ -2129,7 +2128,7 @@ int mmc_hw_reset(struct mmc_host *host) ret = host->bus_ops->hw_reset(host); mmc_bus_put(host); - if (ret) + if (ret < 0) pr_warn("%s: tried to HW reset card, got error %d\n", mmc_hostname(host), ret); --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -70,6 +70,8 @@ void mmc_rescan(struct work_struct *work void mmc_start_host(struct mmc_host *host); void mmc_stop_host(struct mmc_host *host); +void _mmc_detect_change(struct mmc_host *host, unsigned long delay, + bool cd_irq); int _mmc_detect_card_removed(struct mmc_host *host); int mmc_detect_card_removed(struct mmc_host *host); --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -1048,9 +1048,35 @@ static int mmc_sdio_runtime_resume(struc return ret; } +/* + * SDIO HW reset + * + * Returns 0 if the HW reset was executed synchronously, returns 1 if the HW + * reset was asynchronously scheduled, else a negative error code. + */ static int mmc_sdio_hw_reset(struct mmc_host *host) { - mmc_power_cycle(host, host->card->ocr); + struct mmc_card *card = host->card; + + /* + * In case the card is shared among multiple func drivers, reset the + * card through a rescan work. In this way it will be removed and + * re-detected, thus all func drivers becomes informed about it. + */ + if (atomic_read(&card->sdio_funcs_probed) > 1) { + if (mmc_card_removed(card)) + return 1; + host->rescan_entered = 0; + mmc_card_set_removed(card); + _mmc_detect_change(host, 0, false); + return 1; + } + + /* + * A single func driver has been probed, then let's skip the heavy + * hotplug dance above and execute the reset immediately. + */ + mmc_power_cycle(host, card->ocr); return mmc_sdio_reinit_card(host); } --- a/drivers/mmc/core/sdio_bus.c +++ b/drivers/mmc/core/sdio_bus.c @@ -138,6 +138,8 @@ static int sdio_bus_probe(struct device if (ret) return ret; + atomic_inc(&func->card->sdio_funcs_probed); + /* Unbound SDIO functions are always suspended. * During probe, the function is set active and the usage count * is incremented. If the driver supports runtime PM, @@ -153,7 +155,10 @@ static int sdio_bus_probe(struct device /* Set the default block size so the driver is sure it's something * sensible. */ sdio_claim_host(func); - ret = sdio_set_block_size(func, 0); + if (mmc_card_removed(func->card)) + ret = -ENOMEDIUM; + else + ret = sdio_set_block_size(func, 0); sdio_release_host(func); if (ret) goto disable_runtimepm; @@ -165,6 +170,7 @@ static int sdio_bus_probe(struct device return 0; disable_runtimepm: + atomic_dec(&func->card->sdio_funcs_probed); if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD) pm_runtime_put_noidle(dev); dev_pm_domain_detach(dev, false); @@ -181,6 +187,7 @@ static int sdio_bus_remove(struct device pm_runtime_get_sync(dev); drv->remove(func); + atomic_dec(&func->card->sdio_funcs_probed); if (func->irq_handler) { pr_warn("WARNING: driver %s did not remove its interrupt handler!\n", --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -291,6 +291,7 @@ struct mmc_card { struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ unsigned int sdio_funcs; /* number of SDIO functions */ + atomic_t sdio_funcs_probed; /* number of probed SDIO funcs */ struct sdio_cccr cccr; /* common card info */ struct sdio_cis cis; /* common tuple info */ struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */ From patchwork Thu Dec 19 18:34:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 182177 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp869629iln; Thu, 19 Dec 2019 10:54:21 -0800 (PST) X-Google-Smtp-Source: APXvYqzjLujpNZI8zXMPuWMGxRPOWTfcQ2E2LnmX3warTgcXHV+tdZj7t3mqEkHa8A3M7hV6pjT8 X-Received: by 2002:a05:6830:18e9:: with SMTP id d9mr1931998otf.332.1576781661382; Thu, 19 Dec 2019 10:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781661; cv=none; d=google.com; s=arc-20160816; b=Y3MCa20bFSNqHQMjpKPbaUc0XnXk0gfe7geEKahRY+67Y16U8F6yyPvfMFqBaq1HMm Mbr401rPUKye7rZWuqOW8Y5g2dAoSAjBFgqHn+j5xZWH5TlfuTVobSuWBfuTiTW8pXYc 78pj8ZZh3UEizdu0KV8UzwGokcf3yI1xniNvhrGhOfogT9jD4IrHJfJd1reJPtdBum7D ACKAwSuaJ5TYdUmUV7aQfPzZobceVLQgkAerVEJ70nxm7gY4kVxOSRoWyHjNmUU7+0Wy 6vmRS5s0CIRVw/FA13AUCDjsjB4j33kRErx5kgSN6/4LGcigEVP5+WpDJim2PgAbpEQJ OP6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rIqZHnhWEMzZH49nTKxn6kMeINUi/gPMcn4u+mUJEHs=; b=t4RBjI1k3+N8t0dQTeW+5tch6DOsXRO0C5eEU1UV6MtYOy6fXDPMNdYoUQEUMb9rLC VBpAgpmPFStfbhdSOmgt0ipoRHf0631mzFQlr3fOi+N76My5zXKlI5sNI1lQq8Utxd9j ji0cm69HZos4vmit1pxRrdn8vjmRo+nQe+SzyUEmhvVZQeOWLpgVhizF0ADk756tedQJ 9V5igJhjjatIqdxxnVlpugV01kBrP7n9CqzyRjijXR5Od+Dj91E43DmVMh0Ct5v8amrq nekC1p7JKGSDNE7PR1iqxF1vz4ENMImJCKkEkh9l9hcfyjNlm9U+axONF4Tg0m/7pHN0 xMLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JqcjvyeY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si3615561otr.64.2019.12.19.10.54.21; Thu, 19 Dec 2019 10:54:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JqcjvyeY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730491AbfLSSyT (ORCPT + 27 others); Thu, 19 Dec 2019 13:54:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:49668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730312AbfLSSyR (ORCPT ); Thu, 19 Dec 2019 13:54:17 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7548222C2; Thu, 19 Dec 2019 18:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781656; bh=axVM7PxtCOj1DqmmtjY6K5VnsVEfJD0vyDPh5EF9+2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JqcjvyeYsbQ895h0SbhFRB5DBuThKUPEA4ZA4fa1IyIwwb79aS1Fhl+mzA0zzXdJi vKwNWBNW70SWmX86OneTcjDJ63iNQGf9Pm4YKKHhVkbMf9en4Z4vdBHj/oPENuEwX6 3oErKXkfik0dzIwbZEMADlqhaf400IVdMYFsp/RQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Lew , Srinivas Kandagatla , Bjorn Andersson Subject: [PATCH 5.4 26/80] rpmsg: glink: Dont send pending rx_done during remove Date: Thu, 19 Dec 2019 19:34:18 +0100 Message-Id: <20191219183102.757924777@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bjorn Andersson commit c3dadc19b7564c732598b30d637c6f275c3b77b6 upstream. Attempting to transmit rx_done messages after the GLINK instance is being torn down will cause use after free and memory leaks. So cancel the intent_work and free up the pending intents. With this there are no concurrent accessors of the channel left during qcom_glink_native_remove() and there is therefor no need to hold the spinlock during this operation - which would prohibit the use of cancel_work_sync() in the release function. So remove this. Fixes: 1d2ea36eead9 ("rpmsg: glink: Add rx done command") Cc: stable@vger.kernel.org Acked-by: Chris Lew Tested-by: Srinivas Kandagatla Signed-off-by: Bjorn Andersson Signed-off-by: Greg Kroah-Hartman --- drivers/rpmsg/qcom_glink_native.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -241,11 +241,23 @@ static void qcom_glink_channel_release(s { struct glink_channel *channel = container_of(ref, struct glink_channel, refcount); + struct glink_core_rx_intent *intent; struct glink_core_rx_intent *tmp; unsigned long flags; int iid; + /* cancel pending rx_done work */ + cancel_work_sync(&channel->intent_work); + spin_lock_irqsave(&channel->intent_lock, flags); + /* Free all non-reuse intents pending rx_done work */ + list_for_each_entry_safe(intent, tmp, &channel->done_intents, node) { + if (!intent->reuse) { + kfree(intent->data); + kfree(intent); + } + } + idr_for_each_entry(&channel->liids, tmp, iid) { kfree(tmp->data); kfree(tmp); @@ -1625,7 +1637,6 @@ void qcom_glink_native_remove(struct qco struct glink_channel *channel; int cid; int ret; - unsigned long flags; disable_irq(glink->irq); cancel_work_sync(&glink->rx_work); @@ -1634,7 +1645,6 @@ void qcom_glink_native_remove(struct qco if (ret) dev_warn(glink->dev, "Can't remove GLINK devices: %d\n", ret); - spin_lock_irqsave(&glink->idr_lock, flags); /* Release any defunct local channels, waiting for close-ack */ idr_for_each_entry(&glink->lcids, channel, cid) kref_put(&channel->refcount, qcom_glink_channel_release); @@ -1645,7 +1655,6 @@ void qcom_glink_native_remove(struct qco idr_destroy(&glink->lcids); idr_destroy(&glink->rcids); - spin_unlock_irqrestore(&glink->idr_lock, flags); mbox_free_channel(glink->mbox_chan); } EXPORT_SYMBOL_GPL(qcom_glink_native_remove);