Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3135193pxj; Mon, 7 Jun 2021 03:17:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmCoFprAH17JEEhsj0lVPWaq7EdqAt2Qdv232Ks5awjnIhlPk7T88x0eHPDimkuSlg6R2X X-Received: by 2002:aa7:de8b:: with SMTP id j11mr19310818edv.363.1623061050368; Mon, 07 Jun 2021 03:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623061050; cv=none; d=google.com; s=arc-20160816; b=KG/s34W344c5aSjy3xsF9WitVGOQWsJ/mBL+pF41fxSBfqFjESypKi+uMzyf2Tt4r9 a0v9xYcYygkqZzI1PJ042uDMaTRVVtmb6he5Nc2FMEZhtG/sR8jutpRMBlj53JrrKAns YKSVWCbZ6alwGQJhWoeX3cZzNgpyimpvdqjlPC9focpfWDlw+K6eS60ESy6Y5YVA2NtD Td8/6S3fsxaNq54Mt/kCZwJ3tfd/pjdPR2svFuyiYgYSDbcizoLxTIldMJNKRZWY4VxQ 8WLRPbHywURb9Y7GEQtz+TrDo/s0OMuklXnQG8zLoNbJL5+e94En8HiKdC+im923AXAs pj7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=jq438R/dBczHuDKna83pbkAS09nHnTvvltQrphANycQ=; b=fWXcLELik9qetw4A+ox3f+ByK471M6e/rgmEuGGkIfM2ywTOyAsw6LjHmL1dk8vxCz ifM+CdaauhK9QdFOnegW4gzE0AiLe072QTdMC9DM0xcYDP+DqOufmO9Jv9n1CLo4A1TL BXI0SDzM6lT9VQTVmgTa/XJhrNEv+8vKLw10RZM/IZC/7vptxD/tONsZfQWxWzPbFOCd mNkwVBqqR8vzhRqTRJVUtS2gQeJFognLATNTjdnOwuirCEie8uPDu3usBqNPQ7NVcIJX 20m7UZAO2be+2jEvQ/3tgLS1SgynkclYmegf+b4AUgWF92yQWYpuB/Rg9whAhr2odhNY VP/w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si14906822edk.213.2021.06.07.03.17.08; Mon, 07 Jun 2021 03:17:30 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbhFGKOw convert rfc822-to-8bit (ORCPT + 99 others); Mon, 7 Jun 2021 06:14:52 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:54042 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbhFGKOv (ORCPT ); Mon, 7 Jun 2021 06:14:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-37-3Lglvf-YPGeF-wOFVogcHQ-1; Mon, 07 Jun 2021 06:12:57 -0400 X-MC-Unique: 3Lglvf-YPGeF-wOFVogcHQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5864F1883527; Mon, 7 Jun 2021 10:12:55 +0000 (UTC) Received: from web.messagingengine.com (ovpn-116-49.sin2.redhat.com [10.67.116.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74B935C238; Mon, 7 Jun 2021 10:12:48 +0000 (UTC) Subject: [PATCH v5 6/6] kernfs: add kernfs_need_inode_refresh() From: Ian Kent To: Greg Kroah-Hartman , Tejun Heo Cc: Eric Sandeen , Fox Chen , Brice Goglin , Al Viro , Rick Lindsley , David Howells , Miklos Szeredi , Marcelo Tosatti , "Eric W. Biederman" , Carlos Maiolino , linux-fsdevel , Kernel Mailing List Date: Mon, 07 Jun 2021 18:12:47 +0800 Message-ID: <162306076700.69474.13051618210568968165.stgit@web.messagingengine.com> In-Reply-To: <162306058093.69474.2367505736322611930.stgit@web.messagingengine.com> References: <162306058093.69474.2367505736322611930.stgit@web.messagingengine.com> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=raven@themaw.net X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: themaw.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now the kernfs_rwsem read lock is held for kernfs_refresh_inode() and the i_lock taken to protect inode updates there can be some contention introduced when .permission() is called with concurrent path walks in progress. Since .permission() is called frequently during path walks it's worth checking if the update is actually needed before taking the lock and performing the update. Signed-off-by: Ian Kent --- fs/kernfs/inode.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 6728ecd81eb37..67fb1289c51dc 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -158,6 +158,30 @@ static inline void set_default_inode_attr(struct inode *inode, umode_t mode) inode->i_ctime = current_time(inode); } +static bool kernfs_need_inode_refresh(struct kernfs_node *kn, + struct inode *inode, + struct kernfs_iattrs *attrs) +{ + if (kernfs_type(kn) == KERNFS_DIR) { + if (inode->i_nlink != kn->dir.subdirs + 2) + return true; + } + + if (inode->i_mode != kn->mode) + return true; + + if (attrs) { + if (!timespec64_equal(&inode->i_atime, &attrs->ia_atime) || + !timespec64_equal(&inode->i_mtime, &attrs->ia_mtime) || + !timespec64_equal(&inode->i_ctime, &attrs->ia_ctime) || + !uid_eq(inode->i_uid, attrs->ia_uid) || + !gid_eq(inode->i_gid, attrs->ia_gid)) + return true; + } + + return false; +} + static inline void set_inode_attr(struct inode *inode, struct kernfs_iattrs *attrs) { @@ -172,6 +196,9 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) { struct kernfs_iattrs *attrs = kn->iattr; + if (!kernfs_need_inode_refresh(kn, inode, attrs)) + return; + spin_lock(&inode->i_lock); inode->i_mode = kn->mode; if (attrs)