From: Greg Kroah-Hartman Date: Mon, 4 Dec 2017 09:25:13 +0000 (+0100) Subject: 3.18-stable patches X-Git-Tag: v3.18.86~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3d5543a00c2a5acbfce5a1b738dc12d54b216e4;p=thirdparty%2Fkernel%2Fstable-queue.git 3.18-stable patches added patches: btrfs-clear-space-cache-inode-generation-always.patch kvm-x86-exit-to-user-mode-on-ud-intercept-when-emulator-requires.patch kvm-x86-inject-exceptions-produced-by-x86_decode_insn.patch --- diff --git a/queue-3.18/btrfs-clear-space-cache-inode-generation-always.patch b/queue-3.18/btrfs-clear-space-cache-inode-generation-always.patch new file mode 100644 index 00000000000..057e30901fe --- /dev/null +++ b/queue-3.18/btrfs-clear-space-cache-inode-generation-always.patch @@ -0,0 +1,59 @@ +From 8e138e0d92c6c9d3d481674fb14e3439b495be37 Mon Sep 17 00:00:00 2001 +From: Josef Bacik +Date: Fri, 17 Nov 2017 14:50:46 -0500 +Subject: btrfs: clear space cache inode generation always + +From: Josef Bacik + +commit 8e138e0d92c6c9d3d481674fb14e3439b495be37 upstream. + +We discovered a box that had double allocations, and suspected the space +cache may be to blame. While auditing the write out path I noticed that +if we've already setup the space cache we will just carry on. This +means that any error we hit after cache_save_setup before we go to +actually write the cache out we won't reset the inode generation, so +whatever was already written will be considered correct, except it'll be +stale. Fix this by _always_ resetting the generation on the block group +inode, this way we only ever have valid or invalid cache. + +With this patch I was no longer able to reproduce cache corruption with +dm-log-writes and my bpf error injection tool. + +Signed-off-by: Josef Bacik +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman + +--- + fs/btrfs/extent-tree.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +--- a/fs/btrfs/extent-tree.c ++++ b/fs/btrfs/extent-tree.c +@@ -3219,13 +3219,6 @@ again: + goto again; + } + +- /* We've already setup this transaction, go ahead and exit */ +- if (block_group->cache_generation == trans->transid && +- i_size_read(inode)) { +- dcs = BTRFS_DC_SETUP; +- goto out_put; +- } +- + /* + * We want to set the generation to 0, that way if anything goes wrong + * from here on out we know not to trust this cache when we load up next +@@ -3235,6 +3228,13 @@ again: + ret = btrfs_update_inode(trans, root, inode); + WARN_ON(ret); + ++ /* We've already setup this transaction, go ahead and exit */ ++ if (block_group->cache_generation == trans->transid && ++ i_size_read(inode)) { ++ dcs = BTRFS_DC_SETUP; ++ goto out_put; ++ } ++ + if (i_size_read(inode) > 0) { + ret = btrfs_check_trunc_cache_free_space(root, + &root->fs_info->global_block_rsv); diff --git a/queue-3.18/kvm-x86-exit-to-user-mode-on-ud-intercept-when-emulator-requires.patch b/queue-3.18/kvm-x86-exit-to-user-mode-on-ud-intercept-when-emulator-requires.patch new file mode 100644 index 00000000000..578e6c54fd2 --- /dev/null +++ b/queue-3.18/kvm-x86-exit-to-user-mode-on-ud-intercept-when-emulator-requires.patch @@ -0,0 +1,54 @@ +From 61cb57c9ed631c95b54f8e9090c89d18b3695b3c Mon Sep 17 00:00:00 2001 +From: Liran Alon +Date: Sun, 5 Nov 2017 16:56:32 +0200 +Subject: KVM: x86: Exit to user-mode on #UD intercept when emulator requires +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Liran Alon + +commit 61cb57c9ed631c95b54f8e9090c89d18b3695b3c upstream. + +Instruction emulation after trapping a #UD exception can result in an +MMIO access, for example when emulating a MOVBE on a processor that +doesn't support the instruction. In this case, the #UD vmexit handler +must exit to user mode, but there wasn't any code to do so. Add it for +both VMX and SVM. + +Signed-off-by: Liran Alon +Reviewed-by: Nikita Leshenko +Reviewed-by: Konrad Rzeszutek Wilk +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Wanpeng Li +Reviewed-by: Paolo Bonzini +Signed-off-by: Radim Krčmář +Signed-off-by: Greg Kroah-Hartman + +--- + arch/x86/kvm/svm.c | 2 ++ + arch/x86/kvm/vmx.c | 2 ++ + 2 files changed, 4 insertions(+) + +--- a/arch/x86/kvm/svm.c ++++ b/arch/x86/kvm/svm.c +@@ -1785,6 +1785,8 @@ static int ud_interception(struct vcpu_s + int er; + + er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD); ++ if (er == EMULATE_USER_EXIT) ++ return 0; + if (er != EMULATE_DONE) + kvm_queue_exception(&svm->vcpu, UD_VECTOR); + return 1; +--- a/arch/x86/kvm/vmx.c ++++ b/arch/x86/kvm/vmx.c +@@ -4899,6 +4899,8 @@ static int handle_exception(struct kvm_v + + if (is_invalid_opcode(intr_info)) { + er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD); ++ if (er == EMULATE_USER_EXIT) ++ return 0; + if (er != EMULATE_DONE) + kvm_queue_exception(vcpu, UD_VECTOR); + return 1; diff --git a/queue-3.18/kvm-x86-inject-exceptions-produced-by-x86_decode_insn.patch b/queue-3.18/kvm-x86-inject-exceptions-produced-by-x86_decode_insn.patch new file mode 100644 index 00000000000..992e53814bb --- /dev/null +++ b/queue-3.18/kvm-x86-inject-exceptions-produced-by-x86_decode_insn.patch @@ -0,0 +1,53 @@ +From 6ea6e84309ca7e0e850b3083e6b09344ee15c290 Mon Sep 17 00:00:00 2001 +From: Paolo Bonzini +Date: Fri, 10 Nov 2017 10:49:38 +0100 +Subject: KVM: x86: inject exceptions produced by x86_decode_insn +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Paolo Bonzini + +commit 6ea6e84309ca7e0e850b3083e6b09344ee15c290 upstream. + +Sometimes, a processor might execute an instruction while another +processor is updating the page tables for that instruction's code page, +but before the TLB shootdown completes. The interesting case happens +if the page is in the TLB. + +In general, the processor will succeed in executing the instruction and +nothing bad happens. However, what if the instruction is an MMIO access? +If *that* happens, KVM invokes the emulator, and the emulator gets the +updated page tables. If the update side had marked the code page as non +present, the page table walk then will fail and so will x86_decode_insn. + +Unfortunately, even though kvm_fetch_guest_virt is correctly returning +X86EMUL_PROPAGATE_FAULT, x86_decode_insn's caller treats the failure as +a fatal error if the instruction cannot simply be reexecuted (as is the +case for MMIO). And this in fact happened sometimes when rebooting +Windows 2012r2 guests. Just checking ctxt->have_exception and injecting +the exception if true is enough to fix the case. + +Thanks to Eduardo Habkost for helping in the debugging of this issue. + +Reported-by: Yanan Fu +Cc: Eduardo Habkost +Signed-off-by: Paolo Bonzini +Signed-off-by: Radim Krčmář +Signed-off-by: Greg Kroah-Hartman + +--- + arch/x86/kvm/x86.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/arch/x86/kvm/x86.c ++++ b/arch/x86/kvm/x86.c +@@ -5372,6 +5372,8 @@ int x86_emulate_instruction(struct kvm_v + if (reexecute_instruction(vcpu, cr2, write_fault_to_spt, + emulation_type)) + return EMULATE_DONE; ++ if (ctxt->have_exception && inject_emulated_exception(vcpu)) ++ return EMULATE_DONE; + if (emulation_type & EMULTYPE_SKIP) + return EMULATE_FAIL; + return handle_emulation_failure(vcpu); diff --git a/queue-3.18/series b/queue-3.18/series index a4ad08c96cc..454a192fe12 100644 --- a/queue-3.18/series +++ b/queue-3.18/series @@ -2,3 +2,6 @@ netlink-add-a-start-callback-for-starting-a-netlink-dump.patch ipsec-fix-aborted-xfrm-policy-dump-crash.patch mm-thp-do-not-make-page-table-dirty-unconditionally-in-touch_pd.patch mm-madvise.c-fix-madvise-infinite-loop-under-special-circumstances.patch +btrfs-clear-space-cache-inode-generation-always.patch +kvm-x86-exit-to-user-mode-on-ud-intercept-when-emulator-requires.patch +kvm-x86-inject-exceptions-produced-by-x86_decode_insn.patch