From nobody Mon Nov 25 07:41:37 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2087.outbound.protection.outlook.com [40.107.92.87]) (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 3F34420C46D; Tue, 29 Oct 2024 23:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730244372; cv=fail; b=AieJOzYE6XJipma3nyc0V9+eQIvOadiXRNilK8fjeMwXBuLZwURVy9ryD4gcyjeeM77B81fAqOfLQHeGuGx3TDVSnP/pmMkdObvIEZhYy6+MKOJqAfFzVwOLXN2iKDWlFVJEYJiftnLdK9g5DZ9aAcV6WW9X68YlO/aSBKDo9+g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730244372; c=relaxed/simple; bh=9m65ClpxNVfQlngwhM8XM95G1YPtOlBC5Z18c1+VEgo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V9VRzsLLXPFeT4JqIZsgUO1H5w/tLpEUUyvPDN7dOoN+0aHUTd49SHJ+fCtI6efmyVqNzYrmp8jsMSH/PUmhr3Ph0KkPqGhD7fATYLMZV+bAK2HHR2UrixHOdOIXxk23iEeJaoz1Oeugd/c3AP3jNmOM4yFTnFdJ8pzjC2pwpRM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=bw+zQqzh; arc=fail smtp.client-ip=40.107.92.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="bw+zQqzh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h1e0VMvRUWSe/TJMe37Hab/JvZVby/Af6UKedZQgs0drcbj3Lglx22o+N1WvP6DRyanOjMwmliTWxqu4k7tPmdKzrZPBlvaRr5VNyiGHL3J8JwFlTX+EbSixsB7fwaC39d9LavWL5tgIkyzVkzL6PBENCJ4glQ1NQfJV91aL9Oyogq81aebIT4xiPIuZ1WGDuDOVzm56zpZ28+Ciq/QfVfywr4LYzKDp7ct8FPs85B8RtKg1lgrY7Klbe3dOuFEQD+Ejp+MM4xV10yiOwrhuZ+5TzO5fVWvaNLrOzcn6AnO0gPgsT2qAMv9noEWFo1oZXPPEe3ptCq3I6fLu/xsLcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=XpuUQzZ3m6n5peXlKD8Llgs5qGiEScsi5EAcCniIV30=; b=sWa0dxrtEFUHFzuvDKgrZt8uGfheZkQ+38Buwe4cT2mO8ZcQObaL/A/pWrXxrB/TehyPy5vJQhvXSb/LNjeGAl0thAJCfYA/atZbEn7HOu6FnZTaeo/uEn26vLi3kfE8+fRpziTy0I3tkDEdSS4plIFo/zXS/hYeL4VVR2EwD8glbXNI+fNZSry8pg6EKh2t7slbLXJ4wDeIAn2/79ubmozl6GoVvBHduCjA6dsKrhftaDsMZP95czU5kld1X64fAuEsPiz1TdoBKS35R3QNgQsas98xEwkU21DF2X8cNaGFmoNmuoLDsw1D46zZyfMgbNxHPHdwfDPAEbCVHKJFXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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 (0) 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=XpuUQzZ3m6n5peXlKD8Llgs5qGiEScsi5EAcCniIV30=; b=bw+zQqzhRjlApSuNjgXDxxeKwcdJoGR9g0j1PLquFIhrwDXJC1d886rWMp64lc3jkShe7JjQoppXKjzRjQ488L7TX4JnEyYo5vT0kiFk9gBovIw1K5pKOPWZ8RR01A6dvA0oOk5heELleAJGomTRAt6XC8TIwoY9T7ulm/W6BKA= Received: from SN7PR04CA0236.namprd04.prod.outlook.com (2603:10b6:806:127::31) by PH8PR12MB7303.namprd12.prod.outlook.com (2603:10b6:510:220::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Tue, 29 Oct 2024 23:26:04 +0000 Received: from SA2PEPF00001504.namprd04.prod.outlook.com (2603:10b6:806:127:cafe::cb) by SN7PR04CA0236.outlook.office365.com (2603:10b6:806:127::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.17 via Frontend Transport; Tue, 29 Oct 2024 23:26:04 +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 SA2PEPF00001504.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Tue, 29 Oct 2024 23:26:04 +0000 Received: from bmoger-ubuntu.amd.com (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.2507.39; Tue, 29 Oct 2024 18:25:45 -0500 From: Babu Moger To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v9 26/26] x86/resctrl: Introduce interface to modify assignment states of the groups Date: Tue, 29 Oct 2024 18:21:58 -0500 Message-ID: <1dfa8b184a00d94013470b2818c23fd8eab66baa.1730244116.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001504:EE_|PH8PR12MB7303:EE_ X-MS-Office365-Filtering-Correlation-Id: c0e3a92b-a106-4d13-1754-08dcf8710ede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZUdQb3ZtbDI3MktURFlXamluU2FTTkZWQ1dTc3ptdGVhQTlzUnBIKzBkY1cv?= =?utf-8?B?d092MjQrb2dCbURJcGhrSzZCWWRoSzY3UEZKcHVmNDEweWpuYmVSZEYzVHQ3?= =?utf-8?B?TCtOVjlRRUV3aXc3RGhCU3A1bjYrOGFOcS9xRmlVWm5hVEJvNzArbW84bjJI?= =?utf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.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 23:26:04.3259 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0e3a92b-a106-4d13-1754-08dcf8710ede 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: SA2PEPF00001504.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7303 Introduce the interface to assign MBM events in mbm_cntr_assign mode. Events can be enabled or disabled by writing to file /sys/fs/resctrl/info/L3_MON/mbm_assign_control Format is similar to the list format with addition of opcode for the assignment operation. "//" Format for specific type of groups: * Default CTRL_MON group: "//" * Non-default CTRL_MON group: "//" * Child MON group of default CTRL_MON group: "//" * Child MON group of non-default CTRL_MON group: "//" Domain_id '*' will apply the flags on all the domains. Opcode can be one of the following: =3D Update the assignment to match the flags + Assign a new MBM event without impacting existing assignments. - Unassign a MBM event from currently assigned events. Assignment flags can be one of the following: t MBM total event l MBM local event tl Both total and local MBM events _ None of the MBM events. Valid only with '=3D' opcode. This flag cannot be combined with other flags. Signed-off-by: Babu Moger --- v9: Fixed handling special case '//0=3D' and '//". Removed extra strstr() call. Added generic failure text when assignment operation fails. Corrected user documentation format texts. v8: Moved unassign as the first action during the assign modification. Assign none "_" takes priority. Cannot be mixed with other flags. Updated the documentation and .rst file format. htmldoc looks ok. v7: Simplified the parsing (strsep(&token, "//") in rdtgroup_mbm_assign_con= trol_write(). Added mutex lock in rdtgroup_mbm_assign_control_write() while processin= g. Renamed rdtgroup_find_grp to rdtgroup_find_grp_by_name. Fixed rdtgroup_str_to_mon_state to return error for invalid flags. Simplified the calls rdtgroup_assign_cntr by merging few functions earl= ier. Removed ABMC reference in FS code. Reinette commented about handling the combination of flags like 'lt_' a= nd '_lt'. Not sure if we need to change the behaviour here. Processed them sequen= cially right now. Users have the liberty to pass the flags. Restricting it might be a pro= blem later. v6: Added support assign all if domain id is '*' Fixed the allocation of counter id if it not assigned already. v5: Interface name changed from mbm_assign_control to mbm_control. Fixed opcode and flags combination. '=3D_" is valid. "-_" amd "+_" is not valid. Minor message update. Renamed the function with prefix - rdtgroup_. Corrected few documentation mistakes. Rebase related changes after SNC support. v4: Added domain specific assignments. Fixed the opcode parsing. v3: New patch. Addresses the feedback to provide the global assignment interface. https://lore.kernel.org/lkml/c73f444b-83a1-4e9a-95d3-54c5165ee782@intel= .com/ --- Documentation/arch/x86/resctrl.rst | 116 +++++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 10 ++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 236 ++++++++++++++++++++++++- 3 files changed, 360 insertions(+), 2 deletions(-) diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/re= sctrl.rst index 590727bec44b..d0a107d251ec 100644 --- a/Documentation/arch/x86/resctrl.rst +++ b/Documentation/arch/x86/resctrl.rst @@ -347,7 +347,8 @@ with the following files: t MBM total event is assigned. l MBM local event is assigned. tl Both MBM total and local events are assigned. - _ None of the MBM events are assigned. + _ None of the MBM events are assigned. Only works with opcode '=3D' for= write + and cannot be combined with other flags. =20 Examples: :: @@ -365,6 +366,119 @@ with the following files: There are four resctrl groups. All the groups have total and local MBM ev= ents assigned on domain 0 and 1. =20 + Assignment state can be updated by writing to the interface. + + Format is similar to the list format with addition of opcode for the + assignment operation. + + "//" + + Format for each type of groups: + + * Default CTRL_MON group: + "//" + + * Non-default CTRL_MON group: + "//" + + * Child MON group of default CTRL_MON group: + "//" + + * Child MON group of non-default CTRL_MON group: + "//" + + Domain_id '*' will apply the flags on all the domains. + + Opcode can be one of the following: + :: + + =3D Update the assignment to match the MBM event. + + Assign a new MBM event without impacting existing assignments. + - Unassign a MBM event from currently assigned events. + + Examples: + Initial group status: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=3Dtl;1=3Dtl; + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=3Dtl;1=3Dtl; + //0=3Dtl;1=3Dtl; + /child_default_mon_grp/0=3Dtl;1=3Dtl; + + To update the default group to assign only total MBM event on domain 0: + :: + + # echo "//0=3Dt" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=3Dtl;1=3Dtl; + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=3Dtl;1=3Dtl; + //0=3Dt;1=3Dtl; + /child_default_mon_grp/0=3Dtl;1=3Dtl; + + To update the MON group child_default_mon_grp to remove total MBM event o= n domain 1: + :: + + # echo "/child_default_mon_grp/1-t" > /sys/fs/resctrl/info/L3_MON/mbm_a= ssign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=3Dtl;1=3Dtl; + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=3Dtl;1=3Dtl; + //0=3Dt;1=3Dtl; + /child_default_mon_grp/0=3Dtl;1=3Dl; + + To update the MON group non_default_ctrl_mon_grp/child_non_default_mon_gr= p to unassign + both local and total MBM events on domain 1: + :: + + # echo "non_default_ctrl_mon_grp/child_non_default_mon_grp/1=3D_" > + /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=3Dtl;1=3Dtl; + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=3Dtl;1=3D_; + //0=3Dt;1=3Dtl; + /child_default_mon_grp/0=3Dtl;1=3Dl; + + To update the default group to add a local MBM event domain 0. + :: + + # echo "//0+l" > /sys/fs/resctrl/info/L3_MON/mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=3Dtl;1=3Dtl; + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=3Dtl;1=3D_; + //0=3Dtl;1=3Dtl; + /child_default_mon_grp/0=3Dtl;1=3Dl; + + To update the non default CTRL_MON group non_default_ctrl_mon_grp to unas= sign all the + MBM events on all the domains. + :: + + # echo "non_default_ctrl_mon_grp//*=3D_" > /sys/fs/resctrl/info/L3_MON/= mbm_assign_control + + Assignment status after the update: + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_control + non_default_ctrl_mon_grp//0=3D_;1=3D_; + non_default_ctrl_mon_grp/child_non_default_mon_grp/0=3Dtl;1=3D_; + //0=3Dtl;1=3Dtl; + /child_default_mon_grp/0=3Dtl;1=3Dl; + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index b90d8c90b4b6..3ccaea6a2803 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -74,6 +74,16 @@ */ #define MBM_EVENT_ARRAY_INDEX(_event) ((_event) - 2) =20 +/* + * Assignment flags for mbm_cntr_assign feature + */ +enum { + ASSIGN_NONE =3D 0, + ASSIGN_TOTAL =3D BIT(QOS_L3_MBM_TOTAL_EVENT_ID), + ASSIGN_LOCAL =3D BIT(QOS_L3_MBM_LOCAL_EVENT_ID), + ASSIGN_INVALID, +}; + /** * cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those = that * aren't marked nohz_full diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 5cc40eacbe85..9fe419d0c536 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1082,6 +1082,239 @@ static int rdtgroup_mbm_assign_control_show(struct = kernfs_open_file *of, return 0; } =20 +static int rdtgroup_str_to_mon_state(char *flag) +{ + int i, mon_state =3D ASSIGN_NONE; + + if (!strlen(flag)) + return ASSIGN_INVALID; + + for (i =3D 0; i < strlen(flag); i++) { + switch (*(flag + i)) { + case 't': + mon_state |=3D ASSIGN_TOTAL; + break; + case 'l': + mon_state |=3D ASSIGN_LOCAL; + break; + case '_': + return ASSIGN_NONE; + default: + return ASSIGN_INVALID; + } + } + + return mon_state; +} + +static struct rdtgroup *rdtgroup_find_grp_by_name(enum rdt_group_type rtyp= e, + char *p_grp, char *c_grp) +{ + struct rdtgroup *rdtg, *crg; + + if (rtype =3D=3D RDTCTRL_GROUP && *p_grp =3D=3D '\0') { + return &rdtgroup_default; + } else if (rtype =3D=3D RDTCTRL_GROUP) { + list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) + if (!strcmp(p_grp, rdtg->kn->name)) + return rdtg; + } else if (rtype =3D=3D RDTMON_GROUP) { + list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) { + if (!strcmp(p_grp, rdtg->kn->name)) { + list_for_each_entry(crg, &rdtg->mon.crdtgrp_list, + mon.crdtgrp_list) { + if (!strcmp(c_grp, crg->kn->name)) + return crg; + } + } + } + } + + return NULL; +} + +static int rdtgroup_process_flags(struct rdt_resource *r, + enum rdt_group_type rtype, + char *p_grp, char *c_grp, char *tok) +{ + int op, mon_state, assign_state, unassign_state; + char *dom_str, *id_str, *op_str; + struct rdt_mon_domain *d; + struct rdtgroup *rdtgrp; + unsigned long dom_id; + int ret, found =3D 0; + + rdtgrp =3D rdtgroup_find_grp_by_name(rtype, p_grp, c_grp); + + if (!rdtgrp) { + rdt_last_cmd_puts("Not a valid resctrl group\n"); + return -EINVAL; + } + +next: + if (!tok || tok[0] =3D=3D '\0') + return 0; + + /* Start processing the strings for each domain */ + dom_str =3D strim(strsep(&tok, ";")); + + op_str =3D strpbrk(dom_str, "=3D+-"); + + if (op_str) { + op =3D *op_str; + } else { + rdt_last_cmd_puts("Missing operation =3D, +, - character\n"); + return -EINVAL; + } + + id_str =3D strsep(&dom_str, "=3D+-"); + + /* Check for domain id '*' which means all domains */ + if (id_str && *id_str =3D=3D '*') { + d =3D NULL; + goto check_state; + } else if (!id_str || kstrtoul(id_str, 10, &dom_id)) { + rdt_last_cmd_puts("Missing domain id\n"); + return -EINVAL; + } + + /* Verify if the dom_id is valid */ + list_for_each_entry(d, &r->mon_domains, hdr.list) { + if (d->hdr.id =3D=3D dom_id) { + found =3D 1; + break; + } + } + + if (!found) { + rdt_last_cmd_printf("Invalid domain id %ld\n", dom_id); + return -EINVAL; + } + +check_state: + mon_state =3D rdtgroup_str_to_mon_state(dom_str); + + if (mon_state =3D=3D ASSIGN_INVALID) { + rdt_last_cmd_puts("Invalid assign flag\n"); + goto out_fail; + } + + assign_state =3D 0; + unassign_state =3D 0; + + switch (op) { + case '+': + if (mon_state =3D=3D ASSIGN_NONE) { + rdt_last_cmd_puts("Invalid assign opcode\n"); + goto out_fail; + } + assign_state =3D mon_state; + break; + case '-': + if (mon_state =3D=3D ASSIGN_NONE) { + rdt_last_cmd_puts("Invalid assign opcode\n"); + goto out_fail; + } + unassign_state =3D mon_state; + break; + case '=3D': + assign_state =3D mon_state; + unassign_state =3D (ASSIGN_TOTAL | ASSIGN_LOCAL) & ~assign_state; + break; + default: + break; + } + + if (unassign_state & ASSIGN_TOTAL) { + ret =3D rdtgroup_unassign_cntr_event(r, rdtgrp, d, QOS_L3_MBM_TOTAL_EVEN= T_ID); + if (ret) + goto out_fail; + } + + if (unassign_state & ASSIGN_LOCAL) { + ret =3D rdtgroup_unassign_cntr_event(r, rdtgrp, d, QOS_L3_MBM_LOCAL_EVEN= T_ID); + if (ret) + goto out_fail; + } + + if (assign_state & ASSIGN_TOTAL) { + ret =3D rdtgroup_assign_cntr_event(r, rdtgrp, d, QOS_L3_MBM_TOTAL_EVENT_= ID); + if (ret) + goto out_fail; + } + + if (assign_state & ASSIGN_LOCAL) { + ret =3D rdtgroup_assign_cntr_event(r, rdtgrp, d, QOS_L3_MBM_LOCAL_EVENT_= ID); + if (ret) + goto out_fail; + } + + goto next; + +out_fail: + rdt_last_cmd_printf("Assign operation '%c%s' failed on the group %s/%s/\n= ", + op, dom_str, p_grp, c_grp); + + return -EINVAL; +} + +static ssize_t rdtgroup_mbm_assign_control_write(struct kernfs_open_file *= of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdt_resource *r =3D of->kn->parent->priv; + char *token, *cmon_grp, *mon_grp; + enum rdt_group_type rtype; + int ret; + + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') + return -EINVAL; + + buf[nbytes - 1] =3D '\0'; + + cpus_read_lock(); + mutex_lock(&rdtgroup_mutex); + + rdt_last_cmd_clear(); + + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { + rdt_last_cmd_puts("mbm_cntr_assign mode is not enabled\n"); + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + return -EINVAL; + } + + while ((token =3D strsep(&buf, "\n")) !=3D NULL) { + /* + * The write command follows the following format: + * =E2=80=9C//=E2= =80=9D + * Extract the CTRL_MON group. + */ + cmon_grp =3D strsep(&token, "/"); + + /* + * Extract the MON_GROUP. + * strsep returns empty string for contiguous delimiters. + * Empty mon_grp here means it is a RDTCTRL_GROUP. + */ + mon_grp =3D strsep(&token, "/"); + + if (*mon_grp =3D=3D '\0') + rtype =3D RDTCTRL_GROUP; + else + rtype =3D RDTMON_GROUP; + + ret =3D rdtgroup_process_flags(r, rtype, cmon_grp, mon_grp, token); + if (ret) + break; + } + + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + + return ret ?: nbytes; +} + #ifdef CONFIG_PROC_CPU_RESCTRL =20 /* @@ -2383,9 +2616,10 @@ static struct rftype res_common_files[] =3D { }, { .name =3D "mbm_assign_control", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, .seq_show =3D rdtgroup_mbm_assign_control_show, + .write =3D rdtgroup_mbm_assign_control_write, }, { .name =3D "mbm_assign_mode", --=20 2.34.1