From nobody Sat Nov 30 02:55:46 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) ) From nobody Sat Nov 30 02:55:46 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=1618228139; cv=none; d=zohomail.com; s=zohoarc; b=l6+/DeqQz9zjW4vjlpNB8WlfzUgvscJmdjUlH8DWCiqpr0X6sPMaX78Nm3XJtsCp5Cn8SCnYCPN4CZ5wnBEX/kFxcQ1Z1HmyFhSJIMASYU4twx52pRYRrQM4H0viBOUQBUJ0WtYHYQjir6tSUHkZCwfUvlUr0xyJpgLh6gsTlhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618228139; 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=oLMMZLurdOShZGSmBBd6sEABJTI2Dapn7waZkVo+PAY=; b=mjAM26cjwcJFWBP5PpY1Du+wssfj3Xx6cChNSlayHjka8WfgF6WuEtd3q0zcX3eIQKNhV8+/nf4oYzOkqYPNzubWBgFX/0ay8ijq1zI2g9LgdSCQCYOTuOiWYVt8g+wp4wvsE2uiwaGL8XeYBPvfkxinkOUNktmr0eNJ6tCksZo= 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 1618228139913916.0441029248974; Mon, 12 Apr 2021 04:48:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.109045.208149 (Exim 4.92) (envelope-from ) id 1lVv3c-000719-Uz; Mon, 12 Apr 2021 11:48:44 +0000 Received: by outflank-mailman (output) from mailman id 109045.208149; Mon, 12 Apr 2021 11:48:44 +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-000712-Rd; Mon, 12 Apr 2021 11:48:44 +0000 Received: by outflank-mailman (input) for mailman id 109045; Mon, 12 Apr 2021 11:48:44 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lVv3c-00070x-0P for xen-devel@lists.xenproject.org; Mon, 12 Apr 2021 11:48:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7067a87d-1c18-4f39-bd06-61a4f903cf66; Mon, 12 Apr 2021 11:48:43 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 65893AC6A; Mon, 12 Apr 2021 11:48:42 +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: 7067a87d-1c18-4f39-bd06-61a4f903cf66 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=1618228122; 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=oLMMZLurdOShZGSmBBd6sEABJTI2Dapn7waZkVo+PAY=; b=RtE7xqYkwbsucNJMDikWbvY3iJYQKDO+UnIK6ZBM7RCxRc3FyRCdpCPHjEW8rrev/Xhelh o/khsavjVXHBjsnvCXhzZzc2CffEiOM4ValhuRlT3M9kKsMTW0Wu8DMjEU8bL7+u5NvCUI xtwnihfDlzkJ7WP2Qw2r6Q9KNQBd2gg= Subject: [PATCH 2/2] x86/shadow: streamline 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: <5473f1b2-eae7-aa57-d910-b33b5678ec06@suse.com> Date: Mon, 12 Apr 2021 13:48:43 +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" Trying get_page_from_l1e() up to three times isn't helpful; in debug builds it may lead to log messages mking things look as if there was a problem somewhere. And there's no need to have more than one try: The function can only possibly succeed for one domain passed as 3rd argument (unless the page is an MMIO one to which both have access, but MMIO pages should be "got" by specifying the requesting domain anyway). Re-arrange things so just the one call gets made which has a chance of succeeding. The code could in principle be arranged such that there's only a single call to get_page_from_l1e(), but the conditional would become pretty complex then and hence hard to follow / understand / adjust. The redundant (with shadow_mode_refcounts()) shadow_mode_translate() gets dropped. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/shadow/set.c +++ b/xen/arch/x86/mm/shadow/set.c @@ -112,40 +112,36 @@ shadow_get_page_from_l1e(shadow_l1e_t sl return 0; } =20 - res =3D get_page_from_l1e(sl1e, d, d); + if ( owner =3D=3D dom_io ) + owner =3D NULL; =20 /* * If a privileged domain is attempting to install a map of a page it = does * not own, we let it succeed anyway. */ - if ( unlikely(res < 0) && - !shadow_mode_translate(d) && - owner && (d !=3D owner) ) + if ( owner && (d !=3D owner) && + !(res =3D xsm_priv_mapping(XSM_TARGET, d, owner)) ) { - res =3D xsm_priv_mapping(XSM_TARGET, d, owner); - if ( !res ) - { - res =3D get_page_from_l1e(sl1e, d, owner); - SHADOW_PRINTK("privileged %pd installs map of mfn %"PRI_mfn" o= wned by %pd: %s\n", - d, mfn_x(mfn), owner, - res >=3D 0 ? "success" : "failed"); - } + res =3D get_page_from_l1e(sl1e, d, owner); + SHADOW_PRINTK("privileged %pd installs map of %pd's mfn %"PRI_mfn"= : %s\n", + d, owner, mfn_x(mfn), + res >=3D 0 ? "success" : "failed"); } - /* Okay, it might still be a grant mapping PTE. Try it. */ - if ( unlikely(res < 0) && - (type =3D=3D p2m_grant_map_rw || - (type =3D=3D p2m_grant_map_ro && - !(shadow_l1e_get_flags(sl1e) & _PAGE_RW))) ) + else if ( owner && + (type =3D=3D p2m_grant_map_rw || + (type =3D=3D p2m_grant_map_ro && + !(shadow_l1e_get_flags(sl1e) & _PAGE_RW))) ) { /* * It's a grant mapping. The grant table implementation will * already have checked that we're supposed to have access, so * we can just grab a reference directly. */ - if ( owner ) - res =3D get_page_from_l1e(sl1e, d, owner); + res =3D get_page_from_l1e(sl1e, d, owner); } + else + res =3D get_page_from_l1e(sl1e, d, d); =20 if ( unlikely(res < 0) ) {