Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2494150pxb; Mon, 18 Apr 2022 01:14:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVBpo+pZuHGeu6lIkdwqGtbgjjLU5R/i6+2mAIIBgmxxcdUGuQg03u0UrxpksFcffqZlii X-Received: by 2002:a05:6a00:1a49:b0:505:7ab3:e5c7 with SMTP id h9-20020a056a001a4900b005057ab3e5c7mr11140263pfv.62.1650269670016; Mon, 18 Apr 2022 01:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650269670; cv=none; d=google.com; s=arc-20160816; b=FvX+QsZESXw/wy87hXjz+ZUp+K9WAbpIC38WPyc0X2+MTGqIv7ywnGA6FDil39wq1Z bBZ9M5IcMaIXsIG0m59wLVZEppBsksVlBrSoMHgglGk6GclVBm7zqdW0PJQZQTSBm1Yp IkD3ofqRXuo/uh4eTAyr+uq1YtVq6KaVMe59bBzHHbq2zns1srqkSZejDwb+Cy/fKeSx Kq40uJYmCMebXq3tseab3fwoNcRbG0+/1SNYKe4KE+AZLDaqcYKI/JyXsJ7I4kcwLpEH V0fLVa/8kMbHRj/t/tNPfSbj5i/cRzOiXxkwdslWgplke5sDmzW1BXiQkFqjP+TalMFZ H7zQ== 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:references:message-id :in-reply-to:subject:cc:to:from:date; bh=QIuLvtmgUBxB8kFIVefzTz9rvbYL15n/k07+Vj5gE/w=; b=wB+tqDzofLWO7CkYdLR9936tYbgqoOdl0XdRWhLeN5lYbUDh5GA2JL30F2WZWZ/dZb Xvio5iKXwEajEM5RmtJ50Me+b24Z/1BMnzcDgk7COfRJjxzOQWbW0Twg+HNimDmD3wUo MnitRtiys5+nQEmej09drIrc0Q9YznyLgrElIHFSSgmhGYcyIyCXfykVKUIaJLoCC8sf EzPdPl/R5hNDGqie2rh8g1hCnBR9wuzaxtg7tqKvWykfZ/Fn6zwOQuidYHFU/iGcyD11 qWDZF6Sa9QNy/xbDviQey1nSu6PMlvRSCY9rEioFhMOc0vfN84p5gpR+zvyLE5x7Sqwr gDUQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f23-20020a63f117000000b003a9fd4424a3si2018456pgi.666.2022.04.18.01.14.14; Mon, 18 Apr 2022 01:14:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232216AbiDPOFO (ORCPT + 99 others); Sat, 16 Apr 2022 10:05:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231854AbiDPOFK (ORCPT ); Sat, 16 Apr 2022 10:05:10 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5FD1E29CB2; Sat, 16 Apr 2022 07:02:38 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id ED50F92009E; Sat, 16 Apr 2022 16:02:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id E061592009C; Sat, 16 Apr 2022 15:02:35 +0100 (BST) Date: Sat, 16 Apr 2022 15:02:35 +0100 (BST) From: "Maciej W. Rozycki" To: Bjorn Helgaas 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 In-Reply-To: <20220415183912.GA824311@bhelgaas> Message-ID: References: <20220415183912.GA824311@bhelgaas> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 Fri, 15 Apr 2022, Bjorn Helgaas wrote: > > > 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. > > > > Unfortunately just as IRQ 0 is considered special and barring the 8254 > > special exception for PC-style legacy junk it means "no IRQ", similarly > > I/O port or MMIO address 0 is considered "no device" in several places. > > One I have identified as noted above is `uart_configure_port': > > > > /* > > * If there isn't a port here, don't do anything further. > > */ > > if (!port->iobase && !port->mapbase && !port->membase) > > return; > > > > So even if we let address 0 through it will be rejected downstream here > > and there and the device won't work. > > This is a driver question, which I think is secondary. If necessary, > we can fix drivers after figuring out what the PCI core should do. This goes back to ISA and user-supplied driver options given as kernel parameters, so I am fairly sure it's been a part of our user interface since forever. Changing these assumptions would surely break something for someone out there, so I would be very wary making such changes. > > > 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. > > Another possibility is PCIBIOS_MIN_IO. It's also kind of an ugly > special case, but at least it already exists. Most arches define it > to be non-zero, which should avoid this issue. > > Defining PCIBIOS_MIN_IO would be simple; what would we lose compared > to adding code in pci_bus_alloc_from_region()? As I explained in the change description: > Especially I/O space ranges are particularly valuable, because bridges > only decode bits from 12 up and consequently where 16-bit addressing is > in effect, as few as 16 separate ranges can be assigned to individual > buses only. > > Therefore avoid handing out address 0, however rather than bumping the > lowest address available to PCI via PCIBIOS_MIN_IO and PCIBIOS_MIN_MEM, > or doing an equivalent arrangement in `__pci_assign_resource', let the > whole range assigned to a bus start from that address and instead only > avoid it for actual devices. [...] Yes, just bumping up PCIBIOS_MIN_IO was my first thought and the path of least resistance. However with the strictly hierarchical topology of PCIe systems the limit of 16 ranges feels so frighteningly low to me already as to make me rather unwilling to reduce it even further for a system that is free from PC legacy junk (no southbridge let alone ISA) and therefore does not require it. So I've reconsidered my initial approach and came up with this proposal instead. I think it is a good compromise. Maciej