Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1959945pxb; Sat, 2 Apr 2022 09:39:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0WecSRzOJE+FnUkN0IwTcl0l0tEwFnPeYBhv+oc/YQ94jX9mPGpjMtJqRN1cfsS+AUt+F X-Received: by 2002:a63:334c:0:b0:386:291f:3435 with SMTP id z73-20020a63334c000000b00386291f3435mr19006130pgz.264.1648917598670; Sat, 02 Apr 2022 09:39:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648917598; cv=none; d=google.com; s=arc-20160816; b=nJwliHr4bEVsfLdfMJMEqhbkIZgRhiSUQLL/xrlhMRWSgHLKYYP2MPyI34Jx+BdoOA miK687WXOpoU1vOnhTCsa4lsWT2PY/r3eT24UWvWfMZTZLahXD8sKRhArMzlxUPWDi3A 1Pd/yzY82pB8KfNu3SbE+GYh4e7wc3L75Blpj7pvMO6OqXG+0BD0J+OFERhddh6IjyGD K4sUoGEtXDIkSveBSX/c3Gvb38HfML9sooXxKLy9fB9xt4VhZDhDiTuK1cDzDZOqD8ez DV4MgQ7pp1K7/pBoqkAlnhqTW3nc/51KMmMbDsdxHum0KfumQVAAEXpyE+nieQNae+4F rb6w== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=5+QCIECCOiAlWarI7BjA67sATkFR0ShGwQUN3oITb9k=; b=EvCxY4FEOOGTaiBgsYM/lSf46n7P/IVxrDrGGR8fGJuq1pOUMAeRRQ95/+242ktT9/ kaFp7lEZKWcAXpomJqB7PyVPEMXBefvTFIVC7c1mKFy1T/IweuuQJ6MYVaIXv7w54RUw exF6hLrAg3mpB5I95dOVSykXQ2+K3IYlwP96OiFkKkDykhaNgmcfBXJOC55MwY/QQtti D/OaegPbdT0l/GJchTBearexvqObHXX6eZNIntpu2vT0ASviDJDmOG/Nb8cCqG9G9FBV aRvFIZYhBj0emRPGcElx6ENt/Vl0DsPHlTwCHYFBMCfj6+QXfVb2D4eI3hXzVjNAsAvX 2AvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nm83YWZG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a630f54000000b003816043f076si5498401pgp.619.2022.04.02.09.39.43; Sat, 02 Apr 2022 09:39:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nm83YWZG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242875AbiCaXPD (ORCPT + 99 others); Thu, 31 Mar 2022 19:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242867AbiCaXPC (ORCPT ); Thu, 31 Mar 2022 19:15:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2C724B5C9 for ; Thu, 31 Mar 2022 16:13:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9827A6152D for ; Thu, 31 Mar 2022 23:13:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED6A3C340ED; Thu, 31 Mar 2022 23:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648768393; bh=ki8Jcuqk/wwUM9+LuyWgTTyWSrQjUthx1u+VD8E3pZQ=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Nm83YWZGcHxcvZezZl8gLrjWLsrCcodUjMJfLLTUK90RAH/s3Akn/DWKzJCQRHo/l ohvleongY23a925PbJBLKyEvk/gWXiFMgvW6eBSgYtM5TOsgAPyx7btOwaec705jjw sKOYr/FkgKYAIlVKU3UYhbsgdDfbqzyW1CiWN5lGjr2rvOFJo/Zgb7Y21NEJ6bWGG3 DAuPvhiIEzhT443a5EuTNPyYzm65dxYZYYvBrjtWt0e2g9VwSqISKYFrVaEXpWUM3+ 1Ow5b87PpzuikXf9UuijJzKhFTbn24D23uvq5MVpxQ6mW2zOpQRKDkZeXj3bf6yMeb dV/0kjNatKYvQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 892015C0A0E; Thu, 31 Mar 2022 16:13:12 -0700 (PDT) Date: Thu, 31 Mar 2022 16:13:12 -0700 From: "Paul E. McKenney" To: Eric Dumazet Cc: LKML Subject: Re: [BUG] rcu-tasks : should take care of sparse cpu masks Message-ID: <20220331231312.GA4285@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220331224222.GY4285@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 31, 2022 at 03:57:36PM -0700, Eric Dumazet wrote: > On Thu, Mar 31, 2022 at 3:54 PM Eric Dumazet wrote: > > > > On Thu, Mar 31, 2022 at 3:42 PM Paul E. McKenney wrote: > > > > > > On Thu, Mar 31, 2022 at 02:45:25PM -0700, Eric Dumazet wrote: > > > > Hi Paul > > > > > > > > It seems you assume per cpu ptr for arbitrary indexes (< nr_cpu_ids) are valid. > > > > > > Gah! I knew I was forgetting something... > > > > > > But just to check, is this a theoretical problem or something you hit > > > on real hardware? (For the rest of this email, I am assuming the latter.) > > > > Code review really... > > > > > > > > > What do you think of the (untested) following patch ? > > > > > > One issue with this patch is that the contention could be unpredictable, > > > or worse, vary among CPU, especially if the cpu_possible_mask was oddly > > > distributed. > > > > > > So might it be better to restrict this to all on CPU 0 on the one hand > > > and completely per-CPU on the other? (Or all on the boot CPU, in case > > > I am forgetting some misbegotten architecture that can run without a > > > CPU 0.) > > > > If I understand correctly, cblist_init_generic() could setup > > percpu_enqueue_shift > > to something smaller than order_base_2(nr_cpu_ids) > > > > Meaning that we could reach a non zero idx in (smp_processor_id() >> > > percpu_enqueue_shift) > > > > So even if CPU0 is always present (I am not sure this is guaranteed, > > but this seems reasonable), > > we could still attempt a per_cpu_ptr(PTR, not_present_cpu), and get garbage. > > Also you mention CPU 0, but I do not see where cpu binding is > performed on the kthread ? The initial setting of ->percpu_enqueue_shift forces all in-range CPU IDs to shift down to zero. The grace-period kthread is allowed to run where it likes. The callback lists are protected by locking, even in the case of local access, so this should be safe. Or am I missing your point? Thanx, Paul > > > > Thanks. > > > > > > > > diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h > > > > index 99cf3a13954cfb17828fbbeeb884f11614a526a9..df3785be4022e903d9682dd403464aa9927aa5c2 > > > > 100644 > > > > --- a/kernel/rcu/tasks.h > > > > +++ b/kernel/rcu/tasks.h > > > > @@ -273,13 +273,17 @@ static void call_rcu_tasks_generic(struct > > > > rcu_head *rhp, rcu_callback_t func, > > > > bool needadjust = false; > > > > bool needwake; > > > > struct rcu_tasks_percpu *rtpcp; > > > > + int ideal_cpu, chosen_cpu; > > > > > > > > rhp->next = NULL; > > > > rhp->func = func; > > > > local_irq_save(flags); > > > > rcu_read_lock(); > > > > - rtpcp = per_cpu_ptr(rtp->rtpcpu, > > > > - smp_processor_id() >> > > > > READ_ONCE(rtp->percpu_enqueue_shift)); > > > > + > > > > + ideal_cpu = smp_processor_id() >> READ_ONCE(rtp->percpu_enqueue_shift); > > > > + chosen_cpu = cpumask_next(ideal_cpu - 1, cpu_online_mask); > > > > + > > > > + rtpcp = per_cpu_ptr(rtp->rtpcpu, chosen_cpu); > > > > if (!raw_spin_trylock_rcu_node(rtpcp)) { // irqs already disabled. > > > > raw_spin_lock_rcu_node(rtpcp); // irqs already disabled. > > > > j = jiffies;