Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3405660ybd; Tue, 25 Jun 2019 01:56:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDBdLWkqPFcHhbIgTB2W3+uSY0gRKTvU2EMyDYVnCl7Grs4Vznh4QJxhLmA3KRbEMEsoCe X-Received: by 2002:a17:902:6a88:: with SMTP id n8mr62122698plk.70.1561452982741; Tue, 25 Jun 2019 01:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561452982; cv=none; d=google.com; s=arc-20160816; b=AyBGwKX8fKXq9EUwi4vBuUyZ+Ua7X1ADefk429DmyEKe24j8Cp5Dyx6jJFuIshP9N2 WjG6m0KbfKrt+e/5a8gKyO5/NKRLlY3RXxDq0RTtfNQI/ZQBz6qGmFVvz2szQzcj8T/8 1Dhcf83jiAKFaYzcM/qQZDdK0fn8EXGv8+AGwskSddxoCDIrMgDMY726BRvjErQZ/O+c JRPzbThBPHEMrrWQVCqUXZjyo4cOsIaIOH8qYKtxfr+x7DGcpfWWUf/Fk1l689KdPAQ3 AKPzwztY4rOsuvmBvj71blZUpDhpiazIc7Jy9p6qjscnGD8eiB6JZ+XI2WAlK1L/UvbF lktA== 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=+IzEucIG54RmCyKHNUFpI/gXT16OQrPA9k18KegFQh4=; b=i/dM87hM+KTSysPNpXHOETyq37yHW8PYt5/KJngOcyUxy5JGXAZXZiceCfwG8hFq5F WrwpMuhOQ0N6hyvF16GDNTj2VLZc1izlE4K2LRD0kH6CqfXWX2bCpcjLELPjF0ZrbUxU jQS4q9bfz64KeDHFPOa57AvjS0jE5X7/+cGTqWsquuhIxMqk23uUn2cQMyYN8HIA/pfX lGazEyCBlizL/VSWfFIhzu+03Rg/wsOpMobr1+Ba6mK0glZxjcoJFPwIDVndod/WTlFH Bi3Q/9VpRwWyV/EYjHZLG1sRReovYGCKVlYoJVT3D8OJ4x40C6hojFFHtH2usKnbvGmp Gfjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EO3l1E7x; 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 j2si3605005pgp.23.2019.06.25.01.56.06; Tue, 25 Jun 2019 01:56:22 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EO3l1E7x; 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 S1731114AbfFYIzx (ORCPT + 99 others); Tue, 25 Jun 2019 04:55:53 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34678 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731075AbfFYIzx (ORCPT ); Tue, 25 Jun 2019 04:55:53 -0400 Received: by mail-pl1-f194.google.com with SMTP id i2so8477636plt.1 for ; Tue, 25 Jun 2019 01:55:52 -0700 (PDT) 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=+IzEucIG54RmCyKHNUFpI/gXT16OQrPA9k18KegFQh4=; b=EO3l1E7x1mMuMayS9FO0D6d2bRbRNDKZRvMX/rPQnRqccWt+GtKsk3FuusXMkc3URA DnB9oA01u1WluZXmCdTzBipssgWFyA2lSgLLE3XGF5I0dSHZXfg43pMyji9y5isEnZQ4 XWY8X7dxUtQmMXDm11+Scn/qfwHiVRks4+slosnPWPquEaIzqZzAQZ2oFZ4/lmhQtAnI GAylyAGOgBdlwCl+jN0n3L2soEiQwl9frqHlNoxi014VoG2qF8bJB+r66slh0NEAVMeF 7KOkZu0IVqDLtELToKKjkB0Rw7CO8q2r/FGT/cG94Go603d+F4seCJMcugx2Rh9GiHcl 1upQ== 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=+IzEucIG54RmCyKHNUFpI/gXT16OQrPA9k18KegFQh4=; b=lo9lloF5a0fWOHOHXhi8KU8rKVmfMISdHCR9ZGfLEEczVATbkugNQJWd81wAAGNwZO DCCLx47xglefboRvjDw4bSSvhhAWB/gtvzKgB//FSY0PwG62zl7ZmCIjpX7aP0V2EJ0Q Y+VF5uWEyGCrqKrvCZisvLgDM3J1a+VRcNOJzd++tRNuA2rDODp81JcFk3ZNBso4/e6X o59WrVGnemwjjXLFm7A9emMqNOiS8vpMDRkml52tYIPAXpxapNziWej4GAcWpEV1nAMi 7GrxkXMWG2G/tuqKBG3bU8hxN5sD5IbnfzgCNR+6hO0uWpubti08TDHbSs9BESjIo7Xv OexA== X-Gm-Message-State: APjAAAWAOpN0FI0DCzCg7qHEiovkcoYRJqR3qSBknVA+DQOQHbyFk2LV 9HHbq9FYr8kkXsoNyU+6TDw= X-Received: by 2002:a17:902:e65:: with SMTP id 92mr146290242plw.13.1561452952337; Tue, 25 Jun 2019 01:55:52 -0700 (PDT) Received: from localhost ([175.223.22.38]) by smtp.gmail.com with ESMTPSA id j13sm13725770pfh.13.2019.06.25.01.55.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 25 Jun 2019 01:55:51 -0700 (PDT) Date: Tue, 25 Jun 2019 17:55:48 +0900 From: Sergey Senozhatsky To: John Ogness Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky Subject: Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation Message-ID: <20190625085548.GA532@jagdpanzerIV> References: <20190607162349.18199-1-john.ogness@linutronix.de> <20190607162349.18199-2-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190607162349.18199-2-john.ogness@linutronix.de> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (06/07/19 18:29), John Ogness wrote: [..] > +static void add_descr_list(struct prb_reserved_entry *e) > +{ > + struct printk_ringbuffer *rb = e->rb; > + struct prb_list *l = &rb->descr_list; > + struct prb_descr *d = e->descr; > + struct prb_descr *newest_d; > + unsigned long newest_id; > + > + /* set as newest */ > + do { > + /* MB5: synchronize add descr */ > + newest_id = smp_load_acquire(&l->newest); > + newest_d = TO_DESCR(rb, newest_id); > + > + if (newest_id == EOL) > + WRITE_ONCE(d->seq, 1); > + else > + WRITE_ONCE(d->seq, READ_ONCE(newest_d->seq) + 1); > + /* > + * MB5: synchronize add descr > + * > + * In particular: next written before cmpxchg > + */ > + } while (cmpxchg_release(&l->newest, newest_id, e->id) != newest_id); > + > + if (unlikely(newest_id == EOL)) { > + /* no previous newest means we *are* the list, set oldest */ > + > + /* > + * MB UNPAIRED > + * > + * In particular: Force cmpxchg _after_ cmpxchg on newest. > + */ > + WARN_ON_ONCE(cmpxchg_release(&l->oldest, EOL, e->id) != EOL); > + } else { > + /* link to previous chain */ > + > + /* > + * MB6: synchronize link descr > + * > + * In particular: Force cmpxchg _after_ cmpxchg on newest. > + */ > + WARN_ON_ONCE(cmpxchg_release(&newest_d->next, > + EOL, e->id) != EOL); > + } > +} [..] > +char *prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, > + unsigned int size) > +{ > + struct prb_datablock *b; > + struct prb_descr *d; > + char *buf; > + > + if (size == 0) > + return NULL; > + > + size += sizeof(struct prb_datablock); > + size = DATA_ALIGN_SIZE(size); > + if (size > DATAARRAY_SIZE(rb)) > + return NULL; > + > + e->rb = rb; > + > + local_irq_save(e->irqflags); > + > + if (!assign_descr(e)) > + goto err_out; > + > + d = e->descr; > + WRITE_ONCE(d->id, e->id); > + > + if (!data_reserve(e, size)) { > + /* put invalid descriptor on list, can still be traversed */ > + WRITE_ONCE(d->next, EOL); > + add_descr_list(e); > + goto err_out; > + } I'm wondering if prb can always report about its problems. Including the cases when things "go rather bad". Suppose we have printk() prb_reserve() !data_reserve() add_descr_list() WARN_ON_ONCE() printk() prb_reserve() !assign_descr(e) << lost WARN_ON's "printk" or "printks"? In general, assuming that there might be more error printk-s either called directly directly from prb->printk on indirectly, from prb->ABC->printk. Also note, Lost printk-s are not going to be accounted as 'lost' automatically. It seems that for printk() there is no way to find out that it has recursed from printk->prb_commit but hasn't succeeded in storing recursive messages. I'd say that prb_reserve() err_out should probably &rb->lost++. -ss