From nobody Thu Nov 12 15:08:25 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793315464; cv=none; d=zohomail.com; s=zohoarc; b=RAMp0b09qW73qtX8CblUkdE9d/BSZHdQJYLXq9FqP3LNP8hUjR/WqrMy1sDLLEzCzb90+RxEypwaopgajkWlS/s3s7FBThk2T2T8hsAt8XPmFz9LlrmUeeDHAVMXr04Q4Icu1N8zkvE9y5mtd3TNaqkW2gmsNuudTtjW0IW7FH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793315464; h=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=GAkypcA8H4GOZoMJ0zYDAuHv44NctvKtilUiB9J4joM=; b=ICfo9heeusNRkH/adoqbnauWgfhPEy7b8mBaT6Du143kojY/mU3mS5t4xdfYNGbTuruGOG1Rc+6WVS6UGN7YQ1ouhF0SIfffaX5lb+XxzS/6ZU21AFYSkVgZdxVtD3pJwbx2gkRm6AVMQPKM+Bbm07jvQv8Xx5n/atUoU2cK5uc= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793315464517628.0650477382045; Thu, 29 Oct 2026 16:11:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMZGe-00061K-BV; Thu, 29 Oct 2026 19:10:50 -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 1xMZGF-0005oy-FK for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMZGC-0004to-5h for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:18 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-YNOPPfSwNiy8xpqfDSzk_A-1; Thu, 29 Oct 2026 19:10:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 721CB18052DD; Thu, 29 Oct 2026 23:10:09 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.61]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 40D6730002CB; Thu, 29 Oct 2026 23:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793315413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GAkypcA8H4GOZoMJ0zYDAuHv44NctvKtilUiB9J4joM=; b=YazT4mKnGnp4ZINKeHNJyN+DbNaBfVgDGuAXb6lSUED8JyyaB4rlj0ufFFYld8zusMbNf7 G2D/j7ocLpH5m5pcBLXdqnNBWHVWb7KOmMKeBUiGamWMFaxURegRYDa+tOmdNyQhcfx5XZ Sld9uMLpKioDjCO96Qnp4BLIY74xwAA= X-MC-Unique: YNOPPfSwNiy8xpqfDSzk_A-1 X-Mimecast-MFC-AGG-ID: YNOPPfSwNiy8xpqfDSzk_A_1793315409 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, mst@redhat.com, devel@lists.libvirt.org, qemu-devel@nongnu.org Subject: [PATCH v2 1/4] virtio-blk: Implement full NUL padding for GET_ID Date: Fri, 30 Oct 2026 00:09:58 +0100 Message-ID: <20261029231001.194240-2-kwolf@redhat.com> In-Reply-To: <20261029231001.194240-1-kwolf@redhat.com> References: <20261029231001.194240-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1793315466280158500 Content-Type: text/plain; charset="utf-8" The spec requires not only NUL termination of the device ID string, but NUL padding: VIRTIO_BLK_T_GET_ID requests fetch the device ID string from the device into data. The device ID string is a NUL-padded ASCII string up to 20 bytes long. If the string is 20 bytes long then there is no NUL terminator. Zero out all of the remaining bytes in the request buffer. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 536d71a91ad..3f236f22d57 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1011,14 +1011,18 @@ static int virtio_blk_handle_request(VirtIOBlockReq= *req, MultiReqBuffer *mrb) case VIRTIO_BLK_T_GET_ID: { /* - * NB: per existing s/n string convention the string is + * The spec requires NUL-padding for the output. The string is * terminated by '\0' only when shorter than buffer. */ const char *serial =3D s->conf.serial ? s->conf.serial : ""; - size_t size =3D MIN(strlen(serial) + 1, - MIN(iov_size(in_iov, in_num), - VIRTIO_BLK_ID_BYTES)); + size_t req_size =3D MIN(iov_size(in_iov, in_num), VIRTIO_BLK_ID_BY= TES); + size_t size =3D MIN(strlen(serial), req_size); + size_t padding =3D req_size - size; + iov_from_buf(in_iov, in_num, 0, serial, size); + if (padding) { + iov_memset(in_iov, in_num, size, 0, padding); + } virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); g_free(req); break; --=20 2.56.0 From nobody Thu Nov 12 15:08:25 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793315457; cv=none; d=zohomail.com; s=zohoarc; b=VA/j6F140w33UFpSQlyClh8TqHaSL+2RMOiGlPRiQs+qMWVJtG67l4Akp7o2qXFxFKuf2JsUPZ6uVnvj2YGUAyDKbMQ7GQ+LEGGubrPtaObcqb4bZ1YUWymt20TQJEy8wZeBj778v6BDN7B3FCn6VezWLTucQvxcL5bqqmxB5HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793315457; h=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=9qvdSaIaK87sVcHW5zbdFmyJqw37YG2nepSnLCDJBSI=; b=VQ3ggHyCDk6J7KXikeql0eIiyJVEp1AjnGbUPMBiz//fzwFhCCPgFYrrxiUAYryz0PTvxVzepE6TlpFSfpYEPMj2JyloxP6n8o3VT+f95rNQSaVMSTNYANAeW/9DAUO5QQN61OUp5sZ3dUqTYyU3K6b8owN2cIOtV3/SB8GqZgw= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793315457478935.4601829869123; Thu, 29 Oct 2026 16:10:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMZGJ-0005py-7B; Thu, 29 Oct 2026 19:10:23 -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 1xMZGF-0005ot-EQ for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMZGB-0004uD-JF for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:18 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-EEwW4pK2MuyndO0idojNxQ-1; Thu, 29 Oct 2026 19:10:13 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1E2A4180ABF2; Thu, 29 Oct 2026 23:10:12 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.61]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F374030002CB; Thu, 29 Oct 2026 23:10:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793315414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9qvdSaIaK87sVcHW5zbdFmyJqw37YG2nepSnLCDJBSI=; b=VGgrrM/J91d1Xky06DdWtQz3ntvoIEsho1yCX/q8nV559tRst2PzBWsZuvYKdGtz/HpjM+ tQ9aA9F8saiDR0+DoriLRTIuJFSdB6qbc5sArq7FoGV1Ng0vGkzxKWMjU+YP7HPkNIN72p A47s7X9hok6gFGftjUnwjMLkbiQ+njw= X-MC-Unique: EEwW4pK2MuyndO0idojNxQ-1 X-Mimecast-MFC-AGG-ID: EEwW4pK2MuyndO0idojNxQ_1793315412 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, mst@redhat.com, devel@lists.libvirt.org, qemu-devel@nongnu.org Subject: [PATCH v2 2/4] virtio-blk-test: Add a basic GET_ID test case Date: Fri, 30 Oct 2026 00:09:59 +0100 Message-ID: <20261029231001.194240-3-kwolf@redhat.com> In-Reply-To: <20261029231001.194240-1-kwolf@redhat.com> References: <20261029231001.194240-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1793315460154158500 Content-Type: text/plain; charset="utf-8" This covers the simple common case with no surprises: A serial that is shorter than 20 characters and can fit in the request buffer. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- tests/qtest/virtio-blk-test.c | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c index 98c906ebb4a..825ea261bed 100644 --- a/tests/qtest/virtio-blk-test.c +++ b/tests/qtest/virtio-blk-test.c @@ -95,6 +95,8 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc= , QVirtioDevice *d, g_assert_cmpuint(data_size % sizeof(struct virtio_blk_discard_write_zeroes), = =3D=3D, 0); break; + case VIRTIO_BLK_T_GET_ID: + break; default: g_assert_cmpuint(data_size, =3D=3D, 0); } @@ -771,6 +773,91 @@ static void resize(void *obj, void *data, QGuestAlloca= tor *t_alloc) =20 } =20 +static QVirtQueue *get_id_setup(QVirtioDevice *dev, QGuestAllocator *t_all= oc) +{ + QVirtQueue *vq; + uint64_t features =3D qvirtio_get_features(dev); + + features =3D features & (1ull << VIRTIO_F_VERSION_1); + qvirtio_set_features(dev, features); + + vq =3D qvirtqueue_setup(dev, t_alloc, 0); + qvirtio_set_driver_ok(dev); + return vq; +} + +static uint8_t get_id_request(QVirtioDevice *dev, QVirtQueue *vq, + char *buf, size_t buf_len, + char pattern_byte, + QGuestAllocator *t_alloc) +{ + QTestState *qts =3D global_qtest; + uint64_t req_addr; + uint32_t free_head; + uint8_t status; + + QVirtioBlkReq req =3D { + .type =3D VIRTIO_BLK_T_GET_ID, + .data =3D buf, + }; + + req_addr =3D virtio_blk_request(t_alloc, dev, &req, buf_len); + + memset(req.data, pattern_byte, buf_len); + memwrite(req_addr + 16, req.data, buf_len); + + free_head =3D qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, buf_len, true, true); + qvirtqueue_add(qts, vq, req_addr + 16 + buf_len, 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status =3D readb(req_addr + 16 + buf_len); + memread(req_addr + 16, buf, buf_len); + + guest_free(t_alloc, req_addr); + + return status; +} + +static void get_id_serial_short(void *obj, void *data, QGuestAllocator *t_= alloc) +{ + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; + QVirtQueue *vq; + uint8_t status; + const char expected[20] =3D "abc"; + char buf[20]; + + vq =3D get_id_setup(dev, t_alloc); + status =3D get_id_request(dev, vq, buf, 20, 0xa5, t_alloc); + g_assert_cmpint(status, =3D=3D, 0); + g_assert_cmpmem(buf, 20, expected, sizeof(expected)); + + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); +} + +static void get_id_serial_short_20_characters(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; + QVirtQueue *vq; + uint8_t status; + /* Edge case of a serial with exactly 20 characters: No NUL terminatio= n */ + const char expected[25] =3D "01234567890123456789\xa5\xa5\xa5\xa5\xa5"; + char buf[25]; + + vq =3D get_id_setup(dev, t_alloc); + status =3D get_id_request(dev, vq, buf, 25, 0xa5, t_alloc); + g_assert_cmpint(status, =3D=3D, 0); + g_assert_cmpmem(buf, 25, expected, sizeof(expected)); + + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); +} + static void *virtio_blk_test_setup(GString *cmd_line, void *arg) { char *tmp_path =3D drive_create(); @@ -802,6 +889,15 @@ static void register_virtio_blk_test(void) qos_add_test("nxvirtq", "virtio-blk-pci", test_nonexistent_virtqueue, &opts); qos_add_test("hotplug", "virtio-blk-pci", pci_hotplug, &opts); + + /* serial number tests */ + opts.edge.extra_device_opts =3D "serial=3Dabc"; + qos_add_test("get_id/serial_short", "virtio-blk", + get_id_serial_short, &opts); + + opts.edge.extra_device_opts =3D "serial=3D01234567890123456789"; + qos_add_test("get_id/serial_short_20_characters", "virtio-blk", + get_id_serial_short_20_characters, &opts); } =20 libqos_init(register_virtio_blk_test); --=20 2.56.0 From nobody Thu Nov 12 15:08:25 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793315464; cv=none; d=zohomail.com; s=zohoarc; b=befQ8SaBlQtFL/EaC5+43RLa8+6hSQlM+119t/WMki9jpLiOSD2sOGpv0E8GIe4rijLO0FPPGC2vtXYfw0PdNyF9ceyzGciPgS6Yg4jd0BkOAA0d4Lh5w6Hwei2B0xTvbdz+JpsYJVVA2D2qM86hSz/xw4TSLeGsoa4p0l69vEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793315464; h=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=X6BP07/9Ge9TgRpSTb8fwLZ1S03ijWtG/KBKK1t/z0s=; b=draXrb7jtKcN8n/H0BvKVYOZwd2pznaMEQ/ovATO3jkI5NThvlLEg/HGy/eUspUSNu9kPhQe0HIMLM040p6r38d6Ik29kFDUXtWk0S//NcX9RswQZdpduGPA0MDHveqfXRspztMqjk3zhOr3URTNBsRippHFAN6qy9eyrqhoqAw= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793315464516320.6038650126558; Thu, 29 Oct 2026 16:11:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMZGY-0005zQ-4L; Thu, 29 Oct 2026 19:10:39 -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 1xMZGH-0005pP-9y for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMZGF-0004vL-81 for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:20 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-313-wA-veBt3PQiTh5hnMlQEDw-1; Thu, 29 Oct 2026 19:10:15 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 86EE4195BDD0; Thu, 29 Oct 2026 23:10:14 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.61]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 847ED30002CB; Thu, 29 Oct 2026 23:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793315417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X6BP07/9Ge9TgRpSTb8fwLZ1S03ijWtG/KBKK1t/z0s=; b=Ru0AzpYqgwmYQ2UQmjY5iJlb5gaMbulRTE2apb/+v/QCS1Iqkt26e4HMHouMN3D6/Cw8Cj qNofEuF8PMUZFUJk5iu/impV0GGXcfxtKW1+zuqhp/Km3RsHULMuchZIBhgCDu7f3Wtdk5 oKJ9bOYZYiGvde+aGPNi1mocQxBT8Rs= X-MC-Unique: wA-veBt3PQiTh5hnMlQEDw-1 X-Mimecast-MFC-AGG-ID: wA-veBt3PQiTh5hnMlQEDw_1793315414 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, mst@redhat.com, devel@lists.libvirt.org, qemu-devel@nongnu.org Subject: [PATCH v2 3/4] virtio-blk: Deprecate silent truncation of serial Date: Fri, 30 Oct 2026 00:10:00 +0100 Message-ID: <20261029231001.194240-4-kwolf@redhat.com> In-Reply-To: <20261029231001.194240-1-kwolf@redhat.com> References: <20261029231001.194240-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1793315466243158501 Content-Type: text/plain; charset="utf-8" Commit a8686a9b, which made serial a qdev property instead of relying on -drive options, accidentally allowed specifying serial strings of arbitraty length while the virtio-blk protocol can only communicate 20 characters to the guest. This means that a longer serial number on the command line is silently truncated to 20 characters from the guest perspective. This is obviously bad behaviour. People are specifying longer serials in practice and guests will see something different than what was configured. Instead of silent truncation, this should be an error. Deprecate the silent truncation for now as a first step towards making it an error later. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- docs/about/deprecated.rst | 13 +++++++++++++ hw/block/virtio-blk.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index dab47b6ca38..0891bbc44de 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -362,6 +362,19 @@ the addition of volatile memory support, it is now nec= essary to distinguish between persistent and volatile memory backends. As such, memdev is depre= cated in favor of persistent-memdev. =20 +``-device virtio-blk,serial=3Dmore_than_20_characters`` (since 11.2) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``virtio-blk`` device has a limitation of 20 characters for the serial +string. Accidentally, QEMU started accepting longer strings on the command= line +in version 0.15.0, but it was still silently truncated to 20 characters for +guests. + +Specifying a longer serial than can be exposed to the guest is a configura= tion +error and deprecated; it will become a hard error in later versions. If the +truncation is intentional, explicitly specify the serial already in trunca= ted +form on the command line instead. + Block device options '''''''''''''''''''' =20 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 3f236f22d57..eeeb405127c 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1849,6 +1849,12 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (conf->serial && strlen(conf->serial) > VIRTIO_BLK_ID_BYTES) { + warn_report("serial is longer than %d characters and will be trunc= ated " + "for the guest. This configuration is deprecated.", + VIRTIO_BLK_ID_BYTES); + } + if (!blkconf_apply_backend_options(&conf->conf, !blk_supports_write_perm(conf->conf= .blk), true, errp)) { --=20 2.56.0 From nobody Thu Nov 12 15:08:25 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793315476; cv=none; d=zohomail.com; s=zohoarc; b=BfBnQRfuMf3jBvOgNp+8Atkf8b0rsJNCh/BnV+h5id1NWxgQ69bVoy70Z3GOR3IP0i00luSB3O3spSJXuKOKDniKovtRvIJKisUEB0iZ6q0pd7IK6df1d7m0beBsivAEyL9QpiKLQxASse59WkCfLXpGGpnHgGGKVCwxSqQqPJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793315476; h=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=nNKsljSIk9V0hYOOIvk0r+0Bu8IdfWwiZAgFL6FJYng=; b=hqArl0gB0NRLCQ9DyEFRWsUGEJhZrQ6k71tpCidh/kaEkZBzlxQ4iveyfCIfkOpft7sfbpykW1QxSfi+pavg12bYR9ku0y4ZYu7GwpHJVtDP87hKV+EcwNWA2pRxS8gLQSniHONaCMGkIEfNlaK80AfVUXFC4RCmgCfdHU60op8= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793315475949328.758610223299; Thu, 29 Oct 2026 16:11:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMZGl-00064b-AS; Thu, 29 Oct 2026 19:10:51 -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 1xMZGJ-0005qt-VY for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMZGH-0004xS-Ty for qemu-devel@nongnu.org; Thu, 29 Oct 2026 19:10:23 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-sLUZQmwKPMiUGKzOeNKARQ-1; Thu, 29 Oct 2026 19:10:18 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 038A6194510F; Thu, 29 Oct 2026 23:10:17 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.61]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC52C30002CB; Thu, 29 Oct 2026 23:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793315421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nNKsljSIk9V0hYOOIvk0r+0Bu8IdfWwiZAgFL6FJYng=; b=A1ACzCG23ME0BR1psaAktmI7uq3+lWa64vhWiT61RUI+a6omV5EWLdIUxNYPhckNuE3Xz3 MyRS9jDDRbU71XDoGkz3pDz++1kocFdl8PbimVpkgKPTjhX7cCG8ydcjCEK+jJBPJXWCpz ZDkbo6WJPKEmzEwnGTsB608otMzD5b0= X-MC-Unique: sLUZQmwKPMiUGKzOeNKARQ-1 X-Mimecast-MFC-AGG-ID: sLUZQmwKPMiUGKzOeNKARQ_1793315417 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, mst@redhat.com, devel@lists.libvirt.org, qemu-devel@nongnu.org Subject: [PATCH v2 4/4] virtio-blk-test: Test truncated serial Date: Fri, 30 Oct 2026 00:10:01 +0100 Message-ID: <20261029231001.194240-5-kwolf@redhat.com> In-Reply-To: <20261029231001.194240-1-kwolf@redhat.com> References: <20261029231001.194240-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1793315478353158500 Content-Type: text/plain; charset="utf-8" Only 20 bytes are written to the passed buffer and the returned string doesn't have a NUL terminator. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- tests/qtest/virtio-blk-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c index 825ea261bed..722bd0711fa 100644 --- a/tests/qtest/virtio-blk-test.c +++ b/tests/qtest/virtio-blk-test.c @@ -858,6 +858,25 @@ static void get_id_serial_short_20_characters(void *ob= j, void *data, qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); } =20 +static void get_id_serial_short_trunc(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; + QVirtQueue *vq; + uint8_t status; + /* Everything after the 20 character maximum is untouched, no '\0' */ + const char expected[25] =3D "01234567890123456789\xa5\xa5\xa5\xa5\xa5"; + char buf[25]; + + vq =3D get_id_setup(dev, t_alloc); + status =3D get_id_request(dev, vq, buf, 25, 0xa5, t_alloc); + g_assert_cmpint(status, =3D=3D, 0); + g_assert_cmpmem(buf, 25, expected, sizeof(expected)); + + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); +} + static void *virtio_blk_test_setup(GString *cmd_line, void *arg) { char *tmp_path =3D drive_create(); @@ -898,6 +917,10 @@ static void register_virtio_blk_test(void) opts.edge.extra_device_opts =3D "serial=3D01234567890123456789"; qos_add_test("get_id/serial_short_20_characters", "virtio-blk", get_id_serial_short_20_characters, &opts); + + opts.edge.extra_device_opts =3D "serial=3D0123456789012345678901234567= 89"; + qos_add_test("get_id/serial_short_trunc", "virtio-blk", + get_id_serial_short_trunc, &opts); } =20 libqos_init(register_virtio_blk_test); --=20 2.56.0