1. 21 12月, 2020 1 次提交
    • M
      modpost: rename merror() to error() · bc72d723
      Masahiro Yamada 提交于
      The log function names, warn(), merror(), fatal() are inconsistent.
      
      Commit 2a116659 ("kbuild: distinguish between errors and warnings
      in modpost") intentionally chose merror() to avoid the conflict with
      the library function error(). See man page of error(3).
      
      But, we are already causing the conflict with warn() because it is also
      a library function. See man page of warn(3). err() would be a problem
      for the same reason.
      
      The common technique to work around name conflicts is to use macros.
      For example:
      
          /* in a header */
          #define error(fmt, ...)  __error(fmt, ##__VA_ARGS__)
          #define warn(fmt, ...)   __warn(fmt, ##__VA_ARGS__)
      
          /* function definition */
          void __error(const char *fmt, ...)
          {
                  <our implementation>
          }
      
          void __warn(const char *fmt, ...)
          {
                  <our implementation>
          }
      
      In this way, we can implement our own warn() and error(), still we can
      include <error.h> and <err.h> with no problem.
      
      And, commit 93c95e52 ("modpost: rework and consolidate logging
      interface") already did that.
      
      Since the log functions are all macros, we can use error() without
      causing "conflicting types" errors.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      bc72d723
  2. 26 10月, 2020 1 次提交
  3. 10 8月, 2020 1 次提交
    • M
      kbuild: introduce hostprogs-always-y and userprogs-always-y · faabed29
      Masahiro Yamada 提交于
      To build host programs, you need to add the program names to 'hostprogs'
      to use the necessary build rule, but it is not enough to build them
      because there is no dependency.
      
      There are two types of host programs: built as the prerequisite of
      another (e.g. gen_crc32table in lib/Makefile), or always built when
      Kbuild visits the Makefile (e.g. genksyms in scripts/genksyms/Makefile).
      
      The latter is typical in Makefiles under scripts/, which contains host
      programs globally used during the kernel build. To build them, you need
      to add them to both 'hostprogs' and 'always-y'.
      
      This commit adds hostprogs-always-y as a shorthand.
      
      The same applies to user programs. net/bpfilter/Makefile builds
      bpfilter_umh on demand, hence always-y is unneeded. In contrast,
      programs under samples/ are added to both 'userprogs' and 'always-y'
      so they are always built when Kbuild visits the Makefiles.
      
      userprogs-always-y works as a shorthand.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: NMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      faabed29
  4. 27 7月, 2020 1 次提交
  5. 07 7月, 2020 1 次提交
  6. 30 6月, 2020 1 次提交
  7. 06 6月, 2020 23 次提交
    • M
      modpost: change elf_info->size to size_t · 3b09efc4
      Masahiro Yamada 提交于
      Align with the mmap / munmap APIs.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      3b09efc4
    • M
      modpost: remove is_vmlinux() helper · 4de7b629
      Masahiro Yamada 提交于
      Now that is_vmlinux() is called only in new_module(), we can inline
      the function call.
      
      modname is the basename with '.o' is stripped. No need to compare it
      with 'vmlinux.o'.
      
      vmlinux is always located at the current working directory. No need
      to strip the directory path.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      4de7b629
    • M
      modpost: strip .o from modname before calling new_module() · a82f794c
      Masahiro Yamada 提交于
      new_module() conditionally strips the .o because the modname has .o
      suffix when it is called from read_symbols(), but no .o when it is
      called from read_dump().
      
      It is clearer to strip .o in read_symbols().
      
      I also used flexible-array for mod->name.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      a82f794c
    • M
      modpost: set have_vmlinux in new_module() · 858b937d
      Masahiro Yamada 提交于
      Set have_vmlinux flag in a single place.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      858b937d
    • M
      modpost: remove mod->skip struct member · 0b19d54c
      Masahiro Yamada 提交于
      The meaning of 'skip' is obscure since it does not explain
      "what to skip".
      
      mod->skip is set when it is vmlinux or the module info came from
      a dump file.
      
      So, mod->skip is equivalent to (mod->is_vmlinux || mod->from_dump).
      
      For the check in write_namespace_deps_files(), mod->is_vmlinux is
      unneeded because the -d option is not passed in the first pass of
      modpost.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      0b19d54c
    • M
      modpost: add mod->is_vmlinux struct member · 5a438af9
      Masahiro Yamada 提交于
      is_vmlinux() is called in several places to check whether the current
      module is vmlinux or not.
      
      It is faster and clearer to check mod->is_vmlinux flag.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      5a438af9
    • M
      modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}() · 1be5fa6c
      Masahiro Yamada 提交于
      check_exports() is never called for vmlinux because mod->skip is set
      for vmlinux.
      
      Hence, check_for_gpl_usage() and check_for_unused() are not called
      for vmlinux, either. is_vmlinux() is always false here.
      
      Remove the is_vmlinux() calls, and hard-code the ".ko" suffix.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      1be5fa6c
    • M
      modpost: remove mod->is_dot_o struct member · 3379576d
      Masahiro Yamada 提交于
      Previously, there were two cases where mod->is_dot_o is unset:
      
      [1] the executable 'vmlinux' in the second pass of modpost
      [2] modules loaded by read_dump()
      
      I think [1] was intended usage to distinguish 'vmlinux.o' and 'vmlinux'.
      Now that modpost does not parse the executable 'vmlinux', this case
      does not happen.
      
      [2] is obscure, maybe a bug. Module.symver stores module paths without
      extension. So, none of modules loaded by read_dump() has the .o suffix,
      and new_module() unsets ->is_dot_o. Anyway, it is not a big deal because
      handle_symbol() is not called for the case.
      
      To sum up, all the parsed ELF files are .o files.
      
      mod->is_dot_o is unneeded.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      3379576d
    • M
      modpost: remove -s option · 467b82d7
      Masahiro Yamada 提交于
      The -s option was added by commit 8d8d8289 ("kbuild: do not do
      section mismatch checks on vmlinux in 2nd pass").
      
      Now that the second pass does not parse vmlinux, this option is
      unneeded.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      467b82d7
    • M
      modpost: remove get_next_text() and make {grab,release_}file static · 75893572
      Masahiro Yamada 提交于
      get_next_line() is no longer used. Remove.
      
      grab_file() and release_file() are only used in modpost.c. Make them
      static.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      75893572
    • M
      modpost: use read_text_file() and get_line() for reading text files · 70f30cfe
      Masahiro Yamada 提交于
      grab_file() mmaps a file, but it is not so efficient here because
      get_next_line() copies every line to the temporary buffer anyway.
      
      read_text_file() and get_line() are simpler. get_line() exploits the
      library function strchr().
      
      Going forward, the missing *.symvers or *.cmd is a fatal error.
      This should not happen because scripts/Makefile.modpost guards the
      -i option files with $(wildcard $(input-symdump)).
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      70f30cfe
    • M
      modpost: avoid false-positive file open error · 7c8f5662
      Masahiro Yamada 提交于
      One problem of grab_file() is that it cannot distinguish the following
      two cases:
      
       - It cannot read the file (the file does not exist, or read permission
         is not set)
      
       - It can read the file, but the file size is zero
      
      This is because grab_file() calls mmap(), which requires the mapped
      length is greater than 0. Hence, grab_file() fails for both cases.
      
      If an empty header file were included for checksum calculation, the
      following warning would be printed:
      
        WARNING: modpost: could not open ...: Invalid argument
      
      An empty file is a valid source file, so it should not fail.
      
      Use read_text_file() instead. It can read a zero-length file.
      Then, parse_file() will succeed with doing nothing.
      
      Going forward, the first case (it cannot read the file) is a fatal
      error. If the source file from which an object was compiled is missing,
      something went wrong.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      7c8f5662
    • M
      modpost: fix potential mmap'ed file overrun in get_src_version() · f531c1b5
      Masahiro Yamada 提交于
      I do not know how reliably this function works, but it looks dangerous
      to me.
      
          strchr(sources, '\n');
      
      ... continues searching until it finds '\n' or it reaches the '\0'
      terminator. In other words, 'sources' should be a null-terminated
      string.
      
      However, grab_file() just mmaps a file, so 'sources' is not terminated
      with null byte. If the file does not contain '\n' at all, strchr() will
      go beyond the mmap'ed memory.
      
      Use read_text_file(), which loads the file content into a malloc'ed
      buffer, appending null byte.
      
      Here we are interested only in the first line of *.mod files. Use
      get_line() helper to get the first line.
      
      This also makes missing *.mod file a fatal error.
      
      Commit 4be40e22 ("kbuild: do not emit src version warning for
      non-modules") ignored missing *.mod files.
      
      I do not fully understand what that commit addressed, but commit
      91341d4b ("kbuild: introduce new option to enhance section mismatch
      analysis") introduced partial section checks by using modpost. built-in.o
      was parsed by modpost. Even modules had a problem because *.mod files
      were created after the modpost check.
      
      Commit b7dca6dd ("kbuild: create *.mod with full directory path and
      remove MODVERDIR") stopped doing that. Now that modpost is only invoked
      after the directory descend, *.mod files should always exist at the
      modpost stage.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      f531c1b5
    • M
      modpost: add read_text_file() and get_line() helpers · ac5100f5
      Masahiro Yamada 提交于
      modpost uses grab_file() to open a file, but it is not suitable for
      a text file because the mmap'ed file is not terminated by null byte.
      Actually, I see some issues for the use of grab_file().
      
      The new helper, read_text_file() loads the whole file content into a
      malloc'ed buffer, and appends a null byte. Then, get_line() reads
      each line.
      
      To handle text files, I intend to replace as follows:
      
        grab_file()    -> read_text_file()
        get_new_line() -> get_line()
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      ac5100f5
    • M
      modpost: do not call get_modinfo() for vmlinux(.o) · 4ddea2f8
      Masahiro Yamada 提交于
      The three calls of get_modinfo() ("license", "import_ns", "version")
      always return NULL for vmlinux(.o) because the built-in module info is
      prefixed with __MODULE_INFO_PREFIX.
      
      It is harmless to call get_modinfo(), but there is no point to search
      for what apparently does not exist.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      4ddea2f8
    • M
      modpost: drop RCS/CVS $Revision handling in MODULE_VERSION() · f6931535
      Masahiro Yamada 提交于
      As far as I understood, this code gets rid of '$Revision$' or '$Revision:'
      of CVS, RCS or whatever in MODULE_VERSION() tags.
      
      Remove the primeval code.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      f6931535
    • M
      modpost: show warning if vmlinux is not found when processing modules · 7e8a3235
      Masahiro Yamada 提交于
      check_exports() does not print warnings about unresolved symbols if
      vmlinux is missing because there would be too many.
      
      This situation happens when you do 'make modules' from the clean
      tree, or compile external modules against a kernel tree that has
      not been completely built.
      
      It is dangerous to not check unresolved symbols because you might be
      building useless modules. At least it should be warned.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      7e8a3235
    • M
      modpost: invoke modpost only when input files are updated · 436b2ac6
      Masahiro Yamada 提交于
      Currently, the second pass of modpost is always invoked when you run
      'make' or 'make modules' even if none of modules is changed.
      
      Use if_changed to invoke it only when it is necessary.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      436b2ac6
    • M
      modpost: re-add -e to set external_module flag · e3fb4df7
      Masahiro Yamada 提交于
      Previously, the -i option had two functions; load a symbol dump file,
      and set the external_module flag.
      
      I want to assign a dedicate option for each of them.
      
      Going forward, the -i is used to load a symbol dump file, and the -e
      to set the external_module flag.
      
      With this, we will be able to use -i for loading in-kernel symbols.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      e3fb4df7
    • M
      modpost: rename ext_sym_list to dump_list · 7924799e
      Masahiro Yamada 提交于
      The -i option is used to include Modules.symver as well as files from
      $(KBUILD_EXTRA_SYMBOLS).
      
      Make the struct and variable names more generic.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      7924799e
    • M
      modpost: allow to pass -i option multiple times to remove -e option · ce2ddd6d
      Masahiro Yamada 提交于
      Now that there is no difference between -i and -e, they can be unified.
      
      Make modpost accept the -i option multiple times, then remove -e.
      
      I will reuse -e for a different purpose.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      ce2ddd6d
    • M
      modpost: track if the symbol origin is a dump file or ELF object · 52c3416d
      Masahiro Yamada 提交于
      The meaning of sym->kernel is obscure; it is set for in-kernel symbols
      loaded from Modules.symvers. This happens only when we are building
      external modules, and it is used to determine whether to dump symbols
      to $(KBUILD_EXTMOD)/Modules.symvers
      
      It is clearer to remember whether the symbol or module came from a dump
      file or ELF object.
      
      This changes the KBUILD_EXTRA_SYMBOLS behavior. Previously, symbols
      loaded from KBUILD_EXTRA_SYMBOLS are accumulated into the current
      $(KBUILD_EXTMOD)/Modules.symvers
      
      Going forward, they will be only used to check symbol references, but
      not dumped into the current $(KBUILD_EXTMOD)/Modules.symvers. I believe
      this makes more sense.
      
      sym->vmlinux will have no user. Remove it too.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      52c3416d
    • E
      firmware/dmi: Report DMI Bios & EC firmware release · f5152f4d
      Erwan Velu 提交于
      Some vendors like HPe or Dell, encode the release version of their BIOS
      in the "System BIOS {Major|Minor} Release" fields of Type 0.
      
      This information is used to know which bios release actually runs.
      It could be used for some quirks, debugging sessions or inventory tasks.
      
      A typical output for a Dell system running the 65.27 bios is :
      	[root@t1700 ~]# cat /sys/devices/virtual/dmi/id/bios_release
      	65.27
      	[root@t1700 ~]#
      
      Servers that have a BMC encode the release version of their firmware in the
       "Embedded Controller Firmware {Major|Minor} Release" fields of Type 0.
      
      This information is used to know which BMC release actually runs.
      It could be used for some quirks, debugging sessions or inventory tasks.
      
      A typical output for a Dell system running the 3.75 bmc release is :
          [root@t1700 ~]# cat /sys/devices/virtual/dmi/id/ec_firmware_release
          3.75
          [root@t1700 ~]#
      Signed-off-by: NErwan Velu <e.velu@criteo.com>
      Signed-off-by: NJean Delvare <jdelvare@suse.de>
      f5152f4d
  8. 03 6月, 2020 1 次提交
  9. 29 5月, 2020 2 次提交
    • M
      modpost: refactor sech_name() · 565587d8
      Masahiro Yamada 提交于
      Use sym_get_data_by_offset() helper to get access to the .shstrtab
      section data. No functional change is intended because
      elf->sechdrs[elf->secindex_strings].sh_addr is 0 for both ET_REL
      and ET_EXEC object types.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      565587d8
    • M
      modpost: fix potential segmentation fault for addend_i386_rel() · d2e4d05c
      Masahiro Yamada 提交于
      This may not be a practical problem, but the second pass of ARCH=i386
      modpost causes segmentation fault if the -s option is not passed.
      
          MODPOST 12 modules
        Segmentation fault (core dumped)
        make[2]: *** [scripts/Makefile.modpost:94: __modpost] Error 139
        make[1]: *** [Makefile:1339: modules] Error 2
        make[1]: *** Waiting for unfinished jobs....
      
      The segmentation fault occurs when section_rel() is called for vmlinux,
      which is untested in regular builds. The cause of the problem is
      reloc_location() returning a wrong pointer for ET_EXEC object type.
      In this case, you need to subtract sechdr->sh_addr, otherwise it would
      get access beyond the mmap'ed memory.
      
      Add sym_get_data_by_offset() helper to avoid code duplication.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      d2e4d05c
  10. 25 5月, 2020 1 次提交
    • G
      modpost,fixdep: Replace zero-length array with flexible-array · 859c8175
      Gustavo A. R. Silva 提交于
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      859c8175
  11. 19 5月, 2020 1 次提交
  12. 22 4月, 2020 1 次提交
  13. 25 3月, 2020 1 次提交
  14. 21 3月, 2020 1 次提交
  15. 19 3月, 2020 2 次提交
  16. 17 3月, 2020 1 次提交
    • J
      modpost: move the namespace field in Module.symvers last · 5190044c
      Jessica Yu 提交于
      In order to preserve backwards compatability with kmod tools, we have to
      move the namespace field in Module.symvers last, as the depmod -e -E
      option looks at the first three fields in Module.symvers to check symbol
      versions (and it's expected they stay in the original order of crc,
      symbol, module).
      
      In addition, update an ancient comment above read_dump() in modpost that
      suggested that the export type field in Module.symvers was optional. I
      suspect that there were historical reasons behind that comment that are
      no longer accurate. We have been unconditionally printing the export
      type since 2.6.18 (commit bd5cbced), which is over a decade ago now.
      
      Fix up read_dump() to treat each field as non-optional. I suspect the
      original read_dump() code treated the export field as optional in order
      to support pre <= 2.6.18 Module.symvers (which did not have the export
      type field). Note that although symbol namespaces are optional, the
      field will not be omitted from Module.symvers if a symbol does not have
      a namespace. In this case, the field will simply be empty and the next
      delimiter or end of line will follow.
      
      Cc: stable@vger.kernel.org
      Fixes: cb9b55d2 ("modpost: add support for symbol namespaces")
      Tested-by: NMatthias Maennich <maennich@google.com>
      Reviewed-by: NMatthias Maennich <maennich@google.com>
      Reviewed-by: NLucas De Marchi <lucas.demarchi@intel.com>
      Signed-off-by: NJessica Yu <jeyu@kernel.org>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      5190044c