From patchwork Tue Jun 7 06:30:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9159899 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 5182260572 for ; Tue, 7 Jun 2016 06:33:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20B1A27248 for ; Tue, 7 Jun 2016 06:33:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 151F72823D; Tue, 7 Jun 2016 06:33:00 +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 7B72927248 for ; Tue, 7 Jun 2016 06:32:59 +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 1bAAXZ-0002md-Il; Tue, 07 Jun 2016 06:31:05 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAAXY-0002mR-7c for xen-devel@lists.xenproject.org; Tue, 07 Jun 2016 06:31:04 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id F6/DB-14119-72A66575; Tue, 07 Jun 2016 06:31:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsXS6fjDS1ctKyz c4NUsS4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNePs3zUsBRNEK95efsDSwHhKsIuRk0NIIE9i wv8pTCA2r4CdxIL3x9hBbAkBQ4l981exgdgsAqoSL1dcAathE1CXaHu2nbWLkYtDRGALo0THy n6wImaBQIm5s3eygNjCAj4Sa59tZ4RYYCfxYeYGVhCbU8Be4vnelUD1HEDLBCX+7hCGaNWSeP jrFguErS2xbOFrZpASZgFpieX/OCYw8s1CaJiFpGEWkoZZCA0LGFlWMaoXpxaVpRbpGuolFWW mZ5TkJmbm6BoamOrlphYXJ6an5iQmFesl5+duYgQGXz0DA+MOxqZe50OMkhxMSqK8D73DwoX4 kvJTKjMSizPii0pzUosPMcpwcChJ8L7JAMoJFqWmp1akZeYA4wAmLcHBoyQCkeYtLkjMLc5Mh 0idYlSUEuedAJIQAElklObBtcFi7xKjrJQwLyMDA4MQT0FqUW5mCar8K0ZxDkYlYV6OTKApPJ l5JXDTXwEtZgJavOxaMMjikkSElFQDY9qWx/k8b6ytbjzY8nbNGb+swyfLf0++rFpT2JSknX3 adN+bZtfuMyt19xUlcxx8vYzlxbIHoZNTv71vkVqn8kCDcSW35gNe103vzslavG0xmn/shse8 qtybvyWT3R62HZJZabzh9j77qEWSyaa+vDssVbX3HFWVne8zcf3ViZO4N52R01n3/roSS3FGo qEWc1FxIgCwQYonuAIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-3.tower-206.messagelabs.com!1465281060!39877293!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 7392 invoked from network); 7 Jun 2016 06:31:02 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-3.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Jun 2016 06:31:02 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Tue, 07 Jun 2016 00:31:00 -0600 Message-Id: <5756864102000078000F269A@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Tue, 07 Jun 2016 00:30:57 -0600 From: "Jan Beulich" To: "David Vrabel" , "Boris Ostrovsky" , "Konrad Rzeszutek Wilk" , "Juergen Gross" References: <5756857802000078000F268D@prv-mh.provo.novell.com> In-Reply-To: <5756857802000078000F268D@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Cc: xen-devel , linux-kernel@vger.kernel.org Subject: [Xen-devel] [PATCH v2 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; }