Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp719650ybl; Mon, 2 Dec 2019 17:18:17 -0800 (PST) X-Google-Smtp-Source: APXvYqw+YFowNxtUu+P5sZfE+jM0m7ki9rJTCo6txo11GQFu1yPnhVa4bG8uFFrR2TPe/DcXUQg4 X-Received: by 2002:a9d:3af:: with SMTP id f44mr1471919otf.332.1575335897270; Mon, 02 Dec 2019 17:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575335897; cv=none; d=google.com; s=arc-20160816; b=marLUJJ2ySA2PMDIEov6zdhSMonEtAJs737tIK5xLAyh+QeeQvKz94q1wF8SCtEakM vkX6B8cNOwah0MxtyWE/pcpqkEaXVnime8neAWwEtOmNy4WXt5Z184VrFNzkP0QG8Wdz F0s/9C99MsQ935/rP6Cd9WugKoK6sZAHLaPRonG9ZRQh2DDBPPX8QNF6rofTLFoNi1xY /1D20S51cAYsc40t8h/QhtSEoGfn/izzAwzOE0sA6y5eHKcKxSwgGGaQk0VpH3JnQFyu AwOyImoGNYFhDXVseBMJOaKi9xvjk2YOig+qs3+s5DncWlC6WtpDIPOBgXDDSNokhHgu kPcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gpkHGfMnAbBIyHMTVJxkg4C53iHTuLlw5bP50AIqABQ=; b=dHupATevFc3GrHUHrPD4TO/AaXbKmCkaTH/+n6MlzLVQMsNCVKwTe9hx4vgtmuqbiW IXG3i3UVlGnGdBsd3f2OyKZ5iW5SLvZPWVwpFcfkAWfrsXp9tduX9bdnL2SEbwkrOqEz iTIvK/rti+aQ0bFfCFERvldfrqlLHnAaojC4ldXv+EtWsUsTmG5sX2FVTSws3s7oUkuE upNhrix0j5ciaSxF2oUNVCdcvOBbYkNI2OCFjD5ufwSEgu4K68hp17FYwcYaAiuhTpMM OJZEoLoax6qV2yyYS8v1oQDDsSW2t9SxfwX4KcTHk3+xmUz93/C7WU8yCtlDtoNI51v7 43dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OJazjn4d; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si428797otk.64.2019.12.02.17.17.58; Mon, 02 Dec 2019 17:18:17 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=OJazjn4d; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbfLCBRZ (ORCPT + 99 others); Mon, 2 Dec 2019 20:17:25 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39561 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbfLCBRZ (ORCPT ); Mon, 2 Dec 2019 20:17:25 -0500 Received: by mail-pg1-f195.google.com with SMTP id b137so753188pga.6 for ; Mon, 02 Dec 2019 17:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gpkHGfMnAbBIyHMTVJxkg4C53iHTuLlw5bP50AIqABQ=; b=OJazjn4dJQ2XU6QMdTYDi6Ehk3RROAXULx0PZwJwrEaOSDdgV8+QBKBRvGgeMeagGq TIkbnayPo6OF/dIVaHgqcMMPUaHrI4/x3eEStiS1gPp0Q5PCkolFxlAuryJVK+dtJxLh VVyf1pHutzWfgdDczDBABWJXcr6nw8xVebRMxvc6wzLFRrhUweoLVxjbMzvo+XH200b0 MwKRgYXfb3zZiLaE1s8OEOm3BBvQow/HcDe/aduPyTagEA2kuiITxdU+TFxeuwZK09aa 1uHjdwxlDp5VHHkOpWJ+hC7acOg2rNiwxqXQLJEgoB4PAk2zFelZkWOCKTb4LNAInDj4 X4aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=gpkHGfMnAbBIyHMTVJxkg4C53iHTuLlw5bP50AIqABQ=; b=UTf6tKK+DFp8nqLT9780bg2I9g/shV2Kj6POUb65CRXzvkls+tE4jQQQFJc8nTBCnK meUd3LWg2xlZUS6uRfbpAy5uPmItBkrpPqJsufVliXY/pTW46N9xsAX+zAoWJRBaKuwO wJm76M2CNZNNyCMmFb8W7BtpJhy/ZsjYnTxj4WlBgDb8IFYueyQJKGdq39i5J1BHr5RA hqNlUIDa5h5CA6mK287zAEPLjM90+UgwwSjmIZsGZRVhAhG700nhUb8IYZ/wRzcGkDLI K9NMC9dpM6GwVYJ9INcHipql1TFJAW/n9E+6bPkWGx5p2fIg+4890XGHAPsV3D1qwagc BzJQ== X-Gm-Message-State: APjAAAX2VzsnxceSivmfdq6I20fgkePXno78HUhmT2ZoWDbi4/opewxb ExQ3iGHSJVE5MmYgZHyREt4= X-Received: by 2002:a65:578e:: with SMTP id b14mr2442103pgr.444.1575335844294; Mon, 02 Dec 2019 17:17:24 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id i3sm738898pfd.154.2019.12.02.17.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:17:23 -0800 (PST) Date: Tue, 3 Dec 2019 10:17:21 +0900 From: Sergey Senozhatsky To: John Ogness Cc: Petr Mladek , linux-kernel@vger.kernel.org, Peter Zijlstra , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky , Brendan Higgins , kexec@lists.infradead.org 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87sgm2fzuh.fsf@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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