All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-next:master 6149/7089] drivers/firmware/efi/capsule.c:171 efi_capsule_update_locked() warn: should - mem_map) + pfn_base)) << (12)' be a 64 bit
@ 2020-09-12 12:57 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2020-09-12 12:57 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 14198 bytes --]

CC: kbuild-all(a)lists.01.org
TO: Atish Patra <atish.patra@wdc.com>
CC: Palmer Dabbelt <palmerdabbelt@google.com>
CC: Ard Biesheuvel <ardb@kernel.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   d5b2251d63b5344ee827d3680fa79bdb9f9ddfa1
commit: 282048ee6534dc5e218f6957eebe6805b2d0c3df [6149/7089] RISC-V: Add EFI stub support.
:::::: branch date: 30 hours ago
:::::: commit date: 4 days ago
config: riscv-randconfig-m031-20200911 (attached as .config)
compiler: riscv32-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/firmware/efi/capsule.c:171 efi_capsule_update_locked() warn: should '((((sg_pages[0]) - mem_map) + pfn_base)) << (12)' be a 64 bit type?
drivers/firmware/efi/capsule.c:266 efi_capsule_update() warn: should '((((sg_pages[i + 1]) - mem_map) + pfn_base)) << (12)' be a 64 bit type?

# https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=282048ee6534dc5e218f6957eebe6805b2d0c3df
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
git fetch --no-tags linux-next master
git checkout 282048ee6534dc5e218f6957eebe6805b2d0c3df
vim +171 drivers/firmware/efi/capsule.c

