From patchwork Tue Feb 13 18:44:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 200553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp738415dyb; Tue, 13 Feb 2024 10:46:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW3hd4qgDfldiqKp54WETjxpDbqxLRztMz7AgzxlLIplNPlvaQ4jDnLBlwzQk7sFWh8o4CUg7BOlLwuZfrtGLPGB/E0wA== X-Google-Smtp-Source: AGHT+IEI9gUVvsA3on7CNS2QFwXuvztImwiEVPAx2cqqU0vEBmZE6XesuCZ+2qJ+8PtxpMWGGZ7u X-Received: by 2002:a05:6214:2268:b0:68c:a6ab:cedf with SMTP id gs8-20020a056214226800b0068ca6abcedfmr438962qvb.28.1707849963111; Tue, 13 Feb 2024 10:46:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707849963; cv=pass; d=google.com; s=arc-20160816; b=QPZKq0e7I6uCmp/qfgfLyyzHklNVAnKxMUNyzMjvKcTAQ4Lvvet8XDSDOLqN399gXT euY08t6weeGsmac+eJJeT0Ag7fcg2JRxUqcEPm+V1M45uMc9ledQA5bPTzipxjA8lCbV i2jildFNs2ZUUEe+K5Nq8Jq2jwTQdf9MVOTAyq4yR/XKbZ8zu2pUY/WIWi6A84BOm/61 /yi1Tz+HB+rfbYkU1KhDqFa2Fy0SPeOP214/PbVlZkxdVtJoQLgHf2ZnXjguyEiKN8+B VlISmyb5S5hveFv3wWjfeple6Bhmbq/v5viyQl5/BrF76ema26n1jIoNOCS11yMPCoSG m74A== 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; bh=i/PWf0O7w77zQqYguicZljE1MqS+U4xfA2ohOvgrMKc=; fh=bjQffL4QSkRacjXWEz+X548T+NsKL6NWYfekoIwVOpM=; b=Z6QnVjgEIpCTL474IlbByGK1khhHhLcgxPpV81nF3sGnM1/1tL/JP7MAsF0uOzKGnl Yt+FCRnspHW+ZgdnVn5llIF8S+sA9lZGXepgHBW6SIidz2jkrdmQRX7hClBM/jCNnQx4 Wkl69yCIFKMkIv+VRmIu+Idt//hOFfH5ApeVWbExrq97y9Qt1bDgvhwqwZ6dGoyPBC+q sh3lTWnyEUYmc4Igka8DZg3mx87acXhk0//ctKl3nCV5ic2R7LMXr62eWWG7w8OnESyy 3s1ZnFIhgfd3ZCS/53egWidfSHwLOrb923M+AMSRPY2iT+psSYbJUN1cXN//MiO1JyqV 3FtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64094-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWfSVAjdycaXQpbTsbSyxjRjPe/64/ZO9rFUbM4NM7tFz3NeS3Ar05cNDXKo0bRgHQtIYW5f2v5AK2TbPVsLrxwXz+zWg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p10-20020a05621421ea00b0068cb4c6ecdbsi3448262qvj.317.2024.02.13.10.46.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:46:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64094-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 E20A21C20864 for ; Tue, 13 Feb 2024 18:46:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C7C26089D; Tue, 13 Feb 2024 18:45:15 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E93C60881 for ; Tue, 13 Feb 2024 18:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849914; cv=none; b=i+kyYcLScuE5xclZK28AYW0lmYje+C3JBL5JxGBMQzB7cZt+efSsJmOmhj5G0mht7m5MBFT9YMWjbGXaeBdDFdesCa42OGhrfJGQSNSdavdhbZbZYRja1uERBDnCiiKFQO7YH6uXRqEwoX5siruBIC3qzGEJMWmnch6ADRaVZTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849914; c=relaxed/simple; bh=e9JWYiCmeFsWinCmEWYZOTDNfITJiLE8EatsPyrLEfU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=e21cLK1Uef0QuLrhhti6QXmCdrlXaco+v6R5BI0p2zZw7Q15L1p/B+rEh5psyCpQ7nDX95HshEp08xA8GI3wsb5FMpNIGhhVYIcXfPQ9oxg6bpQuyo25GSwN0RXSHPKb+7EmyeioJudr9OM0dQSk1UEB0gkLAFqhwo/TNc7Y0b4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2FE2F1042; Tue, 13 Feb 2024 10:45:53 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AB1CB3F766; Tue, 13 Feb 2024 10:45:08 -0800 (PST) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Babu Moger , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v9 03/24] x86/resctrl: Create helper for RMID allocation and mondata dir creation Date: Tue, 13 Feb 2024 18:44:17 +0000 Message-Id: <20240213184438.16675-4-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240213184438.16675-1-james.morse@arm.com> References: <20240213184438.16675-1-james.morse@arm.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: 1790810482892951971 X-GMAIL-MSGID: 1790810482892951971 When monitoring is supported, each monitor and control group is allocated an RMID. For control groups, rdtgroup_mkdir_ctrl_mon() later goes on to allocate the CLOSID. MPAM's equivalent of RMID are not an independent number, so can't be allocated until the CLOSID is known. An RMID allocation for one CLOSID may fail, whereas another may succeed depending on how many monitor groups a control group has. The RMID allocation needs to move to be after the CLOSID has been allocated. Move the RMID allocation and mondata dir creation to a helper. Signed-off-by: James Morse Tested-by: Peter Newman Tested-by: Shaopeng Tan Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Reviewed-by: Shaopeng Tan Reviewed-by: Ilpo Järvinen Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger Reviewed-by: David Hildenbrand --- Changes since v4: * Fixed typo in commit message, moved some words around. --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 42 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index aa24343f1d23..4ea5a871be49 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3288,6 +3288,30 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) return ret; } +static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp) +{ + int ret; + + if (!rdt_mon_capable) + return 0; + + ret = alloc_rmid(); + if (ret < 0) { + rdt_last_cmd_puts("Out of RMIDs\n"); + return ret; + } + rdtgrp->mon.rmid = ret; + + ret = mkdir_mondata_all(rdtgrp->kn, rdtgrp, &rdtgrp->mon.mon_data_kn); + if (ret) { + rdt_last_cmd_puts("kernfs subdir error\n"); + free_rmid(rdtgrp->mon.rmid); + return ret; + } + + return 0; +} + static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, const char *name, umode_t mode, enum rdt_group_type rtype, struct rdtgroup **r) @@ -3360,20 +3384,10 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, goto out_destroy; } - if (rdt_mon_capable) { - ret = alloc_rmid(); - if (ret < 0) { - rdt_last_cmd_puts("Out of RMIDs\n"); - goto out_destroy; - } - rdtgrp->mon.rmid = ret; + ret = mkdir_rdt_prepare_rmid_alloc(rdtgrp); + if (ret) + goto out_destroy; - ret = mkdir_mondata_all(kn, rdtgrp, &rdtgrp->mon.mon_data_kn); - if (ret) { - rdt_last_cmd_puts("kernfs subdir error\n"); - goto out_idfree; - } - } kernfs_activate(kn); /* @@ -3381,8 +3395,6 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, */ return 0; -out_idfree: - free_rmid(rdtgrp->mon.rmid); out_destroy: kernfs_put(rdtgrp->kn); kernfs_remove(rdtgrp->kn);