From patchwork Tue Feb 13 18:44:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 200567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp742886dyb; Tue, 13 Feb 2024 10:55:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYKLoFhY/Ug1Qp4XBq1KVYit4QbBj6bMuc8v9e5ADDW/cH6ra8wZvmLznT3dtsVi1q9Jac8G2ZimC7Og57KtQnK3JBnw== X-Google-Smtp-Source: AGHT+IGGjCwLen/3NxTbZyStjtv3vxa2EPhmYrju1xtQ2iho2spV9VAWNvZZT+t/aghWe4ESGW7W X-Received: by 2002:a17:90a:dc12:b0:298:c3b8:5e15 with SMTP id i18-20020a17090adc1200b00298c3b85e15mr404467pjv.14.1707850516078; Tue, 13 Feb 2024 10:55:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707850516; cv=pass; d=google.com; s=arc-20160816; b=SQS6j4w4LYTrSbPSGxu00/stNEVyCINe+mp+w/vTnmKPupTeZHq8GScHCw0Id5Lux3 RAIYvQssg0QS4oVw8+S4ZiJfjnbJTbYlQ3uw4VglQvb2Gjaw1cqU9tDIxQjZqT6/oI72 bUKD9/ZNM6V4gd05Oq2llKwuQEaF6JXdb9JjctZKdlul47nt1c/oRIh9jrH3oPeYiK01 FSANi0ZxwfjX+ASFtoRqzANUBwnP/Y0CEKQNvRxgj20SE6HhMvaMMkLH48j6lVcI5JNV IEIt62HjzWJAjHs5QHHy2UCduHHB9d/53vDXZu8eQqE+7OPiWRAgfdZIeatxeEXpw23B QIVw== 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=59i1OFjG0+TtAS1HTCAtk0aaAOuQs3Xjv4pSc2gIHho=; b=ppCImOw5zw/mmvRXZmIrSToxbKvUitcDSV5dhNGiZ8SRTTQ5zc0FpQBF9KdcvRWWAO zQ3e3ySq3RMWTOr7CHgnDIxkLVl5KIGR2k9a03rhz6CxVn6O9LzvNO7HVvae/5uNfHGq JZsNoru0fAy/064szKq2c6iF0UI3mpwQsllu14BLliRPMQm19OTWdDAObu7AsSFeSWPF +In7cfhzFlVJPHuaEooiyBSWfg7bH7Dbh4UqkseYL8Y1BuJ3iBXFoc/FqITGW6CNxs0W R6CCUo0iOf7zgt9fKF+sYsOu1Bc738sx9xaLNDw4JGO8MJ2JUTZGww5QkMbe7DBDZC1w K4Zg==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64095-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWlfvSozdemX4/oTl+I8203FD9U+SnxGf+Haec2eTcdSsCHLBc/G8Hnzj6pnVvkqG8l8veBBkOsDOKoSDgXOCfgR7kXPw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v23-20020a17090abb9700b002969bca1b53si2394811pjr.96.2024.02.13.10.55.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:55:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64095-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64095-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 93F9728DB2C for ; Tue, 13 Feb 2024 18:46:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A32A60BA2; Tue, 13 Feb 2024 18:45:19 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790811062777822663 X-GMAIL-MSGID: 1790811062777822663 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);