From nobody Wed Nov 27 04:47:42 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701504118; cv=none; d=zohomail.com; s=zohoarc; b=hJdk3wjm/HI62rYmbUFcM7iPFdbEIE2PXJLNuJYblXZbziZvhn4M7CC8/xt7rq09y3YXRE/syA755UWH+wtSP8WYeg3noQAGLnoQdVeYumvJ65DrI6eri4OoZLWHyF77zr0bTw7rSu/lrZW/tpizMNpQXSSn9OKKDyP3w8dqrkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701504118; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bj8XVIcfBYxFCt7yVr0gyoBi8ZlaEENnjEghOjifY8I=; b=NAqLk0c6cxPjnsFgpPpEjNJjR/ozIzheauFDZZQze6CHIRlgwWIKmtF9j5k5e+mnDWszA9WD8FS9zHH5k4y7PhH7GSZsXDFMjYHh+e6l0lOwmwfgVBK+KFy7c4hzfw+FBpxRuPal9E7W0nBMICOo5yKQF/pOpVcF/p0q8X8onMM= 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701504118752614.253083814765; Sat, 2 Dec 2023 00:01:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kw9-0004O2-4h; Sat, 02 Dec 2023 03:01:18 -0500 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 1r9Kvl-0004K6-TM for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:53 -0500 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9Kvk-0004zd-7l for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:53 -0500 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-35c18e55633so12373205ab.2 for ; Sat, 02 Dec 2023 00:00:51 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id bg6-20020a17090b0d8600b00286558ad352sm2735558pjb.8.2023.12.02.00.00.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504051; x=1702108851; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Bj8XVIcfBYxFCt7yVr0gyoBi8ZlaEENnjEghOjifY8I=; b=jrIIeuK9mldjdWmrTFtJDYi54EqW0GcbmzTMs1zBt8Tmrw/27Ldx1MLakuywnnherw kzvKASXC8CP1T0lplz4srN1ynT22Sla7W3+BiJ8TG6rU3EtrkZillHO3H08jaCVbO63n xLx9tMq7+NWM/DiQ5n+9nZYbm+J0YqBL1R/3pvWWp8cJGWE3FzxN47LhkEcmJ3NaXOkf ryAz2/aykkCTC6OM4sdT/0kQGks8en9nlm+9FCZPZQzRa5I8OXK17LepdxaJGIVHFpxK WF4B22VbBcansVTF00cC8EZSwikG1UNuolD+CVJjwp07ModOdAMnkCk7dlamOBI5XdX3 LM5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504051; x=1702108851; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bj8XVIcfBYxFCt7yVr0gyoBi8ZlaEENnjEghOjifY8I=; b=bEkqj/FQiZDeHf74MaSCfQkKFkUtJ28gNLoipPKn+CNVyD8pG8IlvqkxqVMyQOhHIv jm51+PX0S5Kzmc8wDdgtayyqmqzjElHLPsTVbDjUEof+WCEbLtpGL01gkUTSme6WxnCO j0zlR8X1qZpL4gjeiPkLr32lQfPCvTH1xSKYQufbT1laNUCe2sI8X+bQEayP8x63r6Om 9g3C51gLTKjfRKdxPqyVeDtQQvJksxSGV9n3QFhQbcImI2bLD8NY3AheabCWoITPW8sZ YsJ1oW2j0NNmAdfLLKsJINXweih+gkOO1IRJ5VwnEz6TZEGFHL5IHTRqgrUYiRQYZYHE YhBw== X-Gm-Message-State: AOJu0YwNeESJqosECA9Hiby2vbvbl5AJb/P4yT4sMGMklE697qh6Smi4 bGE1O2uHxvPQaUMJx2jKzsm1yg== X-Google-Smtp-Source: AGHT+IG6Xiul2ufJptSl6rNTgX/WyEaTOhl3ssbdyNFFtxdeVXcZh8guEm61cpqewSpBe2uVM9+hZg== X-Received: by 2002:a92:cb4d:0:b0:35d:5995:798b with SMTP id f13-20020a92cb4d000000b0035d5995798bmr1130440ilq.37.1701504050726; Sat, 02 Dec 2023 00:00:50 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:27 +0900 Subject: [PATCH 04/14] hw/pci: Add pci-failover MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231202-sriov-v1-4-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 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: none client-ip=2607:f8b0:4864:20::12e; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12e.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701504120656000005 pci-failover allows to create a device capable of failover without relying on DeviceListener::hide_device(), which intrudes the pci-device implementation from outside. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 14 ++++++++++++++ hw/pci/pci.c | 43 +++++++++++++++++++++++++++++++++++++++++= ++ 2 files changed, 57 insertions(+) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 8e287c5414..a7bfb192e8 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -9,6 +9,11 @@ typedef struct PCIDeviceClass PCIDeviceClass; DECLARE_OBJ_CHECKERS(PCIDevice, PCIDeviceClass, PCI_DEVICE, TYPE_PCI_DEVICE) =20 +#define TYPE_PCI_FAILOVER "pci-failover" +typedef struct PCIFailoverClass PCIFailoverClass; +DECLARE_CLASS_CHECKERS(PCIFailoverClass, PCI_FAILOVER, TYPE_PCI_FAILOVER) +#define PCI_FAILOVER(obj) INTERFACE_CHECK(PciFailover, (obj), TYPE_PCI_FAI= LOVER) + /* * Implemented by devices that can be plugged on CXL buses. In the spec, t= his is * actually a "CXL Component, but we name it device to match the PCI namin= g. @@ -162,6 +167,15 @@ struct PCIDevice { uint32_t acpi_index; }; =20 +struct PCIFailoverClass { + /* private */ + InterfaceClass parent_class; + + /* public */ + bool (* set_primary)(DeviceState *dev, const QDict *device_opts, + bool from_json, Error **errp); +}; + static inline int pci_intx(PCIDevice *pci_dev) { return pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 53c59a5b9f..3d07246f8e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -46,6 +46,7 @@ #include "hw/pci/msix.h" #include "hw/hotplug.h" #include "hw/boards.h" +#include "qapi/qmp/qdict.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "pci-internal.h" @@ -2050,6 +2051,40 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num,= uint8_t devfn) return bus->devices[devfn]; } =20 +static bool pci_qdev_hide(DeviceClass *dc, const QDict *device_opts, + bool from_json, Error **errp) +{ + const char *standby_id; + DeviceState *dev; + ObjectClass *class; + ObjectClass *interface; + + if (!device_opts) { + return false; + } + + if (!qdict_haskey(device_opts, "failover_pair_id")) { + return false; + } + + standby_id =3D qdict_get_str(device_opts, "failover_pair_id"); + dev =3D qdev_find_recursive(sysbus_get_default(), standby_id); + if (!dev) { + error_setg(errp, "failover pair not found"); + return false; + } + + class =3D object_get_class(OBJECT(dev)); + interface =3D object_class_dynamic_cast(class, TYPE_PCI_FAILOVER); + if (!interface) { + error_setg(errp, "failover pair does not support failover"); + return false; + } + + return ((PCIFailoverClass *)interface)->set_primary(dev, device_opts, + from_json, errp); +} + #define ONBOARD_INDEX_MAX (16 * 1024 - 1) =20 static void pci_qdev_realize(DeviceState *qdev, Error **errp) @@ -2653,6 +2688,7 @@ static void pci_device_class_init(ObjectClass *klass,= void *data) { DeviceClass *k =3D DEVICE_CLASS(klass); =20 + k->hide =3D pci_qdev_hide; k->realize =3D pci_qdev_realize; k->unrealize =3D pci_qdev_unrealize; k->bus_type =3D TYPE_PCI_BUS; @@ -2861,6 +2897,12 @@ static const TypeInfo pci_device_type_info =3D { .class_base_init =3D pci_device_class_base_init, }; =20 +static const TypeInfo pci_failover_type_info =3D { + .name =3D TYPE_PCI_FAILOVER, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(PCIFailoverClass), +}; + static void pci_register_types(void) { type_register_static(&pci_bus_info); @@ -2870,6 +2912,7 @@ static void pci_register_types(void) type_register_static(&cxl_interface_info); type_register_static(&pcie_interface_info); type_register_static(&pci_device_type_info); + type_register_static(&pci_failover_type_info); } =20 type_init(pci_register_types) --=20 2.43.0