From patchwork Mon Mar 22 20:13:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 406179 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3861252jai; Mon, 22 Mar 2021 13:15:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBV2NC0JT037MC2Z9SUfCECp9Z8OzU6L1h/xdCxNWp3Bws/oZinG+sSbOf3yZX23sSbuGh X-Received: by 2002:a5d:9c50:: with SMTP id 16mr1308215iof.66.1616444126308; Mon, 22 Mar 2021 13:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616444126; cv=none; d=google.com; s=arc-20160816; b=byl9gyJrBoQE+v4S1OhOvD7qFrSCD1sg8JsOb8sPDi2gCryRtYomHbrmVY3Ywpx4ui GPo2yB/manFzf2NUi6QwbRI8pJYX6KtjOHHqqkksXRJH1XW5hoCPlbSrfPIcIKl28zcb 68rPJAGPm/t5tHRk4JZojMKD3M8xczohqcI5OlM19d1dh5o6tCNGaE4t644mW15bw0bn dPC2e7kXdhh4Qn8jtcOONjvIPYnNRT9I0CNLtlHFVj+AlAAkfG5mfmEUyb2JgxOH7Voj r7J3EldKuyHcpVKTPJtMYq5Z4d+QpeXg91c8Sp+AJa0dE7U3WDG8yy+Zjbmsg2oULgoG k7xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=VRN75fiZq3z0KsQUrseR+n6u9jCms7lasgObIRtwiok=; b=DNtQaRC4AX9zjVSuK84nuomCea2FUxWnR9LYtPGDO93AD/T5IvTeEKOaJpCQ4TyxGw uj2s0Bb/q7/r8Funej+UOrGjvkK1rnyMRupX0FAPx7KEtU4MhkhA3faJpfSwDcwdK2AY xWHMqmGQbvzgv3KFORy4XCsBkAcdQOJR8vbahjkuEoQlr4E+I2dXunRHhCagSkqeLfx8 cCWlHdAjx+CG3OIl+V0CN0ShM1tyWbd6CD3KW4mJ5V5gqMOjdrhV4vqwYWMxWBgEA8Xn 9aS58SGo9nkUq2NnXg8P631BpFFKX0bic1djIJfD13bBUg2IH7QthrBFvBwcc3WZgpe7 i3Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=r4dR3MBO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k8si9228757ioq.58.2021.03.22.13.15.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Mar 2021 13:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=r4dR3MBO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOQxR-0000Wx-NR for patch@linaro.org; Mon, 22 Mar 2021 16:15:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOQvr-0000TD-PH for qemu-devel@nongnu.org; Mon, 22 Mar 2021 16:13:48 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40829) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOQvl-0003jk-J6 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 16:13:47 -0400 Received: by mail-wr1-x444.google.com with SMTP id v11so18478118wro.7 for ; Mon, 22 Mar 2021 13:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VRN75fiZq3z0KsQUrseR+n6u9jCms7lasgObIRtwiok=; b=r4dR3MBOpVmKBR+8fSZcoMzu2dgyUoK3HFccRcnWoQ50uKFwhgY0TuttELxN+QhBAG tjPC8kuaPop+3jl5xR3lAHgWxcfl3mJ4PXrCElWUPMRhIwHj497UBKHZ31M3f/a+biBp T3TSG3fjhLMcu7gYiInhcRNazQ+umDYIF58SlpjVXT2lGjciewzA2irKVRhuxwYa2Jtx 2gjngSFOmWi7yQlo1cii5KWRicJOWu54m/lc9zwmZ0y82/ZBCLW+oSdFVq55fKWskNM7 pMkju6A++2ts2rJH2WyaY3cHWRKJtAcjxpipc/EVUj2Stdlj/YkuFqtHHYtlHvDacfno glUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VRN75fiZq3z0KsQUrseR+n6u9jCms7lasgObIRtwiok=; b=bZyKSMHmu61OFdB5Ed7OZInEZV9uT3OhhlEMd9PTjqZGkTuITN8ej83ytkxHKSoa+X s6ErBghhW/kXYjdw5++RlFrQM5aCkyf+ZnPJmMMYvHKT4scrBcSMwpSkooZdMiplTq+M oud2MDmZ0kWrswIgncpO7sUWTevdr3fF+dYgI2Nt58TLZ4BWSzSYKEvG0lkCJV6nah8V oZeVZztxuL3Z8GT6jkU/qCVJ0E5pwCDsqrW4aDPoYQtDEtzylxkuDmZXnOucEij++A5W WTu94ctIV5/x+O9mSX/sbUcJGq8lVJ+m0TajtcmNxYroyXmnMSCLhXmSYNzjbZ126nAJ uE7Q== X-Gm-Message-State: AOAM530k2QYnmmmgL02SbNYdBY2JOkHmTML17WxqG15R0A9RL/NjK2CJ RFmBPEPyvDRmZkFRyMw1nYNbvg== X-Received: by 2002:adf:8151:: with SMTP id 75mr323008wrm.152.1616444019883; Mon, 22 Mar 2021 13:13:39 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id u15sm419548wmq.4.2021.03.22.13.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 13:13:39 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH] hw/pci-host/gpex: Don't fault for unmapped parts of MMIO and PIO windows Date: Mon, 22 Mar 2021 20:13:36 +0000 Message-Id: <20210322201336.9539-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x444.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Arnd Bergmann , Dmitry Vyukov , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently the gpex PCI controller implements no special behaviour for guest accesses to areas of the PIO and MMIO where it has not mapped any PCI devices, which means that for Arm you end up with a CPU exception due to a data abort. Most host OSes expect "like an x86 PC" behaviour, where bad accesses like this return -1 for reads and ignore writes. In the interests of not being surprising, make host CPU accesses to these windows behave as -1/discard where there's no mapped PCI device. Reported-by: Dmitry Vyukov Fixes: https://bugs.launchpad.net/qemu/+bug/1918917 Signed-off-by: Peter Maydell --- Not convinced that this is 6.0 material, because IMHO the kernel shouldn't be doing this in the first place. Do we need to have the property machinery so that old virt-5.2 etc retain the previous behaviour ? --- include/hw/pci-host/gpex.h | 2 ++ hw/pci-host/gpex.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) -- 2.20.1 Acked-by: Michael S. Tsirkin diff --git a/include/hw/pci-host/gpex.h b/include/hw/pci-host/gpex.h index d48a020a952..ad876ecd209 100644 --- a/include/hw/pci-host/gpex.h +++ b/include/hw/pci-host/gpex.h @@ -49,6 +49,8 @@ struct GPEXHost { MemoryRegion io_ioport; MemoryRegion io_mmio; + MemoryRegion io_ioport_window; + MemoryRegion io_mmio_window; qemu_irq irq[GPEX_NUM_IRQS]; int irq_num[GPEX_NUM_IRQS]; }; diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c index 2bdbe7b4561..1f48c89ac6a 100644 --- a/hw/pci-host/gpex.c +++ b/hw/pci-host/gpex.c @@ -82,13 +82,46 @@ static void gpex_host_realize(DeviceState *dev, Error **errp) PCIExpressHost *pex = PCIE_HOST_BRIDGE(dev); int i; + /* + * Note that the MemoryRegions io_mmio and io_ioport that we pass + * to pci_register_root_bus() are not the same as the + * MemoryRegions io_mmio_window and io_ioport_window that we + * expose as SysBus MRs. The difference is in the behaviour of + * accesses to addresses where no PCI device has been mapped. + * + * io_mmio and io_ioport are the underlying PCI view of the PCI + * address space, and when a PCI device does a bus master access + * to a bad address this is reported back to it as a transaction + * failure. + * + * io_mmio_window and io_ioport_window implement "unmapped + * addresses read as -1 and ignore writes"; this is traditional + * x86 PC behaviour, which is not mandated by the PCI spec proper + * but expected by much PCI-using guest software, including Linux. + * + * In the interests of not being unnecessarily surprising, we + * implement it in the gpex PCI host controller, by providing the + * _window MRs, which are containers with io ops that implement + * the 'background' behaviour and which hold the real PCI MRs as + * subregions. + */ pcie_host_mmcfg_init(pex, PCIE_MMCFG_SIZE_MAX); memory_region_init(&s->io_mmio, OBJECT(s), "gpex_mmio", UINT64_MAX); memory_region_init(&s->io_ioport, OBJECT(s), "gpex_ioport", 64 * 1024); + memory_region_init_io(&s->io_mmio_window, OBJECT(s), + &unassigned_io_ops, OBJECT(s), + "gpex_mmio_window", UINT64_MAX); + memory_region_init_io(&s->io_ioport_window, OBJECT(s), + &unassigned_io_ops, OBJECT(s), + "gpex_ioport_window", 64 * 1024); + + memory_region_add_subregion(&s->io_mmio_window, 0, &s->io_mmio); + memory_region_add_subregion(&s->io_ioport_window, 0, &s->io_ioport); + sysbus_init_mmio(sbd, &pex->mmio); - sysbus_init_mmio(sbd, &s->io_mmio); - sysbus_init_mmio(sbd, &s->io_ioport); + sysbus_init_mmio(sbd, &s->io_mmio_window); + sysbus_init_mmio(sbd, &s->io_ioport_window); for (i = 0; i < GPEX_NUM_IRQS; i++) { sysbus_init_irq(sbd, &s->irq[i]); s->irq_num[i] = -1;