[PATCH v11 04/23] s390/mm: Clear memory before making it shared

Christian Borntraeger borntraeger at linux.ibm.com
Wed Dec 2 01:57:46 PST 2026


Am 02.12.26 um 10:54 schrieb Aneesh Kumar K.V (Arm):
> The comment in share() warns that sharing operates on whole pages and
> can expose unintended data to the hypervisor. Memory whose previous
> contents must remain private therefore needs to be cleared before
> uv_set_shared() makes it accessible to the host.
> 
> The common CoCo allocator masks __GFP_ZERO because a private-to-shared
> transition may modify memory contents, and currently clears the
> allocation after sharing. On s390, that ordering could expose previous
> contents before the clear.
> 
> Clear the range in set_memory_decrypted() before calling
> uv_set_shared(). This also establishes the zeroing guarantee that
> subsequent patches will use to remove redundant caller-side clears.
> 
> Cc: Alexander Gordeev <agordeev at linux.ibm.com>
> Cc: Gerald Schaefer <gerald.schaefer at linux.ibm.com>
> Cc: Heiko Carstens <hca at linux.ibm.com>
> Cc: Vasily Gorbik <gor at linux.ibm.com>
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar at kernel.org>

Acked-by: Christian Borntraeger <borntraeger at linux.ibm.com>


> ---
>   arch/s390/mm/init.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index be7e009e7b59..fdacd9380286 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -129,6 +129,13 @@ int set_memory_encrypted(unsigned long vaddr, int numpages)
>   int set_memory_decrypted(unsigned long vaddr, int numpages)
>   {
>   	int i;
> +
> +	/*
> +	 * uv_set_shared() exposes existing contents to the host; see the data
> +	 * leakage warning in share() in asm/uv.h. Clear private data first.
> +	 */
> +	memset((void *)vaddr, 0, (size_t)numpages << PAGE_SHIFT);
> +
>   	/* make specified pages shared (swiotlb, dma_alloca) */
>   	for (i = 0; i < numpages; ++i) {
>   		uv_set_shared(virt_to_phys((void *)vaddr));




More information about the linux-arm-kernel mailing list