Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp182338lqr; Wed, 5 Jun 2024 02:52:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVy8PVSa3gJfm3jUbHtrB//4PgQOCSZ5/gzMmMFl68FrLWczd664KJut4hp12BDAa18wMkjMDPGtFXhrg4vJuEKCJI5Ywg4tanQuNRbag== X-Google-Smtp-Source: AGHT+IEug3hwxOt76dzfXpXz42X8PemIc+wOAXDufNBTKWNWwFsyo0MvXp1C6/sq5kFA3wXluaCi X-Received: by 2002:a05:6a21:6d96:b0:1b2:6870:c5d9 with SMTP id adf61e73a8af0-1b2b7024bc9mr2338897637.36.1717581122956; Wed, 05 Jun 2024 02:52:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717581122; cv=pass; d=google.com; s=arc-20160816; b=FpU0GVkqqOzFdXajPz/OJsm0yXqhsFiejMFfwsQg7K5rY6MTWVVm+FqyjDpfjkTs8/ 0Fknr4WRztu0zFmScy+9WUdU66Hs7ZL8jaqaX8wwwPgABa0HHm3Ss74pqEnE7PdZNIMr 5s7Jk14jV7u5m6537O/zehcIirFDjBLUxDQRx438rZxSpLQGjUc1qFIhoN4hjecfdk8n myVm/wS6q9z26nzf+z9QXh+sDyOZ5jBUEutRumaETYWC0hdjvd/MLnVzKA6a2XKuZHW1 +c+A51KWub3JsKl6Jo0TuIReuROjsQkpT66SWK5SlrcMC3I2TwolTH376LVw4vclhA8M fN6Q== ARC-Message-Signature: i=2; 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:subject:cc:to:dkim-signature:dkim-signature:from; bh=0QM4N2NR8SUu7foXmQ7iHQLEtg2Qof8D3BqkfSR4DCM=; fh=wYG9BI/Fq6gB58VQotLyjI5OdE2AsOtQk5San/a3JAQ=; b=GIkbMF+4F+wOQcnWbk/mJkaTi9qfvI/ySXHHxQyl5agwkhCawKWJrs20Quz6Q6qZII PHOQqXqDEdhETNsco/R7Sil7EWwGKdUnRktEoEmsGD/2j1ozUr4AZvi51vU0rgdLEcP+ ntLW0DYdhfCA6zoVFTTn4iU3KzaKdW8kWoclaxw05EuwEnR7G5wzN+nZ74w+zoN8kh4X DT2vzEpLiJZEfziIWvhQV1tZO5WoptQT50FDAMy/Bn+/28P1DVFj7PTu3X8YZtgUaIJQ d2KP7sYmhavoP7BdtIvre6khKA34AcvNQZKrjD/r3CXOqoSRlthI1FHXw0xVTFRLyRhH 585Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yL8gTGBk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-202147-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202147-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 d2e1a72fcca58-70242d58ba2si966834b3a.352.2024.06.05.02.52.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:52:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202147-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=yL8gTGBk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-202147-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202147-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 6A2662825CF for ; Wed, 5 Jun 2024 09:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B8BC18FDAD; Wed, 5 Jun 2024 09:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yL8gTGBk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="l/McjD6p" 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 21B6AD268 for ; Wed, 5 Jun 2024 09:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717581098; cv=none; b=dDm1LWhrjSK8dZgW5rIxnOz/UoVHEf/cL3gZm5Ef6P5vZJ35Og4+Wzf3Uy/WCofmujWXFrIWuaC2TBtYiczTefmJhpnic7s0onikOYfO4K6akRTUJ9hRLNvhJg4Ulo8hM5fsxQEU38ifMe4B/m4kz7yXWlmscRVSuqoKJpbf3GY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717581098; c=relaxed/simple; bh=6OJT5ZN++te2WoJcUN6WngMunIIobFOiHdfduMnT8Rs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=mvdfdM9qd+QeZPG9/N6bZ7WfAUaDlNHDl/9FBNiV1pEhMsJG2CtgEtsOhYhNTfc4WJWMupmwpPHxPLqW4UiYttcLsYz5dY8SbVSUV7vaJPKEWlp/EZK2YVD3dUIThSvQhqeYm/LuPj5GYDTEL19OCyEzImgP8Zjq29nCKjsnM18= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yL8gTGBk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=l/McjD6p; arc=none smtp.client-ip=193.142.43.55 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=1717581095; 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; bh=0QM4N2NR8SUu7foXmQ7iHQLEtg2Qof8D3BqkfSR4DCM=; b=yL8gTGBkwxSPBEbq2EskIGxGiGeeLjoStgQeyA4j4ggcoUhkcb0KS/mQ65ZMReKDI5zbG6 R8cfzgdgApyNJWz/QL609za2a9hPXvCnbhZW+qt/M286xLGb3O+SQzhO6EJRhcpgqbD50d R0ewQvp+idlEk1Tt3Js/GX6737xIbN4ycWJCrZ5/svdYP9q+ZcaJpXyyl5BnOrYkcbcJQS Om3j17xteD45rK/Ytf+SYycRsXoBoSQ6RvSJeUw5vxMZXgeUK9TZf+jiXzDELxNKyOIsJJ wbp6SVY+gJKMjS0+M4NQJNOn/kof4FrHRSv6yKa2Uo9+XEv176ZH36pHVkOS8w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717581095; 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; bh=0QM4N2NR8SUu7foXmQ7iHQLEtg2Qof8D3BqkfSR4DCM=; b=l/McjD6pYbZx5aZjRrYE9/fgstU6SPk2RCP5ZlWUCxXRxMzp/hAEZIQWWbVMFZxMzFnYLu 0UvpgmHgd624XwCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Juri Lelli , linux-kernel@vger.kernel.org Subject: [PATCH linux-next] printk: nbcon: Fix nbcon_cpu_emergency_flush() when preemptible Date: Wed, 05 Jun 2024 11:57:34 +0206 Message-ID: <87zfrzvhsp.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 nbcon_cpu_emergency_flush() can be called in a preemptible context. In that case the CPU is not in an emergency state. However, in order to see that the CPU is not in an emergency state (accessing the per-cpu variable), preemption must be disabled. Disable preemption when checking the CPU state. Reported-by: Juri Lelli Closes: https://lore.kernel.org/aqkcpca4vgadxc3yzcu74xwq3grslj5m43f3eb5fcs23yo2gy4@gcsnqcts5tos Fixes: 46a1379208b7 ("printk: nbcon: Implement emergency sections") Signed-off-by: John Ogness --- kernel/printk/nbcon.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 19f0db6945e4..39eb369880d9 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1443,8 +1443,19 @@ void nbcon_cpu_emergency_exit(void) */ void nbcon_cpu_emergency_flush(void) { + bool is_emergency; + + /* + * If this context is not an emergency context, preemption might be + * enabled. To be sure, disable preemption when checking if this is + * an emergency context. + */ + preempt_disable(); + is_emergency = (*nbcon_get_cpu_emergency_nesting() != 0); + preempt_enable(); + /* The explicit flush is needed only in the emergency context. */ - if (*(nbcon_get_cpu_emergency_nesting()) == 0) + if (!is_emergency) return; nbcon_atomic_flush_pending(); -- 2.30.2