From nobody Mon Sep 16 19:44:54 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=1707130367; cv=none; d=zohomail.com; s=zohoarc; b=hg/fZHythgf1g7BJtXCDu/l84gN7xkVf43wbALN4ErkaiPDEifjTjlUhEQf4sbo24uMISCFlvJHiL31DzcPoar2qTu1G8YdOb21c+KcfQrJ6LcmxUw3VHwLJEWFchcutUHGcF4HBQMqLQKIIvHC+SVDDbYv8IzqJ+6+J4ONbIJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707130367; 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=sBN45VY796bPT208E7z1cKUSQ/jSCHWuzgN6GPy8ckw=; b=BpOgimWQoITvoaTboYs5oxw/lVeZ0O9Ce+b00sovj+9dHwlYG4o8BY+9KV2NXUkYofmlZT2TsLG0fBVPp5tGvDFzELjqbXi+ioZQr56xghuMVxehOLIXZzZqfBnK42MdjJLDi1FGgFAblsVreSNoMYIhyZqocuk4itfMNAQQT/E= 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 1707130367952983.0459012198818; Mon, 5 Feb 2024 02:52:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.675812.1051343 (Exim 4.92) (envelope-from ) id 1rWwaX-00064m-CR; Mon, 05 Feb 2024 10:52:33 +0000 Received: by outflank-mailman (output) from mailman id 675812.1051343; Mon, 05 Feb 2024 10:52:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rWwaX-00064d-95; Mon, 05 Feb 2024 10:52:33 +0000 Received: by outflank-mailman (input) for mailman id 675812; Mon, 05 Feb 2024 10:52:32 +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 1rWwaW-00064Q-Le for xen-devel@lists.xenproject.org; Mon, 05 Feb 2024 10:52:32 +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 a8c4cb0b-c414-11ee-98f5-efadbce2ee36; Mon, 05 Feb 2024 11:52:30 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [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 5255922285; Mon, 5 Feb 2024 10:52: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 14A4A132DD; Mon, 5 Feb 2024 10:52: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 QOmNA+69wGXmNgAAD6G6ig (envelope-from ); Mon, 05 Feb 2024 10:52: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: a8c4cb0b-c414-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130350; 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=sBN45VY796bPT208E7z1cKUSQ/jSCHWuzgN6GPy8ckw=; b=XPLQmfsImAnW4qPMeUaZMNYUKSCWkTag5wGDPSYySdjzxWw0LTfK7czpaKIGUbR2VOgO/U w/sayaMlagAz0M9Fclx3CRPeO7wYiBdhqS4ushlEwZ2F8eoSOVBWGaxr7mgKgLiW+ZIqQ4 BWDxSi9ki62/PDIMB4SWLuhbqmMLaTY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707130350; 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=sBN45VY796bPT208E7z1cKUSQ/jSCHWuzgN6GPy8ckw=; b=XPLQmfsImAnW4qPMeUaZMNYUKSCWkTag5wGDPSYySdjzxWw0LTfK7czpaKIGUbR2VOgO/U w/sayaMlagAz0M9Fclx3CRPeO7wYiBdhqS4ushlEwZ2F8eoSOVBWGaxr7mgKgLiW+ZIqQ4 BWDxSi9ki62/PDIMB4SWLuhbqmMLaTY= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD , Jason Andryuk , Julien Grall Subject: [PATCH v4 26/32] tools/xenstored: rework ring page (un)map functions Date: Mon, 5 Feb 2024 11:49:55 +0100 Message-Id: <20240205105001.24171-27-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240205105001.24171-1-jgross@suse.com> References: <20240205105001.24171-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.89 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[suse.com,xen.org,citrix.com,gmail.com,amazon.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.01)[50.16%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.89 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707130369872100001 Content-Type: text/plain; charset="utf-8" When [un]mapping the ring page of a Xenstore client, different actions are required for "normal" guests and dom0. Today this distinction is made at call site. Move this distinction into [un]map_interface() instead, avoiding code duplication and preparing special handling for [un]mapping the stub domain's ring page. Signed-off-by: Juergen Gross Reviewed-by: Jason Andryuk Reviewed-by: Julien Grall --- tools/xenstored/domain.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 040df98b8c..af80a8221d 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -497,14 +497,20 @@ static const struct interface_funcs domain_funcs =3D { =20 static void *map_interface(domid_t domid) { + if (domid =3D=3D xenbus_master_domid()) + return xenbus_map(); + return xengnttab_map_grant_ref(*xgt_handle, domid, GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE); } =20 -static void unmap_interface(void *interface) +static void unmap_interface(domid_t domid, void *interface) { - xengnttab_unmap(*xgt_handle, interface, 1); + if (domid =3D=3D xenbus_master_domid()) + unmap_xenbus(interface); + else + xengnttab_unmap(*xgt_handle, interface, 1); } =20 static int domain_tree_remove_sub(const void *ctx, struct connection *conn, @@ -594,14 +600,8 @@ static int destroy_domain(void *_domain) eprintf("> Unbinding port %i failed!\n", domain->port); } =20 - if (domain->interface) { - /* Domain 0 was mapped by dom0_init, so it must be unmapped - using munmap() and not the grant unmap call. */ - if (domain->domid =3D=3D dom0_domid) - unmap_xenbus(domain->interface); - else - unmap_interface(domain->interface); - } + if (domain->interface) + unmap_interface(domain->domid, domain->interface); =20 fire_special_watches("@releaseDomain"); =20 @@ -966,18 +966,13 @@ static struct domain *introduce_domain(const void *ct= x, return NULL; =20 if (!domain->introduced) { - interface =3D is_master_domain ? xenbus_map() - : map_interface(domid); + interface =3D map_interface(domid); if (!interface && !restore) return NULL; if (new_domain(domain, port, restore)) { rc =3D errno; - if (interface) { - if (is_master_domain) - unmap_xenbus(interface); - else - unmap_interface(interface); - } + if (interface) + unmap_interface(domid, interface); errno =3D rc; return NULL; } --=20 2.35.3