From patchwork Tue Jan 30 22:20:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Luck, Tony" X-Patchwork-Id: 194347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1530619dyb; Tue, 30 Jan 2024 14:22:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKGEkkHsngzGffiV0oEW/WT1J2D0DSHAa/OpFNYK1KKyeQl+bTdjxp/0dajv6/Yni3NKes X-Received: by 2002:a25:80c5:0:b0:dc3:71ac:cbd7 with SMTP id c5-20020a2580c5000000b00dc371accbd7mr6235252ybm.8.1706653324575; Tue, 30 Jan 2024 14:22:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706653324; cv=pass; d=google.com; s=arc-20160816; b=iIhwMNUwi39sh/SCHfUpVQ7pd1fAYjYtQLf6chkXFVV5hdlv9RqLwLW6bSNXDgcfmm 23kjPqrityxNg1dnEPKBrjq9sPfDacI9JYuylzSM8rgXMbPTnCMR4g0JHueEWcPniiIp uyX7TFNFOGrR6YUues3Biu5W+iBMYD6eVVGAeZiZZDr7dvA1SpEoUy3FpeNd/Ji1gDyp Akfj5xlTZGJAqkUsSR0h2owJZ/ZQN3cl+Nr+L8W9TEdSfE9wGZiri5a2GtUeo0YEhrHn OusSS3AU7MB7LWeZkSAkNF2wvXcI7i7zOvEwDlzzYnbtx8P7LBLVtphgDd6nhYOHIB9O Z4yw== 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:dkim-signature; bh=FRRPFU9IydhPsNmTJDGCtz11V/S2JxLWf9ypKJ3Dbhs=; fh=kDu4WSgSKQjfqS0+uR7gDD47kd+EMQAW47hbuuOMwvI=; b=w6IaA64pFLtre2VuENLl2pxUdoDtYfSGh1yOVOwW2474IhRvIgX/lqkII53E8Uk2g7 7VsX0p7Jz6tNWp1rKTucFgdRC8WdMknUhMjIGbRcdPaI7ZHOee7FTofLxcla3LMEv66f s8G0oi/j6CAkJRaJZIRurMXopofgBAWaEj02CWjIB0dSn2x1/OWsaRvHT33a3Qj6Fc1j XahofZXULnZD8o26aOyqFu81/tw9GIU5SepuwmZIleYMwahDCPC/0dFTUWV0AQXlq2LD M9JQY7WqDMzuVqXEWVnP8P9mhiE1YQUWBd1lEdoZcY++u/FkIUY1zMHkp9fmiaiBdsGf tRfw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fvikW4Vn; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45387-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45387-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gu6-20020a056214260600b006819867ed39si1351605qvb.388.2024.01.30.14.22.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 14:22:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45387-ouuuleilei=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=@intel.com header.s=Intel header.b=fvikW4Vn; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45387-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45387-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 4E36C1C21BC0 for ; Tue, 30 Jan 2024 22:22:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE80086AC5; Tue, 30 Jan 2024 22:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fvikW4Vn" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) (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 D49FD762DD; Tue, 30 Jan 2024 22:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706653248; cv=none; b=VRnHvl3c7XInZj6ZjYvTy2rE3KmXMhz2oStQLdssPAGiALoNGTA/HGvFKY7LCxRpM+FpMiWAMQDr4yrzvZ/dOscV5cRO4Zv/LFSXUyjrNoVqpNYIJ6oL/fYbem7e0eBYuwLU7Djlom3a53sHazLSbm0RHrM0ZmMaewMTHyOa0oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706653248; c=relaxed/simple; bh=e1U36HnQRGJev5PeIToOOlwXKxHkepDX5Nu7sz6o/IU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=USmDrHpkYSl7TG8i0PPFWpyFpIbSX0bItAleM3bmutU4t1zVT0GBN0QBr32uQCAmGn4PqXUat+FpLUB+e+f5+mtVVQrWxcw878BLx14MpG15NNWXPGVE7n4OcVpWE89Nqo1rPeNK66wjhEpYpNzANSZMn02KatfwJDydxV0CWuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fvikW4Vn; arc=none smtp.client-ip=192.55.52.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706653246; x=1738189246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e1U36HnQRGJev5PeIToOOlwXKxHkepDX5Nu7sz6o/IU=; b=fvikW4Vnk036nODM9ERbvF4Ovr4oz0omwKo3QQzYMIDVqHcm5l/FTwC0 f/m8U2mZggWS3ydP5DdBGrpBtwnwfHuawRVokehA3ieVQ00+/5wjAyh6W BBoANwsFFL0FopJZinC9o2Ull1mTrNm7L0H5jYTSZIXJiabAytXa+2zx2 Nj/YsWsQnfdrPFVqyPSwOE/eO/sixKQzHozc+3pimooQBBHJkq3D9KBTL C8dlaovg04izVXZXh2ySkwQsNX+XxgYBh0RKII88Fbl/bHkHBCXqSMKZS EdHirtWrVGSHZ4ouvNTbvsgDx2SAzgsCh+enptKbetrtAU3q9ji7ENG14 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="403041769" X-IronPort-AV: E=Sophos;i="6.05,230,1701158400"; d="scan'208";a="403041769" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 14:20:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="1119412850" X-IronPort-AV: E=Sophos;i="6.05,230,1701158400"; d="scan'208";a="1119412850" Received: from agluck-desk3.sc.intel.com ([172.25.222.74]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 14:20:43 -0800 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Peter Newman , Jonathan Corbet , Shuah Khan , x86@kernel.org Cc: Shaopeng Tan , James Morse , Jamie Iles , Babu Moger , Randy Dunlap , Drew Fustini , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v15-RFC 5/8] x86/resctrl: Add "NODE" as an option for resource scope Date: Tue, 30 Jan 2024 14:20:31 -0800 Message-ID: <20240130222034.37181-6-tony.luck@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130222034.37181-1-tony.luck@intel.com> References: <20240126223837.21835-1-tony.luck@intel.com> <20240130222034.37181-1-tony.luck@intel.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: 1789555716431662794 X-GMAIL-MSGID: 1789555716431662794 Add RESCTRL_NODE to the enum, and to the helper function that looks up a domain id from a scope. There are a couple of places where the scope must be a cache scope. Add some defensive WARN_ON checks to those. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 3 +++ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 ++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 +++ 4 files changed, 11 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 2155dc15e636..e3cddf3f07f8 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -147,6 +147,7 @@ struct resctrl_schema; enum resctrl_scope { RESCTRL_L2_CACHE = 2, RESCTRL_L3_CACHE = 3, + RESCTRL_NODE, }; /** diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 59e6aa7abef5..b741cbf61843 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -505,6 +505,9 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) case RESCTRL_L2_CACHE: case RESCTRL_L3_CACHE: return get_cpu_cacheinfo_id(cpu, scope); + case RESCTRL_NODE: + return cpu_to_node(cpu); + default: break; } diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index 6a72fb627aa5..2bafc73b51e2 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr) */ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) { + enum resctrl_scope scope = plr->s->res->scope; struct cpu_cacheinfo *ci; int ret; int i; + if (WARN_ON_ONCE(scope != RESCTRL_L2_CACHE && scope != RESCTRL_L3_CACHE)) + return -ENODEV; + /* Pick the first cpu we find that is associated with the cache. */ plr->cpu = cpumask_first(&plr->d->cpu_mask); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index eff9d87547c9..770f2bf98462 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1413,6 +1413,9 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, unsigned int size = 0; int num_b, i; + if (WARN_ON_ONCE(r->scope != RESCTRL_L2_CACHE && r->scope != RESCTRL_L3_CACHE)) + return size; + num_b = bitmap_weight(&cbm, r->cache.cbm_len); ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask)); for (i = 0; i < ci->num_leaves; i++) {