From patchwork Sat Feb 24 00:52:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 10240113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 95D2C60390 for ; Sat, 24 Feb 2018 00:54:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8888128BA8 for ; Sat, 24 Feb 2018 00:54:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C23A29AA3; Sat, 24 Feb 2018 00:54:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3189128BA8 for ; Sat, 24 Feb 2018 00:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752689AbeBXAwd (ORCPT ); Fri, 23 Feb 2018 19:52:33 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:52427 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752681AbeBXAwb (ORCPT ); Fri, 23 Feb 2018 19:52:31 -0500 Received: by mail-wm0-f67.google.com with SMTP id t3so7660164wmc.2; Fri, 23 Feb 2018 16:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=AvKsWEJ0udTjhRVCG05eXWkOAbe2U1BFZAwbzvv/xV0=; b=TRoRh2Nin1fhmDEJ63CxjcOC0k/AN48PEn3PPTX4zef6oiKM52XeGnZqjOfdrp8Y6i D97oqgoj6o2K6KCLV9MazggL2rqcS1YnrULDE/UYvyZwS/aFpZ9bMFBwiTjQsGqCMtre UIYF5yEacGo7bsP/+cl+EQaa8JBYogj1eI3zK1qf9/aVldG232JZeE0jz9khuIahd9Q4 /fdI9CeSshmbiqkXLrMZL2YgEt3s/8/Grw3qo9UOySrji5Or0jr8tr/kfMmgM3HdVYPH PpdhtSGPSOYKK0I52pMVraEZ/JHRz/G9ph7Oayq9yNfY0cFXTtrA0Og1GN0WGqsbcXuG Q/wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=AvKsWEJ0udTjhRVCG05eXWkOAbe2U1BFZAwbzvv/xV0=; b=Yq1mIB8/+7pJ6skXQt9rUIJcEDIpV5cdbMNVQ2B0SOr+3pcdnfGdt8lbc62gZXf27x TLipLvQ5DkfeSY6sg5+0JTWb4auipUFkaeQPZaBRZ7uJ1+Td9/bompuEo4wTRh2TXuNp tk6YBgG6iPZkXCk8wQNKvFpMlLHpg8Zqa5uwhYYaKGE8x7XisDYkrm/9TInSHtscqUSZ rN/cOTYJPftuF4rzysQm48Yr3icGaeDvOoIIy/SZIBM7696Hne2RB5o3twKlh8oss/PK im/vgZL+t6wwYb5BCF8GUWp7uzxldO4egP4lVJgdnv+qbbjy9g8VM1Rk1ECFbATZ1bXF IOZg== X-Gm-Message-State: APf1xPBIZFAmMZDZZ2vfQqaYLdsl4zw8s3ftUfvboVAx6Uh4ciKZJTAS zgjkQWzNoBA4qXrFea1CobRt/QYn X-Google-Smtp-Source: AG47ELvTW8/KuurPOgAEppRVwdeDgY5ccHymi+EW7S5X1QP3WGvo1zVMklxblV+x67TyV3PqfwYZEg== X-Received: by 10.28.63.81 with SMTP id m78mr3367088wma.102.1519433549733; Fri, 23 Feb 2018 16:52:29 -0800 (PST) Received: from 640k.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id r1sm3418982wmg.22.2018.02.23.16.52.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 16:52:27 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: David Woodhouse , KarimAllah Ahmed Subject: [PATCH] KVM: VMX: expose the host's ARCH_CAPABILITIES MSR to userspace Date: Sat, 24 Feb 2018 01:52:26 +0100 Message-Id: <1519433546-33879-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the new MSR feature framework to expose the ARCH_CAPABILITIES MSR to userspace. This way, userspace can access the capabilities even if it does not have the permissions to read MSRs. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx.c | 12 +++++++++++- arch/x86/kvm/x86.c | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 130fca0ea1bf..99689061e11e 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3228,7 +3228,17 @@ static inline bool vmx_feature_control_msr_valid(struct kvm_vcpu *vcpu, static int vmx_get_msr_feature(struct kvm_msr_entry *msr) { - return 1; + switch (msr->index) { + case MSR_IA32_ARCH_CAPABILITIES: + if (!boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) + return 1; + rdmsrl(msr->index, msr->data); + break; + default: + return 1; + } + + return 0; } /* diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 54b4ed55945b..e9a8cc9e3b2b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1054,6 +1054,7 @@ bool kvm_rdpmc(struct kvm_vcpu *vcpu) * can be used by a hypervisor to validate requested CPU features. */ static u32 msr_based_features[] = { + MSR_IA32_ARCH_CAPABILITIES, MSR_F10H_DECFG, };