Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp107707rdh; Tue, 13 Feb 2024 10:46:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZo5r8CwnypI0HyQ7BlfIF+UNxpWWXSwC0+TrOTsQYU+3W9yltic2NVNwx0MnHqoK1wZ0uf1FiCPYvFNcwPdvzmJjfCXk042xC6AppNA== X-Google-Smtp-Source: AGHT+IGycZ3FGs1qpM/KVfTchp1Ji5SNoKnJasvOZlE3cqk/ZBK6ZUcJ5gYQErslzOjt/8cYDaMs X-Received: by 2002:a05:6402:1504:b0:560:2a89:2540 with SMTP id f4-20020a056402150400b005602a892540mr386718edw.22.1707849970545; Tue, 13 Feb 2024 10:46:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707849970; cv=pass; d=google.com; s=arc-20160816; b=cRgLwbhfDc+mTWySJQ/CcaKkSgarFnacA9VKJZVGUBvAWtLeB/L1OM1jj1LHSYMS2C nDg8QqQ3QA29N0kTojS+rsXHPb5gXNqg1KgQjUY4GD9NvoQIvDHq5bic2TwJ3uIE7Bq4 arQdf60m9gu23m7ACqUF+H7cyXhreR7lsq5yWDY6Bh7RMOPtxkGN6TbIYC/IBmeHrtBu PiOUPT5MfuoiSFB+XFLD7KBlnS7YiEeURILSXUceUZKFlw+bq+n2NhPQWkgpJXZ5FTLO uv/0dMPfFLofebn0pG3PFYOKFziEYvxN5eCJeX0yehRY2MP8Oj1wqAyQkqFk/cRK305G eA2g== 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=hmLpwX2wiOP/xgTST0rAoarfL9MYtsAs81Y9M0YoZuM=; fh=lp78maBpc2ehXvjOX7ZB2QWdBlCxQ+tYr5+K98rEZfk=; b=NPc8qx7JCHWsboFgAnLRDoK0lq2geffeBsixvBzl14hFxWlmRNJUJpyzzJOWgVFJOI 1pTD9KwvEQt6BYwbf68UuVoxKJr9y4x6WXoxyYjfVyKua/HHSCPOSyaqaSVCon3Uy0au XoH/VMulNUVx0NCO2q4pYCN9Emp7aVwRL5sJr8gbWZ/Q5xhwNhXs6QwAPhQdgBvSg6cO 9lx2zRjDCJYCdZXSzaJkhJmpnT1gC/t0W/WKlE9LE3KcOfnn7NrALOj/hjh0DCAM5/RM JSkhgr6ot+pnahlw1o7ipFO12Ft8bN4NrCI4y+XZDzVQalUlHIeXDqiuhNzrC/8plKRE XLow==; 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-64095-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64095-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUubkfh85Ku0wj+UZrjiBUA7k2ECQK5kGBGtsvYUgtXjBYpY90h6qsM8hm1zM0qkvhFixdqLHLBrt4VXGjFAgjtPRsIKYcDL4e8citcFA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c20-20020a50f614000000b00561e6647ffbsi1215690edn.200.2024.02.13.10.46.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:46:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64095-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64095-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64095-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 4D1D61F24F2F for ; Tue, 13 Feb 2024 18:46:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 308F660B8E; Tue, 13 Feb 2024 18:45:18 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E294A60B81 for ; Tue, 13 Feb 2024 18:45:15 +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=1707849917; cv=none; b=YIMburLYXqd+GRb3xJd306lo3ifFqlK2zc811WCjXdyf/stAJm58MbgqSmASQXKyKkL9hBWYYkDYfF1ZeWLNS1iIVKA4nzGT9h9flLiAKwAYHrTMoNQRP06iKErMDiYUEIVp/1VRNN5Tr4r2BstvXLDQKUwwvOdbkLNOHgm32KY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849917; c=relaxed/simple; bh=YcQFSWDQA1m6PdSQ0Ol/gs7JJFkLp0C6qtBwalerQcc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ekEWN2In9NXxcQbKi9l7LxmZsYEbaBsbobU2XojtCWCArseZG3vSjZy8K+xoXsMwXy9KTlJvgeRW/Mov/p7nHIAH8aF0XYAjCdRx8OZU6JMUab4vKjQayi80Id2Wh/7ADVAkzKYxDL/Ohau+btMUYda6XgKJs9jY7qnU5o3t/HA= 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 8740413D5; Tue, 13 Feb 2024 10:45:56 -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 2C8623F766; Tue, 13 Feb 2024 10:45:12 -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 Subject: [PATCH v9 04/24] x86/resctrl: Move rmid allocation out of mkdir_rdt_prepare() Date: Tue, 13 Feb 2024 18:44:18 +0000 Message-Id: <20240213184438.16675-5-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 Content-Transfer-Encoding: 8bit RMID are allocated for each monitor or control group directory, because each of these needs its own RMID. For control groups, rdtgroup_mkdir_ctrl_mon() later goes on to allocate the CLOSID. MPAM's equivalent of RMID is 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 out of mkdir_rdt_prepare() to occur in its caller, after the mkdir_rdt_prepare() call. This allows the RMID allocator to know the CLOSID. Signed-off-by: James Morse Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- Changes since v2: * Moved kernfs_activate() later to preserve atomicity of files being visible Changes since v5: * Renamed out_id_free as out_closid_free. --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 4ea5a871be49..f455a10b74ab 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3312,6 +3312,12 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp) return 0; } +static void mkdir_rdt_prepare_rmid_free(struct rdtgroup *rgrp) +{ + if (rdt_mon_capable) + free_rmid(rgrp->mon.rmid); +} + static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, const char *name, umode_t mode, enum rdt_group_type rtype, struct rdtgroup **r) @@ -3384,12 +3390,6 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, goto out_destroy; } - ret = mkdir_rdt_prepare_rmid_alloc(rdtgrp); - if (ret) - goto out_destroy; - - kernfs_activate(kn); - /* * The caller unlocks the parent_kn upon success. */ @@ -3408,7 +3408,6 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, static void mkdir_rdt_prepare_clean(struct rdtgroup *rgrp) { kernfs_remove(rgrp->kn); - free_rmid(rgrp->mon.rmid); rdtgroup_remove(rgrp); } @@ -3430,12 +3429,21 @@ static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn, prgrp = rdtgrp->mon.parent; rdtgrp->closid = prgrp->closid; + ret = mkdir_rdt_prepare_rmid_alloc(rdtgrp); + if (ret) { + mkdir_rdt_prepare_clean(rdtgrp); + goto out_unlock; + } + + kernfs_activate(rdtgrp->kn); + /* * Add the rdtgrp to the list of rdtgrps the parent * ctrl_mon group has to track. */ list_add_tail(&rdtgrp->mon.crdtgrp_list, &prgrp->mon.crdtgrp_list); +out_unlock: rdtgroup_kn_unlock(parent_kn); return ret; } @@ -3466,9 +3474,16 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn, ret = 0; rdtgrp->closid = closid; + + ret = mkdir_rdt_prepare_rmid_alloc(rdtgrp); + if (ret) + goto out_closid_free; + + kernfs_activate(rdtgrp->kn); + ret = rdtgroup_init_alloc(rdtgrp); if (ret < 0) - goto out_id_free; + goto out_rmid_free; list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups); @@ -3488,7 +3503,9 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn, out_del_list: list_del(&rdtgrp->rdtgroup_list); -out_id_free: +out_rmid_free: + mkdir_rdt_prepare_rmid_free(rdtgrp); +out_closid_free: closid_free(closid); out_common_fail: mkdir_rdt_prepare_clean(rdtgrp); -- 2.39.2