Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp40846lqg; Fri, 26 Apr 2024 08:15:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVA0G/NVScymYKvV3zav8f6C4mqMrBAyH6/pS1UfdvNdBhkNEHHbJF9j+DXc5pJMTf22FYDVji43tWDg+LzAlNgSahwQBA6LcVAnywxtw== X-Google-Smtp-Source: AGHT+IFRfbXphDrywV9iMVriEqLJQjzf6LBzIW6wCH9wACoFJeqzsbZxXEud7ri1b4AhpIl5+87v X-Received: by 2002:a17:90a:5d8b:b0:2aa:9ae9:31ac with SMTP id t11-20020a17090a5d8b00b002aa9ae931acmr2667809pji.28.1714144511525; Fri, 26 Apr 2024 08:15:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714144511; cv=pass; d=google.com; s=arc-20160816; b=MqA4Yw+euLK+c0RrKALcI6mrvKa96JlmYPNuPFBrD+EryVe8itun+Di3wo829O/Cfk OIeN321GngZcnVZHbN47WMmv73qLWvH1+tl5E04YRLobey/xKZ9xI1ibLtr24CqLh//W UC00/HUVU6uqGhN6QuLOBRbHsfLG68wYGNg/DYUNefnqTpxU9anh1RNt+yiEBfqbez3I pqil+gJYBiZEe0E6SGghbfGKRcE/cRXUilo/nyw/btyMQ2sFrHooAfFYDO+ztwhQyzvb Egd0RVCYLHHfErYS3vSPLf6eUPgV9HxKFIaS4inl9bj9gwzFNksbP1wqfS/mo6faWOd6 DNCQ== 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=tSAkjMKJ9RbT9tvCSmYKH09KKYLKdLtKiykH6bVOcFo=; fh=Vo4MxA0u7CmSKYL/GjcyKHwusyvU+nKR43bqJem+vcY=; b=WCNbszCdwoVKMA2P0sXChbBfg81l64pLkt4kj67Fr8sjBnqImzlYOkVnQzWGxcdjBB Pzgfv4i8Pv1urDosQmA53ufVmPRHBnF7n9KZAv5QsbEXZdksQuePzueTM31GfxJr8tyt RJmba81JAvWx6slCeKFeTVjxkUx5q7SYcooK7zHEunKOqI0e2gyhIC9jQj9yI2FVRBTd DoxyMQZ5rJLmoRmnS6knnkNqWSsGTZhtkgtZw6f3rJOPhrM0JlU4Dh0cUfBHiVZ852RR Q940OG+IrJScATG4SuMR+azxqxVZ6WTF+Xs7sIDNPCqS23lfI28PQ2/dWcXxNpr3/hQo 1pEg==; 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-160238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160238-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l8-20020a17090b078800b002ab34eb171bsi17019981pjz.43.2024.04.26.08.15.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:15:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-160238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160238-linux.lists.archive=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 4B5022826C2 for ; Fri, 26 Apr 2024 15:14:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4322716F836; Fri, 26 Apr 2024 15:10:17 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C41A16F824 for ; Fri, 26 Apr 2024 15:10:15 +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=1714144216; cv=none; b=U61uYSJS/X+P3JVEzopOgUyMDX4QnL2s59bUAuFSf6UN09+XCRBIfogqQzer2KL65fVi4p8n8gY8lV5fcmrZmeKmKMghNjjOYoDrYIEyUoLOGZTJGy1/TKkQD2u3hDpH4cauAI7QNAl1wxM0z/EjShjz0n+oVAFLbNwRdQfm4KI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714144216; c=relaxed/simple; bh=Y0vJ2VIICzaEAp6dvb4JNuwfoarLYyuvimMCr6UcrMM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D/jkMyYeh3FnUbYDs0S43eDVsSdANJcq589AU0i0iFzkcCDAvV3IY6MdvSG+DMTFqLF34hO2KIHnVpvS+Rk1hF+yqllMNvT99Pt59/Rw2Sifip9kBdBdGgT6vj5yod7zw2g7UxiyAL64lUkTG9qtDV/+1hyLHvTZlwVYdNkNAWI= 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 CFCBC15DB; Fri, 26 Apr 2024 08:10:42 -0700 (PDT) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9BDBF3F73F; Fri, 26 Apr 2024 08:10:11 -0700 (PDT) From: Dave Martin To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: James Morse , Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, "Shaopeng Tan (Fujitsu)" , baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , Peter Newman , dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie Subject: [PATCH v2 20/35] x86/resctrl: Allow an architecture to disable pseudo lock Date: Fri, 26 Apr 2024 16:08:49 +0100 Message-Id: <20240426150904.8854-20-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426150904.8854-1-Dave.Martin@arm.com> References: <20240426150537.8094-1-Dave.Martin@arm.com> <20240426150904.8854-1-Dave.Martin@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: James Morse Pseudo-lock relies on knowledge of the micro-architecture to disable prefetchers etc. On arm64 these controls are typically secure only, meaning linux can't access them. Arm's cache-lockdown feature works in a very different way. Resctrl's pseudo-lock isn't going to be used on arm64 platforms. Add a Kconfig symbol that can be selected by the architecture. This enables or disables building of the pseudo_lock.c file, and replaces the functions with stubs. An additional IS_ENABLED() check is needed in rdtgroup_mode_write() so that attempting to enable pseudo-lock reports an "Unknown or unsupported mode" to user-space. Signed-off-by: James Morse --- Changes in v2: * [Commit message only] Typo fix: s/psuedo/pseudo/g --- arch/x86/Kconfig | 7 ++++ arch/x86/kernel/cpu/resctrl/Makefile | 5 +-- arch/x86/kernel/cpu/resctrl/internal.h | 48 +++++++++++++++++++++----- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 +- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 7aed87cbf386..e071e564452e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -481,6 +481,7 @@ config X86_CPU_RESCTRL depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD) select KERNFS select PROC_CPU_RESCTRL if PROC_FS + select RESCTRL_FS_PSEUDO_LOCK help Enable x86 CPU resource control support. @@ -506,6 +507,12 @@ config X86_FRED ring transitions and exception/interrupt handling if the system supports. +config RESCTRL_FS_PSEUDO_LOCK + bool + help + Software mechanism to pin data in a cache portion using + micro-architecture specific knowledge. + if X86_32 config X86_BIGSMP bool "Support for big SMP systems with more than 8 CPUs" diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/resctrl/Makefile index 4a06c37b9cf1..0c13b0befd8a 100644 --- a/arch/x86/kernel/cpu/resctrl/Makefile +++ b/arch/x86/kernel/cpu/resctrl/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o -obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o pseudo_lock.o +obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o +obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o +obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) += pseudo_lock.o CFLAGS_pseudo_lock.o = -I$(src) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 238b81d3f64a..d6db15839dc4 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -489,14 +489,6 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_domain *d, unsigned long cbm); enum rdtgrp_mode rdtgroup_mode_by_closid(int closid); int rdtgroup_tasks_assigned(struct rdtgroup *r); -int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); -int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp); -bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm); -bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d); -int rdt_pseudo_lock_init(void); -void rdt_pseudo_lock_release(void); -int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp); -void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); int closids_supported(void); void closid_free(int closid); @@ -529,4 +521,44 @@ void rdt_staged_configs_clear(void); bool closid_allocated(unsigned int closid); int resctrl_find_cleanest_closid(void); +#ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK +int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); +int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp); +bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm); +bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d); +int rdt_pseudo_lock_init(void); +void rdt_pseudo_lock_release(void); +int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp); +void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); +#else +static inline int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp) +{ + return -EOPNOTSUPP; +} + +static inline int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp) +{ + return -EOPNOTSUPP; +} + +static inline bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm) +{ + return false; +} + +static inline bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d) +{ + return false; +} + +static inline int rdt_pseudo_lock_init(void) { return 0; } +static inline void rdt_pseudo_lock_release(void) { } +static inline int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp) +{ + return -EOPNOTSUPP; +} + +static inline void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp) { } +#endif /* CONFIG_RESCTRL_FS_PSEUDO_LOCK */ + #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 38436e4c1741..6ca986d3f5f2 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1450,7 +1450,8 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, goto out; } rdtgrp->mode = RDT_MODE_EXCLUSIVE; - } else if (!strcmp(buf, "pseudo-locksetup")) { + } else if (IS_ENABLED(CONFIG_RESCTRL_FS_PSEUDO_LOCK) && + !strcmp(buf, "pseudo-locksetup")) { ret = rdtgroup_locksetup_enter(rdtgrp); if (ret) goto out; -- 2.34.1