Message ID | 20230606084539.1694441-1-maobibo@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3247058vqr; Tue, 6 Jun 2023 01:58:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+qw0UsSz6TKe86AJFjC1FL8yqrCAW6t4zQskywN/LnScATILEa4IDbm10b+U6SnbyO/5s X-Received: by 2002:a05:620a:4914:b0:75e:c6a7:3822 with SMTP id ed20-20020a05620a491400b0075ec6a73822mr1360493qkb.43.1686041917113; Tue, 06 Jun 2023 01:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686041917; cv=none; d=google.com; s=arc-20160816; b=Ngc/zzESH+aKWRoSjjlircEHgTClTmANs9pZ2y7k2DRYW2oYrCnD2eVzlYAFr9fpgd nl1gtVhmoZVaHKR6TpCL9sd7P6g0BIa3RYOON97oAGZ3yrbXa6+zODEdbk1rf1Mtxl5J 81y7iD5molu1NxtXTIziwfBM27LzQlYNm44FdphWYfdm2rCbsi5EjYM62mmKoNw9nZsr nwnV+PoJiQiyorRhYOv8TFuQoQAh8XI4ycAaRNuqLNmbTunI1VukCcrvjORiKodknpZ4 lsHmd6HtV8n0ZUsT1avol+/Z+k8K0uRbRx+s4jlccMZVLw35RFWPS2YzRi1+yQiAzQ9a rJWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=GS+ldAfbk9zdCdYxpA0m1ugojBqv73eNg/K9V1a3KmQ=; b=MqUIQAx6oEKqdU0PaSaTgPYaxmRIV5EDw8QG1YFJNyq/MA5vPMmtT3cqHXkFLgjbP5 GsaSL6E+ulH/WjXVK13JlLT546kohLc/6JuO2oDqaFdUzG4wb9+84TAMIdV8qg+u6eWN Lsockxn92gCPyR2/waBNCVSiXCsa6c9BXupC/d3LhnLvnHeZ+hk+E7d/9plrD6zCRlvX Imu4TpvMWvzt5y28BU97KoZMr7qOIqo5vSezSrHzMSU3oByJpBJ60iNwY/9SowVhRTeb dHU/0S96aachYul1sqELY1nGHrkn53brq6iHjMCO2hCaufnD5ZqzWzhixPmy4Zqi46DZ kqXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020ae9c30c000000b0075b26bc1dc8si5411513qkg.656.2023.06.06.01.58.22; Tue, 06 Jun 2023 01:58:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236858AbjFFIpu (ORCPT <rfc822;xxoosimple@gmail.com> + 99 others); Tue, 6 Jun 2023 04:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231545AbjFFIpp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Jun 2023 04:45:45 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 21F6FEA; Tue, 6 Jun 2023 01:45:42 -0700 (PDT) Received: from loongson.cn (unknown [10.2.9.158]) by gateway (Coremail) with SMTP id _____8BxHPA08n5k1g0AAA--.408S3; Tue, 06 Jun 2023 16:45:40 +0800 (CST) Received: from kvm-1-158.loongson.cn (unknown [10.2.9.158]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxTMoz8n5kzAkCAA--.301S2; Tue, 06 Jun 2023 16:45:39 +0800 (CST) From: Bibo Mao <maobibo@loongson.cn> To: Bjorn Helgaas <bhelgaas@google.com> Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>, Will Deacon <will@kernel.org>, loongarch@lists.linux.dev, loongson-kernel@lists.loongnix.cn Subject: [PATCH v3] PCI: Align pci memory space base address with page size Date: Tue, 6 Jun 2023 16:45:39 +0800 Message-Id: <20230606084539.1694441-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxTMoz8n5kzAkCAA--.301S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7AF15tFy7CrWfZFWrGr45Jwc_yoW8Xr13pF W7AanrCry8Gr13Gw4vqw1kuF4fWa1v93yYyrWfAasag3ZrCas2yr1UAFy5Zry8ur47GF1U XFs8tr1fZFWrXagCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Ib4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVWxJr0_GcWln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y 6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnI WIevJa73UjIFyTuYvjxU2MKZDUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767833682742460930?= X-GMAIL-MSGID: =?utf-8?q?1767943089391829616?= |
Series |
[v3] PCI: Align pci memory space base address with page size
|
|
Commit Message
maobibo
June 6, 2023, 8:45 a.m. UTC
Some PCI devices have only 4K memory space size, it is normal in general
machines and aligned with page size. However some architectures which
support different page size, default page size on LoongArch is 16K, and
ARM64 supports page size varying from 4K to 64K. On machines where larger
page size is use, memory space region of two different pci devices may be
in one page. It is not safe with mmu protection, also VFIO pci device
driver requires base address of pci memory space page aligned, so that it
can be memory mapped to qemu user space when it is passed-through to vm.
It consumes more pci memory resource with page size alignment requirement,
it should not be a problem on 64 bit system.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
drivers/pci/setup-res.c | 8 ++++++++
1 file changed, 8 insertions(+)
Comments
Huacai, Although I post this patch, I think this should be arch specified rather than general problem. X86 has solved this problem, arm64 with 64K page size is not popular. However LoongArch has this problem, page size is 16K rather than 4K. It is the problem of LoongArch system rather than generic issue. There is such discussion before: https://patchwork.kernel.org/project/linux-pci/patch/22400b8828ad44ddbccb876cc5ca3b11@FE-MBX1012.de.bosch.com/#19319457 UEFI bios sets pci memory space 4K aligned, however Loongarch kernel rescans the pci bus and reassigns pci memory resource. So it it strange like this, here is pci memory info on my 7A2000 board. root@user-pc:~# lspci -vvv | grep Region Region 5: Memory at e003526e800 (32-bit, non-prefetchable) [size=1K] Region 0: Memory at e003526ec00 (64-bit, non-prefetchable) [size=1K] Regards Bibo, Mao 在 2023/6/6 16:45, Bibo Mao 写道: > Some PCI devices have only 4K memory space size, it is normal in general > machines and aligned with page size. However some architectures which > support different page size, default page size on LoongArch is 16K, and > ARM64 supports page size varying from 4K to 64K. On machines where larger > page size is use, memory space region of two different pci devices may be > in one page. It is not safe with mmu protection, also VFIO pci device > driver requires base address of pci memory space page aligned, so that it > can be memory mapped to qemu user space when it is passed-through to vm. > > It consumes more pci memory resource with page size alignment requirement, > it should not be a problem on 64 bit system. > > Signed-off-by: Bibo Mao <maobibo@loongson.cn> > --- > drivers/pci/setup-res.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c > index 967f9a758923..55440ae0128d 100644 > --- a/drivers/pci/setup-res.c > +++ b/drivers/pci/setup-res.c > @@ -339,6 +339,14 @@ int pci_assign_resource(struct pci_dev *dev, int resno) > return -EINVAL; > } > > +#ifdef CONFIG_64BIT > + /* > + * force minimum page alignment for vfio pci usage > + * supposing there is enough pci memory resource on 64bit system > + */ > + if (res->flags & IORESOURCE_MEM) > + align = max_t(resource_size_t, PAGE_SIZE, align); > +#endif > size = resource_size(res); > ret = _pci_assign_resource(dev, resno, size, align); >
On Tue, Jun 06, 2023 at 06:06:04PM +0800, bibo, mao wrote: > Huacai, > > Although I post this patch, I think this should be arch specified > rather than general problem. X86 has solved this problem, arm64 > with 64K page size is not popular. However LoongArch has this > problem, page size is 16K rather than 4K. It is the problem of > LoongArch system rather than generic issue. I think this is only related to the page size, not to any LoongArch-specific details. If that's the case, I don't think the change should be arch-specific. > There is such discussion before: > https://patchwork.kernel.org/project/linux-pci/patch/22400b8828ad44ddbccb876cc5ca3b11@FE-MBX1012.de.bosch.com/#19319457 > > UEFI bios sets pci memory space 4K aligned, however Loongarch kernel rescans the pci > bus and reassigns pci memory resource. So it it strange like this, here is pci memory info on > my 7A2000 board. > root@user-pc:~# lspci -vvv | grep Region > Region 5: Memory at e003526e800 (32-bit, non-prefetchable) [size=1K] > Region 0: Memory at e003526ec00 (64-bit, non-prefetchable) [size=1K] I guess these BARs are from different devices, and the problem you're pointing out is that both BARs end up in the same 16K page (actually even the same 4K page): (gdb) p/x 0xe003526e800 >> 12 $1 = 0xe003526e (gdb) p/x 0xe003526ec00 >> 12 $2 = 0xe003526e I agree that's a potential issue because a user mmap of the first device also gets access to the BAR of the second device. But it doesn't seem to be a *new* or LoongArch-specific issue. So I *think* the point of this patch is to ensure that BARs of different devices never share a page. Why is that suddenly an issue for LoongArch? Is it only because you see more sharing with 16K pages than other arches do with 4K pages? > 在 2023/6/6 16:45, Bibo Mao 写道: > > Some PCI devices have only 4K memory space size, it is normal in general > > machines and aligned with page size. However some architectures which > > support different page size, default page size on LoongArch is 16K, and > > ARM64 supports page size varying from 4K to 64K. On machines where larger > > page size is use, memory space region of two different pci devices may be > > in one page. It is not safe with mmu protection, also VFIO pci device > > driver requires base address of pci memory space page aligned, so that it > > can be memory mapped to qemu user space when it is passed-through to vm. The minimum memory BAR per spec is 128 bytes (not 4K). You just demonstrated that even with 4K pages, different devices can share a page. > > It consumes more pci memory resource with page size alignment requirement, > > it should not be a problem on 64 bit system. > > > > Signed-off-by: Bibo Mao <maobibo@loongson.cn> > > --- > > drivers/pci/setup-res.c | 8 ++++++++ > > 1 file changed, 8 insertions(+) > > > > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c > > index 967f9a758923..55440ae0128d 100644 > > --- a/drivers/pci/setup-res.c > > +++ b/drivers/pci/setup-res.c > > @@ -339,6 +339,14 @@ int pci_assign_resource(struct pci_dev *dev, int resno) > > return -EINVAL; > > } > > > > +#ifdef CONFIG_64BIT > > + /* > > + * force minimum page alignment for vfio pci usage > > + * supposing there is enough pci memory resource on 64bit system > > + */ > > + if (res->flags & IORESOURCE_MEM) > > + align = max_t(resource_size_t, PAGE_SIZE, align); > > +#endif Why is this under CONFIG_64BIT? That doesn't have anything to do with the BAR size. The only reason I can see is that with CONFIG_64BIT=y, we *might* have more MMIO space to use for BARs. > > size = resource_size(res); > > ret = _pci_assign_resource(dev, resno, size, align);
在 2023/6/7 04:45, Bjorn Helgaas 写道: > On Tue, Jun 06, 2023 at 06:06:04PM +0800, bibo, mao wrote: >> Huacai, >> >> Although I post this patch, I think this should be arch specified >> rather than general problem. X86 has solved this problem, arm64 >> with 64K page size is not popular. However LoongArch has this >> problem, page size is 16K rather than 4K. It is the problem of >> LoongArch system rather than generic issue. > > I think this is only related to the page size, not to any > LoongArch-specific details. If that's the case, I don't think the > change should be arch-specific. > >> There is such discussion before: >> https://patchwork.kernel.org/project/linux-pci/patch/22400b8828ad44ddbccb876cc5ca3b11@FE-MBX1012.de.bosch.com/#19319457 >> >> UEFI bios sets pci memory space 4K aligned, however Loongarch kernel rescans the pci >> bus and reassigns pci memory resource. So it it strange like this, here is pci memory info on >> my 7A2000 board. >> root@user-pc:~# lspci -vvv | grep Region >> Region 5: Memory at e003526e800 (32-bit, non-prefetchable) [size=1K] >> Region 0: Memory at e003526ec00 (64-bit, non-prefetchable) [size=1K] > > I guess these BARs are from different devices, and the problem you're > pointing out is that both BARs end up in the same 16K page (actually > even the same 4K page): > > (gdb) p/x 0xe003526e800 >> 12 > $1 = 0xe003526e > (gdb) p/x 0xe003526ec00 >> 12 > $2 = 0xe003526e > > I agree that's a potential issue because a user mmap of the first > device also gets access to the BAR of the second device. But it > doesn't seem to be a *new* or LoongArch-specific issue. > > So I *think* the point of this patch is to ensure that BARs of > different devices never share a page. Why is that suddenly an issue > for LoongArch? Is it only because you see more sharing with 16K pages > than other arches do with 4K pages? The UEFI BIOS has assigned the PCI device with minimal 4K aligned, I guest Linux kernel on X86/ARM uses resource directly rather than reassign resource again. So there is problem for hot-plug devices, however most hot-plug devices are used for server system and they are high speed devices, PCI resource size is larger than 4K. So it is not obvious on x86/ARM system. However on LoongArch system with page size 16K, the problem is obvious since pci devices with 4K resource size are popular. > >> 在 2023/6/6 16:45, Bibo Mao 写道: >>> Some PCI devices have only 4K memory space size, it is normal in general >>> machines and aligned with page size. However some architectures which >>> support different page size, default page size on LoongArch is 16K, and >>> ARM64 supports page size varying from 4K to 64K. On machines where larger >>> page size is use, memory space region of two different pci devices may be >>> in one page. It is not safe with mmu protection, also VFIO pci device >>> driver requires base address of pci memory space page aligned, so that it >>> can be memory mapped to qemu user space when it is passed-through to vm. > > The minimum memory BAR per spec is 128 bytes (not 4K). You just > demonstrated that even with 4K pages, different devices can share a > page. > >>> It consumes more pci memory resource with page size alignment requirement, >>> it should not be a problem on 64 bit system. >>> >>> Signed-off-by: Bibo Mao <maobibo@loongson.cn> >>> --- >>> drivers/pci/setup-res.c | 8 ++++++++ >>> 1 file changed, 8 insertions(+) >>> >>> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c >>> index 967f9a758923..55440ae0128d 100644 >>> --- a/drivers/pci/setup-res.c >>> +++ b/drivers/pci/setup-res.c >>> @@ -339,6 +339,14 @@ int pci_assign_resource(struct pci_dev *dev, int resno) >>> return -EINVAL; >>> } >>> >>> +#ifdef CONFIG_64BIT >>> + /* >>> + * force minimum page alignment for vfio pci usage >>> + * supposing there is enough pci memory resource on 64bit system >>> + */ >>> + if (res->flags & IORESOURCE_MEM) >>> + align = max_t(resource_size_t, PAGE_SIZE, align); >>> +#endif > > Why is this under CONFIG_64BIT? That doesn't have anything to do with > the BAR size. The only reason I can see is that with CONFIG_64BIT=y, > we *might* have more MMIO space to use for BARs. yes, I assume that there is enough PCI memory resource with 64 bit system, after all it consumes more memory resource and brings out negative effect. For UIO and SRIOV requirements, they are most 64-bit server system, they can suffer from wasting some PCI memory resource. Regards Bibo, Mao > >>> size = resource_size(res); >>> ret = _pci_assign_resource(dev, resno, size, align);
在 2023/6/7 09:42, bibo, mao 写道: > > > 在 2023/6/7 04:45, Bjorn Helgaas 写道: >> On Tue, Jun 06, 2023 at 06:06:04PM +0800, bibo, mao wrote: >>> Huacai, >>> >>> Although I post this patch, I think this should be arch specified >>> rather than general problem. X86 has solved this problem, arm64 >>> with 64K page size is not popular. However LoongArch has this >>> problem, page size is 16K rather than 4K. It is the problem of >>> LoongArch system rather than generic issue. >> >> I think this is only related to the page size, not to any >> LoongArch-specific details. If that's the case, I don't think the >> change should be arch-specific. >> >>> There is such discussion before: >>> https://patchwork.kernel.org/project/linux-pci/patch/22400b8828ad44ddbccb876cc5ca3b11@FE-MBX1012.de.bosch.com/#19319457 >>> >>> UEFI bios sets pci memory space 4K aligned, however Loongarch kernel rescans the pci >>> bus and reassigns pci memory resource. So it it strange like this, here is pci memory info on >>> my 7A2000 board. >>> root@user-pc:~# lspci -vvv | grep Region >>> Region 5: Memory at e003526e800 (32-bit, non-prefetchable) [size=1K] >>> Region 0: Memory at e003526ec00 (64-bit, non-prefetchable) [size=1K] >> >> I guess these BARs are from different devices, and the problem you're >> pointing out is that both BARs end up in the same 16K page (actually >> even the same 4K page): >> >> (gdb) p/x 0xe003526e800 >> 12 >> $1 = 0xe003526e >> (gdb) p/x 0xe003526ec00 >> 12 >> $2 = 0xe003526e >> >> I agree that's a potential issue because a user mmap of the first >> device also gets access to the BAR of the second device. But it >> doesn't seem to be a *new* or LoongArch-specific issue. >> >> So I *think* the point of this patch is to ensure that BARs of >> different devices never share a page. Why is that suddenly an issue >> for LoongArch? Is it only because you see more sharing with 16K pages >> than other arches do with 4K pages? > The UEFI BIOS has assigned the PCI device with minimal 4K aligned, I guest > Linux kernel on X86/ARM uses resource directly rather than reassign resource > again. So there is problem for hot-plug devices, however most hot-plug devices > are used for server system and they are high speed devices, PCI resource size > is larger than 4K. So it is not obvious on x86/ARM system. > > However on LoongArch system with page size 16K, the problem is obvious since > pci devices with 4K resource size are popular. >> >>> 在 2023/6/6 16:45, Bibo Mao 写道: >>>> Some PCI devices have only 4K memory space size, it is normal in general >>>> machines and aligned with page size. However some architectures which >>>> support different page size, default page size on LoongArch is 16K, and >>>> ARM64 supports page size varying from 4K to 64K. On machines where larger >>>> page size is use, memory space region of two different pci devices may be >>>> in one page. It is not safe with mmu protection, also VFIO pci device >>>> driver requires base address of pci memory space page aligned, so that it >>>> can be memory mapped to qemu user space when it is passed-through to vm. >> >> The minimum memory BAR per spec is 128 bytes (not 4K). You just >> demonstrated that even with 4K pages, different devices can share a >> page. >> >>>> It consumes more pci memory resource with page size alignment requirement, >>>> it should not be a problem on 64 bit system. >>>> >>>> Signed-off-by: Bibo Mao <maobibo@loongson.cn> >>>> --- >>>> drivers/pci/setup-res.c | 8 ++++++++ >>>> 1 file changed, 8 insertions(+) >>>> >>>> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c >>>> index 967f9a758923..55440ae0128d 100644 >>>> --- a/drivers/pci/setup-res.c >>>> +++ b/drivers/pci/setup-res.c >>>> @@ -339,6 +339,14 @@ int pci_assign_resource(struct pci_dev *dev, int resno) >>>> return -EINVAL; >>>> } >>>> >>>> +#ifdef CONFIG_64BIT >>>> + /* >>>> + * force minimum page alignment for vfio pci usage >>>> + * supposing there is enough pci memory resource on 64bit system >>>> + */ >>>> + if (res->flags & IORESOURCE_MEM) >>>> + align = max_t(resource_size_t, PAGE_SIZE, align); >>>> +#endif >> >> Why is this under CONFIG_64BIT? That doesn't have anything to do with >> the BAR size. The only reason I can see is that with CONFIG_64BIT=y, >> we *might* have more MMIO space to use for BARs. > yes, I assume that there is enough PCI memory resource with 64 bit system, > after all it consumes more memory resource and brings out negative effect. > For UIO and SRIOV requirements, they are most 64-bit server system, they > can suffer from wasting some PCI memory resource. Can we add extra config option and let architecture selects whether enable it? Here is piece of code: #ifdef CONFIG_PCI_MEMRES_PAGE_ALIGN /* * force minimum page alignment for vfio pci usage */ if (res->flags & IORESOURCE_MEM) align = max_t(resource_size_t, PAGE_SIZE, align); #endif Regards Bibo, Mao > > Regards > Bibo, Mao >> >>>> size = resource_size(res); >>>> ret = _pci_assign_resource(dev, resno, size, align);
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 967f9a758923..55440ae0128d 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -339,6 +339,14 @@ int pci_assign_resource(struct pci_dev *dev, int resno) return -EINVAL; } +#ifdef CONFIG_64BIT + /* + * force minimum page alignment for vfio pci usage + * supposing there is enough pci memory resource on 64bit system + */ + if (res->flags & IORESOURCE_MEM) + align = max_t(resource_size_t, PAGE_SIZE, align); +#endif size = resource_size(res); ret = _pci_assign_resource(dev, resno, size, align);