From nobody Sat Feb 7 21:15:40 2026 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C722E1494C3; Mon, 20 Oct 2025 13:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760965700; cv=none; b=Exsfz9armODEkL6bRUtE+k7wHfwclTxBCP1MMCjHso68DC2/lYoYZ2CNSC/cw8jEPwZxUGD6H2skZYm4AtlI9qu07ESX9yxVG9iOzIhmt31D5AXZbt3APfMmhiMac/N39pi49cvr4Uk3SuKBcmxacYOCf/XI6y/JmKoMeyMVU1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760965700; c=relaxed/simple; bh=//8I0dVPfl3/ugxAvErXNaziF9i3d9ZAbRKxDdDYIb4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oWt/Wkk7hNpZ2dmlIA3CEt2tj8IoBjwOlck5ZigG3YoBBooCjm94addnVqe9Gf47p6zFGtQQEVA01M/pZJ6HbIx7GxWcHrKMQ0rVqdxTilHAeR63Hln2+Qg+gtSJX5KFJPXpsFpdLPji3ArIUeSMy1NEqHxCLpF0NPM/tShZFoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Zwsji4yH; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Zwsji4yH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1760965687; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=VqNvlk/xz73z1KmMrkOxoHo6m+80ptyKkYHpzu2di2U=; b=Zwsji4yHWSRTx48z27eJlvfIuf7DRxUlsxxHhXOXpMiUbce67yhmMNy1GnKiCO9TXIrHk6PrNA44UQJRHTrBHLVsm1aqyexDTyF/2i/Fy47l8B3sH3UVitekX3DLgUwVxYu40V+L8hyoW0LJVLXWeKGjBcT0c13UDBRTcuZzcbI= Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0WqchCgl_1760965684 cluster:ay36) by smtp.aliyun-inc.com; Mon, 20 Oct 2025 21:08:06 +0800 From: fangyu.yu@linux.alibaba.com To: anup@brainfault.org, atish.patra@linux.dev, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, pbonzini@redhat.com, jiangyifei@huawei.com Cc: guoren@kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Fangyu Yu Subject: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP Date: Mon, 20 Oct 2025 21:08:01 +0800 Message-Id: <20251020130801.68356-1-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fangyu Yu As of commit aac6db75a9fc ("vfio/pci: Use unmap_mapping_range()"), vm_pgoff may no longer guaranteed to hold the PFN for VM_PFNMAP regions. Using vma->vm_pgoff to derive the HPA here may therefore produce incorrect mappings. Instead, I/O mappings for such regions can be established on-demand during g-stage page faults, making the upfront ioremap in this path is unnecessary. Fixes: 9d05c1fee837 ("RISC-V: KVM: Implement stage2 page table programming") Signed-off-by: Fangyu Yu Acked-by: Guo Ren Reviewed-by: Anup Patel Reviewed-by: Guo Ren Tested-by: Daniel Henrique Barboza --- arch/riscv/kvm/mmu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 525fb5a330c0..84c04c8f0892 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -197,8 +197,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, =20 /* * A memory region could potentially cover multiple VMAs, and - * any holes between them, so iterate over all of them to find - * out if we can map any of them right now. + * any holes between them, so iterate over all of them. * * +--------------------------------------------+ * +---------------+----------------+ +----------------+ @@ -229,32 +228,15 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, vm_end =3D min(reg_end, vma->vm_end); =20 if (vma->vm_flags & VM_PFNMAP) { - gpa_t gpa =3D base_gpa + (vm_start - hva); - phys_addr_t pa; - - pa =3D (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT; - pa +=3D vm_start - vma->vm_start; - /* IO region dirty page logging not allowed */ if (new->flags & KVM_MEM_LOG_DIRTY_PAGES) { ret =3D -EINVAL; goto out; } - - ret =3D kvm_riscv_mmu_ioremap(kvm, gpa, pa, vm_end - vm_start, - writable, false); - if (ret) - break; } hva =3D vm_end; } while (hva < reg_end); =20 - if (change =3D=3D KVM_MR_FLAGS_ONLY) - goto out; - - if (ret) - kvm_riscv_mmu_iounmap(kvm, base_gpa, size); - out: mmap_read_unlock(current->mm); return ret; --=20 2.50.1