2020-07-17 09:38:41

by Shile Zhang

[permalink] [raw]
Subject: [PATCH] virtio_ring: use alloc_pages_node for NUMA-aware allocation

Use alloc_pages_node() allocate memory for vring queue with proper
NUMA affinity.

Suggested-by: Jiang Liu <[email protected]>
Signed-off-by: Shile Zhang <[email protected]>
---
drivers/virtio/virtio_ring.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 58b96baa8d48..ded82880281a 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -276,9 +276,11 @@ static void *vring_alloc_queue(struct virtio_device *vdev, size_t size,
return dma_alloc_coherent(vdev->dev.parent, size,
dma_handle, flag);
} else {
- void *queue = alloc_pages_exact(PAGE_ALIGN(size), flag);
-
- if (queue) {
+ void *queue = NULL;
+ struct page *page = alloc_pages_node(dev_to_node(&vdev->dev.parent),
+ flag, get_order(size));
+ if (page) {
+ queue = page_address(page);
phys_addr_t phys_addr = virt_to_phys(queue);
*dma_handle = (dma_addr_t)phys_addr;

@@ -308,7 +310,7 @@ static void vring_free_queue(struct virtio_device *vdev, size_t size,
if (vring_use_dma_api(vdev))
dma_free_coherent(vdev->dev.parent, size, queue, dma_handle);
else
- free_pages_exact(queue, PAGE_ALIGN(size));
+ free_pages((unsigned long)queue, get_order(size));
}

/*
--
2.24.0.rc2


2020-07-17 14:23:03

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] virtio_ring: use alloc_pages_node for NUMA-aware allocation

Hi Shile,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc5 next-20200716]
[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]

url: https://github.com/0day-ci/linux/commits/Shile-Zhang/virtio_ring-use-alloc_pages_node-for-NUMA-aware-allocation/20200717-173734
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8882572675c1bb1cc544f4e229a11661f1fc52e4
config: s390-randconfig-r015-20200717 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ed6b578040a85977026c93bf4188f996148f3218)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All error/warnings (new ones prefixed by >>):

#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:19:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
^
In file included from drivers/virtio/virtio_ring.c:6:
In file included from include/linux/virtio.h:7:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:20:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
^
In file included from drivers/virtio/virtio_ring.c:6:
In file included from include/linux/virtio.h:7:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:21:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
^
In file included from drivers/virtio/virtio_ring.c:6:
In file included from include/linux/virtio.h:7:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:22:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
^
In file included from drivers/virtio/virtio_ring.c:6:
In file included from include/linux/virtio.h:7:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:45: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:120:12: note: expanded from macro '__swab32'
__fswab32(x))
^
In file included from drivers/virtio/virtio_ring.c:6:
In file included from include/linux/virtio.h:7:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:46: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew(cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:46: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> drivers/virtio/virtio_ring.c:280:52: error: incompatible pointer types passing 'struct device **' to parameter of type 'struct device *'; remove & [-Werror,-Wincompatible-pointer-types]
struct page *page = alloc_pages_node(dev_to_node(&vdev->dev.parent),
^~~~~~~~~~~~~~~~~
include/linux/device.h:668:46: note: passing argument to parameter 'dev' here
static inline int dev_to_node(struct device *dev)
^
>> drivers/virtio/virtio_ring.c:284:16: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
phys_addr_t phys_addr = virt_to_phys(queue);
^
21 warnings and 1 error generated.

vim +280 drivers/virtio/virtio_ring.c

271
272 static void *vring_alloc_queue(struct virtio_device *vdev, size_t size,
273 dma_addr_t *dma_handle, gfp_t flag)
274 {
275 if (vring_use_dma_api(vdev)) {
276 return dma_alloc_coherent(vdev->dev.parent, size,
277 dma_handle, flag);
278 } else {
279 void *queue = NULL;
> 280 struct page *page = alloc_pages_node(dev_to_node(&vdev->dev.parent),
281 flag, get_order(size));
282 if (page) {
283 queue = page_address(page);
> 284 phys_addr_t phys_addr = virt_to_phys(queue);
285 *dma_handle = (dma_addr_t)phys_addr;
286
287 /*
288 * Sanity check: make sure we dind't truncate
289 * the address. The only arches I can find that
290 * have 64-bit phys_addr_t but 32-bit dma_addr_t
291 * are certain non-highmem MIPS and x86
292 * configurations, but these configurations
293 * should never allocate physical pages above 32
294 * bits, so this is fine. Just in case, throw a
295 * warning and abort if we end up with an
296 * unrepresentable address.
297 */
298 if (WARN_ON_ONCE(*dma_handle != phys_addr)) {
299 free_pages_exact(queue, PAGE_ALIGN(size));
300 return NULL;
301 }
302 }
303 return queue;
304 }
305 }
306

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (10.34 kB)
.config.gz (24.23 kB)
Download all attachments

