[PATCH v1 00/11] FBE virtualization: inline encryption for virtio-blk guests
Linlin Zhang <[email protected]>
| Newsgroups | dev.linux.lists.virtualization,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-block,org.kernel.vger.linux-crypto,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.linux-scsi |
|---|---|
| Message-ID | <[email protected]> |
From: linlzhan <[email protected]> Current virtio-blk does not provide a mechanism for a guest to program hardware keys or submit encrypted I/O using pre-programmed keyslots. It drops the crypto context when issuing a bio request to the virtio-blk queue, preventing inline-encryption-based FBE on virtio block devices. This series enables File-Based Encryption in guest VMs on Qualcomm GVM platforms where the ICE inline encryption hardware is shared between the host and guests. In this environment the guest kernel has no access to the ICE hardware directly; it supplies a virtual keyslot index and data unit number with each encrypted I/O request via VIRTIO_BLK_F_INLINE_ENCRYPTION, and the host must translate the virtual slot to a physical ICE keyslot and submit the bio — without transferring raw key material across the VM boundary. +----------------------------------------------------------------+ | | | LA GVM | | | | | | | | | | | | | +------v------+ | | +----y-----------+ blk-mq | | | | +-------+-----+ | | | | | | | | | | +----------v-----------+ | | | |blk-crypto-profile +------------v | | +----------------------+ | | | | | | | | | Control path: | | | generate/import/prepare key | | | program/evict/derive_sw_secret key | | +----------+ | | | | | |+-------------+ +-----------------------+ +-----v-----+ | |Trust Zone| || crypto-virt <-----+ virtio-blk-crypto-ext <-----+virtio-blk | | | | |+------+------+ +-----------------------+ +-----+-----+ | | | | | Data path: I/O | +-------^--+ +-------+------------------------------------------------+-------+ | SMC|call (virt_slot, DUN, DUSize) | | appended in virtblk_req +---+------------v------------------------------------------------v----------+ | +--------------+ +--------------------------+ | | | SMC trap | Hypervisor | MMIO trap/VIRQ injection | | +--+--------------+-----------------------------+--------------------------+ + +--------------------------------------------------------------------------------------------+ | PVM | | | | Crypto IO +--------------+ | +-+--------------> QEMU/Crosvm +-------+ | | | +--------------+ IO data | | | virt_slot, DUN, DUSize | | | | | | |+----------------+ +--------- -v-----+ | | || blk-crypto <-------+ blk-crypto-proxy+-------------+----------------------+ | | |+----------------+ +-----------+-----+ | | | | | slot path based | | | | | bio_crypt_ctx | | | | |+-----------------------+ +--- v----+ | | | | || blk-crypto-profile <---x---+ blk-mq | bcp_hypervisor_ops | | | |+-----------------------+ +----+----+ | | | | | | | bcp_slot_virt_ops | | | +-----------v-----+ | | | | | | SCSI | | | | | | +-----------+-----+ | | | | | | | | | | | crypto msg in UTRD | | | | | |+----------------------+ +----v-----+ +----------v-- ---------+ +-------v--- ------+| | || ufs crypto <--------+ ufs-core | |blk-crypto-hyp-backend | | keyslot-partition|| | |+----------------------+ +-----+----+ +-----------------------+ +------------------+| | +--------------------------------------+-----------------------------------------------------+ | | | | +-----------------------------------+ +--v---+-----------+ | +------------------------+ | | ICE | UFS | ||MMIO trap/VIRQ injection | HYP | +------+-----------+ + +------------------------+--------+ Patches 1-3 land in the guest kernel. Patch 1 negotiates VIRTIO_BLK_F_INLINE_ENCRYPTION and wires it into blk-crypto. Patches 2-3 add the Qualcomm GVM-side crypto backend, which routes key programming and software-secret derivation through SCM calls to TrustZone. These patches are sent for review; the virtio-blk inline encryption protocol is also under review (see https://lore.kernel.org/all/[email protected]/). These patches and the virtio-spec depend on each other. They must be kept consistent for upstream merging. Patch 4 adds the dt-binding for the Qualcomm crypto-virt node used by the guest-side backend. Patch 5 introduces a "slot path" in blk-crypto that lets a bio carry a pre-programmed physical ICE keyslot index in bc_slot rather than a blk_crypto_key pointer (bc_key == NULL). This is needed on the host side where the hypervisor has already programmed the keyslot; the host kernel has no access to the raw key. Patch 6 extends ufshcd_prepare_lrbp_crypto() to handle this path. Patch 7 moves bio_crypt_dun_increment() to the public header so it can be called from drivers/block/. Patch 8 adds /dev/blk-crypto-proxy, a misc character device for userspace virtio-blk backends. The interface is three ioctls: BCP_BIND_CONTEXT binds a host block device fd and a hypervisor VM fd; BCP_GET_CRYPTO_CAPS queries the device's inline-crypto capabilities and the VM's ICE keyslot allocation; BCP_SUBMIT_IO_BY_VSLOT resolves a guest virtual slot to a physical ICE keyslot and submits the inline-encrypted bio synchronously. The driver is hypervisor-agnostic and storage-vendor-agnostic, using two pluggable op-sets registered by platform drivers at runtime. Patch 9 implements bcp_slot_virt_ops for Qualcomm platforms: it parses a qcom,ice-keyslot-map device-tree node that maps each guest_id to a contiguous physical keyslot range. Patch 10 adds slot_offset to struct blk_crypto_profile so that blk_crypto_keyslot_index() returns the correct physical slot number when the host's ICE range does not start at slot 0. Patch 11 extends ufs-qcom to read the host's own slot reservation from the same DT node and initialize the blk_crypto_profile accordingly. Patches 1-4 are technically ready for review. However, since they depend on the proposed virtio-blk inline encryption protocol, progress on these patches is expected to follow consensus on the protocol design. Feedback on the overall architecture is therefore particularly valuable, as it will also help advance the associated virtio-spec work. Patches 5-8 implement the core host-side infrastructure and are believed ready for review. Patches 9-11 do not depend on any hypervisor-specific code. Of them, patches 9 and 11 provide the Qualcomm platform implementation based on a static device-tree keyslot mapping; this may be revised in a future version to use a TZ SCM query interface. The kernel-internal header declares bcp_hypervisor_ops, which translates a hypervisor VM fd to an opaque guest_id. No upstream implementation is included in this series because the series was validated on a downstream Qualcomm GVM platform using the Gunyah hypervisor, which provides a stable per-VM identifier but is not yet upstream. KVM does not currently expose an externally-visible per-VM identifier that a kernel module could use for this purpose. Input from KVM maintainers on whether and how such an interface could be added, or whether an alternative identity mechanism is preferred, would be welcome. Known limitations ------- - Only AES-256-XTS has been tested. - virtio_blk_crypto_msg.dun is a fixed __virtio64; the driver refuses to enable inline crypto if the device advertises max_dun_bytes > 8 to prevent silent IV truncation and reuse. - Inline encryption is mutually exclusive with VIRTIO_BLK_F_ZONED. - The qcom_ice_slots driver uses a global singleton and ignores the blk_crypto_profile argument to its callbacks, so multiple storage controllers sharing a single slot table are not yet supported. - BCP_SUBMIT_IO_BY_VSLOT submits each bio synchronously with submit_bio_wait(); concurrent in-flight bios from multiple threads sharing one fd are not supported. Testing ------- Compilation pass on Linux-next. End-to-end FBE virtualization with wrapped key enabled was validated on top of gunyah hypervisor. wrapped_key_test is a local utility to get wrapped key and ephemeral wrapped key via storage ioctl interfaces. - /data/wrapped_key_test /dev/block/userdata generate - /data/wrapped_key_test /dev/block/userdata prepare /data/lt_key.bin - /data/fscryptctl insert_wrapped_key < /data/eph_key.bin - /data/fscryptctl set_policy --identifier=20f553802e64e36b43469211266a5f1c /data/testing - echo "data" > /data/testing/file.txt - sync and reboot - /data/wrapped_key_test /dev/block/userdata prepare /data/lt_key.bin - /data/fscryptctl insert_wrapped_key < /data/eph_key_2.bin - /data/fscryptctl set_policy --identifier=d8ca51d6d2094b73b2dae5ee7e3a10b6 /data/testing - cat /data/testing/file.txt linlzhan (11): virtio_blk: add inline encryption support soc: qcom: add crypto_virt backend for virtio-blk inline crypto soc: qcom: crypto_virt: add support for create, prepare and import keys dt-bindings: soc: qcom: add binding for qcom,crypto-virt blk-crypto: add slot-based inline encryption path scsi: ufs: core: add slot path to ufshcd_prepare_lrbp_crypto blk-crypto: move bio_crypt_dun_increment() to the public header block: add /dev/blk-crypto-proxy for host-side virtio-blk inline encryption soc: qcom: add ICE keyslot partitioning driver for guest VMs blk-crypto: add slot_offset to blk_crypto_profile scsi: ufs: ufs-qcom: support ICE keyslot partitioning for guest VMs .../bindings/soc/qcom/qcom,crypto-virt.yaml | 39 + block/blk-crypto-internal.h | 5 +- block/blk-crypto-profile.c | 7 +- block/blk-crypto.c | 57 +- drivers/block/Kconfig | 28 + drivers/block/Makefile | 3 + drivers/block/blk-crypto-proxy.c | 667 ++++++++++++++++++ drivers/block/virtio_blk.c | 199 +++++- drivers/block/virtio_blk_crypto_ext.c | 283 ++++++++ drivers/soc/qcom/Kconfig | 30 + drivers/soc/qcom/Makefile | 2 + drivers/soc/qcom/crypto_virt.c | 197 ++++++ drivers/soc/qcom/qcom_ice_slots.c | 232 ++++++ drivers/ufs/core/ufshcd-crypto.h | 14 +- drivers/ufs/host/ufs-qcom.c | 91 ++- include/linux/blk-crypto-profile.h | 9 + include/linux/blk-crypto-proxy.h | 100 +++ include/linux/blk-crypto.h | 28 + include/linux/virtio_blk_crypto_ext.h | 78 ++ include/uapi/linux/blk-crypto-proxy.h | 122 ++++ include/uapi/linux/virtio_blk.h | 62 ++ 21 files changed, 2224 insertions(+), 29 deletions(-) create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,crypto-virt.yaml create mode 100644 drivers/block/blk-crypto-proxy.c create mode 100644 drivers/block/virtio_blk_crypto_ext.c create mode 100644 drivers/soc/qcom/crypto_virt.c create mode 100644 drivers/soc/qcom/qcom_ice_slots.c create mode 100644 include/linux/blk-crypto-proxy.h create mode 100644 include/linux/virtio_blk_crypto_ext.h create mode 100644 include/uapi/linux/blk-crypto-proxy.h -- 2.34.1