Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161224AbcKABi3 (ORCPT ); Mon, 31 Oct 2016 21:38:29 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35663 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161162AbcKABiZ (ORCPT ); Mon, 31 Oct 2016 21:38:25 -0400 From: Kyle Huey X-Google-Original-From: Kyle Huey To: "Robert O'Callahan" , Thomas Gleixner , Andy Lutomirski , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Jeff Dike , Richard Weinberger , Alexander Viro , Shuah Khan , Dave Hansen , Borislav Petkov , Peter Zijlstra , Boris Ostrovsky , Len Brown , "Rafael J. Wysocki" , Dmitry Safonov Cc: linux-kernel@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, user-mode-linux-user@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH v8 0/7] x86/arch_prctl Add ARCH_[GET|SET]_CPUID for controlling the CPUID instruction Date: Mon, 31 Oct 2016 18:37:42 -0700 Message-Id: <20161101013749.4003-1-khuey@kylehuey.com> X-Mailer: git-send-email 2.10.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1273 Lines: 26 rr (http://rr-project.org/), a userspace record-and-replay reverse- execution debugger, would like to trap and emulate the CPUID instruction. This would allow us to a) mask away certain hardware features that rr does not support (e.g. RDRAND) and b) enable trace portability across machines by providing constant results. Newer Intel CPUs (Ivy Bridge and later) can fault when CPUID is executed at CPL > 0. Expose this capability to userspace as a new pair of arch_prctls, ARCH_GET_CPUID and ARCH_SET_CPUID, with two values, ARCH_CPUID_ENABLE and ARCH_CPUID_SIGSEGV. Since v7: Patch 5: - Applied and tested Thomas's review comments re: generic MSR testing code. Patch 6: - arch_prctl now returns ENODEV for ARCH_[GET|SET]_CPUID if the feature is not supported by the hardware. The selftest has been updated for this. - Applied and tested review comments from Thomas and Andy re: context switching performance. Added patch 7, implementing KVM support for virtualizing cpuid faulting. One thing to note is that this exposes this Intel-only feature to VMs running on both Intel and AMD CPUs. A Linux guest kernel with these patches will not take advantage of this on an AMD CPU though, because the feature detection code inside Linux is in an Intel-specific codepath.