From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E47C433F5 for ; Wed, 27 Oct 2021 12:01:46 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D3A3B6109E for ; Wed, 27 Oct 2021 12:01:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D3A3B6109E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=oderland.se Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.216902.376681 (Exim 4.92) (envelope-from ) id 1mfhca-0003JX-4G; Wed, 27 Oct 2021 12:01:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 216902.376681; Wed, 27 Oct 2021 12:01:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mfhca-0003JO-0R; Wed, 27 Oct 2021 12:01:32 +0000 Received: by outflank-mailman (input) for mailman id 216902; Wed, 27 Oct 2021 12:01:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mfhcY-0003J5-Hp for xen-devel@lists.xenproject.org; Wed, 27 Oct 2021 12:01:30 +0000 Received: from office.oderland.com (unknown [91.201.60.5]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 993a5837-de9b-4c34-bf53-82085f17bb45; Wed, 27 Oct 2021 12:01:28 +0000 (UTC) Received: from [193.180.18.161] (port=57004 helo=[10.137.0.14]) by office.oderland.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mfhcV-00DPNq-Bn; Wed, 27 Oct 2021 14:01:27 +0200 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 993a5837-de9b-4c34-bf53-82085f17bb45 Message-ID: <89d6c2f4-4d00-972f-e434-cb1839e78598@oderland.se> Date: Wed, 27 Oct 2021 14:01:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Thunderbird/93.0 Subject: Re: [PATCH] PCI/MSI: Move non-mask check back into low level accessors Content-Language: en-US From: Josef Johansson To: Thomas Gleixner , David Woodhouse Cc: boris.ostrovsky@oracle.com, helgaas@kernel.org, jgross@suse.com, linux-pci@vger.kernel.org, maz@kernel.org, xen-devel@lists.xenproject.org, Jason Andryuk References: <90277228-cf14-0cfa-c95e-d42e7d533353@oderland.se> <20211025012503.33172-1-jandryuk@gmail.com> <87fssmg8k4.ffs@tglx> <87cznqg5k8.ffs@tglx> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - office.oderland.com X-AntiAbuse: Original Domain - lists.xenproject.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - oderland.se X-Get-Message-Sender-Via: office.oderland.com: authenticated_id: josjoh@oderland.se X-Authenticated-Sender: office.oderland.com: josjoh@oderland.se On 10/27/21 11:54, Josef Johansson wrote: > On 10/27/21 11:50, Thomas Gleixner wrote: >> The recent rework of PCI/MSI[X] masking moved the non-mask checks from the >> low level accessors into the higher level mask/unmask functions. >> >> This missed the fact that these accessors can be invoked from other places >> as well. The missing checks break XEN-PV which sets pci_msi_ignore_mask and >> also violates the virtual MSIX and the msi_attrib.maskbit protections. >> >> Instead of sprinkling checks all over the place, lift them back into the >> low level accessor functions. To avoid checking three different conditions >> combine them into one property of msi_desc::msi_attrib. >> >> Reported-by: Josef Johansson >> Fixes: fcacdfbef5a1 ("PCI/MSI: Provide a new set of mask and unmask functions") >> Signed-off-by: Thomas Gleixner >> Cc: Jason Andryuk >> Cc: Marc Zyngier >> Cc: Bjorn Helgaas >> Cc: linux-pci@vger.kernel.org >> Cc: xen-devel >> Cc: Juergen Gross >> Cc: Boris Ostrovsky >> Cc: David Woodhouse >> --- >> drivers/pci/msi.c | 26 ++++++++++++++------------ >> include/linux/msi.h | 2 +- >> 2 files changed, 15 insertions(+), 13 deletions(-) >> >> --- a/drivers/pci/msi.c >> +++ b/drivers/pci/msi.c >> @@ -148,6 +148,9 @@ static noinline void pci_msi_update_mask >> raw_spinlock_t *lock = &desc->dev->msi_lock; >> unsigned long flags; >> >> + if (!desc->msi_attrib.can_mask) >> + return; >> + >> raw_spin_lock_irqsave(lock, flags); >> desc->msi_mask &= ~clear; >> desc->msi_mask |= set; >> @@ -181,7 +184,8 @@ static void pci_msix_write_vector_ctrl(s >> { >> void __iomem *desc_addr = pci_msix_desc_addr(desc); >> >> - writel(ctrl, desc_addr + PCI_MSIX_ENTRY_VECTOR_CTRL); >> + if (desc->msi_attrib.can_mask) >> + writel(ctrl, desc_addr + PCI_MSIX_ENTRY_VECTOR_CTRL); >> } >> >> static inline void pci_msix_mask(struct msi_desc *desc) >> @@ -200,23 +204,17 @@ static inline void pci_msix_unmask(struc >> >> static void __pci_msi_mask_desc(struct msi_desc *desc, u32 mask) >> { >> - if (pci_msi_ignore_mask || desc->msi_attrib.is_virtual) >> - return; >> - >> if (desc->msi_attrib.is_msix) >> pci_msix_mask(desc); >> - else if (desc->msi_attrib.maskbit) >> + else >> pci_msi_mask(desc, mask); >> } >> >> static void __pci_msi_unmask_desc(struct msi_desc *desc, u32 mask) >> { >> - if (pci_msi_ignore_mask || desc->msi_attrib.is_virtual) >> - return; >> - >> if (desc->msi_attrib.is_msix) >> pci_msix_unmask(desc); >> - else if (desc->msi_attrib.maskbit) >> + else >> pci_msi_unmask(desc, mask); >> } >> >> @@ -484,7 +482,8 @@ msi_setup_entry(struct pci_dev *dev, int >> entry->msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT); >> entry->msi_attrib.is_virtual = 0; >> entry->msi_attrib.entry_nr = 0; >> - entry->msi_attrib.maskbit = !!(control & PCI_MSI_FLAGS_MASKBIT); >> + entry->msi_attrib.can_mask = !pci_msi_ignore_mask && >> + !!(control & PCI_MSI_FLAGS_MASKBIT); >> entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ >> entry->msi_attrib.multi_cap = (control & PCI_MSI_FLAGS_QMASK) >> 1; >> entry->msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec)); >> @@ -495,7 +494,7 @@ msi_setup_entry(struct pci_dev *dev, int >> entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_32; >> >> /* Save the initial mask status */ >> - if (entry->msi_attrib.maskbit) >> + if (entry->msi_attrib.can_mask) >> pci_read_config_dword(dev, entry->mask_pos, &entry->msi_mask); >> >> out: >> @@ -638,10 +637,13 @@ static int msix_setup_entries(struct pci >> entry->msi_attrib.is_virtual = >> entry->msi_attrib.entry_nr >= vec_count; >> >> + entry->msi_attrib.can_mask = !pci_msi_ignore_mask && >> + !entry->msi_attrib.is_virtual; >> + >> entry->msi_attrib.default_irq = dev->irq; >> entry->mask_base = base; >> >> - if (!entry->msi_attrib.is_virtual) { >> + if (!entry->msi_attrib.can_mask) { >> addr = pci_msix_desc_addr(entry); >> entry->msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL); >> } >> --- a/include/linux/msi.h >> +++ b/include/linux/msi.h >> @@ -148,7 +148,7 @@ struct msi_desc { >> u8 is_msix : 1; >> u8 multiple : 3; >> u8 multi_cap : 3; >> - u8 maskbit : 1; >> + u8 can_mask : 1; >> u8 is_64 : 1; >> u8 is_virtual : 1; >> u16 entry_nr; > Thanks, > I'll test this out ASAP. I'm adding diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 6a5ecee6e567..28d509452958 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -529,10 +529,10 @@ static bool msi_check_reservation_mode(struct irq_domain *domain, /* * Checking the first MSI descriptor is sufficient. MSIX supports - * masking and MSI does so when the maskbit is set. + * masking and MSI does so when the can_mask is set. */ desc = first_msi_entry(dev); - return desc->msi_attrib.is_msix || desc->msi_attrib.maskbit; + return desc->msi_attrib.is_msix || desc->msi_attrib.can_mask; } int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,