Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp48463lqg; Fri, 26 Apr 2024 08:26:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX+FvKtk+J9P+X88uSwhynymzZ9vAKvwd3Lpd3uT12ZLZOHF/P5U97yLWfD9LwYmklfg6AK9pytK/zvl4hE723O+ucuLAZ1di8/H17ZVA== X-Google-Smtp-Source: AGHT+IG7MRMy4gLAd+5XtVNvCTwmIrbfTTWjbA5YdGDyumgcY3HtsCbRwv5KmBiwH3aWIfnJHgSX X-Received: by 2002:a17:90a:9e1:b0:2af:1f3f:bd79 with SMTP id 88-20020a17090a09e100b002af1f3fbd79mr3085965pjo.35.1714145162056; Fri, 26 Apr 2024 08:26:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714145162; cv=pass; d=google.com; s=arc-20160816; b=tnb6Fs5fZYLIfLts4UKpUh0nCsN8dwREUNh6qYItAZscrf/Da0l7mHWkYkjjuBVhG9 aR+RlmtmLYOWRqyXPcnEGKRASjU//Ksf+CKTpQfdgbFeE4TDVAv3QTmGy9e7vYKsIQZX rOHY8a0Sd7APklIFTtaFcOpSyp/M9Lk07SJ2DISvqyFjENRiuh2Ya3nVyzgu9zvoUUqp Gptc7xohVFdaY4r8pLZ2+9jZCQkcJRqJ3FqCOQhL39dKxxwhLKRVLnVT2QcfWI+Yl1Iz 9GckRBG3APRBe65fEPT9jB9MZ9YoliScjf2+uEvaj2g9/481WKVcP1OiOQRzTnuC5vPe xASQ== 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=kWo8Z4sMqQsbgcsilYhEiUWk8d5m/GToBwyng6swicc=; fh=Vo4MxA0u7CmSKYL/GjcyKHwusyvU+nKR43bqJem+vcY=; b=NWfGAPni6HARfaZskCnQZFKPjl3q02Q+i+Vu59LHqWqBGhMRdsdpTKY7hTNsCQjcEA vJalQwQusCdhSi2mk4CMHQR8U6CfwWL5VmCsKOAJIhhbj1vmgPqGhuJ2HOK0qnwbcd4J zkHN5syJKDut3UujZ+ayxmsHsYIzAjmcm6KWEg/lbduG5sNLHDi1R2WUDpA4LOosxotA p1zrGVkIJQlXqEqvFLvhlGAOb8LPWe6rINj8FLcq/TE2elA9HDem35zfdUbYyavfJiqa eP/bAvgJCA/J0iuygoKRCqsVYcZjI/jsRnv2yRMzWmUxUzVr9wytd6CTtRHkg/UeEGFf kDag==; 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-160243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160243-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bw11-20020a17090af60b00b002ab6ccac659si15346768pjb.13.2024.04.26.08.26.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:26:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-160243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160243-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 70562B25794 for ; Fri, 26 Apr 2024 15:15:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 170A3171650; Fri, 26 Apr 2024 15:10:33 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1746F171644 for ; Fri, 26 Apr 2024 15:10:31 +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=1714144232; cv=none; b=MufdkcEPOX1II/lFAx/1v03oLTZWXhEBeDCnPFuZUIm2rw1cWNsXaUOGlsiAbXEzowuaMYNqorkUhy/GQV2f/ArvuX8MbRwkhD9T2I6e6770QXf5+CkV7Xv+/dj+CZkm2sU4tYoqkLGrmm8jEfsJ3SghDnsqEY+QeXSpEHINPWg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714144232; c=relaxed/simple; bh=bZNFrQIBg/+HhhLiUnczWrUs+VzK9msn94VjMy+qKuQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MV0mNPPR7SQknddNMaHMKseP/4zLb3blt4LFFJtGHfh46gyLMm0fTSiCsfBFZhrPh86CMUrvTzuX8AbfnCGJ9lKDGCfekFGie9NqxX6oX7CPxKdi5jOVg75IHmGwM2fdnveCXUGcFncD6vzevhQrr4nvmQs0Oc1g+kwugqF3i6U= 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 BDDFA1007; Fri, 26 Apr 2024 08:10:58 -0700 (PDT) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D82413F73F; Fri, 26 Apr 2024 08:10:27 -0700 (PDT) From: Dave Martin To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: James Morse , Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, "Shaopeng Tan (Fujitsu)" , baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , Peter Newman , dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie Subject: [PATCH v2 25/35] x86/resctrl: Claim get_domain_from_cpu() for resctrl Date: Fri, 26 Apr 2024 16:08:54 +0100 Message-Id: <20240426150904.8854-25-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426150904.8854-1-Dave.Martin@arm.com> References: <20240426150537.8094-1-Dave.Martin@arm.com> <20240426150904.8854-1-Dave.Martin@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 From: James Morse 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 --- 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 | 19 +++++++++++++++++++ 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 7cdecd8ac00b..f94ad04023c3 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -355,19 +355,6 @@ cat_wrmsr(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r) 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; - - 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; @@ -381,7 +368,7 @@ void rdt_ctrl_update(void *arg) int cpu = smp_processor_id(); struct rdt_domain *d; - d = get_domain_from_cpu(cpu, r); + d = resctrl_get_domain_from_cpu(cpu, r); if (d) { hw_res->msr_update(d, m, r); return; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index e849d4407769..3a3962736061 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -452,7 +452,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 403655b49081..e6aefed3225b 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -676,7 +676,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 ff209ba9176e..a7dd2f494b46 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -4167,7 +4167,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 7bbed5d8a155..be004dc2ec79 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 @@ -284,6 +285,24 @@ 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; + + list_for_each_entry_rcu(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.34.1