From nobody Thu May 9 01:10:56 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; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=bitdefender.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1569240506467177.61224646836718; Mon, 23 Sep 2019 05:08:26 -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 1iCN6M-0000wa-Db; Mon, 23 Sep 2019 12:05: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 1iCN6K-0000wU-IF for xen-devel@lists.xenproject.org; Mon, 23 Sep 2019 12:05:56 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (unknown [40.107.3.130]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7e973dca-ddfa-11e9-95fc-12813bfff9fa; Mon, 23 Sep 2019 12:05:55 +0000 (UTC) Received: from AM7PR02MB5750.eurprd02.prod.outlook.com (10.141.171.8) by AM7PR02MB5878.eurprd02.prod.outlook.com (10.141.173.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.20; Mon, 23 Sep 2019 12:05:53 +0000 Received: from AM7PR02MB5750.eurprd02.prod.outlook.com ([fe80::2d9b:67b0:d407:67b8]) by AM7PR02MB5750.eurprd02.prod.outlook.com ([fe80::2d9b:67b0:d407:67b8%2]) with mapi id 15.20.2284.023; Mon, 23 Sep 2019 12:05:53 +0000 X-Inumbo-ID: 7e973dca-ddfa-11e9-95fc-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AE/hsWPCMc6ft9PETo6HUTf2XasyBoRDQ7NK0LKRTwwGrtmyJwG5k8tq1Z3q4HPcgLJO7zwgdQ8fAqs5ftt2m7wo4yccB7Y1MwSffcHexDIHyRtuEqcq1gLnoRYEfqh0tTERSBv6CScS42ojhO5XbJHIwPxqwIZXziPJAAcLbL3TmgSvs8aAhM5zxWOdS0poNPu9pgXh3PkGD39OJlOhRr6RZpH76w7HgZSMPwgrkqhvbPEUENklXBHytXbv4tQOUCo1+thSAWsVMMBX6pVls7F+jnIoqIsmj/P181LoIGqhszwfMZWjh+0ouR2KyzQcq/jXbeSzKbDUVIgwqFMS/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=63S0AHDFK8MoC0VvWzl+ruARqI+Hs0wazi0+MnhSknw=; b=PAi1LnhR0bmAby2HsKWsZwPupgo0C1qJD2L9IbupsM3FB0RHaEhSqozbq/UWPJvW3Sae1KJeiYn3PV1NyNAuWICFhq95HWQWj3BU3BuN5amI9tBZGoocRCZhLSqimynwWiU+y3aYe8qJJalb+peYnSK4MvWItOTTU+D6TwyZeAwtYHnilMforqTs+ledqjzBiEEHueoyqWNVDY2lg+RDCfFYinmUqH2v6LAG+W9dLGcbvJpwlMb9l1PX635FK7huF5Ra9kzYAG6NgN+6hZfCavDFzrHJZm35SFNrcfhkRb7yhB16tC1+5H8jegde2ULDmYEuy9Vm0YvgoIrdNSvfhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bitdefender.com; dmarc=pass action=none header.from=bitdefender.com; dkim=pass header.d=bitdefender.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector2-bitdefender-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=63S0AHDFK8MoC0VvWzl+ruARqI+Hs0wazi0+MnhSknw=; b=ihSYCQS1/NedAfn6yeV8TDtgSWBidkP9aUF6fdWOixhL2u3DAFgUpt03ruzDvwDNL/WVMnxM6ERnV3ZdfImodzrA3UcGoa2vHOO14pxwPBce2stFEbReGw50zjOcvaVuXHieSmWh6zWN+flqsbpMF2SzUZIVAD3S0Br0mw/vbNA= From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v13] x86/emulate: Send vm_event from emulate Thread-Index: AQHVcgc/RjZRGBRqJUWCjIFeFraK9A== Date: Mon, 23 Sep 2019 12:05:53 +0000 Message-ID: <20190923120539.25242-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM3PR05CA0134.eurprd05.prod.outlook.com (2603:10a6:207:3::12) To AM7PR02MB5750.eurprd02.prod.outlook.com (2603:10a6:20b:102::8) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aisaila@bitdefender.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [91.199.104.6] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3f0f916a-21c2-43c8-03a8-08d7401e61b8 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:AM7PR02MB5878; x-ms-traffictypediagnostic: AM7PR02MB5878:|AM7PR02MB5878:|AM7PR02MB5878: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0169092318 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(39860400002)(136003)(376002)(396003)(346002)(199004)(189003)(5660300002)(66476007)(8676002)(2501003)(86362001)(2351001)(36756003)(6486002)(486006)(66446008)(6916009)(4326008)(8936002)(26005)(81156014)(3846002)(102836004)(6436002)(99286004)(256004)(50226002)(14454004)(186003)(54906003)(25786009)(81166006)(6116002)(5640700003)(66066001)(14444005)(71200400001)(305945005)(2906002)(1076003)(71190400001)(6506007)(316002)(386003)(7736002)(476003)(66556008)(64756008)(2616005)(30864003)(66946007)(52116002)(6512007)(478600001)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:AM7PR02MB5878; H:AM7PR02MB5750.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; 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 (protection.outlook.com: bitdefender.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: NqkhkQSx2tHVV0MQ5K8aEB+vDWszSLFvC8WcJ0lP3JPWUO05wr599mbQfVw1DYpe9qv20PBCO0+iGmJNLC8bqlZa9pBngLrDJ1pC06p4xI3XQiagdFmPL4jI4kEH4bsUpoRgbBv3KfBuDyLTuLar1fEVgbx6wGVhO7Cov9ipr+HiI4r2kEANA2PvMqi6Tom+1IPkHwCnTBqrFiSSKiAjWth0Bw5nVfG2AggnQY8lPYDYDTdWmaCXuWX2bBZhnLL9euJZKNAiR1q2gfDLNMaysoJJ9cBkvXboTxsOeaeSUB3xqrngANcBJEILyx1q//Or7HspUvtoVPwefoqvkjPfKgxpQfRJhIRbTr7uTymRY2egEWqZM10g0HOUGrS4A9PtuURj2O6RcJUmEwBgByG0jYi5w3wGEDJ73PEJ4Wkv+EQ= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f0f916a-21c2-43c8-03a8-08d7401e61b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Sep 2019 12:05:53.1362 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 487baf29-f1da-469a-9221-243f830c36f3 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: hMPA02P257VOJlnfpQTlJStmwi9FZLiBY8BOyOBfQ2Xnsn9SFVRjdRL8Vk6+idc/Yf53qzuWWEV6HTSG8EYpj8HcyDWo5JJ38dTLBf2k4Bk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR02MB5878 Subject: [Xen-devel] [PATCH v13] x86/emulate: Send vm_event from emulate 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: Petre Ovidiu PIRCALABU , "tamas@tklengyel.com" , "wl@xen.org" , Razvan COJOCARU , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.com" , "paul.durrant@citrix.com" , "jbeulich@suse.com" , Alexandru Stefan ISAILA , "roger.pau@citrix.com" 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) A/D bit writes (on page walks) can be considered benign by an introspection agent, so receiving vm_events for them is a pessimization. We try here to optimize by filtering these events out. Currently, we are fully emulating the instruction at RIP when the hardware = sees an EPT fault with npfec.kind !=3D npfec_kind_with_gla. This is, however, incorrect, because the instruction at RIP might legitimately cause an EPT fault of its own while accessing a _different_ page from the original o= ne, where A/D were set. The solution is to perform the whole emulation, while ignoring EPT restrict= ions for the walk part, and taking them into account for the "actual" emulating = of the instruction at RIP. When we send out a vm_event, we don't want the emul= ation to complete, since in that case we won't be able to veto whatever it is doi= ng. That would mean that we can't actually prevent any malicious activity, inst= ead we'd only be able to report on it. When we see a "send-vm_event" case while emulating, we need to first send t= he event out and then suspend the emulation (return X86EMUL_RETRY). After the emulation stops we'll call hvm_vm_event_do_resume() again after t= he introspection agent treats the event and resumes the guest. There, the instruction at RIP will be fully emulated (with the EPT ignored) if the introspection application allows it, and the guest will continue to run past the instruction. A common example is if the hardware exits because of an EPT fault caused by= a page walk, p2m_mem_access_check() decides if it is going to send a vm_event. If the vm_event was sent and it would be treated so it runs the instruction at RIP, that instruction might also hit a protected page and provoke a vm_e= vent. Now if npfec.kind =3D=3D npfec_kind_in_gpt and d->arch.monitor.inguest_page= fault_disabled is true then we are in the page walk case and we can do this emulation opti= mization and emulate the page walk while ignoring the EPT, but don't ignore the EPT = for the emulation of the actual instruction. In the first case we would have 2 EPT events, in the second case we would h= ave 1 EPT event if the instruction at the RIP triggers an EPT event. We use hvmemul_map_linear_addr() to intercept write access and __hvm_copy() to intercept exec, read and write access. A new return type was added, HVMTRANS_need_retry, in order to have all the places that consume HVMTRANS* return X86EMUL_RETRY. hvm_emulate_send_vm_event() can return false if there was no violation, if there was an error from monitor_traps() or p2m_get_mem_access(). -ESRCH from p2m_get_mem_access() is treated as restricted access. NOTE: hvm_emulate_send_vm_event() assumes the caller will enable/disable arch.vm_event->send_event Signed-off-by: Alexandru Isaila Acked-by: Paul Durrant Reviewed-by: Jan Beulich Reviewed-by: Petre Pircalabu --- Changes since V12: - Update commit message - Rework switch() in map_linear_addr()/rep_movs()/rep_stos(). --- xen/arch/x86/hvm/emulate.c | 57 +++++++++++++++++----- xen/arch/x86/hvm/hvm.c | 9 ++++ xen/arch/x86/hvm/intercept.c | 2 + xen/arch/x86/hvm/monitor.c | 78 +++++++++++++++++++++++++++++++ xen/arch/x86/mm/mem_access.c | 9 +++- xen/arch/x86/mm/shadow/hvm.c | 1 + xen/include/asm-x86/hvm/monitor.h | 3 ++ xen/include/asm-x86/hvm/support.h | 1 + xen/include/asm-x86/vm_event.h | 2 + 9 files changed, 149 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 36bcb526d3..85ab009717 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -548,6 +548,7 @@ static void *hvmemul_map_linear_addr( unsigned int nr_frames =3D ((linear + bytes - !!bytes) >> PAGE_SHIFT) - (linear >> PAGE_SHIFT) + 1; unsigned int i; + gfn_t gfn; =20 /* * mfn points to the next free slot. All used slots have a page refer= ence @@ -582,7 +583,7 @@ static void *hvmemul_map_linear_addr( ASSERT(mfn_x(*mfn) =3D=3D 0); =20 res =3D hvm_translate_get_page(curr, addr, true, pfec, - &pfinfo, &page, NULL, &p2mt); + &pfinfo, &page, &gfn, &p2mt); =20 switch ( res ) { @@ -599,8 +600,15 @@ static void *hvmemul_map_linear_addr( err =3D NULL; goto out; =20 - case HVMTRANS_gfn_paged_out: + case HVMTRANS_need_retry: + /* + * hvm_translate_get_page() does not return HVMTRANS_need_retr= y. + * It can dropped if future work requires this. + */ + ASSERT_UNREACHABLE(); + /* fall through */ case HVMTRANS_gfn_shared: + case HVMTRANS_gfn_paged_out: err =3D ERR_PTR(~X86EMUL_RETRY); goto out; =20 @@ -626,6 +634,14 @@ static void *hvmemul_map_linear_addr( =20 ASSERT(p2mt =3D=3D p2m_ram_logdirty || !p2m_is_readonly(p2mt)); } + + if ( unlikely(curr->arch.vm_event) && + curr->arch.vm_event->send_event && + hvm_monitor_check_p2m(addr, gfn, pfec, npfec_kind_with_gla) ) + { + err =3D ERR_PTR(~X86EMUL_RETRY); + goto out; + } } =20 /* Entire access within a single frame? */ @@ -1141,6 +1157,7 @@ static int linear_read(unsigned long addr, unsigned i= nt bytes, void *p_data, =20 case HVMTRANS_gfn_paged_out: case HVMTRANS_gfn_shared: + case HVMTRANS_need_retry: return X86EMUL_RETRY; } =20 @@ -1192,6 +1209,7 @@ static int linear_write(unsigned long addr, unsigned = int bytes, void *p_data, =20 case HVMTRANS_gfn_paged_out: case HVMTRANS_gfn_shared: + case HVMTRANS_need_retry: return X86EMUL_RETRY; } =20 @@ -1852,19 +1870,27 @@ static int hvmemul_rep_movs( =20 xfree(buf); =20 - if ( rc =3D=3D HVMTRANS_gfn_paged_out ) - return X86EMUL_RETRY; - if ( rc =3D=3D HVMTRANS_gfn_shared ) - return X86EMUL_RETRY; - if ( rc !=3D HVMTRANS_okay ) + switch ( rc ) { - gdprintk(XENLOG_WARNING, "Failed memory-to-memory REP MOVS: sgpa= =3D%" - PRIpaddr" dgpa=3D%"PRIpaddr" reps=3D%lu bytes_per_rep=3D%= u\n", - sgpa, dgpa, *reps, bytes_per_rep); - return X86EMUL_UNHANDLEABLE; + case HVMTRANS_need_retry: + /* + * hvm_copy_to_guest_phys() does not return HVMTRANS_need_retry. + * It can dropped if future work requires this. + */ + ASSERT_UNREACHABLE(); + /* fall through */ + case HVMTRANS_gfn_paged_out: + case HVMTRANS_gfn_shared: + return X86EMUL_RETRY; + case HVMTRANS_okay: + return X86EMUL_OKAY; } =20 - return X86EMUL_OKAY; + gdprintk(XENLOG_WARNING, "Failed memory-to-memory REP MOVS: sgpa=3D%" + PRIpaddr" dgpa=3D%"PRIpaddr" reps=3D%lu bytes_per_rep=3D%u\n", + sgpa, dgpa, *reps, bytes_per_rep); + + return X86EMUL_UNHANDLEABLE; } =20 static int hvmemul_rep_stos( @@ -1966,6 +1992,13 @@ static int hvmemul_rep_stos( =20 switch ( rc ) { + case HVMTRANS_need_retry: + /* + * hvm_copy_to_guest_phys() does not return HVMTRANS_need_retr= y. + * It can dropped if future work requires this. + */ + ASSERT_UNREACHABLE(); + /* fall through */ case HVMTRANS_gfn_paged_out: case HVMTRANS_gfn_shared: return X86EMUL_RETRY; diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index fdb1e17f59..c82e7b2cd3 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3236,6 +3236,15 @@ static enum hvm_translation_result __hvm_copy( return HVMTRANS_bad_gfn_to_mfn; } =20 + if ( unlikely(v->arch.vm_event) && + (flags & HVMCOPY_linear) && + v->arch.vm_event->send_event && + hvm_monitor_check_p2m(addr, gfn, pfec, npfec_kind_with_gla) ) + { + put_page(page); + return HVMTRANS_need_retry; + } + p =3D (char *)__map_domain_page(page) + (addr & ~PAGE_MASK); =20 if ( flags & HVMCOPY_to_guest ) diff --git a/xen/arch/x86/hvm/intercept.c b/xen/arch/x86/hvm/intercept.c index aac22c595d..90202bdcec 100644 --- a/xen/arch/x86/hvm/intercept.c +++ b/xen/arch/x86/hvm/intercept.c @@ -145,6 +145,7 @@ int hvm_process_io_intercept(const struct hvm_io_handle= r *handler, case HVMTRANS_bad_linear_to_gfn: case HVMTRANS_gfn_paged_out: case HVMTRANS_gfn_shared: + case HVMTRANS_need_retry: ASSERT_UNREACHABLE(); /* fall through */ default: @@ -174,6 +175,7 @@ int hvm_process_io_intercept(const struct hvm_io_handle= r *handler, case HVMTRANS_bad_linear_to_gfn: case HVMTRANS_gfn_paged_out: case HVMTRANS_gfn_shared: + case HVMTRANS_need_retry: ASSERT_UNREACHABLE(); /* fall through */ default: diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c index 2a41ccc930..7fb1e2c04e 100644 --- a/xen/arch/x86/hvm/monitor.c +++ b/xen/arch/x86/hvm/monitor.c @@ -23,8 +23,10 @@ */ =20 #include +#include #include #include +#include #include #include #include @@ -215,6 +217,82 @@ void hvm_monitor_interrupt(unsigned int vector, unsign= ed int type, monitor_traps(current, 1, &req); } =20 +/* + * Send memory access vm_events based on pfec. Returns true if the event w= as + * sent and false for p2m_get_mem_access() error, no violation and event s= end + * error. Assumes the caller will enable/disable arch.vm_event->send_event. + */ +bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn, uint32_t pfec, + uint16_t kind) +{ + xenmem_access_t access; + struct vcpu *curr =3D current; + vm_event_request_t req =3D {}; + paddr_t gpa =3D (gfn_to_gaddr(gfn) | (gla & ~PAGE_MASK)); + int rc; + + ASSERT(curr->arch.vm_event->send_event); + + /* + * p2m_get_mem_access() can fail from a invalid MFN and return -ESRCH + * in which case access must be restricted. + */ + rc =3D p2m_get_mem_access(curr->domain, gfn, &access, altp2m_vcpu_idx(= curr)); + + if ( rc =3D=3D -ESRCH ) + access =3D XENMEM_access_n; + else if ( rc ) + return false; + + switch ( access ) + { + case XENMEM_access_x: + case XENMEM_access_rx: + if ( pfec & PFEC_write_access ) + req.u.mem_access.flags =3D MEM_ACCESS_R | MEM_ACCESS_W; + break; + + case XENMEM_access_w: + case XENMEM_access_rw: + if ( pfec & PFEC_insn_fetch ) + req.u.mem_access.flags =3D MEM_ACCESS_X; + break; + + case XENMEM_access_r: + case XENMEM_access_n: + if ( pfec & PFEC_write_access ) + req.u.mem_access.flags |=3D MEM_ACCESS_R | MEM_ACCESS_W; + if ( pfec & PFEC_insn_fetch ) + req.u.mem_access.flags |=3D MEM_ACCESS_X; + break; + + case XENMEM_access_wx: + case XENMEM_access_rwx: + case XENMEM_access_rx2rw: + case XENMEM_access_n2rwx: + case XENMEM_access_default: + break; + } + + if ( !req.u.mem_access.flags ) + return false; /* no violation */ + + if ( kind =3D=3D npfec_kind_with_gla ) + req.u.mem_access.flags |=3D MEM_ACCESS_FAULT_WITH_GLA | + MEM_ACCESS_GLA_VALID; + else if ( kind =3D=3D npfec_kind_in_gpt ) + req.u.mem_access.flags |=3D MEM_ACCESS_FAULT_IN_GPT | + MEM_ACCESS_GLA_VALID; + + + req.reason =3D VM_EVENT_REASON_MEM_ACCESS; + req.u.mem_access.gfn =3D gfn_x(gfn); + req.u.mem_access.gla =3D gla; + req.u.mem_access.offset =3D gpa & ~PAGE_MASK; + + return monitor_traps(curr, true, &req) >=3D 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 0144f92b98..320b9fe621 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -210,11 +210,18 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long = gla, return true; } } + + /* + * Try to avoid sending a mem event. Suppress events caused by page-wa= lks + * by emulating but still checking mem_access violations. + */ if ( vm_event_check_ring(d->vm_event_monitor) && d->arch.monitor.inguest_pagefault_disabled && - npfec.kind !=3D npfec_kind_with_gla ) /* don't send a mem_event */ + npfec.kind =3D=3D npfec_kind_in_gpt ) { + v->arch.vm_event->send_event =3D true; hvm_emulate_one_vm_event(EMUL_KIND_NORMAL, TRAP_invalid_op, X86_EV= ENT_NO_EC); + v->arch.vm_event->send_event =3D false; =20 return true; } diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c index 0aa560b7f5..48dfad4557 100644 --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -139,6 +139,7 @@ hvm_read(enum x86_segment seg, return X86EMUL_UNHANDLEABLE; case HVMTRANS_gfn_paged_out: case HVMTRANS_gfn_shared: + case HVMTRANS_need_retry: return X86EMUL_RETRY; } =20 diff --git a/xen/include/asm-x86/hvm/monitor.h b/xen/include/asm-x86/hvm/mo= nitor.h index f1af4f812a..325b44674d 100644 --- a/xen/include/asm-x86/hvm/monitor.h +++ b/xen/include/asm-x86/hvm/monitor.h @@ -49,6 +49,9 @@ void hvm_monitor_interrupt(unsigned int vector, unsigned = int type, unsigned int err, uint64_t cr2); bool hvm_monitor_emul_unimplemented(void); =20 +bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn, uint32_t pfec, + uint16_t kind); + #endif /* __ASM_X86_HVM_MONITOR_H__ */ =20 /* diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/su= pport.h index e989aa7349..1500e6c94b 100644 --- a/xen/include/asm-x86/hvm/support.h +++ b/xen/include/asm-x86/hvm/support.h @@ -61,6 +61,7 @@ enum hvm_translation_result { HVMTRANS_unhandleable, HVMTRANS_gfn_paged_out, HVMTRANS_gfn_shared, + HVMTRANS_need_retry, }; =20 /* diff --git a/xen/include/asm-x86/vm_event.h b/xen/include/asm-x86/vm_event.h index 23e655710b..66db9e1e25 100644 --- a/xen/include/asm-x86/vm_event.h +++ b/xen/include/asm-x86/vm_event.h @@ -36,6 +36,8 @@ struct arch_vm_event { bool set_gprs; /* A sync vm_event has been sent and we're not done handling it. */ bool sync_event; + /* Send mem access events from emulator */ + bool send_event; }; =20 int vm_event_init_domain(struct domain *d); --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel