diff mbox series

[v5,1/2] mm: allow dynamic vmalloc range restrictions

Message ID ozcyvkcdqhxhlg3sjz3s4odt7ejiwx2cctgb7sdx6jbardui37@al6uvt4yx5nt (mailing list archive)
State New
Headers show
Series [v5,1/2] mm: allow dynamic vmalloc range restrictions | expand

Commit Message

Maxwell Bland May 9, 2024, 6:25 p.m. UTC
Add an API to the vmalloc infrastructure, create_vmalloc_range_check,
which allows for the creation of restricted sub-ranges of vmalloc memory
during the init process, which can only be allocated from via vmalloc
requests with vaddr start addresses explicitly matching the range's
start addresses. Calls to this API can split up to two nodes in the
red-black tree.

create_vmalloc_range_check restricts vmalloc requests not matching the
range's start address to all other locations in the standard vmalloc
range, i.e. users of the interface are responsible for requesting only
correct and appropriate reservations. The primary intention of this API
is supporting ASLR module region allocation regions while not
undermining existing security mechanisms by necessitating interleaved
code and data pages.

To perform range allocation at the appropriate, earliest time, provide a
callback arch_init_checked_vmap_ranges rather than maintaining a linked
list outside of the vmalloc infrastructure, ensuring all vmap management
is still owned by vmalloc.c.

Considering some alternatives, i.e. a large change to the vmalloc
infrastructure to provide true support for a module code dynamic
allocation region, this smaller vstart-based opt-in seems preferable.

These changes may need to wait/be rebased on Mike Rapoport's patches
at 20240505160628.2323363-11-rppt@kernel.org , but this version is
submitted to account for the justification for unrestricted BPF/kprobe
code allocations and squashes some bugs the last version created in the
bpf selftests.

Changes from v4:
20240423095843.446565600-1-mbland@motorola.com
- Fix the corruption because of backslash created by SMTP mailer
- Add config to permit the reduction of BPF memory to 128MB, i.e. fix
  issue with the arm64 side of this change implicitly breaking
  1636131046-5982-2-git-send-email-alan.maguire@oracle.com "128MB of
  JIT memory can be quickly exhausted"
- Expand modules_alloc region used on arm64 to support larger BPF
  allocations present in the selftests.

Changes from v3:
20240416122254.868007168-1-mbland@motorola.com
- Added callbacks into arch-specific code to dynamically partition
  red-black tree

(The freedom of architectures to determine vm area allocation was deemed
dangerous since there was no possibility of enforcing that areas were
correctly managed.)

Changes from v2:
20240220203256.31153-1-mbland@motorola.com
- No longer depends on reducing the size of the vmalloc region
- Attempted to implement change by allowing architectures to override
  most abstract public vmalloc interface

(Overrides on vmalloc methods were deemed undesirable.)

Changes from v1:
CAP5Mv+ydhk=Ob4b40ZahGMgT-5+-VEHxtmA=-LkJiEOOU+K6hw@mail.gmail.com
- Statically reduced the range of the vmalloc region to support
  parititoned code ranges

(The trade off between space reduction and security was deemed
unnecessary.)

Signed-off-by: Maxwell Bland <mbland@motorola.com>
---
Thanks again to the maintainers for their review, apologies for the
mailer and BPF selftest errors on the previous version. This version
will still be incompatible with BPF allocation limit stress tests, for
clear reasons. I plan to rebase this same exact code on top of Mike
Rapoport's recent patchset, but this version is compatible with the
current linus upstream.

 include/linux/vmalloc.h |  14 ++++++
 mm/vmalloc.c            | 102 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 113 insertions(+), 3 deletions(-)


base-commit: ee5b455b0adae9ecafb38b174c648c48f2a3c1a5

Comments

kernel test robot May 11, 2024, 4:56 a.m. UTC | #1
Hi Maxwell,

kernel test robot noticed the following build errors:

[auto build test ERROR on ee5b455b0adae9ecafb38b174c648c48f2a3c1a5]

