From patchwork Mon Mar 18 11:20:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 10857395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99DBD1390 for ; Mon, 18 Mar 2019 11:23:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80AFE2937E for ; Mon, 18 Mar 2019 11:23:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7391629380; Mon, 18 Mar 2019 11:23:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E7C612937E for ; Mon, 18 Mar 2019 11:23:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h5qKM-0004GC-QE; Mon, 18 Mar 2019 11:21:10 +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 1h5qKK-0004FK-QS for xen-devel@lists.xenproject.org; Mon, 18 Mar 2019 11:21:08 +0000 X-Inumbo-ID: ec288f6c-496f-11e9-836a-1b8e103764b7 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumb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Wg1g9erp qWcQTYhfMKuJaR6ipkBfyxaot2MKedN7e5My9TmClPDj6exl/+3abb7kM4B1ce2i23VmxCjz Fi5mW29HvHVXAkvtS5nKyD6j+azi/T4qef/wo+AVdfovuIirrcYaqHA6mrtI07Ivf9ABGhiC rQ9rgoWFpYOv7+RMbz+jtUT8irSHI2s1a0xVuKMpXDQy3X8ETtTPQIwRgQXg8C5hd9cgKxRf SF+ELDt3J+2PuwQ8M3Bi+86mOJ83Pu5i+psE0N7lAvkZ/kxHnv6E3yOXZKSoLySd8l0N+ktt AXYpyUpA2D/Ow4KC2gRGM5tDXgzs/+Q7VmyMvrpFqi6O55tTMjlx8YmG7Bybfp6LEv8dGNbR L1ExLNuqeaitg0KDPbZ8YYKrdboGV5idfWMDNCGjQvp3erCtVefhR0Z2YZCvMnH5QT3zCbix sa2UppNHyaatQn5BrqekH1JlufcA34Eejyv5gCOuNXeaY5Z6HYXv6xwJrG77oaZaCPLsPVyj cNX98DKVqRvVZycUqu0h2KzkVkbbacgaOdvmW6i87psKekEcoXjCtEwL4p8QEXaRVCPUX1h1 NKoMU//ZiyuIK8qG5+6LLHrzoljMjXNOScL4ktRLzdDFU69LkMvtcL28nG8nJ8mK3Y6xv+3H aGpBW3Czbw49p0C+aUkrN+iYVMJi+BKJYl2KSfwdUGCmV+IWqCQcJWuxAl8GENO9O9TMyXGL L1ZJlKL9eJv6YUCiKgqlgb5h2q9zQtZ9KExcNtmhi9fCZjJSFbcRFTl9I4mdUO/KFLnall/i ZUYOUmWRYh0JaybC5GPdb3oICoGRrnL3aXZ8S/K6QcWOQouk3B4sfG X-IronPort-AV: E=Sophos;i="5.58,493,1544486400"; d="scan'208";a="80850936" From: Paul Durrant To: Date: Mon, 18 Mar 2019 11:20:53 +0000 Message-ID: <20190318112059.21910-6-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190318112059.21910-1-paul.durrant@citrix.com> References: <20190318112059.21910-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v8 05/11] viridian: extend init/deinit hooks into synic and time modules 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: Andrew Cooper , Paul Durrant , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch simply adds domain and vcpu init/deinit hooks into the synic and time modules and wires them into viridian_[domain|vcpu]_[init|deinit](). Only one of the hooks is currently needed (to unmap the 'VP Assist' page) but subsequent patches will make use of the others. NOTE: To perform the unmap of the VP Assist page, viridian_unmap_guest_page() is now directly called in the new viridian_synic_vcpu_deinit() function (which is safe even if is_viridian_vcpu() evaluates to false). This replaces the slightly hacky mechanism of faking a zero write to the HV_X64_MSR_VP_ASSIST_PAGE MSR in viridian_cpu_deinit(). Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich Reviewed-by: Wei Liu --- Cc: Andrew Cooper Cc: "Roger Pau Monné" v4: - Constify vcpu and domain pointers v2: - Pay attention to sync and time init hook return values --- xen/arch/x86/hvm/viridian/private.h | 12 +++++++++ xen/arch/x86/hvm/viridian/synic.c | 19 ++++++++++++++ xen/arch/x86/hvm/viridian/time.c | 18 ++++++++++++++ xen/arch/x86/hvm/viridian/viridian.c | 37 ++++++++++++++++++++++++++-- 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/private.h b/xen/arch/x86/hvm/viridian/private.h index 46174f48cd..8c029f62c6 100644 --- a/xen/arch/x86/hvm/viridian/private.h +++ b/xen/arch/x86/hvm/viridian/private.h @@ -74,6 +74,12 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val); int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val); +int viridian_synic_vcpu_init(const struct vcpu *v); +int viridian_synic_domain_init(const struct domain *d); + +void viridian_synic_vcpu_deinit(const struct vcpu *v); +void viridian_synic_domain_deinit(const struct domain *d); + void viridian_synic_save_vcpu_ctxt(const struct vcpu *v, struct hvm_viridian_vcpu_context *ctxt); void viridian_synic_load_vcpu_ctxt( @@ -82,6 +88,12 @@ void viridian_synic_load_vcpu_ctxt( int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val); int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val); +int viridian_time_vcpu_init(const struct vcpu *v); +int viridian_time_domain_init(const struct domain *d); + +void viridian_time_vcpu_deinit(const struct vcpu *v); +void viridian_time_domain_deinit(const struct domain *d); + void viridian_time_save_domain_ctxt( const struct domain *d, struct hvm_viridian_domain_context *ctxt); void viridian_time_load_domain_ctxt( diff --git a/xen/arch/x86/hvm/viridian/synic.c b/xen/arch/x86/hvm/viridian/synic.c index 05d971b365..4b00dbe1b3 100644 --- a/xen/arch/x86/hvm/viridian/synic.c +++ b/xen/arch/x86/hvm/viridian/synic.c @@ -146,6 +146,25 @@ int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val) return X86EMUL_OKAY; } +int viridian_synic_vcpu_init(const struct vcpu *v) +{ + return 0; +} + +int viridian_synic_domain_init(const struct domain *d) +{ + return 0; +} + +void viridian_synic_vcpu_deinit(const struct vcpu *v) +{ + viridian_unmap_guest_page(&v->arch.hvm.viridian->vp_assist); +} + +void viridian_synic_domain_deinit(const struct domain *d) +{ +} + void viridian_synic_save_vcpu_ctxt(const struct vcpu *v, struct hvm_viridian_vcpu_context *ctxt) { diff --git a/xen/arch/x86/hvm/viridian/time.c b/xen/arch/x86/hvm/viridian/time.c index 909a3fb9e3..48aca7e0ab 100644 --- a/xen/arch/x86/hvm/viridian/time.c +++ b/xen/arch/x86/hvm/viridian/time.c @@ -215,6 +215,24 @@ int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val) return X86EMUL_OKAY; } +int viridian_time_vcpu_init(const struct vcpu *v) +{ + return 0; +} + +int viridian_time_domain_init(const struct domain *d) +{ + return 0; +} + +void viridian_time_vcpu_deinit(const struct vcpu *v) +{ +} + +void viridian_time_domain_deinit(const struct domain *d) +{ +} + void viridian_time_save_domain_ctxt( const struct domain *d, struct hvm_viridian_domain_context *ctxt) { diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 1a20d68aaf..f9a509d918 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -418,22 +418,52 @@ int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val) int viridian_vcpu_init(struct vcpu *v) { + int rc; + ASSERT(!v->arch.hvm.viridian); v->arch.hvm.viridian = xzalloc(struct viridian_vcpu); if ( !v->arch.hvm.viridian ) return -ENOMEM; + rc = viridian_synic_vcpu_init(v); + if ( rc ) + goto fail; + + rc = viridian_time_vcpu_init(v); + if ( rc ) + goto fail; + return 0; + + fail: + viridian_vcpu_deinit(v); + + return rc; } int viridian_domain_init(struct domain *d) { + int rc; + ASSERT(!d->arch.hvm.viridian); d->arch.hvm.viridian = xzalloc(struct viridian_domain); if ( !d->arch.hvm.viridian ) return -ENOMEM; + rc = viridian_synic_domain_init(d); + if ( rc ) + goto fail; + + rc = viridian_time_domain_init(d); + if ( rc ) + goto fail; + return 0; + + fail: + viridian_domain_deinit(d); + + return rc; } void viridian_vcpu_deinit(struct vcpu *v) @@ -441,8 +471,8 @@ void viridian_vcpu_deinit(struct vcpu *v) if ( !v->arch.hvm.viridian ) return; - if ( is_viridian_vcpu(v) ) - viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0); + viridian_time_vcpu_deinit(v); + viridian_synic_vcpu_deinit(v); XFREE(v->arch.hvm.viridian); } @@ -457,6 +487,9 @@ void viridian_domain_deinit(struct domain *d) if ( !d->arch.hvm.viridian ) return; + viridian_time_domain_deinit(d); + viridian_synic_domain_deinit(d); + XFREE(d->arch.hvm.viridian); }