From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id D420C3230 for ; Mon, 25 Sep 2017 06:46:48 +0200 (CEST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP; 24 Sep 2017 21:46:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,435,1500966000"; d="scan'208";a="131966918" Received: from debian-zgviawfucg.sh.intel.com (HELO debian-ZGViaWFuCg) ([10.67.104.151]) by orsmga004.jf.intel.com with ESMTP; 24 Sep 2017 21:46:46 -0700 Date: Mon, 25 Sep 2017 12:46:51 +0800 From: Tiwei Bie To: Yi Yang Cc: yliu@fridaylinux.org, dev@dpdk.org Message-ID: <20170925044651.GA18891@debian-ZGViaWFuCg> References: <1505896323-125943-1-git-send-email-yi.y.yang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1505896323-125943-1-git-send-email-yi.y.yang@intel.com> User-Agent: Mutt/1.7.2 (2016-11-26) Subject: Re: [dpdk-dev] [PATCH] vhost: fix vhost_user_set_mem_table error X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Sep 2017 04:46:49 -0000 Hi Yi, On Wed, Sep 20, 2017 at 04:32:03PM +0800, Yi Yang wrote: > Usually vhost_user message VHOST_USER_SET_MEM_TABLE > is only sent out during initialization and only sent > once, but it isn't so for memory hotplug and hotunplug > , for that case, vhost_user message VHOST_USER_SET_MEM_TABLE > will be resent with the old memory regions (not hotunplugged) > and the new memory regions (hotplugged), so current > vhost_user_set_mem_table implementation is wrong for > memory hotplug and hotunplug case, it will free current > memory regions and unmap hugepages no matter if they > are be using or not and if they are memory regions which > have been initialized and mapped in the previous vhost_user > message VHOST_USER_SET_MEM_TABLE or not. > > This commit fixed this issue very well, it will keep them > intact for those old memory region it will unmap those > memroy regions if they have been hotunplugged, it will > initialize the new hotplugged memory regions and map > hugepages if they are hotplugged. > > vhost_user message VHOST_USER_SET_MEM_TABLE will include > all the current effective memory regions, the hotunplugged > memory regions won't be included in VHOST_USER_SET_MEM_TABLE, > the hotplugged memroy regions will be included in > VHOST_USER_SET_MEM_TABLE. > > This has been verified in OVS DPDK by memory hotplug and > hotunplug in qemu. > > Signed-off-by: Yi Yang > --- > lib/librte_vhost/vhost_user.c | 72 ++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 65 insertions(+), 7 deletions(-) > > diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c > index ad2e8d3..1c475d1 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c [...] > @@ -532,7 +558,7 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) > } > } > > - dev->mem = rte_zmalloc("vhost-mem-table", sizeof(struct rte_vhost_memory) + > + dev->mem = rte_realloc(dev->mem, sizeof(struct rte_vhost_memory) + The rte_realloc() will free the memory pointed by the dev->mem. But it's possible that some other threads are using it (e.g. by calling rte_vhost_gpa_to_vva()). It's an issue that needs to be fixed in this patch. Best regards, Tiwei Bie