Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6846388rdb; Fri, 15 Dec 2023 09:44:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEA8OHK/I05XpBs1gkAtn8kq3flssNNejLR8d/ZkBclNTDLINz+IIoflo4mltT0jR0mPc5i X-Received: by 2002:a17:907:9483:b0:a1e:5ea5:c5d3 with SMTP id dm3-20020a170907948300b00a1e5ea5c5d3mr4086687ejc.131.1702662293948; Fri, 15 Dec 2023 09:44:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662293; cv=none; d=google.com; s=arc-20160816; b=vZew2WwynEyOG3d4Vrkd6lHWKcDPXQpOpwWNo1MyTd6c9JsBjaQ2wvkCG6warhxS/z SVH36HrmWFX7iLS9DtHAK0oQQia8G06hRDXxx9AD5p2Xiuw3x5oQEWTsoWa+udvOHaGu v/U1s53sqaNFmY/GM3QVGbdMQKYSTmkKoPZtrEcro7gCZhGjgkOuP2u4q1hD7vxDSPro muSBr9PbgNuYRi67M1ALDvsEBdAMdciPJb+6UeU49ln2B5zUXo3/gzopzhw+Gie69trd 7680Xx4fwjFRSmp29sgAdazt2cqOyTHYn/3VGn0I1xtFE+ANO7NxbzWCWxhxPyleziyg ulxg== ARC-Message-Signature: i=1; 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=srYZfZTSEcisJ3vP2z+1LAQv+VDN/1PIWk8h0CLmhns=; fh=xUB5GvUwrrIgH5LetwNPU6KAJitcZFtG8mDjXbqODWM=; b=HnnovqK10oXFv1n0O+8G0twvTdUGZQ3hqrEh1p5Qz5VM6yY8i4mR2ikL7GP6ryyJ86 4+/sltDP2ui3Np+OUeZKkCI1xbbl19AEhZ5bYAYYunmPiun7VK/VCzoY3gg/CqPV/aIM m0JF4jfuut/oXdCbr3fOGlMrErbIvgQhRiELZge37cb+xFJaIcwCXi2nPw1EoqCF5TNv I3e8qyMvNIzF+OOXSWPjt5XFDF2+T40x6e86+6tUNfMBJ0o5KtWUNHixZNANt6sTsEWB hJhc8mWW2SiIWN+cb9NAa1SHGgwJApRyBj/H0A2qP37A6pS/orHWuofn6jpODtaKadsQ ZeAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f8-20020a17090660c800b00a1e095c4e74si7611915ejk.430.2023.12.15.09.44.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:44:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1442-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; spf=pass (google.com: domain of linux-kernel+bounces-1442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1442-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id B18701F25909 for ; Fri, 15 Dec 2023 17:44:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 833CA3FE37; Fri, 15 Dec 2023 17:44:14 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ED9D3FB28 for ; Fri, 15 Dec 2023 17:44:12 +0000 (UTC) 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 0E4F3C15; Fri, 15 Dec 2023 09:44:57 -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 F06623F5A1; Fri, 15 Dec 2023 09:44: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, Babu Moger , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v8 03/24] x86/resctrl: Create helper for RMID allocation and mondata dir creation Date: Fri, 15 Dec 2023 17:43:22 +0000 Message-Id: <20231215174343.13872-4-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231215174343.13872-1-james.morse@arm.com> References: <20231215174343.13872-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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Shaopeng Tan Reviewed-by: Ilpo Järvinen Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- 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 69a1de92384a..1eb3a3075093 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3293,6 +3293,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) @@ -3365,20 +3389,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); /* @@ -3386,8 +3400,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); -- 2.20.1