Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6851037rdb; Fri, 15 Dec 2023 09:53:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJWORn4oVjDDWE7a0cKin8bVMNYWLtAl0Hfv/8HLKyQuxab7YLBqoKqd7q3kMGvG10bpB/ X-Received: by 2002:a05:620a:269d:b0:77f:b706:ad0a with SMTP id c29-20020a05620a269d00b0077fb706ad0amr808076qkp.99.1702662816079; Fri, 15 Dec 2023 09:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662816; cv=none; d=google.com; s=arc-20160816; b=XHqPPZv4UPCKOPnM2HounBsWqi1ylacjg55c9Jh0EteIJ4Tv0hmY24WO3tAfL1fH5R j2WwXjrmPhYnDqsq856z7jkbeNmk14L24/KBeeJ3YnImwM12OtPYAJA++k/Xl7SIeqku EI5YQCjZ4EXzBTLDOIDzjrKn72dnv6whRJOBolSjezFAEbRcnYqAbQPg35of1md5HzCq 2zSVC3vXKF4gCWpfRS7i+qg9jq+d+tzx7T6SbilUhz2PefK3FsYBICYoZ+Zuu6lAvi46 NAByMy1PwAxQ9wBYymnrQ7EDrjgEpYIX86We9SI8l7XhN7g6bcu4Ot6FKhmccF6OSHND tpyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EA5bCuP5bQE+M6LMBG9odszWdaXjVZquesmQp5Vuknk=; fh=fEJWjqJ+RLhmQ25ff48PFsNJUwvWKNLk08bfN+2nXBY=; b=nRLkl2dTvdUCI5XMQzU5bTxZTEdQHUOblxYp9ZWoOuncwjnRAfGhc/0g4Zt1ifbKAf Zxrcri4gHMCJEAsnx+txyUXLa4ew5gKkQG0bm8ODcR0A5iiLNBtTtzRLtorkL20yOTel KtQAYmYO3sbSl8hCp4iOEmRsBm31nmu+X6q/JGOB58mkKHvjYtxDBUW51Pmcm1sAAMm3 4kifRfwe0ay5cfYutsqgddOyfpn0TrhPJBl79KikNSLfLFw7mg/G54pnH2Tbx6PM8UBG TmqtnTVaKfYZLZ3ApwROpNi0M6jK/a5mS/cfH0BAp9fJKoWTWsURjSkkITQ6vSMAldtR qzAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n1HNiIs7; spf=pass (google.com: domain of linux-kernel+bounces-1474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w14-20020a05620a424e00b0077f261dd26esi18435075qko.416.2023.12.15.09.53.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:53:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n1HNiIs7; spf=pass (google.com: domain of linux-kernel+bounces-1474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D22B11C24797 for ; Fri, 15 Dec 2023 17:53:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2186D3011D; Fri, 15 Dec 2023 17:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="n1HNiIs7" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E6C0530108; Fri, 15 Dec 2023 17:53:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E78C433C7; Fri, 15 Dec 2023 17:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1702662794; bh=bCeZYjdKbAsjH+3ZnxxwoKFd5W+uxUmvZZXD9LOmVAI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=n1HNiIs70ftZwmIX3BAKT7HlQFwEbubiqSnRfQqpa9/Sfl3TuxPsso5m19okbZO5v nw9dM7Vsy5Kt7w2PbsH6hj2ArcNdwxExg5KAlYr2dArzus0yDJByYdefDdLnKtFEDf kPAtGPf4l5SHoWFNvuAQILAgH9gaflnt5pWNgKU8= Date: Fri, 15 Dec 2023 18:53:11 +0100 From: "gregkh@linuxfoundation.org" To: "Verma, Vishal L" Cc: "Williams, Dan J" , "david@redhat.com" , "joao.m.martins@oracle.com" , "Jiang, Dave" , "akpm@linux-foundation.org" , "osalvador@suse.de" , "linux-cxl@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "dave.hansen@linux.intel.com" , "Huang, Ying" , "nvdimm@lists.linux.dev" , "linux-mm@kvack.org" Subject: Re: [PATCH v6 2/4] dax/bus: Use guard(device) in sysfs attribute helpers Message-ID: <2023121517-flammable-ragweed-d42e@gregkh> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> <20231214-vv-dax_abi-v6-2-ad900d698438@intel.com> <2023121515-litigate-finished-76dd@gregkh> <657c89c16d5f5_269bd294bd@dwillia2-mobl3.amr.corp.intel.com.notmuch> <89ea0a46cd1cf22393c6b05a50cd3e719ab6a4ba.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <89ea0a46cd1cf22393c6b05a50cd3e719ab6a4ba.camel@intel.com> On Fri, Dec 15, 2023 at 05:32:50PM +0000, Verma, Vishal L wrote: > On Fri, 2023-12-15 at 09:15 -0800, Dan Williams wrote: > > Greg Kroah-Hartman wrote: > > > On Thu, Dec 14, 2023 at 10:25:27PM -0700, Vishal Verma wrote: > > > > Use the guard(device) macro to lock a 'struct device', and unlock it > > > > automatically when going out of scope using Scope Based Resource > > > > Management semantics. A lot of the sysfs attribute writes in > > > > drivers/dax/bus.c benefit from a cleanup using these, so change these > > > > where applicable. > > > > > > Wait, why are you needing to call device_lock() at all here?? Why is dax > > > special in needing this when no other subsystem requires it? > > > > > > > > > > > Cc: Joao Martins > > > > Cc: Dan Williams > > > > Signed-off-by: Vishal Verma > > > > --- > > > > ?drivers/dax/bus.c | 143 ++++++++++++++++++++++-------------------------------- > > > > ?1 file changed, 59 insertions(+), 84 deletions(-) > > > > > > > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > > > > index 1ff1ab5fa105..6226de131d17 100644 > > > > --- a/drivers/dax/bus.c > > > > +++ b/drivers/dax/bus.c > > > > @@ -294,13 +294,10 @@ static ssize_t available_size_show(struct device *dev, > > > > ????????????????struct device_attribute *attr, char *buf) > > > > ?{ > > > > ????????struct dax_region *dax_region = dev_get_drvdata(dev); > > > > -???????unsigned long long size; > > > > ? > > > > -???????device_lock(dev); > > > > -???????size = dax_region_avail_size(dax_region); > > > > -???????device_unlock(dev); > > > > +???????guard(device)(dev); > > > > > > You have a valid device here, why are you locking it?? How can it go > > > away?? And if it can, shouldn't you have a local lock for it, and not > > > abuse the driver core lock? > > > > Yes, this is a driver-core lock abuse written by someone who should have > > known better. And yes, a local lock to protect the dax_region resource > > tree should replace this. A new rwsem to synchronize all list walks > > seems appropriate. > > I see why _a_ lock is needed both here and in size_show() - the size > calculations do a walk over discontiguous ranges, and we don't want the > device to get reconfigured in the middle of that. A different local > lock seems reasonable - however can that go as a separate cleanup that > stands on its own? Sure, but do not add a conversion to use guard(device) here, as that will be pointless as you will just use a real lock instead. > For this series, I'll add a cleanup to replace the sprintfs with > sysfs_emit(). Why not have that be the first patch in the series? Then add your local lock and convert everything to use it instead of the device lock? thanks, greg k-h