From patchwork Tue Feb 13 18:44:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 200576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp754948dyb; Tue, 13 Feb 2024 11:14:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX3w1GbqPYOK+lm997u133v0eTqlrUbHLHFe+PW43j86p0iWXHIxzTCassIqDIbJfmAKWd/UclvUn+3gZKhO2n9/uEz6Q== X-Google-Smtp-Source: AGHT+IEHXd3QgiMHEYS83idbEWEZzuKnuUys7HLOmTnrzwaakLPV/gDXQydKboFkBmjCChbfFjVu X-Received: by 2002:a17:902:82ca:b0:1d9:63e2:680a with SMTP id u10-20020a17090282ca00b001d963e2680amr408620plz.24.1707851668480; Tue, 13 Feb 2024 11:14:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707851668; cv=pass; d=google.com; s=arc-20160816; b=WreUhlgMkAIGN4xSmS5uOcr/YGt637d3oTExupS86uV3cYxYCerou3rSHP0HhoEIVy NABJC6oxTFMp7NYOGhlMgSJDYUudkPSnZDkeMhZmHbFx/u63nKBaUnq2516LwANr9+Du A/k/dP1AwUrMj6REa/tfFzW7k8ClrLjn//YHfeBlO8UdDxWyEJmGW9HqdTxCwIVFP0Ft xQVrI48VrIYdLFVSxXUAorTIuxqRkewLhzapT0DXrgaxDwQrl067bAIdcW7iZSb3O6l3 vXXaJaglTyBhxEUACXTnsRuVC26Tp9YfJiPyXYGugLGrRUEUOqwC0Gy7aH4xvOBat57K josA== ARC-Message-Signature: i=2; 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=dyg1PQBXjzOurYsqs4MsUkQbyNLjRgUYb1TxLj6nCEU=; fh=TIs4PTuzSMCW1Sfje5KP6cWhkWVWXYmbfsx/8bwFJXw=; b=MIEJrqNuyge86EhldSAVuwd4p25IpS1yBazpUlbuPKdWHwtSMBMbcShZDmI1KtS4a5 D1Vl3dfPEQRVZZLNk9deVMPspP9vmXo+P63s+lhlCgJQzmegfYArgh5NmRadVewWuTWp yZxh3AmiLFWD5QYpB2IcDZoaNgCa0G/idzUHqNNutSNp/vg6Ysdm7X2r8qgy6XSNgeuo xLbXOuzrrO5hG4rm+43+CcqNV12vxUL3ZJRkwWrhzY7vofBeHuscTJtlqS5z1SqZDrbK Q3X3QD1WUb2mCsELsir2LFizMcMVb4U8ore0MG6RJv2LkdP07yvEkQPwnfqc+pC/+Aeq Oqeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64109-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64109-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVNFTKVk+CwXXAVuIjCIf1TnknWcEaB9Pr4bqDaWaHdQJOtyGN7VN2qKl1ipP5wStnfHH85FCuV0Yoig8gq4PGi2bOIjw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id qj6-20020a17090b28c600b00297315d3f7bsi2529282pjb.26.2024.02.13.11.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:14:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64109-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64109-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64109-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8F04FB26579 for ; Tue, 13 Feb 2024 18:49:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 989C36088D; Tue, 13 Feb 2024 18:46:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94C955FB88 for ; Tue, 13 Feb 2024 18:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849964; cv=none; b=upvH4ghxjxXfH2VP4hUYdl9Pbw50ZGGuUGB6Px140XTw5LY5QC0AdNaCZNOZHLWwDRPMU+5OfNUToEQHoYqiQ1BGmzq2/GMrMAar30zqToMRWvdwVjuBG684UsnYloUcsHI653K2jnU/RqxaIrRQphd6YSduFYMRrM4tRD9+lHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849964; c=relaxed/simple; bh=GBgK+HKsOLOZBaUQG/gKw1CrHgLc7JCW+Za9mnYk4R8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c3jZQS4xYpHp2JKT4mO5XPhsSGHWW57R1EF6vHQ5TdHCs0nvVSUALnsFdvEABr8orfgm5Upr51IUOzUwDJgsq2/bVJZQn1ubVDTlVtyoHwSmqEKPXoZl8CzsXpdn/y1VFUWgRAjKpuojrFL/9kLzIzG2HCnrjkCxqzd0jLBpt40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 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 4C52B15A1; Tue, 13 Feb 2024 10:46:43 -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 E8A6D3F766; Tue, 13 Feb 2024 10:45:58 -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, David Hildenbrand , Babu Moger Subject: [PATCH v9 18/24] x86/resctrl: Make rdt_enable_key the arch's decision to switch Date: Tue, 13 Feb 2024 18:44:32 +0000 Message-Id: <20240213184438.16675-19-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240213184438.16675-1-james.morse@arm.com> References: <20240213184438.16675-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: 1790812270950718437 X-GMAIL-MSGID: 1790812270950718437 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 Tested-by: Carl Worth # arm64 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 231207f09e04..7e57ac9d81f7 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2672,10 +2672,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; @@ -2946,9 +2944,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);