From nobody Mon Apr 29 16:03:44 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1601540159; cv=none; d=zohomail.com; s=zohoarc; b=PzuFmz7nB+mGt5iuKUBlWT3rHcu6taSQSfARbllKI2bOqT1xBV+D4rkOEWZO24L+3cHykan8RQu0x6/bwX2OvJcorXwqMlhy6E226X16r4/nrB2kyTZeUf7hnJAcgo/D+/0he85qVDoPCpdPYnMj1k17kWPh51T3lFgJhMP0m5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601540159; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=FbjlksMu36p7p6zRsPPG2Wo7gSzgDilHr5PW/goywzg=; b=MyJFFav+SDW6Usv/cqdjUaXDP2uzk/23Q+wadqc4MOLgkK0trebRDAz4eiiKV8aVT9/WfxPlXULpmKDkQhQLMw/GKp4VcZl6Zp+7v2M5jo7orgjIUx4AvhqoAQL82r85BhAVL3Dm7AaVcCUqR2+RAWV//IIj30iXTzwvUk2omDs= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160154015952421.700012307652287; Thu, 1 Oct 2020 01:15:59 -0700 (PDT) Received: from localhost ([::1]:51304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNtkp-0003HN-Oc for importer@patchew.org; Thu, 01 Oct 2020 04:15:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNtk2-0002np-UA for qemu-devel@nongnu.org; Thu, 01 Oct 2020 04:15:06 -0400 Received: from mail.xenproject.org ([104.130.215.37]:50426) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNtk1-0000ie-20 for qemu-devel@nongnu.org; Thu, 01 Oct 2020 04:15:06 -0400 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kNtjy-0008NO-IX; Thu, 01 Oct 2020 08:15:02 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNtjy-000244-8G; Thu, 01 Oct 2020 08:15:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=FbjlksMu36p7p6zRsPPG2Wo7gSzgDilHr5PW/goywzg=; b=hilq0i uzkQAjHMtDMOkBwWo43MPEvjvYipGJgep2B5L2FmfnfwnZK9wyo3jCx9MuD6NGa9UJZuERGXmP8g0 piILENWxKcwz26eM2X+AzCU2pc07uAvKWdcBEIdS+hvVRF0qI/NiSS8s8crDlSaXGmG/lmc2naT89 7Q8NQ2jNLK8=; From: Paul Durrant To: xen-devel@lists.xenproject.org, qemu-devel@nongnu.org Subject: [PATCH v2] xen-bus: reduce scope of backend watch Date: Thu, 1 Oct 2020 09:15:00 +0100 Message-Id: <20201001081500.1026-1-paul@xen.org> X-Mailer: git-send-email 2.20.1 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@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=104.130.215.37; envelope-from=paul@xen.org; helo=mail.xenproject.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/01 04:15:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: Anthony Perard , Paul Durrant , Stefano Stabellini , Edwin Torok , Jerome Leseinne Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paul Durrant Currently a single watch on /local/domain/X/backend is registered by each QEMU process running in service domain X (where X is usually 0). The purpose of this watch is to ensure that QEMU is notified when the Xen toolstack creates a new device backend area. Such a backend area is specific to a single frontend area created for a specific guest domain and, since each QEMU process is also created to servi= ce a specfic guest domain, it is unnecessary and inefficient to notify all QEMU processes. Only the QEMU process associated with the same guest domain need receive the notification. This patch re-factors the watch registration code such that notifications are targetted appropriately. Reported-by: Jerome Leseinne Signed-off-by: Paul Durrant Reviewed-by: Anthony PERARD --- Cc: Edwin Torok Cc: Stefano Stabellini Cc: Anthony Perard v2: - Re-work casting - Check for a NULL watch before trying to remove it --- hw/xen/xen-backend.c | 11 ++++++++++ hw/xen/xen-bus.c | 40 ++++++++++++++++++++++++++++-------- include/hw/xen/xen-backend.h | 1 + include/hw/xen/xen-bus.h | 3 ++- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c index 10199fb58d..5b0fb76eae 100644 --- a/hw/xen/xen-backend.c +++ b/hw/xen/xen-backend.c @@ -41,6 +41,12 @@ static void xen_backend_table_add(XenBackendImpl *impl) g_hash_table_insert(xen_backend_table_get(), (void *)impl->type, impl); } =20 +static const char **xen_backend_table_keys(unsigned int *count) +{ + return (const char **)g_hash_table_get_keys_as_array( + xen_backend_table_get(), count); +} + static const XenBackendImpl *xen_backend_table_lookup(const char *type) { return g_hash_table_lookup(xen_backend_table_get(), type); @@ -70,6 +76,11 @@ void xen_backend_register(const XenBackendInfo *info) xen_backend_table_add(impl); } =20 +const char **xen_backend_get_types(unsigned int *count) +{ + return xen_backend_table_keys(count); +} + static QLIST_HEAD(, XenBackendInstance) backend_list; =20 static void xen_backend_list_add(XenBackendInstance *backend) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 9ce1c9540b..8c588920d9 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -430,7 +430,15 @@ static void xen_bus_unrealize(BusState *bus) trace_xen_bus_unrealize(); =20 if (xenbus->backend_watch) { - xen_bus_remove_watch(xenbus, xenbus->backend_watch, NULL); + unsigned int i; + + for (i =3D 0; i < xenbus->backend_types; i++) { + if (xenbus->backend_watch[i]) { + xen_bus_remove_watch(xenbus, xenbus->backend_watch[i], NUL= L); + } + } + + g_free(xenbus->backend_watch); xenbus->backend_watch =3D NULL; } =20 @@ -446,8 +454,11 @@ static void xen_bus_unrealize(BusState *bus) =20 static void xen_bus_realize(BusState *bus, Error **errp) { + char *key =3D g_strdup_printf("%u", xen_domid); XenBus *xenbus =3D XEN_BUS(bus); unsigned int domid; + const char **type; + unsigned int i; Error *local_err =3D NULL; =20 trace_xen_bus_realize(); @@ -469,19 +480,32 @@ static void xen_bus_realize(BusState *bus, Error **er= rp) =20 module_call_init(MODULE_INIT_XEN_BACKEND); =20 - xenbus->backend_watch =3D - xen_bus_add_watch(xenbus, "", /* domain root node */ - "backend", xen_bus_backend_changed, &local_err); - if (local_err) { - /* This need not be treated as a hard error so don't propagate */ - error_reportf_err(local_err, - "failed to set up enumeration watch: "); + type =3D xen_backend_get_types(&xenbus->backend_types); + xenbus->backend_watch =3D g_new(XenWatch *, xenbus->backend_types); + + for (i =3D 0; i < xenbus->backend_types; i++) { + char *node =3D g_strdup_printf("backend/%s", type[i]); + + xenbus->backend_watch[i] =3D + xen_bus_add_watch(xenbus, node, key, xen_bus_backend_changed, + &local_err); + if (local_err) { + /* This need not be treated as a hard error so don't propagate= */ + error_reportf_err(local_err, + "failed to set up '%s' enumeration watch: ", + type[i]); + } + + g_free(node); } =20 + g_free(type); + g_free(key); return; =20 fail: xen_bus_unrealize(bus); + g_free(key); } =20 static void xen_bus_unplug_request(HotplugHandler *hotplug, diff --git a/include/hw/xen/xen-backend.h b/include/hw/xen/xen-backend.h index 010d712638..aac2fd454d 100644 --- a/include/hw/xen/xen-backend.h +++ b/include/hw/xen/xen-backend.h @@ -31,6 +31,7 @@ void xen_backend_set_device(XenBackendInstance *backend, XenDevice *xen_backend_get_device(XenBackendInstance *backend); =20 void xen_backend_register(const XenBackendInfo *info); +const char **xen_backend_get_types(unsigned int *nr); =20 void xen_backend_device_create(XenBus *xenbus, const char *type, const char *name, QDict *opts, Error **errp= ); diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index 3df696136f..6bdbf3ff82 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -66,7 +66,8 @@ struct XenBus { domid_t backend_id; struct xs_handle *xsh; XenWatchList *watch_list; - XenWatch *backend_watch; + unsigned int backend_types; + XenWatch **backend_watch; QLIST_HEAD(, XenDevice) inactive_devices; }; =20 --=20 2.20.1