• Thomas Gleixner's avatar
    PCI/MSI: Mask all unused MSI-X entries · 7d5ec3d3
    Thomas Gleixner authored
    When MSI-X is enabled the ordering of calls is:
    
      msix_map_region();
      msix_setup_entries();
      pci_msi_setup_msi_irqs();
      msix_program_entries();
    
    This has a few interesting issues:
    
     1) msix_setup_entries() allocates the MSI descriptors and initializes them
        except for the msi_desc:masked member which is left zero initialized.
    
     2) pci_msi_setup_msi_irqs() allocates the interrupt descriptors and sets
        up the MSI interrupts which ends up in pci_write_msi_msg() unless the
        interrupt chip provides its own irq_write_msi_msg() function.
    
     3) msix_program_entries() does not do what the name suggests. It solely
        updates the entries array (if not NULL) and initializes the masked
        member for each MSI descriptor by reading the hardware state and then
        masks the entry.
    
    Obviously this has some issues:
    
     1) The uninitialized masked member of msi_desc prevents the enforcement
        of masking the entry in pci_write_msi_msg() depending on the cached
        masked bit. Aside of that half initialized data is a NONO in general
    
     2) msix_program_entries() only ensures that the actually allocated entries
        are masked. This is wrong as experimentation with crash testing and
        crash kernel kexec has shown.
    
        This limited testing unearthed that when the production kernel had more
        entries in use and unmasked when it crashed and the crash kernel
        allocated a smaller amount of entries, then a full scan of all entries
        found unmasked entries which were in use in the production kernel.
    
        This is obviously a device or emulation issue as the device reset
        should mask all MSI-X table entries, but obviously that's just part
        of the paper specification.
    
    Cure this by:
    
     1) Masking all table entries in hardware
     2) Initializing msi_desc::masked in msix_setup_entries()
     3) Removing the mask dance in msix_program_entries()
     4) Renaming msix_program_entries() to msix_update_entries() to
        reflect the purpose of that function.
    
    As the masking of unused entries has never been done the Fixes tag refers
    to a commit in:
       git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
    
    Fixes: f036d4ea ("[PATCH] ia32 Message Signalled Interrupt support")
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Tested-by: default avatarMarc Zyngier <maz@kernel.org>
    Reviewed-by: default avatarMarc Zyngier <maz@kernel.org>
    Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20210729222542.403833459@linutronix.de
    7d5ec3d3
msi.c 40.8 KB