Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1935341pxu; Sun, 6 Dec 2020 12:29:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyD5BtXh4w+DBjlgGYOR4mh8jz0+lPHaBonhFrtW5kPLXgkB7O30KjORy9IBs3m+0LiJaW8 X-Received: by 2002:a17:906:7f11:: with SMTP id d17mr16407783ejr.534.1607286541568; Sun, 06 Dec 2020 12:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607286541; cv=none; d=google.com; s=arc-20160816; b=xSfF5OyFsfAPoHB69MGbE+oINvQSs3MaAQ25QTZRK1Z8i0CN4th4DWvObEhgWyaeu/ PeUU7X/D6izpqLPUwQ7+Z0fGXBBWD5VJ40XXtlt5dQnVTiHxt5tSuYq/1ivycZh/oeUN UfuWKlO/nWt5U1RWvqdLfkh9XnQNSVEAJP4j0Tk11/C2suIm4cWvgC5sZUzC+mzFJhxw PixzsNDE32LgwvABUdewDOQyENptY4ZcG5mCPpYm9GO98FfTkWMgecGUF9SRcV4MHZ55 inNWmFViY5JQxv2OkjqRIdT+/Xq1PExfZamSYYYB+WUM2SI7on6v+/J2HQbpQZpY4eW2 0vHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=JTrbLxSVsa+AJjMwFCvM3YrglsqeqmRd6O81SfPFnrY=; b=ka2+yIV20O1CYDMjjVx1gFwddEKAAR4QBLH8+YVRSeahEXfJXwR4eVJxPEz2yOY9jz UcbEe6LIw27oyXE/8iXMkYRdYVLzH5VXG5nwmrUM/i6Tyeczccldf6VvNYfOxaE4Yn/E ZUek37Hg7ZYU8zs0UjIEBTkL0TVWooARcDTXthkQgi4zCNwtpHEp5Azd/VBunWH0oHSB GR2EyGE0VC9nYFqUmaYmx/tbO6QKuBTs1jalEBJxrWhylqJgR2BITHmZzBOTJnZqoDW5 B84+Bxc7oECfbdnDnwxy7coHm68kq+DblGzd53UqSvvG6lKCckuw4ExEObSUKpUoCKrT WFwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D762acnc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SqDCGd2g; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si7007002edi.388.2020.12.06.12.28.38; Sun, 06 Dec 2020 12:29:01 -0800 (PST) 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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D762acnc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SqDCGd2g; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727427AbgLFUYm (ORCPT + 99 others); Sun, 6 Dec 2020 15:24:42 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:59934 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726731AbgLFUYm (ORCPT ); Sun, 6 Dec 2020 15:24:42 -0500 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1607286240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JTrbLxSVsa+AJjMwFCvM3YrglsqeqmRd6O81SfPFnrY=; b=D762acncMNFT4eJbtzjA0Nb0CFGslfEYsX7pbMjZ87qVVBpH1SgenykDfkBbkhEFO3eY7C SnGggmLVnd2Z24lgJv/bsjYFX2CCHZruFYHnrfc4wk+WksBh4WPc/3xWJ3VfF+E1wDJUfT 1siFxsqaV7zuyftTCOxLHwyxX5qMyTVkcyZbOD724ecSwtT1pJUgjO98uB+khyPvuWz+JV iNQ/cCDTFDnSV3tJPvxEWlzd1xbWel4/IFZjwExVxom2MInIdKx0tR3pyaIY2isoXZV2lF hXi9vUvUMSfNMgFYtIXZdNiZmbP0VtYp0SJWdl1GfIbbeVT4XU92XMox64hyUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1607286240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JTrbLxSVsa+AJjMwFCvM3YrglsqeqmRd6O81SfPFnrY=; b=SqDCGd2gx88hR2ztINUYQhOdlUxxSr+Z1zTtv5YFOmH0xbqz7l0EyNueCpiPBjl9a0p17z lYTnkcTsAk+AXDCg== To: Petr Mladek Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH next v2 2/3] printk: change @clear_seq to atomic64_t In-Reply-To: References: <20201201205341.3871-1-john.ogness@linutronix.de> <20201201205341.3871-3-john.ogness@linutronix.de> Date: Sun, 06 Dec 2020 21:29:59 +0106 Message-ID: <875z5eof8g.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-12-04, Petr Mladek wrote: > On Tue 2020-12-01 21:59:40, John Ogness wrote: >> Currently @clear_seq access is protected by @logbuf_lock. Once >> @logbuf_lock is removed some other form of synchronization will be >> required. Change the type of @clear_seq to atomic64_t to provide the >> synchronization. >> >> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c >> index fc5e3a7d6d89..e9018c4e1b66 100644 >> --- a/kernel/printk/printk.c >> +++ b/kernel/printk/printk.c >> @@ -3412,7 +3418,7 @@ EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer); >> */ >> void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper) >> { >> - dumper->cur_seq = clear_seq; >> + dumper->cur_seq = atomic64_read(&clear_seq); > > Sigh, atomic64_read() uses a spin lock in the generic implementation > that is used on some architectures. > > Hmm, this seems to be the only location where the lock must not be > used. Yes, and it is read-only access. Perhaps atomic64_t is the wrong thing to use here. We could use a seqcount_latch and a shadow variable so that if a writer has been preempted, we can use the previous value. (Only kmsg_dump would need to use the lockless variant to read the value.) void clear_seq_set(u64 val) { spin_lock_irq(&clear_lock); raw_write_seqcount_latch(&clear_latch); clear_seq[0] = val; raw_write_seqcount_latch(&clear_latch); clear_seq[1] = val; spin_unlock_irq(&clear_lock); } u64 clear_seq_get_nolock(void) { unsigned int seq, idx; u64 val; do { seq = raw_read_seqcount_latch(&clear_latch); idx = seq & 0x1; val = clear_seq[idx]; } while (read_seqcount_latch_retry(&clear_latch, seq)); return val; } u64 clear_seq_get(void) { u64 val; spin_lock_irq(&clear_lock); val = clear_seq[0]; spin_unlock_irq(&clear_lock); return val; } > Alternative solution would to always fallback to the first_seq on > these architectures. Few people would complain when they see more > messages. We could always improve it when it causes problems. I am also OK with this solution. John Ogness