From 3afb71880ea7159662c149a9a049b03039000115 Mon Sep 17 00:00:00 2001 From: Mel Gorman Date: Apr 26 2023 09:40:38 +0000 Subject: locking/rwbase: Mitigate indefinite writer starvation (bsc#1189998 (PREEMPT_RT prerequisite backports), bsc#1206552). --- diff --git a/patches.suse/locking-rwbase-Mitigate-indefinite-writer-starvation.patch b/patches.suse/locking-rwbase-Mitigate-indefinite-writer-starvation.patch new file mode 100644 index 0000000..e3c5456 --- /dev/null +++ b/patches.suse/locking-rwbase-Mitigate-indefinite-writer-starvation.patch @@ -0,0 +1,58 @@ +From 6c9564384d5ae49a40293408d330f520f638de09 Mon Sep 17 00:00:00 2001 +From: Sebastian Andrzej Siewior +Date: Wed, 22 Mar 2023 14:26:59 +0000 +Subject: [PATCH] locking/rwbase: Mitigate indefinite writer starvation. + +References: bsc#1189998 (PREEMPT_RT prerequisite backports), bsc#1206552 +Patch-mainline: Queued in subsystem maintainer repository +Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git +Git-commit: 9d29d8e36cd6448966d83ab1acf946a2df3c2833 + +The rw_semaphore and rwlock_t locks are unfair to writers. Readers can +indefinitely acquire the lock unless the writer fully acquired the lock. +This can never happen if there is always a reader in the critical +section owning the lock. + +Mel Gorman reported that since LTP-20220121 the dio_truncate test case +went from having 1 reader to having 16 reader and the number of readers +is sufficient to prevent the down_write ever succeeding while readers +exist. Eventually the test is killed after 30 minutes as a failure. + +Mel proposed a timeout to limit how long a writer can be blocked until +the reader is forced into the slowpath. +Thomas argued that there is no added value by providing this timeout. +From PREEMPT_RT point of view, there are no critical rw_semaphore or +rwlock_t locks left where the reader must be prefer. + +Mitigate indefinite writer starvation by forcing the READER into the +slowpath once the WRITER attempts to acquire the lock. + +Reported-by: Mel Gorman +Link: https://lore.kernel.org/877cwbq4cq.ffs@tglx +Signed-off-by: Sebastian Andrzej Siewior +Acked-by: Mel Gorman +Signed-off-by: Mel Gorman +--- + kernel/locking/rwbase_rt.c | 9 --------- + 1 file changed, 9 deletions(-) + +diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c +index 6fd3162e4098..356b247521d8 100644 +--- a/kernel/locking/rwbase_rt.c ++++ b/kernel/locking/rwbase_rt.c +@@ -72,15 +72,6 @@ static int __sched __rwbase_read_lock(struct rwbase_rt *rwb, + int ret; + + raw_spin_lock_irq(&rtm->wait_lock); +- /* +- * Allow readers, as long as the writer has not completely +- * acquired the semaphore for write. +- */ +- if (atomic_read(&rwb->readers) != WRITER_BIAS) { +- atomic_inc(&rwb->readers); +- raw_spin_unlock_irq(&rtm->wait_lock); +- return 0; +- } + + /* + * Call into the slow lock path with the rtmutex->wait_lock diff --git a/series.conf b/series.conf index f713ec3..2b45e13 100644 --- a/series.conf +++ b/series.conf @@ -2601,6 +2601,9 @@ patches.suse/rt-Add-documentation-describing-what-kernel-debug-options-to-add-for-testing.patch patches.suse/rt-Add-helper-script-to-refresh-RT-configs-based-on-the-parent.patch + # Pending merge to ALP-current + patches.suse/locking-rwbase-Mitigate-indefinite-writer-starvation.patch + ######################################################## # You'd better have a good reason for adding a patch # below here.