From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DBDDC433E6 for ; Mon, 15 Mar 2021 07:34:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5617964E74 for ; Mon, 15 Mar 2021 07:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbhCOHeI (ORCPT ); Mon, 15 Mar 2021 03:34:08 -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; > >