All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yijing Wang <wangyijing@huawei.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: <linux-pci@vger.kernel.org>, Yinghai Lu <yinghai@kernel.org>
Subject: Re: [PATCH] PCI: Add guard to avoid mapping a invalid msix base address
Date: Wed, 28 Jan 2015 09:42:15 +0800	[thread overview]
Message-ID: <54C83E77.2030800@huawei.com> (raw)
In-Reply-To: <20150127174129.GE4063@google.com>

>> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
>> index fd60806..cd401a2 100644
>> --- a/drivers/pci/msi.c
>> +++ b/drivers/pci/msi.c
>> @@ -699,6 +699,9 @@ static void __iomem *msix_map_region(struct pci_dev *dev, unsigned nr_entries)
>>  	pci_read_config_dword(dev, dev->msix_cap + PCI_MSIX_TABLE,
>>  			      &table_offset);
>>  	bir = (u8)(table_offset & PCI_MSIX_TABLE_BIR);
>> +	if (!pci_resource_flags(dev, bir))
>> +		return NULL;
> 
> This definitely seems like a good idea.  We should not just assume that
> space has been assigned for the BAR.  
> 
> However, I don't think we should test the resource flags for zero.
> reset_resource() does set the flags to zero, but I think that is a mistake.
> The PCI core should retain the information about the type and size of the
> BAR, even if it was unable to assign space for it.  So eventually
> reset_resource() should be reworked somehow.
> 
> I would like reset_resource() to set the IORESOURCE_UNSET bit in the flags.
> That would let %pR print it correctly, e.g., "[mem size 0x1000]".  But I
> don't know what other code in setup-bus.c depends on the assumption that
> "flags == 0" means something important.

Agree, "flags == 0" is not clear enough to point the status of the resource.

> 
> In the meantime, I guess you could do something like:
> 
>   flags = pci_resource_flags(dev, bir);
>   if (!flags || (flags & IORESOURCE_UNSET))
>     return NULL;

OK, I will update it, thanks.

Thanks!
Yijing.

> 
>> +
>>  	table_offset &= PCI_MSIX_TABLE_OFFSET;
>>  	phys_addr = pci_resource_start(dev, bir) + table_offset;
>>  
>> -- 
>> 1.7.1
>>
> 
> .
> 


-- 
Thanks!
Yijing


      reply	other threads:[~2015-01-28  1:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27  8:44 [PATCH] PCI: Add guard to avoid mapping a invalid msix base address Yijing Wang
2015-01-27 17:41 ` Bjorn Helgaas
2015-01-28  1:42   ` Yijing Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54C83E77.2030800@huawei.com \
    --to=wangyijing@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.