From nobody Thu Sep 19 00:19:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1721339896; cv=none; d=zohomail.com; s=zohoarc; b=NbfBBQJ9OsAWlV7gLvzSz7Y7/nDmDmWLkK3G9PlRMNFVuUmLiDZfn5lD5T6CZBrwfRd1fVnrzJCJQu6SmO7Wk5adVE0nGgBCqIzdtqBXENHy+LppPwQwO4xrYqKTrpc4beo0vpmX42gf/mmqf47M4wDepzdcfWXt3C0/nzm1HXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721339896; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0kD2ViH5db6Uhco+HhIi3wbdU8JjVgf/T8jwX9hiBjs=; b=UMXjo53gdsWU61xpVEN1v2fDWPi+dMlmX/QnBwalz7V1v4kKFr2zcwoSLLnKmTkxM0rU8vESb1eBqVsZ3YNgl51KCfrx0Ik3ur/PWb2O70VNgVIXMPaOO9uNgPlmN2YISpNBghH6KkV1IMc2rB4/YYBACJYNGcyfxLNwYxS0pu0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17213398960781014.8578153425489; Thu, 18 Jul 2024 14:58:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.760738.1170667 (Exim 4.92) (envelope-from ) id 1sUZ8Q-0003vB-Dz; Thu, 18 Jul 2024 21:57:58 +0000 Received: by outflank-mailman (output) from mailman id 760738.1170667; Thu, 18 Jul 2024 21:57:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sUZ8Q-0003v2-9y; Thu, 18 Jul 2024 21:57:58 +0000 Received: by outflank-mailman (input) for mailman id 760738; Thu, 18 Jul 2024 21:57:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sUZ8P-0002ha-1r for xen-devel@lists.xenproject.org; Thu, 18 Jul 2024 21:57:57 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c99aefcf-4550-11ef-8776-851b0ebba9a2; Thu, 18 Jul 2024 23:57:55 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2eeb2d60efbso20289261fa.1 for ; Thu, 18 Jul 2024 14:57:55 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a33de74e5sm5294266b.147.2024.07.18.14.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 14:57:53 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: c99aefcf-4550-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1721339874; x=1721944674; darn=lists.xenproject.org; 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=0kD2ViH5db6Uhco+HhIi3wbdU8JjVgf/T8jwX9hiBjs=; b=ANnUEvxc/vpl9CEkHpCop9xNZHENXl93pV0kHUKa+CTQ/vcGluBBuBpf6JSIfF9Lj2 HXY1mX1bzCJwai6fPNzjLLHtZ7IjwZmerDHEz/+gRIqsCOyysL8RfOPDi9zNVg+PtzVG hXXipgtRDf6S1ZMhYMZROGlB5k5oje/tguD2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721339874; x=1721944674; 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=0kD2ViH5db6Uhco+HhIi3wbdU8JjVgf/T8jwX9hiBjs=; b=Y8ezOTb66sZwZCt0wfcSSgTvdcFMQO0/nWlQbpYuhTWYYZAJfwGj7nwjxVnIs1aRql EqX6vvLRgCrW1DW5yEjRsHUKodOnnrTacQqVxECBp/Iu11eTle5MRs8aGMggM4yx7q2C 97ozrdmv7O2r00Del0frhQBnnv6JuC+CMO06wt2qpzoX/imm+mU8Wg76He1DxeJnAtuK gbJeP+/J0fQEmALBtAoieIaypO/5TNO8DeGBUZMpjw/ukkov1a2/+ebxHqh9j4CxPsLf hmLK1k20A0oZuhAQ+auez/SqAKNFjenOKB301McGndOQ6QOmu6YOWsBCF7Toz72LinDN DNzg== X-Gm-Message-State: AOJu0Yw+yvVzRjO6PHvHPvtEo0JVq85V+8NHJuwsKN1wMutXJopyaVPs omRGAo/psi5+48/Kq3VouSYDhVe7brr0jrsFnEze2oYkAxMPf6dNwU7wcMfh8SZeXlTle7N9d1K G X-Google-Smtp-Source: AGHT+IGHlZV97i3PU5wQnBNAb4+RoZtIr+55cNa39VxMHty8bOFfUy/Rr/pg4MsU3ofnYw53Ne+R8Q== X-Received: by 2002:a05:6512:6c7:b0:52e:9670:e40b with SMTP id 2adb3069b0e04-52ee53d2c31mr4190759e87.39.1721339874564; Thu, 18 Jul 2024 14:57:54 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko Subject: [PATCH 3/4] xen/domain: Simpliy domain_create() now the idle domain is complete earlier Date: Thu, 18 Jul 2024 22:57:43 +0100 Message-Id: <20240718215744.3892072-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718215744.3892072-1-andrew.cooper3@citrix.com> References: <20240718215744.3892072-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1721339897014116600 With x86 implementing arch_init_idle_domain(), there is no longer any need = to call arch_domain_create() with the idle domain. Have the idle domain exit early with all other system domains. Move the static-analysis ASSERT() earlier. Then, remove the !is_idle_domain() protections around the majority of domain_create() and remove one level of indentation. No practical change. Signed-off-by: Andrew Cooper Reviewed-by: Stefano Stabellini --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko --- xen/common/domain.c | 127 +++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 67 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index e312c820d641..8bc0bcd06ca5 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -688,95 +688,88 @@ struct domain *domain_create(domid_t domid, if ( is_idle_domain(d) ) arch_init_idle_domain(d); =20 - /* DOMID_{XEN,IO,etc} (other than IDLE) are sufficiently constructed. = */ - if ( is_system_domain(d) && !is_idle_domain(d) ) + /* DOMID_{XEN,IO,IDLE,etc} are sufficiently constructed. */ + if ( is_system_domain(d) ) return d; =20 + /* + * The assertion helps static analysis tools infer that config cannot = be + * NULL in this branch, which in turn means that it can be safely + * dereferenced. Therefore, this assertion is not redundant. + */ + ASSERT(config); + #ifdef CONFIG_HAS_PIRQ - if ( !is_idle_domain(d) ) - { - if ( !is_hardware_domain(d) ) - d->nr_pirqs =3D nr_static_irqs + extra_domU_irqs; - else - d->nr_pirqs =3D extra_hwdom_irqs ? nr_static_irqs + extra_hwdo= m_irqs - : arch_hwdom_irqs(d); - d->nr_pirqs =3D min(d->nr_pirqs, nr_irqs); + if ( !is_hardware_domain(d) ) + d->nr_pirqs =3D nr_static_irqs + extra_domU_irqs; + else + d->nr_pirqs =3D extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_ir= qs + : arch_hwdom_irqs(d); + d->nr_pirqs =3D min(d->nr_pirqs, nr_irqs); =20 - radix_tree_init(&d->pirq_tree); - } + radix_tree_init(&d->pirq_tree); #endif =20 if ( (err =3D arch_domain_create(d, config, flags)) !=3D 0 ) goto fail; init_status |=3D INIT_arch; =20 - if ( !is_idle_domain(d) ) - { - /* - * The assertion helps static analysis tools infer that config can= not - * be NULL in this branch, which in turn means that it can be safe= ly - * dereferenced. Therefore, this assertion is not redundant. - */ - ASSERT(config); - - watchdog_domain_init(d); - init_status |=3D INIT_watchdog; + watchdog_domain_init(d); + init_status |=3D INIT_watchdog; =20 - err =3D -ENOMEM; - d->iomem_caps =3D rangeset_new(d, "I/O Memory", RANGESETF_prettypr= int_hex); - d->irq_caps =3D rangeset_new(d, "Interrupts", 0); - if ( !d->iomem_caps || !d->irq_caps ) - goto fail; + err =3D -ENOMEM; + d->iomem_caps =3D rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_= hex); + d->irq_caps =3D rangeset_new(d, "Interrupts", 0); + if ( !d->iomem_caps || !d->irq_caps ) + goto fail; =20 - if ( (err =3D xsm_domain_create(XSM_HOOK, d, config->ssidref)) != =3D 0 ) - goto fail; + if ( (err =3D xsm_domain_create(XSM_HOOK, d, config->ssidref)) !=3D 0 ) + goto fail; =20 - d->controller_pause_count =3D 1; - atomic_inc(&d->pause_count); + d->controller_pause_count =3D 1; + atomic_inc(&d->pause_count); =20 - if ( (err =3D evtchn_init(d, config->max_evtchn_port)) !=3D 0 ) - goto fail; - init_status |=3D INIT_evtchn; + if ( (err =3D evtchn_init(d, config->max_evtchn_port)) !=3D 0 ) + goto fail; + init_status |=3D INIT_evtchn; =20 - if ( (err =3D grant_table_init(d, config->max_grant_frames, - config->max_maptrack_frames, - config->grant_opts)) !=3D 0 ) - goto fail; - init_status |=3D INIT_gnttab; + if ( (err =3D grant_table_init(d, config->max_grant_frames, + config->max_maptrack_frames, + config->grant_opts)) !=3D 0 ) + goto fail; + init_status |=3D INIT_gnttab; =20 - if ( (err =3D argo_init(d)) !=3D 0 ) - goto fail; + if ( (err =3D argo_init(d)) !=3D 0 ) + goto fail; =20 - err =3D -ENOMEM; + err =3D -ENOMEM; + d->pbuf =3D xzalloc_array(char, DOMAIN_PBUF_SIZE); + if ( !d->pbuf ) + goto fail; =20 - d->pbuf =3D xzalloc_array(char, DOMAIN_PBUF_SIZE); - if ( !d->pbuf ) - goto fail; + if ( (err =3D sched_init_domain(d, config->cpupool_id)) !=3D 0 ) + goto fail; =20 - if ( (err =3D sched_init_domain(d, config->cpupool_id)) !=3D 0 ) - goto fail; + if ( (err =3D late_hwdom_init(d)) !=3D 0 ) + goto fail; =20 - if ( (err =3D late_hwdom_init(d)) !=3D 0 ) - goto fail; + /* + * Must not fail beyond this point, as our caller doesn't know whether + * the domain has been entered into domain_list or not. + */ =20 - /* - * Must not fail beyond this point, as our caller doesn't know whe= ther - * the domain has been entered into domain_list or not. - */ + spin_lock(&domlist_update_lock); + pd =3D &domain_list; /* NB. domain_list maintained in order of domid. = */ + for ( pd =3D &domain_list; *pd !=3D NULL; pd =3D &(*pd)->next_in_list ) + if ( (*pd)->domain_id > d->domain_id ) + break; + d->next_in_list =3D *pd; + d->next_in_hashbucket =3D domain_hash[DOMAIN_HASH(domid)]; + rcu_assign_pointer(*pd, d); + rcu_assign_pointer(domain_hash[DOMAIN_HASH(domid)], d); + spin_unlock(&domlist_update_lock); =20 - spin_lock(&domlist_update_lock); - pd =3D &domain_list; /* NB. domain_list maintained in order of dom= id. */ - for ( pd =3D &domain_list; *pd !=3D NULL; pd =3D &(*pd)->next_in_l= ist ) - if ( (*pd)->domain_id > d->domain_id ) - break; - d->next_in_list =3D *pd; - d->next_in_hashbucket =3D domain_hash[DOMAIN_HASH(domid)]; - rcu_assign_pointer(*pd, d); - rcu_assign_pointer(domain_hash[DOMAIN_HASH(domid)], d); - spin_unlock(&domlist_update_lock); - - memcpy(d->handle, config->handle, sizeof(d->handle)); - } + memcpy(d->handle, config->handle, sizeof(d->handle)); =20 return d; =20 --=20 2.39.2