From: Mike Snitzer <snitzer@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Nikos Tsironis <ntsironis@arrikto.com>,
dm-devel@redhat.com, Scott Wood <swood@redhat.com>,
Ilias Tsitsimpis <iliastsi@arrikto.com>
Subject: Re: [PATCH 1/2] dm-snapshot: fix crash with the realtime kernel
Date: Tue, 12 Nov 2019 11:06:16 -0500 [thread overview]
Message-ID: <20191112160616.GB3768@redhat.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1911121051400.12815@file01.intranet.prod.int.rdu2.redhat.com>
On Tue, Nov 12 2019 at 10:57am -0500,
Mikulas Patocka <mpatocka@redhat.com> wrote:
>
>
> On Tue, 12 Nov 2019, Mike Snitzer wrote:
>
> > On Mon, Nov 11 2019 at 8:59am -0500,
> > Mikulas Patocka <mpatocka@redhat.com> wrote:
> >
> > > Snapshot doesn't work with realtime kernels since the commit f79ae415b64c.
> > > hlist_bl is implemented as a raw spinlock and the code takes two non-raw
> > > spinlocks while holding hlist_bl (non-raw spinlocks are blocking mutexes
> > > in the realtime kernel, so they couldn't be taken inside a raw spinlock).
> > >
> > > This patch fixes the problem by using non-raw spinlock
> > > exception_table_lock instead of the hlist_bl lock.
> > >
> > > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > > Fixes: f79ae415b64c ("dm snapshot: Make exception tables scalable")
> > >
> > > ---
> > > drivers/md/dm-snap.c | 65 ++++++++++++++++++++++++++++++++-------------------
> > > 1 file changed, 42 insertions(+), 23 deletions(-)
> > >
> > > Index: linux-2.6/drivers/md/dm-snap.c
> > > ===================================================================
> > > --- linux-2.6.orig/drivers/md/dm-snap.c 2019-11-08 15:51:42.000000000 +0100
> > > +++ linux-2.6/drivers/md/dm-snap.c 2019-11-08 15:54:58.000000000 +0100
> > > @@ -141,6 +141,10 @@ struct dm_snapshot {
> > > * for them to be committed.
> > > */
> > > struct bio_list bios_queued_during_merge;
> > > +
> > > +#ifdef CONFIG_PREEMPT_RT_BASE
> > > + spinlock_t exception_table_lock;
> > > +#endif
> > > };
> > >
> > > /*
> > > @@ -625,30 +629,42 @@ static uint32_t exception_hash(struct dm
> > >
> > > /* Lock to protect access to the completed and pending exception hash tables. */
> > > struct dm_exception_table_lock {
> > > +#ifndef CONFIG_PREEMPT_RT_BASE
> > > struct hlist_bl_head *complete_slot;
> > > struct hlist_bl_head *pending_slot;
> > > +#endif
> > > };
> >
> > Why not put the spinlock_t in 'struct dm_exception_table_lock' with the
> > member name 'lock'?
>
> struct dm_exception_table_lock is allocated temporarily on the stack - we
> can't put locks into it, because every user uses different structurer.
>
> However, I can put pointer to to the spinlock to this structure. It
> shortens the patch - because then we don't have to pass a pointer to
> struct dm_snapshot to dm_exception_table_lock and
> dm_exception_table_unlock.
OK, I should've looked at the dm-snap.c code with more context, thanks
for clarifying.
> > > static void dm_exception_table_lock_init(struct dm_snapshot *s, chunk_t chunk,
> > > struct dm_exception_table_lock *lock)
> > > {
> > > +#ifndef CONFIG_PREEMPT_RT_BASE
> > > struct dm_exception_table *complete = &s->complete;
> > > struct dm_exception_table *pending = &s->pending;
> > >
> > > lock->complete_slot = &complete->table[exception_hash(complete, chunk)];
> > > lock->pending_slot = &pending->table[exception_hash(pending, chunk)];
> > > +#endif
> > > }
> > >
> > > -static void dm_exception_table_lock(struct dm_exception_table_lock *lock)
> > > +static void dm_exception_table_lock(struct dm_snapshot *s, struct dm_exception_table_lock *lock)
> > > {
> > > +#ifdef CONFIG_PREEMPT_RT_BASE
> > > + spin_lock(&s->exception_table_lock);
> > > +#else
> > > hlist_bl_lock(lock->complete_slot);
> > > hlist_bl_lock(lock->pending_slot);
> > > +#endif
> > > }
> > >
> > > -static void dm_exception_table_unlock(struct dm_exception_table_lock *lock)
> > > +static void dm_exception_table_unlock(struct dm_snapshot *s, struct dm_exception_table_lock *lock)
> > > {
> > > +#ifdef CONFIG_PREEMPT_RT_BASE
> > > + spin_unlock(&s->exception_table_lock);
> > > +#else
> > > hlist_bl_unlock(lock->pending_slot);
> > > hlist_bl_unlock(lock->complete_slot);
> > > +#endif
> > > }
> > >
> > > static int dm_exception_table_init(struct dm_exception_table *et,
> > > @@ -835,9 +851,9 @@ static int dm_add_exception(void *contex
> > > */
> > > dm_exception_table_lock_init(s, old, &lock);
> > >
> > > - dm_exception_table_lock(&lock);
> > > + dm_exception_table_lock(s, &lock);
> > > dm_insert_exception(&s->complete, e);
> > > - dm_exception_table_unlock(&lock);
> > > + dm_exception_table_unlock(s, &lock);
> > >
> > > return 0;
> > > }
> >
> > That way you don't need the extra 'struct dm_snapshot' arg to all the
> > various dm_exception_table_{lock,unlock} calls.
> >
> > > @@ -1318,6 +1334,9 @@ static int snapshot_ctr(struct dm_target
> > > s->first_merging_chunk = 0;
> > > s->num_merging_chunks = 0;
> > > bio_list_init(&s->bios_queued_during_merge);
> > > +#ifdef CONFIG_PREEMPT_RT_BASE
> > > + spin_lock_init(&s->exception_table_lock);
> > > +#endif
> > >
> > > /* Allocate hash table for COW data */
> > > if (init_hash_tables(s)) {
> >
> > And this spin_lock_init() would go in dm_exception_table_lock_init()
> > in appropriate #ifdef with spin_lock_init(&lock->lock)
>
> dm_exception_table_lock_init initializes an on-stack structure. It can't
> contain locks.
>
> > Doing it that way would seriously reduce the size of this patch.
>
> I reduced the size and I'll send next version.
>
> > Unless I'm missing something, please submit a v2 and cc linux-rt-user
> > mailing list and the other direct CCs suggested by others in reply to
> > patch 2/2.
Sounds good.
prev parent reply other threads:[~2019-11-12 16:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-11 13:59 [PATCH 1/2] dm-snapshot: fix crash with the realtime kernel Mikulas Patocka
2019-11-11 16:37 ` Nikos Tsironis
2019-11-12 1:14 ` Mike Snitzer
2019-11-12 7:50 ` Mikulas Patocka
2019-11-12 11:45 ` Nikos Tsironis
2019-11-13 6:01 ` Scott Wood
2019-11-12 15:34 ` Mike Snitzer
2019-11-12 15:57 ` Mikulas Patocka
2019-11-12 16:06 ` Mike Snitzer [this message]
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=20191112160616.GB3768@redhat.com \
--to=snitzer@redhat.com \
--cc=dm-devel@redhat.com \
--cc=iliastsi@arrikto.com \
--cc=mpatocka@redhat.com \
--cc=ntsironis@arrikto.com \
--cc=swood@redhat.com \
/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.