Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1929339pxb; Thu, 4 Nov 2021 10:56:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7APz/oObrvimrwo1KtF1Neb6CcmtfBHhigzLMIGErdA6v6SKA85CCTqMbK2fXItGR6dkI X-Received: by 2002:a05:6e02:1846:: with SMTP id b6mr12227671ilv.164.1636048563931; Thu, 04 Nov 2021 10:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636048563; cv=none; d=google.com; s=arc-20160816; b=iZjFhOyGkZh+d21CMhCmEbEkW6+YDviUCEs1M6WooxwxB4CJ+R9dEPrcj9lmiM5Bhn bdxe5AuM1By2bceRiu4m/UqByoVW0sm0euPFXNcmmhJ7dBi5/gObJ+04YuA7goA41sM5 YkaIyEbSf9iy2Ewfs7e8CPoTXxdcru1eijI7xZubZ0qxoLkY/NQJZ3E2NMQdtj4ItqQm 3PoDz9pNFYu2R1za+KpOqbbEL7k6DPLoCz1EjczY8QMc12G+cKDQxPdK+Mq3E+H+3ttk Ayz6wdmenbGFDzlB1QdPMdWcBDuFMuNp54SjzaeVFT/TQtyXLUU/uO7XWe5dTq6Q+TLT yAWQ== 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 :message-id:date:subject:cc:to:from; bh=6RYS9Bxrd4VRgvNe+4JDivGgVL2ZEhFW7zJj00zQ3W4=; b=mziAOWbqLz6eEgn+XNsXJY2wAObNxLXejNtqemqax9pqVNdjuESJn/Ozq/iL+ziDKX c0l77OilSxS76KJ0fK++AFojZh88ZVN0YuJMvtiJ6eZMNQAaWTHSUJzBxVpI/HjlH69f yXNdXxQrlj6iR7P1XhAk16p7tkZlKClc5SRcxB+DmZz2ywHKE9DqNAEbo8Zmb2wXGzal SKloS2jS5LzIC+7WgUnn08pSUQO0mYiKFvQg5OY5/C7dfk8BdBNB1x/xVw9lPaH/iKF7 Vo3pW62J43b3ofAI5ArYHJp8QbtZ9B3OnHMuf7m5leCXxXN2XhGyTITZgL7irDiCeLGC rrPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si8245311ilo.181.2021.11.04.10.55.37; Thu, 04 Nov 2021 10:56:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229850AbhKDRzf (ORCPT + 99 others); Thu, 4 Nov 2021 13:55:35 -0400 Received: from foss.arm.com ([217.140.110.172]:50404 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbhKDRza (ORCPT ); Thu, 4 Nov 2021 13:55:30 -0400 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 3274012FC; Thu, 4 Nov 2021 10:52:52 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.47.199]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0742C3F719; Thu, 4 Nov 2021 10:52:50 -0700 (PDT) From: Vincent Donnefort To: peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, valentin.schneider@arm.com, jing-ting.wu@mediatek.com, Vincent Donnefort Subject: [PATCH] sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain() Date: Thu, 4 Nov 2021 17:51:20 +0000 Message-Id: <20211104175120.857087-1-vincent.donnefort@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Valentin Schneider diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f2611b9cf503..f5ca15cdcff4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3726,6 +3726,9 @@ void wake_up_if_idle(int cpu) 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); } -- 2.25.1