From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: drivers/firmware/efi/capsule.c:172 efi_capsule_update_locked() warn: should '((((sg_pages[0]) - mem_map) + riscv_pfn_base)) << (12)' be a 64 bit type?
Date: Tue, 09 Nov 2021 10:27:53 +0800 [thread overview]
Message-ID: <202111091042.bC3Wyffr-lkp@intel.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 12759 bytes --]
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Kenneth Lee <liguozhu@hisilicon.com>
CC: Palmer Dabbelt <palmerdabbelt@google.com>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d2f38a3c6507b2520101f9a3807ed98f1bdc545a
commit: fb31f0a499332a053477ed57312b214e42476e6d riscv: fix the global name pfn_base confliction error
date: 3 months ago
:::::: branch date: 6 hours ago
:::::: commit date: 3 months ago
config: riscv-randconfig-m031-20211015 (attached as .config)
compiler: riscv32-linux-gcc (GCC) 11.2.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:172 efi_capsule_update_locked() warn: should '((((sg_pages[0]) - mem_map) + riscv_pfn_base)) << (12)' be a 64 bit type?
drivers/firmware/efi/capsule.c:267 efi_capsule_update() warn: should '((((sg_pages[i + 1]) - mem_map) + riscv_pfn_base)) << (12)' be a 64 bit type?
vim +172 drivers/firmware/efi/capsule.c
f0133f3c5b8bb3 Matt Fleming 2016-04-25 126
f0133f3c5b8bb3 Matt Fleming 2016-04-25 127 /**
f0133f3c5b8bb3 Matt Fleming 2016-04-25 128 * efi_capsule_update_locked - pass a single capsule to the firmware
f0133f3c5b8bb3 Matt Fleming 2016-04-25 129 * @capsule: capsule to send to the firmware
f0133f3c5b8bb3 Matt Fleming 2016-04-25 130 * @sg_pages: array of scatter gather (block descriptor) pages
f0133f3c5b8bb3 Matt Fleming 2016-04-25 131 * @reset: the reset type required for @capsule
f0133f3c5b8bb3 Matt Fleming 2016-04-25 132 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 133 * Since this function must be called under capsule_mutex check
f0133f3c5b8bb3 Matt Fleming 2016-04-25 134 * whether efi_reset_type will conflict with @reset, and atomically
f0133f3c5b8bb3 Matt Fleming 2016-04-25 135 * set it and capsule_pending if a capsule was successfully sent to
f0133f3c5b8bb3 Matt Fleming 2016-04-25 136 * the firmware.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 137 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 138 * We also check to see if the system is about to restart, and if so,
f0133f3c5b8bb3 Matt Fleming 2016-04-25 139 * abort. This avoids races between efi_capsule_update() and
f0133f3c5b8bb3 Matt Fleming 2016-04-25 140 * efi_capsule_pending().
f0133f3c5b8bb3 Matt Fleming 2016-04-25 141 */
f0133f3c5b8bb3 Matt Fleming 2016-04-25 142 static int
f0133f3c5b8bb3 Matt Fleming 2016-04-25 143 efi_capsule_update_locked(efi_capsule_header_t *capsule,
f0133f3c5b8bb3 Matt Fleming 2016-04-25 144 struct page **sg_pages, int reset)
f0133f3c5b8bb3 Matt Fleming 2016-04-25 145 {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 146 efi_physical_addr_t sglist_phys;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 147 efi_status_t status;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 148
f0133f3c5b8bb3 Matt Fleming 2016-04-25 149 lockdep_assert_held(&capsule_mutex);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 150
f0133f3c5b8bb3 Matt Fleming 2016-04-25 151 /*
f0133f3c5b8bb3 Matt Fleming 2016-04-25 152 * If someone has already registered a capsule that requires a
f0133f3c5b8bb3 Matt Fleming 2016-04-25 153 * different reset type, we're out of luck and must abort.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 154 */
f0133f3c5b8bb3 Matt Fleming 2016-04-25 155 if (efi_reset_type >= 0 && efi_reset_type != reset) {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 156 pr_err("Conflicting capsule reset type %d (%d).\n",
f0133f3c5b8bb3 Matt Fleming 2016-04-25 157 reset, efi_reset_type);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 158 return -EINVAL;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 159 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 160
f0133f3c5b8bb3 Matt Fleming 2016-04-25 161 /*
f0133f3c5b8bb3 Matt Fleming 2016-04-25 162 * If the system is getting ready to restart it may have
f0133f3c5b8bb3 Matt Fleming 2016-04-25 163 * called efi_capsule_pending() to make decisions (such as
f0133f3c5b8bb3 Matt Fleming 2016-04-25 164 * whether to force an EFI reboot), and we're racing against
f0133f3c5b8bb3 Matt Fleming 2016-04-25 165 * that call. Abort in that case.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 166 */
62075e581802ea Matt Fleming 2016-05-06 167 if (unlikely(stop_capsules)) {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 168 pr_warn("Capsule update raced with reboot, aborting.\n");
f0133f3c5b8bb3 Matt Fleming 2016-04-25 169 return -EINVAL;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 170 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 171
f0133f3c5b8bb3 Matt Fleming 2016-04-25 @172 sglist_phys = page_to_phys(sg_pages[0]);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 173
f0133f3c5b8bb3 Matt Fleming 2016-04-25 174 status = efi.update_capsule(&capsule, 1, sglist_phys);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 175 if (status == EFI_SUCCESS) {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 176 capsule_pending = true;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 177 efi_reset_type = reset;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 178 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 179
f0133f3c5b8bb3 Matt Fleming 2016-04-25 180 return efi_status_to_err(status);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 181 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 182
f0133f3c5b8bb3 Matt Fleming 2016-04-25 183 /**
f0133f3c5b8bb3 Matt Fleming 2016-04-25 184 * efi_capsule_update - send a capsule to the firmware
f0133f3c5b8bb3 Matt Fleming 2016-04-25 185 * @capsule: capsule to send to firmware
f0133f3c5b8bb3 Matt Fleming 2016-04-25 186 * @pages: an array of capsule data pages
f0133f3c5b8bb3 Matt Fleming 2016-04-25 187 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 188 * Build a scatter gather list with EFI capsule block descriptors to
f0133f3c5b8bb3 Matt Fleming 2016-04-25 189 * map the capsule described by @capsule with its data in @pages and
f0133f3c5b8bb3 Matt Fleming 2016-04-25 190 * send it to the firmware via the UpdateCapsule() runtime service.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 191 *
6862e6ad95e984 Austin Christ 2016-08-11 192 * @capsule must be a virtual mapping of the complete capsule update in the
6862e6ad95e984 Austin Christ 2016-08-11 193 * kernel address space, as the capsule can be consumed immediately.
6862e6ad95e984 Austin Christ 2016-08-11 194 * A capsule_header_t that describes the entire contents of the capsule
f0133f3c5b8bb3 Matt Fleming 2016-04-25 195 * must be at the start of the first data page.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 196 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 197 * Even though this function will validate that the firmware supports
f0133f3c5b8bb3 Matt Fleming 2016-04-25 198 * the capsule guid, users will likely want to check that
f0133f3c5b8bb3 Matt Fleming 2016-04-25 199 * efi_capsule_supported() returns true before calling this function
f0133f3c5b8bb3 Matt Fleming 2016-04-25 200 * because it makes it easier to print helpful error messages.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 201 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 202 * If the capsule is successfully submitted to the firmware, any
f0133f3c5b8bb3 Matt Fleming 2016-04-25 203 * subsequent calls to efi_capsule_pending() will return true. @pages
f0133f3c5b8bb3 Matt Fleming 2016-04-25 204 * must not be released or modified if this function returns
f0133f3c5b8bb3 Matt Fleming 2016-04-25 205 * successfully.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 206 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 207 * Callers must be prepared for this function to fail, which can
f0133f3c5b8bb3 Matt Fleming 2016-04-25 208 * happen if we raced with system reboot or if there is already a
f0133f3c5b8bb3 Matt Fleming 2016-04-25 209 * pending capsule that has a reset type that conflicts with the one
f0133f3c5b8bb3 Matt Fleming 2016-04-25 210 * required by @capsule. Do NOT use efi_capsule_pending() to detect
f0133f3c5b8bb3 Matt Fleming 2016-04-25 211 * this conflict since that would be racy. Instead, submit the capsule
f0133f3c5b8bb3 Matt Fleming 2016-04-25 212 * to efi_capsule_update() and check the return value.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 213 *
f0133f3c5b8bb3 Matt Fleming 2016-04-25 214 * Return 0 on success, a converted EFI status code on failure.
f0133f3c5b8bb3 Matt Fleming 2016-04-25 215 */
2a457fb31df62c Ard Biesheuvel 2017-06-02 216 int efi_capsule_update(efi_capsule_header_t *capsule, phys_addr_t *pages)
f0133f3c5b8bb3 Matt Fleming 2016-04-25 217 {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 218 u32 imagesize = capsule->imagesize;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 219 efi_guid_t guid = capsule->guid;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 220 unsigned int count, sg_count;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 221 u32 flags = capsule->flags;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 222 struct page **sg_pages;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 223 int rv, reset_type;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 224 int i, j;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 225
f0133f3c5b8bb3 Matt Fleming 2016-04-25 226 rv = efi_capsule_supported(guid, flags, imagesize, &reset_type);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 227 if (rv)
f0133f3c5b8bb3 Matt Fleming 2016-04-25 228 return rv;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 229
f0133f3c5b8bb3 Matt Fleming 2016-04-25 230 count = DIV_ROUND_UP(imagesize, PAGE_SIZE);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 231 sg_count = sg_pages_num(count);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 232
6396bb221514d2 Kees Cook 2018-06-12 233 sg_pages = kcalloc(sg_count, sizeof(*sg_pages), GFP_KERNEL);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 234 if (!sg_pages)
f0133f3c5b8bb3 Matt Fleming 2016-04-25 235 return -ENOMEM;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 236
f0133f3c5b8bb3 Matt Fleming 2016-04-25 237 for (i = 0; i < sg_count; i++) {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 238 sg_pages[i] = alloc_page(GFP_KERNEL);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 239 if (!sg_pages[i]) {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 240 rv = -ENOMEM;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 241 goto out;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 242 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 243 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 244
f0133f3c5b8bb3 Matt Fleming 2016-04-25 245 for (i = 0; i < sg_count; i++) {
f0133f3c5b8bb3 Matt Fleming 2016-04-25 246 efi_capsule_block_desc_t *sglist;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 247
91c1c092f27da4 Ard Biesheuvel 2020-12-07 248 sglist = kmap_atomic(sg_pages[i]);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 249
f0133f3c5b8bb3 Matt Fleming 2016-04-25 250 for (j = 0; j < SGLIST_PER_PAGE && count > 0; j++) {
2a457fb31df62c Ard Biesheuvel 2017-06-02 251 u64 sz = min_t(u64, imagesize,
2a457fb31df62c Ard Biesheuvel 2017-06-02 252 PAGE_SIZE - (u64)*pages % PAGE_SIZE);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 253
f0133f3c5b8bb3 Matt Fleming 2016-04-25 254 sglist[j].length = sz;
2a457fb31df62c Ard Biesheuvel 2017-06-02 255 sglist[j].data = *pages++;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 256
f0133f3c5b8bb3 Matt Fleming 2016-04-25 257 imagesize -= sz;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 258 count--;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 259 }
f0133f3c5b8bb3 Matt Fleming 2016-04-25 260
f0133f3c5b8bb3 Matt Fleming 2016-04-25 261 /* Continuation pointer */
f0133f3c5b8bb3 Matt Fleming 2016-04-25 262 sglist[j].length = 0;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 263
f0133f3c5b8bb3 Matt Fleming 2016-04-25 264 if (i + 1 == sg_count)
f0133f3c5b8bb3 Matt Fleming 2016-04-25 265 sglist[j].data = 0;
f0133f3c5b8bb3 Matt Fleming 2016-04-25 266 else
f0133f3c5b8bb3 Matt Fleming 2016-04-25 @267 sglist[j].data = page_to_phys(sg_pages[i + 1]);
f0133f3c5b8bb3 Matt Fleming 2016-04-25 268
:::::: The code at line 172 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: 30724 bytes --]
next reply other threads:[~2021-11-09 2:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-09 2:27 kernel test robot [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-12-14 3:05 drivers/firmware/efi/capsule.c:172 efi_capsule_update_locked() warn: should '((((sg_pages[0]) - mem_map) + riscv_pfn_base)) << (12)' be a 64 bit type? kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202111091042.bC3Wyffr-lkp@intel.com \
--to=lkp@intel.com \
--cc=kbuild@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.