Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2108992pxu; Fri, 18 Dec 2020 05:52:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzN0wZwR0TlQQV9aN72OVG0vupYDAF2nBvO74U02fqPOiXinTq5kIGr/ZDN5Mvop2mvYuR6 X-Received: by 2002:a05:6402:1d15:: with SMTP id dg21mr4441392edb.280.1608299558124; Fri, 18 Dec 2020 05:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608299558; cv=none; d=google.com; s=arc-20160816; b=PnieHP4y0J2WOJtxQXqTd7zVj1G0xCac1Zj11HgSX0EqFRVbH0qgR4BLemS9f8rRLv l/MUyMUpCpyni++uEhUpyPaqYe7i83VNpDBZOpDLMl2JJsBCwlVg7s7+a3zDsQhosKS+ YqwIjZzLG6Ij3VV15m41YjlTWpgbauwteONwxrDrix9bo025PaIBTq3dTf2EOWad8BVC V4p20J62Xk4NfONrDoL4CGixB9S8a/XCrD1XuU7896grQaLeDn2GYpBFevBncVKJgeSs c62lsC5Qf3dZXd2OJxCjD4buy5Kr/lRyLfIfhT5sOxZghHizi43t5h8XCR7W8GhGgXMi wKnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OGRVW3Zib+bLKNC+Amev3v1cKadH0SToLHNOIADvq2o=; b=FMvCy46fkCl/CSKUIAj3hpvx31FZKRz8bXFo7qSMOT3KD5E7HK2ruLLFU2dYQ8cqnw hBjV53Ya0aOk6fti4SG/etREjesa2hGevwE+6OIrxWeRFoofrnhc1eI5bceYsUHnJ/TJ /P3IEc0OnNmZ785ZvYr4w/alzlfVJEDx7SlGL+aCV7PTEQmgRNaqxS+wvJOL2WEgThXq 2nnfd8dc86lKoW7jLBwwNUCjcdgRQ1A/yn/7C4uOnXcNhUiil1X1xbY8e2TqAJitkMdu BJnd61CHyMILelqYz0zxI1QjDqLtITP/FVfE4bCnj0ve+y9F0DCpeHzUynKN+WPXadI1 IcOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pkvKvgjl; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt5si4723474ejb.639.2020.12.18.05.52.15; Fri, 18 Dec 2020 05:52:38 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=pkvKvgjl; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726942AbgLRNV2 (ORCPT + 99 others); Fri, 18 Dec 2020 08:21:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726286AbgLRNV1 (ORCPT ); Fri, 18 Dec 2020 08:21:27 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4F3DC0617A7; Fri, 18 Dec 2020 05:20:46 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id a9so5410059lfh.2; Fri, 18 Dec 2020 05:20:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OGRVW3Zib+bLKNC+Amev3v1cKadH0SToLHNOIADvq2o=; b=pkvKvgjlTYrU0/rcHyKjHlh90stI5sOSKLqGgQy9GEpaW9fC2vF8hJQnOIt5c8SBdh 7On4XSt9s2ahIXDe/XUoBWn6cfWjgfCdXS4QjYXKcRgzTwdLxVEfxv9olmHEGjbZsywP LYVkZAnsmZT+WJTkGNNZXB+Xa3ckIxvo8Gq4VG0KuSwnNlIhmE00z4HLFTX2FR8EronV 6FxqB3D2LyUlsmqSUBEpjlqc1AWMQ2FXzKZe2M4yJCz/qDh8HDKcvRnbDWKBg97PHhGf 3EZE7XSx/qAxFqVumF0TklBSIE4cHG0OS9qjDAVG24JPlQAjXxMUHACej1ioVnzM7P8I L0vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OGRVW3Zib+bLKNC+Amev3v1cKadH0SToLHNOIADvq2o=; b=DFE/d82pSAvaotvC5mZXFGiU45HPk2/SkwT9YZ6TTKkqBs9zZd9e7h7Ffov8BVgmDu PsF55/mLarLY52Nw+UfzvNIbJVG3i3jZ3ny3PRxqz+Jveya+sRB9mvD3BPM0pftK1Nr+ TWTYjNq7K4YVOWBjBp0nbdSpb2iQQ0wiURFxMWybRFON+rlZYAb8ateQIJTeIpx48Fug ucvi5IyG05TvUS42MBzkyQgOjlpRXA2pGmd/AGJtNpY5K/97WauXHOZHXaMNGLH3vlZV hRnR2o283dovc2GR7qAbVIw6acTfDlDaaLTZTibMHpPF/k3FnqMi6KMO6QroePVhL1q7 Vi8A== X-Gm-Message-State: AOAM533dB/amjyNFD4wiSBgcYJPvhvvQae5JxNNcoRUkWfZdBy1qRn5F u7xQXRt/SO/3m1A0D1wBd8gLaReFwiwkey6ayHg= X-Received: by 2002:a2e:874d:: with SMTP id q13mr1791068ljj.323.1608297645213; Fri, 18 Dec 2020 05:20:45 -0800 (PST) MIME-Version: 1.0 References: <3e97846b52a46759c414bff855e49b07f0d908fc.camel@themaw.net> <67a3012a6a215001c8be9344aee1c99897ff8b7e.camel@themaw.net> In-Reply-To: From: Fox Chen Date: Fri, 18 Dec 2020 21:20:33 +0800 Message-ID: Subject: Re: [PATCH v2 0/6] kernfs: proposed locking and concurrency improvement To: Ian Kent Cc: Tejun Heo , Greg KH , akpm@linux-foundation.org, dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, miklos@szeredi.hu, ricklind@linux.vnet.ibm.com, sfr@canb.auug.org.au, viro@zeniv.linux.org.uk Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 18, 2020 at 7:21 PM Ian Kent wrote: > > On Fri, 2020-12-18 at 16:01 +0800, Fox Chen wrote: > > On Fri, Dec 18, 2020 at 3:36 PM Ian Kent wrote: > > > On Thu, 2020-12-17 at 10:14 -0500, Tejun Heo wrote: > > > > Hello, > > > > > > > > On Thu, Dec 17, 2020 at 07:48:49PM +0800, Ian Kent wrote: > > > > > > What could be done is to make the kernfs node attr_mutex > > > > > > a pointer and dynamically allocate it but even that is too > > > > > > costly a size addition to the kernfs node structure as > > > > > > Tejun has said. > > > > > > > > > > I guess the question to ask is, is there really a need to > > > > > call kernfs_refresh_inode() from functions that are usually > > > > > reading/checking functions. > > > > > > > > > > Would it be sufficient to refresh the inode in the write/set > > > > > operations in (if there's any) places where things like > > > > > setattr_copy() is not already called? > > > > > > > > > > Perhaps GKH or Tejun could comment on this? > > > > > > > > My memory is a bit hazy but invalidations on reads is how sysfs > > > > namespace is > > > > implemented, so I don't think there's an easy around that. The > > > > only > > > > thing I > > > > can think of is embedding the lock into attrs and doing xchg > > > > dance > > > > when > > > > attaching it. > > > > > > Sounds like your saying it would be ok to add a lock to the > > > attrs structure, am I correct? > > > > > > Assuming it is then, to keep things simple, use two locks. > > > > > > One global lock for the allocation and an attrs lock for all the > > > attrs field updates including the kernfs_refresh_inode() update. > > > > > > The critical section for the global lock could be reduced and it > > > changed to a spin lock. > > > > > > In __kernfs_iattrs() we would have something like: > > > > > > take the allocation lock > > > do the allocated checks > > > assign if existing attrs > > > release the allocation lock > > > return existing if found > > > othewise > > > release the allocation lock > > > > > > allocate and initialize attrs > > > > > > take the allocation lock > > > check if someone beat us to it > > > free and grab exiting attrs > > > otherwise > > > assign the new attrs > > > release the allocation lock > > > return attrs > > > > > > Add a spinlock to the attrs struct and use it everywhere for > > > field updates. > > > > > > Am I on the right track or can you see problems with this? > > > > > > Ian > > > > > > > umm, we update the inode in kernfs_refresh_inode, right?? So I guess > > the problem is how can we protect the inode when kernfs_refresh_inode > > is called, not the attrs?? > > But the attrs (which is what's copied from) were protected by the > mutex lock (IIUC) so dealing with the inode attributes implies > dealing with the kernfs node attrs too. > > For example in kernfs_iop_setattr() the call to setattr_copy() copies > the node attrs to the inode under the same mutex lock. So, if a read > lock is used the copy in kernfs_refresh_inode() is no longer protected, > it needs to be protected in a different way. > Ok, I'm actually wondering why the VFS holds exclusive i_rwsem for .setattr but no lock for .getattr (misdocumented?? sometimes they have as you've found out)? What does it protect against?? Because .permission does a similar thing here -- updating inode attributes, the goal is to provide the same protection level for .permission as for .setattr, am I right??? thanks, fox