mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yisheng Xie <xieyisheng1@huawei.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Bjorn Helgaas <bhelgaas@google.com>, Len Brown <lenb@kernel.org>,
	Linux PCI <linux-pci@vger.kernel.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Hanjun Guo <guohanjun@huawei.com>, "Jon Masters" <jcm@redhat.com>,
	Toshi Kani <toshi.kani@hpe.com>, <tanxiaojun@huawei.com>,
	Zhou Wang <wangzhou1@hisilicon.com>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Hanjun Guo <hanjun.guo@linaro.org>
Subject: Re: [PATCH v2 1/2] PCI ACPI: Avoid panic when PCI IO resource's size is not page aligned
Date: Wed, 9 May 2018 11:46:50 +0800	[thread overview]
Message-ID: <31dd8592-635c-ec88-2734-2fa9d4ce373e@huawei.com> (raw)
In-Reply-To: <CAJZ5v0h4DLNBJz1QmgmCitj2_UfMBLxboZ2i9rpFZ4+qZPf+eA@mail.gmail.com>

Hi Rafael,

On 2018/5/9 5:20, Rafael J. Wysocki wrote:
> On Mon, May 7, 2018 at 10:06 AM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
>>
>>
>> On 2018/5/1 17:28, Rafael J. Wysocki wrote:
>>>>  drivers/acpi/pci_root.c | 2 +-
>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
>>>>> index 6fc204a..b758ca3 100644
>>>>> --- a/drivers/acpi/pci_root.c
>>>>> +++ b/drivers/acpi/pci_root.c
>>>>> @@ -746,7 +746,7 @@ static void acpi_pci_root_remap_iospace(struct resource_entry *entry)
>>>>>            goto err;
>>>>>
>>>>>    res->start = port;
>>>>> -  res->end = port + length - 1;
>>>>> +  res->end = PAGE_ALIGN(port + length) - 1;
>>> Shouldn't pci_remap_iospace() sanitize its arguments instead?
>>
>> Yeah, I thought that pci_remap_iospace() will be called at many place, and presently I
>> had not seen any problem at other place except acpi_pci_root_remap_iospace(). Anyway,
>> sanitize arguments in pci_remap_iospace() can resolve the problem more thoroughly, but
>> should more common, right?
>>
>> Therefore, is the follow change ok from your point of view?
>>
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index e597655..8607298 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -3527,6 +3527,9 @@ int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
>>         if (res->end > IO_SPACE_LIMIT)
>>                 return -EINVAL;
>>
>> +       if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
>> +               return -EINVAL;
>> +
>>         return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
>>                                   pgprot_device(PAGE_KERNEL));
>>  #else
> 
> I'd rather apply PAGE_ALIGN() to the arguments of ioremap_page_range()
> and call it anyway.  It will fail if the mapping cannot be created.
> 
Hmm, here is a corner case which take 64k page size as an example:
 step 1. someone call pci_remap_iospace() with res:
		res->start 0x1000, resource_size(res) 0x1000
	after PAGE_ALIGN(), the arguments of ioremap_page_range() will be
		addr: (PCI_IOBASE + PAGE_SIZE), end: (PCI_IOBASE + 2*PAGE_SIZE)
	and ioremap_page_range will be ok.

 step 2. another one call pci_remap_iospace() with res:
		res->start 0x2000, resource_size(res) 0x1000
	after PAGE_ALIGN(), the arguments of ioremap_page_range() also will be:
		addr: (PCI_IOBASE + PAGE_SIZE), end: (PCI_IOBASE + 2*PAGE_SIZE)
	then ioremap_page_range() will also trigger BUG_ON(!pte_none(*pte));
	for the pte is not none after step 1, right?

 ps, if let addr = vaddr && PAGE_MASK, above case seems also will trigger BUG_ON.

Actually, I am not sure whether the above case is exist in real system.

Thanks
Yisheng

> .
> 

      reply	other threads:[~2018-05-09  3:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-31  7:12 Yisheng Xie
2018-03-31  7:12 ` [PATCH v2 2/2] PCI: Check phys_addr for pci_remap_iospace Yisheng Xie
2018-04-19  8:03 ` [PATCH v2 1/2] PCI ACPI: Avoid panic when PCI IO resource's size is not page aligned Yisheng Xie
2018-05-01  9:28 ` Rafael J. Wysocki
2018-05-07  8:06   ` Yisheng Xie
2018-05-08 21:20     ` Rafael J. Wysocki
2018-05-09  3:46       ` Yisheng Xie [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=31dd8592-635c-ec88-2734-2fa9d4ce373e@huawei.com \
    --to=xieyisheng1@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=guohanjun@huawei.com \
    --cc=hanjun.guo@linaro.org \
    --cc=jcm@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=sudeep.holla@arm.com \
    --cc=tanxiaojun@huawei.com \
    --cc=toshi.kani@hpe.com \
    --cc=wangzhou1@hisilicon.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®