From patchwork Tue Nov 15 15:45:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 20442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2803274wru; Tue, 15 Nov 2022 07:50:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf54B+Z/0Vm9KBD935WrVdr3CgytWk82u7RSKsNKXauWEQgngYwEssAdGXbkHp47XrY4svJx X-Received: by 2002:aa7:c0d6:0:b0:467:7519:6bff with SMTP id j22-20020aa7c0d6000000b0046775196bffmr13865447edp.301.1668527452701; Tue, 15 Nov 2022 07:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668527452; cv=none; d=google.com; s=arc-20160816; b=iEVgjXlk1Aut9fBZt0IgtCETqb9yI/fS/ctfq4R/ra327xvmyXIBkD1ZBHG8m/mE23 8qheOc8dyI1QkOpi/nCgAsjz3HrMsjQmpoTehUcQcjG0ZDUEGSzdgJbkTDtLReWvRDPq B3JlhPYlYqAEINBj4nSgBrg23yG8BAyR9Ild/H7Ji6NE+5OZEtP9zSFg6G+zl9a489Cd 9pPA5G/9XuRiEyCsBpb0KU+zLxyRxjqU52jVq47QSsLMp1J4hIW2aWtnP8WGSQmicmzA IfJc7bd8V8Bxv+rOu07w8UP1q7/8o2VIam9OTEvh80GgkqJtFc1H2HXDB2xiKV/VliGf KzXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=cUFeRtZYB7UeTgxIn2ZhYMocLTGExrmRKO4xcP78LzE=; b=LqCuLSdK9+9w1Sq/3NyUcslKACiphDp7BHR6JdwKSYLogzSwpySuRgKzcCxusZbErE Nvh/TgVU2y1W4gRXB75xlJZfFi75ITRd8lkz7s2VWPk+A8qNMDTw7NEhlz36BNl+lMbE LQ3QXmU+aizXj8czIkB/GnEWnja4y75vjikT6IVbDfPTL8rrOsA9XFXHprYGBKclxGSk UdYaYrBeVElVZEHMO65vZz9A3ivUZWpeo1rqVRt4rLPeTrpjH1hDAo0nvLJxmtIneLZM vgUrjikRkLSbz0ZiyiKiG37VNii2fqb9b9Olsp2O5gAbW1Vkr0EC4bd1KeH5F7MUKsnU hqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Si5zz34w; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x25-20020aa7d399000000b00461c9bb5205si10559691edq.152.2022.11.15.07.50.28; Tue, 15 Nov 2022 07:50:52 -0800 (PST) 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=@google.com header.s=20210112 header.b=Si5zz34w; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbiKOPpx (ORCPT + 99 others); Tue, 15 Nov 2022 10:45:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231347AbiKOPps (ORCPT ); Tue, 15 Nov 2022 10:45:48 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779FF10565 for ; Tue, 15 Nov 2022 07:45:47 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-370624ca2e8so138944817b3.16 for ; Tue, 15 Nov 2022 07:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cUFeRtZYB7UeTgxIn2ZhYMocLTGExrmRKO4xcP78LzE=; b=Si5zz34w8W5OUKEmuwma1mET23o1UNMM0e+o9fGg5w5QBLXN0EQOINeapJXw0xkhN5 jIBGAQpEgsaEeu2F7RJfTUTekBnD5xmh7oO3DT9e/g5GH9xCDINR/nnIH1JQBtjCA8Ky cGd2mkkePepc9zsCKoQBhNWoANyqmXIHeOPNSUqILXJ+JDo0m+Fg58+w9dEi+qyzv9PK mkkEjCyPJL2UD0KfMddbIdEX6IIwT+BCGM1qp7vQZJ89JXMBRgZua0U4jSF0TfY/8A3L P5OCi+bq6OzDA/4TybR/avT7cMQ6ZUIN1MQpCKdkmJhl6PAQflUILq9El2VnyO7VmIPI Ckig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cUFeRtZYB7UeTgxIn2ZhYMocLTGExrmRKO4xcP78LzE=; b=UAoHqmIwUjv6pmHoHfLUzdnwzEEavYeH5PIg7sBNDDyfPF/szhhHAxawbSnelet5v9 z0C+rTMXMmMjyT+TW96ti0hrcMVK7WPJFJGkZqJWXx9oenxvbYNyHvw2uuDnntNLVeJr r4hN+leZO8qlwdt0o+9sr6ouXLGjrUhTAC6umz2gpNxv1hIXIdYj/G6wvKdNUvvbUKHK 7sBOQuExuKbLpKo7OAjBcxD910I9MbGVJ7oTkOoQfTHCzbevutu17iH+xWVSAiWUDy3C VafdGZfURm6GY7nByFRNSSM9fgGzQqgnsukO1BlRo8HPwk7WzopofWAry5rP+/Dam4+q 37FA== X-Gm-Message-State: ANoB5pmqsQSnvWCN+RWeDRP6OajdBGKggHz8xkbxLT2QpE5PV+NWQmG5 qP4LYytun7sphLNWJfh6IIc18IJgS/0egFZvPg== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:fe62:9ede:ae13:6fda]) (user=peternewman job=sendgmr) by 2002:a25:40ce:0:b0:6d5:34ad:10c5 with SMTP id n197-20020a2540ce000000b006d534ad10c5mr28033116yba.494.1668527146292; Tue, 15 Nov 2022 07:45:46 -0800 (PST) Date: Tue, 15 Nov 2022 16:45:14 +0100 In-Reply-To: <20221115154515.952783-1-peternewman@google.com> Mime-Version: 1.0 References: <20221115154515.952783-1-peternewman@google.com> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog Message-ID: <20221115154515.952783-2-peternewman@google.com> Subject: [PATCH v1 1/2] x86/resctrl: factor rdtgroup lock for multi-file ops From: Peter Newman To: Fenghua Yu , Reinette Chatre Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , James Morse , Stephane Eranian , Gaurang Upasani , Babu Moger , linux-kernel@vger.kernel.org, Peter Newman X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1749577842571151076?= X-GMAIL-MSGID: =?utf-8?q?1749577842571151076?= To help implement kernfs 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}(). The existing rdtgroup_kn_lock_live() could only release the kernfs lock for a single file before waiting on the rdtgroup_mutex. This refactoring should not result in any functional change. Signed-off-by: Peter Newman --- 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 e5a48f05e787..03b51543c26d 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2026,6 +2026,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); @@ -2033,8 +2053,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); @@ -2053,17 +2072,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,