From patchwork Fri Jul 28 16:42:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 127791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp591822vqg; Fri, 28 Jul 2023 10:37:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlE2aGa+zBx5MClkc7voNFfT+7yE8XjPvr1BRtsX1ac9gncCs8oS+DgODjg+GTDZZfpe6e+5 X-Received: by 2002:a05:6512:ac2:b0:4fb:74da:989a with SMTP id n2-20020a0565120ac200b004fb74da989amr2558218lfu.3.1690565822646; Fri, 28 Jul 2023 10:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690565822; cv=none; d=google.com; s=arc-20160816; b=PFu5/K+zuNyZ4KNF5k704D5isjdWuVk7OzE3bDJc5kAeV8zI1YIfhd20dAv20Zk0LH sfMIb7PqDkQ1CIgQ3aQxAfzME2Na/O4f8yhpd39eT5IxLC2F8Kb0dIs3ZcHYLBQreNCs tP/g9VlaGojFr26gJbILs3EK6KLdE2rthpxFXzeXXxF3yYqwTIjq8A5cPvWBG3Udy3iM 7lREcnK7VJpRSo/yazrAUVuCZA8L5lKaMRG/341PdmK53dmDenmDEpjVcVN0Kgwqw7gL c0rcm3+QDgT942ShODr9RR+fSmsTggE2VSoqpTKRrP6Lbd78FPGvXWQrVuX+2Xuf43Up sghQ== 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=yfjHi81RltcrpQriY41CLAJjgcnKoLIQqxoFqt/CVaU=; fh=n9L+e/Mo/wOalMjVbltm4zKnQoPh0Qbxoe+x3eznw8A=; b=OygdFaYyVucIk/OwphI2WJjQGRPikdhDTOFi7A4e8GNITOwIzdtPew+4ATBwSmwIFZ fhBhYTTg/E4RYKI5U7p4OonKaWrxm+AuHs5pm03Ssywow6JqpcX7Fb+dQ5KLBoqRHxV/ 2z6x59Ys4f9CQQ7i4OEp8bzVo0lHr9rI4Zr8oGOFNUGQGmEVUUrpFkhw3S7KxebGp+aK PvfXSYQmvgbD//DcPuAV0hfVdf/oOd9L5h6rWN8hATE1waZ8QQsyyOdkvQwBnUFLqH6e InxjVm/vpdkP1itdQlpd/cpO3fh9Xa7RwCr6u96NEUuFnJRII10qkC4wIYHAFsOguXP3 NMbQ== 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 sb9-20020a170906edc900b009937af8ac4asi2956810ejb.241.2023.07.28.10.36.37; Fri, 28 Jul 2023 10:37:02 -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 S233925AbjG1QwV (ORCPT + 99 others); Fri, 28 Jul 2023 12:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbjG1QwI (ORCPT ); Fri, 28 Jul 2023 12:52:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E3035278 for ; Fri, 28 Jul 2023 09:50:33 -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 4D29E1684; Fri, 28 Jul 2023 09:44:54 -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 82D6F3F67D; Fri, 28 Jul 2023 09:44:08 -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, dfustini@baylibre.com Subject: [PATCH v5 18/24] x86/resctrl: Make rdt_enable_key the arch's decision to switch Date: Fri, 28 Jul 2023 16:42:48 +0000 Message-Id: <20230728164254.27562-19-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230728164254.27562-1-james.morse@arm.com> References: <20230728164254.27562-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,T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1772686748375339583 X-GMAIL-MSGID: 1772686748375339583 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 23010fce5f8f..3876d4bb4bed 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 91a740e10865..ce1ed485e4f7 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2546,10 +2546,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; @@ -2817,9 +2815,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);