From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1765330AbcINVIY (ORCPT ); Wed, 14 Sep 2016 17:08:24 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:35539 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762314AbcINVIW (ORCPT ); Wed, 14 Sep 2016 17:08:22 -0400 From: Kyle Huey X-Google-Original-From: Kyle Huey To: "Robert O'Callahan" Cc: linux-kernel@vger.kernel.org, Borislav Petkov , Andy Lutomirski Subject: [RESEND][PATCH v2] arch_prctl,x86 Add ARCH_[GET|SET]_CPUID for controlling the CPUID instruction Date: Wed, 14 Sep 2016 14:08:08 -0700 Message-Id: <1473887291-18384-1-git-send-email-khuey@kylehuey.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (Resending because I screwed up the cover email, sorry about that.) 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. 4 patches follow, the first 3 to the kernel, and the final patch to man-pages. The following changes have been made since v1: Suggested by Borislav Petkov: - Uses arch_prctl instead of prctl. - Uses rdmsr_safe. - Added sample man-pages patch. - Various functions are renamed, style fixes. Suggested by Andy Lutomirski: - Added a cpufeature bit to show up in /proc/cpuinfo. - Added sane behavior in Xen, by masking away the MSR_PLATFORM_INFO bit showing support for this feature for now. - Added a selftest, clarifying the bit is preserved on fork/exec. The following issues were raised and are not addressed: Use of cpuid within interrupt handlers: as Linus pointed out, CPUID only faults at cpl>0, so this is not a concern. Use a static_key instead of a TIF: I don't believe this solves anything. There are currently 8 free TIF bits (after this patch), and it's always possible to move this (or others) later if they are needed. Even if we were to use a static_key we would still need to maintain state about which tasks are subject to CPUID faulting and which are not somewhere else.