From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org, mreitz@redhat.com,
kwolf@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH v3 5/5] crypto: support multiple threads accessing one QCryptoBlock
Date: Mon, 10 Dec 2018 14:52:03 +0000 [thread overview]
Message-ID: <20181210145203.GM20272@redhat.com> (raw)
In-Reply-To: <w514lbllblo.fsf@maestria.local.igalia.com>
On Mon, Dec 10, 2018 at 03:06:59PM +0100, Alberto Garcia wrote:
> On Fri 07 Dec 2018 05:13:51 PM CET, Vladimir Sementsov-Ogievskiy wrote:
> > @@ -148,12 +154,97 @@ int qcrypto_block_encrypt(QCryptoBlock *block,
> >
> > QCryptoCipher *qcrypto_block_get_cipher(QCryptoBlock *block)
> > {
> > - return block->cipher;
> > + /* Ciphers should be accessed through pop/push method to be thread-safe.
> > + * Better, they should not be accessed externally at all (note, that
> > + * pop/push are static functions)
> > + * This function is used only in test with one thread (it's safe to skip
> > + * pop/push interface), so it's enough to assert it here:
> > + */
> > + assert(block->n_ciphers <= 1);
> > + return block->ciphers ? block->ciphers[0] : NULL;
>
> If this is only supposed to be called in test mode I think you can also
> assert that g_test_initialized() is true.
>
> And the same with qcrypto_block_get_ivgen() later in this patch.
I consider these APIs as being valid for use anywhere - it just
happens it is only used in the tests right now. So I think it is
ok to assert on n_cipers here.
> > +int qcrypto_block_init_cipher(QCryptoBlock *block,
> > + QCryptoCipherAlgorithm alg,
> > + QCryptoCipherMode mode,
> > + const uint8_t *key, size_t nkey,
> > + size_t n_threads, Error **errp)
> > +{
> > + size_t i;
> > +
> > + assert(!block->ciphers && !block->n_ciphers && !block->n_free_ciphers);
> > +
> > + block->ciphers = g_new0(QCryptoCipher *, n_threads);
>
> You can use g_new() instead of g_new0() because you're anyway
> overwriting all elements of the array.
I'd rather have it initialized to zero upfront, so if creating any
cipher in the array fails, we don't have uninitialized array elements
during later cleanup code.
> But these are minor nits, the patchs looks good to me else.
>
> Reviewed-by: Alberto Garcia <berto@igalia.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2018-12-10 14:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-07 16:13 [Qemu-devel] [PATCH v3 0/5] crypto threads Vladimir Sementsov-Ogievskiy
2018-12-07 16:13 ` [Qemu-devel] [PATCH v3 1/5] crypto/block-luks: fix memory leak in qcrypto_block_luks_create Vladimir Sementsov-Ogievskiy
2018-12-07 16:13 ` [Qemu-devel] [PATCH v3 2/5] crypto/block: refactor qcrypto_block_*crypt_helper functions Vladimir Sementsov-Ogievskiy
2018-12-07 16:13 ` [Qemu-devel] [PATCH v3 3/5] crypto/block: rename qcrypto_block_*crypt_helper Vladimir Sementsov-Ogievskiy
2018-12-10 10:44 ` Alberto Garcia
2018-12-10 13:21 ` Daniel P. Berrangé
2018-12-10 13:24 ` Alberto Garcia
2018-12-07 16:13 ` [Qemu-devel] [PATCH v3 4/5] crypto/block: introduce qcrypto_block_*crypt_helper functions Vladimir Sementsov-Ogievskiy
2018-12-10 10:45 ` Alberto Garcia
2018-12-07 16:13 ` [Qemu-devel] [PATCH v3 5/5] crypto: support multiple threads accessing one QCryptoBlock Vladimir Sementsov-Ogievskiy
2018-12-10 14:06 ` Alberto Garcia
2018-12-10 14:52 ` Daniel P. Berrangé [this message]
2018-12-10 15:09 ` Alberto Garcia
2018-12-10 15:16 ` Daniel P. Berrangé
2018-12-10 15:24 ` Alberto Garcia
2018-12-10 15:19 ` [Qemu-devel] [PATCH v3 0/5] crypto threads Daniel P. Berrangé
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=20181210145203.GM20272@redhat.com \
--to=berrange@redhat.com \
--cc=berto@igalia.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@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.