Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3049343lqo; Tue, 21 May 2024 05:37:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUXDqheZchQbAG+u2XoRS8e4J3MobaYbDZ0NwjIEp6FDzpqNPS7YTq76QF7t/nNb1f2Ed+45g9pPDc9HUzTgJBgqYDcnfiuCtAsFq/d3Q== X-Google-Smtp-Source: AGHT+IHjPEuGjTvhVToGDVhSXaFTpo4S3zMBJLZu16H7IGNG9Xx15D80YsuJzJAhreDwS4nNQK4f X-Received: by 2002:a05:620a:a14:b0:792:c0af:dda1 with SMTP id af79cd13be357-792c75abf30mr3191495485a.32.1716295058359; Tue, 21 May 2024 05:37:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716295058; cv=pass; d=google.com; s=arc-20160816; b=hCLvmP3+epS5aYOPaUKtak7PoBl8s1gk2ndlisu/rM/qFiTru7F4ca0OwrWRP/cbFM CSAYhGliymc2gc8uAgAmQWx95Q4JEwMipc7DivjY1+u2CBTs08NusOlYdLx4NrzAA5CY aycx/L5JOb6STpGIjnZO3FsMNeKtMh1We4G14i8+e7XIxRENtJ0U5SP8jlze3uxyPSAE BDL6qSCuUmQLHvFQNupHb072GurJIYcoVPUzGFjArCfXdiza+JrJbA7yCWIbP97cJ1kE 5ty45GpwP99/8JCRPUN/2VquEE0cmVkDXNlrWzc5T7P+oUKIiaC+QmjhP0MOpNAT2Nlu D0jA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CkFOGlpOKeStDNfuqkdG9T+khvpIoGQQxktttnrUnLI=; fh=3/jSAarQGQa/01hSAcOTcsGEuNBGom1gEEMchvzBT94=; b=X3PQj3nR1rLsFwUe6dcPdFxbCNNywi+oD6n5uHK1UtXC4hCyLX7576JExTXa81Lf/g YsEq8wvzorkTyc82FFW5+tMlminCEeysF3+lz318yi1ne5xYcumeG2H4zDchzxu9NfIJ bAqSO65w+YBT43Td4ltqOtQxEBK2GgEc5e1KjC0NWuq7nmjhW07T6RERQw0QAfDsm7Hi vwkF4gDwYv6gvDhZZ2I+K8KXOF1VOK44PH3yBfARKZ4ukt7KxTtCNo4J4SbdfZhgVu5m DB0rHiMz4ukzGw7LO7PuKjxRGs6yL42m49dsPGRPDXnCmXZ7+2E5vMTDQwlIeX9ZrOKR Sk2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=BTUbSOeb; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-184956-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-79300c47953si1365268985a.491.2024.05.21.05.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 05:37:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184956-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=BTUbSOeb; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-184956-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0D3E61C217B1 for ; Tue, 21 May 2024 12:37:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF568762F7; Tue, 21 May 2024 12:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="BTUbSOeb" Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C05E28E7 for ; Tue, 21 May 2024 12:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716295034; cv=none; b=U/T30SDn+nip9Jw+TuNVSf+pVT+UWdIeS9qkaWupI+IQwvm7mLU74kfLgCF+MOq1fhsanZwpT5Vlb5P3Hxu5nfMQ6YYyMkz3cX9iJQaOeuvMTNmJjm6dG9JIB9SYpaDvfvMZr3J85Z+qPZzdErxnqOhfKQZ2YAR8BoW3G5jLaaY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716295034; c=relaxed/simple; bh=Klu0gGVfZMfblIpCTCUXJjJGPJyTfcM5cThq4DA/HRk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f2OHoktFUCQTeTUgzBr1d4kJLHkELWPnm7qqNJyXNmrikPyqhf5RU/LCVIzSRK7895K0pjPMcL1SI5pZMpWLTo0sFAVIiLC6SPhx1EtFpy2mdqXOBmpMvCB/mbB4wKs2Dn21kGLPfyAgBrmfBX8rlvXdPoUrKkr8mA/vmKKPwK4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=BTUbSOeb; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a59a352bbd9so1210194466b.1 for ; Tue, 21 May 2024 05:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1716295031; x=1716899831; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=CkFOGlpOKeStDNfuqkdG9T+khvpIoGQQxktttnrUnLI=; b=BTUbSOebTd+Sqv0Yc+PlFN9xQgdX0wWyVjDpkC3PjB41FRA9a5dJbwIlgDGVCGiU72 X3OYXqL1DQ8SW4AmjjDTW4yuv5fDr4x+jP0xTB5nA2j3hvNA01YbKEqVE81bIEmwXXwj mwbjjHTy4HVc3L9OLQyVOHa9HYbByTDu3q1yfSvGYNGT1Rs1VGeyjTHZOcOMchZnR8yO 6JPy1vcgbWQgLl5LfSAONhdSSCblhIVXYbgXUKCHvCOqjjezbPOGNRQpKHWZTs4rU90H NnoVkQGkXQEFGU287joUyQ33OyxBBnxtXUuVuEWf3QTDmmGpDwL2H4Ciju9IkHCW5ETt JMlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716295031; x=1716899831; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CkFOGlpOKeStDNfuqkdG9T+khvpIoGQQxktttnrUnLI=; b=i+/jrIsICf1aWJwZ9SBpFsxxgRcrJN5hvAG63SmASrRTKY6/Rxur5YqpUJD1j6jvt9 NiVkwozZEeC7zHa/MxapN/kRgk3U7G+qjrtvbdQW+8T1VdazjvHx3LKrHX79U+YBmQ+Z hCci1jGYCSYoJ10t1pAgx2tHsKQIfhJXjNKL2IfAm8NoHEZMmPs1leIt1nYg50ikOwRY zzJpbG1VW1LxYzFnnIMQ3XZ5AcfwVfs2bnN0d41m1SU8R/0ftvYUAY8C6DjmeLDMSeNr PjZexmcAaGDrddaYY15b0//FRYZxJ1ugbU6vuFe8FD4o637LznsZL837ni5k8ot+CmHN NIUg== X-Forwarded-Encrypted: i=1; AJvYcCVbFOA5zT8yRWDw7Qv9nOG32R8wFCAY5N2XyQrZCxQUam7JWObEwJJ8ZSepk7UbzjW9jeZm4Gc4PzwNVPH435zGVC/BEoW/CiBi583R X-Gm-Message-State: AOJu0YxiugzHRAcFj7faUu2i7AJfupsOvRT8Why2sc9pjv9raDbgKb7I S/Lr7JxTaJUuch23CSV8VUncPVRGlwOYXY9dpxuIuiQnmpVF4cFgp9KHvKNaafM= X-Received: by 2002:a17:906:a05a:b0:a59:a7ea:dd22 with SMTP id a640c23a62f3a-a5d5a376cb2mr762273666b.14.1716295030667; Tue, 21 May 2024 05:37:10 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a5c033afasm1263036866b.156.2024.05.21.05.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 05:37:10 -0700 (PDT) Date: Tue, 21 May 2024 14:37:08 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH printk v5 26/30] printk: nbcon: Implement emergency sections Message-ID: References: <20240502213839.376636-1-john.ogness@linutronix.de> <20240502213839.376636-27-john.ogness@linutronix.de> <87h6fbi5q8.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; charset=us-ascii Content-Disposition: inline In-Reply-To: <87h6fbi5q8.fsf@jogness.linutronix.de> On Mon 2024-05-06 12:45:59, John Ogness wrote: > On 2024-05-02, John Ogness wrote: > > diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c > > index 8f6b3858ab27..991e2702915c 100644 > > --- a/kernel/printk/nbcon.c > > +++ b/kernel/printk/nbcon.c > > +void nbcon_cpu_emergency_exit(void) > > +{ > > + unsigned int *cpu_emergency_nesting; > > + bool do_trigger_flush = false; > > + > > + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); > > + > > + /* > > + * Flush the messages before enabling preemtion to see them ASAP. > > + * > > + * Reduce the risk of potential softlockup by using the > > + * flush_pending() variant which ignores messages added later. It is > > + * called before decrementing the counter so that the printing context > > + * for the emergency messages is NBCON_PRIO_EMERGENCY. > > + */ > > + if (*cpu_emergency_nesting == 1) { > > + nbcon_atomic_flush_pending(); > > + do_trigger_flush = true; > > + } > > + > > + (*cpu_emergency_nesting)--; > > + > > + if (WARN_ON_ONCE(*cpu_emergency_nesting < 0)) > > + *cpu_emergency_nesting = 0; > > I see two issues here. First, this is unsigned. kernel test robot > reported: > > > kernel/printk/nbcon.c:1540 nbcon_cpu_emergency_exit() warn: unsigned > > '*cpu_emergency_nesting' is never less than zero. > > Also, in this situation, we are allowing a brief window of activated > emergency mode by allowing it to become !0 before correcting > it. Instead, we should avoid illegally decrementing. I suggest: Great catch! > void nbcon_cpu_emergency_exit(void) > { > unsigned int *cpu_emergency_nesting; > bool do_trigger_flush = false; > > cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); > > /* > * Flush the messages before enabling preemtion to see them ASAP. > * > * Reduce the risk of potential softlockup by using the > * flush_pending() variant which ignores messages added later. It is > * called before decrementing the counter so that the printing context > * for the emergency messages is NBCON_PRIO_EMERGENCY. > */ > if (*cpu_emergency_nesting == 1) { > nbcon_atomic_flush_pending(); > do_trigger_flush = true; > } > > if (!WARN_ON_ONCE(*cpu_emergency_nesting == 0)) > (*cpu_emergency_nesting)--; Looks good. > preempt_enable(); > > if (do_trigger_flush) > printk_trigger_flush(); > } Best Regards, Petr