Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp994097pxb; Tue, 9 Feb 2021 19:17:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMmtWx46Y3w0KN3NUBWQ4jRE+KG3yE0wLxmzw9vbhSo7LreLQtHZ5v2sCNogrr/EUKnFHq X-Received: by 2002:a50:e882:: with SMTP id f2mr1210247edn.35.1612927027635; Tue, 09 Feb 2021 19:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612927027; cv=none; d=google.com; s=arc-20160816; b=M+dQGGjg8IIXrKTPTtmYmqWz3v+sQqvPKNE6sAe4Hzy43qeTgvn2fo9vr+mQQv1me7 eNy/KL2c8HV3U2I5MjWSMcWkuTPQBqXRtylUtc8XJi+AwS5VQ/C86aK1OlwPsh31c9AU xfAklUtbIhMw9F2lzGuOeVwicEFbpWDwxqK3bMYyKsGzbyUCqvj1TsWmhwcvE1J4lebb j55yZlRnTbZcLI6Kf4zZ71uQKN7pR3PaVQrOpbbRIEB3nFbt85kANkAmEoOaW2u/lS5+ ubmKhSKSy2oimhxs1uGga1uoEJBw+TC+lNe6RD1gRVWYoqbSG0lBdI2PxU2YMZa3l1Cx lGyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=gbORY0Z76vYpmZXkvmZp4D8Rd1YEL3mMnZP4l7HFbj0=; b=kFIN6ewqJfyldnB4DecEpMzszRvZXbqu7vV/1je1mfA1OyaZ1C2O+uccpgcpWU3aNK XbKpeGLzZblj5mH9tmH3LHDCmlF5SVg15Uuje6jJgHmmyTSrJ4r7AHCyPVfDVWv6o7B4 uoiT2n2oTnVCYqe+flimFvteuFGVrv0O2eJaloAxePGPTZPwld1YmGS68wqGQ3q+Fpwb eTFEEWU5840HoXk1bbQt9ZdkoUqZXj9oa9/RyMNAjDRJjyB1Uc/nOBFEPM4UjL69CZvL Y2zrvPm584vgNSnz1yMoMDwZ+9VfAyZCkdHZUl1qHQOXCJ3Xh3ie4ekXPnQOLeq/2RGv j9sA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si588362edv.513.2021.02.09.19.16.43; Tue, 09 Feb 2021 19:17:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbhBILDJ (ORCPT + 99 others); Tue, 9 Feb 2021 06:03:09 -0500 Received: from mga06.intel.com ([134.134.136.31]:33675 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232172AbhBIK5k (ORCPT ); Tue, 9 Feb 2021 05:57:40 -0500 IronPort-SDR: C452LsrHA2GGMh/naHlHSJ67SjONlud0rJZwU4wz1ECR6kCzEdK3zwUvGdKGsYr1pjgoVON08O MyXlBcpPQy9g== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="243356845" X-IronPort-AV: E=Sophos;i="5.81,164,1610438400"; d="scan'208";a="243356845" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2021 02:55:50 -0800 IronPort-SDR: 8JAL2x2H0J4WHV4St6Mu6Mj45fGB7cL871ydig3rzAXc68ooxSlv54MhyATXzM9ybX/RSJeYVa k3XQoEVGVlfQ== X-IronPort-AV: E=Sophos;i="5.81,164,1610438400"; d="scan'208";a="396072221" Received: from liujiaq1-mobl2.ccr.corp.intel.com (HELO localhost) ([10.249.174.87]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2021 02:55:47 -0800 Date: Tue, 9 Feb 2021 18:55:43 +0800 From: Yu Zhang To: pbonzini@redhat.com, seanjc@google.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org Subject: Re: [PATCH v3] KVM: x86/MMU: Do not check unsync status for root SP. Message-ID: <20210209105543.bgxd4qftfqz5k4pa@linux.intel.com> References: <20210209170111.4770-1-yu.c.zhang@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210209170111.4770-1-yu.c.zhang@linux.intel.com> User-Agent: NeoMutt/20171215 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry, forget the change log: Changes in V3: - fixed a bug in warnings inside mmu_sync_children(). - commit message changes based on Paolo's suggestion. - added Co-developed-by: Sean Christopherson Changes in V2: - warnings added based on Sean's suggestion. On Wed, Feb 10, 2021 at 01:01:11AM +0800, Yu Zhang wrote: > In shadow page table, only leaf SPs may be marked as unsync; > instead, for non-leaf SPs, we store the number of unsynced > children in unsync_children. Therefore, in kvm_mmu_sync_root(), > sp->unsync shall always be zero for the root SP and there is > no need to check it. Remove the check, and add a warning > inside mmu_sync_children() to assert that the flags are used > properly. > > While at it, move the warning from mmu_need_write_protect() > to kvm_unsync_page(). > > Co-developed-by: Sean Christopherson > Signed-off-by: Sean Christopherson > Signed-off-by: Paolo Bonzini > Signed-off-by: Yu Zhang > --- > arch/x86/kvm/mmu/mmu.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 86af58294272..5f482af125b4 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -1995,6 +1995,12 @@ static void mmu_sync_children(struct kvm_vcpu *vcpu, > LIST_HEAD(invalid_list); > bool flush = false; > > + /* > + * Only 4k SPTEs can directly be made unsync, the parent pages > + * should never be unsyc'd. > + */ > + WARN_ON_ONCE(parent->unsync); > + > while (mmu_unsync_walk(parent, &pages)) { > bool protected = false; > > @@ -2502,6 +2508,8 @@ EXPORT_SYMBOL_GPL(kvm_mmu_unprotect_page); > > static void kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) > { > + WARN_ON(sp->role.level != PG_LEVEL_4K); > + > trace_kvm_mmu_unsync_page(sp); > ++vcpu->kvm->stat.mmu_unsync; > sp->unsync = 1; > @@ -2524,7 +2532,6 @@ bool mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn, > if (sp->unsync) > continue; > > - WARN_ON(sp->role.level != PG_LEVEL_4K); > kvm_unsync_page(vcpu, sp); > } > > @@ -3406,8 +3413,7 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu) > * mmu_need_write_protect() describe what could go wrong if this > * requirement isn't satisfied. > */ > - if (!smp_load_acquire(&sp->unsync) && > - !smp_load_acquire(&sp->unsync_children)) > + if (!smp_load_acquire(&sp->unsync_children)) > return; > > write_lock(&vcpu->kvm->mmu_lock); > -- > 2.17.1 >