Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp6382416pxb; Mon, 8 Nov 2021 07:44:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqoPHVR4PMsQro/zAnmPBJbj+ozvyyIe8TsB86Edlq/C9BKgYuBCi048Eiq335EKSYt/f2 X-Received: by 2002:a05:6e02:156a:: with SMTP id k10mr413ilu.200.1636386288343; Mon, 08 Nov 2021 07:44:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636386288; cv=none; d=google.com; s=arc-20160816; b=YCrIqQRdXw0vJekaHShD1J9E7X5kT5+RolOTdUhiNSzYOorM5uHX4CSxez8QGHeNs2 ZN+5RePegcNBkKLcTiEzbz9RmWR0RbgY7liqkhwAAB2xfEU0oFp/mSHG6C4OBFhVhA7n owbhMA00hrQAOh9YEEr9+ZJXmrXNxNGsChJRwO5+Rx6o4svrUjLDBQmxAngKEywM7pOQ xsb5MTHgN+ajpMtR4loU42AxD8T9/2ygenTNRrVHnAFeDWj3yOpBXVvY3SyzrsEApErv leomFmFOFmlPHnnbAoNqGtauX+CReAO6TuqgRU32a0PQvmmJceJ+/UCC5FHv7SS1uZ1h u8iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7l9Qh23ABh9dJBsIWZLWZvILEE4YxWy7+qXg5zYdiIk=; b=mhBZLk82LVSYAdcEa8tWIsja1GT1ZkA3zHDw+j6UfLQBdZRkuM0IC9v9cy5hXxVFgj cDMuGTqYDjlsZEiUK3lSpJTj37GsMMbelvvGM4qK6+ziXyCyw3xPrZRUlSmFTM8+XTC3 rkv5L9RVhd9adet7aiITWEiCmlNBFYkQUs1wz20VyQOAx+SCp3qn5QMIkQnOW4C2kzyi X+6l3mI+uI+eEcy6OKwSre/WFcIhvUj5GtKTtln8mLJVpukawIjagYhvMSK/yMbx0mw2 ua2/+pcCBZePa4VCupVar6CUjiLK3pzhARwfJnP8/02hVgg085Glooh/mj6qFL8j/IqP z3aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="IWW3vvi/"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si4392547jaj.117.2021.11.08.07.44.35; Mon, 08 Nov 2021 07:44:48 -0800 (PST) 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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="IWW3vvi/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239192AbhKHLYz (ORCPT + 99 others); Mon, 8 Nov 2021 06:24:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235502AbhKHLYz (ORCPT ); Mon, 8 Nov 2021 06:24:55 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB12C061570 for ; Mon, 8 Nov 2021 03:22:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7l9Qh23ABh9dJBsIWZLWZvILEE4YxWy7+qXg5zYdiIk=; b=IWW3vvi/BKZOJ+HoTuYfplYJ4D Gt6Qbib3UE3GJBsc6nVW58xSTiUouh8ZgnsGwqymYrz5lLGJdEk20O9uWbWIDPv1nQu96H5mRiX8n CXMxLabp58gs+negPerQwX7Seccm0NZGkVCPOLe1q9DjD4rFhzOJq9sRYDPTfbCWj94GzMcNd8nGc uZ1HyJs+FDTfCzLOmpkbjL719hXzmFJIgy3hhVS7XrTE2YanRT+AoYb1FK19E4QID3pThRiiBhuKr ywoQNoIn9PD0L3A0SXvvlJCF0HikLxIBARGIZpETJER5ks0p8N4wAtTDQdCf1/WFDKikl9uRSEUUc mHXot00w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mk2gQ-0008LC-QR; Mon, 08 Nov 2021 11:19:28 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 869093000DD; Mon, 8 Nov 2021 12:19:23 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 58E16202A012E; Mon, 8 Nov 2021 12:19:23 +0100 (CET) Date: Mon, 8 Nov 2021 12:19:23 +0100 From: Peter Zijlstra To: Vincent Guittot Cc: Vincent Donnefort , mingo@redhat.com, linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, Valentin.Schneider@arm.com, jing-ting.wu@mediatek.com Subject: Re: [PATCH] sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain() Message-ID: References: <20211104175120.857087-1-vincent.donnefort@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 05, 2021 at 04:08:33PM +0100, Vincent Guittot wrote: > On Thu, 4 Nov 2021 at 18:52, Vincent Donnefort > wrote: > > > > 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 > > Reviewed-by: Vincent Guittot > > > > > 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); > > } Blergh, that's annoying. Thanks guys, picked it up for /urgent