From nobody Sat May 18 21:45:33 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; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1675763085; cv=none; d=zohomail.com; s=zohoarc; b=i9NluVmr+G8ZU7JX7d8xg0yp06FY8+O6/McfpGWib1lwmJmMTNMgHM+W12XBpa7B+xKufXNcZU8wu4iEHDw5xH4n+QXIu02CyAKclyocz/gAhM42lD8fk7tgIr9tyWqCcKWoDOrVYz/J96TxOIJFysOcEeiWaScxih0YRCHjnzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675763085; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3oDDsC41sLF+atuCMTLto1TqTReol5tcMlO6ePzFZbY=; b=iN3G+3hTBmDC3iJ+2kHA4kjwQOB56+a9xtlLodp62iB7zH56LDuG+Mgvlh9Gz7SsdHsH2+hyia6fCylWl/KFBor7FymMycXhiUe/X+U4QvjvUDpCDBJq0ldXjtuUM4aUI8t4Q7wBVFr1aFFNjLalNdY0uKLRSCk3vDoKYXIKn28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1675763085555240.26441339094515; Tue, 7 Feb 2023 01:44:45 -0800 (PST) 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 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-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: 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=20Pau=20Monn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1675763100742100001 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 =E2=80=98TRACE_2_LONG_3D=E2=80=99 and =E2=80=98TRC= _PAR_LONG=E2=80=99 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 virtualiza= tion) 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 va= lue) if ( vlapic_x2apic_mode(vlapic) ) set_x2apic_id(vlapic); =20 - vmx_vlapic_msr_changed(vlapic_vcpu(vlapic)); + hvm_update_vlapic_mode(vlapic_vcpu(vlapic)); =20 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; =20 - vmx_vlapic_msr_changed(v); + hvm_update_vlapic_mode(v); =20 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(vo= id) setup_ept_dump(); } =20 + vmx_function_table.update_vlapic_mode =3D vmx_vlapic_msr_changed; + if ( cpu_has_vmx_virtual_intr_delivery ) { vmx_function_table.update_eoi_exit_bitmap =3D 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); =20 /*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); } =20 +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 */ =20 #define hvm_enabled false --=20 2.37.2