From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B432FF8850 for ; Mon, 27 Apr 2026 06:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=C+WzWmZGxytZvimCMV4gQU1Ld7CSCylOvbslEQrK6Rg=; b=vmTp3JvzMVjlolagQekSrwjG1D KcH0khrb4p6++KimPday2183F3IJ2bo/aZ33vfncVYnOyI24PKeDoLavvGjQ6ph4IxonOjg45TrT/ nCElmhjF7a44cO34QSLJbJML++Ms6b08nj2PX1ozMotioipzZ+5HL0+B2qofzwBMZND9no5pWKFJ0 8Q+ud9O8z3zqHzSKXgLdOfX8v5o4t6EQJUkVoWJ4dZEWx1/OYfuKlpOk/904JX3MuBl5wFFBOhpYn +6OQKdtHrN2HweuJov6YA4H8OnAg1QOPUFxA/TDofY41EPec6v+PqnLYjn7CaaxR6k/rVeLQv+sJl 2HdB636g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wHFV2-0000000GGV6-2b5K; Mon, 27 Apr 2026 06:31:20 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wHFUz-0000000GGUk-3hLP for linux-arm-kernel@lists.infradead.org; Mon, 27 Apr 2026 06:31:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id B94054091D; Mon, 27 Apr 2026 06:31:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9294DC19425; Mon, 27 Apr 2026 06:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777271476; bh=TT3ZABo3gdbLCPLVCA/3gAb1IpW94r3+NRwJmZ4Vdas=; h=From:To:Cc:Subject:Date:From; b=r44Pt2ZR8rT+xlusdriUwtEEiy0YDkqD78pNWIlbVj1zLLqmVZqNduCbhvByi5Gj1 EY0vxn4WO9IibbXFwfukUBlRyxBywJQDBgAsApZqir9RmRIX4wWwnCKMPhd8rFvkW9 rM+wvm9fdz+dI/adkMdR5TWdwGljh/eQxGjfEOCHvOC/iq7w1U9A9mVM3beYdOqvFY IeuXC0ThOAbGcl9mBXzDBj9DzSRRtv6lshW7bFFILIha/gOM3qsAL9O7TiP42nXf04 x+kpAWvF/LB0JbnIZ1fqUqkSZ/YSEm8UajaIMvm3/AhI4Ps4rMbwvyp7YkLJyAIMi9 igb4TCgupRd1A== From: "Aneesh Kumar K.V (Arm)" To: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-coco@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Catalin Marinas , Jason Gunthorpe , Marc Zyngier , Marek Szyprowski , Robin Murphy , Steven Price , Suzuki K Poulose , Thomas Gleixner , Will Deacon Subject: [PATCH v4 0/3] Enforce host page-size alignment for shared buffers Date: Mon, 27 Apr 2026 12:01:05 +0530 Message-ID: <20260427063108.909019-1-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260426_233117_977730_C75D8A20 X-CRM114-Status: GOOD ( 18.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi all, This patch series addresses alignment requirements for buffers shared between private-memory guests and the host. When running private-memory guests, the guest kernel must apply additional constraints when allocating buffers that are shared with the hypervisor. These shared buffers are also accessed by the host kernel and therefore must be aligned to the host’s page size. Architectures such as Arm can tolerate realm physical address space PFNs being mapped as shared memory, as incorrect accesses are detected and reported as GPC faults. However, relying on this mechanism alone is unsafe and can still lead to kernel crashes. This is particularly likely when guest_memfd allocations are mmapped and accessed from userspace. Once exposed to userspace, it is not possible to guarantee that applications will only access the intended 4K shared region rather than the full 64K page mapped into their address space. Such userspace addresses may also be passed back into the kernel and accessed via the linear map, potentially resulting in a GPC fault and a kernel crash. To address this, the series introduces a new helpers, mem_decrypt_granule_size() and mem_decrypt_align(), which allows callers to enforce the required alignment for shared buffers. Changes from v3: https://lore.kernel.org/all/20260309102625.2315725-1-aneesh.kumar@kernel.org * Fix build error reported by kernel test robot Changes from v2: https://lore.kernel.org/all/20251221160920.297689-1-aneesh.kumar@kernel.org * Rebase to latest kernel * Consider swiotlb always decrypted and don't align when allocating from swiotlb. Changes from v1: * Rename the helper to mem_encrypt_align * Improve the commit message * Handle DMA allocations from contiguous memory * Handle DMA allocations from the pool * swiotlb is still considered unencrypted. Support for an encrypted swiotlb pool is left as TODO and is independent of this series. Cc: Catalin Marinas Cc: Jason Gunthorpe Cc: Marc Zyngier Cc: Marek Szyprowski Cc: Robin Murphy Cc: Steven Price Cc: Suzuki K Poulose Cc: Thomas Gleixner Cc: Will Deacon Aneesh Kumar K.V (Arm) (3): dma-direct: swiotlb: handle swiotlb alloc/free outside __dma_direct_alloc_pages swiotlb: dma: its: Enforce host page-size alignment for shared buffers coco: guest: arm64: Query host IPA-change alignment via RHI arch/arm64/include/asm/mem_encrypt.h | 3 ++ arch/arm64/include/asm/rhi.h | 24 ++++++++++++ arch/arm64/include/asm/rsi.h | 2 + arch/arm64/include/asm/rsi_cmds.h | 10 +++++ arch/arm64/include/asm/rsi_smc.h | 7 ++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/rhi.c | 54 ++++++++++++++++++++++++++ arch/arm64/kernel/rsi.c | 13 +++++++ arch/arm64/mm/mem_encrypt.c | 27 +++++++++++-- drivers/irqchip/irq-gic-v3-its.c | 20 ++++++---- include/linux/mem_encrypt.h | 14 +++++++ kernel/dma/contiguous.c | 10 +++++ kernel/dma/direct.c | 58 ++++++++++++++++++++++++---- kernel/dma/pool.c | 4 +- kernel/dma/swiotlb.c | 21 ++++++---- 15 files changed, 240 insertions(+), 29 deletions(-) create mode 100644 arch/arm64/include/asm/rhi.h create mode 100644 arch/arm64/kernel/rhi.c -- 2.43.0