From nobody Sat Nov 30 04:33:08 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) ) {