Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp319383rdb; Tue, 16 Jan 2024 00:49:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQ7cCgR5vk/MGKjt8vQD35PytSxZpwLW6QlwZCdtbah7oLASa45h4ooTt9FbMSPzrr4gV0 X-Received: by 2002:a05:6871:b1ad:b0:210:7f83:ae3a with SMTP id an45-20020a056871b1ad00b002107f83ae3amr178921oac.94.1705394942400; Tue, 16 Jan 2024 00:49:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705394942; cv=none; d=google.com; s=arc-20160816; b=ju+8LDIUmk5Ci5bupryGahnAUFcChJxqcdNH87cF9nwZ73c3PIr4eajAhVb109rYWY jszVa0EnzYzv1tbNJE/A1QbQDQHvHBxwmrsa34APSg6smOOCk4tOOXEpvoK70rnYTBbN rzW4dQVy6vLzjKhN+L1FLv6YbHusLNJLiq3NwnzROatczZcs6ZuNPQUdSZTpvRkxs5va 4xeRUWPd4xr1bA6F4WB+o7XY0UH0csE0JOkyxuhfLZMjqFL07rEOv9GFmXCsYhGRTIIO ezVUA93MJYFmCDDhDNWrtM+sJAMAuI9JpU7XJ/j5oDYIIEjXsIlGKS3uZm1spixJ8fJv 69sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:date:from :dkim-signature; bh=VjhbNo1ujd1QRp4N6HHrcQMKxeBqd2EyOBnCEZ5QgmE=; fh=2yMqf6zoWj4fLo2nqxDF9U01LaytxHtGDYZra8nBzAY=; b=uzWcVvB+SagZZF02/83XXRaiWAUHsJJ0vTypvUvgrsiWEtHPkH31ccSrHZaY9689di kMDFN75ZOF7PivR8KTzYf5Tvgqfp3AfFFZPSZANqIQkCvjJ8dC/b7hByNqmnM/+7Juh8 YddLFt5Py71AsXcwbu1m3y8V4FDfwT6Q2EtMYCAlKgStybun1khDAhJxe1j+ee8li4vV KJGEedq6Y9ceOkTuq6q/kF1wfa9F1wM3Ta4bfugsEt3t8gj7gPecpkliQLKpl070a9/P UKtUZJm6ihukkbPApSldq+FJe/mzA9dYpbphTZKeWV44Ui4K5gRN73TvvBq2uOS2uaGt XBFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CHQrNaXK; spf=pass (google.com: domain of linux-kernel+bounces-27143-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g11-20020a63564b000000b005cde420a01fsi2510903pgm.667.2024.01.16.00.49.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 00:49:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27143-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=@intel.com header.s=Intel header.b=CHQrNaXK; spf=pass (google.com: domain of linux-kernel+bounces-27143-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0FBD028551F for ; Tue, 16 Jan 2024 08:49:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19D02125B6; Tue, 16 Jan 2024 08:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CHQrNaXK" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (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 048BB125A3; Tue, 16 Jan 2024 08:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705394934; x=1736930934; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=B6rzE15E+3r6Gl6rpOFZgLwTO62J00BCuGerH7lFMtQ=; b=CHQrNaXKvK33ncsD9gr14V1ruRe1pUat5akt1iLne48evhsBvx84RSMf 6GRQTyNQTYY2XBauJEXdAK/ClKIhdaM8PmLA7FTwPFIC3KWlcMynIHVi8 4W6kXdnv22GArdjAT/NBdbdQSt+7E1K/5povy9wlDKWdGTeDN5kg7MTFd Rsxb9Ky5DkOes7i94O/VBUbTm9zljpBUbj8Eg+6LYh4M1RQOVTMPeqdeH QRPC/WYClargpioRZ+nMP1GmF81ZRmBBCSBZUkCdO9Q23YGDhPRWXIoV7 toJu6bduG4QMllquvbJsuIawWYFEF1VHhqrokcY8mNr/DeDsaCnwcebuv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="390246229" X-IronPort-AV: E=Sophos;i="6.04,198,1695711600"; d="scan'208";a="390246229" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 00:48:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="854281511" X-IronPort-AV: E=Sophos;i="6.04,198,1695711600"; d="scan'208";a="854281511" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.246.35.68]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 00:48:48 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 16 Jan 2024 10:48:44 +0200 (EET) To: Leonardo Bras cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Andy Shevchenko , Florian Fainelli , John Ogness , Tony Lindgren , Marcelo Tosatti , LKML , linux-serial Subject: Re: [RESEND RFC PATCH v1 2/2] serial/8250: Avoid getting lock in RT atomic context In-Reply-To: <20240116073701.2356171-3-leobras@redhat.com> Message-ID: <75a39f0a-8f79-eacf-4a35-5de512a3cbed@linux.intel.com> References: <20240116073701.2356171-1-leobras@redhat.com> <20240116073701.2356171-3-leobras@redhat.com> 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 On Tue, 16 Jan 2024, Leonardo Bras wrote: > With PREEMPT_RT enabled, a spin_lock_irqsave() becomes a possibly sleeping > spin_lock(), without preempt_disable() or irq_disable(). > > This allows a task T1 to get preempted or interrupted while holding the > port->lock. If the preempting task T2 need the lock, spin_lock() code > will schedule T1 back until it finishes using the lock, and then go back to > T2. > > There is an issue if a T1 holding port->lock is interrupted by an > IRQ, and this IRQ handler needs to get port->lock for writting (printk): > spin_lock() code will try to reschedule the interrupt handler, which is in > atomic context, causing a BUG() for trying to reschedule/sleep in atomic > context. I thought that the printk side was supposed to be become aware when it's not safe to write to serial side so the printing can be deferred... Has that plan changed? -- i. > So for the case (PREEMPT_RT && in_atomic()) try to get the lock, and if it > fails proceed anyway, just like it's done in oops_in_progress case. > > Signed-off-by: Leonardo Bras > --- > drivers/tty/serial/8250/8250_port.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c > index 8ca061d3bbb92..8480832846319 100644 > --- a/drivers/tty/serial/8250/8250_port.c > +++ b/drivers/tty/serial/8250/8250_port.c > @@ -3397,7 +3397,7 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, > > touch_nmi_watchdog(); > > - if (oops_in_progress) > + if (oops_in_progress || (IS_ENABLED(CONFIG_PREEMPT_RT) && in_atomic()) > locked = uart_port_trylock_irqsave(port, &flags); > else > uart_port_lock_irqsave(port, &flags); >