From: Kevin Wolf <kwolf@redhat.com>
To: Denis Lunev <den@virtuozzo.com>
Cc: "psyhomb@gmail.com" <psyhomb@gmail.com>,
"michael@weiser.dinsnail.net" <michael@weiser.dinsnail.net>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"qemu-stable@nongnu.org" <qemu-stable@nongnu.org>,
"dgilbert@redhat.com" <dgilbert@redhat.com>,
"mreitz@redhat.com" <mreitz@redhat.com>,
"lersek@redhat.com" <lersek@redhat.com>
Subject: Re: [PATCH 2/3] qcow2: Assert that qcow2_cache_get() callers hold s->lock
Date: Thu, 24 Oct 2019 14:07:20 +0200 [thread overview]
Message-ID: <20191024120720.GE6200@linux.fritz.box> (raw)
In-Reply-To: <b244c211-aa73-b4f9-7313-474e909359fb@virtuozzo.com>
Am 24.10.2019 um 13:14 hat Denis Lunev geschrieben:
> On 10/24/19 1:57 PM, Kevin Wolf wrote:
> > Am 24.10.2019 um 12:01 hat Denis Lunev geschrieben:
> >> On 10/23/19 6:26 PM, Kevin Wolf wrote:
> >>> qcow2_cache_do_get() requires that s->lock is locked because it can
> >>> yield between picking a cache entry and actually taking ownership of it
> >>> by setting offset and increasing the reference count.
> >>>
> >>> Add an assertion to make sure the caller really holds the lock. The
> >>> function can be called outside of coroutine context, where bdrv_pread
> >>> and flushes become synchronous operations. The lock cannot and need not
> >>> be taken in this case.
> >>>
> >>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> >>> ---
> >>> block/qcow2-cache.c | 5 +++++
> >>> 1 file changed, 5 insertions(+)
> >>>
> >>> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> >>> index d29b038a67..75b13dad99 100644
> >>> --- a/block/qcow2-cache.c
> >>> +++ b/block/qcow2-cache.c
> >>> @@ -327,6 +327,9 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
> >>> int min_lru_index = -1;
> >>>
> >>> assert(offset != 0);
> >>> + if (qemu_in_coroutine()) {
> >>> + qemu_co_mutex_assert_locked(&s->lock);
> >>> + }
> >> that is looking not good to me. If this is really requires lock, we should
> >> check for the lock always. In the other hand we could face missed
> >> lock out of coroutine.
> > As the commit message explains, outside of coroutine context, we can't
> > yield and bdrv_pread and bdrv_flush become synchronous operations
> > instead, so there is nothing else that we need to protect against.
> >
> Hmm. It seems I was not careful enough with reading entire message.
> I am fine with this though it looks a bit tricky to me as such things
> can change in the future.
In which way do you think this could change? It's a pretty fundamental
fact about non-coroutine code that it can't yield.
What could change, of course, is that some code switches from being
synchronous to using a coroutine. The assertion would automatically
apply then and catch the bug if adding proper locking is forgotten.
> Anyway, you could consider this as
>
> Reviewed-by: Denis V. Lunev <den@openvz.org>
Thanks!
Kevin
next prev parent reply other threads:[~2019-10-24 12:53 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-23 15:26 [PATCH 0/3] qcow2: Fix image corruption bug in 4.1 Kevin Wolf
2019-10-23 15:26 ` [PATCH 1/3] coroutine: Add qemu_co_mutex_assert_locked() Kevin Wolf
2019-10-24 9:59 ` Denis Lunev
2019-10-24 10:54 ` Kevin Wolf
2019-10-24 11:11 ` Denis Lunev
2019-10-23 15:26 ` [PATCH 2/3] qcow2: Assert that qcow2_cache_get() callers hold s->lock Kevin Wolf
2019-10-23 15:37 ` Kevin Wolf
2019-10-25 10:35 ` Michael Weiser
2019-10-25 12:42 ` Kevin Wolf
2019-10-24 10:01 ` Denis Lunev
2019-10-24 10:57 ` Kevin Wolf
2019-10-24 11:14 ` Denis Lunev
2019-10-24 12:07 ` Kevin Wolf [this message]
2019-10-24 13:03 ` Vladimir Sementsov-Ogievskiy
2019-10-24 13:17 ` Kevin Wolf
2019-10-23 15:26 ` [PATCH 3/3] qcow2: Fix corruption bug in qcow2_detect_metadata_preallocation() Kevin Wolf
2019-10-24 10:46 ` Vladimir Sementsov-Ogievskiy
2019-10-24 11:17 ` Kevin Wolf
2019-10-24 12:41 ` Vladimir Sementsov-Ogievskiy
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=20191024120720.GE6200@linux.fritz.box \
--to=kwolf@redhat.com \
--cc=den@virtuozzo.com \
--cc=dgilbert@redhat.com \
--cc=lersek@redhat.com \
--cc=michael@weiser.dinsnail.net \
--cc=mreitz@redhat.com \
--cc=psyhomb@gmail.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=vsementsov@virtuozzo.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.