From patchwork Sat Dec 2 01:41:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13476722 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 D8529C07E97 for ; Sat, 2 Dec 2023 01:41:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.645876.1008412 (Exim 4.92) (envelope-from ) id 1r9F0g-000736-Pb; Sat, 02 Dec 2023 01:41:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 645876.1008412; Sat, 02 Dec 2023 01:41:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r9F0g-00072z-LK; Sat, 02 Dec 2023 01:41:34 +0000 Received: by outflank-mailman (input) for mailman id 645876; Sat, 02 Dec 2023 01:41:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r9F0f-00072l-0t for xen-devel@lists.xenproject.org; Sat, 02 Dec 2023 01:41:33 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id eaa68380-90b3-11ee-98e5-6d05b1d4d9a1; Sat, 02 Dec 2023 02:41:31 +0100 (CET) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 3B21X1Qm015641; Sat, 2 Dec 2023 01:41:26 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3uqa3aucrx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 02 Dec 2023 01:41:26 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB7285.eurprd03.prod.outlook.com (2603:10a6:20b:2ef::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Sat, 2 Dec 2023 01:41:21 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::8e03:368:1fd7:1822]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::8e03:368:1fd7:1822%6]) with mapi id 15.20.7046.027; Sat, 2 Dec 2023 01:41:21 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: eaa68380-90b3-11ee-98e5-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Al0hqmWcJ5SVYym2QD9l6trDde0nES0K+LUnxEcDfZ0dE+piyaYEJh6mMMezzU9cmSizQLheQIGWrte5zqc/4l3VU+9vhp60KS2DCgJr+wRoe1GulOc45J6h+4AgdwsGP44I2Nk2U/9Hs5nIvhg9J1HFu0G0kbKNGgaBuutF+6rVIZ0iUVstJqqVos3e91ytgMyuaB7paDtCcVKlYFhBRILsVv3EWUgofUwPc6h3hMcFWEoyzrIrx+XvtoXth+z5o8DJRP7NevNTRTq8Yp/8lDAKqCu9Exy6vkh7NGEHIlYswOKsIGnIkCoo+cCPJtHHlrWHesR9+c8lwJXDHjL0tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xHbTU4afcP4VPCt7c5t9HdrtExRFqhrJyZbbFA7antU=; b=LXYNTES626N6WVrrtUj8y2tH9yuJhV+u7CWfoXGN5SsTJ4zj0TK/70X/+HLFhBSbJFRARGXp5YClMKw8mYN90+lrjBOrzw+K58n9sO/gKUAgKldjLmhdc9u5gFQj7ccEg8dlj/rmLFuqHDR2i1JSLRxraAaYeDrB0CNFML2C6GnHf5jS9U1dhx0M3uBS3YAgkDY1a4gwJ4/kQtnqnn5KqlKJ9yLnqCGCvH6XC2SfAvswRvHcwtApAmRXxQWx649SZ8Z088t6gfve1V7FMjPHSZ+m0Uf24PCcyuO+5vk1lmTLizdFNl1jS0s56YSSFHelywo3G3TN9VMY7mAN3LJohg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xHbTU4afcP4VPCt7c5t9HdrtExRFqhrJyZbbFA7antU=; b=PtHfUbJaDc5STELSmfCJq0P8LXFjcTdBkb3y2rmA93rEaP9PJ4KF6Qac6dC3hcDP+cdlYqxN84cJzW06sVFdqSnpqMR9JA+dukqUFdMs4fBsOFK7QfXFNpyYIc7t7Zd1sQgp6TGBfG6044mgx5q8lGYtZMElEqBpZeVaMZIofr3M5l5sWS/Pj+41U1TvQU0y43bqFCWI27GrbglVUAYzhxENHcrgE7F747dhH5mxYUrrRkWe2GbUanEW+iIHSlZ3xQ3cvtwiXOIayiVpS5Gj7Vc0p4IjfbQ5U4A1T6xfK4H8XRG39FXJYM2PmIrTOFP1uZNrxIIqy3jDvF1GI//bdQ== From: Volodymyr Babchuk To: "qemu-devel@nongnu.org" CC: David Woodhouse , Stefano Stabellini , Julien Grall , Paul Durrant , Anthony Perard , Kevin Wolf , Hanna Reitz , =?iso-8859-1?q?Marc-Andr=E9_Lureau?= , Paolo Bonzini , Jason Wang , "open list:X86 Xen CPUs" , "open list:Block layer core" Subject: [PATCH v4 1/6] hw/xen: Set XenBackendInstance in the XenDevice before realizing it Thread-Topic: [PATCH v4 1/6] hw/xen: Set XenBackendInstance in the XenDevice before realizing it Thread-Index: AQHaJMCmNcy1jH3c30+hdicFpfwJ+Q== Date: Sat, 2 Dec 2023 01:41:21 +0000 Message-ID: <20231202014108.2017803-2-volodymyr_babchuk@epam.com> References: <20231202014108.2017803-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231202014108.2017803-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB7285:EE_ x-ms-office365-filtering-correlation-id: 55de17d1-f2c3-49db-c873-08dbf2d7c995 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SEmRHbAvkOF1F+M92scRmJda/E2LKTScNWl3z+dwwicVp9uQcdr+2iVtygauYY69ujsvNQ8fDDLrg+hZfMy0hbGE2xC2ir/I8syyhAqBgzqxb0YCEFfHEtDWjxKregYsAm5ozxD8c/4L5H545pnKuXOH3PGF+eWJYkO272X6ZyIg5EoKkjsJCQ9QIYtUXq9vz/ZQJkTuqeu+lTc0Wsh073ytOdtVkKGbc+8mzzmECRDHBMk4vtvAhcs068WR74F4iZJ/tDThkH9letr9MyxUHxzgjXH3vYqzdYvmLZX3J7DA1LBXfvZswojXSVITZBpTyNPbHe3T1ts5YLk0Wk1Lwi77EQAJKEYb7lgdOfsgS6P3NvyCd8ZTmqBl4MRXmmlJnM5HZ3rxIAPfm0QnqrsNZgaLV0y8KJbCQ+/s3FIokXDQzVmNa85lLjjX7xqmYDf+WJvpY8mjxgnjVFfct7z+TfLYX5d0cxYhNaAfUoeKU3fcu5bMpeocUvU3ZvN0gGQV+iSHsZZ+mfB6mjZS15U50wfosfVbTXhjTv0FdJIP6AkvkzsMdSygxR0M6yrYjBn21/rTZP1uOjjOTH6JhfYGCk4fbzEnO7XGRwAXGEAtZdFKgFuBGS5g4tPJk2PDPOW8 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(396003)(366004)(346002)(136003)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(122000001)(38070700009)(41300700001)(2906002)(7416002)(5660300002)(83380400001)(71200400001)(55236004)(38100700002)(6506007)(6512007)(1076003)(2616005)(26005)(66556008)(478600001)(91956017)(6486002)(36756003)(76116006)(66946007)(64756008)(66446008)(8936002)(6916009)(54906003)(86362001)(66476007)(4326008)(316002)(8676002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?a7Qj4f9DRmURavv37ag2UMa?= =?iso-8859-1?q?tMN5hyNgP8Z7r55nTOXOvP97FvNHsSE4rnd8kWS7yXkUo6ngjiKMiuu4Xc7u?= =?iso-8859-1?q?9Ek3dWG9oz22Bld/rVcOQf2/z1CcX2ZKgoRErpsyVYit/08RSKW5zrFC2XXa?= =?iso-8859-1?q?Lb6+Rt8oP4AvjpnOusvvChMrw2+CpCVztscTZaLvYU4JTMvXUClaeSMWcCr1?= =?iso-8859-1?q?jo/0ftUvcQq+py4IJMw4j6XZ0eCRbJu8opI9Mf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XM4p8flt?= =?iso-8859-1?q?6hDhrisnOHFsqE872s3SWiLRvjRJiwtiofzCeljUGCmLvjusAxruCX5itgrZ?= =?iso-8859-1?q?fP8badv/l+56Gtc/dAxL7Ghh/6E71Lx62aLMUf2vT5kOaf7MBM0DCD+9rPQ2?= =?iso-8859-1?q?AZqzG8ytYzRgeWgQZg546nKUG96hTqeugm0uWBS+pUaI9qT7KSVd826Rp/yo?= =?iso-8859-1?q?cBvWEPF5h9PSdUo/N0GRUWXA7QY4kqNeR7TP6yV6jYZ20xWSqRsToGtOQoJr?= =?iso-8859-1?q?Yp++EXAMjrtH1PAsjYIwfJLr2dHQYEvTf1aJV7Aq/h++uJRm81GTatKPZcLP?= =?iso-8859-1?q?1B8kvq065kzAZ1uKKoguuyneolgBXulrpcl3IYVPHd0ZduLDILV8nHaVs5AE?= =?iso-8859-1?q?ak6MFaSjnHFW4M1bPIITB2qs8oepSjmj2+NVYvL/J6fZFra2nrHkFN/pARed?= =?iso-8859-1?q?FLTC6eCmNFuXMlfHxNSF3wTspQzafiAP6xKwVcTjxKItSjq/l/MQon7RjonE?= =?iso-8859-1?q?VWNN6FRp/noaZjHEeT5Gu+kW3YLfMNPrLNZjlCA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55de17d1-f2c3-49db-c873-08dbf2d7c995 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Dec 2023 01:41:21.4747 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: OlIU3njXmpGSqJXQCcZYXlAx7K8RNyQRla0IH1J9p5qpS3pMlSPmWdjKjFd0KoFuLc82GOF8QnZx85xzSAJckddQmurvz+W4CcJRzUILGik= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7285 X-Proofpoint-ORIG-GUID: NY1ySJ2ni0D9wvujoIJInK0EAWdhitnJ X-Proofpoint-GUID: NY1ySJ2ni0D9wvujoIJInK0EAWdhitnJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-01_24,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=412 malwarescore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 adultscore=0 spamscore=0 impostorscore=0 clxscore=1015 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312020009 From: David Woodhouse This allows a XenDevice implementation to know whether it was created by QEMU, or merely discovered in XenStore after the toolstack created it. This will allow us to create frontend/backend nodes only when we should, rather than unconditionally attempting to overwrite them from a driver domain which doesn't have privileges to do so. As an added benefit, it also means we no longer have to call the xen_backend_set_device() function from the device models immediately after calling qdev_realize_and_unref(). Even though we could make the argument that it's safe to do so, and the pointer to the unreffed device *will* actually still be valid, it still made my skin itch to look at it. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/block/xen-block.c | 3 +-- hw/char/xen_console.c | 2 +- hw/net/xen_nic.c | 2 +- hw/xen/xen-backend.c | 15 +-------------- hw/xen/xen-bus.c | 4 ++++ include/hw/xen/xen-backend.h | 2 -- include/hw/xen/xen-bus.h | 2 ++ 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 6d64ede94f..c2ac9db4a2 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -1081,13 +1081,12 @@ static void xen_block_device_create(XenBackendInstance *backend, blockdev->iothread = iothread; blockdev->drive = drive; + xendev->backend = backend; if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) { error_prepend(errp, "realization of device %s failed: ", type); goto fail; } - - xen_backend_set_device(backend, xendev); return; fail: diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 5cbee2f184..bef8a3a621 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -600,8 +600,8 @@ static void xen_console_device_create(XenBackendInstance *backend, goto fail; } + xendev->backend = backend; if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) { - xen_backend_set_device(backend, xendev); goto done; } diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index af4ba3f1e6..afa10c96e8 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -627,8 +627,8 @@ static void xen_net_device_create(XenBackendInstance *backend, net->dev = number; memcpy(&net->conf.macaddr, &mac, sizeof(mac)); + xendev->backend = backend; if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) { - xen_backend_set_device(backend, xendev); return; } diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c index b9bf70a9f5..b2e753ebc8 100644 --- a/hw/xen/xen-backend.c +++ b/hw/xen/xen-backend.c @@ -88,19 +88,6 @@ static void xen_backend_list_add(XenBackendInstance *backend) QLIST_INSERT_HEAD(&backend_list, backend, entry); } -static XenBackendInstance *xen_backend_list_find(XenDevice *xendev) -{ - XenBackendInstance *backend; - - QLIST_FOREACH(backend, &backend_list, entry) { - if (backend->xendev == xendev) { - return backend; - } - } - - return NULL; -} - bool xen_backend_exists(const char *type, const char *name) { const XenBackendImpl *impl = xen_backend_table_lookup(type); @@ -170,7 +157,7 @@ XenDevice *xen_backend_get_device(XenBackendInstance *backend) bool xen_backend_try_device_destroy(XenDevice *xendev, Error **errp) { - XenBackendInstance *backend = xen_backend_list_find(xendev); + XenBackendInstance *backend = xendev->backend; const XenBackendImpl *impl; if (!backend) { diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 4973e7d9c9..dd0171ab98 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -1079,6 +1079,10 @@ static void xen_device_realize(DeviceState *dev, Error **errp) } } + if (xendev->backend) { + xen_backend_set_device(xendev->backend, xendev); + } + xendev->exit.notify = xen_device_exit; qemu_add_exit_notifier(&xendev->exit); return; diff --git a/include/hw/xen/xen-backend.h b/include/hw/xen/xen-backend.h index 0f01631ae7..ea080ba7c9 100644 --- a/include/hw/xen/xen-backend.h +++ b/include/hw/xen/xen-backend.h @@ -10,8 +10,6 @@ #include "hw/xen/xen-bus.h" -typedef struct XenBackendInstance XenBackendInstance; - typedef void (*XenBackendDeviceCreate)(XenBackendInstance *backend, QDict *opts, Error **errp); typedef void (*XenBackendDeviceDestroy)(XenBackendInstance *backend, diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index 334ddd1ff6..7647c4c38e 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -14,9 +14,11 @@ #include "qom/object.h" typedef struct XenEventChannel XenEventChannel; +typedef struct XenBackendInstance XenBackendInstance; struct XenDevice { DeviceState qdev; + XenBackendInstance *backend; domid_t frontend_id; char *name; struct qemu_xs_handle *xsh;