From patchwork Mon Jun 6 08:11:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9157385 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 055BD60572 for ; Mon, 6 Jun 2016 08:13:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1EFE26907 for ; Mon, 6 Jun 2016 08:13:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6BDC272AA; Mon, 6 Jun 2016 08:13:46 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 747A526907 for ; Mon, 6 Jun 2016 08:13:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9pdW-0001WZ-47; Mon, 06 Jun 2016 08:11:50 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9pdV-0001WS-2D for xen-devel@lists.xenproject.org; Mon, 06 Jun 2016 08:11:49 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 33/06-09289-44035575; Mon, 06 Jun 2016 08:11:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsXS6fjDS9fZIDT c4NAOZYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePCoUssBddFKrpf/WNuYJwi2MXIySEkkCcx 8cgyFhCbV8BOom/Pe0YQW0LAUGLf/FVsIDaLgKrE5YXv2EFsNgF1ibZn21m7GLk4RASuMUrMv nqYFSTBLBAoMXf2TqBBHBzCAp4Svy7aQ8y3k1ja+54JxOYUsJe49nY5G0gJr4CgxN8dwhCdWh IPf91igbC1JZYtfM0MUsIsIC2x/B/HBEa+WQgNs5A0zELSMAuhYQEjyypGjeLUorLUIl1DY72 kosz0jJLcxMwcXUMDY73c1OLixPTUnMSkYr3k/NxNjMDgYwCCHYzbtnseYpTkYFIS5ZX9GhIu xJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3gV5ouJBgUWp6akVaZg4wDmDSEhw8SiK8L0DSvMUFi bnFmekQqVOMilLivPNBEgIgiYzSPLg2WOxdYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkjDvFZ ApPJl5JXDTXwEtZgJavOxaMMjikkSElFQDY+gRNj8vXTEvv6xtxlOn/ONY9e1qbN8KR7//yiq yU/jb7Hxe3l8zdeusPy4rf0rMerCjdZ70f1sPV5FHb/RPPS3tW8VfdPXstiPiq+v26Fz/9K5i if6ZTYnrfkTalfOc/cydtuvjb6aguAvzpvHPyrohue+yrHG5tN3R0N22rNpnDQpEnDUjtyuxF GckGmoxFxUnAgAS5NveuAIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1465200705!43898667!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1278 invoked from network); 6 Jun 2016 08:11:47 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Jun 2016 08:11:47 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Mon, 06 Jun 2016 02:11:44 -0600 Message-Id: <57554C5D02000078000F1DF1@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Mon, 06 Jun 2016 02:11:41 -0600 From: "Jan Beulich" To: "David Vrabel" , "Boris Ostrovsky" , "Konrad Rzeszutek Wilk" , "Jan Beulich" ,"Juergen Gross" References: <57554B8D02000078000F1DE4@prv-mh.provo.novell.com> In-Reply-To: <57554B8D02000078000F1DE4@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Cc: xen-devel , linux-kernel@vger.kernel.org Subject: [Xen-devel] [PATCH 1/2] xen-pciback: return proper values during BAR sizing X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reads following writes with all address bits set to 1 should return all changeable address bits as one, not the BAR size (nor, as was the case for the upper half of 64-bit BARs, the high half of the region's end address). Presumably this didn't cause any problems so far because consumers use the value to calculate the size (usually via val & -val), and do nothing else with it. But also consider the exception here: Unimplemented BARs should always return all zeroes. And finally, the check for whether to return the sizing address on read for the ROM BAR should ignore all non-address bits, not just the ROM Enable one. Signed-off-by: Jan Beulich Reviewed-by: Boris Ostrovsky --- drivers/xen/xen-pciback/conf_space_header.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) --- 4.7-rc2-xen-pciback-BAR.orig/drivers/xen/xen-pciback/conf_space_header.c +++ 4.7-rc2-xen-pciback-BAR/drivers/xen/xen-pciback/conf_space_header.c @@ -145,7 +145,7 @@ static int rom_write(struct pci_dev *dev /* A write to obtain the length must happen as a 32-bit write. * This does not (yet) support writing individual bytes */ - if (value == ~PCI_ROM_ADDRESS_ENABLE) + if ((value | ~PCI_ROM_ADDRESS_MASK) == ~0) bar->which = 1; else { u32 tmpval; @@ -225,38 +225,42 @@ static inline void read_dev_bar(struct p (PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64))) { bar_info->val = res[pos - 1].start >> 32; - bar_info->len_val = res[pos - 1].end >> 32; + bar_info->len_val = -resource_size(&res[pos - 1]) >> 32; return; } } + if (!res[pos].flags || + (res[pos].flags & (IORESOURCE_DISABLED | IORESOURCE_UNSET | + IORESOURCE_BUSY))) + return; + bar_info->val = res[pos].start | (res[pos].flags & PCI_REGION_FLAG_MASK); - bar_info->len_val = resource_size(&res[pos]); + bar_info->len_val = -resource_size(&res[pos]) | + (res[pos].flags & PCI_REGION_FLAG_MASK); } static void *bar_init(struct pci_dev *dev, int offset) { - struct pci_bar_info *bar = kmalloc(sizeof(*bar), GFP_KERNEL); + struct pci_bar_info *bar = kzalloc(sizeof(*bar), GFP_KERNEL); if (!bar) return ERR_PTR(-ENOMEM); read_dev_bar(dev, bar, offset, ~0); - bar->which = 0; return bar; } static void *rom_init(struct pci_dev *dev, int offset) { - struct pci_bar_info *bar = kmalloc(sizeof(*bar), GFP_KERNEL); + struct pci_bar_info *bar = kzalloc(sizeof(*bar), GFP_KERNEL); if (!bar) return ERR_PTR(-ENOMEM); read_dev_bar(dev, bar, offset, ~PCI_ROM_ADDRESS_ENABLE); - bar->which = 0; return bar; }