Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9215734rwp; Thu, 20 Jul 2023 01:04:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFVqY0u5lsC2qQkZz/Jkpdu2Qh49QaI7bpiCqoM1FciyYYvxdYHkyTcrTPQcnXEMkWPEXg4 X-Received: by 2002:a17:90b:4a12:b0:261:110e:30c1 with SMTP id kk18-20020a17090b4a1200b00261110e30c1mr6463249pjb.4.1689840240492; Thu, 20 Jul 2023 01:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689840240; cv=none; d=google.com; s=arc-20160816; b=x+gVguh9j58BCc/A3B+Gz3bYXH4fIeq+cKIBy6TPSYzmgsT8pTv33fICVzfG7R0tzZ MCdtNOginDs8khK8/G8hJuzhEG+xUF7NXTx+pp/l7nPOrWQOekfAmZigkb0vAMO4nEqQ YgeP1DOhv1u+7/HAlNdQ4I3O8DXaAjsEJqljmXE3iyMZZJTCU+lUxZ66km/m/33WziIA wsZC0Fw3CAcYOwcbhO+9yINQTDl9pIc3OPj1b2mOLjrar+/7y3dAJ7nsoP0H+yb4pA9U h/UDNAWPDkJ0XUKftrflnl1D4ly583Ewn7SNwQ+U+6C/igvD9jSpfPMDsQ2gzuQ02xi3 r9+Q== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=QNB/0N9R5M6RtT3MwFaZdQo6B1nBwlY6WJTmqAYEkq8=; fh=K+AqHgYRl0EeFK0LkJF4lWkjRojzETovX4qpZb+Y5UQ=; b=hC/dwrsDMq/taM1UxcWpp5Eddj5Awnuw3zDMkI7ApCn2obZXN7yijMUJyCz6jXf8/L eXNBofnnQuSuHafSqADaG6bvO7m2MIRTrTTZ+PHegbNekryVoQ9hyuWgjJDZ+j6Ehp3Z Lm97xbmlsOhGmyqY6bLrmWebtdG3Y9Nie8/1AhbfxqF0zE5DSFl1Rr5LBtDt3m55LJbb W4SpbDejkh/gO9+uS0CLqwyou/bthtwkGnyJL8XmnByU05eRiyrNSO0xW6kstcBFcGxn KE+ylHYGMTnnyZtKRwbe/BvmVFOaZxvI3v4q0llXEdzXHcVbI4S/i8Sp7TlP5bDQzJ90 ywHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=r9ToG10A; 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=tesarici.cz Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t25-20020a639559000000b0054481da6ee5si341056pgn.418.2023.07.20.01.03.48; Thu, 20 Jul 2023 01:04:00 -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=@tesarici.cz header.s=mail header.b=r9ToG10A; 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=tesarici.cz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbjGTHyR (ORCPT + 99 others); Thu, 20 Jul 2023 03:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjGTHyQ (ORCPT ); Thu, 20 Jul 2023 03:54:16 -0400 Received: from bee.tesarici.cz (bee.tesarici.cz [IPv6:2a03:3b40:fe:2d4::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 179F72128; Thu, 20 Jul 2023 00:54:15 -0700 (PDT) Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 39C4416840B; Thu, 20 Jul 2023 09:54:11 +0200 (CEST) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=none dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1689839651; bh=BJwL8Mo+1mra8+b/CdY/uUP8gohBFG2ZiuHo+xJAYDU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=r9ToG10AhpvW4JM508uc+NskNEr56L4qZdWR6gmLHKXzFc9vG+58URXqJFCt5425C umoUV7zsftWcrElVcdedthF9VDkO4+3bBrDCQuXmLh1KPmziq8R1WnoVI899D7qecV AHvnvQlRfomek07wT+ReyEhXZcbpk3iv0kSeFD5aNam+LwfNmXDZW3DiFy3ctXRhE6 nox25YIAihil1b73FwVDreIAAxgcfmQP6vUBpaxgoyLgYXQ89/NFApOls4l6C9YnmN xSBO+gkN270w/xKtiR/cmS/Jtcbask42UH/KfY9+VRFeZRTjgEGXFGUuG/m2Q8o3WS P7gy5dMRggh0A== Date: Thu, 20 Jul 2023 09:54:10 +0200 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Christoph Hellwig Cc: Petr Tesarik , 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 , 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 Subject: Re: [PATCH v4 1/8] swiotlb: make io_tlb_default_mem local to swiotlb.c Message-ID: <20230720095410.16832a9e@meshulam.tesarici.cz> In-Reply-To: <20230720063744.GA3842@lst.de> References: <7f64111986f4f361a2deb4a1a1b6f588e63a851b.1689261692.git.petr.tesarik.ext@huawei.com> <20230720063744.GA3842@lst.de> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 On Thu, 20 Jul 2023 08:37:44 +0200 Christoph Hellwig wrote: > 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. Oh, you're right! These are the only two places that look at io_tlb_default_mem.nslabs, and all they need is to avoid double initialization. Makes perfect sense to move it inside swiotlb_init_late(). > > +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. Eh, yes. I initially declared the return type as int and then forgot to change the return statement. But as you say, the whole function will go away entirely. Petr T