f0133f3c5b8bb3 Matt Fleming   2016-04-25  125  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  126  /**
f0133f3c5b8bb3 Matt Fleming   2016-04-25  127   * efi_capsule_update_locked - pass a single capsule to the firmware
f0133f3c5b8bb3 Matt Fleming   2016-04-25  128   * @capsule: capsule to send to the firmware
f0133f3c5b8bb3 Matt Fleming   2016-04-25  129   * @sg_pages: array of scatter gather (block descriptor) pages
f0133f3c5b8bb3 Matt Fleming   2016-04-25  130   * @reset: the reset type required for @capsule
f0133f3c5b8bb3 Matt Fleming   2016-04-25  131   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  132   * Since this function must be called under capsule_mutex check
f0133f3c5b8bb3 Matt Fleming   2016-04-25  133   * whether efi_reset_type will conflict with @reset, and atomically
f0133f3c5b8bb3 Matt Fleming   2016-04-25  134   * set it and capsule_pending if a capsule was successfully sent to
f0133f3c5b8bb3 Matt Fleming   2016-04-25  135   * the firmware.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  136   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  137   * We also check to see if the system is about to restart, and if so,
f0133f3c5b8bb3 Matt Fleming   2016-04-25  138   * abort. This avoids races between efi_capsule_update() and
f0133f3c5b8bb3 Matt Fleming   2016-04-25  139   * efi_capsule_pending().
f0133f3c5b8bb3 Matt Fleming   2016-04-25  140   */
f0133f3c5b8bb3 Matt Fleming   2016-04-25  141  static int
f0133f3c5b8bb3 Matt Fleming   2016-04-25  142  efi_capsule_update_locked(efi_capsule_header_t *capsule,
f0133f3c5b8bb3 Matt Fleming   2016-04-25  143  			  struct page **sg_pages, int reset)
f0133f3c5b8bb3 Matt Fleming   2016-04-25  144  {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  145  	efi_physical_addr_t sglist_phys;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  146  	efi_status_t status;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  147  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  148  	lockdep_assert_held(&capsule_mutex);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  149  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  150  	/*
f0133f3c5b8bb3 Matt Fleming   2016-04-25  151  	 * If someone has already registered a capsule that requires a
f0133f3c5b8bb3 Matt Fleming   2016-04-25  152  	 * different reset type, we're out of luck and must abort.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  153  	 */
f0133f3c5b8bb3 Matt Fleming   2016-04-25  154  	if (efi_reset_type >= 0 && efi_reset_type != reset) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  155  		pr_err("Conflicting capsule reset type %d (%d).\n",
f0133f3c5b8bb3 Matt Fleming   2016-04-25  156  		       reset, efi_reset_type);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  157  		return -EINVAL;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  158  	}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  159  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  160  	/*
f0133f3c5b8bb3 Matt Fleming   2016-04-25  161  	 * If the system is getting ready to restart it may have
f0133f3c5b8bb3 Matt Fleming   2016-04-25  162  	 * called efi_capsule_pending() to make decisions (such as
f0133f3c5b8bb3 Matt Fleming   2016-04-25  163  	 * whether to force an EFI reboot), and we're racing against
f0133f3c5b8bb3 Matt Fleming   2016-04-25  164  	 * that call. Abort in that case.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  165  	 */
62075e581802ea Matt Fleming   2016-05-06  166  	if (unlikely(stop_capsules)) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  167  		pr_warn("Capsule update raced with reboot, aborting.\n");
f0133f3c5b8bb3 Matt Fleming   2016-04-25  168  		return -EINVAL;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  169  	}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  170  
f0133f3c5b8bb3 Matt Fleming   2016-04-25 @171  	sglist_phys = page_to_phys(sg_pages[0]);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  172  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  173  	status = efi.update_capsule(&capsule, 1, sglist_phys);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  174  	if (status == EFI_SUCCESS) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  175  		capsule_pending = true;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  176  		efi_reset_type = reset;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  177  	}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  178  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  179  	return efi_status_to_err(status);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  180  }
f0133f3c5b8bb3 Matt Fleming   2016-04-25  181  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  182  /**
f0133f3c5b8bb3 Matt Fleming   2016-04-25  183   * efi_capsule_update - send a capsule to the firmware
f0133f3c5b8bb3 Matt Fleming   2016-04-25  184   * @capsule: capsule to send to firmware
f0133f3c5b8bb3 Matt Fleming   2016-04-25  185   * @pages: an array of capsule data pages
f0133f3c5b8bb3 Matt Fleming   2016-04-25  186   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  187   * Build a scatter gather list with EFI capsule block descriptors to
f0133f3c5b8bb3 Matt Fleming   2016-04-25  188   * map the capsule described by @capsule with its data in @pages and
f0133f3c5b8bb3 Matt Fleming   2016-04-25  189   * send it to the firmware via the UpdateCapsule() runtime service.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  190   *
6862e6ad95e984 Austin Christ  2016-08-11  191   * @capsule must be a virtual mapping of the complete capsule update in the
6862e6ad95e984 Austin Christ  2016-08-11  192   * kernel address space, as the capsule can be consumed immediately.
6862e6ad95e984 Austin Christ  2016-08-11  193   * A capsule_header_t that describes the entire contents of the capsule
f0133f3c5b8bb3 Matt Fleming   2016-04-25  194   * must be at the start of the first data page.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  195   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  196   * Even though this function will validate that the firmware supports
f0133f3c5b8bb3 Matt Fleming   2016-04-25  197   * the capsule guid, users will likely want to check that
f0133f3c5b8bb3 Matt Fleming   2016-04-25  198   * efi_capsule_supported() returns true before calling this function
f0133f3c5b8bb3 Matt Fleming   2016-04-25  199   * because it makes it easier to print helpful error messages.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  200   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  201   * If the capsule is successfully submitted to the firmware, any
f0133f3c5b8bb3 Matt Fleming   2016-04-25  202   * subsequent calls to efi_capsule_pending() will return true. @pages
f0133f3c5b8bb3 Matt Fleming   2016-04-25  203   * must not be released or modified if this function returns
f0133f3c5b8bb3 Matt Fleming   2016-04-25  204   * successfully.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  205   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  206   * Callers must be prepared for this function to fail, which can
f0133f3c5b8bb3 Matt Fleming   2016-04-25  207   * happen if we raced with system reboot or if there is already a
f0133f3c5b8bb3 Matt Fleming   2016-04-25  208   * pending capsule that has a reset type that conflicts with the one
f0133f3c5b8bb3 Matt Fleming   2016-04-25  209   * required by @capsule. Do NOT use efi_capsule_pending() to detect
f0133f3c5b8bb3 Matt Fleming   2016-04-25  210   * this conflict since that would be racy. Instead, submit the capsule
f0133f3c5b8bb3 Matt Fleming   2016-04-25  211   * to efi_capsule_update() and check the return value.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  212   *
f0133f3c5b8bb3 Matt Fleming   2016-04-25  213   * Return 0 on success, a converted EFI status code on failure.
f0133f3c5b8bb3 Matt Fleming   2016-04-25  214   */
2a457fb31df62c Ard Biesheuvel 2017-06-02  215  int efi_capsule_update(efi_capsule_header_t *capsule, phys_addr_t *pages)
f0133f3c5b8bb3 Matt Fleming   2016-04-25  216  {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  217  	u32 imagesize = capsule->imagesize;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  218  	efi_guid_t guid = capsule->guid;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  219  	unsigned int count, sg_count;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  220  	u32 flags = capsule->flags;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  221  	struct page **sg_pages;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  222  	int rv, reset_type;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  223  	int i, j;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  224  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  225  	rv = efi_capsule_supported(guid, flags, imagesize, &reset_type);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  226  	if (rv)
f0133f3c5b8bb3 Matt Fleming   2016-04-25  227  		return rv;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  228  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  229  	count = DIV_ROUND_UP(imagesize, PAGE_SIZE);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  230  	sg_count = sg_pages_num(count);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  231  
6396bb221514d2 Kees Cook      2018-06-12  232  	sg_pages = kcalloc(sg_count, sizeof(*sg_pages), GFP_KERNEL);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  233  	if (!sg_pages)
f0133f3c5b8bb3 Matt Fleming   2016-04-25  234  		return -ENOMEM;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  235  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  236  	for (i = 0; i < sg_count; i++) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  237  		sg_pages[i] = alloc_page(GFP_KERNEL);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  238  		if (!sg_pages[i]) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  239  			rv = -ENOMEM;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  240  			goto out;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  241  		}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  242  	}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  243  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  244  	for (i = 0; i < sg_count; i++) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  245  		efi_capsule_block_desc_t *sglist;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  246  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  247  		sglist = kmap(sg_pages[i]);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  248  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  249  		for (j = 0; j < SGLIST_PER_PAGE && count > 0; j++) {
2a457fb31df62c Ard Biesheuvel 2017-06-02  250  			u64 sz = min_t(u64, imagesize,
2a457fb31df62c Ard Biesheuvel 2017-06-02  251  				       PAGE_SIZE - (u64)*pages % PAGE_SIZE);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  252  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  253  			sglist[j].length = sz;
2a457fb31df62c Ard Biesheuvel 2017-06-02  254  			sglist[j].data = *pages++;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  255  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  256  			imagesize -= sz;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  257  			count--;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  258  		}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  259  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  260  		/* Continuation pointer */
f0133f3c5b8bb3 Matt Fleming   2016-04-25  261  		sglist[j].length = 0;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  262  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  263  		if (i + 1 == sg_count)
f0133f3c5b8bb3 Matt Fleming   2016-04-25  264  			sglist[j].data = 0;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  265  		else
f0133f3c5b8bb3 Matt Fleming   2016-04-25 @266  			sglist[j].data = page_to_phys(sg_pages[i + 1]);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  267  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  268  		kunmap(sg_pages[i]);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  269  	}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  270  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  271  	mutex_lock(&capsule_mutex);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  272  	rv = efi_capsule_update_locked(capsule, sg_pages, reset_type);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  273  	mutex_unlock(&capsule_mutex);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  274  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  275  out:
f0133f3c5b8bb3 Matt Fleming   2016-04-25  276  	for (i = 0; rv && i < sg_count; i++) {
f0133f3c5b8bb3 Matt Fleming   2016-04-25  277  		if (sg_pages[i])
f0133f3c5b8bb3 Matt Fleming   2016-04-25  278  			__free_page(sg_pages[i]);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  279  	}
f0133f3c5b8bb3 Matt Fleming   2016-04-25  280  
f0133f3c5b8bb3 Matt Fleming   2016-04-25  281  	kfree(sg_pages);
f0133f3c5b8bb3 Matt Fleming   2016-04-25  282  	return rv;
f0133f3c5b8bb3 Matt Fleming   2016-04-25  283  }
f0133f3c5b8bb3 Matt Fleming   2016-04-25  284  EXPORT_SYMBOL_GPL(efi_capsule_update);
62075e581802ea Matt Fleming   2016-05-06  285  

:::::: The code@line 171 was first introduced by commit
:::::: f0133f3c5b8bb34ec4dec50c27e7a655aeee8935 efi: Add 'capsule' update support

:::::: TO: Matt Fleming <matt@codeblueprint.co.uk>
:::::: CC: Ingo Molnar <mingo@kernel.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 27019 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-12 12:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-12 12:57 [linux-next:master 6149/7089] drivers/firmware/efi/capsule.c:171 efi_capsule_update_locked() warn: should - mem_map) + pfn_base)) << (12)' be a 64 bit kernel test robot

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.