Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp298682rdb; Mon, 15 Jan 2024 23:51:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IG94pFtzL3lWb/AjwTddwdmcyYG0g0o7IRhjUnicGrYyib37bX0MEPqI4IwaAsMO83ZFSLV X-Received: by 2002:a17:906:c28a:b0:a2e:6f5f:89cd with SMTP id r10-20020a170906c28a00b00a2e6f5f89cdmr253040ejz.119.1705391367987; Mon, 15 Jan 2024 23:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705391367; cv=none; d=google.com; s=arc-20160816; b=lWXEdslQWybpDBNgov6Q9/a8fZ3Z8THr6zdDxPH2rfA6+FdkB/XmcqBQijo9CEtwNI AJ1yfGJN7D3td99/VxbEKS8xLxZ8R8ZHKGatpL3YpkbNQryUb6Izp7naFfI0Iq+oiOxQ zUvIEnWSzVM4ZxWCtp6TKLGm06NvgzF1vQovOeDjlo22b3sRl//PZQfJ+5Jrq/q/uu6U kSdr/oF4OshX8cdP2Fqwj26d7R5VzMzI5hPAW/IDV0aiyGus2MSQZmkjjqwgxI8EE8zC F85XLxKmutdwa+XyYeYuHe6E46Ygtb+BKLUqatuqNTUVTsnP4IBLwaz4RURK/6NHVcv2 0RoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=bMFfua79vsNO5VMfysSZXzOkQtkiDmf25dFKcIPKIxo=; fh=JqNBWHYUbMCq4onCxX5AFYZQoifouO9YaDnRX4jbRb4=; b=gUCwThsLZcC91vlBQRm/kyKV9yib7FWuSzW3YFc0/lxTwv61kr9uGnl1b6AOpKISYQ JarKvLA7ijHS3Pff5yf7u85rPW06dnIU76uN+PYuRsbTr2wW++N5UHnkCBwnDeJDLwuG KBKVwjIlHtO9UwFd6A72LxGHAVxFTN43y+iP+rLzxm47r+EMUmBI5QBUV3WohN/rP75W 5AmnHwBPHQ22dS8K5z1hzfMQ58L1K3srDyVytZx08KmwhBUJ+ArO3NRM08yIB1nirsde /DyF5b9Ijxi6DPc+qwSgfNObXU4UUZ9n4qVVs8PgirKMujoxCZ0Qzd8+4umNcirFq1AT O+Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27099-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27099-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hb13-20020a170906b88d00b00a2e72d8f9a8si374758ejb.823.2024.01.15.23.49.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 23:49:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27099-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27099-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27099-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 915191F23E81 for ; Tue, 16 Jan 2024 07:49:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A734111A4; Tue, 16 Jan 2024 07:49:19 +0000 (UTC) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 832DF11181; Tue, 16 Jan 2024 07:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-337b976773fso255205f8f.0; Mon, 15 Jan 2024 23:49:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705391356; x=1705996156; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bMFfua79vsNO5VMfysSZXzOkQtkiDmf25dFKcIPKIxo=; b=dv9BGTAG/d1KopuTciFELCtTbbxeZ+KUItyVPZiyDw+Y2SHcvc6h/V1J0a113+PaxY 8P2ffdZT4qFokd5zM5cA3Bl87ajV4l01EivxzSWamfdJyf9I9zDapOSlHh0Njdqw9c+r IH4ciwUHTmMZCRzisHv3T55K7L9prCd8JDyUt7s7OjnTozIhdo/pYeWysf19y25lMlZ+ 9BtQz43M+83buS4u1+XfyHeHZv0d1kqkZQHtbP5wfitu5eXSRadFZBGruz07kp8DHndS uvuVoNx6PteOfEjC1TcoC04/TmCjlyfcVC9zgbYVl2RqAqB0R0VKegwLsxz/+ykCO56V aGrw== X-Gm-Message-State: AOJu0YyuJDmfpX034u/u79T0vgwLxTzvKvO49cuK/z/1xWCzIVutYoP/ xNOjBdPn3mN+cttYgYdATcU= X-Received: by 2002:a5d:6e90:0:b0:333:2e15:632c with SMTP id k16-20020a5d6e90000000b003332e15632cmr3705374wrz.10.1705391355593; Mon, 15 Jan 2024 23:49:15 -0800 (PST) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:59? ([2a0b:e7c0:0:107::aaaa:59]) by smtp.gmail.com with ESMTPSA id q2-20020a056000136200b003373fe3d345sm13786900wrz.65.2024.01.15.23.49.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jan 2024 23:49:15 -0800 (PST) Message-ID: Date: Tue, 16 Jan 2024 08:49:14 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 2/2] serial/8250: Avoid getting lock in RT atomic context Content-Language: en-US To: Leonardo Bras , Greg Kroah-Hartman , Thomas Gleixner , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Florian Fainelli , John Ogness , Tony Lindgren , Marcelo Tosatti , Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org References: <20240116073234.2355850-2-leobras@redhat.com> <20240116073234.2355850-4-leobras@redhat.com> From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx wr+aw6qqQVgvT/McQtsI0S66uIkQjzPUrgAEtWUv76rM4ekqL9stHyvTGw0Fjsualwb0Gwdx ReTZzMgheAyoy/umIOKrSEpWouVoBt5FFSZUyjuDdl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fEJW9JXp3BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20240116073234.2355850-4-leobras@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 16. 01. 24, 8:32, 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. > > 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. Hmm, that appears incorrect to me. Perhaps we need a raw spin lock? Or maybe I am totally off, as my RT knowledge is close to zero. This needs advices from RT folks... > 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); -- js suse labs