Skip to content

Commit

Permalink
feat: Add patches from virt-pvm/linux#7 (comment) to AWS branch to de…
Browse files Browse the repository at this point in the history
…bug cross-host restore issues
  • Loading branch information
pojntfx committed Apr 23, 2024
1 parent 3f04372 commit a361585
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ patch/fedora/baremetal: patch/pre/fedora/baremetal
patch/fedora/hetzner: patch/pre/fedora/hetzner
patch/fedora/digitalocean: patch/pre/fedora/digitalocean
patch/fedora/aws: patch/pre/fedora/aws
cd work/fedora/aws/linux && \
git apply ../../../../patches/use-fixed-pvm-range.patch && \
git apply ../../../../patches/add-xsave-debug-logs.patch
patch/fedora/gcp: patch/pre/fedora/gcp
patch/fedora/ovh: patch/pre/fedora/ovh
patch/fedora/linode: patch/pre/fedora/linode
Expand All @@ -38,6 +41,9 @@ patch/rocky/baremetal: patch/pre/rocky/baremetal
patch/rocky/hetzner: patch/pre/rocky/hetzner
patch/rocky/digitalocean: patch/pre/rocky/digitalocean
patch/rocky/aws: patch/pre/rocky/aws
cd work/rocky/aws/linux && \
git apply ../../../../patches/use-fixed-pvm-range.patch && \
git apply ../../../../patches/add-xsave-debug-logs.patch
patch/rocky/gcp: patch/pre/rocky/gcp
patch/rocky/equinix: patch/pre/rocky/equinix
patch/rocky/ovh: patch/pre/rocky/ovh
Expand All @@ -49,6 +55,9 @@ patch/alma/baremetal: patch/pre/alma/baremetal
patch/alma/hetzner: patch/pre/alma/hetzner
patch/alma/digitalocean: patch/pre/alma/digitalocean
patch/alma/aws: patch/pre/alma/aws
cd work/alma/aws/linux && \
git apply ../../../../patches/use-fixed-pvm-range.patch && \
git apply ../../../../patches/add-xsave-debug-logs.patch
patch/alma/gcp: patch/pre/alma/gcp
patch/alma/equinix: patch/pre/alma/equinix
patch/alma/ovh: patch/pre/alma/ovh
Expand Down
78 changes: 78 additions & 0 deletions patches/add-xsave-debug-logs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
From: bysui <[email protected]>
Subject: https://github.com/virt-pvm/linux/issues/7#issuecomment-2069445537
---
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 29413cb2f..aa819f664 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5517,12 +5517,20 @@ static void kvm_vcpu_ioctl_x86_get_xsave2(struct kvm_vcpu *vcpu,
*/
u64 supported_xcr0 = vcpu->arch.guest_supported_xcr0 |
XFEATURE_MASK_FPSSE;
+ union fpregs_state *ustate = (void *)state;

if (fpstate_is_confidential(&vcpu->arch.guest_fpu))
return;

fpu_copy_guest_fpstate_to_uabi(&vcpu->arch.guest_fpu, state, size,
supported_xcr0, vcpu->arch.pkru);
+
+ pr_info("during getting:\n guest xcr0: %llx, host xcr0: %llx, supported_xcr0: %llx\n",
+ vcpu->arch.xcr0, host_xcr0, supported_xcr0);
+ pr_info("guest pkru: %x, host pkru: %x\n",
+ vcpu->arch.pkru, vcpu->arch.host_pkru);
+ pr_info("xfeatures: %llx, xcomp_bv: %llx\n",
+ ustate->xsave.header.xfeatures, ustate->xsave.header.xcomp_bv);
}

static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu,
@@ -5535,9 +5543,18 @@ static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu,
static int kvm_vcpu_ioctl_x86_set_xsave(struct kvm_vcpu *vcpu,
struct kvm_xsave *guest_xsave)
{
+ union fpregs_state *ustate = (void *)guest_xsave->region;
+
if (fpstate_is_confidential(&vcpu->arch.guest_fpu))
return 0;

+ pr_info("during settting:\n guest xcr0: %llx, host xcr0: %llx, supported_xcr0: %llx\n",
+ vcpu->arch.xcr0, host_xcr0, kvm_caps.supported_xcr0);
+ pr_info("guest pkru: %x, host pkru: %x\n",
+ vcpu->arch.pkru, vcpu->arch.host_pkru);
+ pr_info("xfeatures: %llx, xcomp_bv: %llx\n",
+ ustate->xsave.header.xfeatures, ustate->xsave.header.xcomp_bv);
+
return fpu_copy_uabi_to_guest_fpstate(&vcpu->arch.guest_fpu,
guest_xsave->region,
kvm_caps.supported_xcr0,
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 271dcb2de..b2e280172 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -6,6 +6,7 @@
#include <xen/xen.h>

#include <asm/fpu/api.h>
+#include <asm/fpu/xcr.h>
#include <asm/sev.h>
#include <asm/traps.h>
#include <asm/kdebug.h>
@@ -121,8 +122,18 @@ static bool ex_handler_sgx(const struct exception_table_entry *fixup,
static bool ex_handler_fprestore(const struct exception_table_entry *fixup,
struct pt_regs *regs)
{
+ static bool once;
regs->ip = ex_fixup_addr(fixup);

+ if (boot_cpu_has(X86_FEATURE_XSAVE) && !once) {
+ struct xregs_state *state = (void *)regs->di;
+
+ once = true;
+ pr_info("xcr0 is %llx\n", xgetbv(XCR_XFEATURE_ENABLED_MASK));
+ pr_info("xfeatures: %llx, xcomp_bv: %llx\n",
+ state->header.xfeatures, state->header.xcomp_bv);
+ }
+
WARN_ONCE(1, "Bad FPU state detected at %pB, reinitializing FPU registers.",
(void *)instruction_pointer(regs));

32 changes: 32 additions & 0 deletions patches/use-fixed-pvm-range.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From: bysui <[email protected]>
Subject: https://github.com/virt-pvm/linux/issues/7#issuecomment-2069445537
---
diff --git a/arch/x86/kvm/pvm/host_mmu.c b/arch/x86/kvm/pvm/host_mmu.c
index 35e97f4f7..f4da658b1 100644
--- a/arch/x86/kvm/pvm/host_mmu.c
+++ b/arch/x86/kvm/pvm/host_mmu.c
@@ -35,8 +35,9 @@ static int __init guest_address_space_init(void)
return -1;
}

- pvm_va_range_l4 = get_vm_area_align(DEFAULT_RANGE_L4_SIZE, PT_L4_SIZE,
- VM_ALLOC|VM_NO_GUARD);
+ pvm_va_range_l4 = __get_vm_area_caller(DEFAULT_RANGE_L4_SIZE, VM_ALLOC|VM_NO_GUARD,
+ VMALLOC_END - DEFAULT_RANGE_L4_SIZE, VMALLOC_END,
+ __builtin_return_address(0));
if (!pvm_va_range_l4)
return -1;

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 6e4b95f24..0b8b2d4ed 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2623,6 +2623,8 @@ struct vm_struct *__get_vm_area_caller(unsigned long size, unsigned long flags,
NUMA_NO_NODE, GFP_KERNEL, caller);
}

++EXPORT_SYMBOL_GPL(__get_vm_area_caller);
+
/**
* get_vm_area - reserve a contiguous kernel virtual area
* @size: size of the area

0 comments on commit a361585

Please sign in to comment.