Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3933753pxb; Mon, 8 Feb 2021 04:01:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDgmR6VIpS0If45nEpz7yJZFcXxofzTm6Hpnfl/zu3NP8a0TOj1wq2cl3sGmpKPhLjSeWu X-Received: by 2002:a50:e0c1:: with SMTP id j1mr16672003edl.253.1612785672321; Mon, 08 Feb 2021 04:01:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612785672; cv=none; d=google.com; s=arc-20160816; b=BgJVLXtXcO+VfcvAV2PfCEhBZ6Wh4u9dpvvbRwX1WF9zaiolJJkIuBdNOBRjh/oN9u 71p8djz7/2o5W23lr15mt7xRJnK4zjziHlCzZ44Gkz5Qcj3bUy98Y+2k8cJolzj59giw 8qI7TVhHyRFmx+dih44gcm/I3lnrWviaWZ+TmltcbEvjmfBlCWHwxBaC01CPgaeo8RNz 70XPql3G1KONG0n50kduQcfT/V23/p1eb2nEpuwglm0IJXzCUP/Kdr/sAnccdxYNzA/G cHcvsQ9QLuF+LjqwvHevxGTRtAjRELLqHGk6baU/aNiO23tNYK91jqiXG9mv7tBSESdo lfcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=FRVdxrImUiPLKR5+ep3bKLlsb+cGXPiY/H7oj/ZApPg=; b=iDBekLdvnJQZ/GHwNIJXTbKkKkCf4iqeXMwAI/cVe4vixRiVs79TAdevvJKfm7Sxau HDhqZ05MoZ1gOdqhzveSzHt/FXUdWxz857M+DHJBVO91BHWPnv8ehCNrNdX2lx/Vbjtz AAfOJ9K5fh+k46GTlL0bBKJDA37tueknuXRNHrgEYZ/eU7mZ5FthXDVM/i4U5z4rNQCa ItbdRdk1teYcP4vCEztOTudIrLkgBfeTAhaVNyOhvplL1az/c6Uo0T8JoqFouMO+2lKE qJInWaIBVoE2nOQsq8yRyKs6YAONEQSAFyBvvSFLEGW/qlK/N+nKXisGlLlG6VvKpqPL obJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LOazIzJg; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si11409410eds.609.2021.02.08.04.00.47; Mon, 08 Feb 2021 04:01:12 -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=@redhat.com header.s=mimecast20190719 header.b=LOazIzJg; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232528AbhBHL6v (ORCPT + 99 others); Mon, 8 Feb 2021 06:58:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31447 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233366AbhBHLif (ORCPT ); Mon, 8 Feb 2021 06:38:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612784226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FRVdxrImUiPLKR5+ep3bKLlsb+cGXPiY/H7oj/ZApPg=; b=LOazIzJgzmLvAvsAmIMuut8hm8rvmQf4PnrH3xyXdZHjKUbMYhU3FSkXWHIcuezoUp2V0h VQfWJqiPRhn0R39aEe9Q+z/7VoHmjl8xEKGTOUjvWTIhot/hsmbGvz599AI6fB9chMZRZn G4RcwxD8cUCJGwTqKmZWj6tzochdAF0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-135-5S4OaCv6MrmK_XUhePQMPw-1; Mon, 08 Feb 2021 06:37:05 -0500 X-MC-Unique: 5S4OaCv6MrmK_XUhePQMPw-1 Received: by mail-wr1-f71.google.com with SMTP id n15so12719029wrv.20 for ; Mon, 08 Feb 2021 03:37:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FRVdxrImUiPLKR5+ep3bKLlsb+cGXPiY/H7oj/ZApPg=; b=fRMk0C9s8hn9xmxYth67chqWkz1BNTzy0iMhreMjzVy80Q16hmoCpcmkAo0aqmR/bo T68OT0RUwQ9o4Xd6PUkmwRbIcRnEdA7j1vm8JL7dsjif5Qw5gdixcwYgV5hJWPTexfy4 fCi7QAO8m9HVKNkgdgtYAPd/YW6PtWnv2FBwr4YDWhdMMDqqHMmEJy2LEyBQfjFNmSkg uHdBZ+BY4Pc6BCenKyjQD1QoPoEAQnl+FKeoCXyMQ5P3Pc7pQGGyFZpWtVzZmboUsMen KoDQLeBGhr6jZxa0JMrexLlAGwRloRGbnFz9puVh7j2YmWattJ8TdmhmJQnKbKaRdYdB Umyg== X-Gm-Message-State: AOAM5317XbxdnUvJgIwFofBJQhHEX6SBIcAM2gqE59KwuyTBvVUkWk2J hcu3FC5gJkTmwxOjtoDkPAY111S9874IU1l07TXnYYwynT/KaQjT32Nkq8+Sfm/pCerMj+ciyrJ TpQliBCfsOwlacsCO0LIIE6L7 X-Received: by 2002:a5d:4e4c:: with SMTP id r12mr19404677wrt.354.1612784224008; Mon, 08 Feb 2021 03:37:04 -0800 (PST) X-Received: by 2002:a5d:4e4c:: with SMTP id r12mr19404650wrt.354.1612784223796; Mon, 08 Feb 2021 03:37:03 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:63a7:c72e:ea0e:6045? ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id t7sm13799049wrv.75.2021.02.08.03.36.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Feb 2021 03:37:02 -0800 (PST) Subject: Re: [PATCH v2] KVM: x86/MMU: Do not check unsync status for root SP. To: Yu Zhang , 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 References: <20210207122254.23056-1-yu.c.zhang@linux.intel.com> From: Paolo Bonzini Message-ID: <671ae214-22b9-1d89-75cb-0c6da5230988@redhat.com> Date: Mon, 8 Feb 2021 12:36:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210207122254.23056-1-yu.c.zhang@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/02/21 13:22, 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. Instead, a warning inside mmu_sync_children() is added, in > case someone incorrectly used it. > > Also, clarify the mmu_need_write_protect(), by moving the warning > into kvm_unsync_page(). > > Signed-off-by: Yu Zhang > Signed-off-by: Sean Christopherson This should really be more of a Co-developed-by, and there are a couple adjustments that could be made in the commit message. I've queued the patch and I'll fix it up later. Paolo > --- > Changes in V2: > - warnings added based on Sean's suggestion. > > 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 86af582..c4797a00cc 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(sp->unsync); > + > while (mmu_unsync_walk(parent, &pages)) { > bool protected = false; > > @@ -2502,6 +2508,8 @@ int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn) > > 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); >