From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F2B51DDEA; Sat, 4 Jan 2025 23:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736032956; cv=none; b=EuG6c7yS+ZC+n2tViB+dTJLIv9prvqw38IQb2gpUZnsjlIWsZgy6302zGHORXIr7FpU94WJVPUQhBmueV3M/BqAp6plPsgPXWzpPn2soxxBrPhFN0ded8QZZljAlkulRWZxoCWl1LnmucFYnIuxikpa9IY4tTKGpTWl1q4i9TG0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736032956; c=relaxed/simple; bh=GIP5QKKgJFalBlSUUqK8b56mVm4TJQ00MlqYe20ZICw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YAQ1PsWD+IKHXfZ0RXwGk8S/oE/6e0b6IhNRvHLt9l/Cs74KpxCSnyKhPbPsDbqzX5fzVB2fyqlm+K75o6nVaixzt/LF7cvja6AUCJSDsFTXvrTduVdbNjVmfzgKyqXFsbhu3l/M480jVv+Wc63vtlpW2pR3HHIQerd+Vy3aM94= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VucKZeP5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VucKZeP5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CCD9C4CED1; Sat, 4 Jan 2025 23:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736032956; bh=GIP5QKKgJFalBlSUUqK8b56mVm4TJQ00MlqYe20ZICw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VucKZeP5D4St+2xWibrgaKBLqfhLtwIxLg+E3BGVLm/GQp6qWOmikY8wLsv9qmRmJ vxsk44W4nu4H6zSb859EOJhPj2BBNdFVKMrOIrp/6R76cMjLtnpfMcaysIYhOTEXBP mwiQ9+pyTbLJM2wxotaGkAYhLxU+wBaNZWS1ikAmwc8fnXriSPblTWtB1dWj35rSJH zZVPndZlye6tGcmjl5XqswQ5ZClEJ8pc+tV++dpuJGTFxsCr+zuAZWOt8I5/3JqKEP uariv0uUY6FuNCnowd4WKFbIs14F1nKOq7+JdWjCFIlEUrq5SPzm9c/Ewo99p/7k0w nVOIdlllxJRMg== Date: Sun, 5 Jan 2025 00:22:33 +0100 From: Frederic Weisbecker To: Will Deacon Cc: LKML , Catalin Marinas , Marc Zyngier , Oliver Upton , Ard Biesheuvel , Mark Rutland , Peter Zijlstra , Vincent Guittot , Thomas Gleixner , Vlastimil Babka , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , Uladzislau Rezki , rcu@vger.kernel.org, Michal Hocko , Andrew Morton Subject: Re: [PATCH 10/19] sched,arm64: Handle CPU isolation on last resort fallback rq selection Message-ID: References: <20241211154035.75565-1-frederic@kernel.org> <20241211154035.75565-11-frederic@kernel.org> <20250103152702.GB3816@willie-the-truck> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20250103152702.GB3816@willie-the-truck> Le Fri, Jan 03, 2025 at 03:27:03PM +0000, Will Deacon a écrit : > On Wed, Dec 11, 2024 at 04:40:23PM +0100, Frederic Weisbecker wrote: > > +const struct cpumask *task_cpu_fallback_mask(struct task_struct *p) > > +{ > > + if (!static_branch_unlikely(&arm64_mismatched_32bit_el0)) > > + return housekeeping_cpumask(HK_TYPE_TICK); > > + > > + if (!is_compat_thread(task_thread_info(p))) > > + return housekeeping_cpumask(HK_TYPE_TICK); > > + > > + return system_32bit_el0_cpumask(); > > +} > > I think this is correct, but damn what we really want to ask for is the > intersection of task_cpu_possible_mask(p) and > housekeeping_cpumask(HK_TYPE_TICK). It's a shame to duplicate the logic > in task_cpu_possible_mask() here because we don't want to allocate a > temporary mask. Yeah I know :-/ > > Maybe we could have a helper to consolidate things a little? > > static inline const struct cpumask * > __task_cpu_possible_mask(struct task_struct *p, const struct cpumask *mask) > { > if (!static_branch_unlikely(&arm64_mismatched_32bit_el0)) > return mask; > > if (!is_compat_thread(task_thread_info(p))) > return mask; > > return system_32bit_el0_cpumask(); > } > > Then we could call that from both task_cpu_possible_mask() and > task_cpu_fallback_mask(), but passing 'cpu_possible_mask' and > housekeeping_cpumask(HK_TYPE_TICK) for the 'mask' argument respectively? Good point! How is the following updated version? --- From: Frederic Weisbecker Date: Fri, 27 Sep 2024 00:48:59 +0200 Subject: [PATCH 2/2] sched,arm64: Handle CPU isolation on last resort fallback rq selection When a kthread or any other task has an affinity mask that is fully offline or unallowed, the scheduler reaffines the task to all possible CPUs as a last resort. This default decision doesn't mix up very well with nohz_full CPUs that are part of the possible cpumask but don't want to be disturbed by unbound kthreads or even detached pinned user tasks. Make the fallback affinity setting aware of nohz_full. Suggested-by: Michal Hocko Signed-off-by: Frederic Weisbecker --- arch/arm64/include/asm/cpufeature.h | 1 + arch/arm64/include/asm/mmu_context.h | 14 +++++++++++--- arch/arm64/kernel/cpufeature.c | 5 +++++ include/linux/mmu_context.h | 1 + kernel/sched/core.c | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 8b4e5a3cd24c..cac5efc836c0 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -671,6 +671,7 @@ static inline bool supports_clearbhb(int scope) } const struct cpumask *system_32bit_el0_cpumask(void); +const struct cpumask *fallback_32bit_el0_cpumask(void); DECLARE_STATIC_KEY_FALSE(arm64_mismatched_32bit_el0); static inline bool system_supports_32bit_el0(void) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 48b3d9553b67..0dbe3b29049b 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -271,18 +271,26 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next, } static inline const struct cpumask * -task_cpu_possible_mask(struct task_struct *p) +__task_cpu_possible_mask(struct task_struct *p, const struct cpumask *mask) { if (!static_branch_unlikely(&arm64_mismatched_32bit_el0)) - return cpu_possible_mask; + return mask; if (!is_compat_thread(task_thread_info(p))) - return cpu_possible_mask; + return mask; return system_32bit_el0_cpumask(); } + +static inline const struct cpumask * +task_cpu_possible_mask(struct task_struct *p) +{ + return __task_cpu_possible_mask(p, cpu_possible_mask); +} #define task_cpu_possible_mask task_cpu_possible_mask +const struct cpumask *task_cpu_fallback_mask(struct task_struct *p); + void verify_cpu_asid_bits(void); void post_ttbr_update_workaround(void); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 3c87659c14db..a983e8660987 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1642,6 +1642,11 @@ const struct cpumask *system_32bit_el0_cpumask(void) return cpu_possible_mask; } +const struct cpumask *task_cpu_fallback_mask(struct task_struct *p) +{ + return __task_cpu_possible_mask(p, housekeeping_cpumask(HK_TYPE_TICK)); +} + static int __init parse_32bit_el0_param(char *str) { allow_mismatched_32bit_el0 = true; diff --git a/include/linux/mmu_context.h b/include/linux/mmu_context.h index bbaec80c78c5..ac01dc4eb2ce 100644 --- a/include/linux/mmu_context.h +++ b/include/linux/mmu_context.h @@ -24,6 +24,7 @@ static inline void leave_mm(void) { } #ifndef task_cpu_possible_mask # define task_cpu_possible_mask(p) cpu_possible_mask # define task_cpu_possible(cpu, p) true +# define task_cpu_fallback_mask(p) housekeeping_cpumask(HK_TYPE_TICK) #else # define task_cpu_possible(cpu, p) cpumask_test_cpu((cpu), task_cpu_possible_mask(p)) #endif diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 95e40895a519..233b50b0e123 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3534,7 +3534,7 @@ static int select_fallback_rq(int cpu, struct task_struct *p) * * More yuck to audit. */ - do_set_cpus_allowed(p, task_cpu_possible_mask(p)); + do_set_cpus_allowed(p, task_cpu_fallback_mask(p)); state = fail; break; case fail: -- 2.46.0