[PATCH v1 01/13] KVM: Add KVM_MEM_USERFAULT memslot flag and bitmap
kernel test robot
lkp at intel.com
Thu Dec 5 06:22:50 PST 2024
Hi James,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 4d911c7abee56771b0219a9fbf0120d06bdc9c14]
url: https://github.com/intel-lab-lkp/linux/commits/James-Houghton/KVM-Add-KVM_MEM_USERFAULT-memslot-flag-and-bitmap/20241205-032516
base: 4d911c7abee56771b0219a9fbf0120d06bdc9c14
patch link: https://lore.kernel.org/r/20241204191349.1730936-2-jthoughton%40google.com
patch subject: [PATCH v1 01/13] KVM: Add KVM_MEM_USERFAULT memslot flag and bitmap
config: i386-buildonly-randconfig-006 (https://download.01.org/0day-ci/archive/20241205/202412052133.pTg3UAQm-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241205/202412052133.pTg3UAQm-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 at intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412052133.pTg3UAQm-lkp@intel.com/
All warnings (new ones prefixed by >>):
arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function '__kvm_set_memory_region':
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:2049:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
2049 | new->userfault_bitmap = (unsigned long *)mem->userfault_bitmap;
| ^
vim +2049 arch/x86/kvm/../../../virt/kvm/kvm_main.c
1931
1932 /*
1933 * Allocate some memory and give it an address in the guest physical address
1934 * space.
1935 *
1936 * Discontiguous memory is allowed, mostly for framebuffers.
1937 *
1938 * Must be called holding kvm->slots_lock for write.
1939 */
1940 int __kvm_set_memory_region(struct kvm *kvm,
1941 const struct kvm_userspace_memory_region2 *mem)
1942 {
1943 struct kvm_memory_slot *old, *new;
1944 struct kvm_memslots *slots;
1945 enum kvm_mr_change change;
1946 unsigned long npages;
1947 gfn_t base_gfn;
1948 int as_id, id;
1949 int r;
1950
1951 r = check_memory_region_flags(kvm, mem);
1952 if (r)
1953 return r;
1954
1955 as_id = mem->slot >> 16;
1956 id = (u16)mem->slot;
1957
1958 /* General sanity checks */
1959 if ((mem->memory_size & (PAGE_SIZE - 1)) ||
1960 (mem->memory_size != (unsigned long)mem->memory_size))
1961 return -EINVAL;
1962 if (mem->guest_phys_addr & (PAGE_SIZE - 1))
1963 return -EINVAL;
1964 /* We can read the guest memory with __xxx_user() later on. */
1965 if ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
1966 (mem->userspace_addr != untagged_addr(mem->userspace_addr)) ||
1967 !access_ok((void __user *)(unsigned long)mem->userspace_addr,
1968 mem->memory_size))
1969 return -EINVAL;
1970 if (mem->flags & KVM_MEM_GUEST_MEMFD &&
1971 (mem->guest_memfd_offset & (PAGE_SIZE - 1) ||
1972 mem->guest_memfd_offset + mem->memory_size < mem->guest_memfd_offset))
1973 return -EINVAL;
1974 if (as_id >= kvm_arch_nr_memslot_as_ids(kvm) || id >= KVM_MEM_SLOTS_NUM)
1975 return -EINVAL;
1976 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
1977 return -EINVAL;
1978 if ((mem->memory_size >> PAGE_SHIFT) > KVM_MEM_MAX_NR_PAGES)
1979 return -EINVAL;
1980
1981 slots = __kvm_memslots(kvm, as_id);
1982
1983 /*
1984 * Note, the old memslot (and the pointer itself!) may be invalidated
1985 * and/or destroyed by kvm_set_memslot().
1986 */
1987 old = id_to_memslot(slots, id);
1988
1989 if (!mem->memory_size) {
1990 if (!old || !old->npages)
1991 return -EINVAL;
1992
1993 if (WARN_ON_ONCE(kvm->nr_memslot_pages < old->npages))
1994 return -EIO;
1995
1996 return kvm_set_memslot(kvm, old, NULL, KVM_MR_DELETE);
1997 }
1998
1999 base_gfn = (mem->guest_phys_addr >> PAGE_SHIFT);
2000 npages = (mem->memory_size >> PAGE_SHIFT);
2001
2002 if (!old || !old->npages) {
2003 change = KVM_MR_CREATE;
2004
2005 /*
2006 * To simplify KVM internals, the total number of pages across
2007 * all memslots must fit in an unsigned long.
2008 */
2009 if ((kvm->nr_memslot_pages + npages) < kvm->nr_memslot_pages)
2010 return -EINVAL;
2011 } else { /* Modify an existing slot. */
2012 /* Private memslots are immutable, they can only be deleted. */
2013 if (mem->flags & KVM_MEM_GUEST_MEMFD)
2014 return -EINVAL;
2015 if ((mem->userspace_addr != old->userspace_addr) ||
2016 (npages != old->npages) ||
2017 ((mem->flags ^ old->flags) & KVM_MEM_READONLY))
2018 return -EINVAL;
2019
2020 if (base_gfn != old->base_gfn)
2021 change = KVM_MR_MOVE;
2022 else if (mem->flags != old->flags)
2023 change = KVM_MR_FLAGS_ONLY;
2024 else /* Nothing to change. */
2025 return 0;
2026 }
2027
2028 if ((change == KVM_MR_CREATE || change == KVM_MR_MOVE) &&
2029 kvm_check_memslot_overlap(slots, id, base_gfn, base_gfn + npages))
2030 return -EEXIST;
2031
2032 /* Allocate a slot that will persist in the memslot. */
2033 new = kzalloc(sizeof(*new), GFP_KERNEL_ACCOUNT);
2034 if (!new)
2035 return -ENOMEM;
2036
2037 new->as_id = as_id;
2038 new->id = id;
2039 new->base_gfn = base_gfn;
2040 new->npages = npages;
2041 new->flags = mem->flags;
2042 new->userspace_addr = mem->userspace_addr;
2043 if (mem->flags & KVM_MEM_GUEST_MEMFD) {
2044 r = kvm_gmem_bind(kvm, new, mem->guest_memfd, mem->guest_memfd_offset);
2045 if (r)
2046 goto out;
2047 }
2048 if (mem->flags & KVM_MEM_USERFAULT)
> 2049 new->userfault_bitmap = (unsigned long *)mem->userfault_bitmap;
2050
2051 r = kvm_set_memslot(kvm, old, new, change);
2052 if (r)
2053 goto out_unbind;
2054
2055 return 0;
2056
2057 out_unbind:
2058 if (mem->flags & KVM_MEM_GUEST_MEMFD)
2059 kvm_gmem_unbind(new);
2060 out:
2061 kfree(new);
2062 return r;
2063 }
2064 EXPORT_SYMBOL_GPL(__kvm_set_memory_region);
2065
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
More information about the linux-arm-kernel
mailing list