Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2362880lqp; Sun, 24 Mar 2024 15:51:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3+4vN7IahnUt0ZWZov8tqBslaKWszGXCMiMQKj9VwdKqOwiJOMY7hc+IwOG1eVgUxG/7efTdGeoP79ltCbyYLPoFk4Q1n+nzI9d/9UA== X-Google-Smtp-Source: AGHT+IHrjdlsbeu73YE3hRlVr6gAn+zDYtcxwmK5HYAg7jpPRD2yxbn/k8xFGzH3uyl8zwQ7xVVE X-Received: by 2002:a05:6512:312e:b0:513:8102:1a1e with SMTP id p14-20020a056512312e00b0051381021a1emr3854113lfd.50.1711320715608; Sun, 24 Mar 2024 15:51:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320715; cv=pass; d=google.com; s=arc-20160816; b=OKunZ7NvHSkFhxoZuUPRC5eQnAmmaJix9EK0xgxMrdsoEg6YmvhJX35kFiTsFZj3Gh vxYCcOLS5d6rS1iK2o6FbRtgVitfq4UWxdB7qftWM/wsj4YaQvguLnF7jf0yDyim/64D WYyFQOUMwZgZol2b/T0bs1B6fo74iCZzf5hpAILBxBcvaJw7X1JQUrdyKOXESZzjN7uk uaVW1b4yoPGsRo29CuUWNjR7y0oneG0Sf2o5NnT8//nRPdhFxFvI216VJHu2uSDCwe50 2P68IO/4wiD3xlWogwh2BZn3Cy+xASBid65a5WOVQpu81FElIz/fC/XYQcGt0HM4ys4H Cupw== 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=4DUr9z7psfsuWZh2Q5eRoY+qN5+mZJYWj4y6ogJtNZE=; fh=QeBAep1dRQ2Qj+0i7uGWKOu3OqyKogpjFL7e4B5W6TM=; b=cif1UazSy8LdLy47CEnmXaQUKuIxEGYlzqLJaahoWvlzY0FRJ49t+9G2bbFg9Qv5NA +QLKqQpk33mK3Ly12XZ6NTRFIloN0FFTEfDR8DzGafY1ngYael3kk3MSgOvkBhqXM6xu 0DnY6hqKAgyaQ84frof4gVoYBtBEZdh2yd7em5J5b47nyNR6MgtuIAKDVMQ3tsHYOyoh nMTXeqAHM6oSO+UftzIFTboivKZ+lwCS5YUcB78O8PV0E72VsU2rRqL6p1CHGW7gWbZd S9ENiPbrCBSaDGiNTNMz13BOD+2JJ2ACEi/XBKZ8KmB3mu7WfouTG+jh3yTGaCFkrz9i 2hzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bdvi8PHy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112933-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i15-20020a0564020f0f00b0056c08d0d3b8si890456eda.426.2024.03.24.15.51.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:51:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bdvi8PHy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112933-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id AEB071F221B0 for ; Sun, 24 Mar 2024 22:46:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B420C757E5; Sun, 24 Mar 2024 22:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bdvi8PHy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A83E374C0E; Sun, 24 Mar 2024 22:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319745; cv=none; b=s8zmaNlNAjMtKtqGNAygVD47VDtf3/2w/DFsEkKPe9CugwNZ9Gg46GscUm7WBW6TtCKcsZ/Yg1+Jywp7imuzdddfHBiylKTFB2Wt21jQ69rmTv14rQqTteiLkbVPKMSHSTytfgRDo87tsFwZJvWz8S3B2RameTLxKis7nT8Ukfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319745; c=relaxed/simple; bh=P49efD8rlRGlUbOAd0Tvwnd/0EIr02E5XZUZfN8A1nI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=agb0K1FSV/Wyp+2qAtveqvil5b8qdQLSTHMzmuwNaMQa3ILDf8jyNdcsSu9MoqFxdIjGBuCvFTmn75NgOSjrCHhbVZ3Mqsc9AlZpOn/FXsP+PoXldwIYHolK/ecNNOV4aYu8FtFMPVKCaaayHeup4V4SZAnoOcmpqfinJV8KfwU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bdvi8PHy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C326EC433C7; Sun, 24 Mar 2024 22:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319745; bh=P49efD8rlRGlUbOAd0Tvwnd/0EIr02E5XZUZfN8A1nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bdvi8PHyAt9wOQYw+9r7iuJ7PdydMVAC5OCA3SncE0Zzvg7JSXwpkKKBjWOBYMomF fjMfaKTnwfDYmch0I4PxPDhCz/lacpjJMj8nrjM0gV1DVidhLp7GUMljRdrVTnI860 jFNILUJSoTJyKQUYi54pQ9NyZ4IL4OL3+abrA6W8g6B/6zajyFZrct+5UigwZDrVp5 XoLJY7oL6w4oX13zER3HQqPlChScucCzcTbMAjZseIThRJZyfpNIakHcEDE3FzG9NV MSuq/Qx31LNvvsmsvPtvjilCFSkEXoc0UmOSMFgrzlgDcIzbK5uc5IjYJ+JLXevTJu PJNQ2YX+kyTug== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Babu Moger , Borislav Petkov , Reinette Chatre , Sasha Levin Subject: [PATCH 6.8 046/715] x86/resctrl: Read supported bandwidth sources from CPUID Date: Sun, 24 Mar 2024 18:23:45 -0400 Message-ID: <20240324223455.1342824-47-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Babu Moger [ Upstream commit 54e35eb8611cce5550d3d7689679b1a91c864f28 ] If the BMEC (Bandwidth Monitoring Event Configuration) feature is supported, the bandwidth events can be configured. The maximum supported bandwidth bitmask can be read from CPUID: CPUID_Fn80000020_ECX_x03 [Platform QoS Monitoring Bandwidth Event Configuration] Bits Description 31:7 Reserved 6:0 Identifies the bandwidth sources that can be tracked. While at it, move the mask checking to mon_config_write() before iterating over all the domains. Also, print the valid bitmask when the user tries to configure invalid event configuration value. The CPUID details are documented in the Processor Programming Reference (PPR) Vol 1.1 for AMD Family 19h Model 11h B1 - 55901 Rev 0.25 in the Link tag. Fixes: dc2a3e857981 ("x86/resctrl: Add interface to read mbm_total_bytes_config") Signed-off-by: Babu Moger Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Link: https://lore.kernel.org/r/669896fa512c7451319fa5ca2fdb6f7e015b5635.1705359148.git.babu.moger@amd.com Signed-off-by: Sasha Levin --- arch/x86/kernel/cpu/resctrl/internal.h | 3 +++ arch/x86/kernel/cpu/resctrl/monitor.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 ++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index d2979748fae47..e3dc35a00a197 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -394,6 +394,8 @@ struct rdt_parse_data { * @msr_update: Function pointer to update QOS MSRs * @mon_scale: cqm counter * mon_scale = occupancy in bytes * @mbm_width: Monitor width, to detect and correct for overflow. + * @mbm_cfg_mask: Bandwidth sources that can be tracked when Bandwidth + * Monitoring Event Configuration (BMEC) is supported. * @cdp_enabled: CDP state of this resource * * Members of this structure are either private to the architecture @@ -408,6 +410,7 @@ struct rdt_hw_resource { struct rdt_resource *r); unsigned int mon_scale; unsigned int mbm_width; + unsigned int mbm_cfg_mask; bool cdp_enabled; }; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index f136ac046851c..acca577e2b066 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -813,6 +813,12 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) return ret; if (rdt_cpu_has(X86_FEATURE_BMEC)) { + u32 eax, ebx, ecx, edx; + + /* Detect list of bandwidth sources that can be tracked */ + cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx); + hw_res->mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS; + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { mbm_total_event.configurable = true; mbm_config_rftype_init("mbm_total_bytes_config"); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 69a1de92384ab..2b69e560b05f1 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1620,12 +1620,6 @@ static int mbm_config_write_domain(struct rdt_resource *r, struct mon_config_info mon_info = {0}; int ret = 0; - /* mon_config cannot be more than the supported set of events */ - if (val > MAX_EVT_CONFIG_BITS) { - rdt_last_cmd_puts("Invalid event configuration\n"); - return -EINVAL; - } - /* * Read the current config value first. If both are the same then * no need to write it again. @@ -1663,6 +1657,7 @@ static int mbm_config_write_domain(struct rdt_resource *r, static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid) { + struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); char *dom_str = NULL, *id_str; unsigned long dom_id, val; struct rdt_domain *d; @@ -1686,6 +1681,13 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid) return -EINVAL; } + /* Value from user cannot be more than the supported set of events */ + if ((val & hw_res->mbm_cfg_mask) != val) { + rdt_last_cmd_printf("Invalid event configuration: max valid mask is 0x%02x\n", + hw_res->mbm_cfg_mask); + return -EINVAL; + } + list_for_each_entry(d, &r->domains, list) { if (d->id == dom_id) { ret = mbm_config_write_domain(r, d, evtid, val); -- 2.43.0