Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp385761rdb; Thu, 22 Feb 2024 06:54:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUyM+UrllkDUEGXrs61Yt4LQP53I/S6r+dgoXhTwvdESXLu1y2B93+zu8/7v5TeSjGvjWwIBQJGNw7ABzPwPsDm15cA0B64lhKUhTKZuQ== X-Google-Smtp-Source: AGHT+IFHKSEimUdmkCir+0OHdEXFj+b7q3jJ8E5YFrA7kjHB9IQUo2ew0yVflc3/eLqjP3kXoe3e X-Received: by 2002:a05:6a21:1394:b0:1a0:9e45:1537 with SMTP id oa20-20020a056a21139400b001a09e451537mr12859801pzb.30.1708613644499; Thu, 22 Feb 2024 06:54:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708613644; cv=pass; d=google.com; s=arc-20160816; b=mzvN+eP9RHFuQocFAn0vFpPHBP2nNEYCkce/1esmIVWLO9QJKEOF64yVatXHZqoI6c KKlW2mDZDGX9i4QuH4mvcT+ih+SAShjerheDfCeWJ9fLgZXG4HgkGGAUyFGCv6HumxiC 0XWxwbF6Jec1ziaS1wBO7e8EQcEAFYdCzjfrOGNNx+BsFCF0AhcG2fK0weoDof9hB3/3 g+xBcY2FR1z5C1N9TdB31vGdLAhDN3oE6070SyDreoFEhKGQWQyAi1Vx3RyFTDEIfhj6 vfqLVWyxYEfzmUsKDyq0Y7Xb6rHsTfRwaITErsC8HCOglz3Jm+biRzLI4zdRkdWS1bJY WmNA== 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:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=ftFB7iq5QbNfkEzFk48AFLpiuJwfQQxJUlxL4LvbesA=; fh=+BKP1uTbi+tuKis3rRuPY3qPTdLBRhvccYJtd74xapQ=; b=oM6wW4vFBviYcF6HjM32NvJlTEBhTBxb+3ElMot8gYBdAcY2SFwHguYjOQ/lYPcZnj 1VWuDSU8Ayxhpd48A2U+2H+/gY7kzWUsPxKfRbfqnMoyY7+9j6kVsqWdOS6Zx/Q95Uu+ DRTog0GlIgT8Tzl14pHklnHmenzfcoC5SnY/AXqX3MZ+Dz7nD90pe6cZKE1edQWRlNbN kQBGaewm8tITKz9TpxR8BkwgOm2XuOL6eaQJe57ZVuDvEYcWwa7ZZtzWfBiyj40btnVo xl/fYmQ6zIX+nmVQ/vii5f0sYRWqK9x9jxAdFXkcTCuFLRcuOI+iWB5DYvtqmByVV0d+ 9sjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qXxhbRr+; 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-76728-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76728-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 l123-20020a632581000000b005dc88c4700dsi10210167pgl.31.2024.02.22.06.54.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:54:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76728-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=qXxhbRr+; 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-76728-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76728-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 2CAEE28B395 for ; Thu, 22 Feb 2024 14:54:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C97A1487C5; Thu, 22 Feb 2024 14:54:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qXxhbRr+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dVQ8Uaod" 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 DD5621474A2 for ; Thu, 22 Feb 2024 14:53:57 +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=1708613639; cv=none; b=HEERLmwxF6oP0gaME/gzlnDk0x55SqTkhjA7N5x4nOlzVNAYmPTRiTi8raBWKCyYNlMbK8JVIQMDH0pKLsYHKK8e0Sh4wHfsm4YQC7cLj1UYYSyU3eLvlpTDgMY0OcMfb1sYHJ6p9G+7Pyf2zEZWKQxwcPL+pBTiCnvtcFKDmhU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708613639; c=relaxed/simple; bh=l1dvnYIkbVQGD2EOv6y5d0AMbBQic+r+Q8ubYp/1wzc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=VrAMKPuaYMp3bFYlZRCrhFbApanz2ZTjRJbwJJI9nETj7yUvQlS8jJsci+OnJZk9ZAI3PQEgKhfNQBYhxqaW2ClxENMiVrS+tUzUb1wh4QWJXAqfM3vfOUA/CgeERJQ6mo+9X6fbmzRz5Fub3tSR+PYL7K30xF/7Qq4EAgWYq5A= 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=qXxhbRr+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dVQ8Uaod; 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=1708613635; 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=ftFB7iq5QbNfkEzFk48AFLpiuJwfQQxJUlxL4LvbesA=; b=qXxhbRr+8fbp4feSZQlXFT48tW1d+9ECLIOuzKO7R6GYS8KQKz8rlE7T0vNeVEXXjZiDgb 8pvujYcWkxg9guXpeRtS5FmMHtahJHQPardhs9liwHfVdm5gvPJ1Nj+o231nSqsOr5n0yj 5UmYxrxTPdzWperHKaUDnaykK/imsmdvvuWwFpgMqTpRnlI4eMOpiI6yYqYJebjM+ZVGaR Fl95q6+NbyMjExwyRI1wAINTarvotqY4fOBLfcJXAeEneS2vNaMOHR5H1Wxg6WqAyKWlGZ awdztHKGgXY4J7o7RUe6NMU05kpj0rOARGfHtauJRJS+GLEB3KwOgwvukfXlBw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708613635; 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=ftFB7iq5QbNfkEzFk48AFLpiuJwfQQxJUlxL4LvbesA=; b=dVQ8UaodovodkLeyjIRK3u9a1o7yw/M73eVVSHMYk8UpkBEiHrpuTaC78x5/C6pFb0BLaV eUKU70asSrQOS4BQ== To: Mukesh Ojha , pmladek@suse.com, rostedt@goodmis.org, senozhatsky@chromium.org Cc: linux-kernel@vger.kernel.org, Mukesh Ojha Subject: Re: [PATCH] printk: Add atomic context check inside console_unlock() In-Reply-To: <20240222090538.23017-1-quic_mojha@quicinc.com> References: <20240222090538.23017-1-quic_mojha@quicinc.com> Date: Thu, 22 Feb 2024 15:59:31 +0106 Message-ID: <87plwo5z4k.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-02-22, Mukesh Ojha wrote: > Situation of schedule while atomic context can happen in a > scenario if CPU-Y executing a async probe of ufs and while > printing a line it is started spinning for console lock > after preemption disable on CPU-Y and later it got the handover > of console lock from CPU-X and in console_unlock() it get > schedule with preempt disable as console_may_schedule was one > and due to which do_cond_resched was one. Nice catch. But I think the below patch is the appropriate fix: John Ogness -------8<-------- Subject: [PATCH] printk: Update @console_may_schedule in console_trylock_spinning() console_trylock_spinning() may takeover the console lock from a scheduable context. Update @console_may_schedule to make sure it reflects a trylock acquire. Reported-by: Mukesh Ojha Link: https://lore.kernel.org/lkml/20240222090538.23017-1-quic_mojha@quicinc.com Signed-off-by: John Ogness --- kernel/printk/printk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1685a71f3f71..1612b50b2374 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2020,6 +2020,12 @@ static int console_trylock_spinning(void) */ mutex_acquire(&console_lock_dep_map, 0, 1, _THIS_IP_); + /* + * Update @console_may_schedule for trylock because the previous + * owner may have been scheduable. + */ + console_may_schedule = 0; + return 1; } base-commit: e7081d5a9d976b84f61f497316d7c940a4a2e67a -- 2.30.2