Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3087755pxf; Mon, 15 Mar 2021 00:35:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJtX4I+VJrnuzRMacuAvIAOpty9R9SrisUpRoy92k8JKqM61xNNQa2j9+of3Fs9yQWxxJr X-Received: by 2002:a50:fd8b:: with SMTP id o11mr28241223edt.346.1615793727688; Mon, 15 Mar 2021 00:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615793727; cv=none; d=google.com; s=arc-20160816; b=023a+po4H43L7JCAMCd8C8R1cy5cBZvVXcjZ4qXyy1tJwZC7xR41DYdxOiguYotr9l iqCp3v5hoUe/Dv2XVv2yYUec96fDz7bB4Zc+si/aZBDdAY5CAWnVj5Et0ed+Uwv4/KM2 ITmY6MXMvPzgsVkVNyjFkFT+zy4wK8T51b4EeXGr0O3aljOOKiLJZJxP8vwOIwJy5Pxq Uo15+v3zq2VT+2XqFRueinMz5i332O2E5Fe9d2gz3vqgYML1+mMC1kC5AL6BVq/3CRRF UMHi7JeN3FotxgxRoDaBaL+8iWqg/wjnBAsZV/eqxmC6DrkCeX3HjENn07bMYoIY/65p tBbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=434j4avn2vS8yqiW9Jqua+qFUOR4J92bWOfOryOhCko=; b=Gos4QO0cfo//C6P91tmm996Q+ZuybWU63rTcIKODov4SiE9UF8Nk8/Ss7x569JqzHr to3jLV//DRzPxSwTvgzFojxxQFJGGlVYTnZznlrzs9KXzFaYuZQiePm97U+8IRni3ORh yvkN5RFKDqcR0ZYeM+vosVsYN9JOCC/Tp0pUSf8N5p+5Sy/gHUMWp+LruorcuHcy1pBI UUV8l9U1jrgVgnjJ5rXG5ON/Bq6+MK/VGPyhawyc9N50rdSj94KeLvwkyEbKolv/Jh7I WBNPJ5NzgMZPZ39U7MhzqNIPPOHiOquNuS0jDc9vUiTa4aybkz2dQdy+IbuZonEDSDKW jhwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ho11si10520363ejc.258.2021.03.15.00.35.04; Mon, 15 Mar 2021 00:35:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbhCOHeH (ORCPT + 99 others); Mon, 15 Mar 2021 03:34:07 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:14338 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbhCOHdo (ORCPT ); Mon, 15 Mar 2021 03:33:44 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DzSm56Pybz8yRT; Mon, 15 Mar 2021 15:31:49 +0800 (CST) Received: from [10.174.184.42] (10.174.184.42) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Mon, 15 Mar 2021 15:33:39 +0800 Subject: Re: [PATCH 3/4] KVM: arm64: Fix address check for memory slot To: Gavin Shan , References: <20210315041844.64915-1-gshan@redhat.com> <20210315041844.64915-4-gshan@redhat.com> CC: , , , From: Keqian Zhu Message-ID: Date: Mon, 15 Mar 2021 15:33:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20210315041844.64915-4-gshan@redhat.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gavin, FYI, this has been fixed by Marc in commit 262b003d059c. Thanks, Keqian On 2021/3/15 12:18, Gavin Shan wrote: > The last (IPA) page can't be specified when a new memory slot is > added. The error -EFAULT is returned when the memory slot is added > with the following parameters for the VM, which has 40-bits IPA > limit. The host has 4KB base page size. It's not correct because > the last (IPA) page is still usable. > > struct kvm_userspace_memory_region { > __u32 slot; /* 1 */ > __u32 flags; /* 0 */ > __u64 guest_phys_addr; /* 0xfffffff000 */ > __u64 memory_size; /* 0x1000 */ > __u64 userspace_addr; > }; > > Signed-off-by: Gavin Shan > --- > arch/arm64/kvm/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 286b603ed0d3..a5a8ade9fde4 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1313,7 +1313,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, > * Prevent userspace from creating a memory region outside of the IPA > * space addressable by the KVM guest IPA space. > */ > - if (memslot->base_gfn + memslot->npages >= > + if (memslot->base_gfn + memslot->npages > > (kvm_phys_size(kvm) >> PAGE_SHIFT)) > return -EFAULT; > >