[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 5/5] libvhost-user: handle removal of identical regions
|
From: |
Raphael Norwitz |
|
Subject: |
Re: [PATCH v2 5/5] libvhost-user: handle removal of identical regions |
|
Date: |
Mon, 10 Jan 2022 22:38:46 +0000 |
|
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Mon, Jan 10, 2022 at 09:58:01AM +0100, David Hildenbrand wrote:
> On 06.01.22 07:47, Raphael Norwitz wrote:
> > Today if QEMU (or any other VMM) has sent multiple copies of the same
> > region to a libvhost-user based backend and then attempts to remove the
> > region, only one instance of the region will be removed, leaving stale
> > copies of the region in dev->regions[].
> >
> > This change resolves this by having vu_rem_mem_reg() iterate through all
> > regions in dev->regions[] and delete all matching regions.
> >
> > Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
> > Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
> > ---
> > subprojects/libvhost-user/libvhost-user.c | 26 ++++++++++++-----------
> > 1 file changed, 14 insertions(+), 12 deletions(-)
> >
> > diff --git a/subprojects/libvhost-user/libvhost-user.c
> > b/subprojects/libvhost-user/libvhost-user.c
> > index 0fe3aa155b..14482484d3 100644
> > --- a/subprojects/libvhost-user/libvhost-user.c
> > +++ b/subprojects/libvhost-user/libvhost-user.c
> > @@ -809,6 +809,7 @@ static bool
> > vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
> > VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region =
> > &m;
> > int i;
> > + bool found = false;
> >
> > if (vmsg->fd_num != 1 ||
> > vmsg->size != sizeof(vmsg->payload.memreg)) {
> > @@ -835,21 +836,22 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
> > munmap(m, r->size + r->mmap_offset);
> > }
> >
> > - break;
> > + /*
> > + * Shift all affected entries by 1 to close the hole at index
> > i and
> > + * zero out the last entry.
> > + */
> > + memmove(dev->regions + i, dev->regions + i + 1,
> > + sizeof(VuDevRegion) * (dev->nregions - i - 1));
> > + memset(dev->regions + dev->nregions - 1, 0,
> > sizeof(VuDevRegion));
> > + DPRINT("Successfully removed a region\n");
> > + dev->nregions--;
> > + i--;
> > +
> > + found = true;
>
> Maybe add a comment like
>
> /* Continue the search for eventual duplicates. */
Ack - I'll add it.
>
>
> --
> Thanks,
>
> David / dhildenb
>
- Re: [PATCH v2 1/5] libvhost-user: Add vu_rem_mem_reg input validation, (continued)
[PATCH v2 2/5] libvhost-user: Add vu_add_mem_reg input validation, Raphael Norwitz, 2022/01/06
[PATCH v2 3/5] libvhost-user: Simplify VHOST_USER_REM_MEM_REG, Raphael Norwitz, 2022/01/06
[PATCH v2 5/5] libvhost-user: handle removal of identical regions, Raphael Norwitz, 2022/01/06
[PATCH v2 4/5] libvhost-user: prevent over-running max RAM slots, Raphael Norwitz, 2022/01/06
Re: [PATCH v2 0/5] Clean up error handling in libvhost-user memory mapping, David Hildenbrand, 2022/01/10
Re: [PATCH v2 0/5] Clean up error handling in libvhost-user memory mapping, Stefan Hajnoczi, 2022/01/10