From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757040AbcIOXTZ (ORCPT ); Thu, 15 Sep 2016 19:19:25 -0400 Received: from mail-vk0-f43.google.com ([209.85.213.43]:35629 "EHLO mail-vk0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756594AbcIOXTQ (ORCPT ); Thu, 15 Sep 2016 19:19:16 -0400 MIME-Version: 1.0 In-Reply-To: <32FABFC8-D606-4918-AAEF-FAA7982308A1@zytor.com> References: <1473886902-17902-1-git-send-email-khuey@kylehuey.com> <1473886902-17902-3-git-send-email-khuey@kylehuey.com> <57D9C2AC.8050905@linux.intel.com> <32FABFC8-D606-4918-AAEF-FAA7982308A1@zytor.com> From: Andy Lutomirski Date: Thu, 15 Sep 2016 16:18:54 -0700 Message-ID: Subject: Re: [PATCH v2 2/3] x86 Test and expose CPUID faulting capabilities in /proc/cpuinfo To: "H. Peter Anvin" Cc: Kyle Huey , Dave Hansen , "Robert O'Callahan" , Thomas Gleixner , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Boris Ostrovsky , David Vrabel , Juergen Gross , Borislav Petkov , Andy Lutomirski , Peter Zijlstra , Huang Rui , "Rafael J. Wysocki" , Len Brown , Srinivas Pandruvada , Aravind Gopalakrishnan , Alexander Shishkin , Vladimir Zapolskiy , Kristen Carlson Accardi , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "moderated list:XEN HYPERVISOR INTERFACE" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 15, 2016 at 1:38 PM, H. Peter Anvin wrote: > On September 14, 2016 6:17:51 PM PDT, Andy Lutomirski wrote: >>On Wed, Sep 14, 2016 at 3:03 PM, Kyle Huey wrote: >>> On Wed, Sep 14, 2016 at 2:35 PM, Dave Hansen >>> wrote: >>>> On 09/14/2016 02:01 PM, Kyle Huey wrote: >> >>>> Is any of this useful to optimize away at compile-time? We have >>config >>>> options for when we're running as a guest, and this seems like a >>feature >>>> that isn't available when running on bare metal. >>> >>> On the contrary, this is only available when we're on bare metal. >>> Neither Xen nor KVM virtualize CPUID faulting (although KVM correctly >>> suppresses MSR_PLATFORM_INFO's report of support for it). >> >>KVM could easily support this. If rr starts using it, I think KVM >>*should* add support, possibly even for older CPUs that don't support >>the feature in hardware. >> >>It's too bad that x86 doesn't give us the instruction bytes on a >>fault. Otherwise we could lazily switch this feature. >> >>--Andy > > You can "always" examine the instruction bytes in memory... have to make sure you properly consider the impact of race conditions though. I'd rather avoid needing to worry about those race conditions if at all possible, though. Intel and AMD both have fancy "decode assists" and such -- it would be quite nice IMO if we could get the same data exposed in the handlers of synchronous faults. If Intel or AMD were to do this for real, presumably the rule would be that any fault-class exception caused by a validly-decoded instruction at CPL3 (so #PF and #GP would count but #DB probably wouldn't, and #DF wouldn't either unless the initial fault did) would stash away the faulting instruction and other entries would instead stash away "nothing here". Some pair of MSRs or new instruction would read out information. Then we could accurately emulate CPUID, we could accurately emulate page-faulting instructions if we cared, etc. All of the relevant hardware must already mostly exist because VMX and SVM both have this capability. --Andy