All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Oleg.Karfich@wago.com, Thomas Gleixner <tglx@linutronix.de>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Sasha Levin <sashal@kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 14/14] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT
Date: Thu, 11 Aug 2022 12:09:42 -0400	[thread overview]
Message-ID: <20220811160948.1542842-14-sashal@kernel.org> (raw)
In-Reply-To: <20220811160948.1542842-1-sashal@kernel.org>

From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

[ Upstream commit cf634d540a29018e8d69ab1befb7e08182bc6594 ]

i_dir_seq is a sequence counter with a lock which is represented by the
lowest bit. The writer atomically updates the counter which ensures that it
can be modified by only one writer at a time. This requires preemption to
be disabled across the write side critical section.

On !PREEMPT_RT kernels this is implicit by the caller acquiring
dentry::lock. On PREEMPT_RT kernels spin_lock() does not disable preemption
which means that a preempting writer or reader would live lock. It's
therefore required to disable preemption explicitly.

An alternative solution would be to replace i_dir_seq with a seqlock_t for
PREEMPT_RT, but that comes with its own set of problems due to arbitrary
lock nesting. A pure sequence count with an associated spinlock is not
possible because the locks held by the caller are not necessarily related.

As the critical section is small, disabling preemption is a sensible
solution.

Reported-by: Oleg.Karfich@wago.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lkml.kernel.org/r/20220613140712.77932-2-bigeasy@linutronix.de
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/dcache.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 1e9f4dd94e6c..6f6a972ea20c 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2406,7 +2406,15 @@ EXPORT_SYMBOL(d_rehash);
 
 static inline unsigned start_dir_add(struct inode *dir)
 {
-
+	/*
+	 * The caller holds a spinlock (dentry::d_lock). On !PREEMPT_RT
+	 * kernels spin_lock() implicitly disables preemption, but not on
+	 * PREEMPT_RT.  So for RT it has to be done explicitly to protect
+	 * the sequence count write side critical section against a reader
+	 * or another writer preempting, which would result in a live lock.
+	 */
+	if (IS_ENABLED(CONFIG_PREEMPT_RT))
+		preempt_disable();
 	for (;;) {
 		unsigned n = dir->i_dir_seq;
 		if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n)
@@ -2418,6 +2426,8 @@ static inline unsigned start_dir_add(struct inode *dir)
 static inline void end_dir_add(struct inode *dir, unsigned n)
 {
 	smp_store_release(&dir->i_dir_seq, n + 2);
+	if (IS_ENABLED(CONFIG_PREEMPT_RT))
+		preempt_enable();
 }
 
 static void d_wait_lookup(struct dentry *dentry)
-- 
2.35.1


  parent reply	other threads:[~2022-08-11 16:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 16:09 [PATCH AUTOSEL 4.19 01/14] drm/r128: Fix undefined behavior due to shift overflowing the constant Sasha Levin
2022-08-11 16:09 ` Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 02/14] drm/radeon: integer overflow in radeon_mode_dumb_create() Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 03/14] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 04/14] media: davinci: vpif: add missing of_node_put() in vpif_probe() Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 05/14] media: airspy: respect the DMA coherency rules Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 06/14] media: pvrusb2: fix memory leak in pvr_probe Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 07/14] mlxsw: cmd: Increase 'config_profile.flood_mode' length Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 08/14] crypto: vmx - Fix warning on p8_ghash_alg Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09 ` [Nouveau] [PATCH AUTOSEL 4.19 09/14] drm/nouveau/nvkm: use list_add_tail() when building object tree Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09   ` Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 10/14] can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 11/14] net/cdc_ncm: Increase NTB max RX/TX values to 64kb Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 12/14] wifi: rtl8xxxu: Fix the error handling of the probe function Sasha Levin
2022-08-11 16:09 ` [PATCH AUTOSEL 4.19 13/14] d_add_ci(): make sure we don't miss d_lookup_done() Sasha Levin
2022-08-11 16:09 ` Sasha Levin [this message]
2022-08-13 13:43   ` [PATCH AUTOSEL 4.19 14/14] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220811160948.1542842-14-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Oleg.Karfich@wago.com \
    --cc=bigeasy@linutronix.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.