Monitoring IO to ioremap'ed addresses

From: Andrew Miklas (public_at_mikl.as)
Date: 11/11/03

  • Next message: Paul Venezia: "Re: I/O issues, iowait problems, 2.4 v 2.6"
    To: linux-kernel@vger.kernel.org
    Date:	Mon, 10 Nov 2003 23:15:54 -0500
    
    

    Hi all,

    Does Linux have any way of monitoring all IO done over a range of ioremap'ed
    addresses? This would be useful if someone wanted to examine exactly how a
    driver interacted with hardware, especially if the driver is binary-only.
    Some architectures have debug registers that can trigger over large areas of
    memory, but i386 is pretty limited in this regard.

    If Linux doesn't yet have such a system in place, one possible way to
    implement it (for i386 anyways) would be to remove the page table entry
    created by ioremap when the device was first mapped into kernel memory. A
    table could be created somewhere to keep track of all virtual addresses we've
    invalidated in this way. Then, when an attempt at MMIO occurs, the page
    fault hander would be invoked.

    The page fault hander would be modified to correct the fault by mapping the
    faulting address to a page of kmalloc'ed memory. If the faulting operation
    was a read, then we would do the MMIO read operation ourselves, and put the
    result into the appropriate offset of the page we've used to correct the
    fault. We would also log the read (ie. address, value read, and triggering
    EIP) somewhere. Next, we would set the trace bit (TR), and return from the
    fault. After the faulting instruction was successfully executed, we would
    clean everything up in the INT 1 handler. That is, somewhere in do_debug, we
    would remove the page table entry we set up in the page fault handler, clear
    the trace bit, and return.

    For write operations, we would just reverse the above order. We would
    retrieve the value intended to be written to MMIO from the kmalloc'ed memory
    in the INT 1 handler, log it, and then pass it on to the device.

    Additionally, if such a scheme were extended to support all of memory and
    exposed to processes, user mode debuggers could make use of it to allow for
    as many "break on memory access" type breakpoints as required, rather than
    being limited to the handful of debug registers present in the i386
    architecture.

    I can think of a few potential problems with this scheme. It blends MMIO
    operations with memory operations done on regular kmalloc'ed memory, which
    doesn't usually seem like the right thing to do. Also, it might be difficult
    to determine the actual size of the memory operation. I don't know how
    devices respond to having a long read done at some address when they are only
    expecting to have a byte read.

    I suppose these problems and the messiness of using the TR bit and the INT 1
    handler could be avoided by actually reading the instruction at the faulting
    EIP, and doing the operation ourselves, but that would involve a partial
    emulator being in the kernel. :)

    Am I missing anything important? Any ideas on better ways to do this? Does
    anyone see this kind of feature as being useful enough to justify the work
    required to put it in?

    -- Andrew
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Paul Venezia: "Re: I/O issues, iowait problems, 2.4 v 2.6"

    Relevant Pages

    • Panic: Kernel page fault with ath0_com_lock held, r211295
      ... Kernel page fault with the following non-sleepable locks held: ... Physical memory: 2031 MB ... Loaded symbols for /boot/kernel/tmpfs.ko ... data packets ...
      (freebsd-current)
    • Re: Binary data in multiple adjacent files
      ... Mapping it doesn't eat any working set except, possibly, for the ... It's not faulted into physical memory. ... You also get a whole "page fault cluster" faulted in. ... grid sections immediately north, south, northeast, northwest, southeast ...
      (comp.os.vms)
    • Re: [SUSPECTED SPAM] Re: [linux-pm] Proposal for a new algorithm for reading & writing a hib
      ... fault allowed to proceed. ... page faulting code touches memory, ... will know to do just one thing, write the memory to disk. ... Linux loads the suspend module to memory (if it is inside kernel ...
      (Linux-Kernel)
    • Re: Applications "buying" resources
      ... L4's approach for virtual memory is similar to yours: ... While the OS can field the fault, ... resources are disposable into the same entity which manages the ... you also need a way of letting the kernel ...
      (comp.arch.embedded)
    • Re: Anyone using Foxconn motherboards
      ... The vast majority of the faults I've seen with generic memory were cell faults - ie. one or two memory locations repeatedly produced the wrong bit in certain tests. ... I've *never* had a cell fault on a memory stick with chips marked from a major manufacturer. ... Hardware DIMM checkers need more time to check a stick. ...
      (uk.comp.homebuilt)