Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5149009pxj; Wed, 9 Jun 2021 10:13:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbOCC2Wb1Yxws7CJwbVxs1qF+2HOo0CJ/yH3fp0KA4fLJBQKcmbg51wM0KAi5BrbLg5p4e X-Received: by 2002:a05:6402:1b04:: with SMTP id by4mr501015edb.238.1623258803143; Wed, 09 Jun 2021 10:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623258803; cv=none; d=google.com; s=arc-20160816; b=BRZ2H5kfxsCovIFYTtstmyMhJB2OskvrofDiTnHsSbPbCQ8ad97i6KKyZe1jHOmmgI 3IiVJqU8PjqF3x4uWpjtaVZd3zF5Wk2YZZ4kQXYOr0oO66K06g22yTnGuJMcdaH8z9TG ztJt2v9WfGwrQCsLe2CdRiUwDSbF75lyrcNSDi6lKBOBfnW9kESCcvYRanQd3FwoR6gF GsJ9LJHXemuFPNrP6TownjEKf+bnQCKmbXAsKl6q7g864p6L6Q+c0ljrxt0aqNkdJs3B IP5h7ABm0/hcyimpGeSi2b7ZG1j6rMpsJFBt2gtH2TozzjK+qEriBfytNrlB1zqehOhK KrNQ== 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=uqXhUybkP+QW+2bWHDqZN9UOlXVx6pnCrvZxdED10Nr604APHJzo1mHHPW37RLhh13 0H4LRaJg/aOqxjyx+Pp1ARsmq1nXwvBKdikT1/K2IRltOJUPicuvAG6cFyAt1Tvdr432 Iy5FnJ0nlQvm60CO3Un+iSTFN5syUrXrNhv67WsHnCsJpPRrWNNBIixxYjBwS8tJTs2T hdtv7801VhNi6gjEfx160/SEFMucUOElPWH0kk9V+7KYD2cQhyvId0xZ/SdQq/tubAtL /rwf3RBJZc/EKO+kqoYv0GPKEbw2Y3Z1XnG8swQ48Hn8BkpjlSWsSMF2xV/HR2vjUh4P VYGw== 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 z23si383011ejl.394.2021.06.09.10.12.59; Wed, 09 Jun 2021 10:13:23 -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 S237804AbhFIIyT convert rfc822-to-8bit (ORCPT + 99 others); Wed, 9 Jun 2021 04:54:19 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:52307 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237800AbhFIIyS (ORCPT ); Wed, 9 Jun 2021 04:54:18 -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-561-ZeIgQlZ8P3qvM7_yvvXxQg-1; Wed, 09 Jun 2021 04:52:20 -0400 X-MC-Unique: ZeIgQlZ8P3qvM7_yvvXxQg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE929C7400; Wed, 9 Jun 2021 08:52:18 +0000 (UTC) Received: from web.messagingengine.com (ovpn-116-20.sin2.redhat.com [10.67.116.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1E865D9DE; Wed, 9 Jun 2021 08:52:07 +0000 (UTC) Subject: [PATCH v6 6/7] 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: Wed, 09 Jun 2021 16:52:05 +0800 Message-ID: <162322872534.361452.17619177755627322271.stgit@web.messagingengine.com> In-Reply-To: <162322846765.361452.17051755721944717990.stgit@web.messagingengine.com> References: <162322846765.361452.17051755721944717990.stgit@web.messagingengine.com> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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)