Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3091817pxb; Fri, 5 Nov 2021 09:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR96H0C2wPU1CYELSV93dzPiGbUbwiOlgBXG+UxG1VMVQDIdgN3xIz/E4nAbONeL4DVSo3 X-Received: by 2002:a05:6e02:2166:: with SMTP id s6mr24868359ilv.170.1636130162985; Fri, 05 Nov 2021 09:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636130162; cv=none; d=google.com; s=arc-20160816; b=Kh558XmlC83T0s+Ua85r9zBv8zz5epBSO7dAxx42od1PEDg7RwIIP2PHn1kXz9V31p bse8DVUHpiAA+3TjaJuuVDbV/d15FvggmSef3wBa4A2FywHYTyuPwPiJLiM2OsVAGPYA XSYSAyXORZiunXXp7u8eoeYGHTryL9rKHebGtFm6ypk0D0q+E4hrRZuA+urqphDmWZQZ TQFTFCiWRM1oZryrLdEguEo9PoPNXP6jIBt4t8j34HTVDOTAJLgN6k7klKwiV8IN3rWH t98NzrJLr+qcaW3hK6mBmU+5sPwe25leq6KWNhq7PIdLDOI/jctHgAo6HIjqwa2GxpaZ GcYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=j33KrwjkN+z1uaFwNqXLFBS987taWab4KSTbR7zl0nQ=; b=FTX24GwiyFcsYI0Cr+QdEE6WPaLuq3fOSPgn7TjUGqY6XTIJBheORlYW2A7CcNDKQs LEw2mz7ZUXY9AqNmrjbF7v4q/bTOGAtHVE9QNyMtVtF/W2+Z7QwiOY1swR6iJu5EKVCc UPqRp9+leAul27IDxhOh+ViUyN2Ule2G9vnkY/sAqUgFslAGVhCuX9sXLMt+c/QJZb/M AyMn5UhfiLe7BNLIV83skec2HRr/wWf39komx/lqXtmGrmyD6ob7u/D5eJkTCrvRlMH7 fduNZLUMNwzScsCJBla59Z73rA34qexO89k54ZK6zDyslezOMihxx1XClSxxcDBLlieL rypQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EgBQdFR0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w12si17245511iov.5.2021.11.05.09.35.47; Fri, 05 Nov 2021 09:36:02 -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; dkim=pass header.i=@linaro.org header.s=google header.b=EgBQdFR0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233352AbhKEPL1 (ORCPT + 99 others); Fri, 5 Nov 2021 11:11:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233330AbhKEPL0 (ORCPT ); Fri, 5 Nov 2021 11:11:26 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 907C1C061714 for ; Fri, 5 Nov 2021 08:08:46 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id q74so23513266ybq.11 for ; Fri, 05 Nov 2021 08:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=j33KrwjkN+z1uaFwNqXLFBS987taWab4KSTbR7zl0nQ=; b=EgBQdFR0adjN8m+uR+wwu1bg46u/fl5WzZ8pQjop9UQiygnlXUvbxnS8E3ZtREyLX8 dT9p9m2aEHfUpzb6QQr81RX8V99xQXf1BHd7kw1N2dZbs0zRJ27HEmstoHQPGk4+egy2 AkIrZMOo9oepmLzL100IkPR1eTAAlTMba3dzmhGi6LEcDD1aUtlbDJkYIqbkBCFaOqlo AGBmTyrBc5y8/hd4QtlUaSGPG0Ndwrb7tLn8vqk0mUwuWUsatqfItyHOflrXR2PDLdbU 7owI+ak0q0WuqNh+M8qQAuC02NQIxqtRPUqJ0G/4mGfzR/ctU4LL1AxCaqI6RG1PUJnQ wJpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=j33KrwjkN+z1uaFwNqXLFBS987taWab4KSTbR7zl0nQ=; b=TtB2ugrGryKOxfJv+M/xvIOvYUtKrpQ527kSjGG1vUAjLrTVD7ihIAfmn3DKq16Syw tfLGk7+wZuo2eS9KiD6zfrmuu/tbLGSqYI8iuc4IPTz2iOKRPuOmowkxMOTm9IVXV8M+ VCZZe61Kzen6H1wa0Fxoi8MYfEh8Dyh90xHHdCMI1Y+XvZ/QnF6jaOrOgyYMlTFB1CFD gP4SWfIkWzXdKYoZggrGjbn+UJVzv7S0+w8h+wxyfb9nO3vrI2j5RhXiO0uZEXNM7rHv oYxiCHFc2RnqkJzWW+h5nNlqcsOwBEhoijHxOpLUHBPp6J3mfSdkHYRmICBK9XOmfmGY kD/A== X-Gm-Message-State: AOAM5323d99GMZouE7QlPfSX6c/zeRxLBNgZJBb5jgv8q7uRDtXoHaV5 IrgaEp7kilEBVOS9MONSppKYOMT6o78SVRnb9CgHFQ== X-Received: by 2002:a25:10c1:: with SMTP id 184mr59679168ybq.245.1636124924724; Fri, 05 Nov 2021 08:08:44 -0700 (PDT) MIME-Version: 1.0 References: <20211104175120.857087-1-vincent.donnefort@arm.com> In-Reply-To: <20211104175120.857087-1-vincent.donnefort@arm.com> From: Vincent Guittot Date: Fri, 5 Nov 2021 16:08:33 +0100 Message-ID: Subject: Re: [PATCH] sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain() To: Vincent Donnefort Cc: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, Valentin.Schneider@arm.com, jing-ting.wu@mediatek.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > } > > -- > 2.25.1 >