From patchwork Fri Jul 10 18:33:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11657241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47CCF17C7 for ; Fri, 10 Jul 2020 18:35:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 383D12078B for ; Fri, 10 Jul 2020 18:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728097AbgGJSfn (ORCPT ); Fri, 10 Jul 2020 14:35:43 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:7518 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbgGJSfn (ORCPT ); Fri, 10 Jul 2020 14:35:43 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 10 Jul 2020 11:35:38 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id CF6EE40CA9; Fri, 10 Jul 2020 11:35:42 -0700 (PDT) From: Nadav Amit To: Paolo Bonzini CC: , Nadav Amit Subject: [kvm-unit-tests PATCH 1/4] x86: svm: clear CR4.DE on DR intercept test Date: Fri, 10 Jul 2020 11:33:17 -0700 Message-ID: <20200710183320.27266-2-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200710183320.27266-1-namit@vmware.com> References: <20200710183320.27266-1-namit@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org DR4/DR5 can only be written when CR4.DE is clear, and otherwise trigger a #GP exception. The BIOS might not clear CR4.DE so update the tests not to make this assumption. Signed-off-by: Nadav Amit Reported-by: Nadav Amit Signed-off-by: Paolo Bonzini --- x86/svm_tests.c | 1 + 1 file changed, 1 insertion(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index d4d130f..9adee23 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -171,6 +171,7 @@ static void prepare_dr_intercept(struct svm_test *test) default_prepare(test); vmcb->control.intercept_dr_read = 0xff; vmcb->control.intercept_dr_write = 0xff; + vmcb->save.cr4 &= ~X86_CR4_DE; } static void test_dr_intercept(struct svm_test *test) From patchwork Fri Jul 10 18:33:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11657243 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6564D14E3 for ; Fri, 10 Jul 2020 18:35:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5542E2078B for ; Fri, 10 Jul 2020 18:35:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728031AbgGJSfn (ORCPT ); Fri, 10 Jul 2020 14:35:43 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:7518 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726872AbgGJSfn (ORCPT ); Fri, 10 Jul 2020 14:35:43 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 10 Jul 2020 11:35:38 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id DB23F40CB7; Fri, 10 Jul 2020 11:35:42 -0700 (PDT) From: Nadav Amit To: Paolo Bonzini CC: , Nadav Amit Subject: [kvm-unit-tests PATCH 2/4] x86: svm: present bit is set on nested page-faults Date: Fri, 10 Jul 2020 11:33:18 -0700 Message-ID: <20200710183320.27266-3-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200710183320.27266-1-namit@vmware.com> References: <20200710183320.27266-1-namit@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On nested page-faults due to write-protect or reserved bits, the present-bit in EXITINFO1 is set, as confirmed on bare-metal. Set the expected result accordingly. This indicates that KVM has a bug. Signed-off-by: Nadav Amit --- x86/svm_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 9adee23..7069e0b 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -816,7 +816,7 @@ static bool npt_rw_pfwalk_check(struct svm_test *test) *pte |= (1ULL << 1); return (vmcb->control.exit_code == SVM_EXIT_NPF) - && (vmcb->control.exit_info_1 == 0x200000006ULL) + && (vmcb->control.exit_info_1 == 0x200000007ULL) && (vmcb->control.exit_info_2 == read_cr3()); } @@ -835,7 +835,7 @@ static bool npt_rsvd_pfwalk_check(struct svm_test *test) pdpe[0] &= ~(1ULL << 8); return (vmcb->control.exit_code == SVM_EXIT_NPF) - && (vmcb->control.exit_info_1 == 0x20000000eULL); + && (vmcb->control.exit_info_1 == 0x20000000fULL); } static void npt_l1mmio_prepare(struct svm_test *test) From patchwork Fri Jul 10 18:33:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11657247 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADA5817C7 for ; Fri, 10 Jul 2020 18:35:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B2FC2078D for ; Fri, 10 Jul 2020 18:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbgGJSfq (ORCPT ); Fri, 10 Jul 2020 14:35:46 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:7518 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728022AbgGJSfn (ORCPT ); Fri, 10 Jul 2020 14:35:43 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 10 Jul 2020 11:35:38 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id E5FB040CBC; Fri, 10 Jul 2020 11:35:42 -0700 (PDT) From: Nadav Amit To: Paolo Bonzini CC: , Nadav Amit Subject: [kvm-unit-tests PATCH 3/4] x86: remove blind writes from setup_mmu() Date: Fri, 10 Jul 2020 11:33:19 -0700 Message-ID: <20200710183320.27266-4-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200710183320.27266-1-namit@vmware.com> References: <20200710183320.27266-1-namit@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Recent changes cause end_of_memory to be disregarded in 32-bit. Remove the blind writes to it. Signed-off-by: Nadav Amit --- lib/x86/vm.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/x86/vm.c b/lib/x86/vm.c index 2bc2a39..41d6d96 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -151,9 +151,6 @@ void *setup_mmu(phys_addr_t end_of_memory) setup_mmu_range(cr3, 0, end_of_memory); #else - if (end_of_memory > (1ul << 31)) - end_of_memory = (1ul << 31); - setup_mmu_range(cr3, 0, (2ul << 30)); setup_mmu_range(cr3, 3ul << 30, (1ul << 30)); init_alloc_vpage((void*)(3ul << 30)); From patchwork Fri Jul 10 18:33:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11657245 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 134C814F6 for ; Fri, 10 Jul 2020 18:35:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F033C2078B for ; Fri, 10 Jul 2020 18:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728173AbgGJSfr (ORCPT ); Fri, 10 Jul 2020 14:35:47 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:56297 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbgGJSfn (ORCPT ); Fri, 10 Jul 2020 14:35:43 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Fri, 10 Jul 2020 11:35:38 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id F24E540CB1; Fri, 10 Jul 2020 11:35:42 -0700 (PDT) From: Nadav Amit To: Paolo Bonzini CC: , Nadav Amit Subject: [kvm-unit-tests PATCH 4/4] x86: Allow to limit maximum RAM address Date: Fri, 10 Jul 2020 11:33:20 -0700 Message-ID: <20200710183320.27266-5-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200710183320.27266-1-namit@vmware.com> References: <20200710183320.27266-1-namit@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-001.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org While there is a feature to limit RAM memory, we should also be able to limit the maximum RAM address. Specifically, svm can only work when the maximum RAM address is lower than 4G, as it does not map the rest of the memory into the NPT. Allow to do so using the firmware, when in fact the expected use-case is to provide this infomation on bare-metal using the MEMLIMIT parameter in initrd. Signed-off-by: Nadav Amit --- lib/x86/fwcfg.c | 4 ++++ lib/x86/fwcfg.h | 1 + lib/x86/setup.c | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/lib/x86/fwcfg.c b/lib/x86/fwcfg.c index 06ef62c..c2aaf5a 100644 --- a/lib/x86/fwcfg.c +++ b/lib/x86/fwcfg.c @@ -28,6 +28,10 @@ static void read_cfg_override(void) if ((str = getenv("TEST_DEVICE"))) no_test_device = !atol(str); + if ((str = getenv("MEMLIMIT"))) + fw_override[FW_CFG_MAX_RAM] = atol(str) * 1024 * 1024; + + fw_override_done = true; } diff --git a/lib/x86/fwcfg.h b/lib/x86/fwcfg.h index 2f17461..64d4c6e 100644 --- a/lib/x86/fwcfg.h +++ b/lib/x86/fwcfg.h @@ -21,6 +21,7 @@ #define FW_CFG_BOOT_MENU 0x0e #define FW_CFG_MAX_CPUS 0x0f #define FW_CFG_MAX_ENTRY 0x10 +#define FW_CFG_MAX_RAM 0x11 #define FW_CFG_WRITE_CHANNEL 0x4000 #define FW_CFG_ARCH_LOCAL 0x8000 diff --git a/lib/x86/setup.c b/lib/x86/setup.c index b5941cd..7befe09 100644 --- a/lib/x86/setup.c +++ b/lib/x86/setup.c @@ -66,6 +66,9 @@ void find_highmem(void) u64 upper_end = bootinfo->mem_upper * 1024ull; u64 best_start = (uintptr_t) &edata; u64 best_end = upper_end; + u64 max_end = fwcfg_get_u64(FW_CFG_MAX_RAM); + if (max_end == 0) + max_end = -1ull; bool found = false; uintptr_t mmap = bootinfo->mmap_addr; @@ -79,8 +82,12 @@ void find_highmem(void) continue; if (mem->length < best_end - best_start) continue; + if (mem->base_addr >= max_end) + continue; best_start = mem->base_addr; best_end = mem->base_addr + mem->length; + if (best_end > max_end) + best_end = max_end; found = true; }