From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897592; cv=none; d=zohomail.com; s=zohoarc; b=Eb3xB5dfjVHaey8j5LQ3/yb96pqpra99thUMcYBf8I1p5N48Ko03xd9j+xl653dW6nC0prL3Pv19XJb9P0zzqWGR3ncKh7sPTih3+B0lqcRqRxGM1B7qhfFAvQEVnQsQ/rjKjo0PMo13u6fglnX6pf099OP/KFUUfFLag8oDjXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897592; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q8pEUQ5FwlT0wragKtjYtr65kguSGvb6UgV7rba+aMM=; b=UbgvnibBPBSYS+/Ej3iLq0dKrX6WJPwao7MPp3qAtLTOA6IHproruXxVVLF3wIYQGU6P7sqPRhNdrCi6pEMFFPB4dzTkJ37zgQTlW0ZIt3zK8DsIikSvTxMxo277ROnyY1C5W25u5XIefN6+aH0dED70WAE4i4ehStW9pI7FZ84= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612897592329973.7557063129531; Tue, 9 Feb 2021 11:06:32 -0800 (PST) Received: from localhost ([::1]:47312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YLG-0003SS-Dt for importer@patchew.org; Tue, 09 Feb 2021 14:06:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YHl-0001jz-V4 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:02:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YHi-0001ZV-Bg for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:02:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-475-n8pSb7C0NH6sVg1fx-2eUA-1; Tue, 09 Feb 2021 14:02:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A02FE801976 for ; Tue, 9 Feb 2021 19:02:44 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0650360C04; Tue, 9 Feb 2021 19:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q8pEUQ5FwlT0wragKtjYtr65kguSGvb6UgV7rba+aMM=; b=OYER9qPSdYxeEJRcgWi/YsGPKdFA1wTlevwRXcOomtDPbiieoLO6fdk/e1svcxMr86R7fA X139Lea4ujlxL8yzLOOTzMLiu9qbvwj2eiaED94IrIS0S1ugmgNgJYwYUX1Z7NW7J33rwX xPenPMYQn5WqU+QsB4ueXbVj98qNhA4= X-MC-Unique: n8pSb7C0NH6sVg1fx-2eUA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 01/24] DAX: vhost-user: Rework slave return values Date: Tue, 9 Feb 2021 19:02:01 +0000 Message-Id: <20210209190224.62827-2-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" All the current slave handlers on the qemu side generate an 'int' return value that's squashed down to a bool (!!ret) and stuffed into a uint64_t (field of a union) to be returned. Move the uint64_t type back up through the individual handlers so that we can mkae one actually return a full uint64_t. Note that the definition in the interop spec says most of these cases are defined as returning 0 on success and non-0 for failure, so it's OK to change from a bool to another non-0. Vivek: This is needed because upcoming patches in series will add new functions which want to return full error code. Existing functions continue to return true/false so, it should not lead to change of behavior for existing users. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost-backend.c | 4 ++-- hw/virtio/vhost-user.c | 32 ++++++++++++++++--------------- include/hw/virtio/vhost-backend.h | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 31b33bde37..21082084ea 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -401,7 +401,7 @@ int vhost_backend_invalidate_device_iotlb(struct vhost_= dev *dev, return -ENODEV; } =20 -int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, +uint64_t vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, struct vhost_iotlb_msg *imsg) { int ret =3D 0; @@ -429,5 +429,5 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *de= v, break; } =20 - return ret; + return !!ret; } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 2fdd5daf74..13789cc55e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1317,24 +1317,25 @@ static int vhost_user_reset_device(struct vhost_dev= *dev) return 0; } =20 -static int vhost_user_slave_handle_config_change(struct vhost_dev *dev) +static uint64_t vhost_user_slave_handle_config_change(struct vhost_dev *de= v) { int ret =3D -1; =20 if (!dev->config_ops) { - return -1; + return true; } =20 if (dev->config_ops->vhost_dev_config_notifier) { ret =3D dev->config_ops->vhost_dev_config_notifier(dev); } =20 - return ret; + return !!ret; } =20 -static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *d= ev, - VhostUserVringArea = *area, - int fd) +static uint64_t vhost_user_slave_handle_vring_host_notifier( + struct vhost_dev *dev, + VhostUserVringArea *area, + int fd) { int queue_idx =3D area->u64 & VHOST_USER_VRING_IDX_MASK; size_t page_size =3D qemu_real_host_page_size; @@ -1348,7 +1349,7 @@ static int vhost_user_slave_handle_vring_host_notifie= r(struct vhost_dev *dev, if (!virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev =3D=3D NULL || queue_idx >=3D virtio_get_num_queues(vdev)) { - return -1; + return true; } =20 n =3D &user->notifier[queue_idx]; @@ -1361,18 +1362,18 @@ static int vhost_user_slave_handle_vring_host_notif= ier(struct vhost_dev *dev, } =20 if (area->u64 & VHOST_USER_VRING_NOFD_MASK) { - return 0; + return false; } =20 /* Sanity check. */ if (area->size !=3D page_size) { - return -1; + return true; } =20 addr =3D mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, area->offset); if (addr =3D=3D MAP_FAILED) { - return -1; + return true; } =20 name =3D g_strdup_printf("vhost-user/host-notifier@%p mmaps[%d]", @@ -1383,13 +1384,13 @@ static int vhost_user_slave_handle_vring_host_notif= ier(struct vhost_dev *dev, =20 if (virtio_queue_set_host_notifier_mr(vdev, queue_idx, &n->mr, true)) { munmap(addr, page_size); - return -1; + return true; } =20 n->addr =3D addr; n->set =3D true; =20 - return 0; + return false; } =20 static void slave_read(void *opaque) @@ -1398,7 +1399,8 @@ static void slave_read(void *opaque) struct vhost_user *u =3D dev->opaque; VhostUserHeader hdr =3D { 0, }; VhostUserPayload payload =3D { 0, }; - int size, ret =3D 0; + int size; + uint64_t ret =3D 0; struct iovec iov; struct msghdr msgh; int fd[VHOST_USER_SLAVE_MAX_FDS]; @@ -1472,7 +1474,7 @@ static void slave_read(void *opaque) break; default: error_report("Received unexpected msg type: %d.", hdr.request); - ret =3D -EINVAL; + ret =3D (uint64_t)-EINVAL; } =20 /* Close the remaining file descriptors. */ @@ -1493,7 +1495,7 @@ static void slave_read(void *opaque) hdr.flags &=3D ~VHOST_USER_NEED_REPLY_MASK; hdr.flags |=3D VHOST_USER_REPLY_MASK; =20 - payload.u64 =3D !!ret; + payload.u64 =3D ret; hdr.size =3D sizeof(payload.u64); =20 iovec[0].iov_base =3D &hdr; diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 8a6f8e2a7a..64ac6b6444 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -186,7 +186,7 @@ int vhost_backend_update_device_iotlb(struct vhost_dev = *dev, int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev, uint64_t iova, uint64_t l= en); =20 -int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, +uint64_t vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, struct vhost_iotlb_msg *imsg); =20 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd); --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898070; cv=none; d=zohomail.com; s=zohoarc; b=ks6VcXOly0R1gCDrdk8xFcYPGRBrjYGaTTfJNE3AatOEJ8YdGaBbahTZJvJpNnhKNPEoJXoakHo43sK+7KcNSc+FGvBlWSuQdcnMH9WpJ9v70o8FiEqKrMK03ISr4Hd+GyETrkP8JYu5cEmvOzMXxrrbKYwTph9uqlvEPSaXAM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898070; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QNlair57xLZNrH0eP3P8pdNTju7RHayYUY0OubI3yAo=; b=QG+Mujb8GYWUBDU/le9cHnltp2pesDDcXHGldDLj81tB3vY6C/+NJWFatkmVNhrSAYL4ZQdJWzgAkm2xyF5/Ncd2Yg7BCpOQNmpfwcL0tlgQ86+bWR5L2KU4yAKflVKOS/DbGG2QSmH+4WLALPonj7GyU6CFFnoCHYCtrEi08hQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16128980702804.452459424709673; Tue, 9 Feb 2021 11:14:30 -0800 (PST) Received: from localhost ([::1]:35606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YSy-00029h-TV for importer@patchew.org; Tue, 09 Feb 2021 14:14:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YHp-0001mQ-BP for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:02:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22998) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YHn-0001cK-O1 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:02:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-502-OQrZAUutMTmZNaklyrXwEQ-1; Tue, 09 Feb 2021 14:02:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73931107ACE3 for ; Tue, 9 Feb 2021 19:02:52 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D96E60C04; Tue, 9 Feb 2021 19:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QNlair57xLZNrH0eP3P8pdNTju7RHayYUY0OubI3yAo=; b=GUTB+DJYZ/MelbHPh6HG/IYfus+H4a8m2FlN1+MVtU/IEkTMwaDhfQCuQCSU2FoG1lN6k/ jnh2Rc2fn/CbM8IxO63s79d/bsY9t6ek/+bKxgbirmtfWvMOSpxjEnmI/R+/R3I+1nOElt dPPm2PhjoeX0GrbbICkJPdcx6V9FN8c= X-MC-Unique: OQrZAUutMTmZNaklyrXwEQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 02/24] DAX: libvhost-user: Route slave message payload Date: Tue, 9 Feb 2021 19:02:02 +0000 Message-Id: <20210209190224.62827-3-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Route the uint64 payload from message replies on the slave back up through vu_process_message_reply and to the callers. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- subprojects/libvhost-user/libvhost-user.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index fab7ca17ee..937f64480d 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -403,9 +403,11 @@ vu_send_reply(VuDev *dev, int conn_fd, VhostUserMsg *v= msg) * Processes a reply on the slave channel. * Entered with slave_mutex held and releases it before exit. * Returns true on success. + * *payload is written on success */ static bool -vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg) +vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg, + uint64_t *payload) { VhostUserMsg msg_reply; bool result =3D false; @@ -425,7 +427,8 @@ vu_process_message_reply(VuDev *dev, const VhostUserMsg= *vmsg) goto out; } =20 - result =3D msg_reply.payload.u64 =3D=3D 0; + *payload =3D msg_reply.payload.u64; + result =3D true; =20 out: pthread_mutex_unlock(&dev->slave_mutex); @@ -1312,6 +1315,8 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *= vq, int fd, { int qidx =3D vq - dev->vq; int fd_num =3D 0; + bool res; + uint64_t payload =3D 0; VhostUserMsg vmsg =3D { .request =3D VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG, .flags =3D VHOST_USER_VERSION | VHOST_USER_NEED_REPLY_MASK, @@ -1342,7 +1347,10 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq = *vq, int fd, } =20 /* Also unlocks the slave_mutex */ - return vu_process_message_reply(dev, &vmsg); + res =3D vu_process_message_reply(dev, &vmsg, &payload); + res =3D res && (payload =3D=3D 0); + + return res; } =20 static bool --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897629; cv=none; d=zohomail.com; s=zohoarc; b=XVTHATrXl0NMaVYfGz4DprcOJ2LndOGDdNGGWCB0DOHlFofRuqCUav+IMQINJSGXG/EAq0JMrG5no8j9sPby7WyRDjllpctBcxhWSjKmgVYar4UWEUXyDz0K4WxkLb+E0og5URtMbGZGplgCQ99VY/VY/Bga8ZyE1M0JPXZos70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897629; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gn0w9wN1RegIA4b9x4nFm2bDrVSexrO+xV4vhcLhI+s=; b=P77Zr44P5PopaH0gl2KBG8fq8xROk9fD5OUNwjLMYfJ/sPre+0nasNMGukPuKl0wYidoxH/FqXjqzIISBa4EsV16+oDteYwVN6QMl87UdQbGEsDlUFkrVTi+9eW1QA5f10fZD/iMwyLFj9p1DFxoZNQCKjDSbMUBWPnZNm5QA44= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612897629545560.6080208005167; Tue, 9 Feb 2021 11:07:09 -0800 (PST) Received: from localhost ([::1]:48340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YLs-0003t3-A8 for importer@patchew.org; Tue, 09 Feb 2021 14:07:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YI7-0001zW-ER for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:03:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YI1-0001gJ-O1 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:03:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-313-k1myZ7wzPRmB6_u_HQ4Ykw-1; Tue, 09 Feb 2021 14:03:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C807918A08C1 for ; Tue, 9 Feb 2021 19:03:05 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBFA660C04; Tue, 9 Feb 2021 19:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gn0w9wN1RegIA4b9x4nFm2bDrVSexrO+xV4vhcLhI+s=; b=AG0fwTA/46uHrIi5WossbdEtcT4IEINFtWGVSjPgVfn6+GMpmwY+qWLm06HMTYt2iIJUoB 4+XH5Gx8H7ZdmL+6zTLpDHu2nGneA5DioruSDt8+ETqsdHXuHvvp61tnOaR1VGXuHZ6o2T S67gaU3xoL5omom4sPrsumQGsVpwfsQ= X-MC-Unique: k1myZ7wzPRmB6_u_HQ4Ykw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 03/24] DAX: libvhost-user: Allow popping a queue element with bad pointers Date: Tue, 9 Feb 2021 19:02:03 +0000 Message-Id: <20210209190224.62827-4-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Allow a daemon implemented with libvhost-user to accept an element with pointers to memory that aren't in the mapping table. The daemon might have some special way to deal with some special cases of this. The default behaviour doesn't change. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 2 +- contrib/vhost-user-blk/vhost-user-blk.c | 3 +- contrib/vhost-user-gpu/vhost-user-gpu.c | 5 ++- contrib/vhost-user-input/main.c | 4 +- contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +- subprojects/libvhost-user/libvhost-user.c | 51 ++++++++++++++++++----- subprojects/libvhost-user/libvhost-user.h | 8 +++- tests/vhost-user-bridge.c | 4 +- tools/virtiofsd/fuse_virtio.c | 3 +- 9 files changed, 60 insertions(+), 22 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index ab2c4d44c4..ea2d302e33 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -205,7 +205,7 @@ static void vu_blk_process_vq(VuDev *vu_dev, int idx) while (1) { VuBlkReq *req; =20 - req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlkReq)); + req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlkReq), NULL, NULL); if (!req) { break; } diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index d14b2896bf..01193552e9 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -235,7 +235,8 @@ static int vub_virtio_process_req(VubDev *vdev_blk, unsigned out_num; VubReq *req; =20 - elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + sizeof(VubR= eq)); + elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + sizeof(VubR= eq), + NULL, NULL); if (!elem) { return -1; } diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index b27990ffdb..58f50ae83f 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -840,7 +840,8 @@ vg_handle_ctrl(VuDev *dev, int qidx) return; } =20 - cmd =3D vu_queue_pop(dev, vq, sizeof(struct virtio_gpu_ctrl_comman= d)); + cmd =3D vu_queue_pop(dev, vq, sizeof(struct virtio_gpu_ctrl_comman= d), + NULL, NULL); if (!cmd) { break; } @@ -943,7 +944,7 @@ vg_handle_cursor(VuDev *dev, int qidx) struct virtio_gpu_update_cursor cursor; =20 for (;;) { - elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement), NULL, NULL); if (!elem) { break; } diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/mai= n.c index c15d18c33f..d5c435605c 100644 --- a/contrib/vhost-user-input/main.c +++ b/contrib/vhost-user-input/main.c @@ -57,7 +57,7 @@ static void vi_input_send(VuInput *vi, struct virtio_inpu= t_event *event) =20 /* ... then check available space ... */ for (i =3D 0; i < vi->qindex; i++) { - elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement), NULL, NULL); if (!elem) { while (--i >=3D 0) { vu_queue_unpop(dev, vq, vi->queue[i].elem, 0); @@ -141,7 +141,7 @@ static void vi_handle_sts(VuDev *dev, int qidx) g_debug("%s", G_STRFUNC); =20 for (;;) { - elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement), NULL, NULL); if (!elem) { break; } diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user= -scsi/vhost-user-scsi.c index 4f6e3e2a24..7564d6ab2d 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -252,7 +252,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx) VirtIOSCSICmdReq *req; VirtIOSCSICmdResp *rsp; =20 - elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement)); + elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement), NULL, NU= LL); if (!elem) { g_debug("No more elements pending on vq[%d]@%p", idx, vq); break; diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 937f64480d..68eb165755 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -2469,7 +2469,8 @@ vu_queue_set_notification(VuDev *dev, VuVirtq *vq, in= t enable) =20 static bool virtqueue_map_desc(VuDev *dev, - unsigned int *p_num_sg, struct iovec *iov, + unsigned int *p_num_sg, unsigned int *p_bad_sg, + struct iovec *iov, unsigned int max_num_sg, bool is_write, uint64_t pa, size_t sz) { @@ -2490,10 +2491,35 @@ virtqueue_map_desc(VuDev *dev, return false; } =20 - iov[num_sg].iov_base =3D vu_gpa_to_va(dev, &len, pa); - if (iov[num_sg].iov_base =3D=3D NULL) { - vu_panic(dev, "virtio: invalid address for buffers"); - return false; + if (p_bad_sg && *p_bad_sg) { + /* A previous mapping was bad, we won't try and map this eithe= r */ + *p_bad_sg =3D *p_bad_sg + 1; + } + if (!p_bad_sg || !*p_bad_sg) { + /* No bad mappings so far, lets try mapping this one */ + iov[num_sg].iov_base =3D vu_gpa_to_va(dev, &len, pa); + if (iov[num_sg].iov_base =3D=3D NULL) { + /* + * OK, it won't map, either panic or if the caller can han= dle + * it, then count it. + */ + if (!p_bad_sg) { + vu_panic(dev, "virtio: invalid address for buffers"); + return false; + } else { + *p_bad_sg =3D *p_bad_sg + 1; + } + } + } + if (p_bad_sg && *p_bad_sg) { + /* + * There was a bad mapping, either now or previously, since + * the caller set p_bad_sg it means it's prepared to deal with + * it, so give it the pa in the iov + * Note: In this case len will be the whole sz, so we won't + * go around again for this descriptor + */ + iov[num_sg].iov_base =3D (void *)(uintptr_t)pa; } iov[num_sg].iov_len =3D len; num_sg++; @@ -2524,7 +2550,8 @@ virtqueue_alloc_element(size_t sz, } =20 static void * -vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) +vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz, + unsigned int *p_bad_in, unsigned int *p_bad_out) { struct vring_desc *desc =3D vq->vring.desc; uint64_t desc_addr, read_len; @@ -2568,7 +2595,7 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned i= nt idx, size_t sz) /* Collect all the descriptors */ do { if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) { - if (!virtqueue_map_desc(dev, &in_num, iov + out_num, + if (!virtqueue_map_desc(dev, &in_num, p_bad_in, iov + out_num, VIRTQUEUE_MAX_SIZE - out_num, true, le64toh(desc[i].addr), le32toh(desc[i].len))) { @@ -2579,7 +2606,7 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned i= nt idx, size_t sz) vu_panic(dev, "Incorrect order for descriptors"); return NULL; } - if (!virtqueue_map_desc(dev, &out_num, iov, + if (!virtqueue_map_desc(dev, &out_num, p_bad_out, iov, VIRTQUEUE_MAX_SIZE, false, le64toh(desc[i].addr), le32toh(desc[i].len))) { @@ -2669,7 +2696,8 @@ vu_queue_inflight_post_put(VuDev *dev, VuVirtq *vq, i= nt desc_idx) } =20 void * -vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) +vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz, + unsigned int *p_bad_in, unsigned int *p_bad_out) { int i; unsigned int head; @@ -2682,7 +2710,8 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) =20 if (unlikely(vq->resubmit_list && vq->resubmit_num > 0)) { i =3D (--vq->resubmit_num); - elem =3D vu_queue_map_desc(dev, vq, vq->resubmit_list[i].index, sz= ); + elem =3D vu_queue_map_desc(dev, vq, vq->resubmit_list[i].index, sz, + p_bad_in, p_bad_out); =20 if (!vq->resubmit_num) { free(vq->resubmit_list); @@ -2714,7 +2743,7 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) vring_set_avail_event(vq, vq->last_avail_idx); } =20 - elem =3D vu_queue_map_desc(dev, vq, head, sz); + elem =3D vu_queue_map_desc(dev, vq, head, sz, p_bad_in, p_bad_out); =20 if (!elem) { return NULL; diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index 3d13dfadde..330b61c005 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -589,11 +589,17 @@ void vu_queue_notify_sync(VuDev *dev, VuVirtq *vq); * @dev: a VuDev context * @vq: a VuVirtq queue * @sz: the size of struct to return (must be >=3D VuVirtqElement) + * @p_bad_in: If none NULL, a pointer to an integer count of + * unmappable regions in input descriptors + * @p_bad_out: If none NULL, a pointer to an integer count of + * unmappable regions in output descriptors + * * * Returns: a VuVirtqElement filled from the queue or NULL. The * returned element must be free()-d by the caller. */ -void *vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz); +void *vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz, + unsigned int *p_bad_in, unsigned int *p_bad_out); =20 =20 /** diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c index 24815920b2..4f6829e6c3 100644 --- a/tests/vhost-user-bridge.c +++ b/tests/vhost-user-bridge.c @@ -184,7 +184,7 @@ vubr_handle_tx(VuDev *dev, int qidx) unsigned int out_num; struct iovec sg[VIRTQUEUE_MAX_SIZE], *out_sg; =20 - elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement), NULL, NULL); if (!elem) { break; } @@ -299,7 +299,7 @@ vubr_backend_recv_cb(int sock, void *ctx) ssize_t ret, total =3D 0; unsigned int num; =20 - elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement), NULL, NULL); if (!elem) { break; } diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index ddcefee427..bd19358437 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -657,7 +657,8 @@ static void *fv_queue_thread(void *opaque) __func__, qi->qidx, (size_t)evalue, in_bytes, out_bytes); =20 while (1) { - FVRequest *req =3D vu_queue_pop(dev, q, sizeof(FVRequest)); + FVRequest *req =3D vu_queue_pop(dev, q, sizeof(FVRequest), + NULL, NULL); if (!req) { break; } --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897642; cv=none; d=zohomail.com; s=zohoarc; b=Gjqd3f9ESU5oLcoy5DLCg1BTC458U2Op9F4wBVFE5yOReXisc5T9cXWvbX/MUaXnDT4eQG3pOQ55I7WAPOHbsSMKEiYa3XwjIDoPN5vgapfJayC95zPlCjb9AyPKJqTDK80uQMRvkvHYyAnX57ph/YSP7W/44wEKMhl5UXFB8mw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897642; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6i+5rOwQonBwdlwGosx6D2J44wHzpwaETs+74bPCtRI=; b=BQWCb+4j8iaQXtM++QIgHDPyyHYTQVhSzVS3qpR1UbthJVDDgUi/HGbhmFzxBL8WDpBCGbqZ+7VEayiheSqGG38BTmlI+zZKx14a4FKm5j3/bjZJRWk527dpoAkdSFuh9SGsXSGSD1h2s5XtxeTnknqpPa/OvCgTlGvxPhBVSnY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612897642075967.7988182392442; Tue, 9 Feb 2021 11:07:22 -0800 (PST) Received: from localhost ([::1]:49714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YM4-0004Vu-RN for importer@patchew.org; Tue, 09 Feb 2021 14:07:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YIg-0002cD-Tc for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:03:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YIc-0001qp-SZ for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:03:50 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-KZwOcblIMJyT-Ko1_t7dNw-1; Tue, 09 Feb 2021 14:03:41 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F83818A08BD for ; Tue, 9 Feb 2021 19:03:40 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34E1B60C04; Tue, 9 Feb 2021 19:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6i+5rOwQonBwdlwGosx6D2J44wHzpwaETs+74bPCtRI=; b=VB/VxoMJl1srefF396r3w3mHXnlcczomIMjhpnz0iAwyP9pTYtdcdHjyUj9BYTG+Z3qIOt dCILvihQKzy61UsLx9hvGpU7NMUZnQ6G7dBIBJmmiPv0nrMdFi0mVRTgUWK7c4Rb8+FUHz bQY+4RqqVNBsiV8vCbBWPRrdd3obLXk= X-MC-Unique: KZwOcblIMJyT-Ko1_t7dNw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 04/24] DAX subprojects/libvhost-user: Add virtio-fs slave types Date: Tue, 9 Feb 2021 19:02:04 +0000 Message-Id: <20210209190224.62827-5-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add virtio-fs definitions to libvhost-user Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- subprojects/libvhost-user/libvhost-user.c | 41 +++++++++++++++++++++++ subprojects/libvhost-user/libvhost-user.h | 31 +++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 68eb165755..b35abdd9f9 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -2918,3 +2918,44 @@ vu_queue_push(VuDev *dev, VuVirtq *vq, vu_queue_flush(dev, vq, 1); vu_queue_inflight_post_put(dev, vq, elem->index); } + +int64_t vu_fs_cache_request(VuDev *dev, VhostUserSlaveRequest req, int fd, + VhostUserFSSlaveMsg *fsm) +{ + int fd_num =3D 0; + bool res; + uint64_t payload =3D 0; + VhostUserMsg vmsg =3D { + .request =3D req, + .flags =3D VHOST_USER_VERSION | VHOST_USER_NEED_REPLY_MASK, + .size =3D sizeof(vmsg.payload.fs), + .payload.fs =3D *fsm, + }; + + if (fd !=3D -1) { + vmsg.fds[fd_num++] =3D fd; + } + + vmsg.fd_num =3D fd_num; + + if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)= ) { + return -EINVAL; + } + + pthread_mutex_lock(&dev->slave_mutex); + if (!vu_message_write(dev, dev->slave_fd, &vmsg)) { + pthread_mutex_unlock(&dev->slave_mutex); + return -EIO; + } + + /* Also unlocks the slave_mutex */ + res =3D vu_process_message_reply(dev, &vmsg, &payload); + if (!res) { + return -EIO; + } + /* + * Payload is delivered as uint64_t but is actually signed for + * errors. + */ + return (int64_t)payload; +} diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index 330b61c005..e12e9c1532 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -122,6 +122,24 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 +/* Structures carried over the slave channel back to QEMU */ +#define VHOST_USER_FS_SLAVE_ENTRIES 8 + +/* For the flags field of VhostUserFSSlaveMsg */ +#define VHOST_USER_FS_FLAG_MAP_R (1ull << 0) +#define VHOST_USER_FS_FLAG_MAP_W (1ull << 1) + +typedef struct { + /* Offsets within the file being mapped */ + uint64_t fd_offset[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Offsets within the cache */ + uint64_t c_offset[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Lengths of sections */ + uint64_t len[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Flags, from VHOST_USER_FS_FLAG_* */ + uint64_t flags[VHOST_USER_FS_SLAVE_ENTRIES]; +} VhostUserFSSlaveMsg; + typedef struct VhostUserMemoryRegion { uint64_t guest_phys_addr; uint64_t memory_size; @@ -197,6 +215,7 @@ typedef struct VhostUserMsg { VhostUserConfig config; VhostUserVringArea area; VhostUserInflight inflight; + VhostUserFSSlaveMsg fs; } payload; =20 int fds[VHOST_MEMORY_BASELINE_NREGIONS]; @@ -693,4 +712,16 @@ void vu_queue_get_avail_bytes(VuDev *vdev, VuVirtq *vq= , unsigned int *in_bytes, bool vu_queue_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int in_bytes, unsigned int out_bytes); =20 +/** + * vu_fs_cache_request: Send a slave message for an fs client + * @dev: a VuDev context + * @req: The request type (map, unmap, sync) + * @fd: an fd (only required for map, else must be -1) + * @fsm: The body of the message + * + * Returns: 0 or above for success, nevative errno on error + */ +int64_t vu_fs_cache_request(VuDev *dev, VhostUserSlaveRequest req, int fd, + VhostUserFSSlaveMsg *fsm); + #endif /* LIBVHOST_USER_H */ --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898337; cv=none; d=zohomail.com; s=zohoarc; b=VAFNpIpTyD6fJ+zTgkVTV4hJotl3YfZ4vQXf3Lkse/5s5Y8gXpP+tPDicStLQ+V01SFl8GepHArey2CRVuikjMo6C6wpRTc5+UV2/QAUkR7JiWppndmzgD5YzurXkYn3b5RedoBnH3YCtkrFym44cob0W/8Ct6ikXfIeMroUXBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898337; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OVKzDZ9NtFDXNkk57xPSPoIr0HCvR8FN4dlXdaErfkw=; b=lF1SDazlvRy3O8APxeiiRAKZgmW66UgJJaXYHVQ8UFObz2OgcGwSSU5x1GymHqBa4OYCvDxtg7NBbmwqffd+2EZ3QMZbD8BOvT9K2iqYX22BvA9yef3Rl8waFvPfwuH2VVKrDnBPbYaUbboCaRwXd/f1taj5zKGHzGjSMfTPqyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898337066407.6662231126028; Tue, 9 Feb 2021 11:18:57 -0800 (PST) Received: from localhost ([::1]:44202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YXH-0005zT-Vq for importer@patchew.org; Tue, 09 Feb 2021 14:18:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJF-0002pR-Hb for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJ1-0001xF-Jj for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:23 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-598-smX7ezjeOk69HR2ESdoqXw-1; Tue, 09 Feb 2021 14:04:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0125C803648 for ; Tue, 9 Feb 2021 19:04:06 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1F0360C04; Tue, 9 Feb 2021 19:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OVKzDZ9NtFDXNkk57xPSPoIr0HCvR8FN4dlXdaErfkw=; b=I0kudjpS6fKVteMF+nEIPpZFXAL2l6GeKi7C2kdXT9HX0WTi5xCx9hTD7wNLq9lnxsNsmi UenTRudI6C3ilAiZnBNSMCJITrdkwgsORWzu28gEKkskueZwb/LaKfZyBp49W8Ws7RCtfk QYqKuH8uguZsENunIJBKonYhwFnSYD0= X-MC-Unique: smX7ezjeOk69HR2ESdoqXw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 05/24] DAX: virtio: Add shared memory capability Date: Tue, 9 Feb 2021 19:02:05 +0000 Message-Id: <20210209190224.62827-6-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG' and the data structure 'virtio_pci_cap64' to go with it. They allow defining shared memory regions with sizes and offsets of 2^32 and more. Multiple instances of the capability are allowed and distinguished by the 'id' field in the base capability. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- hw/virtio/virtio-pci.c | 20 ++++++++++++++++++++ hw/virtio/virtio-pci.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 094c36aa3e..de378c594e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1138,6 +1138,26 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *pr= oxy, return offset; } =20 +int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, + uint8_t bar, uint64_t offset, uint64_t length, + uint8_t id) +{ + struct virtio_pci_cap64 cap =3D { + .cap.cap_len =3D sizeof cap, + .cap.cfg_type =3D VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, + }; + uint32_t mask32 =3D ~0; + + cap.cap.bar =3D bar; + cap.cap.id =3D id; + cap.cap.length =3D cpu_to_le32(length & mask32); + cap.length_hi =3D cpu_to_le32((length >> 32) & mask32); + cap.cap.offset =3D cpu_to_le32(offset & mask32); + cap.offset_hi =3D cpu_to_le32((offset >> 32) & mask32); + + return virtio_pci_add_mem_cap(proxy, &cap.cap); +} + static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, unsigned size) { diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index d7d5d403a9..31ca339099 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -247,4 +247,8 @@ void virtio_pci_types_register(const VirtioPCIDeviceTyp= eInfo *t); */ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues); =20 +int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, + uint8_t bar, uint64_t offset, uint64_t length, + uint8_t id); + #endif --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898497; cv=none; d=zohomail.com; s=zohoarc; b=LJBB/D3ypfc/EuPhX4F4WGlvy7ic6z9xbD9nEjTLdDSz6ZzLSUSv464QGISWIw1RQ82Cin9c2yqRFctwuqNgCBy5o31xQLm/Hreu333xZsXA9YohRM7uhWC7boYsbyDdVwKk4hDnu8wPb6kf7oDbPMkuFjW5b6s9vJPiCvHNEPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898497; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gcGlEQT50fPyVTMZkdJ1irgF/q0toIiUP9GnQhrSW0M=; b=fyIT26HJTAL66RJaS57UQF/oyeu3xmIPncB149ngh9gVElifg2i+LUkQ1QWBsdE/PJgGWbhnws7WofTPBZ8P3PqTV/4nFaVtXOLZQuAz/QBFzS9NoiUgi+fFYMTEBmGnKTEf5aJsL1i0Co1C1KcAGScrclWs6pLpRQUZIwO/y7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898496595616.7294044669554; Tue, 9 Feb 2021 11:21:36 -0800 (PST) Received: from localhost ([::1]:51152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YZr-0000bs-Ev for importer@patchew.org; Tue, 09 Feb 2021 14:21:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJN-0002rj-Gq for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJF-0001zf-A2 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:33 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-522-7m3z1kPrMsOylV9gLTEhBA-1; Tue, 09 Feb 2021 14:04:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D78C803F59 for ; Tue, 9 Feb 2021 19:04:14 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65E8A60C04; Tue, 9 Feb 2021 19:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gcGlEQT50fPyVTMZkdJ1irgF/q0toIiUP9GnQhrSW0M=; b=TnNZAbVkxc9I9ljpYnNdgm9WsMhHV1QSyLzi67wkdbM2KxmLZCNW62Sc0E1FSOvWiTcsc8 Mvq1KZ8kBic0Q4DVMBgtSCyv2qGFR4qzuDCDRcMXe9q2nzewdRjNNGleIeMO35vbaeJ3U5 Fhm9OW8DLugde4fNLqD0/U/l7qsQx7k= X-MC-Unique: 7m3z1kPrMsOylV9gLTEhBA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 06/24] DAX: virtio-fs: Add cache BAR Date: Tue, 9 Feb 2021 19:02:06 +0000 Message-Id: <20210209190224.62827-7-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add a cache BAR into which files will be directly mapped. The size can be set with the cache-size=3D property, e.g. -device vhost-user-fs-pci,chardev=3Dchar0,tag=3Dmyfs,cache-size=3D16G The default is no cache. Signed-off-by: Dr. David Alan Gilbert with PPC fixes by: Signed-off-by: Fabiano Rosas --- hw/virtio/vhost-user-fs-pci.c | 25 ++++++++++++++++++++++++ hw/virtio/vhost-user-fs.c | 32 +++++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-fs.h | 2 ++ 3 files changed, 59 insertions(+) diff --git a/hw/virtio/vhost-user-fs-pci.c b/hw/virtio/vhost-user-fs-pci.c index 2ed8492b3f..0388e063c6 100644 --- a/hw/virtio/vhost-user-fs-pci.c +++ b/hw/virtio/vhost-user-fs-pci.c @@ -16,10 +16,14 @@ #include "hw/virtio/vhost-user-fs.h" #include "virtio-pci.h" #include "qom/object.h" +#include "standard-headers/linux/virtio_fs.h" + +#define VIRTIO_FS_PCI_CACHE_BAR 2 =20 struct VHostUserFSPCI { VirtIOPCIProxy parent_obj; VHostUserFS vdev; + MemoryRegion cachebar; }; =20 typedef struct VHostUserFSPCI VHostUserFSPCI; @@ -39,6 +43,7 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpc= i_dev, Error **errp) { VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); + uint64_t cachesize; =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { /* Also reserve config change and hiprio queue vectors */ @@ -46,6 +51,26 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vp= ci_dev, Error **errp) } =20 qdev_realize(vdev, BUS(&vpci_dev->bus), errp); + cachesize =3D dev->vdev.conf.cache_size; + + /* + * The bar starts with the data/DAX cache + * Others will be added later. + */ + memory_region_init(&dev->cachebar, OBJECT(vpci_dev), + "vhost-fs-pci-cachebar", cachesize); + if (cachesize) { + memory_region_add_subregion(&dev->cachebar, 0, &dev->vdev.cache); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, 0, cache= size, + VIRTIO_FS_SHMCAP_ID_CACHE); + } + + /* After 'realized' so the memory region exists */ + pci_register_bar(&vpci_dev->pci_dev, VIRTIO_FS_PCI_CACHE_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &dev->cachebar); } =20 static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index ac4fc34b36..b077d8e705 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -24,6 +24,16 @@ #include "monitor/monitor.h" #include "sysemu/sysemu.h" =20 +/* + * The powerpc kernel code expects the memory to be accessible during + * addition/removal. + */ +#if defined(TARGET_PPC64) && defined(CONFIG_LINUX) +#define DAX_WINDOW_PROT PROT_READ +#else +#define DAX_WINDOW_PROT PROT_NONE +#endif + static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); @@ -163,6 +173,7 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserFS *fs =3D VHOST_USER_FS(dev); + void *cache_ptr; unsigned int i; size_t len; int ret; @@ -202,6 +213,26 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) VIRTQUEUE_MAX_SIZE); return; } + if (fs->conf.cache_size && + (!is_power_of_2(fs->conf.cache_size) || + fs->conf.cache_size < qemu_real_host_page_size)) { + error_setg(errp, "cache-size property must be a power of 2 " + "no smaller than the page size"); + return; + } + if (fs->conf.cache_size) { + /* Anonymous, private memory is not counted as overcommit */ + cache_ptr =3D mmap(NULL, fs->conf.cache_size, DAX_WINDOW_PROT, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (cache_ptr =3D=3D MAP_FAILED) { + error_setg(errp, "Unable to mmap blank cache"); + return; + } + + memory_region_init_ram_ptr(&fs->cache, OBJECT(vdev), + "virtio-fs-cache", + fs->conf.cache_size, cache_ptr); + } =20 if (!vhost_user_init(&fs->vhost_user, &fs->conf.chardev, errp)) { return; @@ -277,6 +308,7 @@ static Property vuf_properties[] =3D { DEFINE_PROP_UINT16("num-request-queues", VHostUserFS, conf.num_request_queues, 1), DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), + DEFINE_PROP_SIZE("cache-size", VHostUserFS, conf.cache_size, 0), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 0d62834c25..04596799e3 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -28,6 +28,7 @@ typedef struct { char *tag; uint16_t num_request_queues; uint16_t queue_size; + uint64_t cache_size; } VHostUserFSConf; =20 struct VHostUserFS { @@ -42,6 +43,7 @@ struct VHostUserFS { int32_t bootindex; =20 /*< public >*/ + MemoryRegion cache; }; =20 #endif /* _QEMU_VHOST_USER_FS_H */ --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897660; cv=none; d=zohomail.com; s=zohoarc; b=BAQf+8uYizxsx/vwAzDlPdFkdP4/A/qyWZnwc8gW5PkEbhSZrd68fm7CR8jE0/4yZZvw16c5ThRc0gyFlsVFxVrvX4n3BGwKwf1QFrHYiTEd86j/VLkBFbnKW4FqDyMxSgNFVOYrbkrfyc3XeZm+nUnH6zN9rMSlys0ZCczjSwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897660; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Uw/8KQdYFFex4P9QuFrS4i6Y1ZCBVpqmZItpysSQRoI=; b=AYWFJvwOGH2pbktxzHJiD0z6lnX0FEofExzOqAIpKLMiqEBsne0PjQUkqyNkTmTfwZqLs5ddBe1znsWp1ygS97V4TEAbAQFu/achStwqYCIorRbVPurZ4aA9xMWul6oOrRf/X1MLcL6nFxBH4aixlB9Jfu5SfXaXb/c5XrntBbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612897660366562.7998188491426; Tue, 9 Feb 2021 11:07:40 -0800 (PST) Received: from localhost ([::1]:50456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YMN-0004oY-Ar for importer@patchew.org; Tue, 09 Feb 2021 14:07:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJQ-0002vs-5a for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJM-00021j-M9 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:35 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-_i-OJdm6PWyRQxSKPBiriQ-1; Tue, 09 Feb 2021 14:04:27 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EDA5106BB3A for ; Tue, 9 Feb 2021 19:04:26 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E352F60C04; Tue, 9 Feb 2021 19:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uw/8KQdYFFex4P9QuFrS4i6Y1ZCBVpqmZItpysSQRoI=; b=Tn+9+b1VyVoxDiLfIVvg15Ktn/GT5lHVlU+wq7zrrCeWTFUYKpxaDXuqHe9cdu4anAkBST aMPLyyPdOUO0vm2bO7BktNooDJdxbSG+JW77B6EXHuuTza7JEnz2mdDp0TlooRhaB7WjiN IZ/U9amqaAzBEaR53mDiq1LnjZRLgas= X-MC-Unique: _i-OJdm6PWyRQxSKPBiriQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 07/24] DAX: virtio-fs: Add vhost-user slave commands for mapping Date: Tue, 9 Feb 2021 19:02:07 +0000 Message-Id: <20210209190224.62827-8-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The daemon may request that fd's be mapped into the virtio-fs cache visible to the guest. These mappings are triggered by commands sent over the slave fd from the daemon. Signed-off-by: Dr. David Alan Gilbert --- docs/interop/vhost-user.rst | 20 +++++++++++++++++++ hw/virtio/vhost-user-fs.c | 14 +++++++++++++ hw/virtio/vhost-user.c | 14 +++++++++++++ include/hw/virtio/vhost-user-fs.h | 24 +++++++++++++++++++++++ subprojects/libvhost-user/libvhost-user.h | 2 ++ 5 files changed, 74 insertions(+) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index d6085f7045..1deedd3407 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -1432,6 +1432,26 @@ Slave message types =20 The state.num field is currently reserved and must be set to 0. =20 +``VHOST_USER_SLAVE_FS_MAP`` + :id: 6 + :equivalent ioctl: N/A + :slave payload: fd + n * (offset + address + len) + :master payload: N/A + + Requests that the QEMU mmap the given fd into the virtio-fs cache; + multiple chunks can be mapped in one command. + A reply is generated indicating whether mapping succeeded. + +``VHOST_USER_SLAVE_FS_UNMAP`` + :id: 7 + :equivalent ioctl: N/A + :slave payload: n * (address + len) + :master payload: N/A + + Requests that the QEMU un-mmap the given range in the virtio-fs cache; + multiple chunks can be unmapped in one command. + A reply is generated indicating whether unmapping succeeded. + .. _reply_ack: =20 VHOST_USER_PROTOCOL_F_REPLY_ACK diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index b077d8e705..78401d2ff1 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -34,6 +34,20 @@ #define DAX_WINDOW_PROT PROT_NONE #endif =20 +uint64_t vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMs= g *sm, + int fd) +{ + /* TODO */ + return (uint64_t)-1; +} + +uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *dev, + VhostUserFSSlaveMsg *sm) +{ + /* TODO */ + return (uint64_t)-1; +} + static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 13789cc55e..21e40ff91a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -12,6 +12,7 @@ #include "qapi/error.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-fs.h" #include "hw/virtio/vhost-backend.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-net.h" @@ -132,6 +133,10 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_IOTLB_MSG =3D 1, VHOST_USER_SLAVE_CONFIG_CHANGE_MSG =3D 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3D 3, + VHOST_USER_SLAVE_VRING_CALL =3D 4, + VHOST_USER_SLAVE_VRING_ERR =3D 5, + VHOST_USER_SLAVE_FS_MAP =3D 6, + VHOST_USER_SLAVE_FS_UNMAP =3D 7, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 @@ -218,6 +223,7 @@ typedef union { VhostUserCryptoSession session; VhostUserVringArea area; VhostUserInflight inflight; + VhostUserFSSlaveMsg fs; } VhostUserPayload; =20 typedef struct VhostUserMsg { @@ -1472,6 +1478,14 @@ static void slave_read(void *opaque) ret =3D vhost_user_slave_handle_vring_host_notifier(dev, &payload.= area, fd[0]); break; +#ifdef CONFIG_VHOST_USER_FS + case VHOST_USER_SLAVE_FS_MAP: + ret =3D vhost_user_fs_slave_map(dev, &payload.fs, fd[0]); + break; + case VHOST_USER_SLAVE_FS_UNMAP: + ret =3D vhost_user_fs_slave_unmap(dev, &payload.fs); + break; +#endif default: error_report("Received unexpected msg type: %d.", hdr.request); ret =3D (uint64_t)-EINVAL; diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 04596799e3..25e14ab17a 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -23,6 +23,24 @@ #define TYPE_VHOST_USER_FS "vhost-user-fs-device" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserFS, VHOST_USER_FS) =20 +/* Structures carried over the slave channel back to QEMU */ +#define VHOST_USER_FS_SLAVE_ENTRIES 8 + +/* For the flags field of VhostUserFSSlaveMsg */ +#define VHOST_USER_FS_FLAG_MAP_R (1ull << 0) +#define VHOST_USER_FS_FLAG_MAP_W (1ull << 1) + +typedef struct { + /* Offsets within the file being mapped */ + uint64_t fd_offset[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Offsets within the cache */ + uint64_t c_offset[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Lengths of sections */ + uint64_t len[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Flags, from VHOST_USER_FS_FLAG_* */ + uint64_t flags[VHOST_USER_FS_SLAVE_ENTRIES]; +} VhostUserFSSlaveMsg; + typedef struct { CharBackend chardev; char *tag; @@ -46,4 +64,10 @@ struct VHostUserFS { MemoryRegion cache; }; =20 +/* Callbacks from the vhost-user code for slave commands */ +uint64_t vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMs= g *sm, + int fd); +uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *dev, + VhostUserFSSlaveMsg *sm); + #endif /* _QEMU_VHOST_USER_FS_H */ diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index e12e9c1532..150b1121cc 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -119,6 +119,8 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3D 3, VHOST_USER_SLAVE_VRING_CALL =3D 4, VHOST_USER_SLAVE_VRING_ERR =3D 5, + VHOST_USER_SLAVE_FS_MAP =3D 6, + VHOST_USER_SLAVE_FS_UNMAP =3D 7, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897883; cv=none; d=zohomail.com; s=zohoarc; b=akD1fz3//gFOG4NyChB9IAYY5ewFLPM+TM2qqQv+D9tM8jPBJaqZpcGijWtmW+KLol2QwSLcNHycLNPDRvekspmkDVD/jJu31epF2Gmfpcfnox//bcsNTCx1fMBd3kviB9TjUXagatX4sInbHXaFE6TiQN92Mv6tIpV+3oor3a4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897883; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q2BHuaHwyAeHruEDsZi0dteCYPsHDGR868zs0c/yNDs=; b=KnxfwCnEPIQ8ZFjykGCTZMIjqXmnihPr02/n0cRbsaawNG+GkSY1X89SqOptYnjBku1uteNp0twIkIBqbPbfwC/VKVJ/2NiI48EavQEqjV2e1HkWFaelWQcQxSrLERfD/qzjAF8xcycD2XwEXNtUNm9lb7MG0rVsJd2mA0ulyk0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161289788283262.48388682146913; Tue, 9 Feb 2021 11:11:22 -0800 (PST) Received: from localhost ([::1]:58790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YPx-0008MS-QA for importer@patchew.org; Tue, 09 Feb 2021 14:11:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJR-0002xU-TB for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJP-00022l-2x for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-490-poSY6VNJMXi4pe0pfFs2GQ-1; Tue, 09 Feb 2021 14:04:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F08D79EC7 for ; Tue, 9 Feb 2021 19:04:31 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE7D860C04; Tue, 9 Feb 2021 19:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q2BHuaHwyAeHruEDsZi0dteCYPsHDGR868zs0c/yNDs=; b=XTlFaaybKN/5aP/xjcHZs6X52mmx6noB0ded8Pwvi1WNKN6dSdU1uZFcgbaSyds7+r0Ccy kxVkUpd9CMcvrYbmcrDfXSo25/ur/3FE8vajTceD4dL1/dr1qZfQ880jxgfgASIWljc8PQ HNdeZrnip+0fw1IbEpsVNc3ZpN5o3/w= X-MC-Unique: poSY6VNJMXi4pe0pfFs2GQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 08/24] DAX: virtio-fs: Fill in slave commands for mapping Date: Tue, 9 Feb 2021 19:02:08 +0000 Message-Id: <20210209190224.62827-9-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Fill in definitions for map, unmap and sync commands. Signed-off-by: Dr. David Alan Gilbert with fix by misono.tomohiro@fujitsu.com --- hw/virtio/vhost-user-fs.c | 115 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 78401d2ff1..5f2fca4d82 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -37,15 +37,122 @@ uint64_t vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMs= g *sm, int fd) { - /* TODO */ - return (uint64_t)-1; + VHostUserFS *fs =3D VHOST_USER_FS(dev->vdev); + if (!fs) { + /* Shouldn't happen - but seen on error path */ + error_report("Bad fs ptr"); + return (uint64_t)-1; + } + size_t cache_size =3D fs->conf.cache_size; + if (!cache_size) { + error_report("map called when DAX cache not present"); + return (uint64_t)-1; + } + void *cache_host =3D memory_region_get_ram_ptr(&fs->cache); + + unsigned int i; + int res =3D 0; + + if (fd < 0) { + error_report("Bad fd for map"); + return (uint64_t)-1; + } + + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES; i++) { + if (sm->len[i] =3D=3D 0) { + continue; + } + + if ((sm->c_offset[i] + sm->len[i]) < sm->len[i] || + (sm->c_offset[i] + sm->len[i]) > cache_size) { + error_report("Bad offset/len for map [%d] %" PRIx64 "+%" PRIx6= 4, + i, sm->c_offset[i], sm->len[i]); + res =3D -1; + break; + } + + if (mmap(cache_host + sm->c_offset[i], sm->len[i], + ((sm->flags[i] & VHOST_USER_FS_FLAG_MAP_R) ? PROT_READ : = 0) | + ((sm->flags[i] & VHOST_USER_FS_FLAG_MAP_W) ? PROT_WRITE := 0), + MAP_SHARED | MAP_FIXED, + fd, sm->fd_offset[i]) !=3D (cache_host + sm->c_offset[i])= ) { + res =3D -errno; + error_report("map failed err %d [%d] %" PRIx64 "+%" PRIx64 " f= rom %" + PRIx64, errno, i, sm->c_offset[i], sm->len[i], + sm->fd_offset[i]); + break; + } + } + + if (res) { + /* Something went wrong, unmap them all */ + vhost_user_fs_slave_unmap(dev, sm); + } + return (uint64_t)res; } =20 uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm) { - /* TODO */ - return (uint64_t)-1; + VHostUserFS *fs =3D VHOST_USER_FS(dev->vdev); + if (!fs) { + /* Shouldn't happen - but seen on error path */ + error_report("Bad fs ptr"); + return (uint64_t)-1; + } + size_t cache_size =3D fs->conf.cache_size; + if (!cache_size) { + /* + * Since dax cache is disabled, there should be no unmap request. + * Howerver we still receives whole range unmap request during umo= unt + * for cleanup. Ignore it. + */ + if (sm->len[0] =3D=3D ~(uint64_t)0) { + return 0; + } + + error_report("unmap called when DAX cache not present"); + return (uint64_t)-1; + } + void *cache_host =3D memory_region_get_ram_ptr(&fs->cache); + + unsigned int i; + int res =3D 0; + + /* + * Note even if one unmap fails we try the rest, since the effect + * is to clean up as much as possible. + */ + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES; i++) { + void *ptr; + if (sm->len[i] =3D=3D 0) { + continue; + } + + if (sm->len[i] =3D=3D ~(uint64_t)0) { + /* Special case meaning the whole arena */ + sm->len[i] =3D cache_size; + } + + if ((sm->c_offset[i] + sm->len[i]) < sm->len[i] || + (sm->c_offset[i] + sm->len[i]) > cache_size) { + error_report("Bad offset/len for unmap [%d] %" PRIx64 "+%" PRI= x64, + i, sm->c_offset[i], sm->len[i]); + res =3D -1; + continue; + } + + ptr =3D mmap(cache_host + sm->c_offset[i], sm->len[i], DAX_WINDOW_= PROT, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + if (ptr !=3D (cache_host + sm->c_offset[i])) { + res =3D -errno; + error_report("mmap failed (%s) [%d] %" PRIx64 "+%" PRIx64 " fr= om %" + PRIx64 " res: %p", strerror(errno), i, sm->c_offs= et[i], + sm->len[i], sm->fd_offset[i], ptr); + } + } + + return (uint64_t)res; } =20 static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898628; cv=none; d=zohomail.com; s=zohoarc; b=byi+kwImHDy2tQrD225ZqQF7idCFw3kt+JTQdd5oOwNo+qUkh7/R8meDqstsIVKkushcX/WOeZ7MrOyjgXxz72+Gv8kL7QX7UvPVKP0BbKgCLVW0VFJLWzQyprVOyP0nJ3r9263Oo53aJdRik8LVLqC11W3UxdQdp9jOqmThwYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898628; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jNEBGGAYn3wMh9aSrFeptYiM+eCb3vvFensafMYNNV8=; b=IyxHB51PXLeHboBIdJmlIX6HJ0Xbg8mwC35xFv2gZA3eccecgUxVyogzYukRpSIzrDUOZfAnh9Scd2U8nmMN4ubGFsI3Y6yrXHlCW3cX4LMsdvkU3DREeR1hiJLtqofpAh85jO9JjUO709eNYbwLz+V1e291oheQmd6KXpvfQJ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16128986276211017.6512095038883; Tue, 9 Feb 2021 11:23:47 -0800 (PST) Received: from localhost ([::1]:57462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Yby-0003Qd-Ju for importer@patchew.org; Tue, 09 Feb 2021 14:23:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJU-0002xo-20 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJR-00023Y-So for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-513-k_wJiKeUO7i6BKy6nJaEYA-1; Tue, 09 Feb 2021 14:04:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96C5580196E for ; Tue, 9 Feb 2021 19:04:33 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDBF960C04; Tue, 9 Feb 2021 19:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jNEBGGAYn3wMh9aSrFeptYiM+eCb3vvFensafMYNNV8=; b=Lb3iIvTnq8dIDmXN+oymL57sECCffy7+5GzYL6PMnWbnneTKaxvaRhJZvKBW8sB1a9huNI PQhvuY/7R/0wVkDt5IKM+kV7KLeo0zs9cYqD0ZCt7uitCHJQxKkt2WcqDjVNKLcN6+6JbC C7pxeS5Xo7RdJWE0QXKW2gIquP1ke4U= X-MC-Unique: k_wJiKeUO7i6BKy6nJaEYA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 09/24] DAX: virtiofsd Add cache accessor functions Date: Tue, 9 Feb 2021 19:02:09 +0000 Message-Id: <20210209190224.62827-10-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add low level functions that the clients can use to map/unmap cache areas. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_lowlevel.h | 21 +++++++++++++++++++++ tools/virtiofsd/fuse_virtio.c | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index 0e10a14bc9..c0ff4f07a4 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -29,6 +29,8 @@ #include #include =20 +#include "subprojects/libvhost-user/libvhost-user.h" + /* * Miscellaneous definitions */ @@ -1970,4 +1972,23 @@ void fuse_session_process_buf(struct fuse_session *s= e, */ int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf= ); =20 +/** + * For use with virtio-fs; request an fd be mapped into the cache + * + * @param req The request that triggered this action + * @param msg A set of mapping requests + * @param fd The fd to map + * @return Zero on success + */ +int64_t fuse_virtio_map(fuse_req_t req, VhostUserFSSlaveMsg *msg, int fd); + +/** + * For use with virtio-fs; request unmapping of part of the cache + * + * @param se The session this request is on + * @param msg A set of unmapping requests + * @return Zero on success + */ +int64_t fuse_virtio_unmap(struct fuse_session *se, VhostUserFSSlaveMsg *ms= g); + #endif /* FUSE_LOWLEVEL_H_ */ diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index bd19358437..f217a093c8 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -1044,3 +1044,21 @@ void virtio_session_close(struct fuse_session *se) free(se->virtio_dev); se->virtio_dev =3D NULL; } + +int64_t fuse_virtio_map(fuse_req_t req, VhostUserFSSlaveMsg *msg, int fd) +{ + if (!req->se->virtio_dev) { + return -ENODEV; + } + return vu_fs_cache_request(&req->se->virtio_dev->dev, + VHOST_USER_SLAVE_FS_MAP, fd, msg); +} + +int64_t fuse_virtio_unmap(struct fuse_session *se, VhostUserFSSlaveMsg *ms= g) +{ + if (!se->virtio_dev) { + return -ENODEV; + } + return vu_fs_cache_request(&se->virtio_dev->dev, VHOST_USER_SLAVE_FS_U= NMAP, + -1, msg); +} --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898168; cv=none; d=zohomail.com; s=zohoarc; b=mb/H6ye0U1vQKZLG1BCVC0K5qIjLEiJkpKFQ7cVAyBgxSFNajO9Sx7ED5x4C8lwv5cDXujO6mpp1Y004LEhU2fq8NL1t84dkHTaqys4HyztAOT7afajes2fZEEKxcmtwpVSzzUsDi8LJQxPfa+SkwgsRWxeya7HCZ9JmiNwBVUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898168; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3OdXa2R5nkQoYYUAIjiNx1jwsxesCSlibW3o1SjJNvE=; b=Xq82ukAul3CnyQEHhQH1nr3ws++bg+IbFuQqusXARynRiBSODocsYjpy9Dkg+Ssy1UfO/SCNRiO9AGcX0y7C2N6NAKtua63e0q4/b/EO06j+2c0+5V4nv0mi6pxyknFkA7b1MIU0b8MsGJjR04ouzFSSMihfVajg3PJh7B9ZtsY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898168343383.1633059118685; Tue, 9 Feb 2021 11:16:08 -0800 (PST) Received: from localhost ([::1]:38948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YUY-0003a5-MQ for importer@patchew.org; Tue, 09 Feb 2021 14:16:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJl-0002zJ-Ce for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJf-00025M-IS for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:04:56 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-3_TC7P3pOMOK0xCSCncAWg-1; Tue, 09 Feb 2021 14:04:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12CD6801982 for ; Tue, 9 Feb 2021 19:04:48 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1BC760C04; Tue, 9 Feb 2021 19:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3OdXa2R5nkQoYYUAIjiNx1jwsxesCSlibW3o1SjJNvE=; b=ikLkMp0LZd6a9d5VfTfYH+6m32BEIdU4qaaUHeZU+I9zanrq0LOSjgZpqtVIpXYU+Cq+79 S+nF1H3bKpr5INhFUEfeXQR6+mkdvcG2ZcwZcs0gxSHNOUp7RwGFCQ6bXl9Su+rznlD9EW 5qTehZ5uY3U4Xk1s+ToUH1gol6yi4Vo= X-MC-Unique: 3_TC7P3pOMOK0xCSCncAWg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 10/24] DAX: virtiofsd: Add setup/remove mappings fuse commands Date: Tue, 9 Feb 2021 19:02:10 +0000 Message-Id: <20210209190224.62827-11-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add commands so that the guest kernel can ask the daemon to map file sections into a guest kernel visible cache. Note: Catherine Ho had sent a patch to fix an issue with multiple removemapping. It was a merge issue though. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Vivek Goyal Signed-off-by: Peng Tao Including-fixes: Catherine Ho Signed-off-by: Catherine Ho --- tools/virtiofsd/fuse_lowlevel.c | 68 +++++++++++++++++++++++++++++++++ tools/virtiofsd/fuse_lowlevel.h | 23 ++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index e94b71110b..0d3768b7d0 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1868,6 +1868,72 @@ static void do_lseek(fuse_req_t req, fuse_ino_t node= id, } } =20 +static void do_setupmapping(fuse_req_t req, fuse_ino_t nodeid, + struct fuse_mbuf_iter *iter) +{ + struct fuse_setupmapping_in *arg; + struct fuse_file_info fi; + + arg =3D fuse_mbuf_iter_advance(iter, sizeof(*arg)); + if (!arg) { + fuse_reply_err(req, EINVAL); + return; + } + + memset(&fi, 0, sizeof(fi)); + fi.fh =3D arg->fh; + + /* + * TODO: Need to come up with a better definition of flags here; it c= an't + * be the kernel view of the flags, since that's abstracted from the c= lient + * similarly, it's not the vhost-user set + * for now just use O_ flags + */ + uint64_t genflags; + + genflags =3D O_RDONLY; + if (arg->flags & FUSE_SETUPMAPPING_FLAG_WRITE) { + genflags =3D O_RDWR; + } + + if (req->se->op.setupmapping) { + req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len, + arg->moffset, genflags, &fi); + } else { + fuse_reply_err(req, ENOSYS); + } +} + +static void do_removemapping(fuse_req_t req, fuse_ino_t nodeid, + struct fuse_mbuf_iter *iter) +{ + struct fuse_removemapping_in *arg; + struct fuse_removemapping_one *one; + + arg =3D fuse_mbuf_iter_advance(iter, sizeof(*arg)); + if (!arg || arg->count <=3D 0) { + fuse_log(FUSE_LOG_ERR, "do_removemapping: invalid arg %p\n", arg); + fuse_reply_err(req, EINVAL); + return; + } + + one =3D fuse_mbuf_iter_advance(iter, arg->count * sizeof(*one)); + if (!one) { + fuse_log( + FUSE_LOG_ERR, + "do_removemapping: invalid in, expected %d * %ld, has %ld - %l= d\n", + arg->count, sizeof(*one), iter->size, iter->pos); + fuse_reply_err(req, EINVAL); + return; + } + + if (req->se->op.removemapping) { + req->se->op.removemapping(req, req->se, nodeid, arg->count, one); + } else { + fuse_reply_err(req, ENOSYS); + } +} + static void do_init(fuse_req_t req, fuse_ino_t nodeid, struct fuse_mbuf_iter *iter) { @@ -2258,6 +2324,8 @@ static struct { [FUSE_RENAME2] =3D { do_rename2, "RENAME2" }, [FUSE_COPY_FILE_RANGE] =3D { do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_LSEEK] =3D { do_lseek, "LSEEK" }, + [FUSE_SETUPMAPPING] =3D { do_setupmapping, "SETUPMAPPING" }, + [FUSE_REMOVEMAPPING] =3D { do_removemapping, "REMOVEMAPPING" }, }; =20 #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0])) diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index c0ff4f07a4..014564ff07 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -24,6 +24,7 @@ #endif =20 #include "fuse_common.h" +#include "standard-headers/linux/fuse.h" =20 #include #include @@ -1170,7 +1171,6 @@ struct fuse_lowlevel_ops { */ void (*readdirplus)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t= off, struct fuse_file_info *fi); - /** * Copy a range of data from one file to another * @@ -1226,6 +1226,27 @@ struct fuse_lowlevel_ops { */ void (*lseek)(fuse_req_t req, fuse_ino_t ino, off_t off, int whence, struct fuse_file_info *fi); + + /* + * Map file sections into kernel visible cache + * + * Map a section of the file into address space visible to the kernel + * mounting the filesystem. + * TODO + */ + void (*setupmapping)(fuse_req_t req, fuse_ino_t ino, uint64_t foffset, + uint64_t len, uint64_t moffset, uint64_t flags, + struct fuse_file_info *fi); + + /* + * Unmap file sections in kernel visible cache + * + * Unmap sections previously mapped by setupmapping + * TODO + */ + void (*removemapping)(fuse_req_t req, struct fuse_session *se, + fuse_ino_t ino, unsigned num, + struct fuse_removemapping_one *argp); }; =20 /** --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898836; cv=none; d=zohomail.com; s=zohoarc; b=aANSEStLxEPTSxtT6BwVl6pfhBOEz0s4l+byh5yjrWxBYj5tjGgNGqMy1hA/ZzldXVHClGPjRNTAiPWiiznWbJgqh4sr2DWCXZTVE63Uu8PS3k7drofy2rKWOu6lZ00++nyaNei9vfCaQk+s05v8P4MAoReBleGiOSCNiq6YpWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898836; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TGfTDXB3Y9zBXZDDsU0pPd8Flh5YS87NuxSF/Vj4+SA=; b=dUiTmNTT2LpUHt8Sz4+rgNRVgFFaJTyAV9yr4VQ7Wzu+nuP7djShE1WGRvrKa3z+oRTeAzqKy6TZlGrXCFkAM14EU+Zq7hYJ8L01Ysiw2ifKqHrTDtIzt2pGjf6R23oam/lcgzgEXG5F39L4diqwZuITwNmeQ4+lCrXVeo4QvdI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161289883615026.900356996176697; Tue, 9 Feb 2021 11:27:16 -0800 (PST) Received: from localhost ([::1]:37050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YfK-0007Ct-Vs for importer@patchew.org; Tue, 09 Feb 2021 14:27:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJs-0003Dx-O9 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJq-00027t-OK for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-RSupXggRMem0xp6twtEsvQ-1; Tue, 09 Feb 2021 14:04:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F09C5107ACE6 for ; Tue, 9 Feb 2021 19:04:52 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7516360C04; Tue, 9 Feb 2021 19:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TGfTDXB3Y9zBXZDDsU0pPd8Flh5YS87NuxSF/Vj4+SA=; b=P402asxQdOebfueYcZ22MpuqROa646mF5ZiVm18GGDozzzioSME4Lwu2Wr6u5Qy9rVShb9 FyoYi9I7QYuAY7L2RuPaD0wzx91XtExtoZfGtJSO2oHXWD2Iqfl+HcgyJ9CQ6cOE1YccDx 5O7n/wAhQRUzMGXts0epRNO8r+8c8Do= X-MC-Unique: RSupXggRMem0xp6twtEsvQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 11/24] DAX: virtiofsd: Add setup/remove mapping handlers to passthrough_ll Date: Tue, 9 Feb 2021 19:02:11 +0000 Message-Id: <20210209190224.62827-12-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 147b59338a..31c43d67a0 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2963,6 +2963,22 @@ static void lo_destroy(void *userdata) pthread_mutex_unlock(&lo->mutex); } =20 +static void lo_setupmapping(fuse_req_t req, fuse_ino_t ino, uint64_t foffs= et, + uint64_t len, uint64_t moffset, uint64_t flags, + struct fuse_file_info *fi) +{ + /* TODO */ + fuse_reply_err(req, ENOSYS); +} + +static void lo_removemapping(fuse_req_t req, struct fuse_session *se, + fuse_ino_t ino, unsigned num, + struct fuse_removemapping_one *argp) +{ + /* TODO */ + fuse_reply_err(req, ENOSYS); +} + static struct fuse_lowlevel_ops lo_oper =3D { .init =3D lo_init, .lookup =3D lo_lookup, @@ -3004,6 +3020,8 @@ static struct fuse_lowlevel_ops lo_oper =3D { #endif .lseek =3D lo_lseek, .destroy =3D lo_destroy, + .setupmapping =3D lo_setupmapping, + .removemapping =3D lo_removemapping, }; =20 /* Print vhost-user.json backend program capabilities */ --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898369; cv=none; d=zohomail.com; s=zohoarc; b=aoPqjhXirgcdTleY3PzU1pY/3mk6R/SDYWAt6BJ8WnIJj1pEe1srKRGuQB/GigxvvBa6Z2roGevGVHEH5BuKCDt7Vu16VAksAdPoscOB1HjP2+R1wgJAC8r2nDWAq/OdRqo33Qjh565IGjgJNtdPLIvTpkIr+RzFl/sC+nKTT9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898369; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4hyC0DoLv2hnyPTPX8CUYqMiRQq6B9qtchp08JRsbNU=; b=cBq99C8EUFJiXxBXd2KyDeFO5taXjvhkwIwppdXshlhSqfHIVENxlzeEnz6q1Fy1Su/Z+IVXmieOfsIhdqprzSoKNQFnL2A3qRY2TG4tM4gbhSgVUBvRra6cF0bXqPyomp1bpq6NLbyPWCjXg5HA1gij024/esc2KMCyvdmXrTA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898368618802.023973027242; Tue, 9 Feb 2021 11:19:28 -0800 (PST) Received: from localhost ([::1]:47150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YXm-0007H3-KL for importer@patchew.org; Tue, 09 Feb 2021 14:19:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YJr-0003C2-9v for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42008) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YJp-00027f-Ft for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-126-2YhafU3HOKKjtIXZ8-GVFQ-1; Tue, 09 Feb 2021 14:04:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1FC980196E for ; Tue, 9 Feb 2021 19:04:57 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5729C60C04; Tue, 9 Feb 2021 19:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4hyC0DoLv2hnyPTPX8CUYqMiRQq6B9qtchp08JRsbNU=; b=OnERQyh7rRKjTYAnWx2psMR6Va/l7/s9R+IiMjuWZKNJktfByQoSw88PtZTs3SusIqkMSQ G0yU9wtNJpO7DamVmY772ZmSzXfDtgZGwmuDIJOa/dDDcpVvhmXzyOdH13Yfu6ojxuS5gx p1+0DlXWxAVPolHSZNrmgolcjIzd7M4= X-MC-Unique: 2YhafU3HOKKjtIXZ8-GVFQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 12/24] DAX: virtiofsd: Wire up passthrough_ll's lo_setupmapping Date: Tue, 9 Feb 2021 19:02:12 +0000 Message-Id: <20210209190224.62827-13-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Wire up passthrough_ll's setupmapping to allocate, send to virtio and then reply OK. Guest might not pass file pointer. In that case using inode info, open the file again, mmap() and close fd. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Vivek Goyal With fix from: Signed-off-by: Fotis Xenakis Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_lowlevel.c | 13 ++++++-- tools/virtiofsd/passthrough_ll.c | 52 ++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 0d3768b7d0..f74583e095 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1897,8 +1897,17 @@ static void do_setupmapping(fuse_req_t req, fuse_ino= _t nodeid, } =20 if (req->se->op.setupmapping) { - req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len, - arg->moffset, genflags, &fi); + /* + * TODO: Add a flag to request which tells if arg->fh is + * valid or not. + */ + if (fi.fh =3D=3D (uint64_t)-1) { + req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len, + arg->moffset, genflags, NULL); + } else { + req->se->op.setupmapping(req, nodeid, arg->foffset, arg->len, + arg->moffset, genflags, &fi); + } } else { fuse_reply_err(req, ENOSYS); } diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 31c43d67a0..0493f00756 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2967,8 +2967,56 @@ static void lo_setupmapping(fuse_req_t req, fuse_ino= _t ino, uint64_t foffset, uint64_t len, uint64_t moffset, uint64_t flags, struct fuse_file_info *fi) { - /* TODO */ - fuse_reply_err(req, ENOSYS); + struct lo_data *lo =3D lo_data(req); + int ret =3D 0, fd; + VhostUserFSSlaveMsg msg =3D { 0 }; + uint64_t vhu_flags; + char *buf; + bool writable =3D flags & O_RDWR; + + fuse_log(FUSE_LOG_DEBUG, + "lo_setupmapping(ino=3D%" PRIu64 ", fi=3D0x%p," + " foffset=3D%" PRIu64 ", len=3D%" PRIu64 ", moffset=3D%" PRIu= 64 + ", flags=3D%" PRIu64 ")\n", + ino, (void *)fi, foffset, len, moffset, flags); + + vhu_flags =3D VHOST_USER_FS_FLAG_MAP_R; + if (writable) { + vhu_flags |=3D VHOST_USER_FS_FLAG_MAP_W; + } + + msg.fd_offset[0] =3D foffset; + msg.len[0] =3D len; + msg.c_offset[0] =3D moffset; + msg.flags[0] =3D vhu_flags; + + if (fi) { + fd =3D lo_fi_fd(req, fi); + } else { + ret =3D asprintf(&buf, "%i", lo_fd(req, ino)); + if (ret =3D=3D -1) { + return (void)fuse_reply_err(req, errno); + } + + fd =3D openat(lo->proc_self_fd, buf, flags); + free(buf); + if (fd =3D=3D -1) { + return (void)fuse_reply_err(req, errno); + } + } + + ret =3D fuse_virtio_map(req, &msg, fd); + if (ret < 0) { + fuse_log(FUSE_LOG_ERR, + "%s: map over virtio failed (ino=3D%" PRId64 + "fd=3D%d moffset=3D0x%" PRIx64 "). err =3D %d\n", + __func__, ino, fd, moffset, ret); + } + + if (!fi) { + close(fd); + } + fuse_reply_err(req, -ret); } =20 static void lo_removemapping(fuse_req_t req, struct fuse_session *se, --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898536; cv=none; d=zohomail.com; s=zohoarc; b=SY8kC2iWgLhUTFp8oHVuP+kKaxBMNgzOjzvZZSDaRFWMm+QQDWdThHwC1CxQSmdTeEhKyaKHo+hbQ99H/fzku3XuBjAg15YayPWl5R0kis3ML/a4Vq6/fsCAwvYJd7rZqIIKEIqW90AO6JHLuF5ipjhHopTUawwj5dNX3zUM6z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898536; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2HE8LrddnxGky44SJcOH9gN83cUyYp9owH4SNW0DxjQ=; b=XOU5WXPY//vCkhxibirxu+/xhn4Yz4YrYhc9CqBYEByw4UfkibCap94YCwJUqVR8SEkw88zZyW4174yMU2oj+ETpxWr9DZrcJcvbyt2kQcN2HYvJai5J+PWy6poc86vpNQrPGCTJukTXrKw50BVS7hTW6YjVVd/RtaVZM4s/+HM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898536336402.37905931915043; Tue, 9 Feb 2021 11:22:16 -0800 (PST) Received: from localhost ([::1]:53602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YaV-0001jf-6t for importer@patchew.org; Tue, 09 Feb 2021 14:22:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YKG-0003RM-Rt for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKE-0002Dq-1N for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:28 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-8VkxbY-cMA2Q-SpmnMbATA-1; Tue, 09 Feb 2021 14:05:17 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C04A803F4A for ; Tue, 9 Feb 2021 19:05:16 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 393E960C04; Tue, 9 Feb 2021 19:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2HE8LrddnxGky44SJcOH9gN83cUyYp9owH4SNW0DxjQ=; b=bEbA3POd0RxlCHtB2a37cD94WUiOKZ0hgWqj6r73GZdUuGTtFn7Ww7aYaVjmIgQp4Rs6Mz ehVIkViZ8jrycwjH70HzByQ2g8mM1GyKVYdDp/tPMOSbKTAugHdxrRl/qccssnOFtAH235 OA6HIxwbOFUc6RXdPanJO6msifQNGxI= X-MC-Unique: 8VkxbY-cMA2Q-SpmnMbATA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 13/24] DAX: virtiofsd: Make lo_removemapping() work Date: Tue, 9 Feb 2021 19:02:13 +0000 Message-Id: <20210209190224.62827-14-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vivek Goyal Let guest pass in the offset in dax window a mapping is currently mapped at and needs to be removed. Vivek added the initial support to remove single mapping and later Peng added patch to support removing multiple mappings in single command. Signed-off-by: Vivek Goyal Signed-off-by: Peng Tao Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 0493f00756..971ff2b2ea 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -3023,8 +3023,30 @@ static void lo_removemapping(fuse_req_t req, struct = fuse_session *se, fuse_ino_t ino, unsigned num, struct fuse_removemapping_one *argp) { - /* TODO */ - fuse_reply_err(req, ENOSYS); + VhostUserFSSlaveMsg msg =3D { 0 }; + int ret =3D 0; + + for (int i =3D 0; num > 0; i++, argp++) { + msg.len[i] =3D argp->len; + msg.c_offset[i] =3D argp->moffset; + + if (--num =3D=3D 0 || i =3D=3D VHOST_USER_FS_SLAVE_ENTRIES - 1) { + ret =3D fuse_virtio_unmap(se, &msg); + if (ret < 0) { + fuse_log(FUSE_LOG_ERR, + "%s: unmap over virtio failed " + "(offset=3D0x%lx, len=3D0x%lx). err=3D%d\n", + __func__, argp->moffset, argp->len, ret); + break; + } + if (num > 0) { + i =3D 0; + memset(&msg, 0, sizeof(msg)); + } + } + } + + fuse_reply_err(req, -ret); } =20 static struct fuse_lowlevel_ops lo_oper =3D { --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898764; cv=none; d=zohomail.com; s=zohoarc; b=KoUqso23305qI+cZYDNauribaaai8IxqK4rIkV/Uvy+YJ8Bojxqo4/n4t4r8m8vGrk+ot0oddBVpqb5TajFQaSkPWbAN6P2glGR0UYvOUAuCRVnH4c/GclJyNZkVBBK11AgYgGzFKRQBYQz2mlJHKarJ6ZzCYVJJSPo1KANKm78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898764; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O+SJEeMxpjc2p11R+aC1gV3DJGZOs4v0Hd4xIFSvH90=; b=D9vKi0FS7On3YTFhb6tmcWQIGMdYr9/uRL+5vxWSw8d+5iJrLfPqiLGai0JOdRzfl/gRYjFRD/cXD139XyWN6bnGOSzd/JpSaZA4wdjJrfdhX3hgM2M261voklGo8cyA7/qkFG4YTECjOyJXpA1G1YfVuEuCXX6if8V60zOyG8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898764566513.3140928070966; Tue, 9 Feb 2021 11:26:04 -0800 (PST) Received: from localhost ([::1]:60260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YeB-0004qY-EI for importer@patchew.org; Tue, 09 Feb 2021 14:26:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YKO-0003Vp-0r for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKL-0002Gi-Lx for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:35 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-0mZGH2YzNQSJueyissahXg-1; Tue, 09 Feb 2021 14:05:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72D59107ACC7 for ; Tue, 9 Feb 2021 19:05:29 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96D0E60C04; Tue, 9 Feb 2021 19:05:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O+SJEeMxpjc2p11R+aC1gV3DJGZOs4v0Hd4xIFSvH90=; b=KzDswFKbr4/fB8X90dupDBGFLgatsDcHbo84b9jVV/3NbrOsl2KAYm9YXY3/nl0fR9igef LaGsNb9B7HQPQBBHSZbJSy0ovPmi1Jlh9MUBiXKNaDthrqrd39z/s9uDaTeN5AWKlsYRxg 7ACxERbS/62Nqt3cBPdWnC2zlxPxJ40= X-MC-Unique: 0mZGH2YzNQSJueyissahXg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 14/24] DAX: virtiofsd: route se down to destroy method Date: Tue, 9 Feb 2021 19:02:14 +0000 Message-Id: <20210209190224.62827-15-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" We're going to need to pass the session down to destroy so that it can pass it back to do the remove mapping. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_lowlevel.c | 6 +++--- tools/virtiofsd/fuse_lowlevel.h | 2 +- tools/virtiofsd/passthrough_ll.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index f74583e095..99ba000c2e 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -2212,7 +2212,7 @@ static void do_destroy(fuse_req_t req, fuse_ino_t nod= eid, se->got_destroy =3D 1; se->got_init =3D 0; if (se->op.destroy) { - se->op.destroy(se->userdata); + se->op.destroy(se->userdata, se); } =20 send_reply_ok(req, NULL, 0); @@ -2439,7 +2439,7 @@ void fuse_session_process_buf_int(struct fuse_session= *se, se->got_destroy =3D 1; se->got_init =3D 0; if (se->op.destroy) { - se->op.destroy(se->userdata); + se->op.destroy(se->userdata, se); } } else { goto reply_err; @@ -2527,7 +2527,7 @@ void fuse_session_destroy(struct fuse_session *se) { if (se->got_init && !se->got_destroy) { if (se->op.destroy) { - se->op.destroy(se->userdata); + se->op.destroy(se->userdata, se); } } pthread_rwlock_destroy(&se->init_rwlock); diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index 014564ff07..53439f5432 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -208,7 +208,7 @@ struct fuse_lowlevel_ops { * * @param userdata the user data passed to fuse_session_new() */ - void (*destroy)(void *userdata); + void (*destroy)(void *userdata, struct fuse_session *se); =20 /** * Look up a directory entry by name and get its attributes. diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 971ff2b2ea..badac23fef 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2943,7 +2943,7 @@ static void lo_lseek(fuse_req_t req, fuse_ino_t ino, = off_t off, int whence, } } =20 -static void lo_destroy(void *userdata) +static void lo_destroy(void *userdata, struct fuse_session *se) { struct lo_data *lo =3D (struct lo_data *)userdata; =20 --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898892; cv=none; d=zohomail.com; s=zohoarc; b=FigSRAEmZSvG4Rfcu5C/tvLyZXIPR6ivsRlwR/925l44DykO/B9ki7mwNuNI7V9Pl1KHVM6GmCQt+Q5nqA9qSeEDBZVZx0gpUat5wxKzghz8cYrrKID1IR/xkYM2CfYEMwmsSfo3G7OQxFOPmakEEtdS5K7ZYYJT1ORS/fLHF18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898892; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hCd5VPaweV0QnK2JlRUPl/yoUKg+WTPaXC8x4ej1Qts=; b=X5AjooNKgzowRY19VlG7B7m0OMCFhOrm9vCMESye9xhvxKGlc6Tm8M1SIf9f6ITeau7NSoVXRPkr8VeVbnakBHfSJCYgARiBXlEOzA5SqXfkbKk7FBDPCGoh8zrdULXC76DloUf+IWkT1BQYJvhL1/RhuVjz7Oz0vQVW4V6tfGQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898892454764.302095066549; Tue, 9 Feb 2021 11:28:12 -0800 (PST) Received: from localhost ([::1]:40196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YgF-0000Ug-6G for importer@patchew.org; Tue, 09 Feb 2021 14:28:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YKU-0003aw-M8 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKS-0002Ht-Hj for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:05:42 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-f5merSrRMaiYB1Cp02WNQA-1; Tue, 09 Feb 2021 14:05:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D9D3192AB78 for ; Tue, 9 Feb 2021 19:05:36 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5EF860C04; Tue, 9 Feb 2021 19:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hCd5VPaweV0QnK2JlRUPl/yoUKg+WTPaXC8x4ej1Qts=; b=dO/F4S0/hNIWornNoAd/CmunlGf4OS6zhY7hD2DJZvdsvxz/1h8APT4My06sa/1YArx7E9 XByTRD0LTCJRnOJCOWxHNLVad7a/+VVtX1d08tqfUhFt2Cq079dy5OtFf3jhCbY5TXTeJq 6XJxAczjojG2IuRqTdk1OOVbcORukzs= X-MC-Unique: f5merSrRMaiYB1Cp02WNQA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 15/24] DAX: virtiofsd: Perform an unmap on destroy Date: Tue, 9 Feb 2021 19:02:15 +0000 Message-Id: <20210209190224.62827-16-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Force unmap all remaining dax cache entries on a destroy. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index badac23fef..21ddb434ae 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2947,6 +2947,17 @@ static void lo_destroy(void *userdata, struct fuse_s= ession *se) { struct lo_data *lo =3D (struct lo_data *)userdata; =20 + if (fuse_lowlevel_is_virtio(se)) { + VhostUserFSSlaveMsg msg =3D { 0 }; + + msg.len[0] =3D ~(uint64_t)0; /* Special: means 'all' */ + msg.c_offset[0] =3D 0; + if (fuse_virtio_unmap(se, &msg)) { + fuse_log(FUSE_LOG_ERR, "%s: unmap during destroy failed\n", + __func__); + } + } + pthread_mutex_lock(&lo->mutex); while (true) { GHashTableIter iter; --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898086; cv=none; d=zohomail.com; s=zohoarc; b=TdC0oiByMeyVwJxVDJx/u0M8b/nzi2cYtJwZN45X0Cs018G8sC1R4p4uvwjtRLpKCQWdqYDF9CATXXrin6i7QNgx/qTwf0TcNMOlVLWUpXVSrGLcBg+TcxFi4w/PZvfTQkfEJb8h7eSkVlZ7YLSl9hLkqYpNwx3VPfGfRWinLUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898086; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iNzMYMma9BmiNHsoGKqBx/7LZMqn2DePQZYu1UsVyUo=; b=Sr1mzwFlmoCZ+q4dTFAJne7y/xhkBWXpRRCHOt6lqBQhHq3L4i0HgG6/imGGwryhsv8HPmlgjZ2PfDoQ+Bmk1NfRdX/0JO+jzZ/tRT1Pu6k0XQntEUmoO5hoJNgZXo5dxTb95Uy2PWiU6sMf0b05YtSWbJ8ye7pXf/xIailjfXI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898085768500.6027132404331; Tue, 9 Feb 2021 11:14:45 -0800 (PST) Received: from localhost ([::1]:37200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YTE-0002rZ-KY for importer@patchew.org; Tue, 09 Feb 2021 14:14:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLQ-0004L5-Hy for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKZ-0002NQ-Lh for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-n0I18hqQPoGOBzj3UYhKuQ-1; Tue, 09 Feb 2021 14:05:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 890FE803F47 for ; Tue, 9 Feb 2021 19:05:41 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0BA960C04; Tue, 9 Feb 2021 19:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iNzMYMma9BmiNHsoGKqBx/7LZMqn2DePQZYu1UsVyUo=; b=ePdFY3ZlSfJqgS4kkzjJQrnw+iX4FpBFPAokn+i+UXMTM+hXa+7psKMpsQQg+jaO5Qql6z /RKEp2nOipRzeijUzO1IdOc1LhLjKyGLSYZiOWik3zkME7w6yVWT7SYAozBYowcqrLAXom Q/Vj6tgrJn+wB0mLxB+aBUgb1Wa1IKQ= X-MC-Unique: n0I18hqQPoGOBzj3UYhKuQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 16/24] DAX/unmap: virtiofsd: Add VHOST_USER_SLAVE_FS_IO Date: Tue, 9 Feb 2021 19:02:16 +0000 Message-Id: <20210209190224.62827-17-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Define a new slave command 'VHOST_USER_SLAVE_FS_IO' for a client to ask qemu to perform a read/write from an fd directly to GPA. Signed-off-by: Dr. David Alan Gilbert --- docs/interop/vhost-user.rst | 11 +++ hw/virtio/trace-events | 6 ++ hw/virtio/vhost-user-fs.c | 84 +++++++++++++++++++++++ hw/virtio/vhost-user.c | 4 ++ include/hw/virtio/vhost-user-fs.h | 2 + subprojects/libvhost-user/libvhost-user.h | 1 + 6 files changed, 108 insertions(+) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 1deedd3407..821712f4a2 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -1452,6 +1452,17 @@ Slave message types multiple chunks can be unmapped in one command. A reply is generated indicating whether unmapping succeeded. =20 +``VHOST_USER_SLAVE_FS_IO`` + :id: 9 + :equivalent ioctl: N/A + :slave payload: fd + n * (offset + address + len) + :master payload: N/A + + Requests that the QEMU performs IO directly from an fd to guest memory + on behalf of the daemon; this is normally for a case where a memory regi= on + isn't visible to the daemon. slave payload has flags which determine + the direction of IO operation. + .. _reply_ack: =20 VHOST_USER_PROTOCOL_F_REPLY_ACK diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index c62727f879..20557a078e 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -53,6 +53,12 @@ vhost_vdpa_get_features(void *dev, uint64_t features) "d= ev: %p features: 0x%"PRI vhost_vdpa_set_owner(void *dev) "dev: %p" vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint6= 4_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_add= r: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64 =20 +# vhost-user-fs.c + +vhost_user_fs_slave_io_loop(const char *name, uint64_t owr, int is_ram, in= t is_romd, size_t size) "region %s with internal offset 0x%"PRIx64 " ram=3D= %d romd=3D%d mrs.size=3D%zd" +vhost_user_fs_slave_io_loop_res(ssize_t transferred) "%zd" +vhost_user_fs_slave_io_exit(int res, size_t done) "res: %d done: %zd" + # virtio.c virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned o= ut_num) "elem %p size %zd in_num %u out_num %u" virtqueue_fill(void *vq, const void *elem, unsigned int len, unsigned int = idx) "vq %p elem %p len %u idx %u" diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 5f2fca4d82..357bc1d04e 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -23,6 +23,8 @@ #include "hw/virtio/vhost-user-fs.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" +#include "exec/address-spaces.h" +#include "trace.h" =20 /* * The powerpc kernel code expects the memory to be accessible during @@ -155,6 +157,88 @@ uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *d= ev, return (uint64_t)res; } =20 +uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev, VhostUserFSSlaveMsg= *sm, + int fd) +{ + VHostUserFS *fs =3D VHOST_USER_FS(dev->vdev); + if (!fs) { + /* Shouldn't happen - but seen it in error paths */ + error_report("Bad fs ptr"); + return (uint64_t)-1; + } + + unsigned int i; + int res =3D 0; + size_t done =3D 0; + + if (fd < 0) { + error_report("Bad fd for map"); + return (uint64_t)-1; + } + + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES && !res; i++) { + if (sm->len[i] =3D=3D 0) { + continue; + } + + size_t len =3D sm->len[i]; + hwaddr gpa =3D sm->c_offset[i]; + + while (len && !res) { + MemoryRegionSection mrs =3D memory_region_find(get_system_memo= ry(), + gpa, len); + size_t mrs_size =3D (size_t)int128_get64(mrs.size); + + if (!mrs_size) { + error_report("No guest region found for 0x%" HWADDR_PRIx, = gpa); + res =3D -EFAULT; + break; + } + + trace_vhost_user_fs_slave_io_loop(mrs.mr->name, + (uint64_t)mrs.offset_within_regi= on, + memory_region_is_ram(mrs.mr), + memory_region_is_romd(mrs.mr), + (size_t)mrs_size); + + void *hostptr =3D qemu_map_ram_ptr(mrs.mr->ram_block, + mrs.offset_within_region); + ssize_t transferred; + if (sm->flags[i] & VHOST_USER_FS_FLAG_MAP_R) { + /* Read from file into RAM */ + if (mrs.mr->readonly) { + res =3D -EFAULT; + break; + } + transferred =3D pread(fd, hostptr, mrs_size, sm->fd_offset= [i]); + } else { + /* Write into file from RAM */ + assert((sm->flags[i] & VHOST_USER_FS_FLAG_MAP_W)); + transferred =3D pwrite(fd, hostptr, mrs_size, sm->fd_offse= t[i]); + } + trace_vhost_user_fs_slave_io_loop_res(transferred); + if (transferred < 0) { + res =3D -errno; + break; + } + if (!transferred) { + /* EOF */ + break; + } + + done +=3D transferred; + len -=3D transferred; + } + } + close(fd); + + trace_vhost_user_fs_slave_io_exit(res, done); + if (res < 0) { + return (uint64_t)res; + } + return (uint64_t)done; +} + static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 21e40ff91a..0bc83c2714 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -137,6 +137,7 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_VRING_ERR =3D 5, VHOST_USER_SLAVE_FS_MAP =3D 6, VHOST_USER_SLAVE_FS_UNMAP =3D 7, + VHOST_USER_SLAVE_FS_IO =3D 8, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 @@ -1485,6 +1486,9 @@ static void slave_read(void *opaque) case VHOST_USER_SLAVE_FS_UNMAP: ret =3D vhost_user_fs_slave_unmap(dev, &payload.fs); break; + case VHOST_USER_SLAVE_FS_IO: + ret =3D vhost_user_fs_slave_io(dev, &payload.fs, fd[0]); + break; #endif default: error_report("Received unexpected msg type: %d.", hdr.request); diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 25e14ab17a..ffd3165c29 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -69,5 +69,7 @@ uint64_t vhost_user_fs_slave_map(struct vhost_dev *dev, V= hostUserFSSlaveMsg *sm, int fd); uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm); +uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev, VhostUserFSSlaveMsg= *sm, + int fd); =20 #endif /* _QEMU_VHOST_USER_FS_H */ diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index 150b1121cc..a398148ed9 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -121,6 +121,7 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_VRING_ERR =3D 5, VHOST_USER_SLAVE_FS_MAP =3D 6, VHOST_USER_SLAVE_FS_UNMAP =3D 7, + VHOST_USER_SLAVE_FS_IO =3D 8, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612899123; cv=none; d=zohomail.com; s=zohoarc; b=ZSYmg+CTTb+uji3+ItGiRuEubMKqx9aEWQrqrDoyXln/25kFNOBWeNc7RXeJcWpNmbsg+jigVkhwKQTzRe5DYrFcUWOie9Z9jQGPSWVWZH1F1Ra2DjRl0NOs99bULCtVSLZ1myoUsPhMJXJ4s6/lRLdzJkVKvVDHdprTNLFCrDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612899123; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3vnDcYNtXdA75tzYyQ3WuP21iiFzA1/9eBscdagyK00=; b=Kt+xR1sxtdmDuHZBJRi4LMHQyOYYLx6OYHd07yfyaNy70goht6Yss6ME7wbH6bdo2pa2xHBr+cBX2GApComotPyuvyKadjeGIXPMhEeSfvMvOoveQdARCAVCzT6f8J54QJ1WgArzroLnwVdj2OD6YeEz3cmu1PbyUDavEtrXjP8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612899123417529.7002515772086; Tue, 9 Feb 2021 11:32:03 -0800 (PST) Received: from localhost ([::1]:48512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Yjy-0004RP-6H for importer@patchew.org; Tue, 09 Feb 2021 14:32:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLB-00048z-Mj for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKl-0002PE-Hk for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:25 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-A70neh55O4SJG1MkPBTRHg-1; Tue, 09 Feb 2021 14:05:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA1CE803F48 for ; Tue, 9 Feb 2021 19:05:55 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E345B60C04; Tue, 9 Feb 2021 19:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3vnDcYNtXdA75tzYyQ3WuP21iiFzA1/9eBscdagyK00=; b=ehLZC1E/hn2664STiikj05PaKwi3LPAMM1kAn5ByT83HUKYrUjDdZ2tUW70MSsW1kw+iO3 v2StVTSpEQ49VYAW9IzanbjnTnMlInFmcLfFAisQvIWCTJ9ZWv6aJcFerVu+nR0WFSLiou 9q0F7eXid+MEcQI1udvVvv7zjjgUQBE= X-MC-Unique: A70neh55O4SJG1MkPBTRHg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 17/24] DAX/unmap virtiofsd: Add wrappers for VHOST_USER_SLAVE_FS_IO Date: Tue, 9 Feb 2021 19:02:17 +0000 Message-Id: <20210209190224.62827-18-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add a wrapper to send VHOST_USER_SLAVE_FS_IO commands and a further wrapper for sending a fuse_buf write using the FS_IO slave command. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_lowlevel.h | 25 ++++++++++++++++++++++ tools/virtiofsd/fuse_virtio.c | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index 53439f5432..af928b262f 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -2012,4 +2012,29 @@ int64_t fuse_virtio_map(fuse_req_t req, VhostUserFSS= laveMsg *msg, int fd); */ int64_t fuse_virtio_unmap(struct fuse_session *se, VhostUserFSSlaveMsg *ms= g); =20 +/** + * For use with virtio-fs; request IO directly to memory + * + * @param se The current session + * @param msg A set of IO requests + * @param fd The fd to map + * @return Length on success, negative errno on error + */ +int64_t fuse_virtio_io(struct fuse_session *se, VhostUserFSSlaveMsg *msg, + int fd); + +/** + * For use with virtio-fs; wrapper for fuse_virtio_io for writes + * from memory to an fd + * @param req The request that triggered this action + * @param dst The destination (file) memory buffer + * @param dst_off Byte offset in the file + * @param src The source (memory) buffer + * @param src_off The GPA + * @param len Length in bytes + */ +ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst, + size_t dst_off, const struct fuse_buf *src, + size_t src_off, size_t len); + #endif /* FUSE_LOWLEVEL_H_ */ diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index f217a093c8..8feb3c0261 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -1062,3 +1062,41 @@ int64_t fuse_virtio_unmap(struct fuse_session *se, V= hostUserFSSlaveMsg *msg) return vu_fs_cache_request(&se->virtio_dev->dev, VHOST_USER_SLAVE_FS_U= NMAP, -1, msg); } + +int64_t fuse_virtio_io(struct fuse_session *se, VhostUserFSSlaveMsg *msg, + int fd) +{ + if (!se->virtio_dev) { + return -ENODEV; + } + return vu_fs_cache_request(&se->virtio_dev->dev, VHOST_USER_SLAVE_FS_I= O, + fd, msg); +} + +/* + * Write to a file (dst) from an area of guest GPA (src) that probably + * isn't visible to the daemon. + */ +ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst, + size_t dst_off, const struct fuse_buf *src, + size_t src_off, size_t len) +{ + VhostUserFSSlaveMsg msg =3D { 0 }; + + if (dst->flags & FUSE_BUF_FD_SEEK) { + msg.fd_offset[0] =3D dst->pos + dst_off; + } else { + off_t cur =3D lseek(dst->fd, 0, SEEK_CUR); + if (cur =3D=3D (off_t)-1) { + return -errno; + } + msg.fd_offset[0] =3D cur; + } + msg.c_offset[0] =3D (uintptr_t)src->mem + src_off; + msg.len[0] =3D len; + msg.flags[0] =3D VHOST_USER_FS_FLAG_MAP_W; + + int64_t result =3D fuse_virtio_io(req->se, &msg, dst->fd); + fuse_log(FUSE_LOG_DEBUG, "%s: result=3D%ld\n", __func__, result); + return result; +} --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612899126; cv=none; d=zohomail.com; s=zohoarc; b=KFlPPjrC+bdyfURXGMdzQUjUzb7YMDI+eLlbg3DQ6jZIQ1YjX0eqphmLjxa7fUKTPMWG97q4Z/K/m1cvhynAC9EbaA6C3NJuPxjUw4dCEctMgo4xcSzbav14rGQb1jP3BeXmWQy694pFTHQqlARjA6MDXHsV4CbzPII34msOGgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612899126; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=faTCVSeQLqChQ09ek9mWExtkX355uDV6HPGJ7MDvDg8=; b=nQOYNuMsll8yhBL/qWMv4nobforV1lNVrajpKvVXL9s/NyO+1OXZtT2LJRFtbLLwfRkaaHxbHKphFQVoNfWeAOrrBzsPKhquI0lnEBh/gMpDxtVYGQ6rnFOU34VLOyDz/2SUkySuvWdcPSG1JWG6L/MJlP1gr5N6kJHUFnhKQVg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612899125758446.9960047984781; Tue, 9 Feb 2021 11:32:05 -0800 (PST) Received: from localhost ([::1]:48736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Yk0-0004Xe-Gb for importer@patchew.org; Tue, 09 Feb 2021 14:32:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLB-00047o-5d for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKu-0002PQ-1p for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:23 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-TqHOhcwoOACvU7jHeP9GOw-1; Tue, 09 Feb 2021 14:06:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D4A3F192AB7D for ; Tue, 9 Feb 2021 19:06:00 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A80C60C04; Tue, 9 Feb 2021 19:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=faTCVSeQLqChQ09ek9mWExtkX355uDV6HPGJ7MDvDg8=; b=bpyofkvJrVXTAWqLkQMbsBJ8SYJrEiuXAuG3kKWP4XcHo9+iM5JsPrc15NTFaYMd13sIsK DwCgVtShYz7MF77IFi3io5ZARJHV7ozFWjyFn6b0UnP8I17m3Bch/nfmIBC3IYnaaL7pFZ /qjnUSs8V27hzYT982CL1c1I++BqrH4= X-MC-Unique: TqHOhcwoOACvU7jHeP9GOw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 18/24] DAX/unmap virtiofsd: Parse unmappable elements Date: Tue, 9 Feb 2021 19:02:18 +0000 Message-Id: <20210209190224.62827-19-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" For some read/writes the virtio queue elements are unmappable by the daemon; these are cases where the data is to be read/written from non-RAM. In viritofs's case this is typically a direct read/write into an mmap'd DAX file also on virtiofs (possibly on another instance). When we receive a virtio queue element, check that we have enough mappable data to handle the headers. Make a note of the number of unmappable 'in' entries (ie. for read data back to the VMM), and flag the fuse_bufvec for 'out' entries with a new flag FUSE_BUF_PHYS_ADDR. Signed-off-by: Dr. David Alan Gilbert with fix by: Signed-off-by: Liu Bo --- tools/virtiofsd/buffer.c | 4 +- tools/virtiofsd/fuse_common.h | 7 ++ tools/virtiofsd/fuse_virtio.c | 191 ++++++++++++++++++++++++---------- 3 files changed, 145 insertions(+), 57 deletions(-) diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c index 874f01c488..1a050aa441 100644 --- a/tools/virtiofsd/buffer.c +++ b/tools/virtiofsd/buffer.c @@ -77,6 +77,7 @@ static ssize_t fuse_buf_write(const struct fuse_buf *dst,= size_t dst_off, ssize_t res =3D 0; size_t copied =3D 0; =20 + assert(!(src->flags & FUSE_BUF_PHYS_ADDR)); while (len) { if (dst->flags & FUSE_BUF_FD_SEEK) { res =3D pwrite(dst->fd, (char *)src->mem + src_off, len, @@ -272,7 +273,8 @@ ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct = fuse_bufvec *srcv) * process */ for (i =3D 0; i < srcv->count; i++) { - if (srcv->buf[i].flags & FUSE_BUF_IS_FD) { + if ((srcv->buf[i].flags & FUSE_BUF_PHYS_ADDR) || + (srcv->buf[i].flags & FUSE_BUF_IS_FD)) { break; } } diff --git a/tools/virtiofsd/fuse_common.h b/tools/virtiofsd/fuse_common.h index a090040bb2..ed9280de91 100644 --- a/tools/virtiofsd/fuse_common.h +++ b/tools/virtiofsd/fuse_common.h @@ -611,6 +611,13 @@ enum fuse_buf_flags { * detected. */ FUSE_BUF_FD_RETRY =3D (1 << 3), + + /** + * The addresses in the iovec represent guest physical addresses + * that can't be mapped by the daemon process. + * IO must be bounced back to the VMM to do it. + */ + FUSE_BUF_PHYS_ADDR =3D (1 << 4), }; =20 /** diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 8feb3c0261..8fa438525f 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -49,6 +49,10 @@ typedef struct { VuVirtqElement elem; struct fuse_chan ch; =20 + /* Number of unmappable iovecs */ + unsigned bad_in_num; + unsigned bad_out_num; + /* Used to complete requests that involve no reply */ bool reply_sent; } FVRequest; @@ -291,8 +295,10 @@ int virtio_send_data_iov(struct fuse_session *se, stru= ct fuse_chan *ch, =20 /* The 'in' part of the elem is to qemu */ unsigned int in_num =3D elem->in_num; + unsigned int bad_in_num =3D req->bad_in_num; struct iovec *in_sg =3D elem->in_sg; size_t in_len =3D iov_size(in_sg, in_num); + size_t in_len_writeable =3D iov_size(in_sg, in_num - bad_in_num); fuse_log(FUSE_LOG_DEBUG, "%s: elem %d: with %d in desc of length %zd\n= ", __func__, elem->index, in_num, in_len); =20 @@ -300,7 +306,7 @@ int virtio_send_data_iov(struct fuse_session *se, struc= t fuse_chan *ch, * The elem should have room for a 'fuse_out_header' (out from fuse) * plus the data based on the len in the header. */ - if (in_len < sizeof(struct fuse_out_header)) { + if (in_len_writeable < sizeof(struct fuse_out_header)) { fuse_log(FUSE_LOG_ERR, "%s: elem %d too short for out_header\n", __func__, elem->index); ret =3D E2BIG; @@ -327,7 +333,7 @@ int virtio_send_data_iov(struct fuse_session *se, struc= t fuse_chan *ch, memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num); /* These get updated as we skip */ struct iovec *in_sg_ptr =3D in_sg_cpy; - int in_sg_cpy_count =3D in_num; + int in_sg_cpy_count =3D in_num - bad_in_num; =20 /* skip over parts of in_sg that contained the header iov */ size_t skip_size =3D iov_len; @@ -460,17 +466,21 @@ static void fv_queue_worker(gpointer data, gpointer u= ser_data) =20 /* The 'out' part of the elem is from qemu */ unsigned int out_num =3D elem->out_num; + unsigned int out_num_readable =3D out_num - req->bad_out_num; struct iovec *out_sg =3D elem->out_sg; size_t out_len =3D iov_size(out_sg, out_num); + size_t out_len_readable =3D iov_size(out_sg, out_num_readable); fuse_log(FUSE_LOG_DEBUG, - "%s: elem %d: with %d out desc of length %zd\n", - __func__, elem->index, out_num, out_len); + "%s: elem %d: with %d out desc of length %zd" + " bad_in_num=3D%u bad_out_num=3D%u\n", + __func__, elem->index, out_num, out_len, req->bad_in_num, + req->bad_out_num); =20 /* * The elem should contain a 'fuse_in_header' (in to fuse) * plus the data based on the len in the header. */ - if (out_len < sizeof(struct fuse_in_header)) { + if (out_len_readable < sizeof(struct fuse_in_header)) { fuse_log(FUSE_LOG_ERR, "%s: elem %d too short for in_header\n", __func__, elem->index); assert(0); /* TODO */ @@ -484,63 +494,129 @@ static void fv_queue_worker(gpointer data, gpointer = user_data) copy_from_iov(&fbuf, 1, out_sg); =20 pbufv =3D NULL; /* Compiler thinks an unitialised path */ - if (out_num > 2 && - out_sg[0].iov_len =3D=3D sizeof(struct fuse_in_header) && - ((struct fuse_in_header *)fbuf.mem)->opcode =3D=3D FUSE_WRITE && - out_sg[1].iov_len =3D=3D sizeof(struct fuse_write_in)) { - /* - * For a write we don't actually need to copy the - * data, we can just do it straight out of guest memory - * but we must still copy the headers in case the guest - * was nasty and changed them while we were using them. - */ - fuse_log(FUSE_LOG_DEBUG, "%s: Write special case\n", __func__); - - /* copy the fuse_write_in header afte rthe fuse_in_header */ - fbuf.mem +=3D out_sg->iov_len; - copy_from_iov(&fbuf, 1, out_sg + 1); - fbuf.mem -=3D out_sg->iov_len; - fbuf.size =3D out_sg[0].iov_len + out_sg[1].iov_len; - - /* Allocate the bufv, with space for the rest of the iov */ - pbufv =3D malloc(sizeof(struct fuse_bufvec) + - sizeof(struct fuse_buf) * (out_num - 2)); - if (!pbufv) { - fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n", - __func__); - goto out; - } + if (req->bad_in_num || req->bad_out_num) { + bool handled_unmappable =3D false; + + if (out_num > 2 && out_num_readable >=3D 2 && !req->bad_in_num && + out_sg[0].iov_len =3D=3D sizeof(struct fuse_in_header) && + ((struct fuse_in_header *)fbuf.mem)->opcode =3D=3D FUSE_WRITE = && + out_sg[1].iov_len =3D=3D sizeof(struct fuse_write_in)) { + handled_unmappable =3D true; + + /* copy the fuse_write_in header after fuse_in_header */ + fbuf.mem +=3D out_sg->iov_len; + copy_from_iov(&fbuf, 1, out_sg + 1); + fbuf.mem -=3D out_sg->iov_len; + fbuf.size =3D out_sg[0].iov_len + out_sg[1].iov_len; + + /* Allocate the bufv, with space for the rest of the iov */ + pbufv =3D malloc(sizeof(struct fuse_bufvec) + + sizeof(struct fuse_buf) * (out_num - 2)); + if (!pbufv) { + fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n", + __func__); + goto out; + } =20 - allocated_bufv =3D true; - pbufv->count =3D 1; - pbufv->buf[0] =3D fbuf; + allocated_bufv =3D true; + pbufv->count =3D 1; + pbufv->buf[0] =3D fbuf; + + size_t iovindex, pbufvindex; + iovindex =3D 2; /* 2 headers, separate iovs */ + pbufvindex =3D 1; /* 2 headers, 1 fusebuf */ + + for (; iovindex < out_num; iovindex++, pbufvindex++) { + pbufv->count++; + pbufv->buf[pbufvindex].pos =3D ~0; /* Dummy */ + pbufv->buf[pbufvindex].flags =3D + (iovindex < out_num_readable) ? 0 : + FUSE_BUF_PHYS_ADDR; + pbufv->buf[pbufvindex].mem =3D out_sg[iovindex].iov_base; + pbufv->buf[pbufvindex].size =3D out_sg[iovindex].iov_len; + } + } =20 - size_t iovindex, pbufvindex; - iovindex =3D 2; /* 2 headers, separate iovs */ - pbufvindex =3D 1; /* 2 headers, 1 fusebuf */ + if (out_num =3D=3D 2 && out_num_readable =3D=3D 2 && req->bad_in_n= um && + out_sg[0].iov_len =3D=3D sizeof(struct fuse_in_header) && + ((struct fuse_in_header *)fbuf.mem)->opcode =3D=3D FUSE_READ && + out_sg[1].iov_len =3D=3D sizeof(struct fuse_read_in)) { + fuse_log(FUSE_LOG_DEBUG, + "Unmappable read case " + "in_num=3D%d bad_in_num=3D%d\n", + elem->in_num, req->bad_in_num); + handled_unmappable =3D true; + } =20 - for (; iovindex < out_num; iovindex++, pbufvindex++) { - pbufv->count++; - pbufv->buf[pbufvindex].pos =3D ~0; /* Dummy */ - pbufv->buf[pbufvindex].flags =3D 0; - pbufv->buf[pbufvindex].mem =3D out_sg[iovindex].iov_base; - pbufv->buf[pbufvindex].size =3D out_sg[iovindex].iov_len; + if (!handled_unmappable) { + fuse_log(FUSE_LOG_ERR, + "Unhandled unmappable element: out: %d(b:%d) in: " + "%d(b:%d)", + out_num, req->bad_out_num, elem->in_num, req->bad_in_= num); + fv_panic(dev, "Unhandled unmappable element"); } - } else { - /* Normal (non fast write) path */ + } + + if (!req->bad_out_num) { + if (out_num > 2 && + out_sg[0].iov_len =3D=3D sizeof(struct fuse_in_header) && + ((struct fuse_in_header *)fbuf.mem)->opcode =3D=3D FUSE_WRITE = && + out_sg[1].iov_len =3D=3D sizeof(struct fuse_write_in)) { + /* + * For a write we don't actually need to copy the + * data, we can just do it straight out of guest memory + * but we must still copy the headers in case the guest + * was nasty and changed them while we were using them. + */ + fuse_log(FUSE_LOG_DEBUG, "%s: Write special case\n", + __func__); + + /* copy the fuse_write_in header after fuse_in_header */ + fbuf.mem +=3D out_sg->iov_len; + copy_from_iov(&fbuf, 1, out_sg + 1); + fbuf.mem -=3D out_sg->iov_len; + fbuf.size =3D out_sg[0].iov_len + out_sg[1].iov_len; + + /* Allocate the bufv, with space for the rest of the iov */ + pbufv =3D malloc(sizeof(struct fuse_bufvec) + + sizeof(struct fuse_buf) * (out_num - 2)); + if (!pbufv) { + fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n", + __func__); + goto out; + } =20 - /* Copy the rest of the buffer */ - fbuf.mem +=3D out_sg->iov_len; - copy_from_iov(&fbuf, out_num - 1, out_sg + 1); - fbuf.mem -=3D out_sg->iov_len; - fbuf.size =3D out_len; + allocated_bufv =3D true; + pbufv->count =3D 1; + pbufv->buf[0] =3D fbuf; =20 - /* TODO! Endianness of header */ + size_t iovindex, pbufvindex; + iovindex =3D 2; /* 2 headers, separate iovs */ + pbufvindex =3D 1; /* 2 headers, 1 fusebuf */ =20 - /* TODO: Add checks for fuse_session_exited */ - bufv.buf[0] =3D fbuf; - bufv.count =3D 1; - pbufv =3D &bufv; + for (; iovindex < out_num; iovindex++, pbufvindex++) { + pbufv->count++; + pbufv->buf[pbufvindex].pos =3D ~0; /* Dummy */ + pbufv->buf[pbufvindex].flags =3D 0; + pbufv->buf[pbufvindex].mem =3D out_sg[iovindex].iov_base; + pbufv->buf[pbufvindex].size =3D out_sg[iovindex].iov_len; + } + } else { + /* Normal (non fast write) path */ + + /* Copy the rest of the buffer */ + fbuf.mem +=3D out_sg->iov_len; + copy_from_iov(&fbuf, out_num - 1, out_sg + 1); + fbuf.mem -=3D out_sg->iov_len; + fbuf.size =3D out_len; + + /* TODO! Endianness of header */ + + /* TODO: Add checks for fuse_session_exited */ + bufv.buf[0] =3D fbuf; + bufv.count =3D 1; + pbufv =3D &bufv; + } } pbufv->idx =3D 0; pbufv->off =3D 0; @@ -657,13 +733,16 @@ static void *fv_queue_thread(void *opaque) __func__, qi->qidx, (size_t)evalue, in_bytes, out_bytes); =20 while (1) { + unsigned int bad_in_num =3D 0, bad_out_num =3D 0; FVRequest *req =3D vu_queue_pop(dev, q, sizeof(FVRequest), - NULL, NULL); + &bad_in_num, &bad_out_num); if (!req) { break; } =20 req->reply_sent =3D false; + req->bad_in_num =3D bad_in_num; + req->bad_out_num =3D bad_out_num; =20 if (!se->thread_pool_size) { req_list =3D g_list_prepend(req_list, req); --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897874; cv=none; d=zohomail.com; s=zohoarc; b=glJvJ3gTcLm+BdQ5pFT5BkIZqPaMTPhX492HKuBH81WL47ctsCeaUkxbqefQ//d/BIBZdycpi2b7K2seJA27VsVT8xC6Ix7AmuXtEdrIHxikGH9p1z6LyqcqYI7fCcwlqh3nShXVO78VDf2lZZyzlLl9ukbqj9hY0eiFT7DfPlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897874; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q/ejKjFIclrNcqqmohGqfzQuQM1Jg6BBc10aarO0k+4=; b=F96nRd4w+99rWg9nnJmPNn4qBy/Ran0SsN5708oljn7e5D3FW/rBSUWhF0vDuZqVus31u8WquOiwTkAR42JdGuO4mReQjt3Job+uyLpJPCIZBGJKV6wi2JsJUZsrB7qjiOGtRjxvI9Bm0MJVOyEeIdrbGWynA2Cr6hSeYjb34Y0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612897873820480.92280151166847; Tue, 9 Feb 2021 11:11:13 -0800 (PST) Received: from localhost ([::1]:58230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YPo-00088T-Qy for importer@patchew.org; Tue, 09 Feb 2021 14:11:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YL6-00045c-75 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YKx-0002Qz-2w for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-G70tmIK-OH6TEpCNuI95Ng-1; Tue, 09 Feb 2021 14:06:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3087803F47 for ; Tue, 9 Feb 2021 19:06:05 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BEF960C04; Tue, 9 Feb 2021 19:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q/ejKjFIclrNcqqmohGqfzQuQM1Jg6BBc10aarO0k+4=; b=NyVDfytS3WigB8uAJOTHiBupG3QEO4Eb0US2UTyKKLAhK998e+bsTcGwiOKTPFw1aVzX8u 5qLeY5uuzolb1gVGjcmW+hyrfqYanodiDzQvYVLakgU5sCRJyqRTe1i/tNIjTMq5y/JhFT 8l9pdURDxxd8pIdw8U+ozaRwHpvHRn4= X-MC-Unique: G70tmIK-OH6TEpCNuI95Ng-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 19/24] DAX/unmap virtiofsd: Route unmappable reads Date: Tue, 9 Feb 2021 19:02:19 +0000 Message-Id: <20210209190224.62827-20-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" When a read with unmappable buffers is found, map it to a slave read command. Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/fuse_virtio.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 8fa438525f..316d1f2463 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -397,6 +397,37 @@ int virtio_send_data_iov(struct fuse_session *se, stru= ct fuse_chan *ch, in_sg_left -=3D ret; len -=3D ret; } while (in_sg_left); + + if (bad_in_num) { + while (len && bad_in_num) { + VhostUserFSSlaveMsg msg =3D { 0 }; + msg.flags[0] =3D VHOST_USER_FS_FLAG_MAP_R; + msg.fd_offset[0] =3D buf->buf[0].pos; + msg.c_offset[0] =3D (uint64_t)(uintptr_t)in_sg_ptr[0].iov_base; + msg.len[0] =3D in_sg_ptr[0].iov_len; + if (len < msg.len[0]) { + msg.len[0] =3D len; + } + int64_t req_res =3D fuse_virtio_io(se, &msg, buf->buf[0].fd); + fuse_log(FUSE_LOG_DEBUG, + "%s: bad loop; len=3D%zd bad_in_num=3D%d fd_offset=3D= %zd " + "c_offset=3D%p req_res=3D%ld\n", + __func__, len, bad_in_num, buf->buf[0].pos, + in_sg_ptr[0].iov_base, req_res); + if (req_res > 0) { + len -=3D msg.len[0]; + buf->buf[0].pos +=3D msg.len[0]; + in_sg_ptr++; + bad_in_num--; + } else if (req_res =3D=3D 0) { + break; + } else { + ret =3D req_res; + free(in_sg_cpy); + goto err; + } + } + } free(in_sg_cpy); =20 /* Need to fix out->len on EOF */ --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612897854; cv=none; d=zohomail.com; s=zohoarc; b=V/BRyW8sN0rl2GGn3BqoaktFd/tUeMtYENz1GdiPzhU3318TV6IW84LqYM8vDIuhT1n7NahizmwZHpNbPPiS+8vy36CMOV/LE7nRFleK5IQgheSM9+4vLcaLLoEQZFnO5hAh+f8I1qQiuiSKyLBfY7tPV79iX4n9I72KtqN7yYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612897854; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QncF93T67Su1/OODXxjr7IkgXv6iMGq4WvY5yBFhbHw=; b=fFKbuU81216pa+bnsA3QVbWeLiJdslN/iJdFmFU0I76a51lFmXl7qbNyTt1TxsuAVEx740gu8i3V2oXns15d5XyaQ0vCaQ0X6ylPQu2u0r1NYJh6ht0kRWkRpFNpPdMzDPK5LyIuZIqDbg8/D/VIHRsnVQ7Xpmq2nVvq3Gqqtmg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161289785383883.52527989678117; Tue, 9 Feb 2021 11:10:53 -0800 (PST) Received: from localhost ([::1]:57058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YPU-0007cE-Io for importer@patchew.org; Tue, 09 Feb 2021 14:10:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLE-0004Cj-BU for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60350) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YL4-0002TD-I0 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:27 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-oWJPJWn_OKqwcpqIwNml-Q-1; Tue, 09 Feb 2021 14:06:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BEB9107ACE3 for ; Tue, 9 Feb 2021 19:06:13 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4323A60C4D; Tue, 9 Feb 2021 19:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QncF93T67Su1/OODXxjr7IkgXv6iMGq4WvY5yBFhbHw=; b=YMfO6W2srd1bHtFBecb4I1N6jAhOs6O0AUuLVhpgz93gdPoKf0cmrTCiIIgCdarfmma599 K3RNH+rCic//jZtD50mQEuoizROieCiO0jdcAa9dJXoqGwrjejTaMdvH92+dE4vYbb1HxV f8chXHOrPVrzi+EmQY4TvxbprdmSD1A= X-MC-Unique: oWJPJWn_OKqwcpqIwNml-Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 20/24] DAX/unmap virtiofsd: route unmappable write to slave command Date: Tue, 9 Feb 2021 19:02:20 +0000 Message-Id: <20210209190224.62827-21-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" When a fuse_buf_copy is performed on an element with FUSE_BUF_PHYS_ADDR route it to a fuse_virtio_write request that does a slave command to perform the write. Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/buffer.c | 14 +++++++++++--- tools/virtiofsd/fuse_common.h | 6 +++++- tools/virtiofsd/fuse_lowlevel.h | 3 --- tools/virtiofsd/passthrough_ll.c | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c index 1a050aa441..8135d52d2a 100644 --- a/tools/virtiofsd/buffer.c +++ b/tools/virtiofsd/buffer.c @@ -200,13 +200,20 @@ static ssize_t fuse_buf_fd_to_fd(const struct fuse_bu= f *dst, size_t dst_off, return copied; } =20 -static ssize_t fuse_buf_copy_one(const struct fuse_buf *dst, size_t dst_of= f, +static ssize_t fuse_buf_copy_one(fuse_req_t req, + const struct fuse_buf *dst, size_t dst_of= f, const struct fuse_buf *src, size_t src_of= f, size_t len) { int src_is_fd =3D src->flags & FUSE_BUF_IS_FD; int dst_is_fd =3D dst->flags & FUSE_BUF_IS_FD; + int src_is_phys =3D src->flags & FUSE_BUF_PHYS_ADDR; + int dst_is_phys =3D src->flags & FUSE_BUF_PHYS_ADDR; =20 + if (src_is_phys && !src_is_fd && dst_is_fd) { + return fuse_virtio_write(req, dst, dst_off, src, src_off, len); + } + assert(!src_is_phys && !dst_is_phys); if (!src_is_fd && !dst_is_fd) { char *dstmem =3D (char *)dst->mem + dst_off; char *srcmem =3D (char *)src->mem + src_off; @@ -259,7 +266,8 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv= , size_t len) return 1; } =20 -ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct fuse_bufvec *srcv) +ssize_t fuse_buf_copy(fuse_req_t req, struct fuse_bufvec *dstv, + struct fuse_bufvec *srcv) { size_t copied =3D 0, i; =20 @@ -301,7 +309,7 @@ ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct = fuse_bufvec *srcv) dst_len =3D dst->size - dstv->off; len =3D min_size(src_len, dst_len); =20 - res =3D fuse_buf_copy_one(dst, dstv->off, src, srcv->off, len); + res =3D fuse_buf_copy_one(req, dst, dstv->off, src, srcv->off, len= ); if (res < 0) { if (!copied) { return res; diff --git a/tools/virtiofsd/fuse_common.h b/tools/virtiofsd/fuse_common.h index ed9280de91..05d56883dd 100644 --- a/tools/virtiofsd/fuse_common.h +++ b/tools/virtiofsd/fuse_common.h @@ -495,6 +495,8 @@ struct fuse_conn_info { struct fuse_session; struct fuse_pollhandle; struct fuse_conn_info_opts; +struct fuse_req; +typedef struct fuse_req *fuse_req_t; =20 /** * This function parses several command-line options that can be used @@ -713,11 +715,13 @@ size_t fuse_buf_size(const struct fuse_bufvec *bufv); /** * Copy data from one buffer vector to another * + * @param req The request this copy is part of * @param dst destination buffer vector * @param src source buffer vector * @return actual number of bytes copied or -errno on error */ -ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src); +ssize_t fuse_buf_copy(fuse_req_t req, + struct fuse_bufvec *dst, struct fuse_bufvec *src); =20 /** * Memory buffer iterator diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index af928b262f..b36140c565 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -42,9 +42,6 @@ /** Inode number type */ typedef uint64_t fuse_ino_t; =20 -/** Request pointer type */ -typedef struct fuse_req *fuse_req_t; - /** * Session * diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 21ddb434ae..5baf4f1d50 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2135,7 +2135,7 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t i= no, } } =20 - res =3D fuse_buf_copy(&out_buf, in_buf); + res =3D fuse_buf_copy(req, &out_buf, in_buf); if (res < 0) { fuse_reply_err(req, -res); } else { --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612899422; cv=none; d=zohomail.com; s=zohoarc; b=YJtipqp6plvMzf7vPcj2usNCn+EhW66rRBXFHrRVc/dQ77ishlN0ddgiuJYbfNU4LYBk+VFLdq3ovkA2qb/g1xFnsx6r27tetX8c7UWqBjtN20Ew9wjmK3F3ljyUo5nus80UB7Lo0GsPdD+9OhXRkDgxWiJJveNt/m2UU2MrWYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612899422; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P3rZMY58INtk87tu2FtQul6FS7jcBWV6BgotKQumVfg=; b=fb59A4xOfqdn64bT2oS8Nxxn5VtlrO3rb6q00xXt/JF6xFlbTv+ptNQcUnfeA+2rKtL7jSlkAUZ5GQh1NC1hD+DoYCf2W3vr8F0cnCV4yPWO0HP2WEWvkL/7JLb1cQs58SxLu+O/S0oywiO9ZtFzLT6BTnqBkySLh0bgK9TL9co= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161289942162131.68156523589971; Tue, 9 Feb 2021 11:37:01 -0800 (PST) Received: from localhost ([::1]:59658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Yol-00012U-Sk for importer@patchew.org; Tue, 09 Feb 2021 14:37:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLH-0004Hq-Sk for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YL5-0002UN-Un for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:31 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-qYYv2uncNOe58Z5QXEQsDw-1; Tue, 09 Feb 2021 14:06:16 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B69F1005501 for ; Tue, 9 Feb 2021 19:06:15 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03EF460C04; Tue, 9 Feb 2021 19:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P3rZMY58INtk87tu2FtQul6FS7jcBWV6BgotKQumVfg=; b=CzTvBe23lVUZu1Eivmw36xSOUKC33R/jp133OL6jLv6NZQNdzkPp6zORIcvvFSM5+ipRqk jKB+Cg1OiI+f5dzcfzoLyUHEVYEaB4E75TXLtY5q9x7lIpAbHEFrcsvfx8pa3Bi0/wHFhK hjRlez2tQueQny5nDc+L8XH9IgWxp3Y= X-MC-Unique: qYYv2uncNOe58Z5QXEQsDw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 21/24] DAX:virtiofsd: implement FUSE_INIT map_alignment field Date: Tue, 9 Feb 2021 19:02:21 +0000 Message-Id: <20210209190224.62827-22-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Communicate the host page size to the FUSE client so that FUSE_SETUPMAPPING/FUSE_REMOVEMAPPING requests are aware of our alignment constraints. Signed-off-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_lowlevel.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 99ba000c2e..df4527acc9 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -10,6 +10,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/host-utils.h" #include "fuse_i.h" #include "standard-headers/linux/fuse.h" #include "fuse_misc.h" @@ -2188,6 +2189,12 @@ static void do_init(fuse_req_t req, fuse_ino_t nodei= d, outarg.max_background =3D se->conn.max_background; outarg.congestion_threshold =3D se->conn.congestion_threshold; outarg.time_gran =3D se->conn.time_gran; + if (arg->flags & FUSE_MAP_ALIGNMENT) { + outarg.flags |=3D FUSE_MAP_ALIGNMENT; + + /* This constraint comes from mmap(2) and munmap(2) */ + outarg.map_alignment =3D ctz64(sysconf(_SC_PAGE_SIZE)); + } =20 fuse_log(FUSE_LOG_DEBUG, " INIT: %u.%u\n", outarg.major, outarg.mino= r); fuse_log(FUSE_LOG_DEBUG, " flags=3D0x%08x\n", outarg.flags); @@ -2197,6 +2204,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, fuse_log(FUSE_LOG_DEBUG, " congestion_threshold=3D%i\n", outarg.congestion_threshold); fuse_log(FUSE_LOG_DEBUG, " time_gran=3D%u\n", outarg.time_gran); + fuse_log(FUSE_LOG_DEBUG, " map_alignment=3D%u\n", outarg.map_alignme= nt); =20 send_reply_ok(req, &outarg, outargsize); } --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612899382; cv=none; d=zohomail.com; s=zohoarc; b=Zykd3A3VMAUYHEynLGwM2B+FVXhFUEHSam4ktax86F0yFAIOKFxFpE0LMJz6f3rSx7FA9tAeLj35E0BgAppb8hTWfCDfwXRfg6FimZrw1Ur3AYsjes97znQNB2LzJWT3aV5D5BhJajnP5Q2GNaupbAWQEKq1YdmdAEXUWiNGbaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612899382; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T/oYr2t8mDYWd6w6H+YWFCqSVP+EpinZjBiYU940ang=; b=FV36rfYlFI1Pt9fWeL37fYo/X0CjjiOkwrb+/iLd77+iXDltjx5/LsH3YMkz3W6TW59vKsRWswpk5yA3yFctx9lRe9VLdDal7ztpM7SnQcavye+HZi/SyLtm8rjBrSYkrrIXGNtEVzdyGGCzNiUSrOXNVG3nwYsnZVCfKZFQ208= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612899381944542.4228113600973; Tue, 9 Feb 2021 11:36:21 -0800 (PST) Received: from localhost ([::1]:57006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Yo8-0008Ge-RI for importer@patchew.org; Tue, 09 Feb 2021 14:36:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLO-0004KX-JB for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YLI-0002bB-CC for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-128--IputoMYOOS4spQfOpAx8w-1; Tue, 09 Feb 2021 14:06:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 751CF107ACE3 for ; Tue, 9 Feb 2021 19:06:20 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0201560C04; Tue, 9 Feb 2021 19:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/oYr2t8mDYWd6w6H+YWFCqSVP+EpinZjBiYU940ang=; b=DFF99qXbhF8rbE9GdIOU574lQz+bHEvdgsyA4MhjsulvqE4RvX4NxybMJF+/8+fnTJmlpo geixgjI/h6CMRuqLIjp5upYIt2dXl1ZpVuMuYymmaEf16j51KI//DkZATqMaOndP6NSTv+ YF8U8Te2JgkpWiDq/mH9keWQrCRhkJY= X-MC-Unique: -IputoMYOOS4spQfOpAx8w-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 22/24] vhost-user-fs: Extend VhostUserFSSlaveMsg to pass additional info Date: Tue, 9 Feb 2021 19:02:22 +0000 Message-Id: <20210209190224.62827-23-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vivek Goyal Extend VhostUserFSSlaveMsg so that slave can ask it to drop CAP_FSETID before doing I/O on fd. In some cases, virtiofsd takes the onus of clearing setuid bit on a file when WRITE happens. Generally virtiofsd does the WRITE to fd (from guest memory which is mapped in virtiofsd as well), but if this memory is unmappable in virtiofsd (like cache window), then virtiofsd asks qemu to do the I/O instead. To retain the capability to drop suid bit on write, qemu needs to drop the CAP_FSETID as well before write to fd. Extend VhostUserFSSlaveMsg so that virtiofsd can specify in message if CAP_FSETID needs to be dropped. Signed-off-by: Vivek Goyal --- hw/virtio/vhost-user-fs.c | 5 +++++ include/hw/virtio/vhost-user-fs.h | 6 ++++++ subprojects/libvhost-user/libvhost-user.h | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 357bc1d04e..61e891c82d 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -176,6 +176,11 @@ uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev,= VhostUserFSSlaveMsg *sm, return (uint64_t)-1; } =20 + if (sm->gen_flags & VHOST_USER_FS_GENFLAG_DROP_FSETID) { + error_report("Dropping CAP_FSETID is not supported"); + return (uint64_t)-ENOTSUP; + } + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES && !res; i++) { if (sm->len[i] =3D=3D 0) { continue; diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index ffd3165c29..e646eb004a 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -30,7 +30,13 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserFS, VHOST_USER_FS) #define VHOST_USER_FS_FLAG_MAP_R (1ull << 0) #define VHOST_USER_FS_FLAG_MAP_W (1ull << 1) =20 +/* Generic flags for the overall message and not individual ranges */ +/* Drop capability CAP_FSETID during the operation */ +#define VHOST_USER_FS_GENFLAG_DROP_FSETID (1ull << 0) + typedef struct { + /* Generic flags for the overall message */ + uint64_t gen_flags; /* Offsets within the file being mapped */ uint64_t fd_offset[VHOST_USER_FS_SLAVE_ENTRIES]; /* Offsets within the cache */ diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index a398148ed9..f7de8f6387 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -132,7 +132,13 @@ typedef enum VhostUserSlaveRequest { #define VHOST_USER_FS_FLAG_MAP_R (1ull << 0) #define VHOST_USER_FS_FLAG_MAP_W (1ull << 1) =20 +/* Generic flags for the overall message and not individual ranges */ +/* Drop capability CAP_FSETID during the operation */ +#define VHOST_USER_FS_GENFLAG_DROP_FSETID (1ull << 0) + typedef struct { + /* Generic flags for the overall message */ + uint64_t gen_flags; /* Offsets within the file being mapped */ uint64_t fd_offset[VHOST_USER_FS_SLAVE_ENTRIES]; /* Offsets within the cache */ --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612898349; cv=none; d=zohomail.com; s=zohoarc; b=gZ+tjrWU5VgEdL+6lTZLGCTWA/NHBoSbU6aVFyGDSIsNykNkaAzEB0wpnqhWCC0Ye5jT8IFJeD13Rjm+IgFw2nTkWu6ONBxyO3SHZ2rYBKsGkWXiL1qSaKgm7mtSh70qkbrO3qcoQJPKxEp1hLJKfTSzhBjseHiSc34Jg8r9tOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612898349; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2+PKRjRL0uQkeqx2q2kSSEHpKI8DjUcO+q9RzQ70mTY=; b=hHtX8SkfclGnbcZgvNsjv+RM9Kj3j58XOAMfkEX83rKATm5Gx1gKWmBoJ2EJpq1+jiRQuezNLOIntRebUCFvCo+mYvB6HCzzFey6ZrDGD+6FR8QrGwYbYFg1jlValGM5mgR+bVfpgPLrTv0yQLx9AtLiKNGrGnCPqtuOptUxRpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612898349476858.0117578765161; Tue, 9 Feb 2021 11:19:09 -0800 (PST) Received: from localhost ([::1]:45664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9YXU-0006eW-FF for importer@patchew.org; Tue, 09 Feb 2021 14:19:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLX-0004M8-BV for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YLS-0002cp-MC for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:47 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-yKKwSIX9PVSL4YVCWRh5tQ-1; Tue, 09 Feb 2021 14:06:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9E45801988 for ; Tue, 9 Feb 2021 19:06:36 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id D08EF60C04; Tue, 9 Feb 2021 19:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2+PKRjRL0uQkeqx2q2kSSEHpKI8DjUcO+q9RzQ70mTY=; b=VI7+sZTey3Hpke4jtOpGr36vGbTg7q3kmBPQB9O5bEkTlWsp5Ek4yn18GOs/SmlK3mN68h yH1PEWEVElapgf14EUte7bOVke0IPGADEoCFZFlm4q3wtB1hc9kqbxOXx/B+Eadj/U24FF dhAtImsxrG31DeZIrKkvxwMor3kTCzo= X-MC-Unique: yKKwSIX9PVSL4YVCWRh5tQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 23/24] vhost-user-fs: Implement drop CAP_FSETID functionality Date: Tue, 9 Feb 2021 19:02:23 +0000 Message-Id: <20210209190224.62827-24-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vivek Goyal As part of slave_io message, slave can ask to do I/O on an fd. Additionally slave can ask for dropping CAP_FSETID (if master has it) before doing I/O. Implement functionality to drop CAP_FSETID and gain it back after the operation. This also creates a dependency on libcap-ng. Signed-off-by: Vivek Goyal --- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-fs.c | 92 ++++++++++++++++++++++++++++++++++++++- meson.build | 6 +++ 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index fbff9bc9d4..bdcdc82e13 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -18,6 +18,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: fil= es('virtio-balloon.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('virtio-crypto.= c')) virtio_ss.add(when: ['CONFIG_VIRTIO_CRYPTO', 'CONFIG_VIRTIO_PCI'], if_true= : files('virtio-crypto-pci.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs.= c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: libcap_ng) virtio_ss.add(when: ['CONFIG_VHOST_USER_FS', 'CONFIG_VIRTIO_PCI'], if_true= : files('vhost-user-fs-pci.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem.c')) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c', = 'vhost-vsock-common.c')) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 61e891c82d..0d6ec27edd 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -13,6 +13,8 @@ =20 #include "qemu/osdep.h" #include +#include +#include #include "standard-headers/linux/virtio_fs.h" #include "qapi/error.h" #include "hw/qdev-properties.h" @@ -36,6 +38,84 @@ #define DAX_WINDOW_PROT PROT_NONE #endif =20 +/* + * Helpers for dropping and regaining effective capabilities. Returns 0 + * on success, error otherwise + */ +static int drop_effective_cap(const char *cap_name, bool *cap_dropped) +{ + int cap, ret; + + cap =3D capng_name_to_capability(cap_name); + if (cap < 0) { + ret =3D -errno; + error_report("capng_name_to_capability(%s) failed:%s", cap_name, + strerror(errno)); + goto out; + } + + if (capng_get_caps_process()) { + ret =3D -errno; + error_report("capng_get_caps_process() failed:%s", strerror(errno)= ); + goto out; + } + + /* We dont have this capability in effective set already. */ + if (!capng_have_capability(CAPNG_EFFECTIVE, cap)) { + ret =3D 0; + goto out; + } + + if (capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, cap)) { + ret =3D -errno; + error_report("capng_update(DROP,) failed"); + goto out; + } + if (capng_apply(CAPNG_SELECT_CAPS)) { + ret =3D -errno; + error_report("drop:capng_apply() failed"); + goto out; + } + + ret =3D 0; + if (cap_dropped) { + *cap_dropped =3D true; + } + +out: + return ret; +} + +static int gain_effective_cap(const char *cap_name) +{ + int cap; + int ret =3D 0; + + cap =3D capng_name_to_capability(cap_name); + if (cap < 0) { + ret =3D -errno; + error_report("capng_name_to_capability(%s) failed:%s", cap_name, + strerror(errno)); + goto out; + } + + if (capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, cap)) { + ret =3D -errno; + error_report("capng_update(ADD,) failed"); + goto out; + } + + if (capng_apply(CAPNG_SELECT_CAPS)) { + ret =3D -errno; + error_report("gain:capng_apply() failed"); + goto out; + } + ret =3D 0; + +out: + return ret; +} + uint64_t vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMs= g *sm, int fd) { @@ -170,6 +250,7 @@ uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev, = VhostUserFSSlaveMsg *sm, unsigned int i; int res =3D 0; size_t done =3D 0; + bool cap_fsetid_dropped =3D false; =20 if (fd < 0) { error_report("Bad fd for map"); @@ -177,8 +258,10 @@ uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev,= VhostUserFSSlaveMsg *sm, } =20 if (sm->gen_flags & VHOST_USER_FS_GENFLAG_DROP_FSETID) { - error_report("Dropping CAP_FSETID is not supported"); - return (uint64_t)-ENOTSUP; + res =3D drop_effective_cap("FSETID", &cap_fsetid_dropped); + if (res !=3D 0) { + return (uint64_t)res; + } } =20 for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES && !res; i++) { @@ -237,6 +320,11 @@ uint64_t vhost_user_fs_slave_io(struct vhost_dev *dev,= VhostUserFSSlaveMsg *sm, } close(fd); =20 + if (cap_fsetid_dropped) { + if (gain_effective_cap("FSETID")) { + error_report("Failed to gain CAP_FSETID"); + } + } trace_vhost_user_fs_slave_io_exit(res, done); if (res < 0) { return (uint64_t)res; diff --git a/meson.build b/meson.build index 2d8b433ff0..99a7fbacc1 100644 --- a/meson.build +++ b/meson.build @@ -1060,6 +1060,12 @@ elif get_option('virtfs').disabled() have_virtfs =3D false endif =20 +if config_host.has_key('CONFIG_VHOST_USER_FS') + if not libcap_ng.found() + error('vhost-user-fs requires libcap-ng-devel') + endif +endif + config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / get_op= tion('bindir')) config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix')) config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / = qemu_confdir) --=20 2.29.2 From nobody Fri May 17 12:14:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612899609; cv=none; d=zohomail.com; s=zohoarc; b=e1R19KPv97A9Ucnf+c36u1CwzAQABtAPJoCVxW+ZqeA8/zGeqPO0i39O1vv7U7bQRrhYdoj0uOHzc3xfRxU/FZto6hRfqvmHRDEReaeu0AjiaTNZfgh2SnpJUWyuhRQ8w5II1/GJ3Yy+qQKQxn7loz9U40aijix4WPv7ISRAwOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612899609; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hnO1JFIT4ig1h7ZZw0NFiElN0hfpmt4U9rvIhq7owdQ=; b=auB1HxVWySnqlvlIcpoCwO5uceXeU/N7I8JbEWzrBNqUJDoJTncy4p7xrUt9RdPsVdDVD97UYgV0VtaP1xLqAHcR+qBwzyZXtMNErqRVqL5PbYYDjRnhR2HMtP6i8nKXDnJI77xzLhKFmICK/tKP+UGiWOrhDHFT3KcBs6DtGn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612899609135338.463701956064; Tue, 9 Feb 2021 11:40:09 -0800 (PST) Received: from localhost ([::1]:41102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Yrn-00055u-Re for importer@patchew.org; Tue, 09 Feb 2021 14:40:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9YLb-0004NP-S4 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9YLZ-0002df-M6 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 14:06:51 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-z25y2fuZPw2Pq2rvaAKt8A-1; Tue, 09 Feb 2021 14:06:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BAD321005501 for ; Tue, 9 Feb 2021 19:06:44 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4833B60C04; Tue, 9 Feb 2021 19:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612897607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hnO1JFIT4ig1h7ZZw0NFiElN0hfpmt4U9rvIhq7owdQ=; b=NNh88c+XjPhrxxcxsn59r1BctH911Lhcc9wXzrWERqeJ+5Eglgd5mqOrnweLlM2WYh6JSP XDRlIwiMfg5JZ0QhOHdxItfLd8zaZV5BXE/4L/Nvhnp/lsK9SwmWD9oN4fXHBRndo6TLww ow/ml0KfFlDweqvb/s0kaH9noQfJ2ZI= X-MC-Unique: z25y2fuZPw2Pq2rvaAKt8A-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, vgoyal@redhat.com, stefanha@redhat.com, virtio-fs@redhat.com, marcandre.lureau@redhat.com, mst@redhat.com Subject: [PATCH 24/24] virtiofsd: Ask qemu to drop CAP_FSETID if client asked for it Date: Tue, 9 Feb 2021 19:02:24 +0000 Message-Id: <20210209190224.62827-25-dgilbert@redhat.com> In-Reply-To: <20210209190224.62827-1-dgilbert@redhat.com> References: <20210209190224.62827-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vivek Goyal If qemu guest asked to drop CAP_FSETID upon write, send that info to qemu in SLAVE_FS_IO message so that qemu can drop capability before WRITE. This is to make sure that any setuid bit is killed on fd (if there is one set). Signed-off-by: Vivek Goyal --- tools/virtiofsd/buffer.c | 10 ++++++---- tools/virtiofsd/fuse_common.h | 6 +++++- tools/virtiofsd/fuse_lowlevel.h | 6 +++++- tools/virtiofsd/fuse_virtio.c | 5 ++++- tools/virtiofsd/passthrough_ll.c | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c index 8135d52d2a..b4cda7db9a 100644 --- a/tools/virtiofsd/buffer.c +++ b/tools/virtiofsd/buffer.c @@ -203,7 +203,7 @@ static ssize_t fuse_buf_fd_to_fd(const struct fuse_buf = *dst, size_t dst_off, static ssize_t fuse_buf_copy_one(fuse_req_t req, const struct fuse_buf *dst, size_t dst_of= f, const struct fuse_buf *src, size_t src_of= f, - size_t len) + size_t len, bool dropped_cap_fsetid) { int src_is_fd =3D src->flags & FUSE_BUF_IS_FD; int dst_is_fd =3D dst->flags & FUSE_BUF_IS_FD; @@ -211,7 +211,8 @@ static ssize_t fuse_buf_copy_one(fuse_req_t req, int dst_is_phys =3D src->flags & FUSE_BUF_PHYS_ADDR; =20 if (src_is_phys && !src_is_fd && dst_is_fd) { - return fuse_virtio_write(req, dst, dst_off, src, src_off, len); + return fuse_virtio_write(req, dst, dst_off, src, src_off, len, + dropped_cap_fsetid); } assert(!src_is_phys && !dst_is_phys); if (!src_is_fd && !dst_is_fd) { @@ -267,7 +268,7 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv= , size_t len) } =20 ssize_t fuse_buf_copy(fuse_req_t req, struct fuse_bufvec *dstv, - struct fuse_bufvec *srcv) + struct fuse_bufvec *srcv, bool dropped_cap_fsetid) { size_t copied =3D 0, i; =20 @@ -309,7 +310,8 @@ ssize_t fuse_buf_copy(fuse_req_t req, struct fuse_bufve= c *dstv, dst_len =3D dst->size - dstv->off; len =3D min_size(src_len, dst_len); =20 - res =3D fuse_buf_copy_one(req, dst, dstv->off, src, srcv->off, len= ); + res =3D fuse_buf_copy_one(req, dst, dstv->off, src, srcv->off, len, + dropped_cap_fsetid); if (res < 0) { if (!copied) { return res; diff --git a/tools/virtiofsd/fuse_common.h b/tools/virtiofsd/fuse_common.h index 05d56883dd..8cf9a5544e 100644 --- a/tools/virtiofsd/fuse_common.h +++ b/tools/virtiofsd/fuse_common.h @@ -718,10 +718,14 @@ size_t fuse_buf_size(const struct fuse_bufvec *bufv); * @param req The request this copy is part of * @param dst destination buffer vector * @param src source buffer vector + * @param dropped_cap_fsetid Caller has dropped CAP_FSETID. If work is han= ded + * over to a different thread/process, CAP_FSETID needs to be dropp= ed + * there as well. * @return actual number of bytes copied or -errno on error */ ssize_t fuse_buf_copy(fuse_req_t req, - struct fuse_bufvec *dst, struct fuse_bufvec *src); + struct fuse_bufvec *dst, struct fuse_bufvec *src, + bool dropped_cap_fsetid); =20 /** * Memory buffer iterator diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index b36140c565..21e1ee24d0 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -2029,9 +2029,13 @@ int64_t fuse_virtio_io(struct fuse_session *se, Vhos= tUserFSSlaveMsg *msg, * @param src The source (memory) buffer * @param src_off The GPA * @param len Length in bytes + * @param dropped_cap_fsetid Caller dropped CAP_FSETID. If it is being han= ded + * over to different thread/process, CAP_FSETID needs to be dropped + * before write. */ ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst, size_t dst_off, const struct fuse_buf *src, - size_t src_off, size_t len); + size_t src_off, size_t len, + bool dropped_cap_fsetid); =20 #endif /* FUSE_LOWLEVEL_H_ */ diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 316d1f2463..6cdf131bc7 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -1189,7 +1189,7 @@ int64_t fuse_virtio_io(struct fuse_session *se, Vhost= UserFSSlaveMsg *msg, */ ssize_t fuse_virtio_write(fuse_req_t req, const struct fuse_buf *dst, size_t dst_off, const struct fuse_buf *src, - size_t src_off, size_t len) + size_t src_off, size_t len, bool dropped_cap_fse= tid) { VhostUserFSSlaveMsg msg =3D { 0 }; =20 @@ -1205,6 +1205,9 @@ ssize_t fuse_virtio_write(fuse_req_t req, const struc= t fuse_buf *dst, msg.c_offset[0] =3D (uintptr_t)src->mem + src_off; msg.len[0] =3D len; msg.flags[0] =3D VHOST_USER_FS_FLAG_MAP_W; + if (dropped_cap_fsetid) { + msg.gen_flags |=3D VHOST_USER_FS_GENFLAG_DROP_FSETID; + } =20 int64_t result =3D fuse_virtio_io(req->se, &msg, dst->fd); fuse_log(FUSE_LOG_DEBUG, "%s: result=3D%ld\n", __func__, result); diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 5baf4f1d50..8dba129785 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2135,7 +2135,7 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t i= no, } } =20 - res =3D fuse_buf_copy(req, &out_buf, in_buf); + res =3D fuse_buf_copy(req, &out_buf, in_buf, fi->kill_priv); if (res < 0) { fuse_reply_err(req, -res); } else { --=20 2.29.2