Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1280873rdb; Fri, 1 Dec 2023 11:38:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGleJuaWsILTgYSZpyGo1q7i55+IMWbz3VyyfZvAn3awt2JL8uJPyOaq7SlXDqV0t+NVmeQ X-Received: by 2002:a17:90b:4d92:b0:27c:fc2a:a178 with SMTP id oj18-20020a17090b4d9200b0027cfc2aa178mr7458pjb.9.1701459497523; Fri, 01 Dec 2023 11:38:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701459497; cv=none; d=google.com; s=arc-20160816; b=PWHA19wlwG3f4hgGE0j4POSmLlVuraXXIQ3aeRKzIkYWcda9nzq1IRqW3KReXtbr6r sOC6ocBMERL7NHVKTSCeNQAQKpDQmZRrKiYUBROy+J6mqncX58WnKHX2MZYlAZxYt3jP jBIpSdgKMvq/EBaziugX4Dzdb99McNVXaLwemWUFjyZ4t4Xyt5LSJxfgvood4rOU5tuk KhPb+n+EMhhJfksuNja3G8Lyg8rHP1ZF0E5G3clAM1tZRzJ56PRNYDVFh3Uc8OFwKmhA Dv289gpezPwJXjiBMVp9yx5ZqFhEz6SxswY2s3Ehf1vmnm1aliKi2hzQjnGQgm0AJXcB DpPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=/l/6GujMYtdeF8lFtocp3i7GfbxtCh5Sv6fX69W1IJI=; fh=1qL6YcQmZt0JSCcZwPNK1BIaGbVPdWj0/QPnomlPOr4=; b=JhkwxA9Tr356CrM6FWOUuEYCsfb/W0wpzA2TkqFZo3rcYEe7Vr2XL7VYYvWNX9Wyzt YKe5aT0m7Ns4JPqZR1bntuRHvjFKMdS1A+BJhSnr69LrJpk54enmI/BkewbBpcflWWZa zvfKs1L5xlKMfAGH+nhYXagw4fSaodjb43PWPPK+Y3qGoVkD5e1L6/6WIEsn4397oRnc aQoHfDsxsx2/Qvp6cyToXC+9HDwP/NaXE0leuuIvNbeuPVyjgcgNxzcBOMPpb2GWCR96 DvU6SNZWF8jB6EbItuUMaqT55XnG3oeTrKt6oKNWxlu7jW875XEO/B8brNaygYTAkuzR llBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bApsYd/z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id jx18-20020a17090b46d200b00280ca0a527fsi6148595pjb.114.2023.12.01.11.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 11:38:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bApsYd/z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0565E8411898; Fri, 1 Dec 2023 11:38:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379535AbjLATh7 (ORCPT + 99 others); Fri, 1 Dec 2023 14:37:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbjLATh5 (ORCPT ); Fri, 1 Dec 2023 14:37:57 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BAEA10F2 for ; Fri, 1 Dec 2023 11:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701459482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/l/6GujMYtdeF8lFtocp3i7GfbxtCh5Sv6fX69W1IJI=; b=bApsYd/zRcv3vnSsRsF9VCnII1JwLfPDm+qIX4UBwCRxRcZDH85INYYajfWJICI14Kxii0 vjZvTKc8B4ivHzeRMkVuliJFIjuQfmKC7rGW1DQg46Pn0g+y8/I/YvESLQczkIjM0MikVA 3QQdzpPbioUoKnUzRwvungq6cU4J5+U= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-XSZ2RXx1Osmy53mok_c5Ew-1; Fri, 01 Dec 2023 14:38:01 -0500 X-MC-Unique: XSZ2RXx1Osmy53mok_c5Ew-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-423c28eababso6437061cf.1 for ; Fri, 01 Dec 2023 11:38:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701459481; x=1702064281; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/l/6GujMYtdeF8lFtocp3i7GfbxtCh5Sv6fX69W1IJI=; b=j3J9J6FL/mkbkDKPQ+Q+i9SnpWlakH3AIcMIRWZR28Dg8Sa+qGuglci9Q84xgSeWtR Da/Uot0SGjh7bYpo+DWPDjFY1cGwFqvHSTrb6ApYHLkHXiChC73VWB/WfgclTyGQh6FB wEfgVY9BIAMVm70HxcRunMFgnOo9Yb+q9xdP/o9vw83VomvMSTJdr6Fs1VAZleqD5Kpx MwGDUVQ1fGYL+y8u7cr8TwzGPcsclgtLp8oarHlyYUuTxWDMePFJ7VPe4afTCEQnjAa4 NzQSSeh0xVGnK/qV6/edGYqPAeUh9aICxnop9FVgnnpAADimsAer5qV2NPG/Qy/JU+Uz PyIw== X-Gm-Message-State: AOJu0Yw0I6KshksmK+tG82zxF0U1YhBa73HVSBCk0nSQCZByQYfEu/nB eHvG/tzq/1RsYbzYkuWqFn296MyEII+sngZoeJ1mbM1PsHuzvLEJRdZf9CLcVCV8PpKnuBLTM1e Jupe+QjmjQM6ST6qcRwzKDDRm X-Received: by 2002:a05:622a:1e1a:b0:403:c2fa:83b with SMTP id br26-20020a05622a1e1a00b00403c2fa083bmr31754620qtb.4.1701459480776; Fri, 01 Dec 2023 11:38:00 -0800 (PST) X-Received: by 2002:a05:622a:1e1a:b0:403:c2fa:83b with SMTP id br26-20020a05622a1e1a00b00403c2fa083bmr31754605qtb.4.1701459480410; Fri, 01 Dec 2023 11:38:00 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32e2:4e00:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id v4-20020ac87484000000b00423a5ea2a0asm1746091qtq.20.2023.12.01.11.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 11:38:00 -0800 (PST) Message-ID: Subject: Re: [PATCH v2 4/4] lib, pci: unify generic pci_iounmap() From: Philipp Stanner To: Arnd Bergmann , Bjorn Helgaas , Andrew Morton , Dan Williams , Jonathan Cameron , Jakub Kicinski , Dave Jiang , Uladzislau Koshchanka , Neil Brown , Niklas Schnelle , John Sanpe , Kent Overstreet , Masami Hiramatsu , Kees Cook , David Gow , Yury Norov , "wuqiang.matt" , Jason Baron , Kefeng Wang , Ben Dooks , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Linux-Arch , Arnd Bergmann Date: Fri, 01 Dec 2023 20:37:55 +0100 In-Reply-To: <619ea619-29e4-42fb-9b27-1d1a32e0ee66@app.fastmail.com> References: <20231201121622.16343-1-pstanner@redhat.com> <20231201121622.16343-5-pstanner@redhat.com> <619ea619-29e4-42fb-9b27-1d1a32e0ee66@app.fastmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 11:38:14 -0800 (PST) On Fri, 2023-12-01 at 16:26 +0100, Arnd Bergmann wrote: > On Fri, Dec 1, 2023, at 13:16, Philipp Stanner wrote: > > The implementation of pci_iounmap() is currently scattered over two > > files, drivers/pci/iounmap.c and lib/iomap.c. Additionally, > > architectures can define their own version. > >=20 > > Besides one unified version being desirable in the first place, the > > old > > version in drivers/pci/iounmap.c contained a bug and could leak > > memory > > mappings. The bug was that #ifdef ARCH_HAS_GENERIC_IOPORT_MAP > > should not > > have guarded iounmap(p); in addition to the preceding code. > >=20 > > To have only one version, it's necessary to create a helper > > function, > > iomem_is_ioport(), that tells pci_iounmap() whether the passed > > address > > points to an ioport or normal memory. > >=20 > > iomem_is_ioport() can be provided through three different ways: > > =C2=A0 1. The architecture itself provides it. > > =C2=A0 2. As a default version in include/asm-generic/io.h for those > > =C2=A0=C2=A0=C2=A0=C2=A0 architectures that don't use CONFIG_GENERIC_IO= MAP, but also > > don't > > =C2=A0=C2=A0=C2=A0=C2=A0 provide their own version of iomem_is_ioport()= . > > =C2=A0 3. As a default version in lib/iomap.c for those architectures > > that > > =C2=A0=C2=A0=C2=A0=C2=A0 define and use CONFIG_GENERIC_IOMAP (currently= , only x86 > > really > > =C2=A0=C2=A0=C2=A0=C2=A0 uses the functions in lib/iomap.c) >=20 > I would count 3 as a special case of 1 here. ACK >=20 > > Create a unified version of pci_iounmap() in drivers/pci/iomap.c. > > Provide the function iomem_is_ioport() in include/asm-generic/io.h > > and > > lib/iomap.c. > >=20 > > Remove the CONFIG_GENERIC_IOMAP guard around > > ARCH_WANTS_GENERIC_PCI_IOUNMAP so that configs that set > > CONFIG_GENERIC_PCI_IOMAP without CONFIG_GENERIC_IOMAP still get the > > function. > >=20 > > Fixes: 316e8d79a095 ("pci_iounmap'2: Electric Boogaloo: try to make > > sense of it all") > > Suggested-by: Arnd Bergmann > > Signed-off-by: Philipp Stanner >=20 > Looks good overall. It would be nice to go further than this > and replace all the custom pci_iounmap() variants with custom > iomem_is_ioport() implementations, but that can be a follow-up > along with removing the incorrect or useless 'select GENERIC_IOMAP' > parts. Yes, let's schedule that for a follow up. The way my project plans sound currently, it's likely that I'll stay close to PCI for the next months anyways, so it's likely we'll get an opportunity to pick this up on the run >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0return; > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0iounmap(p); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} > > =C2=A0#endif > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0iounmap(addr); > > =C2=A0} >=20 > I think the bugfix should be a separate patch so we can backport > it to stable kernels. ACK, good idea >=20 > > +#ifndef CONFIG_GENERIC_IOMAP > > +static inline bool iomem_is_ioport(void __iomem *addr) > > +{ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0unsigned long port =3D (unsi= gned long __force)addr; > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0// TODO: do we have to take = IO_SPACE_LIMIT and PCI_IOBASE > > into account > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0// similar as in ioport_map(= ) ? > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (port > MMIO_UPPER_LIMIT) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0return false; > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return true; > > +} >=20 > This has to have the exact logic that was present in the > old pci_iounmap(). For the default version that is currently > in lib/pci_iomap.c, this means something along the linens of OK, I see, so iomem_is_ioport() takes the form derived from lib/pci_iomap.c for asm-generic/io.h, and the form of lib/iomap.c for the one in lib/iomap.c (obviously) >=20 > static inline bool struct iomem_is_ioport(void __iomem *p) > { > #ifdef CONFIG_HAS_IOPORT > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 uintptr_t start =3D (uintptr_t= ) PCI_IOBASE; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 uintptr_t addr =3D (uintptr_t)= p; >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (addr >=3D start && addr < = start + IO_SPACE_LIMIT) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 return true; > #endif > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return false; > } >=20 > > +#else /* CONFIG_GENERIC_IOMAP. Version from lib/iomap.c will be > > used.=20 > > */ > > +bool iomem_is_ioport(void __iomem *addr); > > +#define ARCH_WANTS_GENERIC_IOMEM_IS_IOPORT >=20 > I'm not sure what this macro is for, since it appears to > do the opposite of what its name suggests: rather than > provide the generic version of iomem_is_ioport(), it > skips that and provides a custom one to go with lib/iomap.c Hmmm well now it's getting tricky. This else-branch is the one where CONFIG_GENERIC_IOMAP is actually set. I think we're running into the "generic not being generic now that IA64 has died" problem you were hinting at. If we build for x86 and have CONFIG_GENERIC set, only then do we want iomem_is_ioport() from lib/iomap.c. So the macro serves avoiding a collision between symbols. Because lib/iomap.c might be compiled even if someone else already has defined iomem_is_ioport(). I also don't like it, but it was the least bad solution I could come up with Suggestions? P. >=20 > =C2=A0=C2=A0=C2=A0=C2=A0 Arnd >=20