Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15C03C433F5 for ; Wed, 24 Nov 2021 13:14:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345681AbhKXNRp (ORCPT ); Wed, 24 Nov 2021 08:17:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:53882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348743AbhKXNN7 (ORCPT ); Wed, 24 Nov 2021 08:13:59 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DDF0E61242; Wed, 24 Nov 2021 12:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637757815; bh=j9WPFj6m2DmX4szXNfQlp9MtXc8XY6ASzpBqMPa+Fp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Np7v8GaOpKpDUr53YxUre4CRR/LDAm0jIDqI/U5XjHcPmGKlH86FC97jxizw9xnWc CaNQSIpiBJdzXLtSt5ktAhD8CX2JGI0oI6pjbFWj0G482VSx+ufxkz17Chmk/YPBfL TlV8Cxtr2rU6wL68bFPS+6VmIblLOpgd787xoieg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jing-Ting Wu , Vincent Donnefort , "Peter Zijlstra (Intel)" , Valentin Schneider , Vincent Guittot , Sasha Levin Subject: [PATCH 4.19 285/323] sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain() Date: Wed, 24 Nov 2021 12:57:55 +0100 Message-Id: <20211124115728.520942061@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115718.822024889@linuxfoundation.org> References: <20211124115718.822024889@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Donnefort [ Upstream commit 42dc938a590c96eeb429e1830123fef2366d9c80 ] Nothing protects the access to the per_cpu variable sd_llc_id. When testing the same CPU (i.e. this_cpu == that_cpu), a race condition exists with update_top_cache_domain(). One scenario being: CPU1 CPU2 ================================================================== per_cpu(sd_llc_id, CPUX) => 0 partition_sched_domains_locked() detach_destroy_domains() cpus_share_cache(CPUX, CPUX) update_top_cache_domain(CPUX) per_cpu(sd_llc_id, CPUX) => 0 per_cpu(sd_llc_id, CPUX) = CPUX per_cpu(sd_llc_id, CPUX) => CPUX return false ttwu_queue_cond() wouldn't catch smp_processor_id() == cpu and the result is a warning triggered from ttwu_queue_wakelist(). Avoid a such race in cpus_share_cache() by always returning true when this_cpu == that_cpu. Fixes: 518cd6234178 ("sched: Only queue remote wakeups when crossing cache boundaries") Reported-by: Jing-Ting Wu Signed-off-by: Vincent Donnefort Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Reviewed-by: Vincent Guittot Link: https://lore.kernel.org/r/20211104175120.857087-1-vincent.donnefort@arm.com Signed-off-by: Sasha Levin --- kernel/sched/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 013b1c6cb4ed9..32af895bd86b3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1821,6 +1821,9 @@ out: bool cpus_share_cache(int this_cpu, int that_cpu) { + if (this_cpu == that_cpu) + return true; + return per_cpu(sd_llc_id, this_cpu) == per_cpu(sd_llc_id, that_cpu); } #endif /* CONFIG_SMP */ -- 2.33.0