Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2278902ybi; Thu, 4 Jul 2019 08:04:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQwhgPwKqTJX6Z1jOZeAE89ENUfxQYyHVKuGQC3JbdYYEjr9weVKwOHkBlx96lPgPfqa1e X-Received: by 2002:a63:480e:: with SMTP id v14mr43069595pga.182.1562252689295; Thu, 04 Jul 2019 08:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562252689; cv=none; d=google.com; s=arc-20160816; b=XRgUBl+fWLPlZubbXedICqSsmYdPiydwa/PcH/ZTD59ArzncB3GlNhTlY3E0e6PnR7 WQ/FNrcxsDeaS/u0ILuj5d25FAh2dJ81wyiFBQ/yPiitHEaXbiXJn1F1X3R7cxMgQyRC j6tTbRd/6ZsLTg3+w4ih8NtprQVKnD8k0gKN90cWCyXLCLEf2GDqdi8VDks5dfX3BYPR SzHMR4Z3PfNpfuEmBQia8hVpk1OEqOcXSeQww58HP6jPWUr+cyqGcgC2pQ9uK2+yl1S6 cxtfDzuaNBg+oNibb/b9X/sFMbxoGanFe0Hrml2ilw9YepCZwP+0cwn31xbA6L7vDTUk 3sHg== 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=c3ZmLgmE9qSPNTt80+eRmBGm3GUoHp+hG4uB7aPccXU=; b=WtmBmCQDqXCxthAMEHa0PHmc1Fh7BYdxm/U0coFvttOyuJ5KrGe+vpcaH/cWHck2gX g4iRjCxeLjPlNNtgxFANw/Vzs9RBqa1n8tCcACW8eIqy1BPPLmFltJnnJogDLKiBo8NN UHKIwDTITcIDimqOOm7pt74ylLQnxAjX/jnpB2PN4F70yUdk6bmOeMcsA+yqW1Ajt+Zf MDawu4NK4G5ChmuaqwVXaYQ2YQhPoZCVE4O+tswj65EQ7w0MznJo8SddgaPzSiDmfH9G JPzsTL03kGwm+8MVjOBIgbti104qQbB3BLCybCwSPIY9MoyCO4uxYCbnMDlfpJ/22TM+ 9laA== 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 k15si5455743pgh.331.2019.07.04.08.04.31; Thu, 04 Jul 2019 08:04:49 -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 S1727394AbfGDPAI (ORCPT + 99 others); Thu, 4 Jul 2019 11:00:08 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59258 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbfGDPAI (ORCPT ); Thu, 4 Jul 2019 11:00:08 -0400 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1hj3DI-0004JQ-LG; Thu, 04 Jul 2019 16:59:56 +0200 From: John Ogness To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky Subject: Re: [PATCH POC] printk_ringbuffer: Alternative implementation of lockless printk ringbuffer References: <20190621140516.h36g4in26pe3rmly@pathway.suse.cz> <20190704103321.10022-1-pmladek@suse.com> Date: Thu, 04 Jul 2019 16:59:54 +0200 In-Reply-To: <20190704103321.10022-1-pmladek@suse.com> (Petr Mladek's message of "Thu, 4 Jul 2019 12:33:21 +0200") Message-ID: <87r275j15h.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 Hi Petr, On 2019-07-04, Petr Mladek wrote: > This is POC that implements the lockless printk ringbuffer slightly > different way. I believe that it is worth considering because it looks > much easier to deal with. The reasons are: > > + The state of each entry is always clear. > > + The write access rights and validity of the data > are clear from the state of the entry. > > + It seems that three barriers are enough to synchronize > readers vs. writers. The rest is done implicitely > using atomic operations. > > Of course, I might have missed some critical race that can't get > solved by the new design easily. But I do not see it at the moment. Two things jump out at me when looking at the implementation: 1. The code claims that the cmpxchg(seq_newest) in prb_reserve_desc() guarantees that "The descriptor is ours until the COMMITTED bit is set." This is not true if in that wind seq_newest wraps, allowing another writer to gain ownership of the same descriptor. For small descriptor arrays (such as in my test module), this situation is quite easy to reproduce. This was one of the reasons I chose to use a linked list. When the descriptor is atomically removed from the linked list, it can _never_ be used (or even seen) by any other writer until the owning writer is done with it. I'm not yet sure how that could be fixed with this implementation. The state information is in a separate variable than the head pointer for the descriptor array (seq_newest). This means you cannot atomically reserve descriptors. 2. Another issue is when prb_reserve() fails and sets the descriptor as unused. As it is now, no reader can read beyond that descriptor until it is recycled. Readers need to know that the descriptor is bad and can be skipped over. It might be better to handle this the way I did: go ahead and set the state to committed, but have invalid lpos/lpos_next values (for example: lpos_next=lpos) so the reader knows it can skip over the descriptor. > The code compiles but it is not really tested. I wanted to send it > ASAP in a good enough state before we spend more time on cleaning > up either of the proposals. I am glad to see you put together your implementation. If anything, it shows you understand the design! If after seeing my next version (v3) you are still convinced that using a linked list for the descriptors is too complex, then I can help support your idea to move to an array. Thank you for taking so much time for this! John Ogness