From nobody Sun Feb 8 23:25:54 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A21AC77B7A for ; Fri, 2 Jun 2023 01:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233317AbjFBBPg (ORCPT ); Thu, 1 Jun 2023 21:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233277AbjFBBP2 (ORCPT ); Thu, 1 Jun 2023 21:15:28 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C6A180 for ; Thu, 1 Jun 2023 18:15:25 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1b02cd4b829so10253765ad.1 for ; Thu, 01 Jun 2023 18:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685668524; x=1688260524; 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=QZyedvEO4VqsOzfsB28/8dG+6mqt6s6B82uH8fSmwq8=; b=j6CUWl3a3FC0QTS2njOofjKDlfQDmtDJaHSEouWHPCamUcCop7S0W1f56KyCl2MYCz DstIw0CLzrHL+bqnN/88nI8F9zPPVgGPmafeNxh7uQExuP98qW5YpkuGO7fz/JN016ot ONsEzzryAmfo9bNAIsMV34WY7aScQG1sHNQQqUac+jFmNo0cLvSgRWIGQnE1Figc4LgJ TMq/TnB4/PGyJaxLGEgGG93zTw8uRjt4FOxjcHttzl6sUqQzSHIqeSP3ip5fqROjFUlK 1n4cxYxyeLfHcXrK9mKx7vMZUAHJl1sv0YgnAkvwpveJ12L1s6NLxOR3dH5ccmW4qY0f iT9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685668524; x=1688260524; 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=QZyedvEO4VqsOzfsB28/8dG+6mqt6s6B82uH8fSmwq8=; b=S0DehrrQbOSvNmKArdefLawL6BSJsG/1eOwwHcpVxDZjdAYHKJPnVDSvHtEbcDUxtV eDUPmQqTfU1eezmFceYfZemqtf7Kw6btM0yJxQqYHVXGbiggp7VnLBxbVXUhLQjZQkfy 3ageIqouRDHXtFXwbOhE9VlvjpGMMjdIOoWN4pWxviM3/5/tUIG8VI2mM97wnviD0XCQ 5cEELg/I6Nl8ML+yRfDTvpNcaPzxJiv7OuXU+EiqNCtnERZiKSH58UX3RqOqYY0OlJV+ wfIZPTYNGfo7VRqLs5ElWCpRn98b8djzzVgUERujyfhFpvD5GIPfUm1ReTIVWJhPKnr+ tLQg== X-Gm-Message-State: AC+VfDxlc1wuUDIZpI5WwGM4HLVR1OsG89U4eS43hGNrf0U27/doM0ee 1/4BU2MUnnGfxt5gjeC1IhvBZqvm0Ok= X-Google-Smtp-Source: ACHHUZ5UDykUofDWptpYeKLYKUT4lJwC6hmS67vt4RZ2J9Vlllz6wQ7TTKu52RE+bGzNl7D3clsor4HUmDQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:fb85:b0:1a6:8a07:960a with SMTP id lg5-20020a170902fb8500b001a68a07960amr166701plb.0.1685668524538; Thu, 01 Jun 2023 18:15:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 1 Jun 2023 18:15:17 -0700 In-Reply-To: <20230602011518.787006-1-seanjc@google.com> Mime-Version: 1.0 References: <20230602011518.787006-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog Message-ID: <20230602011518.787006-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: x86: Use standard mmu_notifier invalidate hooks for APIC access page From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Gunthorpe , Alistair Popple , Robin Murphy Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that KVM honors past and in-progress mmu_notifier invalidations when reloading the APIC-access page, use KVM's "standard" invalidation hooks to trigger a reload and delete the one-off usage of invalidate_range(). Aside from eliminating one-off code in KVM, dropping KVM's use of invalidate_range() will allow common mmu_notifier to redefine the API to be more strictly focused on invalidating secondary TLBs that share the primary MMU's page tables. Suggested-by: Jason Gunthorpe Cc: Alistair Popple Cc: Robin Murphy Signed-off-by: Sean Christopherson Reviewed-by: Alistair Popple --- arch/x86/kvm/mmu/mmu.c | 3 +++ arch/x86/kvm/x86.c | 14 -------------- include/linux/kvm_host.h | 3 --- virt/kvm/kvm_main.c | 18 ------------------ 4 files changed, 3 insertions(+), 35 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c8961f45e3b1..01a11ce68e57 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1600,6 +1600,9 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_= gfn_range *range) if (tdp_mmu_enabled) flush =3D kvm_tdp_mmu_unmap_gfn_range(kvm, range, flush); =20 + if (range->slot->id =3D=3D APIC_ACCESS_PAGE_PRIVATE_MEMSLOT) + kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD); + return flush; } =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ceb7c5e9cf9e..141a62e59d2b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10431,20 +10431,6 @@ static void vcpu_load_eoi_exitmap(struct kvm_vcpu = *vcpu) vcpu, (u64 *)vcpu->arch.ioapic_handled_vectors); } =20 -void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, - unsigned long start, unsigned long end) -{ - unsigned long apic_address; - - /* - * The physical address of apic access page is stored in the VMCS. - * Update it when it becomes invalid. - */ - apic_address =3D gfn_to_hva(kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT); - if (start <=3D apic_address && apic_address < end) - kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD); -} - void kvm_arch_guest_memory_reclaimed(struct kvm *kvm) { static_call_cond(kvm_x86_guest_memory_reclaimed)(kvm); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 0e571e973bc2..cb66f4100be7 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2237,9 +2237,6 @@ static inline long kvm_arch_vcpu_async_ioctl(struct f= ile *filp, } #endif /* CONFIG_HAVE_KVM_VCPU_ASYNC_IOCTL */ =20 -void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, - unsigned long start, unsigned long end); - void kvm_arch_guest_memory_reclaimed(struct kvm *kvm); =20 #ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index cb5c13eee193..844ff6b0b21d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -154,11 +154,6 @@ static unsigned long long kvm_active_vms; =20 static DEFINE_PER_CPU(cpumask_var_t, cpu_kick_mask); =20 -__weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, - unsigned long start, unsigned long end) -{ -} - __weak void kvm_arch_guest_memory_reclaimed(struct kvm *kvm) { } @@ -521,18 +516,6 @@ static inline struct kvm *mmu_notifier_to_kvm(struct m= mu_notifier *mn) return container_of(mn, struct kvm, mmu_notifier); } =20 -static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn, - struct mm_struct *mm, - unsigned long start, unsigned long end) -{ - struct kvm *kvm =3D mmu_notifier_to_kvm(mn); - int idx; - - idx =3D srcu_read_lock(&kvm->srcu); - kvm_arch_mmu_notifier_invalidate_range(kvm, start, end); - srcu_read_unlock(&kvm->srcu, idx); -} - typedef bool (*hva_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range= ); =20 typedef void (*on_lock_fn_t)(struct kvm *kvm, unsigned long start, @@ -892,7 +875,6 @@ static void kvm_mmu_notifier_release(struct mmu_notifie= r *mn, } =20 static const struct mmu_notifier_ops kvm_mmu_notifier_ops =3D { - .invalidate_range =3D kvm_mmu_notifier_invalidate_range, .invalidate_range_start =3D kvm_mmu_notifier_invalidate_range_start, .invalidate_range_end =3D kvm_mmu_notifier_invalidate_range_end, .clear_flush_young =3D kvm_mmu_notifier_clear_flush_young, --=20 2.41.0.rc2.161.g9c6817b8e7-goog