Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp534206pxb; Fri, 15 Apr 2022 05:37:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4uEesNvMSqOY8Nkng4uh/ylhzg42G2ajpUhiG3GOdA8lvl50gzr2kbdGKQhQHg/EMkOaZ X-Received: by 2002:a17:903:22c6:b0:154:4156:f397 with SMTP id y6-20020a17090322c600b001544156f397mr51823751plg.29.1650026252286; Fri, 15 Apr 2022 05:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650026252; cv=none; d=google.com; s=arc-20160816; b=A5OhiZinZmusnOUuiS9WdRZgyDzVLalWSHHB3OIyuuXEhlSogdWTz21MS+rkI0tqsI 2sSBrik1s/HI3W5ImBCZoiL4Ha5QF1N8/jiD+6Hgg9iDTVWyaQTuiXQf8YeVmqM4sm3K gmmK013kHklDbQ37BH9ZNPvdggv/mUxlH0SAJFBhtoAhC3G33a06Me7queLxYcP5Xl6G EusEUUh6GPdeGt40Rstaz9FHUz09wg/BuEaA/iX4aq7/CA95+pBi5TIQHIqE1/Xh6skv TocWwHRu66xAiUfXC/YS3CeOXZhCCUF8NWZdiwNPoCFgN3ntsoy7+KTESEdbBOC290dW Ndjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=zYUHvRKfkdjRLFK3/CH/9P1TIGF1Q+ZicVfnGSNZbtQ=; b=k1KTk/QIJb3j1vdB+Um/YijD2uelCb4aWDUAdKCJRdi9feDvKyFmP7IW22X1a1mzK4 d7C1DsDy1JumPIOtDv/oFMNczy0KjMxECdL3dXnJd/QnIhfX7V2TOANTVXvXj9hsIznP +8bE02cvXwhD8vXBpgKlEa3LFJqJIkjjn84cVfAnuOByad9TeGgHwvYGMG0tJMmpFLDE cnAaMxMsX8XxinYMF99Zu4ocHVbBIwoTyvOPJ3kUXQFxxMNpY0tpbfmYwtzom+eqO/sN f2pi02Ri+BC0c0GdVpOP4ehMmgDk4y9PZSmlVWO4qhd06vNq49O9koeZDUC8Ecm/deVN ZJ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=h7cJqiwe; 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 w4-20020a170902e88400b001588973b195si1263292plg.436.2022.04.15.05.37.19; Fri, 15 Apr 2022 05:37:32 -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; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=h7cJqiwe; 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 S1346938AbiDNWPM (ORCPT + 99 others); Thu, 14 Apr 2022 18:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238638AbiDNWPH (ORCPT ); Thu, 14 Apr 2022 18:15:07 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F71BA324 for ; Thu, 14 Apr 2022 15:12:40 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id z16so6016957pfh.3 for ; Thu, 14 Apr 2022 15:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=zYUHvRKfkdjRLFK3/CH/9P1TIGF1Q+ZicVfnGSNZbtQ=; b=h7cJqiwetiGHvy16aJqEPAMdNWjKEKQ11taWEHXHAKIrsZnC/uWk0/kOnmc+xupHaJ L8Z9lHMIwClyOvcEmaljSI1xDVBSA7ia76BJNq9XMku0Odol6O5A+S7sOyntimIB74+c DIZMiL1FWlLPM5s8nKLrfcxzSa2GYsWTYIWLGqg8YBOgUNiTD9XNHiO5K3NeK9LDOmGb HnlWgSpWVRRlni/qdML9hGRk/+2Djq3ADXMmBJHYC9TOPcqQ1I758sFfRqLFD5EI8Bgj Vy/2KLDKz4JCfhnMr0NVyBs3hu2Ti8sYMS1sDQHB9AxwGqculm9pfc5znAWhwvT9lO1O lfNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=zYUHvRKfkdjRLFK3/CH/9P1TIGF1Q+ZicVfnGSNZbtQ=; b=Fi2ZAiJ+W79MxFaVJJe+TFdZPJ347ZizulTDStaU4WG6gfRdmCpf0Alys8Lzf+SqMd fTGJdz5PdbMkMTTrrCk23NUPDdRM4Zptus1FcaVSeawOIJ8p/VIOeqAbEbfZPA2LnBey 6iNHKJvh9uQrXFgKAK8EpNGgBoWIUaJX0L/PVgnLWrhoG3I9UjGbuRxZjvTGDintSm59 6r1fikuweq58bCIwxC4XAq1hvzii1yH7HUmhIlL6BhbgVeGbGCXf3LxbV5Ju7DgES1+I RmVL0c7qwPg+bB+RPysxLwtksgz39kGlpLWFolLMcs7G+tJmU3n1k+SebDZNGxT/pdV6 E1QA== X-Gm-Message-State: AOAM53215CkpomD7nVwixTYQuAzICm+qqGP3iHVOmw7TWoTvhBpjy4PI kY74suwQ4/jPycs5ZOq8NhrsiQ== X-Received: by 2002:a65:638d:0:b0:39d:74ad:ce0b with SMTP id h13-20020a65638d000000b0039d74adce0bmr3990433pgv.103.1649974360010; Thu, 14 Apr 2022 15:12:40 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id v27-20020aa799db000000b00509fbf03c91sm434146pfi.171.2022.04.14.15.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 15:12:39 -0700 (PDT) Date: Thu, 14 Apr 2022 15:12:39 -0700 (PDT) X-Google-Original-Date: Thu, 14 Apr 2022 15:12:20 PDT (-0700) Subject: Re: [PATCH] PCI: Avoid handing out address 0 to devices In-Reply-To: CC: helgaas@kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org From: Palmer Dabbelt To: macro@orcam.me.uk Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 Thu, 14 Apr 2022 13:22:42 PDT (-0700), macro@orcam.me.uk 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. > >> I tried to find the RISC-V definition of inb(), but it's obfuscated >> too much to be easily discoverable. > > AFAICT the RISC-V port uses definitions from include/asm-generic/io.h. > Palmer, did I get this right? I'd argue that asm-generic/io.h uses the definitions from RISC-V, but the result is the same ;). The general idea is that the IO itself is pretty generic for a handful of ports, they just need to be decorated with some fences (or whatever the ISA calls them) before/after the load/store. Those are the __io_p{b,a}{r,w}() macros, which are in riscv's io.h. IIRC they stand for something like Port{Before,After}{Read,Write}.