Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp56226rdb; Thu, 25 Jan 2024 08:07:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHp5gbi8zJEc8/dYUlBxKwNo87wmBLHoatk0/HQpjcySiFr7tN+YJATnRumpfFL70W1sAsg X-Received: by 2002:a05:6402:1b19:b0:55d:572:3d7e with SMTP id by25-20020a0564021b1900b0055d05723d7emr411830edb.19.1706198835857; Thu, 25 Jan 2024 08:07:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706198835; cv=pass; d=google.com; s=arc-20160816; b=XT56bU9QdE4Pg7lcdKt8AwVNEfObKYip++Zc+oQSBTJUJBKr1JyLFekwBty5bJDaZd Bthuj8gr+EMzx3yFB5KNb32DJmGrkCc0q+mjsendNFOrIkCCLL4Dp8U891s97HhVLbLk XxCYMz5EHv442rhmVJNDsBy6GDg82bmlt/roiy0cjsejHfnq7uW32YVm0WWMSMpqXChq yjHkLIskHfGF3FemsveGtm/usdWKFLztmJHA/C9EIMbCIFVd5kE7a6kwjaoYviZvaWjF s37H0NWEoJeQU9Ux7Om+m/QedzTYIHNqHYpdyJhCqRWhfHDdiH/QhLJb/jtwA/DYcnYn b/og== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=mxpNg8/1ezqQlLi/nL6WpBh0YQxmcWqg4k8WpwRk6L8=; fh=gmbNRG0OcemrbvV2w5o13xFk2yOSgIrRBSO6CZENfco=; b=nYt/qTAw4BJAaN9ugMxQxc/IMaVXXj/jUTWBWZvoYLxuGO0pDShgeyyCAufKHWzClz wbNaB9LrVD+bkeVD/e+/+264eJazFWF8aUsiAClHZ8OJ95DLQLVfpZ/vn0VpZfn2xXnm G0UiZlwRZ+304cxGPRnsSTt/tVAreRqfVpZKTjcvkZAZ/llAkougc69Y8URtfzOJDcBI 3KEPnX8tx4MxK4B/17mOJzkSRjlKzri/foiBE5gXX66vOgdJ0JFDRGm/OgDSv16O2p3Z gwOG0OLbl/ahR9zOCte8mgi2/QeY9IqlZNRdm5/cSNUh0+xOl/RYJGgR5OWxCtbEL3xH FrBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rt7u9uRp; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-38865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i2-20020a50d742000000b005536465920asi6391574edj.389.2024.01.25.08.07.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 08:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rt7u9uRp; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-38865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 63A961F2725F for ; Thu, 25 Jan 2024 16:07:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2841874E21; Thu, 25 Jan 2024 16:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Rt7u9uRp" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8449074E0F for ; Thu, 25 Jan 2024 16:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706198823; cv=none; b=fTeywrnaQWIlXWobuPX6hkhCy/WwaGKLSh94gtoW1xD56/ZeZHvvbWbBE6iFvKxyv14NwyAxawrT965J8FOc5LNuBftA22A+adjY9QK6Yw+52iiJHEZNtkFSotWjf1YhX0iHsRZvYpOjbPwzppic92NU44C/2rvHO4sSs5g8UD4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706198823; c=relaxed/simple; bh=mxpNg8/1ezqQlLi/nL6WpBh0YQxmcWqg4k8WpwRk6L8=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=r7ZSDRXXJHmbrFczaqQoYg63Jr7ZOUA+nzojBfB05DHvPyEkJpdb54m3lYLlsu6DIk90UGG8rKFieqzrGR8GURztqzNkHhyQBGG7iIGEhLC8hTcVJsp9bq3IImh/ORMaQjNMB5oIqGZ/wrokcFSCmzIp1fvQ+D+BO8ANBPcXgYY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Rt7u9uRp; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706198820; 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=mxpNg8/1ezqQlLi/nL6WpBh0YQxmcWqg4k8WpwRk6L8=; b=Rt7u9uRpmwT9muGuItyUareE/N6aBdfVNWM69ZaH0WM4673/JLrKNorvtX62Ub/sx/HGfl 6EYC8zjpllhEuvS8zAbH6zq0sUMYMy2yFigSQB776ZVmbSCmBU6Up5UabfQeD0VDlaXMSP w+P0pkSUovF+Pm6jPtYuXXyUYVhVrAQ= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-q04NxI3GOTWa-RKgXp8z9g-1; Thu, 25 Jan 2024 11:06:56 -0500 X-MC-Unique: q04NxI3GOTWa-RKgXp8z9g-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-50e743156d0so1495799e87.1 for ; Thu, 25 Jan 2024 08:06:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706198813; x=1706803613; 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=mxpNg8/1ezqQlLi/nL6WpBh0YQxmcWqg4k8WpwRk6L8=; b=K1QJxZAnoOf0WNM81waKzdQvuQXhinIIMTlskrHqGrdv0xzZbXHzoKB3OxVwXnwF+A yBooxZukN6PDDjR7XJfLjIGFzifEbsw/qci8FRog75lzsyEBp07q1PwB1+sR03Yhkwp4 jxHOxvlZ5V/0TL2Yko250Fu1pOCxGWSavDvxB98+O1sSHM0b5SJyY+2cC7n03+pa49xU XX4nAk4sO+gR601uhU6gqNtTlvFZrpki54gUd8LZSIAFJfF/5gyHmXGCpJ/UcIJIg+Jw bBTNTNz77DvtNtEq1uEvHjLAYxX7QJMTXu5nSkW/pJsab/bqD0JpAsiJM1ScAnYxDKr6 1WxQ== X-Gm-Message-State: AOJu0YyxtmJedbCGuChTyl4l5F4iIbvse922oLphBq/StNCnztruYhDD QabAHo6eBOhhm/ePQZHmBRwkcZLUmGbWw7fqjtB98R48dXLdo48AzRTKH1mIkYO2Hh3ZZLLPFSt V1+snvBHs0BvxZ+RQFbkOJxxLhmtd1AmMjpL4z0Eia+iE34Tx61HdHw5e3qSM7A== X-Received: by 2002:a05:6512:60c:b0:50e:7f87:f5aa with SMTP id b12-20020a056512060c00b0050e7f87f5aamr12423lfe.3.1706198812931; Thu, 25 Jan 2024 08:06:52 -0800 (PST) X-Received: by 2002:a05:6512:60c:b0:50e:7f87:f5aa with SMTP id b12-20020a056512060c00b0050e7f87f5aamr12394lfe.3.1706198812557; Thu, 25 Jan 2024 08:06:52 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-u.redhat.com. [149.14.88.27]) by smtp.gmail.com with ESMTPSA id je1-20020a05600c1f8100b0040e5cf9a6c7sm3073530wmb.13.2024.01.25.08.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 08:06:52 -0800 (PST) Message-ID: <13319e46cf2a8caa0b397ef67db7d406261a64b0.camel@redhat.com> Subject: Re: [PATCH v5 RESEND 1/5] lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() From: Philipp Stanner To: Bjorn Helgaas Cc: Bjorn Helgaas , Arnd Bergmann , Johannes Berg , Randy Dunlap , NeilBrown , John Sanpe , Kent Overstreet , Niklas Schnelle , Dave Jiang , Uladzislau Koshchanka , "Masami Hiramatsu (Google)" , David Gow , Kees Cook , Rae Moar , Geert Uytterhoeven , "wuqiang.matt" , Yury Norov , Jason Baron , Thomas Gleixner , Marco Elver , Andrew Morton , Ben Dooks , dakr@redhat.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, stable@vger.kernel.org, Arnd Bergmann Date: Thu, 25 Jan 2024 17:06:38 +0100 In-Reply-To: <20240123184622.GA322265@bhelgaas> References: <20240123184622.GA322265@bhelgaas> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2024-01-23 at 12:46 -0600, Bjorn Helgaas wrote: > On Thu, Jan 11, 2024 at 09:55:36AM +0100, Philipp Stanner wrote: > > pci_iounmap() in lib/pci_iomap.c is supposed to check whether an > > address > > is within ioport-range IF the config specifies that ioports exist. > > If > > so, the port should be unmapped with ioport_unmap(). If not, it's a > > generic MMIO address that has to be passed to iounmap(). > >=20 > > The bugs are: > > =C2=A0 1. ioport_unmap() is missing entirely, so this function will > > never > > =C2=A0=C2=A0=C2=A0=C2=A0 actually unmap a port. >=20 > The preceding comment suggests that in this default implementation, > the ioport does not need unmapping, and it wasn't something it was > supposed to do but just failed to do: >=20 > =C2=A0* NOTE! This default implementation assumes that if the architectur= e > =C2=A0* support ioport mapping (HAS_IOPORT_MAP), the ioport mapping will > =C2=A0* be fixed to the range [ PCI_IOBASE, PCI_IOBASE+IO_SPACE_LIMIT [, > =C2=A0* and does not need unmapping with 'ioport_unmap()'. > =C2=A0* > =C2=A0* If you have different rules for your architecture, you need to > =C2=A0* implement your own pci_iounmap() that knows the rules for where > =C2=A0* and how IO vs MEM get mapped. >=20 > Almost all ioport_unmap() implementations are empty, so in most cases > it's a no-op (parisc is an exception). That sounds correct. >=20 > I'm happy to add the ioport_unmap() even just for symmetry, but if we > do, I think we should update or remove that comment. Yes, I think it's the right way: either all architectures should provide ioport_unmap(), empty or not, or all should use a centralized PCI function I can remove the wrong statement. >=20 > > =C2=A0 2. the #ifdef for the ioport-ranges accidentally also guards > > =C2=A0=C2=A0=C2=A0=C2=A0 iounmap(), potentially compiling an empty func= tion. This would > > =C2=A0=C2=A0=C2=A0=C2=A0 cause the mapping to be leaked. > >=20 > > Implement the missing call to ioport_unmap(). > >=20 > > Move the guard so that iounmap() will always be part of the > > function. >=20 > I think we should fix this bug in a separate patch because the > ioport_unmap() is much more subtle and doesn't need to be complicated > with this fix. If we agree that one is a bug and the other isn't, then ACK, we should probably split it. >=20 > > CC: # v5.15+ > > Fixes: 316e8d79a095 ("pci_iounmap'2: Electric Boogaloo: try to make > > sense of it all") > > Reported-by: Danilo Krummrich >=20 > Is there a URL we can include for Danilo's report?=C2=A0 I found > https://lore.kernel.org/all/a6ef92ae-0747-435b-822d-d0229da4683c@redhat.c= om/ > , > but I'm not sure that's the right part of the conversation. He pointed out it's a bug in an offlist conversation with me. The link you provided is his only public statement about the topic. The Reported-by served more acknowledging the contribution than issue- tracking P. >=20 > > Suggested-by: Arnd Bergmann > > Signed-off-by: Philipp Stanner > > Reviewed-by: Arnd Bergmann > > --- > > =C2=A0lib/pci_iomap.c | 6 ++++-- > > =C2=A01 file changed, 4 insertions(+), 2 deletions(-) > >=20 > > diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c > > index ce39ce9f3526..6e144b017c48 100644 > > --- a/lib/pci_iomap.c > > +++ b/lib/pci_iomap.c > > @@ -168,10 +168,12 @@ void pci_iounmap(struct pci_dev *dev, void > > __iomem *p) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0uintptr_t start =3D (ui= ntptr_t) PCI_IOBASE; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0uintptr_t addr =3D (uin= tptr_t) p; > > =C2=A0 > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (addr >=3D start && addr = < start + IO_SPACE_LIMIT) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (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=A0ioport_unmap(p); > > =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(p); > > =C2=A0} > > =C2=A0EXPORT_SYMBOL(pci_iounmap); > > =C2=A0 > > --=20 > > 2.43.0 > >=20 >=20