From patchwork Tue Nov 1 00:58:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13026536 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F5F9FA3741 for ; Tue, 1 Nov 2022 00:59:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opfcY-0004G5-Tp; Mon, 31 Oct 2022 20:59:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opfcX-0004Fk-FY for qemu-devel@nongnu.org; Mon, 31 Oct 2022 20:59:13 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opfcU-0005cG-Ju for qemu-devel@nongnu.org; Mon, 31 Oct 2022 20:59:13 -0400 Received: by mail-pj1-x102d.google.com with SMTP id c15-20020a17090a1d0f00b0021365864446so11661104pjd.4 for ; Mon, 31 Oct 2022 17:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=D3A97vv38tK0HQSEA8Uri4X+QySKta5nrqPO+Jn+Wqs=; b=hMNHqjhQEiHVqlLX1NjGX1Ps5J0gSEnmaPazGDyznNeM7Bvy0tmdWtlFw3G1lbMQze 8j+EO9My5AaXcx40yjwr1yRpQ559YGyu7Twx6Bt+d/14acP2XR0xjt+xWsCFkZmDOX4O u19+DVMOzb5NfteAiUQnyKw0PSuFiz7F3Xec1JC6l7xBqqq/QN1VxUSh+NX9YS3Ln4DW ERF3tFbE3McIY5SBNfRn1DRpAMeelJ4zOpew1ukVvoxGAlXNWP+yNew/wp0+MikJ7ME2 J2C2s0NCxQ7BTuupyd+zVA2jkmZo0zp2ieWzeXWoZ8CeEJlUSz0qeflBplFU2Au18SO3 yN0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D3A97vv38tK0HQSEA8Uri4X+QySKta5nrqPO+Jn+Wqs=; b=xuT5eIWNzge+3lmfwo9/dEl0lungH/hsDVKmmG0gBeNJs4LZYoL1fmcttxMiTHlDi6 ZeOC2P6Jvd2Lnmqxg45RvD1cXpJ/E7lGEIj07gOXyD3emcpMJmFElwF/CCzPa18myGDG 2+ILk3FbgcWwc3sSHBH4B4YsOqcvKl4LIdxZi3iNR9Bit2hjpxx5qdtpYyaxPjmKsK1x bFZgum1Zzvg5MnYRPkF5TtR5+LhzaKEzGGD33SIRERRb7AE35A+R5h558AKNHCSoNN7x UR9WWaVbQJU57aTr/OON5bk+G6DKAVI/o9+HiYMGywhJkz3VGZXABoFidkQCwCtRxQuq CJ8w== X-Gm-Message-State: ACrzQf255InypUKE7xvg804DkJ5/dhTHl+IyTKGl3r3KrI4osbhyy4Rl Fpynp4CG6zaEIYxzGfCefSfPmd6wNb6tY0y3 X-Google-Smtp-Source: AMsMyM6sTELxh6m/WT8m1mzYMue13dUdzovC+/UThc+egt8+mYtL1c2zsYfmQPNmrcGeBazsdSQz9w== X-Received: by 2002:a17:90a:680d:b0:213:d200:e992 with SMTP id p13-20020a17090a680d00b00213d200e992mr10501349pjj.220.1667264348730; Mon, 31 Oct 2022 17:59:08 -0700 (PDT) Received: from fedora.flets-east.jp ([2400:4050:c360:8200:8ae8:3c4:c0da:7419]) by smtp.gmail.com with ESMTPSA id o9-20020aa79789000000b0056d98e359a5sm1875644pfp.165.2022.10.31.17.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 17:59:08 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , Marcel Apfelbaum , Gerd Hoffmann , Paolo Bonzini , Richard Henderson , Eduardo Habkost , John Snow , Dmitry Fleytman , Jason Wang , Stefan Weil , Keith Busch , Klaus Jensen , Peter Maydell , Andrey Smirnov , Paul Burton , Aleksandar Rikalo , Yan Vugenfirer , Yuri Benditovich , Akihiko Odaki Subject: [PATCH v7 00/17] pci: Abort if pci_add_capability fails Date: Tue, 1 Nov 2022 09:58:42 +0900 Message-Id: <20221101005859.4198-1-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::102d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org+qemu-devel=archiver.kernel.org@nongnu.org pci_add_capability appears most PCI devices. Its error handling required lots of code, and led to inconsistent behaviors such as: - passing error_abort - passing error_fatal - asserting the returned value - propagating the error to the caller - skipping the rest of the function - just ignoring The code generating errors in pci_add_capability had a comment which says: > Verify that capabilities don't overlap. Note: device assignment > depends on this check to verify that the device is not broken. > Should never trigger for emulated devices, but it's helpful for > debugging these. Indeed vfio has some code that passes capability offsets and sizes from a physical device, but it explicitly pays attention so that the capabilities never overlap and the only exception are MSI and MSI-X capabilities. Therefore, we can add code specific to the case, and always assert that capabilities never overlap in the other cases, resolving these inconsistencies. v7: - Perform checks in vfio_msi_setup() and vfio_msix_setup() (Alex Williamson) v6: - Error in case of MSI/MSI-X capability overlap (Alex Williamson) v5: - Fix capability ID specification in vfio_msi_early_setup (Alex Williamson) - Use range_covers_byte() (Alex Williamson) - warn_report() in case of MSI/MSI-X capability overlap (Alex Williamson) v4: - Fix typos in messages (Markus Armbruster) - hw/vfio/pci: Ensure MSI and MSI-X do not overlap (Alex Williamson) v3: - Correct patch split between virtio-pci and pci (Markus Armbruster) - Add messages for individual patches (Markus Armbruster) - Acked-by: Jonathan Cameron Akihiko Odaki (17): hw/vfio/pci: Ensure MSI and MSI-X do not overlap pci: Allow to omit errp for pci_add_capability hw/i386/amd_iommu: Omit errp for pci_add_capability ahci: Omit errp for pci_add_capability e1000e: Omit errp for pci_add_capability eepro100: Omit errp for pci_add_capability hw/nvme: Omit errp for pci_add_capability msi: Omit errp for pci_add_capability hw/pci/pci_bridge: Omit errp for pci_add_capability pcie: Omit errp for pci_add_capability pci/shpc: Omit errp for pci_add_capability msix: Omit errp for pci_add_capability pci/slotid: Omit errp for pci_add_capability hw/pci-bridge/pcie_pci_bridge: Omit errp for pci_add_capability hw/vfio/pci: Omit errp for pci_add_capability virtio-pci: Omit errp for pci_add_capability pci: Remove legacy errp from pci_add_capability docs/pcie_sriov.txt | 4 +-- hw/display/bochs-display.c | 4 +-- hw/i386/amd_iommu.c | 21 +++--------- hw/ide/ich.c | 8 ++--- hw/net/e1000e.c | 22 +++---------- hw/net/eepro100.c | 7 +--- hw/nvme/ctrl.c | 14 ++------ hw/pci-bridge/cxl_downstream.c | 9 ++---- hw/pci-bridge/cxl_upstream.c | 8 ++--- hw/pci-bridge/i82801b11.c | 14 ++------ hw/pci-bridge/pci_bridge_dev.c | 2 +- hw/pci-bridge/pcie_pci_bridge.c | 19 +++-------- hw/pci-bridge/pcie_root_port.c | 16 ++------- hw/pci-bridge/xio3130_downstream.c | 15 ++------- hw/pci-bridge/xio3130_upstream.c | 15 ++------- hw/pci-host/designware.c | 3 +- hw/pci-host/xilinx-pcie.c | 4 +-- hw/pci/msi.c | 9 +----- hw/pci/msix.c | 8 ++--- hw/pci/pci.c | 46 +++++++++++++------------- hw/pci/pci_bridge.c | 21 ++++-------- hw/pci/pcie.c | 52 ++++++++---------------------- hw/pci/shpc.c | 23 ++++--------- hw/pci/slotid_cap.c | 8 ++--- hw/usb/hcd-xhci-pci.c | 3 +- hw/vfio/pci-quirks.c | 15 ++------- hw/vfio/pci.c | 29 +++++++++++------ hw/virtio/virtio-pci.c | 12 ++----- include/hw/pci/pci.h | 8 +++-- include/hw/pci/pci_bridge.h | 5 ++- include/hw/pci/pcie.h | 11 +++---- include/hw/pci/shpc.h | 3 +- include/hw/virtio/virtio-pci.h | 2 +- 33 files changed, 131 insertions(+), 309 deletions(-)