From patchwork Wed Sep 26 01:01:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mjr@cs.wisc.edu X-Patchwork-Id: 186925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EC66F2C0086 for ; Wed, 26 Sep 2012 11:04:09 +1000 (EST) Received: from localhost ([::1]:40483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGg2q-0007Wb-3Y for incoming@patchwork.ozlabs.org; Tue, 25 Sep 2012 21:04:08 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGg2i-0007VH-5A for qemu-devel@nongnu.org; Tue, 25 Sep 2012 21:04:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGg2h-0000T8-5A for qemu-devel@nongnu.org; Tue, 25 Sep 2012 21:04:00 -0400 Received: from sabe.cs.wisc.edu ([128.105.6.20]:40131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGg2g-0000T1-W0 for qemu-devel@nongnu.org; Tue, 25 Sep 2012 21:03:59 -0400 Received: from localhost.localdomain (cpe-184-58-210-31.wi.res.rr.com [184.58.210.31]) (authenticated bits=0) by sabe.cs.wisc.edu (8.14.1/8.14.1) with ESMTP id q8Q13tMx005887 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 25 Sep 2012 20:03:58 -0500 From: mjr@cs.wisc.edu To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2012 20:01:53 -0500 Message-Id: <1348621313-47404-1-git-send-email-mjr@cs.wisc.edu> X-Mailer: git-send-email 1.7.5.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 128.105.6.20 Cc: alex.williamson@redhat.com Subject: [Qemu-devel] [PATCH v2] Align PCI capabilities in pci_find_space X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Matt Renzelmann The current implementation of pci_find_space does not correctly align PCI capabilities in the PCI configuration space. This patch fixes this issue. Signed-off-by: Matt Renzelmann --- Alex Williamson wrote: > I think you could just search every 4th byte. In fact, this whole used > byte-map could be turned into a single uint64_t bitmap for standard > config space. Thanks, I've not tested this version of the patch, in contrast to the last, so I'm a bit less confident of its correctness. I did not reimplement it as suggested as I'm not that familiar with this code, and instead just applied the every 4th byte strategy. hw/pci.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index f855cf3..e99866a 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1631,11 +1631,15 @@ static int pci_find_space(PCIDevice *pdev, uint8_t size) int config_size = pci_config_size(pdev); int offset = PCI_CONFIG_HEADER_SIZE; int i; - for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i) - if (pdev->used[i]) - offset = i + 1; - else if (i - offset + 1 == size) + + for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; i += 4) { + if (pdev->used[i]) { + offset = i + 4; + } else if (i - offset + 1 == size) { return offset; + } + } + return 0; }