From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ibwog-0006uJ-MR for kexec@lists.infradead.org; Tue, 03 Dec 2019 01:17:30 +0000 Received: by mail-pf1-x441.google.com with SMTP id y206so869878pfb.0 for ; Mon, 02 Dec 2019 17:17:24 -0800 (PST) Date: Tue, 3 Dec 2019 10:17:21 +0900 From: Sergey Senozhatsky Subject: Re: [RFC PATCH v5 1/3] printk-rb: new printk ringbuffer implementation (writer) Message-ID: <20191203011721.GH93017@google.com> References: <20191128015235.12940-1-john.ogness@linutronix.de> <20191128015235.12940-2-john.ogness@linutronix.de> <20191202154841.qikvuvqt4btudxzg@pathway.suse.cz> <20191202155955.meawljmduiciw5t2@pathway.suse.cz> <87sgm2fzuh.fsf@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87sgm2fzuh.fsf@linutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: John Ogness Cc: Andrea Parri , Petr Mladek , Sergey Senozhatsky , Peter Zijlstra , Greg Kroah-Hartman , Brendan Higgins , linux-kernel@vger.kernel.org, Steven Rostedt , Sergey Senozhatsky , Thomas Gleixner , Linus Torvalds , kexec@lists.infradead.org On (19/12/02 17:37), John Ogness wrote: > On 2019-12-02, Petr Mladek wrote: > >> > +/* Reserve a new descriptor, invalidating the oldest if necessary. */ > >> > +static bool desc_reserve(struct printk_ringbuffer *rb, u32 *id_out) > >> > +{ > >> > + struct prb_desc_ring *desc_ring = &rb->desc_ring; > >> > + struct prb_desc *desc; > >> > + u32 id_prev_wrap; > >> > + u32 head_id; > >> > + u32 id; > >> > + > >> > + head_id = atomic_read(&desc_ring->head_id); > >> > + > >> > + do { > >> > + desc = to_desc(desc_ring, head_id); > >> > + > >> > + id = DESC_ID(head_id + 1); > >> > + id_prev_wrap = DESC_ID_PREV_WRAP(desc_ring, id); > >> > + > >> > + if (id_prev_wrap == atomic_read(&desc_ring->tail_id)) { > >> > + if (!desc_push_tail(rb, id_prev_wrap)) > >> > + return false; > >> > + } > >> > + } while (!atomic_try_cmpxchg(&desc_ring->head_id, &head_id, id)); > >> > >> Hmm, in theory, ABA problem might cause that we successfully > >> move desc_ring->head_id when tail has not been pushed yet. > >> > >> As a result we would never call desc_push_tail() until > >> it overflows again. > >> > >> I am not sure if we need to take care of it. The code is called with > >> interrupts disabled. IMHO, only NMI could cause ABA problem > >> in reality. But the game (debugging) is lost anyway when NMI ovewrites > >> the buffer several times. > > > > BTW: If I am counting correctly. The ABA problem would happen when > > exactly 2^30 (1G) messages is written in the mean time. > > All the ringbuffer code assumes that the use of index numbers handles > the ABA problem (i.e. there must not be 1 billion printk's within an > NMI). If we want to support 1 billion+ printk's within an NMI, then > perhaps the index number should be increased. For 64-bit systems it > would be no problem to go to 62 bits. For 32-bit systems, I don't know > how well the 64-bit atomic operations are supported. ftrace dumps from NMI (DUMP_ALL type ftrace_dump_on_oops on a $BIG machine)? 1G seems large enough, but who knows. -ss _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec