Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp875968lqs; Fri, 14 Jun 2024 08:07:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUVcTZuc3PGCXzIOKQyvwc95KutLrR8jeimsEul4O7wtakPB9MDqpltYxIkTz/Azy+YevmvlbTfGYZzyxV2sX5QW+VOYziTuMqPmOQsxg== X-Google-Smtp-Source: AGHT+IHvMrA4SWVjHBtgGvsoaxTuHhd9knhMuiPFs6gDRc/78aAucsWThdHqD1S9Y9oq1NjDC2or X-Received: by 2002:a05:690c:d82:b0:614:74f6:df18 with SMTP id 00721157ae682-63206ad787emr20451797b3.26.1718377674123; Fri, 14 Jun 2024 08:07:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718377674; cv=pass; d=google.com; s=arc-20160816; b=SyuJKnwrHP/aCbD4SUlsFbEsEtI2ULG5EizTLQAJhrvPyQiB1oxWwAxOVAALbOOmML qWXH3YJ0Yrs8b66vWptBxyDPKJ+oPLJARJcJeby2AO7Em/nf2+sJUVPCT27hvmZJyVLZ DUeWTMNYgDLfSXBmp66U8U+zkFiSDxaVJQ7/iGkjC7fgYuy7ebhn/YPMY2ySN73IWMKq X5Xewrd7r5MRVmaXI3GbGTtm5PSttAQmTxkLegeXeS8gbZKV6HwCkUKDlRJkUDjA1zbS nPUOdPjpjxaVIdgmM4vPlo9WGtp6IIkRk/Wa5t4KK/1TzuBGKZXuR8fdJAdl0V0JOEnd 2arQ== 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=dWKtNXz9bGqw/Lwo//KcOl0aT2Cz7jG9izvAgipdmBY=; fh=ZzIMw8TvFOndukyZ2OYtyPajIHhdrLW0CERhi5Mu63Y=; b=k4gbj8XwrTRXQ+y6D1rz2yons238hnvxwBifJsp0ak2K8cVYUnOPHRgkYNG2KgPHQ2 XLPvNZzKqhjRANGABlfM2/yA/Vzj3LcNtF5wPN10bPF8fcHDSTOvGv4i25j/+4NMGQXN YY0I5VaYEmQqs7gnY/4gPlqDHRVPCl7gfcW6wUcrP4C+saDjPGD7H4qzA11VMTCyFNho 8ebBvPINaDdeTqL4cHHr93Z/BPPIBye1zxpcDm30XbMGVwWaoJRX8ykiLnaL1nGL5v/b QVvCE7WeAol1VF7HGcAfHKak428HStacPZ/p4PrX8AkoU9SBk65cmzB61jJESeWv63/p 9tHA==; 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-215096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 00721157ae682-632ad81c12esi5378687b3.313.2024.06.14.08.07.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 08:07:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-215096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215096-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EA20A1C20C4A for ; Fri, 14 Jun 2024 15:07:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 484F61AC248; Fri, 14 Jun 2024 15:02:45 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E30E1AC422 for ; Fri, 14 Jun 2024 15:02:43 +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=1718377364; cv=none; b=Q7jTrbsB+PiD33FyJJUvPEGO/R1VMaLrHSdr9hNqCfAepUHEtiy4RORDfSakC8B7JYARZ+FkO4w3fXIFJ9QyVd0uYnv1Vj6De8gpnS/ZKBNIXTZS1ZWD+R+ZccGuw5iMxp9Yg5LjkOkQzlg0Zc7yMQUBCzSfeerI6zAFxSl+3iM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718377364; c=relaxed/simple; bh=A6gXVJ0/SIxSdOMYIUGh7FJvovxGD4gIhDVuN5uqNec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BTgr1VVYBhaR4J39jpFPUSwVZJBojLq7p1G3u3lWnS5MB8m0069INYS3es6Y96vW8caUJQvqXXR55OXRUcznkQdaL0ZGs18Zp61MCNeWDNJc4ysAnOL+8xb8h503e1VEF/fp14dMXSIBjSy13Y3SAFePVQjNR/xDhiQ6Tqvb+Eo= 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 4AEEA1BC0; Fri, 14 Jun 2024 08:03:07 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 98D473F5A1; Fri, 14 Jun 2024 08:02: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 , Shaopeng Tan Subject: [PATCH v3 28/38] x86/resctrl: Claim get_domain_from_cpu() for resctrl Date: Fri, 14 Jun 2024 15:00:23 +0000 Message-Id: <20240614150033.10454-29-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240614150033.10454-1-james.morse@arm.com> References: <20240614150033.10454-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 get_domain_from_cpu() is a handy helper that both the arch code and resctrl need to use. Rename it resctrl_get_domain_from_cpu() so it gets moved out to /fs, and exported back to the arch code. Signed-off-by: James Morse Tested-by: Peter Newman Tested-by: Shaopeng Tan --- arch/x86/kernel/cpu/resctrl/core.c | 15 --------------- arch/x86/kernel/cpu/resctrl/internal.h | 1 - arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- include/linux/resctrl.h | 21 +++++++++++++++++++++ 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index d932e03f129f..258e0a945f87 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -343,21 +343,6 @@ static void cat_wrmsr(struct msr_param *m) wrmsrl(hw_res->msr_base + i, hw_dom->ctrl_val[i]); } -struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) -{ - struct rdt_domain *d; - - lockdep_assert_cpus_held(); - - list_for_each_entry(d, &r->domains, list) { - /* Find the domain that contains this CPU */ - if (cpumask_test_cpu(cpu, &d->cpu_mask)) - return d; - } - - return NULL; -} - u32 resctrl_arch_get_num_closid(struct rdt_resource *r) { return resctrl_to_arch_res(r)->num_closid; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index fc837d144894..bad103f20663 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -454,7 +454,6 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_domain *d, unsigned long cbm); enum rdtgrp_mode rdtgroup_mode_by_closid(int closid); int rdtgroup_tasks_assigned(struct rdtgroup *r); -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(u32 closid); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index a09f5ed929d3..145bd05eafa5 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -687,7 +687,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) idx = resctrl_arch_rmid_idx_encode(closid, rmid); pmbm_data = &dom_mbm->mbm_local[idx]; - dom_mba = get_domain_from_cpu(smp_processor_id(), r_mba); + dom_mba = resctrl_get_domain_from_cpu(smp_processor_id(), r_mba); if (!dom_mba) { pr_warn_once("Failure to get domain for MBA update\n"); return; diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 8066d0e51a73..74edf83a3eec 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -4171,7 +4171,7 @@ void resctrl_offline_cpu(unsigned int cpu) if (!l3->mon_capable) goto out_unlock; - d = get_domain_from_cpu(cpu, l3); + d = resctrl_get_domain_from_cpu(cpu, l3); if (d) { if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) { cancel_delayed_work(&d->mbm_over); diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index e07d719ace33..d67225f95ee1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -2,6 +2,7 @@ #ifndef _RESCTRL_H #define _RESCTRL_H +#include #include #include #include @@ -330,6 +331,26 @@ static inline u32 resctrl_get_config_index(u32 closid, } } +/* + * Caller must hold the cpuhp read lock to prevent the struct rdt_domain being + * freed. + */ +static inline struct rdt_domain * +resctrl_get_domain_from_cpu(int cpu, struct rdt_resource *r) +{ + struct rdt_domain *d; + + lockdep_assert_cpus_held(); + + list_for_each_entry(d, &r->domains, list) { + /* Find the domain that contains this CPU */ + if (cpumask_test_cpu(cpu, &d->cpu_mask)) + return d; + } + + return NULL; +} + /* * Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. -- 2.39.2