From nobody Tue Feb 10 23:54:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1667264506; cv=none; d=zohomail.com; s=zohoarc; b=euJPLV7hfR8C08OE3LviNTtD0haUseHwuJMog65o6RY1HHleHvQ4z/deh7UFI47ZOMVYibZvZs5DvElLHZZn0TJWZuKsGMlPEJEPEnJKJC/aUj2BHdY9sDhnuCLrU7V4Ns3AUYNIzjuq3Ia4L+WTx9TcjmWabnIIO/oBNkqi/ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667264506; h=Content-Transfer-Encoding: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; bh=0C0Qx5SE6iSDPWaw8xqp3ZGFhXwr8M+xwNmJeAtQUf8=; b=jSzXfTAg37CUbE5dmFa4WGHofofYuNZe4HR5gD+H/oiuKE7S69eXsdMoNXnyQUYFzF6pnHATjL9+qcsqsu/ygmSD3yLLOEmxKxGvhBC+ruzbFTaEPOBIdt65BU2Z4HwefLy+t8Rhp+d2hgykF11lPC/u0RKC70+MW28nnzksyUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1667264506230422.26903491413896; Mon, 31 Oct 2022 18:01:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opfch-0004Hu-RK; Mon, 31 Oct 2022 20:59:23 -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 1opfcg-0004Hf-N2 for qemu-devel@nongnu.org; Mon, 31 Oct 2022 20:59:22 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opfce-0005dY-Lv for qemu-devel@nongnu.org; Mon, 31 Oct 2022 20:59:22 -0400 Received: by mail-pj1-x102a.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso17424289pjg.5 for ; Mon, 31 Oct 2022 17:59:20 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 17:59:18 -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:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0C0Qx5SE6iSDPWaw8xqp3ZGFhXwr8M+xwNmJeAtQUf8=; b=zOaTQCD/vYKs7C4jABXNEbQGWQBTvTNHFzaDcf2dBhS4Zac/lHxsDAzXaVFhNtUJ2o Uj3/CJX64w46EETBLAAcXR1HZWjo951S9Jj36PJVbzaTTH9YhqrDzcrM+nQfYVG5x2Gl xEHpnSNKGBEMboIXRMr+Gc321gy+BOhJhTYmYyMQ+ITIw7J4wLhVUG28EFgDenTI4i03 fuUMQpqUT1giZ5yw306N/zZTlPNn5oNfaIDvPdwvyBi0M6ImHGUkNHgq3X/lLhRimtSe Ez/mPBd/Q84x80acGxDuS+hfDp3OC8DjB8TfCkmYlMkNbtH1Ia0t3CzHe0CKvBfGvB7F hMwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0C0Qx5SE6iSDPWaw8xqp3ZGFhXwr8M+xwNmJeAtQUf8=; b=sUUPK/HtxDjaQAFW+LaCWFN5YMezdVDtTu7ATzOHouR/uxm3RaKx5bHBBAyIjaI80V AjOT4oBMwtBTOVGm69DbpB9TqBDowoLnTS5Du0QZcEJBGBOByyOf6hk7ac3glWM4wcRQ r9H514m26oSE6Am58Cl3Xwr6UnonS2vYt5W6xxqJgO4+ggPEMbVlR25bZsduCwKadyvV 7h9SrW2433hClp13TbHvXMERQ0V1g/99Wz7yshQp2Iv6nFMWnmDC8IC7cN9eVInlwgUN ivps9qfjQ2A9GEna3zFSUPI6uA0N1Z1X4vbmrrfPOj0lb6YALypWxoWNvEzmmBo6zqvz IraA== X-Gm-Message-State: ACrzQf01zcwUcHBldP4519XqivVMhHHYWW+0grvmYjCrbwjX4bqpaLIX B5YqNWU96XDIMn8lIDMaLxkzDiYZaureXHcG X-Google-Smtp-Source: AMsMyM6wZR2xKdFoMqRBuOKPruO03XnBZz4COMdAZBxvFCYZANz7dPgPfjBQ8UzjbR2zjE7yYRDjww== X-Received: by 2002:a17:90b:1bd2:b0:212:cf30:3d53 with SMTP id oa18-20020a17090b1bd200b00212cf303d53mr34268074pjb.18.1667264359118; Mon, 31 Oct 2022 17:59:19 -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 02/17] pci: Allow to omit errp for pci_add_capability Date: Tue, 1 Nov 2022 09:58:44 +0900 Message-Id: <20221101005859.4198-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221101005859.4198-1-akihiko.odaki@daynix.com> References: <20221101005859.4198-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::102a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102a.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+importer=patchew.org+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1667264508038100003 Content-Type: text/plain; charset="utf-8" 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. Therefore, we can always assert that capabilities never overlap when pci_add_capability is called, resolving these inconsistencies. Such an implementation of pci_add_capability will not have errp parameter. However, there are so many callers of pci_add_capability that it does not make sense to amend all of them at once to match with the new signature. Instead, this change will allow callers of pci_add_capability to omit errp as the first step. Signed-off-by: Akihiko Odaki --- hw/pci/pci.c | 8 ++++---- include/hw/pci/pci.h | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 33f5406706..9e62c8e75d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2530,14 +2530,14 @@ void pci_check_capability_overlap(PCIDevice *pdev, = uint8_t cap_id, } =20 /* - * On success, pci_add_capability() returns a positive value + * On success, pci_add_capability_legacy() returns a positive value * that the offset of the pci capability. * On failure, it sets an error and returns a negative error * code. */ -int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, - uint8_t offset, uint8_t size, - Error **errp) +int pci_add_capability_legacy(PCIDevice *pdev, uint8_t cap_id, + uint8_t offset, uint8_t size, + Error **errp) { uint8_t *config; =20 diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 75e64ecdf2..4f3e1e2558 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -2,6 +2,7 @@ #define QEMU_PCI_H =20 #include "exec/memory.h" +#include "qapi/error.h" #include "sysemu/dma.h" =20 /* PCI includes legacy ISA access. */ @@ -393,9 +394,15 @@ pcibus_t pci_get_bar_addr(PCIDevice *pci_dev, int regi= on_num); void pci_check_capability_overlap(PCIDevice *pdev, uint8_t cap_id, uint8_t offset, uint8_t size, Error **er= rp); =20 -int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, - uint8_t offset, uint8_t size, - Error **errp); +int pci_add_capability_legacy(PCIDevice *pdev, uint8_t cap_id, + uint8_t offset, uint8_t size, + Error **errp); + +#define PCI_ADD_CAPABILITY_VA(pdev, cap_id, offset, size, errp, ...) \ + pci_add_capability_legacy(pdev, cap_id, offset, size, errp) + +#define pci_add_capability(...) \ + PCI_ADD_CAPABILITY_VA(__VA_ARGS__, &error_abort) =20 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_si= ze); =20 --=20 2.38.1