Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3860846ybl; Mon, 9 Dec 2019 01:04:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyqUAM65Ayzy24R4qKYcSNI4bor0HKBofnzKWXBfGcWCcKjekQK+XNslrlBfLAjTmrhwSZk X-Received: by 2002:a05:6830:1e8a:: with SMTP id n10mr7029561otr.228.1575882288420; Mon, 09 Dec 2019 01:04:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575882288; cv=none; d=google.com; s=arc-20160816; b=tpYl8AQSN8MSdLy5qfl76f4om/oBHw+Mv8gjrvBk4bsF6C3ZYnb9lDewITo0j/cE12 442EgbD3YirOTg48OXZkgI7n3P0aVagUD0MjraabbK+uOx0VuAkfYTdaAUry2U2CUTgo akjVoTDt4O4xpCTPF6FgyvSd/17eAUX1pjgvSVntCawKy/D14kSqWcuTOSYhpiM28Qzp l90n7v8JGzTYRa9XVJlUy1bNEfRBJyaqslHM2OwiFSKmMGLxn9dAGI6LGuc188ls4wIQ 7t8lCOA0MV60ruENYHTXSOwHPrl7ZU9hFuRnwmz4hqtFi1w29xF9345xxGIbSEMNbgP5 zfnA== 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=h04+/kyq65eedtQzdgewP9Eey1SBByTI6ESOC8A2z5w=; b=WswOlQ8njSsaSFhiVjyYt+9YqT0DF4sIeM4vp0KpOXaBULrCh8baUkGVqdWcnlyHPm 1dwpO42WrPHtxiAeXDfSBkPz85RStk+rqi54/xpqFm2DjoPtagIBHqw+eHdJqLYskdqH aCC5QQ41ShaWjWtpRNe7ltz3+62GF8MPZcY5MXA69A+rk6rPd6dGbEGk3OiVSHI83vgL GKjS5GOJyUYK+UIb/yzH53srm8FVMcJ1lRLCQnPR/YV0IcjwIUlJa8AMDZ5F2l2I35pw 7kOcizIHHLeFqpsVvfP+NMYZeeg3YuvBBL382+Y/G1XqrdRSE8wqiNW416s82nuTGCuU U4MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=csGHgfyh; 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 r202si11679618oie.247.2019.12.09.01.04.35; Mon, 09 Dec 2019 01:04:48 -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=csGHgfyh; 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 S1727394AbfLIJDZ (ORCPT + 99 others); Mon, 9 Dec 2019 04:03:25 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43528 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbfLIJDY (ORCPT ); Mon, 9 Dec 2019 04:03:24 -0500 Received: by mail-pg1-f193.google.com with SMTP id b1so6764553pgq.10 for ; Mon, 09 Dec 2019 01:03: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=h04+/kyq65eedtQzdgewP9Eey1SBByTI6ESOC8A2z5w=; b=csGHgfyhplhdKydGgYEkaWlien9YKSWfKoZaDOGlwGTOGsrnVuzI64STLpfsAfpfZ+ nyuPCsgiX5bMi8f8tb2/r0ZesQxRAJiQBhWiyJ6JwOKWq6x0Pbd9yYWuuH/jzObv2/o9 3gkJdkolovWodQCUAPMj6h+mxm9Ot6MyMMh2Lv4duDL01GatJd7ItO3AKUCpryiRuGVF q+WEUJrTguu1sMVymPPrfRFAgDrSatP8T0Ef4JtuTFIXojCIFfY5LWgdY8gQeKhJAS9d SRTI50jAnp5LRk9SGAVhypvtzd/YIlC27Lkno6z1ensTkgyLFpJFbT9H+unnyhXexgW4 PzRQ== 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=h04+/kyq65eedtQzdgewP9Eey1SBByTI6ESOC8A2z5w=; b=d61mB3ZZ0aeSSgJJsvJ2pKlz9FI+21fe0m2y+cfe4cIY4D0JeDMUvsEONh+jTHibbf Q+Iov49WET+MpsQGGxY62cNdF6ESI8318S0e0n31ArJshBPzVI+eaVfjpfFIe13+aDkI p4zxQiQV+tGKdEGX8IpI3fAkypXtmC0hRlufrYV6wEDArggAy67hXTd7TFzklRmzwVUm 6jQoGdmmWgOIyczYOOUa/lajeuGq/G1TI/0bZMA9oqFKOukfDzxZXWT3ik8SwH2ZsSKG I477LHpAbobYFzQjLFK51FgeASoJ0uodRBGLV77o0nq+l1mF3ljsbR0t0nC4ZIS0ljpF KBBA== X-Gm-Message-State: APjAAAWuafE7zfkDKRlKa67esHpF6wtpWVtiW0pXdRMXBn56tmXJfBpk ECIK9tBC+qJuLEm3lz2Tix0= X-Received: by 2002:a63:1a22:: with SMTP id a34mr16682023pga.403.1575882204085; Mon, 09 Dec 2019 01:03:24 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id i4sm24552332pgc.51.2019.12.09.01.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 01:03:23 -0800 (PST) Date: Mon, 9 Dec 2019 18:03:21 +0900 From: Sergey Senozhatsky To: Sergey Senozhatsky Cc: John Ogness , linux-kernel@vger.kernel.org, Peter Zijlstra , Petr Mladek , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky , Brendan Higgins , kexec@lists.infradead.org Subject: Re: [RFC PATCH v5 2/3] printk-rb: new printk ringbuffer implementation (reader) Message-ID: <20191209090321.GF88619@google.com> References: <20191128015235.12940-1-john.ogness@linutronix.de> <20191128015235.12940-3-john.ogness@linutronix.de> <20191209084300.GD88619@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191209084300.GD88619@google.com> 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/09 17:43), Sergey Senozhatsky wrote: > > +static int desc_read_committed(struct prb_desc_ring *desc_ring, u32 id, > > + u64 seq, struct prb_desc *desc) > > +{ > > + enum desc_state d_state; > > + > > + d_state = desc_read(desc_ring, id, desc); > > + if (desc->info.seq != seq) > > + return -EINVAL; > > + else if (d_state == desc_reusable) > > + return -ENOENT; > > + else if (d_state != desc_committed) > > + return -EINVAL; > > + > > + return 0; > > +} > > + > > +/* > > + * Copy the ringbuffer data from the record with @seq to the provided > > + * @r buffer. On success, 0 is returned. > > + * > > + * See desc_read_committed() for error return values. > > + */ > > +static int prb_read(struct printk_ringbuffer *rb, u64 seq, > > + struct printk_record *r) > > +{ > > + struct prb_desc_ring *desc_ring = &rb->desc_ring; > > + struct prb_desc *rdesc = to_desc(desc_ring, seq); > > + atomic_t *state_var = &rdesc->state_var; > > + struct prb_desc desc; > > + int err; > > + u32 id; > > + > > + /* Get a reliable local copy of the descriptor and check validity. */ > > + id = DESC_ID(atomic_read(state_var)); > > + err = desc_read_committed(desc_ring, id, seq, &desc); > > + if (err) > > + return err; > > + > > + /* If requested, copy meta data. */ > > + if (r->info) > > + memcpy(r->info, &desc.info, sizeof(*(r->info))); > > I wonder if those WARN_ON-s will trigger false positive sometimes. > > A theoretical case. > > What if reader gets preempted/interrupted in the middle of > desc_read_committed()->desc_read()->memcpy(). The context which interrupts > the reader recycles the descriptor and pushes new data. Suppose that > reader was interrupted right after it copied ->info.seq and ->info.text_len. > So the first desc_read_committed() will pass - we have matching ->seq > and committed state. copy_data(), however, most likely, will generate > WARNs. The final desc_read_committed() will notice that local copy > of desc was in non-consistent state and everything is fine, but we have > WARNs in the log buffer now. Hmm. No, that won't happen. We should get desc_miss first, and then -EINVAL. -ss