From nobody Sat Nov 30 04:45:27 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=1618228122; cv=none; d=zohomail.com; s=zohoarc; b=H2oxeLvU+a6pXQ004CQHEATdlytKAtK6m2I9836hLPFxrz7kgxDfqpWa3/WzMGh9NngojsN1codesNWuoawGsyXcQsS9jhg4mlkJENdAxEUnV8d99gdzAqIvbRmTXLYeOZsgNJI8nqWtxpDuPDHT5wAs00BjT97qbZrURaX/9ZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618228122; h=Content-Type: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=efXFBmOcOFrcWbNhfJK8dazr1JEkvwc/LrJUCkX1xVY=; b=fxPVIsdZayWFwOv40BBT/6AdmZKcDfWfcHamOvzb27TN34KsTqvbaP5w0lCkKpCFKvy/XqZLPvpVtsrOxBuBkKgjn+PW4Y29hOO4ykJUV3iL1ZLbWhG+G+chibNeL/hgFNVxOSOVrCsfTB495ih0kLuqXYza0a0vRmU4v25c9HA= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1618228122554452.72282047383624; Mon, 12 Apr 2021 04:48:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.109042.208137 (Exim 4.92) (envelope-from ) id 1lVv3C-0006vf-Lk; Mon, 12 Apr 2021 11:48:18 +0000 Received: by outflank-mailman (output) from mailman id 109042.208137; Mon, 12 Apr 2021 11:48:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lVv3C-0006vY-Iq; Mon, 12 Apr 2021 11:48:18 +0000 Received: by outflank-mailman (input) for mailman id 109042; Mon, 12 Apr 2021 11:48:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lVv3B-0006vS-EJ for xen-devel@lists.xenproject.org; Mon, 12 Apr 2021 11:48:17 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 20c674ae-4072-4863-a91a-f87ee2a263eb; Mon, 12 Apr 2021 11:48:16 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EB506AC6A; Mon, 12 Apr 2021 11:48:15 +0000 (UTC) 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: 20c674ae-4072-4863-a91a-f87ee2a263eb X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1618228096; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=efXFBmOcOFrcWbNhfJK8dazr1JEkvwc/LrJUCkX1xVY=; b=QMnerBIMAOm5HtjfFstMrAbuygTmvJ7GjjlpMYjnUGlPmkK0WCrvHvvjU+kgSGaF1cBDrm Z0+TncfxuWhuiW7s7dR3UB8Z2joRR4tLi8sfhz8LZ090L4AxvGEupWV5gWpeKuJ8m0xJGd 7wwNJNevnYpIaf+ydeYd1nDI3+woD60= Subject: [PATCH 1/2] x86/shadow: re-use variables in shadow_get_page_from_l1e() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Tim Deegan , George Dunlap , Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: Message-ID: Date: Mon, 12 Apr 2021 13:48:16 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" There's little point in doing multiple mfn_to_page() or page_get_owner() on all the same MFN. Calculate them once at the start of the function. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/shadow/set.c +++ b/xen/arch/x86/mm/shadow/set.c @@ -89,25 +89,27 @@ shadow_get_page_from_l1e(shadow_l1e_t sl { int res; mfn_t mfn; - struct domain *owner; + const struct page_info *pg =3D NULL; + struct domain *owner =3D NULL; =20 ASSERT(!sh_l1e_is_magic(sl1e)); ASSERT(shadow_mode_refcounts(d)); =20 + if ( mfn_valid(mfn =3D shadow_l1e_get_mfn(sl1e)) ) + { + pg =3D mfn_to_page(mfn); + owner =3D page_get_owner(pg); + } + /* * VMX'es APIC access MFN is just a surrogate page. It doesn't actual= ly * get accessed, and hence there's no need to refcount it (and refcoun= ting * would fail, due to the page having no owner). */ - if ( mfn_valid(mfn =3D shadow_l1e_get_mfn(sl1e)) ) + if ( pg && !owner && (pg->count_info & PGC_extra) ) { - const struct page_info *pg =3D mfn_to_page(mfn); - - if ( !page_get_owner(pg) && (pg->count_info & PGC_extra) ) - { - ASSERT(type =3D=3D p2m_mmio_direct); - return 0; - } + ASSERT(type =3D=3D p2m_mmio_direct); + return 0; } =20 res =3D get_page_from_l1e(sl1e, d, d); @@ -118,9 +120,7 @@ shadow_get_page_from_l1e(shadow_l1e_t sl */ if ( unlikely(res < 0) && !shadow_mode_translate(d) && - mfn_valid(mfn =3D shadow_l1e_get_mfn(sl1e)) && - (owner =3D page_get_owner(mfn_to_page(mfn))) && - (d !=3D owner) ) + owner && (d !=3D owner) ) { res =3D xsm_priv_mapping(XSM_TARGET, d, owner); if ( !res ) @@ -143,9 +143,8 @@ shadow_get_page_from_l1e(shadow_l1e_t sl * already have checked that we're supposed to have access, so * we can just grab a reference directly. */ - mfn =3D shadow_l1e_get_mfn(sl1e); - if ( mfn_valid(mfn) ) - res =3D get_page_from_l1e(sl1e, d, page_get_owner(mfn_to_page(= mfn))); + if ( owner ) + res =3D get_page_from_l1e(sl1e, d, owner); } =20 if ( unlikely(res < 0) )