Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp354745lqs; Tue, 5 Mar 2024 04:19:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXo4OrzX0VAQp0pyQftWAbOpFIp2K5dSLumF9+ewmtl1x+dgONmRqeG92msnH/V87Jz/dWFOnfxqCFhUi/JkQRofTeQO1J3+B1PDIr6Kg== X-Google-Smtp-Source: AGHT+IErg4oRlCJAa23gBgXnh5uCotk+KDwKt+/fA73DnQ9Vaj0HUbfYl/b1nKxLpXu4kPVNmbk4 X-Received: by 2002:a05:6a21:1693:b0:1a1:4cd2:3e2e with SMTP id np19-20020a056a21169300b001a14cd23e2emr1211918pzb.14.1709641170049; Tue, 05 Mar 2024 04:19:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709641170; cv=pass; d=google.com; s=arc-20160816; b=b7kTO/4ezY6Rywc05Skel9bBi8M5ItQOf5aD4M7siZJu9/a/QC6Lyw0HWvAAEMC0K5 E7To1ovhCmlKt9ol+TnQ41l5HkX9v/2YPTaCKOSJqSeOCz/UYiiExAgVc1rBJYqMeHQ5 u8sFmbb6A5rIi8NjXeTaYvIBuF02df8ornfeor+pSO9kq3fQEjJnGBjo2Yi0sLXaHrYt 32h6mbjEfnbqFpdb3mwREOuGKFYZHiwxPMy+agfAudBWJ7HqLdJ06E3kH3dUdFsLLFgy yBUCWdq+0QJ9F8KPfop2R8SV0ebkKNcS3ZPl+893+ONQFcN34SW9QGkdA+JQ76rz7IzO pQwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=ZVW/PXVs5nzy5Gr+BEyjbP8Shu9TAluG0kZZRSGaf1s=; fh=kstcr8YCIuaY025cNjRmkkTudOjhSdqFiUaCv1Wrb+A=; b=UcaApE7hJeSHaVZepjTbW9YtR/66JK7MngusolE8wSpSqt6wCWGpPv/BmoBJ3vCMLT sWN/GLrBmE+38t1OM1nI+d+o9pXwQoBs1aNhqN7NEBE+KHmXrM1rccvRufoZoK3Jef6Z pD8VcqEeCAcsJuxpdbTSPCpsMNG0Yi31SMzD9DsYCfQO0BqJ2o22YEJwR4lzbA11ScIo JwJWBX8yKK/c9iPjJwtKTcD4vNpwtovmr6jd3BP8uUNU5fVjKNoBPOrp0Mps5pnAnsk9 rz2QkvVqcKMum3DgIXCQK/DRbjwOLeTgy9TCVskaMzE+Tie/GKvKK2X7/8tic7AizcQz 2Iyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UlXlibw3; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-92338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fa24-20020a056a002d1800b006e5ecfaa491si5527597pfb.399.2024.03.05.04.19.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:19:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UlXlibw3; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-92338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 AA91FB23441 for ; Tue, 5 Mar 2024 12:15:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 699805A4CC; Tue, 5 Mar 2024 12:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UlXlibw3" Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31DD5A118 for ; Tue, 5 Mar 2024 12:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709640911; cv=none; b=b+BhitpfpXfXvLllLcq9mrU2L0V37RmA+/8l3xRA3kOEWsCWPcTvY2ziUCHFltj55i3SEjXxufMQK68OOp0Rljx5UnQEbWkxf1DCB5phk57ECdl4yFF5K+bIJdQKbPMFWSVYBPtcdADA/3spUBy8CE73V6Cwp+TwvCD/vYjKUwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709640911; c=relaxed/simple; bh=RCaP4GDWT87Zd9IUZzQQpBKEXe+s1x2lF2pIn4GuNXU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=YzSLCwHUfaYxwT4wrUewS+CxMaRP6z6Gebnle085z1Z9Ello+rHS6ASU0cQSkntLKAtY1rDBulm0VpQhCyRebWGzjdKv5fxTijWznNruYHRUKR+1WPbkrm/c49wix2F9cmWcplbUlhOU8CqvWygSkIyEpUvjxphDgyowy2+k+Gg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UlXlibw3; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-dd045349d42so625367276.2 for ; Tue, 05 Mar 2024 04:15:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709640908; x=1710245708; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZVW/PXVs5nzy5Gr+BEyjbP8Shu9TAluG0kZZRSGaf1s=; b=UlXlibw3caQYA57kMfjNtfV6yf5J+oylhS9K4ZXt73FtLQhoSMTyKVWUDyiZYM9FlO EpBnaNdd20YdCCHFYLDfAnnK92S9dPpJ2Y9GVPA05wQI9IcIc2O1F8zGjuqEbuf3blQA Xj9Fvt86ML6cxLIoamGCj1otdU1z5qe1RbQvrj8ausuGUyRf1TBAKvzTjczJAhCmix1s qTtYnakLOvJnfliFe+S++misrWDWyrDGTwvbUAKHi7KiM62Jz34pKCbGwLnoWqAzuB2h cHAWIhmJRSiprowLH6F341m3oIAjgIg4nZXuKHrW/AA6Caed9MyL3loyZrer3w39SvHg fi6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709640908; x=1710245708; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZVW/PXVs5nzy5Gr+BEyjbP8Shu9TAluG0kZZRSGaf1s=; b=loRo7rAKWMe9ULNqshva9BbFuLOMjD6m7ujL40WCxe0cYMPOnsBuxHXPE36z4uBZx6 wtPL3TGYGpVGFs1q+2Hxp3wOkmQGaSjmuuq7X2qJsxvUNQa1DmZFUb55gQj48ehvFVsv e6Alvqbu8qBHhjpJQARTTCDrKL81bQZ4ZZDvAG2tS6ZzFPPJ0NXof0hJ+efzMYTrjnz6 LEUxm+SBqzT6giVP9GVRccNX6MSSXqa1LvQOJ8CWMNZr3Gw2PzD/VJcd3PNADb2NZOCC levWLVl2YVAryMUQvVRsMcBzJUwhDZoq896ltzZ72gStq80C6XqmVp6txIsjuZA+oWuH nM7g== X-Forwarded-Encrypted: i=1; AJvYcCU9K+tBwkDh367d3V3qc4yEzpfe3SbeXVWwGDqGdrBnGultDt31QAlxp1Red6UDPdn063CwuKp5uxyA7xALlsn4FnFijT3vsFNCIILL X-Gm-Message-State: AOJu0Yz/+gO7ZzUQxprx+u41SU/CQrxl8tWH52h5pMw3ECHwi78uvAKp Kcw6YQeESr7tUAdUn0AqEfraytCyRbI8uOQYg8xZXTbnRmM0run/n2hiHhAd2MzY4B4ooRc6h5P jkNcqG8PWsRC+WCz4cvmZMUFqckI+WyX/PjzBVA== X-Received: by 2002:a25:660c:0:b0:dd0:c2a:26f9 with SMTP id a12-20020a25660c000000b00dd00c2a26f9mr6859439ybc.27.1709640907662; Tue, 05 Mar 2024 04:15:07 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240305104423.3177-2-wsa+renesas@sang-engineering.com> In-Reply-To: <20240305104423.3177-2-wsa+renesas@sang-engineering.com> From: Ulf Hansson Date: Tue, 5 Mar 2024 13:14:31 +0100 Message-ID: Subject: Re: [PATCH v2] mmc: tmio: avoid concurrent runs of mmc_request_done() To: Wolfram Sang Cc: linux-renesas-soc@vger.kernel.org, Dirk Behme , stable@vger.kernel.org, Chris Ball , Guennadi Liakhovetski , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Tue, 5 Mar 2024 at 11:44, Wolfram Sang wrote: > > 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 below). > > 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/ > Fixes: df3ef2d3c92c ("mmc: protect the tmio_mmc driver against a theoretical race") > Signed-off-by: Wolfram Sang > Tested-by: Dirk Behme > Reviewed-by: Dirk Behme > Cc: stable@vger.kernel.org # 3.0+ Applied for fixes, thanks! Kind regards Uffe > --- > > Change since v1/RFT: added Dirk's tags and stable tag > > @Ulf: this is nasty, subtle stuff. Would be awesome to have it in 6.8 > already! > > 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 >