Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1138750ybb; Thu, 28 Mar 2019 21:07:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIYUSVnH5vPAO44KSOzzAWA/1CAdsndwZqCVQnml/0SjcXVLHGjEhwTJqfMy4oFEGSUN9i X-Received: by 2002:aa7:8d01:: with SMTP id j1mr45940359pfe.122.1553832463590; Thu, 28 Mar 2019 21:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553832463; cv=none; d=google.com; s=arc-20160816; b=Tgfpwlurw0dnabTSnnmcRVyxb1MjZ6V6/4dXgv6mHmKNayqRPp4dYZmeiG9lsrlqEs vj1DKKijFjtbNDxkk4nlxAQgRJMoveyIhDTJMSDhDKYmIXRJOl37Mv3RTi8bAhDGpMTo 36skELuH0vKWGwEe9arffgR2uerWWgMR1VZNSu1zRFbhsyE5EEJmTFrxKqavZ1AgiYsJ gUd2W7DoOGpDxyHrhVKqniTGmv9KIKh6XuKbFxd0XoOqA+ZC0pStqqbAl+/cunQHrl9q 0m9sJD1p2pyBC8JQeg7kmu7b1uUMhYMKYCdZoxizUwPNrXc6qEVIvR8sNGw4m9mTGsQO 60QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=E99/uDmEWiANrLfG/9dDK6an3z4rD0PRA3vgayXozKU=; b=l8OEdkgR4JK1cSdruzSFXajJmP7J4dW2/SK7kDRbUDiYiv1SxWNNOeFz0MmL7mmHwe YbPrLIdQCspy5qrR3dz7A9Sjbz2r/u3QbabNBHr3lqEh7XWXntCfUcV3+vAfJoV+K5qY SgMn0ySa7raZ8xVoWbYDHFxs/B/lt5T0YCIc9+V1ZLmYATUhcabEXAIgA8xm50Rv6p+S BMnv5ynNQdPDxAOQePxGIspb2+JR1MDhzPx0T1mfWONx5H8pljly09KY79RQv1p1cMkq yPzg0GbPPp2Kc65zwEmSowmDJk82W1AxpwrHEcckwpSOC1AGtVZ/KGbc8Ah+gNh6vu3S rYXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="M/bN7OD8"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s83si923381pgs.420.2019.03.28.21.07.26; Thu, 28 Mar 2019 21:07:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="M/bN7OD8"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1725865AbfC2EGs (ORCPT + 99 others); Fri, 29 Mar 2019 00:06:48 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:45700 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbfC2EGs (ORCPT ); Fri, 29 Mar 2019 00:06:48 -0400 Received: by mail-oi1-f195.google.com with SMTP id y84so621209oia.12 for ; Thu, 28 Mar 2019 21:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E99/uDmEWiANrLfG/9dDK6an3z4rD0PRA3vgayXozKU=; b=M/bN7OD8LEBlR3l3ADqC3eSZyjwZWmAhXdFmhR8g2fPLnn3TONVkGx3baOW76e2s9m o9SKaECoEe2c4Mxx/Le8fFluvhCyS6enTskijRnZUGiKYytnbUU8msdfVzdghVCg4OZf g6OSzl19jMlzE5jiNnQQEazWVRCSXu1lIzQcDEgICdUWe1oBQhv8UmGF5EHoH6YIdjAR gH5rTRGvUjl9A3t4AC1Fwx3geZKsBBNRtmp+Mwu1+jH+SCy72AHLkJrmd6F8g1zqDlKO FHv8mvUTjtW2VR+wbFwVp14DhOLPEl06QWB+FMEzHfLtYlPWPxWkPI5HSuKscELILbSu Py/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E99/uDmEWiANrLfG/9dDK6an3z4rD0PRA3vgayXozKU=; b=oj3SFBj87RV8nboE52mKMk+e8otawfRGsonXgb2cYW25GqtkZvJaLDvteWU7a5J2gL Rssjl/xBvi8U1hMzt2daCSkOfTPZ0lLII619a9N1eCfr8I6g4onpBW1do0hxv/WfLMZ4 lKDzDzJW4eBGgprH4+35iuU+ll40nDfqYU47WUaCt7IfnkGGZHbU54wW3v1if06F1q6F X4G/dLnqpz37qUVJtr4HINZepxAN7ov0AqXJup4DAyA59mWb2EqzQdj4cHSmwW5Xzg+r Hh6tBjoi7pf6V+3w47uIYlWgD64KnPD3Iv7b46sa4dRfQ+rw+KtZsY4fxtetLoj97zui okMQ== X-Gm-Message-State: APjAAAUCIbvU28lkHap3hAv2jJ/MAgNaePcJJVVJ3Sg8NOtwjZOluNRB TtAOzsPIX0cGYsxTTo/ukIo/E9h1GSVi1bmgEdXAEA== X-Received: by 2002:aca:e4cc:: with SMTP id b195mr2374186oih.39.1553832407601; Thu, 28 Mar 2019 21:06:47 -0700 (PDT) MIME-Version: 1.0 References: <20190329024047.206989-1-joel@joelfernandes.org> In-Reply-To: <20190329024047.206989-1-joel@joelfernandes.org> From: Jann Horn Date: Fri, 29 Mar 2019 05:06:21 +0100 Message-ID: Subject: Re: [PATCH] doc/rcuref: Document real world examples in kernel To: "Joel Fernandes (Google)" Cc: kernel list , Oleg Nesterov , Jonathan Corbet , Josh Triplett , Lai Jiangshan , linux-doc@vger.kernel.org, Mathieu Desnoyers , "Paul E. McKenney" , Steven Rostedt Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 29, 2019 at 3:40 AM Joel Fernandes (Google) wrote: > Document similar real world examples in the kernel corresponding to the > second and third code snippets. Also correct an issue in > release_referenced() in the code snippet example. > > Cc: oleg@redhat.com > Cc: jannh@google.com > Signed-off-by: Joel Fernandes (Google) > > --- > Documentation/RCU/rcuref.txt | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/Documentation/RCU/rcuref.txt b/Documentation/RCU/rcuref.txt > index 613033ff2b9b..e5f4a49f886a 100644 > --- a/Documentation/RCU/rcuref.txt > +++ b/Documentation/RCU/rcuref.txt > @@ -28,7 +28,8 @@ add() search_and_reference() > release_referenced() delete() > { { > ... write_lock(&list_lock); > - atomic_dec(&el->rc, relfunc) ... > + if(atomic_dec_and_test(&el->rc)) ... > + kfree(el); > ... remove_element > } write_unlock(&list_lock); > ... > @@ -114,6 +115,11 @@ element can therefore safely be freed. This in turn guarantees that if > any reader finds the element, that reader may safely acquire a reference > without checking the value of the reference counter. > > +The other advantage of the last pattern is, if there are several calls to > +search_and_reference() in parallel to the delete(), then all of those will > +succeed in obtaining a reference to the object if the object could be found in > +the list before it was deleted in delete(). Isn't this the same as what the previous paragraph said? "if any reader finds the element, that reader may safely acquire a reference without checking the value of the reference counter". > In cases where delete() can sleep, synchronize_rcu() can be called from > delete(), so that el_free() can be subsumed into delete as follows: > > @@ -130,3 +136,7 @@ delete() > kfree(el); > ... > } > + > +As additional examples in the kernel, This last pattern is also followed by nit: s/, This/, this/