From patchwork Fri Jun 22 23:59:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10483343 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 D257960532 for ; Sat, 23 Jun 2018 00:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE79828E24 for ; Sat, 23 Jun 2018 00:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0C4329004; Sat, 23 Jun 2018 00:00:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham 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 3C28128E24 for ; Sat, 23 Jun 2018 00:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934444AbeFWAAa (ORCPT ); Fri, 22 Jun 2018 20:00:30 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:36302 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934302AbeFWAAY (ORCPT ); Fri, 22 Jun 2018 20:00:24 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5MNx6nX169143; Sat, 23 Jun 2018 00:00:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=J3fjAWwkrD2Zd5F9bJnRGa8I9kPMghe0RM2GjT6mNpY=; b=NWS3CLdiTyW5t0fnPGduAeOsY8Rf9+0idZVHUWUV+iBk+knMwEv8Z771I9APwnBwzluM 6dGYA7dyg939a2qKRNeKyN67i6b2B7fqLB/Htfobvud3KEV5dalQVxlmdiM+FYPRKyEO XCnYtIXbWNzUUfL8K9340uScnuRTZCL64bz65Mp73VMB+jMh5s56uvCKoVyI4bA7LPtP 6i1LMURV8IpK4pygBsBywAy1YXJ0x/yQnkASJvqLfzaD5qROVGn0nzSamYqU8Bq632Zc Fnwxq7rfFDb2pPuF7pHMhVTvbZfdbCMd29mFk5T7aQ8an33bQuROZZ7ulTQp6o2B3+rQ tw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2jrp8hur8t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 Jun 2018 00:00:11 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5N008Mp002494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 Jun 2018 00:00:09 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5N0075H014536; Sat, 23 Jun 2018 00:00:07 GMT Received: from liran-pc.mynet (/79.183.72.72) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 Jun 2018 17:00:06 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: jmattson@google.com, idan.brown@oracle.com, Liran Alon Subject: [PATCH kvm-unit-tests 6/9] x86: nVMX: Enhance basic vmwrite/vmread test Date: Sat, 23 Jun 2018 02:59:37 +0300 Message-Id: <1529711980-32764-7-git-send-email-liran.alon@oracle.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1529711980-32764-1-git-send-email-liran.alon@oracle.com> References: <1529711980-32764-1-git-send-email-liran.alon@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8932 signatures=668703 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806220265 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check that "read-only" fields are writable when the IA32_VMX_MISC MSR reports that software can use VMWRITE to write to any supported field in the VMCS. Signed-off-by: Jim Mattson Signed-off-by: Liran Alon --- lib/x86/msr.h | 3 +++ x86/vmx.c | 62 ++++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/x86/msr.h b/lib/x86/msr.h index 663bad034c0d..abf0d93bc58d 100644 --- a/lib/x86/msr.h +++ b/lib/x86/msr.h @@ -405,6 +405,9 @@ #define MSR_IA32_VMX_TRUE_EXIT 0x0000048f #define MSR_IA32_VMX_TRUE_ENTRY 0x00000490 +/* MSR_IA32_VMX_MISC bits */ +#define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29) + #define MSR_IA32_TSCDEADLINE 0x000006e0 /* AMD-V MSRs */ diff --git a/x86/vmx.c b/x86/vmx.c index aa04ac68dab5..f80b155c4dae 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -125,7 +125,7 @@ static struct vmcs_field vmcs_fields[] = { { MASK(64), APIC_ACCS_ADDR }, { MASK(64), EPTP }, - { 0 /* read-only */, INFO_PHYS_ADDR }, + { MASK(64), INFO_PHYS_ADDR }, { MASK(64), VMCS_LINK_PTR }, { MASK(64), GUEST_DEBUGCTL }, @@ -155,14 +155,14 @@ static struct vmcs_field vmcs_fields[] = { { MASK(32), TPR_THRESHOLD }, { MASK(32), CPU_EXEC_CTRL1 }, - { 0 /* read-only */, VMX_INST_ERROR }, - { 0 /* read-only */, EXI_REASON }, - { 0 /* read-only */, EXI_INTR_INFO }, - { 0 /* read-only */, EXI_INTR_ERROR }, - { 0 /* read-only */, IDT_VECT_INFO }, - { 0 /* read-only */, IDT_VECT_ERROR }, - { 0 /* read-only */, EXI_INST_LEN }, - { 0 /* read-only */, EXI_INST_INFO }, + { MASK(32), VMX_INST_ERROR }, + { MASK(32), EXI_REASON }, + { MASK(32), EXI_INTR_INFO }, + { MASK(32), EXI_INTR_ERROR }, + { MASK(32), IDT_VECT_INFO }, + { MASK(32), IDT_VECT_ERROR }, + { MASK(32), EXI_INST_LEN }, + { MASK(32), EXI_INST_INFO }, { MASK(32), GUEST_LIMIT_ES }, { MASK(32), GUEST_LIMIT_CS }, @@ -199,12 +199,12 @@ static struct vmcs_field vmcs_fields[] = { { MASK_NATURAL, CR3_TARGET_2 }, { MASK_NATURAL, CR3_TARGET_3 }, - { 0 /* read-only */, EXI_QUALIFICATION }, - { 0 /* read-only */, IO_RCX }, - { 0 /* read-only */, IO_RSI }, - { 0 /* read-only */, IO_RDI }, - { 0 /* read-only */, IO_RIP }, - { 0 /* read-only */, GUEST_LINEAR_ADDRESS }, + { MASK_NATURAL, EXI_QUALIFICATION }, + { MASK_NATURAL, IO_RCX }, + { MASK_NATURAL, IO_RSI }, + { MASK_NATURAL, IO_RDI }, + { MASK_NATURAL, IO_RIP }, + { MASK_NATURAL, GUEST_LINEAR_ADDRESS }, { MASK_NATURAL, GUEST_CR0 }, { MASK_NATURAL, GUEST_CR3 }, @@ -241,6 +241,28 @@ static struct vmcs_field vmcs_fields[] = { { MASK_NATURAL, HOST_RIP }, }; +enum vmcs_field_type { + VMCS_FIELD_TYPE_CONTROL = 0, + VMCS_FIELD_TYPE_READ_ONLY_DATA = 1, + VMCS_FIELD_TYPE_GUEST = 2, + VMCS_FIELD_TYPE_HOST = 3, + VMCS_FIELD_TYPES, +}; + +static inline int vmcs_field_type(struct vmcs_field *f) +{ + return (f->encoding >> VMCS_FIELD_TYPE_SHIFT) & 0x3; +} + +static int vmcs_field_readonly(struct vmcs_field *f) +{ + u64 ia32_vmx_misc; + + ia32_vmx_misc = rdmsr(MSR_IA32_VMX_MISC); + return !(ia32_vmx_misc & MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS) && + (vmcs_field_type(f) == VMCS_FIELD_TYPE_READ_ONLY_DATA); +} + static inline u64 vmcs_field_value(struct vmcs_field *f, u8 cookie) { u64 value; @@ -264,6 +286,16 @@ static bool check_vmcs_field(struct vmcs_field *f, u8 cookie) u64 actual; int ret; + if (f->encoding == VMX_INST_ERROR) { + printf("Skipping volatile field %lx\n", f->encoding); + return true; + } + + if (vmcs_field_readonly(f)) { + printf("Skipping read-only field %lx\n", f->encoding); + return true; + } + ret = vmcs_read_checking(f->encoding, &actual); assert(!(ret & X86_EFLAGS_CF)); /* Skip VMCS fields that aren't recognized by the CPU */