Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp655472rdb; Mon, 15 Jan 2024 09:09:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEW+iowRNzSdKJCo4/VSVQ5IGUVDY2Nvt+2qDilR9KBcok70DcA968b/neygcLUao5kRDl X-Received: by 2002:a17:902:d501:b0:1d5:8bce:2ba4 with SMTP id b1-20020a170902d50100b001d58bce2ba4mr3477666plg.119.1705338556168; Mon, 15 Jan 2024 09:09:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705338556; cv=none; d=google.com; s=arc-20160816; b=olf3Jw4EKfhPzRSioPHz9WknA4e8AVF/ILCzIeX1S7Ba8muD8ZjoQkSbzjrxDKMBV0 UyRg31b/RGQJJRxwz5D+d/qaj8A0JlDxsV2SHRFci6XRKkw0IPHob+7x/rsz/IW1kKod ujf48XtH6vWs/IHnqCySqjpCpbZdF9EpsKtHLYIk8MfLe0wbmPJ4LRuzCbtPjklLhEnu SAK02bdtlErlb+7E4cWYeHvzb5Z19JkeWuKLE/ZI613urdamwq/MzCx3DcwJCZqGCbHX cH/bx9fHZAMXTXBz5Rxa0jKLozZaYysk/KrIzdoGsyfeRxNofqm8CbVX27JEFtMTbGo9 p12Q== 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=zI9aOA5pFU1a8/3o2IH5nyS4T+dQsL0rAjim+dM8zO8=; fh=FsZvNuK0qXzIHpKngach73/EWdkC91/zDh9w34lnxX4=; b=kKPiBmK5ge47vcYuKSWilFNEmn5ME3wXUB8G7GpC5m913evC7WOZ9P//hBjbLunaVD nRpbeoTHRqLCNClBUf6js6yRWKyq23BmI31Lv3lVUgviN8cU2WYg77pNkC9lTz35gXHT SMJSSB8pNFwQWzr7oOkeCJ3qaC5g7NVNbpn5WGCYDV+XUkox/2DwmBqOnzgVLWGY0FiZ MPOpLFdqpVPx2wOSik/ewJAJZiZoqqu7xtcmY3uc+YMNVmEXoykXNTGDNyBye69kCD7Z 1cR991vKoWQdV1Mk0pIkmHDGlSGn76YXL8v0TIjLSVIiN2YFLiyx220OM/tWTgfy9m52 peYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IvsNTlqI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-26292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26292-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 b9-20020a170902d50900b001d43ebbd741si10031337plg.387.2024.01.15.09.09.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 09:09:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26292-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=IvsNTlqI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-26292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26292-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 20C202830B3 for ; Mon, 15 Jan 2024 17:09:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3AC018625; Mon, 15 Jan 2024 17:08:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IvsNTlqI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5tGferVp" 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 4A0371804A for ; Mon, 15 Jan 2024 17:08:36 +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=1705338509; 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=zI9aOA5pFU1a8/3o2IH5nyS4T+dQsL0rAjim+dM8zO8=; b=IvsNTlqI5vHFY6RPku5rZbLyYhDqZT+z6SqVjp51zkwn0rW6zExuu4xxclfJmwDKUDzJnS TFVvEZfU7Qngf1Lrvv9gEFmxc0FiqG/XlCCRZ2ZHlvhNjYwwl8ccX20Fsw3UB/0s/ajpN+ LAcSCPTDHljriPPKj9DwHHHzBTQtSKvNsWRXDsPXsgH2ZvpZrPkLG4f6IIovis6zvfsqI+ k2gaOdbS8AXhbs8HFJJEf0DCeYgvuEvBl6OcIo0inyvFsspRaUp1+Qeg0HmkZTX2Ir6OAM r0CEZhi3TKq2b79IP5NKoPduvWXbra8Hdq2lHH3hg4RDjMtmyaYUeXLDSuYrkw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705338509; 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=zI9aOA5pFU1a8/3o2IH5nyS4T+dQsL0rAjim+dM8zO8=; b=5tGferVpSF9AFa/KVdSYMQ5zcf7+pYzj8oAMzX5djeCRBV9gdlXDR6Dn0+zrRZA78d2PA3 etbrMaX1SxzZZdCA== 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> <87a5p6g96w.fsf@jogness.linutronix.de> Date: Mon, 15 Jan 2024 18:14:26 +0106 Message-ID: <87ttneed85.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-15, Petr Mladek wrote: > You know, the code around reading the messages is getting more > and more complex. Also the u32 -> u64 transition is not 100% safe. > So some sanity checks might be useful. This complexity only exists for 32bit systems, but yeah, it is still important. > That said, I do not see any obvious trivial one. Just the following > came to my mind. prb_first_seq() is reliable and we could do: > > void next_seq_sanity_check(struct printk_ringbuffer *rb, u64 next_seq) > { > struct prb_desc_ring *desc_ring = &rb->desc_ring; > u64 first_seq = prb_first_seq(rb); > u64 desc_count = DESC_COUNT(&rb->desc_ring)). > > WARN_ONCE(seq > first_seq + DESC_COUNT(desc_ring)); > } @seq is allowed to be 2^31 before or after @first_seq. The check would look more like this: WARN_ONCE((rb_first_seq < 0xffffffff80000000 && seq > rb_first_seq + 0x80000000) || (rb_first_seq > 0x80000000 && seq < rb_first_seq - 0x80000000)); > Well, I am not sure if it is worth it. Also the WARN() won't be > printed on consoles when the reading is broken. Broken printing is irrelevant. There are plenty of debug methods to get at the ringbuffer. I am OK with adding this sanity check (again, only for 32bit, within __ulseq_to_u64seq()). John