From nobody Fri Apr 26 11:00:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1559565310; cv=none; d=zoho.com; s=zohoarc; b=k2cwGbdbuuRJ/fkssKqtKyVgToHfOxKpMp+QQ5fYGLcD1511DCkLxqodEjssgccDXR0RlpjqkM53n6HkY153jFrIUP8d/ElLxZgvZBuuzWBA1Uh4T56Ye70OZhvoMw0ja60yWz/rFXU09+hjq1Qoshep510r6cEVhfuLVdvUvag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559565310; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=TBkv7QneaXzfLott1uLvQ75e2IZOi9VcjGzQMes+4g8=; b=CnMpHMUtcaiP1f5Wn0siuZHsM8TzFp3VUo/49b+ks138IB3uxbl1xbnnwyB5zL30jjbCGjG7sVsQIvp1j1RPY7d+VA7iZWA+mXh88s2Jimohc8ofYjt1x+PR2EguAzrqdqlvB6sutCzlZmBto+XbpjPFM0dfv7+vAiqCu99O1ro= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559565310148232.56057892222464; Mon, 3 Jun 2019 05:35:10 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXmA2-0004K3-BJ; Mon, 03 Jun 2019 12:33:58 +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.89) (envelope-from ) id 1hXmA1-0004Jo-Ge for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 12:33:57 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d9840170-85fb-11e9-876b-db723debf754; Mon, 03 Jun 2019 12:33:55 +0000 (UTC) X-Inumbo-ID: d9840170-85fb-11e9-876b-db723debf754 Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@MIAPEX02MSOL01.citrite.net Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=23.29.105.83; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 23.29.105.83 as permitted sender) identity=mailfrom; client-ip=23.29.105.83; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:23.29.105.83 ip4:162.221.156.50 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@MIAPEX02MSOL01.citrite.net) identity=helo; client-ip=23.29.105.83; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@MIAPEX02MSOL01.citrite.net"; x-conformance=sidf_compatible IronPort-SDR: M8pNHGGQ+Bi9BrIvKX0M0XvfKbCFnbdYBHroOv7zamEPZHCz6yGWSGF55aG/FPAaA4B6wtNo5B IOx7OCLCAqjuR2BfxXhaHJvxjKBqwXJTET/bAPTR9AzoW1UBYDLvDm6lX6FphztM27vy5QpykU LfjWFiHvE4kZmYmqSDlgbumhvZov6jSjwyFwV/KboBrwYrTRbap7TX71GF/JT+RcY+/RD8JRyI aoYpiFeMpA56tdxjS2JXxqeLyqdQ2PDnM9cdwu+bewe3FmAj0GlSmky3kQYDUV86Jux+Pk5px+ /5Y= X-SBRS: 2.7 X-MesageID: 1213600 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 23.29.105.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.60,546,1549947600"; d="scan'208";a="1213600" From: Andrew Cooper To: Xen-devel Date: Mon, 3 Jun 2019 13:33:46 +0100 Message-ID: <1559565226-19789-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] x86/hvm: Make the altp2m locking in hvm_hap_nested_page_fault() easier to follow X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap , Andrew Cooper , Tamas K Lengyel , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Drop the ap2m_active boolean, and consistently use the unlocking form: if ( p2m !=3D hostp2m ) __put_gfn(p2m, gfn); __put_gfn(hostp2m, gfn); which makes it clear that we always unlock the altp2m's gfn if it is in use, and always unlock the hostp2m's gfn. This also drops the ternary expression in the logdirty case. Extend the logdirty comment to identify where the locking violation is liab= le to occur. No (intended) overall change in behaviour. Signed-off-by: Andrew Cooper Reviewed-by: Razvan Cojocaru Reviewed-by: Jan Beulich Acked-by: George Dunlap --- CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Tamas K Lengyel CC: George Dunlap v2: * Edit subject to be clearer * Rebase over Tamas' lazy copy cleanup --- xen/arch/x86/hvm/hvm.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index d8d5d45..029eea3 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1691,7 +1691,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned l= ong gla, int rc, fall_through =3D 0, paged =3D 0; int sharing_enomem =3D 0; vm_event_request_t *req_ptr =3D NULL; - bool_t ap2m_active, sync =3D 0; + bool sync =3D false; unsigned int page_order; =20 /* On Nested Virtualization, walk the guest page table. @@ -1750,8 +1750,6 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned l= ong gla, goto out; } =20 - ap2m_active =3D altp2m_active(currd); - /* * Take a lock on the host p2m speculatively, to avoid potential * locking order problems later and to handle unshare etc. @@ -1761,7 +1759,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned l= ong gla, P2M_ALLOC | (npfec.write_access ? P2M_UNSHAR= E : 0), &page_order); =20 - if ( ap2m_active ) + if ( altp2m_active(currd) ) { p2m =3D p2m_get_altp2m(curr); =20 @@ -1888,13 +1886,14 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned= long gla, { paging_mark_pfn_dirty(currd, _pfn(gfn)); /* - * If p2m is really an altp2m, unlock here to avoid lock order= ing - * violation when the change below is propagated from host p2m. + * If p2m is really an altp2m, unlock it before changing the t= ype, + * as p2m_altp2m_propagate_change() needs to acquire the + * altp2m_list lock. */ - if ( ap2m_active ) + if ( p2m !=3D hostp2m ) __put_gfn(p2m, gfn); p2m_change_type_one(currd, gfn, p2m_ram_logdirty, p2m_ram_rw); - __put_gfn(ap2m_active ? hostp2m : p2m, gfn); + __put_gfn(hostp2m, gfn); =20 goto out; } @@ -1915,9 +1914,9 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned l= ong gla, rc =3D fall_through; =20 out_put_gfn: - __put_gfn(p2m, gfn); - if ( ap2m_active ) - __put_gfn(hostp2m, gfn); + if ( p2m !=3D hostp2m ) + __put_gfn(p2m, gfn); + __put_gfn(hostp2m, gfn); out: /* All of these are delayed until we exit, since we might=20 * sleep on event ring wait queues, and we must not hold --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel