Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2471235lqp; Sun, 24 Mar 2024 22:10:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXysJSI0z7WmKR9EhS8qZZyoa6tmstfx9SeTWjHIXtyaFq9gWvdYI1b3yyuuSJx3UfP9fdeE7XXzHdmwC6BVnfueE/w41pfRFYH5drbDQ== X-Google-Smtp-Source: AGHT+IFJPLzl9MS8LXDVW/GYopES631LthxMdqSiA5bn4L7hgU6+OoKgfOt14Sup28zWTOan0gaD X-Received: by 2002:a17:907:7899:b0:a46:e377:1468 with SMTP id ku25-20020a170907789900b00a46e3771468mr4311995ejc.31.1711343419835; Sun, 24 Mar 2024 22:10:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711343419; cv=pass; d=google.com; s=arc-20160816; b=OdM4Spuezq1OIltMjwhNnMS2Za0ZElPTN3Yv2aoCgjWV+nKeCTuxMTRwit6Tqt46H8 ou4bW+8MCurPRd8DISi2KjD4l2RUQ2Pc+WqJyHy8+FxdlyRxRFkoayJREdw7g4qwpev9 EuYU0H5NmL0Z/+EownFT6VH3tpbUFuOitUqv8WI4bMIxqHooPKG/6qIkIRWuACLQ0Vsc 4PgmVangynwg4A7lfsGdnQ//EV7NCreYwbH6LnGT2Yv0jgI0BmVA+F+zpym9DCzK3gtR YU0+uRhkMA0TTrcdhC07TpHhdYVHYArPoct0R79956/ZlCUNXmszu+mai6wC3Vk2aPgo R69Q== 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=tXE9JW63CbgVF+rFkRyqSIct7E2YsRYbRLv69zWbnjv8otbiRpEf3bJ0gqRbb9y4JI 1GroA4MMach6Qg/GovkX7VnohW/mOxJGCMyuc3+i02V7uRC0JvOsyQoCHvEvJb29WQGE lhMAcT8PHJAo131EVchFCnWC5IXtJNw7mQbeES+WCkii8ryyIsAExHZ8Z9jc03WbYrnn dI4nHjwazYHU0LPLJwjsfJS6e11fy9qLvedsBIl1GC4uJxNyH5uNPgvZ2NakcfMeV/I4 Dpwz+ZIVt4nDIbZBWLQzyvcbpYR+fhoQazxdbnS7e6c2FEqN3lOkAfivuxK8Evn3IcnU 9BvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VquW1RGP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113647-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113647-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 i24-20020a170906091800b00a3f6ba0165dsi2233260ejd.261.2024.03.24.22.10.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 22:10:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113647-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=VquW1RGP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113647-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113647-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 8F9171F2F07F for ; Mon, 25 Mar 2024 05:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3DC586140; Sun, 24 Mar 2024 22:51:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VquW1RGP" 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 CC51B1D564A; Sun, 24 Mar 2024 22:49:22 +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=1711320563; cv=none; b=DX7zORqVwK1OZyjnzKrc7hw5m4jEyULOhAw5DolSARDNU0v4xQ/lSwUnm3GTNBglLUaLhqBSvXdi4bPRqrdw8zjTfiz0iwyRG2ZPdjrSko8efzD3ByiyCK7f/TJY0dsmP+3bvEtHqSaelPafdl2IgKVM5GNzHAAMnI7gf2tozPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320563; c=relaxed/simple; bh=P49efD8rlRGlUbOAd0Tvwnd/0EIr02E5XZUZfN8A1nI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZydaifnsLJ21SupcW9p6Z3fywGXwWcIl6z4/xRcNxhlCgptOfFHavtzEeyZLNTO4gY2Y2qth/6d6Wk7sJmQoRqyGvs/qZPvvxqd5wnOGB9aPIGySMs2AkhVC0Vv1Qq2Xx9gFTFtqlUiF/3ty+NLwLiBi/AxFZzU84hB0xFD6Zng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VquW1RGP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D2A8C433F1; Sun, 24 Mar 2024 22:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320562; bh=P49efD8rlRGlUbOAd0Tvwnd/0EIr02E5XZUZfN8A1nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VquW1RGPM5nHcE05mvLleur+hjzPv2gQZRR5CmnpL85VN2vbipe09fbrjsoaZXMiQ 0W67Ls2Yo1xKPdAQFVeXI7CEo0rjtSJIU5USJAGkQajRhij3vaVIUY8WQfTINE7qqZ mP4JAOgich3dMJP55pWt7zC9+vv6mZNm6Chnl5LO68pBHg9EoPNDj/N62E6ySdHA/Q oDL3NJ52L6i7cgMi6wi8RD2dDM7Mpn5FRPjB/qI2tpkDGB8Hk/z/kiHGKxpf2odl4R THsjzj3pSFNcNIPnJNfWFVIPJyiyhdrWuTOA9NBeeF0cQE16nQFVAl9ZjloMf8jnjc zHrGsqpUiOwAw== 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.7 123/713] x86/resctrl: Read supported bandwidth sources from CPUID Date: Sun, 24 Mar 2024 18:37:29 -0400 Message-ID: <20240324224720.1345309-124-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324224720.1345309-1-sashal@kernel.org> References: <20240324224720.1345309-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