[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230720063744.GA3842@lst.de>
Date: Thu, 20 Jul 2023 08:37:44 +0200
From: Christoph Hellwig <hch@....de>
To: Petr Tesarik <petrtesarik@...weicloud.com>
Cc: Stefano Stabellini <sstabellini@...nel.org>,
Russell King <linux@...linux.org.uk>,
Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Juergen Gross <jgross@...e.com>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@...m.com>,
Christoph Hellwig <hch@....de>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Robin Murphy <robin.murphy@....com>,
Petr Tesarik <petr.tesarik.ext@...wei.com>,
Jonathan Corbet <corbet@....net>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Hans de Goede <hdegoede@...hat.com>,
James Seo <james@...iv.tech>,
James Clark <james.clark@....com>,
Kees Cook <keescook@...omium.org>,
"moderated list:XEN HYPERVISOR ARM" <xen-devel@...ts.xenproject.org>,
"moderated list:ARM PORT" <linux-arm-kernel@...ts.infradead.org>,
open list <linux-kernel@...r.kernel.org>,
"open list:MIPS" <linux-mips@...r.kernel.org>,
"open list:XEN SWIOTLB SUBSYSTEM" <iommu@...ts.linux.dev>,
Roberto Sassu <roberto.sassu@...weicloud.com>,
Kefeng Wang <wangkefeng.wang@...wei.com>, petr@...arici.cz
Subject: Re: [PATCH v4 1/8] swiotlb: make io_tlb_default_mem local to
swiotlb.c
On Thu, Jul 13, 2023 at 05:23:12PM +0200, Petr Tesarik wrote:
> From: Petr Tesarik <petr.tesarik.ext@...wei.com>
>
> SWIOTLB implementation details should not be exposed to the rest of the
> kernel. This will allow to make changes to the implementation without
> modifying non-swiotlb code.
>
> To avoid breaking existing users, provide helper functions for the few
> required fields.
>
> As a bonus, using a helper function to initialize struct device allows to
> get rid of an #ifdef in driver core.
>
> Signed-off-by: Petr Tesarik <petr.tesarik.ext@...wei.com>
> ---
> arch/arm/xen/mm.c | 2 +-
> arch/mips/pci/pci-octeon.c | 2 +-
> arch/x86/kernel/pci-dma.c | 2 +-
> drivers/base/core.c | 4 +---
> drivers/xen/swiotlb-xen.c | 2 +-
> include/linux/swiotlb.h | 25 +++++++++++++++++++++++-
> kernel/dma/swiotlb.c | 39 +++++++++++++++++++++++++++++++++++++-
> 7 files changed, 67 insertions(+), 9 deletions(-)
>
> diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
> index 3d826c0b5fee..0f32c14eb786 100644
> --- a/arch/arm/xen/mm.c
> +++ b/arch/arm/xen/mm.c
> @@ -125,7 +125,7 @@ static int __init xen_mm_init(void)
> return 0;
>
> /* we can work with the default swiotlb */
> - if (!io_tlb_default_mem.nslabs) {
> + if (!is_swiotlb_allocated()) {
> rc = swiotlb_init_late(swiotlb_size_or_default(),
> xen_swiotlb_gfp(), NULL);
> if (rc < 0)
I'd much rather move the already initialized check into
swiotlb_init_late, which is a much cleaer interface.
> /* we can work with the default swiotlb */
> - if (!io_tlb_default_mem.nslabs) {
> + if (!is_swiotlb_allocated()) {
> int rc = swiotlb_init_late(swiotlb_size_or_default(),
> GFP_KERNEL, xen_swiotlb_fixup);
> if (rc < 0)
.. and would take care of this one as well.
> +bool is_swiotlb_allocated(void)
> +{
> + return !!io_tlb_default_mem.nslabs;
Nit: no need for the !!, we can rely on the implicit promotion to
bool. But with the suggestion above the need for this helper
should go away anyway.
Powered by blists - more mailing lists