From patchwork Thu Apr 20 22:06:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Luck, Tony" X-Patchwork-Id: 86058 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp655637vqo; Thu, 20 Apr 2023 15:25:07 -0700 (PDT) X-Google-Smtp-Source: AKy350acGOPzHUEPnYNzUeiFZ6wnE3VpsVKoVkbUxcwUnKWku9kHHqXudF7inZnizpW073V+LEx/ X-Received: by 2002:a05:6a00:1143:b0:63d:3ae4:7c72 with SMTP id b3-20020a056a00114300b0063d3ae47c72mr3688617pfm.0.1682029507051; Thu, 20 Apr 2023 15:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682029507; cv=none; d=google.com; s=arc-20160816; b=FgeBRIV+tf8rs85cO6neYWStTelBFPbfE2v2LSeCWSCnRbGXcS07dtOs58VaB5g5rg eHoeZpii8GvjHheNtopYbNpyZUpQVjj+h0nGCOE6xoQ4amsJF7iMvjMkOHBmVx9Ykk1g WcvcqaBXTaJxtc+1iw5mcqw+MZ++T7fIJ6TSNFjqvglZphNRR5mvr6OispXhyKHMDEF5 SES7kt7BaDKd/et6CFUsFZ1+O7ZGhGM6tYPvDWO19IbQJlc9VU2UwNj8e9N6FjsjraIf IcLblXWUFScB/0vnMbSwNoBkwnaX3YU/yKNixrqc6JhskjxQfZWG0t9pR+ODmluA8zUh 6vUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HqGajp8//BYUzpcQOyJzZMV83pMyXF6V/bxXyLpkhio=; b=x4vkFN1CRDUnqAtls8T6SDsUV20vWB7PXnjheP7+7tLwDLdBqu3BmxisdTBKbaF2+U fhrBMyBZ9ClHeXjBm4+y0h/V0GgM/iQQT3Eiya+KOvIjxwDqkiS6rMuEZjdkmFDN09/C ZBwFOmOGOXhI5gmkgwBxUQv0Wl0gCz3yavmvDgCNkqQLKYZd7Dzx5kSJKupKChlqhnlv 8kdT18tufFjI4zP5q7HIyKCUd8seOcINGW9afqsArBAKihlifXjhYbULkAJBotJEYu7X C7MiBNrCsVvyWrDSKy3hyYKJ9hhttqmLkuDDh5DNh2K1Drl7A10VMhui48t+byhcDtL3 l+ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N1EzTJuu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r17-20020aa79891000000b0063b8eec0832si2717216pfl.114.2023.04.20.15.24.55; Thu, 20 Apr 2023 15:25:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N1EzTJuu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232888AbjDTWGw (ORCPT + 99 others); Thu, 20 Apr 2023 18:06:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjDTWGt (ORCPT ); Thu, 20 Apr 2023 18:06:49 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4757F270C for ; Thu, 20 Apr 2023 15:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682028407; x=1713564407; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TX3utSJkvuG87gr/i0jCm7n2nnIrYB4p9WSinKZRLsI=; b=N1EzTJuu92cE7L979Zhqxd68LQQQ+ZId+6J9f3DFK8okBe9W7tUWnQof Sg8ENeCs5pl0h0YQeJZy9jzbVJyum3kf8nvSSS4SuoCA6UZ+rQ0H8vjGL liJnGmGb/nzN553Mo23N1P1GElEvTgt2mXg18PQ6QtvPmta+YOJ0A75ru QnwRvMbxuAeZ3QvKjYiwqh6cAays6HjVlVHLHRggUZl4zgXFxkVjj+iJO /szTx1OFdSxtUWmYqyIVgxEit/Z0keCWoKtBvXsUYS0nro8yMTK/XeGpl b8VBcM5nulXGNJaj5BLqijJD0k0UcIsqRDXoapUPPhHOHT1NWgwsYWTMh Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10686"; a="348650896" X-IronPort-AV: E=Sophos;i="5.99,213,1677571200"; d="scan'208";a="348650896" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2023 15:06:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10686"; a="724583749" X-IronPort-AV: E=Sophos;i="5.99,213,1677571200"; d="scan'208";a="724583749" Received: from agluck-desk3.sc.intel.com ([172.25.222.78]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2023 15:06:44 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Shaopeng Tan , Jamie Iles , James Morse , Babu Moger Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Tony Luck Subject: [RFC PATCH 1/7] x86/resctrl: Add register/unregister functions for driver to hook into resctrl Date: Thu, 20 Apr 2023 15:06:30 -0700 Message-Id: <20230420220636.53527-2-tony.luck@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230420220636.53527-1-tony.luck@intel.com> References: <20230420220636.53527-1-tony.luck@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763735772406043423?= X-GMAIL-MSGID: =?utf-8?q?1763735772406043423?= Just one callback at the point for the driver to be notified when the resctrl filesystem is mounted or unmounted. Virtually all drivers will need this hook to enable/disable their feature(s) as part of mount/unmount. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 13 +++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 50 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 8334eeacfec5..78513edddca0 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -204,6 +204,19 @@ struct resctrl_schema { u32 num_closid; }; +/** + * struct resctrl_driver - interface for driver to attach to resctrl + * @list: List of registered drivers + * @mount: Callback for mount/unmount + */ +struct resctrl_driver { + struct list_head list; + void (*mount)(bool mount); +}; + +int resctrl_register_driver(struct resctrl_driver *d); +void resctrl_unregister_driver(struct resctrl_driver *d); + /* The number of closid supported by this resource regardless of CDP */ u32 resctrl_arch_get_num_closid(struct rdt_resource *r); int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 6ad33f355861..3e6778bde427 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -51,6 +51,9 @@ static struct kernfs_node *kn_mongrp; /* Kernel fs node for "mon_data" directory under root */ static struct kernfs_node *kn_mondata; +static LIST_HEAD(drivers); +static bool resctrl_is_mounted; + static struct seq_buf last_cmd_status; static char last_cmd_status_buf[512]; @@ -2437,6 +2440,42 @@ static int schemata_list_create(void) return ret; } +static void driver_up(struct resctrl_driver *d) +{ + if (d->mount) + d->mount(true); +} + +static void driver_down(struct resctrl_driver *d) +{ + if (d->mount) + d->mount(false); +} + +int resctrl_register_driver(struct resctrl_driver *d) +{ + mutex_lock(&rdtgroup_mutex); + list_add(&d->list, &drivers); + + if (resctrl_is_mounted) + driver_up(d); + mutex_unlock(&rdtgroup_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(resctrl_register_driver); + +void resctrl_unregister_driver(struct resctrl_driver *d) +{ + mutex_lock(&rdtgroup_mutex); + list_del(&d->list); + + if (resctrl_is_mounted) + driver_down(d); + mutex_unlock(&rdtgroup_mutex); +} +EXPORT_SYMBOL_GPL(resctrl_unregister_driver); + static void schemata_list_destroy(void) { struct resctrl_schema *s, *tmp; @@ -2450,6 +2489,7 @@ static void schemata_list_destroy(void) static int rdt_get_tree(struct fs_context *fc) { struct rdt_fs_context *ctx = rdt_fc2context(fc); + struct resctrl_driver *d; struct rdt_domain *dom; struct rdt_resource *r; int ret; @@ -2516,6 +2556,10 @@ static int rdt_get_tree(struct fs_context *fc) mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL); } + list_for_each_entry(d, &drivers, list) + driver_up(d); + resctrl_is_mounted = true; + goto out; out_psl: @@ -2761,6 +2805,7 @@ static void rmdir_all_sub(void) static void rdt_kill_sb(struct super_block *sb) { + struct resctrl_driver *d; struct rdt_resource *r; cpus_read_lock(); @@ -2780,6 +2825,11 @@ static void rdt_kill_sb(struct super_block *sb) static_branch_disable_cpuslocked(&rdt_mon_enable_key); static_branch_disable_cpuslocked(&rdt_enable_key); kernfs_kill_sb(sb); + + list_for_each_entry(d, &drivers, list) + driver_down(d); + resctrl_is_mounted = false; + mutex_unlock(&rdtgroup_mutex); cpus_read_unlock(); }