jacobfeder / axisfifo

Zynq SoC Linux kernel driver for Xilinx AXI-Stream FIFO IP
GNU General Public License v3.0
49 stars 26 forks source link

Read register ioctl causes crash #22

Closed ShaneEverittM closed 2 years ago

ShaneEverittM commented 2 years ago

The following code causes a crash

  int fifo_fd = open("/dev/axis_fifo_0x43c00000", O_RDWR);
  if (fifo_fd < 0)
      return 1;

  struct axis_fifo_kern_regInfo reg_info{XLLF_RLR_OFFSET, 0};
  int rc = ioctl(fifo_fd, AXIS_FIFO_GET_REG, &reg_info);

  if (rc) {
      return EXIT_FAILURE;
  } else {
      return EXIT_SUCCESS;
  }

Reads and writes are successful, other ioctl operations work fine, and the provided test app functions correctly. When I try the above code I get:

Internal error: Oops - BUG: 1406 [#1] PREEMPT SMP ARM
Modules linked in: axis_fifo(O) uio_pdrv_genirq
CPU: 1 PID: 492 Comm: fifo_benchmark Tainted: G           O      5.10.0-xilinx-v2021.2 #1
Hardware name: Xilinx Zynq Platform
PC is at axis_fifo_ioctl+0x1c0/0x29c [axis_fifo]
LR is at 0x0
pc : [<bf012960>]    lr : [<00000000>]    psr: 60010013
sp : c1c93ef0  ip : 00000018  fp : 00000000
r10: c1c92000  r9 : c18a2f00  r8 : c1c92000
r7 : 80085100  r6 : befffab4  r5 : 00000000  r4 : c1a0f540
r3 : 00000000  r2 : 00000024  r1 : befffabc  r0 : 00000000
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 18c5387d  Table: 01a1404a  DAC: 00000051
Process fifo_benchmark (pid: 492, stack limit = 0xc7d15f33)
Stack: (0xc1c93ef0 to 0xc1c94000)
3ee0:                                     00000000 00000024 00000000 4fb846c8
3f00: 80085100 befffab4 c18a2f00 c19d58d0 00000003 c0210d60 80085100 c0211738
3f20: c1c92000 00000000 00000000 c1c92000 c1c93f40 ffffe000 00000000 c0108704
3f40: 00000000 00000005 00000000 00000001 00401544 00000000 00000000 00000000
3f60: 00000005 00000000 00000001 00401544 00000000 00000000 00000000 4fb846c8
3f80: 00000000 00414ed4 00414ed4 004016ad 00000036 c0100264 c1c92000 00000036
3fa0: 00000000 c0100060 00414ed4 00414ed4 00000003 80085100 befffab4 00000003
3fc0: 00414ed4 00414ed4 004016ad 00000036 00000000 00000000 00414ed4 00000000
3fe0: 00414f4c befffaa4 00403531 b6e10228 40010030 00000003 00000000 00000000
[<bf012960>] (axis_fifo_ioctl [axis_fifo]) from [<c0210d60>] (vfs_ioctl+0x20/0x38)
[<c0210d60>] (vfs_ioctl) from [<c0211738>] (sys_ioctl+0xc0/0x770)
[<c0211738>] (sys_ioctl) from [<c0100060>] (ret_fast_syscall+0x0/0x54)
Exception stack(0xc1c93fa8 to 0xc1c93ff0)
3fa0:                   00414ed4 00414ed4 00000003 80085100 befffab4 00000003
3fc0: 00414ed4 00414ed4 004016ad 00000036 00000000 00000000 00414ed4 00000000
3fe0: 00414f4c befffaa4 00403531 b6e10228
Code: e59d2004 e0833002 e5933000 f57ff04f (e28d1004) 
---[ end trace 5d0f1f8cb441a56f ]---

I am using PetaLinux 2021.2 with the following FIFO configuration image Let me know if you need any more information.

ShaneEverittM commented 2 years ago

Further investigation showed that ioctl operations requesting register values work for all the register offsets below XLLF_RDFD_OFFSET.

jacobfeder commented 2 years ago

@ShaneEverittM not sure I've never tried this. Are you sure you're accessing something that's in the address range of the IP?

ShaneEverittM commented 2 years ago

Also not sure, I just assumed the #define block labeled "IP register offsets" were the valid values for the regNo field in the axis_fifo_kern_regInfo. Can you shed some light on the expected behavior for the AXIS_FIFO_GET_REG ioctl?

Also thanks for the quick reply!

jacobfeder commented 2 years ago

It's been several years since I've looked at this in detail, so can't be of much help unfortunately. I would look at the IP datasheet and make sure you're addressing valid memory regions of the IP.

ShaneEverittM commented 2 years ago

Alright, is this not something you would recommend for production use then? I saw it was in the staging area for the kernel.

jacobfeder commented 2 years ago

Yeah it's been there in limbo for awhile. It seems there are several people using it successfully, but I'm not actively developing it.

ShaneEverittM commented 2 years ago

Gotcha, also the same crash happens when running: cat /sys/class/axis_fifo/axis_fifo_0x43c00000/ip_registers/rlr. Is it likely something I'm messing up? I'm using 4.2 and maybe that doesn't expose the same registers?

ShaneEverittM commented 2 years ago

Ok, it's likely I'm just reading in invalid ways, the data sheet has rules for when registers are valid to read, and in what order.

jacobfeder commented 2 years ago

You definitely have to be careful about accessing the registers directly - if you access them in the wrong order it can break things. IIRC this is somewhat explained in the datasheet (about the order in which you have to access the registers).

jacobfeder commented 2 years ago

Yeah exactly.

ShaneEverittM commented 2 years ago

Cool, other than me messing up, driver has been working great, love the helpful error messages, I'll go ahead and close this issue.