Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1307681rdb; Mon, 19 Feb 2024 10:41:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUiR5zkKVP3AlpP84IHlLJucT9K+qhCnI20/Q/0X4yHI9njQthOSOj1MoftzKsttqPcur7EBn3blICKIfjaO9k+VXINgyVgDIqeft981A== X-Google-Smtp-Source: AGHT+IE4ISqgpJPSlrwSkZX4oevE2qWGlOR+ou43qXmB4RzSyr1ueYM+WMxZd+wMkyIuTm4xefle X-Received: by 2002:a05:6214:2aac:b0:68f:489a:3829 with SMTP id js12-20020a0562142aac00b0068f489a3829mr9775413qvb.39.1708368064521; Mon, 19 Feb 2024 10:41:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708368064; cv=pass; d=google.com; s=arc-20160816; b=ZHB3+uMVsatUeLdk2LFgZftWrJWyp5kzYFYoT7Eh0+AMeuJPJM5QmHfx7t4tcO99AI htsBzFjvGMVIp+DktEl0hPxi2d8G6Z69GEdD6eZ6KvKBQt/dvhLb0Bsdoutti0ozaWLm Fi9ouQ2UOUiWW4ek/9ZhkGsJ8lWztd6+su2FH58bRwsRiOu3I7Eju1E0HsLk+QBLvwBA VXGeBVKrjcWGsjmcErZwDWasiGh0xOAbvXbDONgPe7GKW49gGwEntSckhCJ/FlRNI6uf aeJH9ajfRIjaR2x0o6yX5NScS1aBakrFnYxGgOHDyIcWORJ8EB14CNGP5wfMfE1cBzGQ BPkg== 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=UZb7UAwZ4hyscSYZqUREdcEzKvEB6f2rpJ3lezyWUiw=; fh=n4H4sG50U6DIdypz596/kRWdpMDl152Oh9U3Sp1nb/I=; b=S2oN3FO8HOjRWUluLPLVkgUU7swk9Td9p8eWuEL6VIM+maO46/qN/1T8tHkB9HR//6 I4IFq2vxJkeJUNbTvVnPkAXorQ5nuASNo0OZgBhWcc0FWBVKGSih+WxUONe3g4/Gh70P 9urV908iEbxGmknvEcO0iZW6Tue/g3Ulo60gNQSUyjRPLcEvzHFTxX99w49bUU8V+O7K BjpC7vghjjN37Ir5lIoRQziU4kwj6END2UMgbbv/uEKRvG1zJOtkwHXoh/ft1pav+zH8 Mr+PDGWZ80a38GJQkoLNccE8s6GBWWxyw9YJ4ThmN0FYsyPFHlCCKSWDI54EnNHDupQI oT/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=exap3osf; 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-71828-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71828-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e1-20020a0562140d8100b0068cb9e119b8si6695507qve.576.2024.02.19.10.41.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 10:41:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71828-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=exap3osf; 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-71828-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71828-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2ED0F1C21C77 for ; Mon, 19 Feb 2024 18:41:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 912F3535DE; Mon, 19 Feb 2024 18:37:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="exap3osf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WBZlaUwd" 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 6D96E51C52; 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=1708367860; cv=none; b=BGo6bB9KQzFiog14Y4dbiAejPCa0y9Iasg0VlD2T31FDhsl847hbyAFJUkWtjJqnno9W8D/JQUYsTsfY+aIj08xLMBjnDacsuYgZIQyzisJd8T6twmXmyg4guGFzLYdia3JOqKf9spBn/72YIsUDx/IdOGztHkZkSVmQhoGQ9L0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367860; c=relaxed/simple; bh=dYsRxi/eT0Yrq+MF1Y6n+TwVy7Kz6cPGcwRYdSNP2gc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=f9HxJdgjyNUSB/Ti2n18/zffPTeIgIz1Gc5E0o1B3ce9ctVLpoQgTN/zfgMPE7t5W4NeG/KjFUHmktBbfQzqzGI2C+hb3QHGcTYoiUkmy4Mj01QZatq+KMVCt15fJA7Cu61wUWxvlIH1UCIuVQKmUCIZp7SwX4Je2BYMku8eTCQ= 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=exap3osf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WBZlaUwd; 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:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708367856; 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=UZb7UAwZ4hyscSYZqUREdcEzKvEB6f2rpJ3lezyWUiw=; b=exap3osf0sT104mdZfXSvyCG1s2Bg+rRNIYjwS8ArbwgddM70+IvlDjWk+l6w+pEiZisNS DEwtEZ23neRj5Axm+XHLOi4c3Bd6ZHtqKBjXY0w2AbGbWPHd6E1zmCoo/RZRKMOSs+RdpD PjwC92p978ZXsHe3PNKzfBor4B20dfGHdJHL8ezNLx4lsvTnnEWF95Jv0XvWZQcNhT4HHA PWsVwm4YdCLdQJRgQwisSA1w9C35SS44xc9Wq9pJnP1GaTfp9FvFzhOatHTgWlDC2ysh+r zkstWcMyjI3M0i1bp72vcb1L6ZvOYCcTELUFGQDsyfgCIjG6Ba25HuVm6vEZKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708367856; 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=UZb7UAwZ4hyscSYZqUREdcEzKvEB6f2rpJ3lezyWUiw=; b=WBZlaUwdY4iSS5B9YKY/JxhTFKlUJMy+czKYm9iS4MLDfpMTaRnnS+WmJqAHSvRcr9yrVG CO273v+N590v6tDA== 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: Track the number of dirty RMID a CLOSID has 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-9-james.morse@arm.com> References: <20240213184438.16675-9-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: <170836785569.398.9569424059954651811.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: b30a55df60c35df09b9ef08dfb0a0cbb543abe81 Gitweb: https://git.kernel.org/tip/b30a55df60c35df09b9ef08dfb0a0cbb543abe81 Author: James Morse AuthorDate: Tue, 13 Feb 2024 18:44:22 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 16 Feb 2024 19:18:31 +01:00 x86/resctrl: Track the number of dirty RMID a CLOSID has MPAM's PMG bits extend its PARTID space, meaning the same PMG value can be used for different control groups. This means once a CLOSID is allocated, all its monitoring ids may still be dirty, and held in limbo. Keep track of the number of RMID held in limbo each CLOSID has. This will allow a future helper to find the 'cleanest' CLOSID when allocating. The array is only needed when CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is defined. This will never be the case on x86. 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-9-james.morse@arm.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/kernel/cpu/resctrl/monitor.c | 75 ++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index c49f2e8..13b0c8d 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -51,6 +51,13 @@ struct rmid_entry { static LIST_HEAD(rmid_free_lru); /* + * @closid_num_dirty_rmid The number of dirty RMID each CLOSID has. + * Only allocated when CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is defined. + * Indexed by CLOSID. Protected by rdtgroup_mutex. + */ +static u32 *closid_num_dirty_rmid; + +/* * @rmid_limbo_count - count of currently unused but (potentially) * dirty RMIDs. * This counts RMIDs that no one is currently using but that @@ -292,6 +299,17 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, return 0; } +static void limbo_release_entry(struct rmid_entry *entry) +{ + lockdep_assert_held(&rdtgroup_mutex); + + rmid_limbo_count--; + list_add_tail(&entry->list, &rmid_free_lru); + + if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) + closid_num_dirty_rmid[entry->closid]--; +} + /* * Check the RMIDs that are marked as busy for this domain. If the * reported LLC occupancy is below the threshold clear the busy bit and @@ -328,10 +346,8 @@ void __check_limbo(struct rdt_domain *d, bool force_free) if (force_free || !rmid_dirty) { clear_bit(idx, d->rmid_busy_llc); - if (!--entry->busy) { - rmid_limbo_count--; - list_add_tail(&entry->list, &rmid_free_lru); - } + if (!--entry->busy) + limbo_release_entry(entry); } cur_idx = idx + 1; } @@ -398,6 +414,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) u64 val = 0; u32 idx; + lockdep_assert_held(&rdtgroup_mutex); + idx = resctrl_arch_rmid_idx_encode(entry->closid, entry->rmid); entry->busy = 0; @@ -423,10 +441,13 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) } put_cpu(); - if (entry->busy) + if (entry->busy) { rmid_limbo_count++; - else + if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) + closid_num_dirty_rmid[entry->closid]++; + } else { list_add_tail(&entry->list, &rmid_free_lru); + } } void free_rmid(u32 closid, u32 rmid) @@ -770,13 +791,39 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms) static int dom_data_init(struct rdt_resource *r) { u32 idx_limit = resctrl_arch_system_num_rmid_idx(); + u32 num_closid = resctrl_arch_get_num_closid(r); struct rmid_entry *entry = NULL; + int err = 0, i; u32 idx; - int i; + + mutex_lock(&rdtgroup_mutex); + if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) { + u32 *tmp; + + /* + * If the architecture hasn't provided a sanitised value here, + * this may result in larger arrays than necessary. Resctrl will + * use a smaller system wide value based on the resources in + * use. + */ + tmp = kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL); + if (!tmp) { + err = -ENOMEM; + goto out_unlock; + } + + closid_num_dirty_rmid = tmp; + } rmid_ptrs = kcalloc(idx_limit, sizeof(struct rmid_entry), GFP_KERNEL); - if (!rmid_ptrs) - return -ENOMEM; + if (!rmid_ptrs) { + if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) { + kfree(closid_num_dirty_rmid); + closid_num_dirty_rmid = NULL; + } + err = -ENOMEM; + goto out_unlock; + } for (i = 0; i < idx_limit; i++) { entry = &rmid_ptrs[i]; @@ -796,13 +843,21 @@ static int dom_data_init(struct rdt_resource *r) entry = __rmid_entry(idx); list_del(&entry->list); - return 0; +out_unlock: + mutex_unlock(&rdtgroup_mutex); + + return err; } static void __exit dom_data_exit(void) { mutex_lock(&rdtgroup_mutex); + if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) { + kfree(closid_num_dirty_rmid); + closid_num_dirty_rmid = NULL; + } + kfree(rmid_ptrs); rmid_ptrs = NULL;