RE: [PATCH v2 1/1] vhost: tolerate file descriptor in REM_MEM_REG msg
"Bathija, Pravin" <[email protected]> Fri, 31 Jul 2026 07:07:28 +0000
| Newsgroups | org.dpdk.dev |
|---|---|
| Message-ID | <IA0PPF659BD4C466F2C7E46C7DF91081BF6F5C82@IA0PPF659BD4C46.namprd19.prod.outlook.com> |
Internal Use - Confidential > -----Original Message----- > From: David Marchand <[email protected]> > Sent: Thursday, July 30, 2026 11:22 PM > To: Bathija, Pravin <[email protected]>; stephen= AEA-networkplumber.org > Cc: [email protected]; [email protected]; > [email protected]; [email protected]; thomas@= monjalon.net > Subject: Re: [PATCH v2 1/1] vhost: tolerate file descriptor i= n REM_MEM_REG > msg > > > [EXTERNAL EMAIL] > > On Fri, 31 Jul 2026 at 05:14, <[email protected]> w= rote: > > > > From: Pravin M Bathija <[email protected]> > > > > The vhost-user specification (vhost-user.rst) states that no fi= le > > descriptors SHOULD be passed with VHOST_USER_REM_ME= M_REG. > However, it > > also says: "For compatibility with existing incorrect imple= mentations, > > the back-end MAY accept messages with one file descriptor. If = a file > > descriptor is passed, the back-end MUST close it without using = it > > otherwise." > > > > Some front-ends, notably libblkio, reuse the same message-build= ing > > helper for both ADD_MEM_REG and REM_MEM_REG and= unconditionally > attach > > the mapping fd. The previous implementation rejected any REM F8-MEM_REG > > carrying a file descriptor with the error: > > > > expect 0 FDs for request VHOST_USER_REM_MEM= _REG, received 1 > > > > This broke teardown and memory region hot-swap with these front= -ends. > > > > To reproduce, run any libblkio (v1.5.0) application using the > > virtio-blk-vhost-user driver against a DPDK vhost back-end. Th= e > > connection is dropped during cleanup or whenever a memory regio= n is > > unmapped and remapped. > > Is libblkio fixed now? > > I am not a fan of such compatibility fix, having to accept one buggy = client... > Yes, the libblkio fix is ready and will be submitted upstream within a day = or so. It stops sending the fd with REM_MEM_REG. That said, this DPDK fix stands on its own regardless of libblkio. The vhos= t-user specification explicitly anticipates this situation and requires back-ends = to handle it: "For compatibility with existing incorrect implementations, the back-en= d MAY accept messages with one file descriptor. If a file descriptor is passed, the back-end MUST= close it without using it otherwise." While the immediate motivation was libblkio, the spec's compatibility claus= e was written for exactly this situation — any front-end could make the same mistake. QEM= U's libvhost-user reference implementation already tolerates it (see vu_rem_mem_r= eg). The fix is 2 lines with no downside: accept the message, close the fd. Reje= cting it drops the connection entirely, which is a disproportionate response to a harmless ext= ra fd. > > > > QEMU's libvhost-user reference back-end (vu_rem_mem_= -reg) already > > tolerates zero or one fd in this message. Align DPDK's behavio= r with > > both the specification's compatibility clause and the reference > > implementation by accepting the message and closing any unexpec= ted fd. > > > > Tested with: > > - QEMU VM bring-up with runtime add/remove memory regions via > > QEMU monitor > > - QEMU post-copy live migration between source and destination > > - SPDK vhost-blk with libblkio (fio libblkio engine, write + = md5 > > verify) > > - libblkio alloc-mem-region and map-mem-region tests exercisin= g > > ADD_MEM_REG / REM_MEM_REG / ADD_MEM_= REG cycles against SPDK > > vhost-blk > > > > Fixes: 1d730eea6a42 ("vhost: add memory region handlers"= -) > > Cc: [email protected] > > > > Signed-off-by: Pravin M Bathija <[email protected]= m> > > --- > > doc/guides/rel_notes/release_26_07.rst | 8 += -++++++ > > lib/vhost/vhost_user.c | 9 +++++= -++- > > 2 files changed, 16 insertions(+), 1 deletion(-) > > > > diff --git a/doc/guides/rel_notes/release_26_07.rst > > b/doc/guides/rel_notes/release_26_07.rst > > index 3d18ba2dd0..86042bd5e3 100644 > > --- a/doc/guides/rel_notes/release_26_07.rst > > +++ b/doc/guides/rel_notes/release_26_07.rst > > We are working on 26.*11* ... > > > > @@ -85,6 +85,14 @@ New Features > > to support adding and removing memory regions without resett= ing > > the whole guest memory map. > > > > +* **Fixed vhost REM_MEM_REG compatibility w= ith front-ends sending > > +file descriptors.** > > + > > + The vhost-user ``REM_MEM_REG`` message = handler now tolerates an > > + unexpected file descriptor sent by the front-end, closing i= t > > + without use as permitted by the vhost-user specification. > > + This fixes interoperability with front-ends such as libblki= o that > > + unconditionally attach a file descriptor to the message. > > + > > ... and regardless of the version this was put in, this is not a feat= ure. > > We usually don't put Fixes: in RN. > The AI bot nags too much. > > > -- > David Marchand