From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 01F46606A322 for ; Fri, 4 Dec 2026 20:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=eCswD4vR; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=mR560Z3a 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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=OJ3y4sZBNMK953EnD3r2gchFL14yy9/qdMM63ShMHpg=; b=eCswD4vRGJaSik3tpIYhCFzsAK GXGtFnHyjNhpw6yzirjEyWd5QLgNsuSoGZIWOHZFzB52aV8bz2HRSirypUMe/T3bcypgXKQ9XxoXS jUVgd27oqm+lJQ1BTAm2uYfMCmeBJJNFV/9UbNIF4aEWC7FeCsqIKnyyPD7RIr8vnuVI9a5vH/ZCe 3EIZ+Q2aH61/KkJ7t6KCbLWbMkE26lTj370xO8KFMWaTGeXmnHz3QSKHEXxfCd/x0CsGj0TTWlW/B kQ/XsfZNWclOPRfz5ne2gTEimKAeck+UjmvNGPNUb5kzrorVTNx/SuvPoqQ34cg88d3t/UnIuLbq3 T+enD79Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZa6x-00000001TLm-0pP7; Fri, 04 Dec 2026 20:42:31 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZa6s-00000001TLD-1AmB for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 20:42:28 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4bb702a7548so8188975e9.1 for ; Fri, 04 Dec 2026 12:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796416942; x=1797021742; darn=lists.infradead.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=OJ3y4sZBNMK953EnD3r2gchFL14yy9/qdMM63ShMHpg=; b=mR560Z3aU6Gu4wiQklhbFMBZW6hqbJ9oaIvSfSW9NMOIl8dxTX2R/3U03YGRQ8AkMN 9LOZxNqL/BXc2UVr0lqt1NmVXbqSwfWKrET52wOj1jCpHXZR1dVAVAzgrcn1ZSApTV88 u5I70W3vBaXwhQXfVCVWLar1Rwm+H0VqllfXslLrNCC7YIchmN74zk2TPVt1ZBJ7agFd fPHK7S9vxscc1ps8+OkHiO7yGjLEM/moP08UHOjCqgyr4Kv7ASQaMNSPj8WGqCm3ZKLF /qXTfyRbzZJ5USQW0/U+SKo4SMDt5A8HmNnhNQjWFUF4zMztsAEg1Mm0qy8+nOw9REF2 KxKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796416942; x=1797021742; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OJ3y4sZBNMK953EnD3r2gchFL14yy9/qdMM63ShMHpg=; b=p2cWrniUeSrGDHkTD52IaSFH2igYtFgg+uCrPbjeI8R6bgWcZ6BapYFOo0TlwAcHsm UT1ObjSiuCNavFZFL1zkiWK74ZSBae+kgEbbG4DEg9P66w8qj+Fg3ygY4cvnzqVfRuNy Mai+zacpJZFS37iAyasP7zTdtXHiivmsujHQP2SNs7JHcYvZsv6j2IuRpTNdu+x9Ag1q av6EsxT6xxGw+1Kskg4PUfk9FZP7wSr3fMKmXMLKzdrb2q/UpgQNBl4JBNAwZD2aWh0w SKCw+2S7Ud856KR3wSjR45UcPi3sWa+As81wdqKjCniTDDYKAm96jypK3UMGN4ML5ejj BnSQ== X-Forwarded-Encrypted: i=1; AL+hErHLex+2kY/9pdzki407uOBIaI3bV5v6flEkx2/0BGmmr3htud7mhOcvvLyMJzxdOeNp8bZEp4p6ObEL+09Rv/BQ@lists.infradead.org X-Gm-Message-State: APuU4Z8CGrHDMT8HE77Yp5twGl5yHXD3qOszEtXRbLNYKKcba9EiMuoR N8YoO3NiqsxLEjiRk674CGJFCDwyFXYOdViPFPGvc0U7injPdFOBRPE11wdMOKKN5A== X-Gm-Gg: AZFdTZcI/hMOPw3B9xHUM7UlVvTbS0hhgWIFSgnFeWljojBburU0lVKULJunNeUdewm 6NMDq/K2YxBCI5Y5lrs43Or/pkwU27JxSa+H85/5wzxWjQ6y4H30PbuorFXhtHxvZLeVrjokWWc OKZHxUnwTJWWfPflN2/SfpamFDaR3+mWlQyfwKMJn51zcDsBcrgocDugFoONFWAklIEfzS97dNP 56ZNT/5xZUCngCUH/qIGeI/ucbFibf+ejfFM6nmnIruDZBQQyfpOvqpQ9ke8E/HmOSuJvrFdY2u wMcpEcJaMnIm0y1iRS7otr1NyPWGC528XncHRQp8ZBVw477hhKQMl2LIedTSKQkryw7RcQzyI47 +HInmQs2hKtv6sf6nsD1fVH8QfogX000aotlI/3mVmuNJfo1EbPO2pmcfh6Eh1KUXFJWt6k5uRI 70d29S60sgDCdqtNTv0X59bs6ZvYOdshjO2QP3/7KYwf241MscoINsndK8iWsEen8QszhpNYs2P x9kIUcxgVI038WcylcgkXc/h+vlXMpqIBHwusSwtK6dCWb0Z261UYOkmJzC9LLQYeJ+xc8jPT+6 vlCC5nv/QWdg+NJh/lMNNb2XRPFm+HfSIaLK8Ap0JknbsieqcVvOSrYMdu6+CiivPNz+N0kBFTT 3K+k+Df48dXJUpMu8IrCTmz06De6laLQ0ubo/PHBT0Q== X-Received: by 2002:a05:600c:e54a:10b0:4bb:7757:fe58 with SMTP id 5b1f17b1804b1-4bbeb8d4973mr40644145e9.19.1796416941734; Fri, 04 Dec 2026 12:42:21 -0800 (PST) Received: from google.com (0.182.34.34.bc.googleusercontent.com. [34.34.182.0]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1723b8b6fsm7545224f8f.10.2026.12.04.12.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:42:21 -0800 (PST) Date: Fri, 4 Dec 2026 20:42:17 +0000 From: Vincent Donnefort To: Robin Murphy Cc: catalin.marinas@arm.com, will@kernel.org, rppt@kernel.org, akpm@linux-foundation.org, m.szyprowski@samsung.com, jenswi@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, "Aneesh Kumar K.V" , Suzuki K Poulose , mark.rutland@arm.com, hch@lst.de, ryan.roberts@arm.com, sumit.garg@kernel.org, sudeep.holla@kernel.org, ardb@kernel.org, thierry.reding@kernel.org, david@kernel.org, danielmentz@google.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, iommu@lists.linux.dev, op-tee@lists.trustedfirmware.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 0/8] arm64: Unmap FF-A lent memory from direct map Message-ID: References: <20261111110738.872947-1-vdonnefort@google.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_124226_794180_7EB77C34 X-CRM114-Status: GOOD ( 43.79 ) X-Spam-Score: -14.5 (--------------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FSL_HELO_FAKE,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Dec 02, 2026 at 03:47:52PM +0000, Robin Murphy wrote: > On 11/11/2026 11:07 am, Vincent Donnefort wrote: > > This series is a follow-up to the discussion that has started here [1]. > > > > When memory is lent to the Secure world via FF-A, CPU speculative > > accesses from NS to the lent pages can still occur as long as it retains > > a cacheable mapping to it. > > > > Ideally, lent memory would be "no-map" but that would mean giving up > > MiBs of useful memory, so let's try to do better with the help of a CMA > > pool. > > > > On arm64, modifying the direct map at runtime is generally restricted > > because the linear map defaults to block mapping and splitting blocks at > > runtime may trigger fatal page fault, unless the CPU implements BBML3 > > or the entire direct map was mapped at page granularity from boot. > > Forcing last-level mappings system-wide incurs a severe penalty we want > > to avoid. Instead, this series introduces targeted last-level mappings > > for designated memory regions, along with a generic "lendable-dma-pool" > > CMA driver to manage unmapping and remapping on lend/reclaim transitions: > > This has a lot of conceptual overlap with the ongoing CoCo work here: > > https://lore.kernel.org/r/20261202095446.2029567-1-aneesh.kumar@kernel.org > > Delegating memory to a Secure TEE should be the exact same thing as > delegating memory to a CCA guest in terms of kernel housekeeping - a page > goes into a different PAS and we can (and must) no longer touch it, that's > that. Shared memory is actually in the same boat too, it's just "delegated" > from a guest back to the host, and while the guest does still touch the > memory in this case, it's still a change of PAS (from Realm back to NS) with > a potentially similar degree of linear map manipulation. The way the isolation is enforced changes what the kernel has to do. On a CCA host, delegation is internal to KVM and doesn't unmap the linear map at all. So there's no abstraction to reuse. That series from Aneesh is strictly guest side, and is about sharing memory (contrary to lending the memory). And just like CCA on the host, it does leave the memory mapped into the linear map. I do not see any abstraction that could be reused either. However, the MEMBLOCK_PTEMAP introduced in this series could benefit CCA guests by having a fixed-size pool known to contain last-level mappings while keeping the rest of the linear map with block mappings. > > I appreciate that there are still differences, like some TEEs only being > prepared to share specific fixed ranges of memory, that justify some new DT > bindings and/or other specific discovery mechanisms, but beyond that can we > please try to converge on a single common abstraction of memory state, > rather than have multiple different implementations of the same thing? Not > to mention the potential for conflicts - what happens if a CCA guest wants > to interact directly with a TEE and tries to delegate a Realm IPA through > this standalone dma-pool mechanism? the lendable-dma-pool doesn't delegate, it only lets the caller zap and restore the stage-1 direct map. The caller transport driver owns the actual delegation protocal. The guest would need to unmap that memory from its linear map. Do CCA guests support FF-A anyway? If it does, it would simply have to call the dma_zap_direct_map() before lending the memory (doesn't even need a pool, since can_set_direct_map() is already true for those guests). -- Vincent > > To me this still looks suspiciously like all the previous vendor-specific > "secure heap" proposals in a trenchcoat... > > Thanks, > Robin. > > > > > 1. memblock: > > - Introduce MEMBLOCK_PTEMAP to force PTE mappings only for a specific region. > > > > 2. dma-mapping: > > - Introduce the "lendable-dma-pool" CMA reserved-memory driver, along with > > generic dma_zap_direct_map() and dma_restore_direct_map() APIs to unmap > > pages from the direct map and restore them. > > > > 3. arm64 direct map support: > > - Implement the "lendable-dma-pool" hooks. > > > > 4. OP-TEE support: > > - Hook OP-TEE dynamic protected memory allocation (tee_shm_alloc_dma_mem()) to > > dma_zap_direct_map() and dma_restore_direct_map(). > > > > Testing: > > ======== > > > > Tested with QEMU v8 using OP-TEE OS (built with CFG_CORE_DYN_PROTMEM=y) > > under both SMC and FF-A transports [2] > > > > static void dump_direct_map(const char *label) > > { > > printf("\n=== %s ===\n", label); > > fflush(stdout); > > system("sed -n '/Linear Mapping start/,/Linear Mapping end/p' /sys/kernel/debug/kernel_page_tables"); > > fflush(stdout); > > } > > > > int main(int argc, char *argv[]) > > { > > int heap_fd; > > int dmabuf_fd; > > struct dma_heap_allocation_data data = { 0 }; > > size_t size = 1024 * 1024; /* 1MB */ > > > > if (argc > 1) > > size = strtoul(argv[1], NULL, 0); > > > > dump_direct_map("BEFORE ALLOCATION"); > > > > heap_fd = open("/dev/dma_heap/protected,secure-video", O_RDWR); > > if (heap_fd < 0) { > > perror("open /dev/dma_heap/protected,secure-video"); > > return 1; > > } > > > > printf("\nOpened /dev/dma_heap/protected,secure-video\n"); > > printf("Allocating %zu bytes of protected memory via DMA heap...\n", size); > > > > data.len = size; > > data.fd_flags = O_RDWR | O_CLOEXEC; > > if (ioctl(heap_fd, DMA_HEAP_IOCTL_ALLOC, &data) < 0) { > > perror("ioctl DMA_HEAP_IOCTL_ALLOC"); > > close(heap_fd); > > return 1; > > } > > > > dmabuf_fd = data.fd; > > printf("Successfully allocated %zu bytes! dmabuf_fd = %d\n", size, dmabuf_fd); > > > > dump_direct_map("DURING LEND (EXPECT HOLE IN DIRECT MAP)"); > > > > printf("\nReleasing dmabuf_fd...\n"); > > close(dmabuf_fd); > > close(heap_fd); > > > > dump_direct_map("AFTER RECLAIM (RESTORED DIRECT MAP)"); > > > > return 0; > > } > > > > [1] https://lore.kernel.org/all/20260807-tegra-vpr-v4-7-5510d16af89e@nvidia.com/ > > [2] https://optee.readthedocs.io/en/latest/building/gits/build.html#qemu-v8 > > > > Changelog: > > > > v3: > > - Replace "arm,ffa-lend-pool" and OP-TEE "memory-region" DT binding with generic > > "lendable-dma-pool" compatible with "linux,cma-default" (Sumit). > > - move conflict check to flag-setting time in memblock_setclr_flag() > > (Mike) > > - Rebase onto v7.4-rc1. > > > > v2 (https://lore.kernel.org/all/20260921110050.3977591-1-vdonnefort@google.com/): > > - Rename MEMBLOCK_LLMAP to MEMBLOCK_PTEMAP (Mike) > > - Warn on conflicting MEMBLOCK_NOMAP and MEMBLOCK_PTEMAP flags (Mike) > > - Drop DT "ll-map" property and mark MEMBLOCK_PTEMAP from ffa_lend_pool_setup() (Rob, Thierry) > > - Drop "reusable" and "no-map" property checks from ffa_lend_pool_setup() (Rob) > > - dt-bindings: Document arm,ffa-lend-pool (Rob) > > - Rework the Optee support with a separate ffa_lend_pool.c file. > > - use walk_kernel_page_table_range_lockless() for > > can_set_direct_map_range() to fix folded page table (Sashiko) > > - Add missing TLB flush in ffa_prepare_lend() > > - Disable hibernation > > - Rebase on linux-next (next-20260918) to use the new set_direct_map*() ranges (Mike) > > > > v1 (https://lore.kernel.org/all/20260902104712.2399797-1-vdonnefort@google.com/) > > > > Vincent Donnefort (8): > > memblock: Introduce MEMBLOCK_PTEMAP > > arm64: Add support for MEMBLOCK_PTEMAP > > dma-contiguous: Expose rmem_cma_ops > > dt-bindings: reserved-memory: Add lendable-dma-pool > > dma-mapping: Introduce lendable-dma-pool > > arm64: Introduce direct_map_is_ptemap() > > arm64: Add support for lendable-dma-pool > > optee: Add support for lendable-dma-pool > > > > .../reserved-memory/lendable-dma-pool.yaml | 58 +++++ > > arch/arm64/Kconfig | 1 + > > arch/arm64/include/asm/set_memory.h | 6 + > > arch/arm64/mm/dma-mapping.c | 71 +++++ > > arch/arm64/mm/mmu.c | 22 +- > > arch/arm64/mm/pageattr.c | 121 ++++++++- > > drivers/tee/optee/protmem.c | 48 +++- > > include/linux/dma-map-ops.h | 9 + > > include/linux/dma-mapping.h | 16 ++ > > include/linux/memblock.h | 9 + > > kernel/dma/Kconfig | 3 + > > kernel/dma/Makefile | 1 + > > kernel/dma/contiguous.c | 4 +- > > kernel/dma/contiguous.h | 10 + > > kernel/dma/lendable.c | 243 ++++++++++++++++++ > > mm/memblock.c | 39 ++- > > 16 files changed, 630 insertions(+), 31 deletions(-) > > create mode 100644 Documentation/devicetree/bindings/reserved-memory/lendable-dma-pool.yaml > > create mode 100644 kernel/dma/contiguous.h > > create mode 100644 kernel/dma/lendable.c > > > > > > base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 >