Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp26635ybg; Thu, 11 Jun 2020 16:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFBx+3QFYiad4v0thvAFZG5uOk3uUA/j4Lq4qsL1diSS720TIvaEqlCRX07pKFnAgg8NBy X-Received: by 2002:a17:906:1d52:: with SMTP id o18mr9753269ejh.399.1591916953812; Thu, 11 Jun 2020 16:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591916953; cv=none; d=google.com; s=arc-20160816; b=JZG3E4MU6QaS+LRRyfpaE6Fw8B++o1EsDnnnrMGz1xz45W5DSwIDbvjs+6NvC9eAr1 dvWMb6F7ZXtu9N0Yvxs/j9tqtK2wT8a4W+PXEwEtufZUkRTFVqVwmsNc/m7h3HMIHq32 2ttaQftBRlyu6DEYTXPckgfX/MGPEnrwSoE+k8+5+7OwigyIMBk3+c0jHcJAs8ez17Ac h3c984Zu+dnXGVzaBuYkv9kC0/U6G6dw6S0wwhs7XqjLIqfgnCQbP6+0QcMEDUmPjhyT ogFkvoSGR1PpQk3gvw67Ohmf0ogcj2DHvoKlBY8OzIoyJCwPQTgSJv4Qxn/TvWi1R3zO m8WA== 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=SVmb+MK4+ejdjxAVFMlwQWYTMDuVPzKkO0HIHWuGfPo=; b=1KixPYTKEfgTZKuaV+v9N4WUxaQKZCJsPgdAmc/jBssj9W4swIi/R4CnnwKx9XsmkJ Ht2ockWYILJ8YDg4H9mxQA7smYjjSWpxoWUPD/VnwiqD9yBw8Nw5EIuNf/0/QCM7nAHI NYqzXppJOApKapjCOBkXz8VNl34kzojVOlD+8mB8iW3mIWqHM4SqvsUG2IojiHCDpr0E lnLirtO2ze9RnTQNYzH5FDwyTqfjaAYnoaw2AffY8QG+6b/43YiySAb5lZ7qcLVMuPtu rIkSaHifUa2riJ9FXOK3XilsEI8iasJRUf2qfpp7L4CnBgp4FCl5hBeHM4HTwCPDUe6d jYfw== ARC-Authentication-Results: i=1; mx.google.com; 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 c19si2974993ejp.127.2020.06.11.16.08.51; Thu, 11 Jun 2020 16:09:13 -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; 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 S1726332AbgFKXGi (ORCPT + 99 others); Thu, 11 Jun 2020 19:06:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbgFKXGi (ORCPT ); Thu, 11 Jun 2020 19:06:38 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28E4EC08C5C1 for ; Thu, 11 Jun 2020 16:06:38 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=vostro) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jjWHH-0008Ah-R0; Fri, 12 Jun 2020 01:06:32 +0200 From: John Ogness To: Petr Mladek Cc: Peter Zijlstra , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Paul McKenney Subject: Re: Barrier before pushing desc_ring tail: was [PATCH v2 2/3] printk: add lockless buffer References: <20200501094010.17694-1-john.ogness@linutronix.de> <20200501094010.17694-3-john.ogness@linutronix.de> <20200609113751.GD23752@linux-b0ei> <87d068utbg.fsf@vostro.fn.ogness.net> <20200611120107.GD6581@linux-b0ei> Date: Fri, 12 Jun 2020 01:06:28 +0200 In-Reply-To: <20200611120107.GD6581@linux-b0ei> (Petr Mladek's message of "Thu, 11 Jun 2020 14:01:08 +0200") Message-ID: <87bllpyzgr.fsf@vostro.fn.ogness.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-11, Petr Mladek wrote: > All this relies on the fact the the full barrier is called in > data_push_tail() and data_push_tail() is called right above. > But there are two situations where the barrier is not called. > It is when: > > 1. desc.text_blk_lpos.next already is behind data_ring->tail_lpos. > > This is safe. Yes, and I have since expanded the comment above the data_push_tail() while loop to mention that: /* * Loop until the tail lpos is at or beyond @lpos. This condition * may already be satisfied, resulting in no full memory barrier * from data_push_tail:C being performed. However, since this CPU * sees the new tail lpos, any descriptor states that transitioned to * the reusable state must already be visible. */ > 2. desc.text_blk_lpos == INVALID_LPOS. > > It seems that this is not synchronized and other CPUs might see > the old state. Great catch! This could trigger the WARN_ON at desc_reserve:F and lead to prb_reserve() unnecessarily failing. > The question is what to do with the empty data case. I see three > possibilities: > > 1. Ignore the case with empty block because it (probably) does not > cause real problems. It could cause dropped messages. > 2. Call the full barrier in data_push_tail() even when the data > block is empty. This is the common case, since most records will not have dictionary data. > 3. Call the full barrier also in desc_push_tail() as I suggested. > > My opinion: > > I prefer 3rd solution. Agreed. For my next version I am folding all smp_mb() and smp_wmb() calls into their neighboring cmpxchg_relaxed(). This would apply here as well, changing desc_push_tail:B to a full cmpxchg(). We still need the full memory barrier at data_push_tail:C. Readers rely on it to be able to verify if their copied data is still valid: CPU0 (writer0) CPU1 (writer1) CPU2 (reader) desc_read->committed desc_make_reusable smp_mb data_push_tail read new data tail data_push_head smp_mb write new data read garbage new data desc_read->reusable John Ogness