From nobody Sat May 4 17:45:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605687067; cv=none; d=zohomail.com; s=zohoarc; b=jKgC72/5i/ksT+w7mTPyED0qDc/rrMrQ5FEzVJMipJSpCBAYIC1nFiFVv/hsthmB1LMC86z/Njh4G3MLSOSMfbwMjA/KhviiFAFE47iy4G6GJh7raCsjiZd+tnggV7jFJnZCKlN/HfyHoGAynIe3gHuUY66qPSsESi74wkD5oLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605687067; h=Content-Type:Content-Transfer-Encoding:Cc: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=6mXkZftTsZuqQYcTrgM47Ju8w47JOdXRZojxTJpK8b0=; b=DPfP+EHW41Ier/cK8v+DI4qgx3vkRTeB4kbYkP/99KDVK9hdWRxk4srEaoMvNl3HKDr2QddZ6d7nI5HmR4zGnasrSEx8gWtwwA0fGYx9d/MhBMZ5TxGzrhQvGjoSH24ZBQ7J6mSB++yUf2SmYDW1QZ6AP8A2zC+kZ1s4cjTgyyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1605687067721583.7859896171096; Wed, 18 Nov 2020 00:11:07 -0800 (PST) Received: from localhost ([::1]:48766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfIYU-0002qC-Gj for importer@patchew.org; Wed, 18 Nov 2020 03:11:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfIWx-0001bI-Vb for qemu-devel@nongnu.org; Wed, 18 Nov 2020 03:09:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23959) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kfIWv-0001mp-Rt for qemu-devel@nongnu.org; Wed, 18 Nov 2020 03:09: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-163-B_2MSTRaPMS0_FPRjy_tqg-1; Wed, 18 Nov 2020 03:09:26 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB9DA1009440 for ; Wed, 18 Nov 2020 08:09:25 +0000 (UTC) Received: from localhost (unknown [10.36.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE6625D9CA; Wed, 18 Nov 2020 08:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605686969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6mXkZftTsZuqQYcTrgM47Ju8w47JOdXRZojxTJpK8b0=; b=RYx28kpaRkSa8WzlKSZK+9/1DYIZjrrGsl5hCuzTj+Rk22UkurqFwt8NecEf+haklOnuGI PFeuRmcmBmLhUUwlI9PJZFZYV2RSMFIgfk/eD89funRiJCC42HHHaOfBrIHFHWnwQqlVCN 7ea+G/Hq82o0QA8i90d3BHDWDa0B9mw= X-MC-Unique: B_2MSTRaPMS0_FPRjy_tqg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 1/2] libvhost-user: replace qemu/bswap.h with glibc endian.h Date: Wed, 18 Nov 2020 12:09:01 +0400 Message-Id: <20201118080902.30033-2-marcandre.lureau@redhat.com> In-Reply-To: <20201118080902.30033-1-marcandre.lureau@redhat.com> References: <20201118080902.30033-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/18 00:38:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, stefanha@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- contrib/libvhost-user/libvhost-user.c | 77 ++++++++++++++------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 5c73ffdd6b..1c1cfbf1e7 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "qemu/compiler.h" =20 #if defined(__linux__) @@ -42,7 +43,6 @@ =20 #include "qemu/atomic.h" #include "qemu/osdep.h" -#include "qemu/bswap.h" #include "qemu/memfd.h" =20 #include "libvhost-user.h" @@ -1081,7 +1081,7 @@ vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg) return false; } =20 - vq->used_idx =3D lduw_le_p(&vq->vring.used->idx); + vq->used_idx =3D le16toh(vq->vring.used->idx); =20 if (vq->last_avail_idx !=3D vq->used_idx) { bool resume =3D dev->iface->queue_is_processed_in_order && @@ -1198,7 +1198,7 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq) return 0; } =20 - vq->used_idx =3D lduw_le_p(&vq->vring.used->idx); + vq->used_idx =3D le16toh(vq->vring.used->idx); vq->resubmit_num =3D 0; vq->resubmit_list =3D NULL; vq->counter =3D 0; @@ -2031,13 +2031,13 @@ vu_queue_started(const VuDev *dev, const VuVirtq *v= q) static inline uint16_t vring_avail_flags(VuVirtq *vq) { - return lduw_le_p(&vq->vring.avail->flags); + return le16toh(vq->vring.avail->flags); } =20 static inline uint16_t vring_avail_idx(VuVirtq *vq) { - vq->shadow_avail_idx =3D lduw_le_p(&vq->vring.avail->idx); + vq->shadow_avail_idx =3D le16toh(vq->vring.avail->idx); =20 return vq->shadow_avail_idx; } @@ -2045,7 +2045,7 @@ vring_avail_idx(VuVirtq *vq) static inline uint16_t vring_avail_ring(VuVirtq *vq, int i) { - return lduw_le_p(&vq->vring.avail->ring[i]); + return le16toh(vq->vring.avail->ring[i]); } =20 static inline uint16_t @@ -2133,12 +2133,12 @@ virtqueue_read_next_desc(VuDev *dev, struct vring_d= esc *desc, int i, unsigned int max, unsigned int *next) { /* If this descriptor says it doesn't chain, we're done. */ - if (!(lduw_le_p(&desc[i].flags) & VRING_DESC_F_NEXT)) { + if (!(le16toh(desc[i].flags) & VRING_DESC_F_NEXT)) { return VIRTQUEUE_READ_DESC_DONE; } =20 /* Check they're not leading us off end of descriptors. */ - *next =3D lduw_le_p(&desc[i].next); + *next =3D le16toh(desc[i].next); /* Make sure compiler knows to grab that: we don't want it changing! */ smp_wmb(); =20 @@ -2181,8 +2181,8 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, uns= igned int *in_bytes, } desc =3D vq->vring.desc; =20 - if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) { - if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) { + if (le16toh(desc[i].flags) & VRING_DESC_F_INDIRECT) { + if (le32toh(desc[i].len) % sizeof(struct vring_desc)) { vu_panic(dev, "Invalid size for indirect buffer table"); goto err; } @@ -2195,8 +2195,8 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, uns= igned int *in_bytes, =20 /* loop over the indirect descriptor table */ indirect =3D 1; - desc_addr =3D ldq_le_p(&desc[i].addr); - desc_len =3D ldl_le_p(&desc[i].len); + desc_addr =3D le64toh(desc[i].addr); + desc_len =3D le32toh(desc[i].len); max =3D desc_len / sizeof(struct vring_desc); read_len =3D desc_len; desc =3D vu_gpa_to_va(dev, &read_len, desc_addr); @@ -2223,10 +2223,10 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, u= nsigned int *in_bytes, goto err; } =20 - if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) { - in_total +=3D ldl_le_p(&desc[i].len); + if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) { + in_total +=3D le32toh(desc[i].len); } else { - out_total +=3D ldl_le_p(&desc[i].len); + out_total +=3D le32toh(desc[i].len); } if (in_total >=3D max_in_bytes && out_total >=3D max_out_bytes= ) { goto done; @@ -2377,7 +2377,7 @@ vring_used_flags_set_bit(VuVirtq *vq, int mask) =20 flags =3D (uint16_t *)((char*)vq->vring.used + offsetof(struct vring_used, flags)); - stw_le_p(flags, lduw_le_p(flags) | mask); + *flags =3D htole16(le16toh(*flags) | mask); } =20 static inline void @@ -2387,17 +2387,20 @@ vring_used_flags_unset_bit(VuVirtq *vq, int mask) =20 flags =3D (uint16_t *)((char*)vq->vring.used + offsetof(struct vring_used, flags)); - stw_le_p(flags, lduw_le_p(flags) & ~mask); + *flags =3D htole16(le16toh(*flags) & ~mask); } =20 static inline void vring_set_avail_event(VuVirtq *vq, uint16_t val) { + uint16_t *avail; + if (!vq->notification) { return; } =20 - stw_le_p(&vq->vring.used->ring[vq->vring.num], val); + avail =3D (uint16_t *)&vq->vring.used->ring[vq->vring.num]; + *avail =3D htole16(val); } =20 void @@ -2487,15 +2490,15 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned= int idx, size_t sz) struct vring_desc desc_buf[VIRTQUEUE_MAX_SIZE]; int rc; =20 - if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) { - if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) { + if (le16toh(desc[i].flags) & VRING_DESC_F_INDIRECT) { + if (le32toh(desc[i].len) % sizeof(struct vring_desc)) { vu_panic(dev, "Invalid size for indirect buffer table"); return NULL; } =20 /* loop over the indirect descriptor table */ - desc_addr =3D ldq_le_p(&desc[i].addr); - desc_len =3D ldl_le_p(&desc[i].len); + desc_addr =3D le64toh(desc[i].addr); + desc_len =3D le32toh(desc[i].len); max =3D desc_len / sizeof(struct vring_desc); read_len =3D desc_len; desc =3D vu_gpa_to_va(dev, &read_len, desc_addr); @@ -2517,11 +2520,11 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned= int idx, size_t sz) =20 /* Collect all the descriptors */ do { - if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) { + if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) { if (!virtqueue_map_desc(dev, &in_num, iov + out_num, VIRTQUEUE_MAX_SIZE - out_num, true, - ldq_le_p(&desc[i].addr), - ldl_le_p(&desc[i].len))) { + le64toh(desc[i].addr), + le32toh(desc[i].len))) { return NULL; } } else { @@ -2531,8 +2534,8 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned i= nt idx, size_t sz) } if (!virtqueue_map_desc(dev, &out_num, iov, VIRTQUEUE_MAX_SIZE, false, - ldq_le_p(&desc[i].addr), - ldl_le_p(&desc[i].len))) { + le64toh(desc[i].addr), + le32toh(desc[i].len))) { return NULL; } } @@ -2731,15 +2734,15 @@ vu_log_queue_fill(VuDev *dev, VuVirtq *vq, max =3D vq->vring.num; i =3D elem->index; =20 - if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) { - if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) { + if (le16toh(desc[i].flags) & VRING_DESC_F_INDIRECT) { + if (le32toh(desc[i].len) % sizeof(struct vring_desc)) { vu_panic(dev, "Invalid size for indirect buffer table"); return; } =20 /* loop over the indirect descriptor table */ - desc_addr =3D ldq_le_p(&desc[i].addr); - desc_len =3D ldl_le_p(&desc[i].len); + desc_addr =3D le64toh(desc[i].addr); + desc_len =3D le32toh(desc[i].len); max =3D desc_len / sizeof(struct vring_desc); read_len =3D desc_len; desc =3D vu_gpa_to_va(dev, &read_len, desc_addr); @@ -2765,9 +2768,9 @@ vu_log_queue_fill(VuDev *dev, VuVirtq *vq, return; } =20 - if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) { - min =3D MIN(ldl_le_p(&desc[i].len), len); - vu_log_write(dev, ldq_le_p(&desc[i].addr), min); + if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) { + min =3D MIN(le32toh(desc[i].len), len); + vu_log_write(dev, le64toh(desc[i].addr), min); len -=3D min; } =20 @@ -2792,15 +2795,15 @@ vu_queue_fill(VuDev *dev, VuVirtq *vq, =20 idx =3D (idx + vq->used_idx) % vq->vring.num; =20 - stl_le_p(&uelem.id, elem->index); - stl_le_p(&uelem.len, len); + uelem.id =3D htole32(elem->index); + uelem.len =3D htole32(len); vring_used_write(dev, vq, &uelem, idx); } =20 static inline void vring_used_idx_set(VuDev *dev, VuVirtq *vq, uint16_t val) { - stw_le_p(&vq->vring.used->idx, val); + vq->vring.used->idx =3D htole16(val); vu_log_write(dev, vq->vring.log_guest_addr + offsetof(struct vring_used, id= x), sizeof(vq->vring.used->idx)); --=20 2.29.0 From nobody Sat May 4 17:45:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605687093; cv=none; d=zohomail.com; s=zohoarc; b=ODXmMG3H1OWKdNmmDW+/mQYSE7a06Id21tbVTjKADJmX2AWzZn5Qk/3T48tEPyweo9IEfT08KOrRFmrhptYH2NOEr72nhiFjDPMcVkUp4neyqjESpa9ZW+SWS7Hjteb2TEBYRRNHlz8fmndNvBZ+MsLsPr3DwrM/sSFmTOJPSWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605687093; h=Content-Type:Content-Transfer-Encoding:Cc: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=Avtj+hw4pq1j0k1zaeczCO8UVhJf+3taB0iD+4nw2o8=; b=P75u6HBfnkso2bQUSsnh6DpEYJiTQzjH93rTWQuvuI8reTSPG6sOh3BroDqzmvf6S4Rq0jTVhuCc9yl235hAqt5jP/F8ffDvCsl+EXL5Ksue2k2rGYQdXUPBVTs8TOyMGyo4Y8WV5EPjtcHCvtlNgs1bd4oOAXtoTV9Yj5H9/8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1605687093982294.4379864540871; Wed, 18 Nov 2020 00:11:33 -0800 (PST) Received: from localhost ([::1]:49256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfIYu-00034f-SW for importer@patchew.org; Wed, 18 Nov 2020 03:11:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfIXA-0001lj-CE for qemu-devel@nongnu.org; Wed, 18 Nov 2020 03:09:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kfIX6-0001nB-97 for qemu-devel@nongnu.org; Wed, 18 Nov 2020 03:09: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-271-v9qr2U1FM36fa6Xsye8WpQ-1; Wed, 18 Nov 2020 03:09:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 867E21009462 for ; Wed, 18 Nov 2020 08:09:36 +0000 (UTC) Received: from localhost (unknown [10.36.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92DFE1759F; Wed, 18 Nov 2020 08:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605686979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Avtj+hw4pq1j0k1zaeczCO8UVhJf+3taB0iD+4nw2o8=; b=eeJOX+llPrImEGcHT8nEeSe2Sz95gDVilpid6QqAUePE5oB0U0q1oNXR+UfJZxMW7pHkCz d8CH4BIjS1rjPDorCNY9N7MolmNCQ9LFFaclRsU/l4yt/EQvVRBvtzaJ4WthUDlVob+wgD 9jkownIolH7t5T72TPrAFoAuqcwGSDM= X-MC-Unique: v9qr2U1FM36fa6Xsye8WpQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 2/2] libvhost-user: replace qemu/memfd.h usage Date: Wed, 18 Nov 2020 12:09:02 +0400 Message-Id: <20201118080902.30033-3-marcandre.lureau@redhat.com> In-Reply-To: <20201118080902.30033-1-marcandre.lureau@redhat.com> References: <20201118080902.30033-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/18 00:38:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, stefanha@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Undo the damage from commit 5f9ff1eff3 ("libvhost-user: Support tracking inflight I/O in shared memory") which introduced glib dependency through osdep.h inclusion. libvhost-user.c tries to stay free from glib usage. Use glibc memfd_create directly when available (assumed so when MFD_ALLOW_SEALING is defined). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi --- contrib/libvhost-user/libvhost-user.c | 50 +++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 1c1cfbf1e7..805521859d 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -42,8 +42,6 @@ #endif =20 #include "qemu/atomic.h" -#include "qemu/osdep.h" -#include "qemu/memfd.h" =20 #include "libvhost-user.h" =20 @@ -1615,11 +1613,45 @@ vu_inflight_queue_size(uint16_t queue_size) sizeof(uint16_t), INFLIGHT_ALIGNMENT); } =20 +#ifdef MFD_ALLOW_SEALING +static void * +memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd) +{ + void *ptr; + int ret; + + *fd =3D memfd_create(name, MFD_ALLOW_SEALING); + if (*fd < 0) { + return NULL; + } + + ret =3D ftruncate(*fd, size); + if (ret < 0) { + close(*fd); + return NULL; + } + + ret =3D fcntl(*fd, F_ADD_SEALS, F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_S= EAL); + if (ret < 0) { + close(*fd); + return NULL; + } + + ptr =3D mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); + if (ptr =3D=3D MAP_FAILED) { + close(*fd); + return NULL; + } + + return ptr; +} +#endif + static bool vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) { - int fd; - void *addr; + int fd =3D -1; + void *addr =3D NULL; uint64_t mmap_size; uint16_t num_queues, queue_size; =20 @@ -1637,9 +1669,13 @@ vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) =20 mmap_size =3D vu_inflight_queue_size(queue_size) * num_queues; =20 - addr =3D qemu_memfd_alloc("vhost-inflight", mmap_size, - F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL, - &fd, NULL); +#ifdef MFD_ALLOW_SEALING + addr =3D memfd_alloc("vhost-inflight", mmap_size, + F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL, + &fd); +#else + vu_panic(dev, "Not implemented: memfd support is missing"); +#endif =20 if (!addr) { vu_panic(dev, "Failed to alloc vhost inflight area"); --=20 2.29.0