Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp665102rdb; Tue, 23 Jan 2024 10:47:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcZX+gviJdvk7cCZ35ucj6geci+3Hi6df/eAvseWT5TvjDu25fqKivgOCP7N3HZhprFUij X-Received: by 2002:a05:6402:1d83:b0:55c:9c5c:45c3 with SMTP id dk3-20020a0564021d8300b0055c9c5c45c3mr176970edb.5.1706035638295; Tue, 23 Jan 2024 10:47:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706035638; cv=pass; d=google.com; s=arc-20160816; b=MwRMCuEAlkxbSFonNO6JPkO1PsHM0U7Q9kaOyOgLRLxmMQPHfmnN5OXeVcdSvi9MTf gAy+aH108M5Baw9zIq0put5Yu28jHB2DNPS2yd15a+2yjhU170uMuqJa4HKMC9z8IF5p OcqYNVpRwSGAcLrD+AiS65/7DHLJDxesR+tIWq8Z4x2ybVCU4yU17kjTL6DkuD154Ivi a877IEBJ6kqMfgonr3fYY/G7YLfiqgkGT43xq70kJ+q2JPzLMqORwCwajP4QduJuil8a ZkiJnnQrv0kbOyjiiPf8RQYZYyhgeypjm7gHaaggTAnpCPt0w+6Nm8mwaOTi63Z6Mozc Ry/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=PNThdERSuH1m46/viuCv9D+98QpRi6S82ryk8k2z1Wk=; fh=nSvDU1yU6QHYerAhDyPvEVWogF4HX9ozaU3bzLE22ds=; b=OfXrL74f8btlJJvx8CpzhVsBnL4FuZv8SqXLaHYr9W/roD0FfVahxTPutlln0heYmF 8Q9eWs/HqyqBHBmKSqrvHx0t8Qv5ptuc+vwfAwvxaJDw8PWVFhkkAvKfn2wnzWrcsq8r v7s2sNyT3TsEpX8Zl341dprACiCvTy6jw0ULujoVPdvhLSEfZMaSfcPgIpFg8VQuyYGG h6s9D7/AwCECHdzF9ksCEREyrdhJb4iLpGlmXgwzLTVfQwBeI3wAj1NbxNgZtwpeQrqo OSLsgYM9JWQCNQ9MGH4QqdQoLpGdCRL7YiJz33MGDnr7PWDuM/nbgxtt9w10r6Od+iH6 hofA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r++rzSzb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35887-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id en13-20020a056402528d00b00558740d4f83si12634335edb.101.2024.01.23.10.47.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 10:47:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r++rzSzb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35887-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 161A71F2164E for ; Tue, 23 Jan 2024 18:47:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAED382D68; Tue, 23 Jan 2024 18:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r++rzSzb" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F3ABC823A8; Tue, 23 Jan 2024 18:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706035585; cv=none; b=BuK6ob6D3rQhSSs6nbPhB5C4corp9mVDj5WEMfWp4rRGaxeIgtqX+zdWgJ1XPpGp9wb/VaaN/zuDc/k9g0UYfagC9SQVUiEcdZbeJQDeA2EPTZIwMU/htSGe/FVRS0G0oZ+PTsnzI1yzYvtwB4+TfBDh5r7xzYfSJAxXMKlGYy4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706035585; c=relaxed/simple; bh=xlETS4vfNKM7NA6UlEXX0jTXt3XzQwXBLD5Nx+jrOU4=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=naKaqtqBScPjwxf/mUlJFu8mq0jHUyn1mXA5uGc0VFXKumFSqyIUnOOf85KULFuKfg3kXi2lcjKW6QqGEkm/rQMafuf1ppmSbuNx1cBAsj5UXgsuUEatKFX5HwiCO6IIPfnqoX6XQkPBnjeKYNrwBHHqusa5yjjZ92eTaghbZ7g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r++rzSzb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D114C433F1; Tue, 23 Jan 2024 18:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706035584; bh=xlETS4vfNKM7NA6UlEXX0jTXt3XzQwXBLD5Nx+jrOU4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=r++rzSzbdOdCg4Bk0FX/ltZades3wcWMo1/cZDk8BsIK2avLSDgrXRVlu66sDs15D k9AJPhr/bXSZRZkZCSMtl/swPKxnNzYP7gn4ONuOqeD1aVEW2yg4OwVIu+k/mJ0V5p krJMR+aBE/hp+oRzL9ujwC2hhYqZMOXu/oP1uMcmGMZoMLskHgeCBIANhwRT+aDUam nv0iym9WNfKYAmSszPhqcOIvlTk6VjKMJmJFMuHvLfnBdIf0NbbI3m+qnVJPhV2zKi IzcaQcLcfGDGKvUxQW0cQFt/pOLPqir/dfbCKLBahPOjoMGsogXqEkKVSMEpuBl/QO CKjRk1JRsUkFQ== Date: Tue, 23 Jan 2024 12:46:22 -0600 From: Bjorn Helgaas To: Philipp Stanner 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 Subject: Re: [PATCH v5 RESEND 1/5] lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() Message-ID: <20240123184622.GA322265@bhelgaas> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240111085540.7740-2-pstanner@redhat.com> 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(). > > The bugs are: > 1. ioport_unmap() is missing entirely, so this function will never > actually unmap a port. 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: * NOTE! This default implementation assumes that if the architecture * support ioport mapping (HAS_IOPORT_MAP), the ioport mapping will * be fixed to the range [ PCI_IOBASE, PCI_IOBASE+IO_SPACE_LIMIT [, * and does not need unmapping with 'ioport_unmap()'. * * If you have different rules for your architecture, you need to * implement your own pci_iounmap() that knows the rules for where * and how IO vs MEM get mapped. Almost all ioport_unmap() implementations are empty, so in most cases it's a no-op (parisc is an exception). 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. > 2. the #ifdef for the ioport-ranges accidentally also guards > iounmap(), potentially compiling an empty function. This would > cause the mapping to be leaked. > > Implement the missing call to ioport_unmap(). > > Move the guard so that iounmap() will always be part of the function. 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. > CC: # v5.15+ > Fixes: 316e8d79a095 ("pci_iounmap'2: Electric Boogaloo: try to make sense of it all") > Reported-by: Danilo Krummrich Is there a URL we can include for Danilo's report? I found https://lore.kernel.org/all/a6ef92ae-0747-435b-822d-d0229da4683c@redhat.com/, but I'm not sure that's the right part of the conversation. > Suggested-by: Arnd Bergmann > Signed-off-by: Philipp Stanner > Reviewed-by: Arnd Bergmann > --- > lib/pci_iomap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > 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) > uintptr_t start = (uintptr_t) PCI_IOBASE; > uintptr_t addr = (uintptr_t) p; > > - if (addr >= start && addr < start + IO_SPACE_LIMIT) > + if (addr >= start && addr < start + IO_SPACE_LIMIT) { > + ioport_unmap(p); > return; > - iounmap(p); > + } > #endif > + iounmap(p); > } > EXPORT_SYMBOL(pci_iounmap); > > -- > 2.43.0 >