Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1307742rdb; Mon, 19 Feb 2024 10:41:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVLIddNQ2sOQolrvp2QVop/oe1GITVAuG2Hs8UIk8mtxJtaqKkrcs4ZKsjEeo5zEfrMkGOvqho3MiEAHuTB1AaBsFMENJcSskYY6yEWcA== X-Google-Smtp-Source: AGHT+IGP/JigiGM29io8q5zHveUOCSGxHD+42z3/FNulJdwjSNtQURXDdWkH9QVcPVxiF3gHDor+ X-Received: by 2002:a17:903:22c6:b0:1db:d42f:fde9 with SMTP id y6-20020a17090322c600b001dbd42ffde9mr6586116plg.41.1708368075327; Mon, 19 Feb 2024 10:41:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708368075; cv=pass; d=google.com; s=arc-20160816; b=XdOa9wVBjIPVS8SD2nIeH5KhLcs4xX5sympSk1nPzhfqxNy4boK9V6bTL1D4FlTiO9 Hc2/tcaOBkLeQ/UCOZinVnHaYgwfrVqhRxgdhBsoUYWOAKh7dwE2fcA0wgj7Y45pDgI8 ME52USioXYlFY+Nya3N94vylqW1IEpuS9X0iIyhM5jEa9hCvFFMUjMnV9HWDfEXJ/olO WSDBEP1Aolb0W1iws+ymmhjGpIjqh9YcmS2BdXw84xjQqHyzoJELcSstqxH7ibhOQaJ5 fkGl2U1TK1KHTP21xLWI6aOutYBCgSASOrPk9pgVqfKb3moEutwHtVObcLu3dBXD5HBG b9Iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=tu6FJ9xhhYXX3pgLppJ9uAaNstlFmxXjTl6koTxXxG0=; fh=n4H4sG50U6DIdypz596/kRWdpMDl152Oh9U3Sp1nb/I=; b=zRRPWrKlz8Qg8GJ/Xt+b+OlzLFJVV4VG5i95SYccPDCJZzYqEmsoQrVpYSVV3YDc5P NkWVpxWgiX/p+0bUUYbeDLS68eRMC2toPuMndX79E2p/b4VV7ovlV7my17OZo47lFdbc 7DnB4VRTgndKkXxEpcxEDLLRjAYa7IDzj1uQspzwPboq1TXF6BjRLGBu3Lj+zVEYED3H QTqPUyPwAK/HaquZbQFIuE/pYp5NAPeQnR9TT0UIds6PHGM8UlkKlUk318ol80zyB8ly FxoJrXDKN2dFOSUpKrKV6GA3Ocuq+sxnz+4XhOzkXB0xKRn8AGs7LCzKJQfUMB6X7C6I EHiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WcmoeVJ3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-71829-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w13-20020a170902e88d00b001dbde64981esi3271896plg.379.2024.02.19.10.41.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 10:41:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71829-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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WcmoeVJ3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-71829-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 0949A280C4A for ; Mon, 19 Feb 2024 18:41:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 419FD53818; Mon, 19 Feb 2024 18:37:42 +0000 (UTC) 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" 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 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: 7bit The following commit has been merged into the x86/cache branch of tip: Commit-ID: c4c0376eefe185b790d89ca8016b7f837ebf25da Gitweb: https://git.kernel.org/tip/c4c0376eefe185b790d89ca8016b7f837ebf25da Author: James Morse AuthorDate: Tue, 13 Feb 2024 18:44:21 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 comparing 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/resctrl/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 *rdtgrp); 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/resctrl/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) != idx_limit; } +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 = resctrl_arch_rmid_idx_encode(itr->closid, itr->rmid); + cmp_idx = resctrl_arch_rmid_idx_encode(closid, itr->rmid); + + if (itr_idx == 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 handler. */ -int alloc_rmid(void) +int alloc_rmid(u32 closid) { struct rmid_entry *entry; lockdep_assert_held(&rdtgroup_mutex); - if (list_empty(&rmid_free_lru)) - return rmid_limbo_count ? -EBUSY : -ENOSPC; + entry = resctrl_find_free_rmid(closid); + if (IS_ERR(entry)) + return PTR_ERR(entry); - entry = list_first_entry(&rmid_free_lru, - struct rmid_entry, list); list_del(&entry->list); - return entry->rmid; } diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/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; if (rdt_mon_capable) { - ret = alloc_rmid(); + ret = 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/resctrl/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 rdtgroup *rdtgrp) if (!rdt_mon_capable) return 0; - ret = alloc_rmid(); + ret = alloc_rmid(rdtgrp->closid); if (ret < 0) { rdt_last_cmd_puts("Out of RMIDs\n"); return ret;