From nobody Sat Apr 11 23:02:57 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=1772448300; cv=none; d=zohomail.com; s=zohoarc; b=gQnDVJapyfigbaoGxfsWA6WMLvIXbNtKBKYEbJqclQDNVrFlLQv+lKrfprXqE6l12kmmlfWwkpiRj/6GQFvSqYQMg8AhC/MOIV/l4VynqVMS54sbxVqh7DgUX1trcZFAslkr+6vTGVIMZSAWI+2hiR4UnWVlOrDMI/VnJhbso4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772448300; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From: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=TF+XPMaZ1UZjXw5PXrQWRSROD8ZwCCDG24WrQG3i85g=; b=PMWRceIMHa8zxLYidS8MjRADA4f7gjIyhi4KYkCdjdJ8VtOhfXwcMjSmNdjLxh/jcfuI6SIH8tuXIThV7/UmRDBR04h/O/qxwvcQtjuqHKWWkkshvsDB23DPhYX5GZnXQbY4N2ssga1Tn6Ia3M6NsSyMfb7yd9eCIrJQ+LhFR7w= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772448300345958.1843599619148; Mon, 2 Mar 2026 02:45:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vx0lZ-0008Il-Am; Mon, 02 Mar 2026 05:44:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vx0lS-0008Hm-8g for qemu-devel@nongnu.org; Mon, 02 Mar 2026 05:44:38 -0500 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 1vx0lQ-000303-94 for qemu-devel@nongnu.org; Mon, 02 Mar 2026 05:44:37 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4836f363d0dso37245465e9.3 for ; Mon, 02 Mar 2026 02:44:34 -0800 (PST) Received: from ST.. ([102.185.186.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439b4e771basm11664843f8f.0.2026.03.02.02.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 02:44:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772448273; x=1773053073; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TF+XPMaZ1UZjXw5PXrQWRSROD8ZwCCDG24WrQG3i85g=; b=LulPvbRhI6xHuV+niqW4S9OkRMI86XquTU4ZEitVQh6q7qqRoIcN+HQ1IvpeFtFtOx wTTVYPdetU9NE1g9D8KDH+lpLwXFTcqmgAlHb8TzApiPhRBijw8s+jPj43ahRvSLHBkS EAsA0Y4XEJk05YKzSfDL0wApk568W7OsxK9ylmCMesyuJsmZ+egoAo/pGvtYJqQNHCjs pY7mI6A2WYhUsOVa6Ygt9ZlPkLgThACc60xG+eNEIvjt6JWt3QbXUoLaPoBRIiw7thCZ cq8nGQlBHHsO6eMAUGb08TfHrUpx/Y+PCC8Wev5rM53weXmNo0pQhDdNROqmhoMF6P16 gZTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772448273; x=1773053073; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TF+XPMaZ1UZjXw5PXrQWRSROD8ZwCCDG24WrQG3i85g=; b=uefZZphFfdYYc6MYqAZJQz2breYcAMaz1jgBDfMK2KIWP4KgiNCnZltHGkX3zcWs6T lE5xqa094KETq/8VFZvbQ6DADhOZJCn7KuCzJ4UdYdYeUtThdTgJ3V1d/zzse1TCdSpn yxPI5ekYR9aINy+MgttA5HSzZoBCh2UPrZEPXV5I9H5IzmxlOzw5MUi/eBti8yU4nIxX 5zUj+qh3ryio0KTm8TWZU7HdhyoSD/7Pgz3vbzhbpsxbLbkGLNrbbNJG7ZcKNtlRRJT+ i87VznYLFVFtWaZ6HhgBzGWZFq6Vf0/KhECYDdoC5C1p7qnaJsE4NK9fzA7luzTiRNOv OcVA== X-Gm-Message-State: AOJu0YxYUzA8ZirLAr2kpOKtAbS1oK2mwX9rqeD8jKUXzQycAap+gkAE D81QNhjUQPclL/go3edDzjv4r19gJw8e7Oh3BBCPEnb3O1m64rNb+ETChKlqd+XrDP4= X-Gm-Gg: ATEYQzww7HNo2kFtQd4+NvSHH1857jIbVAbUSUHOxtae2H5u4jY63RPugTNA2rNhVRp EBA8yd7NQjER05uvej1N0nx9bLadObjNlYRkByDTzfEHYFCL6HD2Y2hD+0mCIbdrTUG+v5t1gLM 8KgarzFzcGQK677QzqQIAwAOWJBR+Qcgy63JJiEoMIaAqPH+6+VOaDRsY43DLKvPBkGD6ZXKRDb m7PFalhAE7CsxjUGCXZCObjffq6wGoA3URni7dtO8P7NsXZY28TbB+9BWXlvZlponvFePOYBUJb KDaILFPjadC/onXRdfGxeGZXTp22mo4keaQQD+XTaWSB2M7ptxOW6n8WTCbPJmcMjQ9fznwqYaH bAubsFyQjQ+80Z+DFLUkYmnSUK3EaM+2F3cSbkJaJKoImUdaDrPDjo2vUs9nSAdnpFtIAb2bTY3 L+oYE2lkrDEwMhyXoylkUfYohvL+wM X-Received: by 2002:a05:600c:3e86:b0:480:6941:d38b with SMTP id 5b1f17b1804b1-483c9c1bc0bmr194638385e9.30.1772448272795; Mon, 02 Mar 2026 02:44:32 -0800 (PST) From: Mohamed Ayman To: qemu-devel@nongnu.org Cc: Mohamed Ayman Subject: [PATCH] doc: add detailed comment for vhost_user_read_header function Date: Mon, 2 Mar 2026 12:44:27 +0200 Message-Id: <20260302104427.233089-1-mohamedaymanworkspace@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=mohamedaymanworkspace@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: 1772448302723158500 Content-Type: text/plain; charset="utf-8" This comment explains the purpose of the function, its parameters, the expected return values, and what each internal step does, including reading from the character device and validating the message header flags according to the vhost-user protocol. Signed-off-by: Mohamed Ayman --- hw/virtio/vhost-user.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index bb8f8eab77..67525dc403 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -272,6 +272,20 @@ struct scrub_regions { int fd_idx; }; =20 +/** + * vhost_user_read_header: + * @dev: The vhost device state + * @msg: Pointer to the vhost-user message structure to populate + * + * Reads exactly VHOST_USER_HDR_SIZE bytes from the character device + * to populate the message header. Validates that the read operation + * succeeds entirely and that the received message flags indicate a + * valid reply matching the expected vhost-user protocol version. + * + * Returns: 0 on success, + * -EIO or -errno on read failure or short read, + * -EPROTO if the protocol flags are invalid. + */ static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -279,15 +293,20 @@ static int vhost_user_read_header(struct vhost_dev *d= ev, VhostUserMsg *msg) uint8_t *p =3D (uint8_t *) msg; int r, size =3D VHOST_USER_HDR_SIZE; =20 + /* Block and read the exact header size from the character device */ r =3D qemu_chr_fe_read_all(chr, p, size); if (r !=3D size) { int saved_errno =3D errno; + =20 + /* * Note: Logging msg->hdr.request here assumes the msg struct wa= s=20 + * pre-populated with the outgoing request prior to this read. + */ error_report("Failed to read msg header. Read %d instead of %d." " Original request %d.", r, size, msg->hdr.request); return r < 0 ? -saved_errno : -EIO; } =20 - /* validate received flags */ + /* Validate that the received message is a reply and matches our versi= on */ if (msg->hdr.flags !=3D (VHOST_USER_REPLY_MASK | VHOST_USER_VERSION)) { error_report("Failed to read msg header." " Flags 0x%x instead of 0x%x.", msg->hdr.flags, @@ -295,6 +314,7 @@ static int vhost_user_read_header(struct vhost_dev *dev= , VhostUserMsg *msg) return -EPROTO; } =20 + /* Trace the successful header read */ trace_vhost_user_read(msg->hdr.request, msg->hdr.flags); =20 return 0; --=20 2.34.1