Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp602974lqp; Thu, 21 Mar 2024 09:59:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVGDloVPT3OF8S1mvn+pemSBW+yiSFIXDNHc2Vi5ycjL+4dDaMIg+umnKPmClpFKbiUHwlENfQ4QdOr984IqmCtG8/dSkq2I+nhvCoDQ== X-Google-Smtp-Source: AGHT+IFg1QWRN3mo2if2NSUlFhzUqvlk75e3MtvPGGy8z1pp9Rd+ppnVCTF4CjvkQHa3Br6nrwPr X-Received: by 2002:a05:6a21:3997:b0:1a3:55d2:1489 with SMTP id ad23-20020a056a21399700b001a355d21489mr142458pzc.7.1711040397846; Thu, 21 Mar 2024 09:59:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711040397; cv=pass; d=google.com; s=arc-20160816; b=NqUCsJqTgjw4sHksLF6bGp6XhPsClcXv4D6QIN+Zty7t+gEJvJTcbRsXw1EFb/1XVs Lk5q1dZN1Iti5xgSteyd8ALlkWnWCWuZrdwdW+EAR/fxvrEmj6mbZ03SjRCV6cpvRMHK /Ca4X45+JaqnF2DVpWIrlUClRvHgquvBnE1iM5tNpoSn16EcDxXWCzD49zRXA8bTxfrf cnUzbEPEJHISextL9lcaxOxMHqiBrEgAx7KW8dEIhRSZJCKQ0LKHqFY8njrPQO+iHJNv KzEZerrIAN6YfptU0VqtnTUOKHuS+UeONaRnqnoenaszUYPLVswdRemFu2ybcClc0vRo TNDg== 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=iqpsT2D02gQeKn7tnIxoEIuBlCNE1wRuthbuAGbA7pM=; fh=knouHfhWmUABu+sT2q0nnGKUzC7/WRiZH1KSpGv7uFs=; b=pgNrffCJnBBjWkzbdqcTXS/BW6it2Uo6eS0iUDb99BZWHrD0UY/nFJeJ/sTE51tWg5 oBYWgfkfQ+Z2NFVH26cziLSfCrRVDOFd1l0r25excEGA+L2tDVnNlWShPbvp8Uo/DInR 6AazrqeD5XSFs4Onx5yVwf9TZRqC+apRrBklvIPQMdmp4Gr/4EwHDyOBkySOfVoZjRKj 69+IiSFxMRvh2IDPxonhnSUW39WlJpUNPbGQGcDv/1fAiLE2f6W12K4k/osE9BStelQB nIJITb0D+Dnq64QMTQ2Bvyqwi32zd4DIay+2+qRnxBU378HyTaITTKDRjaLYhoSeiii2 QplA==; 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-110420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110420-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 e6-20020a63e006000000b005dc89485b21si125866pgh.535.2024.03.21.09.59.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:59:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110420-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-110420-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110420-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 E2D8F280366 for ; Thu, 21 Mar 2024 16:59:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E26291386C2; Thu, 21 Mar 2024 16:51:44 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6E1F1386A4 for ; Thu, 21 Mar 2024 16:51:42 +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=1711039904; cv=none; b=gLpGk+OqfFULUQ2hPDqYX3Kxu8KyzrRfJikLQZHxZttkcuOJyzGvQxFB1nfbSo42Qs7I9NAXUpFyQ2A2KX3nrXzvbB9u6v6hsPe65f8o4u2MkvI5K85Xrs3KsxM2okZjGcuWZKODKSUGjq080IwMUqR+az4bgJUtiz/84ShFJhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039904; c=relaxed/simple; bh=hu9mtLJGF/MyobQYIaeWa1a64zsBcn1pF6EnLBJKSxo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u3nat7UNsFOHg++r7pnBhYpVXBGvNdpjy0HOwYaGjovCI7a7TYlhZzQ/0eBuczFbTOmalrsgFNFwheSNY/Bh0MLopCbzQI7O1X+gRumuJtf9S941vIKABclRG+ouOcGDxEOaXb+ScqzXflSZCNNzPGE8gnUo/bKfrrORYgkY9xc= 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 BCD6E1063; Thu, 21 Mar 2024 09:52:16 -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 7C60A3F67D; Thu, 21 Mar 2024 09:51:39 -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, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin Subject: [PATCH v1 04/31] x86/resctrl: Add helper for setting CPU default properties Date: Thu, 21 Mar 2024 16:50:39 +0000 Message-Id: <20240321165106.31602-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240321165106.31602-1-james.morse@arm.com> References: <20240321165106.31602-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 Content-Transfer-Encoding: 8bit rdtgroup_rmdir_ctrl() and rdtgroup_rmdir_mon() set the per-CPU pqr_state for CPUs that were part of the rmdir()'d group. Another architecture might not have a 'pqr_state', its hardware may need the values in a different format. MPAM's equivalent of RMID values are not unique, and always need the CLOSID to be provided too. There is only one caller that modifies a single value, (rdtgroup_rmdir_mon()). MPAM always needs both CLOSID and RMID for the hardware value as these are written to the same system register. As rdtgroup_rmdir_mon() has the CLOSID on hand, only provide a helper to set both values. These values are read by __resctrl_sched_in(), but may be written by a different CPU without any locking, add READ/WRTE_ONCE() to avoid torn values. Signed-off-by: James Morse --- arch/x86/include/asm/resctrl.h | 14 +++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 12dbd2588ca7..f61382258743 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -4,8 +4,9 @@ #ifdef CONFIG_X86_CPU_RESCTRL -#include #include +#include +#include /* * This value can never be a valid CLOSID, and is used when mapping a @@ -96,8 +97,8 @@ static inline void resctrl_arch_disable_mon(void) static inline void __resctrl_sched_in(struct task_struct *tsk) { struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state); - u32 closid = state->default_closid; - u32 rmid = state->default_rmid; + u32 closid = READ_ONCE(state->default_closid); + u32 rmid = READ_ONCE(state->default_rmid); u32 tmp; /* @@ -132,6 +133,13 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val) return val * scale; } +static inline void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, + u32 rmid) +{ + WRITE_ONCE(per_cpu(pqr_state.default_closid, cpu), closid); + WRITE_ONCE(per_cpu(pqr_state.default_rmid, cpu), rmid); +} + static inline void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 45372b6a6215..5d2c1ce5b6b1 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3623,14 +3623,18 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) { struct rdtgroup *prdtgrp = rdtgrp->mon.parent; + u32 closid, rmid; int cpu; /* Give any tasks back to the parent group */ rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask); /* Update per cpu rmid of the moved CPUs first */ + closid = rdtgrp->closid; + rmid = prdtgrp->mon.rmid; for_each_cpu(cpu, &rdtgrp->cpu_mask) - per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid; + resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid); + /* * Update the MSR on moved CPUs and CPUs which have moved * task running on them. @@ -3663,6 +3667,7 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp) static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) { + u32 closid, rmid; int cpu; /* Give any tasks back to the default group */ @@ -3673,10 +3678,10 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); /* Update per cpu closid and rmid of the moved CPUs first */ - for_each_cpu(cpu, &rdtgrp->cpu_mask) { - per_cpu(pqr_state.default_closid, cpu) = rdtgroup_default.closid; - per_cpu(pqr_state.default_rmid, cpu) = rdtgroup_default.mon.rmid; - } + closid = rdtgroup_default.closid; + rmid = rdtgroup_default.mon.rmid; + for_each_cpu(cpu, &rdtgrp->cpu_mask) + resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid); /* * Update the MSR on moved CPUs and CPUs which have moved -- 2.39.2