From patchwork Mon Mar 20 17:26:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 72348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1361183wrt; Mon, 20 Mar 2023 11:13:58 -0700 (PDT) X-Google-Smtp-Source: AK7set/HJaSJ9vlnX4HFA8ZAW9qY0y/g/VhFIhvAq4KUxlWHOcnU5gvxWVNgR1itJREMdN0k/fDq X-Received: by 2002:a05:6a20:4fa3:b0:da:2fdf:385e with SMTP id gh35-20020a056a204fa300b000da2fdf385emr1615464pzb.49.1679336037864; Mon, 20 Mar 2023 11:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679336037; cv=none; d=google.com; s=arc-20160816; b=aDf1q3FXx/ZmHgmUGReEYH43WFb3cYnXLCd3/HRwVtlNccEvnT/2J7Wr1Dz99qKJZu ZRtovV3huDThRht7sqS6HW+4Tsw7vu+zL/T9K+jRk9y2HBrEdeQAwWUn0pUolNwu+fnX Yu8gekwXwxy/KA1zV79O1kz21GeoE6SfDJWRTRofGJsVfYyq2d1kd5atpgCXZHl6yrUQ C5e1JNCPeOXXqneuJAYoeuG99fdLHpIbqB8gL8plx/nrQw/QhWJ6pVdaYBg0y2zj3hwu sgfvjgLVl7mlZFQjzkO1ib+N/mhL1Qxjhuuj09FHFwS6rgK3+9JsMai6RfEB1SH2DTts NoHw== 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=WPJz3dmnQWgZ9e3nKqn4+PmnB0T9NQF1YtwvWcOwApQ=; b=OUmhqTgBf9ERLKrI1FVAPsp5gc8X52yfX6fWxWHqjihGwE9yhwdob57VRQxpU183Oh Ft+2PjRxtrdwoOqCps4cHBmGhM4wJr+kc4dUITQglpuGyt2J9Qo56rwx1ih2yoC56VMP K5abRutN7ebt07Am8o4cvtzphY6UhzQukUqF0z8pcUy50CaBg0/CqCAFxZZa0bJcbmqN Xueiy3/7ztW8Iiv+veKioMKRrPjN1DxWX/Z17px/9LnJuAfeqHxvFecq248d1HpWrBiP msOLHUffbxrjUDzOunq5LoAIG4Q7nWFzX1tFSr3Bd6Bwzqb1jkSvOiCGHKlpQmu01jiX 5hvA== 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 f5-20020a056a0022c500b005a8d684c05dsi12053891pfj.271.2023.03.20.11.13.44; Mon, 20 Mar 2023 11:13:57 -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; 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 S230134AbjCTRsM (ORCPT + 99 others); Mon, 20 Mar 2023 13:48:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjCTRrT (ORCPT ); Mon, 20 Mar 2023 13:47:19 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 622983B21D for ; Mon, 20 Mar 2023 10:42:48 -0700 (PDT) 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 612D51BB0; Mon, 20 Mar 2023 10:28:34 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DD8FF3F67D; Mon, 20 Mar 2023 10:27:47 -0700 (PDT) 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 v3 14/19] x86/resctrl: Make rdt_enable_key the arch's decision to switch Date: Mon, 20 Mar 2023 17:26:15 +0000 Message-Id: <20230320172620.18254-15-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230320172620.18254-1-james.morse@arm.com> References: <20230320172620.18254-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?1760911465010858297?= X-GMAIL-MSGID: =?utf-8?q?1760911465010858297?= 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 there are helpers for enabling 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 5fdfcd5f943e..147af2b43385 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 c6c31efb85ac..2ca8981c7d0d 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2514,10 +2514,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; @@ -2785,9 +2783,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);