From patchwork Wed Jun 7 10:52:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 104440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp177892vqr; Wed, 7 Jun 2023 04:17:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ465izIqRDeKIxbVVWIL60B66TGikIZuyMOe6ocFXw2PTgJs24OQeaTatOIAtleUk7zccQg X-Received: by 2002:a17:90a:d703:b0:256:4189:2b0d with SMTP id y3-20020a17090ad70300b0025641892b0dmr1555236pju.12.1686136653888; Wed, 07 Jun 2023 04:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686136653; cv=none; d=google.com; s=arc-20160816; b=qOe9umKps1/v6O9aN2VXTQGYrv0I+3Jibben2qBhwnotAAcv0v9msgdQKZ8rVlGDp1 yh8CfXoGkGRkan5Jw87EK51GCKlDjFFlUEnwxp5Gfa8BGcv2cbRdQYrjbnJwQpXPhrk0 +G1O/leKiRAD9ICFaOxqb0p1rPcHVtyLwy+l0U+S90pb/tq7GXcST0sORTRSbEMtY3Af hNVe1ZWsLAj53FYX7tI7ITu//XtU1p5ayhqafRMQuhMPLME4ZNxLhFpUFQCmtsp/4Y/f poQmvI6tpMeGkvPQYhaqAvEMhCBbOfeQUslsSNlhB9BhtF1zKsJcZV3W2uCAhDe7eooY I5xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=CaF8PzEF9e7LF8fr6u7QZMgwza+QflistAgrP9nL8qA=; b=jrglmZDl2TORCTCDoXqfRdWQ+1ORWYItT4VU6VJ1t6jCK+1MeMAjkjxsd96NOx6ye3 yaWRBfOUxF2oAwsau4HQXCfk2oXxHt3cVzHZQhqX3V4+O/p4f6ecUNcPuxmfE5zBBL14 GYYuH8GcpTwbtaB7VyMzyjbneDZ3mlYLwU2atBtDhDuReMz/G4UgPGU/KyMO9nS6cafo VVhh9gXsjgaFWoOfkaqrHBArxC2n9ADdaZCKhonXBV8bno4c8R7PnZb41+kpj876KW/f esXLwgGVS1Yx77z0RY2L4SsKASlmtOqXQzkfCtK/xUBTBT888mSdg0dMdcsqEBW/j1Cv dpWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="lmh6X/88"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a17090ac28e00b002534791ea59si973035pjt.28.2023.06.07.04.17.19; Wed, 07 Jun 2023 04:17:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="lmh6X/88"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239899AbjFGKxS (ORCPT + 99 others); Wed, 7 Jun 2023 06:53:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239993AbjFGKxL (ORCPT ); Wed, 7 Jun 2023 06:53:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5025A1FC4; Wed, 7 Jun 2023 03:52:49 -0700 (PDT) Date: Wed, 07 Jun 2023 10:52:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686135128; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CaF8PzEF9e7LF8fr6u7QZMgwza+QflistAgrP9nL8qA=; b=lmh6X/88g1M+sYvlHUfTIKzfhXYEi8Kl9IguegOjysqxJjUh8uo2sRlnPJflSfbFF4CsMH 5+Lv3sSsxepYIo09QjNlyRfX6EScZSTgsUiy6Pq/wjIDJcr+6aB4BFBIKGyzNGoOo5yC3k odXZuM9WaDfrZLbrNeK5V9vol33SrN4Jh8FCxJHWhqZOpxZjaxlWO8OxvMgALMF+JrGhPc TE2s79Mef/q+CE4ocgOzcVcb6GlSruvMZVGlMjotDMAHNoLycX135bxLKrNiNwDPRZYvHK nB9cBsQm0cYN/cD7PDc1tsSBjqI56If4orfwyxHMhAgQLy2ANLmwQ9i+kedLgA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686135128; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CaF8PzEF9e7LF8fr6u7QZMgwza+QflistAgrP9nL8qA=; b=aiGs2NwCXiX6U9Ryx6M6W2bdGou1eLNgCDacVHU9pfRMYTPbt7jUIlEPtuFBiNq2CYnhjf DUgkdVhSZy81fjAg== From: "tip-bot2 for Peter Newman" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Factor rdtgroup lock for multi-file ops Cc: Peter Newman , "Borislav Petkov (AMD)" , Reinette Chatre , Babu Moger , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230419125015.693566-2-peternewman@google.com> References: <20230419125015.693566-2-peternewman@google.com> MIME-Version: 1.0 Message-ID: <168613512832.404.10934762057759711815.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763609969114572646?= X-GMAIL-MSGID: =?utf-8?q?1768042428011616239?= The following commit has been merged into the x86/cache branch of tip: Commit-ID: c45c06d4ae63a0714efbfa435c5a8f64a5f35b9b Gitweb: https://git.kernel.org/tip/c45c06d4ae63a0714efbfa435c5a8f64a5f35b9b Author: Peter Newman AuthorDate: Wed, 19 Apr 2023 14:50:13 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 07 Jun 2023 12:15:18 +02:00 x86/resctrl: Factor rdtgroup lock for multi-file ops rdtgroup_kn_lock_live() can only release a kernfs reference for a single file before waiting on the rdtgroup_mutex, limiting its usefulness for operations on multiple files, such as rename. Factor the work needed to respectively break and unbreak active protection on an individual file into rdtgroup_kn_{get,put}(). No functional change. Signed-off-by: Peter Newman Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Tested-by: Babu Moger Link: https://lore.kernel.org/r/20230419125015.693566-2-peternewman@google.com --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 +++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 61cdd9b..653d258 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2305,6 +2305,26 @@ static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn) } } +static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn) +{ + atomic_inc(&rdtgrp->waitcount); + kernfs_break_active_protection(kn); +} + +static void rdtgroup_kn_put(struct rdtgroup *rdtgrp, struct kernfs_node *kn) +{ + if (atomic_dec_and_test(&rdtgrp->waitcount) && + (rdtgrp->flags & RDT_DELETED)) { + if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP || + rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) + rdtgroup_pseudo_lock_remove(rdtgrp); + kernfs_unbreak_active_protection(kn); + rdtgroup_remove(rdtgrp); + } else { + kernfs_unbreak_active_protection(kn); + } +} + struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) { struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn); @@ -2312,8 +2332,7 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) if (!rdtgrp) return NULL; - atomic_inc(&rdtgrp->waitcount); - kernfs_break_active_protection(kn); + rdtgroup_kn_get(rdtgrp, kn); mutex_lock(&rdtgroup_mutex); @@ -2332,17 +2351,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn) return; mutex_unlock(&rdtgroup_mutex); - - if (atomic_dec_and_test(&rdtgrp->waitcount) && - (rdtgrp->flags & RDT_DELETED)) { - if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP || - rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) - rdtgroup_pseudo_lock_remove(rdtgrp); - kernfs_unbreak_active_protection(kn); - rdtgroup_remove(rdtgrp); - } else { - kernfs_unbreak_active_protection(kn); - } + rdtgroup_kn_put(rdtgrp, kn); } static int mkdir_mondata_all(struct kernfs_node *parent_kn,