• Serge Semin's avatar
    nvme-hwmon: kmalloc the NVME SMART log buffer · c94b7f9b
    Serge Semin authored
    Recent commit 52fde2c0 ("nvme: set dma alignment to dword") has
    caused a regression on our platform.
    
    It turned out that the nvme_get_log() method invocation caused the
    nvme_hwmon_data structure instance corruption.  In particular the
    nvme_hwmon_data.ctrl pointer was overwritten either with zeros or with
    garbage.  After some research we discovered that the problem happened
    even before the actual NVME DMA execution, but during the buffer mapping.
    Since our platform is DMA-noncoherent, the mapping implied the cache-line
    invalidations or write-backs depending on the DMA-direction parameter.
    In case of the NVME SMART log getting the DMA was performed
    from-device-to-memory, thus the cache-invalidation was activated during
    the buffer mapping.  Since the log-buffer isn't cache-line aligned, the
    cache-invalidation caused the neighbour data to be discarded.  The
    neighbouring data turned to be the data surrounding the buffer in the
    framework of the nvme_hwmon_data structure.
    
    In order to fix that we need to make sure that the whole log-buffer is
    defined within the cache-line-aligned memory region so the
    cache-invalidation procedure wouldn't involve the adjacent data. One of
    the option to guarantee that is to kmalloc the DMA-buffer [1]. Seeing the
    rest of the NVME core driver prefer that method it has been chosen to fix
    this problem too.
    
    Note after a deeper researches we found out that the denoted commit wasn't
    a root cause of the problem. It just revealed the invalidity by activating
    the DMA-based NVME SMART log getting performed in the framework of the
    NVME hwmon driver. The problem was here since the initial commit of the
    driver.
    
    [1] Documentation/core-api/dma-api-howto.rst
    
    Fixes: 400b6a7b ("nvme: Add hardware monitoring support")
    Signed-off-by: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
    Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
    c94b7f9b
hwmon.c 6.23 KB