From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id C68D6F72 for ; Mon, 21 Dec 2015 16:33:02 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 21 Dec 2015 07:33:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,460,1444719600"; d="scan'208";a="621658235" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by FMSMGA003.fm.intel.com with ESMTP; 21 Dec 2015 07:33:01 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.110.15) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 21 Dec 2015 07:33:01 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.190]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.151]) with mapi id 14.03.0248.002; Mon, 21 Dec 2015 23:32:53 +0800 From: "Xie, Huawei" To: Yuanhan Liu , "dev@dpdk.org" Thread-Topic: [PATCH v2 1/6] vhost: handle VHOST_USER_SET_LOG_BASE request Thread-Index: AQHRPATbtmURE7JOBUePmgVPkbcV6A== Date: Mon, 21 Dec 2015 15:32:53 +0000 Message-ID: References: <1449027793-30975-1-git-send-email-yuanhan.liu@linux.intel.com> <1450321921-27799-1-git-send-email-yuanhan.liu@linux.intel.com> <1450321921-27799-2-git-send-email-yuanhan.liu@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: Victor Kaplansky , "Michael S. Tsirkin" Subject: Re: [dpdk-dev] [PATCH v2 1/6] vhost: handle VHOST_USER_SET_LOG_BASE request X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2015 15:33:03 -0000 On 12/17/2015 11:11 AM, Yuanhan Liu wrote:=0A= > VHOST_USER_SET_LOG_BASE request is used to tell the backend (dpdk=0A= > vhost-user) where we should log dirty pages, and how big the log=0A= > buffer is.=0A= >=0A= > This request introduces a new payload:=0A= >=0A= > typedef struct VhostUserLog {=0A= > uint64_t mmap_size;=0A= > uint64_t mmap_offset;=0A= > } VhostUserLog;=0A= >=0A= > Also, a fd is delivered from QEMU by ancillary data.=0A= >=0A= > With those info given, an area of memory is mmaped, assigned=0A= > to dev->log_base, for logging dirty pages.=0A= >=0A= > Signed-off-by: Yuanhan Liu =0A= > Signed-off-by: Victor Kaplansky ---=0A= >=0A= > v2: workaround mmap issue when offset is not zero=0A= > ---=0A= > lib/librte_vhost/rte_virtio_net.h | 4 ++-=0A= > lib/librte_vhost/vhost_user/vhost-net-user.c | 7 ++--=0A= > lib/librte_vhost/vhost_user/vhost-net-user.h | 6 ++++=0A= > lib/librte_vhost/vhost_user/virtio-net-user.c | 48 +++++++++++++++++++++= ++++++=0A= > lib/librte_vhost/vhost_user/virtio-net-user.h | 1 +=0A= > 5 files changed, 63 insertions(+), 3 deletions(-)=0A= >=0A= > diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_vir= tio_net.h=0A= > index 10dcb90..8acee02 100644=0A= > --- a/lib/librte_vhost/rte_virtio_net.h=0A= > +++ b/lib/librte_vhost/rte_virtio_net.h=0A= > @@ -129,7 +129,9 @@ struct virtio_net {=0A= > char ifname[IF_NAME_SZ]; /**< Name of the tap device or socket path. = */=0A= > uint32_t virt_qp_nb; /**< number of queue pair we have allocated */=0A= > void *priv; /**< private context */=0A= > - uint64_t reserved[64]; /**< Reserve some spaces for future extension. = */=0A= > + uint64_t log_size; /**< Size of log area */=0A= > + uint64_t log_base; /**< Where dirty pages are logged */=0A= > + uint64_t reserved[62]; /**< Reserve some spaces for future extension. = */=0A= > struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2]; /**< Cont= ains all virtqueue information. */=0A= > } __rte_cache_aligned;=0A= > =0A= > diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vh= ost/vhost_user/vhost-net-user.c=0A= > index 8b7a448..32ad6f6 100644=0A= > --- a/lib/librte_vhost/vhost_user/vhost-net-user.c=0A= > +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c=0A= > @@ -388,9 +388,12 @@ vserver_message_handler(int connfd, void *dat, int *= remove)=0A= > break;=0A= > =0A= > case VHOST_USER_SET_LOG_BASE:=0A= > - RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n");=0A= > - break;=0A= > + user_set_log_base(ctx, &msg);=0A= > =0A= > + /* it needs a reply */=0A= > + msg.size =3D sizeof(msg.payload.u64);=0A= > + send_vhost_message(connfd, &msg);=0A= > + break;=0A= > case VHOST_USER_SET_LOG_FD:=0A= > close(msg.fds[0]);=0A= > RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n");=0A= > diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vh= ost/vhost_user/vhost-net-user.h=0A= > index 38637cc..6d252a3 100644=0A= > --- a/lib/librte_vhost/vhost_user/vhost-net-user.h=0A= > +++ b/lib/librte_vhost/vhost_user/vhost-net-user.h=0A= > @@ -83,6 +83,11 @@ typedef struct VhostUserMemory {=0A= > VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];=0A= > } VhostUserMemory;=0A= > =0A= > +typedef struct VhostUserLog {=0A= > + uint64_t mmap_size;=0A= > + uint64_t mmap_offset;=0A= > +} VhostUserLog;=0A= > +=0A= > typedef struct VhostUserMsg {=0A= > VhostUserRequest request;=0A= > =0A= > @@ -97,6 +102,7 @@ typedef struct VhostUserMsg {=0A= > struct vhost_vring_state state;=0A= > struct vhost_vring_addr addr;=0A= > VhostUserMemory memory;=0A= > + VhostUserLog log;=0A= > } payload;=0A= > int fds[VHOST_MEMORY_MAX_NREGIONS];=0A= > } __attribute((packed)) VhostUserMsg;=0A= > diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_v= host/vhost_user/virtio-net-user.c=0A= > index 2934d1c..b77c9b3 100644=0A= > --- a/lib/librte_vhost/vhost_user/virtio-net-user.c=0A= > +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c=0A= > @@ -365,3 +365,51 @@ user_set_protocol_features(struct vhost_device_ctx c= tx,=0A= > =0A= > dev->protocol_features =3D protocol_features;=0A= > }=0A= > +=0A= > +int=0A= > +user_set_log_base(struct vhost_device_ctx ctx,=0A= > + struct VhostUserMsg *msg)=0A= > +{=0A= > + struct virtio_net *dev;=0A= > + int fd =3D msg->fds[0];=0A= > + uint64_t size, off;=0A= > + void *addr;=0A= > +=0A= > + dev =3D get_device(ctx);=0A= > + if (!dev)=0A= > + return -1;=0A= > +=0A= > + if (fd < 0) {=0A= > + RTE_LOG(ERR, VHOST_CONFIG, "invalid log fd: %d\n", fd);=0A= > + return -1;=0A= > + }=0A= > +=0A= > + if (msg->size !=3D sizeof(VhostUserLog)) {=0A= > + RTE_LOG(ERR, VHOST_CONFIG,=0A= > + "invalid log base msg size: %"PRId32" !=3D %d\n",=0A= > + msg->size, (int)sizeof(VhostUserLog));=0A= > + return -1;=0A= > + }=0A= > +=0A= > + size =3D msg->payload.log.mmap_size;=0A= > + off =3D msg->payload.log.mmap_offset;=0A= > + RTE_LOG(INFO, VHOST_CONFIG,=0A= > + "log mmap size: %"PRId64", offset: %"PRId64"\n",=0A= > + size, off);=0A= > +=0A= > + /*=0A= > + * mmap from 0 to workaround a hugepage mmap bug: mmap will be=0A= > + * failed when offset is not page size aligned.=0A= > + */=0A= s /will be failed/will fail/=0A= mmap will fail when offset is not zero.=0A= Also we only know this workaround is for hugetlbfs. Not sure of other=0A= tmpfs, so mention hugetlbfs here.=0A= > + addr =3D mmap(0, size + off, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)= ;=0A= > + if (addr =3D=3D MAP_FAILED) {=0A= > + RTE_LOG(ERR, VHOST_CONFIG, "mmap log base failed!\n");=0A= > + return -1;=0A= > + }=0A= > +=0A= > + /* TODO: unmap on stop */=0A= > + dev->log_base =3D (uint64_t)(uintptr_t)addr + off;=0A= (uint64_t)(uintptr_t)RTE_PTR_ADD(addr, off)?=0A= > + dev->log_size =3D size;=0A= > +=0A= > + return 0;=0A= > +}=0A= > diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_v= host/vhost_user/virtio-net-user.h=0A= > index b82108d..013cf38 100644=0A= > --- a/lib/librte_vhost/vhost_user/virtio-net-user.h=0A= > +++ b/lib/librte_vhost/vhost_user/virtio-net-user.h=0A= > @@ -49,6 +49,7 @@ void user_set_vring_kick(struct vhost_device_ctx, struc= t VhostUserMsg *);=0A= > =0A= > void user_set_protocol_features(struct vhost_device_ctx ctx,=0A= > uint64_t protocol_features);=0A= > +int user_set_log_base(struct vhost_device_ctx ctx, struct VhostUserMsg *= );=0A= > =0A= > int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_stat= e *);=0A= > =0A= =0A=