Cornelia Huck
2023-Sep-27 10:08 UTC
[PATCH] crypto: virtio-crypto: call finalize with bh disabled
On Tue, Sep 26 2023, Halil Pasic <pasic at linux.ibm.com> wrote:> [..] >> --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c >> +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c >> @@ -61,8 +61,9 @@ static void virtio_crypto_akcipher_finalize_req( >> vc_akcipher_req->src_buf = NULL; >> vc_akcipher_req->dst_buf = NULL; >> virtcrypto_clear_request(&vc_akcipher_req->base); >> - >> + local_bh_disable(); >> crypto_finalize_akcipher_request(vc_akcipher_req->base.dataq->engine, req, err); >> + local_bh_enable(); > > Thanks Gonglei! > > I did this a quick spin, and it does not seem to be sufficient on s390x. > Which does not come as a surprise to me, because > > #define lockdep_assert_in_softirq() \ > do { \ > WARN_ON_ONCE(__lockdep_enabled && \ > (!in_softirq() || in_irq() || in_nmi())); \ > } while (0) > > will still warn because in_irq() still evaluates to true (your patch > addresses the !in_softirq() part). > > I don't have any results on x86 yet. My current understanding is that the > virtio-pci transport code disables interrupts locally somewhere in the > call chain (actually in vp_vring_interrupt() via spin_lock_irqsave()) > and then x86 would be fine. But I will get that verified. > > On the other hand virtio_airq_handler() calls vring_interrupt() with > interrupts enabled. (While vring_interrupt() is called in a (read) > critical section in virtio_airq_handler() we use read_lock() and > not read_lock_irqsave() to grab the lock. Whether that is correct in > it self (i.e. disregarding the crypto problem) or not I'm not sure right > now. Will think some more about it tomorrow.) If the way to go forward > is disabling interrupts in virtio-ccw before vring_interrupt() is > called, I would be glad to spin a patch for that.virtio_airq_handler() is supposed to be an interrupt handler for an adapter interrupt -- as such I would expect it to always run with interrupts disabled (and I'd expect vring_interrupt() to be called with interrupts disabled as well; if that's not the case, I think it would need to run asynchronously.) At least that was my understanding at the time I wrote the code.> > Copying Conny, as she may have an opinion on this (if I'm not wrong she > authored that code). > > Regards, > Halil
Halil Pasic
2023-Sep-27 11:25 UTC
[PATCH] crypto: virtio-crypto: call finalize with bh disabled
On Wed, 27 Sep 2023 12:08:43 +0200 Cornelia Huck <cohuck at redhat.com> wrote:> > On the other hand virtio_airq_handler() calls vring_interrupt() with > > interrupts enabled. (While vring_interrupt() is called in a (read) > > critical section in virtio_airq_handler() we use read_lock() and > > not read_lock_irqsave() to grab the lock. Whether that is correct in > > it self (i.e. disregarding the crypto problem) or not I'm not sure right > > now. Will think some more about it tomorrow.) If the way to go forward > > is disabling interrupts in virtio-ccw before vring_interrupt() is > > called, I would be glad to spin a patch for that. > > virtio_airq_handler() is supposed to be an interrupt handler for an > adapter interrupt -- as such I would expect it to always run with > interrupts disabled (and I'd expect vring_interrupt() to be called > with interrupts disabled as well; if that's not the case, I think it > would need to run asynchronously.) At least that was my understanding at > the time I wrote the code.Thanks Connie! I don't quite understand what do you mean by "run with interrupts disabled" in this context. Do you mean that if I were to add the following warning: diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c index ac67576301bf..2a9c73f5964f 100644 --- a/drivers/s390/virtio/virtio_ccw.c +++ b/drivers/s390/virtio/virtio_ccw.c @@ -211,6 +211,8 @@ static void virtio_airq_handler(struct airq_struct *airq, struct airq_info *info = container_of(airq, struct airq_info, airq); unsigned long ai; + WARN_ONCE(in_irq(), "irqs are ought to be disabled but are not\n"); + inc_irq_stat(IRQIO_VAI); it would/should never trigger, or do you mean something different? If yes, does that mean that you would expect the common airq code (i.e. something like do_airq_interrupt()) to disable interrupts, or call virtio_airq_handler()? asynchronously sort of as a bottom half (my understanding of bottom halves is currently not complete). If no what do you actually mean? Regards, Halil Regards, Halil