From patchwork Tue Feb 13 18:44:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 200569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp743627dyb; Tue, 13 Feb 2024 10:56:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWAWWB5x2uUp/z6gw0Ia0VX65kNVnuGObxFIazcH9pOWZrtIK86pKj5zVEg+B9Lb8XY6//MS1oO0wtIrbJuwJmtK6ULg== X-Google-Smtp-Source: AGHT+IHAoNiiJKb9odHTXSn0JYSAeRganbMvKq8JJyWoinGGpgGYfqXQUCy/eIAK1Dy4ePOKWur9 X-Received: by 2002:a17:90a:34c8:b0:298:ae6f:313e with SMTP id m8-20020a17090a34c800b00298ae6f313emr363376pjf.29.1707850606503; Tue, 13 Feb 2024 10:56:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707850606; cv=pass; d=google.com; s=arc-20160816; b=nGAMQqtMkaDzcGyBmkxB1n4UpwMQta/56Rd1CkC3a8QZ0uOG6VzzjfXWESgpVYrgM/ EvPsOpjoVRvGL8RRmOJwaT/xPLFn2B4qqIcrN7naTySw2p3YnHdrWpUJe/ZifQS23q96 oJDDacG2YVW25hx31Ge9RByJySPghdeVxsMIT0QXge8V1hlw1WKoLeoaEQpwJ7ccA1p+ Xyx2GW+dXwsjtAfiekyn6P6sfhz60D24hICQXMFmeKTlAw8sP301a/aBMqYp409g3FgF Q/iJzizVVQBUsoQkh+5cuEZBz0W3v+ud5eVPKMjyZkwgGu8CByL1JlnuZfdEOnoaDe0R 0/VQ== 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=yKCbwn03evTkb1pYfysjE7wPYkPceMkGFBq5p9Eo8IQ=; fh=1AaxPsA6uh8uoO61UTqjBmgr2+czbwMr+PSIFfcH9rM=; b=STVj/UlCAiuJjAra+0F02nnNWNms5jrFIrIS3XKs8aSyJbB+YXFZ6sBd4LdEYnb6r8 EF8bY8Px8wXw0PbSCvwovPzGTS48KvENHlzBua1uykuboH9ky9EHd/6iAcNlDu8/hksu wCnRph3UkPlyL1C6ReI6HcSq6wsRWh44/HuW+tvr6PZ1pdJwwo5UhT+0rNro2WHl63tU MFWetn8yCufydAIJEQF3jcVPRqiRkhVOCEf791kFmZHJDMyYvmEJnzkjceLvMlpmJsOP pomzs4H0KfcqSPFviceNUm9w5OV5P0Zw4LUYMmmE/0gk5hnhVDPPLd3w2IIAh2B2EIlJ uV5g==; 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-64098-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64098-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCU4/VRBFyT6ptAgcvHTvut/SUtEfIj5HDkOJaZnKugrYTDGvoo5Hnr/PX9W4eXs44JSoZ0vk6VCW/RgYen3bNh6AnPYUg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bo10-20020a17090b090a00b00296fd518c20si2428782pjb.80.2024.02.13.10.56.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:56:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64098-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-64098-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64098-ouuuleilei=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 C6C4128E3FD for ; Tue, 13 Feb 2024 18:47:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C938160DC8; Tue, 13 Feb 2024 18:45:29 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 150681F5FA for ; Tue, 13 Feb 2024 18:45:25 +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=1707849927; cv=none; b=nuoYLLFLaMp1XgURrTY/L+ggPExOp/8qopx8QuvWKKFFeOWmceQKKwDwZc/NMgXRuVt1KuMobnjFF4Ga2TeZBLL4JsCyXj4cdUz9L/UUKOPX8LcTCFk72/xcVVz3/z5J6VyvLDW7950XCImSRVo+xDwe2OD1kBpsrHPX5SH2K0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849927; c=relaxed/simple; bh=6ebG69cbFczaqBbQqA7uAG5WhTVnWJljhAVqTzlCvT4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M3B0ciqvFjs//ge32fkB5CS6wS/TbZlguDiOrME+IEhPHU9R0Wnbk2Tgn8ilWHRr3wwJ+SUAbfKooc3SOys+IC+HMFCqf2n4p3OGrJ3AiKcf3b0d8GcGXvLjj5R11tBAc41KWAeG9VzbdN8Biescj3Z7JHv7IGoGGa3Ip7EVnq4= 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 B23AE1476; Tue, 13 Feb 2024 10:46:06 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5AA3A3F766; Tue, 13 Feb 2024 10:45:22 -0800 (PST) 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 , Babu Moger Subject: [PATCH v9 07/24] x86/resctrl: Allow RMID allocation to be scoped by CLOSID Date: Tue, 13 Feb 2024 18:44:21 +0000 Message-Id: <20240213184438.16675-8-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240213184438.16675-1-james.morse@arm.com> References: <20240213184438.16675-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790811157174057031 X-GMAIL-MSGID: 1790811157174057031 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 Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- Changes since v2; * Rephrased comment in resctrl_find_free_rmid() to describe this in terms of list_entry_first() * Rephrased comment above alloc_rmid() Changes since v3: * Flipped conditions in alloc_rmid() Changes since v4: * Typo in comment Changes since v5: * Reworded two comments. Changes since v6: * Fixed a typo and some whitespace. --- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 51 +++++++++++++++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index cbba782acd0c..872ba1a34103 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 bc5ceef143ab..c49f2e89ef29 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; } -/* - * 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. - */ -int alloc_rmid(void) +static struct rmid_entry *resctrl_find_free_rmid(u32 closid) { - struct rmid_entry *entry; - - lockdep_assert_held(&rdtgroup_mutex); + struct rmid_entry *itr; + u32 itr_idx, cmp_idx; if (list_empty(&rmid_free_lru)) - return rmid_limbo_count ? -EBUSY : -ENOSPC; + 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); +} + +/* + * 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(u32 closid) +{ + struct rmid_entry *entry; + + lockdep_assert_held(&rdtgroup_mutex); + + 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 65bee6f11015..d8f44113ed1f 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 a7dbc0e7e559..dcffd1c4a476 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;