All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: fangyu.yu@linux.alibaba.com, 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: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	guoren@kernel.org, kvm@vger.kernel.org,
	kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Fangyu Yu <fangyu.yu@linux.alibaba.com>
Subject: Re: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP
Date: Tue, 21 Oct 2025 10:38:33 +0800	[thread overview]
Message-ID: <202510211010.XRaEeuBa-lkp@intel.com> (raw)
In-Reply-To: <20251020130801.68356-1-fangyu.yu@linux.alibaba.com>

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kvm/queue]
[also build test WARNING on kvm/next linus/master v6.18-rc2 next-20251020]
[cannot apply to kvm/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/fangyu-yu-linux-alibaba-com/RISC-V-KVM-Remove-automatic-I-O-mapping-for-VM_PFNMAP/20251020-210957
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link:    https://lore.kernel.org/r/20251020130801.68356-1-fangyu.yu%40linux.alibaba.com
patch subject: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP
config: riscv-defconfig (https://download.01.org/0day-ci/archive/20251021/202510211010.XRaEeuBa-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 754ebc6ebb9fb9fbee7aef33478c74ea74949853)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251021/202510211010.XRaEeuBa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510211010.XRaEeuBa-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> arch/riscv/kvm/mmu.c:211:9: warning: variable 'vm_start' set but not used [-Wunused-but-set-variable]
     211 |                 hva_t vm_start, vm_end;
         |                       ^
>> arch/riscv/kvm/mmu.c:174:8: warning: variable 'base_gpa' set but not used [-Wunused-but-set-variable]
     174 |         gpa_t base_gpa;
         |               ^
   2 warnings generated.


vim +/vm_start +211 arch/riscv/kvm/mmu.c

99cdc6c18c2d815 Anup Patel          2021-09-27  167  
99cdc6c18c2d815 Anup Patel          2021-09-27  168  int kvm_arch_prepare_memory_region(struct kvm *kvm,
537a17b31493009 Sean Christopherson 2021-12-06  169  				const struct kvm_memory_slot *old,
537a17b31493009 Sean Christopherson 2021-12-06  170  				struct kvm_memory_slot *new,
99cdc6c18c2d815 Anup Patel          2021-09-27  171  				enum kvm_mr_change change)
99cdc6c18c2d815 Anup Patel          2021-09-27  172  {
d01495d4cffb327 Sean Christopherson 2021-12-06  173  	hva_t hva, reg_end, size;
d01495d4cffb327 Sean Christopherson 2021-12-06 @174  	gpa_t base_gpa;
d01495d4cffb327 Sean Christopherson 2021-12-06  175  	bool writable;
9d05c1fee837572 Anup Patel          2021-09-27  176  	int ret = 0;
9d05c1fee837572 Anup Patel          2021-09-27  177  
9d05c1fee837572 Anup Patel          2021-09-27  178  	if (change != KVM_MR_CREATE && change != KVM_MR_MOVE &&
9d05c1fee837572 Anup Patel          2021-09-27  179  			change != KVM_MR_FLAGS_ONLY)
99cdc6c18c2d815 Anup Patel          2021-09-27  180  		return 0;
9d05c1fee837572 Anup Patel          2021-09-27  181  
9d05c1fee837572 Anup Patel          2021-09-27  182  	/*
9d05c1fee837572 Anup Patel          2021-09-27  183  	 * Prevent userspace from creating a memory region outside of the GPA
9d05c1fee837572 Anup Patel          2021-09-27  184  	 * space addressable by the KVM guest GPA space.
9d05c1fee837572 Anup Patel          2021-09-27  185  	 */
537a17b31493009 Sean Christopherson 2021-12-06  186  	if ((new->base_gfn + new->npages) >=
dd82e35638d67f4 Anup Patel          2025-06-18  187  	    (kvm_riscv_gstage_gpa_size >> PAGE_SHIFT))
9d05c1fee837572 Anup Patel          2021-09-27  188  		return -EFAULT;
9d05c1fee837572 Anup Patel          2021-09-27  189  
d01495d4cffb327 Sean Christopherson 2021-12-06  190  	hva = new->userspace_addr;
d01495d4cffb327 Sean Christopherson 2021-12-06  191  	size = new->npages << PAGE_SHIFT;
d01495d4cffb327 Sean Christopherson 2021-12-06  192  	reg_end = hva + size;
d01495d4cffb327 Sean Christopherson 2021-12-06  193  	base_gpa = new->base_gfn << PAGE_SHIFT;
d01495d4cffb327 Sean Christopherson 2021-12-06  194  	writable = !(new->flags & KVM_MEM_READONLY);
d01495d4cffb327 Sean Christopherson 2021-12-06  195  
9d05c1fee837572 Anup Patel          2021-09-27  196  	mmap_read_lock(current->mm);
9d05c1fee837572 Anup Patel          2021-09-27  197  
9d05c1fee837572 Anup Patel          2021-09-27  198  	/*
9d05c1fee837572 Anup Patel          2021-09-27  199  	 * A memory region could potentially cover multiple VMAs, and
b35152e0fb35983 Fangyu Yu           2025-10-20  200  	 * any holes between them, so iterate over all of them.
9d05c1fee837572 Anup Patel          2021-09-27  201  	 *
9d05c1fee837572 Anup Patel          2021-09-27  202  	 *     +--------------------------------------------+
9d05c1fee837572 Anup Patel          2021-09-27  203  	 * +---------------+----------------+   +----------------+
9d05c1fee837572 Anup Patel          2021-09-27  204  	 * |   : VMA 1     |      VMA 2     |   |    VMA 3  :    |
9d05c1fee837572 Anup Patel          2021-09-27  205  	 * +---------------+----------------+   +----------------+
9d05c1fee837572 Anup Patel          2021-09-27  206  	 *     |               memory region                |
9d05c1fee837572 Anup Patel          2021-09-27  207  	 *     +--------------------------------------------+
9d05c1fee837572 Anup Patel          2021-09-27  208  	 */
9d05c1fee837572 Anup Patel          2021-09-27  209  	do {
fce11b667022766 Quan Zhou           2025-06-17  210  		struct vm_area_struct *vma;
9d05c1fee837572 Anup Patel          2021-09-27 @211  		hva_t vm_start, vm_end;
9d05c1fee837572 Anup Patel          2021-09-27  212  
fce11b667022766 Quan Zhou           2025-06-17  213  		vma = find_vma_intersection(current->mm, hva, reg_end);
fce11b667022766 Quan Zhou           2025-06-17  214  		if (!vma)
9d05c1fee837572 Anup Patel          2021-09-27  215  			break;
9d05c1fee837572 Anup Patel          2021-09-27  216  
9d05c1fee837572 Anup Patel          2021-09-27  217  		/*
9d05c1fee837572 Anup Patel          2021-09-27  218  		 * Mapping a read-only VMA is only allowed if the
9d05c1fee837572 Anup Patel          2021-09-27  219  		 * memory region is configured as read-only.
9d05c1fee837572 Anup Patel          2021-09-27  220  		 */
9d05c1fee837572 Anup Patel          2021-09-27  221  		if (writable && !(vma->vm_flags & VM_WRITE)) {
9d05c1fee837572 Anup Patel          2021-09-27  222  			ret = -EPERM;
9d05c1fee837572 Anup Patel          2021-09-27  223  			break;
9d05c1fee837572 Anup Patel          2021-09-27  224  		}
9d05c1fee837572 Anup Patel          2021-09-27  225  
9d05c1fee837572 Anup Patel          2021-09-27  226  		/* Take the intersection of this VMA with the memory region */
9d05c1fee837572 Anup Patel          2021-09-27  227  		vm_start = max(hva, vma->vm_start);
9d05c1fee837572 Anup Patel          2021-09-27  228  		vm_end = min(reg_end, vma->vm_end);
9d05c1fee837572 Anup Patel          2021-09-27  229  
9d05c1fee837572 Anup Patel          2021-09-27  230  		if (vma->vm_flags & VM_PFNMAP) {
9d05c1fee837572 Anup Patel          2021-09-27  231  			/* IO region dirty page logging not allowed */
537a17b31493009 Sean Christopherson 2021-12-06  232  			if (new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
9d05c1fee837572 Anup Patel          2021-09-27  233  				ret = -EINVAL;
9d05c1fee837572 Anup Patel          2021-09-27  234  				goto out;
9d05c1fee837572 Anup Patel          2021-09-27  235  			}
9d05c1fee837572 Anup Patel          2021-09-27  236  		}
9d05c1fee837572 Anup Patel          2021-09-27  237  		hva = vm_end;
9d05c1fee837572 Anup Patel          2021-09-27  238  	} while (hva < reg_end);
9d05c1fee837572 Anup Patel          2021-09-27  239  
9d05c1fee837572 Anup Patel          2021-09-27  240  out:
9d05c1fee837572 Anup Patel          2021-09-27  241  	mmap_read_unlock(current->mm);
9d05c1fee837572 Anup Patel          2021-09-27  242  	return ret;
99cdc6c18c2d815 Anup Patel          2021-09-27  243  }
99cdc6c18c2d815 Anup Patel          2021-09-27  244  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

WARNING: multiple messages have this Message-ID (diff)
From: kernel test robot <lkp@intel.com>
To: fangyu.yu@linux.alibaba.com, 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: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	guoren@kernel.org, kvm@vger.kernel.org,
	kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Fangyu Yu <fangyu.yu@linux.alibaba.com>
Subject: Re: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP
Date: Tue, 21 Oct 2025 10:38:33 +0800	[thread overview]
Message-ID: <202510211010.XRaEeuBa-lkp@intel.com> (raw)
In-Reply-To: <20251020130801.68356-1-fangyu.yu@linux.alibaba.com>

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kvm/queue]
[also build test WARNING on kvm/next linus/master v6.18-rc2 next-20251020]
[cannot apply to kvm/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/fangyu-yu-linux-alibaba-com/RISC-V-KVM-Remove-automatic-I-O-mapping-for-VM_PFNMAP/20251020-210957
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link:    https://lore.kernel.org/r/20251020130801.68356-1-fangyu.yu%40linux.alibaba.com
patch subject: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP
config: riscv-defconfig (https://download.01.org/0day-ci/archive/20251021/202510211010.XRaEeuBa-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 754ebc6ebb9fb9fbee7aef33478c74ea74949853)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251021/202510211010.XRaEeuBa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510211010.XRaEeuBa-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> arch/riscv/kvm/mmu.c:211:9: warning: variable 'vm_start' set but not used [-Wunused-but-set-variable]
     211 |                 hva_t vm_start, vm_end;
         |                       ^
>> arch/riscv/kvm/mmu.c:174:8: warning: variable 'base_gpa' set but not used [-Wunused-but-set-variable]
     174 |         gpa_t base_gpa;
         |               ^
   2 warnings generated.


vim +/vm_start +211 arch/riscv/kvm/mmu.c

99cdc6c18c2d815 Anup Patel          2021-09-27  167  
99cdc6c18c2d815 Anup Patel          2021-09-27  168  int kvm_arch_prepare_memory_region(struct kvm *kvm,
537a17b31493009 Sean Christopherson 2021-12-06  169  				const struct kvm_memory_slot *old,
537a17b31493009 Sean Christopherson 2021-12-06  170  				struct kvm_memory_slot *new,
99cdc6c18c2d815 Anup Patel          2021-09-27  171  				enum kvm_mr_change change)
99cdc6c18c2d815 Anup Patel          2021-09-27  172  {
d01495d4cffb327 Sean Christopherson 2021-12-06  173  	hva_t hva, reg_end, size;
d01495d4cffb327 Sean Christopherson 2021-12-06 @174  	gpa_t base_gpa;
d01495d4cffb327 Sean Christopherson 2021-12-06  175  	bool writable;
9d05c1fee837572 Anup Patel          2021-09-27  176  	int ret = 0;
9d05c1fee837572 Anup Patel          2021-09-27  177  
9d05c1fee837572 Anup Patel          2021-09-27  178  	if (change != KVM_MR_CREATE && change != KVM_MR_MOVE &&
9d05c1fee837572 Anup Patel          2021-09-27  179  			change != KVM_MR_FLAGS_ONLY)
99cdc6c18c2d815 Anup Patel          2021-09-27  180  		return 0;
9d05c1fee837572 Anup Patel          2021-09-27  181  
9d05c1fee837572 Anup Patel          2021-09-27  182  	/*
9d05c1fee837572 Anup Patel          2021-09-27  183  	 * Prevent userspace from creating a memory region outside of the GPA
9d05c1fee837572 Anup Patel          2021-09-27  184  	 * space addressable by the KVM guest GPA space.
9d05c1fee837572 Anup Patel          2021-09-27  185  	 */
537a17b31493009 Sean Christopherson 2021-12-06  186  	if ((new->base_gfn + new->npages) >=
dd82e35638d67f4 Anup Patel          2025-06-18  187  	    (kvm_riscv_gstage_gpa_size >> PAGE_SHIFT))
9d05c1fee837572 Anup Patel          2021-09-27  188  		return -EFAULT;
9d05c1fee837572 Anup Patel          2021-09-27  189  
d01495d4cffb327 Sean Christopherson 2021-12-06  190  	hva = new->userspace_addr;
d01495d4cffb327 Sean Christopherson 2021-12-06  191  	size = new->npages << PAGE_SHIFT;
d01495d4cffb327 Sean Christopherson 2021-12-06  192  	reg_end = hva + size;
d01495d4cffb327 Sean Christopherson 2021-12-06  193  	base_gpa = new->base_gfn << PAGE_SHIFT;
d01495d4cffb327 Sean Christopherson 2021-12-06  194  	writable = !(new->flags & KVM_MEM_READONLY);
d01495d4cffb327 Sean Christopherson 2021-12-06  195  
9d05c1fee837572 Anup Patel          2021-09-27  196  	mmap_read_lock(current->mm);
9d05c1fee837572 Anup Patel          2021-09-27  197  
9d05c1fee837572 Anup Patel          2021-09-27  198  	/*
9d05c1fee837572 Anup Patel          2021-09-27  199  	 * A memory region could potentially cover multiple VMAs, and
b35152e0fb35983 Fangyu Yu           2025-10-20  200  	 * any holes between them, so iterate over all of them.
9d05c1fee837572 Anup Patel          2021-09-27  201  	 *
9d05c1fee837572 Anup Patel          2021-09-27  202  	 *     +--------------------------------------------+
9d05c1fee837572 Anup Patel          2021-09-27  203  	 * +---------------+----------------+   +----------------+
9d05c1fee837572 Anup Patel          2021-09-27  204  	 * |   : VMA 1     |      VMA 2     |   |    VMA 3  :    |
9d05c1fee837572 Anup Patel          2021-09-27  205  	 * +---------------+----------------+   +----------------+
9d05c1fee837572 Anup Patel          2021-09-27  206  	 *     |               memory region                |
9d05c1fee837572 Anup Patel          2021-09-27  207  	 *     +--------------------------------------------+
9d05c1fee837572 Anup Patel          2021-09-27  208  	 */
9d05c1fee837572 Anup Patel          2021-09-27  209  	do {
fce11b667022766 Quan Zhou           2025-06-17  210  		struct vm_area_struct *vma;
9d05c1fee837572 Anup Patel          2021-09-27 @211  		hva_t vm_start, vm_end;
9d05c1fee837572 Anup Patel          2021-09-27  212  
fce11b667022766 Quan Zhou           2025-06-17  213  		vma = find_vma_intersection(current->mm, hva, reg_end);
fce11b667022766 Quan Zhou           2025-06-17  214  		if (!vma)
9d05c1fee837572 Anup Patel          2021-09-27  215  			break;
9d05c1fee837572 Anup Patel          2021-09-27  216  
9d05c1fee837572 Anup Patel          2021-09-27  217  		/*
9d05c1fee837572 Anup Patel          2021-09-27  218  		 * Mapping a read-only VMA is only allowed if the
9d05c1fee837572 Anup Patel          2021-09-27  219  		 * memory region is configured as read-only.
9d05c1fee837572 Anup Patel          2021-09-27  220  		 */
9d05c1fee837572 Anup Patel          2021-09-27  221  		if (writable && !(vma->vm_flags & VM_WRITE)) {
9d05c1fee837572 Anup Patel          2021-09-27  222  			ret = -EPERM;
9d05c1fee837572 Anup Patel          2021-09-27  223  			break;
9d05c1fee837572 Anup Patel          2021-09-27  224  		}
9d05c1fee837572 Anup Patel          2021-09-27  225  
9d05c1fee837572 Anup Patel          2021-09-27  226  		/* Take the intersection of this VMA with the memory region */
9d05c1fee837572 Anup Patel          2021-09-27  227  		vm_start = max(hva, vma->vm_start);
9d05c1fee837572 Anup Patel          2021-09-27  228  		vm_end = min(reg_end, vma->vm_end);
9d05c1fee837572 Anup Patel          2021-09-27  229  
9d05c1fee837572 Anup Patel          2021-09-27  230  		if (vma->vm_flags & VM_PFNMAP) {
9d05c1fee837572 Anup Patel          2021-09-27  231  			/* IO region dirty page logging not allowed */
537a17b31493009 Sean Christopherson 2021-12-06  232  			if (new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
9d05c1fee837572 Anup Patel          2021-09-27  233  				ret = -EINVAL;
9d05c1fee837572 Anup Patel          2021-09-27  234  				goto out;
9d05c1fee837572 Anup Patel          2021-09-27  235  			}
9d05c1fee837572 Anup Patel          2021-09-27  236  		}
9d05c1fee837572 Anup Patel          2021-09-27  237  		hva = vm_end;
9d05c1fee837572 Anup Patel          2021-09-27  238  	} while (hva < reg_end);
9d05c1fee837572 Anup Patel          2021-09-27  239  
9d05c1fee837572 Anup Patel          2021-09-27  240  out:
9d05c1fee837572 Anup Patel          2021-09-27  241  	mmap_read_unlock(current->mm);
9d05c1fee837572 Anup Patel          2021-09-27  242  	return ret;
99cdc6c18c2d815 Anup Patel          2021-09-27  243  }
99cdc6c18c2d815 Anup Patel          2021-09-27  244  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

WARNING: multiple messages have this Message-ID (diff)
From: kernel test robot <lkp@intel.com>
To: fangyu.yu@linux.alibaba.com, 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: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	guoren@kernel.org, kvm@vger.kernel.org,
	kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Fangyu Yu <fangyu.yu@linux.alibaba.com>
Subject: Re: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP
Date: Tue, 21 Oct 2025 10:38:33 +0800	[thread overview]
Message-ID: <202510211010.XRaEeuBa-lkp@intel.com> (raw)
In-Reply-To: <20251020130801.68356-1-fangyu.yu@linux.alibaba.com>

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kvm/queue]
[also build test WARNING on kvm/next linus/master v6.18-rc2 next-20251020]
[cannot apply to kvm/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/fangyu-yu-linux-alibaba-com/RISC-V-KVM-Remove-automatic-I-O-mapping-for-VM_PFNMAP/20251020-210957
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link:    https://lore.kernel.org/r/20251020130801.68356-1-fangyu.yu%40linux.alibaba.com
patch subject: [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP
config: riscv-defconfig (https://download.01.org/0day-ci/archive/20251021/202510211010.XRaEeuBa-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 754ebc6ebb9fb9fbee7aef33478c74ea74949853)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251021/202510211010.XRaEeuBa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510211010.XRaEeuBa-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> arch/riscv/kvm/mmu.c:211:9: warning: variable 'vm_start' set but not used [-Wunused-but-set-variable]
     211 |                 hva_t vm_start, vm_end;
         |                       ^
>> arch/riscv/kvm/mmu.c:174:8: warning: variable 'base_gpa' set but not used [-Wunused-but-set-variable]
     174 |         gpa_t base_gpa;
         |               ^
   2 warnings generated.


vim +/vm_start +211 arch/riscv/kvm/mmu.c

99cdc6c18c2d815 Anup Patel          2021-09-27  167  
99cdc6c18c2d815 Anup Patel          2021-09-27  168  int kvm_arch_prepare_memory_region(struct kvm *kvm,
537a17b31493009 Sean Christopherson 2021-12-06  169  				const struct kvm_memory_slot *old,
537a17b31493009 Sean Christopherson 2021-12-06  170  				struct kvm_memory_slot *new,
99cdc6c18c2d815 Anup Patel          2021-09-27  171  				enum kvm_mr_change change)
99cdc6c18c2d815 Anup Patel          2021-09-27  172  {
d01495d4cffb327 Sean Christopherson 2021-12-06  173  	hva_t hva, reg_end, size;
d01495d4cffb327 Sean Christopherson 2021-12-06 @174  	gpa_t base_gpa;
d01495d4cffb327 Sean Christopherson 2021-12-06  175  	bool writable;
9d05c1fee837572 Anup Patel          2021-09-27  176  	int ret = 0;
9d05c1fee837572 Anup Patel          2021-09-27  177  
9d05c1fee837572 Anup Patel          2021-09-27  178  	if (change != KVM_MR_CREATE && change != KVM_MR_MOVE &&
9d05c1fee837572 Anup Patel          2021-09-27  179  			change != KVM_MR_FLAGS_ONLY)
99cdc6c18c2d815 Anup Patel          2021-09-27  180  		return 0;
9d05c1fee837572 Anup Patel          2021-09-27  181  
9d05c1fee837572 Anup Patel          2021-09-27  182  	/*
9d05c1fee837572 Anup Patel          2021-09-27  183  	 * Prevent userspace from creating a memory region outside of the GPA
9d05c1fee837572 Anup Patel          2021-09-27  184  	 * space addressable by the KVM guest GPA space.
9d05c1fee837572 Anup Patel          2021-09-27  185  	 */
537a17b31493009 Sean Christopherson 2021-12-06  186  	if ((new->base_gfn + new->npages) >=
dd82e35638d67f4 Anup Patel          2025-06-18  187  	    (kvm_riscv_gstage_gpa_size >> PAGE_SHIFT))
9d05c1fee837572 Anup Patel          2021-09-27  188  		return -EFAULT;
9d05c1fee837572 Anup Patel          2021-09-27  189  
d01495d4cffb327 Sean Christopherson 2021-12-06  190  	hva = new->userspace_addr;
d01495d4cffb327 Sean Christopherson 2021-12-06  191  	size = new->npages << PAGE_SHIFT;
d01495d4cffb327 Sean Christopherson 2021-12-06  192  	reg_end = hva + size;
d01495d4cffb327 Sean Christopherson 2021-12-06  193  	base_gpa = new->base_gfn << PAGE_SHIFT;
d01495d4cffb327 Sean Christopherson 2021-12-06  194  	writable = !(new->flags & KVM_MEM_READONLY);
d01495d4cffb327 Sean Christopherson 2021-12-06  195  
9d05c1fee837572 Anup Patel          2021-09-27  196  	mmap_read_lock(current->mm);
9d05c1fee837572 Anup Patel          2021-09-27  197  
9d05c1fee837572 Anup Patel          2021-09-27  198  	/*
9d05c1fee837572 Anup Patel          2021-09-27  199  	 * A memory region could potentially cover multiple VMAs, and
b35152e0fb35983 Fangyu Yu           2025-10-20  200  	 * any holes between them, so iterate over all of them.
9d05c1fee837572 Anup Patel          2021-09-27  201  	 *
9d05c1fee837572 Anup Patel          2021-09-27  202  	 *     +--------------------------------------------+
9d05c1fee837572 Anup Patel          2021-09-27  203  	 * +---------------+----------------+   +----------------+
9d05c1fee837572 Anup Patel          2021-09-27  204  	 * |   : VMA 1     |      VMA 2     |   |    VMA 3  :    |
9d05c1fee837572 Anup Patel          2021-09-27  205  	 * +---------------+----------------+   +----------------+
9d05c1fee837572 Anup Patel          2021-09-27  206  	 *     |               memory region                |
9d05c1fee837572 Anup Patel          2021-09-27  207  	 *     +--------------------------------------------+
9d05c1fee837572 Anup Patel          2021-09-27  208  	 */
9d05c1fee837572 Anup Patel          2021-09-27  209  	do {
fce11b667022766 Quan Zhou           2025-06-17  210  		struct vm_area_struct *vma;
9d05c1fee837572 Anup Patel          2021-09-27 @211  		hva_t vm_start, vm_end;
9d05c1fee837572 Anup Patel          2021-09-27  212  
fce11b667022766 Quan Zhou           2025-06-17  213  		vma = find_vma_intersection(current->mm, hva, reg_end);
fce11b667022766 Quan Zhou           2025-06-17  214  		if (!vma)
9d05c1fee837572 Anup Patel          2021-09-27  215  			break;
9d05c1fee837572 Anup Patel          2021-09-27  216  
9d05c1fee837572 Anup Patel          2021-09-27  217  		/*
9d05c1fee837572 Anup Patel          2021-09-27  218  		 * Mapping a read-only VMA is only allowed if the
9d05c1fee837572 Anup Patel          2021-09-27  219  		 * memory region is configured as read-only.
9d05c1fee837572 Anup Patel          2021-09-27  220  		 */
9d05c1fee837572 Anup Patel          2021-09-27  221  		if (writable && !(vma->vm_flags & VM_WRITE)) {
9d05c1fee837572 Anup Patel          2021-09-27  222  			ret = -EPERM;
9d05c1fee837572 Anup Patel          2021-09-27  223  			break;
9d05c1fee837572 Anup Patel          2021-09-27  224  		}
9d05c1fee837572 Anup Patel          2021-09-27  225  
9d05c1fee837572 Anup Patel          2021-09-27  226  		/* Take the intersection of this VMA with the memory region */
9d05c1fee837572 Anup Patel          2021-09-27  227  		vm_start = max(hva, vma->vm_start);
9d05c1fee837572 Anup Patel          2021-09-27  228  		vm_end = min(reg_end, vma->vm_end);
9d05c1fee837572 Anup Patel          2021-09-27  229  
9d05c1fee837572 Anup Patel          2021-09-27  230  		if (vma->vm_flags & VM_PFNMAP) {
9d05c1fee837572 Anup Patel          2021-09-27  231  			/* IO region dirty page logging not allowed */
537a17b31493009 Sean Christopherson 2021-12-06  232  			if (new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
9d05c1fee837572 Anup Patel          2021-09-27  233  				ret = -EINVAL;
9d05c1fee837572 Anup Patel          2021-09-27  234  				goto out;
9d05c1fee837572 Anup Patel          2021-09-27  235  			}
9d05c1fee837572 Anup Patel          2021-09-27  236  		}
9d05c1fee837572 Anup Patel          2021-09-27  237  		hva = vm_end;
9d05c1fee837572 Anup Patel          2021-09-27  238  	} while (hva < reg_end);
9d05c1fee837572 Anup Patel          2021-09-27  239  
9d05c1fee837572 Anup Patel          2021-09-27  240  out:
9d05c1fee837572 Anup Patel          2021-09-27  241  	mmap_read_unlock(current->mm);
9d05c1fee837572 Anup Patel          2021-09-27  242  	return ret;
99cdc6c18c2d815 Anup Patel          2021-09-27  243  }
99cdc6c18c2d815 Anup Patel          2021-09-27  244  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2025-10-21  2:39 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 13:08 [PATCH] RISC-V: KVM: Remove automatic I/O mapping for VM_PFNMAP fangyu.yu
2025-10-20 13:08 ` fangyu.yu
2025-10-20 13:08 ` fangyu.yu
2025-10-20 19:43 ` Daniel Henrique Barboza
2025-10-20 19:43   ` Daniel Henrique Barboza
2025-10-20 19:43   ` Daniel Henrique Barboza
2025-10-21  1:44   ` fangyu.yu
2025-10-21  1:44     ` fangyu.yu
2025-10-21  1:44     ` fangyu.yu
2025-10-21  2:38 ` kernel test robot [this message]
2025-10-21  2:38   ` kernel test robot
2025-10-21  2:38   ` kernel test robot
2025-10-21 15:27 ` Guo Ren
2025-10-21 15:27   ` Guo Ren
2025-10-21 15:27   ` Guo Ren
2025-10-21 15:31   ` Jason Gunthorpe
2025-10-21 15:31     ` Jason Gunthorpe
2025-10-21 15:31     ` Jason Gunthorpe
2025-10-24  7:31   ` Anup Patel
2025-10-24  7:31     ` Anup Patel
2025-10-24  7:31     ` Anup Patel
2025-10-24 10:03     ` Guo Ren
2025-10-24 10:03       ` Guo Ren
2025-10-24 10:03       ` Guo Ren
2025-10-24  7:29 ` Anup Patel
2025-10-24  7:29   ` Anup Patel
2025-10-24  7:29   ` Anup Patel
2025-10-24 13:31   ` fangyu.yu
2025-10-24 13:31     ` fangyu.yu
2025-10-24 13:31     ` fangyu.yu
2025-10-24 15:25     ` Anup Patel
2025-10-24 15:25       ` Anup Patel
2025-10-24 15:25       ` Anup Patel
2025-10-24 15:57       ` Anup Patel
2025-10-24 15:57         ` Anup Patel
2025-10-24 15:57         ` Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202510211010.XRaEeuBa-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=alex@ghiti.fr \
    --cc=anup@brainfault.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=atish.patra@linux.dev \
    --cc=fangyu.yu@linux.alibaba.com \
    --cc=guoren@kernel.org \
    --cc=jiangyifei@huawei.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=llvm@lists.linux.dev \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=pjw@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.