• Philipp Tomsich's avatar
    usb: dwc3: gadget: make cache-maintenance on event buffers more robust · ac167da4
    Philipp Tomsich authored
    Merely using dma_alloc_coherent does not ensure that there is no stale
    data left in the caches for the allocated DMA buffer (i.e. that the
    affected cacheline may still be dirty).
    
    The original code was doing the following (on AArch64, which
    translates a 'flush' into a 'clean + invalidate'):
      # during initialisation:
          1. allocate buffers via memalign
          	 => buffers may still be modified (cached, dirty)
      # during interrupt processing
          2. clean + invalidate buffers
          	 => may commit stale data from a modified cacheline
          3. read from buffers
    
    This could lead to garbage info being written to buffers before
    reading them during even-processing.
    
    To make the event processing more robust, we use the following sequence
    for the cache-maintenance:
      # during initialisation:
          1. allocate buffers via memalign
          2. clean + invalidate buffers
          	 (we only need the 'invalidate' part, but dwc3_flush_cache()
    	  always performs a 'clean + invalidate')
      # during interrupt processing
          3. read the buffers
          	 (we know these lines are not cached, due to the previous
    	  invalidation and no other code touching them in-between)
          4. clean + invalidate buffers
          	 => writes back any modification we may have made during event
    	    processing and ensures that the lines are not in the cache
    	    the next time we enter interrupt processing
    
    Note that with the original sequence, we observe reproducible
    (depending on the cache state: i.e. running dhcp/usb start before will
    upset caches to get us around this) issues in the event processing (a
    fatal synchronous abort in dwc3_gadget_uboot_handle_interrupt on the
    first time interrupt handling is invoked) when running USB mass
    storage emulation on our RK3399-Q7 with data-caches on.
    Signed-off-by: 's avatarPhilipp Tomsich <philipp.tomsich@theobroma-systems.com>
    (cherry picked from commit 889239d6)
    ac167da4
Name
Last commit
Last update
Licenses Loading commit data...
api Loading commit data...
arch Loading commit data...
board Loading commit data...
cmd Loading commit data...
common Loading commit data...
configs Loading commit data...
disk Loading commit data...
doc Loading commit data...
drivers Loading commit data...
dts Loading commit data...
examples Loading commit data...
fs Loading commit data...
include Loading commit data...
lib Loading commit data...
net Loading commit data...
post Loading commit data...
scripts Loading commit data...
test Loading commit data...
tools Loading commit data...
.checkpatch.conf Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
Kbuild Loading commit data...
Kconfig Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README Loading commit data...
config.mk Loading commit data...
snapshot.commit Loading commit data...