From nobody Sun May 5 01:01:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1574100979; cv=none; d=zoho.com; s=zohoarc; b=Isg0WXz55kWsTX6PnWMaleAIuNVi3rCL0inKMCSA26Ty7KEJHADpVTpRnzX1JBohFZQzi88tN10ej3kLkDCVF8aNlCKLjcAZE9CtUviBtP+37mNwiR8rvi9foFgNI9U67iA4fKSBdIwAIzFFyDkk9bQoRG8TSAy6jnOKgm54wq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574100979; 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; bh=QvIlL6GIA3e/4C3E2TFiYGXMiSgmsbh9NxK3eeJYqDE=; b=Dwj1b2Yu9J12QzPhKTtcX9cofV4z7tfao2gmLDC+BvpYgvGtymsNsX3XdJPmoeeFzKYzMufPOQ34nJxAPPUvuMIRMyotu8d6a5rbpFattLM1X3XnrArJiCWplnyCSTAQpC1cgXj+WohWmaDflL/ql8R4ZctNQgomYMslBx2KLJw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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; dmarc=fail header.from= (p=none 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 157410097914090.67888532870472; Mon, 18 Nov 2019 10:16:19 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iWlYQ-0004ke-Tj; Mon, 18 Nov 2019 18:15:14 +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 1iWlYP-0004kX-SH for xen-devel@lists.xenproject.org; Mon, 18 Nov 2019 18:15:13 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5ccc0d0e-0a2f-11ea-a2df-12813bfff9fa; Mon, 18 Nov 2019 18:15:13 +0000 (UTC) X-Inumbo-ID: 5ccc0d0e-0a2f-11ea-a2df-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574100912; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=mkPlKTunlXNe+agMkPgBLYGzKeTsrGcjq7BjfJnrZ5o=; b=g9Nyz68eqiM1WAdIvt3H9V84CA+OitMz+r40oMSPVN0gOthDprW76hWa Eu4jgFHvFuyfBwalhfmxEEI96Th8Z9OoowCmsKSf6wnDXy2YBL/b+acV0 38nXjALbS9v94Suw0dAIReEHB4gckjHLRIXJ2WKEaN/OPQQUG1YGqyzo9 A=; Authentication-Results: esa6.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@mail.citrix.com 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 (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: WQWGQBZQJNbe5EFt3YvowA4zxcxZASSzysr94pFCTMyejBB1gB/bycwmErk9uCpUO8ZzXU1Lnd YUMevPIel3t4zQs8GKHyZw2cjPsAg8NiFdhHBtUDrrGufnUz6JHLh0d5MTgoOnnquDnfgbZ3Fo BJeJtBE92pKLPYiscV372jzYGz6rXSCXKg6HvASPwK0mNlOCUVrSTw1oJtz+NM33amPp5rwIMc DIPdz9DqnN45/p+e5BOt8+3qDjvCcEgSoszl9SHncwO61e3cA5WxFX7XOB1b30LT4u759rQlxC ukk= X-SBRS: 2.7 X-MesageID: 8892082 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.68,321,1569297600"; d="scan'208";a="8892082" From: Andrew Cooper To: Xen-devel Date: Mon, 18 Nov 2019 18:15:09 +0000 Message-ID: <20191118181509.10981-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/nested-hap: Fix handling of L0_ERROR 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: Juergen Gross , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?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" X-ZohoMail-DKIM: fail (Header signature does not verify) When nestedhvm_hap_nested_page_fault() returns L0_ERROR, hvm_hap_nested_page_fault() operates on the adjusted gpa. However, it operates with the original npfec, which is no longer be correct. In particular, it is possible to get a nested fault where the translation is not present in L12 (and therefore L02), while it is present in L01. When handling an L0_ERROR, adjust npfec as well as gpa. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: George Dunlap CC: Juergen Gross This is one part of fixing nested virt in light of XSA-304. Combined with: diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_hap.c index a509a40c93..bd58a86b46 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -167,7 +167,8 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa, goto out; rc =3D NESTEDHVM_PAGEFAULT_L0_ERROR; - if ( access_w && p2m_is_readonly(*p2mt) ) + if ( (access_w && p2m_is_readonly(*p2mt)) || + (access_x && *page_order) ) goto out; if ( p2m_is_paging(*p2mt) || p2m_is_shared(*p2mt) || !p2m_is_ram(*p2mt= ) ) it does resolve the issue. However, the above isn't correct in the general case, and is still under development. --- xen/arch/x86/hvm/hvm.c | 6 ++---- xen/arch/x86/mm/hap/nested_hap.c | 27 +++++++++++++++++++-------- xen/include/asm-x86/hvm/nestedhvm.h | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 818e705fd1..87eed13ee1 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1729,10 +1729,8 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned = long gla, * the same as for shadow paging. */ =20 - rv =3D nestedhvm_hap_nested_page_fault(curr, &gpa, - npfec.read_access, - npfec.write_access, - npfec.insn_fetch); + rv =3D nestedhvm_hap_nested_page_fault(curr, &gpa, &npfec); + switch (rv) { case NESTEDHVM_PAGEFAULT_DONE: case NESTEDHVM_PAGEFAULT_RETRY: diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_= hap.c index abe5958a52..9eba35f7e8 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -149,8 +149,7 @@ nestedhap_walk_L1_p2m(struct vcpu *v, paddr_t L2_gpa, p= addr_t *L1_gpa, static int nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_= gpa, p2m_type_t *p2mt, p2m_access_t *p2ma, - unsigned int *page_order, - bool_t access_r, bool_t access_w, bool_t access_x) + unsigned int *page_order, struct npfec *npfec) { mfn_t mfn; int rc; @@ -167,7 +166,7 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L= 1_gpa, paddr_t *L0_gpa, goto out; =20 rc =3D NESTEDHVM_PAGEFAULT_L0_ERROR; - if ( access_w && p2m_is_readonly(*p2mt) ) + if ( npfec->write_access && p2m_is_readonly(*p2mt) ) goto out; =20 if ( p2m_is_paging(*p2mt) || p2m_is_shared(*p2mt) || !p2m_is_ram(*p2mt= ) ) @@ -181,6 +180,18 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t = L1_gpa, paddr_t *L0_gpa, *L0_gpa =3D (mfn_x(mfn) << PAGE_SHIFT) + (L1_gpa & ~PAGE_MASK); out: __put_gfn(p2m, L1_gpa >> PAGE_SHIFT); + + /* + * When reporting L0_ERROR, rewrite nfpec to match what would have occ= ured + * if hardware had walked the L0, rather than the combined L02. + */ + if ( rc =3D=3D NESTEDHVM_PAGEFAULT_L0_ERROR ) + { + npfec->present =3D !mfn_eq(mfn, INVALID_MFN); + npfec->gla_valid =3D 0; + npfec->kind =3D npfec_kind_unknown; + } + return rc; } =20 @@ -191,7 +202,7 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L= 1_gpa, paddr_t *L0_gpa, */ int nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa, - bool_t access_r, bool_t access_w, bool_t access_x) + struct npfec *npfec) { int rv; paddr_t L1_gpa, L0_gpa; @@ -206,7 +217,8 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t= *L2_gpa, =20 /* walk the L1 P2M table */ rv =3D nestedhap_walk_L1_p2m(v, *L2_gpa, &L1_gpa, &page_order_21, &p2m= a_21, - access_r, access_w, access_x); + npfec->read_access, npfec->write_access, + npfec->insn_fetch); =20 /* let caller to handle these two cases */ switch (rv) { @@ -222,9 +234,8 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t= *L2_gpa, } =20 /* =3D=3D> we have to walk L0 P2M */ - rv =3D nestedhap_walk_L0_p2m(p2m, L1_gpa, &L0_gpa, - &p2mt_10, &p2ma_10, &page_order_10, - access_r, access_w, access_x); + rv =3D nestedhap_walk_L0_p2m(p2m, L1_gpa, &L0_gpa, &p2mt_10, &p2ma_10, + &page_order_10, npfec); =20 /* let upper level caller to handle these two cases */ switch (rv) { diff --git a/xen/include/asm-x86/hvm/nestedhvm.h b/xen/include/asm-x86/hvm/= nestedhvm.h index 256fed733a..7b53f23e97 100644 --- a/xen/include/asm-x86/hvm/nestedhvm.h +++ b/xen/include/asm-x86/hvm/nestedhvm.h @@ -58,7 +58,7 @@ bool_t nestedhvm_vcpu_in_guestmode(struct vcpu *v); #define NESTEDHVM_PAGEFAULT_RETRY 5 #define NESTEDHVM_PAGEFAULT_DIRECT_MMIO 6 int nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa, - bool_t access_r, bool_t access_w, bool_t access_x); + struct npfec *npfec); =20 int nestedhap_walk_L1_p2m(struct vcpu *v, paddr_t L2_gpa, paddr_t *L1_gpa, unsigned int *page_order, uint8_t *p2m_acc, --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel