Received: from eggs.gnu.org ([2001:4830:134:3::10]:46689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bK9xO-0000kJ-Hf for qemu-devel@nongnu.org; Mon, 04 Jul 2016 15:55:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bK9xM-0001TD-Aw for qemu-devel@nongnu.org; Mon, 04 Jul 2016 15:55:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bK9xM-0001T7-2I for qemu-devel@nongnu.org; Mon, 04 Jul 2016 15:55:00 -0400 Date: Mon, 4 Jul 2016 22:54:56 +0300 From: "Michael S. Tsirkin" Message-ID: <20160704225325-mutt-send-email-mst@redhat.com> References: <1467366382-7216-1-git-send-email-saxenap.ltc@gmail.com> <20160704145441-mutt-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 0/2]vhost-user: Extend protocol to seek response for any command. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Prerna Saxena Cc: "qemu-devel@nongnu.org" , Felipe Franciosi , "marcandre.lureau@gmail.com" , Anil Kumar Boggarapu , Prerna Saxena On Mon, Jul 04, 2016 at 04:50:04PM +0000, Prerna Saxena wrote: > Hi Michael, > Thank you for taking a look. >=20 >=20 >=20 >=20 >=20 > On 04/07/16 5:29 pm, "Michael S. Tsirkin" wrote: >=20 > >On Fri, Jul 01, 2016 at 02:46:20AM -0700, Prerna Saxena wrote: > >> From: Prerna Saxena > >>=20 > >> The current vhost-user protocol requires the client to send response= s to only a > >> few commands. For the remaining commands, it is impossible for QEMU = to know the > >> status of the requested operation -- ie, did it succeed? If so, by w= hat time? > >>=20 > >> This is inconvenient, and can also lead to races. As an example: > >>=20 > >> (1) Qemu sends a SET_MEM_TABLE to the backend (eg, a vhost-user net = application). > >> Note that SET_MEM_TABLE does not require a reply according to the sp= ec. > >> (2) Qemu commits the memory to the guest. > >> (3) Guest issues an I/O operation over a new memory region which was= configured on (1). > >> (4) The application hasn't yet remapped the memory, but it sees the = I/O request. > >> (5) The application cannot satisfy the request because it does not k= now about those GPAs. > >>=20 > >> Note that the kernel implementation does not suffer from this limita= tion since messages are sent via an ioctl(). The ioctl() blocks until the= backend (eg. vhost-net) completes the command and returns (with an error= code). > >>=20 > >> Changing the behaviour of current vhost-user commands would break ex= isting applications.=20 > >> To work around this race, Patch 1 adds a get_features command to be = sent before returning from set_mem_table. While this is not a complete fi= x, it will help client applications that strictly process messages in ord= er. > >>=20 > >> The second patch introduces a protocol extension, VHOST_USER_PROTOCO= L_F_REPLY_ACK. This feature, if negotiated, allows QEMU to request a resp= onse to any message by setting the newly introduced "need_response" flag.= The application must then respond to qemu by providing a status about th= e requested operation. > > > > > >OK this all looks very reasonable (and I do like patch 1 too) > >but there's one source of waste here: we do not need to > >synchronize when we set up device the first time > >when hdev->memory_changed is false. > > > >I think we should test that and skip synch in both patches > >unless hdev->memory_changed is set. >=20 > I do not entirely agree with that. The first set_mem_table command is n= ot much different from subsequent set_mem_table calls. > For all cases, there is a fair chance that the vhost-user application m= ay, for some reason, not be able to map the guest memory. > This protocol extension provides a mechanism for such errors to be prop= agated back to QEMU. It is upto QEMU to acknowledge the failure (by termi= nating itself or failing the device) or ignore it. However, in the absenc= e of such a mechanism, it would be really bad for QEMU to believe that th= e vhost application is all set to process guest requests when reality is = quite the opposite. Same applies to any other request in theory. Backend can disconnect if it can not handle a request, this seems sufficient to me. > Also, as pointed out before, QEMU needs to have a notion of _when_ the = memory mapping was finished, so that it may proceed to pass on actual req= uests to the vhost user application. The race described in the covering l= etter (above) can potentially happen even at first-time initialization. >=20 > This protocol extension is an attempt to bridge the subtle behavioural = difference between vhost-user and vhost-kernel. Patch 1, in my opinion, m= akes the code less intuitive. This is because we are calling a GET_FEATUR= ES vhost message from inside the handler for another vhost command=E2=80=94= SET_MEM_TABLE. However, if you think it better to have both Patch 1 & 2,= I=E2=80=99ll be happy to post both. >=20 > Regards, > Prerna >=20 > > > > > >> Changelog: > >> --------- > >> Changes since v1: > >> Patch 1 : Ask for get_features before returning from set_mem_table(n= ew).=20 > >> Patch 2 : * Improve documentation.=20 > >> * Abstract out commonly used operations in the form of a f= unction, process_message_response(). Also implement this only for SET_MEM= _TABLE. > >>=20 > >> Prerna Saxena (2): > >> vhost-user: Attempt to prevent a race on set_mem_table. > >> vhost-user : Introduce a new feature VHOST_USER_PROTOCOL_F_REPLY_A= CK. > >>=20 > >> docs/specs/vhost-user.txt | 40 ++++++++++++ > >> hw/virtio/vhost-user.c | 157 ++++++++++++++++++++++++++++++++---= ----------- > >> 2 files changed, 150 insertions(+), 47 deletions(-) > >>=20 > >> --=20 > >> 1.8.1.2