From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: Hanna Reitz <hreitz@redhat.com>, qemu-block@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
qemu-devel@nongnu.org, "John Snow" <jsnow@redhat.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Greg Kurz" <groug@kaod.org>,
qemu-ppc@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Denis V. Lunev" <den@openvz.org>,
"Eric Blake" <eblake@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH v6 32/33] crypto: delegate permission functions to JobDriver .pre_run
Date: Fri, 28 Jan 2022 17:57:52 +0100 [thread overview]
Message-ID: <eeec5f93-f38f-4f83-632e-a6f574e82b06@redhat.com> (raw)
In-Reply-To: <49d12b8b-cf53-06cb-de26-d4e8f03a8e04@redhat.com>
On 26/01/2022 17:10, Hanna Reitz wrote:
> On 21.01.22 18:05, Emanuele Giuseppe Esposito wrote:
>> block_crypto_amend_options_generic_luks uses the block layer
>> permission API, therefore it should be called with the BQL held.
>>
>> However, the same function is being called by two BlockDriver
>> callbacks: bdrv_amend_options (under BQL) and bdrv_co_amend (I/O).
>>
>> The latter is I/O because it is invoked by block/amend.c's
>> blockdev_amend_run(), a .run callback of the amend JobDriver
>>
>> Therefore we want to 1) change block_crypto driver
>> to use the permission API only when the BQL is held, and
>> 2) use the .pre_run JobDriver callback to check for
>> permissions before switching to the job aiocontext. This has also
>> the benefit of applying the same permission operation to all
>> amend implementations, not only luks.
>>
>> Remove the permission check in block_crypto_amend_options_generic_luks()
>> and:
>> - Add helper functions block_crypto_amend_options_{prepare/cleanup}
>> that take care of checking permissions in
>> block_crypto_amend_options_luks(), so when it is under BQL, and
>>
>> - Use job->pre_run() and job->clean() to do the same thing when
>> we are in an iothread, by performing these checks before the
>> job runs in its aiocontext. So far job->pre_run() is only defined
>> but not called in job_start(), now it is the moment to use it.
>>
>> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
>> ---
>> block/crypto.c | 57 ++++++++++++++++++++++++++++++++------------------
>> job.c | 13 ++++++++++++
>> 2 files changed, 50 insertions(+), 20 deletions(-)
>>
>> diff --git a/block/crypto.c b/block/crypto.c
>> index f5e0c7b7c0..bdb4ba5664 100644
>> --- a/block/crypto.c
>> +++ b/block/crypto.c
>> @@ -791,6 +791,28 @@ block_crypto_amend_cleanup(BlockDriverState *bs)
>> crypto->updating_keys = false;
>> }
>> +static int
>> +block_crypto_amend_options_prepare(BlockDriverState *bs,
>> + Error **errp)
>> +{
>> + BlockCrypto *crypto = bs->opaque;
>> +
>> + /* apply for exclusive read/write permissions to the underlying
>> file*/
>> + crypto->updating_keys = true;
>> + return bdrv_child_refresh_perms(bs, bs->file, errp);
>> +}
>> +
>> +static int
>> +block_crypto_amend_options_cleanup(BlockDriverState *bs,
>> + Error **errp)
>> +{
>> + BlockCrypto *crypto = bs->opaque;
>> +
>> + /* release exclusive read/write permissions to the underlying file*/
>> + crypto->updating_keys = false;
>> + return bdrv_child_refresh_perms(bs, bs->file, errp);
>> +}
>> +
>
> Now that I have this patch applied, it does look like it would be nicer
> if we could skip adding these functions and just reuse
> block_crypto_amend_{pre_run,cleanup}() (which would require them to call
> bdrv_child_refresh_perms()).
>
>> static int
>> block_crypto_amend_options_generic_luks(BlockDriverState *bs,
>> QCryptoBlockAmendOptions
>> *amend_options,
>> @@ -798,30 +820,17 @@
>> block_crypto_amend_options_generic_luks(BlockDriverState *bs,
>> Error **errp)
>> {
>> BlockCrypto *crypto = bs->opaque;
>> - int ret;
>> assert(crypto);
>> assert(crypto->block);
>> - /* apply for exclusive read/write permissions to the underlying
>> file*/
>> - crypto->updating_keys = true;
>> - ret = bdrv_child_refresh_perms(bs, bs->file, errp);
>> - if (ret) {
>> - goto cleanup;
>> - }
>> -
>> - ret = qcrypto_block_amend_options(crypto->block,
>> - block_crypto_read_func,
>> - block_crypto_write_func,
>> - bs,
>> - amend_options,
>> - force,
>> - errp);
>> -cleanup:
>> - /* release exclusive read/write permissions to the underlying file*/
>> - crypto->updating_keys = false;
>> - bdrv_child_refresh_perms(bs, bs->file, errp);
>> - return ret;
>> + return qcrypto_block_amend_options(crypto->block,
>> + block_crypto_read_func,
>> + block_crypto_write_func,
>> + bs,
>> + amend_options,
>> + force,
>> + errp);
>> }
>> static int
>> @@ -847,8 +856,16 @@ block_crypto_amend_options_luks(BlockDriverState
>> *bs,
>> if (!amend_options) {
>> goto cleanup;
>> }
>> +
>> + ret = block_crypto_amend_options_prepare(bs, errp);
>> + if (ret) {
>> + goto perm_cleanup;
>> + }
>> ret = block_crypto_amend_options_generic_luks(bs, amend_options,
>> force, errp);
>> +
>> +perm_cleanup:
>> + block_crypto_amend_options_cleanup(bs, errp);
>
> Uh, pre-existing but still dangerous. We must not pass @errp here,
> because it may (and if we come from ..._prepare() failing, s/may/will/)
> already contain some error, and then, if this fails (which it very
> likely will not), we will get an assertion failure in error_setv().
>
> We could decide that this must not fail and pass &error_abort (but then
> block_crypto_amend_options_cleanup() should do that), or we pass some
> new guaranteed-empty pointer and report it.
>
> In any case, we should probably have
> block_crypto_amend_options_cleanup() (or block_crypto_amend_cleanup())
> handle this and have that function return void and no error, so we don’t
> have to worry about that here at all.
Applied all feedback on crypto and amend (patches 30, 31, 32).
All what you said makes sense.
>
>> cleanup:
>> qapi_free_QCryptoBlockAmendOptions(amend_options);
>> return ret;
>> diff --git a/job.c b/job.c
>> index 39bf511949..cf0dc9325a 100644
>> --- a/job.c
>> +++ b/job.c
>> @@ -967,11 +967,24 @@ static void coroutine_fn job_co_entry(void *opaque)
>> aio_bh_schedule_oneshot(qemu_get_aio_context(), job_exit, job);
>> }
>> +static int job_pre_run(Job *job)
>> +{
>> + assert(qemu_in_main_thread());
>> + if (job->driver->pre_run) {
>> + return job->driver->pre_run(job, &job->err);
>> + }
>> +
>> + return 0;
>> +}
>> +
>> void job_start(Job *job)
>> {
>> assert(job && !job_started(job) && job->paused &&
>> job->driver && job->driver->run);
>> job->co = qemu_coroutine_create(job_co_entry, job);
>> + if (job_pre_run(job)) {
>> + return;
>
> Do we not need to announce the error somehow? Like, perhaps
> job_pre_run() should set job->ret to the value returned by .pre_run()
> (like job_co_entry() does it for .run()), and then call job_completed()
> on error (or even job_exit()? I’m not sure :/).
>
> The way it is, it looks like the job will just basically leak on error,
> and never complete.
>
I will do something like this:
1. move job_pre_run to run just before aio_co_enter() in job_start(),
because it must be in JOB_STATUS_RUNNING otherwise the transition status
in job_exit functions won't probably work.
Basically simulate as .run() just finished and failed.
2. change in this
+ ret = job->driver->pre_run(job, &job->err);
+ if (ret) {
+ job->ret = ret;
+ job_exit(job);
+ return ret;
+ }
basically cache the reply of pre_run, and if it's non-zero, set job->ret
and exit, just as job_co_entry does.
Thank you,
Emanuele
> Hanna
>
>> + }
>> job->pause_count--;
>> job->busy = true;
>> job->paused = false;
>
next prev parent reply other threads:[~2022-01-28 17:11 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-21 17:05 [PATCH v6 00/33] block layer: split block APIs in global state and I/O Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 01/33] main-loop.h: introduce qemu_in_main_thread() Emanuele Giuseppe Esposito
2022-01-27 10:56 ` Kevin Wolf
2022-01-31 11:25 ` Emanuele Giuseppe Esposito
2022-01-31 14:33 ` Kevin Wolf
2022-01-31 15:49 ` Paolo Bonzini
2022-02-01 9:08 ` Emanuele Giuseppe Esposito
2022-02-01 10:41 ` Paolo Bonzini
2022-02-01 11:55 ` Kevin Wolf
2022-02-01 12:10 ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 02/33] include/block/block: split header into I/O and global state API Emanuele Giuseppe Esposito
2022-01-27 11:01 ` Kevin Wolf
2022-01-31 13:40 ` Emanuele Giuseppe Esposito
2022-01-31 14:54 ` Kevin Wolf
2022-01-31 15:58 ` Paolo Bonzini
2022-02-01 9:45 ` Emanuele Giuseppe Esposito
2022-02-01 10:30 ` Paolo Bonzini
2022-02-07 16:53 ` Kevin Wolf
2022-02-08 10:50 ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 03/33] assertions for block " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 04/33] block/export/fuse.c: allow writable exports to take RESIZE permission Emanuele Giuseppe Esposito
2022-01-25 16:51 ` Hanna Reitz
2022-01-28 14:44 ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 05/33] include/sysemu/block-backend: split header into I/O and global state (GS) API Emanuele Giuseppe Esposito
2022-02-07 17:04 ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 06/33] block/block-backend.c: assertions for block-backend Emanuele Giuseppe Esposito
2022-01-26 9:02 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 07/33] include/block/block_int: split header into I/O and global state API Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 08/33] assertions for block_int " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 09/33] block: introduce assert_bdrv_graph_writable Emanuele Giuseppe Esposito
2022-02-07 17:14 ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 10/33] include/block/blockjob_int.h: split header into I/O and GS API Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 11/33] assertions for blockjob_int.h Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 12/33] block.c: add assertions to static functions Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 13/33] include/block/blockjob.h: global state API Emanuele Giuseppe Esposito
2022-02-07 17:26 ` Kevin Wolf
2022-02-08 10:50 ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 14/33] assertions for blockjob.h " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 15/33] include/sysemu/blockdev.h: " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 16/33] assertions for blockdev.h " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 17/33] include/block/snapshot: global state API + assertions Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 18/33] block/copy-before-write.h: " Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 19/33] block: introduce bdrv_activate Emanuele Giuseppe Esposito
2022-01-26 11:49 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 20/33] block: rename bdrv_invalidate_cache_all, blk_invalidate_cache and test_sync_op_invalidate_cache Emanuele Giuseppe Esposito
2022-01-24 10:44 ` Juan Quintela
2022-01-27 9:18 ` Emanuele Giuseppe Esposito
2022-01-31 15:59 ` Paolo Bonzini
2022-01-26 11:57 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 21/33] block: move BQL logic of bdrv_co_invalidate_cache in bdrv_activate Emanuele Giuseppe Esposito
2022-01-26 12:20 ` Hanna Reitz
2022-01-27 11:03 ` Kevin Wolf
2022-02-02 17:27 ` Paolo Bonzini
2022-02-02 18:27 ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 22/33] block/coroutines: I/O API Emanuele Giuseppe Esposito
2022-02-07 17:36 ` Kevin Wolf
2022-01-21 17:05 ` [PATCH v6 23/33] block_int-common.h: split function pointers in BlockDriver Emanuele Giuseppe Esposito
2022-01-26 12:29 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 24/33] block_int-common.h: assertions in the callers of BlockDriver function pointers Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 25/33] block_int-common.h: split function pointers in BdrvChildClass Emanuele Giuseppe Esposito
2022-01-26 12:42 ` Hanna Reitz
2022-01-28 15:08 ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 26/33] block_int-common.h: assertions in the callers of BdrvChildClass function pointers Emanuele Giuseppe Esposito
2022-01-26 12:46 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 27/33] block-backend-common.h: split function pointers in BlockDevOps Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 28/33] job.h: split function pointers in JobDriver Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 29/33] job.h: assertions in the callers of JobDriver funcion pointers Emanuele Giuseppe Esposito
2022-01-26 14:13 ` Hanna Reitz
2022-01-28 15:19 ` Emanuele Giuseppe Esposito
2022-01-31 8:49 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 30/33] include/block/block_int-common.h: introduce bdrv_amend_pre_run and bdrv_amend_clean Emanuele Giuseppe Esposito
2022-01-26 14:54 ` Hanna Reitz
2022-01-21 17:05 ` [PATCH v6 31/33] include/qemu/job.h: introduce job->pre_run() and use it in amend Emanuele Giuseppe Esposito
2022-01-26 15:57 ` Hanna Reitz
2022-02-07 18:14 ` Kevin Wolf
2022-02-08 11:05 ` Emanuele Giuseppe Esposito
2022-01-21 17:05 ` [PATCH v6 32/33] crypto: delegate permission functions to JobDriver .pre_run Emanuele Giuseppe Esposito
2022-01-24 14:41 ` Paolo Bonzini
2022-01-26 16:10 ` Hanna Reitz
2022-01-28 16:57 ` Emanuele Giuseppe Esposito [this message]
2022-01-21 17:05 ` [PATCH v6 33/33] block.c: assertions to the block layer permissions API Emanuele Giuseppe Esposito
2022-02-07 18:30 ` [PATCH v6 00/33] block layer: split block APIs in global state and I/O Kevin Wolf
2022-02-08 11:42 ` Emanuele Giuseppe Esposito
2022-02-08 13:08 ` Kevin Wolf
2022-02-10 16:19 ` Emanuele Giuseppe Esposito
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=eeec5f93-f38f-4f83-632e-a6f574e82b06@redhat.com \
--to=eesposit@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=den@openvz.org \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=f4bug@amsat.org \
--cc=fam@euphon.net \
--cc=groug@kaod.org \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=quintela@redhat.com \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).