From patchwork Tue Oct 17 12:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 154228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4091474vqb; Tue, 17 Oct 2023 05:18:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECbycupqWx1jVwO4dgTFeLRJ/3xK/adtbOBt38RZ9yYjGBNsIFREBTBN6xIW+Qng+QNou2 X-Received: by 2002:a05:6870:7d11:b0:1e9:bb3a:9a32 with SMTP id os17-20020a0568707d1100b001e9bb3a9a32mr2205473oab.0.1697545119176; Tue, 17 Oct 2023 05:18:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697545119; cv=none; d=google.com; s=arc-20160816; b=cQ8yrVW8Q+WpHAHOl9Z/BnLoN1ZXdp3RuzqhtDyX6xb6hDeSIRsDbx6iN9jTlI/yWp 5ijLTDYuAX8HaLOoJewLM6/UfMdlexAd2nkFB4szAyaA6K5WuNK5gGR49R+qvE0AK7QN aJxEEJ8TSNIny8limuQSBniWzDSdor9j2y7UvEcAMGhpQJkjwc1+/n0Zsoq6JvvJCcJf uCseI4kb1SdR8iPfsp/Wj8Kci1hXinWpEQGj4S4vfp+CbAoCsiubEVfaT8nWaasNYfXI +ZpvLrgMQZQqRttuL133BMNezhyELJgt9/WyZC0Z1CcKGoTKIkrmr+od+Ix23pGFpIe9 xLRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=XzzxsCCtkfqVr1CXVRHwouIo2pCpN1B6+HJFXxuoKUA=; fh=/LrpYnhNSCdXI7dNWIJIGk1MLGh9L751YjEufrBXfXw=; b=cHciQuQgZBuK1vXn9YsYviICsJwY2LA9oNxiShahO3cgxtMLT9IX8gFkeKHu2fVhAT jR3R1HMruSbbIzL1qt08oRDKmK31TdA8xa/4bDToxFSBpNJIHFQ0w+l+ZQu3y0Wp/D/c nzRDaoVSIs3FgwfK8NA/rV3N7N9BRPSAqXz2ZAmXrnaGHJwS5tGTziJDGEBZBdndAP20 sdmANoxcvxeZJZTEnlkOVMBIZMtMEtSR4ghJtnnmVSkAnvA5fYo6cjssdgrZV7w11h8u +lTTlF9EFRx85utk5WVOJCSL10C172WhjNEcxoAvVKS0+QIg9GxgXm7dIXUvRD7Z3UVg Ymzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LP+6TKAl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s20-20020a63af54000000b005a1d8816a2bsi1603967pgo.72.2023.10.17.05.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:18:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LP+6TKAl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 74E948029867; Tue, 17 Oct 2023 05:18:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343556AbjJQMSV (ORCPT + 19 others); Tue, 17 Oct 2023 08:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234350AbjJQMSF (ORCPT ); Tue, 17 Oct 2023 08:18:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AFEC13D; Tue, 17 Oct 2023 05:18:03 -0700 (PDT) Date: Tue, 17 Oct 2023 12:18:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697545081; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XzzxsCCtkfqVr1CXVRHwouIo2pCpN1B6+HJFXxuoKUA=; b=LP+6TKAlgtVM28Ji9tlNm/hxpxuMClDRIclTVTkJnZD3uSRCMhuG80yjZRbvv+HQXKKwcy EgKWsGLFxSun7OjVwTxrsPzkDzwCxrGA5MdbWWLialGsbMTQoFwxjyDEeBOy4uzo2M8CaA rZI2wbjDvncgbzB36+/ZoFdgjvqw1F+NSTUBUXM+YtKU7i0a7JgzINCH+AQWoZiQrDv9kN 21U/FWtKJX88D0NUuYFp733h2+ckj1mFbGRAhnQgu3FXbszrBWXmPx5BzHY5fHbtPBLSo/ AVJqOvLlIz5+f/+7QT0QuqSjQ5zSZYjLDQwrI4w5mdwtlCjrM5Sax8OShpQhbg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697545081; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XzzxsCCtkfqVr1CXVRHwouIo2pCpN1B6+HJFXxuoKUA=; b=4kWgW6g5wCFnHsMBN5W1BEPIWYu6aNHPIHk7X7I32kPodvEJ+XJDQZ4SkKnK5GYRulqERQ WhByhRcwiQdOysBQ== From: "tip-bot2 for Babu Moger" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Unwind properly from rdt_enable_ctx() Cc: Reinette Chatre , Babu Moger , "Borislav Petkov (AMD)" , Peter Newman , Tan Shaopeng , Fenghua Yu , ilpo.jarvinen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231017002308.134480-5-babu.moger@amd.com> References: <20231017002308.134480-5-babu.moger@amd.com> MIME-Version: 1.0 Message-ID: <169754508099.3135.17094712952428311617.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 05:18:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780005070863005338 X-GMAIL-MSGID: 1780005070863005338 The following commit has been merged into the x86/cache branch of tip: Commit-ID: df5f3a1dd8a6d3ddb1f07a10817f735194717422 Gitweb: https://git.kernel.org/tip/df5f3a1dd8a6d3ddb1f07a10817f735194717422 Author: Babu Moger AuthorDate: Mon, 16 Oct 2023 19:23:03 -05:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 17 Oct 2023 12:49:02 +02:00 x86/resctrl: Unwind properly from rdt_enable_ctx() rdt_enable_ctx() enables the features provided during resctrl mount. Additions to rdt_enable_ctx() are required to also modify error paths of rdt_enable_ctx() callers to ensure correct unwinding if errors are encountered after calling rdt_enable_ctx(). This is error prone. Introduce rdt_disable_ctx() to refactor the error unwinding of rdt_enable_ctx() to simplify future additions. This also simplifies cleanup in rdt_kill_sb(). Suggested-by: Reinette Chatre Signed-off-by: Babu Moger Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Peter Newman Reviewed-by: Tan Shaopeng Reviewed-by: Fenghua Yu Reviewed-by: Reinette Chatre Reviewed-by: Ilpo Järvinen Tested-by: Peter Newman Tested-by: Tan Shaopeng Link: https://lore.kernel.org/r/20231017002308.134480-5-babu.moger@amd.com --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 53 +++++++++++++++---------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 125d12d..d1b5fd7 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2308,14 +2308,6 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable) return 0; } -static void cdp_disable_all(void) -{ - if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3)) - resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false); - if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2)) - resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false); -} - /* * We don't allow rdtgroup directories to be created anywhere * except the root directory. Thus when looking for the rdtgroup @@ -2395,19 +2387,42 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn, struct rdtgroup *prgrp, struct kernfs_node **mon_data_kn); +static void rdt_disable_ctx(void) +{ + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false); + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false); + set_mba_sc(false); +} + static int rdt_enable_ctx(struct rdt_fs_context *ctx) { int ret = 0; - if (ctx->enable_cdpl2) + if (ctx->enable_cdpl2) { ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, true); + if (ret) + goto out_done; + } - if (!ret && ctx->enable_cdpl3) + if (ctx->enable_cdpl3) { ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, true); + if (ret) + goto out_cdpl2; + } - if (!ret && ctx->enable_mba_mbps) + if (ctx->enable_mba_mbps) { ret = set_mba_sc(true); + if (ret) + goto out_cdpl3; + } + + return 0; +out_cdpl3: + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false); +out_cdpl2: + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false); +out_done: return ret; } @@ -2515,13 +2530,13 @@ static int rdt_get_tree(struct fs_context *fc) } ret = rdt_enable_ctx(ctx); - if (ret < 0) - goto out_cdp; + if (ret) + goto out; ret = schemata_list_create(); if (ret) { schemata_list_destroy(); - goto out_mba; + goto out_ctx; } closid_init(); @@ -2580,11 +2595,8 @@ out_info: kernfs_remove(kn_info); out_schemata_free: schemata_list_destroy(); -out_mba: - if (ctx->enable_mba_mbps) - set_mba_sc(false); -out_cdp: - cdp_disable_all(); +out_ctx: + rdt_disable_ctx(); out: rdt_last_cmd_clear(); mutex_unlock(&rdtgroup_mutex); @@ -2816,12 +2828,11 @@ static void rdt_kill_sb(struct super_block *sb) cpus_read_lock(); mutex_lock(&rdtgroup_mutex); - set_mba_sc(false); + rdt_disable_ctx(); /*Put everything back to default values. */ for_each_alloc_capable_rdt_resource(r) reset_all_ctrls(r); - cdp_disable_all(); rmdir_all_sub(); rdt_pseudo_lock_release(); rdtgroup_default.mode = RDT_MODE_SHAREABLE;