Re: [PATCH] x86/sev-es: Do not use copy_from_kernel_nofault in early #VC handler

From: Dave Hansen
Date: Wed Sep 06 2023 - 19:01:21 EST


On 9/6/23 15:45, Adam Dunlap wrote:
> static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,
> - unsigned char *buffer)
> + unsigned char *buffer, bool is_early)
> {
> - return copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE);
> + if (is_early) {
> + memcpy(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE);
> + return 0;
> + } else {
> + return copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip,
> + MAX_INSN_SIZE);
> + }
> }

This isn't the normal way we do these kinds of things.

If we go with this solution, they next guy who tries
copy_from_kernel_nofault() will hit the same issue, and start plumbing
their own 'is_early' through _their_ little chunk of arch/x86.

Usually, we'll add some gunk in arch/x86/boot/compressed/misc.h to
override the troublesome implementation. In this case, it would make a
lot of sense to somehow avoid touching boot_cpu_data.x86_virt_bits in
the first place.