From nobody Wed Dec 4 09:17:23 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 From nobody Wed Dec 4 09:17:23 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=1729689078; cv=none; d=zohomail.com; s=zohoarc; b=Ufv0Z5H/6V/vGKnNJIKfmUynBaixNiz7TZYOjL5onB+de2KQriMB+hnU3nv02OGnplslVNNzQ8+93IpQu2a5nLNhxWJsQyKn97uYHzEizmDCLuf6NnvBETOsFPqmokpRlVo37h1aSJYCxWmOUF2c8V0GITOaPio7SoqSYjnn+GA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689078; 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=i3xMtPXgKn6GG8oVuMqyejq+21hcqPaJBGgXHENl+cw=; b=bSnqBkgU+CW7Za+dxzpn3Wik+0Yiz0LQQntjCtem6vw/feMi29ZM90zp0rYmLKC4G7ZCMzVbVTCP5i1Kyiav70AqdTEQrgi2EKR7R14tjZrcTer3K5Zg5Xdt/AMI4VrhHwP4oRksJJT8uPIyxWXfQTRzm77TyTTcFht4cJJ/alM= 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 1729689078355898.6783153489391; Wed, 23 Oct 2024 06:11:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824607.1238768 (Exim 4.92) (envelope-from ) id 1t3b84-0006yZ-2e; Wed, 23 Oct 2024 13:10:24 +0000 Received: by outflank-mailman (output) from mailman id 824607.1238768; Wed, 23 Oct 2024 13:10:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3b83-0006yS-W0; Wed, 23 Oct 2024 13:10:23 +0000 Received: by outflank-mailman (input) for mailman id 824607; Wed, 23 Oct 2024 13:10:22 +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 1t3b82-0006Ra-2K for xen-devel@lists.xenproject.org; Wed, 23 Oct 2024 13:10:22 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2779cc7c-9140-11ef-99a3-01e77a169b0f; Wed, 23 Oct 2024 15:10:20 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (unknown [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 A1E6D1FDA3; Wed, 23 Oct 2024 13:10:19 +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 6BC0613A63; Wed, 23 Oct 2024 13:10:19 +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 HKDkGLv1GGfGdwAAD6G6ig (envelope-from ); Wed, 23 Oct 2024 13:10:19 +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: 2779cc7c-9140-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689019; 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=i3xMtPXgKn6GG8oVuMqyejq+21hcqPaJBGgXHENl+cw=; b=PaOzNzSZcG26XL9qxihvCawE2U283fnLlqlhDp0dF1PsI/69+igiohrJUAXLahinNr43hC YbnnVwBxmuClh1LiFklCmovZLDe6IfTgv5r29F1ShW+ZF6cL800yYg+wA/fADwV+xwokbC D2+eJB+unAz2x4HiLr1jk8Z9pBuY5QE= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689019; 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=i3xMtPXgKn6GG8oVuMqyejq+21hcqPaJBGgXHENl+cw=; b=PaOzNzSZcG26XL9qxihvCawE2U283fnLlqlhDp0dF1PsI/69+igiohrJUAXLahinNr43hC YbnnVwBxmuClh1LiFklCmovZLDe6IfTgv5r29F1ShW+ZF6cL800yYg+wA/fADwV+xwokbC D2+eJB+unAz2x4HiLr1jk8Z9pBuY5QE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 2/6] xen: add bitmap to indicate per-domain state changes Date: Wed, 23 Oct 2024 15:10:01 +0200 Message-ID: <20241023131005.32144-3-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-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1729689079883116600 Content-Type: text/plain; charset="utf-8" Add a bitmap with one bit per possible domid indicating the respective domain has changed its state (created, deleted, dying, crashed, shutdown). Registering the VIRQ_DOM_EXC event will result in setting the bits for all existing domains and resetting all other bits. Resetting a bit will be done in a future patch. This information is needed for Xenstore to keep track of all domains. Signed-off-by: Juergen Gross --- xen/common/domain.c | 21 +++++++++++++++++++++ xen/common/event_channel.c | 2 ++ xen/include/xen/sched.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/xen/common/domain.c b/xen/common/domain.c index 3948640fb0..61b7899cb8 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -138,6 +138,22 @@ bool __read_mostly vmtrace_available; =20 bool __read_mostly vpmu_is_available; =20 +static DECLARE_BITMAP(dom_state_changed, DOMID_MASK + 1); + +void domain_reset_states(void) +{ + struct domain *d; + + bitmap_zero(dom_state_changed, DOMID_MASK + 1); + + rcu_read_lock(&domlist_read_lock); + + for_each_domain ( d ) + set_bit(d->domain_id, dom_state_changed); + + rcu_read_unlock(&domlist_read_lock); +} + static void __domain_finalise_shutdown(struct domain *d) { struct vcpu *v; @@ -152,6 +168,7 @@ static void __domain_finalise_shutdown(struct domain *d) return; =20 d->is_shut_down =3D 1; + set_bit(d->domain_id, dom_state_changed); if ( (d->shutdown_code =3D=3D SHUTDOWN_suspend) && d->suspend_evtchn ) evtchn_send(d, d->suspend_evtchn); else @@ -832,6 +849,7 @@ struct domain *domain_create(domid_t domid, */ domlist_insert(d); =20 + set_bit(d->domain_id, dom_state_changed); memcpy(d->handle, config->handle, sizeof(d->handle)); =20 return d; @@ -1097,6 +1115,7 @@ int domain_kill(struct domain *d) /* Mem event cleanup has to go here because the rings=20 * have to be put before we call put_domain. */ vm_event_cleanup(d); + set_bit(d->domain_id, dom_state_changed); put_domain(d); send_global_virq(VIRQ_DOM_EXC); /* fallthrough */ @@ -1286,6 +1305,8 @@ static void cf_check complete_domain_destroy(struct r= cu_head *head) =20 xfree(d->vcpu); =20 + set_bit(d->domain_id, dom_state_changed); + _domain_destroy(d); =20 send_global_virq(VIRQ_DOM_EXC); diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 8db2ca4ba2..9b87d29968 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -1296,6 +1296,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PA= RAM(void) arg) rc =3D evtchn_bind_virq(&bind_virq, 0); if ( !rc && __copy_to_guest(arg, &bind_virq, 1) ) rc =3D -EFAULT; /* Cleaning up here would be a mess! */ + if ( !rc && bind_virq.virq =3D=3D VIRQ_DOM_EXC ) + domain_reset_states(); break; } =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 1dd8a425f9..667863263d 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -800,6 +800,8 @@ void domain_resume(struct domain *d); =20 int domain_soft_reset(struct domain *d, bool resuming); =20 +void domain_reset_states(void); + int vcpu_start_shutdown_deferral(struct vcpu *v); void vcpu_end_shutdown_deferral(struct vcpu *v); =20 --=20 2.43.0 From nobody Wed Dec 4 09:17:23 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=1729689084; cv=none; d=zohomail.com; s=zohoarc; b=jNgpHlKNt+O4begtyi+uKw7MShiSZu17H96A7uu4Y6JRy0bbchaFcg2vJUR9Xw/WcvzwLWHqPvco2V3d+HTLWN2CpjcRHvd2qUETnreZiegMIw6s5sQsKQLNYXSeKbHhEvVn+f6H8JvBTpLvoYiY5dZh0V94/VQt7AnGqgASr2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689084; 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=rtCCiSYqzhqkGXHm58rEQmU6Y1e8RWcxAYmUU38jt1M=; b=mouK/ZMxoboABJ6fTT7dY9IdkuWFh+kjm21qnTMQlqLSz6kc7+Ufba/NwjG4R6NVP8SahEky+HPY6zuYKrRgHNraVqZWdwy94fS4q2QMd1S6WO7uNxuIdTDoUwQiwOatn3ZiYzfiwplzALmN78cVCXktpY4fZ6hR1ZrrFxJvm2I= 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 1729689084287840.2611947493208; Wed, 23 Oct 2024 06:11:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824608.1238779 (Exim 4.92) (envelope-from ) id 1t3b89-0007IA-Bt; Wed, 23 Oct 2024 13:10:29 +0000 Received: by outflank-mailman (output) from mailman id 824608.1238779; Wed, 23 Oct 2024 13:10:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3b89-0007Hx-8m; Wed, 23 Oct 2024 13:10:29 +0000 Received: by outflank-mailman (input) for mailman id 824608; Wed, 23 Oct 2024 13:10:27 +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 1t3b87-0006Ra-Ps for xen-devel@lists.xenproject.org; Wed, 23 Oct 2024 13:10:27 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2aefd767-9140-11ef-99a3-01e77a169b0f; Wed, 23 Oct 2024 15:10:25 +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-out1.suse.de (Postfix) with ESMTPS id 6520721F9E; Wed, 23 Oct 2024 13:10:25 +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 1712813A63; Wed, 23 Oct 2024 13:10:25 +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 EAPoA8H1GGfQdwAAD6G6ig (envelope-from ); Wed, 23 Oct 2024 13:10:25 +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: 2aefd767-9140-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689025; 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=rtCCiSYqzhqkGXHm58rEQmU6Y1e8RWcxAYmUU38jt1M=; b=RfhUd+8M3on1g0OrGEqSSrQWGl6ctFvr16HrqLVVYXFy6NLDYgVu2btE39M70kco8AfnB9 fAId4RJyP9HHkRfTNVuqQ6Z+GfLQixkOyX59ra0pn3dk9GzYwAYhpBEGwvUTtZQ+VInW8p EgbpNvCLa2wKFve6adw9I+F/Wn2hgQ8= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=RfhUd+8M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689025; 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=rtCCiSYqzhqkGXHm58rEQmU6Y1e8RWcxAYmUU38jt1M=; b=RfhUd+8M3on1g0OrGEqSSrQWGl6ctFvr16HrqLVVYXFy6NLDYgVu2btE39M70kco8AfnB9 fAId4RJyP9HHkRfTNVuqQ6Z+GfLQixkOyX59ra0pn3dk9GzYwAYhpBEGwvUTtZQ+VInW8p EgbpNvCLa2wKFve6adw9I+F/Wn2hgQ8= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , "Daniel P. Smith" , Anthony PERARD , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 3/6] xen: add new domctl get_changed_domain Date: Wed, 23 Oct 2024 15:10:02 +0200 Message-ID: <20241023131005.32144-4-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: 6520721F9E X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; 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)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[8]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCVD_COUNT_TWO(0.00)[2]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; 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: 1729689085988116600 Content-Type: text/plain; charset="utf-8" Add a new domctl sub-function to get data of a domain having changed state (this is needed by Xenstore). The returned state just contains the domid, the domain unique id, and some flags (existing, shutdown, dying). In order to enable Xenstore stubdom being built for multiple Xen versions, make this domctl stable. For stable domctls the interface_version is specific to the respective domctl op and it is an in/out parameter: On input the caller is specifying the desired version of the op, while on output the hypervisor will return the used version (this will be at max the caller supplied version, but might be lower in case the hypervisor doesn't support this version). Signed-off-by: Juergen Gross --- V1: - use a domctl subop for the new interface (Jan Beulich) --- tools/flask/policy/modules/dom0.te | 2 +- xen/common/domain.c | 51 +++++++++++++++++++++++++++++ xen/common/domctl.c | 19 ++++++++++- xen/common/event_channel.c | 9 ++++- xen/include/public/domctl.h | 33 +++++++++++++++++++ xen/include/xen/event.h | 6 ++++ xen/include/xen/sched.h | 2 ++ xen/include/xsm/dummy.h | 8 +++++ xen/include/xsm/xsm.h | 6 ++++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 7 ++++ xen/xsm/flask/policy/access_vectors | 2 ++ 12 files changed, 143 insertions(+), 3 deletions(-) diff --git a/tools/flask/policy/modules/dom0.te b/tools/flask/policy/module= s/dom0.te index 16b8c9646d..6043c01b12 100644 --- a/tools/flask/policy/modules/dom0.te +++ b/tools/flask/policy/modules/dom0.te @@ -40,7 +40,7 @@ allow dom0_t dom0_t:domain { }; allow dom0_t dom0_t:domain2 { set_cpu_policy gettsc settsc setscheduler set_vnumainfo - get_vnumainfo psr_cmt_op psr_alloc get_cpu_policy + get_vnumainfo psr_cmt_op psr_alloc get_cpu_policy get_domain_state }; allow dom0_t dom0_t:resource { add remove }; =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 61b7899cb8..e55c6f6c5e 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -154,6 +154,57 @@ void domain_reset_states(void) rcu_read_unlock(&domlist_read_lock); } =20 +static void set_domain_state_info(struct xen_domctl_get_domain_state *info, + const struct domain *d) +{ + info->state =3D XEN_DOMCTL_GETDOMSTATE_STATE_EXIST; + if ( d->is_shut_down ) + info->state |=3D XEN_DOMCTL_GETDOMSTATE_STATE_SHUTDOWN; + if ( d->is_dying =3D=3D DOMDYING_dead ) + info->state |=3D XEN_DOMCTL_GETDOMSTATE_STATE_DYING; + info->unique_id =3D d->unique_id; +} + +int get_domain_state(struct xen_domctl_get_domain_state *info, struct doma= in *d) +{ + unsigned int dom; + + memset(info, 0, sizeof(*info)); + + if ( d ) + { + set_domain_state_info(info, d); + + return 0; + } + + while ( (dom =3D find_first_bit(dom_state_changed, DOMID_MASK + 1)) < + DOMID_FIRST_RESERVED ) + { + d =3D rcu_lock_domain_by_id(dom); + + if ( test_and_clear_bit(dom, dom_state_changed) ) + { + info->domid =3D dom; + if ( d ) + { + set_domain_state_info(info, d); + + rcu_unlock_domain(d); + } + + return 0; + } + + if ( d ) + { + rcu_unlock_domain(d); + } + } + + return -ENOENT; +} + static void __domain_finalise_shutdown(struct domain *d) { struct vcpu *v; diff --git a/xen/common/domctl.c b/xen/common/domctl.c index ea16b75910..e030cce2ec 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -278,6 +278,11 @@ static struct vnuma_info *vnuma_init(const struct xen_= domctl_vnuma *uinfo, return ERR_PTR(ret); } =20 +static bool is_stable_domctl(uint32_t cmd) +{ + return cmd =3D=3D XEN_DOMCTL_get_domain_state; +} + long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) { long ret =3D 0; @@ -288,7 +293,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) if ( copy_from_guest(op, u_domctl, 1) ) return -EFAULT; =20 - if ( op->interface_version !=3D XEN_DOMCTL_INTERFACE_VERSION ) + if ( op->interface_version !=3D XEN_DOMCTL_INTERFACE_VERSION && + !is_stable_domctl(op->cmd) ) return -EACCES; =20 switch ( op->cmd ) @@ -309,6 +315,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) fallthrough; case XEN_DOMCTL_test_assign_device: case XEN_DOMCTL_vm_event_op: + case XEN_DOMCTL_get_domain_state: if ( op->domain =3D=3D DOMID_INVALID ) { d =3D NULL; @@ -866,6 +873,16 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_= domctl) __HYPERVISOR_domctl, "h", u_domctl); break; =20 + case XEN_DOMCTL_get_domain_state: + ret =3D xsm_get_domain_state(XSM_HOOK, d); + if ( ret ) + break; + + copyback =3D 1; + op->interface_version =3D XEN_DOMCTL_GETDOMSTATE_VERS_MAX; + ret =3D get_domain_state(&op->u.get_domain_state, d); + break; + default: ret =3D arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 9b87d29968..13484b3e0d 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -969,11 +969,18 @@ static struct domain *global_virq_handlers[NR_VIRQS] = __read_mostly; =20 static DEFINE_SPINLOCK(global_virq_handlers_lock); =20 +struct domain *get_global_virq_handler(uint32_t virq) +{ + ASSERT(virq_is_global(virq)); + + return global_virq_handlers[virq] ?: hardware_domain; +} + void send_global_virq(uint32_t virq) { ASSERT(virq_is_global(virq)); =20 - send_guest_global_virq(global_virq_handlers[virq] ?: hardware_domain, = virq); + send_guest_global_virq(get_global_virq_handler(virq), virq); } =20 int set_global_virq_handler(struct domain *d, uint32_t virq) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 353f831e40..63607f7754 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -28,6 +28,7 @@ * Pure additions (e.g. new sub-commands) or compatible interface changes * (e.g. adding semantics to 0-checked input fields or data to zeroed outp= ut * fields) don't require a change of the version. + * Stable ops are NOT covered by XEN_DOMCTL_INTERFACE_VERSION! * * Last version bump: Xen 4.19 */ @@ -1236,7 +1237,37 @@ struct xen_domctl_dt_overlay { }; #endif =20 +/* + * XEN_DOMCTL_get_domain_state (stable interface) + * + * Get state information of a domain. + * + * In case domain is DOMID_INVALID, return information about a domain havi= ng + * changed state and reset the state change indicator for that domain. This + * function is usable only by a domain having registered the VIRQ_DOM_EXC + * event (normally Xenstore). + * + * Supported interface versions: 0x00000000 + */ +#define XEN_DOMCTL_GETDOMSTATE_VERS_MAX 0 +struct xen_domctl_get_domain_state { + domid_t domid; + uint16_t state; +#define XEN_DOMCTL_GETDOMSTATE_STATE_EXIST 0x0001 /* Domain is existi= ng. */ +#define XEN_DOMCTL_GETDOMSTATE_STATE_SHUTDOWN 0x0002 /* Shutdown finishe= d. */ +#define XEN_DOMCTL_GETDOMSTATE_STATE_DYING 0x0004 /* Domain dying. */ + uint32_t pad1; /* Returned as 0. */ + uint64_t unique_id; /* Unique domain identifier. */ + uint64_t pad2[6]; /* Returned as 0. */ +}; + struct xen_domctl { +/* + * Stable domctl ops: + * interface_version is per cmd, hypervisor can support multiple versions + * and will return used version (at max caller supplied value) in + * interface_version on return. + */ uint32_t cmd; #define XEN_DOMCTL_createdomain 1 #define XEN_DOMCTL_destroydomain 2 @@ -1325,6 +1356,7 @@ struct xen_domctl { #define XEN_DOMCTL_set_paging_mempool_size 86 #define XEN_DOMCTL_dt_overlay 87 #define XEN_DOMCTL_gsi_permission 88 +#define XEN_DOMCTL_get_domain_state 89 /* stable interface */ #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1391,6 +1423,7 @@ struct xen_domctl { #if defined(__arm__) || defined(__aarch64__) struct xen_domctl_dt_overlay dt_overlay; #endif + struct xen_domctl_get_domain_state get_domain_state; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 48b79f3d62..f380668609 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -43,6 +43,12 @@ void send_guest_global_virq(struct domain *d, uint32_t v= irq); */ int set_global_virq_handler(struct domain *d, uint32_t virq); =20 +/* + * get_global_virq_handler: Get domain handling a global virq. + * @virq: Virtual IRQ number (VIRQ_*), must be global + */ +struct domain *get_global_virq_handler(uint32_t virq); + /* * send_guest_pirq: * @d: Domain to which physical IRQ should be sent diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 667863263d..eb256de9d5 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -801,6 +801,8 @@ void domain_resume(struct domain *d); int domain_soft_reset(struct domain *d, bool resuming); =20 void domain_reset_states(void); +int get_domain_state(struct xen_domctl_get_domain_state *info, + struct domain *d); =20 int vcpu_start_shutdown_deferral(struct vcpu *v); void vcpu_end_shutdown_deferral(struct vcpu *v); diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 7956f27a29..eaf5b05093 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -173,6 +173,7 @@ static XSM_INLINE int cf_check xsm_domctl( case XEN_DOMCTL_unbind_pt_irq: return xsm_default_action(XSM_DM_PRIV, current->domain, d); case XEN_DOMCTL_getdomaininfo: + case XEN_DOMCTL_get_domain_state: return xsm_default_action(XSM_XS_PRIV, current->domain, d); default: return xsm_default_action(XSM_PRIV, current->domain, d); @@ -815,6 +816,13 @@ static XSM_INLINE int cf_check xsm_argo_send( =20 #endif /* CONFIG_ARGO */ =20 +static XSM_INLINE int cf_check xsm_get_domain_state( + XSM_DEFAULT_ARG struct domain *d) +{ + XSM_ASSERT_ACTION(XSM_HOOK); + return xsm_default_action(action, current->domain, d); +} + #include static XSM_INLINE int cf_check xsm_xen_version(XSM_DEFAULT_ARG uint32_t op) { diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 627c0d2731..933b3889c9 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -201,6 +201,7 @@ struct xsm_ops { int (*argo_register_any_source)(const struct domain *d); int (*argo_send)(const struct domain *d, const struct domain *t); #endif + int (*get_domain_state)(struct domain *d); }; =20 #ifdef CONFIG_XSM @@ -775,6 +776,11 @@ static inline int xsm_argo_send(const struct domain *d= , const struct domain *t) =20 #endif /* CONFIG_ARGO */ =20 +static inline int xsm_get_domain_state(struct domain *d) +{ + return alternative_call(xsm_ops.get_domain_state, d); +} + #endif /* XSM_NO_WRAPPERS */ =20 #ifdef CONFIG_MULTIBOOT diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index e6ffa948f7..ce6fbdc6c5 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -148,6 +148,7 @@ static const struct xsm_ops __initconst_cf_clobber dumm= y_ops =3D { .argo_register_any_source =3D xsm_argo_register_any_source, .argo_send =3D xsm_argo_send, #endif + .get_domain_state =3D xsm_get_domain_state, }; =20 void __init xsm_fixup_ops(struct xsm_ops *ops) diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index dfa23738cd..b1bad7e420 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -686,6 +686,7 @@ static int cf_check flask_domctl(struct domain *d, unsi= gned int cmd, case XEN_DOMCTL_memory_mapping: case XEN_DOMCTL_set_target: case XEN_DOMCTL_vm_event_op: + case XEN_DOMCTL_get_domain_state: =20 /* These have individual XSM hooks (arch/../domctl.c) */ case XEN_DOMCTL_bind_pt_irq: @@ -1853,6 +1854,11 @@ static int cf_check flask_argo_send( =20 #endif =20 +static int cf_check flask_get_domain_state(struct domain *d) +{ + return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__GET_DOMAIN_STATE); +} + static const struct xsm_ops __initconst_cf_clobber flask_ops =3D { .set_system_active =3D flask_set_system_active, .security_domaininfo =3D flask_security_domaininfo, @@ -1989,6 +1995,7 @@ static const struct xsm_ops __initconst_cf_clobber fl= ask_ops =3D { .argo_register_any_source =3D flask_argo_register_any_source, .argo_send =3D flask_argo_send, #endif + .get_domain_state =3D flask_get_domain_state, }; =20 const struct xsm_ops *__init flask_init( diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/acc= ess_vectors index a35e3d4c51..c9a8eeda4e 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -251,6 +251,8 @@ class domain2 resource_map # XEN_DOMCTL_get_cpu_policy get_cpu_policy +# XEN_DOMCTL_get_domain_state + get_domain_state } =20 # Similar to class domain, but primarily contains domctls related to HVM d= omains --=20 2.43.0 From nobody Wed Dec 4 09:17:23 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=1729689063; cv=none; d=zohomail.com; s=zohoarc; b=kkr/oKQuVvTt+HP0PaZr+KqDdgtxUFmLG3grpm2pL8iDT7uXwvwHDRZioe6jad07oDLbU2lvUh/EKACXZsIsy8vIkFbCLQ50g32Y7clUyzGrGkHX/udg/yujnBcHNGBi80LEY3OhpQgIB8/4cYpZo69EH2Z0Ytj8pqoeAI72PxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689063; 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=7x+KJfCSsvOCZOfslmW0TQxvrIiaIaj2/srt/KQEvU8=; b=ENX+gWM7VmEHGiNZmnI3eGm51p9biusR4l+JyRpLXPxj0+F9Op6O9zQjnmn7jnE4vpFhLAURmNZo06rZtYU06AGOvA93kf9hSRcKaXr60EiXf7YPbVPfuRkxXcF+Nv2j3ttDi24LwgK5l9tRIok7VNAgjrniw9fyiU5seXrRpg0= 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 1729689063662261.7229435493855; Wed, 23 Oct 2024 06:11:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824609.1238789 (Exim 4.92) (envelope-from ) id 1t3b8E-0007cW-P3; Wed, 23 Oct 2024 13:10:34 +0000 Received: by outflank-mailman (output) from mailman id 824609.1238789; Wed, 23 Oct 2024 13:10: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 1t3b8E-0007cN-Lp; Wed, 23 Oct 2024 13:10:34 +0000 Received: by outflank-mailman (input) for mailman id 824609; Wed, 23 Oct 2024 13:10:33 +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 1t3b8D-0006Ra-AA for xen-devel@lists.xenproject.org; Wed, 23 Oct 2024 13:10:33 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2e4a88f7-9140-11ef-99a3-01e77a169b0f; Wed, 23 Oct 2024 15:10:31 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (unknown [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 ECDB321F9E; Wed, 23 Oct 2024 13:10:30 +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 C797213A63; Wed, 23 Oct 2024 13:10:30 +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 sOZNL8b1GGfcdwAAD6G6ig (envelope-from ); Wed, 23 Oct 2024 13:10:30 +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: 2e4a88f7-9140-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689031; 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=7x+KJfCSsvOCZOfslmW0TQxvrIiaIaj2/srt/KQEvU8=; b=MFOxjtTULwA6Y5YJQTM/E5+0Pzp1nGUNM83lA/Evz3H9ir7J4zu7R1DhNLukfJhXfagKtl UuOk9WmlQBTNGrC71OLbWW5lB0mLm6ITOO8o7j1WpjUVVU6LV5+fIZAF5FPW6YBU/WvGQy ECDA7BPz0mSs7dD9ENAfzx5nsZ25Kr4= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689030; 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=7x+KJfCSsvOCZOfslmW0TQxvrIiaIaj2/srt/KQEvU8=; b=rFiBDNcb2kc9YSQINMEr8u3HC1Dx2UjDEul1Bl71l6MsDrQZks93L8DLvzUa3jJHJfDW6F P98y1pTrFVY9KLxBdJ5QxihOjvmAkflZ9GpbLWJ1t+zGo8gB0w+JKD/sFeUPqlq6w/kov5 x0n0Q1Ai8Am8XPKMRdw99ENFJ1qVm9M= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Anthony PERARD Subject: [PATCH 4/6] tools/libs: add a new libxenmanage library Date: Wed, 23 Oct 2024 15:10:03 +0200 Message-ID: <20241023131005.32144-5-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-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1729689066081116600 Content-Type: text/plain; charset="utf-8" In order to have a stable interface in user land for using stable domctl and possibly later sysctl interfaces, add a new library libxenmanage. Signed-off-by: Juergen Gross --- V1: - new patch --- tools/include/xenmanage.h | 98 +++++++++++++++++ tools/libs/Makefile | 1 + tools/libs/manage/Makefile | 10 ++ tools/libs/manage/Makefile.common | 1 + tools/libs/manage/core.c | 170 +++++++++++++++++++++++++++++ tools/libs/manage/libxenmanage.map | 8 ++ tools/libs/uselibs.mk | 2 + 7 files changed, 290 insertions(+) create mode 100644 tools/include/xenmanage.h create mode 100644 tools/libs/manage/Makefile create mode 100644 tools/libs/manage/Makefile.common create mode 100644 tools/libs/manage/core.c create mode 100644 tools/libs/manage/libxenmanage.map diff --git a/tools/include/xenmanage.h b/tools/include/xenmanage.h new file mode 100644 index 0000000000..2e6c3dedaa --- /dev/null +++ b/tools/include/xenmanage.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 SUSE Software Solutions Germany GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ +#ifndef XENMANAGE_H +#define XENMANAGE_H + +#include + +/* Callers who don't care don't need to #include */ +struct xentoollog_logger; + +typedef struct xenmanage_handle xenmanage_handle; + +/* + * Open libxenmanage. + * + * Get a handle of the xenmanage library. The handle is required for all + * further operations of the library. + * Parameters: + * logger: Logging function to use. If NULL logging is done to stder= r. + * open_flags: Only 0 supported. + * Return value: Handle or NULL if error. + */ +xenmanage_handle *xenmanage_open(struct xentoollog_logger *logger, + unsigned int open_flags); + +/* + * Close libxenmanage. + * + * Return a handle of the xenmanage library. + * Parameters: + * hdl: Handle obtained by xenmanage_open(). + * Return value: always 0. + */ +int xenmanage_close(xenmanage_handle *hdl); + +#define XENMANAGE_GETDOMSTATE_STATE_EXIST 0x0001 /* Domain is existin= g. */ +#define XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN 0x0002 /* Shutdown finished= . */ +#define XENMANAGE_GETDOMSTATE_STATE_DYING 0x0004 /* Domain dying. */ + +/* + * Return state information of an existing domain. + * + * Returns the domain state and unique id of the given domain. + * Parameters: + * hdl: handle returned by xenmanage_open() + * domid: domain id of the domain to get the information for + * state: where to store the state (XENMANAGE_GETDOMSTATE_STATE_ fla= gs, + * nothing stored if NULL) + * unique_id: where to store the unique id of the domain (nothing stored= if + * NULL) + * Return value: 0 if information was stored, -1 else (errno is set) + */ +int xenmanage_get_domain_info(xenmanage_handle *hdl, unsigned int domid, + unsigned int *state, uint64_t *unique_id); + +/* + * Return information of a domain having changed state recently. + * + * Returns the domain id, state and unique id of a domain having changed + * state (any of the state bits was modified) since the last time informat= ion + * for that domain was returned by this function. Only usable by callers w= ho + * have registered the VIRQ_DOM_EXC event (normally Xenstore). + * Parameters: + * hdl: handle returned by xenmanage_open() + * domid: where to store the domid of the domain (not NULL) + * state: where to store the state (XENMANAGE_GETDOMSTATE_STATE_ fla= gs, + * nothing stored if NULL) + * unique_id: where to store the unique id of the domain (nothing stored= if + * NULL) + * Return value: 0 if information was stored, -1 else (errno is set) + */ +int xenmanage_get_changed_domain(xenmanage_handle *hdl, unsigned int *domi= d, + unsigned int *state, uint64_t *unique_id); +#endif /* XENMANAGE_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libs/Makefile b/tools/libs/Makefile index 1afcd12e2b..d39516c1b3 100644 --- a/tools/libs/Makefile +++ b/tools/libs/Makefile @@ -12,6 +12,7 @@ SUBDIRS-y +=3D devicemodel SUBDIRS-y +=3D ctrl SUBDIRS-y +=3D guest SUBDIRS-y +=3D hypfs +SUBDIRS-y +=3D manage SUBDIRS-y +=3D store SUBDIRS-y +=3D stat SUBDIRS-$(CONFIG_Linux) +=3D vchan diff --git a/tools/libs/manage/Makefile b/tools/libs/manage/Makefile new file mode 100644 index 0000000000..dbfe70d259 --- /dev/null +++ b/tools/libs/manage/Makefile @@ -0,0 +1,10 @@ +XEN_ROOT =3D $(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +MAJOR =3D 1 +MINOR =3D 0 +version-script :=3D libxenmanage.map + +include Makefile.common + +include $(XEN_ROOT)/tools/libs/libs.mk diff --git a/tools/libs/manage/Makefile.common b/tools/libs/manage/Makefile= .common new file mode 100644 index 0000000000..d9efe3462e --- /dev/null +++ b/tools/libs/manage/Makefile.common @@ -0,0 +1 @@ +OBJS-y +=3D core.o diff --git a/tools/libs/manage/core.c b/tools/libs/manage/core.c new file mode 100644 index 0000000000..0c9199f829 --- /dev/null +++ b/tools/libs/manage/core.c @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2024 SUSE Software Solutions Germany GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#define __XEN_TOOLS__ 1 + +#define _GNU_SOURCE + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +struct xenmanage_handle { + xentoollog_logger *logger, *logger_tofree; + unsigned int flags; + xencall_handle *xcall; +}; + +xenmanage_handle *xenmanage_open(xentoollog_logger *logger, + unsigned open_flags) +{ + xenmanage_handle *hdl =3D calloc(1, sizeof(*hdl)); + int saved_errno; + + if ( !hdl ) + return NULL; + + if ( open_flags ) + { + errno =3D EINVAL; + goto err; + } + + hdl->flags =3D open_flags; + hdl->logger =3D logger; + hdl->logger_tofree =3D NULL; + + if ( !hdl->logger ) + { + hdl->logger =3D hdl->logger_tofree =3D + (xentoollog_logger *) + xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); + if ( !hdl->logger ) + goto err; + } + + hdl->xcall =3D xencall_open(hdl->logger, 0); + if ( !hdl->xcall ) + goto err; + + return hdl; + +err: + saved_errno =3D errno; + xenmanage_close(hdl); + errno =3D saved_errno; + + return NULL; +} + +int xenmanage_close(xenmanage_handle *hdl) +{ + if ( !hdl ) + return 0; + + xencall_close(hdl->xcall); + xtl_logger_destroy(hdl->logger_tofree); + free(hdl); + return 0; +} + +static int xenmanage_do_domctl_get_domain_state(xenmanage_handle *hdl, + unsigned int domid_in, + unsigned int *domid_out, + unsigned int *state, + uint64_t *unique_id) +{ + struct xen_domctl *buf; + struct xen_domctl_get_domain_state *st; + int saved_errno; + int ret; + + buf =3D xencall_alloc_buffer(hdl->xcall, sizeof(*buf)); + if ( !buf ) + { + errno =3D ENOMEM; + return -1; + } + + memset(buf, 0, sizeof(*buf)); + + buf->cmd =3D XEN_DOMCTL_get_domain_state; + buf->interface_version =3D XEN_DOMCTL_GETDOMSTATE_VERS_MAX; + buf->domain =3D domid_in; + + ret =3D xencall1(hdl->xcall, __HYPERVISOR_domctl, (unsigned long)buf); + saved_errno =3D errno; + if ( !ret ) + { + st =3D &buf->u.get_domain_state; + + if ( domid_out ) + *domid_out =3D st->domid; + if ( state ) + { + *state =3D 0; + if ( st->state & XEN_DOMCTL_GETDOMSTATE_STATE_EXIST ) + *state |=3D XENMANAGE_GETDOMSTATE_STATE_EXIST; + if ( st->state & XEN_DOMCTL_GETDOMSTATE_STATE_SHUTDOWN ) + *state |=3D XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN; + if ( st->state & XEN_DOMCTL_GETDOMSTATE_STATE_DYING ) + *state |=3D XENMANAGE_GETDOMSTATE_STATE_DYING; + } + if ( unique_id ) + *unique_id =3D st->unique_id; + } + + xencall_free_buffer(hdl->xcall, buf); + + errno =3D saved_errno; + + return ret; +} + +int xenmanage_get_domain_info(xenmanage_handle *hdl, unsigned int domid, + unsigned int *state, uint64_t *unique_id) +{ + if ( !hdl || domid >=3D DOMID_FIRST_RESERVED ) + { + errno =3D EINVAL; + return -1; + } + + return xenmanage_do_domctl_get_domain_state(hdl, domid, NULL, state, + unique_id); +} + +int xenmanage_get_changed_domain(xenmanage_handle *hdl, unsigned int *domi= d, + unsigned int *state, uint64_t *unique_id) +{ + if ( !hdl || !domid ) + { + errno =3D EINVAL; + return -1; + } + + return xenmanage_do_domctl_get_domain_state(hdl, DOMID_INVALID, domid, + state, unique_id); +} diff --git a/tools/libs/manage/libxenmanage.map b/tools/libs/manage/libxenm= anage.map new file mode 100644 index 0000000000..65ec76f882 --- /dev/null +++ b/tools/libs/manage/libxenmanage.map @@ -0,0 +1,8 @@ +VERS_1.0 { + global: + xenmanage_open; + xenmanage_close; + xenmanage_get_domain_info; + xenmanage_get_changed_domain; + local: *; /* Do not expose anything by default */ +}; diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk index 7aa8d83e06..c0a234cfec 100644 --- a/tools/libs/uselibs.mk +++ b/tools/libs/uselibs.mk @@ -16,6 +16,8 @@ LIBS_LIBS +=3D devicemodel USELIBS_devicemodel :=3D toollog toolcore call LIBS_LIBS +=3D hypfs USELIBS_hypfs :=3D toollog toolcore call +LIBS_LIBS +=3D manage +USELIBS_manage :=3D toollog toolcore call LIBS_LIBS +=3D ctrl USELIBS_ctrl :=3D toollog call evtchn gnttab foreignmemory devicemodel LIBS_LIBS +=3D guest --=20 2.43.0 From nobody Wed Dec 4 09:17:23 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=1729689090; cv=none; d=zohomail.com; s=zohoarc; b=Hm6qOTxFzE2/NoPHwRROf2BnGqefzjr0qEBOovbqzkJtEwbxDwSjjLDXZWA0iVcaaH6ksUIi9FTIxF+1m+EypUVIciCErW/9RegOXKVMU2FSGW0lzGthJ7vcN0W0xWUj7/F69P9OVeLm0qAAG7yPHjk4leMDturm+O+Xv5QwbnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689090; 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=EmT6zgQqGEJfhsBPK+vPVTMx6Z6hoNe7wMeQORVuQpA=; b=GL3G1HcXphU6USnv5EflcHfOo3hJl9CeO8WwPtufi8BVmaf9ExXcf68Kcg4+RHlQvCpynDWQpPn0GnCXXiIdI7PFoi54PzwZAKCi7PXN7x6JDza3w+ThJsYFucgjj0fgXA0zSaL2RqeaE2yzD/g0GzHxkvbT0Knlo81OFc/FWBs= 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 1729689090192407.8468437253574; Wed, 23 Oct 2024 06:11:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824612.1238799 (Exim 4.92) (envelope-from ) id 1t3b8J-00080z-0N; Wed, 23 Oct 2024 13:10:39 +0000 Received: by outflank-mailman (output) from mailman id 824612.1238799; Wed, 23 Oct 2024 13:10:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3b8I-00080k-TR; Wed, 23 Oct 2024 13:10:38 +0000 Received: by outflank-mailman (input) for mailman id 824612; Wed, 23 Oct 2024 13:10:38 +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 1t3b8I-0006ft-0s for xen-devel@lists.xenproject.org; Wed, 23 Oct 2024 13:10:38 +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 31a3bb0e-9140-11ef-a0be-8be0dac302b0; Wed, 23 Oct 2024 15:10:37 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (unknown [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 8FE5921FC5; Wed, 23 Oct 2024 13:10:36 +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 611E613A63; Wed, 23 Oct 2024 13:10:36 +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 AYlGFsz1GGfwdwAAD6G6ig (envelope-from ); Wed, 23 Oct 2024 13:10:36 +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: 31a3bb0e-9140-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689036; 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=EmT6zgQqGEJfhsBPK+vPVTMx6Z6hoNe7wMeQORVuQpA=; b=Vi722Rtxr7buOD+/TexZ5zPitqdBE+rsc5ZVeotspxsDtU4knClg79iVkvPQuXfQYuDO40 DuFUmaSX7sur95zY4ix4ussKfTE9iukhqqyuab3Bff0fC3Jhsf85LV9ZmV5vKE1nia+wDM cqUFgNiDJL+WJSjJIrmCzOmHTBgiYEs= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689036; 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=EmT6zgQqGEJfhsBPK+vPVTMx6Z6hoNe7wMeQORVuQpA=; b=Vi722Rtxr7buOD+/TexZ5zPitqdBE+rsc5ZVeotspxsDtU4knClg79iVkvPQuXfQYuDO40 DuFUmaSX7sur95zY4ix4ussKfTE9iukhqqyuab3Bff0fC3Jhsf85LV9ZmV5vKE1nia+wDM cqUFgNiDJL+WJSjJIrmCzOmHTBgiYEs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Anthony PERARD Subject: [PATCH 5/6] tools: add a dedicated header file for barrier definitions Date: Wed, 23 Oct 2024 15:10:04 +0200 Message-ID: <20241023131005.32144-6-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-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1729689091912116600 Content-Type: text/plain; charset="utf-8" Instead of having to include xenctrl.h for getting definitions of cpu barriers, add a dedicated header for that purpose. Switch the xen-9pfsd daemon to use the new header instead of xenctrl.h. This is in preparation of making Xenstore independent from libxenctrl. Signed-off-by: Juergen Gross --- V1: - new patch --- tools/9pfsd/io.c | 5 +++- tools/include/xen-barrier.h | 51 +++++++++++++++++++++++++++++++++++++ tools/include/xenctrl.h | 28 +------------------- tools/libs/ctrl/Makefile | 2 +- 4 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 tools/include/xen-barrier.h diff --git a/tools/9pfsd/io.c b/tools/9pfsd/io.c index 468e0241f5..14cfcaf568 100644 --- a/tools/9pfsd/io.c +++ b/tools/9pfsd/io.c @@ -13,15 +13,18 @@ =20 #include #include +#include #include +#include #include #include #include +#include #include #include #include #include -#include /* For cpu barriers. */ +#include #include =20 #include "xen-9pfsd.h" diff --git a/tools/include/xen-barrier.h b/tools/include/xen-barrier.h new file mode 100644 index 0000000000..62036f528b --- /dev/null +++ b/tools/include/xen-barrier.h @@ -0,0 +1,51 @@ +/*************************************************************************= ***** + * xen-barrier.h + * + * Definition of CPU barriers, part of libxenctrl. + * + * Copyright (c) 2003-2004, K A Fraser. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#ifndef XENBARRIER_H +#define XENBARRIER_H + +/* + * DEFINITIONS FOR CPU BARRIERS + */ + +#define xen_barrier() asm volatile ( "" : : : "memory") + +#if defined(__i386__) +#define xen_mb() asm volatile ( "lock addl $0, -4(%%esp)" ::: "memory" ) +#define xen_rmb() xen_barrier() +#define xen_wmb() xen_barrier() +#elif defined(__x86_64__) +#define xen_mb() asm volatile ( "lock addl $0, -32(%%rsp)" ::: "memory" ) +#define xen_rmb() xen_barrier() +#define xen_wmb() xen_barrier() +#elif defined(__arm__) +#define xen_mb() asm volatile ("dmb" : : : "memory") +#define xen_rmb() asm volatile ("dmb" : : : "memory") +#define xen_wmb() asm volatile ("dmb" : : : "memory") +#elif defined(__aarch64__) +#define xen_mb() asm volatile ("dmb sy" : : : "memory") +#define xen_rmb() asm volatile ("dmb sy" : : : "memory") +#define xen_wmb() asm volatile ("dmb sy" : : : "memory") +#else +#error "Define barriers" +#endif + +#endif /* XENBARRIER_H */ diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 29617585c5..ea57e9dbb9 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -48,6 +48,7 @@ #include =20 #include "xentoollog.h" +#include "xen-barrier.h" =20 #if defined(__i386__) || defined(__x86_64__) #include @@ -61,33 +62,6 @@ =20 #define INVALID_MFN (~0UL) =20 -/* - * DEFINITIONS FOR CPU BARRIERS - */ - -#define xen_barrier() asm volatile ( "" : : : "memory") - -#if defined(__i386__) -#define xen_mb() asm volatile ( "lock addl $0, -4(%%esp)" ::: "memory" ) -#define xen_rmb() xen_barrier() -#define xen_wmb() xen_barrier() -#elif defined(__x86_64__) -#define xen_mb() asm volatile ( "lock addl $0, -32(%%rsp)" ::: "memory" ) -#define xen_rmb() xen_barrier() -#define xen_wmb() xen_barrier() -#elif defined(__arm__) -#define xen_mb() asm volatile ("dmb" : : : "memory") -#define xen_rmb() asm volatile ("dmb" : : : "memory") -#define xen_wmb() asm volatile ("dmb" : : : "memory") -#elif defined(__aarch64__) -#define xen_mb() asm volatile ("dmb sy" : : : "memory") -#define xen_rmb() asm volatile ("dmb sy" : : : "memory") -#define xen_wmb() asm volatile ("dmb sy" : : : "memory") -#else -#error "Define barriers" -#endif - - #define XENCTRL_HAS_XC_INTERFACE 1 /* In Xen 4.0 and earlier, xc_interface_open and xc_evtchn_open would * both return ints being the file descriptor. In 4.1 and later, they diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile index 5fe0bfad0c..acce8639d3 100644 --- a/tools/libs/ctrl/Makefile +++ b/tools/libs/ctrl/Makefile @@ -3,7 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk =20 include Makefile.common =20 -LIBHEADER :=3D xenctrl.h xenctrl_compat.h +LIBHEADER :=3D xenctrl.h xenctrl_compat.h xen-barrier.h PKG_CONFIG_FILE :=3D xencontrol.pc PKG_CONFIG_NAME :=3D Xencontrol =20 --=20 2.43.0 From nobody Wed Dec 4 09:17:23 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=1729689095; cv=none; d=zohomail.com; s=zohoarc; b=SfB0tNHl1TJDqVtgDMrbt6Im6I2CPhTu78EA9LP5/FP6hgHXUD6uC2sJP1ucU2usRt21fQU6VI4Str7Lwah5Ej8BJU0M37zvlbHG1Gy9VjjYFQWFwS2Ij6nJmQMcNQhnMCZVZ8Hdgp0/Xrb544Kc8Z4pX9tAW6aFJMiIkGyFe7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689095; 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=E987LsdlIgzKQbdEFTgOeCDvrDTXQ5jG9XVD9+qlAzk=; b=AWDrvkgz5GuNyPQzARGPJL3J9KjII5Y0/oH+3nSPxrua2H9M1kPeMpRHE68Fe3DdzF0aHCjb5kf4U5bF82uq3OR2mortPiGnY7vvXJvNwoz/cF9inKiXW7uKL/6COe0hT8Pst5LSoxpUtyleCaSpXGZcjdpQJ5nvJdNezEpPbdI= 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 172968909564561.7565722019649; Wed, 23 Oct 2024 06:11:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824615.1238809 (Exim 4.92) (envelope-from ) id 1t3b8Q-0000AO-8B; Wed, 23 Oct 2024 13:10:46 +0000 Received: by outflank-mailman (output) from mailman id 824615.1238809; Wed, 23 Oct 2024 13:10:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3b8Q-0000AB-5P; Wed, 23 Oct 2024 13:10:46 +0000 Received: by outflank-mailman (input) for mailman id 824615; Wed, 23 Oct 2024 13:10:44 +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 1t3b8O-0006Ra-It for xen-devel@lists.xenproject.org; Wed, 23 Oct 2024 13:10:44 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 34f4c3fd-9140-11ef-99a3-01e77a169b0f; Wed, 23 Oct 2024 15:10:42 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (unknown [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 26F581FDA3; Wed, 23 Oct 2024 13:10:42 +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 E969713A63; Wed, 23 Oct 2024 13:10:41 +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 J8SFN9H1GGf7dwAAD6G6ig (envelope-from ); Wed, 23 Oct 2024 13:10:41 +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: 34f4c3fd-9140-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689042; 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=E987LsdlIgzKQbdEFTgOeCDvrDTXQ5jG9XVD9+qlAzk=; b=JTVYA1wSacsKybqp0fWSSRubXG1XKGyhEDETDfw3xbdSxZXFlQ4EemOFZnEoZZHeOhwmI5 Z4BXftGSJIGvNBwPENvX4CUv/TR3TSyVGO7qqUBtzgbsHSKA+oU+drHQm8Qb3TeiDEAC+Y 4cpUTLm+65lTGl5F0zW27vwSvD9CXMQ= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1729689042; 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=E987LsdlIgzKQbdEFTgOeCDvrDTXQ5jG9XVD9+qlAzk=; b=JTVYA1wSacsKybqp0fWSSRubXG1XKGyhEDETDfw3xbdSxZXFlQ4EemOFZnEoZZHeOhwmI5 Z4BXftGSJIGvNBwPENvX4CUv/TR3TSyVGO7qqUBtzgbsHSKA+oU+drHQm8Qb3TeiDEAC+Y 4cpUTLm+65lTGl5F0zW27vwSvD9CXMQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Anthony PERARD , Samuel Thibault , Julien Grall Subject: [PATCH 6/6] tools/xenstored: use new stable interface instead of libxenctrl Date: Wed, 23 Oct 2024 15:10:05 +0200 Message-ID: <20241023131005.32144-7-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-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1729689096000116600 Content-Type: text/plain; charset="utf-8" Replace the current use of the unstable xc_domain_getinfo_single() interface with the stable domctl XEN_DOMCTL_get_domain_state call via the new libxenmanage library. This will remove the last usage of libxenctrl by Xenstore, so update the library dependencies accordingly. For now only do a direct replacement without using the functionality of obtaining information about domains having changed the state. Signed-off-by: Juergen Gross --- V1: - use library instead of direct hypercall, only replace current libxenctrl use case Please note that this patch can be committed only after the related Mini-OS patch "config: add support for libxenmanage" has gone in AND the Mini-OS commit-id has been updated in Config.mk accordingly! --- stubdom/Makefile | 8 ++--- stubdom/mini-os.mk | 1 + tools/xenstored/Makefile | 2 +- tools/xenstored/Makefile.common | 2 +- tools/xenstored/core.h | 1 - tools/xenstored/domain.c | 52 ++++++++++++--------------------- tools/xenstored/lu.c | 1 + tools/xenstored/lu_daemon.c | 1 + 8 files changed, 28 insertions(+), 40 deletions(-) diff --git a/stubdom/Makefile b/stubdom/Makefile index 2a81af28a1..ca800b243c 100644 --- a/stubdom/Makefile +++ b/stubdom/Makefile @@ -307,7 +307,7 @@ endif # libraries under tools/libs ####### =20 -STUB_LIBS :=3D toolcore toollog evtchn gnttab call foreignmemory devicemod= el ctrl guest +STUB_LIBS :=3D toolcore toollog evtchn gnttab call foreignmemory devicemod= el ctrl guest manage =20 LIBDEP_guest :=3D cross-zlib =20 @@ -465,7 +465,7 @@ grub: cross-polarssl grub-upstream $(CROSS_ROOT) grub-$= (XEN_TARGET_ARCH)-minios- # xenstore ########## =20 -xenstore-minios.gen.cfg: APP_LIBS =3D gnttab evtchn toollog ctrl +xenstore-minios.gen.cfg: APP_LIBS =3D gnttab evtchn toollog manage xenstore-minios.gen.cfg: xenstore-minios.cfg Makefile $(GEN_config) >$@ =20 @@ -480,7 +480,7 @@ xenstore: $(CROSS_ROOT) xenstore-minios-config.mk # xenstorepvh ############# =20 -xenstorepvh-minios.gen.cfg: APP_LIBS =3D gnttab evtchn toollog ctrl +xenstorepvh-minios.gen.cfg: APP_LIBS =3D gnttab evtchn toollog manage xenstorepvh-minios.gen.cfg: xenstorepvh-minios.cfg Makefile $(GEN_config) >$@ =20 @@ -523,7 +523,7 @@ else pv-grub-if-enabled: endif =20 -XENSTORE_DEPS :=3D libxenevtchn libxengnttab libxenctrl +XENSTORE_DEPS :=3D libxenevtchn libxengnttab libxenmanage =20 .PHONY: xenstore-stubdom xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore $(XENSTORE_DEPS) xen= store diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk index 7e4968e026..be32302f9e 100644 --- a/stubdom/mini-os.mk +++ b/stubdom/mini-os.mk @@ -13,5 +13,6 @@ GNTTAB_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_= ARCH)/gnttab CALL_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call FOREIGNMEMORY_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/fore= ignmemory DEVICEMODEL_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/device= model +MANAGE_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/manage CTRL_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/ctrl GUEST_PATH =3D $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/guest diff --git a/tools/xenstored/Makefile b/tools/xenstored/Makefile index 09adfe1d50..81c42838e0 100644 --- a/tools/xenstored/Makefile +++ b/tools/xenstored/Makefile @@ -5,7 +5,7 @@ include Makefile.common =20 xenstored: LDLIBS +=3D $(LDLIBS_libxenevtchn) xenstored: LDLIBS +=3D $(LDLIBS_libxengnttab) -xenstored: LDLIBS +=3D $(LDLIBS_libxenctrl) +xenstored: LDLIBS +=3D $(LDLIBS_libxenmanage) xenstored: LDLIBS +=3D -lrt xenstored: LDLIBS +=3D $(SOCKET_LIBS) =20 diff --git a/tools/xenstored/Makefile.common b/tools/xenstored/Makefile.com= mon index 27fdb3b49e..271134fcc1 100644 --- a/tools/xenstored/Makefile.common +++ b/tools/xenstored/Makefile.common @@ -12,7 +12,7 @@ XENSTORED_OBJS-$(CONFIG_MiniOS) +=3D minios.o lu_minios.o # Include configure output (config.h) CFLAGS +=3D -include $(XEN_ROOT)/tools/config.h CFLAGS +=3D $(CFLAGS_libxenevtchn) -CFLAGS +=3D $(CFLAGS_libxenctrl) +CFLAGS +=3D $(CFLAGS_libxenmanage) CFLAGS +=3D $(CFLAGS_libxentoolcore) =20 $(XENSTORED_OBJS-y): CFLAGS +=3D $(CFLAGS_libxengnttab) diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h index e58779e88c..632886cecf 100644 --- a/tools/xenstored/core.h +++ b/tools/xenstored/core.h @@ -19,7 +19,6 @@ #ifndef _XENSTORED_CORE_H #define _XENSTORED_CORE_H =20 -#include #include =20 #include diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 64c8fd0cc3..c0264d9477 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -34,14 +34,15 @@ #include "control.h" =20 #include -#include +#include +#include #include =20 #ifdef __MINIOS__ #include #endif =20 -static xc_interface **xc_handle; +static xenmanage_handle *xm_handle; xengnttab_handle **xgt_handle; static evtchn_port_t virq_port; =20 @@ -619,32 +620,28 @@ static int destroy_domain(void *_domain) return 0; } =20 -static bool get_domain_info(unsigned int domid, xc_domaininfo_t *dominfo) -{ - return xc_domain_getinfo_single(*xc_handle, domid, dominfo) =3D=3D 0; -} - static int check_domain(const void *k, void *v, void *arg) { - xc_domaininfo_t dominfo; + unsigned int state; struct connection *conn; - bool dom_valid; + int dom_invalid; struct domain *domain =3D v; bool *notify =3D arg; =20 - dom_valid =3D get_domain_info(domain->domid, &dominfo); + dom_invalid =3D xenmanage_get_domain_info(xm_handle, domain->domid, + &state, NULL); if (!domain->introduced) { - if (!dom_valid) + if (dom_invalid) talloc_free(domain); return 0; } - if (dom_valid) { - if ((dominfo.flags & XEN_DOMINF_shutdown) + if (!dom_invalid) { + if ((state & XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN) && !domain->shutdown) { domain->shutdown =3D true; *notify =3D true; } - if (!(dominfo.flags & XEN_DOMINF_dying)) + if (!(state & XENMANAGE_GETDOMSTATE_STATE_DYING)) return 0; } if (domain->conn) { @@ -786,10 +783,9 @@ static struct domain *find_or_alloc_domain(const void = *ctx, unsigned int domid) static struct domain *find_or_alloc_existing_domain(unsigned int domid) { struct domain *domain; - xc_domaininfo_t dominfo; =20 domain =3D find_domain_struct(domid); - if (!domain && get_domain_info(domid, &dominfo)) + if (!domain && !xenmanage_get_domain_info(xm_handle, domid, NULL, NULL)) domain =3D alloc_domain(NULL, domid); =20 return domain; @@ -1187,12 +1183,6 @@ int do_reset_watches(const void *ctx, struct connect= ion *conn, return 0; } =20 -static int close_xc_handle(void *_handle) -{ - xc_interface_close(*(xc_interface**)_handle); - return 0; -} - static int close_xgt_handle(void *_handle) { xengnttab_close(*(xengnttab_handle **)_handle); @@ -1258,15 +1248,9 @@ void domain_early_init(void) if (!domhash) barf_perror("Failed to allocate domain hashtable"); =20 - xc_handle =3D talloc(talloc_autofree_context(), xc_interface*); - if (!xc_handle) - barf_perror("Failed to allocate domain handle"); - - *xc_handle =3D xc_interface_open(0,0,0); - if (!*xc_handle) - barf_perror("Failed to open connection to hypervisor"); - - talloc_set_destructor(xc_handle, close_xc_handle); + xm_handle =3D xenmanage_open(NULL, 0); + if (!xm_handle) + barf_perror("Failed to open connection to libxenmanage"); =20 xgt_handle =3D talloc(talloc_autofree_context(), xengnttab_handle*); if (!xgt_handle) @@ -1306,6 +1290,8 @@ void domain_deinit(void) { if (virq_port) xenevtchn_unbind(xce_handle, virq_port); + + xenmanage_close(xm_handle); } =20 /* @@ -1335,13 +1321,13 @@ int domain_alloc_permrefs(struct node_perms *perms) { unsigned int i, domid; struct domain *d; - xc_domaininfo_t dominfo; =20 for (i =3D 0; i < perms->num; i++) { domid =3D perms->p[i].id; d =3D find_domain_struct(domid); if (!d) { - if (!get_domain_info(domid, &dominfo)) + if (xenmanage_get_domain_info(xm_handle, domid, + NULL, NULL)) perms->p[i].perms |=3D XS_PERM_IGNORE; else if (!alloc_domain(NULL, domid)) return ENOMEM; diff --git a/tools/xenstored/lu.c b/tools/xenstored/lu.c index bec2a84e10..4fccbbc195 100644 --- a/tools/xenstored/lu.c +++ b/tools/xenstored/lu.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include =20 diff --git a/tools/xenstored/lu_daemon.c b/tools/xenstored/lu_daemon.c index 6df6c80a2a..88d8d9e1b3 100644 --- a/tools/xenstored/lu_daemon.c +++ b/tools/xenstored/lu_daemon.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include =20 #include "talloc.h" --=20 2.43.0