From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752122AbdKYDo1 (ORCPT ); Fri, 24 Nov 2017 22:44:27 -0500 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:50934 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751886AbdKYDoZ (ORCPT ); Fri, 24 Nov 2017 22:44:25 -0500 From: Nadav Amit To: , CC: , Nadav Amit , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Tony Luck , Borislav Petkov , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH v2 0/2] x86: disable IRQs during CR4 changes Date: Fri, 24 Nov 2017 19:29:05 -0800 Message-ID: <20171125032907.2241-1-namit@vmware.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CR4 needs to be updated atomically with its shadow value, as CR4 updates are performed in read-modify-write fashion which are based on the shadow value. If CR4 is changed between the read and the write, CR4 might not be updated correctly. For this to happen, CR4 needs to be rewritten by an interrupt handler. [Presumably, writes to CR4 take place while preemption is disabled, although due to the experience with CR3 - who knows.] CR4.PGD can be updated by an interrupt handler, but it is restored to its previous value, so it should not introduce a race. However, it seems that allowing CR4 updates without disabling IRQs may present a potential future bug. Cc: Andy Lutomirski Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Tony Luck Cc: Borislav Petkov Cc: Paolo Bonzini Cc: "Radim Krčmář" v1 -> v2: - Break into two patches (Andy) - Rename refactored function to __cr4_set() (Andy) Nadav Amit (2): x86: refactor CR4 setting and shadow write x86: disable IRQs before changing CR4 arch/x86/include/asm/mmu_context.h | 4 ++-- arch/x86/include/asm/tlbflush.h | 40 +++++++++++++++++++++--------------- arch/x86/include/asm/virtext.h | 2 +- arch/x86/kernel/cpu/common.c | 38 +++++++++++++++++++++++++--------- arch/x86/kernel/cpu/mcheck/mce.c | 5 ++++- arch/x86/kernel/cpu/mcheck/p5.c | 6 +++++- arch/x86/kernel/cpu/mcheck/winchip.c | 5 ++++- arch/x86/kernel/fpu/init.c | 2 +- arch/x86/kernel/fpu/xstate.c | 4 ++-- arch/x86/kernel/process.c | 20 +++++++++++++----- arch/x86/kernel/reboot.c | 2 +- arch/x86/kvm/vmx.c | 13 ++++++++++-- arch/x86/mm/init.c | 6 +++++- 13 files changed, 102 insertions(+), 45 deletions(-) -- 2.14.1