From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359369; cv=none; d=zohomail.com; s=zohoarc; b=j8paQqv+K1stSfaW7Y13T5vLuHLb70ZDSV6zNLAb709xIUFsoByQLm9B0tpMQrc1dfuct9/4hVAfcYNXhx7rq8wvAz4XFEvvZuyamn8Elpp9Rtd3BI+AM6fMoqX+vLV8/WJm1FgS6cyq2iztg6leKIQkwM9Sqc5DMvOSmuJdtQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359369; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vd5BWeOhgl4OJE0+2tUQcWMWNMpBRcJ6kN3JbG9lrMQ=; b=DE1BvQOSuxTYks2Ti33QpkJdVYQtBd+j3BssZAwHEdSAr9buLGOHaTOXUPdcvUWSL0nPhfDMhewfBSqJ2tW3eychpYAKMyvsKHoDYZjg/ish/pRDCi611A2OIbMXi9kMKe5GyR3CKBSSQlnWr8AeCJshvUQpaW4GyDrpJ2zJm1s= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359369962620.7857667380883; Fri, 30 Oct 2026 04:22:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkgE-0001Se-8d; Fri, 30 Oct 2026 07:21:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkfw-0001L5-Fk for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:37 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkfs-0002kj-Uj for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:35 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-48e3b22e971so275919f8f.0 for ; Fri, 30 Oct 2026 04:21:32 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359291; x=1793964091; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vd5BWeOhgl4OJE0+2tUQcWMWNMpBRcJ6kN3JbG9lrMQ=; b=Cd0E4BlSvDpPikwFm9m6opqrk++Zo1sCsfN0zBmcVR9ogwUxrNFT3o4IothA3+KxXK OWgB0rDG945PK6qc0euXraa6mZHn/VyT+RKNGZ7Avv+NYWDa26HXnIB+ulLuDcOyEXXB 2n2RCavU9avvF1yFel3z+lwiD8Mp4X70wSzgi4NCJRFJH5uzrByvPg2eQtZ6t/MxcwrX h74jiUXnzihbeOMnnWAoHHDBURmlUPYs1tDSURZyZg2ITGKRoSG2KDzDDarKtZ2Kv9gE Tg+ekqqAdzvuiMoOzPd2zcxsqog9dwGRxUEFQxlur/XfMhaTYkPH1lOZcIUyhWiG1vnC QDSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359291; x=1793964091; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vd5BWeOhgl4OJE0+2tUQcWMWNMpBRcJ6kN3JbG9lrMQ=; b=rXqN7gmfUSKZiR2duFwNOrjPwICZBLI3ulwC9f64Tkw7u1mP5bzMLj6ryfXLAWFSgU 6iDbI/I4HziC9Sm/R9XveUKp6kksAlu61hoP5ECRCz+4stbq3GMw0ymlO8CE/KbiAyeF dtnFIbTbIDXF6EPkn6zBiopi/hVPUPK5fzV1Srp2JL4SysjP4DXXjj3DhKs7bIx0XHjK JOkeKrpv6OOmxn8K9Raks45ZtxpaCbCDyeU6NZQPcsSwarrH9WTLv4dYKj+4sbvS1kiN 2YP0G85QmJgp6nXsjbqdnbDrj+QPbo8Y3LkmTbJUeYRulQrjTD07n0Z5mC9fXTVJsrx9 b+gQ== X-Gm-Message-State: AFq9FYLVJbm+hoJrtlz2yMUwte1rPXk6fXnIEltR9BmG8/t8LeO1sa2H jbe2SHp4md1Df2jzAd2hW8G0nsaH2WEqXZPIDu+UokkNQ25Rqwu5D8co X-Gm-Gg: AYBFou2ck0Q1sbLPgohja8Vm95lP25QiAzEmdkKDfsZD50+eLZwfXa78bAMf+0J/RIV CIqz2naXlUny5+iHcxCc5b7XP42J/RT7Pgtg1lP+BJ2R0ZCeQF52YiMXhal55Br9tWGQ3IdyaQr s6wPvTFToI0BVL3Kq2avXxBkT9eQGKsdcRfKKTo3NPPo6ngTSvkfw8dKd2Vk5fwrC9vu6BdG/uz CgSYqaYDx3BFg5WH/kx7JT+WZNKNf99cPlTEZcarvJOU5037lvyQQF5RLjuE3MW6CIxtitEgwck +KIjwGU3GizvQAuTj/Gwtmgc9PC/iisvWLh2T80odigqSpHI/gRNJofOFpTZJU4cCcGwP+aQpRt vgXh8zSKc3EMMUWls6+GH7QsJky+VnyX8EImp12F9iRbXFaf8qbAi1ZFhvyHfV/BCpfURmF7HG1 r49d6ma0y7OLoBaM99IpANVBf686gUlQ2I50toUjyvish0GoudFLXntQoKjFctXfkwOK9DOYgDX Gzwg1hItaKI1S8j7dUKKbLlXKWYGuh2aLhETJyzxQEnhpsgs7zusJ6GVKiRqcgH3TmlNGk909K1 4j26CTpGedW50MC6X88ZHwPScFPJDAkg7uYEUn8AL1K802UXRWGMv21feYN1MaYjBGYJK8essg7 kpNWbLEL38t4I7uDjJXuL25SO7VMOfW+qdgInoBwM4uu8c3368FmFW4V6ezSmaA== X-Received: by 2002:a05:6000:41c8:b0:48d:faa6:cedf with SMTP id ffacd0b85a97d-48e6e50645dmr4644278f8f.56.1793359291162; Fri, 30 Oct 2026 04:21:31 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:20:54 +0100 Subject: [PATCH v2 1/9] libvhost-user: detect memfd support with a link test MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-1-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=timpambor@gmail.com; helo=mail-wr1-x42a.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359372809154100 The inflight fd code is guarded by #ifdef MFD_ALLOW_SEALING, which only tells us that the headers define the flag, not that memfd_create() is available in the C library. There are environments where the flag is defined but the link fails: ld: error: libvhost-user.a(libvhost-user.c.o): undefined symbol: memfd_cr= eate Probe for memfd_create() with MFD_ALLOW_SEALING in the subproject's meson.build, using the same test QEMU's top-level meson.build uses for CONFIG_MEMFD, and guard the code with CONFIG_MEMFD instead. When memfd is not available, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is masked out as before, so the frontend never sends VHOST_USER_GET_INFLIGHT_FD. Signed-off-by: Tim Pambor --- subprojects/libvhost-user/libvhost-user.c | 15 +++++++-------- subprojects/libvhost-user/meson.build | 11 ++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 2fed792e85..adda700630 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1800,13 +1800,12 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUser= Msg *vmsg) features |=3D dev->iface->get_protocol_features(dev); } =20 -#ifndef MFD_ALLOW_SEALING +#ifndef CONFIG_MEMFD /* - * If MFD_ALLOW_SEALING is not defined, we are not able to handle - * VHOST_USER_GET_INFLIGHT_FD messages, since we can't create a memfd. - * Those messages are used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD - * is negotiated. A device implementation can enable it, so let's mask - * it to avoid a runtime panic. + * Without memfd we are not able to handle VHOST_USER_GET_INFLIGHT_FD + * messages. Those messages are used only if + * VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is negotiated. A device + * implementation can enable it, so let's mask it to avoid a runtime p= anic. */ features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); #endif @@ -2001,7 +2000,7 @@ vu_inflight_queue_size(uint16_t queue_size) sizeof(uint16_t), INFLIGHT_ALIGNMENT); } =20 -#ifdef MFD_ALLOW_SEALING +#ifdef CONFIG_MEMFD static void * memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd) { @@ -2068,7 +2067,7 @@ vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) =20 mmap_size =3D vu_inflight_queue_size(queue_size) * num_queues; =20 -#ifdef MFD_ALLOW_SEALING +#ifdef CONFIG_MEMFD addr =3D memfd_alloc("vhost-inflight", mmap_size, F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL, &fd); diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-u= ser/meson.build index a18014e7f2..aa5894a642 100644 --- a/subprojects/libvhost-user/meson.build +++ b/subprojects/libvhost-user/meson.build @@ -11,10 +11,19 @@ add_project_arguments(cc.get_supported_arguments('-Wsig= n-compare', threads =3D dependency('threads') glib =3D dependency('glib-2.0') =20 +vhost_user_flags =3D ['-D_GNU_SOURCE'] + +if cc.links(''' + #define _GNU_SOURCE + #include + int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }''') + vhost_user_flags +=3D '-DCONFIG_MEMFD' +endif + vhost_user =3D static_library('vhost-user', files('libvhost-user.c'), dependencies: threads, - c_args: '-D_GNU_SOURCE') + c_args: vhost_user_flags) =20 executable('link-test', files('link-test.c'), link_whole: vhost_user) --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359371; cv=none; d=zohomail.com; s=zohoarc; b=EakFproMo6wgYPG+elp3IIpKzJwyRp3FIaYoR7gsRpzobCuk7tKGkJvcs8IY7+yz4hsoFDeSdxUqwhjCFbh/8UOZ8ex1+VFNUZNwVbQCPznhKlOcvQ1SG4N9+WpZM44bCcx+ChoDDT2EJ3nWbRTTc3yNJssesr8S1OOJPwjtae8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359371; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9BuA42MLQr/5PMMpsTyjKbeHEHVM7JPHne/HEN7zZQU=; b=OHm68MtsqAwTKWxcTvGmmo54CyDKnBOswU658xNweKE4c+kP+WYrL8E+ESoN60aaU89uJIUP0pHgUxOreoDHpHwqtwAn0tzzKzeV2MyzcynOUqYyhc+Y9P/PAxywABhIiRMTTwoHgKvKPb4X2dKvx4x9F80gsBdY/bK9kY3YOwg= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359371568876.1676909656487; Fri, 30 Oct 2026 04:22:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkg3-0001Nk-TG; Fri, 30 Oct 2026 07:21:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkfw-0001L6-FZ for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:37 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkft-0002kt-W3 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:35 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4a5036bbac7so3175875e9.3 for ; Fri, 30 Oct 2026 04:21:33 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359292; x=1793964092; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9BuA42MLQr/5PMMpsTyjKbeHEHVM7JPHne/HEN7zZQU=; b=D8tGR2hLygnC+aCZ4nCfpjZzmT6KMMSDUugreiVeJcfrBdgIXBJ5aVlOglrQ6l2rl0 yg2F86M48d0OFxouD1Cp0nIp8JFLuyrUN6uEDNUvlHtSbMXuBesJuCzW7i953W821ezS 02oBImwKwZtWGz9RK6Z8a7qYRGzvkfz1HhzOSCy1dCWItNlw07oQuSwNPiNm+elJ126x EKB3VVUKy/g1y2xsF0jAOq5b74+lzV8YJz/xgyOEPlXiLVmzQggPyhS1/egkNpFR5n+I LRpTTzQkMT+x8nLoYDX35G7Qd4Ctc1a16eFrFn6/rdyn7qZdq0gFRlvPUz8tNwPdwO+R UUUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359292; x=1793964092; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9BuA42MLQr/5PMMpsTyjKbeHEHVM7JPHne/HEN7zZQU=; b=Shyi9cF0+PnHLOLxfXfPhUQJHQb/tr7N38VrnIU5NO1sEvZXkr6msx1KIEXfFI6Bzj LmjvAHB28E+Dwc4L5poh+X8Y2Vb3/1nmL2OaRkjLxdqxAK+6alVa3YiReYklcwXk2+Eo A/vPl8Alm3yzceI9xo8EwIxbs1h/2g4UF0nb3t3TSR9iPp45+ouAnmbt61UFwPT0fgw7 TKftKK+ejbdJfnM7nvOoRfcySj3oUfXCaPJkQb62FE7hIyevaVGMMc3tSFSVLVhlP+Ip CEnylew7N0sKSKnuin/F6s6pD8PtOwIlHqeZ5CXlR2ICQLBeuB/D0t6TEX/tZlAsrJoh vEcQ== X-Gm-Message-State: AFq9FYK6HizlPdKF68GcafJpvIQWj/d3gVXJ9LzE2qSLz+Zs/tFgSoET 6IPbJIaRRUFsQlwmMtj35OGLG9CSqsf/F+3lj0s291sDylQ3V/iw6jre X-Gm-Gg: AYBFou1e7jUUSwDanEJsS5H8PDrZPiYYY7WVzNUVioAu1bvCHbejguPZODQXMGUupug SBySTxYM6y+mvVwQVmiUO04SOV03pbT3Lbor6iyEu8rUPQI2ODqwZk/rBGsoE/2Z3l2WzVz0ftC J3VNcjB9e2in9lALBNSBQydbXrzmn+qNI2y1wDFPKsmWkH2pUutZM0q2YCXpFSTUwUFEZ07f6Pj hNmKAholI+fG9NVb5K1iid6vlCU/Ln6EGxCd0mWWNFzCkoWOn8L4xFsKfQ+6plt9TBnltuDFWjo JoYuzE/172cfhjrYhsaqqa4HAka42c4rbKAo8dBDA246KWw68+QxD6Ex6ct/woEtP3fhVAgAy3n +NXF46MER3BN10FCGAsOu6GRmDyLuhIk0sas2C2AsMUb5WPKHkj8FsRvp5ZkgF831PkAWpOCd7k OyKtmF+iYPkD6ygDMRXjrYZDEat9mwgrhnzslK+jNvkLd2EQrJfsZR702Otse1T0lHlNAv8Hcm9 xgoUQQI95w1iZgExw6XrX6E0qd9/fg6r9U90Q6nVLmIlST8Y+0/2hDbbM7skUyQbbALdIHwNKJG FCzDEYLkmQXtcHWKs4gtTNBAelUHhWg7xW3JUQBHFgoAWe+LdikFU/neFO/4vegyxeKvhG6PHsB XKupC2x8olBFKtbjch/94+TmvGyXXrj/gqx9Oe/bF+ooo7kqqniBTJpLg4Bz5vw== X-Received: by 2002:a05:600c:138c:b0:4a1:f90d:6f4c with SMTP id 5b1f17b1804b1-4ac17ffaff2mr39360115e9.7.1793359292398; Fri, 30 Oct 2026 04:21:32 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:20:55 +0100 Subject: [PATCH v2 2/9] libvhost-user: detect eventfd support with a link test MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-2-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=timpambor@gmail.com; helo=mail-wm1-x32d.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359372480158500 libvhost-user includes unconditionally and uses eventfd_read() and eventfd_write(). The header is not available on every POSIX system, e.g. macOS, so the build fails there: libvhost-user.c:31:10: fatal error: 'sys/eventfd.h' file not found Probe for eventfd() in the subproject's meson.build, using the same test QEMU's top-level meson.build uses for CONFIG_EVENTFD, and only include the header when CONFIG_EVENTFD is set. Without eventfd the front-end falls back to pipes, so provide eventfd_read() and eventfd_write() replacements with plain read() and write(). Signed-off-by: Tim Pambor --- subprojects/libvhost-user/libvhost-user.c | 17 ++++++++++++++++- subprojects/libvhost-user/meson.build | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index adda700630..ece2bfcdd7 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include =20 @@ -52,6 +51,22 @@ =20 #endif =20 +#ifdef CONFIG_EVENTFD +#include +#else +#define eventfd_t uint64_t + +int eventfd_write(int fd, eventfd_t value) +{ + return (write(fd, &value, sizeof(value)) =3D=3D sizeof(value)) ? 0 : -= 1; +} + +int eventfd_read(int fd, eventfd_t *value) +{ + return (read(fd, value, sizeof(*value)) =3D=3D sizeof(*value)) ? 0 : -= 1; +} +#endif + #include "include/atomic.h" =20 #include "libvhost-user.h" diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-u= ser/meson.build index aa5894a642..2f9aedb208 100644 --- a/subprojects/libvhost-user/meson.build +++ b/subprojects/libvhost-user/meson.build @@ -20,6 +20,12 @@ if cc.links(''' vhost_user_flags +=3D '-DCONFIG_MEMFD' endif =20 +if cc.links(''' + #include + int main(void) { return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); }''') + vhost_user_flags +=3D '-DCONFIG_EVENTFD' +endif + vhost_user =3D static_library('vhost-user', files('libvhost-user.c'), dependencies: threads, --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359363; cv=none; d=zohomail.com; s=zohoarc; b=CQaOxZM9HNRYygbIusDfvQviygmjJTjql94O1UblfEctN3GvhXIDGb5RYhnA6qCBAwcRTibpdxENZahVAOeHpH73KRATiYMWgCW1spiWptQM0q2WLv014pfT9wBPkJy9/l+dXX3KF5+jaNSZXL9MFoKSMENijTCpp8nUPhZV2n8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359363; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EEwSVgmgSkQ5ZAKDlh9daWSH5HudgGHgylwl/5eaU1k=; b=m87wTRbSIqJUq7ct2ZYwRQrv2jeTPLUaY0L7sVUHXFGqqwtKauAvpk3xseJw90iACn2XXaU+N3PegzfPeJ6rZa+eo6KEHPLUWMm2x2ZDfpovEqXtV0zYsZ7KBVSG1PdtWXRvV69TgE0XgiKXXuDhBdyQ19pmDzbl2m62lWRUpto= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359362967390.59675541524757; Fri, 30 Oct 2026 04:22:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkg3-0001Nq-S5; Fri, 30 Oct 2026 07:21:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkfx-0001LD-NW for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:37 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkfw-0002lC-6s for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:37 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a2084d62cdso4758595e9.1 for ; Fri, 30 Oct 2026 04:21:35 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359294; x=1793964094; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EEwSVgmgSkQ5ZAKDlh9daWSH5HudgGHgylwl/5eaU1k=; b=OFcuf2+uLMy8cvqYlbdGkmn1szWgqjSCBaUPVu6YLSpUhjjqJqQDThNOB3aqjYFpd+ HPXfv9aAhfJS/ik1vntKyrN2UxZP3SXCZCNOhkcacc61zFbn9GBsTMxUE0Xx7FkeFBS1 AlGse/Xwm57+onjxcUtRSSfQ0xNPSiOkT8h5o7Sfg1mdfAaSCbNr4M/JJcHlSFPL16Jh 4wD2NJDSPV2iAR1it4iIMVw7jOMsiXgoXOxVZrZO/WQrRnTSkzkEuQ1mVupV6esAqGuW FwKSerOQtKENM6KtUkIq4hdtANz1HTZg2bgsW4i777Mddf3jBds3FNtlxMPj0Fv6QYXw l4sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359294; x=1793964094; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EEwSVgmgSkQ5ZAKDlh9daWSH5HudgGHgylwl/5eaU1k=; b=B48f2tzVjE8FWpbnaKKqtAFm4lyi8UHqxfa7zEmds6PfkUIEoPUsr2f2MtqKfw0SJj s2BXpaj02jXzunVWeyK0rlGaivMQnxoHjqUJA1n2fL7ic1M7yV7bWnLAKKrsNklVZhcj xkkuLfEBNOdGOHNaBKEkc+MgJ+3XGVHXsMYnPXkG2PLwS2VtSN/8yaEhokfpRcO/TfhZ NfNsDE0y1x7rYGXH/eDbBzl0h4yej8XbJjMdObpcLmdLLApBWJGIWp9vphQH94e7DxzF NNAAbjyLr8I+RlExdTqDfXHxQ04vIcxAD4m+sILmlb8PFKecsx2L4eXNT7Yf5wRHyoho ibRQ== X-Gm-Message-State: AFq9FYKtCylmDX7sCs6GTlb2/TuHBPbzkc7S8SHxTWmtNWvK54zX65VT tgfGyCF+Q0RfE+pGRBOWLWkDnmBJtq9BirzwmqqPBKXyE1Di6mZzjiFx X-Gm-Gg: AYBFou2hi+N4ruORblfR0aPNU6q8ZBy4+jl1Bbq8EMOIhSCU1mgSt0Q5iYLeNGm16RJ xWCC/OxlDvWqAr6mU+ZVaKeHnPxwU/VGwTGeC0YbFz2Mwuisz8EQVOVZTZqi6P6XIGdFNWalans gHEbAKYnYo24aBoxL3ENviG3HEn0ixQ38+STossjnfkdgkf3wlsMv/cJZGa2dqbU2KAZjy93sGc 4StyVBgVlJBNyeRS3pIP5ul/hYbzCoOP6G17VmtLwOHhrTNQV1tsp6qebyyVKpDDklYPbwLi8iB 5T9gl9648iHcli0x7UTngPIDcrz1GBxti1JAgpvnY0zQj8ASSsLmnbHFaMVee22CaydUKxdRtUc AAs5TKPwTOOlW7Qwys0MZjEajMSO19yMNRGsXawQ9N/Gcn3xNfb/brZj1DpAShrww12TZ9N15ql xuttIMOGbpNDG9ePAXaNYW3Xgc3xRaSGqWDB3rsQRfYTly6t/Mvpo94WvRy1i/WDTQNcnN/xiLl q4llvmTazXLntDX1Ye2MSawZeMzbCnmIL2s8qHpw3MmhLCrPdxigOfHeWLqmGqRXyR6fP6CjElB skkEGgiNY8WNgHUp7kjddEp4GUdwlduHdT+c8PlxBHNzRCPlUEiulRU9qVv+N3PpM/rK5GARgYV WjccHbcSDVlufgm/X6IP7i2+ZJHA2+0MGgubMaA4q80XdjfEntAJuOdMmGCG3Xt4= X-Received: by 2002:a05:600c:6087:b0:4a1:fe26:24f0 with SMTP id 5b1f17b1804b1-4ac1765ce52mr40569815e9.20.1793359293737; Fri, 30 Oct 2026 04:21:33 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:20:56 +0100 Subject: [PATCH v2 3/9] vhost-user: kick via event_notifier_set() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-3-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=timpambor@gmail.com; helo=mail-wm1-x32b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359364410158500 vhost-user injects a kick by writing to the fd it has just passed to the back-end. With an eventfd that fd is writable, but when pipes are used it is the read end and the write fails. Instead, kick via event_notifier_set() on the queue's host notifier, which writes to the correct end in both cases. Signed-off-by: Tim Pambor --- Changes in v2: - Add comment about eventfd vs pipe - Add assert file->fd =3D=3D event_notifier_get_fd() --- hw/virtio/vhost-user.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 65889b0776..868b3d25ca 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1527,16 +1527,17 @@ static int vhost_user_set_vring_kick(struct vhost_d= ev *dev, * receiving a kick. The spec suggests this to improve compatibility. */ if (file->fd !=3D -1) { - uint64_t val =3D 1; - ssize_t nwritten; - - do { - nwritten =3D write(file->fd, &val, sizeof(val)); - } while (nwritten < 0 && errno =3D=3D EINTR); + /* + * With an eventfd that fd is writable, but when pipes are used it= is + * the read end and the write fails. Instead, kick via + * event_notifier_set() on the queue's host notifier, which writes + * to the correct end in both cases. + */ + VirtQueue *vq =3D virtio_get_queue(dev->vdev, file->index); + EventNotifier *n =3D virtio_queue_get_host_notifier(vq); =20 - if (nwritten < 0 && errno !=3D EAGAIN /* back-end can already read= */) { - return -errno; - } + assert(file->fd =3D=3D event_notifier_get_fd(n)); + return event_notifier_set(n); } =20 return 0; --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359379; cv=none; d=zohomail.com; s=zohoarc; b=gle71l5Kaa3u6KfvEf90AfRMcpnOtoIo0N/3yQ1xq7w5NM+Nwq8AX8AD72VbvMqXnJARn1y5DfWj7IDuBnA2ZW2qn9tnkc/QSCPUE7XJVYKtdQQash86cXsmc4Dj3dAjwS0Of/RogR5DtfUntpA+uPVDNYI0Boa6+BOyT6AK07c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359379; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OKx3WZoWzdD1zHUS1BNUvEzkmCP6IQtxBC0V6HuRO1M=; b=CsKp1JzdzxhVjN5JIbXoblBRrla08e/Z0IXIekfqip3p3uCj6vv0x8QAvdW+vAvcs/5s1ud15epgCsoK+23x8jCl67a3+3mDPmjgAGP20oejpohhcpNkMBXZ0AW9Oqug5xTbJDP6bIdK/qbGKyQ3av/dT7GGlc2IurXsSoQciVA= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359379160165.69902776233312; Fri, 30 Oct 2026 04:22:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkgG-0001Tm-2i; Fri, 30 Oct 2026 07:21:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkfy-0001M5-HC for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:39 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkfw-0002lR-Lx for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:38 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-48e0d885929so485332f8f.3 for ; Fri, 30 Oct 2026 04:21:36 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359295; x=1793964095; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OKx3WZoWzdD1zHUS1BNUvEzkmCP6IQtxBC0V6HuRO1M=; b=zdYGM7XOB01AoZTtP+NckydOJxGTLCNikYTKdHnO1q+IapTgTJDTyN21DbqpOa+aJW gku8gfn1IfCkIRS4mpIbgmlRKHFjmkVlLh8Rb0KDmHhgb3mObsP2lslkv9iHS4W0c2/T obmryozoWwNBOJXYKft2olY84lFfNAaIHpMUooyOXkvWuPuFJmZ3Eul3S2TKL6QUvAnY 9h7Q5VkVIh73TuIqYeyqsE5ch9QwS2Il9fuXwe7agqDvqJfHZZsuYHE+4ama+EeJe7F1 /kfYp5z/YNjqcLabhHIBtFFAcLvaOZM1moPC6+H5HnCT8UraeIIL2Y6MBJK9StSjSKyh 3IBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359295; x=1793964095; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OKx3WZoWzdD1zHUS1BNUvEzkmCP6IQtxBC0V6HuRO1M=; b=fBlzqe1E24wrdm596xpak94e51/XTCsrBrylcWW04qvASM9znmYmNUxTMpT4QxMD/I IOBIs5UIjoyFbvAzLQH015Tipvdesylhwd1+yS2K6jZ0gFaolmmKrtl1KZfsKHiIxRx+ 1nfxl9QxSdidzF3unfQTiNmQQWjr2VZtw0U9ZKNURedrBxSFAKaJrv0kU+bja7SUa8UO B9tCZzo+3MOgdi+nBvQ4mOpx6tyqUT2liLq6qdWcsV6TbAWBEKnO+/cpQhxmnslqxsvO 4QSjYirg7UMHNxlbJmT8jqNpKWGwjOJTMmRF0KPb6mCHMwvrhhjLL+DPEedXLb3m1PNL vNfA== X-Gm-Message-State: AFq9FYI9/MLbcTPj0rSLXeQ1V3m2fINDGYfveusqd3o5mTy2jeixpjhW 06V2BK7fJzwDt2Tam/ffSB44DHBGnnV+F31LiuDrBO/7Fc06tK1pMXmn X-Gm-Gg: AYBFou3/g4HgXlnHQrs3xcv/asd4GLOFc+jU/QxKXYD06f+ByFF7Fr6XamKwX0rtfSv 8gdhtgpX3KHQq2CrOfQa/+VEsOiNXVKP664zwTdDoRq2oHOmDwuy5vSfzM03bXMmhdvt+4f3ILW p6UvLpcKTxcez8t2oH84z+f99aHDKCrH13G8p+h6cOu2bFu6yyGR6YWLCAuD8i6Eka1VSdO6Cq2 SsorvEDkNwv93SZq3rDEZGjoPKRbi/O5etjf5TUCT5/5X216h6Zh38rSSnj4BOaKHRsRMYfa9lR /oWSk1ChJ0nCKjPlJO6jt0M74aZpH9miwHZKW0XEOVkgh6f4ls5NkQkZ+6Z49xY3qHYeEsdeGt+ FfI+hKlFqQc8FZ26Ja/hCU0I9FuvdOnNgd+klXeQSKvbN5OBcdYWvbFsmR8KYvGa8T7CD/kt3Zq jIzfXIDKAbtcb3k4UDxYK5GEqZJyxnbj2ENzj2W5c17eZddk+IhCZucgRBJOIRylaSV936JQ1Fj 7c2hwkZaUUvlYGHd93mTejhR72Iy1uMN8AGUpEGN+HW9Psb+xbdU35ubAqt0ST3OzxPHwa7F4fH +3/TmaurkgTGoyAS4T1pT8tuFZkGDuScPd5eki6pKTvH0e7L1jYir8PVSl+WglXawe4gcAcDH9j K8+l8RXwCAlwnsSFVGmU5gownNwTYR75yoJyq0XuDLg4y8vjawzLE+m2294hiHg== X-Received: by 2002:a5d:5f85:0:b0:48e:20ed:27b1 with SMTP id ffacd0b85a97d-48e6e2625fcmr4697030f8f.0.1793359295061; Fri, 30 Oct 2026 04:21:35 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:20:57 +0100 Subject: [PATCH v2 4/9] libvhost-user: run handlers of started rings after the reply MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-4-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=timpambor@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359380394158500 When a ring is started, it may already hold requests: ones the driver queued while the back-end was away and ones the previous instance left in flight. libvhost-user handled them by writing to the kick fd it had just received, which only works when that fd is an eventfd. With pipes it is the read end, so the back-end was left relying on the front-end sending a kick after SET_VRING_KICK. Instead, flag the ring in vu_set_vring_kick_exec() and run the handler of every flagged ring at the end of vu_dispatch(), once the reply has gone out. This needs no writable fd and works the same with eventfds and pipes. Signed-off-by: Tim Pambor --- subprojects/libvhost-user/libvhost-user.c | 44 ++++++++++++++++++++++-----= ---- subprojects/libvhost-user/libvhost-user.h | 1 + 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index ece2bfcdd7..5f649a3d52 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1320,6 +1320,7 @@ vu_get_vring_base_exec(VuDev *dev, VhostUserMsg *vmsg) vmsg->size =3D sizeof(vmsg->payload.state); =20 dev->vq[index].started =3D false; + dev->vq[index].kick_pending =3D false; if (dev->iface->queue_set_started) { dev->iface->queue_set_started(dev, index, false); } @@ -1493,19 +1494,12 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vm= sg) vu_panic(dev, "Failed to check inflights for vq: %d\n", index); } =20 - /* Inject a kick to look for available vq buffers */ - if (dev->vq[index].kick_fd !=3D -1) { - int ret; - - do { - ret =3D eventfd_write(dev->vq[index].kick_fd, 1); - } while (ret !=3D 0 && errno =3D=3D EINTR); - - if (ret !=3D 0 && errno !=3D EAGAIN /* already readable */) { - vu_panic(dev, "Failed to inject kick during SET_VRING_KICK " - "on vq: %d with error: %m\n", index); - } - } + /* + * The ring may already hold requests: ones the driver queued while the + * back-end was away and ones the previous instance left in flight. Run + * the handler once the reply to this message has gone out. + */ + dev->vq[index].kick_pending =3D true; =20 return false; } @@ -2313,6 +2307,25 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) return false; } =20 +static void +vu_run_pending_handlers(VuDev *dev) +{ + unsigned int i; + + for (i =3D 0; i < dev->max_queues && !dev->broken; i++) { + VuVirtq *vq =3D &dev->vq[i]; + + /* Without a handler the request stays pending until one is set */ + if (!vq->kick_pending || !vq->handler) { + continue; + } + vq->kick_pending =3D false; + + DPRINT("Running handler for pending requests on vq: %u\n", i); + vq->handler(dev, i); + } +} + bool vu_dispatch(VuDev *dev) { @@ -2345,6 +2358,11 @@ vu_dispatch(VuDev *dev) =20 end: free(vmsg.data); + + if (success) { + vu_run_pending_handlers(dev); + } + return success; } =20 diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index a534d70771..aedb1da96d 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -392,6 +392,7 @@ typedef struct VuVirtq { int err_fd; unsigned int enable; bool started; + bool kick_pending; =20 /* Guest addresses of our ring */ struct vhost_vring_addr vra; --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359378; cv=none; d=zohomail.com; s=zohoarc; b=Kr+cltUl4OLnjQ8uM65JXy+VZHuvGVCq3fPqecAO+0TD7vWbfGU4Atvq185V3z2H5pZFCPJjgtP55D3UT+mpJylbgrnN9wqZQMua8rdFVwd7vjGVXQB0MlqXWRzt28t4dZz5Mr22q2V1nETdN1guA2dO7J9PyQt91QBPMz5nKbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359378; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CtFQfS3ZPQMOHEPZqYufRtBAPULATHXGwg5wUHbxOvE=; b=PzkncXgQZiOH23ESiN0fSHQy49lS1g31XYKkxky1FkFy3gM6HRiyAk4J3fjeFH6PHXN3wR87HqszYVYbrSjdmY+VoFiifZ71gJUwjtp24EvveCQsmkMSIo0ihrr6pbb1mONI7/JyFz81y8USGcE2yF2TaGbuhRISJ9kGa1wm0VQ= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359378324916.6719969929344; Fri, 30 Oct 2026 04:22:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkg4-0001OV-3a; Fri, 30 Oct 2026 07:21:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkfz-0001Mr-UA for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:39 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkfy-0002lz-9f for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:39 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-48e4831c028so584814f8f.0 for ; Fri, 30 Oct 2026 04:21:37 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359296; x=1793964096; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CtFQfS3ZPQMOHEPZqYufRtBAPULATHXGwg5wUHbxOvE=; b=ZpGgcVCaQv35s2rtRailCdSaz2g7IinJ7HZFfdg2QIwm6AHiPvXBV/kfl+Qeo6VA2h RZ05d7znfV0Kkx4S/nTCOPOiG7p2oRkwqVkinF1uU/e9Vc27jsWnglaPnym0es+nwMQF 8HOzCMkn7eIYIcTWkHrYEadLxYRyvOySck+08X0dxEjAedoft7qU/NtrlB57XgWCWOhS JEKFMzynXg0PwOuZcougLsaLTwIuv4G/xplCjFeaGrCezYAysOGqh03X0Fu965uDz1IX 4i3kGIhmxsdtcpdpCpvJG0Jy9u8uIiUHOptCkhnPGgOsEHZLhrJvxScPikCIsGBTKCx8 5xYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359296; x=1793964096; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CtFQfS3ZPQMOHEPZqYufRtBAPULATHXGwg5wUHbxOvE=; b=NRuhAD3HdCkLx6/CIZ2gponVMFnahia7Oy2fAy021uZWmM9DWR4ZFSfRHxmlJQUPS3 6Mtjbdhxwwv6UPpcNY7gz0ojsil1eq1A+Pgr4vdjrLHhbBLqHdQdeiYFjOMv4vBxpfR7 nKRBUbeJKgLvKFFkFeLB2mLBv1kCxfU8n1gk5psGE2lyGcrvFg5Jqkg4tItstl5wzMsO R0DisUaI2ahqtR5XXZUShzlmzVxZhAtG/Y+9/MWwtPoWjtMFuwcU3iFZOI3cbqkiWf9g V4uaw39lvdboo6lRq3ke2E3240TPK0ZNoBgbZONGb+elO3pCjHwZO87awAFogrGXIOwa K6cg== X-Gm-Message-State: AFq9FYKIwq8GfITMXCnJf2zLLavqzh/amUIeJP5W47bLF6Qqu61aKhOo WrkNvWHTAuVj9awG0afNVn91SFhlAwuPHRKXvF7er00AS+HxM9UYa4fD X-Gm-Gg: AYBFou1n/7c47i70TFbjwr19jmaNMk6xga69RVbTYndCFw/T+W5JzUIDaU5guG5Mu9u Q3SqmyOnfwF3z3I8bpmgtsT1sfQLZbkcPd+fbq5T+7rV+Wo4uwqjCxgfd7sR0o6ByiDf3lBlxcA 6MiKf1rkkSkiAjsTaNWN4vO6hkMXjd0fqK3851nBoOlycXPaIi8+6mnykXG4nK+BhlsX8nkchI7 FSNcMCwRwTwc5g22dX/pMhw7KyhMzrdd4rFg0B08OIAtCZZaxR9EdWwkAj+6WQArJAkE99y3GNK nu6QlGH6cX/xg4JLwWYhUj8iu/fSQ1wUncRloOpX+8PJ6socshc9oxlFOsc1JyN19/QdyhE0p/K wAihXLgm3siOWhsmcQm2Qnk3Ob5FP+4k4JkDg9iob4NU6NLd6VJ9i6Xw0gv5PbJATcNpGoUInZj cdA1M/cZryqOwfj5G7STuU2gjMJ+dvj4HAp5cb0Rv51KKo3EWxOBbvdKicUYMydsPWCN4eKAndb Utj1XKSZ+28rdwNuWKVSxlJTEPrZREQlderiIg1omcIIcjf/yV3aHlnbMQvsTCcm4ilBo6rKoVX ZcHZFSYNamzH63ZxpmL9B9VyM77l5g2cM/T7bkZ79Sr0zNhcGq1sVVccMbjkfzLiBxj81GK8XA2 cjqlB0rhBhTMcFUaVYgHDBJK29PP2CINPNNQOMZs7+klWcMgiynmM4uTzItZrkw== X-Received: by 2002:a05:6000:200e:b0:48c:466e:9d08 with SMTP id ffacd0b85a97d-48e6e50ab18mr4700925f8f.43.1793359296428; Fri, 30 Oct 2026 04:21:36 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:20:58 +0100 Subject: [PATCH v2 5/9] util/oslib-posix: implement qemu_set_blocking() with fcntl() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-5-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=timpambor@gmail.com; helo=mail-wr1-x433.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359380373158500 qemu_set_blocking() relies on g_unix_set_fd_nonblocking(), which always issues fcntl(F_SETFL) even if O_NONBLOCK already has the requested value. macOS rejects F_SETFL on POSIX shared memory descriptors. The socket channel treats this like a read error and disconnects. Those descriptors are passed in blocking mode anyway, so there is nothing to change on them. Query the flags with F_GETFL first and only issue F_SETFL when O_NONBLOCK is actually set. Signed-off-by: Tim Pambor --- util/oslib-posix.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index dc001da66d..3d5bb16ca6 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -252,17 +252,29 @@ void qemu_anon_ram_free(void *ptr, size_t size) =20 bool qemu_set_blocking(int fd, bool block, Error **errp) { - g_autoptr(GError) err =3D NULL; + int flags, new_flags; =20 - if (!g_unix_set_fd_nonblocking(fd, !block, &err)) { - error_setg_errno(errp, errno, - "Can't set file descriptor %d %s: %s", fd, - block ? "blocking" : "non-blocking", - err->message); - return false; + flags =3D fcntl(fd, F_GETFL); + if (flags < 0) { + goto fail; + } + + if (block) { + new_flags =3D flags & ~O_NONBLOCK; + } else { + new_flags =3D flags | O_NONBLOCK; + } + + if (new_flags !=3D flags && fcntl(fd, F_SETFL, new_flags) < 0) { + goto fail; } =20 return true; + +fail: + error_setg_errno(errp, errno, "Can't set file descriptor %d %s", fd, + block ? "blocking" : "non-blocking"); + return false; } =20 int socket_set_fast_reuse(int fd) --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359385; cv=none; d=zohomail.com; s=zohoarc; b=BJYjKOXcNAldclJEJqRrdeU4vytyyaTM4t+Yb1u4pWtdJpYK0/9R+SuhosiXrJ+9AxfXwYiijF7jrQsGZ7yMMLF1FB+oMt81bPaPGlXg6ULp7WSA0wCwy4rSm8KLvh8W/kAIhXCmiJG7irsonK+7GWrlB5DGRFo8aPfMuRHMW70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359385; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pcS+Jwk9ybuv9CPMRa2h0bU6xc+TDlXMtbvBgX/ZHzE=; b=DduYA8FvC1qT+TrTUNe3qcdUFisnuhhp0v2ba18vU4PNM+gLI6zwRHAgQWZMRCwa/9st4du9Yi0+iAxL0M/y3vGBvlD+Up6qEW9WIoMqAa7HT2839KTi7TatyEC80Q6JMmeAkWAMl17J2CvuRsWnT4m9jICaRDKN2Krr8l3pC5Y= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359385940666.6912795715965; Fri, 30 Oct 2026 04:23:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkgD-0001Rc-Ca; Fri, 30 Oct 2026 07:21:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkg1-0001Nm-Jc for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:42 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkfz-0002mP-93 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:41 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-48e46e449e8so368873f8f.3 for ; Fri, 30 Oct 2026 04:21:38 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359298; x=1793964098; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pcS+Jwk9ybuv9CPMRa2h0bU6xc+TDlXMtbvBgX/ZHzE=; b=B63epMw90NTSeAoW3SvGIVD9/7hJZ0zbgQdlu/Z1uW2zBOp2aHXK5+L/p+4xEVFx2X 3FUdc4VZdoCvHGJB1FwkChMFB4JlCSZD1ejKvqmv5oWK1gkIX4Q+fsnBMTXzu7qk/ZT7 MwhcYcTzuzMuWFCWO2eFJH1r/OChE1lLDcqBCJNo3iIM/tEb1egBcgz5Fho3JX3shOqx 7M6wFp0mVQFi2/QmmpDD98kaU/Rp6bcrVBWAJitz2pnjhy1y42ykKaWGCHIscahVpIAX QMhI+2wJDolsY4c9h0G/VoV3jaA0kalyFXIF9NdXoQgNuqoBIvecgQ0RdUH9XwTy0Q9R q+KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359298; x=1793964098; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pcS+Jwk9ybuv9CPMRa2h0bU6xc+TDlXMtbvBgX/ZHzE=; b=Y979pisrKmGjckcMAZUmF9M8Pyh2xBdgVeUzFTp3sj6myxQQdw0qwhVs51jXZfI3MS bl01rl6Rhnv0yPoTdRiTAo7/gjncAZ5/JHETJZjpWFaylpN9RKySCQ6ktH6p0KjketFU TUA5+++R9KIUwJV/j/9ORgH6UtS3m96B3WlrLj7sJJ557TViY7ukf9J4tOedEAKtwkPf MWY/haHNAq5EBwBw/osnHkx0zps4P2A5Apoby0b3Ohs5RgmmXWXjohVzAfy+bMQ9Fq3C CdcCUjBJnNgEKOGLdz35zjpaelcJmaRqp71uEyjA8yl4WI1p5spGMsTAqGI9INptDUqb HGyA== X-Gm-Message-State: AFq9FYK1SfkeRFmf+EevVhzClcRu30k9GVqR8ftOFrEQKsjyrao9nw8m jlm4e+EiKVFpNIAfzQFu5IJ/ldj2kvv3aUCp9B5/qZdxKxlMKG9PoF866G/WnpsU X-Gm-Gg: AYBFou38+Yi6Tvwf81+PXczp5icyD5aqHsRQ5uJApmXTRppu7H4PdjF6dEf5R4Bg7W8 kRUTw8AOZ+TkZmgBvoy7Agow2t01fJKCKI5cEW1DB0pzu9xPPm0Jgtl0w21Re20Aajaq5MpeNmn 4pORHxbhX+WzlFpg8RSzcJZQ0rpN7Xe/M2cLcCA0/TpfioQSMoYsdxvO4KfpQH1JXjerddKVhQL JBE8mGOcEBojQV0odQOCED4uvd+ZqcPoeBHRLBEz8bh+1TijxCj4ZPq9DicMMZHmsisnOWvWZwp pI/aLEFZquAZRqZeZIbNcHXBZFC9/eyQsiRYBXI98vWug0e5ynfN+1flukSyzAE2bGbrdshR5w/ 6OtmK2Qj6wiPe3eisifCZuPFrUflJl2aVOVPfw5tv4KIa6YQTq4A/2rP9wez3QYjsfGjPILg/oC nSwp6UbNIdPGXehj1jGZKFGps57HBN5jnnCG9m3H8nOWXffNZp0Z4rLjZDQ6epcEDLMOm55iDPr SErBLEp3TP+eEX5SGKurF9q2i81EwnMEIqd2reuNRo10B+LwAf1zTVcl9A8oDDSOOiKlyVWVJZQ eOXpcwHba0Hk2LLaFV9gVMHGVHiBY6WKuZoIFYSX3C3hRpb7JEbdZyY194rQcFbkNvArDLmjMNV py5PifML/DI3olhka0CNUdc9GvhMnmnr4Vq+dP98jXsrmRgss6JYPTBBXKhzZRO3vrRayx8QCD8 Ch3xFVpWw= X-Received: by 2002:a05:6000:29d1:b0:48e:37dc:7ff8 with SMTP id ffacd0b85a97d-48e6e5008bfmr2729956f8f.22.1793359297651; Fri, 30 Oct 2026 04:21:37 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:20:59 +0100 Subject: [PATCH v2 6/9] chardev/char-socket: detect peer close portably MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-6-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=timpambor@gmail.com; helo=mail-wr1-x436.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359387354154100 A hang-up watch for G_IO_HUP alone is not a portable disconnect detector. Linux wakes such a poll() when the peer closes, but FreeBSD registers a wakeup only for read/write interest and macOS drops its one-shot read filter on any non-EOF event, so as long as nobody polls the socket for readability the hang-up is not noticed until something unrelated wakes the main loop. Frontends that never read from the chardev, such as vhost-user, are the ones without a G_IO_IN watch, and that is what makes the vhost-user/reconnect qtest fail under load on FreeBSD with "wait_for_fds: assertion failed: (s->fds_num)". While the frontend has no read handler at all, also ask for G_IO_IN on the hang-up watch and treat EOF as a hang-up. Signed-off-by: Tim Pambor --- chardev/char-socket.c | 78 ++++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 81bac42a15..62e8871c51 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -36,11 +36,14 @@ #include "trace.h" =20 #include "chardev/char-io.h" +#include "chardev/char-fe.h" #include "chardev/char-socket.h" =20 static gboolean socket_reconnect_timeout(gpointer opaque); static void tcp_chr_telnet_init(Chardev *chr); static char *qemu_chr_compute_filename(SocketChardev *s); +static gboolean tcp_chr_hup(QIOChannel *channel, GIOCondition cond, + void *opaque); =20 static void tcp_chr_change_state(SocketChardev *s, TCPChardevState state) { @@ -345,6 +348,33 @@ static void remove_hup_source(SocketChardev *s) } } =20 +static void add_hup_source(SocketChardev *s, GIOCondition cond) +{ + Chardev *chr =3D CHARDEV(s); + + remove_hup_source(s); + s->hup_source =3D qio_channel_create_watch(s->ioc, cond); + /* + * poll() is liable to return POLLHUP even when there is + * still incoming data available to read on the FD. If + * we have the hup_source at the same priority as the + * main io_add_watch_poll GSource, then we might end up + * processing the POLLHUP event first, closing the FD, + * and as a result silently discard data we should have + * read. + * + * By setting the hup_source to G_PRIORITY_DEFAULT + 1, + * we ensure that io_add_watch_poll GSource will always + * be dispatched first, thus guaranteeing we will be + * able to process all incoming data before closing the + * FD + */ + g_source_set_priority(s->hup_source, G_PRIORITY_DEFAULT + 1); + g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup, + chr, NULL); + g_source_attach(s->hup_source, chr->gcontext); +} + static void char_socket_yank_iochannel(void *opaque) { QIOChannel *ioc =3D QIO_CHANNEL(opaque); @@ -520,6 +550,30 @@ static gboolean tcp_chr_hup(QIOChannel *channel, void *opaque) { Chardev *chr =3D CHARDEV(opaque); + SocketChardev *s =3D SOCKET_CHARDEV(opaque); + + if (!(cond & G_IO_HUP)) { + /* Readable while nobody reads: only EOF counts as a hang-up. */ + int flags =3D MSG_PEEK; + ssize_t n; + char c; + +#ifdef MSG_DONTWAIT + flags |=3D MSG_DONTWAIT; +#endif + + n =3D recv(s->sioc->fd, &c, 1, flags); + + if (n < 0 && (errno =3D=3D EAGAIN || errno =3D=3D EINTR)) { + return G_SOURCE_CONTINUE; + } + + if (n > 0) { + /* Data nobody will read: stop watching for it, or we spin. */ + add_hup_source(s, G_IO_HUP); + return G_SOURCE_REMOVE; + } + } trace_chr_socket_hangup(chr, chr->label); tcp_chr_disconnect(chr); return G_SOURCE_REMOVE; @@ -611,27 +665,13 @@ static void update_ioc_handlers(SocketChardev *s) tcp_chr_read, chr, chr->gcontext); =20 - remove_hup_source(s); - s->hup_source =3D qio_channel_create_watch(s->ioc, G_IO_HUP); /* - * poll() is liable to return POLLHUP even when there is - * still incoming data available to read on the FD. If - * we have the hup_source at the same priority as the - * main io_add_watch_poll GSource, then we might end up - * processing the POLLHUP event first, closing the FD, - * and as a result silently discard data we should have - * read. - * - * By setting the hup_source to G_PRIORITY_DEFAULT + 1, - * we ensure that io_add_watch_poll GSource will always - * be dispatched first, thus guaranteeing we will be - * able to process all incoming data before closing the - * FD + * A G_IO_HUP-only poll() is not woken by a peer close on FreeBSD + * nor reliably on macOS. Therefore, while nobody reads, ask for + * G_IO_IN too and let tcp_chr_hup tell EOF from data. */ - g_source_set_priority(s->hup_source, G_PRIORITY_DEFAULT + 1); - g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup, - chr, NULL); - g_source_attach(s->hup_source, chr->gcontext); + add_hup_source(s, G_IO_HUP | + (chr->fe && chr->fe->chr_can_read ? 0 : G_IO_IN)); } =20 static void tcp_chr_connect(void *opaque) --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359386; cv=none; d=zohomail.com; s=zohoarc; b=USSJwGHw3FM1oqpj2ABguGN3JynuJFVQOkhmEvCEjtBdkgaOo0slqx/aAmcIwnnP3tZohxxIuU8Qeno3P6KsAs9d/P6k/I51KbTwxkPUPJG1+ID60P/G6BwmCuRKY+dKb3xMUcJ89Bofr3PONmAI7yD/sbxSGe3F7uYAGxYBAeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359386; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wATYT6BvjZcVXWDHqPLOg+g6BseY/5lYU9MCydp+P3g=; b=PuHKLrOrxZXMPBy8QSbBfDlcCLu5ZUd+LYO8A0Joj73ykfJ2w09HrvlHGf6HmlNzpqMu0N0aDVYySl9lsFgMIrrtmoTgzTfT9PY7fA1cJ7ngZaVqvjLOt++yTDRLz19k7ZXR5cHkUfyHjJocH4StbCJuSzEDSc070yakfgM271A= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359386970124.80819138950164; Fri, 30 Oct 2026 04:23:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkgD-0001Rf-D5; Fri, 30 Oct 2026 07:21:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkg2-0001O0-Se for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:43 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkg0-0002mf-RR for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:42 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-48df4f540ebso278118f8f.3 for ; Fri, 30 Oct 2026 04:21:40 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359299; x=1793964099; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wATYT6BvjZcVXWDHqPLOg+g6BseY/5lYU9MCydp+P3g=; b=ljWCKYkhXyFwN7A9knIjItNdZC/0Ob1JSJaVxC/V71qcfDvkS1cfe3G/7pxFnLtEtb RHeS8MIUljdF7cnxwdmuzcWKSO5qBMHcmJCgWok0sagMDGNSykjPOz1kebyzv7vKnjfR IjbLmfpW+iQaQH+URhR56N46z3+LRPKNd9dYeiEAjFpnZJYP0OuWRUFTwgTtZdHeAY5C mPyaMhyMwvr2+gpyXBzKVP0H8fx3UTJPhP3dsRk8eDnTlTTexkGfs/+lIjZ8hDxPmI7U F9fqUJwyU65Fc4T5QSFY5xo1P8/Rq4TvWuNcCnPOtsVLtijN+rr/Ti6D/vAM+375UlvM 4BQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359299; x=1793964099; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=wATYT6BvjZcVXWDHqPLOg+g6BseY/5lYU9MCydp+P3g=; b=eMyebkEHnD8Dlz03tKpTyLK/AzaRwM+k0xb9CnASgDBCvEWxY/9vHP07eDvrIyE67w XrRsQNSOmRbB7bo80bqE7Yg5Fkwp7nZUnSEUZtdRPzJ+T77u5P8C/bF6D4JxxawEKR/m ZpLBfbtBjdjTEkjICdYzoQN//D1gZZB38tg1E0tAihR+CwjPSHHwj++awwXDfOE57A8x fW4+OGurzKXM9aHW1KgsUbsA1u3R9d9RqHyGJiSuPtvc7LFiticPg+iZHIZlye1dChLb TpNxL25cSvlzVrnc26XPDwQX6lb5GDhZoY3SJTSQ9IhzN9HERvC9HQ2gF5r3xXOwn0iT oXwA== X-Gm-Message-State: AFq9FYJvZWMywse9HDjCQyY1ILVN1uXlcEcKtH40000bAUZq1AgyoyAV iLcDkce5AIWekfJ7CUv04VigyDlzjNxPzW15w5CN2YcHpj8zds6zx5O9 X-Gm-Gg: AYBFou2vfZrI9n/Tq0rCCy2WKBOZlQUX5XpU0jSt3pc0RB2JSQKw9cKBwqGoZyTnAKJ i4gTXOCeJyl2t37Bke0CpD9bk8bFRPBJyCUDnBXSkPQ1+e6H36m3RKnq/bmeOYYPuz7Fztvjoib PXF3h2PPuvWtTet3VSjYic0dOR7H0VmKBml+daNgoNoYRQ1ZWpXjxy0AMDbdd95huh2nJXIgKP3 eZEXO0DoM9IW4AZViZC56f50PMVc40aKeTl8yezJNpOLs7uPAic7QYsKAz51otlqXWWXWu/XCVY 74OtS+uqs01FokDgyMObjKPuvWCrqzwA9reS68C5RgRjRhRV5lHL1vL4ohF5f63Vc7xLe2agjzr K2b+06Xg54f9dqE23gLtmqVHnXxwjuO1WiDAa8AZYLmuFNtgJYFChrPy3WRxlb5dWCEVESIf2yF wd+Hb2XPjH5aN/F9D6z7C8tvPQG+XjIyDijA2RVWBzZYkIQzZXHKYeg4ExQ2deYPICoZ1Ub8zvH 610GotgpGLV9zdYII4QAAKYKc+A/XT/pJirIUIkPryYMKW4ZWpVYstcsfxiuxegmDTfZIphxLuA PK20pCPZa2i9O57XUy0uopFZhuDi5c3QIe3Df2dgijCXj2kv3lnJR7FtSXwe+eoQ8Hxj+FPj4tn 7S15JuGgbc+PXugdcXijy33UB4lNlvX+uRc2nSRsdaDONtAKtBOsXlqz6LFWYP/CLk48/9bMFrq IpxhTAn7o= X-Received: by 2002:a05:6000:d8c:b0:48e:1c72:abc with SMTP id ffacd0b85a97d-48e6e5066a2mr3651079f8f.35.1793359298840; Fri, 30 Oct 2026 04:21:38 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:21:00 +0100 Subject: [PATCH v2 7/9] vhost-user: enable frontends on any POSIX system MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-7-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=timpambor@gmail.com; helo=mail-wr1-x435.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359388953154100 The vhost-user protocol is not really Linux-specific so let's enable vhost-user frontends for any POSIX system. vhost_net.c uses VHOST_FILE_UNBIND, which is defined in a Linux specific header. The kernel's VHOST_NET_SET_BACKEND documentation asks to pass fd -1 to unbind, so replace the macro with -1 and drop the include, nothing else in the file needs it. Long-term a constant could be introduced and used for it. Co-authored-by: Stefano Garzarella Signed-off-by: Tim Pambor Reviewed-by: Stefan Hajnoczi --- Changes in v2: - Replaced VHOST_FILE_UNBIND with -1 and dropped the include --- hw/block/Kconfig | 2 +- hw/net/vhost_net.c | 3 +-- meson.build | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 737dbcdb3e..7edcd7a8f6 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -28,7 +28,7 @@ config VHOST_USER_BLK bool # Only PCI devices are provided for now default y if VIRTIO_PCI - depends on VIRTIO && VHOST_USER && LINUX + depends on VIRTIO && VHOST_USER =20 config SWIM bool diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6e05c995f1..d0f1014ce1 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -33,7 +33,6 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" -#include "linux-headers/linux/vhost.h" =20 void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) { @@ -681,7 +680,7 @@ err_start: error_report("Error when restarting the queue."); =20 if (net->nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { - file.fd =3D VHOST_FILE_UNBIND; + file.fd =3D -1; file.index =3D idx; int ret =3D vhost_net_set_backend(&net->dev, &file); assert(ret >=3D 0); diff --git a/meson.build b/meson.build index b67a97ab45..eb296346a8 100644 --- a/meson.build +++ b/meson.build @@ -221,7 +221,6 @@ have_tpm =3D get_option('tpm') \ =20 # vhost have_vhost_user =3D get_option('vhost_user') \ - .disable_auto_if(host_os !=3D 'linux') \ .require(host_os !=3D 'windows', error_message: 'vhost-user is not available on Windows').allowe= d() have_vhost_vdpa =3D get_option('vhost_vdpa') \ --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359371; cv=none; d=zohomail.com; s=zohoarc; b=P8E4ie3UfMg9h8skwjJUBBQQ+RrktbKiJ0xwsm0Whr8hqTnrWw9zq2nlHkTDJqJkyzu/wYnVwm4fI7vrpSXtg8KU0b/u4GIRWaW2kS2APfl6mDPJ401GDV8cMVJWs/kgoJqEsPyLYDCsmksQuVD3e1cbRSD0HD/B2NJibQ8263Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359371; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NQyHj/7isbZq1anOngku43wTHeR8eA80fkM1Z6NDWCo=; b=b/9BCesiAqg9hZmgy0PBv24OfnxhkCXpHrIHhZp9qOQi0tmOpcMy1mQe6m9ACiy1BaonFt6ptXvgGFz7t82vsMtWPTMGZ0AdjRboB5oE6XNdsC0aaM2gWrD6ZGkGhset+HyU1cwa7DtYHGBXOpS5FT895lOcCpyoGYj4UTBiRmQ= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359371186109.45496643729098; Fri, 30 Oct 2026 04:22:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkgG-0001Up-RT; Fri, 30 Oct 2026 07:21:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkg3-0001OM-SU for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:43 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkg1-0002mw-Q6 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:43 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-48e00eee27dso315541f8f.0 for ; Fri, 30 Oct 2026 04:21:41 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359300; x=1793964100; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NQyHj/7isbZq1anOngku43wTHeR8eA80fkM1Z6NDWCo=; b=zURiqgz3n6a+0WA9DLO/Wu0m2LYKWtGr99O/WjKDYKtFAkY1W9ukEK4GD8H/LR6Sau DBYoIZq7dhPr3OjI/7e3dZIGL7TZV3iNd8IMlNHJyzQgfiyTAnratFnmIdmUf8ZFw9Qf BCfwW86WiFlLcdlo0rewmLBYmnP29UgIhEUH2/N86UgZxmya/8tr+RKiWuRo0dqlKnFI HK8F4TCFbbOFClMMp4qrS21U4cwDEQmlIDcKKJLD6IvWK7RsOcb9n6GDVLxJRaj0XSmn ge9ARApeplouQE8JnfuporPtaF1XK/WqAWQbQR9m8ko9T+hxrlikGEXlVl+Z3p/sTbX0 AKIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359300; x=1793964100; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NQyHj/7isbZq1anOngku43wTHeR8eA80fkM1Z6NDWCo=; b=itr3Wx3Wam0aXXM1X5UfPgzry43cGkadM2ODgnOxeX7jDaT4IUWNdLD1YR/bQQCUKG ir1CvJngBXhOht8B+7hsp0jbWWFfkCpwPBHmw2A0mz2QJegVsfLROW+ekRB+QV7FyqXg cJ9l64nTi6AO+ll3cwPbYeaLGPUj+/WAZ8gidrU+YrhmX4vrmYzq/s2e1h7z4sjNeIp/ Tj5NOzsEkNbH2QVMZi+ZUVgfp9oBELlf5gdwswtYAlZqU65pz4FQCBPVeJ3aUSdAdzm0 I1U+xNfNxuAAqlI1rMYAp0aNf5t8dc5+NR3q4+NbWekMpF1MfOyRm9VLxHr7EIRzD7Mq 2gBQ== X-Gm-Message-State: AFq9FYKOe4HfnnttNUiCmUen17NL5X55dpGmqZZVoJyO+xesAhGrwO4T VOsI4V82pUH6uL54G++QV017ygZysN+5xwPhT11mawFYJBSvD2J8+rO7 X-Gm-Gg: AYBFou3zkLV37hb828l9GBNb/KIAQgRyAq4XS/tPSqnSY0Q5lfwzbryX1Ynfq+QU6Db q5yEwA+VCBz14lgtQjdHydiktp+jC/IRpNelABTa0pSS0DsHd7Aq/cP/QD7AVtGdAXtltTR12Lg mznVvlTKY/KRbeKgvo1EOT020lsSCgvtZY5GNH/oE3t+RajsLyjWj/6ETe3knQy/IoGKLncorTp dC6riXZTg6yTj7L4bP44ueeJvzNZ2hHAsPpDmZB8OlEyS0DuQvXF9BrbvFkkQTdei319Iplgmy0 hGjpL4blZPS22GyRUpLJrRcXmbiWWJsSDqPcT8mt6BR0PEPKAtIhOUtQ3WMCDcr4I5hHiS0X8hM Q6JhcsIprzAau4VrsEhiBUbn6V7f2F3lWamIsuCmTfJbON9RniTfCJFFZBTv4i2Wd1gYMep23Ep LjX8UCHKTmsBoYYA7xvtEyR6wLAXyyf0tFqSxW+GB65Ot7YjuhVN4V9oXkYI2sE02PpVLUu3C3J k1915y/+spWi4Rontrl6eti/RKgrM3GJVBD5SbHCJvkgrrGJkIssnneQKcZH35B8C35oQU8LQk/ FRS6D+99U1NlTtKdGodXfmfpEdtKDIGyLtivIT33rzQ8HptHi6Wto8Dx05ef1Wxw5p2+IB62BU/ Je7Bn1ct6ijAEV2PNoHChy6v+10b1IBTh/K4b8n9yjmkbSahvnxBWJySFnq1aWnRZz5gguWNIk4 DFsc+vnpA= X-Received: by 2002:a05:6000:40ca:b0:48c:5304:5e50 with SMTP id ffacd0b85a97d-48e6e2620d8mr5235192f8f.0.1793359300014; Fri, 30 Oct 2026 04:21:40 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:21:01 +0100 Subject: [PATCH v2 8/9] libvhost-user: enable it on any POSIX system MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-8-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=timpambor@gmail.com; helo=mail-wr1-x42c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359372518158500 From: Stefano Garzarella The vhost-user protocol is not really Linux-specific so let's enable libvhost-user for any POSIX system. Compiling it on macOS and FreeBSD some problems came up: - avoid to include linux/vhost.h which is available only on Linux (vhost_types.h contains many of the things we need) - macOS doesn't provide sys/endian.h, so let's define them (note: libvhost-user doesn't include QEMU's headers, so we can't use use "qemu/bswap.h") - copy SEAL defines from include/qemu/memfd.h to make the code works on FreeBSD where MFD_ALLOW_SEALING is defined - define MAP_NORESERVE if it's not defined (e.g. on FreeBSD) Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Signed-off-by: Tim Pambor --- meson.build | 2 +- subprojects/libvhost-user/libvhost-user.c | 42 +++++++++++++++++++++++++++= +++- subprojects/libvhost-user/libvhost-user.h | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index eb296346a8..4f4068e7a7 100644 --- a/meson.build +++ b/meson.build @@ -3468,7 +3468,7 @@ if have_system and vfio_user_server_allowed endif =20 vhost_user =3D not_found -if host_os =3D=3D 'linux' and have_vhost_user +if have_vhost_user libvhost_user =3D subproject('libvhost-user') vhost_user =3D libvhost_user.get_variable('vhost_user_dep') endif diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 5f649a3d52..7c5b89dc0b 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -29,7 +29,6 @@ #include #include #include -#include =20 /* Necessary to provide VIRTIO_F_VERSION_1 on system * with older linux headers. Must appear before @@ -38,6 +37,7 @@ #include "standard-headers/linux/virtio_config.h" =20 #if defined(__linux__) +#include #include #include #include @@ -51,6 +51,24 @@ =20 #endif =20 +#if defined(__APPLE__) && (__MACH__) +#include +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#endif + #ifdef CONFIG_EVENTFD #include #else @@ -67,6 +85,28 @@ int eventfd_read(int fd, eventfd_t *value) } #endif =20 +#ifdef CONFIG_MEMFD +#include + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#endif +#endif + +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif + #include "include/atomic.h" =20 #include "libvhost-user.h" diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index aedb1da96d..a2f0add832 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -18,9 +18,9 @@ #include #include #include -#include #include #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/vhost_types.h" =20 /* Based on qemu/hw/virtio/vhost-user.c */ #define VHOST_USER_F_PROTOCOL_FEATURES 30 --=20 2.55.0 From nobody Mon Nov 23 04:26:23 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793359368; cv=none; d=zohomail.com; s=zohoarc; b=JARv8hZtimFIBUMwPuVSfgQvW5N1qbPW11dpC3ru3BF8dFESKyzxGzyJwzJ4DNZPnxt8CHXsUujOtCUfTS2InoeqLnl8dgaKCXZYrWzL1iAUbi0bikEG9+R70ggmRGpHp4h6NoS2BZ78JjDtxyLI1Iei2aCnnv563ydVLzgyOEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793359368; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6GoihID3NL4nc1Mkmoc/1/qZ8Kz/J2UXjW1hpXDbIGU=; b=GmRxfHGbPMkt38FGNrVrDpSYDKBXi+h6FV0djshWysYyULpWRt8PzZ8nbd0Rnr3QvRmv+1/H0RNiVnBLf3GSkw+DhWAVW4oW4t01UEO8W3p7NRBYfGmINhM7TO+LK6BYiRiQBD24fT9mA32w3GMYKB0O+TjjOxlg6eqLE7BaBd8= 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) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793359368764993.9626215463217; Fri, 30 Oct 2026 04:22:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMkgF-0001Tl-OY; Fri, 30 Oct 2026 07:21:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMkg5-0001PU-26 for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:45 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xMkg2-0002nI-PI for qemu-devel@nongnu.org; Fri, 30 Oct 2026 07:21:44 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-48c4d870d54so346835f8f.2 for ; Fri, 30 Oct 2026 04:21:42 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-61d8-3600-98fd-cd98-7ae6-cb49.310.pool.telefonica.de. [2a02:3100:61d8:3600:98fd:cd98:7ae6:cb49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71a4d3e9sm2893608f8f.6.2026.10.30.04.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2026 04:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793359301; x=1793964101; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6GoihID3NL4nc1Mkmoc/1/qZ8Kz/J2UXjW1hpXDbIGU=; b=D0MJWIi0Z2wZDBeY5srXrQJQi/yC+75hbGjcsz+i8eI6i2tbVflHSjuP6jG9xgT0Tb RmldrRFFcFT5RudSjzK7D3ZmiA7/9Z1M3LkMNrvf/kz2tHqjawQtiniHeBcLWkXX1FWp uaFgqfo3dG+VxpRX6MFKQibiJi+spHncT4aXILL23l21WPoZAB8lhPgvwwk2oQMKA43M ujLXUD/srnbvqBWl1bGY/sviR4E/gM073BHVxake2diJ7HXRAoQ1pMhbvkY9MBqQIZq/ Eteu+GFu270MX1THBb8SysTCdTi9/pxA9D6SrNvEHjauLtg5x97Ast1JXSx74eedCIpO BczQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793359301; x=1793964101; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6GoihID3NL4nc1Mkmoc/1/qZ8Kz/J2UXjW1hpXDbIGU=; b=INKLxqoC/9B0+qLQikv3ZXSLSr0Ux+tAAes2yRgBCaHdX6lj8zLatLxbwYNJ9otkkE bniquqaweysFC4jYnl/PS96DW7kkEfwSP/jMO3uY2f7oFmEJWSgg9A2Inlq97BT5igM0 1TYcEZjqw/xBPpOms8AZ9UJN0N9XY0gSHLarkwORObf54x9Pn07vhi77VZMkXNmzjLeI pZDc1rxpT79SlMZJriA0/UyXEmCuZlU15TUxGZ80OlThKJ+47R2cI55J/4uwsCt+vtWy RSFJC50JIdshv3KqK4GT28xSXg1TAmztdpaRSjPRXa69/R5rHDbkI2J0VpaLfqFc1TFZ /jlg== X-Gm-Message-State: AFq9FYJRwIMIfQK9iljaRaaYJFFzIhFYVFgqMq0BNUITWlh9OjMUFgq7 H9RpWMk8aLJdq6K9bivJzJ/5SJ7heptYgJtn63VlazKmy0U7AdCtVs3V X-Gm-Gg: AYBFou1xBen3aYzA8hhpGzdjnsoAZfFs8K3+Rbw7eklHvPc6kxCJkEUYETU6jAjxrDe ZnSg4ueKHu35qKf/1Hn9Oixeo1POILXze4Ndyp0VihYbbiSw+J6UlWhN5KteiV8WpysB65eWCAm KpZ6rG/zPB8KGmfa5hvYjy2Xa7ToCERL6MdxhXwonpzRERI7yUoKGa5nrD5xsZvLUaJaFKjG/aJ 4gMOr6PioGuFUbHCNrm4tSASRCE+gzsD8zkHX+AijZonx8IpWwEulPDf8KoaK0mtDuF0BYet8Cu Hx8DmrrqcibqUDnVREc3kbVKFTwcZ1vLiZ7k6APgl9uPDt8h2QzPdz3hEr17Ko0K4mhqluEYaQb m+q3Zys4XpCpmTphlmeNDwCi3sI+1ee39deNeNEp7SeJUZ9QvFShn7g0Z+SbGc34y/O0MYGZT+T FA3STGrRiBuixxv1st7/U5vVXGxNZL2uv+crNPJS/JRUl7T1pt9ImA6rcGeZpcw4rSYHtwJ6sbq NWNAm7GOYf8m63IfEs9a123bKtwKnc+awi2B7UiCHO1DmzqJgZK3qshHpL5MBRWAtjLxjRVRWO5 FWmmE525PC1GXk5UAexV4ihBMo6GHW9XidS0cMdjlhjuj8kvZk4S/eGUh7KzT0sIPRzq1TDht71 JSX0IDmE860yvao9HbCXeS2CvEkm2xs7Sid0m39xyot3Xz/cvTGXV2/W4kH3eWg== X-Received: by 2002:a05:6000:2f84:b0:48e:e98:8b64 with SMTP id ffacd0b85a97d-48e6e2eb232mr4479528f8f.19.1793359301149; Fri, 30 Oct 2026 04:21:41 -0700 (PDT) From: Tim Pambor Date: Fri, 30 Oct 2026 12:21:02 +0100 Subject: [PATCH v2 9/9] contrib/vhost-user-blk: enable it on any POSIX system MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261030-vhost-user-posix-v2-9-cda7c17aad13@gmail.com> References: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> In-Reply-To: <20261030-vhost-user-posix-v2-0-cda7c17aad13@gmail.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefano Garzarella , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini , Kevin Wolf , Hanna Reitz , Jason Wang , Pierrick Bouvier , qemu-block@nongnu.org, Raphael Norwitz , Brad Smith , vhost-user@lists.linux.dev, Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Mailer: b4 0.16.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=timpambor@gmail.com; helo=mail-wr1-x434.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793359371049154100 From: Stefano Garzarella Let's make the code more portable by adding defines from block/file-posix.c to support O_DIRECT in other systems (e.g. macOS). vhost-user-server.c is a dependency, let's enable it for any POSIX system. Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella Signed-off-by: Tim Pambor --- contrib/vhost-user-blk/vhost-user-blk.c | 14 ++++++++++++++ meson.build | 2 -- util/meson.build | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index 6cc18a1c04..419ad2a10d 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -25,6 +25,20 @@ #include #endif =20 +/* OS X does not have O_DSYNC */ +#ifndef O_DSYNC +#ifdef O_SYNC +#define O_DSYNC O_SYNC +#elif defined(O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +#endif + +/* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ +#ifndef O_DIRECT +#define O_DIRECT O_DSYNC +#endif + enum { VHOST_USER_BLK_MAX_QUEUES =3D 8, }; diff --git a/meson.build b/meson.build index 4f4068e7a7..1250d467a0 100644 --- a/meson.build +++ b/meson.build @@ -2177,8 +2177,6 @@ osdep_prefix =3D ''' ''' =20 have_vhost_user_blk_server =3D get_option('vhost_user_blk_server') \ - .require(host_os =3D=3D 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user suppo= rt') \ .disable_auto_if(not have_tools and not have_system) \ diff --git a/util/meson.build b/util/meson.build index fa174c07a5..54ca587362 100644 --- a/util/meson.build +++ b/util/meson.build @@ -105,10 +105,12 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif if host_os =3D=3D 'linux' - util_ss.add(files('vhost-user-server.c'), vhost_user) util_ss.add(files('vfio-helpers.c')) util_ss.add(files('chardev_open.c')) endif + if host_os !=3D 'windows' + util_ss.add(files('vhost-user-server.c'), vhost_user) + endif util_ss.add(files('yank.c')) endif =20 --=20 2.55.0