mirror of
https://github.com/openbsd/src.git
synced 2026-06-19 15:53:31 +02:00
vmm(4): Check for and allow empty GHCB; only clear valid bitmap
The GHCB valid bitmap indicates wether the GHCB contains a request or not. When no bits are set, ignore the GHCB and do not sync with vCPU state. To clear/invalidate the GHCB just zero out the valid bitmap instead of the full GHCB. ok mlarkin@
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: ghcb.c,v 1.7 2026/01/15 12:11:51 hshoexer Exp $ */
|
||||
/* $OpenBSD: ghcb.c,v 1.8 2026/02/16 15:06:03 hshoexer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024, 2025 Hans-Joerg Hoexer <hshoexer@genua.de>
|
||||
@@ -53,13 +53,29 @@ paddr_t ghcb_paddr;
|
||||
/*
|
||||
* ghcb_clear
|
||||
*
|
||||
* Clear GHCB by setting to all 0.
|
||||
* Clear GHCB valid bitmap to all 0. After that, the GHCB does
|
||||
* not contain a valid request.
|
||||
* Used by host and guest.
|
||||
*/
|
||||
void
|
||||
ghcb_clear(struct ghcb_sa *ghcb)
|
||||
{
|
||||
memset(ghcb, 0, sizeof(*ghcb));
|
||||
memset(&ghcb->valid_bitmap, 0, sizeof(ghcb->valid_bitmap));
|
||||
}
|
||||
|
||||
/*
|
||||
* ghcb_empty
|
||||
*
|
||||
* If the GHCB is all clear, it contains no requests.
|
||||
* Used by host only.
|
||||
*/
|
||||
int
|
||||
ghcb_empty(struct ghcb_sa *ghcb)
|
||||
{
|
||||
static const uint8_t bm_allzero[GHCB_VB_SZ];
|
||||
|
||||
return (memcmp(&bm_allzero, &ghcb->valid_bitmap,
|
||||
sizeof(bm_allzero)) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: vmm_machdep.c,v 1.70 2026/02/16 12:43:58 hshoexer Exp $ */
|
||||
/* $OpenBSD: vmm_machdep.c,v 1.71 2026/02/16 15:06:03 hshoexer Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
|
||||
*
|
||||
@@ -4347,6 +4347,8 @@ svm_vmgexit_sync_host(struct vcpu *vcpu)
|
||||
return (0);
|
||||
|
||||
ghcb = (struct ghcb_sa *)vcpu->vc_svm_ghcb_va;
|
||||
if (ghcb_empty(ghcb))
|
||||
return (0);
|
||||
if (!ghcb_valid(ghcb))
|
||||
return (EINVAL);
|
||||
valid_bm = ghcb->valid_bitmap;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: ghcb.h,v 1.6 2025/09/17 18:37:44 sf Exp $ */
|
||||
/* $OpenBSD: ghcb.h,v 1.7 2026/02/16 15:06:03 hshoexer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024, 2025 Hans-Joerg Hoexer <hshoexer@genua.de>
|
||||
@@ -128,6 +128,7 @@ int ghcb_valbm_set(uint8_t *, int);
|
||||
int ghcb_valbm_isset(uint8_t *, int);
|
||||
int ghcb_verify_bm(uint8_t *, uint8_t *);
|
||||
int ghcb_valid(struct ghcb_sa *);
|
||||
int ghcb_empty(struct ghcb_sa *);
|
||||
|
||||
void ghcb_sync_val(int, int, struct ghcb_sync *);
|
||||
void ghcb_sync_out(struct trapframe *, const struct ghcb_extra_regs *,
|
||||
|
||||
Reference in New Issue
Block a user