From nobody Mon Feb 9 11:32:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604067810; cv=none; d=zohomail.com; s=zohoarc; b=Ytzpn5afUQBKd0V6oG6/F+e1Q/95n8CuiqzoQ3RS4hwXcLrU3VekTLcq3eSfknBT2Y1dQTHoZzElaCwuDHUgjSNN1J1WRnXqO7bAQzAbG1cUcssEedoI+fDQSnMaqrxH1wdfGZUOzN+VaHQT1hZpf2qlrV5ju9MK+pL//x7bTEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604067810; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l6Xr3YozF4IKRpFrhD0A/HyzyCVetEbDlqfMsE4vvfI=; b=N1D0ZI1lDArBaBJcyi/B/I3BFVWAosUUHhbTML7q1enWxfL2C5/wdtVtdK/RzsHdEhdyezdm7SZmTK0HM7s/GsdxVPyvJNVX16MqD2tHUqJYiJzTTlE9RpjeWWEG7kIhFwN5NhnC+99WzBZX218AmQNE2GWuqKWg/jPAZ/KkZM4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604067810120635.2951105279914; Fri, 30 Oct 2020 07:23:30 -0700 (PDT) Received: from localhost ([::1]:48876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYVJQ-0007Ul-TR for importer@patchew.org; Fri, 30 Oct 2020 10:23:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYV8s-0003o7-2p for qemu-devel@nongnu.org; Fri, 30 Oct 2020 10:12:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kYV8n-0007H7-AV for qemu-devel@nongnu.org; Fri, 30 Oct 2020 10:12:33 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-433-VNtCPUKrOA61vRHvJ9iOfA-1; Fri, 30 Oct 2020 10:12:20 -0400 Received: by mail-wr1-f70.google.com with SMTP id h8so2712714wrt.9 for ; Fri, 30 Oct 2020 07:12:20 -0700 (PDT) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id j9sm7394525wrr.49.2020.10.30.07.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 07:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604067143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=l6Xr3YozF4IKRpFrhD0A/HyzyCVetEbDlqfMsE4vvfI=; b=JCAgmYUo/KvXnGnW0Vq1xN5YrKCS0QzjvChkESFVHZpvJwctYg0SNJ1K4BTESKLnyC3jkN oUvNU2kYp3hRxbz3euOjaEwKOO4n1qislJUR9VzvfUaGtk5j/fQAW2eB7ZypnbsnNXDdU4 6S3xHnps+22W33SqsDHxg3V+JY3nmww= X-MC-Unique: VNtCPUKrOA61vRHvJ9iOfA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=l6Xr3YozF4IKRpFrhD0A/HyzyCVetEbDlqfMsE4vvfI=; b=WO/jlhJb8M4Wpl8CqE/W7F/gE+CE9w7rETq38cfzJ1FNEoWHI7C4K3a+wylq6oApyC ZUkcefGomEU5Li6i6izpbD/XIATq9JrA2JXvEivUiFeZSQe/apw+RCVG5wTGkUApiPmH VgVMNWkCgS1tZzmCENAWgdJusxsKiEFH21mwrcjpN6LocXm/3pns14oRY08/1985JSAr xYK/CzFuZHlsPc2lDOAvt5Pu+ro7dYsRvv+ztElYC78gIw28UpOAltA97Oq36IyBtD+n hvM/SpyX0Ym29AxrJXpchXZPLIQYeS5kzNqv+Y7nm5OB2A7oYNGoBgUxKzuohKA6UiOe dDqw== X-Gm-Message-State: AOAM5305PVXe2qOJ84yZ1Ld8xj9y2XR2uIpXobOTa7cR4f0wG8X4/VU1 48FfPfnzUohgmUCvuNJjmYTjdxZvKFpSXnAy7AleTXMuW0Bc5/1JoS4+9bj6GcC7f5WInlwp8Pa TXTa8VXc3ec6VPPk= X-Received: by 2002:adf:e892:: with SMTP id d18mr3620631wrm.103.1604067138891; Fri, 30 Oct 2020 07:12:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfdnUb2d32ttTtm/PYVoQtbPY8uGtcVL12j/NYgBMoAc4PMSRACN7d5AyVvcQspH/JJnefDg== X-Received: by 2002:adf:e892:: with SMTP id d18mr3620590wrm.103.1604067138633; Fri, 30 Oct 2020 07:12:18 -0700 (PDT) Date: Fri, 30 Oct 2020 10:12:16 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 12/15] pci: Disallow improper BAR registration for type 1 Message-ID: <20201030141136.1013521-13-mst@redhat.com> References: <20201030141136.1013521-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201030141136.1013521-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/30 02:24:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Ben Widawsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ben Widawsky Prevent future developers working on root complexes, root ports, or bridges that also wish to implement a BAR for those, from shooting themselves in the foot. PCI type 1 headers only support 2 base address registers. It is incorrect and difficult to figure out what is wrong with the device when this mistake is made. With this, it is immediate and obvious what has gone wrong. Signed-off-by: Ben Widawsky Message-Id: <20201015181411.89104-2-ben.widawsky@intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e5b7c9a42b..0131d9d02c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1148,11 +1148,17 @@ void pci_register_bar(PCIDevice *pci_dev, int regio= n_num, uint32_t addr; /* offset in pci config space */ uint64_t wmask; pcibus_t size =3D memory_region_size(memory); + uint8_t hdr_type; =20 assert(region_num >=3D 0); assert(region_num < PCI_NUM_REGIONS); assert(is_power_of_2(size)); =20 + /* A PCI bridge device (with Type 1 header) may only have at most 2 BA= Rs */ + hdr_type =3D + pci_dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION; + assert(hdr_type !=3D PCI_HEADER_TYPE_BRIDGE || region_num < 2); + r =3D &pci_dev->io_regions[region_num]; r->addr =3D PCI_BAR_UNMAPPED; r->size =3D size; --=20 MST