url:    https://github.com/intel-lab-lkp/linux/commits/Maxwell-Bland/arm64-mm-code-and-data-allocation-partitioning/20240510-022822
base:   ee5b455b0adae9ecafb38b174c648c48f2a3c1a5
patch link:    https://lore.kernel.org/r/ozcyvkcdqhxhlg3sjz3s4odt7ejiwx2cctgb7sdx6jbardui37%40al6uvt4yx5nt
patch subject: [PATCH v5 1/2] mm: allow dynamic vmalloc range restrictions
config: alpha-defconfig (https://download.01.org/0day-ci/archive/20240511/202405111234.17zoTVX3-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240511/202405111234.17zoTVX3-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/202405111234.17zoTVX3-lkp@intel.com/

All errors (new ones prefixed by >>):

   alpha-linux-ld: net/8021q/vlan_dev.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/8021q/vlan.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/8021q/vlan_netlink.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/8021q/vlan.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/8021q/vlanproc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/8021q/vlan.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: net/sunrpc/xprt.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/socklib.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/xprtsock.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/sched.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_null.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_tls.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_unix.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/svc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/svcsock.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/svcauth.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/svcauth_unix.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/addr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/rpcb_clnt.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/timer.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/sunrpc_syms.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/cache.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/rpc_pipe.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/sysfs.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/svc_xprt.o: in function `arch_init_checked_vmap_ranges':
   include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/xprtmultipath.o: in function `arch_init_checked_vmap_ranges':
   include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/stats.o: in function `arch_init_checked_vmap_ranges':
   include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/sysctl.o: in function `arch_init_checked_vmap_ranges':
   net/sunrpc/sysctl.c:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/clnt.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: drivers/scsi/aic7xxx/aic7xxx_93cx6.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; drivers/scsi/aic7xxx/aic7xxx_core.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: drivers/scsi/aic7xxx/aic7xxx_pci.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; drivers/scsi/aic7xxx/aic7xxx_core.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: drivers/scsi/aic7xxx/aic7xxx_reg_print.o: in function `arch_init_checked_vmap_ranges':
   drivers/scsi/aic7xxx/aic7xxx_reg_print.c:137: multiple definition of `arch_init_checked_vmap_ranges'; drivers/scsi/aic7xxx/aic7xxx_core.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: drivers/scsi/aic7xxx/aic7xxx_osm.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; drivers/scsi/aic7xxx/aic7xxx_core.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: drivers/scsi/aic7xxx/aic7xxx_proc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; drivers/scsi/aic7xxx/aic7xxx_core.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: drivers/scsi/aic7xxx/aic7xxx_osm_pci.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; drivers/scsi/aic7xxx/aic7xxx_core.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: net/sunrpc/auth_gss/gss_generic_token.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/auth_gss.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_mech_switch.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/auth_gss.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/svcauth_gss.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/auth_gss.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_rpc_upcall.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/auth_gss.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_rpc_xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/auth_gss.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/trace.o: in function `arch_init_checked_vmap_ranges':
   net/sunrpc/auth_gss/trace.c:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/auth_gss.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: net/sunrpc/auth_gss/gss_krb5_seal.o: in function `arch_init_checked_vmap_ranges':
>> net/sunrpc/auth_gss/gss_krb5_seal.c:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/gss_krb5_mech.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_krb5_unseal.o: in function `arch_init_checked_vmap_ranges':
   net/sunrpc/auth_gss/gss_krb5_unseal.c:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/gss_krb5_mech.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_krb5_wrap.o: in function `arch_init_checked_vmap_ranges':
   include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/gss_krb5_mech.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_krb5_crypto.o: in function `arch_init_checked_vmap_ranges':
   include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/gss_krb5_mech.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: net/sunrpc/auth_gss/gss_krb5_keys.o: in function `arch_init_checked_vmap_ranges':
   include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; net/sunrpc/auth_gss/gss_krb5_mech.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: fs/reiserfs/do_balan.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/namei.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/inode.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/file.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/dir.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/fix_node.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/super.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/prints.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/objectid.o: in function `arch_init_checked_vmap_ranges':
   fs/reiserfs/objectid.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/lbalance.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/ibalance.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/stree.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/hashes.o: in function `arch_init_checked_vmap_ranges':
   fs/reiserfs/hashes.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/tail_conversion.o: in function `arch_init_checked_vmap_ranges':
   fs/reiserfs/tail_conversion.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/journal.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/resize.o: in function `arch_init_checked_vmap_ranges':
   fs/reiserfs/resize.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/item_ops.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/ioctl.o: in function `arch_init_checked_vmap_ranges':
   fs/reiserfs/ioctl.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/xattr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/reiserfs/lock.o: in function `arch_init_checked_vmap_ranges':
   fs/reiserfs/lock.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/reiserfs/bitmap.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: fs/nfs/dir.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/file.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/getroot.o: in function `arch_init_checked_vmap_ranges':
   fs/nfs/getroot.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/inode.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/super.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/io.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/direct.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/pagelist.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/read.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/symlink.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/unlink.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/write.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/namespace.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/mount_clnt.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/nfstrace.o: in function `arch_init_checked_vmap_ranges':
   fs/nfs/nfstrace.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/export.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/sysfs.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/fs_context.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/sysctl.o: in function `arch_init_checked_vmap_ranges':
   fs/nfs/sysctl.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/client.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: fs/nfs/proc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/nfs2super.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/nfs2xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/nfs2super.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: fs/nfs/nfs3client.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/nfs3super.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/nfs3proc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/nfs3super.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/nfs/nfs3xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfs/nfs3super.o:include/linux/vmalloc.h:137: first defined here
--
   alpha-linux-ld: fs/nfsd/nfssvc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/nfsctl.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/nfsfh.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/vfs.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/export.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/auth.o: in function `arch_init_checked_vmap_ranges':
   fs/nfsd/auth.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/lockd.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/nfscache.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/stats.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/filecache.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/nfs3proc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/nfs3xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
   alpha-linux-ld: fs/nfsd/netlink.o: in function `arch_init_checked_vmap_ranges':
   fs/nfsd/netlink.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/nfsd/trace.o:fs/nfsd/trace.c:137: first defined here
--
   alpha-linux-ld: fs/lockd/clntproc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/clntxdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/host.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/svc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/svclock.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/svcshare.o: in function `arch_init_checked_vmap_ranges':
   fs/lockd/svcshare.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/svcproc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/svcsubs.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/mon.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/trace.o: in function `arch_init_checked_vmap_ranges':
   fs/lockd/trace.c:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/clnt4xdr.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/xdr4.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/svc4proc.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here
   alpha-linux-ld: fs/lockd/procfs.o: in function `arch_init_checked_vmap_ranges':
>> include/linux/vmalloc.h:137: multiple definition of `arch_init_checked_vmap_ranges'; fs/lockd/clntlock.o:include/linux/vmalloc.h:137: first defined here


vim +137 include/linux/vmalloc.h

   133	
   134	#ifndef arch_init_checked_vmap_ranges
   135	inline void __init arch_init_checked_vmap_ranges(void)
   136	{
 > 137	}
   138	#endif
   139
kernel test robot May 11, 2024, 5:30 a.m. UTC | #2
Hi Maxwell,

kernel test robot noticed the following build errors:

[auto build test ERROR on ee5b455b0adae9ecafb38b174c648c48f2a3c1a5]

url:    https://github.com/intel-lab-lkp/linux/commits/Maxwell-Bland/arm64-mm-code-and-data-allocation-partitioning/20240510-022822
base:   ee5b455b0adae9ecafb38b174c648c48f2a3c1a5
patch link:    https://lore.kernel.org/r/ozcyvkcdqhxhlg3sjz3s4odt7ejiwx2cctgb7sdx6jbardui37%40al6uvt4yx5nt
patch subject: [PATCH v5 1/2] mm: allow dynamic vmalloc range restrictions
config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20240511/202405111325.7IRuG4ZE-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240511/202405111325.7IRuG4ZE-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/202405111325.7IRuG4ZE-lkp@intel.com/

All errors (new ones prefixed by >>):

   or1k-linux-ld: init/do_mounts.o: in function `arch_init_checked_vmap_ranges':
>> do_mounts.c:(.init.text+0x53c): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: init/do_mounts_initrd.o: in function `arch_init_checked_vmap_ranges':
   do_mounts_initrd.c:(.init.text+0x100): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: init/initramfs.o: in function `arch_init_checked_vmap_ranges':
   initramfs.c:(.init.text+0x13b4): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: init/init_task.o: in function `arch_init_checked_vmap_ranges':
   init_task.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/setup.o: in function `arch_init_checked_vmap_ranges':
   setup.c:(.init.text+0x6c): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/or32_ksyms.o: in function `arch_init_checked_vmap_ranges':
   or32_ksyms.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/process.o: in function `arch_init_checked_vmap_ranges':
   process.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/dma.o: in function `arch_init_checked_vmap_ranges':
   dma.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/traps.o: in function `arch_init_checked_vmap_ranges':
   traps.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/time.o: in function `arch_init_checked_vmap_ranges':
   time.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/irq.o: in function `arch_init_checked_vmap_ranges':
   irq.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/signal.o: in function `arch_init_checked_vmap_ranges':
   signal.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/kernel/sys_call_table.o: in function `arch_init_checked_vmap_ranges':
   sys_call_table.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/mm/fault.o: in function `arch_init_checked_vmap_ranges':
   fault.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/mm/init.o: in function `arch_init_checked_vmap_ranges':
   init.c:(.init.text+0x21c): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: arch/openrisc/mm/ioremap.o: in function `arch_init_checked_vmap_ranges':
   ioremap.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/fork.o: in function `arch_init_checked_vmap_ranges':
   fork.c:(.init.text+0x40): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/exec_domain.o: in function `arch_init_checked_vmap_ranges':
   exec_domain.c:(.init.text+0x44): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/panic.o: in function `arch_init_checked_vmap_ranges':
   panic.c:(.init.text+0x204): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/cpu.o: in function `arch_init_checked_vmap_ranges':
   cpu.c:(.init.text+0xb0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/exit.o: in function `arch_init_checked_vmap_ranges':
   exit.c:(.init.text+0x84): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/softirq.o: in function `arch_init_checked_vmap_ranges':
   softirq.c:(.init.text+0x8c): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/resource.o: in function `arch_init_checked_vmap_ranges':
   resource.c:(.init.text+0x2dc): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/sysctl.o: in function `arch_init_checked_vmap_ranges':
   sysctl.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/capability.o: in function `arch_init_checked_vmap_ranges':
   capability.c:(.init.text+0x2c): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/ptrace.o: in function `arch_init_checked_vmap_ranges':
   ptrace.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/user.o: in function `arch_init_checked_vmap_ranges':
   user.c:(.init.text+0xb0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/signal.o: in function `arch_init_checked_vmap_ranges':
   signal.c:(.init.text+0x84): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/sys.o: in function `arch_init_checked_vmap_ranges':
   sys.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/umh.o: in function `arch_init_checked_vmap_ranges':
   umh.c:(.init.text+0x48): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/workqueue.o: in function `arch_init_checked_vmap_ranges':
   workqueue.c:(.init.text+0x7e8): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/pid.o: in function `arch_init_checked_vmap_ranges':
   pid.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/task_work.o: in function `arch_init_checked_vmap_ranges':
   task_work.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/extable.o: in function `arch_init_checked_vmap_ranges':
   extable.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/params.o: in function `arch_init_checked_vmap_ranges':
   params.c:(.init.text+0x444): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/kthread.o: in function `arch_init_checked_vmap_ranges':
   kthread.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/nsproxy.o: in function `arch_init_checked_vmap_ranges':
   nsproxy.c:(.init.text+0x48): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/notifier.o: in function `arch_init_checked_vmap_ranges':
   notifier.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/ksysfs.o: in function `arch_init_checked_vmap_ranges':
   ksysfs.c:(.init.text+0xe0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/cred.o: in function `arch_init_checked_vmap_ranges':
   cred.c:(.init.text+0x44): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/reboot.o: in function `arch_init_checked_vmap_ranges':
   reboot.c:(.init.text+0x2c0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/ucount.o: in function `arch_init_checked_vmap_ranges':
   ucount.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/ksyms_common.o: in function `arch_init_checked_vmap_ranges':
   ksyms_common.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/groups.o: in function `arch_init_checked_vmap_ranges':
   groups.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/sched/core.o: in function `arch_init_checked_vmap_ranges':
   core.c:(.init.text+0x44): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/sched/fair.o: in function `arch_init_checked_vmap_ranges':
   fair.c:(.init.text+0xbc): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/sched/build_policy.o: in function `arch_init_checked_vmap_ranges':
   build_policy.c:(.init.text+0x90): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/sched/build_utility.o: in function `arch_init_checked_vmap_ranges':
   build_utility.c:(.init.text+0x44): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/locking/mutex.o: in function `arch_init_checked_vmap_ranges':
   mutex.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/locking/semaphore.o: in function `arch_init_checked_vmap_ranges':
   semaphore.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
   or1k-linux-ld: kernel/power/qos.o: in function `arch_init_checked_vmap_ranges':
   qos.c:(.init.text+0x0): multiple definition of `arch_init_checked_vmap_ranges'; init/main.o:main.c:(.init.text+0xa54): first defined here
diff mbox series

Patch

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 98ea90e90439..ece8879ab060 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -81,6 +81,12 @@  struct vmap_area {
 	unsigned long flags; /* mark type of vm_map_ram area */
 };
 
+struct checked_vmap_range {
+	unsigned long va_start;
+	unsigned long va_end;
+	struct list_head list;
+};
+
 /* archs that select HAVE_ARCH_HUGE_VMAP should override one or more of these */
 #ifndef arch_vmap_p4d_supported
 static inline bool arch_vmap_p4d_supported(pgprot_t prot)
@@ -125,6 +131,12 @@  static inline pgprot_t arch_vmap_pgprot_tagged(pgprot_t prot)
 }
 #endif
 
+#ifndef arch_init_checked_vmap_ranges
+inline void __init arch_init_checked_vmap_ranges(void)
+{
+}
+#endif
+
 /*
  *	Highlevel APIs for driver use
  */
@@ -211,6 +223,8 @@  extern struct vm_struct *__get_vm_area_caller(unsigned long size,
 					unsigned long flags,
 					unsigned long start, unsigned long end,
 					const void *caller);
+int __init create_vmalloc_range_check(unsigned long start_vaddr,
+					unsigned long end_vaddr);
 void free_vm_area(struct vm_struct *area);
 extern struct vm_struct *remove_vm_area(const void *addr);
 extern struct vm_struct *find_vm_area(const void *addr);
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 68fa001648cc..8f382b6c31de 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -817,6 +817,16 @@  static struct kmem_cache *vmap_area_cachep;
  */
 static LIST_HEAD(free_vmap_area_list);
 
+static struct kmem_cache *vmap_checked_range_cachep;
+
+/*
+ * This linked list is used to record ranges of the vmalloc
+ * region which are checked at allocation time to ensure they
+ * are only allocated within when an explicit allocation
+ * request to that range is made.
+ */
+static LIST_HEAD(checked_range_list);
+
 /*
  * This augment red-black tree represents the free vmap space.
  * All vmap_area objects in this tree are sorted by va->va_start
@@ -1454,6 +1464,23 @@  merge_or_add_vmap_area_augment(struct vmap_area *va,
 	return va;
 }
 
+static __always_inline bool
+va_is_range_restricted(struct vmap_area *va, unsigned long vstart)
+{
+	struct checked_vmap_range *range, *tmp;
+
+	if (list_empty(&checked_range_list))
+		return false;
+
+	list_for_each_entry_safe(range, tmp, &checked_range_list, list)
+		if (va->va_start >= range->va_start &&
+		    va->va_end <= range->va_end &&
+		    vstart != range->va_start)
+			return true;
+
+	return false;
+}
+
 static __always_inline bool
 is_within_this_va(struct vmap_area *va, unsigned long size,
 	unsigned long align, unsigned long vstart)
@@ -1501,7 +1528,8 @@  find_vmap_lowest_match(struct rb_root *root, unsigned long size,
 				vstart < va->va_start) {
 			node = node->rb_left;
 		} else {
-			if (is_within_this_va(va, size, align, vstart))
+			if (!va_is_range_restricted(va, vstart) &&
+			    is_within_this_va(va, size, align, vstart))
 				return va;
 
 			/*
@@ -1522,7 +1550,8 @@  find_vmap_lowest_match(struct rb_root *root, unsigned long size,
 			 */
 			while ((node = rb_parent(node))) {
 				va = rb_entry(node, struct vmap_area, rb_node);
-				if (is_within_this_va(va, size, align, vstart))
+				if (!va_is_range_restricted(va, vstart) &&
+				    is_within_this_va(va, size, align, vstart))
 					return va;
 
 				if (get_subtree_max_size(node->rb_right) >= length &&
@@ -1554,7 +1583,8 @@  find_vmap_lowest_linear_match(struct list_head *head, unsigned long size,
 	struct vmap_area *va;
 
 	list_for_each_entry(va, head, list) {
-		if (!is_within_this_va(va, size, align, vstart))
+		if (va_is_range_restricted(va, vstart) ||
+		    !is_within_this_va(va, size, align, vstart))
 			continue;
 
 		return va;
@@ -1717,6 +1747,36 @@  va_clip(struct rb_root *root, struct list_head *head,
 	return 0;
 }
 
+static inline int
+split_and_alloc_va(struct rb_root *root, struct list_head *head, unsigned long addr)
+{
+	struct vmap_area *va;
+	int ret;
+	struct vmap_area *lva = NULL;
+
+	va = __find_vmap_area(addr, root);
+	if (!va) {
+		pr_err("%s: could not find vmap\n", __func__);
+		return -1;
+	}
+
+	lva = kmem_cache_alloc(vmap_area_cachep, GFP_NOWAIT);
+	if (!lva) {
+		pr_err("%s: unable to allocate va for range\n", __func__);
+		return -1;
+	}
+	lva->va_start = addr;
+	lva->va_end = va->va_end;
+	ret = va_clip(root, head, va, addr, va->va_end - addr);
+	if (WARN_ON_ONCE(ret)) {
+		pr_err("%s: unable to clip code base region\n", __func__);
+		kmem_cache_free(vmap_area_cachep, lva);
+		return -1;
+	}
+	insert_vmap_area_augment(lva, NULL, root, head);
+	return 0;
+}
+
 static unsigned long
 va_alloc(struct vmap_area *va,
 		struct rb_root *root, struct list_head *head,
@@ -4424,6 +4484,35 @@  int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
 }
 EXPORT_SYMBOL(remap_vmalloc_range);
 
+/**
+ * create_vmalloc_range_check - create a checked range of vmalloc memory
+ * @start_vaddr:	The starting vaddr of the code range
+ * @end_vaddr:		The ending vaddr of the code range
+ *
+ * Returns:	0 for success, -1 on failure
+ *
+ * This function marks regions within or overlapping the vmalloc region for
+ * requested range checking during allocation. When requesting virtual memory,
+ * if the requested starting vaddr does not explicitly match the starting vaddr
+ * of this range, this range will not be allocated from.
+ */
+int __init create_vmalloc_range_check(unsigned long start_vaddr,
+					unsigned long end_vaddr)
+{
+	struct checked_vmap_range *range;
+
+	range = kmem_cache_alloc(vmap_checked_range_cachep, GFP_NOWAIT);
+	if (split_and_alloc_va(&free_vmap_area_root, &free_vmap_area_list, start_vaddr) ||
+	    split_and_alloc_va(&free_vmap_area_root, &free_vmap_area_list, end_vaddr))
+		return -1;
+
+	range->va_start = start_vaddr;
+	range->va_end = end_vaddr;
+
+	list_add(&range->list, &checked_range_list);
+	return 0;
+}
+
 void free_vm_area(struct vm_struct *area)
 {
 	struct vm_struct *ret;
@@ -5082,6 +5171,11 @@  void __init vmalloc_init(void)
 	 */
 	vmap_area_cachep = KMEM_CACHE(vmap_area, SLAB_PANIC);
 
+	/*
+	 * Create the cache for checked vmap ranges.
+	 */
+	vmap_checked_range_cachep = KMEM_CACHE(checked_vmap_range, SLAB_PANIC);
+
 	for_each_possible_cpu(i) {
 		struct vmap_block_queue *vbq;
 		struct vfree_deferred *p;
@@ -5129,4 +5223,6 @@  void __init vmalloc_init(void)
 	vmap_node_shrinker->count_objects = vmap_node_shrink_count;
 	vmap_node_shrinker->scan_objects = vmap_node_shrink_scan;
 	shrinker_register(vmap_node_shrinker);
+
+	arch_init_checked_vmap_ranges();
 }