Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2801233pxk; Sun, 20 Sep 2020 18:23:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydTYjkxiYIeYf5Wf2s4zbXtPK767oIIO8q7F/qTKHWsGQkmjooCpES6JU9LWqrccHxRPTZ X-Received: by 2002:a17:906:11d2:: with SMTP id o18mr46250660eja.420.1600651406411; Sun, 20 Sep 2020 18:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600651406; cv=none; d=google.com; s=arc-20160816; b=i/Dn+6cwJDCmNwHNVd2a/HVdixiLuR+ArqDWb7fe9OMs1J3g8yx4kVbXkt/B+QAfTq OTTwmzLDWGiB+g3FyF41qXvj1MqOQaxO9ABKeYcB+V0pkD1nNZFU0Xa7Vy9h6XuV+saj W/2PQO6NSLD9esdkZlUyhTJZ+E7LfojeTeMCoNpmq1TOUaIyd/7A5zLj+NqTh2IJwRMo EoGnXCrAUVCv0Jmct+onQwXMrfcNLXGxPr1nvdAV4d+mh3//gGUmUbRbS9uxNu9Yolls jc0e9p/+nxQ3zW4Mlmz70VDTL/r+bd0Zp3dlMxqcUgjJQt4HLn7mQss02JmOHTNnAxWl nFGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W4dCcj2aIPeMu97ITQjVMX+AXZqRg6ZN64LfwJhTHAs=; b=anMskIEcBJ5FcQhcyx0a2WSNjdbMleLq52rwuj2yWUT/ehyG1/h9DO5E/YO93tOx5v W+KHYBP+9Ldg57K6ZyTZb3PF/gLCuRe7DP/d1JVAbbW1trZQeUzJlkpqT6aZXVewIqhk m+vlO7imZDjyEtXy95V4g15MOwR1ly0iMpH5PrE01kVJGS5RO9jtjanue2qcYaO7u/2L cqbLDlGNrB+sITy5e8HilCv1UytRnvDYQKJ4rF6tvNLdtMizovydhcAWicOXteGrQXSE 1Loc0PkWrJkxtQ9VuPlrm5s2xf/a7Vl2jnnoXYmhc0MWEeHsMp7sUTkLIMl+RgSBeuHJ 6naw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="gNBI/VMB"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si7149360edw.77.2020.09.20.18.23.03; Sun, 20 Sep 2020 18:23:26 -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=@joelfernandes.org header.s=google header.b="gNBI/VMB"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726455AbgIUBWE (ORCPT + 99 others); Sun, 20 Sep 2020 21:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgIUBWB (ORCPT ); Sun, 20 Sep 2020 21:22:01 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDCA8C0613CE for ; Sun, 20 Sep 2020 18:22:01 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id g72so13415045qke.8 for ; Sun, 20 Sep 2020 18:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W4dCcj2aIPeMu97ITQjVMX+AXZqRg6ZN64LfwJhTHAs=; b=gNBI/VMBq4ECyrD0v65eTyivjMRH5CImLVww0RA4eFmlzxf71wnvwob5fTp+9WoCnL Itg9daCoYA5XlcPkthj4gOF+CX9rv4lJqxBR8nJVaeKlyNe1nimGXaJBvOkSp9K15Yft PjpkLw/CSInfNc42Ak0R82w/Im2lhBAY/l3rI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W4dCcj2aIPeMu97ITQjVMX+AXZqRg6ZN64LfwJhTHAs=; b=O9Pxro07OYCkv5nYy6YpfgVK8W/KkaQRYoVve3UAmx3VRJdQW9q/c5WakmNGZ/Ozmu PwCoyFFJr77mWMPhW/L6zzAuVRPIvD4ag9wix1qAUKhWX/DMAjzoiTgZqnjAm/xTg9wn T+aL+MMZDjKQD8+dN7Jgab1OIzyEU6KzzBFZkz5Yo98Bvo58QbOmxjVHNRfKS/+gtNkg TsBLyRpXnYX8Tk9QYGHd+a3APpb95nrVfgSy744vj9vYtAOV5FcMeFUUyMxphFqL+Jwh RPTRjMzM/ftLYrZ2eOkt3zAo4sEEUvPVO3OeBydbugoymiXZRAS1a4WRPnM/NIL1aMyw RwEQ== X-Gm-Message-State: AOAM533bI8El/3GHl4IqJkZVYrGqek0IOPYtZ9ucjqKCx7WMU1FAmbf7 IqLph8iGuW2jgQAV0io71GutZAcuvyCx/w== X-Received: by 2002:a37:912:: with SMTP id 18mr43005490qkj.29.1600651320735; Sun, 20 Sep 2020 18:22:00 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id l26sm7741951qki.62.2020.09.20.18.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 18:22:00 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Ingo Molnar , Josh Triplett , Lai Jiangshan , Marco Elver , Mathieu Desnoyers , neeraj.iitr10@gmail.com, "Paul E. McKenney" , rcu@vger.kernel.org, Steven Rostedt , "Uladzislau Rezki (Sony)" Subject: [RFC v5 3/5] rcu: Fix rcu_barrier() breakage from earlier patch Date: Sun, 20 Sep 2020 21:21:50 -0400 Message-Id: <20200921012152.2831904-4-joel@joelfernandes.org> X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog In-Reply-To: <20200921012152.2831904-1-joel@joelfernandes.org> References: <20200921012152.2831904-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is split up because I'm not sure about the patch, and also because it does not fix the issue I am seeing with TREE04. :-(. Though it does fix the theoretical issue I was considering, with rcu_barrier. The previous patch breaks rcu_barrier (in theory at least). This is because rcu_barrier() may skip queuing a callback and return too early. Fix it by storing state to indicate that callbacks are being invoked and the callback list should not appear as non-empty. This is a terrible hack, however it still does not fix TREE04. Signed-off-by: Joel Fernandes (Google) --- include/linux/rcu_segcblist.h | 1 + kernel/rcu/rcu_segcblist.h | 23 +++++++++++++++++++++-- kernel/rcu/tree.c | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/linux/rcu_segcblist.h b/include/linux/rcu_segcblist.h index d462ae5e340a..319a565f6ecb 100644 --- a/include/linux/rcu_segcblist.h +++ b/include/linux/rcu_segcblist.h @@ -76,6 +76,7 @@ struct rcu_segcblist { #endif u8 enabled; u8 offloaded; + u8 invoking; }; #define RCU_SEGCBLIST_INITIALIZER(n) \ diff --git a/kernel/rcu/rcu_segcblist.h b/kernel/rcu/rcu_segcblist.h index 7f4e02bbb806..78949e125364 100644 --- a/kernel/rcu/rcu_segcblist.h +++ b/kernel/rcu/rcu_segcblist.h @@ -40,14 +40,33 @@ static inline bool rcu_segcblist_empty(struct rcu_segcblist *rsclp) return !READ_ONCE(rsclp->head); } +static inline void rcu_segcblist_set_invoking(struct rcu_segcblist *rsclp) +{ + WRITE_ONCE(rsclp->invoking, 1); +} + +static inline void rcu_segcblist_reset_invoking(struct rcu_segcblist *rsclp) +{ + WRITE_ONCE(rsclp->invoking, 0); +} + /* Return number of callbacks in segmented callback list. */ static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp) { + long ret; #ifdef CONFIG_RCU_NOCB_CPU - return atomic_long_read(&rsclp->len); + ret = atomic_long_read(&rsclp->len); #else - return READ_ONCE(rsclp->len); + ret = READ_ONCE(rsclp->len); #endif + + /* + * An invoking list should not appear empty. This is required + * by rcu_barrier(). + */ + if (ret) + return ret; + return READ_ONCE(rsclp->invoking) ? 1 : 0; } /* diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index ab4d4e9ff549..23fb6d7b6d4a 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2461,6 +2461,7 @@ static void rcu_do_batch(struct rcu_data *rdp) } trace_rcu_batch_start(rcu_state.name, rcu_segcblist_n_cbs(&rdp->cblist), bl); + rcu_segcblist_set_invoking(&rdp->cblist); rcu_segcblist_extract_done_cbs(&rdp->cblist, &rcl); if (offloaded) rdp->qlen_last_fqs_check = rcu_segcblist_n_cbs(&rdp->cblist); @@ -2517,6 +2518,9 @@ static void rcu_do_batch(struct rcu_data *rdp) /* Update counts and requeue any remaining callbacks. */ rcu_segcblist_insert_done_cbs(&rdp->cblist, &rcl); + smp_mb(); + rcu_segcblist_reset_invoking(&rdp->cblist); + /* Reinstate batch limit if we have worked down the excess. */ count = rcu_segcblist_n_cbs(&rdp->cblist); if (rdp->blimit >= DEFAULT_MAX_RCU_BLIMIT && count <= qlowmark) -- 2.28.0.681.g6f77f65b4e-goog