Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2456257rbb; Wed, 28 Feb 2024 02:18:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUq4hqjuZ1xWrlabJpFWBlqYoeJVXzy8Vs4E1le+AeryF8wcedK6yTv3v6jlDxsLllykOzaWQ8bnxgy8i+IKz4ElIUr5UI+fdTPlVrzag== X-Google-Smtp-Source: AGHT+IF1jEQ2Db8+ZG9PmK2l6et+mRGYg/ALdhiTrwmOOC32gLS9mlwUl870Iaw7EEh6KylKXLMV X-Received: by 2002:a05:6a21:394a:b0:1a0:5841:669d with SMTP id ac10-20020a056a21394a00b001a05841669dmr5703478pzc.39.1709115539733; Wed, 28 Feb 2024 02:18:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709115539; cv=pass; d=google.com; s=arc-20160816; b=iCEI1OHxTfZkrizbMNo3P1K2Oll/U9Hed67Ra0H+pMyh26K5jZRGi2iurdgiS+9+ny MqqT9aQzNyaLG6Tz4IRd8ACzisNZjZ0B5gt4UZL9JQ7EF8gQELwV2vB4JFDrqmkIZNID Qe+Ud8Ilv1eroI15T6x/rG2pNoeHkAwYyUtx9oNw3zqZY1B2SMOcR03Euj8b4lp8RpiG xcNmVSGAmjZ41okPtdCCcfHZL1NyO2WZxz063P7x7GBSLIGG2pEURHLYp4OSf1lFvSl9 3Mw8rXkL/VLk6toZrqYZQ4BWN2UXKoFlBWbnjUQd+i2OxJ++f6gWXmwWyJKsYySGIOrQ Ehuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=rDq91xwkdeBq+poVwEnDTvivychr45vA3bZxWuSbk7g=; fh=TxzlyfPjoNzZ3gH2FNqg89sqlQrfZoexDuM7GS8b4xU=; b=F2r6KT8uj8oZNdFn42G4X5xfpbBhi7Hi/8zIMhvhq17U/HByOqPnTIJSnEaihumCpB zdD1tj3bGXpKnnVhyoZcxpK3jRHjihsa/ocXj9bpqFYwqXWBHxEXfS89DrIOL3gKFTYV sn7Oh2zFNFVOHSzZMxY/kDSfdqljbV30chHGRDzcmCEkvcCynkfeIJIKedtTj3GFBH6U /HOYv7MpsSBRBfAPC0W/PJHnHs+bKVdo3G28wEOAzO0nAlGdJZ/R7QsQ3KrGm+b2Cfap JoYWpJaBDDF0blFJAbTqcEoX4MLdyIzRX15TWmmPuGH6MAdu0qcst7gixjCsKdN2sGIC ILsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sang-engineering.com header.s=k1 header.b=N7XJfSGv; arc=pass (i=1 spf=pass spfdomain=sang-engineering.com dkim=pass dkdomain=sang-engineering.com); spf=pass (google.com: domain of linux-kernel+bounces-84807-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84807-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id g30-20020a63565e000000b005dc8a17167csi7032326pgm.529.2024.02.28.02.18.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 02:18:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84807-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@sang-engineering.com header.s=k1 header.b=N7XJfSGv; arc=pass (i=1 spf=pass spfdomain=sang-engineering.com dkim=pass dkdomain=sang-engineering.com); spf=pass (google.com: domain of linux-kernel+bounces-84807-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84807-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5E993B26026 for ; Wed, 28 Feb 2024 10:04:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A6C737171; Wed, 28 Feb 2024 10:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="N7XJfSGv" Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AAF5364C0 for ; Wed, 28 Feb 2024 10:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709114648; cv=none; b=fuEk5RJf0sujxtbDCd8QGCZrobIBo0yK5fswBtTzbzSN0hdadBSdUPJ4aImIT5bjDQmS2mUxqJyB5hSvocJoHOMlxM/cscrGXgoV5Dht4GM1NNRStnjJW4sH2NSCrLSqYQ01XopvApbQX2cix1EE+8lkSl8Zv/C8zRAG01Ls2IU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709114648; c=relaxed/simple; bh=KQzzUhLT/q9KbVtq8OAn3e60tMLMhyaDIKLmaNMeNN4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bwqVF+Vp7wHyIahQgsKKi/P8VrAYd6JHNXM9vJLvqdnkNYRKP1KwnMk3ojl/uXKfCcpC+FLgvl8SFd2pywyo/BrgBQfAzQqEQXHIViHB7ZoWipYCP3dO7x4yzg9WCCD8r3nZKTEUY5O3VHhQRVReUkQoeniZHyaZUmjLmNVNgkQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=N7XJfSGv; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=k1; bh=rDq91xwkdeBq+p oVwEnDTvivychr45vA3bZxWuSbk7g=; b=N7XJfSGvkmJmWbKxaWscPZOpHc4+QO 6D3dbNNONjAyvRDPFam8H2yUdSC4/afPOW0KWMmYfX9wEc+E7wnIvyNRlrWzWxZb wytxOaen9+3EeuLvKwkhGfgzivPanwwU0IKmZVbwkvWrBo/+tmPTuQ6671MxFn8S mbC3nPZqN+HBy/vW+9EfSmn1+y2sgoDwSSnfJ8WPTQ2CotaHbbWuO14LWRGRk5cQ Pdd3y5Qpqlvk5LgJYrVsl5tvApAkhjDYyJrysnDn+GowpscN+Y6Ts2VpY/jgwqKl M5xdYJw747B/9HN/Vx3M8l97pUBPfslRtdgCitq/CWI8olUTGqHKQ9zQ== Received: (qmail 1906275 invoked from network); 28 Feb 2024 11:04:02 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 28 Feb 2024 11:04:02 +0100 X-UD-Smtp-Session: l3s3148p1@nlEfQ24SbIMgAwDPXyvUACsbJ+4rxOVH From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Dirk Behme , Ulf Hansson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFT] mmc: tmio: avoid concurrent runs of mmc_request_done() Date: Wed, 28 Feb 2024 11:03:45 +0100 Message-ID: <20240228100354.3285-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit With the to-be-fixed commit, the reset_work handler cleared 'host->mrq' outside of the spinlock protected critical section. That leaves a small race window during execution of 'tmio_mmc_reset()' where the done_work handler could grab a pointer to the now invalid 'host->mrq'. Both would use it to call mmc_request_done() causing problems (see Link). However, 'host->mrq' cannot simply be cleared earlier inside the critical section. That would allow new mrqs to come in asynchronously while the actual reset of the controller still needs to be done. So, like 'tmio_mmc_set_ios()', an ERR_PTR is used to prevent new mrqs from coming in but still avoiding concurrency between work handlers. Reported-by: Dirk Behme Closes: https://lore.kernel.org/all/20240220061356.3001761-1-dirk.behme@de.bosch.com/ Signed-off-by: Wolfram Sang Fixes: df3ef2d3c92c ("mmc: protect the tmio_mmc driver against a theoretical race") --- Dirk: could you get this tested on your affected setups? I am somewhat optimistic that this is already enough. For sure, it is a needed first step. drivers/mmc/host/tmio_mmc_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c index be7f18fd4836..c253d176db69 100644 --- a/drivers/mmc/host/tmio_mmc_core.c +++ b/drivers/mmc/host/tmio_mmc_core.c @@ -259,6 +259,8 @@ static void tmio_mmc_reset_work(struct work_struct *work) else mrq->cmd->error = -ETIMEDOUT; + /* No new calls yet, but disallow concurrent tmio_mmc_done_work() */ + host->mrq = ERR_PTR(-EBUSY); host->cmd = NULL; host->data = NULL; -- 2.43.0