From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932490AbbJMQ2b (ORCPT ); Tue, 13 Oct 2015 12:28:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55619 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753082AbbJMQ23 (ORCPT ); Tue, 13 Oct 2015 12:28:29 -0400 Subject: Re: [PATCH 2/2] KVM: x86: map/unmap private slots in __x86_set_memory_region To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1444651758-6926-1-git-send-email-pbonzini@redhat.com> <1444651758-6926-3-git-send-email-pbonzini@redhat.com> <20151013153957.GA9987@potion.brq.redhat.com> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, aderumier@odiso.com, stable@vger.kernel.org From: Paolo Bonzini X-Enigmail-Draft-Status: N1110 Message-ID: <561D3126.8060402@redhat.com> Date: Tue, 13 Oct 2015 18:28:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151013153957.GA9987@potion.brq.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/10/2015 17:39, Radim Krčmář wrote: > 2015-10-12 14:09+0200, Paolo Bonzini: >> Otherwise, two copies (one of them never used and thus bogus) are >> allocated for the regular and SMM address spaces. This breaks >> SMM with EPT but without unrestricted guest support, because the >> SMM copy of the identity page map is all zeros. > > (Have you found out why EPT+unrestricted didn't use the alternative SMM > mapping as well?) Yes, that I already knew; EPT+unrestricted uses CR0.PG=0 directly so it doesn't use the identity page at all. (CR0.PG=0 w/o unrestricted instead runs with CR0.PG=1. CR3 load and store exits are enabled, and the guest CR3 always points to the identity page map while the guest runs). >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> @@ -7717,23 +7717,53 @@ void kvm_arch_sync_events(struct kvm *kvm) >> int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size) >> { >> int i, r; >> + u64 hva; >> + struct kvm_memslots *slots = kvm_memslots(kvm); >> + struct kvm_memory_slot *slot, old; > | [...] >> + slot = &slots->memslots[slots->id_to_index[id]]; > > This seems better written as > > slot = id_to_memslot(slots, id); Gah, I could not recall the right API! I'll fix it. > (Made me remember that I want to refactor the memslot API ...) > > | [...] >> + } else { >> + if (!slot->npages) >> + return 0; >> + >> + hva = 0; >> + } >> + >> + old = *slot; > > (Assignment could be in the 'else' == !size branch, GCC would have fun.) It would have fun _and_ warn, which is why it's not in the else branch. :) Paolo