From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Wang Subject: Re: [PATCH net-next] vhost: switch to use new message format Date: Mon, 6 Aug 2018 11:15:40 +0800 Message-ID: <9f270c8c-e596-1e7f-f4f1-abfcdd467825@redhat.com> References: <1533279891-12249-1-git-send-email-jasowang@redhat.com> <20180803105511-mutt-send-email-mst@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org To: "Michael S. Tsirkin" Return-path: In-Reply-To: <20180803105511-mutt-send-email-mst@kernel.org> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On 2018年08月03日 15:59, Michael S. Tsirkin wrote: >> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c >> index a502f1a..6f6c42d 100644 >> --- a/drivers/vhost/vhost.c >> +++ b/drivers/vhost/vhost.c >> @@ -315,6 +315,7 @@ static void vhost_vq_reset(struct vhost_dev *dev, >> vq->log_addr = -1ull; >> vq->private_data = NULL; >> vq->acked_features = 0; >> + vq->acked_backend_features = 0; >> vq->log_base = NULL; >> vq->error_ctx = NULL; >> vq->kick = NULL; >> @@ -1027,28 +1028,40 @@ static int vhost_process_iotlb_msg(struct vhost_dev *dev, >> ssize_t vhost_chr_write_iter(struct vhost_dev *dev, >> struct iov_iter *from) >> { >> - struct vhost_msg_node node; >> - unsigned size = sizeof(struct vhost_msg); >> - size_t ret; >> - int err; >> + struct vhost_iotlb_msg msg; >> + size_t offset; >> + int type, ret; >> >> - if (iov_iter_count(from) < size) >> - return 0; >> - ret = copy_from_iter(&node.msg, size, from); >> - if (ret != size) >> + ret = copy_from_iter(&type, sizeof(type), from); >> + if (ret != sizeof(type)) >> goto done; >> >> - switch (node.msg.type) { >> + switch (type) { >> case VHOST_IOTLB_MSG: >> - err = vhost_process_iotlb_msg(dev, &node.msg.iotlb); >> - if (err) >> - ret = err; >> + /* There maybe a hole after type for V1 message type, >> + * so skip it here. >> + */ >> + offset = offsetof(struct vhost_msg, iotlb) - sizeof(int); >> + break; >> + case VHOST_IOTLB_MSG_V2: >> + offset = sizeof(__u32); >> break; >> default: >> ret = -EINVAL; >> - break; >> + goto done; >> + } >> + >> + iov_iter_advance(from, offset); >> + ret = copy_from_iter(&msg, sizeof(msg), from); >> + if (ret != sizeof(msg)) >> + goto done; >> + if (vhost_process_iotlb_msg(dev, &msg)) { >> + ret = -EFAULT; >> + goto done; >> } >> >> + ret = (type == VHOST_IOTLB_MSG) ? sizeof(struct vhost_msg) : >> + sizeof(struct vhost_msg_v2); >> done: >> return ret; >> } > We can actually fix 32 bit apps too, checking the mode for v1. > But that can wait for another patch. > Yes, let me do it on top. Thanks