Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp721815rwr; Thu, 27 Apr 2023 07:22:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6A7Rt6Bsu4KbtfKDsBKiliVSdOWt/8itVdZHaTaZst3OpRKcrdkVjVmGjGK388gdNjywvm X-Received: by 2002:a17:90a:1912:b0:23b:4bce:97de with SMTP id 18-20020a17090a191200b0023b4bce97demr1833206pjg.4.1682605367178; Thu, 27 Apr 2023 07:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682605367; cv=none; d=google.com; s=arc-20160816; b=TYoUI9OO0Gx5AjED8+H6llo0qKXDq+a53fQvdDp/RauPd096CGmBY15JJ+cUYldUeG cMVElZFchHWS7qTkysu1YDQVbSUJuAjrqNE+G6lNdclvTu2qeNq4OJ8Mrnq48S6jDCsc LjrXT9ws5XXP4+vffCID3x52W2Jpgdd6NTb5F5UHIfiOl3m01mkaTX/YkCOq0tWLfTHZ vsmdUQWFys+2Xr65e7ekGtZkVeNF0HXFkbPKMlJY+FHSy52x3+FdzH1aJ1JjDs2zfyeH JHvSiwnbp/gcthI6CAgsN78ty0h+R+bgA+OKH68qoEmfU7JiSQVvYqxsxtv2lerxSIwP lN5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=tVKUAxEiobfGpFEkXZ132qpbExLpO5M++VzY26+z4KU=; b=VQT8lI9o60OvpbywFfAPYqpJHXlnAPmGF7O6MEyoFkdOStvjGw9XW3OCOxrX4RS4z4 HP/YyO5hjOFv9/tr8fsg3XbHEspIfKCSRCYoLImPEl/dE0njBh1QzD6ev+VankiP/Yc6 g3gbPxtD/BPE7hBD+C7GoVvRUuGdmt4vJqVwZ8J84lXUUqJCPKypntuDPfYW18CQ4PsK AtTbNSaaTuqIf20i/CwUB+U7iglvHnHsDfwOY3adWktMBPjBA3Sph8DplTCqCpDO9Lnh 8uQpA7j6jjd0spjSAQ+2fFMi1cbfddqMSteaM9lZvFwIEctQO4T4IGHhCNSgftOdILoj MZ2w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a17090aa10500b0024b2d3e245asi19006526pjp.27.2023.04.27.07.22.31; Thu, 27 Apr 2023 07:22:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243928AbjD0OTr (ORCPT + 99 others); Thu, 27 Apr 2023 10:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243927AbjD0OTq (ORCPT ); Thu, 27 Apr 2023 10:19:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 04230212D for ; Thu, 27 Apr 2023 07:19:45 -0700 (PDT) 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 AB9DD2F4; Thu, 27 Apr 2023 07:20:28 -0700 (PDT) Received: from [10.1.196.177] (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8AF2C3F64C; Thu, 27 Apr 2023 07:19:38 -0700 (PDT) Message-ID: Date: Thu, 27 Apr 2023 15:19:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v3 12/19] x86/resctrl: Make resctrl_mounted checks explicit Content-Language: en-GB To: Reinette Chatre , x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com References: <20230320172620.18254-1-james.morse@arm.com> <20230320172620.18254-13-james.morse@arm.com> <94b54f42-a70b-498b-ca05-62528a98cea8@intel.com> From: James Morse In-Reply-To: <94b54f42-a70b-498b-ca05-62528a98cea8@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 Hi Reinette, On 01/04/2023 00:28, Reinette Chatre wrote: > On 3/20/2023 10:26 AM, James Morse wrote: >> The rdt_enable_key is switched when resctrl is mounted, and used to >> prevent a second mount of the filesystem. It also enables the >> architecture's context switch code. >> >> This requires another architecture to have the same set of static-keys, >> as resctrl depends on them too. >> >> Make the resctrl_mounted checks explicit: resctrl can keep track of >> whether it has been mounted once. This doesn't need to be combined with >> whether the arch code is context switching the CLOSID. >> Tests against the rdt_mon_enable_key become a test that resctrl is >> mounted and that monitoring is enabled. > > The last sentence above makes the code change hard to follow ... > (see below) > >> >> This will allow the static-key changing to be moved behind resctrl_arch_ >> calls. >> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c >> index f38cd2f12285..6279f5c98b39 100644 >> --- a/arch/x86/kernel/cpu/resctrl/monitor.c >> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c >> @@ -834,7 +834,7 @@ void mbm_handle_overflow(struct work_struct *work) >> >> mutex_lock(&rdtgroup_mutex); >> >> - if (!static_branch_likely(&rdt_mon_enable_key)) >> + if (!resctrl_mounted || !static_branch_likely(&rdt_mon_enable_key)) > > ... considering the text in the changelog the "resctrl_mounted" check seems > unnecessary. Looking ahead I wonder if this check would not be more > appropriate in patch 15? How so? This is secretly relying on rdt_mon_enable_key being cleared in rdt_kill_sb() when the filesystem is unmounted, otherwise the overflow thread keeps running once the filesystem is unmounted. I thought it simpler to add all these checks explicitly in one go. That makes it simpler to thin out the static keys as their 'and its mounted' behaviour is no longer relied on. I'll add comments for these cases covering why the filesystem-mounted check is needed. >> goto out_unlock; >> >> r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; >> @@ -867,8 +867,9 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms) >> unsigned long delay = msecs_to_jiffies(delay_ms); >> int cpu; >> >> - if (!static_branch_likely(&rdt_mon_enable_key)) >> + if (!resctrl_mounted || !static_branch_likely(&rdt_mon_enable_key)) >> return; > > same here If a domain comes online mbm_setup_overflow_handler() is called, if the filesystem is not mounted, there is nothing for it to do. Today this relies on the architecture having a static key that resctrl can toggle when it gets unmounted. >> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c >> index 2306fbc9a9bb..5176a85f281c 100644 >> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c >> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c >> @@ -3687,8 +3693,7 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) >> if (is_llc_occupancy_enabled()) >> INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); >> >> - /* If resctrl is mounted, add per domain monitor data directories. */ >> - if (static_branch_unlikely(&rdt_mon_enable_key)) >> + if (resctrl_mounted && static_branch_unlikely(&rdt_mon_enable_key)) >> mkdir_mondata_subdir_allrdtgrp(r, d); >> >> return 0; > > Above also, the resctrl_mounted check does not seem to be needed. Today its implicit in the rdt_mon_enable_key. If the filesystem isn't mounted, there is no need to create the directories as no-one can see them. (it does look like it would be harmless as kernfs_create_root() is called once at init time). Instead this work gets done at mount time by rdt_get_tree() calling mkdir_mondata_all(). Thanks, James