[PATCH v1] virtio-blk: Add inline encryption support
Linlin Zhang <[email protected]> Tue, 27 Jan 2026 22:14:32 +0800
| Newsgroups | dev.linux.lists.virtio-dev |
|---|---|
| Message-ID | <[email protected]> |
From: linlzhan <[email protected]> Inline encryption on virtio block can only be supported when the new feature bit VIRTIO_BLK_F_ICE is negotiated. Extend struct virtio_blk_config and struct virtio_blk_req, so that crypto capabilities can be got in the frontend and encryption metadata can be sent to the backend, together with each I/O transaction. Signed-off-by: linlzhan <[email protected]> --- device-types/blk/description.tex | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/device-types/blk/description.tex b/device-types/blk/description.tex index 2712ada..23d8dc0 100644 --- a/device-types/blk/description.tex +++ b/device-types/blk/description.tex @@ -66,6 +66,11 @@ \subsection{Feature bits}\label{sec:Device Types / Block Device / Feature bits} (ZNS). For brevity, these standard documents are referred as "ZBD standards" from this point on in the text. +\item[VIRTIO_BLK_F_ICE(22)] Inline Crypto Extensions are supported. When this + is negotiated, the device exposes crypto characteristics in configuration + space and the driver SHALL provide an extended request header containing a + crypto payload for block I/O. + \end{description} \subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Block Device / Feature bits / Legacy Interface: Feature bits} @@ -128,6 +133,11 @@ \subsection{Device configuration layout}\label{sec:Device Types / Block Device / u8 model; u8 unused2[3]; } zoned; + struct virtio_blk_crypto_characteristics { + __virtio16 slot_info; + __virtio16 reserved; + __virtio32 capability; + } crypto; }; \end{lstlisting} @@ -215,6 +225,25 @@ \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 VIRTIO_BLK_F_ICE feature is negotiated, then in +\field{virtio_blk_crypto_characteristics}, +\begin{itemize} +\item \field{slot_info} value packs two 8-bits values: + \begin{itemize} + \item Bits~\[15:8] (\emph{max\_slots}): the maximum number of supported + crypto key slots. + \item Bits~\[7:0] (\emph{slot\_offset}): an offset applied to slot numbering. + \end{itemize} +\item \field{capability} value packs four 8-bits values: + \begin{itemize} + \item Bits~\[31:24]: crypto algorithm id. + \item Bits~\[23:16]: mask of data unit size. + \item Bits~\[15:8]: crypto key size. + \item Bits~\[7:0]: unused. + \end{itemize} +\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 @@ -278,6 +307,10 @@ \subsection{Device Initialization}\label{sec:Device Types / Block Device / Devic \field{zoned} can be read by the driver to determine the zone characteristics of the device. All \field{zoned} fields are read-only. +\item If the VIRTIO_BLK_F_ICE feature is negotiated, the fields in + \field{crypto} can be read by the driver to determine the inline crypto + characteristics of the device. All \field{crypto} fields are read-only. + \end{enumerate} \drivernormative{\subsubsection}{Device Initialization}{Device Types / Block Device / Device Initialization} @@ -317,6 +350,9 @@ \subsection{Device Initialization}\label{sec:Device Types / Block Device / Devic driver SHOULD ignore all other fields in \field{zoned}. \end{itemize} +If the VIRTIO_BLK_F_ICE feature is negotiated, then the driver must validate + the max_slots in \field{slot_info} before the slot usage. + \devicenormative{\subsubsection}{Device Initialization}{Device Types / Block Device / Device Initialization} Devices SHOULD always offer VIRTIO_BLK_F_FLUSH, and MUST offer it @@ -402,6 +438,16 @@ \subsection{Device Initialization}\label{sec:Device Types / Block Device / Devic \item the device MUST initialize padding bytes \field{unused2} to 0. \end{itemize} +If the VIRTIO_BLK_F_ICE feature is negotiated, then the fields in \field{cryto} +struct in the configuration space MUST be set by the device. +\begin{itemize} +\item the \field{slot_info} field of \field{crypto} MUST be set by the device to a + max_slots in the higher 8 bits and slot_offset in the lower 8 bits. + +\item the \field{capability} field of \field{crypto} MUST be set by the device + to a crypto capability read from the storage register. +\end{itemize} + \subsubsection{Legacy Interface: Device Initialization}\label{sec:Device Types / Block Device / Device Initialization / Legacy Interface: Device Initialization} Because legacy devices do not have FEATURES_OK, transitional devices @@ -436,6 +482,13 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope le32 type; le32 reserved; le64 sector; + struct virtio_blk_crypto_payload { + u8 slot; + u8 activate; + le16 reserved1; + le32 reserved2; + le64 data_unit_num; + } payload; u8 data[]; u8 status; }; @@ -463,6 +516,20 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope the read or write is to occur. This field is unused and set to 0 for commands other than read, write and some zone operations. +The \field{payload} consists of the encryption information for current +request. It need to be set by the driver only when the feature VIRTIO_BLK_F_ICE +is negotiated. +\begin{itemize} +\item The \field{slot} filed in \field{payload} indicates the ICE + (Inline Crypto Encryption) slot index where the key resides in. + +\item The \field{activate} filed in \field{payload} implies this is a + encryption request. + +\item The \field{data_unit_num} filed in \field{payload} indicates the + starting block of the request. +\end{itemize} + VIRTIO_BLK_T_IN requests populate \field{data} with the contents of sectors read from the block device (in multiples of 512 bytes). VIRTIO_BLK_T_OUT requests write the contents of \field{data} to the block device (in multiples @@ -912,6 +979,8 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope successfully, failed, or were processed by the device at all if the request failed with VIRTIO_BLK_S_IOERR. +A driver MUST set \field{activate} to 0 for a non VIRTIO_BLK_F_ICE request. + The following requirements only apply if the VIRTIO_BLK_F_ZONED feature is negotiated. -- 2.34.1