From patchwork Thu Oct 10 18:23:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13831140 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 CB00FD2444F for ; Thu, 10 Oct 2024 21:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y8lbNB/D/08aZFhDXGcnGhmU21hzz7mkS1sZcBdn5JE=; b=QL942kMa1Vk+ZI euWPsjNDwwPQ61KOAmUKSucoVCPvxtKzdKa6GxwdGO7UOk6IwoAmopabhOnTvsU5z+KCR9qfkV4Tt /DudzzW9uy6u1ulejhIeTLL1rzEsO0LEke5G0VRnMjV8hnaBDSIxQg9eqQn3d2rzWTU5TQxdy4y0B ZCZ0qY2ybfBrxXYKEAR7Zh1Q3G0dhDSA9kYd/+tn+BiEyNPO1VOScyR9dSkP6BaDitltvRd2wEm/O 1EZRQl/Ewi7Uf4hVM2qwKb+O7K4uS+UTDrazCuDvFneIKwnLtmpTw5aPg/CUXyrv2ZYPmBiKyMLlw O/Ms6U4Jo8F/JIJGibjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sz0Hm-0000000ELju-35yC; Thu, 10 Oct 2024 21:01:26 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxr4-0000000DqEd-0vzh for linux-riscv@lists.infradead.org; Thu, 10 Oct 2024 18:25:45 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-20b8bf5d09aso15596605ad.3 for ; Thu, 10 Oct 2024 11:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584741; x=1729189541; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:from:to:cc:subject:date :message-id:reply-to; bh=UxQVf2h1B1ZgTBX9bfQB+O4u0WEdBy2E8BNaXtNQtEc=; b=cHCxW9OvZGr1yBq6iVLuom+7EfZOc2EiXI7ygoBxdL22tnMY4Rj8QktPQoH9Zvi7rY qyOcJSNL56bk8CzNNK18Qv8diJFnIWO5chCmwCAkSlGhhfKd2k9jLijI97GeNIR3JSb5 KDlg64BqicYf/HRueE0w1SDL7nCmZA4NdT6OUJajraX/1Si4XFYP/vdmBM232nIzJ/Vg 6B+M47Y5OHDhvCmF/DpY/dTExiOIuOVDanc++9fpYZHB1avwuohYC45mdc78wc8C+odL PzeJTkRQxew5bIRj0u4rP3K84+JAXK/nVdKxY+zRIlu3rMcO5RHJD0zj3yKwqUl7by/Z hxkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584741; x=1729189541; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=UxQVf2h1B1ZgTBX9bfQB+O4u0WEdBy2E8BNaXtNQtEc=; b=GoAMQejNn/zySbrOCD7bLEfZCKAcqt2bDfxYBT+GwmzozW+C0iG2sitMlWovr844MG Z1GUoInRg42y/e9sXvs6Kef1Y2kC/3/05tctNcPPxfWdRLg40kOOe+P64xvfhYV3e4cY GZIcjLyymC2uGyHUe3SlIXzsUTgi6f31za/d/ePTothlJ3zlu6NHmZloCLoJm2wXohFe x8YkH34JhDvGymwUqpIeeW5T1DkzfQ4uicudI3zDSOWyQAaRnTFMgCJAWAqcAs1Tou8r 4+yE6jASuvk56o/pCJnxHBosN3ni9ltO/2yTYQ3cwH8Og2ZEmHYutsFy9SvRlQfGEij1 BDjQ== X-Forwarded-Encrypted: i=1; AJvYcCXUNgjNWmAEcfiitz+csOvdOg50wjZw2+ndb9rSUiMWVVj4FEi3vsFa3oxNcpxzluy7dlzHjGxVSV6QRw==@lists.infradead.org X-Gm-Message-State: AOJu0Yy/wxa2Q59bAqDaizGicQjtc3pl52ofAkwNoQuS4gFc0Qa1/lQ3 HOdiU3ZxfRelze9PUnen+VsMTom5mVZLHt51298bKf1Z55O7pWqEb2C+v0byYb5GG2a5FSPdh4o pzQ== X-Google-Smtp-Source: AGHT+IFSsaj7YGs0xXvL7KvHpo4OHZS23TfW901WnGn1dNBw4UEq8HUBbyPz7tDSJuBwPv672jv+MkN6+4M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:903:2349:b0:20b:9365:e6e4 with SMTP id d9443c01a7336-20c63782bdcmr1094885ad.9.1728584740809; Thu, 10 Oct 2024 11:25:40 -0700 (PDT) Date: Thu, 10 Oct 2024 11:23:25 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-24-seanjc@google.com> Subject: [PATCH v13 23/85] KVM: nVMX: Rely on kvm_vcpu_unmap() to track validity of eVMCS mapping From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, " =?utf-8?q?Alex_Benn=C3=A9e?= " , Yan Zhao , David Matlack , David Stevens , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_112542_369474_37E85BEE X-CRM114-Status: UNSURE ( 9.67 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Remove the explicit evmptr12 validity check when deciding whether or not to unmap the eVMCS pointer, and instead rely on kvm_vcpu_unmap() to play nice with a NULL map->hva, i.e. to do nothing if the map is invalid. Note, vmx->nested.hv_evmcs_map is zero-allocated along with the rest of vcpu_vmx, i.e. the map starts out invalid/NULL. Tested-by: Alex Bennée Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index a8e7bc04d9bf..e94a25373a59 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -231,11 +231,8 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu) struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); - if (nested_vmx_is_evmptr12_valid(vmx)) { - kvm_vcpu_unmap(vcpu, &vmx->nested.hv_evmcs_map, true); - vmx->nested.hv_evmcs = NULL; - } - + kvm_vcpu_unmap(vcpu, &vmx->nested.hv_evmcs_map, true); + vmx->nested.hv_evmcs = NULL; vmx->nested.hv_evmcs_vmptr = EVMPTR_INVALID; if (hv_vcpu) {