From nobody Fri May 17 21:26:07 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=1662962088; cv=none; d=zohomail.com; s=zohoarc; b=D2lkGuMqrTCh5ufK/ANg/m9A6im3woFWJsXQM3vjeS9KEpm1cwFxH83r6bwH2l+PyT4r8hr7vMVvhNtYeFHNzYh9bRuvBMurERrS9i6iELlfdHDCLZufoXY1U3QAfHF6xuTbE0+sarExsSH732nntnoXW0nXiQ3vzAqWHoOdV48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662962088; 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=uD7RrO3aPkckiRSiv33Wtr4oGXbDCkJ2Ff62zi7V5Uc=; b=b7N0e1OHgkJFrXmJZRv2pbQHSvKxsuI50OpboxZBKATjvg9mjKk7JES0wM8QudjG0clkVM8uvvC0oFBB0cYEPmK5nnJ1ph3SV7rkautDmiszIMDVS5cTFZGOkBAEmZYIMhW1PWmXNijyR5NhxAbXTD9Z9hVSgE4byBypZa98ucs= 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 1662962088568352.0977769543549; Sun, 11 Sep 2022 22:54:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.405421.647872 (Exim 4.92) (envelope-from ) id 1oXcOY-00079m-Oq; Mon, 12 Sep 2022 05:54:10 +0000 Received: by outflank-mailman (output) from mailman id 405421.647872; Mon, 12 Sep 2022 05:54:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oXcOY-00079f-MF; Mon, 12 Sep 2022 05:54:10 +0000 Received: by outflank-mailman (input) for mailman id 405421; Mon, 12 Sep 2022 05:54:09 +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 1oXcOW-00078t-Sn for xen-devel@lists.xenproject.org; Mon, 12 Sep 2022 05:54:09 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4f5a542f-325f-11ed-a31c-8f8a9ae3403f; Mon, 12 Sep 2022 07:54:06 +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-out2.suse.de (Postfix) with ESMTPS id 0A9451F98E; Mon, 12 Sep 2022 05:54:05 +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 C157D139BE; Mon, 12 Sep 2022 05:54:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kGLqLXzJHmMnawAAMHmgww (envelope-from ); Mon, 12 Sep 2022 05:54:04 +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: 4f5a542f-325f-11ed-a31c-8f8a9ae3403f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1662962045; 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=uD7RrO3aPkckiRSiv33Wtr4oGXbDCkJ2Ff62zi7V5Uc=; b=DTei/9XGCYT+qquqRDTge8bX7duA49Ou/AzSMJGkbtgYHWtnZM5j/ZxSN+aOdyNmUsjbWa FnmMZid9O9cf1zIubdXfUiBnITQa6YptuGZPYEs1+cfoZgkv+79g57F0c+xsY00MtnQfU5 U6HTD0qaprG3CDvZhp8Ox/pox03S/ng= 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 1/2] xen: add domid_to_domain() helper Date: Mon, 12 Sep 2022 07:53:55 +0200 Message-Id: <20220912055356.24064-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220912055356.24064-1-jgross@suse.com> References: <20220912055356.24064-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1662962090085100001 Content-Type: text/plain; charset="utf-8" Add a helper domid_to_domain() 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 --- xen/common/domain.c | 54 ++++++++++++++++++++++++++--------------- xen/include/xen/sched.h | 4 +++ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index c23f449451..2b1866ea42 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -832,25 +832,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_2_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_2_domain(dom); + if ( d && unlikely(!get_domain(d)) ) + d =3D NULL; + rcu_read_unlock(&domlist_read_lock); =20 return d; @@ -859,20 +866,27 @@ 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_2_domain(dom); + if ( d ) + rcu_lock_domain(d); + + rcu_read_unlock(&domlist_read_lock); + + return d; +} + +/* Use only if struct domain is known to stay allocated! */ +struct domain *domid_to_domain(domid_t dom) +{ + struct domain *d; + + rcu_read_lock(&domlist_read_lock); + + d =3D domid_2_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..f4c4d3a60f 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 stay allocated. */ +struct domain *domid_to_domain(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 21:26:07 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=1662962091; cv=none; d=zohomail.com; s=zohoarc; b=DXa8h6h+9Aj4ULaK0S47HlYPKtW1cKFlf50djhc88pmqZrqr9XTjXZ1h+YHiZB8wanwdZkF4VDuPx0zq9+aNntchHk6uDtVOZquTt3vKsZgrbHjNDebM1RXmczcmnkf41cpM5htqV8I1Bc7JzstdMIIgisjkgMMcKFKrqhLFt+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662962091; 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=Ul1iFRnyaP+EjSwgFYHlOg+ezwj9WuwKzmQ6FnbRLy4=; b=ZiSa5Y8bQf35rtDFsLO0LLeNOidh1A4Whi5nWwXCiTLBh2MzwB70Y3dfECRuANySXIi1pVwr0cjCSHeOucpY74RD9xwBAt+j6GEP4vBmTCOX/4trVgyEzmhsXkbBlUooTfLECSvLKL0dEBD1uNJ6TN72XbXB8iEBWVcmZeIx3IA= 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 1662962091393674.0468131338488; Sun, 11 Sep 2022 22:54:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.405422.647884 (Exim 4.92) (envelope-from ) id 1oXcOc-0007RQ-21; Mon, 12 Sep 2022 05:54:14 +0000 Received: by outflank-mailman (output) from mailman id 405422.647884; Mon, 12 Sep 2022 05:54:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oXcOb-0007RJ-Un; Mon, 12 Sep 2022 05:54:13 +0000 Received: by outflank-mailman (input) for mailman id 405422; Mon, 12 Sep 2022 05:54:12 +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 1oXcOa-00078t-4d for xen-devel@lists.xenproject.org; Mon, 12 Sep 2022 05:54:12 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 52a17d56-325f-11ed-a31c-8f8a9ae3403f; Mon, 12 Sep 2022 07:54:11 +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 B3E25227C6; Mon, 12 Sep 2022 05:54:10 +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 6E504139BE; Mon, 12 Sep 2022 05:54:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HJuEGYLJHmMuawAAMHmgww (envelope-from ); Mon, 12 Sep 2022 05:54:10 +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: 52a17d56-325f-11ed-a31c-8f8a9ae3403f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1662962050; 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=Ul1iFRnyaP+EjSwgFYHlOg+ezwj9WuwKzmQ6FnbRLy4=; b=ObwtyCGROAgkmoE9giDM1R+ryoK6UHuHq00FAOvQdcf+/7Kcq3LYYFsMD3OgNI7pZxuh8h cNs+ByOJlNBuI2UDlgaezEtW6bXLf0Xn+/YhDmNoLEpURH3UrT66OeeGAhoY1GJlecgOCR RMG6MXrMqlGp88Hr5SVcSgVXuoA9LYs= 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 2/2] xen/gnttab: reduce size of struct active_grant_entry Date: Mon, 12 Sep 2022 07:53:56 +0200 Message-Id: <20220912055356.24064-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220912055356.24064-1-jgross@suse.com> References: <20220912055356.24064-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1662962093548100005 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 last known user has been the old Xenolinux branch of the Linux kernel. 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 today. Signed-off-by: Juergen Gross --- 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..8e4bbe3824 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 trans_domid; /* 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->trans_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->trans_domid =3D=3D rd->domain_id) + ? rd : domid_to_domain(act->trans_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->trans_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->trans_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->trans_domid =3D td->domain_id; act->trans_gref =3D trans_gref; act->mfn =3D grant_mfn; } --=20 2.35.3