From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69F3CC433E0 for ; Mon, 21 Dec 2020 18:33:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38AFA22D49 for ; Mon, 21 Dec 2020 18:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727098AbgLUSdY (ORCPT ); Mon, 21 Dec 2020 13:33:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51275 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbgLUSdX (ORCPT ); Mon, 21 Dec 2020 13:33:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608575516; 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=K9FeuGmQgyv7B/8HpfW7JWOxHabUVt0zhGvyltedBTw=; b=gGcP59z+4tbX7Hii9YN6Rw03XoG1iagZmMMWgHm7UaDUfLJ4RGehJU42tbymdBAi3H0Afh jvf8GcinZ5orwS/i5aUJ2LyW91Mr099gV2lqKcec0L0YV4k8oDtt+gd0iGylVLvP7G5Zcd eODSsQJMIaeRCrkogGMvkUH5fPfeWzw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-660rqlbBOTGtpmNlQGWSAg-1; Mon, 21 Dec 2020 13:31:55 -0500 X-MC-Unique: 660rqlbBOTGtpmNlQGWSAg-1 Received: by mail-wm1-f71.google.com with SMTP id s185so5382765wme.0 for ; Mon, 21 Dec 2020 10:31:54 -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=K9FeuGmQgyv7B/8HpfW7JWOxHabUVt0zhGvyltedBTw=; b=Q2s0L77x72GRoAdwyPKoSwzT+58iUhxFOmYMXXeOwMo188iiU1DTeNayuiRqFrXBvT fdLb3v2/cuYFRPAJ8tBb3QPzUmMZA0pp7GR3HqjsPWKd1v7y6Kr9nsSsEQc/glwM7uGQ XhDfuAW88rpYTKqbjdt6ucZTSYLuJSQkM7XzaRxEdcrnk+7zkBSWdzFbUOPJs5DaNo/9 vbd/oBOr1fpYo5dTQAkXr22wNpP7Efk4WSg7V6KJW/xrdkOUOt2hs6aZc+jBH08ITHpi /wImdLOyklyE3oDGFTCILIF45Bb3v2ePITg/ACFGb7ZmguUTglETu/C+q+rKtjPNUhHb m2iQ== X-Gm-Message-State: AOAM5314R4dW861g4mI8uy2xKKW9qgFpV7URnlTIeDcuHgzMOY8ozHKK tZ+WLCXIHNwepXw7klcIrzfb99z4+h6WPEirGDI7ZNqyVyiUVdIQWyU7hytX9ZorLKRPneZitX1 sp+895peFJhi4JEFXrOp3p4Sb X-Received: by 2002:a5d:62c8:: with SMTP id o8mr20536536wrv.51.1608575513891; Mon, 21 Dec 2020 10:31:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSeg8I2cfYyaGyf0kM/XC//Jnj5R+Jg+aS41jlXlZ40yng81myXCqLuP6DCmIHPLCq7CfQHA== X-Received: by 2002:a5d:62c8:: with SMTP id o8mr20536508wrv.51.1608575513589; Mon, 21 Dec 2020 10:31:53 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u83sm11568628wmu.12.2020.12.21.10.31.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Dec 2020 10:31:52 -0800 (PST) Subject: Re: [PATCH V3] kvm: check tlbs_dirty directly To: Lai Jiangshan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , Lai Jiangshan , stable@vger.kernel.org References: <20201217154118.16497-1-jiangshanlai@gmail.com> From: Paolo Bonzini Message-ID: <8c5f3503-860d-b3c0-4838-0a4a04f64a47@redhat.com> Date: Mon, 21 Dec 2020 19:31:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201217154118.16497-1-jiangshanlai@gmail.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 17/12/20 16:41, Lai Jiangshan wrote: > From: Lai Jiangshan > > In kvm_mmu_notifier_invalidate_range_start(), tlbs_dirty is used as: > need_tlb_flush |= kvm->tlbs_dirty; > with need_tlb_flush's type being int and tlbs_dirty's type being long. > > It means that tlbs_dirty is always used as int and the higher 32 bits > is useless. We need to check tlbs_dirty in a correct way and this > change checks it directly without propagating it to need_tlb_flush. > > Note: it's _extremely_ unlikely this neglecting of higher 32 bits can > cause problems in practice. It would require encountering tlbs_dirty > on a 4 billion count boundary, and KVM would need to be using shadow > paging or be running a nested guest. > > Cc: stable@vger.kernel.org > Fixes: a4ee1ca4a36e ("KVM: MMU: delay flush all tlbs on sync_page path") > Signed-off-by: Lai Jiangshan > --- > Changed from V1: > Update the patch and the changelog as Sean Christopherson suggested. > > Changed from v2: > don't change the type of need_tlb_flush > > virt/kvm/kvm_main.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 2541a17ff1c4..3083fb53861d 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -482,9 +482,8 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, > kvm->mmu_notifier_count++; > need_tlb_flush = kvm_unmap_hva_range(kvm, range->start, range->end, > range->flags); > - need_tlb_flush |= kvm->tlbs_dirty; > /* we've to flush the tlb before the pages can be freed */ > - if (need_tlb_flush) > + if (need_tlb_flush || kvm->tlbs_dirty) > kvm_flush_remote_tlbs(kvm); > > spin_unlock(&kvm->mmu_lock); > Queued, thanks. Paolo