From patchwork Mon Mar 12 18:34:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey G X-Patchwork-Id: 10277017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 14F8660211 for ; Mon, 12 Mar 2018 18:44:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06F5128BE6 for ; Mon, 12 Mar 2018 18:44:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFFAB28C49; Mon, 12 Mar 2018 18:44:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 85B4F28BE6 for ; Mon, 12 Mar 2018 18:44:06 +0000 (UTC) Received: from localhost ([::1]:33925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evSQX-0002Hk-1q for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Mar 2018 14:44:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evSJ8-0000N6-Dm for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evSJ7-0005kK-C2 for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:36:26 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:40079) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evSJ7-0005k3-6Z for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:36:25 -0400 Received: by mail-pf0-x242.google.com with SMTP id x1so4728740pfh.7 for ; Mon, 12 Mar 2018 11:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=lv9NSzDggq2maVRE7T+YW7GooKhPrx+wvDzPdkNPLeQ=; b=n+1haOXrd86tjlVhLs6btQ8t3Os4aYz6uAP0h5I7PSg7OKbO5GCM5H8g1A/xyLnhug c8iyF4gEpSY4kYiWumSER2OWJNGDrF2nWWISMqHXg4F2skolf59bxmoD7k0EHSeTUarS FJTn7raraWedYbzSUMF8kpzJGh4ZYduhuaXrWUrBE12CSyQ3dy2HDbZ9EhWb7rJqvcZz Lr4zK2L4Wdj4NdQ0wc8YTEU6Lz8YTPre/CaInbQGaYnG4E3Zz0L4HAGem4Au6Lp+NFt4 Fn7G6Yha5hRrvVdW4QVWJ6jHU7A5S7TEJ8cmLHkc+XtnLgYdbzk2irQDRcH2Jcp6rn2m +X9g== 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:in-reply-to :references:in-reply-to:references; bh=lv9NSzDggq2maVRE7T+YW7GooKhPrx+wvDzPdkNPLeQ=; b=KI7coh3LfjfobFmxx9L5e0c/wFFgAjmnAvJ2N0nEac4EZz3f1b7uL348iDJZuJOO/A LePg9DEV819zx9CGjh7mQi0mnY1dC6aWM3IzrNBXWvO9SuuHzwZh7cmLv9H+Dn4gqcPC mI20G8EAJ8/w/FDfkczS2XywJ/5ytIfNgcKtsYgpMV3wtQc3LU0KGyvEfRa4YrmDD1JY PVMOppv2OpfXN6ZsIvk4TgblHlzSCrqHiwsLBZII8QeopKEkMD0JVd/Eqr+jzhNMm/gY uWfDHfoGU4ME3WlSg/Ys+IhmaJKfodtgIO27PdDEEgPGmKKwazdeBPac5zsahXqiIWB/ fwKQ== X-Gm-Message-State: AElRT7EFcBR1JF3ULpnuP4qavohRFHkal2nrEAeaybh6EspOQxKh7juK Gt17u1i/JPXmJzxbIuFno50= X-Google-Smtp-Source: AG47ELvVMRQtZg+VXbSvTmsklJ6fpq8suHyovoi9+6qmDR6UcH5umct29tgZEB07G/aLnQMfuhtQTw== X-Received: by 10.98.163.143 with SMTP id q15mr8857300pfl.94.1520879784387; Mon, 12 Mar 2018 11:36:24 -0700 (PDT) Received: from localhost.localdomain ([217.150.73.25]) by smtp.gmail.com with ESMTPSA id w10sm14468666pgr.57.2018.03.12.11.36.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 11:36:23 -0700 (PDT) From: Alexey Gerasimenko To: xen-devel@lists.xenproject.org Date: Tue, 13 Mar 2018 04:34:14 +1000 Message-Id: <303852531690715bd3b5abfe884bd072523d0072.1520867956.git.x1917x@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [RFC PATCH 29/30] xen/pt: add Resizable BAR PCIe Extended Capability descriptor and sizing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Stefano Stabellini , Alexey Gerasimenko , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Unlike other PCIe Extended Capabilities, we currently cannot allow attempts to use Resizable BAR Capability. Without specifically handling BAR resizing we're likely end up with corrupted MMIO hole layout if guest OS will attempt to use this feature. Actually, recent Windows versions started to understand and use the Resizable BAR Capability (see [1]). For now, we need to hide the Resizable BAR Capability from guest OS until BAR resizing emulation support will be implemented in Xen. This support is a pretty much mandatory todo-feature as the effect of writing to Resizable BAR control registers can be considered similar to reprogramming normal BAR registers -- i.e. this needs to be handled explicitly, resulting in corresponding MMIO BAR range(s) remapping. Until then, we mark the Resizable BAR Capability as XEN_PT_GRP_TYPE_HARDWIRED. [1]: https://docs.microsoft.com/en-us/windows-hardware/drivers/display/resizable-bar-support Signed-off-by: Alexey Gerasimenko --- hw/xen/xen_pt_config_init.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 326f5671ff..b03b071b22 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -2156,6 +2156,26 @@ static int xen_pt_ext_cap_pmux_size_init(XenPCIPassthroughState *s, return ret; } +/* get Resizable BAR Extended Capability register group size */ +static int xen_pt_ext_cap_rebar_size_init(XenPCIPassthroughState *s, + const XenPTRegGroupInfo *grp_reg, + uint32_t base_offset, + uint32_t *size) +{ + uint32_t rebar_ctl = 0; + uint32_t num_entries; + + int ret = xen_host_pci_get_long(&s->real_device, + base_offset + PCI_REBAR_CTRL, + &rebar_ctl); + num_entries = + (rebar_ctl & PCI_REBAR_CTRL_NBAR_MASK) >> PCI_REBAR_CTRL_NBAR_SHIFT; + + *size = num_entries*8 + 4; + + log_pcie_extended_cap(s, "Resizable BAR", base_offset, *size); + return ret; +} static const XenPTRegGroupInfo xen_pt_emu_reg_grps[] = { /* Header Type0 reg group */ @@ -2488,6 +2508,13 @@ static const XenPTRegGroupInfo xen_pt_emu_reg_grps[] = { .size_init = xen_pt_ext_cap_dpc_size_init, .emu_regs = xen_pt_ext_cap_emu_reg_dummy, }, + /* Resizable BAR Extended Capability reg group */ + { + .grp_id = PCIE_EXT_CAP_ID(PCI_EXT_CAP_ID_REBAR), + .grp_type = XEN_PT_GRP_TYPE_HARDWIRED, + .grp_size = 0xFF, + .size_init = xen_pt_ext_cap_rebar_size_init, + }, { .grp_size = 0, },