From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: Re: [PATCH v3] pci: correct pci config size default for cap version 2 endpoints Date: Fri, 22 Jul 2011 11:00:16 -0600 Message-ID: <1311354017.2653.89.camel@bling.home> References: <20110722155338.43049.12587.stgit@dddsys0.bos.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, mst@redhat.com To: Donald Dutile Return-path: Received: from mx1.redhat.com ([209.132.183.28]:54246 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753336Ab1GVRAS (ORCPT ); Fri, 22 Jul 2011 13:00:18 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6MH0Hk8000402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Jul 2011 13:00:18 -0400 In-Reply-To: <20110722155338.43049.12587.stgit@dddsys0.bos.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, 2011-07-22 at 11:59 -0400, Donald Dutile wrote: > v3: remove all boundary tests. just fix the obvious bug. > : boundary test is not necessary; get this fix in & > post boundary test in another separate patch. > > v2: do local boundary check with respect to legacy PCI header length, > and don't depend on it in pci_add_capability(). > : fix compilation, and change else>2 to simple else for all other cases. > > v1: first patch: boundary check in pci_add_capability(). > > Doing device assignement using a PCIe device with it's > PCI Cap structure at offset 0xcc showed a problem in > the default size mapped for this cap-id. > > The failure caused a corruption which might have gone unnoticed > otherwise. > > Fix assigned_device_pci_cap_init() to set the default > size of PCIe Cap structure (cap-id 0x10) to 0x34 instead of 0x3c. > 0x34 is default, min, for endpoint device with a cap version of 2. > > Signed-off-by: Donald Dutile > cc: Alex Williamson > cc: Michael S. Tsirkin > > tested-by: ebenes@redhat.com > > --- > > hw/device-assignment.c | 8 +++++--- > 1 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/hw/device-assignment.c b/hw/device-assignment.c > index 36ad6b0..34db52e 100644 > --- a/hw/device-assignment.c > +++ b/hw/device-assignment.c > @@ -1419,16 +1419,18 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev) > } > > if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_EXP, 0))) { > - uint8_t version; > + uint8_t version, size; > uint16_t type, devctl, lnkcap, lnksta; > uint32_t devcap; > - int size = 0x3c; /* version 2 size */ > > version = pci_get_byte(pci_dev->config + pos + PCI_EXP_FLAGS); > version &= PCI_EXP_FLAGS_VERS; > if (version == 1) { > size = 0x14; > - } else if (version > 2) { > + } else if (version == 2) { > + /* don't include slot cap/stat/ctrl 2 regs; only support endpoints */ > + size = 0x34; > + } else { > fprintf(stderr, "Unsupported PCI express capability version %d\n", > version); > return -EINVAL; > Acked-by: Alex Williamson