diff mbox series

[v4] misc: pci_endpoint_test: Fix overflow of bar_size

Message ID 20241231065500.168799-1-18255117159@163.com (mailing list archive)
State Superseded
Delegated to: Krzysztof WilczyƄski
Headers show
Series [v4] misc: pci_endpoint_test: Fix overflow of bar_size | expand

Commit Message

Hans Zhang Dec. 31, 2024, 6:55 a.m. UTC
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.

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 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

kernel test robot Jan. 1, 2025, 11:50 a.m. UTC | #1
Hi Hans,

kernel test robot noticed the following build errors:

[auto build test ERROR on pci/next]
[also build test ERROR on pci/for-linus mani-mhi/mhi-next soc/for-next linus/master v6.13-rc5 next-20241220]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Hans-Zhang/misc-pci_endpoint_test-Fix-overflow-of-bar_size/20241231-145733
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/20241231065500.168799-1-18255117159%40163.com
patch subject: [v4] misc: pci_endpoint_test: Fix overflow of bar_size
config: i386-randconfig-003-20250101 (https://download.01.org/0day-ci/archive/20250101/202501011917.ugP1ywJV-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250101/202501011917.ugP1ywJV-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/202501011917.ugP1ywJV-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: drivers/misc/pci_endpoint_test.o: in function `pci_endpoint_test_bar':
>> drivers/misc/pci_endpoint_test.c:315: undefined reference to `__udivmoddi4'


vim +315 drivers/misc/pci_endpoint_test.c

2a35703a6a00e8 Niklas Cassel          2024-03-22  282  
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  283  static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  284  				  enum pci_barno barno)
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  285  {
2a35703a6a00e8 Niklas Cassel          2024-03-22  286  	void *write_buf __free(kfree) = NULL;
2a35703a6a00e8 Niklas Cassel          2024-03-22  287  	void *read_buf __free(kfree) = NULL;
cda370ec6d1f7b Kishon Vijay Abraham I 2017-08-18  288  	struct pci_dev *pdev = test->pdev;
bb17ee74a3494e Hans Zhang             2024-12-31  289  	int j, buf_size, iters, remain;
bb17ee74a3494e Hans Zhang             2024-12-31  290  	resource_size_t bar_size;
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  291  
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  292  	if (!test->bar[barno])
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  293  		return false;
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  294  
2a35703a6a00e8 Niklas Cassel          2024-03-22  295  	bar_size = pci_resource_len(pdev, barno);
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  296  
834b9051992580 Kishon Vijay Abraham I 2017-08-18  297  	if (barno == test->test_reg_bar)
2a35703a6a00e8 Niklas Cassel          2024-03-22  298  		bar_size = 0x4;
834b9051992580 Kishon Vijay Abraham I 2017-08-18  299  
2a35703a6a00e8 Niklas Cassel          2024-03-22  300  	/*
2a35703a6a00e8 Niklas Cassel          2024-03-22  301  	 * Allocate a buffer of max size 1MB, and reuse that buffer while
2a35703a6a00e8 Niklas Cassel          2024-03-22  302  	 * iterating over the whole BAR size (which might be much larger).
2a35703a6a00e8 Niklas Cassel          2024-03-22  303  	 */
2a35703a6a00e8 Niklas Cassel          2024-03-22  304  	buf_size = min(SZ_1M, bar_size);
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  305  
2a35703a6a00e8 Niklas Cassel          2024-03-22  306  	write_buf = kmalloc(buf_size, GFP_KERNEL);
2a35703a6a00e8 Niklas Cassel          2024-03-22  307  	if (!write_buf)
2a35703a6a00e8 Niklas Cassel          2024-03-22  308  		return false;
2a35703a6a00e8 Niklas Cassel          2024-03-22  309  
2a35703a6a00e8 Niklas Cassel          2024-03-22  310  	read_buf = kmalloc(buf_size, GFP_KERNEL);
2a35703a6a00e8 Niklas Cassel          2024-03-22  311  	if (!read_buf)
2a35703a6a00e8 Niklas Cassel          2024-03-22  312  		return false;
2a35703a6a00e8 Niklas Cassel          2024-03-22  313  
2a35703a6a00e8 Niklas Cassel          2024-03-22  314  	iters = bar_size / buf_size;
2a35703a6a00e8 Niklas Cassel          2024-03-22 @315  	for (j = 0; j < iters; j++)
2a35703a6a00e8 Niklas Cassel          2024-03-22  316  		if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * j,
2a35703a6a00e8 Niklas Cassel          2024-03-22  317  						 write_buf, read_buf, buf_size))
2a35703a6a00e8 Niklas Cassel          2024-03-22  318  			return false;
2a35703a6a00e8 Niklas Cassel          2024-03-22  319  
2a35703a6a00e8 Niklas Cassel          2024-03-22  320  	remain = bar_size % buf_size;
2a35703a6a00e8 Niklas Cassel          2024-03-22  321  	if (remain)
2a35703a6a00e8 Niklas Cassel          2024-03-22  322  		if (pci_endpoint_test_bar_memcmp(test, barno, buf_size * iters,
2a35703a6a00e8 Niklas Cassel          2024-03-22  323  						 write_buf, read_buf, remain))
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  324  			return false;
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  325  
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  326  	return true;
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  327  }
2c156ac71c6b25 Kishon Vijay Abraham I 2017-03-27  328
diff mbox series

Patch

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 3aaaf47fa4ee..414c4e55fb0a 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;