Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2143700pxb; Fri, 5 Feb 2021 09:57:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwC4q0fEPShTucDw5nWMURLqdPV0QGUmEDxgIGJpETM45MXI/SV2xMqBypkr2zUI2Dx320I X-Received: by 2002:a17:906:9b4f:: with SMTP id ep15mr1120434ejc.423.1612547826908; Fri, 05 Feb 2021 09:57:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612547826; cv=none; d=google.com; s=arc-20160816; b=Fyw5v40AS26iYbOfNAXPFb2wxPhuE5PO+P19LmXe181iSpN6Ibw50y7XUaURoqwFDb ONCIy3E671gWzCzQ8G2T8hvaEWnyjp3XDa3SlvkejNTUndlyIj2D8/W6nbwVuBfj4RHk JKT1lK5lOSt2l5x6YTAo+o2wbuvADVp/v02/O2wfUdLBDSrVaUsjl02zcD2iXUunpFXN j9t9XVLQVS3XiFIN0MtdSwfSBH9z0rP+T5RrpMMaFhcb6nwm7iJ4PyiserViOHBv6kxU ldk3fTSSOwHXG2a/RMt9PAxVsijy1s+3mYh/s4RO0e1npN3W7Tw9b5RfTVSdav+Db6T/ wS9Q== 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=8LdcV8DMgciJSckP8og9DY1KpzD/dHjlqzcgElgAVXM=; b=PJXLQIGEyVAl2uGpdpIbsKmaqyTZVxEe+fhj0MiN/iszsbTU/J34k8/L+/dG2vkS3v 7oMqV1tVMp9luHT/gMILG8lAnniv1xO77YnTqHWmpI58VcOU7wGrcyLjFHLnCj4nySkz IAQL3Z9bF15XlWQInfQE8JPuiB6sJiJwwdBpTpavVnrE+bdA+zLikh+JjTxEh3mU1c8P R35AwQdByCqAhS+vBvytEfwYgBQZX1YCiW2k4g/s2b2i8zF93NTN0K2ZvWtqHgf92qs3 eVrDAvblXBOAebAjCunvi3/QJCXqxEy19ZCIXmGzlOktVbTle0VxCHYsqQW6s7zLWDAs p9Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=o26e66MU; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si1295918edd.7.2021.02.05.09.56.41; Fri, 05 Feb 2021 09:57:06 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=o26e66MU; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233544AbhBEQNS (ORCPT + 99 others); Fri, 5 Feb 2021 11:13:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233510AbhBEQJL (ORCPT ); Fri, 5 Feb 2021 11:09:11 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37ADBC061786 for ; Fri, 5 Feb 2021 09:50:54 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id a16so3942125plh.8 for ; Fri, 05 Feb 2021 09:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=8LdcV8DMgciJSckP8og9DY1KpzD/dHjlqzcgElgAVXM=; b=o26e66MUJ9hLAu9jrOp/+vQ/wqpT3vSn+OAqARm2Dr9nuJ9x0cpajYYgM/JZwGijHM amM2qTGshvMv9EP2EC42ryZgdh7/NhUxkeSOEkF7SuoSyH8sbTij9rUcrPdB5wz/Go59 je0R+HE+os02G5T5NbJ8vNA7OHm6CemIB5WVstzjKJyXlmVYSrI5P6N5NKZm1kw2pFEi 9PtA/Qmue6lAc1/NLPbkCpEH+WoTL+jFiCE7Z4wO4goZKDqk7tjWs8fdfozVd7iwAgTx baE2v9c7cFtOI8MQp61kF5cqiNRqWYKVaM4ipyBiorzEX7V48JJeY7n6FsVLCCNVgS2h 4Rsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8LdcV8DMgciJSckP8og9DY1KpzD/dHjlqzcgElgAVXM=; b=FFUZmPwwrGqyZkTAjX/KB6ztsKVf9oc/tUd35FapeEnByICHQNw1l1IpzfeY/LQ4xR VN2DlIpZE8VkSpsCxXccdtJ+9wLaScoZOgVOvpHkUY2uXnD/JqGvsGs0bu/Zw155eo/1 7vEkQMGVS8Bl/Rc+j5M5YU6kHtkrL8hHWOS3ENiYhlZ5ZU7+kQXgDt+t0Go5oDeyxK8U 7fdehjOQe12KSZCKgl/8yOwUng6HNqAwgp+xQUrgvpYZvsaTvvuxaoCg5VWIUjYlQg9A ezb09Rnj2oF31tLevrNH9MJLtbnZJwYOhzK436D11HSLOFotQjNbv6Wh8BNnndnlw6aU jBiw== X-Gm-Message-State: AOAM530BGTubZokdfI37M0xJYoWvIkVEmpU6wThcS7/MwU14pU50kXsR QAQ+8Jj6vB8P9YhGTNHs7xW/LbQsRDyR9w== X-Received: by 2002:a17:90a:a084:: with SMTP id r4mr5138668pjp.190.1612547453595; Fri, 05 Feb 2021 09:50:53 -0800 (PST) Received: from google.com ([2620:15c:f:10:d169:a9f7:513:e5]) by smtp.gmail.com with ESMTPSA id a6sm9445934pfr.43.2021.02.05.09.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 09:50:52 -0800 (PST) Date: Fri, 5 Feb 2021 09:50:46 -0800 From: Sean Christopherson To: Yu Zhang Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org Subject: Re: [PATCH] KVM: x86/MMU: Do not check unsync status for root SP. Message-ID: References: <20210116002100.17339-1-yu.c.zhang@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210116002100.17339-1-yu.c.zhang@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 16, 2021, Yu Zhang wrote: > In shadow page table, only leaf SPs may be marked as unsync. > And for non-leaf SPs, we use unsync_children to keep the number > of the unsynced children. In kvm_mmu_sync_root(), sp->unsync > shall always be zero for the root SP, hence no need to check it. > > Signed-off-by: Yu Zhang > --- > arch/x86/kvm/mmu/mmu.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 6d16481a..1a6bb03 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3412,8 +3412,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; > > spin_lock(&vcpu->kvm->mmu_lock); Looks good. To make this less scary and more obviously correct, maybe move the the WARN on !PG_LEVEL_4K into kvm_unsync_page() instead of having the WARN in its sole caller, and add a WARN in mmu_sync_children()? diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 86af58294272..bc8ee05bb3d3 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 root shadow page + * should never be unsyc'd. + */ + WARN_ON_ONCE(sp->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);