Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2337636pxp; Mon, 21 Mar 2022 17:21:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJwS/LFEpES3k2ctxk/iAvVcqlmveCnq14KD2rwIZ8KBNU8nNxtfdD0uOdUJRotuwaY5uG X-Received: by 2002:a17:90b:314:b0:1be:dc22:62f2 with SMTP id ay20-20020a17090b031400b001bedc2262f2mr1848723pjb.102.1647908468046; Mon, 21 Mar 2022 17:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647908468; cv=none; d=google.com; s=arc-20160816; b=MSCaLwN9nuG1uHfbNGVhrgxDW1HSPk3zFgwbrySg9DUxSaIdfC+cfdl8NK1Atf12NP LsAtE9xOnl2WSvRg5/1MrsA7OTcbxqCUQUNjo7zMpF4dlgR32mzdeXEBMjYLK/EvU5lp /4/Zxgr9QHqaMwornODSgZfusjLR89nurwAefttnRGxYIcwQTSN4suZvJV6YZ2CGEzZd Buk+rm8wX+ZO+VM/ZOXcLPlLs5NaVARU8KtYTfsLIL5ymUonFSg9ol1XkBdha+Cr156Y PPocptU62Yfm7rRMmBifE0CPukV0tvtsz9kRXVgvM6h0UCAEYI1Gk/TfjDDJwdrFxmG8 TNnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=HTko+mjwSCY8/8jCHYIzXlXkhpUJFcRy2EV5oJp9m3Q=; b=0StzsQ+PpeWOVMK7TyDbKnpG0hmeU2lDyKiqm8i7hBMLqXulupTwxen/iPlIj9ss9W wEwbciAYmJ+3OTV+8MkUAPly1oel3MJoZT/XkZN8vhlZy0hzCtDS22MglLNVvakiJrfj KvgNwwGMOuN3k2PWtzJp+bpB9Bu7OcVSiKEpKUB2NZ2Tvfn5bQ5udosohtrT9pOD3Exc jsEsYKuOtqx9YENXlb79sdDipfBxL2XljgrRYC4UMzkK6s3NPGsVEbLDchULeYUOUxhc ZKX6orEAORqEYKCWpA6QH5sN3BV3FBWNKHx48pTiGXtMgDmRaDh0wFqH9gXXaGjeseAK tbyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=I22SNpJT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m9-20020a170902bb8900b00153b2d165f3si12178231pls.507.2022.03.21.17.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 17:21:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=I22SNpJT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB4F72662FF; Mon, 21 Mar 2022 16:50:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233787AbiCUXvj (ORCPT + 99 others); Mon, 21 Mar 2022 19:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233578AbiCUXvK (ORCPT ); Mon, 21 Mar 2022 19:51:10 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBBA81AA051 for ; Mon, 21 Mar 2022 16:49:10 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id z132-20020a63338a000000b003844e317066so167484pgz.19 for ; Mon, 21 Mar 2022 16:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HTko+mjwSCY8/8jCHYIzXlXkhpUJFcRy2EV5oJp9m3Q=; b=I22SNpJTSp7u2DkXDp+DZcXecT0aJNWQsYrggepx4bKXKn5jFK8VNlPisgR9wW+gZi sypyACQIoThc8e16NmgO60qt1r5TdXaq4OBmHDr0wcQbVn8Ixvjf84zb0XZHVNOjcBqN L07M7jQJ3Dmzbwwr8ienEAHrv2B7U3dwrascuPvMrO3R+s2U10dHS0H0k/WRZu4aDo4Z xqqkSP7Mfc1F3HoUP89S8h+v7/104N7SfBKCakhJXwea8h7EaYHxn6B5fjTh+JEgAF/E CIDd/hyZ2/pOhkrneK9nUuF4MxB9VfkIxSMd4+4YS+yVFstDLqD2CXAcR0U71vwoPaxJ vcdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HTko+mjwSCY8/8jCHYIzXlXkhpUJFcRy2EV5oJp9m3Q=; b=1rvtqiGTif2Rah/jT3m8SzBu81/BU6hHy9nCR9Q24/Fwz3t8foAzzcF0+gqK3Pa28S 0ilISY7SDlzxBlMHp2jYr222C4FefcGfitXgZIH6ASIZGGaJfqtlA3QurCCzHPtrt9So z3hx2jo/ELAzZygX/2pucKjBB+GLG972eyer/NbW5hcqp0GLHPG8/9ZZcyqKn31EGwVS +kEVP7DYYGL9UnxImeIuii2mTK/ObfnDMeWP0Y26hfkjxFoGvjU+LVeFehGjnulUw/IH m6cRgAT9JIm+6tbl5aFOkiHtadhFaO8MJKHJuc/PwEQt/tkwe6zzcrVmzRGrl0ydNZxO CDTQ== X-Gm-Message-State: AOAM532pe8mt/5nkwOeB6d9PZtD+WnHRu1IR1xGXhTR3h6NXx/d7Dd/e JjiLAO/d8ufGTeo4eHArNPQVG0zf5raGPQ1EhXpgZLZ7m6RJ6JVyc5Jzxd53ROKu3d7NH+D2wpH dfPBMIXbbsCOS0FYNIblYwT24j2/OjeJo4yx0X49UVAu2qrDze1ByXMu5E8TBXyCRb9MtvQVc X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:b76a:f152:cb5e:5cd2]) (user=bgardon job=sendgmr) by 2002:a05:6a00:238f:b0:4f7:78b1:2f6b with SMTP id f15-20020a056a00238f00b004f778b12f6bmr26325911pfc.17.1647906549813; Mon, 21 Mar 2022 16:49:09 -0700 (PDT) Date: Mon, 21 Mar 2022 16:48:40 -0700 In-Reply-To: <20220321234844.1543161-1-bgardon@google.com> Message-Id: <20220321234844.1543161-8-bgardon@google.com> Mime-Version: 1.0 References: <20220321234844.1543161-1-bgardon@google.com> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [PATCH v2 07/11] KVM: x86/MMU: Factor out updating NX hugepages state for a VM From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , David Matlack , Jim Mattson , David Dunn , Jing Zhang , Junaid Shahid , Ben Gardon Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out the code to update the NX hugepages state for an individual VM. This will be expanded in future commits to allow per-VM control of Nx hugepages. No functional change intended. Signed-off-by: Ben Gardon --- arch/x86/kvm/mmu/mmu.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 3b8da8b0745e..1b59b56642f1 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6195,6 +6195,15 @@ static void __set_nx_huge_pages(bool val) nx_huge_pages = itlb_multihit_kvm_mitigation = val; } +static int kvm_update_nx_huge_pages(struct kvm *kvm) +{ + mutex_lock(&kvm->slots_lock); + kvm_mmu_zap_all_fast(kvm); + mutex_unlock(&kvm->slots_lock); + + wake_up_process(kvm->arch.nx_lpage_recovery_thread); +} + static int set_nx_huge_pages(const char *val, const struct kernel_param *kp) { bool old_val = nx_huge_pages; @@ -6217,13 +6226,8 @@ static int set_nx_huge_pages(const char *val, const struct kernel_param *kp) mutex_lock(&kvm_lock); - list_for_each_entry(kvm, &vm_list, vm_list) { - mutex_lock(&kvm->slots_lock); - kvm_mmu_zap_all_fast(kvm); - mutex_unlock(&kvm->slots_lock); - - wake_up_process(kvm->arch.nx_lpage_recovery_thread); - } + list_for_each_entry(kvm, &vm_list, vm_list) + kvm_set_nx_huge_pages(kvm); mutex_unlock(&kvm_lock); } -- 2.35.1.894.gb6a874cedc-goog