From patchwork Mon Mar 11 18:02:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 10847969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16C496C2 for ; Mon, 11 Mar 2019 18:07:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02FA7292B1 for ; Mon, 11 Mar 2019 18:07:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB630292C5; Mon, 11 Mar 2019 18:07:45 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 917B3292B1 for ; Mon, 11 Mar 2019 18:07:45 +0000 (UTC) Received: from localhost ([127.0.0.1]:37998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3PKy-0006Es-Oo for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 Mar 2019 14:07:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3PHA-0003Ah-Vy for qemu-devel@nongnu.org; Mon, 11 Mar 2019 14:03:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3PH9-0002hq-W6 for qemu-devel@nongnu.org; Mon, 11 Mar 2019 14:03:48 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:34643) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3PH6-0002Wv-4x for qemu-devel@nongnu.org; Mon, 11 Mar 2019 14:03:46 -0400 Received: by mail-qk1-x744.google.com with SMTP id n6so3279391qkf.1 for ; Mon, 11 Mar 2019 11:03:31 -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 :mime-version:content-transfer-encoding; bh=2pZYwQaJACSsOGn4WGDZJwf1nT2bs3mpeMm63NmR5yo=; b=DzklfA1n+P0B8jvdOePPjPzyO2hOpiUNBaaHiUUL1cpJ37o3DJUr4Eh6T9IeJt5xiz G1F3o6ivdYOpfZ6cpLD0nma64RB5G/FwLLJryzbGg3oNMGZF8MWjhUrMkDqoYcT1Rh4u rbmXe9AoNxhZZT9KzjJdRXzIYZcCz2EF9llEarlokejiP3Fekez3z2hi7JZhfU10LGQS A/y6MqBioiTVS1qxC3QbFUZX+kPWkGzrFKtshHjwFpjQdGYoAmty8sIMFC/duJfJ4kg7 TIpoFgnfTk++x+6p3eu6LFCue9cPXvoeGwjXqFZd4iAJGAiGPbEsv6W4Q9grWeqtdTbV qKyQ== 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:mime-version:content-transfer-encoding; bh=2pZYwQaJACSsOGn4WGDZJwf1nT2bs3mpeMm63NmR5yo=; b=eibgyW9j4V+TEH5Ph6QiGia3/5psZ6RqATnMvdxqgsiy/wxUZKR7xwvUdzmN/EGI6W 5H8j4dNLXRKl3pOJbIJiv85XeJaO7mqHzd88HERsZN0lfnoNGTDVc1o/BHIzBOyyLjOx 97qMdPpXjd2ufXoo06I0HFTxK61d3/btT2CxRBWupP+YGWkvUXK7viWWGGTV0qAx8s8B WVN7IMc+j6vPTBEkTTLV3WZ+Xf/QMrLwD0d7iXbCdThcMoP7uGM6j6Ayhh4kbobW+bpH MG/RJkS+ZvVrWKw9Lw1KD5TPszyefNh6hEEcAx7C2uD/rzM4wrHDn1rhaeMCmJhax4XD 47Xw== X-Gm-Message-State: APjAAAX6VkrwYqGviV8tjYqqTkwKoGPb/P/Px50wm5BHA605zuP9MHTL fY2nzUDZ8RaUNVnv6qK49tkzufkqar4= X-Google-Smtp-Source: APXvYqyPE+SDB8Bko5uGxRwWOq/nef328TC8LKIE58vmCwuBBmxmlx4b3IYIAEyZiIgH8YA8TkfiPQ== X-Received: by 2002:a37:4a84:: with SMTP id x126mr25189066qka.326.1552327410658; Mon, 11 Mar 2019 11:03:30 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id f126sm4687637qka.14.2019.03.11.11.03.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 11:03:29 -0700 (PDT) From: Jason Andryuk To: qemu-devel@nongnu.org Date: Mon, 11 Mar 2019 14:02:16 -0400 Message-Id: <20190311180216.18811-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311180216.18811-1-jandryuk@gmail.com> References: <20190311180216.18811-1-jandryuk@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::744 Subject: [Qemu-devel] [PATCH 6/6] xen-pt: Round pci regions sizes to XEN_PAGE_SIZE 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: Stefano Stabellini , Jason Andryuk , marmarek@invisiblethingslab.com, Simon Gaiser , Paul Durrant , Anthony Perard , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Simon Gaiser If a pci memory region has a size < XEN_PAGE_SIZE it can get located at an address which is not page aligned. This breaks the memory mapping via xc_domain_memory_mapping since this function is page based and the "offset" is therefore lost. Without this patch you will see error like this in the stubdom log: [00:05.0] xen_pt_bar_read: Error: Should not read BAR through QEMU. @0x0000000000000004 QubesOS/qubes-issues#2849 Signed-off-by: Simon Gaiser Signed-off-by: Jason Andryuk --- hw/xen/xen_pt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 5539d56c3a..7f680442ee 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -449,9 +449,10 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s, uint16_t *cmd) /* Register PIO/MMIO BARs */ for (i = 0; i < PCI_ROM_SLOT; i++) { XenHostPCIIORegion *r = &d->io_regions[i]; + pcibus_t r_size = r->size; uint8_t type; - if (r->base_addr == 0 || r->size == 0) { + if (r->base_addr == 0 || r_size == 0) { continue; } @@ -469,15 +470,18 @@ static int xen_pt_register_regions(XenPCIPassthroughState *s, uint16_t *cmd) type |= PCI_BASE_ADDRESS_MEM_TYPE_64; } *cmd |= PCI_COMMAND_MEMORY; + + /* Round up to a full page for the hypercall. */ + r_size = (r_size + XC_PAGE_SIZE - 1) & XC_PAGE_MASK; } memory_region_init_io(&s->bar[i], OBJECT(s), &ops, &s->dev, - "xen-pci-pt-bar", r->size); + "xen-pci-pt-bar", r_size); pci_register_bar(&s->dev, i, type, &s->bar[i]); XEN_PT_LOG(&s->dev, "IO region %i registered (size=0x%08"PRIx64 " base_addr=0x%08"PRIx64" type: %#x)\n", - i, r->size, r->base_addr, type); + i, r_size, r->base_addr, type); } /* Register expansion ROM address */