Message ID | 875xybmo2z.fsf@jogness.linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-81323-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2021128dyb; Mon, 26 Feb 2024 04:02:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX1vIyTIFp6gcl7XhInyfTirojNQ3q752rtjnqIS2uersjdUs12GOgA8yOyu154Hu/gcwbpnnFTq5L0OOwrTXU9C8RVzQ== X-Google-Smtp-Source: AGHT+IFOz7FwqkwQb+0K0IY0/3kuAfcsw1qqYE3eHx2gDdvion+lWEQbwoIJ6AoImd/PgG0lVWBF X-Received: by 2002:a17:902:ef8d:b0:1dc:1ca9:daf9 with SMTP id iz13-20020a170902ef8d00b001dc1ca9daf9mr5110665plb.12.1708948929146; Mon, 26 Feb 2024 04:02:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708948929; cv=pass; d=google.com; s=arc-20160816; b=YdvTm7y92e0ugB2odw28dzGqpgfAiVfHESeBU88nLby4tT+Lm8J8N0swAyKPI7DkDH gtNz7naYMDpCKKQx7GP0BcVdKXoCzA4bqmQ3g3F9ZPr14Q/kYaj82Ndr4wul2342RUEa xqKMr3MiJw32ROp+Vzx6glAt15W0nRLHqoAwyJ3QCAQdWko3Pwt593FSrQ+2VxH9uF4n AXequQ9CG7JDZzn9alOXHVNPjkEM3PcaMONPKo9pS06UQhj1uvWaxwvGJ5yz7vqqpeGi B1jdEf5+R/7yZWdT8/RxPvFE+qIX3BI5/YoiU4BGQf1qipz0k0ZiN3EvDC3scdgXtfcQ iM8Q== 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=ssDX0tZ9H4aDFqTnUDa/YmbnpDQsXNRYjqJeEeUC+QE=; fh=zQtNUD4bVhfr04umHcX+NdGHfLH6aI7S0/IDFRulQTU=; b=PA6S3tFxA0RjOHemwbw11/vdFmeZIVUir0KV9xFXSYrunNSxUx7v4RyO52lpAGX07U PgYzZqRcu39L1N99UHyqgb3aT2nnTNhTgFuqydYYrzwVgYG4uASpZ2djaGFDBQUWa8ig TYltShsjfPVU+SOeqycS3+rLrwIU+T6fM8gnduKFwhj7l/VIcui4IrZbdL9RZrUXDs5L 8n+Ys7Mb5eITtFsDNJ9xtbBLxJ79ID3dH0GfeGwqZxA08epiDZum+XOXKVSE5fw9kTK1 D80MiFND3JxImdlSqtGWN9Zifd8EUhEpAKq46sWM254gwiNRwgVEgi9F4lQdzQwi45zW ic3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WQcV0big; 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-81323-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81323-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y8-20020a17090322c800b001dc6a8dcecesi3630558plg.34.2024.02.26.04.02.09 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:02:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81323-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WQcV0big; 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-81323-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81323-ouuuleilei=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 EFB3729084A for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 12:02:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0EAA5B5AC; Mon, 26 Feb 2024 12:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WQcV0big"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NficySbP" 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 DE9E01DA5F for <linux-kernel@vger.kernel.org>; Mon, 26 Feb 2024 12:01:53 +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=1708948915; cv=none; b=RVAfFw7V7otsGPHvk2GRIyLCAMP5wZ/VwjEaHz89HpR+sdP1u8dUSoRvYcU//nWgjeJiC0zdE6Lej6lw+SeNRTr82aogw2Td7pEAv2uphIKYox+RpU0532EcLwxIq7MsjDvPCkCN4b371xizsx8j+FGbonglcmSoE9F3zN2JN1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708948915; c=relaxed/simple; bh=n6cj64Or9PbJgGcoTFOmTwi8YEiwtQFw0GN6ev3weiE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=cADsCl0yOBgosZOUEkoDDXVfak0ujywRcDn0+9dpYMHdMt1y/Z2gUrCcvy9sWE3F9K9pDKBax+ImD0ZyWlW/cjm8wBXIjHeVLxpKBih+sdsLd67oS50YqzOXHtvojXX8bZKWFxh/IRHzaDnAIfdwtoHC/gzT7hD3VEX+QNhTJ8s= 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=WQcV0big; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NficySbP; 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 <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708948912; 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=ssDX0tZ9H4aDFqTnUDa/YmbnpDQsXNRYjqJeEeUC+QE=; b=WQcV0biglPoBwnOItFsCWzHjvUl/N1wVCLQ5nLY9wqZ1XR2725+jHwPkHXinEzxQQ99pYX +sTn8tsf2SJRctmOnAANkkqHRakTEodjojHB0re/Uae21skTs9c6bD4W+9Z0RBiD663x9J tg1jLIgR8PlyjydI0vq4pMOYrJoXEgHzC+Obqrezs8KAHEbAaF1R8VTWCg1jjRZRdPaGBE McFYZTBWyXvaUBvTQznd9vEZz2zA95yUCPysb9dywex2vf9A5X5njTE3xQ5zkfA9B9vXDI Ks6xEwuvh86Ye5CM9MD249m3C4Y1qX9wElppfHozxFVm7zoYMlBpY2vZ2UVYlw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708948912; 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=ssDX0tZ9H4aDFqTnUDa/YmbnpDQsXNRYjqJeEeUC+QE=; b=NficySbPs2/2+86UeilOXLw3LS+2zvXSEFsOG1gj3oGHWghV+YG4FqrrR+scflwoR/R644 FCHoSf3RhRG4EUAA== To: Mukesh Ojha <quic_mojha@quicinc.com>, pmladek@suse.com, rostedt@goodmis.org, senozhatsky@chromium.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] printk: Update @console_may_schedule in console_trylock_spinning() In-Reply-To: <e5474801-53c1-6bbb-8781-e5cee42d6a90@quicinc.com> References: <20240222090538.23017-1-quic_mojha@quicinc.com> <87plwo5z4k.fsf@jogness.linutronix.de> <e5474801-53c1-6bbb-8781-e5cee42d6a90@quicinc.com> Date: Mon, 26 Feb 2024 13:07:24 +0106 Message-ID: <875xybmo2z.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791962832347519315 X-GMAIL-MSGID: 1791962832347519315 |
Series |
printk: Update @console_may_schedule in console_trylock_spinning()
|
|
Commit Message
John Ogness
Feb. 26, 2024, 12:01 p.m. UTC
console_trylock_spinning() may takeover the console lock from a
schedulable context. Update @console_may_schedule to make sure it
reflects a trylock acquire.
Reported-by: Mukesh Ojha <quic_mojha@quicinc.com>
Link: https://lore.kernel.org/lkml/20240222090538.23017-1-quic_mojha@quicinc.com
Fixes: dbdda842fe96 ("printk: Add console owner and waiter logic to load balance console writes")
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 6 ++++++
1 file changed, 6 insertions(+)
base-commit: e7081d5a9d976b84f61f497316d7c940a4a2e67a
Comments
On 2/26/2024 5:31 PM, John Ogness wrote: > console_trylock_spinning() may takeover the console lock from a > schedulable context. Update @console_may_schedule to make sure it > reflects a trylock acquire. > > Reported-by: Mukesh Ojha <quic_mojha@quicinc.com> > Link: https://lore.kernel.org/lkml/20240222090538.23017-1-quic_mojha@quicinc.com > Fixes: dbdda842fe96 ("printk: Add console owner and waiter logic to load balance console writes") > Signed-off-by: John Ogness <john.ogness@linutronix.de> Thanks for prompt response.. Yes, this looks fine.. As spinning code runs with preemption disabled context and should reset the console_may_schedule to 0 . what if console_trylock_spinning() gets the lock which makes console_may_schedule =1 and it is still schedulable ? -Mukesh > --- > 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 schedulable. > + */ > + console_may_schedule = 0; > + > return 1; > } > > > base-commit: e7081d5a9d976b84f61f497316d7c940a4a2e67a
On 2024-02-26, Mukesh Ojha <quic_mojha@quicinc.com> wrote: > what if console_trylock_spinning() gets the lock which makes > console_may_schedule =1 and it is still schedulable ? I am afraid I do not understand the question. console_trylock_spinning() is only called from the printk caller context. In this context, console_may_schedule is always set to 0. Only if another context acquires the console lock per sleeping wait, console_lock(), can console_may_schedule be set to 1. Note that the value of console_may_schedule is only relevant for the console lock owner when console_unlock() is called. That is why its value is set when locking the console (or, with this patch, when transferring console lock ownerhip). John
On 2/26/2024 6:32 PM, John Ogness wrote: > On 2024-02-26, Mukesh Ojha <quic_mojha@quicinc.com> wrote: >> what if console_trylock_spinning() gets the lock which makes >> console_may_schedule =1 and it is still schedulable ? > > I am afraid I do not understand the question. > > console_trylock_spinning() is only called from the printk caller > context. In this context, console_may_schedule is always set to 0. > > Only if another context acquires the console lock per sleeping wait, > console_lock(), can console_may_schedule be set to 1. > > Note that the value of console_may_schedule is only relevant for the > console lock owner when console_unlock() is called. That is why its > value is set when locking the console (or, with this patch, when > transferring console lock ownerhip). I overlooked it, thanks. Patch LGTM. Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com> -Mukesh > > John
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 schedulable. + */ + console_may_schedule = 0; + return 1; }