From: Christian Borntraeger Subject: Re: [PATCH v1 4/4] KVM: s390: vsie: use common code functions for pinning Date: Fri, 1 Sep 2017 14:49:54 +0200 Message-ID: References: <20170830160603.5452-1-david@redhat.com> <20170830160603.5452-5-david@redhat.com> <1fe98513-327e-8f12-81cd-9ff733f535d5@de.ibm.com> <1efcb979-fa41-1fba-6095-71405a39cf2f@redhat.com> <7caeb543-0239-eb6e-b2a1-23e9b9bb6cc9@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Cornelia Huck To: David Hildenbrand , kvm@vger.kernel.org Return-path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56092 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751839AbdIAMuB (ORCPT ); Fri, 1 Sep 2017 08:50:01 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v81CnDqQ048416 for ; Fri, 1 Sep 2017 08:50:01 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cq2ea67g5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 01 Sep 2017 08:50:01 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 1 Sep 2017 13:49:58 +0100 In-Reply-To: <7caeb543-0239-eb6e-b2a1-23e9b9bb6cc9@redhat.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 08/31/2017 03:00 PM, David Hildenbrand wrote: > On 31.08.2017 14:22, Christian Borntraeger wrote: >> >> >> On 08/31/2017 02:13 PM, David Hildenbrand wrote: >>> On 31.08.2017 13:44, Christian Borntraeger wrote: >>>> >>>> >>>> On 08/30/2017 06:06 PM, David Hildenbrand wrote: >>>>> Signed-off-by: David Hildenbrand >>>>> --- >>>>> arch/s390/kvm/vsie.c | 19 +++++-------------- >>>>> include/linux/kvm_host.h | 1 + >>>>> virt/kvm/kvm_main.c | 4 ++-- >>>>> 3 files changed, 8 insertions(+), 16 deletions(-) >>>>> >>>>> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c >>>>> index b5eec30eb37d..a21763b4c229 100644 >>>>> --- a/arch/s390/kvm/vsie.c >>>>> +++ b/arch/s390/kvm/vsie.c >>>>> @@ -445,17 +445,12 @@ static int map_prefix(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) >>>>> static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa) >>>>> { >>>>> struct page *page; >>>>> - hva_t hva; >>>>> - int rc; >>>>> >>>>> - hva = gfn_to_hva(kvm, gpa_to_gfn(gpa)); >>>>> - if (kvm_is_error_hva(hva)) >>>>> - return -EINVAL; >>>>> - rc = get_user_pages_fast(hva, 1, 1, &page); >>>>> - if (rc < 0) >>>>> - return rc; >>>>> - else if (rc != 1) >>>>> + page = gfn_to_page(kvm, gpa_to_gfn(gpa)); >>>>> + if (PTR_ERR(page) == -ENOMEM) >>>>> return -ENOMEM; >>>> >>>> Can this actually happen? Reading gfn_to_page does not seem >>>> to have a path that returns ENOMEM. >>>> >>> >>> Boils down to what get_user_pages_fast() guarantees (which is called by >>> gfn_to_hva() now). It can call __get_user_pages(). And there I can at >>> least spot a -ENOMEM potentially coming out of faultin_page(). >>> This check essentially makes sure that the behavior of pin_guest_page() >>> doesn't change (this function is specified to return either -ENOMEM or >>> -EINVAL). So unless there is a very good reason, I think we should keep >>> it that way. >> >> I might be misreading the code, but it looks like that >> gfn_to_page will will call >> kvm_pfn_to_page and that function will return KVM_ERR_PTR_BAD_PAGE if something >> fails (which is (ERR_PTR(-ENOENT)). But it will never return ERR_PTR(-ENOMEM) >> >> > > Guess I am getting lost in abstraction layers :) > > I think you're right, is_error_noslot_pfn() in kvm_pfn_to_page() should > convert all such errors to KVM_ERR_PTR_BAD_PAGE. > > -ENOMEM was a theoretical case at that point either way in my opinion. > > So, this would boil down to: > > > From a2cf5d109fc6342df12e361b665c92b73f66cfee Mon Sep 17 00:00:00 2001 > From: David Hildenbrand > Date: Thu, 3 Aug 2017 22:30:40 +0200 > Subject: [PATCH v2 1/1] KVM: s390: vsie: use common code functions for > pinning > > We will not see -ENOMEM (gfn_to_hva() will return KVM_ERR_PTR_BAD_PAGE > for all errors). So we can also get rid of special handling in the > callers of pin_guest_page() and always assume that it is a g2 error. > > As also kvm_s390_inject_program_int() should never fail, we can > simplify pin_scb(), too. > > Signed-off-by: David Hildenbrand Can you send it as a new patch please?