From nobody Fri Oct 23 20:50:56 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=1792676924; cv=none; d=zohomail.com; s=zohoarc; b=Jdw/a1mKRi0mDegpPv6v6Jo/uEHkjWO2FbSkkzrNgfFlcNskjI/9fliScB6Wv8h3ZTExRLAV7cDnxIqkuBfeNUOWcUoUKw2JAmimsXOF9tpyZBYGoigauQMtO1/dwy088nbR9ALfunpeYvbNFK6aBzqGg9veo7/WxT0vQY7APVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792676924; 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=X1CKsFpWJu90qMtUVt/4L+rQag9fOlCL2flGbbnU4Og=; b=ZkWZONIgO2gGFLpfAmRovJO2N3IyGw/DMke+OpEdmfkYoDwnoK7EIqUFlaJKxG4E9hOuEOEDJE8v33SQH8XiY1iYXQZlwhVI4SSmCqMxQ9GuTo9rzVX1amMf4qxkWwRHqBKjp2Xa2GNc4rKBS+LoP/vPxzsNG4uKrm+NqlZehpk= 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 1792676924618495.86940918417383; Thu, 22 Oct 2026 06:48:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJt9e-0000gp-Gh; Thu, 22 Oct 2026 09:48:26 -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 1xJt9L-0000Ob-Sp for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:12 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xJt9H-00056F-8B for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:06 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-48c4d99c32bso1414103f8f.1 for ; Thu, 22 Oct 2026 06:48:01 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676880; x=1793281680; 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=X1CKsFpWJu90qMtUVt/4L+rQag9fOlCL2flGbbnU4Og=; b=RtBUsdOAmmIObVlhfTgfMzQAlil+ai57J+iwRevMqIetmcYkt+VYFlFD/IfoenLXyk WJW1qAY76DKw3ys1VMAM47oWgra2AFMCuJC+OhqC290YHtvfi3PhB2abRwCZ7VDJBQRh s+K6fk1JQlkNjdHnjYSPpUHyfpev3cohZhQlodNDczb8eK9AJ1KXc/A6oVWzo1QVbN86 bs5lgkLd3tv6Tfovmt9PeuWyeEyOV9QptprJEfF6kHPhRBOB2NBkZD4+hyeGFuKlMHdF 5mxoi2Q4/gQaerR6guuvMsDFT2OGerV9E6iASFeT3KG4skNMp6NbKyP9dOPsYrwTDVTC 6t9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676880; x=1793281680; 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=X1CKsFpWJu90qMtUVt/4L+rQag9fOlCL2flGbbnU4Og=; b=S5/fitKqHHgqwEvUVKuVyRQH84Fo4prqD0KU0wILeDuvOzqQ+vIwFpQfS4Fhk56jIz 8Os3xUhfPODkkMyG9HrJ+bX6pZWzAj+wggmxX833CQF0KuNERi2c/ZQ7kQO39ZpwUNB0 0eT2kfgX9ZqCm90bRAtiAX0XaPscpQVLAYVQ5MTdSI+bj/30LQtIb62RvCDeyjwgNiov bv+KhxDiaWfT9RRM0XJLRyyZL+4JjEi+EVng8orunexbRq3p8arQnvLPNVSOQB9009qj pUJDzJZd6Bn9cC1r6/KVaYxH3hdMEaJs8s2lJBrTlZ4hk4jUV6zRy+/jRzZS1xBtKm79 5X2A== X-Gm-Message-State: AFq9FYITuttiz6tSJiXqzXpBHGYvDUAbcstsUH1A9oMCX/AR2l2OEQ5Q zxq2AlxwdVOjSvD71Q0es+fWX/ET3YM6Tv/E1bYRs5hcSoN6gR3Ee+YJ X-Gm-Gg: AYBFou0x8xYM40DnaCtLLQWLABB2Pni3OKHPSTgsyS9zVWXOsxzWJtuYhhNx0UaUzDT +RtJCydgZ2pGPNKBvfWu4u+kM4aVhfG/iSnKy8EgDx8fKhef0dg2hyVYfxZvBxYLFoszfaebkwU rDiyz7v0IaYAZAoMgDs4bWUD/l5iV0lAwUbrYL9dbbmZ6Ceg3ueQ2pmVhg1r30r8FdypfChmYfV Uei/TqeWG8ZjeDqd6xtHdTaQzycxk4k4Fs/sO1mTuqY+p9CC2VysOg0AFAkBnMwTQCzI0a/hO0G aa1sUVi1X7T8XuXCjnTtUWtuN01imNO9paor2hNniwRYk6GOctukISByAKyey17OkOPjmLgY+/P j3dsNkfxBVMNMriWvF5lJEJw4NJb/aV/I6XRVKe+roBQrTQP+Bf2nkStFRzmkx97xn1TfYsWfSQ g0W3yllut8aAADGKz6o7/WygINKtL+DzlyOM05Znd8sCfuDCtaML3QADFWv3vsggvtnULo/BXEp Dd4MyoVFl+5ySsmUX6OkSpaHR1zrqBg+ZHgUC3s5vd/GyiKSV/UCNxcWFLBGjbXOLB/BdJ7ONQj oEJX85I+HUo5Cfd36dLHsArax8ikdNRC1q7iTklsMO1yWkBmgLrUc981XFHQ7LdenBUvmHaeTRK Nrq5ypcocLA== X-Received: by 2002:a5d:50d2:0:b0:48e:20f9:8d75 with SMTP id ffacd0b85a97d-48e264e290dmr8695718f8f.48.1792676879759; Thu, 22 Oct 2026 06:47:59 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:22 +0200 Subject: [PATCH 1/8] 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: <20261022-vhost-user-posix-v1-1-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , Tim Pambor 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::42d; envelope-from=timpambor@gmail.com; helo=mail-wr1-x42d.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: 1792676927293158500 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 --- hw/virtio/vhost-user.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 65889b0776..b817b15d0b 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1527,16 +1527,9 @@ static int vhost_user_set_vring_kick(struct vhost_de= v *dev, * receiving a kick. The spec suggests this to improve compatibility. */ if (file->fd !=3D -1) { - uint64_t val =3D 1; - ssize_t nwritten; + VirtQueue *vq =3D virtio_get_queue(dev->vdev, file->index); =20 - do { - nwritten =3D write(file->fd, &val, sizeof(val)); - } while (nwritten < 0 && errno =3D=3D EINTR); - - if (nwritten < 0 && errno !=3D EAGAIN /* back-end can already read= */) { - return -errno; - } + return event_notifier_set(virtio_queue_get_host_notifier(vq)); } =20 return 0; --=20 2.55.0 From nobody Fri Oct 23 20:50:56 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=1792677038; cv=none; d=zohomail.com; s=zohoarc; b=exdRzQiNzGgsH5x+ONHA2+fnkIAUPaxvm+QZdxEGYPXYCA9tyEOqDlYliPz+ZBu6tFVYikFlY6Zp6ffDxvLv0M58ion8gvS0n7PqQnMKIXYkmmAosdax8mUwr2Mf5LSxVrpRCsVKuRaRDkP8D4o8pDf3cwF4bNEmbdt0pfeuhQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792677038; 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=uCO4jWd/GCl+BQESy4pd/ThUis2N7ZU3bVWGeRHDfMM=; b=jxc6vqpjfBxxV2eiEA1Bzfd8ZQ6Oq7qffivi5k7XYjklBTjZ/8SIPx+oaOeE3srWDirNyqSsxt9uieCuZWxSIp62bZekhoI7xDpQGOUohwFs609mKik6L6BNx0HA7c4yh4izXZX13F+XqltHIHscPdTVtsqTqrtz6m3THiB1+Rs= 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 1792677038746156.60279450376242; Thu, 22 Oct 2026 06:50:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJt9p-00017O-MP; Thu, 22 Oct 2026 09:48:38 -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 1xJt9R-0000SP-K4 for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:18 -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 1xJt9L-00056T-0L for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:10 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a2001dd4e7so20120825e9.3 for ; Thu, 22 Oct 2026 06:48:02 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676881; x=1793281681; 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=uCO4jWd/GCl+BQESy4pd/ThUis2N7ZU3bVWGeRHDfMM=; b=as8MVZhvsA4ddgBGhW/aocwesRrfK8ZkW9hvl2xNWt7Or4mmKfVAtIL3Vzj+qR7EPG f9HP80eAi86lqr+d0HDzftf2wgPvBa19JlnVsT/2Z+kiItZetVBy4tDX8A96BzoWvjbd 7EsV6TNLN9nqv9egn2sSahkuwmEwmlv4ABQ55si/uaviWg7BmchZx0ykoQ+P7sqJ/kuP IYyIVvrCPw+X4SVV8OSDYB7gvpW49D1k+SOLcJ12Spj88aT7s2vVRXLt0HgpghbB0VbL VQJ1h5j5Vwhn74QcQo5WAnxWGRM16eXtqvAKjkMJ/FpF/hIx+82guEef973s5ubjRRJk vdKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676881; x=1793281681; 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=uCO4jWd/GCl+BQESy4pd/ThUis2N7ZU3bVWGeRHDfMM=; b=hsSC6swnBOZ449zO9QfxhOi63aNn1qd25g03SosInlrsj11MBK01o6LfXIwfcxHlKH Lf0fwcPeRxNQUmNHfdGtp6i/svLBRaNPdhC6+PJQ82wix+JeE6jF411vP0JOc4jjyLMf 7+Ym1We8ctoBCCpeWLm+JF9inDdcn6Mm9iWi/fqO5oog19s46EbaoZi1fKc6p91u8+R2 SY8Tx9ryA+7MwIc8f/x9fPTuLZ6xTsgeBUodOg0XHPfkUOfUXL1v9ToFsNV93r/dhVJc soGv8yAtwBpSJ7ywJEsppPWRQn5m/DnGFWERdtM+74t/oA5auD2hpqNTx8XllbTHOZXB 6kxA== X-Gm-Message-State: AFq9FYLctJCCQS1cQadox2SvdjYPq9iUNMYwPSpHLWY1OrcszTk0o3ET 1OYSNus89j3Z+a2VjDf6Ti48st6ad8O9BHcM3woqgES9kNH6BhN7GkHU X-Gm-Gg: AYBFou3Zx0LICmE8yVNVEUXdptAEky+x3ete9DH/+9bhAwDOmQy8wba+fdFHSLHKd6P Nwg11BI9Nve+g7Mn36r6bhc/Kb9xmzBO4pKDH+0Bp51cyfZlpuJKG8pPVQvTK/xU9rH1jFndPrV pdlyhf7RMEpmzTbAGRfhyPuhj4Fmkblb2kqDijeB8CRCu3ZHJtEmh1GsPn6nkONANZSJbTYoDob qZRYAqZqMz7vk7xQrERbWnZ+gcYcLIxfIWXmRh2fZNUNcDWyvbwhEGxOAaWDyYgS3rAkcnzdc6U BS3c2ZfTyYTq8743gXA7Yzg2e/9pkQ/0Pv9FnocNx1Uhw1tzGUaQUbAuBhquWWsR3JOp2l0KQOd 4CC03aKjgiL/OTcWIobob/BlEKHhcgpGevsxPX7h+QwT+kPgR+pGNt4xaG4dHIwDTgI/FaNZO0t 9Ni6TYsuxvoJFZw6SWC96t324XdSl2tCUdKtvaDR7WuYa7LljogtabYflUNdElvadJz5MrtItvM zXxISWgDpZcpCaSQUhj0KEjKnaGgRSfsrEB3DGDTkPBRHAIoxcotZpLkZrypUHXHvU+jGqVDlR4 NY9nRRTYc9HjJNFaggQQgrcDN4jnLyl7ZdUTPcWbWVbCqrLw3GXPQceZBP9ZSiEbpdTkt1SBLkJ KEh3LOxZgFw== X-Received: by 2002:a05:6000:2612:b0:48e:7fb:aed3 with SMTP id ffacd0b85a97d-48e264a5a5bmr11307183f8f.17.1792676881121; Thu, 22 Oct 2026 06:48:01 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:23 +0200 Subject: [PATCH 2/8] libvhost-user: self-kick through a library-owned notifier MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-vhost-user-posix-v1-2-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , Tim Pambor 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=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: 1792677041124158500 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. The spec says front-ends SHOULD send a kick after SET_VRING_KICK and back-ends SHOULD NOT rely on it, so libvhost-user kicks itself by writing to the kick fd it has received from the front-end. With an eventfd that fd is writable, but when pipes are used it is the read end and the write fails. Replace it with a notifier the library owns. vu_init() creates it, the embedder watches its read end through set_watch() like a kick fd, and the library writes it when a started ring has available entries or in-flight requests to resubmit. The watch callback drains it and runs the handler of every queue flagged kick_pending. This way the handler still runs from the event loop after the reply to SET_VRING_KICK has gone out, as with the kick-fd self-kick. Signed-off-by: Tim Pambor --- subprojects/libvhost-user/libvhost-user.c | 145 ++++++++++++++++++++++++++= +--- subprojects/libvhost-user/libvhost-user.h | 10 +++ 2 files changed, 141 insertions(+), 14 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 2fed792e85..e323e32cab 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,6 @@ =20 #if defined(__linux__) #include -#include #include #include #include @@ -1305,6 +1305,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); } @@ -1440,6 +1441,121 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq) return 0; } =20 +static bool +vu_self_kick_init(VuDev *dev) +{ +#ifdef CONFIG_EVENTFD + int fd =3D eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + + if (fd < 0) { + return false; + } + + dev->self_kick_rfd =3D dev->self_kick_wfd =3D fd; +#else + int fds[2]; + int i; + + if (pipe(fds) < 0) { + return false; + } + + for (i =3D 0; i < 2; i++) { + int flags =3D fcntl(fds[i], F_GETFL); + + if (flags < 0 || + fcntl(fds[i], F_SETFL, flags | O_NONBLOCK) < 0 || + fcntl(fds[i], F_SETFD, FD_CLOEXEC) < 0) { + close(fds[0]); + close(fds[1]); + return false; + } + } + + dev->self_kick_rfd =3D fds[0]; + dev->self_kick_wfd =3D fds[1]; +#endif + + return true; +} + +static void +vu_self_kick_deinit(VuDev *dev) +{ + if (dev->self_kick_watched) { + dev->remove_watch(dev, dev->self_kick_rfd); + dev->self_kick_watched =3D false; + } + + if (dev->self_kick_wfd !=3D -1 && dev->self_kick_wfd !=3D dev->self_ki= ck_rfd) { + close(dev->self_kick_wfd); + } + + if (dev->self_kick_rfd !=3D -1) { + close(dev->self_kick_rfd); + } + + dev->self_kick_rfd =3D dev->self_kick_wfd =3D -1; +} + +static void +vu_self_kick_cb(VuDev *dev, int condition, void *data) +{ + eventfd_t value; + unsigned int i; + + while (eventfd_read(dev->self_kick_rfd, &value) =3D=3D 0) { + continue; + } + + for (i =3D 0; i < dev->max_queues; i++) { + VuVirtq *vq =3D &dev->vq[i]; + + if (!vq->kick_pending) { + continue; + } + vq->kick_pending =3D false; + + DPRINT("Running handler for pending requests on vq: %u\n", i); + if (vq->handler) { + vq->handler(dev, i); + } + } +} + +static void +vu_schedule_pending_requests(VuDev *dev, int index) +{ + VuVirtq *vq =3D &dev->vq[index]; + int ret; + + if (!vq->handler) { + return; + } + + if (vq->resubmit_num =3D=3D 0 && vu_queue_empty(dev, vq)) { + return; + } + + DPRINT("Scheduling pending requests on vq: %d (resubmit: %d)\n", + index, vq->resubmit_num); + vq->kick_pending =3D true; + + if (!dev->self_kick_watched) { + dev->set_watch(dev, dev->self_kick_rfd, VU_WATCH_IN, + vu_self_kick_cb, NULL); + dev->self_kick_watched =3D true; + } + + ret =3D eventfd_write(dev->self_kick_wfd, 1); + + /* EAGAIN: the notifier is already pending, which is all we need */ + if (ret < 0 && errno !=3D EAGAIN) { + vu_panic(dev, "Failed to kick ourselves for vq: %d: %s\n", + index, strerror(errno)); + } +} + static bool vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) { @@ -1478,19 +1594,7 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vms= g) 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); - } - } + vu_schedule_pending_requests(dev, index); =20 return false; } @@ -1509,6 +1613,10 @@ void vu_set_queue_handler(VuDev *dev, VuVirtq *vq, dev->remove_watch(dev, vq->kick_fd); } } + + if (handler && vq->started) { + vu_schedule_pending_requests(dev, qidx); + } } =20 bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd, @@ -2379,6 +2487,7 @@ vu_deinit(VuDev *dev) } =20 vu_close_log(dev); + vu_self_kick_deinit(dev); if (dev->backend_fd !=3D -1) { close(dev->backend_fd); dev->backend_fd =3D -1; @@ -2426,10 +2535,17 @@ vu_init(VuDev *dev, pthread_mutex_init(&dev->backend_mutex, NULL); dev->backend_fd =3D -1; dev->max_queues =3D max_queues; + dev->self_kick_rfd =3D dev->self_kick_wfd =3D -1; + + if (!vu_self_kick_init(dev)) { + DPRINT("%s: failed to create the self-kick notifier\n", __func__); + return false; + } =20 dev->regions =3D malloc(VHOST_USER_MAX_RAM_SLOTS * sizeof(dev->regions= [0])); if (!dev->regions) { DPRINT("%s: failed to malloc mem regions\n", __func__); + vu_self_kick_deinit(dev); return false; } =20 @@ -2438,6 +2554,7 @@ vu_init(VuDev *dev, DPRINT("%s: failed to malloc virtqueues\n", __func__); free(dev->regions); dev->regions =3D NULL; + vu_self_kick_deinit(dev); return false; } =20 diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index a534d70771..ddd5cbb90e 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; @@ -471,6 +472,15 @@ struct VuDev { /* Postcopy data */ int postcopy_ufd; bool postcopy_listening; + + /* + * Notifier owned by the library, used to run queue handlers from the + * event loop when a ring is started with requests already pending. + * Either the same eventfd on both sides or the two ends of a pipe. + */ + int self_kick_rfd; + int self_kick_wfd; + bool self_kick_watched; }; =20 typedef struct VuVirtqElement { --=20 2.55.0 From nobody Fri Oct 23 20:50:56 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=1792676923; cv=none; d=zohomail.com; s=zohoarc; b=hSXZQ4LjSNJt73gqa6mRGOYJmMLBQScbHlujvVX+Eb2mqbQ7ta4Y1XLWxWgm2YUlmtploEDvXclfoWIN+WB6whk+qQ1XJcTVNEzRFzdaJIkFKxXMGQR39BOX11NExmYbr0BJuna1cNIXakonOc0GUtRP3rkTQrRW3wd79khpKes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792676923; 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=8C64Oblc06d1Q4TSN2UJSTMdDiz94K+JT5y1Cg6LH64=; b=WHBUvFhJfjIZSHw5gWbjFX2nQ61oRJz9eOz/EfVkhYc8fRVI1P06ntZ/gNN91aSX2iGvr1plUsftfmDQk+nTjeUwdiYV+Vr3/nX0BOSVt+1GZv1jqnYHhwMP79Riuv/4lAkQU0LfXJVwDjC0iFrTwEpQcYvIFFH8jEzkZxvqcwI= 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 1792676923953152.02604231034104; Thu, 22 Oct 2026 06:48:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJt9i-0000vy-Sh; Thu, 22 Oct 2026 09:48:32 -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 1xJt9R-0000SU-Lu for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:18 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xJt9L-00056x-Kh for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:11 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4a2069b9710so6168955e9.2 for ; Thu, 22 Oct 2026 06:48:04 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676884; x=1793281684; 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=8C64Oblc06d1Q4TSN2UJSTMdDiz94K+JT5y1Cg6LH64=; b=qBvQOEL9iVOVK9QVJUGVVMVNMktjTkaPMKgKyZ/LzVe/8/3l3Ba9NKrMujBXIWc/bh ue3ISyaR5egDyiqgMQlNXYlIg4FnjEu2Q2its1dgGAx2pIfWZ4FR6ohX6xHexnr1LpEN WRQ5cO5Udfg1LvNjCaXG0cBAQSFnaFlR3ylrb4zaz7Tzm3L+H3tw+UlC7f//hN2sfQAf FYbWNhrLHXbI8BsQ6axTDXUosd26vTVjxVg5eAca/qZDOikrPyKHcb9IPP2ziElAlCdJ TiJdHKrjuFIU5Ri1bc91gHPrc4yAjNdfQh5u/f4lPUSgF0Tq1WcdmhMUQjXiKNA8+fuP CElA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676884; x=1793281684; 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=8C64Oblc06d1Q4TSN2UJSTMdDiz94K+JT5y1Cg6LH64=; b=OVxqNTsLCY1eKIBGldTqcpFZqnMbWchLqQasAuiiiplLav0Mh8QwkwoUT4HB6OsCMu EAzX9mK2opB99/JX6o7Erg/kjIo78wjncbn3kdh4ioIBdibiqBo28WxEpgAkmI//S1Kw GNfWb2z+Gz/OviVUVOELY541kztspNWeQw8dP+SY2ccw1PUsKq3ePFd7X4ya25AElTqE iz4hyQWNTg8gzNboYcIxo/yJ+KmUWVq0+iyAUo2wK08BfCrkFAuWYOnjTilixq60ldBe ees0rVlXnx4lB9OIAGlqWA/eaJyUi8Iwyaq6Q047v8MSulVzjvG/CXkBgSgjs8wuQ9di Xb5Q== X-Gm-Message-State: AFq9FYLNgOksVXynNEwBOkKcvT13mRrdBMgzGfo6qRnRXOg2OpDaZALE DfdMMdCIxAz7qbZ/Lyt+yIG/kqXtfMXIPHXGb0NyiGBCnBnvKLeGEKUY X-Gm-Gg: AYBFou3wTzd4fGtGJTXCkTB0wPGF0ZGcyL9RhZmZQfxtsJi6ZKnVdAnJA+8gqY/sidF 06mW6r/WYfcTE3ECwBJuyyQSi5tB0oDXLMjzYht2OM6AEX3J8F9Zp1bHmd10E5G+bQHNJfc8rYC vIdjkxJ+QOdAjEbYrKI8PvSFUDT/EmqWpNfckwgYg4zvcK790zVKVDdzXSq10zhyoOjf26BMWMO 59aJ9lEwySJDNs+Zvi7aJzzinxd2MQir+mlz7zlP4+1PhOSTJKb2eaouwdr60ZbxnagWCJaZYtL nogfI/GeFBZw3OuASftCl6LgPWvTZVYAwjv/WpcjrxAg8KMVMGB6HDLWyYGbEANSxv9wyJuhrpp gYiUrzfXlGGS+Z7MltkQt2p8Z7vSRZz7E1pzG93UvRmyOZlyA136sM9qjfBY64Me+BsEQ8LSI8e jT86PKqpU3CZHs8IStqDCQcHHMadJijsrQFlKe00c+Dp0m5W5rGwBa1Dc8N3/9Iep9X0KvgvuXk 1AH1Bt0/ICnKUTHYDi1Y9kuD3ArhSk0g7eukbKqcQG5hVrg83o5BhucAbJo9XjCbNQmVhagW+5m 8chDTAvDEbCj5c9GOs43xOB1ZhW8PBoZ6/cV+M0Y0/rYbIo7ipMgvBzkXa3/HJ/iHqz39At5NBn 2Mt2YACcfVQ== X-Received: by 2002:a05:600c:4713:b0:4a1:6992:f861 with SMTP id 5b1f17b1804b1-4a1fd8a675emr112398905e9.1.1792676883654; Thu, 22 Oct 2026 06:48:03 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:24 +0200 Subject: [PATCH 3/8] io/channel-socket: only clear O_NONBLOCK on received fds if set MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-vhost-user-posix-v1-3-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , Tim Pambor 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::332; envelope-from=timpambor@gmail.com; helo=mail-wm1-x332.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: 1792676925284158500 After receiving descriptors with SCM_RIGHTS the socket channel resets O_NONBLOCK on each of them with fcntl(F_SETFL). macOS rejects F_SETFL on POSIX shared memory descriptors, so every message carrying such a descriptor caused the connection to drop. 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 --- io/channel-socket.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/io/channel-socket.c b/io/channel-socket.c index 7920cee639..1785fd5bfe 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -520,8 +520,23 @@ static bool qio_channel_handle_fds(int *fds, size_t nf= ds, } =20 if (!preserve_blocking) { - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - if (!qemu_set_blocking(*fd, true, errp)) { + /* + * O_NONBLOCK is preserved across SCM_RIGHTS so reset it. + * + * Some descriptors reject F_SETFL outright, e.g. POSIX + * shared memory on macOS. They are passed in blocking + * mode anyway, so only touch descriptors that have it set. + */ + int flags =3D fcntl(*fd, F_GETFL); + + if (flags < 0) { + error_setg_errno(errp, errno, + "Can't get file descriptor %d flags", *fd= ); + return false; + } + + if ((flags & O_NONBLOCK) && + !qemu_set_blocking(*fd, true, errp)) { return false; } } --=20 2.55.0 From nobody Fri Oct 23 20:50:56 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=1792677072; cv=none; d=zohomail.com; s=zohoarc; b=FIcD1wy/y8YSyAWSKQ4FsuHGKfQxD4zOXe+Y3/JDVoMRmHGhxm17QdeQQtf8xCUTnR5DIamrf7PCkIsPvrcvd8cxISxkttckJZK0i9WitelIWaskLPZIgC1QMJNMGNdTSugRncmGs0kPx8Jqm4zzGmu+X5KAxLrCqhh8tTyM6oc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792677072; 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=EOjVJ8Trpf7BcWxktaprhehY988nB9AYYLRyBxVBbR5FKDqpArwVdp7rhVs/pnU7j+CIo5odOPYwq7BV7crUNUbr4KDFr3TAL6iitmJu7ASfzAvcdQl2eG2K6pSPpe9In5z8nw4feGqlOtJRiE7km4uVcRU5UAtTjdXtQKdaGbQ= 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 1792677072728341.69684618423696; Thu, 22 Oct 2026 06:51:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJt9x-0001gf-Kb; Thu, 22 Oct 2026 09:48:45 -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 1xJt9R-0000SS-Ki for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:18 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xJt9N-00057B-HA for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:11 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4a140e7405dso16270145e9.3 for ; Thu, 22 Oct 2026 06:48:06 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676885; x=1793281685; 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=iAHHsqFRRnNSgGglTjb8GX44RYgDN07Q97NIbOrE2gWDCZlFI5pRYE+LDYvhVGhEL3 7GW8/+FtBAZtw3Bm0P+dkOafM091rRprFyyGidV2HC6B+7z/tR9ipJtNEeFe/SfABB4z PvaV3zekPOI7W8PxA+BPAiXe6RxgiWz7kpIkf1E6N6aWMOzdyAh4nFMSm0EeM+4QsU7j 1j3/As9BqgO3kZ51RB85ay8H4BG8F60OQoi6Z3pdNLo2lOAEV6mGHeO7SjZf17uk9ZnZ xElDZsIu9TSHqsdwDJuSRfVIW1MS/DTW1ITMWvEDxKpy1aftr4WVLcQmYf8DUW4bnd1f Q5Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676885; x=1793281685; 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=WT4xQahwesz1/bNiLYazhrAW2sjzhx+AUHSyc7VCrovRsSh32kYHl2RJIZpG+klcZ8 m4hX7boF5BG+oFM9KZ5OpPrRAxdqtpsvdAF10lhHWKfXtERe3AXMwTc86g2Owvm6E2Pc 7uwEVoSOIhojyY6JgOLUXaSGYXDnmPHhXmLSVH1MHiRHuHc/dU1mdmW9bzR8fTISdO9C yWOjU7nzTqbHG+HUE9YjIZrICAoJA72dWIuocTb6u2JzG+zQIbMV9crFh/ERKx3bPhhF U/jidTi4pmUI9lMxMRrjt4Nhvn2ke6rDx5ZyVH+wF8+LTsYu0rzD55cv4m/mjNxE0vTD nxcw== X-Gm-Message-State: AFq9FYLulCWcthD9Fm7OJ1erPrkL7T4k0b4nlmYFuxcltTDLzVBxXv/J HAWyV+iIQegnrEtgs2gKSgzl03/5MrFqp2rBCBc6AVbSOvcIcMJB90Ae X-Gm-Gg: AYBFou1U/d8kugTiklUZklwQY6a0scNY784qMWJ5BepLj7LXJxp17bdLU34LWO10CBe e+1dutLSOXqcKzdnvRrc71lUMlPOCnkH4o5gRMEYhJrJOMpx5q6uXp4o/IrkLDLgqsP06akCz2N EqsSHHIdLA413wqs6lsLGi/nZo9YX5zxWPyJ9eanweDu5embhu/atv+mHzhfvqhFtlmrP1mP3UQ 4jCWwPHq0pdB2AlK3dCtCn85XjxrZInoIsVxbcxXXyCZlrpz9X7kAmLScMmqohNOQK7/aXSiK3w s2v4VT1k6gEqO4uCMpMzkZl//xFvc8IoDLIAWBtp72nH+aQWhOYtpYT4RGl/B+ww7Jj5vzOUMvF Mc9ZRNFZix9u9FISpidyMGNS6tYjAAN2Kw6495gLUFHXcDLC+r857GHd/cf29jXy1TTK1Pu/fyh T7uNSKqbRGH6cvxckPCiI4a1fqKEyRkSGKQ+6taTCdbcbqJ0FjcpkDvOMvteqIzjeftKJoHprt9 OItGa9bW3hFpLQsBwAh5KTyUE6k5Dx3R9DngcnGeirtPRyC+MvFm3UYAwRRjEMBo9SL3F3Ts7UL S1NK1u+Oz6k7CJ5PDowyzc3m6dQ6ao1tXa7hKBxBaH9+CqDqgJKO3Q7kdLwHF3Xcu1eOKmuLuyK nPuWKUME/dw== X-Received: by 2002:a05:600c:b86:b0:4a1:83f0:7c8a with SMTP id 5b1f17b1804b1-4a1fd8a68b1mr106221355e9.1.1792676884676; Thu, 22 Oct 2026 06:48:04 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:25 +0200 Subject: [PATCH 4/8] 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: <20261022-vhost-user-posix-v1-4-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , Tim Pambor 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::332; envelope-from=timpambor@gmail.com; helo=mail-wm1-x332.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: 1792677073479158500 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 Fri Oct 23 20:50:56 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=1792676979; cv=none; d=zohomail.com; s=zohoarc; b=Chj3uAXc5RogGr3+SX4dRUabxh4EsJMZWzCblR3tz/p5LKqXzo987W/w0SZPJvLADc1MmnrQZlcykA19rTZ497/ITxs6U766kmF5bJcQrWw5r6lcDzNq0BHer7fqt9qD3OAuCP8tzXvzPX/i5XfEJFR7W8w3GtMkEfKSxAxFOak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792676979; 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=R+NRdMT+YYqh7tZtf4wG6rEoxejvaUdHqjhlq1eRRiU=; b=ZFUX4bR+LXcNaII/GhE2OVzrRsDAKK3+oWAAYh4kuVcH0WYHBaEydMR7LH4tzNDjUj0FnSGchp328PHqcbSYVYRDSXxOzbsZM8HeegQPeMOJxJm81ehRuzXX7meVfC1+46FpnIaj80404nu7vHlSWQ1Tpo53qe8aO8Cb3KzseSs= 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 1792676979149972.3214699717903; Thu, 22 Oct 2026 06:49:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJtAF-0002Dj-AU; Thu, 22 Oct 2026 09:49:10 -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 1xJt9W-0000Ur-KV for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:20 -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 1xJt9R-00057Z-Rq for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:15 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-48afbd2c386so1284262f8f.3 for ; Thu, 22 Oct 2026 06:48:09 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676888; x=1793281688; 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=R+NRdMT+YYqh7tZtf4wG6rEoxejvaUdHqjhlq1eRRiU=; b=Pw/tFldm65smK/ZB2nFP7p/Fjkw9Yk9tBVBvVp7wl36Nor3a76ISKcpkrrdU1pDQFm aw3O+8OyNff1JA7ht1tzNDV8PInDaQ1/Uiw/gdJ3FP/Dpvkrqd/Q7PkoqxcnaTW62xi0 46DHHXY3nyX7Yd/dm7KRkauRNHcCsFJYK69ZDZibpswR4i9QPKX5MBHsoTGwyxZdTagP Dtfgm0NAT3kGueaeh19kEI4v5icrwJbne54Ztz7kGa3rHkUfMN2WZs3x9Eq0gfBjXyS0 RORciiWUUtuDttEcpeBRes7OJCvSc9d8UghRVUwZQ7uxZeavxvFRaC+Rj+kF3pIm5yio ER6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676888; x=1793281688; 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=R+NRdMT+YYqh7tZtf4wG6rEoxejvaUdHqjhlq1eRRiU=; b=HzCv19t12IbYgRGUY83VYwPoOhsSM+ObRmIJXVFLJD+F+00fDV7nI5ILGejiqNjiI1 vgk/ZCbadhMcflYlGVy9//kZuCxFygbGj2wC0MDdGVJgVndFNRKGCXR+kfn/iWvbRmIN V1rZUTyjOu1YyyQriXzNoyi3hOFVj8RRhxf/XZ5vkkYNx9nRrlDlOdRKdh0/uc/uPpRo ySDiDuFYUYbb1MSg7Vi2WmcyRy5k3ubGmiPBNKI4JrDKO7tAdcYi1pjANLc5Rm4uG0tJ aBu4ZRMRgoGQhRL/zvyKAmU62VKhlroMlwr3SilyJfcBFNp9jgSnBww4fOi8W/1OJlKP 2kiw== X-Gm-Message-State: AFq9FYI1pScNcE/VMmKCqniNz1FChHG9ix6Ly+A4Td15SnexowVUY4sz 8M1YULRohu50NJAAvKm8yZu9IqUQuJsH++BdeRyw48ghpkNmxk6Rqy2k X-Gm-Gg: AYBFou0Xg3vpYJZP0JHSSt7k271gMPfvxRTf0iV9SMX868Km+xUfWScosj3NXoPTQwk 8iK19UIzOtVi/dvnojWgsSzNXkOlfX9JO9s7Njc9CMIoDXXxS0GCQfIttrzcmAICnKqHaVssTVO 9/GQWbP+q3hN+tMLZ7JG3Er8i0tsl9lcbmW9eWZbE427JX7UqYbXRaED4lUoYBxt7HYTXTbwjwU PuvYzlUUwRzADct15V6jfu9FWvzppInlECx838Uv/Hnz6XTV7Zks0VXQQQSsz4utsjL1EgUYn0S 7rao1ABWueMGg7NglqnA+rZYccC8Vn7LOjCV7TFGeoRy3fVcaE31gSzncwaI8+iBGkXsewFycV5 dvMqOkqv2pLN9RUlIatnOOnyiju+owpJpQJtcbLmJWn/dmA0E/DsFyYP1Gz3nyt8ZamoW1t+cge JwE9HxE2KHzMiul8B5GXQf1lgVHY43j1gGjwD+p19hFiYz6kxG20gtbVAB5wT5cligIgSd9GsIf haK2+LIVxxnoTkONOZIxR4+lTbCer2LuiFSWxaxyYZGObZ9LiP9a63mYdZfypD1yxpoJeo4RRxq 1tuInL6L7or+1y3Y9awx5pfZY+SW33zlEfBcZspYbE51S+hSMoh+ff05lgoaKdtDzR5Ve6dFNgh T91DhhNxkIg== X-Received: by 2002:a05:6000:2689:b0:48e:3fc:e393 with SMTP id ffacd0b85a97d-48e26423766mr12010947f8f.6.1792676885810; Thu, 22 Oct 2026 06:48:05 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:26 +0200 Subject: [PATCH 5/8] 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: <20261022-vhost-user-posix-v1-5-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , Tim Pambor , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , David Hildenbrand 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: 1792676980058158500 From: Stefano Garzarella The vhost-user protocol is not really Linux-specific so let's enable vhost-user frontends for any POSIX system. In vhost_net.c we use VHOST_FILE_UNBIND which is defined in a Linux specific header, let's define it for other systems as well. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella Signed-off-by: Tim Pambor --- hw/block/Kconfig | 2 +- hw/net/vhost_net.c | 6 ++++++ meson.build | 1 - 3 files changed, 7 insertions(+), 2 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..788913953d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -33,7 +33,13 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" +#if defined(__linux__) #include "linux-headers/linux/vhost.h" +#endif + +#ifndef VHOST_FILE_UNBIND +#define VHOST_FILE_UNBIND -1 +#endif =20 void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) { 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 Fri Oct 23 20:50:56 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=1792677044; cv=none; d=zohomail.com; s=zohoarc; b=aZR/0UOgKrqkrwwux+SZgx3PB+0JGqwtlQ3DoJEJvT9PgBDWsUzlQho0f91WRltJE1mW3ZXxJi8RQe+Exl7NNSPecWvtx25FzfZ6ZZnVbDwZ4HqRTHz/meWTLgLjHkYr0zDY6pTF0jX4TSL6Q90DwDmLymFaK8mdn8D+1L/ZgMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792677044; 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=x+vatmk2dmI/yp1zURhstHKX4MTHvDuE/7/Wa73Bcu0=; b=Dl9gu6qr6pGGyRbLujq5WqfWic1qB+STHHdpU4Z4DWmy1Kb9do1lNRlcehVpkcA/TjUZhAUNtdospPVB1mHgUDIPPO4mksW1klAmGk25tBghie+nkmBmL4MYkvCpZ1T8cWBO1bMOTkUmJTMVF65/w7pjPb1d6mIcwum6tU+5YCg= 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 1792677044676678.2985392761155; Thu, 22 Oct 2026 06:50:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJt9x-0001eh-B4; Thu, 22 Oct 2026 09:48:45 -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 1xJt9W-0000Uo-Il for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:20 -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 1xJt9R-000585-Cp for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:16 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-48e0d885929so1458301f8f.3 for ; Thu, 22 Oct 2026 06:48:11 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676890; x=1793281690; 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=x+vatmk2dmI/yp1zURhstHKX4MTHvDuE/7/Wa73Bcu0=; b=Zic7U7JeUOJ+OpG7XIyZXh2a2ppznVFme5wLEATyXfUOxU76thipg0DhwRwXSNZ6Fv DzdD8QKqB6wNxwKzADG217DUEPRMGcWjldvuMH4WjVwec0S+9niwpnYEnSlaODiReCAd tcS32fXbNoRPUnQb/34Zl87MovS5gtT1EHfMR6EPeJLHC7HYcQOSvnDii4sTaWmbzSLQ xk14CrKeLxIX2n9NMmXNBbiOlDl6fRuTtqvGgfaaMKL87DXIZ2+db6VUU5nwoVIlV0Y6 rA5ozUnNBgku36V81BGd92x5ZUdK6pu+OvA3pFHd5uZW1phN1HUia8vgFKgtSIh4k7uN VZJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676890; x=1793281690; 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=x+vatmk2dmI/yp1zURhstHKX4MTHvDuE/7/Wa73Bcu0=; b=vuiBfb2vR4yMuTjOpqxcLNUfcnNTAU8kZz51/w24D6OvtCISLmttWt7VNc5+6KdLfw 68Dr1HgSvS+/9FDrzP1Z/bNx96WOCpQCD91Mg5YFXLBmam76CBetNnr45pNYJk/9H2G9 /QwX6TQBaSHmlV36C4ZTbUeyM8Cc0xQB4lRrzViqZ3dZpDgkhG3PE1D/GF1aupZrJWPC Wh5we4SPMfQltyoGxLaVU8ON1/z+/hKTWzgYh8lEU1d0PoRFlcvPoOXLUzT4IQXlUshK 4XJg//nRAhoeeDd97RaCouXII0pyhRL5GLo8S5pOmERxZO/kHrZiWRLEnQb680bX6oBF gLNA== X-Gm-Message-State: AFq9FYLGXBdhCJwWqFaY7NwEdOYrRdrRWutO0JCtcLlbfibk3qNIOltB OJ3JxqNvAi0gvttosCkQpNTR3zKxgC7ImN4/VWCtg3KERB5mGUvmz4wA25j4DMku X-Gm-Gg: AYBFou1XV8WO2xoAZxKnfFObgvyhgLI0FwEktrDXEZiFZ3Yp+HyKLb9F9VMkcWOXQBn Nj8YNLtBr4KsqyJ/I8q+ttknaHyGu+5c+0GKL8TjU+xGziBNcnl9TqD+QQR+0+QUZP54PzJAaAE xwDeBXFvVhNmTjoktUJy18t+tL3S9rfTixXE6uS5eUjYfbULxYLXiUgDQHeHSIldJ7+2+9C8fz6 peHodsVpmy6eRjrPbbt2qihNq9qEwqanbKDIeVtAfm55iHpm+gy3ZvS9yWY5zhZx0d6Pq58EV3k 8CGOeagaLdVohhykw9chLP4B+ENlkShdcOn5FCtEWkXDStgiJJdJ1zXx9YCDpZThcL7fxZiWVJP 2HK/+KHEAZUH4YvTAqCi1ULinx1v4sPGL9FIsUSvIG4KOS8KNh0ETQJibQ/+iP+4PSrcwapRrwm KbaTY0b0UEv53SMrnfEG8KU4YBrr7Z2f/tNnK+kKRTl1lIJ+qydptJuOm5tMVwdJmBHtnSkFn/w VNupAatr0YoIwqdREiXLzCqxSm+00eZLUeRKlLO7lz7QLjWD+9PZzvsbbw+nEWVvbnulrYLzA4v 5t7ZifmHtylmksl7X7GdwEnpTJc257fYPkYdLGdkPQSTz6tb4QV9ydF5mVkqI2UphmrZoRaEw8F 5+v+1nqfwuA== X-Received: by 2002:a05:6000:98a:b0:48d:f014:63ee with SMTP id ffacd0b85a97d-48e264a1d2dmr9864123f8f.20.1792676888346; Thu, 22 Oct 2026 06:48:08 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:27 +0200 Subject: [PATCH 6/8] 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: <20261022-vhost-user-posix-v1-6-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , 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: 1792677047151158500 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") - define eventfd_[write|read] as write/read wrapper when system doesn't provide those (e.g. macOS) - 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 | 59 +++++++++++++++++++++++++++= ++-- subprojects/libvhost-user/libvhost-user.h | 2 +- 3 files changed, 59 insertions(+), 4 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 e323e32cab..7ce73fba19 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -29,9 +29,7 @@ #include #include #include -#include #include -#include =20 /* Necessary to provide VIRTIO_F_VERSION_1 on system * with older linux headers. Must appear before @@ -40,6 +38,7 @@ #include "standard-headers/linux/virtio_config.h" =20 #if defined(__linux__) +#include #include #include #include @@ -52,6 +51,62 @@ =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 +#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 + +#ifdef MFD_ALLOW_SEALING +#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 ddd5cbb90e..f21ba77580 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 Fri Oct 23 20:50:56 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=1792676990; cv=none; d=zohomail.com; s=zohoarc; b=W+Tqx+DnjtJCkajWAqQbnIiA2tukuzSdWDS3wJka1kpHYe0FoAwGaPbMB6xcPZ5L3DBY/mxlD2hOH+08KKVIXN5TkkjzIXGNvUVU1JxP3hhSNdSeHDitMqE9sOx8BJwqfMW62PeDGI2fCELLO9CoIpn4Mgg0DwQI6y2I1eRyHzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792676990; 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=kpuEW8FXTAfmy+jMqsJs+uZcb5rL/eQ37o8Glz3i2ANmUJhjVBiTT4KQJNGVewQr9bRok80WhWLiv1XxKE1bVC95OSR2IEHzJFGGWQ7pE4lWp+gTRKkga7oP+6AHAjGOl5WQJtlg5v0nRr+ajS5PnBpUjfvThpGxEIsINWcTn/A= 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 1792676990636631.9758543822379; Thu, 22 Oct 2026 06:49:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJtA1-0001z4-Da; Thu, 22 Oct 2026 09:48:49 -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 1xJt9W-0000Un-Iv for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:19 -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 1xJt9R-00057v-9y for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:15 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-48b001cd92bso1072965f8f.2 for ; Thu, 22 Oct 2026 06:48:10 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676890; x=1793281690; 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=G+CMGrBZoUIvpsR1nwe7uputxfYhJFBc/5kjLjVcUBmDU8DMDcryZvC4UFphGFUBIR yqaiN9PtXvAKYPZS8g5LZUpHXqSIbXlvQcySKyFDEXNb1w9dA6waGmWBg7k5uODK7r5j iA0dJ5t+2EE4yi2RUFb2h3y4wcxGWe/cQtIpa4C9XOY0u86LDOQmTcCtmA2rml1e8RPp oBV7pAuu3jYIws+/1CYncBO7rWGJ/QAze+/Qoz/GzzN+gDIAFRVB4KXkOZjF5Ek8nurE 1uk0MO7IWMrNKl2v5CZzyS1z1wKUKG1XP3Zv4ApnEE3YyriR9DSDpw0YajnHLuoRiQeC skPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676890; x=1793281690; 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=aW0LVat6Lke2DHSEp20c//MntrOIfqNl7DdGSRl8QSJonNyFmnTo/gO3DpNKd1cgNs Snl5Bas+ELtb9u8XVUzuOPFYrmmXfJJp0y9eB+AqFDbXDetGIRb6q4f50u0NkTSwreGA /I1KgkLYFNELJ28lJsnPAfi2k4d/c3FN96oFjc9gyFtN5RrSNBcg13EyKwhCZIcuduV+ ieWt9XSdTrTdQr1D3+7vYdoX5/iPodrP13dvJmZeKlpZUGHpcX0z8JLI3B1gcgFA7Y6/ Ict4xgm+pQdU/DJfCfDxpo6U1ZcMbs1FbMQeaHU9w1rSD8NlYba34dEw1I8nzklVjbVC xy6g== X-Gm-Message-State: AFq9FYIjkTX6U9zD8AZ4bOTJAfJN8trIaOkn3JIMiV57pfkMjpt8hcVi nguMJ8YOzQ44b/hjGKRnpaboRbYsMMyLD2ToYwglHT17yIAvb41Cw68J X-Gm-Gg: AYBFou0lF9ltVwQ8dEpUnRxyyc5O92nX+oOKbrrRPgh1I/I+qf2L9Y+iFLJsE663WrE roh0+omS72Z2Mo3C0t6vJRceM8K8sA9+9VNXjWQJ0fLzrkABv+WhXdCKJ/k/eFjZ3zHSsRR95og WKI5AeO/7R1rUNBwtELB06yOudIRW5iqItvpURkgzh39kjRdhyl+THSkVYkZpFQwuVtj+l82i9k AagcY5IbzFGSykIEhZXN10fETn1mstiqQ66D4r6CrJ8utCjbrizLSvtYeR5npikVnnyI56bVRjM oayCd8a4YVd/LW/JVAKvpcQLH2HL392bQRlng9/FREFst5N8HJiKIsIu0Hb0GNFOLZ/ytbalfW4 L3khuYtkQ8AP0Ka72ySM8vkiUMQy8fA4Bz4exPWuoTLXuqiXoP5XN4vLzh0LFbxkzlPany7Jl2a zDfd4EY03rOsbrwfTuy6oF/2Quh3LpfpZcJDQ+KDQs+7oC1EjeZ58BU/pIjfD0qnb5aISut33Ci traGP7hj4x97pD790VY51WgLGz/PZ43QjpXh13Mrz+eFheS3bWwmoXWTxS+b9VHfwWZB7uYDUp+ gtaW9JYdxub++1CEPwwQ7tbXSVvavyJxz3NQvkO8CB4qnzOuBkQ1BQfp+A7YOA6WOzV2rvyoIBE lbGVXq1pVAA== X-Received: by 2002:a05:6000:25c4:b0:48d:facb:5937 with SMTP id ffacd0b85a97d-48e2642d1b6mr11766931f8f.7.1792676889686; Thu, 22 Oct 2026 06:48:09 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:28 +0200 Subject: [PATCH 7/8] 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: <20261022-vhost-user-posix-v1-7-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , 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: 1792676992571158500 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 From nobody Fri Oct 23 20:50:56 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=1792676939; cv=none; d=zohomail.com; s=zohoarc; b=SfCf4c1VfJvCDQJgFmsvF1ykPQoFdcYnFULpJRNjsa9JHoDB6khhzyJLXKB0IrRYFHWHm8ocid3zllfM9vb0thunSqTq4cOOerVzk/0aWT2U3Z3PVpFd9CMZZ2obW9GSX+xTpCzbN7yUb4Ad667SNZ2iRFO4XG5urA6EUaQ/hKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792676939; 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=rV63IJW9kz+/YA+jmT/F3tBVCpkCtWkImKaAF2bvNIw=; b=DIsd6bJ/GvJ6id2cqVEftgvIqWWBeS2yqDFsgfauDk2a/WIrMK3j3pBu3grE3nqOdlhzXnv6LlXye1xAETzqtoWVQsqWcw/4mawvLfV4CQkKDgA0xmVrau33RowiA7CoeU4CTu02sPtdvYiCv3HojBtlDhMfxw/2l+4I78RDRLs= 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 1792676939333575.0977634584043; Thu, 22 Oct 2026 06:48:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xJt9r-0001Gu-TH; Thu, 22 Oct 2026 09:48:40 -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 1xJt9W-0000Uq-K4 for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:19 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xJt9R-00058L-Qb for qemu-devel@nongnu.org; Thu, 22 Oct 2026 09:48:16 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4a20b122af8so4824665e9.0 for ; Thu, 22 Oct 2026 06:48:11 -0700 (PDT) Received: from tim-m2.local (dynamic-2a02-3100-5a78-7100-00df-217a-667a-8b0a.310.pool.telefonica.de. [2a02:3100:5a78:7100:df:217a:667a:8b0a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e254ef1bfsm13120414f8f.6.2026.10.22.06.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 06:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792676891; x=1793281691; 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=rV63IJW9kz+/YA+jmT/F3tBVCpkCtWkImKaAF2bvNIw=; b=M6iI//PYDw03jTIOuaB95R4tgjdClm1RznHj3AH2VYrRqjtjY53D+g2qD7lG6QGSPx Xlc9JUjIdQ3hLY+q4l5Bfz2PM9l3rDQWt/r2NFuYUqpOkqHOLOSYahmL+OEfMlYNNfdt up49fCQFonAZHb3/A7ZRSnKnx/jt5FiI0NdfU4DnRlkBePSKAcrngYeqFNRkYH5SVWX0 MjP2cUok++/sBN/8X+13V/8ZXKdA5q/l9OW37WDYvE5DSPk+sVqTD5fIE8bv6NTUYuYV T5AcPNL9QwZdY+7Rgj6aCLSMh4xUItu/3WDIl8si250wSZ5E9oi5mhFuVe4R3+fzZFHj zZjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792676891; x=1793281691; 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=rV63IJW9kz+/YA+jmT/F3tBVCpkCtWkImKaAF2bvNIw=; b=JndEfvjgJvcJFlhEVPQaYY/2CV8KPR6JlSMn5igNvaeCpsSBUE7wRw33wU+IRHdcSW UotlVSx+7BAx/4pfy2zmD/DKW7YWwiqb8Y9vMh2g3s83lzWYTcTraOatuiOdGnZCdl00 Ej3X0OsEKlVZfIh1nhSY2b/oD52A/QFO+fcGSKXKfNfIzdQaSZSEYfFxWPsPGWKSHYwh hJP0iVDru4Svq/FuV3Uf4UDvspBh6QUyqm5MaQ+nAWVX4ujbnnkuhFzXJW0RouRi6a1L bzb9hAz9+ymvbzg9ojDIA9TaYhoczB+QCKNrQNBo4BR9Edf+2rvzu0pb/uAr23nTLphc jq5g== X-Gm-Message-State: AFq9FYLAIptuw0ZH56jy58WbihbmXr83Trz/T1VNGTbzLJJNKe78mFE4 5r4dcr/4+Iv2eMlP/no44ZhxHI20VnCpx1HtzCX+3Hw7kTF2jauTwV7V X-Gm-Gg: AYBFou1Aiik3HbPetVa697x6XWGDaiq6NzSO2QeHoRORfdzOWNHUx+pn7su9iltz1EG NrvKC6AGUu7hvcrgr5y+N0WfBcHCtr32DP7HJJjPddDLUylyTDsazUH+kfnEK30T/cwggp/OeER 0BYuce6UPqqt2l4gt5D+3s99vUgNMjAlb2IJiEg7UznIcbN59vofWODmN3GnOASdajIaQOV/ucV Gpaa4on6J48O8BSfD4v1gpCGaRE9nBnVVo2n18DKUTwMM985r0Xw6PXf2kz5EOek99BZrBdb/yD mh/JqqT6mA8E91QrdPK1q6tivG/xe+coG9t5dbMFuNchA+m6rFKpNjCOHh8d7NYfB+Y0tlMSGZ9 ewHFrkVfP3zIlIfiqJ8/jOZGPvu9F/XK5H7G4ueJpgtT1PZ9KJGjx64x9OFETOf5n/Kejm81vwk kY+yhyy7bczC5JosUyZuMGjIZzV4kYvBlIgPzv7mQij+CFkeKFKNEbcdP8eYEi37NPZz6xYmM4g WF26vyPmRvVfhi9aBlT8qoWt0r+yu4ZVRfbtUNb3u4QlW+YbEgFMdAzpm1My1TxbYuf8A3n3S5c 5mLmRx+Ns4s/4P4Bo3ZwOybElkwPDsBKklRByrxtcpoG86RMhfYzYQNRCoeAWyT09sjTzVmkA9F ixtxW66aYbppyl89nJUlLzMCcmTL0eLY= X-Received: by 2002:a05:600c:34c4:b0:49f:ce78:3562 with SMTP id 5b1f17b1804b1-4a1fdd37971mr109273495e9.19.1792676890715; Thu, 22 Oct 2026 06:48:10 -0700 (PDT) From: Tim Pambor Date: Thu, 22 Oct 2026 15:47:29 +0200 Subject: [PATCH 8/8] 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: <20261022-vhost-user-posix-v1-8-0bd4d450d23c@gmail.com> References: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@gmail.com> In-Reply-To: <20261022-vhost-user-posix-v1-0-0bd4d450d23c@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 , Tim Pambor 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::334; envelope-from=timpambor@gmail.com; helo=mail-wm1-x334.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: 1792676941347158500 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 | 17 ++++++++--------- subprojects/libvhost-user/meson.build | 11 ++++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 7ce73fba19..32b7ae82ce 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -85,7 +85,7 @@ int eventfd_read(int fd, eventfd_t *value) } #endif =20 -#ifdef MFD_ALLOW_SEALING +#ifdef CONFIG_MEMFD #include =20 #ifndef F_LINUX_SPECIFIC_BASE @@ -1963,13 +1963,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 @@ -2164,7 +2163,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) { @@ -2231,7 +2230,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