Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3010297pxf; Sun, 14 Mar 2021 21:21:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/KXHh6+lrhrRcoQwqEMXsXO9OSy/vmkk/eBWCSnkEQcr1YoqMNKGO6TqB4LdUEAaBexFR X-Received: by 2002:a17:906:c414:: with SMTP id u20mr21201631ejz.215.1615782061562; Sun, 14 Mar 2021 21:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615782061; cv=none; d=google.com; s=arc-20160816; b=VnruaR4ucYX86tbmaChHhJnrXvPlfJ/MfyItMM0ewoJ+tls2j+mUFC2PxsENdYEVzE 7NTcqdD8A7Ge50cbjxNnCYMxfmkLCBT7ueWSFXd9Voc3tTT/rcl5g5GHwkR/hXuLtGng bCb9wtYhtQ+MF5qBUdWPLY9S562rS85KEz2NdY/cOQ4NN58yHLMaY+bvgoz8uS3du0iz nfe84Ub+RSL1qx9hAQW6VgZkRxrLA/LFp2bIFIh54m7LEisOzqdc3XpCUo914Y+alhFC l9D1KsmXa25Yn5FAHifLY7sqquw9AXgXtE+fpj+HGG+pnTVDO2P/FFtRbMOomxvQ2Khz +C4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Pu3kXgjRojY47OfIAlD63r8hsjSPAEDkqXq/WsE53ds=; b=GAYrxoCzuHCLqaSLdh4j9KiZGblPeB4U7P5uE1q13lTPBbqa10FBZ9TXv6IVXOx0mF 5RJOeWImizcnn6S/8ra+y5/9R4LiAvhORyKhEIiVy4cqsS13ITzMP9KohjPxayIEGqTY YXfGWD2d7tiP+YO6eDbsHapKn36Ir/NZMR0v76J2zZRFfRZY4d64hZMVy0zTWKv14o0R gfY1BvsfWRQg18izuiRpo7kxBu+YB9/BALI9mKerI81aidoZWq6i/sgGckzjyGWO93ba JcvTRHESXIohL4CJGwIx8W+BfpNNo9Sq63NKhc5UjBZk2fYQrD7/lFvc2BanKSqu9aS/ Lclw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UAohMhC5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lf11si9296784ejc.601.2021.03.14.21.20.39; Sun, 14 Mar 2021 21:21:01 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UAohMhC5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbhCOETr (ORCPT + 99 others); Mon, 15 Mar 2021 00:19:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22035 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbhCOETJ (ORCPT ); Mon, 15 Mar 2021 00:19:09 -0400 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 Cc: linux-kernel@vger.kernel.org, maz@kernel.org, will@kernel.org, alexandru.elisei@arm.com, shan.gavin@gmail.com 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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