Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2489247pxp; Mon, 21 Mar 2022 22:20:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmyKBnL81FjX39bL8hlCECqxSYupw+aRurY47kd7SLTEAykTwBv7UhaLuBL6XGh1RxILbF X-Received: by 2002:a63:7d04:0:b0:378:fb34:5162 with SMTP id y4-20020a637d04000000b00378fb345162mr20813098pgc.487.1647926421924; Mon, 21 Mar 2022 22:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647926421; cv=none; d=google.com; s=arc-20160816; b=zYcYwLKI0paFb8SqOd0rYKWP2JkYk7ql8OVYZKNxBhbOPN54w9Se2DGc6g2lObCRMd ISbVcQUQ2P4RiLJmKYj7dxFzVakmFOng7Smeof+oZdkCqkcurSiraOoA/AKvc1kj6ijX HF2bLCxZjvkPEgHOdxXa4Yk6qJv4fVVh1Z4z4C2Jt6ARLaO1s3/vPzu92zWLkDGpc6lZ 3iCvR6l577M4oUVCZNswvhPZskf7nOE1G+R4RCejKFC2Ux+0WcDlCpSP61UGlj1YhS3O yue5TmlEi3rasc+B4JuAqK0JaCRIqz2JniNCiFCY8M32MI5kFUbIYTKh0zNYRpYPQ8hM PCBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ha0vPVeUDzbZ9ELlg8Nq/jWp7wou24wRrMHx+56fZxo=; b=oBltLSqC+8p9pkclhJ7pcSCO+3h+GacWv7EzdRYtbxtE7iSPdwX5LIq8EXoYyUOCbX Gww1nq6Q41OA97d8CPKiqUmTT55gnKBNHJCgvMZqFQ/XQF8rXiMGKdwZRPoXZe15jzvx W7HRPlF4b+7HhfvMjczLxxXNWWpPCjaAYq9VF8wYnioIZierK3k+MvbkY+PFR/ZnGbSl UtPe54Ro1UU0d9ixOnIE2Rbo70K42JMJF4czOYAyQnrXolkZrVkjcAcA85/esdI0MbuL UzAnBDy8Kx5VscdsaPbbQnL+m5u9BSXY5rMaTGxwEeBebBOtyc77JdtTGMIX0N1Y6ZeL yoEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dS5HqZLf; 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 a190-20020a6390c7000000b003816043ee37si13894422pge.44.2022.03.21.22.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 22:20:21 -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=dS5HqZLf; 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 058FC13DF4; Mon, 21 Mar 2022 21:28:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236429AbiCVEaA (ORCPT + 99 others); Tue, 22 Mar 2022 00:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236363AbiCVE3w (ORCPT ); Tue, 22 Mar 2022 00:29:52 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F468F33 for ; Mon, 21 Mar 2022 21:28:24 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id q19so11775838pgm.6 for ; Mon, 21 Mar 2022 21:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ha0vPVeUDzbZ9ELlg8Nq/jWp7wou24wRrMHx+56fZxo=; b=dS5HqZLfymPE1FEpGN8CF3og/rwMyQBSfx//mku/6Pb3G6uEDl1wZJYqx/0D7Av8DB 0R1BwA2bSA0IC8XfDabP8u00zVP/zA3WEzNSMuXAkO7MmsKljJt6V2A+PNDvioOeH6nW 3nMjlgOtfyZPoBBpMQ7fPsw9NKXjHT/jHE+CHbiVi5dDwxeXEaxlNCBDYLvjAb9INsyy +NtiEqpsIEdjuiUiLD9CBVdvQFZ7gF914nRZp1ZTPCTetElYHenjTD+iWWBdyCgIO8wf LHLPoTah47tJSxQZC9JAYxjhYswJL9+dc/IM37RbZ/8D0FgLmpFtpOgHSyGmpmDuHeDg hRhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ha0vPVeUDzbZ9ELlg8Nq/jWp7wou24wRrMHx+56fZxo=; b=y/p/h3lHGVgNf22VNa7k/GsHscYc4hjeZbs4Fp9ilADC90YMCit8v1M7iKTb6JOy4Q Czs4F4xlU9QS4n7vhLoefIW7qnrAG22YPKeh8eIOFYDRXgJrBJxI47UcmXQsalXggS8Q 3NiNDwwM9ruTQGs/543/UWTl2ZyvIwWjQhnyvfE4aa9sS5iFioiDQvUfdm9TYV2+dRND FYOZAdO/yUuVjiQIIVCedbE67kZMcYdGvbL6aCrogStLqI9YmNIpQ6dcBKQIDj7mPgGB tMnonJ1iNwAy0Efpsqoy5dmSCimS9RHrVZJKPOesbZSdv01LhPlaQYGtJJr9btlCDhlM 7KVw== X-Gm-Message-State: AOAM531t9FyYNykdtmRWcdPZM2GnLJjWSAAY+JJ96q/9stihdc9WdL9H WYKOZ7gtOV1OkEbUJOzxX1udVg== X-Received: by 2002:a05:6a00:1ac8:b0:4fa:917f:c1aa with SMTP id f8-20020a056a001ac800b004fa917fc1aamr11379307pfv.2.1647923303715; Mon, 21 Mar 2022 21:28:23 -0700 (PDT) Received: from google.com (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with ESMTPSA id j3-20020a056a00234300b004faabba358fsm4600997pfj.14.2022.03.21.21.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 21:28:23 -0700 (PDT) Date: Tue, 22 Mar 2022 04:28:19 +0000 From: Mingwei Zhang To: Ben Gardon Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Jing Zhang , Peter Xu , Ben Gardon Subject: Re: [PATCH 3/4] KVM: x86/mmu: explicitly check nx_hugepage in disallowed_hugepage_adjust() Message-ID: References: <20220321002638.379672-1-mizhang@google.com> <20220321002638.379672-4-mizhang@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Mon, Mar 21, 2022, Ben Gardon wrote: > 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). 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. > > > > 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. > > > > 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. > > + */ > > This comment is relevant to Google's internal demand paging scheme, > but isn't really relevant to UFFD demand paging. > Still, as demonstrated by the next commit, this is important for dirty > loggin, so I'd suggest updating this comment to refer to that instead. > Ah, leaking my true motivation :-) Definitely will update the comment. > > + 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 > >