Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1495808rwd; Thu, 8 Jun 2023 20:04:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52ssKT1blrCZNy3kopVzsM1d3iA/c6SoHZwTO0WvJu9or6aX+Eo0N/ql4RfCsCMtfBYeiV X-Received: by 2002:a05:6830:1452:b0:6b0:c4ba:4940 with SMTP id w18-20020a056830145200b006b0c4ba4940mr182920otp.21.1686279898699; Thu, 08 Jun 2023 20:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686279898; cv=none; d=google.com; s=arc-20160816; b=ABWpNmhaEEf8LrzP6sAURO0cAlujLi3eFybrWu/p6XGO6/1zYAfggN88P6/98Uu0DM QNgtSPeQjgVRB3ft5GaqXyCGupo4r+7I5DmcnyFZcGC5SNeMKNnuI6my+NMPP0L1BS3o OuXuM9J2CM8x2KvdZ+RgOICDIhQ4PywvQHSA4rmZATrapKIGxQ9D+r9cV5BQuDsyiiVD +k41sZLI7jmcpYEJc4FDMI3+JNddOqOlGN8StWYjPPmFiRv5H05sTzUjOXAGKasGpyjX h3rLjfd05CksiGNA9RDN8Ia7NVX3XVsu0k6DpEap8oULHbYFD02NhAKEcbsbdLmM5KL1 qQtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0oZ88fuJh/7o8hlwqrs6KXeFq2LEuRIT8LJ/ycjJWrc=; b=shFlzNjfDGaNk0GlN90p4j14LM/Kkdvtg/DsGoVOSAITulu3DIAhniRhSuDpN3J9BU hvwYNnkEg5UcSdFYTxvy3w0XzONqfWC2KrjyxMXEJJW1+X+QnLZekexk++uzFgYct1rZ DN4Zjvz7O5MgCqVbFkpWIzEUsdKwJgbZoT6mmlqpVVrmC/UTQ7zCWnewKtP3QOo/8PWd 3IpFw/1l8ND+l7rphSSUkZ15FqFi81iiDoE7n4CpvVGkQN7ljnXnC1VDgVF9HaUHVEoH AOStk4A+SllGyClOs6GxIgFHLqdN9ngU+fMtKeB0zIETDSzBCjSr6KgoYIZOx1H+dSPQ UocQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AqzWx0G5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a637411000000b00547b25ea097si1848477pgc.665.2023.06.08.20.04.43; Thu, 08 Jun 2023 20:04:58 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AqzWx0G5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230521AbjFICaK (ORCPT + 99 others); Thu, 8 Jun 2023 22:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjFICaI (ORCPT ); Thu, 8 Jun 2023 22:30:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E0E184; Thu, 8 Jun 2023 19:30:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1E95C65328; Fri, 9 Jun 2023 02:30:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 776C5C4339B; Fri, 9 Jun 2023 02:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686277806; bh=lFODl6QKIv49kcz8dOO9K/tHqzGHNLQJ2rXjJtuw2EE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AqzWx0G5buMX45W3K+sM4xQ/cEdkRfSHIpus62lBGCmx2MShFQ0rEnv36+fS6J0Cd QnYq/gfxYlQytVBRJn5y6JjJIf/BOFDnJJQu5N6dr3nfEiqQgtQ94hNYhMcQguPKsc 0nEPiMU0lWEE5DrnxTCxVo3/RDkc5hX9SpB6wMx3iy5OJ9Aa4P5FZIRO1g6Vb2I6VV HLvx93iczcQ2A3oJ//3JHbk8eeHSI0q6w3BPZuSIIM67S83q7hr7fMSq0XSRhGTL6n rgZ4eiQYYvh9N4plgimMnETrAs9d3gyss19lOep5jGo51fzlHsTETykt/aSRMzgB4G SjcPmYzrZfYEw== Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-51491b87565so2236817a12.1; Thu, 08 Jun 2023 19:30:06 -0700 (PDT) X-Gm-Message-State: AC+VfDyYTRV88pSVzvY4KFplSH7VtkIH3CF1qmvCTR4kZH/qFBZ+Rr1F XEwala64KA1eI3zlFb+ZRugemiwPM7RG3MP+iX8= X-Received: by 2002:a17:907:7207:b0:957:17c5:8705 with SMTP id dr7-20020a170907720700b0095717c58705mr302799ejc.51.1686277804594; Thu, 08 Jun 2023 19:30:04 -0700 (PDT) MIME-Version: 1.0 References: <20230609022047.2195689-1-maobibo@loongson.cn> In-Reply-To: <20230609022047.2195689-1-maobibo@loongson.cn> From: Huacai Chen Date: Fri, 9 Jun 2023 10:29:52 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4] PCI: Align pci memory space base address with page size To: Bibo Mao Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , loongarch@lists.linux.dev, loongson-kernel@lists.loongnix.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Bibo, On Fri, Jun 9, 2023 at 10:20=E2=80=AFAM Bibo Mao wrot= e: > > 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= , > here extra option PCI_MEMRES_PAGE_ALIGN is added, it can be enabled by > different architectures. > > Signed-off-by: Bibo Mao > --- > Change history > v4: add extra kernel option PCI_MEMRES_PAGE_ALIGN to set memory resource > page aligned. > > v3: move alignment requirement to generic pci code > > v2: add pci resource alignment requirement in arch specified function > pcibios_align_resource on arm64/LoongArch platforms > > --- > arch/loongarch/Kconfig | 1 + > drivers/pci/Kconfig | 3 +++ > drivers/pci/setup-res.c | 7 +++++++ > 3 files changed, 11 insertions(+) > > diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig > index d38b066fc931..65b2f6ba9f8e 100644 > --- a/arch/loongarch/Kconfig > +++ b/arch/loongarch/Kconfig > @@ -142,6 +142,7 @@ config LOONGARCH > select PCI_LOONGSON > select PCI_MSI_ARCH_FALLBACKS > select PCI_QUIRKS > + select PCI_MEMRES_PAGE_ALIGN > select PERF_USE_VMALLOC > select RTC_LIB > select SMP > diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig > index 9309f2469b41..9be5f85ff9dc 100644 > --- a/drivers/pci/Kconfig > +++ b/drivers/pci/Kconfig > @@ -128,6 +128,9 @@ config PCI_LOCKLESS_CONFIG > config PCI_BRIDGE_EMUL > bool > > +config PCI_MEMRES_PAGE_ALIGN > + bool > + > config PCI_IOV > bool "PCI IOV support" > select PCI_ATS > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c > index 967f9a758923..6ad76734a670 100644 > --- a/drivers/pci/setup-res.c > +++ b/drivers/pci/setup-res.c > @@ -339,6 +339,13 @@ int pci_assign_resource(struct pci_dev *dev, int res= no) > return -EINVAL; > } > > +#ifdef CONFIG_PCI_MEMRES_PAGE_ALIGN > + /* > + * force minimum page alignment for vfio pci usage > + */ > + if (res->flags & IORESOURCE_MEM) > + align =3D max_t(resource_size_t, PAGE_SIZE, align); > +#endif Does this really have its effect? The common version of pcibios_align_resource() simply returns res->start, and doesn't care about the 'align' parameter. Huacai > size =3D resource_size(res); > ret =3D _pci_assign_resource(dev, resno, size, align); > > -- > 2.27.0 >