From nobody Wed Dec 4 19:43:39 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1729689051; cv=none; d=zohomail.com; s=zohoarc; b=FNxz5o+z8QZk6n12+jEFEHXokgUnpUhsiNFDs+FYi53GuuUTTb+1jzQ1smtZujBVF169X3jdOf1tEfHczU2MRUNgppacf9vvcGjF9fTtBwPVRiEds5ijlr/q2rBuMPkDdS9GcWqQGw+y0rue2RzHt4oJw5m+mqBb1iGNIpiPKuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689051; h=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=R/jCtUub5rdGQ3ibE045xPBxKzrjJrpwGC8ELjHDU+0=; b=ME7gxV5DApOemeWpzUUxxXYKQRPp82Xw+AMoXTCqOxzylX6OEwnrxMAbNZMsutHLSY75skMYprQpKgjaKVoW2NpVKhCfZwV6P+eqZUv2dSqqPPt1NGNd9mfebK+0nfYRXhqkDxRnaTAP7CoHBILdwvR90QqU983sioKCSfYJFfI= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1729689051285711.83054139615; Wed, 23 Oct 2024 06:10:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824606.1238759 (Exim 4.92) (envelope-from ) id 1t3b7x-0006gY-R5; Wed, 23 Oct 2024 13:10:17 +0000 Received: by outflank-mailman (output) from mailman id 824606.1238759; Wed, 23 Oct 2024 13:10:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3b7x-0006gR-Nl; Wed, 23 Oct 2024 13:10:17 +0000 Received: by outflank-mailman (input) for mailman id 824606; Wed, 23 Oct 2024 13:10:16 +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 1t3b7w-0006ft-4v for xen-devel@lists.xenproject.org; Wed, 23 Oct 2024 13:10:16 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 24630b65-9140-11ef-a0be-8be0dac302b0; Wed, 23 Oct 2024 15:10:14 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0E0F91FDA2; Wed, 23 Oct 2024 13:10:14 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C0DA013A63; Wed, 23 Oct 2024 13:10:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 7ep2LbX1GGe+dwAAD6G6ig (envelope-from ); Wed, 23 Oct 2024 13:10:13 +0000 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: 24630b65-9140-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689014; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R/jCtUub5rdGQ3ibE045xPBxKzrjJrpwGC8ELjHDU+0=; b=hvrpHxok67YrGN7ETYvPX5Zde5uMbuVhY1TdYwk8wWkpWdkPS49o5F4gGX3QFtxU1x3Tf9 ogp14Jhdz/tsljAUDoX6eKJt3pJ40XQsnySdG0F2BU7FDRfxgtFtxUCQxp9MmO+fMMt5tI YNYv1yrH3nSb/KRm+Ocv18ZUkP745iM= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=hvrpHxok DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689014; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R/jCtUub5rdGQ3ibE045xPBxKzrjJrpwGC8ELjHDU+0=; b=hvrpHxok67YrGN7ETYvPX5Zde5uMbuVhY1TdYwk8wWkpWdkPS49o5F4gGX3QFtxU1x3Tf9 ogp14Jhdz/tsljAUDoX6eKJt3pJ40XQsnySdG0F2BU7FDRfxgtFtxUCQxp9MmO+fMMt5tI YNYv1yrH3nSb/KRm+Ocv18ZUkP745iM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 1/6] xen: add a domain unique id to each domain Date: Wed, 23 Oct 2024 15:10:00 +0200 Message-ID: <20241023131005.32144-2-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241023131005.32144-1-jgross@suse.com> References: <20241023131005.32144-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 0E0F91FDA2 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1729689051667116600 Content-Type: text/plain; charset="utf-8" Xenstore is referencing domains by their domid, but reuse of a domid can lead to the situation that Xenstore can't tell whether a domain with that domid has been deleted and created again without Xenstore noticing the domain is a new one now. Add a global domain creation unique id which is updated when creating a new domain, and store that value in struct domain of the new domain. The global unique id is initialized with the system time and updates are done via the xorshift algorithm which is used for pseudo random number generation, too (see https://en.wikipedia.org/wiki/Xorshift). Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V1: - make unique_id local to function (Jan Beulich) - add lock (Julien Grall) - add comment (Julien Grall) --- xen/common/domain.c | 20 ++++++++++++++++++++ xen/include/xen/sched.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/xen/common/domain.c b/xen/common/domain.c index 92263a4fbd..3948640fb0 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -562,6 +562,25 @@ static void _domain_destroy(struct domain *d) free_domain_struct(d); } =20 +static uint64_t get_unique_id(void) +{ + static uint64_t unique_id; + static DEFINE_SPINLOCK(lock); + uint64_t x =3D unique_id ? : NOW(); + + spin_lock(&lock); + + /* Pseudo-randomize id in order to avoid consumers relying on sequence= . */ + x ^=3D x << 13; + x ^=3D x >> 7; + x ^=3D x << 17; + unique_id =3D x; + + spin_unlock(&lock); + + return x; +} + static int sanitise_domain_config(struct xen_domctl_createdomain *config) { bool hvm =3D config->flags & XEN_DOMCTL_CDF_hvm; @@ -654,6 +673,7 @@ struct domain *domain_create(domid_t domid, =20 /* Sort out our idea of is_system_domain(). */ d->domain_id =3D domid; + d->unique_id =3D get_unique_id(); =20 /* Holding CDF_* internal flags. */ d->cdf =3D flags; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 90666576c2..1dd8a425f9 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -370,6 +370,9 @@ struct domain domid_t domain_id; =20 unsigned int max_vcpus; + + uint64_t unique_id; /* Unique domain identifier */ + struct vcpu **vcpu; =20 shared_info_t *shared_info; /* shared data area */ --=20 2.43.0