From patchwork Fri Jul 26 23:51:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 1965517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fQ8i26Kg; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=sDvOePFA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WW4yM6hPvz1yY9 for ; Sat, 27 Jul 2024 10:20:11 +1000 (AEST) 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=TBtSvABbl8AdS0y8l18lppmGQnhVwltNgdnYStCHAXc=; b=fQ8i26KgoyBoEs MDabXD6G/a5U2d4TD0Za5dwpCw9WQFmlZ+228odWvBmxB2C4xkyYuSM3Oyup1TiCI38Of0D5JA97g 9eJyVeW/OWbYIKv6TNROT5X5S3QBYHjFL3nrADIM06v0Ygv+ZOJ5QliW984hUZUpM9LzdteJf4wXC Veza2JQIK1af1nnOhZb8IbXhaYVdoDA7gjiT9j9pDThN49+HA5ZdJJCUEfL0S+bglH+pCix+IMDrw 4au/xtvYqj0Um6QIP3rNlN62kRB0cywLz1KuC5NE7HhdGcNz95ukDqM5UnGlvmoont6BfsnwqWw6E x2wge5hUXx3hhDf2+2kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVAQ-00000005dnm-2wR2; Sat, 27 Jul 2024 00:20:10 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUlS-00000005QX3-0qk8 for kvm-riscv@lists.infradead.org; Fri, 26 Jul 2024 23:54:28 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-70d19a4137dso1423326b3a.1 for ; Fri, 26 Jul 2024 16:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038061; x=1722642861; darn=lists.infradead.org; h=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=495sZLd3sCBTMIrtoKFKEohUXAwQ30LA4hbLQQBllaM=; b=sDvOePFAvFgC8uzSLk4jiOO2dWqP7lcelY38TFcY8u3eC3K0BWfeJXcSmrJAelD/ps scCgnPTVhWfXLxOE9Hwb5N1TA/J3gkKhceTw7e0/HfcsLcbhGNn4Sul3t8IfH2G1Uq69 WmK2EqQLL9KfYwSi4MxTSBNWL+jpuuE9so1a5EAokko1O/4zLb6L15Ro2TskUbUN8TMh npGUP8ESxShD3krMjJp2X7IS+69JtgGK3KgCzhXmw2eMM1OIcKtEsiMGuszpz3qQmwlg eqTZBipk7LWfJj8tNWknQkJzqdJzwX2OEJI7lO1BbprFFQwmqWRSackU2zvIoPw/XIFg 63/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038061; x=1722642861; h=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=495sZLd3sCBTMIrtoKFKEohUXAwQ30LA4hbLQQBllaM=; b=rY6SseJjVraxILBdtIoYjqnKF0aJSIuMF20dD3ILHVO8FlRhEXFn8rUCcEC/MJmDKS 69IWA1uArgah18+1JsVAMtxuuR8EKxnW5jXFYhy/YFnbxoA+HWzYH5ykfOsiBgKQu8RK kBHoETWQEZ36GUV44DFi1EVErWZPp3jaAv9uCLhgnsjCZ5GreLWQc6DK/BmJQE0Yp8eh Pi9Znw+vgBUNA+nISOnjgmRDKziNkaMBr1yf8bkyKnuPK4+4z3rEXzU/DAwnH9MUpULm bky4Tf9XNv4z6RIhO5ajlENsyTf6ORZVNtSlUTT4piSG7ndoy3YCnpg6HcyBPKduHdlJ XyTw== X-Forwarded-Encrypted: i=1; AJvYcCUnugx3xjlB6LMdpghD7ZQL2PERVsGjP/ivLyoWTAfIBeymU1H8djZwmvlOaup7idHwSPAiHkGeeGoKZ5dwyN+22M7WweZVOcgw/baYKg== X-Gm-Message-State: AOJu0YyhGx9NUxaRdiw/9TXyLxEGyVyqTlL8LjIJ8JgSPXA/MnzWjb35 ohHyPq1v7rtLnW+H4qw5wQklTz8a0fzWbVh5KHuX6f9KHxuu90vp6jbWSWjXtMms1wDP8ROVqS5 bxQ== X-Google-Smtp-Source: AGHT+IEX18wdLlkp+2aMf2anoWcNTpOtSr1c0ECGrHfjhmBCNZQh1f0vS16HR3FEGEctU7qtPLZbGkdGSSc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:6f1c:b0:70d:138a:bee8 with SMTP id d2e1a72fcca58-70ece533146mr8925b3a.0.1722038060383; Fri, 26 Jul 2024 16:54:20 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:59 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-51-seanjc@google.com> Subject: [PATCH v12 50/84] KVM: VMX: Use __kvm_faultin_page() to get APIC access page/pfn 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, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165422_575870_614738B3 X-CRM114-Status: GOOD ( 14.99 ) X-Spam-Score: -9.5 (---------) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Use __kvm_faultin_page() get the APIC access page so that KVM can precisely release the refcounted page, i.e. to remove yet another user of kvm_pfn_to_refcounted_page(). While the path isn't handling [...] Content analysis details: (-9.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:44a listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM welcome-list 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: kvm-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: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use __kvm_faultin_page() get the APIC access page so that KVM can precisely release the refcounted page, i.e. to remove yet another user of kvm_pfn_to_refcounted_page(). While the path isn't handling a guest page fault, the semantics are effectively the same; KVM just happens to be mapping the pfn into a VMCS field instead of a secondary MMU. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 30032585f7dc..b109bd282a52 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6786,8 +6786,10 @@ void vmx_set_apic_access_page_addr(struct kvm_vcpu *vcpu) struct kvm *kvm = vcpu->kvm; struct kvm_memslots *slots = kvm_memslots(kvm); struct kvm_memory_slot *slot; + struct page *refcounted_page; unsigned long mmu_seq; kvm_pfn_t pfn; + bool ign; /* Defer reload until vmcs01 is the current VMCS. */ if (is_guest_mode(vcpu)) { @@ -6823,7 +6825,7 @@ void vmx_set_apic_access_page_addr(struct kvm_vcpu *vcpu) * controls the APIC-access page memslot, and only deletes the memslot * if APICv is permanently inhibited, i.e. the memslot won't reappear. */ - pfn = gfn_to_pfn_memslot(slot, gfn); + pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, &ign, &refcounted_page); if (is_error_noslot_pfn(pfn)) return; @@ -6834,10 +6836,13 @@ void vmx_set_apic_access_page_addr(struct kvm_vcpu *vcpu) vmcs_write64(APIC_ACCESS_ADDR, pfn_to_hpa(pfn)); /* - * Do not pin apic access page in memory, the MMU notifier - * will call us again if it is migrated or swapped out. + * Do not pin the APIC access page in memory so that it can be freely + * migrated, the MMU notifier will call us again if it is migrated or + * swapped out. KVM backs the memslot with anonymous memory, the pfn + * should always point at a refcounted page (if the pfn is valid). */ - kvm_release_pfn_clean(pfn); + if (!WARN_ON_ONCE(!refcounted_page)) + kvm_release_page_clean(refcounted_page); /* * No need for a manual TLB flush at this point, KVM has already done a