From patchwork Fri Dec 15 17:43:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 179479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9458941dys; Fri, 15 Dec 2023 09:48:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKOh7wofJIr/LXPFeekQJhYnbHRMAOSm2vuAjBQEkXElbE/nVWm2tMUAfRuKvmv8+XCO8w X-Received: by 2002:a17:902:d4cf:b0:1d3:45c8:bc3b with SMTP id o15-20020a170902d4cf00b001d345c8bc3bmr4088915plg.87.1702662531605; Fri, 15 Dec 2023 09:48:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662531; cv=none; d=google.com; s=arc-20160816; b=qh7+h4zAIfRyiyn7T5jH+w6KyU2Y3YI9lchw3ipoW/Yz3OmKfkkmyukEEwM/i22hjR psPlNkfpq1D3Ay7gFxRCEoOsvL5YMPZ/oC6LWt4RANe+4ie62ySndqU/jmORMCZV1x2l 9OT+f/frEktcxml0tNkaMGxYVm4f8rPb2bxFb9ngVqrtHp0kM6RbgkqQwnTFwvgnKydD FP9SQvsOl2g2mJ0F9ZhAFjxgN0ZobMOb4sz6zAOmEuIVVW5lkth+F+A5ArhcK+/O6T3I MI4B2MezMy7B2FStyzzI8zroSIJRzK1JlyZyVNHB/VuyY+rlUmQoXu7OoDQMD2QUbYEx U8OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=G2IBflZpaGFotCqSs7OnkwIVb9t4G/3T6Kp2hfgm414=; fh=B41BSS80/g48MVbql1jW7CCXTAGMSWslnmHIfPLpVL4=; b=qtBEm2Bh3DjA7rKhrIgyIIWWlGGMDlbOe1hR4piKDhgH34cg05YDheE/MhELfUEWpd OWD0NZN+NNFv1OEC+3eOMaEEhXMJW3c5atQ6/4HY6hDzGk/IFk8Sk3lDUTq/Q5cephb5 Qis2zSUoJo7V0EjaWptq4gLUysJ2E5pZD5sziHDLBUE3zbKQ00MP8o2zx+WYN5EQW/Z6 oh2LiSFDvXw8npkkd7FU3AoQaKuV84ICpifIr7KonDzlhn0I7Lok2sn5aHx2VcLnz6Ne UALwIK5Ci/1LrCehaxVRofeAkl24UtKnA3fKZvWD0M+osp96cHNPw5WaEzy6hT1RcqOH 7iSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1457-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1457-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y1-20020a17090322c100b001d3752f111csi2506522plg.222.2023.12.15.09.48.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:48:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1457-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1457-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1457-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 49A6F28A4C9 for ; Fri, 15 Dec 2023 17:48:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 703A659E55; Fri, 15 Dec 2023 17:45:01 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05A8841866 for ; Fri, 15 Dec 2023 17:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 823051063; Fri, 15 Dec 2023 09:45:42 -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 8EBD53F5A1; Fri, 15 Dec 2023 09:44:54 -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, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, Babu Moger Subject: [PATCH v8 18/24] x86/resctrl: Make rdt_enable_key the arch's decision to switch Date: Fri, 15 Dec 2023 17:43:37 +0000 Message-Id: <20231215174343.13872-19-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231215174343.13872-1-james.morse@arm.com> References: <20231215174343.13872-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785371067129864685 X-GMAIL-MSGID: 1785371067129864685 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. Signed-off-by: James Morse Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- 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 3c9137b6ad4f..b74aa34dc9e8 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 8cc5a0937fa8..74a8494a0c91 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2677,10 +2677,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; @@ -2951,9 +2949,10 @@ static void rdt_kill_sb(struct super_block *sb) rdtgroup_default.mode = RDT_MODE_SHAREABLE; schemata_list_destroy(); rdtgroup_destroy_root(); - 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);