From mboxrd@z Thu Jan 1 00:00:00 1970 From: Maxime Coquelin Subject: Re: [PATCH] vhost: stop device before updating public vring data Date: Tue, 6 Mar 2018 17:26:31 +0100 Message-ID: <94395154-a1cb-486e-d03f-e42a8872fabb@redhat.com> References: <20180305161108.8232-1-tomaszx.kulasek@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: daniel.verkamp@intel.com, james.r.harris@intel.com, pawelx.wodkowski@intel.com, dev@dpdk.org, Dariusz Stojaczyk To: Tomasz Kulasek , yliu@fridaylinux.org Return-path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id 8E8745B12 for ; Tue, 6 Mar 2018 17:26:37 +0100 (CET) In-Reply-To: <20180305161108.8232-1-tomaszx.kulasek@intel.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Tomasz, On 03/05/2018 05:11 PM, Tomasz Kulasek wrote: > For now DPDK assumes that callfd, kickfd and last_idx are being set just > once during vring initialization and device cannot be running while DPDK > receives SET_VRING_KICK, SET_VRING_CALL and SET_VRING_BASE messages. > However, that assumption is wrong. For Vhost SCSI messages might arrive > at any point of time, possibly multiple times, one after another. > > QEMU issues SET_VRING_CALL once during device initialization, then again > during device start. The second message will close previous callfd, > which is still being used by the user-implementation of vhost device. > This results in writing to invalid (closed) callfd. > > Other messages like SET_FEATURES, SET_VRING_ADDR etc also will change > internal state of VQ or device. To prevent race condition device should > also be stopped before updateing vring data. > > Signed-off-by: Dariusz Stojaczyk > Signed-off-by: Pawel Wodkowski > Signed-off-by: Tomasz Kulasek > --- > lib/librte_vhost/vhost_user.c | 40 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) In last release, we have introduced a per-virtqueue lock to protect vring handling against asynchronous device changes. I think that would solve the issue you are facing, but you would need to export the VQs locking functions to the vhost-user lib API to be able to use it. I don't think your current patch is the right solution anyway, because it destroys the device in case we don't want it to remain alive, like set_log_base, or set_features when only the logging feature gets enabled. Cheers, Maxime