From patchwork Tue Feb 7 09:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xenia Ragiadakou X-Patchwork-Id: 13131282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED0DBC636CD for ; Tue, 7 Feb 2023 09:44:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.490966.759879 (Exim 4.92) (envelope-from ) id 1pPKWC-0000iT-Qw; Tue, 07 Feb 2023 09:44:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 490966.759879; Tue, 07 Feb 2023 09:44:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pPKWC-0000iM-N5; Tue, 07 Feb 2023 09:44:04 +0000 Received: by outflank-mailman (input) for mailman id 490966; Tue, 07 Feb 2023 09:44:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pPKWA-0000iE-N0 for xen-devel@lists.xenproject.org; Tue, 07 Feb 2023 09:44:02 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f26e712e-a6cb-11ed-93b5-47a8fe42b414; Tue, 07 Feb 2023 10:43:59 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id eq11so14636088edb.6 for ; Tue, 07 Feb 2023 01:43:59 -0800 (PST) Received: from uni.router.wind (adsl-89.109.242.226.tellas.gr. [109.242.226.89]) by smtp.googlemail.com with ESMTPSA id es26-20020a056402381a00b00488117821ffsm6193880edb.31.2023.02.07.01.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 01:43:58 -0800 (PST) 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: f26e712e-a6cb-11ed-93b5-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3oDDsC41sLF+atuCMTLto1TqTReol5tcMlO6ePzFZbY=; b=iqtCiOzMXZD3dsv3XJYGyp1ngC/kiRrsR2sHW//eEEL7wCJElqngwxI4Xa18/1Y1Yt NLnQ9RHMvAXzd2okecxJWIfvAxUOFSH3ddHWpGJ/YAO2vbUH2yGLSvzY3xM1NJgTdvqQ ZCpjvKvypQtzD+pc7s0lJxVNDqB0s/cxLEDDvkugnCBxKEMM+SQ/ioBpqNox1D/CzgQO feiz3J1tLu2kIcarA9HpwC3ZRpUqYeNcd/5OPJCyo94XjCcP3MP4nbqBC4Bt2kSEz+ul 7CET6WMEEuMdMvR2/FNimotTdpg/hgOOKANDLo8RglPzG1TLxZi/H2nz4mGbu2E4qt4g YfYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3oDDsC41sLF+atuCMTLto1TqTReol5tcMlO6ePzFZbY=; b=chSvpbMlSbdzfnjhnM2xLDg2XDf/MYUC6gjJhB+8fpni7eEr5A/a8mF1aBJ8c3/yG+ m/OC0FQ6vt8DDNHKFNlNZKGE94AnBl0l0/3tu9vLKl0twnGKN89nnE8B0CJvefLQ7yw4 llk38tFnTOXX/TwfW8qQDQnk24Nh8CjSjHky/xjg2kjCAfj3cTu2C3iBSJZskteJCXkm aYxttMD9J8Ve8anx5IcKDYlQOD1GETbrLdmCE5HjkTLCJ+Nqnny//bsQcbl5sawix8AT adQDcn8fhv1sWK0Sb7/JlPczyFTqK2z/lGqCSBumOrq7TLaT/fcV7NFFydbrX5x33bJI KoTw== X-Gm-Message-State: AO0yUKUWVacPVuVQl3AB5Hjywc9M0YxL0mYV3yno0fjxXSj1AYNFrH/u 1Du3rBzwjkXrjUtT4iovHP6w1qgwoOc= X-Google-Smtp-Source: AK7set+99kLyLrbIod12hxN1P7gPbKejSBK/XshU+Jnqw2rWu/Hz0edkV49zsX/b8aqKJh/PCbNFqA== X-Received: by 2002:a50:a415:0:b0:4aa:a53f:a041 with SMTP id u21-20020a50a415000000b004aaa53fa041mr2749916edb.34.1675763038399; Tue, 07 Feb 2023 01:43:58 -0800 (PST) From: Xenia Ragiadakou To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian Subject: [PATCH v2] x86/vlapic: call vmx_vlapic_msr_changed through an hvm_function callback Date: Tue, 7 Feb 2023 11:43:47 +0200 Message-Id: <20230207094347.1059376-1-burzalodowa@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 APIC virtualization support is currently implemented only for Intel VT-x. To aid future work on separating AMD-V from Intel VT-x code, instead of calling directly vmx_vlapic_msr_changed() from common hvm code, add a stub to the hvm_function_table, named update_vlapic_mode, and create a wrapper function, called hvm_update_vlapic_mode(), to be used by common hvm code. After the change above, do not include header asm/hvm/vmx/vmx.h as it is not required anymore and resolve subsequent build errors for implicit declaration of functions ‘TRACE_2_LONG_3D’ and ‘TRC_PAR_LONG’ by including missing asm/hvm/trace.h header. No functional change intended. Signed-off-by: Xenia Ragiadakou --- Changes in v2: - rename set_virtual_apic_mode to update_vlapic_mode, suggested by Andrew - in hvm_update_vlapic_mode(), call the stub only if available, otherwise a BUG() will be triggered every time an svm guest writes the APIC_BASE MSR, bug reported by Andrew - initialize the stub for vmx unconditionally to maintain current behavior since no functional change is intended, bug reported by Andrew (here, I decided to place the initialization in start_vmx to be closer to the initializations of the other stubs that are relevant to apic virtualization) xen/arch/x86/hvm/vlapic.c | 6 +++--- xen/arch/x86/hvm/vmx/vmx.c | 2 ++ xen/arch/x86/include/asm/hvm/hvm.h | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index eb32f12e2d..dc93b5e930 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -37,8 +37,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -1165,7 +1165,7 @@ int guest_wrmsr_apic_base(struct vcpu *v, uint64_t value) if ( vlapic_x2apic_mode(vlapic) ) set_x2apic_id(vlapic); - vmx_vlapic_msr_changed(vlapic_vcpu(vlapic)); + hvm_update_vlapic_mode(vlapic_vcpu(vlapic)); HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "apic base msr is 0x%016"PRIx64, vlapic->hw.apic_base_msr); @@ -1561,7 +1561,7 @@ static int cf_check lapic_load_hidden(struct domain *d, hvm_domain_context_t *h) unlikely(vlapic_x2apic_mode(s)) ) return -EINVAL; - vmx_vlapic_msr_changed(v); + hvm_update_vlapic_mode(v); return 0; } diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 270bc98195..dd57aa7623 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3011,6 +3011,8 @@ const struct hvm_function_table * __init start_vmx(void) setup_ept_dump(); } + vmx_function_table.update_vlapic_mode = vmx_vlapic_msr_changed; + if ( cpu_has_vmx_virtual_intr_delivery ) { vmx_function_table.update_eoi_exit_bitmap = vmx_update_eoi_exit_bitmap; diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h index 80e4565bd2..43d3fc2498 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -217,6 +217,7 @@ struct hvm_function_table { void (*handle_eoi)(uint8_t vector, int isr); int (*pi_update_irte)(const struct vcpu *v, const struct pirq *pirq, uint8_t gvec); + void (*update_vlapic_mode)(struct vcpu *v); /*Walk nested p2m */ int (*nhvm_hap_walk_L1_p2m)(struct vcpu *v, paddr_t L2_gpa, @@ -786,6 +787,12 @@ static inline int hvm_pi_update_irte(const struct vcpu *v, return alternative_call(hvm_funcs.pi_update_irte, v, pirq, gvec); } +static inline void hvm_update_vlapic_mode(struct vcpu *v) +{ + if ( hvm_funcs.update_vlapic_mode ) + alternative_vcall(hvm_funcs.update_vlapic_mode, v); +} + #else /* CONFIG_HVM */ #define hvm_enabled false