Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3870165ybl; Mon, 26 Aug 2019 01:43:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqasfvA7+WcWVeZtGmF9XVuhg32aF+4TL+UXdcIPuruYQiSLHkNMUHO2hnZD5Qu5FSZYK/ X-Received: by 2002:a62:1bd5:: with SMTP id b204mr18480001pfb.14.1566809003700; Mon, 26 Aug 2019 01:43:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566809003; cv=none; d=google.com; s=arc-20160816; b=A3vsdu6mneEs8euAZfLfF4I9A3jkXSOtfDogLk6TlNuprh4RmsmL1VU/hKqPGBb8BQ PVLKCioInmU9AEcIDlNnzFIKCA2uw+8HX/TdAVMbgn/2GQHwkb2HBAt6dKY4A3w9oVIG iHVWggO5Vp6N9lIU2tQH2yeGX1Kt1b0Pfg1k5T7zTm1fmb09gaD3a/mKx4zVEvvfDnjd zihBfeD1YezCsu5N16mC4sx5QDFpzKafGJWIcFmy7MucRfJJc+L2jaxwk0FMnzxcbPGt xXNqlS3gww2oj39dZbKwZc/JKPzdoFEi3w1l0YFWt1mgfFMrq0MeGnh/UtVBN2G1d73s BaXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=0MGIXLWwqZE5ymPr87PswppR3vg5aXziU0ItiOuyat8=; b=NuhS3+8CiWoLet03Y60mmM47Q+pcDV/uV+/EEzA99kRt/5Lg5/vZXmfViutPdYaVjz JeWDjJU4vxQqhnCFGX2/yQybil3C6HK4dxcpLCXwXbe4CiAREwFTZPt2Ga0GGHd0qJ/z cKVqqkvlepshX2p0y+nWj7PSsxkPDR24iCpcYfcX2JjXIcF4KWqmLus0XYkSvJGit6TW n+Z4w9U5zqaopwRhlWlZy+cJ0b/cIDRBf71tjPanPlgubexFgUGslVDy3RscctqKEZAj pO546IWlvD7DXah6m3maL6aUq9dK2SeeIgAsoeTEIg+Ai9BMF4xRBgjnvfA2YSDdpKZr 3hHw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si1781997plo.411.2019.08.26.01.43.08; Mon, 26 Aug 2019 01:43:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730509AbfHZIWB (ORCPT + 99 others); Mon, 26 Aug 2019 04:22:01 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:39060 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730379AbfHZIWA (ORCPT ); Mon, 26 Aug 2019 04:22:00 -0400 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1i2AGB-000414-2M; Mon, 26 Aug 2019 10:21:55 +0200 From: John Ogness To: Petr Mladek Cc: Andrea Parri , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Brendan Higgins , Peter Zijlstra , Thomas Gleixner , Linus Torvalds , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: assign_desc() barriers: Re: [RFC PATCH v4 1/9] printk-rb: add a new printk ringbuffer implementation References: <20190807222634.1723-1-john.ogness@linutronix.de> <20190807222634.1723-2-john.ogness@linutronix.de> <20190820082253.ybys4fsakxxdvahx@pathway.suse.cz> <20190820141429.hkrnynmr5ou4lem2@pathway.suse.cz> <87v9urdq05.fsf@linutronix.de> <20190822115329.oy5mw3nycwue6dkw@pathway.suse.cz> <87wof2knhe.fsf@linutronix.de> Date: Mon, 26 Aug 2019 10:21:53 +0200 In-Reply-To: <87wof2knhe.fsf@linutronix.de> (John Ogness's message of "Sun, 25 Aug 2019 04:06:21 +0200") Message-ID: <87k1b0cp5q.fsf@linutronix.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-08-25, John Ogness wrote: >>>>>> --- /dev/null >>>>>> +++ b/kernel/printk/ringbuffer.c >>>>>> +static bool assign_desc(struct prb_reserved_entry *e) >>>>>> +{ [...] >>>>>> + atomic_long_set_release(&d->id, atomic_long_read(&d->id) + >>>>>> + DESCS_COUNT(rb)); >>>>> >>>>> atomic_long_set_release() might be a bit confusing here. >>>>> There is no related acquire. >>> >>> As the comment states, this release is for prb_getdesc() users. The >>> only prb_getdesc() user is _dataring_pop(). (i.e. the descriptor's >>> ID is not what _dataring_pop() was expecting), then the tail must >>> have moved and _dataring_pop() needs to see that. Since there are no >>> data dependencies between descriptor ID and tail_pos, an explicit >>> memory barrier is used. More on this below. > >> + The two related barriers are in different source files >> and APIs: >> >> + assign_desc() in ringbuffer.c; ringbuffer API >> + _dataring_pop in dataring.c; dataring API > > Agreed. This is a consequence of the ID management being within the > high-level ringbuffer code. I could have added an smp_rmb() to the > NULL case in prb_getdesc(). Then both barriers would be in the same > file. However, this would mean smp_rmb() is called many times > (particularly by readers) when it is not necessary. What I wrote here is wrong. prb_getdesc() is not called "many times (particularly by readers)". It is only called once within the writer function _dataring_pop(). Looking at this again, I think it would be better to move the smp_rmb() into the NULL case of prb_getdesc(). Then both barrier pairs are located (and documented) in the same file. This also simplifies the documentation by not saying "the caller's smp_rmb() everywhere". I would also change _dataring_pop() so that the smp_rmb() is located within the handling of the other two failed checks (begin_lpos != tail_lpos and !_datablock_valid()). Then the out: at the end is just return atomic_long_read(&dr->tail_lpos). After modifying the code in this way, I think it looks more straight forward and would have avoided your confusion: The RMB in dataring.c:_dataring_pop() matches the MB in dataring.c:dataring_push() and the RMB in ringbuffer.c:prb_getdesc() matches the SET_RELEASE in ringbuffer.c:assign_desc(). John Ogness