Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2313252pxp; Mon, 21 Mar 2022 16:39:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKPpnoA8icd2+oCrgZtJ/zoKjqvbYuzXaJiNIi6ul40C5GJD/UXjuBLCXLSm/je9+ois6m X-Received: by 2002:a63:5b63:0:b0:378:5645:90f6 with SMTP id l35-20020a635b63000000b00378564590f6mr19674096pgm.505.1647905981508; Mon, 21 Mar 2022 16:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647905981; cv=none; d=google.com; s=arc-20160816; b=T/MTJHA09HW5D5Y/wwHKelO+RVmJwVr/y/BHbxhMGfvJfzdZM1NcsmUqUtbxvEK8Nj t9NvsrVQV361k90jT3TFN8TI2DoUdczovRjAkUmvQaFFpAbQhGhE9AcWq+ndAfyuxWA4 dhAuybLynlu5uCIzo0QIl99VQy8ubLFJ07Ws0/EYRSOB42CRWKnuxEWOgle+8WAh4Ehu iF7U+Q9L4bFDe3Oc1ZdnDULknZoZAhvCoEEFNzSgmeYWTsyQVDU4AXbQH/p11vWa5Lzg BTDZ+vqLkWfqNJdvFBNuF4H8bsLYkGx0O9o6NH42+0ldFbb8X/x4PKifEPB+Og29TsTC WSAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=9lfgL3STyhcbUTg/2mdbbAna/81RZPKVO1DCdewIE0c=; b=pzzeK5E27GJwbkuXYzj33Qm+8UJyrqqjp5yIFRoWtjXiUy7gYuPUcoNLKhTExL0Lb5 dkb7z/jLtcrMjzCCBRwv4U048hLByx/h+3MCVk066RNsp2e8CUVtNqg5lw4o8evTZGVv ZZerP5SJx756BbW4uxv8PglyD04ItQ5sRpCkb8TdYuzINcT1O0MLQEFM5mhEc7AROGsn N4xCLa+/7EtnpTQxTmXcJXVAvzJd9bIMj3nkjR2lpZarVbgIMUlnDEm97YAGQcUN3qkQ SvKf2EwlBoVGKPjF95gg8dgf92kZhiVducXUG1cyjsxTYYR613UEf7CWjMF8MTmEZOEp jmlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gyWTW65Q; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id g10-20020a170902868a00b00153c0334fd4si11222237plo.559.2022.03.21.16.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:39:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gyWTW65Q; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 000523FD6EF; Mon, 21 Mar 2022 15:52:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230004AbiCUWwV (ORCPT + 99 others); Mon, 21 Mar 2022 18:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230319AbiCUWvx (ORCPT ); Mon, 21 Mar 2022 18:51:53 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CEF546AE60 for ; Mon, 21 Mar 2022 15:41:43 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a8so32747327ejc.8 for ; Mon, 21 Mar 2022 15:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9lfgL3STyhcbUTg/2mdbbAna/81RZPKVO1DCdewIE0c=; b=gyWTW65QfHhxvHH2bxgBaFULc3nQpwZVt/AImeBaMsagLh7ZILfBIv+cpBZ1WSMI9Y TOPeV02sp4XiVQ8lLN4FhnC7+vP3gy404ImwUap5qVGjKFQLADRuLKDINVF1PWzZB4oh U1mEyqWzxsu3MtArm0qnwbxI0Tx9hdG/LVKbNXemcrBdZ3oknTgvP+A4O4F1hDotj6c7 FVqupN7ClUGTVzfsEfmwX4wkAgsXCHqtd+IxXQCc+4lmBRSffgJC9BQPVBCIHWW3kbD/ 9j6hHMT86dOmHX2WVzZ5qGs1t/Zz97eNKhrycXInFxW646D96NZqUdSy6LBktZ2feENm LGqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9lfgL3STyhcbUTg/2mdbbAna/81RZPKVO1DCdewIE0c=; b=eyIger7lDwxXIqADINbBSoWNEe4uqo9TnUTHjzowYeCJucJ1j7RaaBYA0q5s8oykd6 nCiOYyYo+HTiRgr/Ed8YbCjrzWwduVSkrTVn7mn4HUgea+RRENFtJTuOuEI73v548pCN d7EtY+NzetWrKaAn/Mh1AjSVOBXxiXBXqojcEQrauFtVEtFA/mdXAPv/Q6nxqrjykGX3 eIbT6RBM+cruyZ0XKeMZpGcw5Nqcbezlk2D++Zgj/qaHcBalEzG29dq0ikbzX1G4X4Tn igkUbsVevp7YNCHRGIjcEzLyCmxnhjjIOCjHOfm5myCoBIn1YwjSU/03CUfJKBH/CNDf HN3w== X-Gm-Message-State: AOAM532xpLjthvf59fk9f9cqMZ6uyFvaSimc6Cre04R/3cC2RbBwJfev 2Jp5Oz6hMrUjCRBhz8WTd6YMEbZZ4q3t126hOoFVRpZYbISvjA== X-Received: by 2002:a2e:6804:0:b0:245:f269:618 with SMTP id c4-20020a2e6804000000b00245f2690618mr16315718lja.198.1647900072176; Mon, 21 Mar 2022 15:01:12 -0700 (PDT) MIME-Version: 1.0 References: <20220321002638.379672-1-mizhang@google.com> <20220321002638.379672-4-mizhang@google.com> In-Reply-To: <20220321002638.379672-4-mizhang@google.com> From: David Matlack Date: Mon, 21 Mar 2022 15:00:45 -0700 Message-ID: Subject: Re: [PATCH 3/4] KVM: x86/mmu: explicitly check nx_hugepage in disallowed_hugepage_adjust() To: Mingwei Zhang Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm list , LKML , Ben Gardon , Jing Zhang , Peter Xu , 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 On Sun, Mar 20, 2022 at 5:26 PM Mingwei Zhang wrote: > > Add extra check to specify the case of nx hugepage and allow KVM to > reconstruct large mapping after dirty logging is disabled. Existing code > works only for nx hugepage but the condition is too general in that does > not consider other usage case (such as dirty logging). KVM calls kvm_mmu_zap_collapsible_sptes() when dirty logging is disabled. Why is that not sufficient? > Moreover, existing > code assumes that a present PMD or PUD indicates that there exist 'smaller > SPTEs' under the paging structure. This assumption may no be true if > consider the zapping leafs only behavior in MMU. Good point. Although, that code just got reverted. Maybe say something like: This assumption may not be true in the future if KVM gains support for zapping only leaf SPTEs. > > Missing the check causes KVM incorrectly regards the faulting page as a NX > huge page and refuse to map it at desired level. And this leads to back > performance in shadow mmu and potentiall TDP mmu. s/potentiall/potentially/ > > Fixes: b8e8c8303ff2 ("kvm: mmu: ITLB_MULTIHIT mitigation") > Cc: stable@vger.kernel.org > > Reviewed-by: Ben Gardon > Signed-off-by: Mingwei Zhang > --- > arch/x86/kvm/mmu/mmu.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 5628d0ba637e..4d358c273f6c 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2919,6 +2919,16 @@ void disallowed_hugepage_adjust(struct kvm_page_fault *fault, u64 spte, int cur_ > cur_level == fault->goal_level && > is_shadow_present_pte(spte) && > !is_large_pte(spte)) { > + struct kvm_mmu_page *sp; > + u64 page_mask; > + /* > + * When nx hugepage flag is not set, there is no reason to > + * go down to another level. This helps demand paging to > + * generate large mappings. > + */ > + sp = to_shadow_page(spte & PT64_BASE_ADDR_MASK); > + if (!sp->lpage_disallowed) > + return; > /* > * A small SPTE exists for this pfn, but FNAME(fetch) > * and __direct_map would like to create a large PTE > @@ -2926,8 +2936,8 @@ void disallowed_hugepage_adjust(struct kvm_page_fault *fault, u64 spte, int cur_ > * patching back for them into pfn the next 9 bits of > * the address. > */ > - u64 page_mask = KVM_PAGES_PER_HPAGE(cur_level) - > - KVM_PAGES_PER_HPAGE(cur_level - 1); > + page_mask = KVM_PAGES_PER_HPAGE(cur_level) - > + KVM_PAGES_PER_HPAGE(cur_level - 1); > fault->pfn |= fault->gfn & page_mask; > fault->goal_level--; > } > -- > 2.35.1.894.gb6a874cedc-goog >