Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1792688pxb; Sat, 2 Apr 2022 03:51:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZlgOgA6cbebf01rtk0d7q81TqhlyO1rFbCcY/WHXiOgwbQBd0pH04nN2Yu7Zqf5Dw6ljW X-Received: by 2002:a17:906:19c6:b0:6ce:98a4:5ee6 with SMTP id h6-20020a17090619c600b006ce98a45ee6mr3318470ejd.567.1648896713611; Sat, 02 Apr 2022 03:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648896713; cv=none; d=google.com; s=arc-20160816; b=JqjyuZfjQdcH4DGdZtHORXh6RWVj3AbVrI6skubKeYr6UpkfoJqY7oZwjshbxlxlfx kXBilBAjUiZPYVc1AdwLrdgNu8Hlf2orM1ko+01c8UXQpj6RuInkJJuFImWBLEzKVF8i KmNJdGKui2716x2BTLxoYDEMOoXDTlApDICiGohr7R+kZZ7B8tRhCSMZBWHiR065ZCeO t6MK5CTcrlmUW1Ju06/hPeAPe+MA6CnQkvz0qB/HR2ywkBbSxXGm+ugBxTZ8ZWXVXtAT bRA0O+WfKgNubqBjo/vJOzdNvMbTeTWrLBwvhtj7dVi7yDgFyxYt40ZCAVdsk0IQUw10 1oUw== 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=/K/tbPV/q8JPNsA62KJkI/mZS4mBsmtRHPwnKh620jo=; b=xfmHf2nPOCAAWVfL/5xZj4Quuozz/EKuwVQ8O30uwGDrikPj+KtmMhV9TAebklDdpH 9nLWSyMVACqWbPXeCWmtbDKAJIPs6oC4t7MF54u8e1ypxkw9ycYm2xnXYI77QcR8C/OO v1hkiYrAd1VIZr7u0MTN3Ey1PUfKULVt6LVysFPiSFgayR0JVGBNtYT6inCVjlvCalXz a1Hh8o2gtsJGvkgEYPUk1qxv0CcZ3XWB9E4zTiQRqtn+LxFIYyznwUcXxERBK9x3OBuS Q+EXTiQzQETgZ1T9yjVTwXMolyADhlYUo8HJfjWtLI8vU1b2MsZU9PDXKOJYVQUW/nq6 IbcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bU43DUZW; 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 g10-20020a50bf4a000000b00418c2b5be8csi3156829edk.366.2022.04.02.03.51.28; Sat, 02 Apr 2022 03:51:53 -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=bU43DUZW; 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 S242647AbiCaWoQ (ORCPT + 99 others); Thu, 31 Mar 2022 18:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242648AbiCaWoO (ORCPT ); Thu, 31 Mar 2022 18:44:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A948A23EC55 for ; Thu, 31 Mar 2022 15:42:25 -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 ams.source.kernel.org (Postfix) with ESMTPS id 6A672B82250 for ; Thu, 31 Mar 2022 22:42:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30878C340EE; Thu, 31 Mar 2022 22:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648766543; bh=8hmaQ8bK0qDSdukzI7NQ+DyrV1swRkMPVgfng2e6haI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=bU43DUZW9qxj0O2Iru6CzIBjtgq5G1zbBtuVMDvmsOriaLvdwk1KIOZ1QFh9n6Y5e B+g8m3YHqi78woX177JQQ65MHdg4um1j9PgfZd+gyGxGYKOiQjn+SMKotNtJOQVvS4 huThatyJHMcluD2L+bsyJTiIkEmPugtw1SN1WAXh0NBbC1yZRv8AoRYWkRGk/ujaR8 /KnFH1Jdgh5KQR0VCXnS6SJck5l9PXjvKaw56xHjO1j+yG9UdTMIt6MLr5JPGQJLCy fe3UEgk6nF7WbDo7DSKgrOEDi9/9JFy5cJtN6j9sKMmVIDPgyc9qD+cmNOP+6JCPEy uUmfZ3BSS6frg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C311B5C0A0E; Thu, 31 Mar 2022 15:42:22 -0700 (PDT) Date: Thu, 31 Mar 2022 15:42:22 -0700 From: "Paul E. McKenney" To: Eric Dumazet Cc: LKML Subject: Re: [BUG] rcu-tasks : should take care of sparse cpu masks Message-ID: <20220331224222.GY4285@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: 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 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.) > 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.) 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;