From patchwork Wed Dec 12 01:04:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10725425 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 86A786C5 for ; Wed, 12 Dec 2018 01:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70CB72AFBA for ; Wed, 12 Dec 2018 01:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E6862AFDD; Wed, 12 Dec 2018 01:29: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 C78D92AFBA for ; Wed, 12 Dec 2018 01:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726242AbeLLB3H (ORCPT ); Tue, 11 Dec 2018 20:29:07 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42010 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbeLLB3H (ORCPT ); Tue, 11 Dec 2018 20:29:07 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBC1J2ZD136208; Wed, 12 Dec 2018 01:29:00 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=5t4AB74Gfj1A+4jAXcegsfPNwsMRsIjgy1Em5+8Di9Y=; b=yQXCNBHZHKj6c+h3G/HjycMlGo40PXRe8OxGzBOd1Wd4XOkX7wweei1cKjaC4ZE0Ah/y ooeMsx667LOCu0Fnm5d+b35h8+xz+T+7ewJ65kPh/wbKUfPHZXp+LbOCVOwMsx5rbyX+ +Y0QgLtMvWOxitPbkdnffUvaMc/AczG8NCwPkx5g9cmCWAE2s3CedqKQp5cikC7gpCaB lUqRlafT/qGYvfcB9Q/RHUGE4QTDTz5KFbP87thFeCUX+iaSGw9LlqBjAy073X7RqaCs exHULzoRN99dine3LcX5aQYFEDrFsZFTznthaO1sY1xZ7LN8TJ75bY9LirJ+m5YsGiF4 pQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2p86kqy38k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:00 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wBC1Sxrp027117 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:00 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBC1SxHM020428; Wed, 12 Dec 2018 01:28:59 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Dec 2018 17:28:59 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [kvm-unit-test v2 1/4] KVM nVMX: Change the names of the functions test_vmcs_page_* to test_vmcs_addr_* Date: Tue, 11 Dec 2018 20:04:34 -0500 Message-Id: <20181212010437.11129-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181212010437.11129-1-krish.sadhukhan@oracle.com> References: <20181212010437.11129-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9104 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 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-1810050000 definitions=main-1812120009 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ... because these functions can be used for any VMCS address and not just a page. Signed-off-by: Krish Sadhukhan Reviewed-by: Jim Mattson --- x86/vmx_tests.c | 65 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index b105b23..bdd23df 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -3457,14 +3457,13 @@ static void test_cr3_targets(void) } /* - * Test a particular address setting for a physical page reference in - * the VMCS. + * Test a particular address setting in the VMCS */ -static void test_vmcs_page_addr(const char *name, - enum Encoding encoding, - bool ignored, - bool xfail_beyond_mapped_ram, - u64 addr) +static void test_vmcs_addr(const char *name, + enum Encoding encoding, + bool ignored, + bool xfail_beyond_mapped_ram, + u64 addr) { bool xfail = (xfail_beyond_mapped_ram && @@ -3481,9 +3480,9 @@ static void test_vmcs_page_addr(const char *name, } /* - * Test interesting values for a physical page reference in the VMCS. + * Test interesting values for a VMCS address */ -static void test_vmcs_page_values(const char *name, +static void test_vmcs_addr_values(const char *name, enum Encoding encoding, bool ignored, bool xfail_beyond_mapped_ram) @@ -3492,28 +3491,28 @@ static void test_vmcs_page_values(const char *name, u64 orig_val = vmcs_read(encoding); for (i = 0; i < 64; i++) - test_vmcs_page_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, 1ul << i); - - test_vmcs_page_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, PAGE_SIZE - 1); - test_vmcs_page_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, PAGE_SIZE); - test_vmcs_page_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, - (1ul << cpuid_maxphyaddr()) - PAGE_SIZE); - test_vmcs_page_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, - -1ul); + test_vmcs_addr(name, encoding, ignored, + xfail_beyond_mapped_ram, 1ul << i); + + test_vmcs_addr(name, encoding, ignored, + xfail_beyond_mapped_ram, PAGE_SIZE - 1); + test_vmcs_addr(name, encoding, ignored, + xfail_beyond_mapped_ram, PAGE_SIZE); + test_vmcs_addr(name, encoding, ignored, + xfail_beyond_mapped_ram, + (1ul << cpuid_maxphyaddr()) - PAGE_SIZE); + test_vmcs_addr(name, encoding, ignored, + xfail_beyond_mapped_ram, + -1ul); vmcs_write(encoding, orig_val); } /* - * Test a physical page reference in the VMCS, when the corresponding + * Test a physical address reference in the VMCS, when the corresponding * feature is enabled and when the corresponding feature is disabled. */ -static void test_vmcs_page_reference(u32 control_bit, enum Encoding field, +static void test_vmcs_addr_reference(u32 control_bit, enum Encoding field, const char *field_name, const char *control_name, bool xfail_beyond_mapped_ram, @@ -3540,7 +3539,7 @@ static void test_vmcs_page_reference(u32 control_bit, enum Encoding field, vmcs_write(CPU_EXEC_CTRL0, primary | CPU_SECONDARY); vmcs_write(CPU_EXEC_CTRL1, secondary | control_bit); } - test_vmcs_page_values(field_name, field, false, xfail_beyond_mapped_ram); + test_vmcs_addr_values(field_name, field, false, xfail_beyond_mapped_ram); report_prefix_pop(); report_prefix_pushf("%s disabled", control_name); @@ -3550,7 +3549,7 @@ static void test_vmcs_page_reference(u32 control_bit, enum Encoding field, vmcs_write(CPU_EXEC_CTRL0, primary & ~CPU_SECONDARY); vmcs_write(CPU_EXEC_CTRL1, secondary & ~control_bit); } - test_vmcs_page_values(field_name, field, true, false); + test_vmcs_addr_values(field_name, field, true, false); report_prefix_pop(); vmcs_write(field, page_addr); @@ -3565,10 +3564,10 @@ static void test_vmcs_page_reference(u32 control_bit, enum Encoding field, */ static void test_io_bitmaps(void) { - test_vmcs_page_reference(CPU_IO_BITMAP, IO_BITMAP_A, + test_vmcs_addr_reference(CPU_IO_BITMAP, IO_BITMAP_A, "I/O bitmap A", "Use I/O bitmaps", false, true); - test_vmcs_page_reference(CPU_IO_BITMAP, IO_BITMAP_B, + test_vmcs_addr_reference(CPU_IO_BITMAP, IO_BITMAP_B, "I/O bitmap B", "Use I/O bitmaps", false, true); } @@ -3581,7 +3580,7 @@ static void test_io_bitmaps(void) */ static void test_msr_bitmap(void) { - test_vmcs_page_reference(CPU_MSR_BITMAP, MSR_BITMAP, + test_vmcs_addr_reference(CPU_MSR_BITMAP, MSR_BITMAP, "MSR bitmap", "Use MSR bitmaps", false, true); } @@ -3596,7 +3595,7 @@ static void test_msr_bitmap(void) */ static void test_apic_virt_addr(void) { - test_vmcs_page_reference(CPU_TPR_SHADOW, APIC_VIRT_ADDR, + test_vmcs_addr_reference(CPU_TPR_SHADOW, APIC_VIRT_ADDR, "virtual-APIC address", "Use TPR shadow", true, true); } @@ -3615,7 +3614,7 @@ static void test_apic_access_addr(void) vmcs_write(APIC_ACCS_ADDR, virt_to_phys(apic_access_page)); - test_vmcs_page_reference(CPU_VIRT_APIC_ACCESSES, APIC_ACCS_ADDR, + test_vmcs_addr_reference(CPU_VIRT_APIC_ACCESSES, APIC_ACCS_ADDR, "APIC-access address", "virtualize APIC-accesses", false, false); } @@ -3903,7 +3902,7 @@ static void test_posted_intr(void) test_pi_desc_addr(0x00, true); test_pi_desc_addr(0xc000, true); - test_vmcs_page_values("process-posted interrupts", + test_vmcs_addr_values("process-posted interrupts", POSTED_INTR_DESC_ADDR, false, false); vmcs_write(CPU_EXEC_CTRL0, saved_primary); @@ -4714,7 +4713,7 @@ static void test_pml(void) test_vmx_controls(true, false); report_prefix_pop(); - test_vmcs_page_reference(CPU_PML, PMLADDR, "PML address", + test_vmcs_addr_reference(CPU_PML, PMLADDR, "PML address", "PML", false, false); vmcs_write(CPU_EXEC_CTRL0, primary_saved); From patchwork Wed Dec 12 01:04:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10725429 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 721411751 for ; Wed, 12 Dec 2018 01:29:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63DF02AFBA for ; Wed, 12 Dec 2018 01:29:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5835A2AFDD; Wed, 12 Dec 2018 01:29:12 +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 D26BE2AFBA for ; Wed, 12 Dec 2018 01:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbeLLB3L (ORCPT ); Tue, 11 Dec 2018 20:29:11 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:55924 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeLLB3J (ORCPT ); Tue, 11 Dec 2018 20:29:09 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBC1J8vC128958; Wed, 12 Dec 2018 01:29:01 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=hrktMKEqV0YoTJEF6zOzK52wF7NB+MEmccFd8Eu0/SI=; b=SFcM538sIgKVPB+llGnM7kdZGYNCCgHPcrqEMI7t+EHG6/Sg/UpQSiNKKAlbGW+TtjHb ONZPeUTm8+BIFlLIMZAPKM4sv67OCX0nKwZITapKw0SBYSiaadm2LCh891/3zZ1eUuBB keM32/FWEereJK20WjdP0j/EqiieXgZA9Oj8YSPh6aTetQiVfaAuuUenkIvLzd/fbhe/ vSbmyId01lsnD48vUkC31HdTkxJIWvp4V7phmEjSt8ufkIr243agl8T4dRkeKMWATQj2 aqTVy7nHZ7ix/LcAwkGnLgPQkmis3ZZ0IgMm5DIE0zhKZ6xZdDaq/dA+kBb6Wul8BtcM XA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2p83fe79xt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:01 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wBC1T0v4024951 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:01 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBC1T0Op000808; Wed, 12 Dec 2018 01:29:00 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Dec 2018 17:29:00 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [kvm-unit-test v2 2/4] KVM nVMX: test_vmcs_page_* functions need to accept alignment size as a parameter Date: Tue, 11 Dec 2018 20:04:35 -0500 Message-Id: <20181212010437.11129-3-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181212010437.11129-1-krish.sadhukhan@oracle.com> References: <20181212010437.11129-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9104 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=659 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812120009 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP .. because not all alignments fall on page size boundary. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas --- x86/vmx_tests.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index bdd23df..3e6babe 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -3463,16 +3463,17 @@ static void test_vmcs_addr(const char *name, enum Encoding encoding, bool ignored, bool xfail_beyond_mapped_ram, - u64 addr) + u64 addr, + u64 align) { bool xfail = (xfail_beyond_mapped_ram && - addr > fwcfg_get_u64(FW_CFG_RAM_SIZE) - PAGE_SIZE && + addr > fwcfg_get_u64(FW_CFG_RAM_SIZE) - align && addr < (1ul << cpuid_maxphyaddr())); report_prefix_pushf("%s = %lx", name, addr); vmcs_write(encoding, addr); - test_vmx_controls(ignored || (IS_ALIGNED(addr, PAGE_SIZE) && + test_vmx_controls(ignored || (IS_ALIGNED(addr, align) && addr < (1ul << cpuid_maxphyaddr())), xfail); report_prefix_pop(); @@ -3485,25 +3486,26 @@ static void test_vmcs_addr(const char *name, static void test_vmcs_addr_values(const char *name, enum Encoding encoding, bool ignored, - bool xfail_beyond_mapped_ram) + bool xfail_beyond_mapped_ram, + u64 align) { unsigned i; u64 orig_val = vmcs_read(encoding); for (i = 0; i < 64; i++) test_vmcs_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, 1ul << i); + xfail_beyond_mapped_ram, 1ul << i, align); test_vmcs_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, PAGE_SIZE - 1); + xfail_beyond_mapped_ram, PAGE_SIZE - 1, align); test_vmcs_addr(name, encoding, ignored, - xfail_beyond_mapped_ram, PAGE_SIZE); + xfail_beyond_mapped_ram, PAGE_SIZE, align); test_vmcs_addr(name, encoding, ignored, xfail_beyond_mapped_ram, - (1ul << cpuid_maxphyaddr()) - PAGE_SIZE); + (1ul << cpuid_maxphyaddr()) - PAGE_SIZE, align); test_vmcs_addr(name, encoding, ignored, xfail_beyond_mapped_ram, - -1ul); + -1ul, align); vmcs_write(encoding, orig_val); } @@ -3516,7 +3518,7 @@ static void test_vmcs_addr_reference(u32 control_bit, enum Encoding field, const char *field_name, const char *control_name, bool xfail_beyond_mapped_ram, - bool control_primary) + bool control_primary, u64 align) { u32 primary = vmcs_read(CPU_EXEC_CTRL0); u32 secondary = vmcs_read(CPU_EXEC_CTRL1); @@ -3539,7 +3541,8 @@ static void test_vmcs_addr_reference(u32 control_bit, enum Encoding field, vmcs_write(CPU_EXEC_CTRL0, primary | CPU_SECONDARY); vmcs_write(CPU_EXEC_CTRL1, secondary | control_bit); } - test_vmcs_addr_values(field_name, field, false, xfail_beyond_mapped_ram); + test_vmcs_addr_values(field_name, field, false, + xfail_beyond_mapped_ram, align); report_prefix_pop(); report_prefix_pushf("%s disabled", control_name); @@ -3549,7 +3552,7 @@ static void test_vmcs_addr_reference(u32 control_bit, enum Encoding field, vmcs_write(CPU_EXEC_CTRL0, primary & ~CPU_SECONDARY); vmcs_write(CPU_EXEC_CTRL1, secondary & ~control_bit); } - test_vmcs_addr_values(field_name, field, true, false); + test_vmcs_addr_values(field_name, field, true, false, align); report_prefix_pop(); vmcs_write(field, page_addr); @@ -3566,10 +3569,10 @@ static void test_io_bitmaps(void) { test_vmcs_addr_reference(CPU_IO_BITMAP, IO_BITMAP_A, "I/O bitmap A", "Use I/O bitmaps", false, - true); + true, PAGE_SIZE); test_vmcs_addr_reference(CPU_IO_BITMAP, IO_BITMAP_B, "I/O bitmap B", "Use I/O bitmaps", false, - true); + true, PAGE_SIZE); } /* @@ -3582,7 +3585,7 @@ static void test_msr_bitmap(void) { test_vmcs_addr_reference(CPU_MSR_BITMAP, MSR_BITMAP, "MSR bitmap", "Use MSR bitmaps", false, - true); + true, PAGE_SIZE); } /* @@ -3597,7 +3600,7 @@ static void test_apic_virt_addr(void) { test_vmcs_addr_reference(CPU_TPR_SHADOW, APIC_VIRT_ADDR, "virtual-APIC address", "Use TPR shadow", - true, true); + true, true, PAGE_SIZE); } /* @@ -3616,7 +3619,8 @@ static void test_apic_access_addr(void) test_vmcs_addr_reference(CPU_VIRT_APIC_ACCESSES, APIC_ACCS_ADDR, "APIC-access address", - "virtualize APIC-accesses", false, false); + "virtualize APIC-accesses", false, false, + PAGE_SIZE); } static bool set_bit_pattern(u8 mask, u32 *secondary) @@ -4714,7 +4718,7 @@ static void test_pml(void) report_prefix_pop(); test_vmcs_addr_reference(CPU_PML, PMLADDR, "PML address", - "PML", false, false); + "PML", false, false, PAGE_SIZE); vmcs_write(CPU_EXEC_CTRL0, primary_saved); vmcs_write(CPU_EXEC_CTRL1, secondary_saved); From patchwork Wed Dec 12 01:04:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10725431 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 2F1001751 for ; Wed, 12 Dec 2018 01:29:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2081D2AFBA for ; Wed, 12 Dec 2018 01:29:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 153F32AFDD; Wed, 12 Dec 2018 01:29:13 +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 B5D6D2AFBA for ; Wed, 12 Dec 2018 01:29:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbeLLB3J (ORCPT ); Tue, 11 Dec 2018 20:29:09 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42026 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbeLLB3I (ORCPT ); Tue, 11 Dec 2018 20:29:08 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBC1J1NN136205; Wed, 12 Dec 2018 01:29: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=7O7qc55yKA/c9GZx1GhUxxGXN9vIG0d3D9C4GwP83LI=; b=z2JQCVQwdwQLgu+yO8Ys9edU6Tyuvm9M5hQD808RGSArHKYYVL8TOoFIyJEtWPcVOxHv J1GSirCnVZ67LZJ0CjiNNPfrRFVNFkzOljKKdvYe23BB7nJIkDS5T0OBfn0mTUp3ydhA XFQujPFX1/Z61HoIhd3ZRuLZD+VG2vr8hrtak5t5KVyavdwsmhsB9I1sGBrwhZbZm93e 1lr0XMO6PwJMqGouDxSvVJGekltuF9mGE2EuTc+mGUm94rnfVKDgRQj7FWJ79IdDXnCl vmaaRECul1MuB10uwtwzqwJNObvtk2r0HWrtYgCwWKwXCh1cvDPW9Dy4udY33/e4KeqN +A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2p86kqy38n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:01 +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 wBC1T0lk030317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:01 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wBC1T0pR001445; Wed, 12 Dec 2018 01:29:00 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Dec 2018 17:29:00 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [kvm-unit-test v2 3/4] KVM nVMX: test_vmcs_page_values() needs to accept a bit range Date: Tue, 11 Dec 2018 20:04:36 -0500 Message-Id: <20181212010437.11129-4-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181212010437.11129-1-krish.sadhukhan@oracle.com> References: <20181212010437.11129-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9104 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 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-1810050000 definitions=main-1812120009 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ... because various addresses need to be tested for various bit ranges. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas --- x86/vmx_tests.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 3e6babe..b56f870 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -3487,12 +3487,12 @@ static void test_vmcs_addr_values(const char *name, enum Encoding encoding, bool ignored, bool xfail_beyond_mapped_ram, - u64 align) + u64 align, u32 addr_start, u32 addr_end) { unsigned i; u64 orig_val = vmcs_read(encoding); - for (i = 0; i < 64; i++) + for (i = addr_start; i < addr_end; i++) test_vmcs_addr(name, encoding, ignored, xfail_beyond_mapped_ram, 1ul << i, align); @@ -3541,8 +3541,9 @@ static void test_vmcs_addr_reference(u32 control_bit, enum Encoding field, vmcs_write(CPU_EXEC_CTRL0, primary | CPU_SECONDARY); vmcs_write(CPU_EXEC_CTRL1, secondary | control_bit); } + test_vmcs_addr_values(field_name, field, false, - xfail_beyond_mapped_ram, align); + xfail_beyond_mapped_ram, align, 0, 64); report_prefix_pop(); report_prefix_pushf("%s disabled", control_name); @@ -3552,7 +3553,9 @@ static void test_vmcs_addr_reference(u32 control_bit, enum Encoding field, vmcs_write(CPU_EXEC_CTRL0, primary & ~CPU_SECONDARY); vmcs_write(CPU_EXEC_CTRL1, secondary & ~control_bit); } - test_vmcs_addr_values(field_name, field, true, false, align); + + test_vmcs_addr_values(field_name, field, true, false, align, + 0, 64); report_prefix_pop(); vmcs_write(field, page_addr); @@ -3907,7 +3910,7 @@ static void test_posted_intr(void) test_pi_desc_addr(0xc000, true); test_vmcs_addr_values("process-posted interrupts", - POSTED_INTR_DESC_ADDR, false, false); + POSTED_INTR_DESC_ADDR, false, false, PAGE_SIZE, 0, 64); vmcs_write(CPU_EXEC_CTRL0, saved_primary); vmcs_write(CPU_EXEC_CTRL1, saved_secondary); From patchwork Wed Dec 12 01:04:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10725427 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 089336C5 for ; Wed, 12 Dec 2018 01:29:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED8612AFBA for ; Wed, 12 Dec 2018 01:29:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1AB92AFDD; Wed, 12 Dec 2018 01:29:10 +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 73B5C2AFBA for ; Wed, 12 Dec 2018 01:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726256AbeLLB3J (ORCPT ); Tue, 11 Dec 2018 20:29:09 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:55926 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbeLLB3J (ORCPT ); Tue, 11 Dec 2018 20:29:09 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBC1JVma129141; Wed, 12 Dec 2018 01:29: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 : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=C1MjjCcE7aUNhRkuKEtKP1usYiiIjkgOsB7cWfy5aA0=; b=ZeIxHIbT1sl4eIfVq7ULpNsXc620FCt/tsjprzUhnqKWlBy9zIIHfvFmd5m7KRXk+tbZ AlC67ERiVeGpHNkacsfQhKfchDbYeIxf355zHHBsOzbz11Hw8e+GYJMINt4dwaHBeg77 Vw5AckNYZBLTBbnYbqyFr5K4wKLdRl4Un8ztd6Cmwh7pfUA/ZEAYFOvkrTJn21Rdqt5V PWQk9Qr92SVzBfEM1DpZ4kKan+6eSVHvHuSzf0Ly0sToI2p+w5GtTx4J/LYtVwcT+PED VVwMC8CGeqbrSCTKcJhrRlrYr4siCD/EBT9T2LIG0k/s2d4bq+/xqRyM3B1+2HGc0cGW Sg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2p83fe79xu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:02 +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 wBC1T1cl030336 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Dec 2018 01:29:01 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBC1T1ga000814; Wed, 12 Dec 2018 01:29:01 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Dec 2018 17:29:00 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [kvm-unit-test v2 4/4] KVM nVMX: Check VM-exit MSR-store address on vmentry of L2 guests Date: Tue, 11 Dec 2018 20:04:37 -0500 Message-Id: <20181212010437.11129-5-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181212010437.11129-1-krish.sadhukhan@oracle.com> References: <20181212010437.11129-1-krish.sadhukhan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9104 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=813 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812120009 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 VMX Controls" in Intel SDM vol 3C, the following checks performed for the VM-exit MSR-store address if the the VM-exit MSR-store count field is non-zero: - The lower 4 bits of the VM-exit MSR-store address must be 0. The address should not set any bits beyond the processor’s physical-address width. - The address of the last byte in the VM-exit MSR-store area should not set any bits beyond the processor’s physical-address width. The address of this last byte is VM-exit MSR-store address + (MSR count * 16) - 1. (The arithmetic used for the computation uses more bits than the processor’s physical-address width.) If IA32_VMX_BASIC[48] is read as 1, neither address should set any bits in the range 63:32. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas --- x86/vmx_tests.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index b56f870..fad2bd6 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4728,6 +4728,83 @@ static void test_pml(void) } /* + * The following checks are performed for the VM-exit MSR-store address if + * the VM-exit MSR-store count field is non-zero: + * + * - The lower 4 bits of the VM-exit MSR-store address must be 0. + * The address should not set any bits beyond the processor’s + * physical-address width. + * + * - The address of the last byte in the VM-exit MSR-store area + * should not set any bits beyond the processor’s physical-address + * width. The address of this last byte is VM-exit MSR-store address + * + (MSR count * 16) - 1. (The arithmetic used for the computation + * uses more bits than the processor’s physical-address width.) + * + * If IA32_VMX_BASIC[48] is read as 1, neither address should set any bits + * in the range 63:32. + * + * [Intel SDM] + */ +static void test_exit_msr_store(void) +{ + exit_msr_store = alloc_page(); + u64 tmp; + u32 exit_msr_st_cnt = 1; + int i; + u32 addr_len = 64; + + vmcs_write(EXI_MSR_ST_CNT, exit_msr_st_cnt); + + /* Check first 4 bits of VM-exit MSR-store address */ + for (i = 0; i < 4; i++) { + tmp = (u64)exit_msr_store | 1ull << i; + vmcs_write(EXIT_MSR_ST_ADDR, tmp); + report_prefix_pushf("VM-exit MSR-store addr [4:0] %lx", + tmp & 0xf); + test_vmx_controls(false, false); + report_prefix_pop(); + } + + if (basic.val & (1ul << 48)) + addr_len = 32; + + test_vmcs_addr_values("VM-exit-MSR-store address", + EXIT_MSR_ST_ADDR, false, false, 16, + 4, addr_len - 1); + + /* + * Check last byte of VM-exit MSR-store address + */ + exit_msr_store = (struct vmx_msr_entry *)((u64)exit_msr_store & ~0xf); + + for (i = (addr_len == 64 ? cpuid_maxphyaddr(): addr_len); + i < 64; i++) { + tmp = ((u64)exit_msr_store + exit_msr_st_cnt * 16 - 1) | + 1ul << i; + vmcs_write(EXIT_MSR_ST_ADDR, + tmp - (exit_msr_st_cnt * 16 - 1)); + test_vmx_controls(false, false); + } + + vmcs_write(EXI_MSR_ST_CNT, 2); + vmcs_write(EXIT_MSR_ST_ADDR, (1ULL << cpuid_maxphyaddr()) - 16); + test_vmx_controls(false, false); + vmcs_write(EXIT_MSR_ST_ADDR, (1ULL << cpuid_maxphyaddr()) - 32); + test_vmx_controls(true, false); + vmcs_write(EXIT_MSR_ST_ADDR, (1ULL << cpuid_maxphyaddr()) - 48); + test_vmx_controls(true, false); +} + +/* + * Tests for VM-exit controls + */ +static void test_vm_exit_ctls(void) +{ + test_exit_msr_store(); +} + +/* * Check that the virtual CPU checks all of the VMX controls as * documented in the Intel SDM. */ @@ -4753,6 +4830,7 @@ static void vmx_controls_test(void) test_invalid_event_injection(); test_vpid(); test_eptp(); + test_vm_exit_ctls(); } static bool valid_vmcs_for_vmentry(void)