Re: [PATCH v4 5/6] x86/tdx: Move MMIO helpers to common library

From: Kirill A. Shutemov
Date: Thu Aug 22 2024 - 04:25:22 EST


On Wed, Aug 21, 2024 at 04:24:37PM +0200, Alexey Gladkov wrote:
> @@ -124,3 +125,127 @@ void memset_io(volatile void __iomem *a, int b, size_t c)
> }
> }
> EXPORT_SYMBOL(memset_io);
> +
> +int __get_iomem(char *src, char *buf, size_t size)
> +{
> + /*

This comment (and comment for __put_iomem()) has to be updated to be less
SEV-centric.

> + * This function uses __get_user() independent of whether kernel or user
> + * memory is accessed. This works fine because __get_user() does no
> + * sanity checks of the pointer being accessed. All that it does is
> + * to report when the access failed.
> + *
> + * Also, this function runs in atomic context, so __get_user() is not

It is not going to be atomic context for TDX case.

> + * allowed to sleep. The page-fault handler detects that it is running
> + * in atomic context and will not try to take mmap_sem and handle the
> + * fault, so additional pagefault_enable()/disable() calls are not
> + * needed.
> + *
> + * The access can't be done via copy_from_user() here because
> + * mmio_read_mem() must not use string instructions to access unsafe
> + * memory. The reason is that MOVS is emulated by the #VC handler by
> + * splitting the move up into a read and a write and taking a nested #VC
> + * exception on whatever of them is the MMIO access. Using string
> + * instructions here would cause infinite nesting.

#VC is SEV specific.

> + */

--
Kiryl Shutsemau / Kirill A. Shutemov