From patchwork Tue Mar 19 01:46:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10858695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9319E1708 for ; Tue, 19 Mar 2019 02:12:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74182294FA for ; Tue, 19 Mar 2019 02:12:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6745A29504; Tue, 19 Mar 2019 02:12:05 +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 10C47294FA for ; Tue, 19 Mar 2019 02:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727089AbfCSCMD (ORCPT ); Mon, 18 Mar 2019 22:12:03 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51938 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726666AbfCSCMD (ORCPT ); Mon, 18 Mar 2019 22:12:03 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2J24GhZ026753; Tue, 19 Mar 2019 02:11:57 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-2018-07-02; bh=ind9G7xGJPG/r4uRSGoNRRI2+WIFeDgckQowjSg97OY=; b=2+E3WSFfNuSPRNYrXjfUTOab4LDCImervF03MrVkttxt+A+EHD1SnKDm15SEiYFD+/h4 NkVGTth5UX6aAuQTUObVEcxyrk3PexYDLylFFghoeZBtziZhl/PDvhtQtA0ICRpQcIkB fFEekJ7kDAby1xxJXQA0Z3FRh8yOc8BduZTZ7iVDQ899jJ5k2/fSh3BYDXQ0lZx/LO70 OvjKYcTATvjhcZQRon8wor4QRGw39L6epYb0eiD+/x8nTkqiWasV+iWmahQc0YBeGDbE ITCMbYMRsetv3cnYgB+wCm2JIO5oOl73V0VncBtwowcGfxrDZLxKpSdTm3oukjsrrXqO 4g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2r8ssr9s97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 02:11:57 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2J2BuVk028486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 02:11:56 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2J2Bujg023244; Tue, 19 Mar 2019 02:11:56 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 18 Mar 2019 19:11:56 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [PATCH 1/3][KVM nVMX]: Check "load IA32_PAT" VM-exit control on vmentry of L2 guests Date: Mon, 18 Mar 2019 21:46:22 -0400 Message-Id: <20190319014624.31399-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190319014624.31399-1-krish.sadhukhan@oracle.com> References: <20190319014624.31399-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9199 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=597 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903190014 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to section "Checks on Host Control Registers and MSRs" in Intel SDM vol 3C, the following check is performed on vmentry of L2 guests: If the "load IA32_PAT" VM-exit control is 1, the value of the field for the IA32_PAT MSR must be one that could be written by WRMSR without fault at CPL 0. Specifically, each of the 8 bytes in the field must have one of the values 0 (UC), 1 (WC), 4 (WT), 5 (WP), 6 (WB), or 7 (UC-). Signed-off-by: Krish Sadhukhan Reviewed-by: Karl Heubaum --- arch/x86/kvm/vmx/nested.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 3170e291215d..a1b44d930d26 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2583,6 +2583,24 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu, return 0; } +/* + * Fields in IA32_PAT MSR are allowed to contain one of the + * following values: + * 0 (UC), 1 (WC), 4 (WT), 5 (WP), 6 (WB), or 7 (UC-) + */ +static int nested_check_pat_fields(u64 msr) +{ + int i; + u64 tmp = (msr >> i * 8) & 0xff; + + for (i = 0; i < 8; i++) { + if (tmp == 0x2 || tmp == 0x3 || tmp > 0x7) + return -EINVAL; + } + + return 0; +} + /* * Checks related to Host Control Registers and MSRs */ @@ -2595,6 +2613,12 @@ static int nested_check_host_control_regs(struct kvm_vcpu *vcpu, !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) || !nested_cr3_valid(vcpu, vmcs12->host_cr3)) return -EINVAL; + + if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) { + if (nested_check_pat_fields(vmcs12->host_ia32_pat)) + return -EINVAL; + } + /* * If the load IA32_EFER VM-exit control is 1, bits reserved in the * IA32_EFER MSR must be 0 in the field for that register. In addition, From patchwork Tue Mar 19 01:46:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10858699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 274D31575 for ; Tue, 19 Mar 2019 02:12:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EB1D294FA for ; Tue, 19 Mar 2019 02:12:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02CC329504; Tue, 19 Mar 2019 02:12:09 +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 A5DF1294FA for ; Tue, 19 Mar 2019 02:12:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727465AbfCSCMI (ORCPT ); Mon, 18 Mar 2019 22:12:08 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:41222 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727457AbfCSCMI (ORCPT ); Mon, 18 Mar 2019 22:12:08 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2J24VFC055994; Tue, 19 Mar 2019 02:12:02 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-2018-07-02; bh=enxwGvFDs38StoITiPZjLiWanXAp+IJ/9eZ4s8+osV8=; b=GewUl0NThDmcgOdGVsma8HkeuGIXRzOZyTvvjwL+JNC0LbuzjLA6cSqTCCBBOvuCwxOn Qq+MX8ScMH7az6g0htzFgY+vlRUcHCDIeR7SsKdaPzriQ9B24XIqxxucnpi3EZ58MG98 +DB/Sc7VRnSxFTComNO347i71efcv6kCe7P0DVnLBtilMgilHRlyjU0E26fhJ6EsvGaO YnZZ+wS5rFaG67dpJGs6yknqrgLIPINggXeNXC4JjJGaESNx1c6WPXgti6qVh2HYzQC1 VsJQfp3He2u5O+XoS2yuA6xAdEThfMdevPl5gGeTmusz24rU2EioVZ0Xnw9OjB3YdoDR MQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2r8pnej3p6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 02:12:02 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2J2BuUC001244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 02:11:56 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2J2BuaJ023250; Tue, 19 Mar 2019 02:11:56 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 18 Mar 2019 19:11:56 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [PATCH 2/3][KVM nVMX]: Check "load IA32_PAT" VM-entry control on vmentry of L2 guests Date: Mon, 18 Mar 2019 21:46:23 -0400 Message-Id: <20190319014624.31399-3-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190319014624.31399-1-krish.sadhukhan@oracle.com> References: <20190319014624.31399-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9199 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=775 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903190014 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to section "CHECKING AND LOADING GUEST STATE" in Intel SDM vol 3C, the following check is performed on vmentry of L2 guests: If the "load IA32_PAT" VM-entry control is 1, the value of the field for the IA32_PAT MSR must be one that could be written by WRMSR without fault at CPL 0. Specifically, each of the 8 bytes in the field must have one of the values 0 (UC), 1 (WC), 4 (WT), 5 (WP), 6 (WB), or 7 (UC-). Signed-off-by: Krish Sadhukhan Reviewed-by: Karl Heubaum --- arch/x86/kvm/vmx/nested.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index a1b44d930d26..6185ba4e6e55 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2637,6 +2637,20 @@ static int nested_check_host_control_regs(struct kvm_vcpu *vcpu, return 0; } +/* + * Checks related to Control Registers, Debug Registers and MSRs in + * Guest State Area. + */ +static int nested_check_guest_ctrl_dbg_regs_msrs(struct vmcs12 *vmcs12) +{ + if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) { + if (nested_check_pat_fields(vmcs12->guest_ia32_pat)) + return -EINVAL; + } + + return 0; +} + /* * Checks related to Guest Non-register State */ @@ -2660,6 +2674,9 @@ static int nested_vmx_check_vmentry_prereqs(struct kvm_vcpu *vcpu, if (nested_check_host_control_regs(vcpu, vmcs12)) return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD; + if (nested_check_guest_ctrl_dbg_regs_msrs(vmcs12)) + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + if (nested_check_guest_non_reg_state(vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; From patchwork Tue Mar 19 01:46:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10858697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 034DA1575 for ; Tue, 19 Mar 2019 02:12:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEBEF294FE for ; Tue, 19 Mar 2019 02:12:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D24C5294FA; Tue, 19 Mar 2019 02:12:06 +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 59BE7294FA for ; Tue, 19 Mar 2019 02:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbfCSCMF (ORCPT ); Mon, 18 Mar 2019 22:12:05 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51966 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbfCSCME (ORCPT ); Mon, 18 Mar 2019 22:12:04 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2J24eXE027323; Tue, 19 Mar 2019 02:11:59 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 : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=7fe/0qyEOFwxOKnFCN2nR8QNSsQuruUeB5yaBs8pMpc=; b=rFhFx94IdWsgfMXpEMKchWezJsNy/3PJiMGB6Q/GOVGQUfgpnpNNLjpV0k6tDo2CKYYp Q/TNO2fhkar8vQAHp4T7ULl6NOzes+8xsoKFyJ1DGXdgq8k13KkBXK2tFVYIKIzLofvQ zb0J+IQ5pxpMX7v+6FMLf7msAYBbOI8oPD2aq/u8oPVvG6wMUryb3jUiRslcycjqzCTM O1slP2ECZbCJ7uLFqBi7Wsuf423hp/tp5xkIvLUYXbarKIxq2DVA4Ezo5Ijr3aZm23U2 +s5GFuY+iCUNiIhVPgFBGvlUf+C25qUit3UPY4fh4qf2WJcOQuhnzEiMTH48Pud0Wrt9 ug== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2r8ssr9s9f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 02:11:58 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2J2BvJR001693 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 02:11:58 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2J2BvjJ013398; Tue, 19 Mar 2019 02:11:57 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 18 Mar 2019 19:11:57 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [PATCH 3/3][kvm-unit-test nVMX]: Check "load IA32_PAT" on vmentry of L2 guests Date: Mon, 18 Mar 2019 21:46:24 -0400 Message-Id: <20190319014624.31399-4-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190319014624.31399-1-krish.sadhukhan@oracle.com> References: <20190319014624.31399-1-krish.sadhukhan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9199 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903190014 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1. According to section "Checks on Host Control Registers and MSRs" in Intel SDM vol 3C, the following check is performed on vmentry of L2 guests: If the “load IA32_PAT” VM-exit control is 1, the value of the field for the IA32_PAT MSR must be one that could be written by WRMSR without fault at CPL 0. Specifically, each of the 8 bytes in the field must have one of the values 0 (UC), 1 (WC), 4 (WT), 5 (WP), 6 (WB), or 7 (UC-). 2. According to section "CHECKING AND LOADING GUEST STATE" in Intel SDM vol 3C, the following check is performed on vmentry of L2 guests: If the "load IA32_PAT" VM-entry control is 1, the value of the field for the IA32_PAT MSR must be one that could be written by WRMSR without fault at CPL 0. Specifically, each of the 8 bytes in the field must have one of the values 0 (UC), 1 (WC), 4 (WT), 5 (WP), 6 (WB), or 7 (UC-). Signed-off-by: Krish Sadhukhan Reviewed-by: Karl Heubaum --- x86/vmx_tests.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 66a87f6..7dae0f0 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4995,6 +4995,90 @@ static void test_sysenter_field(u32 field, const char *name) vmcs_write(field, addr_saved); } +static void test_pat_fields(u64 vmcs_fld, const char * vmcs_fld_name, + u64 ctrl, u64 ctrl_fld) +{ + u32 ctrl_saved = vmcs_read(ctrl); + u64 vmcs_fld_saved = vmcs_read(vmcs_fld); + int i, j, error = 0; + u64 val; + + vmcs_write(ctrl, ctrl_saved & ~ctrl_fld); + for (i = 0; i < 256; i++) { + /* Test PAT0..PAT7 fields */ + for (j = 0; j < 8; j++) { + val = i << j * 8; + vmcs_write(vmcs_fld, val); + report_prefix_pushf("%s %lx", vmcs_fld_name, val); + test_vmx_vmlaunch(error, false); + report_prefix_pop(); + } + } + + vmcs_write(ctrl, ctrl_saved | ctrl_fld); + for (i = 0; i < 256; i++) { + /* Test PAT0..PAT7 fields */ + for (j = 0; j < 8; j++) { + val = i << j * 8; + vmcs_write(vmcs_fld, val); + report_prefix_pushf("%s %lx", vmcs_fld_name, val); + if (i == 0x2 || i == 0x3 || i > 0x7) { + if (vmcs_fld == HOST_PAT) + error = + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD; + else + error = + VMXERR_ENTRY_INVALID_CONTROL_FIELD; + } else { + error = 0; + } + test_vmx_vmlaunch(error, false); + report_prefix_pop(); + } + } + + vmcs_write(ctrl, ctrl_saved); + vmcs_write(vmcs_fld, vmcs_fld_saved); +} + +/* + * 1. If the "load IA32_PAT" VM-exit control is 1, the value of the field + * for the IA32_PAT MSR must be one that could be written by WRMSR + * without fault at CPL 0. Specifically, each of the 8 bytes in the + * field must have one of the values 0 (UC), 1 (WC), 4 (WT), 5 (WP), + * 6 (WB), or 7 (UC-). + * + * 2. If the "load IA32_PAT" VM-entry control is 1, the value of the field + * for the IA32_PAT MSR must be one that could be written by WRMSR + * without fault at CPL 0. Specifically, each of the 8 bytes in the + * field must have one of the values 0 (UC), 1 (WC), 4 (WT), 5 (WP), + * 6 (WB), or 7 (UC-). + * + * [Intel SDM] + */ +static void test_load_pat(void) +{ + /* + * "load IA32_PAT" VM-exit control + */ + if (!(ctrl_exit_rev.clr & EXI_LOAD_PAT)) { + printf("\"Load-IA32-PAT\" exit control not supported\n"); + return; + } + + test_pat_fields(HOST_PAT, "HOST_PAT", EXI_CONTROLS, EXI_LOAD_PAT); + + /* + * "load IA32_PAT" VM-entry control + */ + if (!(ctrl_enter_rev.clr & ENT_LOAD_PAT)) { + printf("\"Load-IA32-PAT\" entry control not supported\n"); + return; + } + + test_pat_fields(GUEST_PAT, "GUEST_PAT", ENT_CONTROLS, ENT_LOAD_PAT); +} + /* * Check that the virtual CPU checks the VMX Host State Area as * documented in the Intel SDM. @@ -5010,6 +5094,9 @@ static void vmx_host_state_area_test(void) test_sysenter_field(HOST_SYSENTER_ESP, "HOST_SYSENTER_ESP"); test_sysenter_field(HOST_SYSENTER_EIP, "HOST_SYSENTER_EIP"); + + test_load_pat(); + } static bool valid_vmcs_for_vmentry(void)