From nobody Sun Apr 28 18:09:29 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; 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=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1590712634; cv=none; d=zohomail.com; s=zohoarc; b=SwDD1TANDiIIjDOxHBSP7KVP+8TsVJVnDqYTB9rcbIOmUTtRgpxwEhNCymzc/JHAqUg4tRbCW0Ov9rTM4kaGIAJbr1SROrvBXUJG+sIc8vM2C32oKTF6Sw67D6rIh8a8IBcdUfN2Ggm4YMaExhErGpeqANW2XsJADrApggtP0+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590712634; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=hJHw1VDLcsI//mBPDwkIntcMYAu0YVXS+gXwciy/S8Y=; b=bAkhelMOJYPz3KV8OhotLzkqoXFI1NAbWYsjdr/TCKDNrrrCFpu+n0ByeqR6Oc3sfuZcEOJ9JpkzURu7WwY4khXFctFGByU+0Ctph/WS07XiXTfgdh4hy+mqIWKXem4L2ZM3RgIOder/Efz7vJwTQi0Gt+ErXHZ+rr2duG1TifE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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=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 1590712634326759.0802085234553; Thu, 28 May 2020 17:37:14 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeT0Y-0002zy-LI; Fri, 29 May 2020 00:36:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeT0Y-0002zt-80 for xen-devel@lists.xenproject.org; Fri, 29 May 2020 00:36:22 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6a53ab6a-a144-11ea-8993-bc764e2007e4; Fri, 29 May 2020 00:36:20 +0000 (UTC) X-Inumbo-ID: 6a53ab6a-a144-11ea-8993-bc764e2007e4 Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: wNmvSahmlECqvHg8JedH8RH/SKV/ZtpBZD5yQOkwQklXAkkK2tdbw9cYZpQ1grSS6NuAzPm99s ZCXnSApvy4M+vi3fH0e4HHV7wAvDJfCYB/SD0TVVuFra5Qjvq47DmEU6rPR6+SNf/a3RHI/E5D 8uN6QYuSjmdZ01rZs7t0svsO6e6zsZETKLHsDF6lij6av30wpHXGEQqLHoBWOyls7C9BPL2UkN Ei5WSmaOOuIal6G+xvSEBedIlOpzj98LxXyfPtOTUGZ9Abo3SS8eRkcRU2ajQgGkbzEXWrC7AV riY= X-SBRS: 2.7 X-MesageID: 19456684 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,446,1583211600"; d="scan'208";a="19456684" From: Igor Druzhinin To: Subject: [PATCH] x86/svm: do not try to handle recalc NPT faults immediately Date: Fri, 29 May 2020 01:35:53 +0100 Message-ID: <1590712553-7298-1-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , wl@xen.org, andrew.cooper3@citrix.com, george.dunlap@citrix.com, jbeulich@suse.com, roger.pau@citrix.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A recalculation NPT fault doesn't always require additional handling in hvm_hap_nested_page_fault(), moreover in general case if there is no explicit handling done there - the fault is wrongly considered fatal. Instead of trying to be opportunistic - use safer approach and handle P2M recalculation in a separate NPT fault by attempting to retry after making the necessary adjustments. This is aligned with Intel behavior where there are separate VMEXITs for recalculation and EPT violations (faults) and only faults are handled in hvm_hap_nested_page_fault(). Do it by also unifying do_recalc return code with Intel implementation where returning 1 means P2M was actually changed. This covers a specific case of migration with vGPU assigned on AMD: global log-dirty is enabled and causes immediate recalculation NPT fault in MMIO area upon access. Signed-off-by: Igor Druzhinin Reviewed-by: Roger Pau Monn=C3=A9 --- This is a safer alternative to: https://lists.xenproject.org/archives/html/xen-devel/2020-05/msg01662.html and more correct approach from my PoV. --- xen/arch/x86/hvm/svm/svm.c | 5 +++-- xen/arch/x86/mm/p2m-pt.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 46a1aac..7f6f578 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2923,9 +2923,10 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) v->arch.hvm.svm.cached_insn_len =3D vmcb->guest_ins_len & 0xf; rc =3D vmcb->exitinfo1 & PFEC_page_present ? p2m_pt_handle_deferred_changes(vmcb->exitinfo2) : 0; - if ( rc >=3D 0 ) + if ( rc =3D=3D 0 ) + /* If no recal adjustments were being made - handle this fault= */ svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo= 2); - else + else if ( rc < 0 ) { printk(XENLOG_G_ERR "%pv: Error %d handling NPF (gpa=3D%08lx ec=3D%04lx)\n", diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index 5c05017..377565b 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -340,7 +340,7 @@ static int do_recalc(struct p2m_domain *p2m, unsigned l= ong gfn) unsigned long gfn_remainder =3D gfn; unsigned int level =3D 4; l1_pgentry_t *pent; - int err =3D 0; + int err =3D 0, rc =3D 0; =20 table =3D map_domain_page(pagetable_get_mfn(p2m_get_pagetable(p2m))); while ( --level ) @@ -402,6 +402,8 @@ static int do_recalc(struct p2m_domain *p2m, unsigned l= ong gfn) clear_recalc(l1, e); err =3D p2m->write_p2m_entry(p2m, gfn, pent, e, level + 1); ASSERT(!err); + + rc =3D 1; } } unmap_domain_page((void *)((unsigned long)pent & PAGE_MASK)); @@ -448,12 +450,14 @@ static int do_recalc(struct p2m_domain *p2m, unsigned= long gfn) clear_recalc(l1, e); err =3D p2m->write_p2m_entry(p2m, gfn, pent, e, level + 1); ASSERT(!err); + + rc =3D 1; } =20 out: unmap_domain_page(table); =20 - return err; + return err ? err : rc; } =20 int p2m_pt_handle_deferred_changes(uint64_t gpa) --=20 2.7.4