From nobody Sun Feb 8 07:22:05 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13678524DD; Mon, 19 Feb 2024 18:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367861; cv=none; b=afdLWihXoxbcL2dpYLv1UNctyCHuYGFpmquL5ffIZyDlvS+tPHWOfOdFNhOmtjOQ0dbLejTYxhTLCRq0sxGwh/wUFpAJfkAlVWv4/4yfJlV6EkqbyMpu7ppDjZJFhQfdy9L7jf85Y6m1qpsTO1WJK9K2FHirGgUSMnGntKYquZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367861; c=relaxed/simple; bh=tUtrY79YAqX4M+Tz94D4J/f6c0DV9z7rZa/bNyExzsU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=qBspmFIUvlL1rBIpQkWkRUFRMJADtJRGqQW+TpkOyC/hdDaoSr0is2gMLOGA0fap8wnWiM2tz9sD1f/4t/aqUJUjOPLPu6W530GOOW6seZ2Df0vvtR88z2mdt79/n2bA87Eg8HrflkbM1tDD6ynY9rCl7840ctEOE85PyvgFwQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WcmoeVJ3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3v1iChid; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WcmoeVJ3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3v1iChid" Date: Mon, 19 Feb 2024 18:37:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708367857; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tu6FJ9xhhYXX3pgLppJ9uAaNstlFmxXjTl6koTxXxG0=; b=WcmoeVJ3Gbv7tMvAfN14n/Fnq+x6jY5OUrVwRY8sXNIBojSMXQhKs90/tmr6pFv+XftC6J 5idJYS9mLe29VNPhqJTyrgo8oBSe1Kw3t9MZzeFcXm9uqnM4eJe8hYHm3Q8aoxHOaRRNLW sb4uqzUpzAnT8XCUhQrBs3Z9FNL0zQJ/t03dSr6i/Et5wLwFpMLBZmK+9l7J2EA7fMp2pw cr8y93AlRaNEiWRrw/8/ANGOqEocKQsCTZ1bBuw3nDqQkCuyaSlY3kiRPhiVrhuq9wpAq2 kV4wyDwbiHaXdaEowxQAilD2MFwE6QM/m21R02gxHzIZ05A45pqint2n76Jahg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708367857; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tu6FJ9xhhYXX3pgLppJ9uAaNstlFmxXjTl6koTxXxG0=; b=3v1iChidDCmptlO+NBbBDoDl7KsqtFLsI9b8F1VSzolRiKRNbTEVeFujU6TsnRcHp+yFd3 5b3ilkVOU+vAzKBg== From: "tip-bot2 for James Morse" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Allow RMID allocation to be scoped by CLOSID Cc: James Morse , "Borislav Petkov (AMD)" , Shaopeng Tan , Reinette Chatre , Babu Moger , Peter Newman , Carl Worth , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240213184438.16675-8-james.morse@arm.com> References: <20240213184438.16675-8-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170836785664.398.2250904883339911498.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/cache branch of tip: Commit-ID: c4c0376eefe185b790d89ca8016b7f837ebf25da Gitweb: https://git.kernel.org/tip/c4c0376eefe185b790d89ca8016b7f837= ebf25da Author: James Morse AuthorDate: Tue, 13 Feb 2024 18:44:21=20 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 16 Feb 2024 19:18:31 +01:00 x86/resctrl: Allow RMID allocation to be scoped by CLOSID MPAMs RMID values are not unique unless the CLOSID is considered as well. alloc_rmid() expects the RMID to be an independent number. Pass the CLOSID in to alloc_rmid(). Use this to compare indexes when allocating. If the CLOSID is not relevant to the index, this ends up compar= ing the free RMID with itself, and the first free entry will be used. With MPAM= the CLOSID is included in the index, so this becomes a walk of the free RMID entries, until one that matches the supplied CLOSID is found. Signed-off-by: James Morse Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Link: https://lore.kernel.org/r/20240213184438.16675-8-james.morse@arm.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 43 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index cbba782..872ba1a 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -543,7 +543,7 @@ void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgr= p); struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); int closids_supported(void); void closid_free(int closid); -int alloc_rmid(void); +int alloc_rmid(u32 closid); void free_rmid(u32 closid, u32 rmid); int rdt_get_mon_l3_config(struct rdt_resource *r); void __exit rdt_put_mon_l3_config(void); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index bc5ceef..c49f2e8 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -344,24 +344,49 @@ bool has_busy_rmid(struct rdt_domain *d) return find_first_bit(d->rmid_busy_llc, idx_limit) !=3D idx_limit; } =20 +static struct rmid_entry *resctrl_find_free_rmid(u32 closid) +{ + struct rmid_entry *itr; + u32 itr_idx, cmp_idx; + + if (list_empty(&rmid_free_lru)) + return rmid_limbo_count ? ERR_PTR(-EBUSY) : ERR_PTR(-ENOSPC); + + list_for_each_entry(itr, &rmid_free_lru, list) { + /* + * Get the index of this free RMID, and the index it would need + * to be if it were used with this CLOSID. + * If the CLOSID is irrelevant on this architecture, the two + * index values are always the same on every entry and thus the + * very first entry will be returned. + */ + itr_idx =3D resctrl_arch_rmid_idx_encode(itr->closid, itr->rmid); + cmp_idx =3D resctrl_arch_rmid_idx_encode(closid, itr->rmid); + + if (itr_idx =3D=3D cmp_idx) + return itr; + } + + return ERR_PTR(-ENOSPC); +} + /* - * As of now the RMIDs allocation is global. - * However we keep track of which packages the RMIDs - * are used to optimize the limbo list management. + * For MPAM the RMID value is not unique, and has to be considered with + * the CLOSID. The (CLOSID, RMID) pair is allocated on all domains, which + * allows all domains to be managed by a single free list. + * Each domain also has a rmid_busy_llc to reduce the work of the limbo ha= ndler. */ -int alloc_rmid(void) +int alloc_rmid(u32 closid) { struct rmid_entry *entry; =20 lockdep_assert_held(&rdtgroup_mutex); =20 - if (list_empty(&rmid_free_lru)) - return rmid_limbo_count ? -EBUSY : -ENOSPC; + entry =3D resctrl_find_free_rmid(closid); + if (IS_ERR(entry)) + return PTR_ERR(entry); =20 - entry =3D list_first_entry(&rmid_free_lru, - struct rmid_entry, list); list_del(&entry->list); - return entry->rmid; } =20 diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index 65bee6f..d8f4411 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -777,7 +777,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp) int ret; =20 if (rdt_mon_capable) { - ret =3D alloc_rmid(); + ret =3D alloc_rmid(rdtgrp->closid); if (ret < 0) { rdt_last_cmd_puts("Out of RMIDs\n"); return ret; diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index a7dbc0e..dcffd1c 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3295,7 +3295,7 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgro= up *rdtgrp) if (!rdt_mon_capable) return 0; =20 - ret =3D alloc_rmid(); + ret =3D alloc_rmid(rdtgrp->closid); if (ret < 0) { rdt_last_cmd_puts("Out of RMIDs\n"); return ret;