* [PATCH 0/4] Fix some bugs of the vop driver and mpssd user space tool @ 2020-09-25 7:18 Sherry Sun 2020-09-25 7:18 ` [PATCH 1/4] samples: mpssd: fix the build errors when enable DEBUG in mpssd.c Sherry Sun ` (3 more replies) 0 siblings, 4 replies; 9+ messages in thread From: Sherry Sun @ 2020-09-25 7:18 UTC (permalink / raw) To: sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: linux-kernel, linux-imx This patchset fix some bugs about the vop driver and Intel MIC user space tool -- mpssd. Sherry Sun (4): samples: mpssd: fix the build errors when enable DEBUG in mpssd.c misc: vop: build VOP based on CONFIG_VOP misc: vop: add round_up(x,4) for vring_size to avoid kernel panic mic: vop: copy data to kernel space then write to io memory drivers/misc/mic/vop/Makefile | 2 +- drivers/misc/mic/vop/vop_main.c | 2 +- drivers/misc/mic/vop/vop_vringh.c | 10 +++++++--- samples/mic/mpssd/mpssd.c | 24 ++++++++++++------------ 4 files changed, 21 insertions(+), 17 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/4] samples: mpssd: fix the build errors when enable DEBUG in mpssd.c 2020-09-25 7:18 [PATCH 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun @ 2020-09-25 7:18 ` Sherry Sun 2020-09-25 7:18 ` [PATCH 2/4] misc: vop: build VOP based on CONFIG_VOP Sherry Sun ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: Sherry Sun @ 2020-09-25 7:18 UTC (permalink / raw) To: sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: linux-kernel, linux-imx If enable DEBUG, will meet the following errors when build mpssd, so fix them here. Only one error is listed here, other errors are similar. mpssd.c: In function ‘virtio_net’: mpssd.c:615:21: error: incompatible type for argument 2 of ‘disp_iovec’ disp_iovec(mic, copy, __func__, __LINE__); ^~~~ mpssd.c:361:1: note: expected ‘struct mic_copy_desc *’ but argument is of type ‘struct mic_copy_desc’ disp_iovec(struct mic_info *mic, struct mic_copy_desc *copy, ^~~~~~~~~~ Signed-off-by: Sherry Sun <sherry.sun@nxp.com> --- samples/mic/mpssd/mpssd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c index a11bf6c5b53b..51d03545869e 100644 --- a/samples/mic/mpssd/mpssd.c +++ b/samples/mic/mpssd/mpssd.c @@ -612,7 +612,7 @@ virtio_net(void *arg) copy.out_len, hdr->gso_type); #endif #ifdef DEBUG - disp_iovec(mic, copy, __func__, __LINE__); + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d read from tap 0x%lx\n", mic->name, __func__, __LINE__, len); @@ -632,7 +632,7 @@ virtio_net(void *arg) if (!err) verify_out_len(mic, ©); #ifdef DEBUG - disp_iovec(mic, copy, __func__, __LINE__); + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d wrote to net 0x%lx\n", mic->name, __func__, __LINE__, sum_iovec_len(©)); @@ -681,12 +681,12 @@ virtio_net(void *arg) sizeof(struct virtio_net_hdr); verify_out_len(mic, ©); #ifdef DEBUG - disp_iovec(mic, copy, __func__, + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d ", mic->name, __func__, __LINE__); mpsslog("read from net 0x%lx\n", - sum_iovec_len(copy)); + sum_iovec_len(©)); #endif len = writev(net_poll[NET_FD_TUN].fd, copy.iov, copy.iovcnt); @@ -814,7 +814,7 @@ virtio_console(void *arg) len = readv(pty_fd, copy.iov, copy.iovcnt); if (len > 0) { #ifdef DEBUG - disp_iovec(mic, copy, __func__, __LINE__); + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d read from tap 0x%lx\n", mic->name, __func__, __LINE__, len); @@ -834,10 +834,10 @@ virtio_console(void *arg) if (!err) verify_out_len(mic, ©); #ifdef DEBUG - disp_iovec(mic, copy, __func__, __LINE__); + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d wrote to net 0x%lx\n", mic->name, __func__, __LINE__, - sum_iovec_len(copy)); + sum_iovec_len(©)); #endif /* Reinitialize IOV for next run */ iov0->iov_len = PAGE_SIZE; @@ -866,12 +866,12 @@ virtio_console(void *arg) iov1->iov_len = copy.out_len; verify_out_len(mic, ©); #ifdef DEBUG - disp_iovec(mic, copy, __func__, + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d ", mic->name, __func__, __LINE__); mpsslog("read from net 0x%lx\n", - sum_iovec_len(copy)); + sum_iovec_len(©)); #endif len = writev(pty_fd, copy.iov, copy.iovcnt); @@ -883,7 +883,7 @@ virtio_console(void *arg) sum_iovec_len(©)); } else { #ifdef DEBUG - disp_iovec(mic, copy, __func__, + disp_iovec(mic, ©, __func__, __LINE__); mpsslog("%s %s %d ", mic->name, __func__, -- 2.17.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/4] misc: vop: build VOP based on CONFIG_VOP 2020-09-25 7:18 [PATCH 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun 2020-09-25 7:18 ` [PATCH 1/4] samples: mpssd: fix the build errors when enable DEBUG in mpssd.c Sherry Sun @ 2020-09-25 7:18 ` Sherry Sun 2020-09-25 7:18 ` [PATCH 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic Sherry Sun 2020-09-25 7:18 ` [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun 3 siblings, 0 replies; 9+ messages in thread From: Sherry Sun @ 2020-09-25 7:18 UTC (permalink / raw) To: sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: linux-kernel, linux-imx Build module or builtin VOP based on CONFIG_VOP macro. Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com> Signed-off-by: Sherry Sun <sherry.sun@nxp.com> --- drivers/misc/mic/vop/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/mic/vop/Makefile b/drivers/misc/mic/vop/Makefile index 579da3868c8e..51b9b0022786 100644 --- a/drivers/misc/mic/vop/Makefile +++ b/drivers/misc/mic/vop/Makefile @@ -3,7 +3,7 @@ # Makefile - Intel MIC Linux driver. # Copyright(c) 2016, Intel Corporation. # -obj-m := vop.o +obj-$(CONFIG_VOP) := vop.o vop-objs += vop_main.o vop-objs += vop_debugfs.o -- 2.17.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic 2020-09-25 7:18 [PATCH 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun 2020-09-25 7:18 ` [PATCH 1/4] samples: mpssd: fix the build errors when enable DEBUG in mpssd.c Sherry Sun 2020-09-25 7:18 ` [PATCH 2/4] misc: vop: build VOP based on CONFIG_VOP Sherry Sun @ 2020-09-25 7:18 ` Sherry Sun 2020-09-25 7:18 ` [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun 3 siblings, 0 replies; 9+ messages in thread From: Sherry Sun @ 2020-09-25 7:18 UTC (permalink / raw) To: sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: linux-kernel, linux-imx Since struct _mic_vring_info and vring are allocated together and follow vring, if the vring_size() is not four bytes aligned, which will cause the start address of struct _mic_vring_info is not four byte aligned. For example, when vring entries is 128, the vring_size() will be 5126 bytes. The _mic_vring_info struct layout in ddr looks like: 0x90002400: 00000000 00390000 EE010000 0000C0FF Here 0x39 is the avail_idx member, and 0xC0FFEE01 is the magic member. When EP use ioread32(magic) to reads the magic in RC's share memory, it will cause kernel panic on ARM64 platform due to the cross-byte io read. Here read magic in user space use le32toh(vr0->info->magic) will meet the same issue. So add round_up(x,4) for vring_size, then the struct _mic_vring_info will store in this way: 0x90002400: 00000000 00000000 00000039 C0FFEE01 Which will avoid kernel panic when read magic in struct _mic_vring_info. Signed-off-by: Sherry Sun <sherry.sun@nxp.com> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com> --- drivers/misc/mic/vop/vop_main.c | 2 +- drivers/misc/mic/vop/vop_vringh.c | 4 ++-- samples/mic/mpssd/mpssd.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c index 55e7f21e51f4..6722c726b259 100644 --- a/drivers/misc/mic/vop/vop_main.c +++ b/drivers/misc/mic/vop/vop_main.c @@ -320,7 +320,7 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, /* First assign the vring's allocated in host memory */ vqconfig = _vop_vq_config(vdev->desc) + index; memcpy_fromio(&config, vqconfig, sizeof(config)); - _vr_size = vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN); + _vr_size = round_up(vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN), 4); vr_size = PAGE_ALIGN(_vr_size + sizeof(struct _mic_vring_info)); va = vpdev->hw_ops->remap(vpdev, le64_to_cpu(config.address), vr_size); if (!va) diff --git a/drivers/misc/mic/vop/vop_vringh.c b/drivers/misc/mic/vop/vop_vringh.c index 30eac172f017..45fdb394de11 100644 --- a/drivers/misc/mic/vop/vop_vringh.c +++ b/drivers/misc/mic/vop/vop_vringh.c @@ -296,7 +296,7 @@ static int vop_virtio_add_device(struct vop_vdev *vdev, num = le16_to_cpu(vqconfig[i].num); mutex_init(&vvr->vr_mutex); - vr_size = PAGE_ALIGN(vring_size(num, MIC_VIRTIO_RING_ALIGN) + + vr_size = PAGE_ALIGN(round_up(vring_size(num, MIC_VIRTIO_RING_ALIGN), 4) + sizeof(struct _mic_vring_info)); vr->va = (void *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, @@ -308,7 +308,7 @@ static int vop_virtio_add_device(struct vop_vdev *vdev, goto err; } vr->len = vr_size; - vr->info = vr->va + vring_size(num, MIC_VIRTIO_RING_ALIGN); + vr->info = vr->va + round_up(vring_size(num, MIC_VIRTIO_RING_ALIGN), 4); vr->info->magic = cpu_to_le32(MIC_MAGIC + vdev->virtio_id + i); vr_addr = dma_map_single(&vpdev->dev, vr->va, vr_size, DMA_BIDIRECTIONAL); diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c index 51d03545869e..c03a05d498f0 100644 --- a/samples/mic/mpssd/mpssd.c +++ b/samples/mic/mpssd/mpssd.c @@ -403,9 +403,9 @@ mic_virtio_copy(struct mic_info *mic, int fd, static inline unsigned _vring_size(unsigned int num, unsigned long align) { - return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num) + return _ALIGN_UP(((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num) + align - 1) & ~(align - 1)) - + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num; + + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num, 4); } /* -- 2.17.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory 2020-09-25 7:18 [PATCH 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun ` (2 preceding siblings ...) 2020-09-25 7:18 ` [PATCH 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic Sherry Sun @ 2020-09-25 7:18 ` Sherry Sun 2020-09-25 7:32 ` Arnd Bergmann ` (2 more replies) 3 siblings, 3 replies; 9+ messages in thread From: Sherry Sun @ 2020-09-25 7:18 UTC (permalink / raw) To: sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: linux-kernel, linux-imx Read and write io memory should address align on ARCH ARM. Change to use memcpy_toio to avoid kernel panic caused by the address un-align issue. Signed-off-by: Sherry Sun <sherry.sun@nxp.com> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com> --- drivers/misc/mic/vop/vop_vringh.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/misc/mic/vop/vop_vringh.c b/drivers/misc/mic/vop/vop_vringh.c index 45fdb394de11..f344209ac386 100644 --- a/drivers/misc/mic/vop/vop_vringh.c +++ b/drivers/misc/mic/vop/vop_vringh.c @@ -602,6 +602,7 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf, size_t partlen; bool dma = VOP_USE_DMA && vi->dma_ch; int err = 0; + void *temp = NULL; if (dma) { dma_alignment = 1 << vi->dma_ch->device->copy_align; @@ -655,12 +656,15 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf, * We are copying to IO below and should ideally use something * like copy_from_user_toio(..) if it existed. */ - if (copy_from_user((void __force *)dbuf, ubuf, len)) { + temp = kmalloc(len, GFP_KERNEL); + if (copy_from_user(temp, ubuf, len)) { err = -EFAULT; dev_err(vop_dev(vdev), "%s %d err %d\n", __func__, __LINE__, err); goto err; } + memcpy_toio((void __force *)dbuf, temp, len); + kfree(temp); vdev->out_bytes += len; err = 0; err: -- 2.17.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory 2020-09-25 7:18 ` [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun @ 2020-09-25 7:32 ` Arnd Bergmann 2020-09-25 7:50 ` Sherry Sun 2020-09-25 10:55 ` kernel test robot 2020-09-25 11:03 ` kernel test robot 2 siblings, 1 reply; 9+ messages in thread From: Arnd Bergmann @ 2020-09-25 7:32 UTC (permalink / raw) To: Sherry Sun Cc: Sudeep Dutt, Ashutosh Dixit, gregkh, Rikard Falkeborn, Lee Jones, Michael S. Tsirkin, linux-kernel, NXP Linux Team On Fri, Sep 25, 2020 at 9:22 AM Sherry Sun <sherry.sun@nxp.com> wrote: > > @@ -655,12 +656,15 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf, > * We are copying to IO below and should ideally use something > * like copy_from_user_toio(..) if it existed. > */ > - if (copy_from_user((void __force *)dbuf, ubuf, len)) { > + temp = kmalloc(len, GFP_KERNEL); > + if (copy_from_user(temp, ubuf, len)) This needs to have error handling for a kmalloc() failure. As the length appears to be user-provided, you might also want to limit the size of the allocation and instead do a loop with multiple copies if there is more data than fits into the allocation. Arnd ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory 2020-09-25 7:32 ` Arnd Bergmann @ 2020-09-25 7:50 ` Sherry Sun 0 siblings, 0 replies; 9+ messages in thread From: Sherry Sun @ 2020-09-25 7:50 UTC (permalink / raw) To: Arnd Bergmann Cc: Sudeep Dutt, Ashutosh Dixit, gregkh, Rikard Falkeborn, Lee Jones, Michael S. Tsirkin, linux-kernel, dl-linux-imx Hi Arnd, > Subject: Re: [PATCH 4/4] mic: vop: copy data to kernel space then write to io > memory > > On Fri, Sep 25, 2020 at 9:22 AM Sherry Sun <sherry.sun@nxp.com> wrote: > > > > > @@ -655,12 +656,15 @@ static int vop_virtio_copy_from_user(struct > vop_vdev *vdev, void __user *ubuf, > > * We are copying to IO below and should ideally use something > > * like copy_from_user_toio(..) if it existed. > > */ > > - if (copy_from_user((void __force *)dbuf, ubuf, len)) { > > + temp = kmalloc(len, GFP_KERNEL); > > + if (copy_from_user(temp, ubuf, len)) > > This needs to have error handling for a kmalloc() failure. As the length > appears to be user-provided, you might also want to limit the size of the > allocation and instead do a loop with multiple copies if there is more data > than fits into the allocation. Thanks for your quick reply, you are right, will add error handling for kmalloc() failure and size limit handling in v2. Regards Sherry > > Arnd ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory 2020-09-25 7:18 ` [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun 2020-09-25 7:32 ` Arnd Bergmann @ 2020-09-25 10:55 ` kernel test robot 2020-09-25 11:03 ` kernel test robot 2 siblings, 0 replies; 9+ messages in thread From: kernel test robot @ 2020-09-25 10:55 UTC (permalink / raw) To: Sherry Sun, sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: kbuild-all, linux-kernel, linux-imx [-- Attachment #1: Type: text/plain, Size: 5112 bytes --] Hi Sherry, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on char-misc/char-misc-testing] [also build test WARNING on soc/for-next linus/master v5.9-rc6 next-20200924] [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/Sherry-Sun/Fix-some-bugs-of-the-vop-driver-and-mpssd-user-space-tool/20200925-152356 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 9eb29f2ed95edda511ce28651b1d7cdef3614c12 config: x86_64-randconfig-s021-20200925 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-201-g24bdaac6-dirty # https://github.com/0day-ci/linux/commit/5f4b5ded8447941d43166eba5d303cdca2e54f07 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Sherry-Sun/Fix-some-bugs-of-the-vop-driver-and-mpssd-user-space-tool/20200925-152356 git checkout 5f4b5ded8447941d43166eba5d303cdca2e54f07 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> sparse warnings: (new ones prefixed by >>) >> drivers/misc/mic/vop/vop_vringh.c:666:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem * @@ got void * @@ >> drivers/misc/mic/vop/vop_vringh.c:666:22: sparse: expected void volatile [noderef] __iomem * >> drivers/misc/mic/vop/vop_vringh.c:666:22: sparse: got void * vim +666 drivers/misc/mic/vop/vop_vringh.c 585 586 /* 587 * Initiates copies across the PCIe bus from a user space buffer to card 588 * memory. When transfers are done using DMA, source/destination addresses 589 * and transfer length must follow the alignment requirements of the MIC 590 * DMA engine. 591 */ 592 static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf, 593 size_t len, u64 daddr, size_t dlen, 594 int vr_idx) 595 { 596 struct vop_device *vpdev = vdev->vpdev; 597 void __iomem *dbuf = vpdev->hw_ops->remap(vpdev, daddr, len); 598 struct vop_vringh *vvr = &vdev->vvr[vr_idx]; 599 struct vop_info *vi = dev_get_drvdata(&vdev->vpdev->dev); 600 size_t dma_alignment; 601 bool x200; 602 size_t partlen; 603 bool dma = VOP_USE_DMA && vi->dma_ch; 604 int err = 0; 605 void *temp = NULL; 606 607 if (dma) { 608 dma_alignment = 1 << vi->dma_ch->device->copy_align; 609 x200 = is_dma_copy_aligned(vi->dma_ch->device, 1, 1, 1); 610 611 if (daddr & (dma_alignment - 1)) { 612 vdev->tx_dst_unaligned += len; 613 dma = false; 614 } else if (ALIGN(len, dma_alignment) > dlen) { 615 vdev->tx_len_unaligned += len; 616 dma = false; 617 } 618 } 619 620 if (!dma) 621 goto memcpy; 622 623 /* 624 * X100 uses DMA addresses as seen by the card so adding 625 * the aperture base is not required for DMA. However x200 626 * requires DMA addresses to be an offset into the bar so 627 * add the aperture base for x200. 628 */ 629 if (x200) 630 daddr += vpdev->aper->pa; 631 while (len) { 632 partlen = min_t(size_t, len, VOP_INT_DMA_BUF_SIZE); 633 634 if (copy_from_user(vvr->buf, ubuf, partlen)) { 635 err = -EFAULT; 636 dev_err(vop_dev(vdev), "%s %d err %d\n", 637 __func__, __LINE__, err); 638 goto err; 639 } 640 err = vop_sync_dma(vdev, daddr, vvr->buf_da, 641 ALIGN(partlen, dma_alignment)); 642 if (err) { 643 dev_err(vop_dev(vdev), "%s %d err %d\n", 644 __func__, __LINE__, err); 645 goto err; 646 } 647 daddr += partlen; 648 ubuf += partlen; 649 dbuf += partlen; 650 vdev->out_bytes_dma += partlen; 651 vdev->out_bytes += partlen; 652 len -= partlen; 653 } 654 memcpy: 655 /* 656 * We are copying to IO below and should ideally use something 657 * like copy_from_user_toio(..) if it existed. 658 */ 659 temp = kmalloc(len, GFP_KERNEL); 660 if (copy_from_user(temp, ubuf, len)) { 661 err = -EFAULT; 662 dev_err(vop_dev(vdev), "%s %d err %d\n", 663 __func__, __LINE__, err); 664 goto err; 665 } > 666 memcpy_toio((void __force *)dbuf, temp, len); 667 kfree(temp); 668 vdev->out_bytes += len; 669 err = 0; 670 err: 671 vpdev->hw_ops->unmap(vpdev, dbuf); 672 dev_dbg(vop_dev(vdev), 673 "%s: ubuf %p dbuf %p len 0x%zx vr_idx 0x%x\n", 674 __func__, ubuf, dbuf, len, vr_idx); 675 return err; 676 } 677 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 28053 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory 2020-09-25 7:18 ` [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun 2020-09-25 7:32 ` Arnd Bergmann 2020-09-25 10:55 ` kernel test robot @ 2020-09-25 11:03 ` kernel test robot 2 siblings, 0 replies; 9+ messages in thread From: kernel test robot @ 2020-09-25 11:03 UTC (permalink / raw) To: Sherry Sun, sudeep.dutt, ashutosh.dixit, arnd, gregkh, rikard.falkeborn, lee.jones, mst Cc: kbuild-all, linux-kernel, linux-imx [-- Attachment #1: Type: text/plain, Size: 5305 bytes --] Hi Sherry, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on char-misc/char-misc-testing] [also build test WARNING on soc/for-next linus/master v5.9-rc6 next-20200924] [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/Sherry-Sun/Fix-some-bugs-of-the-vop-driver-and-mpssd-user-space-tool/20200925-152356 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 9eb29f2ed95edda511ce28651b1d7cdef3614c12 config: ia64-randconfig-s032-20200925 (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # apt-get install sparse # sparse version: v0.6.2-201-g24bdaac6-dirty # https://github.com/0day-ci/linux/commit/5f4b5ded8447941d43166eba5d303cdca2e54f07 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Sherry-Sun/Fix-some-bugs-of-the-vop-driver-and-mpssd-user-space-tool/20200925-152356 git checkout 5f4b5ded8447941d43166eba5d303cdca2e54f07 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=ia64 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> sparse warnings: (new ones prefixed by >>) >> drivers/misc/mic/vop/vop_vringh.c:666:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem *dst @@ got void * @@ >> drivers/misc/mic/vop/vop_vringh.c:666:22: sparse: expected void volatile [noderef] __iomem *dst drivers/misc/mic/vop/vop_vringh.c:666:22: sparse: got void * vim +666 drivers/misc/mic/vop/vop_vringh.c 585 586 /* 587 * Initiates copies across the PCIe bus from a user space buffer to card 588 * memory. When transfers are done using DMA, source/destination addresses 589 * and transfer length must follow the alignment requirements of the MIC 590 * DMA engine. 591 */ 592 static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf, 593 size_t len, u64 daddr, size_t dlen, 594 int vr_idx) 595 { 596 struct vop_device *vpdev = vdev->vpdev; 597 void __iomem *dbuf = vpdev->hw_ops->remap(vpdev, daddr, len); 598 struct vop_vringh *vvr = &vdev->vvr[vr_idx]; 599 struct vop_info *vi = dev_get_drvdata(&vdev->vpdev->dev); 600 size_t dma_alignment; 601 bool x200; 602 size_t partlen; 603 bool dma = VOP_USE_DMA && vi->dma_ch; 604 int err = 0; 605 void *temp = NULL; 606 607 if (dma) { 608 dma_alignment = 1 << vi->dma_ch->device->copy_align; 609 x200 = is_dma_copy_aligned(vi->dma_ch->device, 1, 1, 1); 610 611 if (daddr & (dma_alignment - 1)) { 612 vdev->tx_dst_unaligned += len; 613 dma = false; 614 } else if (ALIGN(len, dma_alignment) > dlen) { 615 vdev->tx_len_unaligned += len; 616 dma = false; 617 } 618 } 619 620 if (!dma) 621 goto memcpy; 622 623 /* 624 * X100 uses DMA addresses as seen by the card so adding 625 * the aperture base is not required for DMA. However x200 626 * requires DMA addresses to be an offset into the bar so 627 * add the aperture base for x200. 628 */ 629 if (x200) 630 daddr += vpdev->aper->pa; 631 while (len) { 632 partlen = min_t(size_t, len, VOP_INT_DMA_BUF_SIZE); 633 634 if (copy_from_user(vvr->buf, ubuf, partlen)) { 635 err = -EFAULT; 636 dev_err(vop_dev(vdev), "%s %d err %d\n", 637 __func__, __LINE__, err); 638 goto err; 639 } 640 err = vop_sync_dma(vdev, daddr, vvr->buf_da, 641 ALIGN(partlen, dma_alignment)); 642 if (err) { 643 dev_err(vop_dev(vdev), "%s %d err %d\n", 644 __func__, __LINE__, err); 645 goto err; 646 } 647 daddr += partlen; 648 ubuf += partlen; 649 dbuf += partlen; 650 vdev->out_bytes_dma += partlen; 651 vdev->out_bytes += partlen; 652 len -= partlen; 653 } 654 memcpy: 655 /* 656 * We are copying to IO below and should ideally use something 657 * like copy_from_user_toio(..) if it existed. 658 */ 659 temp = kmalloc(len, GFP_KERNEL); 660 if (copy_from_user(temp, ubuf, len)) { 661 err = -EFAULT; 662 dev_err(vop_dev(vdev), "%s %d err %d\n", 663 __func__, __LINE__, err); 664 goto err; 665 } > 666 memcpy_toio((void __force *)dbuf, temp, len); 667 kfree(temp); 668 vdev->out_bytes += len; 669 err = 0; 670 err: 671 vpdev->hw_ops->unmap(vpdev, dbuf); 672 dev_dbg(vop_dev(vdev), 673 "%s: ubuf %p dbuf %p len 0x%zx vr_idx 0x%x\n", 674 __func__, ubuf, dbuf, len, vr_idx); 675 return err; 676 } 677 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 29373 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-09-25 11:05 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-09-25 7:18 [PATCH 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun 2020-09-25 7:18 ` [PATCH 1/4] samples: mpssd: fix the build errors when enable DEBUG in mpssd.c Sherry Sun 2020-09-25 7:18 ` [PATCH 2/4] misc: vop: build VOP based on CONFIG_VOP Sherry Sun 2020-09-25 7:18 ` [PATCH 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic Sherry Sun 2020-09-25 7:18 ` [PATCH 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun 2020-09-25 7:32 ` Arnd Bergmann 2020-09-25 7:50 ` Sherry Sun 2020-09-25 10:55 ` kernel test robot 2020-09-25 11:03 ` kernel test robot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).