From nobody Fri May 3 14:33:09 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 ARC-Seal: i=1; a=rsa-sha256; t=1609699301; cv=none; d=zohomail.com; s=zohoarc; b=liUk3dxcalefHIHfKkgWHNrMBJ0aRi+HQRF1XTtgc+INomm+RDJcSPee+Q84pHowkHgZCR85W4XUrl4mYuoQ1xC2zjSOHc0QwgpWYVU5LgKgsEScoNTfz0tpLIH4s71TurzM+ZgKJB+N0qM9oafry/nzqMPbu1BJAXFTHxlLAzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609699301; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=CtZ0Ps/DGmjr7BrnhpZQwjEj9K3iGCWKqQ9pc72jRfc=; b=ZdHJ+mZQEKLVnWnbqiL4g6/Zx5Ak3MNEyO6YfQWrMEV8NLMm25yoSNE+P+LMGa1LN9rmCMo7kXjDMzkZHXIxGSAc8qGjcgbe+pdkfhD/yBsfFWGST+ord7bCdHNcGhH+ucnp3MD/hIBKMJOdFO1xOCq4uQDOZKVpqElVwjm94Pg= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1609699301921423.48015796505354; Sun, 3 Jan 2021 10:41:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.60969.106949 (Exim 4.92) (envelope-from ) id 1kw8Ji-0004dU-Ig; Sun, 03 Jan 2021 18:41:26 +0000 Received: by outflank-mailman (output) from mailman id 60969.106949; Sun, 03 Jan 2021 18:41:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kw8Ji-0004dN-Ef; Sun, 03 Jan 2021 18:41:26 +0000 Received: by outflank-mailman (input) for mailman id 60969; Sun, 03 Jan 2021 18:41:24 +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 1kw8Jg-0004dI-QM for xen-devel@lists.xenproject.org; Sun, 03 Jan 2021 18:41:24 +0000 Received: from MTA-10-1.privateemail.com (unknown [68.65.122.30]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id db1bbd50-3250-41fc-b1c8-baba657d0818; Sun, 03 Jan 2021 18:41:23 +0000 (UTC) Received: from MTA-10.privateemail.com (localhost [127.0.0.1]) by MTA-10.privateemail.com (Postfix) with ESMTP id F191A60071; Sun, 3 Jan 2021 13:41:21 -0500 (EST) Received: from t9.localdomain (unknown [10.20.151.215]) by MTA-10.privateemail.com (Postfix) with ESMTPA id C6CB760033; Sun, 3 Jan 2021 18:41:20 +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: db1bbd50-3250-41fc-b1c8-baba657d0818 From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Cc: Tamas K Lengyel , Alexandru Isaila , Petre Pircalabu , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH] x86/vm_event: transfer nested p2m base info Date: Sun, 3 Jan 2021 11:41:17 -0700 Message-Id: <20210103184117.57692-1-tamas@tklengyel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV using ClamSMTP Content-Type: text/plain; charset="utf-8" Required to introspect events originating from nested VMs. Signed-off-by: Tamas K Lengyel --- xen/arch/x86/hvm/monitor.c | 32 ++++++++++++++++++++++++++++++-- xen/include/public/vm_event.h | 7 ++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c index e4a09964a0..eb4afe81b3 100644 --- a/xen/arch/x86/hvm/monitor.c +++ b/xen/arch/x86/hvm/monitor.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,15 @@ #include #include =20 +static inline void set_npt_base(struct vcpu *curr, vm_event_request_t *req) +{ + if ( nestedhvm_enabled(curr->domain) && nestedhvm_vcpu_in_guestmode(cu= rr) ) + { + req->flags |=3D VM_EVENT_FLAG_NESTED_P2M; + req->data.regs.x86.npt_base =3D nhvm_vcpu_p2m_base(curr); + } +} + bool hvm_monitor_cr(unsigned int index, unsigned long value, unsigned long= old) { struct vcpu *curr =3D current; @@ -53,6 +63,8 @@ bool hvm_monitor_cr(unsigned int index, unsigned long val= ue, unsigned long old) .u.write_ctrlreg.old_value =3D old }; =20 + set_npt_base(curr, &req); + return monitor_traps(curr, sync, &req) >=3D 0 && curr->domain->arch.monitor.control_register_values; } @@ -73,6 +85,8 @@ bool hvm_monitor_emul_unimplemented(void) .vcpu_id =3D curr->vcpu_id, }; =20 + set_npt_base(curr, &req); + return curr->domain->arch.monitor.emul_unimplemented_enabled && monitor_traps(curr, true, &req) =3D=3D 1; } @@ -92,6 +106,8 @@ bool hvm_monitor_msr(unsigned int msr, uint64_t new_valu= e, uint64_t old_value) .u.mov_to_msr.old_value =3D old_value }; =20 + set_npt_base(curr, &req); + return monitor_traps(curr, 1, &req) >=3D 0 && curr->domain->arch.monitor.control_register_values; } @@ -103,6 +119,7 @@ void hvm_monitor_descriptor_access(uint64_t exit_info, uint64_t vmx_exit_qualification, uint8_t descriptor, bool is_write) { + struct vcpu *curr =3D current; vm_event_request_t req =3D { .reason =3D VM_EVENT_REASON_DESCRIPTOR_ACCESS, .u.desc_access.descriptor =3D descriptor, @@ -115,7 +132,9 @@ void hvm_monitor_descriptor_access(uint64_t exit_info, req.u.desc_access.arch.vmx.exit_qualification =3D vmx_exit_qualifi= cation; } =20 - monitor_traps(current, true, &req); + set_npt_base(curr, &req); + + monitor_traps(curr, true, &req); } =20 static inline unsigned long gfn_of_rip(unsigned long rip) @@ -189,6 +208,8 @@ int hvm_monitor_debug(unsigned long rip, enum hvm_monit= or_debug_type type, return -EOPNOTSUPP; } =20 + set_npt_base(curr, &req); + return monitor_traps(curr, sync, &req); } =20 @@ -207,12 +228,15 @@ int hvm_monitor_cpuid(unsigned long insn_length, unsi= gned int leaf, req.u.cpuid.leaf =3D leaf; req.u.cpuid.subleaf =3D subleaf; =20 + set_npt_base(curr, &req); + return monitor_traps(curr, 1, &req); } =20 void hvm_monitor_interrupt(unsigned int vector, unsigned int type, unsigned int err, uint64_t cr2) { + struct vcpu *curr =3D current; vm_event_request_t req =3D { .reason =3D VM_EVENT_REASON_INTERRUPT, .u.interrupt.x86.vector =3D vector, @@ -221,7 +245,9 @@ void hvm_monitor_interrupt(unsigned int vector, unsigne= d int type, .u.interrupt.x86.cr2 =3D cr2, }; =20 - monitor_traps(current, 1, &req); + set_npt_base(curr, &req); + + monitor_traps(curr, 1, &req); } =20 /* @@ -297,6 +323,8 @@ bool hvm_monitor_check_p2m(unsigned long gla, gfn_t gfn= , uint32_t pfec, req.u.mem_access.gla =3D gla; req.u.mem_access.offset =3D gpa & ~PAGE_MASK; =20 + set_npt_base(curr, &req); + return monitor_traps(curr, true, &req) >=3D 0; } =20 diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index fdd3ad8a30..8415bc7618 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -29,7 +29,7 @@ =20 #include "xen.h" =20 -#define VM_EVENT_INTERFACE_VERSION 0x00000006 +#define VM_EVENT_INTERFACE_VERSION 0x00000007 =20 #if defined(__XEN__) || defined(__XEN_TOOLS__) =20 @@ -119,6 +119,10 @@ * which singlestep gets automatically disabled. */ #define VM_EVENT_FLAG_FAST_SINGLESTEP (1 << 11) +/* + * Set if the event comes from a nested VM and thus npt_base is valid. + */ +#define VM_EVENT_FLAG_NESTED_P2M (1 << 12) =20 /* * Reasons for the vm event request @@ -208,6 +212,7 @@ struct vm_event_regs_x86 { uint64_t msr_star; uint64_t msr_lstar; uint64_t gdtr_base; + uint64_t npt_base; uint32_t cs_base; uint32_t ss_base; uint32_t ds_base; --=20 2.25.1