NULL pointer dereference in swiotlb_unmap_sg_attrs() on disk IO

Posted by Inductiveload on Stack Overflow See other posts from Stack Overflow or by Inductiveload
Published on 2012-12-04T15:34:00Z Indexed on 2012/12/13 11:05 UTC
Read the original article Hit count: 186

I'm getting an error I really don't understand when reading or writing files using a PCIe block device driver. I seem to be hitting an issue in swiotlb_unmap_sg_attrs(), which appears to be doing a NULL dereference of the sg pointer, but I don't know where this is coming from, as the only scatterlist I use myself is allocated as part of the device info structure and persists as long as the driver does.

There is a stacktrace to go with the problem. It tends to vary a bit in exact details, but it always crashes in swiotlb_unmap_sq_attrs().

I think it's likely I have a locking issue, as I am not sure how to handle the locks around the IO functions. The lock is already held when the request function is called, I release it before the IO functions themselves are called, as they need an (MSI) IRQ to complete. The IRQ handler updates a "status" value, which the IO function is waiting for. When the IO function returns, I then take the lock back up and return to request queue handling.

The crash happens in blk_fetch_request() during the following:

if (!__blk_end_request(req, res, bytes)){
    printk(KERN_ERR "%s next request\n", DRIVER_NAME);

    req = blk_fetch_request(q);
} else {
    printk(KERN_ERR "%s same request\n", DRIVER_NAME);
}

where bytes is updated by the request handler to be the total length of IO (summed length of each scatter-gather segment).

© Stack Overflow or respective owner

Related posts about linux-kernel

Related posts about linux-device-driver