From c75e6681d6270ca16961d7d9d63c7107ce70a52b Mon Sep 17 00:00:00 2001 From: Dan Ziemba Date: Sat, 21 Nov 2015 05:21:52 -0500 Subject: [PATCH] Patch from 4.4 that may fix booting kvm with OVMF. --- .SRCINFO | 2 + PKGBUILD | 8 ++- ...6_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch diff --git a/.SRCINFO b/.SRCINFO index fa8bc77..989e594 100644 --- a/.SRCINFO +++ b/.SRCINFO @@ -19,6 +19,7 @@ pkgbase = linux-vfio source = change-default-console-loglevel.patch source = override_for_missing_acs_capabilities.patch source = i915_317.patch + source = kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch sha256sums = 4a622cc84b8a3c38d39bc17195b0c064d2b46945dfde0dae18f77b120bc9f3ae sha256sums = SKIP sha256sums = 596958c9c4b632fdf5e0cdc677859dccac4304ad07a217c9bcb0e4fa58dbea16 @@ -27,6 +28,7 @@ pkgbase = linux-vfio sha256sums = 1256b241cd477b265a3c2d64bdc19ffe3c9bbcee82ea3994c590c2c76e767d99 sha256sums = 975f79348119bfba8dd972a9fbfe6b38484c45bfd228f2f6d48a0c02426ba149 sha256sums = ff2bb84f054633c6088ad31b450b7b96b5f4ee18667dd56772dff1d8c1687854 + sha256sums = 2d8bf50218cff86db6723f3623823a47b1c8299a2eb0589458b0a19887799f4e pkgname = linux-vfio pkgdesc = The Linux kernel and modules with patches to enable GPU passthrough with KVM diff --git a/PKGBUILD b/PKGBUILD index f2fd0b6..7568561 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -20,6 +20,7 @@ source=("https://www.kernel.org/pub/linux/kernel/v4.x/${_srcname}.tar.xz" 'change-default-console-loglevel.patch' 'override_for_missing_acs_capabilities.patch' 'i915_317.patch' + 'kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch' ) sha256sums=('4a622cc84b8a3c38d39bc17195b0c064d2b46945dfde0dae18f77b120bc9f3ae' 'SKIP' @@ -28,7 +29,8 @@ sha256sums=('4a622cc84b8a3c38d39bc17195b0c064d2b46945dfde0dae18f77b120bc9f3ae' 'f0d90e756f14533ee67afda280500511a62465b4f76adcc5effa95a40045179c' '1256b241cd477b265a3c2d64bdc19ffe3c9bbcee82ea3994c590c2c76e767d99' '975f79348119bfba8dd972a9fbfe6b38484c45bfd228f2f6d48a0c02426ba149' - 'ff2bb84f054633c6088ad31b450b7b96b5f4ee18667dd56772dff1d8c1687854') + 'ff2bb84f054633c6088ad31b450b7b96b5f4ee18667dd56772dff1d8c1687854' + '2d8bf50218cff86db6723f3623823a47b1c8299a2eb0589458b0a19887799f4e') validpgpkeys=( 'ABAF11C65A2970B130ABE3C479BE3E4300411886' # Linus Torvalds '647F28654894E3BD457199BE38DBBDC86092693E' # Greg Kroah-Hartman @@ -64,6 +66,10 @@ prepare() { echo '==> Applying ACS override patch' patch -p1 -i "${srcdir}/override_for_missing_acs_capabilities.patch" + # Backport of 879ae1880449 from 4.4 to fix booting with OVMF + echo '==> Applying OVMF kvm boot patch' + patch -p1 -i "${srcdir}/kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch" + if [ "${_kernelname}" != "" ]; then sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"${_kernelname}\"|g" ./.config sed -i "s|CONFIG_LOCALVERSION_AUTO=.*|CONFIG_LOCALVERSION_AUTO=n|" ./.config diff --git a/kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch b/kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch new file mode 100644 index 0000000..64cdd6b --- /dev/null +++ b/kvm-x86-obey-KVM_X86_QUIRK_CD_NW_CLEARED-in-kvm_set_cr0.patch @@ -0,0 +1,53 @@ +From 879ae1880449c88db11c1ebdaedc2da79b2fe73f Mon Sep 17 00:00:00 2001 +From: Laszlo Ersek +Date: Wed, 4 Nov 2015 12:54:41 +0100 +Subject: KVM: x86: obey KVM_X86_QUIRK_CD_NW_CLEARED in kvm_set_cr0() + +Commit b18d5431acc7 ("KVM: x86: fix CR0.CD virtualization") was +technically correct, but it broke OVMF guests by slowing down various +parts of the firmware. + +Commit fb279950ba02 ("KVM: vmx: obey KVM_QUIRK_CD_NW_CLEARED") quirked the +first function modified by b18d5431acc7, vmx_get_mt_mask(), for OVMF's +sake. This restored the speed of the OVMF code that runs before +PlatformPei (including the memory intensive LZMA decompression in SEC). + +This patch extends the quirk to the second function modified by +b18d5431acc7, kvm_set_cr0(). It eliminates the intrusive slowdown that +hits the EFI_MP_SERVICES_PROTOCOL implementation of edk2's +UefiCpuPkg/CpuDxe -- which is built into OVMF --, when CpuDxe starts up +all APs at once for initialization, in order to count them. + +We also carry over the kvm_arch_has_noncoherent_dma() sub-condition from +the other half of the original commit b18d5431acc7. + +Fixes: b18d5431acc7a2fd22767925f3a6f597aa4bd29e +Cc: stable@vger.kernel.org +Cc: Jordan Justen +Cc: Alex Williamson +Reviewed-by: Xiao Guangrong +Tested-by: Janusz Mocek +Signed-off-by: Laszlo Ersek # +Signed-off-by: Paolo Bonzini +--- + arch/x86/kvm/x86.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c +index a24bae0..30723a4 100644 +--- a/arch/x86/kvm/x86.c ++++ b/arch/x86/kvm/x86.c +@@ -625,7 +625,9 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) + if ((cr0 ^ old_cr0) & update_bits) + kvm_mmu_reset_context(vcpu); + +- if ((cr0 ^ old_cr0) & X86_CR0_CD) ++ if (((cr0 ^ old_cr0) & X86_CR0_CD) && ++ kvm_arch_has_noncoherent_dma(vcpu->kvm) && ++ !kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) + kvm_zap_gfn_range(vcpu->kvm, 0, ~0ULL); + + return 0; +-- +cgit v0.11.2 +