Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1033704pxb; Fri, 15 Apr 2022 19:03:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvPual3Nf/uQSM/9OOK+9Ea98GT7KQHeYs+rrKEYM3muCqaQVWbR3zqYKKz6X4MGtQXyj/ X-Received: by 2002:a17:90a:6402:b0:1c9:9377:dd0e with SMTP id g2-20020a17090a640200b001c99377dd0emr1694246pjj.211.1650074625888; Fri, 15 Apr 2022 19:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650074625; cv=none; d=google.com; s=arc-20160816; b=A40hdi0uZa+zZZc3bePeAjPEcTMDu0NswPUWxX2yykmm0oE41RZP5vRKgso05AgqT/ QpoqV/QiaEDfToJ8rjR9uPaHIucPeP2iO7FxMn+dg37Lge2ZnAP1asmeEe/f1OjmYG+V z20MuplyjZaSTOX1QUkS9VO6qz7BMuuDRwZtd4OzeBpvDpNa5DDpCoXJWpyLpx/QMEHa azn3fp8Md7VffF7mHc30dTC+LyjDt4J08oi8F0rPaF87GX3BYXRR285VXjXlKe0uFK1E zDbmLgJ21+NWAK7ceKCkrkaowi2oJ4cpfykW5WFFNL+N4ePLJwP8SzNUVN+7euOZ01RM PpQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=09pALfFpjjHzPVjOVUpyKy1NPmkrkacXz7/PDEeIk84=; b=FStr46eTdoonGpoJca5HpuEn2EthxKZh5CfXICaM++CKK3oHxGcYuy20xUAx+1W8ZK mva6COUz39O1Q2ABySGoaRDHYIkRVmZKnbsH2mv4DId6WJF9OpvIny3ZcqMGlv2fBHe1 sQvIrlqIyZgiUa7c4b7oEshtcMr4HgTTX+IKF359KDHUBjQxyfiUsrEnDJTY0tpneQuT EHgSoO4myw0hHSncMT0RoQKgmnVXVvNvYivIFIft7YJgqEaCvPM6WXu5MrXCJzHPFprE Df5L3cAgEmfwPjuWOZxStc8LhUt4UY9KcaVQOtojTIXFYFQWFBO3SO+C+3GdrJD5g0j4 OWeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b10SPq1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id gp17-20020a17090adf1100b001c5d7e7e0d3si2887558pjb.40.2022.04.15.19.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:03:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b10SPq1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F37AC1D67CF; Fri, 15 Apr 2022 18:23:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347525AbiDNX0A (ORCPT + 99 others); Thu, 14 Apr 2022 19:26:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiDNXZ6 (ORCPT ); Thu, 14 Apr 2022 19:25:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB7EB898B; Thu, 14 Apr 2022 16:23:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EF618B82762; Thu, 14 Apr 2022 23:23:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F750C385A1; Thu, 14 Apr 2022 23:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649978609; bh=7tRW0rE5UC55+IymPZVk7biWmaN3JlYQe5vs90QpsMs=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=b10SPq1xObHjVgrTTzouDybJFobX/tmlHZCE+xPukgETRF7ws5p0ev0y6kBVeoz6G H/VuXi/V02mpfR2XHSshBnOYDSDB4QsHVfq1qZyACpfS4TT4zOyeFKRpAFsQtvjWUI vUfc0+krpph1Sy0IUJX/4jzCRcLoeAY9ZNijzrilBWBASX5T3n49+t3wiSabhIHAbm hPPrHg3h0PwL5wrZ4XaFwCtxGQG5RMwYnfYubJTa1PE1fv1Kz/1MGo3HdbtXlzTpGA O1SOvBQ9Jy2Z3988HTpfTCx8eTNChalDNWwbGHVvlsmbyUU8jQg4zy13b0dHDzqG4E T8/dMdVE86QYg== Date: Thu, 14 Apr 2022 18:23:28 -0500 From: Bjorn Helgaas To: "Maciej W. Rozycki" , a@bhelgaas Cc: Palmer Dabbelt , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PCI: Avoid handing out address 0 to devices Message-ID: <20220414232328.GA770621@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 14, 2022 at 09:22:42PM +0100, Maciej W. Rozycki wrote: > On Thu, 14 Apr 2022, Bjorn Helgaas wrote: > > > > > > Address 0 is treated specially however in many places, for > > > > > example in `pci_iomap_range' and `pci_iomap_wc_range' we > > > > > require that the start address is non-zero, and even if we > > > > > let such an address through, then individual device drivers > > > > > could reject a request to handle a device at such an > > > > > address, such as in `uart_configure_port'. Consequently > > > > > given devices configured as shown above only one is actually > > > > > usable: > > > > > > > > pci_iomap_range() tests the resource start, i.e., the CPU > > > > address. I guess the implication is that on RISC-V, the > > > > CPU-side port address is the same as the PCI bus port address? > > > > > > Umm, for all systems I came across except x86, which have > > > native port I/O access machine instructions, a port I/O > > > resource records PCI bus addresses of the device rather than > > > its CPU addresses, which encode the location of an MMIO window > > > the PCI port I/O space is accessed through. > > > > My point is only that it is not necessary for the PCI bus address > > and the struct resource address, i.e., the argument to inb(), to > > be the same. > > Sure, but I have yet to see a system where it is the case. > > Also in principle peer PCI buses could have their own port I/O > address spaces each mapped via distinct MMIO windows in the CPU > address space, but I haven't heard of such a system. That of > course doesn't mean there's no such system in existence. They do exist, but are probably rare. Even on x86 where multiple host bridges are now fairly common, and the hardware probably supports a separate 64K port space for each, the ones I've seen split up a single 64K I/O port space so each bridge only gets a fraction of it. I'm not sure Linux would even support multiple spaces. I do know ia64 supports multiple port spaces (see __ia64_mk_io_addr()), so we could have something like this: pci_bus 0000:00: root bus resource [io 0x0000-0xffff] pci_bus 0001:00: root bus resource [io 0x10000-0x1ffff] (bus address [0x0000-0xffff]) I guess the question is whether we want to reserve port 0 and MMIO address 0 as being "invalid". That makes the first space smaller than the others, but it's not *much* smaller and it's an unlikely configuration to begin with. But at the same time, it adds another slightly weird special case in the already full-of-special-cases alloc code, and I'm somewhat averse to things like that. We do have the IORESOURCE_UNSET flag bit that could possibly be used in pci_iomap_range() instead of testing for "!start". Or maybe there's a way to allocate address 0 instead of special-casing the allocator? Just thinking out loud here. Bjorn