From patchwork Thu Dec 1 15:36:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 28433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp329767wrr; Thu, 1 Dec 2022 07:37:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ChwIGGcflDU0FnuklaOg7MhWvC9RAq1zCPxgtJ/K4MSHserFY8mBB6x18IourzHxZc7Cw X-Received: by 2002:a17:903:452:b0:189:6574:7ac2 with SMTP id iw18-20020a170903045200b0018965747ac2mr34188061plb.65.1669909063347; Thu, 01 Dec 2022 07:37:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669909063; cv=pass; d=google.com; s=arc-20160816; b=jJhpc1cUmPTFn2GTje1iSuG2By3+imn0VCdxsE1blVO0GnUaHWFQc5Pf7h43ClX+2D xc8EF1SPOuA3XxBPknXT9E1/tn65pj2Q/8GAz65hhiVhHQ6ywuDBsu6PQN7fl0flYUnb XIj0JeXJgtg3n45nBeNAAQAXBOFFi4NCroMKsdA7uoG3Ve0Bqcr3GiJFiW0vjnYaUc4e kxT5KyRn46oM2b6CqOTT5fFluRIXhJrrIuxGjN0WpPJhmXxBXsU4nlJItuW0ihBUO6bx aJ/Vzs9zSstyIpdhpc27PdTr6Zn6f5rx65CiCLaqT6SSgR6w8nLC2fK1zpSa215Cc76M eraA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=AW2zd7jFywMJXdOBOuCf1XiDGPqCamz7HHcj07GWYDE=; b=V0L7qDV3nPEukV9BS0SqQ+baHQrjf8p0hOETolbVFFYBVK101K2iArphBXoNc6uRJn DRN4+B1Hvvhk1v/+CnmP9t48WEb+prpFAH75SIzmiuzjhHEL2PSpV6G6A6yZ+wN2WxXW 618A+wJDwzo9Y2A7OJXovILdbtE8tFIDhfI8WXpgk3lhxTQgs0FDJbFTDoSEAdGGGK+M rqGKQJvC7OMLnI/Zu5h/Y5AaC0yo2nIb0jWlrJbkMokprdQRi/zMepAckmx1gQUsW9UM 9ie+G9U3rnBkZD3rE6EeqAW32/Ye0IrT1n3vRDqF2QbeJru6aIWrHun5KmcnYLTjgbUC e5Sw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xWF9mnZ+; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a632c15000000b00477a3989772si4870900pgs.12.2022.12.01.07.37.29; Thu, 01 Dec 2022 07:37:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xWF9mnZ+; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232000AbiLAPgu (ORCPT + 99 others); Thu, 1 Dec 2022 10:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231967AbiLAPgn (ORCPT ); Thu, 1 Dec 2022 10:36:43 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2084.outbound.protection.outlook.com [40.107.96.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB7C240B1; Thu, 1 Dec 2022 07:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nN4ivzPGuurbaOPAfXeeaLVHXTLCf7gHnuH6bCgdDbFqsZisjtpN+AOtgey1JBMAC4s/6uGUlF9L/uJ6HpjfrsHQA5Z3qF8abYwkvwHdMMtNyxTbIzKIpNF0ZW/KAmDJvtQx24onkFKGaFRj4XbOm2UZPAl/2fNR+iqDTfwjxT0/QcwhiIXjMThuaJC8LexgP47wVrwLxbHDp6uxQIAHCSHfJRx4nBX7wm2UOfLcBN2H7g+7H50zeybnBMU2OmyKBksEBwLfEIuJov+KtDl8Xpu3oxB8VZCTmGRjyW2MF81VR3bS0Kpar9V0yHQaxUDfsBcyhOybMohFmB/o8GToAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AW2zd7jFywMJXdOBOuCf1XiDGPqCamz7HHcj07GWYDE=; b=e6nc3ofGC3SErpeGJnjZNTIGNDXABc+3vFf910jL8ViWRAa+Ut2bYhWLSWFQqooq1Rlr0Wkf50HQmk6wt4B2vVqeeElco83maml0nvdpGLm0GocjjP8beumvUwH1/G90XGNFYr2T/lIVBvXfc299ac3tqVGVB8WEQ0nst1k5/5bt6KRBKWto51AyjdXTGtc2WAMpvzzQHrf3L7BNnI921U28b4zW13bBw4FddPc37V5wcn5B2ZEh8I7cP6f7AObgROZ7EC/xjrFeDEd+rwyOQV9NHvkMsvD1WM/zElS+UF4EuViNAOYBvz7PyYB0DFYmW9Bw6E72cKwnOYgXOyAnSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linutronix.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AW2zd7jFywMJXdOBOuCf1XiDGPqCamz7HHcj07GWYDE=; b=xWF9mnZ+B+8eLOWVBXN0QcLU3/pZW5NVe5+npqatzAmlISBlGLT0hfHSV63rYAI8DKKsYVL3QROh3v2b7wGPUqo7vGEW0QaqwaZvd3I9KJ70YsozG2ImxBOEDjzT+ZLLGuDW/b8+AlTxEp6E5PxLlzuRYmW+V7/LkMY1DVD8GB4= Received: from MW4PR03CA0192.namprd03.prod.outlook.com (2603:10b6:303:b8::17) by CY5PR12MB6153.namprd12.prod.outlook.com (2603:10b6:930:27::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.23; Thu, 1 Dec 2022 15:36:37 +0000 Received: from CO1NAM11FT110.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b8:cafe::ae) by MW4PR03CA0192.outlook.office365.com (2603:10b6:303:b8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8 via Frontend Transport; Thu, 1 Dec 2022 15:36:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT110.mail.protection.outlook.com (10.13.175.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Thu, 1 Dec 2022 15:36:36 +0000 Received: from [127.0.1.1] (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Dec 2022 09:36:34 -0600 Subject: [PATCH v9 05/13] x86/resctrl: Detect and configure Slow Memory Bandwidth Allocation From: Babu Moger To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Thu, 1 Dec 2022 09:36:34 -0600 Message-ID: <166990899399.17806.8574636266624372983.stgit@bmoger-ubuntu> In-Reply-To: <166990882621.17806.16780480657453071426.stgit@bmoger-ubuntu> References: <166990882621.17806.16780480657453071426.stgit@bmoger-ubuntu> User-Agent: StGit/1.1.dev103+g5369f4c MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT110:EE_|CY5PR12MB6153:EE_ X-MS-Office365-Filtering-Correlation-Id: 044ff21d-6125-455a-79ba-08dad3b1d57f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: daxT0xhPBWeYmJpJfrrRgQsW/WOQ5h2RTmm7OWDTPIu2TmSqIYJYf/pOd0bo8jo521YLG4Lm7lyUVbABYyUX8fvyFsYSR/MX6ZCRCnuiq2MEd1orRFKRmw3GKNdKMJFqt25TMxajkq+EubzXTpzNDKHsMe/aez3jUPB5EiChEhFD6BsdxWUrzixmf/ghseitPnxz67m8A4gKMbBO7q6Q4tYqtd5Pk6vzrD09eCerb4Za0xCse2pyBPOxX1skYIPDq6TXiO7yw2vJiFmskl3ZLDfjK0L7g7XJLdVK4V/QvEYEUmygDHstqTyEYQajLwzIeDgnW+cAsrGI+hBDffttSAGTjzQ4qdPBQYg6cEAWazbXm9Abzd47911uUwd0jP+iUvanE6EL8XejwSHfqGQb/3GSIzDH9XCgExHWYylqA1ATy7y1MU9I+tDV8eTa21GrbLqFEKp4/8T5JJcXH0ZHCi/tb5jcWFzWtBIaxM1NiLiS+6CQKNJ7GF4gHhz3a8D5pmVw4vtKMF33r7FeZPW04cOFypkprJ1/ZBhjsaPRl+oTHu83uxsow7ly6eWU0k+Wm8xEb3rkMv2db7kjFyPQEwZb1MmYrMUBMbeWpPiJziNq8QRYpYVWk53RnBIYEzAIia+BSeDSd2hgZTtaJfGrj7CrkIGAMu5VqWq8xw4LNuLh7oRliyFnKZoFrTelkszmZMkqfR8HwtxzUgwMgMit2I2AGXO7PQNFDv8OCnB1XamIOImhy8Dc3fKCM/4Y4LbgGMVBBGCt8ttI2ra+t6H37Q== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(7916004)(346002)(376002)(136003)(396003)(39860400002)(451199015)(46966006)(36840700001)(40470700004)(103116003)(356005)(8676002)(82740400003)(2906002)(7416002)(7406005)(41300700001)(40460700003)(44832011)(426003)(81166007)(36860700001)(70206006)(16576012)(86362001)(83380400001)(47076005)(316002)(54906003)(478600001)(110136005)(8936002)(186003)(70586007)(5660300002)(26005)(82310400005)(33716001)(9686003)(4326008)(40480700001)(16526019)(336012)(71626007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2022 15:36:36.9357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 044ff21d-6125-455a-79ba-08dad3b1d57f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT110.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6153 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751026566125115399?= X-GMAIL-MSGID: =?utf-8?q?1751026566125115399?= The QoS slow memory configuration details are available via CPUID_Fn80000020_EDX_x02. Detect the available details and initialize the rest to defaults. Signed-off-by: Babu Moger Reviewed-by: Reinette Chatre --- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 36 +++++++++++++++++++++++++++-- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 ++++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 37ff47552bcb..e0a40027aa62 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1061,6 +1061,7 @@ /* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200 +#define MSR_IA32_SMBA_BW_BASE 0xc0000280 /* MSR_IA32_VMX_MISC bits */ #define MSR_IA32_VMX_MISC_INTEL_PT (1ULL << 14) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 10a8c9d96f32..b4fc851f6489 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -162,6 +162,13 @@ bool is_mba_sc(struct rdt_resource *r) if (!r) return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.mba_sc; + /* + * The software controller support is only applicable to MBA resource. + * Make sure to check for resource type. + */ + if (r->rid != RDT_RESOURCE_MBA) + return false; + return r->membw.mba_sc; } @@ -225,9 +232,15 @@ static bool __rdt_get_mem_config_amd(struct rdt_resource *r) struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); union cpuid_0x10_3_eax eax; union cpuid_0x10_x_edx edx; - u32 ebx, ecx; + u32 ebx, ecx, subleaf; - cpuid_count(0x80000020, 1, &eax.full, &ebx, &ecx, &edx.full); + /* + * Query CPUID_Fn80000020_EDX_x01 for MBA and + * CPUID_Fn80000020_EDX_x02 for SMBA + */ + subleaf = (r->rid == RDT_RESOURCE_SMBA) ? 2 : 1; + + cpuid_count(0x80000020, subleaf, &eax.full, &ebx, &ecx, &edx.full); hw_res->num_closid = edx.split.cos_max + 1; r->default_ctrl = MAX_MBA_BW_AMD; @@ -750,6 +763,19 @@ static __init bool get_mem_config(void) return false; } +static __init bool get_slow_mem_config(void) +{ + struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_SMBA]; + + if (!rdt_cpu_has(X86_FEATURE_SMBA)) + return false; + + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) + return __rdt_get_mem_config_amd(&hw_res->r_resctrl); + + return false; +} + static __init bool get_rdt_alloc_resources(void) { struct rdt_resource *r; @@ -780,6 +806,9 @@ static __init bool get_rdt_alloc_resources(void) if (get_mem_config()) ret = true; + if (get_slow_mem_config()) + ret = true; + return ret; } @@ -869,6 +898,9 @@ static __init void rdt_init_res_defs_amd(void) } else if (r->rid == RDT_RESOURCE_MBA) { hw_res->msr_base = MSR_IA32_MBA_BW_BASE; hw_res->msr_update = mba_wrmsr_amd; + } else if (r->rid == RDT_RESOURCE_SMBA) { + hw_res->msr_base = MSR_IA32_SMBA_BW_BASE; + hw_res->msr_update = mba_wrmsr_amd; } } } diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c index 1df0e3262bca..2dd4b8c47f23 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -209,7 +209,7 @@ static int parse_line(char *line, struct resctrl_schema *s, unsigned long dom_id; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP && - r->rid == RDT_RESOURCE_MBA) { + (r->rid == RDT_RESOURCE_MBA || r->rid == RDT_RESOURCE_SMBA)) { rdt_last_cmd_puts("Cannot pseudo-lock MBA resource\n"); return -EINVAL; } diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index e5a48f05e787..8a3dafc0dbf7 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1213,7 +1213,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp) list_for_each_entry(s, &resctrl_schema_all, list) { r = s->res; - if (r->rid == RDT_RESOURCE_MBA) + if (r->rid == RDT_RESOURCE_MBA || r->rid == RDT_RESOURCE_SMBA) continue; has_cache = true; list_for_each_entry(d, &r->domains, list) { @@ -1402,7 +1402,8 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, ctrl = resctrl_arch_get_config(r, d, closid, type); - if (r->rid == RDT_RESOURCE_MBA) + if (r->rid == RDT_RESOURCE_MBA || + r->rid == RDT_RESOURCE_SMBA) size = ctrl; else size = rdtgroup_cbm_to_size(r, d, ctrl); @@ -2845,7 +2846,8 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) list_for_each_entry(s, &resctrl_schema_all, list) { r = s->res; - if (r->rid == RDT_RESOURCE_MBA) { + if (r->rid == RDT_RESOURCE_MBA || + r->rid == RDT_RESOURCE_SMBA) { rdtgroup_init_mba(r, rdtgrp->closid); if (is_mba_sc(r)) continue;