Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3506304pxb; Mon, 4 Apr 2022 19:10:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyIkz1l6d+I91QVGfyaiY4o14RNqziS4gbkobS2+nG3EIFSk38QXm7Ke1MGZ55OgAcgB9v X-Received: by 2002:a65:5b43:0:b0:382:1f25:eaef with SMTP id y3-20020a655b43000000b003821f25eaefmr930660pgr.590.1649124628531; Mon, 04 Apr 2022 19:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649124628; cv=none; d=google.com; s=arc-20160816; b=w6Od2mAjnAsktRLY6iYTggkvT6N9pCfk0suHspiPQ7AbJ3bFcis38GuhgoC/wvYsdg m6LtAnH3Ih4syM39/0D2Z84ACDTO4MGTanOMOqDT20Asp2t7B6uVQva+p7FobAPfUH5w wQGKBAjmB22zbctNMHD+0XFQnAJz0gOSy/18whO7gxOZItTBVwQ2hLzPVUfOvVExNoTl 0g1JYZWJWE8nI3JEb9p4MRCsFk4X/seGVWwoQ0NCsZ6lNexbkDClVR+4Z61R8rw+7VmW hglqXEnWAGrFBeXKjhjarXfPvXhOd+rzVkZGhGOg7uVvIGUVNESGXF7uMmuFxd8JfdZz x1OA== 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=1iuXGgBxyPzPLMVg7RXI0ix1XCOX50HejC1IJldPmzw=; b=fWgPfQ42ser4PLybpre24OlmJgwTlZZi3Ys2PuzF0uOZ4jM290Sot0WXtv1I/G11zT 1oG79kOxL4IHoHM8ozxR97ceoP8zgNbpspaCUDgmDzYvw6uLHYwKOHhxCxAapiAdK0fn GsGIHwlwWEsBKyf9WR1Omesy6HU387ZmoJ5b8/UIzewgAothU95MShiH3xkyMznS0RB4 q7Qa8eRE37AS8Fm4rLn+8vjmCYMHxcESXp9Ox/YQg3e/EAhuM8asOjvOkFTPnQD69S09 O5zFEtejcrrN6TOLDMoSA5C1KxjLYDwlQ6MAaJu93T2x4oZTKdyTLqLWg7VxV5bdOen+ Ne6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OSV+tvN6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m9-20020a056a00080900b004fa3a8dffc6si12648794pfk.125.2022.04.04.19.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:10:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OSV+tvN6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46D6E24B0A4; Mon, 4 Apr 2022 17:33:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236484AbiCaW7h (ORCPT + 99 others); Thu, 31 Mar 2022 18:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbiCaW7g (ORCPT ); Thu, 31 Mar 2022 18:59:36 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59780236BBC for ; Thu, 31 Mar 2022 15:57:48 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id v35so1950004ybi.10 for ; Thu, 31 Mar 2022 15:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1iuXGgBxyPzPLMVg7RXI0ix1XCOX50HejC1IJldPmzw=; b=OSV+tvN6okJxhd4+K9ogju89W0UWCPQieJLXAmoPF+DYLjWIv9K5O1WRDBGkmy0o49 Id6gPWrzd286ZTUsFSLHQ9cpR0DfP1R4C3N7nM6VZAJAMr70cZOczEB/IFdcBXXaZF+M IsbpFX8ZLKdPfNzfJbonHWRJMMSxUmhZcqiBnVdCedEwN5jzdLRO61Ed7nk3png5+P16 nUxrDJN4LSvS0nv52ioW+AWb2OPYKAfYu4UYn5l5vR1pJDE65/du4wTEpy06vGmq5Vpa jm5C6H1MS/GFFJ7jsvOk+vv8CynuDCqYfapx2hfIH/L5M6GN27OO0K/wQ3I3FMRie68W LV5Q== 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=1iuXGgBxyPzPLMVg7RXI0ix1XCOX50HejC1IJldPmzw=; b=tgElFiLjIuP/Ey6k85byguEAkJvDgqwRwMAfHFx1tY4UAY7fosmgqadk0rGHDdAO8V 5TtcP4/ilvibex090/ERD29R87Y+UPsNuGOhVLcH3lsAuBNcohqAZ/zHEOffRvmr9ZDa bMzHPrh1ms7nyKTzt3Rda1oYur5s6EVAik8hmrpGUb0GpkWjDNsqKwcJcRQLcrTueFEG nXLZuRqdszUiCHWmvPAlMEAL6UEbQH+V4pC/GbKwyzEp+PfB4u3jM1MDrY9d8y3un7SO YRhp29xTxCWMegxJ4dbOhUMaOx0Kq6D8VFcGYoCVlvTR/19BWqGxbKiIgq5xuM92YKOU lkZw== X-Gm-Message-State: AOAM530m8bhScsd9iDrolGf8ivRkzf55zzVCUDE1KxrORTamsF80BdSi 3vSNsOR907obZ9RPMS/hXZj4h8EA7K2jekosgXg+SZ/xtHw= X-Received: by 2002:a05:6902:72a:b0:634:6843:499c with SMTP id l10-20020a056902072a00b006346843499cmr6519442ybt.36.1648767467358; Thu, 31 Mar 2022 15:57:47 -0700 (PDT) MIME-Version: 1.0 References: <20220331224222.GY4285@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: From: Eric Dumazet Date: Thu, 31 Mar 2022 15:57:36 -0700 Message-ID: Subject: Re: [BUG] rcu-tasks : should take care of sparse cpu masks To: "Paul E. McKenney" Cc: LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 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 ? > > > > > 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;