From patchwork Thu Mar 20 10:38:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 14023684 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 8FD61C28B30 for ; Thu, 20 Mar 2025 10:38:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.921714.1325484 (Exim 4.92) (envelope-from ) id 1tvDIU-0003Z0-6Y; Thu, 20 Mar 2025 10:38:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 921714.1325484; Thu, 20 Mar 2025 10:38:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tvDIU-0003Yt-43; Thu, 20 Mar 2025 10:38:46 +0000 Received: by outflank-mailman (input) for mailman id 921714; Thu, 20 Mar 2025 10:38:45 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tvDIT-0003Yn-Ak for xen-devel@lists.xenproject.org; Thu, 20 Mar 2025 10:38:45 +0000 Received: from fforwardh-b4-smtp.messagingengine.com (fforwardh-b4-smtp.messagingengine.com [202.12.124.199]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7e7bd635-0577-11f0-9ea0-5ba50f476ded; Thu, 20 Mar 2025 11:38:43 +0100 (CET) Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfforwardh.stl.internal (Postfix) with ESMTP id 6DE461740212; Thu, 20 Mar 2025 06:38:42 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-08.internal (MEProxy); Thu, 20 Mar 2025 06:38:42 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 20 Mar 2025 06:38:41 -0400 (EDT) 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: 7e7bd635-0577-11f0-9ea0-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1742467122; x=1742553522; bh=H CSqtTK0OLa/KDGOXFDTBAHtZN66AA0RE3rsvMWIX/c=; b=IHtiK1r2HHhb0jq6C iof1p/ftdVi3fr6SO7gVFnCeEkFQxqkpUPmNrx8CHzpZdWOow3oeP1dt7yjjj9rA nVJvHoUpKEmteVFGbLMlaO+cBCh1ucQ6kmZDju4KhfNEThkm9g96KCAZHpW4LLmp VewvhhA8TKnMZU2xhfWM4yMxlixOnhGgXtOdJ6Wc6dj9/eFmUsDzHb0fF8mGaEl9 cjsftJ8UKiK5wp7UgTt44hxsTxAi2q9VSsc+2IwKrqC0pQLj/8mSU0cfCJx5Rv7G K6qXgaHp+Y8xODEIMsn1AtwxZIt5opu7IYXRqGeuw+uyIsWryoynT+CPfoSzvlfT F0aMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeektddtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepufgvrhhgihihucfmihgsrhhikhcuoefuvghrghhihigpmfhisghrih hksegvphgrmhdrtghomheqnecuggftrfgrthhtvghrnheptdejgeegvdffkeekleefueev gfduheevkedvhfdvkeeludehleegheeivedugfejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepshgrkhhisgesuggrrhhkshhtrghrrdhsihht vgdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepgi gvnhdquggvvhgvlheslhhishhtshdrgigvnhhprhhojhgvtghtrdhorhhgpdhrtghpthht ohepshgvrhhgihihpghkihgsrhhikhesvghprghmrdgtohhmpdhrtghpthhtohepjhgsvg hulhhitghhsehsuhhsvgdrtghomhdprhgtphhtthhopegrnhgurhgvfidrtghoohhpvghr feestghithhrihigrdgtohhmpdhrtghpthhtoheprhhoghgvrhdrphgruhestghithhrih igrdgtohhmpdhrtghpthhtohepshhsthgrsggvlhhlihhniheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i5fffb4f7:Fastmail From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [XEN PATCH v1 3/4] x86:hvm: guard calls to nestedhvm routines Date: Thu, 20 Mar 2025 12:38:39 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Check whether nested HVM is enabled for domain before calling nestedhvm_vcpu_*() and other not already guarded nestedhvm functions. Signed-off-by: Sergiy Kibrik --- xen/arch/x86/hvm/hvm.c | 6 ++++-- xen/arch/x86/hvm/svm/asid.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 2f31180b6f..5abbf7029d 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1658,7 +1658,8 @@ int hvm_vcpu_initialise(struct vcpu *v) return 0; fail6: - nestedhvm_vcpu_destroy(v); + if ( nestedhvm_enabled(d) ) + nestedhvm_vcpu_destroy(v); fail5: free_compat_arg_xlat(v); fail4: @@ -1682,7 +1683,8 @@ void hvm_vcpu_destroy(struct vcpu *v) if ( hvm_altp2m_supported() ) altp2m_vcpu_destroy(v); - nestedhvm_vcpu_destroy(v); + if ( nestedhvm_enabled(v->domain) ) + nestedhvm_vcpu_destroy(v); free_compat_arg_xlat(v); diff --git a/xen/arch/x86/hvm/svm/asid.c b/xen/arch/x86/hvm/svm/asid.c index 7977a8e86b..05c8971714 100644 --- a/xen/arch/x86/hvm/svm/asid.c +++ b/xen/arch/x86/hvm/svm/asid.c @@ -30,7 +30,7 @@ void svm_asid_handle_vmrun(void) struct vcpu *curr = current; struct vmcb_struct *vmcb = curr->arch.hvm.svm.vmcb; struct hvm_vcpu_asid *p_asid = - nestedhvm_vcpu_in_guestmode(curr) + ( nestedhvm_enabled(curr->domain) && nestedhvm_vcpu_in_guestmode(curr) ) ? &vcpu_nestedhvm(curr).nv_n2asid : &curr->arch.hvm.n1asid; bool need_flush = hvm_asid_handle_vmenter(p_asid); diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 09ac138691..d7d91427fd 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -795,7 +795,7 @@ static void cf_check svm_set_tsc_offset(struct vcpu *v, u64 offset, u64 at_tsc) n1vmcb = vcpu_nestedhvm(v).nv_n1vmcx; n2vmcb = vcpu_nestedhvm(v).nv_n2vmcx; - if ( nestedhvm_vcpu_in_guestmode(v) ) + if ( nestedhvm_enabled(d) && nestedhvm_vcpu_in_guestmode(v) ) { n2_tsc_offset = vmcb_get_tsc_offset(n2vmcb) - vmcb_get_tsc_offset(n1vmcb); @@ -2172,7 +2172,7 @@ svm_vmexit_do_vmrun(struct cpu_user_regs *regs, return; } - if ( !nestedsvm_vmcb_map(v, vmcbaddr) ) + if ( nestedhvm_enabled(v->domain) && !nestedsvm_vmcb_map(v, vmcbaddr) ) { gdprintk(XENLOG_ERR, "VMRUN: mapping vmcb failed, injecting #GP\n"); hvm_inject_hw_exception(X86_EXC_GP, 0); @@ -2190,7 +2190,7 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t vmcbaddr) struct page_info *page; struct nestedvcpu *nv = &vcpu_nestedhvm(v); - if ( !nestedsvm_vmcb_map(v, vmcbaddr) ) + if ( nestedhvm_enabled(v->domain) && !nestedsvm_vmcb_map(v, vmcbaddr) ) return NULL; /* Need to translate L1-GPA to MPA */