Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1059638rwi; Fri, 14 Oct 2022 12:14:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53LB+rNth5mZeY6VQqc7LzqMijVmWakerbAjVM2tM1NFJrhFcFxplm/lBIA3KYI6rcT6SI X-Received: by 2002:a05:6402:42c7:b0:45c:a6f1:c0af with SMTP id i7-20020a05640242c700b0045ca6f1c0afmr5397918edc.75.1665774895389; Fri, 14 Oct 2022 12:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665774895; cv=none; d=google.com; s=arc-20160816; b=k/KBKOtA7usvOmFXZ8ZoFQbgLiYWmsZSJLNw8/7cqVyZgpGOcNNbg87ahZJFwKplkZ mmn+DNPKum8gJAL7qxTJVWAcBCO0U0ZDrj6YVDLNRS49u9y7R2gu+fs8eTngykYjN5en s3aTtX6+tYebJck9Lno+Am8a9omDPhz9K9kBSra/+9oJDSqkarGdwelMiEP/240p2Dcv kIgwmdiejN1pKd/f6NHZWqFVNYgcfGX2uOfywPMG0pYqbQBOwtob1W8F3OXQRG1oWwyY Q0I5QjWyKlm8yGP380kpaQv7IXUwz2+bedrpp5GjpiOxjhQ8HzXmDUHwUMp0F4AqMYl7 i1Xw== 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=Hp3yAxY8quCRjHZnHuBPErW5fHEohLMFvOXbDGO/GC8=; b=P7AlScpUnQGKMwi7iBqawnC92hHvVyAMNjw//kaACtEPD6DyFXT3k6jFAnER9SguwJ APELlepzTf1LWkCZ0v+qHDHrHcZkCvt6mDS5X/00s7EbCsJGobpMByLNCbwzflyWraoy 5HicTU/ZEN5ElpKSqsyPoAPSXsg0kXWSOX9SK37cfb+LYyR2gsKnLa+Oo3mJi0vj4m6h 8UMMh7eF7aE41nhCwppzOT44Yo3Axy6IOGJQPSHg6EdD/lMbJ00xp3LhQqpAh/eKZRaZ VFGZt0AvjUrkSHziippYR8XRSG3xm9Rd/Rop9JmdjmfnfcuygX7HBRWMKdHaWGYcdwJJ XFJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=smV3l+b0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd3-20020a1709069b8300b00783d1a13d69si2944614ejc.231.2022.10.14.12.14.29; Fri, 14 Oct 2022 12:14:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=smV3l+b0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbiJNS53 (ORCPT + 99 others); Fri, 14 Oct 2022 14:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230158AbiJNS51 (ORCPT ); Fri, 14 Oct 2022 14:57:27 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C911D3752 for ; Fri, 14 Oct 2022 11:57:25 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 129so5086074pgc.5 for ; Fri, 14 Oct 2022 11:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Hp3yAxY8quCRjHZnHuBPErW5fHEohLMFvOXbDGO/GC8=; b=smV3l+b0gPfxsb+cqdrtrWHgL08g1JwC/C9k3qD53pTkH5zIwd+CIdIyQkxG2V3LLQ vr0fhAZDODX1iShv+uzVVoKO2yI7QS7Dpy4QRu2J0zo+aNXAVzvGg9sHUoPxlMruufUT Kd/EU2UsY1bQRGYb9CuGI8JhB7KR+4XGd9bVk3KgrDAwpXMdf9mvoLDt+7277BOEjAQV 15NUZRhkPpmEySXzwlsNUL2z1AS+68J/MFJRdyKFhuc1w6rWzoLKg91755NPIspVj/io XF7nOZ5WJqalD97V+ZX9AqmTvPbtx0IjpzWhO5nEiArwNwQFjprucchbkW3wnXB21FW0 xdnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Hp3yAxY8quCRjHZnHuBPErW5fHEohLMFvOXbDGO/GC8=; b=CiQSO9sRKBjXs9Us1Ra7QwEQvaWlFYvbViE4QrN4a1rvGUtnqUGF3lgTusazKhIQHn UyVH0Hw3qxIntfo3wFfECxgYOlwKU9aMq/x2FlanrVaMMY+78HlgrlaRwG73IhpI/1W9 vKrBYDCnHu+9eRqKwL/Vi4NXsfYWkT6ga5anp668aNUMRWXN8oBeEDyLMJXa33tgf1d7 plc9zcmiv/unu4Skwka15KREzDpFTxDyxtP/1LWDtCKXY2dmVem61T+VPMhv0OHgH1EF NhxHesd8OT4ASbG+CCyXnUuP+Ok//h9YUE/yH8TYfwpkM8O2xeBZDIFbMcYuX8KMYxJk qpqQ== X-Gm-Message-State: ACrzQf0lOgP1Pdo3BOqr2OOry1AVzR2tLARGlTxKg2RsVVrtWvQNFPc2 EAMacXPqSnVbSwziKl56Smu65g== X-Received: by 2002:a63:2483:0:b0:461:ab67:ccfb with SMTP id k125-20020a632483000000b00461ab67ccfbmr5521853pgk.341.1665773844428; Fri, 14 Oct 2022 11:57:24 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id j5-20020a625505000000b00562019b961asm2064125pfb.188.2022.10.14.11.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 11:57:23 -0700 (PDT) Date: Fri, 14 Oct 2022 18:57:20 +0000 From: Sean Christopherson To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Subject: Re: [PATCH v8 7/8] KVM: Handle page fault for private memory Message-ID: References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-8-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220915142913.2213336-8-chao.p.peng@linux.intel.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Thu, Sep 15, 2022, Chao Peng wrote: > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index a0f198cede3d..81ab20003824 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3028,6 +3028,9 @@ int kvm_mmu_max_mapping_level(struct kvm *kvm, > break; > } > > + if (kvm_mem_is_private(kvm, gfn)) Rather than reload the Xarray info, which is unnecessary overhead, pass in @is_private. The caller must hold mmu_lock, i.e. invalidations from private<->shared conversions will be stalled and will zap the new SPTE if the state is changed. E.g. diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index d68944f07b4b..44eea47697d8 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3072,8 +3072,8 @@ void kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault * Enforce the iTLB multihit workaround after capturing the requested * level, which will be used to do precise, accurate accounting. */ - fault->req_level = kvm_mmu_max_mapping_level(vcpu->kvm, slot, - fault->gfn, fault->max_level); + fault->req_level = kvm_mmu_max_mapping_level(vcpu->kvm, slot, fault->gfn, + fault->max_level, fault->is_private); if (fault->req_level == PG_LEVEL_4K || fault->huge_page_disallowed) return; @@ -6460,7 +6460,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, */ if (sp->role.direct && sp->role.level < kvm_mmu_max_mapping_level(kvm, slot, sp->gfn, - PG_LEVEL_NUM)) { + PG_LEVEL_NUM, false)) { kvm_zap_one_rmap_spte(kvm, rmap_head, sptep); if (kvm_available_flush_tlb_with_range()) diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 7670c13ce251..9acdf72537ce 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -315,6 +315,12 @@ static inline bool is_dirty_spte(u64 spte) return dirty_mask ? spte & dirty_mask : spte & PT_WRITABLE_MASK; } +static inline bool is_private_spte(u64 spte) +{ + /* FIXME: Query C-bit/S-bit for SEV/TDX. */ + return false; +} + static inline u64 get_rsvd_bits(struct rsvd_bits_validate *rsvd_check, u64 pte, int level) { diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 672f0432d777..69ba00157e90 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1767,8 +1767,9 @@ static void zap_collapsible_spte_range(struct kvm *kvm, if (iter.gfn < start || iter.gfn >= end) continue; - max_mapping_level = kvm_mmu_max_mapping_level(kvm, slot, - iter.gfn, PG_LEVEL_NUM); + max_mapping_level = kvm_mmu_max_mapping_level(kvm, slot, iter.gfn, + PG_LEVEL_NUM, + is_private_spte(iter.old_spte)); if (max_mapping_level < iter.level) continue;