From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Ying Xiao <eagleshaw@google.com>,
Sumit Semwal <sumit.semwal@linaro.org>,
"T . J . Mercier" <tjmercier@google.com>,
Jiri Pirko <jiri@nvidia.com>
Cc: "Jason Gunthorpe" <jgg@nvidia.com>,
"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
"Brian Starkey" <Brian.Starkey@arm.com>,
"John Stultz" <jstultz@google.com>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Jacob Moroni" <jmoroni@google.com>,
"Xuehao Hu" <xuehaohu@google.com>,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-buf: heaps: system: zero pages after set_memory_decrypted()
Date: Wed, 18 Nov 2026 09:05:34 +0100 [thread overview]
Message-ID: <ac09180d-27ea-40dc-a728-68e07333e153@samsung.com> (raw)
In-Reply-To: <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 <jmoroni@google.com>
> Signed-off-by: Ying Xiao <eagleshaw@google.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> 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
prev parent reply other threads:[~2026-11-18 8:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261117155436eucas1p2fa7d030f5557d1c88d943226d65f69ca@eucas1p2.samsung.com>
2026-11-17 15:54 ` Ying Xiao
2026-11-18 8:05 ` Marek Szyprowski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac09180d-27ea-40dc-a728-68e07333e153@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=Brian.Starkey@arm.com \
--cc=benjamin.gaignard@collabora.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eagleshaw@google.com \
--cc=jgg@nvidia.com \
--cc=jiri@nvidia.com \
--cc=jmoroni@google.com \
--cc=jstultz@google.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=phasta@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.com \
--cc=xuehaohu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®