[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 5/9] char: forbid direct chardevice access fo
From: |
Marc-André Lureau |
Subject: |
Re: [Qemu-devel] [PATCH v2 5/9] char: forbid direct chardevice access for hotswap devices |
Date: |
Thu, 25 May 2017 14:31:11 +0000 |
On Fri, May 19, 2017 at 4:49 PM Anton Nefedov <address@hidden>
wrote:
> qemu_chr_fe_get_driver() is unsafe, frontends with hotswap support
> should not access CharDriver ptr directly as CharDriver might change.
>
Signed-off-by: Anton Nefedov <address@hidden>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
>
I would move this patch up in the series, otherwise looks good
> ---
> chardev/char.c | 7 +++++++
> include/sysemu/char.h | 10 ++++++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/chardev/char.c b/chardev/char.c
> index 0483f19..36d6f36 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -484,9 +484,16 @@ static Notifier muxes_realize_notify = {
>
> Chardev *qemu_chr_fe_get_driver(CharBackend *be)
> {
> + /* this is unsafe for the users that support chardev hotswap */
> + assert(be->chr_be_change == NULL);
> return be->chr;
> }
>
> +bool qemu_chr_fe_backend_connected(CharBackend *be)
> +{
> + return !!be->chr;
> +}
> +
> static bool fe_connect(CharBackend *b, Chardev *s, Error **errp)
> {
> int tag = 0;
> diff --git a/include/sysemu/char.h b/include/sysemu/char.h
> index 92ae57e..fa21535 100644
> --- a/include/sysemu/char.h
> +++ b/include/sysemu/char.h
> @@ -404,10 +404,20 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s,
> Error **errp);
> *
> * Returns the driver associated with a CharBackend or NULL if no
> * associated Chardev.
> + * Note: avoid this function as the driver should never be accessed
> directly,
> + * especially by the frontends that support chardevice hotswap.
> + * Consider qemu_chr_fe_backend_connected() to check for driver
> existence
> */
> Chardev *qemu_chr_fe_get_driver(CharBackend *be);
>
> /**
> + * @qemu_chr_fe_backend_connected:
> + *
> + * Returns true if there is a chardevice associated with @be.
> + */
> +bool qemu_chr_fe_backend_connected(CharBackend *be);
> +
> +/**
> * @qemu_chr_fe_deinit:
> *
> * Dissociate the CharBackend from the Chardev.
> --
> 2.7.4
>
>
> --
Marc-André Lureau
- [Qemu-devel] [PATCH v2 0/9] chardevice hotswap, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 1/9] char: move QemuOpts->ChardevBackend translation to a separate func, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 4/9] hmp: add hmp analogue for qmp-chardev-change, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 5/9] char: forbid direct chardevice access for hotswap devices, Anton Nefedov, 2017/05/19
- Re: [Qemu-devel] [PATCH v2 5/9] char: forbid direct chardevice access for hotswap devices,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v2 6/9] virtio-console: chardev hotswap support, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 3/9] char: chardevice hotswap, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 2/9] char: add backend hotswap handler, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 8/9] serial: chardev hotswap support, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 7/9] serial: move TIOCM update to a separate function, Anton Nefedov, 2017/05/19
- [Qemu-devel] [PATCH v2 9/9] char: avoid chardevice direct access, Anton Nefedov, 2017/05/19