From nobody Fri May 17 10:44:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1663595882; cv=none; d=zohomail.com; s=zohoarc; b=a0ykicsHa7hmUZPGJv4kcxytSP5473F/GKu5d7gvvJ66EgZdc3skEgc2c1UXiuWvifNLapkxm8F4OQAmvHhf3oM42ZnUqEnJPZIRLuAITlx+c2Wb1gJsQ5/WE89iysdzYblazU31W2oY2X2we5rxMwDpF0ldymL7yxKWdpIHxF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663595882; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tz8gsHMxNLDss6Wcz9zH14FFQ/wItJfEktj91VmkdgY=; b=fULeDPnzTnpx5xWZ8VnrFKc+VhjeNJoCIICXmAXXaN10bEp2AD6q8JilEiAwW5MnNu0dODMiexmvR0tFhH0oCZYC3JTXUZQ9yHAmFrsputB7MGA74f0P47+0LzztBeknmlah0DHPNJGenSa8W0srwPJHiJgGvqUszzsP3tiotA0= 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 1663595882514130.4921771757464; Mon, 19 Sep 2022 06:58:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.408754.651605 (Exim 4.92) (envelope-from ) id 1oaHHL-0005kb-Bn; Mon, 19 Sep 2022 13:57:43 +0000 Received: by outflank-mailman (output) from mailman id 408754.651605; Mon, 19 Sep 2022 13:57: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 1oaHHL-0005jY-7w; Mon, 19 Sep 2022 13:57:43 +0000 Received: by outflank-mailman (input) for mailman id 408754; Mon, 19 Sep 2022 13:57:42 +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 1oaHHK-0005fY-3s for xen-devel@lists.xenproject.org; Mon, 19 Sep 2022 13:57:42 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fbe970a8-3822-11ed-bad8-01ff208a15ba; Mon, 19 Sep 2022 15:57:22 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 62544210DF; Mon, 19 Sep 2022 13:57:22 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1BEBC13ABD; Mon, 19 Sep 2022 13:57:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id g4JTBUJ1KGNUUwAAMHmgww (envelope-from ); Mon, 19 Sep 2022 13:57:22 +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: fbe970a8-3822-11ed-bad8-01ff208a15ba DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1663595842; 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=Tz8gsHMxNLDss6Wcz9zH14FFQ/wItJfEktj91VmkdgY=; b=dz0FiBOpB+hNTb2zbyB8hKdKBj6xPn2dCVnLjKX0gAHtX1AydzLxjqgmCskodQjq3uhEBu RP44MCyWHrDWigWV8oP3ZJpyFM6UOFILvEIXT1scgFN81nQw2nuIhndtOqEZKeccXjORFG JQVxM8iLlvxqyp9OSmxO2L+wvTM8UAo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v3 1/2] xen: add knownalive_domain_from_domid() helper Date: Mon, 19 Sep 2022 15:57:12 +0200 Message-Id: <20220919135713.16577-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919135713.16577-1-jgross@suse.com> References: <20220919135713.16577-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1663595883740100003 Content-Type: text/plain; charset="utf-8" Add a helper knownalive_domain_from_domid() returning the struct domain pointer for a domain give by its domid and which is known not being able to be released (its reference count isn't incremented and no rcu_lock_domain() is called for it). In order to simplify coding add an internal helper for doing the lookup and call that from the new function and similar functions. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - rename helper to knownalive_domain_from_domid() (Jan Beulich) - enhance comment in header (Jan Beulich) - rename internal helper (Julien Grall) --- xen/common/domain.c | 53 +++++++++++++++++++++++++---------------- xen/include/xen/sched.h | 4 ++++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 8dd6cd5a8f..35e0dc5139 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -835,25 +835,32 @@ out: return 0; } =20 - -struct domain *get_domain_by_id(domid_t dom) +/* rcu_read_lock(&domlist_read_lock) must be held. */ +static struct domain *domid_to_domain(domid_t dom) { struct domain *d; =20 - rcu_read_lock(&domlist_read_lock); - for ( d =3D rcu_dereference(domain_hash[DOMAIN_HASH(dom)]); d !=3D NULL; d =3D rcu_dereference(d->next_in_hashbucket) ) { if ( d->domain_id =3D=3D dom ) - { - if ( unlikely(!get_domain(d)) ) - d =3D NULL; - break; - } + return d; } =20 + return NULL; +} + +struct domain *get_domain_by_id(domid_t dom) +{ + struct domain *d; + + rcu_read_lock(&domlist_read_lock); + + d =3D domid_to_domain(dom); + if ( d && unlikely(!get_domain(d)) ) + d =3D NULL; + rcu_read_unlock(&domlist_read_lock); =20 return d; @@ -862,20 +869,26 @@ struct domain *get_domain_by_id(domid_t dom) =20 struct domain *rcu_lock_domain_by_id(domid_t dom) { - struct domain *d =3D NULL; + struct domain *d; =20 rcu_read_lock(&domlist_read_lock); =20 - for ( d =3D rcu_dereference(domain_hash[DOMAIN_HASH(dom)]); - d !=3D NULL; - d =3D rcu_dereference(d->next_in_hashbucket) ) - { - if ( d->domain_id =3D=3D dom ) - { - rcu_lock_domain(d); - break; - } - } + d =3D domid_to_domain(dom); + if ( d ) + rcu_lock_domain(d); + + rcu_read_unlock(&domlist_read_lock); + + return d; +} + +struct domain *knownalive_domain_from_domid(domid_t dom) +{ + struct domain *d; + + rcu_read_lock(&domlist_read_lock); + + d =3D domid_to_domain(dom); =20 rcu_read_unlock(&domlist_read_lock); =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 557b3229f6..9e9c3d834b 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -737,8 +737,12 @@ static inline struct domain *rcu_lock_current_domain(v= oid) return /*rcu_lock_domain*/(current->domain); } =20 +/* Get struct domain AND increase ref-count of domain. */ struct domain *get_domain_by_id(domid_t dom); =20 +/* Get struct domain known to have reference held or being RCU-locked. */ +struct domain *knownalive_domain_from_domid(domid_t dom); + struct domain *get_pg_owner(domid_t domid); =20 static inline void put_pg_owner(struct domain *pg_owner) --=20 2.35.3 From nobody Fri May 17 10:44:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1663595880; cv=none; d=zohomail.com; s=zohoarc; b=eoQFkZGtCvSR1HyTUnYdv2lgIOQoyfxcjCBWilhYUlLd8ymRHvSooR6gqJQfwSAY8JOfG9GXmbGx89vYolniaMunXDCpZBUprEuYpdDtBO74ubq3ZuiVHk2o8GIVcp5YTYphGBxu0rtzKkY/M7zEnkDKKBO9GjXkhIjVfSo/fAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663595880; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EiGpOOfo6nM2u8o3TQyMPZ74pkfux6LagS477LbaOOM=; b=OownoZU2UGlstwErPhyjwgDDURT6vEP1C3IMJWxIgD46XoYbvooRNDxyK9Fz0hqom9XorczK1tUCu75MV883td78MiKqsMYRIE32o8LIru6m+kGqH1QsubARflIL+uDLULveTRRsk+z7ZGuR+qOv/F3GAWmf4PUcXzKdsknQh14= 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 1663595880459860.5373645859395; Mon, 19 Sep 2022 06:58:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.408752.651600 (Exim 4.92) (envelope-from ) id 1oaHHL-0005hK-1I; Mon, 19 Sep 2022 13:57:43 +0000 Received: by outflank-mailman (output) from mailman id 408752.651600; Mon, 19 Sep 2022 13:57: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 1oaHHK-0005hD-Up; Mon, 19 Sep 2022 13:57:42 +0000 Received: by outflank-mailman (input) for mailman id 408752; Mon, 19 Sep 2022 13:57:41 +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 1oaHHJ-0005fY-BE for xen-devel@lists.xenproject.org; Mon, 19 Sep 2022 13:57:41 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ff4d3c18-3822-11ed-bad8-01ff208a15ba; Mon, 19 Sep 2022 15:57:28 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 15D8E21D34; Mon, 19 Sep 2022 13:57:28 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C883B13ABD; Mon, 19 Sep 2022 13:57:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 9hq7Lkd1KGNiUwAAMHmgww (envelope-from ); Mon, 19 Sep 2022 13:57:27 +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: ff4d3c18-3822-11ed-bad8-01ff208a15ba DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1663595848; 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=EiGpOOfo6nM2u8o3TQyMPZ74pkfux6LagS477LbaOOM=; b=LyiNTbhWJmDJM2LwFwBXSt8Sol7FYU0socBXEOQqXYTMLQCX+nsERpf/4g+1fEplrsMYxh xbo4GAQ4WVW9liXHOUdN0aI+KoSFzEGSwTWMaY0lmNtl4PnOA/e8lI4qHeeSjFjE0MUw4I ah01snMiwqZFd35jbaTqcs1nw4tP7Jc= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v3 2/2] xen/gnttab: reduce size of struct active_grant_entry Date: Mon, 19 Sep 2022 15:57:13 +0200 Message-Id: <20220919135713.16577-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220919135713.16577-1-jgross@suse.com> References: <20220919135713.16577-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1663595882089100001 Content-Type: text/plain; charset="utf-8" The size of struct active_grant_entry for 64-bit builds is 40 or 48 bytes today (with or without NDEBUG). It can easily be reduced by 8 bytes by replacing the trans_domain pointer with the domid of the related domain. trans_domain is only ever used for transitive grants, which doesn't have any known users. This reduction will result in less memory usage and (for production builds) in faster code, as indexing into the active_grant_entry array will be much easier with an entry having a power-of-2 size. The performance loss when using transitive grants shouldn't really matter, given the probability that those aren't in use at all. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - rename trans_domid to src_domid (Jan Beulich) V3: - update comment (Jan Beulich) --- xen/common/grant_table.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index fba329dcc2..f3890c9124 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -381,13 +381,13 @@ struct active_grant_entry { }) =20 domid_t domid; /* Domain being granted access. */ + domid_t src_domid; /* Original domain granting access. */ unsigned int start:15; /* For sub-page grants, the start offset in the page. */ bool is_sub_page:1; /* True if this is a sub-page grant. */ unsigned int length:16; /* For sub-page grants, the length of the grant. */ grant_ref_t trans_gref; - struct domain *trans_domain; mfn_t mfn; /* Machine frame being granted. */ #ifndef NDEBUG gfn_t gfn; /* Guest's idea of the frame being granted. */ @@ -1095,7 +1095,7 @@ map_grant_ref( act->start =3D 0; act->length =3D PAGE_SIZE; act->is_sub_page =3D false; - act->trans_domain =3D rd; + act->src_domid =3D rd->domain_id; act->trans_gref =3D ref; } } @@ -2494,7 +2494,8 @@ release_grant_for_copy( else { status =3D &status_entry(rgt, gref); - td =3D act->trans_domain; + td =3D (act->src_domid =3D=3D rd->domain_id) + ? rd : knownalive_domain_from_domid(act->src_domid); trans_gref =3D act->trans_gref; } =20 @@ -2657,7 +2658,7 @@ acquire_grant_for_copy( !mfn_eq(act->mfn, grant_mfn) || act->start !=3D trans_page_off || act->length !=3D trans_length || - act->trans_domain !=3D td || + act->src_domid !=3D td->domain_id || act->trans_gref !=3D trans_gref || !act->is_sub_page)) ) { @@ -2676,7 +2677,7 @@ acquire_grant_for_copy( act->domid =3D ldom; act->start =3D trans_page_off; act->length =3D trans_length; - act->trans_domain =3D td; + act->src_domid =3D td->domain_id; act->trans_gref =3D trans_gref; act->mfn =3D grant_mfn; act_set_gfn(act, INVALID_GFN); @@ -2738,7 +2739,7 @@ acquire_grant_for_copy( act->is_sub_page =3D is_sub_page; act->start =3D trans_page_off; act->length =3D trans_length; - act->trans_domain =3D td; + act->src_domid =3D td->domain_id; act->trans_gref =3D trans_gref; act->mfn =3D grant_mfn; } --=20 2.35.3