Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp454663rdb; Mon, 15 Jan 2024 02:52:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoMWJPDEuEcXfKki71fGm9JTvsuV/+8NevSFOdSS1A9Tyr+sBvVIq9SFSA55U822V13SVH X-Received: by 2002:a17:903:2990:b0:1d4:d5bb:5d7c with SMTP id lm16-20020a170903299000b001d4d5bb5d7cmr7075260plb.110.1705315978415; Mon, 15 Jan 2024 02:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705315978; cv=none; d=google.com; s=arc-20160816; b=dkJITLHCFuqy9WfLnKHz6PTcrGstwKXaLaxh7TggRbTu/1rd6zLmG1rXs8nJby7K2C hP+eeZPfHOG8eZlXZfCX4G6qbQaIhhAlRsySkLisC4LAPS9ymWCzQP3HnHrz+tPkJj+t K59Rgkjz/YQ5y+BqahSS+bcMR7/AEBSAcIh4urwrN0M1Kr1nVMbYKRr+rudu1YVplpJi vVz5LIFtWx8w8Fo7LnQemR7f80IflYIw6XLV7bX0PWh6+qch2qf8yyj/T2BjfJz6BZ+1 f66zhEiTFOJtJ6ZERbNGBnhpwFP7ewy4C8UzNC3pmzAVM0JQK3Ju/OUVhifH1LFPFosq hgtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=HOIq5xrrcKDhjWifKtOBpW3KDRCmGoSMcl/b7n5dGtg=; fh=FsZvNuK0qXzIHpKngach73/EWdkC91/zDh9w34lnxX4=; b=f3z7D1IjpBWziptJtNPLtTxI3sAySyKKjxXJPLrxbAR7NjLc0vWkKe+H9YlrVqaIBx IGrMgBLhdkkRYaGjj6epdgeQFD2eEucHX/vRcOe6AX55w4K8d/IO3OlCsszZUkFLUHi4 P7tW4XXYCWpGFF27S8BLqfzk/36oq9ASjgmUCEf/ZXWBw1ytCi8aAB6aoq/oxhG1+cpo yEqT6AGKHXetzd8a3jpjsGwsimNSgv7XSSf5ErHeXaOTxsz+anjqShvokLRkdi2dImph VXfUdbeF43MGLQnYwmhYnWfAUf9hXRj9fUQ9t5B8UsRN7FCRp3LIWlAeYOY0d2pQatU2 yzFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="e7/UXl9L"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-25903-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jx5-20020a170903138500b001d3ce203f74si8348698plb.6.2024.01.15.02.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25903-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="e7/UXl9L"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-25903-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0A9B72823A2 for ; Mon, 15 Jan 2024 10:52:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB4991E86D; Mon, 15 Jan 2024 10:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="e7/UXl9L"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mVhAO0jw" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C4631E863 for ; Mon, 15 Jan 2024 10:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1705315960; 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=HOIq5xrrcKDhjWifKtOBpW3KDRCmGoSMcl/b7n5dGtg=; b=e7/UXl9LlTdR8h22ZKKRUQ2CnDreqpzpfv3mUAkWAvxaRkGZlCjS4O1G6nVusitg+as/oV sGyZmjVONlSQA70++6o3jd8cbbzFxgK3L+7JjXV6Wzcp57qH46TSotL3prXdmC2gA5wPiX wa3j/RQv7kocTJGVs5E+A//pmZ88qzcViRaOQ1wn+vyVAd2QDAiIJaMoRjk0yPa6Xx30t6 JysBa4EPR9kwYq7czFYJMDppWbMAoY/BcoCtoLBBMA6e2CNN4a5N9cGvZz/FomipcHa6L1 3+YE+HCYkBb2SJoW2cnq5hTrsfELnmYKoGbIvPC4cyYH5WQN7MBxlGx0O0vy3g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705315960; 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=HOIq5xrrcKDhjWifKtOBpW3KDRCmGoSMcl/b7n5dGtg=; b=mVhAO0jw13hGl0fB4LX37BblU6LQPc1BgdXFtOXdf5oAy3Hq9rwqyEfZgupvKEP5Vri08+ /UArINe+0bw1tHCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Francesco Dolcini , kernel test robot , Sebastian Andrzej Siewior Subject: Re: [PATCH printk v3 02/14] printk: Adjust mapping for 32bit seq macros In-Reply-To: References: <20231214214201.499426-1-john.ogness@linutronix.de> <20231214214201.499426-3-john.ogness@linutronix.de> Date: Mon, 15 Jan 2024 11:58:39 +0106 Message-ID: <87a5p6g96w.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2024-01-12, Petr Mladek wrote: >> > Reported-by: Francesco Dolcini >> > Reported-by: kernel test robot >> > Closes: https://lore.kernel.org/oe-lkp/202311171611.78d41dbe-oliver.sang@intel.com >> > Reported-by: kernel test robot >> > Closes: https://lore.kernel.org/oe-lkp/202311161555.3ee16fc9-oliver.sang@intel.com >> > Signed-off-by: Sebastian Andrzej Siewior >> > Signed-off-by: John Ogness >> >> Great catch! It must have been complicated to debug this. >> >> Reviewed-by: Petr Mladek > > That said, I am a bit nervous that a bug like this might cause > workqueue stall and panic() the kernel. > > At least, this is how I read > https://lore.kernel.org/oe-lkp/202311171611.78d41dbe-oliver.sang@intel.com/ Note that the bug is reported for code that mainline will never have. This patch "fixes" the problem before it is a problem. From the perspective of mainline, the problem never existed. Perhaps it is inappropriate to list these with the Closes tag. > It looks like it caused some loop and refcout overlow or so. > But I might be wrong. > > I would like to better understand this and check if we could prevent > it somehow. The code in question can be found here: https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/tree/kernel/printk/printk_ringbuffer.c?id=768c33033e41ad195a9304ebb183afb730d5ae98#n2031 The URL above points to prb_next_reserve_seq(), which is in an infinite loop. desc_last_finalized_seq() is returning a huge garbage value due to the 32bit sequence value 1 being incorrectly mapped to 0xffffffff00000001 (which is 18446744069414584321). When desc_read_finalized_seq() is called (line 2082), it obviously returns -EINVAL because there is no record with this huge sequence number. The code interrupts -EINVAL to mean that the record has been overwritten, and so it tries again with an updated last finalized sequence number => infinite loop. With this patch applied, the 32bit value 1 is correctly mapped to sequence number 1 and all is OK. The problem was that desc_last_finalized_seq() returned a sequence number that was higher than the highest record. That was the bug. As long as desc_last_finalized_seq() always returns a sequence number that exists or used to exist, the retry loop is fine. And since the tail record is always in the finalized state, there will always be a finalized record available. John