2020-07-17 15:04:25

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] virtio_ring: use alloc_pages_node for NUMA-aware allocation

Hi Shile,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc5 next-20200716]
[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]

url: https://github.com/0day-ci/linux/commits/Shile-Zhang/virtio_ring-use-alloc_pages_node-for-NUMA-aware-allocation/20200717-173734
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8882572675c1bb1cc544f4e229a11661f1fc52e4
config: alpha-allyesconfig (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All error/warnings (new ones prefixed by >>):

drivers/virtio/virtio_ring.c: In function 'vring_alloc_queue':
>> drivers/virtio/virtio_ring.c:280:52: error: passing argument 1 of 'dev_to_node' from incompatible pointer type [-Werror=incompatible-pointer-types]
280 | struct page *page = alloc_pages_node(dev_to_node(&vdev->dev.parent),
| ^~~~~~~~~~~~~~~~~
| |
| struct device **
In file included from include/linux/virtio.h:9,
from drivers/virtio/virtio_ring.c:6:
include/linux/device.h:668:46: note: expected 'struct device *' but argument is of type 'struct device **'
668 | static inline int dev_to_node(struct device *dev)
| ~~~~~~~~~~~~~~~^~~
>> drivers/virtio/virtio_ring.c:284:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
284 | phys_addr_t phys_addr = virt_to_phys(queue);
| ^~~~~~~~~~~
cc1: some warnings being treated as errors

vim +/dev_to_node +280 drivers/virtio/virtio_ring.c

271
272 static void *vring_alloc_queue(struct virtio_device *vdev, size_t size,
273 dma_addr_t *dma_handle, gfp_t flag)
274 {
275 if (vring_use_dma_api(vdev)) {
276 return dma_alloc_coherent(vdev->dev.parent, size,
277 dma_handle, flag);
278 } else {
279 void *queue = NULL;
> 280 struct page *page = alloc_pages_node(dev_to_node(&vdev->dev.parent),
281 flag, get_order(size));
282 if (page) {
283 queue = page_address(page);
> 284 phys_addr_t phys_addr = virt_to_phys(queue);
285 *dma_handle = (dma_addr_t)phys_addr;
286
287 /*
288 * Sanity check: make sure we dind't truncate
289 * the address. The only arches I can find that
290 * have 64-bit phys_addr_t but 32-bit dma_addr_t
291 * are certain non-highmem MIPS and x86
292 * configurations, but these configurations
293 * should never allocate physical pages above 32
294 * bits, so this is fine. Just in case, throw a
295 * warning and abort if we end up with an
296 * unrepresentable address.
297 */
298 if (WARN_ON_ONCE(*dma_handle != phys_addr)) {
299 free_pages_exact(queue, PAGE_ALIGN(size));
300 return NULL;
301 }
302 }
303 return queue;
304 }
305 }
306

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (3.76 kB)
.config.gz (63.50 kB)
Download all attachments