From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.118.77.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794989141; b=G/Z+VkC9mobuuZAB3W2FtxiYs+TQkoxwa4NQcXQRb3VOn0S01c2nS+uerXNOhiiuc55k DuyRDeessUR4H8pzlJ38u5M59Uk1y0zVE1LD4Wm12b8KgufApjkX27yTBahZiaap3mPNP Rz+AzwsC5ekos3vxX8gGE/37lYbwEv9uVHVcqghoKqJMmAwZarz/xBXHRUedOAsDadoRX AYE8YE4k8jwHNp61RvTQPfjtcEkmNuPXIQggJBpX6KC2mY78MMB4REKL7MhuFR7Y8Qopj euGXM9lzPmgGFBbpKPVSnGZUPhj1cxFO9sgNcuya0oP2NBWbSnrgmjan0ZU8jtIJF2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794989141; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: Content-Language:From:In-Reply-To:Content-Transfer-Encoding: X-CMS-MailID:X-Msg-Generator:Content-Type:X-RootMTR:X-EPHeader: X-CMS-RootMailID:References; bh=D6wcvXz+3VFjmwaXZqu53OPZKJ3AhVArDX6YTdc8W4E=; b=IZZDkgVDxQFti+XrYPKyR3Ugm3QK+nrIfeWTIxmoZ1o12DzhV0Nq8tk/e94lxGmzcWKN awSaFY1WpCdOXO1zIOJzP+Z+qiyQyHQL1sNIF1+tz9X5OmaEfTOa+tOi65zA1VaPRQndu x/osrlJfVWHjlHOa7a65DIUzgLFqJ9E3rSvhYQJwuPBvezpGz2Udc7Ug37r2aOOo0uI3z tIFmMi4sGn3bn0kEEHquq5iifwLoiw31OY0IEl6W2lJ5odaMKxTa8WoxwVZD0nTwgt5N4 yZvtvJZVIDlkZbbnzQVRUBO/RoBO01hE6z0Y5I871h2Z+fyFcg91uJ4k5+rdeMGInXQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=aKdqcyhG; arc=none smtp.remote-ip=210.118.77.12 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80644606A325 for ; Wed, 18 Nov 2026 08:05:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80644606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=aKdqcyhG Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20261118080536euoutp02e06613bcab245e1682db5a1acb3b5dff~pFRwFPIaS2412924129euoutp02c for ; Wed, 18 Nov 2026 08:05:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20261118080536euoutp02e06613bcab245e1682db5a1acb3b5dff~pFRwFPIaS2412924129euoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1794989136; bh=D6wcvXz+3VFjmwaXZqu53OPZKJ3AhVArDX6YTdc8W4E=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=aKdqcyhGFaiQHwYEXFHR+D2kPlLirVWKgp/AFFxw/eNnJGJIRz9+vXUSujwa70g+j rfkLIK5cYprST4iPTbgbMH9XNL0iJjg3nkVgKI127PhdnWu0IB4Ym/TNWjtdIckRAQ N8vLCZsOhxh+DetlQuUdkga13JrKpJzqgsd1mZws= Received: from eusmtip1.samsung.com (unknown [203.254.199.221]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20261118080536eucas1p250aaaa4c5a74f1d8ea77b05ae499c208~pFRvmAThv0498604986eucas1p2B; Wed, 18 Nov 2026 08:05:35 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20261118080534eusmtip1f0c261bfe6ce1a4f8ad61f83e303149e~pFRukqbHp2329623296eusmtip1s; Wed, 18 Nov 2026 08:05:34 +0000 (GMT) Message-ID: Date: Wed, 18 Nov 2026 09:05:34 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Betterbird (Windows) Subject: Re: [PATCH] dma-buf: heaps: system: zero pages after set_memory_decrypted() To: Ying Xiao , Sumit Semwal , "T . J . Mercier" , Jiri Pirko Cc: Jason Gunthorpe , Benjamin Gaignard , Brian Starkey , John Stultz , =?UTF-8?Q?Christian_K=C3=B6nig?= , Philipp Stanner , Jacob Moroni , Xuehao Hu , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Content-Language: en-US From: Marek Szyprowski In-Reply-To: <20261117155431.1654298-1-eagleshaw@google.com> Content-Transfer-Encoding: 7bit X-CMS-MailID: 20261118080536eucas1p250aaaa4c5a74f1d8ea77b05ae499c208 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20261117155436eucas1p2fa7d030f5557d1c88d943226d65f69ca X-EPHeader: CA X-CMS-RootMailID: 20261117155436eucas1p2fa7d030f5557d1c88d943226d65f69ca References: <20261117155431.1654298-1-eagleshaw@google.com> On 17.11.2026 16:54, Ying Xiao wrote: > system_heap_allocate() allocates pages via order_flags[] with __GFP_ZERO > while the direct map still has the memory encryption bit set. For the > system_cc_shared heap, set_memory_decrypted() subsequently clears the > encryption bit without re-zeroing, leaving ciphertext in DRAM on > confidential computing (CoCo) guests instead of plaintext zeros. > > Skip __GFP_ZERO during alloc_pages() for cc_shared allocations, and zero > the pages once in system_heap_set_page_decrypted() after > set_memory_decrypted() succeeds. > > Fixes: 78b30c50a7ac ("dma-buf: heaps: system: add system_cc_shared heap for explicitly shared memory") > Reviewed-by: Jacob Moroni > Signed-off-by: Ying Xiao Acked-by: Marek Szyprowski > --- > drivers/dma-buf/heaps/system_heap.c | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c > index c8959eadc71d..5f98d0df11e7 100644 > --- a/drivers/dma-buf/heaps/system_heap.c > +++ b/drivers/dma-buf/heaps/system_heap.c > @@ -72,11 +72,19 @@ static int system_heap_set_page_decrypted(struct page *page) > int ret; > > ret = set_memory_decrypted(addr, nr_pages); > - if (ret) > + if (ret) { > pr_warn_ratelimited("dma-buf system heap: failed to decrypt page at %p\n", > page_address(page)); > + return ret; > + } > > - return ret; > + /* > + * Clearing the encryption bit does not clear DRAM, leaving ciphertext > + * from when the page was encrypted. Zero it now that it is decrypted. > + */ > + memset((void *)addr, 0, (size_t)nr_pages << PAGE_SHIFT); > + > + return 0; > } > > static int system_heap_set_page_encrypted(struct page *page) > @@ -376,7 +384,8 @@ static const struct dma_buf_ops system_heap_buf_ops = { > }; > > static struct page *alloc_largest_available(unsigned long size, > - unsigned int max_order) > + unsigned int max_order, > + bool cc_shared) > { > struct page *page; > int i; > @@ -388,6 +397,12 @@ static struct page *alloc_largest_available(unsigned long size, > if (max_order < orders[i]) > continue; > flags = order_flags[i]; > + /* > + * Zeroing while encrypted is wasted since decryption leaves > + * ciphertext; system_heap_set_page_decrypted() zeroes instead. > + */ > + if (cc_shared) > + flags &= ~__GFP_ZERO; > if (mem_accounting) > flags |= __GFP_ACCOUNT; > page = alloc_pages(flags, orders[i]); > @@ -438,7 +453,8 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, > goto free_buffer; > } > > - page = alloc_largest_available(size_remaining, max_order); > + page = alloc_largest_available(size_remaining, max_order, > + cc_shared_buffer(buffer)); > if (!page) > goto free_buffer; > Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland