Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp192880pxa; Wed, 26 Aug 2020 08:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9fdSQOUo5R9KuPwnmRjjYBayn8KyzM0JzJtdFVkzdkFMWAVOJY1MNxgRmKN3Gf3qhjefr X-Received: by 2002:a17:906:3890:: with SMTP id q16mr15883712ejd.107.1598454638661; Wed, 26 Aug 2020 08:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598454638; cv=none; d=google.com; s=arc-20160816; b=UbauZAEOghVx/z+jCe4poCLAMaU/h+QWxxY2CtZmu+iu+Qiko9xSC1woXVhBy1G8wi OPVKz7tsHxwfTcYA03nszAg+wN+zeXqjDPEqLoOFGyDLMlNXyNrUnGPG44wW9sNpqHL6 lKFw1Y61v8UI/FRmDl5lXkY0DpMUdBchRMAAp8bMbhSPa9fzJ+nmpuCgJ1BNYkiS0ho6 GlYor3oK9FxGx/UfD/SdAMekF43YMPRiACQMc7y9hlAB8FDVENbJD3JUnWu7CdrKcroQ ccGudcIdnJhR1+3xaJ8UqyWb6xYrwoDrsxwsZCFvl1hLb5S9QAgQdZCyZCeuvCrzT7uN j9GQ== 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; bh=35jMjPNW6lXBCT3rwWR1AOVEy8JTEnx2di8yBNmVU3Q=; b=r2uk72s7glqcwI7b1JqxriaD7xawkUsMxel8CrQmp6g8I6+jIauM3LHIijkkERXd4g X9Bd+oCcewGjgKKd6v02W3MbpndEl9zdYeHk//BDxOwj/6RM8Ei7Am/LszoBtrwLShLN 85g5GUoR7FwSG4FOSL+A10A8Am57zXhvrSensMD/aDIkovO3UHO622D3crQFPnxhieie iyE2nwXEm068fyXdLQyl3F7m4JNZ+hq91DdD38Hi4NQp4V3vcTAGmYTyf0fBLqKa90Km GrT1AEGcmEyW0XpiM5oi4grmhtcZXZZmOrl2V/8BOxhfjpgm0IBLdu9E5fEN6ZjavqNW 1XkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si466338eja.139.2020.08.26.08.10.16; Wed, 26 Aug 2020 08:10:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbgHZPHb (ORCPT + 99 others); Wed, 26 Aug 2020 11:07:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:45834 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbgHZPH3 (ORCPT ); Wed, 26 Aug 2020 11:07:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4F4F5ACAF; Wed, 26 Aug 2020 15:07:59 +0000 (UTC) Date: Wed, 26 Aug 2020 17:07:27 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , Peter Zijlstra , Andrea Parri , Paul McKenney , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 5/7][next] printk: ringbuffer: add finalization/extension support Message-ID: <20200826150726.GA4928@alley> References: <20200824103538.31446-1-john.ogness@linutronix.de> <20200824103538.31446-6-john.ogness@linutronix.de> <87lfi1ls2g.fsf@jogness.linutronix.de> <20200826100113.GA8849@jagdpanzerIV.localdomain> <87eentlh19.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eentlh19.fsf@jogness.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 Wed 2020-08-26 14:43:22, John Ogness wrote: > On 2020-08-26, Sergey Senozhatsky wrote: > >>> @@ -1157,6 +1431,14 @@ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, > >>> goto fail; > >>> } > >>> > >>> + /* > >>> + * New data is about to be reserved. Once that happens, previous > >>> + * descriptors are no longer able to be extended. Finalize the > >>> + * previous descriptor now so that it can be made available to > >>> + * readers (when committed). > >>> + */ > >>> + desc_finalize(desc_ring, DESC_ID(id - 1)); > >>> + > >>> d = to_desc(desc_ring, id); > >>> > >>> /* > >> > >> Apparently this is not enough to guarantee that past descriptors are > >> finalized. I am able to reproduce a scenario where the finalization > >> of a certain descriptor never happens. That leaves the descriptor > >> permanently in the reserved queried state, which prevents any new > >> records from being created. I am investigating. > > > > Good to know. I also run into problems: > > - broken dmesg (and broken journalctl -f /dev/kmsg poll) and broken > > syslog read > > > > $ strace dmesg > > > > ... > > openat(AT_FDCWD, "/dev/kmsg", O_RDONLY|O_NONBLOCK) = 3 > > lseek(3, 0, SEEK_DATA) = 0 > > read(3, 0x55dda8c240a8, 8191) = -1 EAGAIN (Resource temporarily unavailable) > > close(3) = 0 > > syslog(10 /* SYSLOG_ACTION_SIZE_BUFFER */) = 524288 > > mmap(NULL, 528384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f43ea847000 > > syslog(3 /* SYSLOG_ACTION_READ_ALL */, "", 524296) = 0 > > Yes, this a consequence of the problem. The tail is in the reserved > queried state, so readers will not advance beyond it. > > This series makes a very naive assumption that the previous descriptor > is either in the reserved or committed queried states. The fact is, it > can be in any of the 4 queried states. Adding support for finalization > of all the states then gets quite complex, since any state transition > (cmpxchg) may have to deal with an unexpected FINAL flag. > > The ringbuffer was designed so that descriptors are completely > self-contained. So adding logic where an action on one descriptor should > affect another descriptor is far more complex than I initially expected. > > Keep in mind the finalization concept satisfies 3 things: > > - denote if a record can be extended (i.e. transition back to reserved) > - denote if a reader may read the record > - denote if a writer may recycle a record > > I have not yet given up on the idea of finalization (particularly > because it allows mainline LOG_CONT behavior to be preserved locklessy), In each case, we need to finalize the descriptor also in prb_commit() when the descriptor is not longer the last reserved one. It has to be done in two steps to avoid race: prb_commit() + set PRB_COMMIT_MASK + check if it is still the last descriptor in the array + set PRB_FINAL_MASK when it is not the last descriptor It should work because prb_reserve() finalizes the previous descriptor after the new one is reserved. As a result: + prb_reserve() should either see PRB_COMMIT_MASK in the previous descriptor and be able to finalize it. + or prb_commit() will see that the head moved and it is not longer the last reserved one. I keep my fingers crossed. Best Regards, Petr PS: I am still in the middle of review. And I had a feeling that this situatuation was not handled.