Re: [PATCH 2/2] x86/tdx: Convert shared memory back to private on kexec

From: Huang, Kai
Date: Tue Feb 14 2023 - 20:53:52 EST



> +void tdx_kexec_prepare(bool crash)
> +{
> + /*
> + * Crash kernel may want to see data in the shared buffers.
> + * Do not revert them to private on kexec of crash kernel.
> + */
> + if (crash)
> + return;
> +
> + /*
> + * Walk direct mapping and convert all shared memory back to private,
> + * so the target kernel will be able use it normally.
> + */
> + mmap_write_lock(&init_mm);
> + walk_page_range_novma(&init_mm,
> + PAGE_OFFSET,
> + PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT),
> + &unshare_ops, init_mm.pgd, NULL);
> + mmap_write_unlock(&init_mm);
> +}

Looks the page table walk is done unconditionally when !crash.

I think it's better to check whether this is TDX guest (either this function, or
below in machine_kexec()) and just return early if it's not a TDX guest?

[..]


> /*
> @@ -312,6 +313,7 @@ void machine_kexec(struct kimage *image)
> local_irq_disable();
> hw_breakpoint_disable();
> cet_disable();
> + tdx_kexec_prepare(image->type == KEXEC_TYPE_CRASH);
>
> if (image->preserve_context) {
> #ifdef CONFIG_X86_IO_APIC