Skip to content

Commit a906f2e

Browse files
PiyushXilinxgregkh
authored andcommitted
usb: gadget: udc-xilinx: replace memcpy with memcpy_toio
commit 3061b64 upstream. For ARM processor, unaligned access to device memory is not allowed. Method memcpy does not take care of alignment. USB detection failure with the unalingned address of memory, with below kernel crash. To fix the unalingned address kernel panic, replace memcpy with memcpy_toio method. Kernel crash: Unable to handle kernel paging request at virtual address ffff80000c05008a Mem abort info: ESR = 0x96000061 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x21: alignment fault Data abort info: ISV = 0, ISS = 0x00000061 CM = 0, WnR = 1 swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000143b000 [ffff80000c05008a] pgd=100000087ffff003, p4d=100000087ffff003, pud=100000087fffe003, pmd=1000000800bcc003, pte=00680000a0010713 Internal error: Oops: 96000061 [khadas#1] SMP Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.15.19-xilinx-v2022.1 khadas#1 Hardware name: ZynqMP ZCU102 Rev1.0 (DT) pstate: 200000c5 (nzCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __memcpy+0x30/0x260 lr : __xudc_ep0_queue+0xf0/0x110 sp : ffff800008003d00 x29: ffff800008003d00 x28: ffff800009474e80 x27: 00000000000000a0 x26: 0000000000000100 x25: 0000000000000012 x24: ffff000800bc8080 x23: 0000000000000001 x22: 0000000000000012 x21: ffff000800bc8080 x20: 0000000000000012 x19: ffff000800bc8080 x18: 0000000000000000 x17: ffff800876482000 x16: ffff800008004000 x15: 0000000000004000 x14: 00001f09785d0400 x13: 0103020101005567 x12: 0781400000000200 x11: 00000000c5672a10 x10: 00000000000008d0 x9 : ffff800009463cf0 x8 : ffff8000094757b0 x7 : 0201010055670781 x6 : 4000000002000112 x5 : ffff80000c05009a x4 : ffff000800a15012 x3 : ffff00080362ad80 x2 : 0000000000000012 x1 : ffff000800a15000 x0 : ffff80000c050088 Call trace: __memcpy+0x30/0x260 xudc_ep0_queue+0x3c/0x60 usb_ep_queue+0x38/0x44 composite_ep0_queue.constprop.0+0x2c/0xc0 composite_setup+0x8d0/0x185c configfs_composite_setup+0x74/0xb0 xudc_irq+0x570/0xa40 __handle_irq_event_percpu+0x58/0x170 handle_irq_event+0x60/0x120 handle_fasteoi_irq+0xc0/0x220 handle_domain_irq+0x60/0x90 gic_handle_irq+0x74/0xa0 call_on_irq_stack+0x2c/0x60 do_interrupt_handler+0x54/0x60 el1_interrupt+0x30/0x50 el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x78/0x7c arch_cpu_idle+0x18/0x2c do_idle+0xdc/0x15c cpu_startup_entry+0x28/0x60 rest_init+0xc8/0xe0 arch_call_rest_init+0x10/0x1c start_kernel+0x694/0x6d4 __primary_switched+0xa4/0xac Fixes: 1f7c516 ("usb: gadget: Add xilinx usb2 device support") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Cc: [email protected] Signed-off-by: Piyush Mehta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7decb65 commit a906f2e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/usb/gadget/udc/udc-xilinx.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,13 @@ static int xudc_eptxrx(struct xusb_ep *ep, struct xusb_req *req,
496496
/* Get the Buffer address and copy the transmit data.*/
497497
eprambase = (u32 __force *)(udc->addr + ep->rambase);
498498
if (ep->is_in) {
499-
memcpy(eprambase, bufferptr, bytestosend);
499+
memcpy_toio((void __iomem *)eprambase, bufferptr,
500+
bytestosend);
500501
udc->write_fn(udc->addr, ep->offset +
501502
XUSB_EP_BUF0COUNT_OFFSET, bufferlen);
502503
} else {
503-
memcpy(bufferptr, eprambase, bytestosend);
504+
memcpy_toio((void __iomem *)bufferptr, eprambase,
505+
bytestosend);
504506
}
505507
/*
506508
* Enable the buffer for transmission.
@@ -514,11 +516,13 @@ static int xudc_eptxrx(struct xusb_ep *ep, struct xusb_req *req,
514516
eprambase = (u32 __force *)(udc->addr + ep->rambase +
515517
ep->ep_usb.maxpacket);
516518
if (ep->is_in) {
517-
memcpy(eprambase, bufferptr, bytestosend);
519+
memcpy_toio((void __iomem *)eprambase, bufferptr,
520+
bytestosend);
518521
udc->write_fn(udc->addr, ep->offset +
519522
XUSB_EP_BUF1COUNT_OFFSET, bufferlen);
520523
} else {
521-
memcpy(bufferptr, eprambase, bytestosend);
524+
memcpy_toio((void __iomem *)bufferptr, eprambase,
525+
bytestosend);
522526
}
523527
/*
524528
* Enable the buffer for transmission.
@@ -1020,7 +1024,7 @@ static int __xudc_ep0_queue(struct xusb_ep *ep0, struct xusb_req *req)
10201024
udc->addr);
10211025
length = req->usb_req.actual = min_t(u32, length,
10221026
EP0_MAX_PACKET);
1023-
memcpy(corebuf, req->usb_req.buf, length);
1027+
memcpy_toio((void __iomem *)corebuf, req->usb_req.buf, length);
10241028
udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, length);
10251029
udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1);
10261030
} else {
@@ -1746,7 +1750,7 @@ static void xudc_handle_setup(struct xusb_udc *udc)
17461750

17471751
/* Load up the chapter 9 command buffer.*/
17481752
ep0rambase = (u32 __force *) (udc->addr + XUSB_SETUP_PKT_ADDR_OFFSET);
1749-
memcpy(&setup, ep0rambase, 8);
1753+
memcpy_toio((void __iomem *)&setup, ep0rambase, 8);
17501754

17511755
udc->setup = setup;
17521756
udc->setup.wValue = cpu_to_le16(setup.wValue);
@@ -1833,7 +1837,7 @@ static void xudc_ep0_out(struct xusb_udc *udc)
18331837
(ep0->rambase << 2));
18341838
buffer = req->usb_req.buf + req->usb_req.actual;
18351839
req->usb_req.actual = req->usb_req.actual + bytes_to_rx;
1836-
memcpy(buffer, ep0rambase, bytes_to_rx);
1840+
memcpy_toio((void __iomem *)buffer, ep0rambase, bytes_to_rx);
18371841

18381842
if (req->usb_req.length == req->usb_req.actual) {
18391843
/* Data transfer completed get ready for Status stage */
@@ -1909,7 +1913,7 @@ static void xudc_ep0_in(struct xusb_udc *udc)
19091913
(ep0->rambase << 2));
19101914
buffer = req->usb_req.buf + req->usb_req.actual;
19111915
req->usb_req.actual = req->usb_req.actual + length;
1912-
memcpy(ep0rambase, buffer, length);
1916+
memcpy_toio((void __iomem *)ep0rambase, buffer, length);
19131917
}
19141918
udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, count);
19151919
udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1);

0 commit comments

Comments
 (0)