Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1078755pxb; Fri, 1 Apr 2022 04:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdf5JKyympKg8kwCqLFIvD+jQIzy7cCuxC5XQeEBMmSNm4U2lLZCLiblC5xeALvnB4S3Wx X-Received: by 2002:a17:907:3e1d:b0:6d7:1031:7e0 with SMTP id hp29-20020a1709073e1d00b006d7103107e0mr8629195ejc.580.1648811321099; Fri, 01 Apr 2022 04:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648811321; cv=none; d=google.com; s=arc-20160816; b=eeyO6Bc454308lWQuHjWWNU7Yzwnth8oK9YJIDfxG3gAXC9HzZ5Ys3WjNrFLbt3Sss Iq0gLcqNKwkxiDpGrIpqpUOUBM0Ej4+C2ovEf90xvMvms3sCwqgtbf+pV4iwN6N0GYWk 97hxLDSoIcHtPE0bvtGOGraQGc3ML8mTU5I/IXeM7ZEAchZ27wA+0/ArV16dXDaUpLwG pZhd5SyEkgR7tw2smyjAkF7eRQEMncVWiYGbfIYMStJeixoigqOpsDjfiz+QDnEFFcZN sZkgzefo5gwaLp6XkdQgrwaLlxxntllAthOyN0nHjlDwyw0Fxkppld/RURdeX8EoCz62 BKXg== 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=H4K1DYo6POxyHa7P+r+PclGm7rs5TWXKiHdrqnC5dzk=; b=NivvUx5bOy1B5jI0IguSVBuMyW1gJ/q9mVdKB2ZNjsDMcA1mz9kdQL/C1txo7B/BZt dAoPVIWXM7Gi2Usbu+yhAFG6DkBnKJ79tLcrPEsFo7FcmgQGxu1U41B/wj90uGlYa/Ye MDMscU7SPVn3gJtWPHxqzCVHHboRXP5FFlT1o1/hOw8aze35iifGWn1LdOkOn0L5okfl zfMWt27rEiCZw3U+upDKdZOVWAmMdm1CFTiBij0wBkrg/jJUPDp3fLAuPpRNmhvj595P 3NB9o1kFPA+Y0rifPYL9zyPgMnQPFMt6sADG5AXa7qYvoB5fwS7vDEikvwUAuSYfLsEo FC5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=l6l3R4RP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020a1709060d4200b006df76385ebasi1333879ejh.858.2022.04.01.04.08.14; Fri, 01 Apr 2022 04:08:41 -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=@google.com header.s=20210112 header.b=l6l3R4RP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242689AbiCaW4F (ORCPT + 99 others); Thu, 31 Mar 2022 18:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242684AbiCaW4D (ORCPT ); Thu, 31 Mar 2022 18:56:03 -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 AE4F06516F for ; Thu, 31 Mar 2022 15:54:14 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id m67so1993949ybm.4 for ; Thu, 31 Mar 2022 15:54:14 -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=H4K1DYo6POxyHa7P+r+PclGm7rs5TWXKiHdrqnC5dzk=; b=l6l3R4RPJBfrQ5v9o/l3WbtqAvsavb7WlXlcj+rdQGaIyoPa45SjS3yqRb58aBIOL4 N2CFmZvPSeUEVQeR0I39B+b8LXyBy7s9otM341m/V/LKv75BQU5+824n4leoIwepKTl3 6//ffE486OzkiGY/gkrVzLypYftNuGZsdgi4LkBPxqW9spQeY34J57XbRcw2JvP9iyJq 7/V+sXc2HD4k7+6fIXv8CUmT1u8uQEk0vKGKRKKwluevG16JV3LJ8Q5KP8DORZZbLpM0 rk27Wyj6yL+1utx0TkD2jgMzcVaMy2tkqyVG+osrQgn+X2vmvYUQxO8h2BJlpoY+EFqI W9xQ== 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=H4K1DYo6POxyHa7P+r+PclGm7rs5TWXKiHdrqnC5dzk=; b=oKsoxhFr5eKD2zX2XqmsORbSOw6KOFg5IIwISWCnf9DfNWejAPbQ0Q888qtVX8vb2B U1aexXFZMQuOkAU/rHct2zip3chU/qKDUhE9V7/gRn/sggnnm1sI50Xly9JQb7cxSjKI qzJvfubZ/AHrTsj8EqFyhALEXA1wN7d5Bz9neHRwGD6IDqThau3y3My47jfih5il2/x2 W/6k6RvAG4M8KNn5egRPFvMJ497L5ow2R1+H5VH99y4LjPg7220bIjXTl96th2kakglZ MSc9SVbRKrKPMk+ytQoCgHVRqzP64zcgBxp8fT6fpj8NwosztzP3U3yIUBP50Ra75hRC D05w== X-Gm-Message-State: AOAM533F5ypSan0G2tpwqQhuOMZVk6KwZkgiBTaXnRF56p6KbdQZzdpV b1H5/A47pALfcdUII9J7BINmER7E7heFy7wxF/N3JQeMlN5LSA== X-Received: by 2002:a5b:7c6:0:b0:60b:a0ce:19b with SMTP id t6-20020a5b07c6000000b0060ba0ce019bmr6042995ybq.407.1648767253585; Thu, 31 Mar 2022 15:54:13 -0700 (PDT) MIME-Version: 1.0 References: <20220331224222.GY4285@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20220331224222.GY4285@paulmck-ThinkPad-P17-Gen-1> From: Eric Dumazet Date: Thu, 31 Mar 2022 15:54:02 -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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 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. > > 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;