Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2369010pxu; Mon, 7 Dec 2020 05:01:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxav/82Qq5+XIKwkG0paHYJqAUFV8G/8+YDCrRRW3/ewSDQkMc3NTyKSnHHRhv1+4TSCZF3 X-Received: by 2002:aa7:c7d8:: with SMTP id o24mr3484861eds.328.1607346101340; Mon, 07 Dec 2020 05:01:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607346101; cv=none; d=google.com; s=arc-20160816; b=v+13Z5DQNo4fKj72UjSUsKbjuBfts0KUJFcI4HpB3DpGACxQwryLP0zxzvHpG9dOTk pMLE4Tk/RwVkWmE/b9b4tjlTwE4WZ395oZVYxmvfVnob8HGnFz2jL4IDnAIGlN3VvMlg JqBTvPTz9WvFtU9HyeNbXsDsup4+qksWVU4pv5zORG1YVQqjKMNUJGcwz4iDlchiYUyj yOEZahnFDZbJhlUZ7dcpOefJrKd32o3g2KAZsOZ/YLl8IiEmRyP+ccpd4nPZWLmOAClw bNpyjSfPu74bCbAkNYzZJeXzuI4dNirEQANiQ9d5wfOmf2pas3LTFgu4pMPIsJlHUtPY sxFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=keFHSMBmtWxbt66sXOQVyjqH1hMokV/Tn2yC85tP24s=; b=lRAVx8trsjOIlITMbPfJfZTafgzdnX8tVnHzHz9KRvtgKkvdGjy5qtN5kkVXToAKGF 2YSLNcVbuPfUF9qW43bCxc5lgkpwezGgl5JE3i+KAIvlOLechcKsQzyFMU9DVnOt6qAp FpDKwCQ/DknSD2p9dwHoCEi5hbnYbOKHUnNrJtlmugHEQ9ukh+/nj7ocq1jyJr3DTNKY Dlcdz8RCkhCF9GvZ+sLcZAeIkx9B5O9+qQWtGj6Iwpn0C2ZN3SpnrYQL4H4ya6W8iyZF jVfpAAGtJi+ulQ0qrl6Pu1eE97ZBlLVC3p90RYO1Qa8eIXJdm3JO7mjTTwDlZbs8/tnT nmXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=F6nQy+bX; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t19si7200623edt.253.2020.12.07.05.01.13; Mon, 07 Dec 2020 05:01:41 -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=@suse.com header.s=susede1 header.b=F6nQy+bX; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726063AbgLGM5d (ORCPT + 99 others); Mon, 7 Dec 2020 07:57:33 -0500 Received: from mx2.suse.de ([195.135.220.15]:52974 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgLGM5d (ORCPT ); Mon, 7 Dec 2020 07:57:33 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1607345806; h=from:from:reply-to: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=keFHSMBmtWxbt66sXOQVyjqH1hMokV/Tn2yC85tP24s=; b=F6nQy+bXVQ4BE3VYT5h+tLvTdFgS6QCNsROXoXqhNA7KXpFtjrYTtQ/WW9mcqDSXeff4KP sDxuQByxbCH00S/F8ZpFMGKlv9sS7r/HkJlAbSJT7vk/qTXRwBoxnUxQ96xpIRLCVhWKxz DHU/BeJrBK5wDzWKVtotC/3v6jhdNhA= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 299A6AB63; Mon, 7 Dec 2020 12:56:46 +0000 (UTC) Date: Mon, 7 Dec 2020 13:56:45 +0100 From: Petr Mladek To: John Ogness Cc: Peter Zijlstra , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH next v2 2/3] printk: change @clear_seq to atomic64_t Message-ID: References: <20201201205341.3871-1-john.ogness@linutronix.de> <20201201205341.3871-3-john.ogness@linutronix.de> <875z5eof8g.fsf@jogness.linutronix.de> <20201207093419.GH3040@hirez.programming.kicks-ass.net> <87mtyq9blw.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87mtyq9blw.fsf@jogness.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2020-12-07 11:09:39, John Ogness wrote: > On 2020-12-07, Peter Zijlstra wrote: > >> 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; > >> } > > > > That's overly complicated. > > > > If you're going to double the storage you can simply do: > > > > > > seq = val > > smp_wmb(); > > seq_copy = val; > > > > vs > > > > do { > > tmp = seq_copy; > > smp_rmb(); > > val = seq; > > } while (val != tmp); > > That will not work. We are talking about a situation where the writer is > preempted. So seq will never equal seq_copy in that situation. I expect > that the seqcount_latch is necessary. Or we could disable interrupts around the writer. But seqcount_latch will actually be need so that it works in panic(). The writer might be on a CPU that has been stopped using NMI. And this code is used by dumpers() that are called during panic(). Sigh, I have to take a coffee and try to really understand the latch code ;-) Best Regards, Petr