Index | Thread | Search

From:
hshoexer <hshoexer@yerbouti.franken.de>
Subject:
Re: SEV-ES: Relocate ghcb in C, not assembler
To:
tech@openbsd.org
Date:
Fri, 21 Nov 2025 15:26:04 +0100

Download raw body.

Thread
On Fri, Nov 21, 2025 at 02:54:50PM +0100, Stefan Fritsch wrote:
> Hi,
> 
> ghcb_vaddr is not used in locore0.S, no need to do the relocation in 
> assembler.
> 
> While there, clarify a comment. When I read about vmm(4) I always think 
> about openbsd being the hypervisor. But this piece of code is about 
> openbsd being the guest.
> 
> ok?

ok hshoexer

> Cheers,
> Stefan
> 
> diff --git a/sys/arch/amd64/amd64/locore0.S b/sys/arch/amd64/amd64/locore0.S
> index 4533b19df2f..951da60b1d2 100644
> --- a/sys/arch/amd64/amd64/locore0.S
> +++ b/sys/arch/amd64/amd64/locore0.S
> @@ -804,15 +804,6 @@ longmode_hi:
>  	addq	%rsi,%rdx
>  	movq	%rdx,atdevbase(%rip)
>  
> -	/* Relocate GHCB. */
> -	movq	cpu_sev_guestmode(%rip),%rax
> -	testq	$SEV_STAT_ES_ENABLED,%rax
> -	jz	.Lnoghcbreloc
> -	movq	$(PROC0_GHCB_OFF+KERNBASE),%rdx
> -	addq	%rsi,%rdx
> -	movq	%rdx,ghcb_vaddr(%rip)
> -
> -.Lnoghcbreloc:
>  	/* Record start of symbols */
>  	movq	$__kernel_bss_end, ssym(%rip)
>  
> diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
> index adb0fc11898..5770f17503a 100644
> --- a/sys/arch/amd64/amd64/machdep.c
> +++ b/sys/arch/amd64/amd64/machdep.c
> @@ -1354,8 +1354,9 @@ cpu_init_early_vctrap(paddr_t addr)
>  	    GSEL(GCODE_SEL, SEL_KPL));
>  	cpu_init_idt();
>  
> -	/* Tell vmm(4) about our GHCB. */
> +	/* Tell the hypervisor about our GHCB. */
>  	ghcb_paddr = addr;
> +	ghcb_vaddr = addr + KERNBASE;
>  	memset((void *)ghcb_vaddr, 0, 2 * PAGE_SIZE);
>  	wrmsr(MSR_SEV_GHCB, ghcb_paddr);
>  }
> -- 
> 2.39.5
>