From patchwork Fri Dec 6 13:02:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13897184 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 68103E7717B for ; Fri, 6 Dec 2024 13:02:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.850265.1264720 (Exim 4.92) (envelope-from ) id 1tJXyl-0003wb-Tj; Fri, 06 Dec 2024 13:02:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 850265.1264720; Fri, 06 Dec 2024 13:02:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJXyl-0003wO-Qt; Fri, 06 Dec 2024 13:02:43 +0000 Received: by outflank-mailman (input) for mailman id 850265; Fri, 06 Dec 2024 13:02:42 +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 1tJXyk-00036p-QZ for xen-devel@lists.xenproject.org; Fri, 06 Dec 2024 13:02:42 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 60cf43f4-b3d2-11ef-a0d5-8be0dac302b0; Fri, 06 Dec 2024 14:02:42 +0100 (CET) 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-out1.suse.de (Postfix) with ESMTPS id A5F7B2115B; Fri, 6 Dec 2024 13:02:40 +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 69C7D13647; Fri, 6 Dec 2024 13:02:40 +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 TjhjGPD1UmfdTgAAD6G6ig (envelope-from ); Fri, 06 Dec 2024 13:02:40 +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: 60cf43f4-b3d2-11ef-a0d5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1733490161; 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=FGgbqx71ndv5sBTrCP7+ufVgCN8ZAPJccnfCSLfUpqw=; b=FfeKbF348liT+jCxEDdX5HPMHtvulKMD2tYDD3pJSSF9i5+ulbRRX4iYiu0AaHQ3CSOA4R tFm6mskQfb5wgOYJmjzCx2h8X+CAmvbpT+nf+TF8uKtULLRESeF5zlPkPoNtYFrxBKZIqa RpolKqtCRtapMyqtNDGZd3egZvRVtPg= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="Ly55pB/H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1733490160; 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=FGgbqx71ndv5sBTrCP7+ufVgCN8ZAPJccnfCSLfUpqw=; b=Ly55pB/HxsCmMbK6Ky7T+ctjUh9B9yT2AkO4VqKFwpyjWRKTX4vchxaSXPPHdK6Rfv9a0p dv5gIN4Fb4w/WbrXcwIE0h1ln8xXNtaC036NayP5eB45o4EL5kjfXhLeHYfkmkHtocABgz EpZ3E85QHeaShslHXne8AynQjX9T6Bs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Alejandro Vallejo Subject: [PATCH v2 3/7] xen: add a domain unique id to each domain Date: Fri, 6 Dec 2024 14:02:17 +0100 Message-ID: <20241206130221.17773-4-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241206130221.17773-1-jgross@suse.com> References: <20241206130221.17773-1-jgross@suse.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A5F7B2115B X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; DBL_BLOCKED_OPENRESOLVER(0.00)[cloud.com:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.com:dkim,suse.com:mid,suse.com:email,wikipedia.org:url] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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 Reviewed-by: Alejandro Vallejo --- V1: - make unique_id local to function (Jan Beulich) - add lock (Julien Grall) - add comment (Julien Grall) V2: - move reading unique_id into locked section (Julien Grall) - add comment (Alejandro Vallejo) --- xen/common/domain.c | 27 +++++++++++++++++++++++++++ xen/include/xen/sched.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/xen/common/domain.c b/xen/common/domain.c index 92263a4fbd..e33a0a5a21 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -562,6 +562,32 @@ static void _domain_destroy(struct domain *d) free_domain_struct(d); } +static uint64_t get_unique_id(void) +{ + static uint64_t unique_id; + static DEFINE_SPINLOCK(lock); + uint64_t x; + + spin_lock(&lock); + + x = unique_id ? : NOW(); + + /* + * Pseudo-randomize id in order to avoid consumers relying on sequence. + * Randomization algorithm has a period of 2^64 - 1. + * Unique id is not repeatable between resets and each id has the same + * lifetime as the domain it is associated with. + */ + x ^= x << 13; + x ^= x >> 7; + x ^= x << 17; + unique_id = x; + + spin_unlock(&lock); + + return x; +} + static int sanitise_domain_config(struct xen_domctl_createdomain *config) { bool hvm = config->flags & XEN_DOMCTL_CDF_hvm; @@ -654,6 +680,7 @@ struct domain *domain_create(domid_t domid, /* Sort out our idea of is_system_domain(). */ d->domain_id = domid; + d->unique_id = get_unique_id(); /* Holding CDF_* internal flags. */ d->cdf = flags; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 76e39378b3..711668e028 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -370,6 +370,9 @@ struct domain domid_t domain_id; unsigned int max_vcpus; + + uint64_t unique_id; /* Unique domain identifier */ + struct vcpu **vcpu; shared_info_t *shared_info; /* shared data area */