Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5203322ybl; Tue, 27 Aug 2019 00:42:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNNN8A3t6CuFruzk6GtL1iHo8oaC9ww5k3t5Q9fC8812DoyBtP8kwIFjLgtMy+9qZXSRGp X-Received: by 2002:a17:902:6a:: with SMTP id 97mr23038579pla.5.1566891732824; Tue, 27 Aug 2019 00:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566891732; cv=none; d=google.com; s=arc-20160816; b=jEZyLPJxCpFTgxsJGwPOELK0ZBWm61aBa1WoEN5x1Zfc3iYy4MsPz/dUItl0QQOSMo REDa07FE+AmghYDHX/6CZ8XeM6PdnyRhTvKYLCRPPnavIAxg0pG1dfpw4To1TXf+LGAl mQMU4zp3m76uH859pcuB459MUTgzZFWYp5Nhal+yNGMjhqe5yf0s1kocuPXaZ7//cUBK Cr1aaj7jNdTVBQMqwGqTOxTx+Q5AXPX7SFUbV79t83Y9uA1entVi6u6aqlsw0/9AxFv4 SOjm95xo6yf8D84MHYgTTumFERfgRabGzZfWYvU49oa2/Erb+6tWhqSsMyd74Zi5Qfaw XveA== 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=qDKDX+VE65/FLXn9hXQ39NqHeCljv/sLh9zNHgBib1c=; b=osYtqmIAIeFVbvVvuCUEY5lV2rRlqfjgJTiWKHKOoYDSY4azJ7R4DlDHztMMjNY3DB 9UY7RcTFIQOwV1Pt9ML6T0q0VPRdslUdh2r0eH8o/V6hjrkboov/LyRqJl46onrGJYYW kJaXSA1slKWnoxdhEoPwHJm+UqNf7vXGNQ7DIDSAejRSQI4N7EARXjO/PAxttuOUclsD IKfkRw3RD3T0sxeHmb2Xl1fOfNULzEe978Ps+RCshfBsdSgCE5JdbSinfWZSQ7lvov8s aHlzTPkXNgPuPQt0ugmVHf7zCIxa9Zy4NEGw22p7FeKPoTilnFZNPpQWxSwMdeWA8DEz rDWg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 200si13203774pfu.152.2019.08.27.00.41.56; Tue, 27 Aug 2019 00:42:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727306AbfH0HlD (ORCPT + 99 others); Tue, 27 Aug 2019 03:41:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:45828 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725890AbfH0HlC (ORCPT ); Tue, 27 Aug 2019 03:41:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 25D36AFF2; Tue, 27 Aug 2019 07:41:00 +0000 (UTC) Date: Tue, 27 Aug 2019 09:40:57 +0200 From: Petr Mladek To: John Ogness Cc: Andrea Parri , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Brendan Higgins , Peter Zijlstra , Thomas Gleixner , Linus Torvalds , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: numlist_push() barriers Re: [RFC PATCH v4 1/9] printk-rb: add a new printk ringbuffer implementation Message-ID: <20190827074057.2qybpmvfueub3ztl@pathway.suse.cz> References: <20190807222634.1723-1-john.ogness@linutronix.de> <20190807222634.1723-2-john.ogness@linutronix.de> <20190823092109.doduc36avylm5cds@pathway.suse.cz> <20190823092109.doduc36avylm5cds@pathway.suse.cz> <878srfo8pp.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878srfo8pp.fsf@linutronix.de> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2019-08-27 00:36:18, John Ogness wrote: > Hi Petr, > > AndreaP responded with some explanation (and great links!) on the topic > of READ_ONCE. But I feel like your comments about the WRITE_ONCE were > not addressed. I address that (and your other comments) below... > > On 2019-08-23, Petr Mladek wrote: > >> --- /dev/null > >> +++ b/kernel/printk/numlist.c > >> +/** > >> + * numlist_push() - Add a node to the list and assign it a sequence number. > >> + * > >> + * @nl: The numbered list to push to. > >> + * > >> + * @n: A node to push to the numbered list. > >> + * The node must not already be part of a list. > >> + * > >> + * @id: The ID of the node. > >> + * > >> + * A node is added in two steps: The first step is to make this node the > >> + * head, which causes a following push to add to this node. The second step is > >> + * to update @next_id of the former head node to point to this one, which > >> + * makes this node visible to any task that sees the former head node. > >> + */ > >> +void numlist_push(struct numlist *nl, struct nl_node *n, unsigned long id) > >> +{ [...] > >> + > >> + /* bB: #1 */ > >> + head_id = atomic_long_read(&nl->head_id); > >> + > >> + for (;;) { > >> + /* bC: */ > >> + while (!numlist_read(nl, head_id, &seq, NULL)) { > >> + /* > >> + * @head_id is invalid. Try again with an > >> + * updated value. > >> + */ > >> + > >> + cpu_relax(); > > > > I have got very confused by this. cpu_relax() suggests that this > > cycle is busy waiting until a particular node becomes valid. > > My first though was that it must cause deadlock in NMI when > > the interrupted code is supposed to make the node valid. > > > > But it is the other way. The head is always valid when it is > > added to the list. It might become invalid when another CPU > > moves the head and the old one gets reused. > > > > Anyway, I do not see any reason for cpu_relax() here. > > You are correct. The cpu_relax() should not be there. But there is still > an issue that this could spin hard if the head was recycled and this CPU > does not yet see the new head value. I do not understand this. The head could get reused only after head_id was replaced with the following valid node. The next cycle is done with a new id that should be valid. Of course, the new ID might get reused as well. But then we just repeat the cycle. We have to be able to find a valid head after few cycles. The last valid ID could not get reused because nodes can be removed only if was not the last valid node. > To handle that, and in preparation for my next version, I'm now using a > read_acquire() to load the ID in the node() callback (matching the > set_release() in assign_desc()). This ensures that if numlist_read() > fails, the new head will be visible. I do not understand this either. The above paragraph seems to describe a race. I do not see how it could cause an infinite loop. Best Regards, Petr