From patchwork Fri Jan 13 17:54:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 43524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp409182wrt; Fri, 13 Jan 2023 10:04:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQdJHsLbZTo8Kfx+qU9ClfGqV8jGTVWnlIkLqgRxEZMqFe7kDmuOAg0PuGhzo7oH2rDrbs X-Received: by 2002:a17:90a:fe89:b0:226:e59a:f869 with SMTP id co9-20020a17090afe8900b00226e59af869mr28637131pjb.43.1673633096755; Fri, 13 Jan 2023 10:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673633096; cv=none; d=google.com; s=arc-20160816; b=rawVxt8C+ORDIOo1Bq+2HU+206zPIrHkod1EVU7iqqgwoDgb1dg86A3DG6/2uNCkCT XFnj4odX2AIIHIHrHPum4eaYBZuCEJuDB80un9caKO3Ve3pkZvfsVe4qPRicig7XOL89 dGSIFQcFcotQulcNUdzF8b6NRFwhwitAWiBevzh7B6zz3QOtf/0j3nWMUyWaBDWWjagi HEfd2JcdXfpnhUG16i5apwDvzbRNVTmcRN5hly73nPXNZnchhy5Lwd2vKQMWZcahMPaw mMZ6IuJbzGlW1fL9r2fNJio9Y2P33mqb2wwuPKZUqkl4vuRMl7GOLnyW3cpAiaRq13Fs 09ng== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PaidQAY9JaqUgg3KSQTT1MYXC6yCEIQZtwljGeifgUE=; b=jpID89vS1Nbb1CFxr58C2NGnwmAVEQ6ObQvVQskMDRUbg39lW8zl1csJFzZXNu53i3 KN4aRgxLeTpD4aINlV2Ze9jUxlcKOTFpyseaT+a7X+Bc4z+pV74GMpYFl3BdNyZVqohk aYvkfZyEvUsy+yIQGMYmvxXjiZagw+uW6yN4R3tPAJyA6pAOaRl6AIsb5ZjxWaUYyG08 7ow+zGHrZdPW0X8kpLXfESFN8nRgzljQeBOwPGtxM4Kh3aYuem89HmUsRAMUdUu7aq/z j+dQDCN6HBUxZ3YY4RkbJkAibLlGDVegKhrA7abenXhvlFEdvXSy+8HrHeTnm7Gbx4mH 3GmQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020a63fd4a000000b0047818d62c89si21037951pgj.237.2023.01.13.10.04.38; Fri, 13 Jan 2023 10:04:56 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbjAMSDZ (ORCPT + 99 others); Fri, 13 Jan 2023 13:03:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjAMSBi (ORCPT ); Fri, 13 Jan 2023 13:01:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 79CCE2672 for ; Fri, 13 Jan 2023 09:56:18 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 489A61763; Fri, 13 Jan 2023 09:57:00 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 996803FA58; Fri, 13 Jan 2023 09:56:15 -0800 (PST) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com Subject: [PATCH v2 13/18] x86/resctrl: Make rdt_enable_key the arch's decision to switch Date: Fri, 13 Jan 2023 17:54:54 +0000 Message-Id: <20230113175459.14825-14-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230113175459.14825-1-james.morse@arm.com> References: <20230113175459.14825-1-james.morse@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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?1754931498020336441?= X-GMAIL-MSGID: =?utf-8?q?1754931498020336441?= rdt_enable_key is switched when resctrl is mounted. It was also previously used to prevent a second mount of the filesystem. Any other architecture that wants to support resctrl has to provide identical static keys. Now that we have helpers for enablign and disabling the alloc/mon keys, resctrl doesn't need to switch this extra key, it can be done by the arch code. Use the static-key increment and decrement helpers, and change resctrl to ensure the calls are balanced. Tested-by: Shaopeng Tan Signed-off-by: James Morse --- arch/x86/include/asm/resctrl.h | 4 ++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 11 +++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index d6889aea5496..5b5ae6d8a343 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -45,21 +45,25 @@ DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key); static inline void resctrl_arch_enable_alloc(void) { static_branch_enable_cpuslocked(&rdt_alloc_enable_key); + static_branch_inc_cpuslocked(&rdt_enable_key); } static inline void resctrl_arch_disable_alloc(void) { static_branch_disable_cpuslocked(&rdt_alloc_enable_key); + static_branch_dec_cpuslocked(&rdt_enable_key); } static inline void resctrl_arch_enable_mon(void) { static_branch_enable_cpuslocked(&rdt_mon_enable_key); + static_branch_inc_cpuslocked(&rdt_enable_key); } static inline void resctrl_arch_disable_mon(void) { static_branch_disable_cpuslocked(&rdt_mon_enable_key); + static_branch_dec_cpuslocked(&rdt_enable_key); } /* diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index bbad906f573a..0e22f8361392 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2247,10 +2247,8 @@ static int rdt_get_tree(struct fs_context *fc) if (rdt_mon_capable) resctrl_arch_enable_mon(); - if (rdt_alloc_capable || rdt_mon_capable) { - static_branch_enable_cpuslocked(&rdt_enable_key); + if (rdt_alloc_capable || rdt_mon_capable) resctrl_mounted = true; - } if (is_mbm_enabled()) { r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; @@ -2514,9 +2512,10 @@ static void rdt_kill_sb(struct super_block *sb) rdt_pseudo_lock_release(); rdtgroup_default.mode = RDT_MODE_SHAREABLE; schemata_list_destroy(); - resctrl_arch_disable_alloc(); - resctrl_arch_disable_mon(); - static_branch_disable_cpuslocked(&rdt_enable_key); + if (rdt_alloc_capable) + resctrl_arch_disable_alloc(); + if (rdt_mon_capable) + resctrl_arch_disable_mon(); resctrl_mounted = false; kernfs_kill_sb(sb); mutex_unlock(&rdtgroup_mutex);