Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9221663rwp; Thu, 20 Jul 2023 01:10:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlETxqGstkMzRiFDIwCcDUUaHzWB0S/ukHyJH5kD1Bo495ANdJ9EPaLmrLYtTgC7493nbUyT X-Received: by 2002:a19:674a:0:b0:4fb:ca59:42d7 with SMTP id e10-20020a19674a000000b004fbca5942d7mr1813475lfj.33.1689840608738; Thu, 20 Jul 2023 01:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689840608; cv=none; d=google.com; s=arc-20160816; b=wc7l/yWqBnW7ENwsoWC7Lq7D/1dWrh7w72HAcok0xb91eZ+kplZYf+iS0+O611PIaW fdWu4dER2DnVoJ6TnChTe3YOb2wNEwRKAG/oY6RZlwnS3LTa6lBdTNfV5d9PRCvoZN8f y/CUKIdmaZeANLLIjMcbjj//MrYK0jsgGnLmfauQMW3jGwaEy6VM8HapDIhazywTWxkB FF4OULAYDhRJeQPDOIWH6vxX9XpDrw8TUzyvqxK/RRtERGjB1kaeTtTgiAPpjYb89NuC e48+Jl4OGmpZPKY1N79Qjwt+fOx1udqPZgMYYilofoSz4SOqAMa9Dds5ZWODovbP9g/+ APOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=4O/oviQmq+CyQ5ErfHSpdBZ/FRlgj7FD6od4cE4Ds7c=; fh=ZUw18KJiJzFgOIjNQkZuBfwlEPPRV5ZrzvLpNlqPGmo=; b=QdnRgMBxh6Nfk/jieRNu9Wox0COPIxpaOBY+iij1nhfRxiepkhws5ksqDVmfbNXLyN H4F7lB/SJiG1UJin3xjXXOzFk37FdWCbwCR2Uz4FsHSlzm3O9Y8UkQ0hOydERxIGP3bl 1uma81MY14ksaAotyhlaXuxrpG4K/RkP3x5Lhpo5Um2xHeVMjHPfya6gbqaoJK4hot7p 4xxCsZsgjunpXttIuJg5e+ZraWwTyst6RgXIrZTt3z+qnGbJJa86uuImLXLZjsv1Yc6p fATm9ad9TrdN652lqitR9E2WXCiYutoqGvCroUUnxQEVIGyOS/VqRArGIKpGa1fNpf1L AVlg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k22-20020a05640212d600b00521656f8555si471638edx.563.2023.07.20.01.09.44; Thu, 20 Jul 2023 01:10:08 -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 S231367AbjGTGoQ (ORCPT + 99 others); Thu, 20 Jul 2023 02:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbjGTGoB (ORCPT ); Thu, 20 Jul 2023 02:44:01 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40A132736; Wed, 19 Jul 2023 23:43:32 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 6AB1267373; Thu, 20 Jul 2023 08:37:44 +0200 (CEST) Date: Thu, 20 Jul 2023 08:37:44 +0200 From: Christoph Hellwig To: Petr Tesarik Cc: Stefano Stabellini , Russell King , Thomas Bogendoerfer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Greg Kroah-Hartman , "Rafael J. Wysocki" , Juergen Gross , Oleksandr Tyshchenko , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Petr Tesarik , Jonathan Corbet , Andy Shevchenko , Hans de Goede , James Seo , James Clark , Kees Cook , "moderated list:XEN HYPERVISOR ARM" , "moderated list:ARM PORT" , open list , "open list:MIPS" , "open list:XEN SWIOTLB SUBSYSTEM" , Roberto Sassu , Kefeng Wang , petr@tesarici.cz Subject: Re: [PATCH v4 1/8] swiotlb: make io_tlb_default_mem local to swiotlb.c Message-ID: <20230720063744.GA3842@lst.de> References: <7f64111986f4f361a2deb4a1a1b6f588e63a851b.1689261692.git.petr.tesarik.ext@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f64111986f4f361a2deb4a1a1b6f588e63a851b.1689261692.git.petr.tesarik.ext@huawei.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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 On Thu, Jul 13, 2023 at 05:23:12PM +0200, Petr Tesarik wrote: > From: Petr Tesarik > > 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 > --- > 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.