From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 CF2F72F2609 for ; Wed, 19 Nov 2025 16:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763571504; cv=none; b=XzEHK9egGbexYZplVZOC1xq09IWtjxo0U1WDennlJyASxguI6unZFUUh/Candz3LZdbw/VXsLhd4dm+RSudXc0JCS0KDBM8HzpUC9r+Zwxxcx2VX0ZK0Nr8mERaEKr75hPzpaRAz2ruzRvLwwlUZc5f4S3JcVqQr2csPBAGp9qI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763571504; c=relaxed/simple; bh=JDs/29Eko32iRFpcnPNVidUdAdokSVQzrSVmUqbBo3c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SjTm/Hn/bmTLXd3oDKY+yrPNVmKSphgYojLhCKr64LJCBNsEsgxV4dQeG8VtriF3M2P9nIhNS9Pgcqn3Nrx/zcJ+Iv4CoxDNB6dLIgxaCvWkX9qyrI4q+oq4+aZk8C0eTMZMLj2GeHTKLwmKGXfzPYHWMDbwP0foPfVaojj5VC4= 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=IzjAFnf/; arc=none smtp.client-ip=209.85.218.44 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="IzjAFnf/" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-b7373fba6d1so846971966b.3 for ; Wed, 19 Nov 2025 08:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1763571500; x=1764176300; 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=W+JYK3ox82faXA72GwEZqKedoEcXCb5w/jtCovydgVM=; b=IzjAFnf/XCK9zWm+0YWJq6oKFtXmBzbiRX4pU8XjcSBMpmwkeCeVeQ/du79woheccI Ku/YJxc3Pl22ORNwdWYaVmVC9o02o84m+oYgyriGhKO5Ok0XWbpUj7Bd1PsxLcD8ZJy2 Ve4PP6PZA8LKf0yagd90OoUEbA0Ck4eNgLcCFG30kn/wDi0cEvWD3FVEqS4OtF76yd7E 8irjn62NzCsBHKGQ7ts/HSNbYVHo+qNoLZdGhWvBZIWvDom1sJG7xpj/GRQvx7CIjvg1 6NxgKk5mmzSr/zhi26zxofE08ahWs+OBjWOXOBftAUX4dv6LkTFullpyQ5TpDncC9r69 9Ndg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763571500; x=1764176300; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W+JYK3ox82faXA72GwEZqKedoEcXCb5w/jtCovydgVM=; b=vdHF52HladEWlSLIU93mTCktzvQ3VQSEPn/re+TJr9ZSJANm4D88S9hA1T2caYJreB 3S0t+VaV4YcJ0QvW7av41Try7xqhjwOlBFIz15Jb50aK1dqLBuuxmUdf8So+SthSIdqY wf7zwx/0Mh5nrtn+I9lrhLJLDpMfYKqm6YSlDb6dBOH/3+Yl2Or/EQCM99ELQOCaPLtj Fzyzl8s3teJDTqG8eT5wub1YbtZXC63Az3i4Mabjh40rPDBvOF5/heIxJ0CrjcLT/tWS Bx0v7Q/2msFtc0nGL3Ni0Pi1IhMGwGWUHhV3MYF+9sXDi8x9vS2XdRUxx6lbQCm2xbLI Xaeg== X-Gm-Message-State: AOJu0YzFmNTkhFXQNY1WofSj02pyvXN2BmYshZ+Wbiu4bBLPKSbBlVZD Qa4gmOg+t64XO1UzYMktU+nEQ4amOBVgSpL9YGJQpWL6ziOqS9SngGshQfNV/p3wIW8= X-Gm-Gg: ASbGncvoaNecKZnO0k0yQtEsm9oZozJZtODZT5K2buer5HG3fQyRhJu2WxD5w+6n38u NkWDc+bfa3BSYMW+Ov+U3Xx0/pTCVps94+GCWCcfafjbcmeeD8+dbu0jbvP3qOeHpv3si6rRSyA dcvqz178stCplcb79G97xnjzaX9YfOYrcbnlzSxvX6hsNFLTdLzPLISTGFvBVx7U94kUHiGWZGi /M6k+5UXcgTSnVThmNXDCenjqz156Rtb6ZJuLVySZgeKq1vKiAcrqCPDJsgGq2QiYDG/SIZHtyf tW6+5V1QnHaUbc7gVGEK8qB4Au4WRtG916B5H0JiU0+v1nL6JUZbbFIiV2gE3VxKDZ49Be/NjFM +0x2msQZBo404fjGJ5RbIpWKNOHQY0aWKNRwYt3KMfBCzAPB6A+C/VdejknTUQTPIU51lLst1xX GaN4UMfJ6cvr0aC7qACm/R2QyV X-Google-Smtp-Source: AGHT+IHM8LRN2pPDUZbbWOLFmWwasxesJLwyy5W8mha1QxUErGW25H5oXQb5QP3z6z1s74RIDzpxxA== X-Received: by 2002:a17:906:fd82:b0:b73:8887:f42d with SMTP id a640c23a62f3a-b738887f472mr1891326266b.5.1763571500036; Wed, 19 Nov 2025 08:58:20 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b734fa81275sm1659582966b.13.2025.11.19.08.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 08:58:19 -0800 (PST) Date: Wed, 19 Nov 2025 17:58:17 +0100 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: Re: [PATCH v7 05/13] printk: Add synchronisation for concurrent console state changes Message-ID: References: <9ffc0801a64e5f7d0685c263c1908a34cf89d1a5.1763492585.git.chris@chrisdown.name> 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: <9ffc0801a64e5f7d0685c263c1908a34cf89d1a5.1763492585.git.chris@chrisdown.name> On Wed 2025-11-19 03:07:17, Chris Down wrote: > The syslog actions SYSLOG_ACTION_CONSOLE_OFF and > SYSLOG_ACTION_CONSOLE_ON currently run without any locking. This creates > a race condition if two processes attempt to toggle the console state > simultaneously. > > While this race has existed for donkey's years, it was previously > somewhat tolerable because it involved only a single integer variable > (saved_console_loglevel). However, upcoming changes will introduce a > second piece of state (saved_ignore_per_console_loglevel) to be saved > and restored. With two variables, this can result in saved state getting > lost. > > Here is a demonstration: > > CPU 0 (SYSLOG_ACTION_CONSOLE_OFF) CPU 1 (SYSLOG_ACTION_CONSOLE_ON) > --------------------------------- -------------------------------- > // saved_console_loglevel is DEFAULT > if (saved == DEFAULT) (True) > saved = console_loglevel (7) > // Race triggers here > if (saved != DEFAULT) (True) > loglevel = saved (7) > saved = DEFAULT > // CPU 0 continues, unaware saved > // was just reset by CPU 1 > loglevel = minimum_console_loglevel (1) > > The result is that the console is now set to the minimum loglevel, but > saved_console_loglevel is LOGLEVEL_DEFAULT. A subsequent CONSOLE_ON call > will see saved == LOGLEVEL_DEFAULT and thus refuse to restore the > original loglevel. The console is effectively stuck in quiet mode until > manually reset via sysctl. Oh dear. > > The callers of do_syslog are syscalls (so user context) or procfs write > handlers. These contexts are allowed to sleep, so acquiring a mutex is > safe. We also already make use of syslog_lock in > SYSLOG_ACTION_SIZE_UNREAD and SYSLOG_ACTION_READ, so this is consistent. > > Signed-off-by: Chris Down Looks good to me: Reviewed-by: Petr Mladek Best Regards, Petr