Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751642AbdG0Qgg (ORCPT ); Thu, 27 Jul 2017 12:36:36 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35033 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbdG0Qgf (ORCPT ); Thu, 27 Jul 2017 12:36:35 -0400 Subject: Re: [PATCH v2 1/3] kvm: svm: Add support for additional SVM NPF error codes To: Brijesh Singh , kvm@vger.kernel.org Cc: thomas.lendacky@amd.com, rkrcmar@redhat.com, joro@8bytes.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, tglx@linutronix.de, bp@suse.de References: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> <147992049856.27638.17076562184960611399.stgit@brijesh-build-machine> From: Paolo Bonzini Message-ID: Date: Thu, 27 Jul 2017 18:27:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <147992049856.27638.17076562184960611399.stgit@brijesh-build-machine> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 937 Lines: 26 On 23/11/2016 18:01, Brijesh Singh wrote: > > + /* > + * Before emulating the instruction, check if the error code > + * was due to a RO violation while translating the guest page. > + * This can occur when using nested virtualization with nested > + * paging in both guests. If true, we simply unprotect the page > + * and resume the guest. > + * > + * Note: AMD only (since it supports the PFERR_GUEST_PAGE_MASK used > + * in PFERR_NEXT_GUEST_PAGE) > + */ > + if (error_code == PFERR_NESTED_GUEST_PAGE) { > + kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(cr2)); > + return 1; > + } What happens if L1 is mapping some memory that is read only in L0? That is, the L1 nested page tables make it read-write, but the L0 shadow nested page tables make it read-only. Accessing it would cause an NPF, and then my guess is that the L1 guest would loop on the failing instruction instead of just dropping the write. Paolo