From: "Daniel P. Berrange" <berrange@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Fam Zheng <famz@redhat.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v5 6/7] block: add generic full disk encryption driver
Date: Fri, 18 Mar 2016 15:37:12 +0000 [thread overview]
Message-ID: <20160318153712.GK17895@redhat.com> (raw)
In-Reply-To: <20160318151907.GD5515@noname.redhat.com>
On Fri, Mar 18, 2016 at 04:19:07PM +0100, Kevin Wolf wrote:
> Am 18.03.2016 um 15:45 hat Daniel P. Berrange geschrieben:
> > On Fri, Mar 18, 2016 at 01:09:35PM +0100, Kevin Wolf wrote:
> > > Am 17.03.2016 um 18:51 hat Daniel P. Berrange geschrieben:
> > > > + ret = bdrv_co_readv(bs->file->bs,
> > > > + payload_offset + sector_num,
> > > > + cur_nr_sectors, &hd_qiov);
> > > > + qemu_co_mutex_lock(&crypto->lock);
> > > > + if (ret < 0) {
> > > > + goto cleanup;
> > > > + }
> > > > +
> > > > + if (qcrypto_block_decrypt(crypto->block,
> > > > + sector_num,
> > > > + cipher_data, cur_nr_sectors * 512,
> > > > + NULL) < 0) {
> > > > + ret = -1;
> > >
> > > Need a real -errno code here.
> > >
> > > > + goto cleanup;
> > > > + }
> > >
> > > ...nor is there one between here and the end of the function.
> > >
> > > So what does this CoMutex protect? If qcrypto_block_decrypt() needs this
> > > for some reason (it doesn't seem to be touching anything that isn't per
> > > request, but maybe I'm missing something), would it be clearer to put
> > > the locking only around that call?
> >
> > This just a result of me blindly copying the locking pattern from
> > qcow2.c qcow2_co_readv() method without really understanding what
> > it was protecting.
>
> qcow2 protects a few fields in BDRVQcow2State and metadata that is used
> and possibly modified by requests. For example, after reading in some
> metadata, another request could make changes that invalidate it, and we
> need to protect against that.
>
> I don't see that the crypto driver relies on any global (i.e. not
> per-request) state either in memory or on disk, except for things that
> are never changed after open, so the lock might not be needed.
Actually it does have global state - the QCryptoCipher object that's
into the QCryptoBlock object must not be used concurrently by multiple
threads, as each thread will need to initialize different IV data.
> > If it not possible for two calls to bdrv_co_readv() to run in
> > parallel, then I can drop this mutex.
>
> They can. The obvious yield point where a coroutine switch can happen is
> the bdrv_co_readv() call above (but you already unlock for that one).
> Unless qcrypto_block_decrypt() does some I/O internally, we can't have
> any other yield points.
Ok, so we do need the mutex then to protect the cipher object state
against concurrent use.
> > > > +BlockDriver bdrv_crypto_luks = {
> > > > + .format_name = "luks",
> > > > + .instance_size = sizeof(BlockCrypto),
> > > > + .bdrv_probe = block_crypto_probe_luks,
> > > > + .bdrv_open = block_crypto_open_luks,
> > > > + .bdrv_close = block_crypto_close,
> > > > + .bdrv_create = block_crypto_create_luks,
> > > > + .create_opts = &block_crypto_create_opts_luks,
> > > > +
> > > > + .bdrv_co_readv = block_crypto_co_readv,
> > > > + .bdrv_co_writev = block_crypto_co_writev,
> > > > + .bdrv_getlength = block_crypto_getlength,
> > > > +};
> > >
> > > Rather minimalistic, but we can always add the missing functions later.
> >
> > Do you have any recommendations on which are top priority / important
> > callbacks to add support for so I can prioritize future effort.
>
> Hm... I was thinking of has_zero_init/discard/get_block_status, but I'm
> not sure how interesting that really is with encryption.
>
> In theory, we could discard with undefined contents as the result, if we
> don't mind that we would be exposing that information (on the other
> hand, encrypted qcow2 images will expose it, too). And you have to
> enable unmap manually anyway.
>
> Efficient zero write is out of question, I'm afraid.
>
> The other thing that would be nice are several functions that provide
> information about the image, like refresh_limits, bdrv_info, etc.
Ok, I'll have a look at these.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
next prev parent reply other threads:[~2016-03-18 15:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-17 17:51 [Qemu-devel] [PATCH v5 0/7] Add new LUKS block driver (for 2.6) Daniel P. Berrange
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 1/7] block: add flag to indicate that no I/O will be performed Daniel P. Berrange
2016-03-18 11:01 ` Kevin Wolf
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 2/7] qemu-img/qemu-io: don't prompt for passwords if not required Daniel P. Berrange
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 3/7] tests: redirect stderr to stdout for iotests Daniel P. Berrange
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 4/7] tests: refactor python I/O tests helper main method Daniel P. Berrange
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 5/7] tests: add output filter to python I/O tests helper Daniel P. Berrange
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 6/7] block: add generic full disk encryption driver Daniel P. Berrange
2016-03-18 12:09 ` Kevin Wolf
2016-03-18 14:45 ` Daniel P. Berrange
2016-03-18 15:19 ` Kevin Wolf
2016-03-18 15:37 ` Daniel P. Berrange [this message]
2016-03-18 15:46 ` Daniel P. Berrange
2016-03-23 20:44 ` Eric Blake
2016-03-17 17:51 ` [Qemu-devel] [PATCH v5 7/7] block: drop support for using qcow[2] encryption with system emulators Daniel P. Berrange
2016-03-18 12:11 ` Kevin Wolf
2016-03-18 12:18 ` Daniel P. Berrange
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=20160318153712.GK17895@redhat.com \
--to=berrange@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.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
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.