From nobody Fri Nov 22 11:27:21 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=1722427477; cv=none; d=zohomail.com; s=zohoarc; b=MIEhleMyhPj5FmpbRBPCqvK6qThQIjRVhye5v/VdWw/LUKgLhtKUG8LEGN87y4kT2mK+UwVfgYf2x/3IM8AdrjN2NT5XsOyvnFWTXGA7sDnAX1++cAQjiLRuOSZNIhJ6hmqvMcBSvQ8w7c3CsJ1hGle6yiRwBlmZJ5jtYU91VIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722427477; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X0gbgRWc2cl9Mm9yDqSZuShUHfl8oIG76nyaAhdJolY=; b=XqZ9YXyBXDJBMTqXg8zJeVKtVG1ew70KG6rIQLeZpnd427rnT2wwoM/gKMj6a60y7ua3ExoWGJbC3pLo3SxaA0nWTGPCOfSuWPLdDqD1mhMEZRxnAUBD8LSLTTbqEXLsYgPtx9JRTHimeNGss3yYIBznNqjFqNPk9X3h3cemISo= 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 1722427477133214.527482809905; Wed, 31 Jul 2024 05:04:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.768521.1179346 (Exim 4.92) (envelope-from ) id 1sZ83y-0007cs-59; Wed, 31 Jul 2024 12:04:14 +0000 Received: by outflank-mailman (output) from mailman id 768521.1179346; Wed, 31 Jul 2024 12:04:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZ83y-0007cl-2U; Wed, 31 Jul 2024 12:04:14 +0000 Received: by outflank-mailman (input) for mailman id 768521; Wed, 31 Jul 2024 12:04:13 +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 1sZ83w-0007cf-Ti for xen-devel@lists.xenproject.org; Wed, 31 Jul 2024 12:04:12 +0000 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [2a00:1450:4864:20::22e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fc9007d1-4f34-11ef-8776-851b0ebba9a2; Wed, 31 Jul 2024 14:04:06 +0200 (CEST) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2ef248ab2aeso84862501fa.0 for ; Wed, 31 Jul 2024 05:04:11 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb98dbsm760514766b.216.2024.07.31.05.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 05:04:09 -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: fc9007d1-4f34-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1722427450; x=1723032250; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=X0gbgRWc2cl9Mm9yDqSZuShUHfl8oIG76nyaAhdJolY=; b=r3GXqEAtBCFcibr9O43xBuWIQwvyk7cnJ7wVCSIQk1NWhru8FTZRck3EBs+0b/wfNI bgtAizIqxihfXH9+nZ9xcp7jOCh4gsZ6u59raJznEnav4zmHGURkaXxyS5Ir/JuacOwU vjdmrKHCO/xIjb1jxApp/11lKLxshzZaUfCUQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722427450; x=1723032250; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X0gbgRWc2cl9Mm9yDqSZuShUHfl8oIG76nyaAhdJolY=; b=ZpXT+bXUHSV8vqtHZwH158GoZFHnsXDL+gtp9SUFCyeB/4HNtiouUMVr8UVrfNYcVy kCFw1EWBHjUDhNcLtv2tbxJ/wYLjF4ACQLBqfLxB/x9rFgXWGGivlDWnmlY8AYDMVLju yhM+I5WIgF9fChZVsQycaw55Fc7i80cdoBZIYctDPMgBUvSn4GWpJIDWGInitB+2x7zT eMN5ezyyNf1APu0Wxbd5nCPKkVNpSxA9EMeBZfpopCdla+trNmGL5brCGqvD+kri0wDm wFyEzQ1NwkHUfj6hCgJtF1klHUDE3jRIgNY23MKHWqsXcVOLYuFqsZbj5aet46/sYiny ZvUA== X-Gm-Message-State: AOJu0YxoaSODGfi8H+pT9hZYigWnv1HycEUns4Og1wKhspD8kHtDHIjK /Mk7yqXrfhpfXqQFqvljhSTbY9Eo7pDCeZwioAuH9zJ+Ek7/+R0QBnRR07mQvnOu9oMJ6QMaJpt A X-Google-Smtp-Source: AGHT+IHfjkJFEQUtisi7OhG3DBCoi73hFYBAuUD5RurOriQYn7NUH6qhEhW43aB3N+amHwVk2MSDVw== X-Received: by 2002:a2e:8250:0:b0:2ef:2226:2317 with SMTP id 38308e7fff4ca-2f12ee12fe6mr120989151fa.20.1722427449595; Wed, 31 Jul 2024 05:04:09 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , Stefano Stabellini , Julien Grall Subject: [PATCH] xen/domain: Factor domlist_{insert,remove}() out of domain_{create,destroy}() Date: Wed, 31 Jul 2024 13:04:06 +0100 Message-Id: <20240731120406.3429430-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1722427478129116600 Content-Type: text/plain; charset="utf-8" These are opencoded linked list and hashtable manipulations. Factor them o= ut into static inline helpers, and discuss the consequence for the domain. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Stefano Stabellini CC: Julien Grall Calling domain_hash a hash is rather disingenuous... It's technically true, but it has terrible scaling. --- xen/common/domain.c | 80 +++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 256660473861..fc0a56673449 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -64,6 +64,57 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock); static struct domain *domain_hash[DOMAIN_HASH_SIZE]; struct domain *domain_list; =20 +/* + * Insert a domain into the domlist/hash. This allows the domain to be lo= oked + * up by domid, and therefore to be the subject of hypercalls/etc. + */ +static void domlist_insert(struct domain *d) +{ + struct domain **pd; + + spin_lock(&domlist_update_lock); + + /* domain_list is maintained in domid order. */ + pd =3D &domain_list; + for ( ; *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(d->domain_id)]; + rcu_assign_pointer(*pd, d); + rcu_assign_pointer(domain_hash[DOMAIN_HASH(d->domain_id)], d); + + spin_unlock(&domlist_update_lock); +} + +/* + * Remove a domain from the domlist/hash. This means the domain can no lo= nger + * be looked up by domid, and therefore can no longer be the subject of + * *subsequent* hypercalls/etc. In-progress hypercalls/etc can still oper= ate + * on the domain. + */ +static void domlist_remove(struct domain *d) +{ + struct domain **pd =3D &domain_list; + + spin_lock(&domlist_update_lock); + + pd =3D &domain_list; + while ( *pd !=3D d ) + pd =3D &(*pd)->next_in_list; + + rcu_assign_pointer(*pd, d->next_in_list); + + pd =3D &domain_hash[DOMAIN_HASH(d->domain_id)]; + while ( *pd !=3D d ) + pd =3D &(*pd)->next_in_hashbucket; + + rcu_assign_pointer(*pd, d->next_in_hashbucket); + + spin_unlock(&domlist_update_lock); +} + struct domain *hardware_domain __read_mostly; =20 #ifdef CONFIG_LATE_HWDOM @@ -589,7 +640,7 @@ struct domain *domain_create(domid_t domid, struct xen_domctl_createdomain *config, unsigned int flags) { - struct domain *d, **pd, *old_hwdom =3D NULL; + struct domain *d, *old_hwdom =3D NULL; enum { INIT_watchdog =3D 1u<<1, INIT_evtchn =3D 1u<<3, INIT_gnttab =3D 1u<<4, INIT_arch =3D 1u<= <5 }; int err, init_status =3D 0; @@ -758,17 +809,7 @@ struct domain *domain_create(domid_t domid, * Must not fail beyond this point, as our caller doesn't know whether * 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); + domlist_insert(d); =20 memcpy(d->handle, config->handle, sizeof(d->handle)); =20 @@ -1232,8 +1273,6 @@ static void cf_check complete_domain_destroy(struct r= cu_head *head) /* Release resources belonging to task @p. */ void domain_destroy(struct domain *d) { - struct domain **pd; - BUG_ON(!d->is_dying); =20 /* May be already destroyed, or get_domain() can race us. */ @@ -1242,17 +1281,8 @@ void domain_destroy(struct domain *d) =20 TRACE_TIME(TRC_DOM0_DOM_REM, d->domain_id); =20 - /* Delete from task list and task hashtable. */ - spin_lock(&domlist_update_lock); - pd =3D &domain_list; - while ( *pd !=3D d )=20 - pd =3D &(*pd)->next_in_list; - rcu_assign_pointer(*pd, d->next_in_list); - pd =3D &domain_hash[DOMAIN_HASH(d->domain_id)]; - while ( *pd !=3D d )=20 - pd =3D &(*pd)->next_in_hashbucket; - rcu_assign_pointer(*pd, d->next_in_hashbucket); - spin_unlock(&domlist_update_lock); + /* Remove from the domlist/hash. */ + domlist_remove(d); =20 /* Schedule RCU asynchronous completion of domain destroy. */ call_rcu(&d->rcu, complete_domain_destroy); base-commit: 561cba38ff551383a628dc93e64ab0691cfc92bf --=20 2.39.2