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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 73128C433E0 for ; Mon, 15 Mar 2021 04:19:13 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id F215E64E13 for ; Mon, 15 Mar 2021 04:19:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F215E64E13 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 900C34B21A; Mon, 15 Mar 2021 00:19:12 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NO2gQy1UCvmN; Mon, 15 Mar 2021 00:19:11 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 960174B360; Mon, 15 Mar 2021 00:19:11 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 96DD84B21A for ; Mon, 15 Mar 2021 00:19:10 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GDGAj4PyHYbn for ; Mon, 15 Mar 2021 00:19:09 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 293624B3D2 for ; Mon, 15 Mar 2021 00:19:09 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615781948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pu3kXgjRojY47OfIAlD63r8hsjSPAEDkqXq/WsE53ds=; b=UAohMhC5tInVDho0Fvn4UPwdJF9Ag0WUgOTcghZDYlPT+3IDr8llJ0G1JegK/y4FrR8VlG G2kVMq5pHqo629ggdfY9mFRkR0WsDLVpKxXwCR9Gj438y2Ym2Jpq31CRlSr2WQByW7jUpU GGm4LUq+74s0TFV14JjVgDI2O9UdiQ8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-6sHIAiESPqStPy2FM__12Q-1; Mon, 15 Mar 2021 00:19:07 -0400 X-MC-Unique: 6sHIAiESPqStPy2FM__12Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D453981746C; Mon, 15 Mar 2021 04:19:05 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-175.bne.redhat.com [10.64.54.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 466AD437F; Mon, 15 Mar 2021 04:19:03 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 3/4] KVM: arm64: Fix address check for memory slot Date: Mon, 15 Mar 2021 12:18:43 +0800 Message-Id: <20210315041844.64915-4-gshan@redhat.com> In-Reply-To: <20210315041844.64915-1-gshan@redhat.com> References: <20210315041844.64915-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Cc: maz@kernel.org, will@kernel.org, linux-kernel@vger.kernel.org, shan.gavin@gmail.com X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu 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; -- 2.23.0 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm