From mboxrd@z Thu Jan 1 00:00:00 1970 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 08307C433EF for ; Sat, 20 Nov 2021 04:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237558AbhKTE4R (ORCPT ); Fri, 19 Nov 2021 23:56:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236570AbhKTEyn (ORCPT ); Fri, 19 Nov 2021 23:54:43 -0500 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 7E829C06179B for ; Fri, 19 Nov 2021 20:51:10 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id p3-20020a170903248300b00143c00a5411so5704019plw.12 for ; Fri, 19 Nov 2021 20:51:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=3YA6l+nCWDobMPdwMK0h4ZN/J+oTuGq2DHmloikAhG4=; b=OT2ThxPI0Z+DmHbtqeAbhdVF5XfOWjPZhjJ7VgLpSyx54RZ6RaCRqT33imBho+6uVA 2vhJdEuWK5SWg+ykQyXb4kr6gcymWsPO2qzs6OknhfsHMzyBBHC9lawd/Sj8WVBK1on3 ZhR+NQlJj3doYgYIlZQAOsPWH56o5h/XirCxBG+i4kqTNh+3lcw1gLh+AhELnh97ZthC f1QKcS6t+D7BRbtUhAy8A/P0tJ0TkV+XmMj1oYUxd7wETacnSxOIU3TeCey/RDXCuXcc z1AvQwDfamppoyX+Az7bTOrMBOb6M1X8jWz9OskFyZlI0gCkDRZD2tnGOgvt8nKDZyvW 2gew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=3YA6l+nCWDobMPdwMK0h4ZN/J+oTuGq2DHmloikAhG4=; b=Z4HQ5K1OICOqPpKeVhjiD1Jam2W29BpdWpjcLTAOLUnAt7VfTNfSB9IGbmYQuzZaT/ X+aMk9Q/STcSsImW5D59dWEeuukw7zhlIwMfj0C9lPGzEohjO3APEDZlaCUvKR1uvPOT btu0Wl8tY5qdEaTOi2BXj+aLd5NUvc5kHeCgYs7D9hpBbcnDlsScEr+wUVQLlsG+0btL bUVOh4xut4VqcJ0fsVjcTPiLFn2KyDa0gt5rsKrJIQNjdZvXcADihIWHpodtkOncN8mN rrLLfUT3lefckywDvTTMRrcc4FPfiQ9YDPk0bYv8guuWjQv8H0gjsdXCsX/U25YlY8Fm 7ANA== X-Gm-Message-State: AOAM533XrbogBieRLU4HZNaxPq+UKtQevjCu2AZ4jTlSMA1KVHY2RyAR VCyn0vqeqhK63goMxdzHPu7Ia45mNMs= X-Google-Smtp-Source: ABdhPJybdVjiF4plk9xbZSXhzzMciJanivTRt10ixVPETWLvjRFOCdlOnjHRBMgAFvzEJd10JBUy4xUan/0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:1bc5:: with SMTP id r5mr6738027pjr.90.1637383869917; Fri, 19 Nov 2021 20:51:09 -0800 (PST) Reply-To: Sean Christopherson Date: Sat, 20 Nov 2021 04:50:28 +0000 In-Reply-To: <20211120045046.3940942-1-seanjc@google.com> Message-Id: <20211120045046.3940942-11-seanjc@google.com> Mime-Version: 1.0 References: <20211120045046.3940942-1-seanjc@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH 10/28] KVM: x86/mmu: Allow yielding when zapping GFNs for defunct TDP MMU root From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Hou Wenlong , Ben Gardon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow yielding when zapping SPTEs for a defunct TDP MMU root. Yielding is safe from a TDP perspective, as the root is unreachable. The only potential danger is putting a root from a non-preemptible context, and KVM currently does not do so. Yield-unfriendly iteration uses for_each_tdp_mmu_root(), which doesn't take a reference to each root (it requires mmu_lock be held for the entire duration of the walk). tdp_mmu_next_root() is used only by the yield-friendly iterator. kvm_tdp_mmu_zap_invalidated_roots() is explicitly yield friendly. kvm_mmu_free_roots() => mmu_free_root_page() is a much bigger fan-out, but is still yield-friendly in all call sites, as all callers can be traced back to some combination of vcpu_run(), kvm_destroy_vm(), and/or kvm_create_vm(). Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 3086c6dc74fb..138c7dc41d2c 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -79,6 +79,11 @@ static void tdp_mmu_free_sp_rcu_callback(struct rcu_head *head) tdp_mmu_free_sp(sp); } +/* + * Note, putting a root might sleep, i.e. the caller must have IRQs enabled and + * must not explicitly disable preemption (it will be disabled by virtue of + * holding mmu_lock, hence the lack of a might_sleep()). + */ void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root, bool shared) { @@ -101,7 +106,7 @@ void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root, * intermediate paging structures, that may be zapped, as such entries * are associated with the ASID on both VMX and SVM. */ - (void)zap_gfn_range(kvm, root, 0, -1ull, false, false, shared); + (void)zap_gfn_range(kvm, root, 0, -1ull, true, false, shared); call_rcu(&root->rcu_head, tdp_mmu_free_sp_rcu_callback); } -- 2.34.0.rc2.393.gf8c9666880-goog