From: Thomas Huth <thuth@redhat.com>
To: Alexander Bulekov <alxndr@bu.edu>, qemu-devel@nongnu.org
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Mauro Matteo Cascella" <mcascell@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Bandan Das" <bsd@redhat.com>,
"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
"Darren Kenny" <darren.kenny@oracle.com>,
"Bin Meng" <bin.meng@windriver.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Jon Maloy" <jmaloy@redhat.com>, "Siqi Chen" <coc.cyqh@gmail.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Anthony Perard" <anthony.perard@citrix.com>,
"Paul Durrant" <paul@xen.org>, "Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>, "Amit Shah" <amit@kernel.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"John Snow" <jsnow@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Keith Busch" <kbusch@kernel.org>,
"Klaus Jensen" <its@irrelevant.dk>, "Fam Zheng" <fam@euphon.net>,
"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"open list:X86 Xen CPUs" <xen-devel@lists.xenproject.org>,
"open list:virtio-blk" <qemu-block@nongnu.org>,
"open list:i.MX31 (kzm)" <qemu-arm@nongnu.org>,
"open list:Old World (g3beige)" <qemu-ppc@nongnu.org>
Subject: Re: [PATCH v6 4/4] hw: replace most qemu_bh_new calls with qemu_bh_new_guarded
Date: Fri, 10 Mar 2023 11:38:52 +0100 [thread overview]
Message-ID: <289e9e47-be6d-1f7f-b0b6-f5b9ed5bc1e8@redhat.com> (raw)
In-Reply-To: <20230205040737.3567731-5-alxndr@bu.edu>
On 05/02/2023 05.07, Alexander Bulekov wrote:
> This protects devices from bh->mmio reentrancy issues.
>
> Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
> ---
...
> diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
> index 65c4979c3c..f077c1b255 100644
> --- a/hw/9pfs/xen-9p-backend.c
> +++ b/hw/9pfs/xen-9p-backend.c
> @@ -441,7 +441,9 @@ static int xen_9pfs_connect(struct XenLegacyDevice *xendev)
> xen_9pdev->rings[i].ring.out = xen_9pdev->rings[i].data +
> XEN_FLEX_RING_SIZE(ring_order);
>
> - xen_9pdev->rings[i].bh = qemu_bh_new(xen_9pfs_bh, &xen_9pdev->rings[i]);
> + xen_9pdev->rings[i].bh = qemu_bh_new_guarded(xen_9pfs_bh,
> + &xen_9pdev->rings[i],
> + &DEVICE(xen_9pdev)->mem_reentrancy_guard);
xen_9pdev is not derived from DeviceState, so you must not cast it with
DEVICE().
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index 7ce001cacd..37091150cb 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -1508,7 +1508,8 @@ static void ahci_cmd_done(const IDEDMA *dma)
> ahci_write_fis_d2h(ad);
>
> if (ad->port_regs.cmd_issue && !ad->check_bh) {
> - ad->check_bh = qemu_bh_new(ahci_check_cmd_bh, ad);
> + ad->check_bh = qemu_bh_new_guarded(ahci_check_cmd_bh, ad,
> + &DEVICE(ad)->mem_reentrancy_guard);
> qemu_bh_schedule(ad->check_bh);
> }
> }
Dito - ad is not derived from DeviceState, so you cannot use DEVICE() here.
(This was causing the crash in the macOS CI job)
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 5d1039378f..8c8d1a8ec2 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -519,7 +519,8 @@ BlockAIOCB *ide_issue_trim(
>
> iocb = blk_aio_get(&trim_aiocb_info, s->blk, cb, cb_opaque);
> iocb->s = s;
> - iocb->bh = qemu_bh_new(ide_trim_bh_cb, iocb);
> + iocb->bh = qemu_bh_new_guarded(ide_trim_bh_cb, iocb,
> + &DEVICE(s)->mem_reentrancy_guard);
IDEState s is also not directly derived from DeviceState. Not sure, but
maybe you can get to the device here in a similar way that is done in
ide_identify() :
IDEDevice *dev = s->unit ? s->bus->slave : s->bus->master;
?
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index 746f07c4d2..309cebacc6 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -908,8 +908,9 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
> precopy_add_notifier(&s->free_page_hint_notify);
>
> object_ref(OBJECT(s->iothread));
> - s->free_page_bh = aio_bh_new(iothread_get_aio_context(s->iothread),
> - virtio_ballloon_get_free_page_hints, s);
> + s->free_page_bh = aio_bh_new_guarded(iothread_get_aio_context(s->iothread),
> + virtio_ballloon_get_free_page_hints, s,
> + &DEVICE(s)->mem_reentrancy_guard);
You could use "dev" instead of "s" here to get rid of the DEVICE() cast.
The remaining changes look fine to me.
Thomas
next prev parent reply other threads:[~2023-03-10 10:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-05 4:07 [PATCH v6 0/4] memory: prevent dma-reentracy issues Alexander Bulekov
2023-02-05 4:07 ` [PATCH v6 1/4] " Alexander Bulekov
2023-03-10 11:14 ` Fiona Ebner
2023-03-10 12:23 ` Alexander Bulekov
2023-03-10 12:31 ` Alexander Bulekov
2023-03-10 12:45 ` Peter Maydell
2023-03-10 13:02 ` Alexander Bulekov
2023-03-10 13:28 ` Alexander Bulekov
2023-03-10 13:37 ` Peter Maydell
2023-03-10 13:07 ` Mark Cave-Ayland
2023-02-05 4:07 ` [PATCH v6 2/4] async: Add an optional reentrancy guard to the BH API Alexander Bulekov
2023-02-05 4:07 ` [PATCH v6 3/4] checkpatch: add qemu_bh_new/aio_bh_new checks Alexander Bulekov
2023-02-05 4:07 ` [PATCH v6 4/4] hw: replace most qemu_bh_new calls with qemu_bh_new_guarded Alexander Bulekov
2023-03-01 20:54 ` Michael S. Tsirkin
2023-03-02 9:25 ` Paul Durrant
2023-03-08 13:40 ` Alexander Bulekov
2023-03-10 10:38 ` Thomas Huth [this message]
2023-02-13 2:11 ` [PATCH v6 0/4] memory: prevent dma-reentracy issues Alexander Bulekov
2023-02-13 20:26 ` Michael S. Tsirkin
2023-02-16 11:14 ` Thomas Huth
2023-02-28 16:07 ` Alexander Bulekov
2023-02-28 16:28 ` Peter Xu
2023-02-13 14:58 ` Darren Kenny
2023-02-22 14:13 ` Stefan Hajnoczi
2023-03-01 20:55 ` Michael S. Tsirkin
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=289e9e47-be6d-1f7f-b0b6-f5b9ed5bc1e8@redhat.com \
--to=thuth@redhat.com \
--cc=alxndr@bu.edu \
--cc=amit@kernel.org \
--cc=anthony.perard@citrix.com \
--cc=arei.gonglei@huawei.com \
--cc=berrange@redhat.com \
--cc=bin.meng@windriver.com \
--cc=bsd@redhat.com \
--cc=coc.cyqh@gmail.com \
--cc=darren.kenny@oracle.com \
--cc=david@redhat.com \
--cc=dmitry.fleytman@gmail.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=its@irrelevant.dk \
--cc=jasowang@redhat.com \
--cc=jmaloy@redhat.com \
--cc=jsnow@redhat.com \
--cc=kbusch@kernel.org \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mcascell@redhat.com \
--cc=mst@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=stefanha@redhat.com \
--cc=xen-devel@lists.xenproject.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 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).