Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp750030lqc; Fri, 8 Mar 2024 10:27:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXhbAe5SvpmKlejv5W4saYr/DA4jCzqcTxkJ9COkxP+hTt3EIINR2H1mGR/IiuK3ciXS7toqwz1fYPeY02hJPFsXGA8k1pbs/j0fabyJA== X-Google-Smtp-Source: AGHT+IE91+P6TdBEv11inLdz7iPaQW9R0gA30zYBcqkREvMAlldrIldtGb58gr0/FRF3GWZF+MCJ X-Received: by 2002:a05:6a00:39a6:b0:6e5:8fad:6f75 with SMTP id fi38-20020a056a0039a600b006e58fad6f75mr23140795pfb.19.1709922465347; Fri, 08 Mar 2024 10:27:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709922465; cv=pass; d=google.com; s=arc-20160816; b=PSEYeizejtyJI0Vh8km8oge8ajPm8MDhDy+TlChLzkohKOoxWrU0OyVzKX8Y3+d1cq nDWFzC6wtDNHKgEg9i8Lad1o8iqXs7urbkg9/D6lRMaoGu8R2A89+6S6TdzhnpZvv+8N k0a338CrnvHqTQC3NzUhrUYuSK/etP0Q1Rv3n51NkkCHXVfC4lrbcpY3hjJkrqhJushk Jijv3Fz01OnI3udqJ7UHYMYU2UYnxzQWUL762TzELS7lTQxNL43d9gHOs/qFFQq3hq0e DV9q9m8HedX3jwE/MlU2n3DQCDEuZH6I1FxJpI953So/D4+T/xDX/Qs7j8DRa7dza8Pd dgiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=YfZ+lOBvRNloFPL2Pfw2Q0xi+/SDTRdSll9pxSlNwQY=; fh=S00fxflteC4pO8OHdk8xbeBJC2TBGMtJ/Sn4k6jzkRM=; b=YOBNxhn4YpzH1oTHP/CZ0CjuKiZMdlwm6JmX5MO+yln8tQVAiq6j96JndMYtvc2qCM 7kqALwLW9l1MCq6lP+XXTzKzzfENAihbz4IxH+K33dLRER4PC7aiEVHT9K3xUMgCTV6Z 4YoqmducJi7o2BGT/mKiKHwCdt8KUCoMtDRWHVQCO4J8a9Do3bRTlk3dQAz7gqj/FUaX JHtgT6tYmoVN4rPxJwP2I5B+cEQ1fg5IpVroiYz3oyorZ9E9L1VXClPMdtIREs6eYPbp dg3ubiHAadSPB1rc68xy3ZWfn5GPy2RQOZuGnOO93YGGUKphp4laDR8t7ZjI51p+IK8V lt3Q==; 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-97456-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97456-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b14-20020a63d30e000000b005dc80a2a308si16943pgg.436.2024.03.08.10.27.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97456-linux.lists.archive=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-97456-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97456-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 69E55283396 for ; Fri, 8 Mar 2024 18:27:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFBEE59171; Fri, 8 Mar 2024 18:27:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FA5954792; Fri, 8 Mar 2024 18:27:02 +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=1709922425; cv=none; b=AJ/i/3FJKGi5IKuAM78dth3RfZeO+i+e/mYJYV/889VvOXQZJGOZCuUTQbYnGucuYsjDjjGaADIHgGZRtMfO7stXyehkbmXFnD3UQTfRlB9CKGXch77PrsbvIBoSDw0evqhXrdAOKdTH5nFjqUifUhCs8/eFQy2FIKV1rhTdwbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922425; c=relaxed/simple; bh=s5b1azrAudYZ5DSM3rTJNg53hbvc+UesOYbnPqfEu7Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PPN6/vNKFico7pKc1M9Yn3EQCnBmSa8D3uRoIT1mJKDg0k+pTss3d/vXYz3fCcqhRE2UXA4TKUk+GV8U5aYY8URnyJb3YR+WvK+0lEs7VmjenOaMS5ARJ+KinMy6svDDx0smjZqJ65+nlHzq13ZhZyYFd1MqzPwjnbSqWlLHx5Q= 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 3A80CC15; Fri, 8 Mar 2024 10:27:38 -0800 (PST) Received: from [10.1.197.60] (eglon.cambridge.arm.com [10.1.197.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 59A9A3F738; Fri, 8 Mar 2024 10:26:58 -0800 (PST) Message-ID: <26f23ba4-4ca5-41f6-b920-08515f494ae5@arm.com> Date: Fri, 8 Mar 2024 18:26:56 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/2] x86/resctrl: Pass domain to target CPU Content-Language: en-GB To: Tony Luck , Fenghua Yu , Reinette Chatre , Peter Newman , Jonathan Corbet , Shuah Khan , x86@kernel.org Cc: Shaopeng Tan , Jamie Iles , Babu Moger , Randy Dunlap , Drew Fustini , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, patches@lists.linux.dev References: <20240228112215.8044-tony.luck@intel.com> <20240228193717.8170-1-tony.luck@intel.com> From: James Morse In-Reply-To: <20240228193717.8170-1-tony.luck@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Tony, On 28/02/2024 19:36, Tony Luck wrote: > reset_all_ctrls() and resctrl_arch_update_domains() use on_each_cpu_mask() > to call rdt_ctrl_update() on potentially one CPU from each domain. > > But this means rdt_ctrl_update() needs to figure out which domain to > apply changes to. Doing so requires a search of all domains in a resource, > which can only be done safely if cpus_lock is held. Both callers do hold > this lock, but there isn't a way for a function called on another CPU > via IPI to verify this. > > Commit c0d848fcb09d ("x86/resctrl: Remove lockdep annotation that triggers > false positive") removed the incorrect assertions. > > Add the target domain to the msr_param structure and > call rdt_ctrl_update() for each domain separately using > smp_call_function_single(). This means that rdt_ctrl_update() doesn't > need to search for the domain and get_domain_from_cpu() can safely assert > that the cpus_lock is held since the remaining callers do not use IPI. > diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c > index 83e40341583e..acf52aa185e0 100644 > --- a/arch/x86/kernel/cpu/resctrl/core.c > +++ b/arch/x86/kernel/cpu/resctrl/core.c > @@ -362,6 +362,8 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) > { > struct rdt_domain *d; > > + lockdep_assert_cpus_held(); (Huzzah!) > list_for_each_entry(d, &r->domains, list) { > /* Find the domain that contains this CPU */ > if (cpumask_test_cpu(cpu, &d->cpu_mask)) > diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c > index 7997b47743a2..a3a0fd80daa8 100644 > --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c > +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c > @@ -315,27 +300,27 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) [..] > - msr_param.res = NULL; > list_for_each_entry(d, &r->domains, list) { > hw_dom = resctrl_to_arch_dom(d); > + msr_param.res = NULL; > + msr_param.dom = d; > for (t = 0; t < CDP_NUM_TYPES; t++) { > cfg = &hw_dom->d_resctrl.staged_config[t]; > if (!cfg->have_new_ctrl) > continue; > > idx = get_config_index(closid, t); > - if (!apply_config(hw_dom, cfg, idx, cpu_mask)) > + if (cfg->new_ctrl == hw_dom->ctrl_val[idx]) > continue; > + hw_dom->ctrl_val[idx] = cfg->new_ctrl; > + cpu = cpumask_any(&d->cpu_mask); If this CPU is part of the domain, then cpumask_any() could chose a different CPU leading to an IPI, where this CPU could have done the work itself. smp_call_function_any() has the logic to try and run on this CPU if possible. As d->cpu_mask is still valid when you call smp_call_function_single(), could we use smp_call_function_any() instead? > if (!msr_param.res) { > msr_param.low = idx; > @@ -346,17 +331,10 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) > msr_param.high = max(msr_param.high, idx + 1); > } > } > + if (msr_param.res) > + smp_call_function_single(cpu, rdt_ctrl_update, &msr_param, 1); > } > diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > index 011e17efb1a6..da4f13db4161 100644 > --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c > +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > @@ -2813,16 +2813,13 @@ static int reset_all_ctrls(struct rdt_resource *r) > @@ -2834,17 +2831,14 @@ static int reset_all_ctrls(struct rdt_resource *r) > */ > list_for_each_entry(d, &r->domains, list) { > hw_dom = resctrl_to_arch_dom(d); > - cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask); > + cpu = cpumask_any(&d->cpu_mask); Same comment about picking an unlucky CPU here, smp_call_function_any() can improve our chances. > for (i = 0; i < hw_res->num_closid; i++) > hw_dom->ctrl_val[i] = r->default_ctrl; > + msr_param.dom = d; > + smp_call_function_single(cpu, rdt_ctrl_update, &msr_param, 1); > } Still: Reviewed-by: James Morse Thanks! James