drivers/misc/pci_endpoint_test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
With 8GB BAR2, running pcitest -b 2 fails with "TEST FAILED".
The return value of the `pci_resource_len` interface is not an integer.
Using `pcitest` with an 8GB BAR2, the bar_size of integer type will
overflow.
Change the data type of bar_size from integer to resource_size_t, to fix
the above issue.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202501021000.7Cwcopot-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202501011917.ugP1ywJV-lkp@intel.com/
Signed-off-by: Hans Zhang <18255117159@163.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
Changes since v4-v6:
https://lore.kernel.org/linux-pci/20241231065500.168799-1-18255117159@163.com/
- Fix undefined reference to `__udivmoddi4`
Changes since v3:
https://lore.kernel.org/linux-pci/20241221141009.27317-1-18255117159@163.com/
- The patch subject were modified.
Changes since v2:
https://lore.kernel.org/linux-pci/20241220075253.16791-1-18255117159@163.com/
- Fix "changes" part goes below the --- line
- The patch commit message were modified.
Changes since v1:
https://lore.kernel.org/linux-pci/20241217121220.19676-1-18255117159@163.com/
- The patch subject and commit message were modified.
---
drivers/misc/pci_endpoint_test.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 3aaaf47fa4ee..df34b742f2de 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -280,10 +280,11 @@ static int pci_endpoint_test_bar_memcmp(struct pci_endpoint_test *test,
static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
enum pci_barno barno)
{
- int j, bar_size, buf_size, iters, remain;
void *write_buf __free(kfree) = NULL;
void *read_buf __free(kfree) = NULL;
struct pci_dev *pdev = test->pdev;
+ int j, buf_size, iters, remain;
+ resource_size_t bar_size;
if (!test->bar[barno])
return false;
@@ -307,13 +308,13 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
if (!read_buf)
return false;
- iters = bar_size / buf_size;
+ remain = do_div(bar_size, buf_size);
+ iters = bar_size;
for (j = 0; j < iters; j++)
if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * j,
write_buf, read_buf, buf_size))
return false;
- remain = bar_size % buf_size;
if (remain)
if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * iters,
write_buf, read_buf, remain))
base-commit: ccb98ccef0e543c2bd4ef1a72270461957f3d8d0
--
2.25.1
Hi Hans,
kernel test robot noticed the following build errors:
[auto build test ERROR on ccb98ccef0e543c2bd4ef1a72270461957f3d8d0]
url: https://github.com/intel-lab-lkp/linux/commits/Hans-Zhang/misc-pci_endpoint_test-Fix-overflow-of-bar_size/20250102-200548
base: ccb98ccef0e543c2bd4ef1a72270461957f3d8d0
patch link: https://lore.kernel.org/r/20250102120222.1403906-1-18255117159%40163.com
patch subject: [v6] misc: pci_endpoint_test: Fix overflow of bar_size
config: arm-defconfig (https://download.01.org/0day-ci/archive/20250103/202501030414.p0DE9xNK-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 096551537b2a747a3387726ca618ceeb3950e9bc)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250103/202501030414.p0DE9xNK-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/202501030414.p0DE9xNK-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
>> drivers/misc/pci_endpoint_test.c:311:11: warning: comparison of distinct pointer types ('typeof ((bar_size)) *' (aka 'unsigned int *') and 'uint64_t *' (aka 'unsigned long long *')) [-Wcompare-distinct-pointer-types]
311 | remain = do_div(bar_size, buf_size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/div64.h:183:28: note: expanded from macro 'do_div'
183 | (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
| ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
>> drivers/misc/pci_endpoint_test.c:311:11: error: incompatible pointer types passing 'resource_size_t *' (aka 'unsigned int *') to parameter of type 'uint64_t *' (aka 'unsigned long long *') [-Werror,-Wincompatible-pointer-types]
311 | remain = do_div(bar_size, buf_size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/div64.h:199:22: note: expanded from macro 'do_div'
199 | __rem = __div64_32(&(n), __base); \
| ^~~~
arch/arm/include/asm/div64.h:24:45: note: passing argument to parameter 'n' here
24 | static inline uint32_t __div64_32(uint64_t *n, uint32_t base)
| ^
>> drivers/misc/pci_endpoint_test.c:311:11: warning: shift count >= width of type [-Wshift-count-overflow]
311 | remain = do_div(bar_size, buf_size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/div64.h:195:25: note: expanded from macro 'do_div'
195 | } else if (likely(((n) >> 32) == 0)) { \
| ^ ~~
include/linux/compiler.h:76:40: note: expanded from macro 'likely'
76 | # define likely(x) __builtin_expect(!!(x), 1)
| ^
2 warnings and 1 error generated.
vim +311 drivers/misc/pci_endpoint_test.c
279
280 static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
281 enum pci_barno barno)
282 {
283 void *write_buf __free(kfree) = NULL;
284 void *read_buf __free(kfree) = NULL;
285 struct pci_dev *pdev = test->pdev;
286 int j, buf_size, iters, remain;
287 resource_size_t bar_size;
288
289 if (!test->bar[barno])
290 return false;
291
292 bar_size = pci_resource_len(pdev, barno);
293
294 if (barno == test->test_reg_bar)
295 bar_size = 0x4;
296
297 /*
298 * Allocate a buffer of max size 1MB, and reuse that buffer while
299 * iterating over the whole BAR size (which might be much larger).
300 */
301 buf_size = min(SZ_1M, bar_size);
302
303 write_buf = kmalloc(buf_size, GFP_KERNEL);
304 if (!write_buf)
305 return false;
306
307 read_buf = kmalloc(buf_size, GFP_KERNEL);
308 if (!read_buf)
309 return false;
310
> 311 remain = do_div(bar_size, buf_size);
312 iters = bar_size;
313 for (j = 0; j < iters; j++)
314 if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * j,
315 write_buf, read_buf, buf_size))
316 return false;
317
318 if (remain)
319 if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * iters,
320 write_buf, read_buf, remain))
321 return false;
322
323 return true;
324 }
325
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Hans,
kernel test robot noticed the following build errors:
[auto build test ERROR on ccb98ccef0e543c2bd4ef1a72270461957f3d8d0]
url: https://github.com/intel-lab-lkp/linux/commits/Hans-Zhang/misc-pci_endpoint_test-Fix-overflow-of-bar_size/20250102-200548
base: ccb98ccef0e543c2bd4ef1a72270461957f3d8d0
patch link: https://lore.kernel.org/r/20250102120222.1403906-1-18255117159%40163.com
patch subject: [v6] misc: pci_endpoint_test: Fix overflow of bar_size
config: powerpc-randconfig-003-20250102 (https://download.01.org/0day-ci/archive/20250103/202501030210.iaAEQUA6-lkp@intel.com/config)
compiler: powerpc-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250103/202501030210.iaAEQUA6-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/202501030210.iaAEQUA6-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from ./arch/powerpc/include/generated/asm/div64.h:1,
from include/linux/math.h:6,
from include/linux/delay.h:12,
from drivers/misc/pci_endpoint_test.c:11:
drivers/misc/pci_endpoint_test.c: In function 'pci_endpoint_test_bar':
include/asm-generic/div64.h:183:35: warning: comparison of distinct pointer types lacks a cast [-Wcompare-distinct-pointer-types]
183 | (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
| ^~
drivers/misc/pci_endpoint_test.c:311:18: note: in expansion of macro 'do_div'
311 | remain = do_div(bar_size, buf_size);
| ^~~~~~
In file included from include/linux/cleanup.h:5,
from drivers/misc/pci_endpoint_test.c:10:
include/asm-generic/div64.h:195:32: warning: right shift count >= width of type [-Wshift-count-overflow]
195 | } else if (likely(((n) >> 32) == 0)) { \
| ^~
include/linux/compiler.h:76:45: note: in definition of macro 'likely'
76 | # define likely(x) __builtin_expect(!!(x), 1)
| ^
drivers/misc/pci_endpoint_test.c:311:18: note: in expansion of macro 'do_div'
311 | remain = do_div(bar_size, buf_size);
| ^~~~~~
>> include/asm-generic/div64.h:199:36: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Wincompatible-pointer-types]
199 | __rem = __div64_32(&(n), __base); \
| ^~~~
| |
| resource_size_t * {aka unsigned int *}
drivers/misc/pci_endpoint_test.c:311:18: note: in expansion of macro 'do_div'
311 | remain = do_div(bar_size, buf_size);
| ^~~~~~
include/asm-generic/div64.h:174:38: note: expected 'uint64_t *' {aka 'long long unsigned int *'} but argument is of type 'resource_size_t *' {aka 'unsigned int *'}
174 | extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
| ~~~~~~~~~~^~~~~~~~
vim +/__div64_32 +199 include/asm-generic/div64.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 176
^1da177e4c3f41 Linus Torvalds 2005-04-16 177 /* The unnecessary pointer compare is there
^1da177e4c3f41 Linus Torvalds 2005-04-16 178 * to check for type safety (n must be 64bit)
^1da177e4c3f41 Linus Torvalds 2005-04-16 179 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 180 # define do_div(n,base) ({ \
^1da177e4c3f41 Linus Torvalds 2005-04-16 181 uint32_t __base = (base); \
^1da177e4c3f41 Linus Torvalds 2005-04-16 182 uint32_t __rem; \
^1da177e4c3f41 Linus Torvalds 2005-04-16 183 (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
911918aa7ef6f8 Nicolas Pitre 2015-11-02 184 if (__builtin_constant_p(__base) && \
911918aa7ef6f8 Nicolas Pitre 2015-11-02 185 is_power_of_2(__base)) { \
911918aa7ef6f8 Nicolas Pitre 2015-11-02 186 __rem = (n) & (__base - 1); \
911918aa7ef6f8 Nicolas Pitre 2015-11-02 187 (n) >>= ilog2(__base); \
c747ce4706190e Geert Uytterhoeven 2021-08-11 188 } else if (__builtin_constant_p(__base) && \
461a5e51060c93 Nicolas Pitre 2015-10-30 189 __base != 0) { \
461a5e51060c93 Nicolas Pitre 2015-10-30 190 uint32_t __res_lo, __n_lo = (n); \
461a5e51060c93 Nicolas Pitre 2015-10-30 191 (n) = __div64_const32(n, __base); \
461a5e51060c93 Nicolas Pitre 2015-10-30 192 /* the remainder can be computed with 32-bit regs */ \
461a5e51060c93 Nicolas Pitre 2015-10-30 193 __res_lo = (n); \
461a5e51060c93 Nicolas Pitre 2015-10-30 194 __rem = __n_lo - __res_lo * __base; \
911918aa7ef6f8 Nicolas Pitre 2015-11-02 195 } else if (likely(((n) >> 32) == 0)) { \
^1da177e4c3f41 Linus Torvalds 2005-04-16 196 __rem = (uint32_t)(n) % __base; \
^1da177e4c3f41 Linus Torvalds 2005-04-16 197 (n) = (uint32_t)(n) / __base; \
c747ce4706190e Geert Uytterhoeven 2021-08-11 198 } else { \
^1da177e4c3f41 Linus Torvalds 2005-04-16 @199 __rem = __div64_32(&(n), __base); \
c747ce4706190e Geert Uytterhoeven 2021-08-11 200 } \
^1da177e4c3f41 Linus Torvalds 2005-04-16 201 __rem; \
^1da177e4c3f41 Linus Torvalds 2005-04-16 202 })
^1da177e4c3f41 Linus Torvalds 2005-04-16 203
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
On Thu, Jan 02, 2025 at 08:02:22PM +0800, Hans Zhang wrote:
> With 8GB BAR2, running pcitest -b 2 fails with "TEST FAILED".
>
> The return value of the `pci_resource_len` interface is not an integer.
> Using `pcitest` with an 8GB BAR2, the bar_size of integer type will
> overflow.
> Change the data type of bar_size from integer to resource_size_t, to fix
> the above issue.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202501021000.7Cwcopot-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202501011917.ugP1ywJV-lkp@intel.com/
Note that you do not need "Reported-by" and "Closes" tags in this case,
see the earlier text from the kernel test bot:
"""
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/202501011917.ugP1ywJV-lkp@intel.com/
"""
In your case, you are fixing it in a new version of the same patch/commit,
so no need to add the tags.
> Signed-off-by: Hans Zhang <18255117159@163.com>
> Reviewed-by: Niklas Cassel <cassel@kernel.org>
> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>
Remove the stray new line above.
> ---
> Changes since v4-v6:
> https://lore.kernel.org/linux-pci/20241231065500.168799-1-18255117159@163.com/
>
> - Fix undefined reference to `__udivmoddi4`
>
> Changes since v3:
> https://lore.kernel.org/linux-pci/20241221141009.27317-1-18255117159@163.com/
>
> - The patch subject were modified.
>
> Changes since v2:
> https://lore.kernel.org/linux-pci/20241220075253.16791-1-18255117159@163.com/
>
> - Fix "changes" part goes below the --- line
> - The patch commit message were modified.
>
> Changes since v1:
> https://lore.kernel.org/linux-pci/20241217121220.19676-1-18255117159@163.com/
>
> - The patch subject and commit message were modified.
> ---
> drivers/misc/pci_endpoint_test.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> index 3aaaf47fa4ee..df34b742f2de 100644
> --- a/drivers/misc/pci_endpoint_test.c
> +++ b/drivers/misc/pci_endpoint_test.c
> @@ -280,10 +280,11 @@ static int pci_endpoint_test_bar_memcmp(struct pci_endpoint_test *test,
> static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
> enum pci_barno barno)
> {
> - int j, bar_size, buf_size, iters, remain;
> void *write_buf __free(kfree) = NULL;
> void *read_buf __free(kfree) = NULL;
> struct pci_dev *pdev = test->pdev;
> + int j, buf_size, iters, remain;
> + resource_size_t bar_size;
>
> if (!test->bar[barno])
> return false;
> @@ -307,13 +308,13 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
> if (!read_buf)
> return false;
>
> - iters = bar_size / buf_size;
> + remain = do_div(bar_size, buf_size);
> + iters = bar_size;
> for (j = 0; j < iters; j++)
> if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * j,
> write_buf, read_buf, buf_size))
> return false;
>
> - remain = bar_size % buf_size;
> if (remain)
> if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * iters,
> write_buf, read_buf, remain))
>
> base-commit: ccb98ccef0e543c2bd4ef1a72270461957f3d8d0
> --
> 2.25.1
>
Changes themselves look good to me.
Kind regards,
Niklas
© 2016 - 2026 Red Hat, Inc.