Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp725796ybm; Fri, 29 May 2020 10:37:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrUXXAv6MxLQ+r6cqiLo1YuYNt5k76NrU2heQLax0HBHyf7OXmOCfpt+Vs8nzgYviayh+f X-Received: by 2002:a17:906:d961:: with SMTP id rp1mr197556ejb.118.1590773868679; Fri, 29 May 2020 10:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590773868; cv=none; d=google.com; s=arc-20160816; b=bP5bC9S1Fz7AC38l04xjdNalfy2LCUGyzxZQ4zggvfpsLQlizhpx0ffCit9zlnUfms YIRdiUnAu7vJK+fEJeeF7sw9tMAOtFPBIs+Q3csVFmQQwboBKrZOGtphYiPwXakAc5bb hVWnfvyDn00gDCGfzDxGaFyB8muP3iyjDsMrsautSMum+488ZoFSiKwMrFCUf4PUkF9T GsRlPtrWzp1hj1n0SjXU4gQB7KOpcILMLrCAiCK0atFn6EYQiln5TDZWAPavHOJH8yq9 IMQ8qYimH4gianpFKmTTy2JBbtEPzOd3cN+20bsE4sgEpIT1S5OFF33Q6ZKy07bv3o3s bORQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Vv9ldXFCL4C/whPnS1mUqMWHmnWNvuasrevBys51oQY=; b=hOJrMwQdAK/gGW7njgZII3CuNcZwzieWRyW4+Y4HPesB/douEAA24jeRb6oSerh6o7 nWepxvEbfjBicb/2FUPbpjahNSnfTWjOgEduCQXYNquZEt6M5g0SjxDxNg2YirTJpqSu PCVXSIrpOhjYtvouOgv2flGsKS69VCPKwt21AOJKn/h3fZk/6/gYqoL6KWqT7UO+bGVH eMvS+chwhSTcjjUhhlnBcDSqjzl4e/tMmf76mpaxmC0i7BKJcdV7lQXeWpjEbntalj7H Q4PTR9qu78J6EbEwVTAKxPBJeSE6we1syY7vXi+miWkEREjDYsNyw53W5gztAv1LBbMO d8cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=sCPj7zeb; 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 qh14si6041194ejb.171.2020.05.29.10.37.25; Fri, 29 May 2020 10:37:48 -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=sCPj7zeb; 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 S1727803AbgE2RfK (ORCPT + 99 others); Fri, 29 May 2020 13:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbgE2Reh (ORCPT ); Fri, 29 May 2020 13:34:37 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D9F2C08C5C9 for ; Fri, 29 May 2020 10:34:34 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id s1so2926148qkf.9 for ; Fri, 29 May 2020 10:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Vv9ldXFCL4C/whPnS1mUqMWHmnWNvuasrevBys51oQY=; b=sCPj7zebj0mv/diKCtrYT+mdgdGgrILrkEIsuMU30qVuUgOq4rON4zv7t2IR2QCCiy 3nrhEnxM2SGiLbEzjs2OAQIKXYa1L0JMAEQbxfGNecN9eTyx0U23ysaxMZTpjXa7RgHj 5VnUzdZXxiTXHSkHixvkLr2YcT2kEKlE/x1Yo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Vv9ldXFCL4C/whPnS1mUqMWHmnWNvuasrevBys51oQY=; b=RSJSaGvffRvKd6N6oCZIDy+v1wElR0yPnU6I7TDnupO1ZC2j88DwvbcUP+J5r7iy7E MFsnoe3dtMtUzDGUAhSKNVbii3ZndcO1Qa0dkyNkFynOemfzwTDCWKkhRepwXpF4c2FH F2n8WObdAYZbbbVY/rFhtSlBVqbVsheLqFSqOUyyyaBkwxkYkBDOkVuRRPFXQY6iXNN6 X1y8MTL1n+tadmjbiSDLBhL53NNqYe1zbnnfnMfWxlFGhv9mbuAC6BA5OY9fI7teDnr5 Tdcg/BlZudFxDxmxvz6hp35zzAFKDp/rolgtQlhkIIwXdVynP2qNvKrQyVn0unXS8sF+ 1LIQ== X-Gm-Message-State: AOAM5337Gvqn559BOcdgz8pdt7k1AgYNHLTZyHEie+NcvPLlR3hr/AU0 Daee44y682Cv6BQV44eBFuExNg== X-Received: by 2002:a37:4d97:: with SMTP id a145mr8891186qkb.94.1590773673300; Fri, 29 May 2020 10:34:33 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id w49sm9228391qth.74.2020.05.29.10.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 10:34:32 -0700 (PDT) Date: Fri, 29 May 2020 13:34:32 -0400 From: Joel Fernandes To: Andrii Nakryiko Cc: Andrii Nakryiko , bpf , Networking , "Paul E . McKenney" , Alan Stern , parri.andrea@gmail.com, will@kernel.org, Peter Ziljstra , Boqun Feng , npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, Akira Yokosawa , dlustig@nvidia.com, open list , linux-arch@vger.kernel.org, Kernel Team Subject: Re: [PATCH linux-rcu] docs/litmus-tests: add BPF ringbuf MPSC litmus tests Message-ID: <20200529173432.GC196085@google.com> References: <20200528062408.547149-1-andriin@fb.com> <20200528225427.GA225299@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrii, On Thu, May 28, 2020 at 10:50:30PM -0700, Andrii Nakryiko wrote: > > [...] > > > diff --git a/Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus b/Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus > > > new file mode 100644 > > > index 000000000000..558f054fb0b4 > > > --- /dev/null > > > +++ b/Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus > > > @@ -0,0 +1,91 @@ > > > +C bpf-rb+1p1c+bounded > > > + > > > +(* > > > + * Result: Always > > > + * > > > + * This litmus test validates BPF ring buffer implementation under the > > > + * following assumptions: > > > + * - 1 producer; > > > + * - 1 consumer; > > > + * - ring buffer has capacity for only 1 record. > > > + * > > > + * Expectations: > > > + * - 1 record pushed into ring buffer; > > > + * - 0 or 1 element is consumed. > > > + * - no failures. > > > + *) > > > + > > > +{ > > > + atomic_t dropped; > > > +} > > > + > > > +P0(int *lenFail, int *len1, int *cx, int *px) > > > +{ > > > + int *rLenPtr; > > > + int rLen; > > > + int rPx; > > > + int rCx; > > > + int rFail; > > > + > > > + rFail = 0; > > > + > > > + rCx = smp_load_acquire(cx); > > > + rPx = smp_load_acquire(px); > > > > Is it possible for you to put some more comments around which ACQUIRE is > > paired with which RELEASE? And, in general more comments around the reason > > for a certain memory barrier and what pairs with what. In the kernel sources, > > the barriers needs a comment anyway. This was the comment earlier that was missed. > > > + if (rCx < rPx) { > > > + if (rCx == 0) { > > > + rLenPtr = len1; > > > + } else { > > > + rLenPtr = lenFail; > > > + rFail = 1; > > > + } > > > + > > > + rLen = smp_load_acquire(rLenPtr); > > > + if (rLen == 0) { > > > + rFail = 1; > > > + } else if (rLen == 1) { > > > + rCx = rCx + 1; > > > + smp_store_release(cx, rCx); > > > + } > > > + } > > > +} > > > + > > > +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) > > > +{ > > > + int rPx; > > > + int rCx; > > > + int rFail; > > > + int *rLenPtr; > > > + > > > + rFail = 0; > > > + > > > + rCx = smp_load_acquire(cx); > > > + spin_lock(rb_lock); > > > + > > > + rPx = *px; > > > + if (rPx - rCx >= 1) { > > > + atomic_inc(dropped); > > > > Why does 'dropped' need to be atomic if you are always incrementing under a > > lock? > > It doesn't, strictly speaking, but making it atomic in litmus test was > just more convenient, especially that I initially also had a lock-less > variant of this algorithm. Ok, that's fine. > > > > > + spin_unlock(rb_lock); > > > + } else { > > > + if (rPx == 0) { > > > + rLenPtr = len1; > > > + } else { > > > + rLenPtr = lenFail; > > > + rFail = 1; > > > + } > > > + > > > + *rLenPtr = -1; > > > > Clarify please the need to set the length intermittently to -1. Thanks. > > This corresponds to setting a "busy bit" in kernel implementation. > These litmus tests are supposed to be correlated with in-kernel > implementation, I'm not sure I want to maintain extra 4 copies of > comments here and in kernel code. Especially for 2-producer cases, > there are 2 identical P1 and P2, which is unfortunate, but I haven't > figured out how to have a re-usable pieces of code with litmus tests > :) I disagree that comments related to memory ordering are optional. IMHO, the documentation should be clear from a memory ordering standpoint. After all, good Documentation/ always clarifies something / some concept to the reader right? :-) Please have mercy on me, I am just trying to learn *your* Documentation ;-) > > > diff --git a/Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus b/Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus [...] > > > +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) > > > +{ > > > + int rPx; > > > + int rCx; > > > + int rFail; > > > + int *rLenPtr; > > > + > > > + rFail = 0; > > > + rLenPtr = lenFail; > > > + > > > + rCx = smp_load_acquire(cx); > > > + spin_lock(rb_lock); > > > + > > > + rPx = *px; > > > + if (rPx - rCx >= 1) { > > > + atomic_inc(dropped); > > > + spin_unlock(rb_lock); > > > + } else { > > > + if (rPx == 0) { > > > + rLenPtr = len1; > > > + } else if (rPx == 1) { > > > + rLenPtr = len1; > > > + } else { > > > + rLenPtr = lenFail; > > > + rFail = 1; > > > + } > > > + > > > + *rLenPtr = -1; > > > + smp_store_release(px, rPx + 1); > > > + > > > + spin_unlock(rb_lock); > > > + > > > + smp_store_release(rLenPtr, 1); > > > > I ran a test replacing the last 2 statements above with the following and it > > still works: > > > > spin_unlock(rb_lock); > > WRITE_ONCE(*rLenPtr, 1); > > > > Wouldn't you expect the test to catch an issue? The spin_unlock is already a > > RELEASE barrier. > > Well, apparently it's not an issue and WRITE_ONCE would work as well > :) My original version actually used WRITE_ONCE here. See [0] and > discussion in [1] after which I removed all the WRITE_ONCE/READ_ONCE > in favor of store_release/load_acquire for consistency. > > [0] https://patchwork.ozlabs.org/project/netdev/patch/20200513192532.4058934-3-andriin@fb.com/ > [1] https://patchwork.ozlabs.org/project/netdev/patch/20200513192532.4058934-2-andriin@fb.com/ Huh. So you are replacing the test to use WRITE_ONCE instead? Why did you favor the acquire/release memory barriers over the _ONCE annotations, if that was not really needed then? > > Suggestion: It is hard to review the patch because it is huge, it would be > > good to split this up into 4 patches for each of the tests. But upto you :) > > Those 4 files are partial copies of each other, not sure splitting > them actually would be easier. If anyone else thinks the same, though, > I'll happily split. I personally disagree. It would be much easier IMHO to review 4 different files since some of them are also quite dissimilar. I frequently keep jumping between diffs to find a different file and it makes the review that much harder. But anything the LKMM experts decide in this regard is acceptable to me :) thanks, - Joel