From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377115; b=F+PUXDhVe4quyyYUf0mhlGxjGfksbiF5OyyrJRFK79T545cAH30WdDpEcbivJFnSIExl To4hYUAxCRKWTt7zuayEdZVpJacy8OUoLhcbaySesvCh41bYb3kiAqx4mDscnVoednKG0 m74OdwRNJYEkzfXHR1hk+7OTXO8W/ZOj3zy3oSGlHtsav3L/o//plo4PhFHvtwwZcymj1 aG3oacCzeFW8U9Rzs1CROPHcZuF3kihljdbOxGPt8BV5GSB3ZGeyRlx1xBgnNq1QmBaFY 9UBJtgOqxOd2h0OYSSMu0bV21yP4kCEVs/kYlyXwxyWqDKrz+nP1lf5s5jWLLUbkDJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377115; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version:X-Scanned-By: X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID:X-Mimecast-Originator: Content-Transfer-Encoding:content-type; bh=+rVmwYdlYJAfSb/k/eD0jQkqYmqEbFRx82yCv4/pvNA=; b=YyQVpRBuMImEaMJv+TFbQFAaD8tEC6Tczh+39wDAB+0e6raRee7mLW0GFfEUItCfrthI /RocgSVmiOeMDwvMSYpxusMBYT4HbYc+YmLp7VaZ45qvJsMcyjMx/ePZkOOMGsApJ2koF tvDqqZ/lEmlnsdzBJ0+PyqDdTxVGRYE+f9Vvv9bV98P6NLjodYEOFSHB/ePYFjjrKFulj rbJ/YycYPFASvdcOWHCIeMpSv5MSkeGRjowLr9+rvfp/7kArBl/wveJTW2Lh8CfMO+ZFo 2KdwehxKV+mbS6x3A3Xe7VOzCe0e273eswhOWBOZmyisJ0sAEgxONI/DVrSU7pQGFMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XB9mkrP7; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 457A2606A322 for ; Fri, 4 Dec 2026 09:38:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 457A2606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XB9mkrP7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796377115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+rVmwYdlYJAfSb/k/eD0jQkqYmqEbFRx82yCv4/pvNA=; b=XB9mkrP79vh+JKYrGP3cG6VBb4p+ERjEw8p9apBNVgIAnBbCOVM/omQfeylkMlPe8TLZa7 eANii0u8VYyvE8LRut1fUGNZ1wJFuhunfrH30WS6CVGjDCMD+lNzIT5oV8vTKLuNivwJfT WxtZH8sirsWhdoEixBYWgVNdMVcvc3A= X-MC-Rep: binary re single 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-83-QJOAo4OWObS4n3bobP5-4g-1; Fri, 4 Dec 2026 09:38:32 +0000 X-MC-Unique: QJOAo4OWObS4n3bobP5-4g-1 X-Mimecast-MFC-AGG-ID: QJOAo4OWObS4n3bobP5-4g_1796377111 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (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 820601889B45 for ; Fri, 4 Dec 2026 09:38:31 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.48.9]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B5B0FB99; Fri, 4 Dec 2026 09:38:29 +0000 (UTC) From: Kevin Wolf To: virtio-comment@lists.linux.dev Cc: kwolf@redhat.com, rjones@redhat.com, stefanha@redhat.com, mst@redhat.com, cohuck@redhat.com Subject: [PATCH 1/1] virtio-blk: Support extended device identifiers Date: Fri, 4 Dec 2026 10:38:04 +0100 Message-ID: <20261204093804.16684-2-kwolf@redhat.com> In-Reply-To: <20261204093804.16684-1-kwolf@redhat.com> References: <20261204093804.16684-1-kwolf@redhat.com> X-Mailing-List: virtio-comment@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Az3Rc7U2qpatF_JkIYGyMWVx2Hcz2omjmk_gn84hoCQ_1796377111 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true So far, VIRTIO_BLK_T_GET_ID requests returned arbitrary ASCII strings that were limited to 20 bytes and had no particular meaning attached. Both of these properties are too limiting for some use cases. While in theory, 20 ASCII bytes are enough to distinguish all devices of a single machine, in practice users want descriptive names and sometimes can't even freely choose the identifier. A common case is conversion of an existing VM from a different device type while keeping the existing (potentially longer) identifier so that the OS can stilll recognise the disk with an identifier it stored before the conversion (e.g. think of /dev/disk/by-id/ paths). A different use case involves identifying the disk with a WWID, which should be separate from the serial and have a defined structure and meaning. This adds a flag VIRTIO_BLK_F_EXT_GET_ID to enable an extended form of the request type that supports multiple different identifier types and identifier lengths up to 255 bytes. There are two noteworthy compatibility considerations: - There are concerns that applications might exist that cannot handle an extension of the existing identifier (now called serial in agreement with the implementations in Linux and QEMU) to more than 20 bytes. While no such applications are known and it is generally expected that new VMs can make use of longer strings without any problems, an alternative device identifcation string is introduced so that a short serial can be kept while still making a longer string available to the driver. - QEMU has an implementation bug that makes it accept a configuration with serials longer than 20 bytes, but truncates it to 20 bytes in VIRTIO_BLK_T_GET_ID. This has no impact on the device behaviour specified in this change, but drivers may want to facilitate upgrades from truncated serials to their full version by exposing the device both with the full serial and a version truncated to 20 bytes (e.g. for symlinks created in udev rules). Signed-off-by: Kevin Wolf --- device-types/blk/description.tex | 80 ++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/device-types/blk/description.tex b/device-types/blk/description.tex index 3b3a4e7..e8408c0 100644 --- a/device-types/blk/description.tex +++ b/device-types/blk/description.tex @@ -73,6 +73,10 @@ \subsection{Feature bits}\label{sec:Device Types / Block Device / Feature bits} VIRTIO_BLK_REQ_FLAG_OUT_FUA flag in the \field{flags} bitfield of the \field{virtio_blk_req} structure for VIRTIO_BLK_T_OUT requests. +\item[VIRTIO_BLK_F_EXT_GET_ID (20)] Device supports the extended version of the + VIRTIO_BLK_T_GET_ID request type, which enables multiple identifier types + and longer values. + \end{description} \subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Block Device / Feature bits / Legacy Interface: Feature bits} @@ -122,7 +126,9 @@ \subsection{Device configuration layout}\label{sec:Device Types / Block Device / le32 max_write_zeroes_sectors; le32 max_write_zeroes_seg; u8 write_zeroes_may_unmap; - u8 unused1[3]; + u8 serial_len; + u8 device_id_len; + u8 scsi_name_len; le32 max_secure_erase_sectors; le32 max_secure_erase_seg; le32 secure_erase_sector_alignment; @@ -222,6 +228,19 @@ \subsection{Device configuration layout}\label{sec:Device Types / Block Device / terminated by the device with a "zone resources exceeded" error as defined for specific commands later. +If the device offers VIRTIO_BLK_F_EXT_GET_ID, the following fields are valid +and contain the length of an identification string in bytes, not including any +trailing NUL characters. A value of 0 means that the respective identifier is +not provided by the device. The fields can be read before the driver accepts +the feature. + +\begin{itemize} +\item \field{serial_len} is the length of the serial string (in previous + versions of the standard the single device ID string). +\item \field{device_id_len} is the length of the secondary device ID string. +\item \field{scsi_name_len} is the length of the SCSI name string. +\end{itemize} + \subsubsection{Legacy Interface: Device configuration layout}\label{sec:Device Types / Block Device / Device configuration layout / Legacy Interface: Device configuration layout} When using the legacy interface, transitional devices and drivers MUST format the fields in struct virtio_blk_config @@ -515,9 +534,45 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope the device to discard the specified range, provided that following reads return zeroes. -VIRTIO_BLK_T_GET_ID requests fetch the device ID string from the device into -\field{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. +VIRTIO_BLK_T_GET_ID requests fetch a device ID string from the device into +\field{data}. + +If the VIRTIO_BLK_F_EXT_GET_ID feature is negotiated, \field{sector} selects +the device identifier type from of the following types: + +\begin{lstlisting} +#define VIRTIO_BLK_ID_SERIAL 0 +#define VIRTIO_BLK_ID_DEVICE_ID 1 +#define VIRTIO_BLK_ID_SCSI_NAME 2 +\end{lstlisting} + +The device identifier types are defined as follows: +\begin{itemize} +\item[VIRTIO_BLK_ID_SERIAL] is an arbitrary NUL-terminated ASCII string (in + previous versions of the standard the single device ID string) serving as + the serial string. +\item[VIRTIO_BLK_ID_DEVICE_ID] is also an arbitrary NUL-terminated ASCII string + and serves as an alternative device identifier primarily for cases where + the serial string cannot be extended beyond the traditional 20 bytes limit + for compatibility reasons, but a longer identification string is still + needed. +\item[VIRTIO_BLK_ID_SCSI_NAME] is a NUL-terminated UTF-8 string to be + interpreted as a SCSI name string as defined by the SCSI Primary Commands + specification for VPD page 83h, designator type 8h. +\end{itemize} + +The length field in the device configuration structure is of type u8 for all +device identifier types, which limits their length to 255 bytes plus the +terminating NUL byte. + +If \field{data} is longer than the requested device identifier including the +terminating NUL byte, the device will put the device identifier at the start of +\field{data} and the value of the remaining bytes in \field{data} is undefined. + +If the VIRTIO_BLK_F_EXT_GET_ID feature is not negotiated, the request always +fetches the serial string, which is then a NUL-padded (not only NUL-terminated) +ASCII string up to 20 bytes long. If the string is 20 bytes long, then there +is no NUL terminator. The \field{data} used for VIRTIO_BLK_T_GET_LIFETIME requests is populated by the device, and is of the form @@ -911,7 +966,11 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope virtio_blk_discard_write_zeroes for VIRTIO_BLK_T_DISCARD, VIRTIO_BLK_T_SECURE_ERASE and VIRTIO_BLK_T_WRITE_ZEROES requests. -The length of \field{data} MUST be 20 bytes for VIRTIO_BLK_T_GET_ID requests. +If VIRTIO_BLK_F_EXT_GET_ID is not negotiated, the length of \field{data} MUST +be 20 bytes for VIRTIO_BLK_T_GET_ID requests and \field{sector} SHOULD be 0. + +If VIRTIO_BLK_F_EXT_GET_ID is negotiated, \field{sector} MUST be a valid device +identifier type. VIRTIO_BLK_T_DISCARD requests MUST NOT contain more than \field{max_discard_seg} struct virtio_blk_discard_write_zeroes segments in @@ -1070,6 +1129,17 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope for implementations that do not wish to be safe against such data losses. \end{note} +If in a VIRTIO_BLK_T_GET_ID request, \field{data} is too short to keep the full +device identifier, the device SHOULD set \field{status} to VIRTIO_BLK_S_IOERR +and SHOULD NOT write to \field{data}. If VIRTIO_BLK_F_EXT_GET_ID was not +negotiated, but the serial string of the device is longer than 20 bytes, this +is always the case. + +If VIRTIO_BLK_F_EXT_GET_ID was negotiated and \field{sector} does not contain a +valid device identifier type or the specified device identifier type is not +available on the device, the device MUST set \field{status} to +VIRTIO_BLK_S_UNSUPP and MUST NOT write to \field{data}. + If the device is backed by storage providing lifetime metrics (such as eMMC or UFS persistent storage), the device SHOULD offer the VIRTIO_BLK_F_LIFETIME flag. The flag MUST NOT be offered if the device is backed by storage for which -- 2.56.1