From: Nadav Amit Subject: Re: 2 CPU Conformance Issue in KVM/x86 Date: Mon, 9 Mar 2015 21:07:50 +0200 Message-ID: <13DCF857-5591-4499-9B0D-4165268E9CE8@gmail.com> References: <54F58471.7020906@redhat.com> <54FDD39C.9060908@gmail.com> <6073FF8F-E261-4DC3-817A-9F4A46B5C0DB@gmail.com> <54FDE50B.8040408@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Paolo Bonzini , kvm list , =?utf-8?Q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= To: Avi Kivity Return-path: Received: from mail-wi0-f170.google.com ([209.85.212.170]:34206 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752393AbbCITHy convert rfc822-to-8bit (ORCPT ); Mon, 9 Mar 2015 15:07:54 -0400 Received: by wiwl15 with SMTP id l15so22960568wiw.1 for ; Mon, 09 Mar 2015 12:07:52 -0700 (PDT) In-Reply-To: <54FDE50B.8040408@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Avi Kivity wrote: > On 03/09/2015 07:51 PM, Nadav Amit wrote: >> Avi Kivity wrote: >>=20 >>> On 03/03/2015 11:52 AM, Paolo Bonzini wrote: >>>>> In this >>>>> case, the VM might expect exceptions when PTE bits which are high= er than the >>>>> maximum (reported) address width are set, and it would not get su= ch >>>>> exceptions. This problem can easily be experienced by small chang= e to the >>>>> existing KVM unit-tests. >>>>>=20 >>>>> There are many variants to this problem, and the only solution wh= ich I >>>>> consider complete is to report to the VM the maximum (52) physica= l address >>>>> width to the VM, configure the VM to exit on #PF with reserved-bi= t >>>>> error-codes, and then emulate these faulting instructions. >>>> Not even that would be a definitive solution. If the guest tries = to map >>>> RAM (e.g. a PCI BAR that is backed by RAM) above the host MAXPHYAD= DR, >>>> you would get EPT misconfiguration vmexits. >>>>=20 >>>> I think there is no way to emulate physical address width correctl= y, >>>> except by disabling EPT. >>> Is the issue emulating a higher MAXPHYADDR on the guest than is ava= ilable >>> on the host? I don't think there's any need to support that. >>>=20 >>> Emulating a lower setting on the guest than is available on the hos= t is, I >>> think, desirable. Whether it would work depends on the relative pri= ority >>> of EPT misconfiguration exits vs. page table permission faults. >> Thanks for the feedback. >>=20 >> Guest page-table permissions faults got priority over EPT misconfigu= ration. >> KVM can even be set to trap page-table permission faults, at least i= n VT-x. >> Anyhow, I don=E2=80=99t think it is enough. >=20 > Why is it not enough? If you trap a permission fault, you can inject = any exception error code you like. Because there is no real permission fault. In the following example, th= e VM expects one (VM=E2=80=99s MAXPHYADDR=3D40), but there isn=E2=80=99t (Ho= st=E2=80=99s MAXPHYADDR=3D46), so the hypervisor cannot trap it. It can only trap all #PF, which is obvio= usly too intrusive. >> Here is an example >>=20 >> My machine has MAXPHYADDR of 46. I modified kvm-unit-tests access te= st to >> set pte.45 instead of pte.51, which from the VM point-of-view should= cause >> the #PF error-code indicate the reserved bits are set (just as pte.5= 1 does). >> Here is one error from the log: >>=20 >> test pte.p pte.45 pde.p user: FAIL: error code 5 expected d >> Dump mapping: address: 123400000000 >> ------L4: 304b007 >> ------L3: 304c007 >> ------L2: 304d001 >> ------L1: 200002000001 >=20 > This is with an ept misconfig programmed into that address, yes? A reserved bit in the PTE is set - from the VM point-of-view. If there wasn=E2=80=99t another cause for #PF, it would lead to EPT violation/mi= sconfig. >> As you can see, the #PF should have had two reasons: reserved bits, = and user >> access to supervisor only page. The error-code however does not indi= cate the >> reserved-bits are set. >>=20 >> Note that KVM did not trap any exit on that faulting instruction, as >> otherwise it would try to emulate the instruction and assuming it is >> supported (and that the #PF was not on an instruction fetch), should= be able >> to emulate the #PF correctly. >> [ The test actually crashes soon after this error due to these reaso= ns. ] >>=20 >> Anyhow, that is the reason for me to assume that having the maximum >> MAXPHYADDR is better. >=20 > Well, that doesn't work for the reasons Paolo noted. The guest can h= ave a ivshmem device attached, and map it above a host-supported virtua= l address, and suddenly it goes slow. I fully understand. That=E2=80=99s the reason I don=E2=80=99t have a re= asonable solution. Regards, Nadav