From: Boqun Feng <boqun.feng@gmail.com> To: Qian Cai <cai@redhat.com> Cc: "Ahmed S. Darwish" <a.darwish@linutronix.de>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, "Sebastian A. Siewior" <bigeasy@linutronix.de>, "Paul E. McKenney" <paulmck@kernel.org>, Steven Rostedt <rostedt@goodmis.org>, LKML <linux-kernel@vger.kernel.org>, Stephen Rothwell <sfr@canb.auug.org.au>, linux-next@vger.kernel.org, Waiman Long <longman@redhat.com> Subject: Re: [PATCH v2 0/5] seqlock: Introduce PREEMPT_RT support Date: Tue, 15 Sep 2020 21:10:59 +0800 Message-ID: <20200915131059.GB127490@debian-boqun.qqnc3lrjykvubdpftowmye0fmh.lx.internal.cloudapp.net> (raw) In-Reply-To: <20200915124817.GA127490@debian-boqun.qqnc3lrjykvubdpftowmye0fmh.lx.internal.cloudapp.net> On Tue, Sep 15, 2020 at 08:48:17PM +0800, Boqun Feng wrote: > On Mon, Sep 14, 2020 at 08:20:53PM -0400, Qian Cai wrote: > > On Fri, 2020-09-04 at 17:32 +0200, Ahmed S. Darwish wrote: > > > Hi, > > > > > > Changelog-v2 > > > ============ > > > > > > - Standardize on seqcount_LOCKNAME_t as the canonical reference for > > > sequence counters with associated locks, instead of v1 > > > seqcount_LOCKTYPE_t. > > > > > > - Use unique prefix "seqprop_*" for all seqcount_t/seqcount_LOCKNAME_t > > > property accessors. > > > > > > - Touch-up the lock-unlock rationale for more clarity. Enforce writer > > > non-preemitiblity using "__seq_enforce_writer_non_preemptibility()". > > > > > > Cover letter (v1) > > > ================= > > > > > > https://lkml.kernel.org/r/20200828010710.5407-1-a.darwish@linutronix.de > > > > > > Preemption must be disabled before entering a sequence counter write > > > side critical section. Otherwise the read side section can preempt the > > > write side section and spin for the entire scheduler tick. If that > > > reader belongs to a real-time scheduling class, it can spin forever and > > > the kernel will livelock. > > > > > > Disabling preemption cannot be done for PREEMPT_RT though: it can lead > > > to higher latencies, and the write side sections will not be able to > > > acquire locks which become sleeping locks (e.g. spinlock_t). > > > > > > To remain preemptible, while avoiding a possible livelock caused by the > > > reader preempting the writer, use a different technique: let the reader > > > detect if a seqcount_LOCKNAME_t writer is in progress. If that's the > > > case, acquire then release the associated LOCKNAME writer serialization > > > lock. This will allow any possibly-preempted writer to make progress > > > until the end of its writer serialization lock critical section. > > > > > > Implement this lock-unlock technique for all seqcount_LOCKNAME_t with > > > an associated (PREEMPT_RT) sleeping lock, and for seqlock_t. > > > > Reverting this patchset [1] from today's linux-next fixed a splat below. The > > splat looks like a false positive anyway because the existing locking dependency > > chains from the task #1 here: > > > > &s->seqcount#2 ---> pidmap_lock > > > > [ 528.078061][ T7867] -> #1 (pidmap_lock){....}-{2:2}: > > [ 528.078078][ T7867] lock_acquire+0x10c/0x560 > > [ 528.078089][ T7867] _raw_spin_lock_irqsave+0x64/0xb0 > > [ 528.078108][ T7867] free_pid+0x5c/0x160 > > free_pid at kernel/pid.c:131 > > [ 528.078127][ T7867] release_task.part.40+0x59c/0x7f0 > > __unhash_process at kernel/exit.c:76 > > (inlined by) __exit_signal at kernel/exit.c:147 > > (inlined by) release_task at kernel/exit.c:198 > > [ 528.078145][ T7867] do_exit+0x77c/0xda0 > > exit_notify at kernel/exit.c:679 > > (inlined by) do_exit at kernel/exit.c:826 > > [ 528.078163][ T7867] kthread+0x148/0x1d0 > > [ 528.078182][ T7867] ret_from_kernel_thread+0x5c/0x80 > > > > It is write_seqlock(&sig->stats_lock) in __exit_signal(), but the &s->seqcount#2 > > in read_mems_allowed_begin() is read_seqcount_begin(¤t->mems_allowed_seq), > > so there should be no deadlock? > > > > I think this happened because seqcount_##lockname##_init() is defined at > function rather than macro, so when the seqcount_init() gets expand in > that function, the lock_class_key of seqcount will be a static variable > of seqcount_##lockname##_init() function, as a result, all > seqcount_##lockname##_t in the same compile unit (in this case it's > kernel/fork.c) share the same lock class key, and lockdep thought they > are the same lock ;-) > Don't know how to fix this properly, but below is an ugly attemption, only build test, just food for thoughts. Regards, Boqun --------------->8 diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index f73c7eb68f27..938a5053def3 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -84,14 +84,18 @@ static inline void __seqcount_init(seqcount_t *s, const char *name, # define SEQCOUNT_DEP_MAP_INIT(lockname) \ .dep_map = { .name = #lockname } +# define MSIOCU 8 /* MAX SEQCOUNT IN ON COMPILE UNIT */ /** * seqcount_init() - runtime initializer for seqcount_t * @s: Pointer to the seqcount_t instance */ # define seqcount_init(s) \ do { \ - static struct lock_class_key __key; \ - __seqcount_init((s), #s, &__key); \ + static struct lock_class_key __key[MSIOCU]; \ + static int idx = 0; \ + \ + BUG_ON(idx >= MSIOCU); \ + __seqcount_init((s), #s, &__key[idx++]); \ } while (0) static inline void seqcount_lockdep_reader_access(const seqcount_t *s)
next prev parent reply index Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-04 15:32 Ahmed S. Darwish 2020-09-04 15:32 ` [PATCH v2 1/5] seqlock: seqcount_LOCKNAME_t: Standardize naming convention Ahmed S. Darwish 2020-09-10 15:08 ` [tip: locking/core] " tip-bot2 for Ahmed S. Darwish 2020-09-04 15:32 ` [PATCH v2 2/5] seqlock: Use unique prefix for seqcount_t property accessors Ahmed S. Darwish 2020-09-08 11:41 ` peterz 2020-09-10 15:08 ` [tip: locking/core] " tip-bot2 for Ahmed S. Darwish 2020-09-04 15:32 ` [PATCH v2 3/5] seqlock: seqcount_t: Implement all read APIs as statement expressions Ahmed S. Darwish 2020-09-10 15:08 ` [tip: locking/core] " tip-bot2 for Ahmed S. Darwish 2020-09-04 15:32 ` [PATCH v2 4/5] seqlock: seqcount_LOCKNAME_t: Introduce PREEMPT_RT support Ahmed S. Darwish 2020-09-08 11:45 ` peterz 2020-09-08 12:48 ` Ahmed S. Darwish 2020-09-04 15:32 ` [PATCH v2 5/5] seqlock: PREEMPT_RT: Do not starve seqlock_t writers Ahmed S. Darwish 2020-09-10 15:08 ` [tip: locking/core] " tip-bot2 for Ahmed S. Darwish 2020-09-15 0:20 ` [PATCH v2 0/5] seqlock: Introduce PREEMPT_RT support Qian Cai 2020-09-15 12:48 ` Boqun Feng 2020-09-15 13:10 ` Boqun Feng [this message] 2020-09-15 14:30 ` peterz 2020-09-16 12:52 ` Qian Cai 2020-09-16 12:54 ` peterz 2020-09-16 13:00 ` Qian Cai 2020-09-16 13:02 ` peterz 2020-09-17 2:31 ` Stephen Rothwell 2020-09-18 8:42 ` [tip: locking/core] seqlock: Unbreak lockdep tip-bot2 for peterz@infradead.org
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=20200915131059.GB127490@debian-boqun.qqnc3lrjykvubdpftowmye0fmh.lx.internal.cloudapp.net \ --to=boqun.feng@gmail.com \ --cc=a.darwish@linutronix.de \ --cc=bigeasy@linutronix.de \ --cc=cai@redhat.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-next@vger.kernel.org \ --cc=longman@redhat.com \ --cc=mingo@redhat.com \ --cc=paulmck@kernel.org \ --cc=peterz@infradead.org \ --cc=rostedt@goodmis.org \ --cc=sfr@canb.auug.org.au \ --cc=tglx@linutronix.de \ --cc=will@kernel.org \ /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
LKML Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lkml.kernel.org/lkml/0 lkml/git/0.git git clone --mirror https://lkml.kernel.org/lkml/1 lkml/git/1.git git clone --mirror https://lkml.kernel.org/lkml/2 lkml/git/2.git git clone --mirror https://lkml.kernel.org/lkml/3 lkml/git/3.git git clone --mirror https://lkml.kernel.org/lkml/4 lkml/git/4.git git clone --mirror https://lkml.kernel.org/lkml/5 lkml/git/5.git git clone --mirror https://lkml.kernel.org/lkml/6 lkml/git/6.git git clone --mirror https://lkml.kernel.org/lkml/7 lkml/git/7.git git clone --mirror https://lkml.kernel.org/lkml/8 lkml/git/8.git git clone --mirror https://lkml.kernel.org/lkml/9 lkml/git/9.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 lkml lkml/ https://lkml.kernel.org/lkml \ linux-kernel@vger.kernel.org public-inbox-index lkml Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git