Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2853808rdh; Mon, 30 Oct 2023 09:29:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXDk2C7NwS/3oUykhq9TB0DON7qwp1Jj2XNxuTpSBiWqf/OtcWg4Q09MTLqHQQzhgknn4H X-Received: by 2002:a05:6a20:7aa7:b0:180:de1d:b93e with SMTP id u39-20020a056a207aa700b00180de1db93emr210471pzh.28.1698683342822; Mon, 30 Oct 2023 09:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698683342; cv=none; d=google.com; s=arc-20160816; b=BCrzZiF4MkX8s3ys09ODwrXJBOBN+WAvixO4dwbQtZKV2psoxt5X13nPiZK0SGwA6K Tax24vlN4fKkniQ/b7I63Du+fetc4tO6Q2ES/IQ9/AIOBBI8yLVgbL3kWb7r8h7WIip0 3Fpm8lg4LFCJqUYYsJLx8JfSf2ZgOSsn7njI4tAqmHyZeVze6l5ncbz78V5ivcc/UOvj 2WQCfiyoZ8e9/IUBPXaxfqE1scm1l+zAru3Q9Fnq6RIjzltrIi1G6I3Kve4ZYk4I44My RXmVChf3zLLznxIirnfoPMOVhoDBDOfSyzKqO6B+1G3JLS8lZMIugCo2NrQKro0cbAuO HxLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=QJRzUGi0crPAdF+PsGr4fd82XBsUf26/RqsTLoK6Cc8=; fh=9GjpMzJz+uuhn19uB36EwSK3xE6lNesC+Xo4sskdlZ8=; b=A6xIACDBlA62kYT2I1Mvvk9wh19PkdKaRx4881fszLe/fxv9BB2yc3itmz0pZzsNQS LIGSoawVYC9H8j1Yhj0t9knZ6ccwmDGMJACnsWe0QRH/GTrA5wI86nHpgmbSn0K2YcLV Ja2r6ZyWm3oqrndWCEzZLmzICLNVAtFkO0Y5yPyOEz+cAQzuMrT0aZEiuimPIeW7593j FJRD2nPBEe5GIB2nQ2NdGZxmmMTaGKYkkNKQJUjTasL19bVtjRIQOGjCMLzY4M8SCkvu AhLLREr/OfWrGenoiFdghsUhMEva2a5Nrv8ydAV/WmOa+qRpwBK3exkDwvo552vVqB73 cOqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="PzDdow5/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h63-20020a638342000000b00585a6bdce46si5222958pge.308.2023.10.30.09.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 09:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="PzDdow5/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DA04980A4ADC; Mon, 30 Oct 2023 09:28:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233182AbjJ3Q2s (ORCPT + 99 others); Mon, 30 Oct 2023 12:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjJ3Q2r (ORCPT ); Mon, 30 Oct 2023 12:28:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72969DB for ; Mon, 30 Oct 2023 09:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698683277; 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:autocrypt:autocrypt; bh=QJRzUGi0crPAdF+PsGr4fd82XBsUf26/RqsTLoK6Cc8=; b=PzDdow5/Wb2YXgvu5Iime0LPp5xVYoWEfI6LnNKBDrY+fgcjqDnTNtER1Q/TyOIzW17SX3 Yav9ta0/6t1/oXJAQge7v3G2ijuel5JQUxYw7eI0+amUFBm1xBuQwrlMh5bz2aY0AVsbs4 MgBsNJZedzOvLJQo+UJjGD6yqyCJ4sk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-OR5uKCWlNr2M6j70bt9zIg-1; Mon, 30 Oct 2023 12:27:56 -0400 X-MC-Unique: OR5uKCWlNr2M6j70bt9zIg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-407d3e55927so32545495e9.1 for ; Mon, 30 Oct 2023 09:27:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698683275; x=1699288075; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QJRzUGi0crPAdF+PsGr4fd82XBsUf26/RqsTLoK6Cc8=; b=awLMl4ZFAaQfMaCXQObpYTzNK0uP7mMlCy70IDVMke/5KIAb/Z2C9LTOgJq1rIfATO WvBcfEMx2+mDlTv+zfTQ87dnrNO5EF2+B2wgZhRapzcGkggNRSqbpWDRS+sLoQsFcsl9 CFEpY0OIuX1bnpFgVb61vCGl2CDS3zUL4NAoiZU5ucZeEdFcaQVKaaS6hHQGsVaZ3D6E hWRunI4ljFKWAKoaCVScHBJ2Y+Y+GUAemJ2dra35IUF0Yg9a19S4xShWcFzZB/7iGVuY LzcRoWzU9aloar15Iz+mDPq8bPQzPjPrMX+4G1tIA5JBH32a8M1N3kjOBuIcMcUmkpZn pdqw== X-Gm-Message-State: AOJu0Ywbjocs8q0YW28VF2NVwbU94oyq4GLslO+TWYmz5fG3dNAbQb/P eNRI/4XEDZ/CuE1JBDPzY5qo7HokoFm9X78knHt1SprcLgkFLyf1UZ144vUNQDnDMpDbVZm/rWC jmWBzCQ5TJX/zVERa2zGgaboh X-Received: by 2002:a05:600c:5204:b0:408:3f61:cb4f with SMTP id fb4-20020a05600c520400b004083f61cb4fmr7847792wmb.23.1698683274959; Mon, 30 Oct 2023 09:27:54 -0700 (PDT) X-Received: by 2002:a05:600c:5204:b0:408:3f61:cb4f with SMTP id fb4-20020a05600c520400b004083f61cb4fmr7847757wmb.23.1698683274613; Mon, 30 Oct 2023 09:27:54 -0700 (PDT) Received: from [192.168.1.174] ([151.81.68.207]) by smtp.googlemail.com with ESMTPSA id u18-20020a05600c19d200b00401b242e2e6sm13160177wmq.47.2023.10.30.09.27.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Oct 2023 09:27:53 -0700 (PDT) Message-ID: Date: Mon, 30 Oct 2023 17:27:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v13 02/35] KVM: Assert that mmu_invalidate_in_progress *never* goes negative Content-Language: en-US To: Sean Christopherson , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8?= =?UTF-8?Q?n?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-3-seanjc@google.com> From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptwLEgTEd3Fo UdhAQyRXGYO8oROiuh+RZ1lXp6AQ4ZjoyH8WLfT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shR+vMY3i3Ip0e41zKx0CvlAhMOo6otaHmcxr35sWq1Jk tLkbn3wG+fPQCVudJJECvVQ//UAthSSEklA50QtD2sBkmQ14ZryEyTHQ+E42K3j2IUmOLriF dNr9NvE1QGmGyIcbw2NIVEBOK/GWxkS5+dmxM2iD4Jdaf2nSn3jlHjEXoPwpMs0KZsgdU0pP JQzMUMwmB1wM8JxovFlPYrhNT9MAEQEAAcLBMwQYAQIACQUCVEJx7gIbDAAKCRB+FRAMzTZp sadRDqCctLmYICZu4GSnie4lKXl+HqlLanpVMOoFNnWs9oRP47MbE2wv8OaYh5pNR9VVgyhD OG0AU7oidG36OeUlrFDTfnPYYSF/mPCxHttosyt8O5kabxnIPv2URuAxDByz+iVbL+RjKaGM GDph56ZTswlx75nZVtIukqzLAQ5fa8OALSGum0cFi4ptZUOhDNz1onz61klD6z3MODi0sBZN Aj6guB2L/+2ZwElZEeRBERRd/uommlYuToAXfNRdUwrwl9gRMiA0WSyTb190zneRRDfpSK5d usXnM/O+kr3Dm+Ui+UioPf6wgbn3T0o6I5BhVhs4h4hWmIW7iNhPjX1iybXfmb1gAFfjtHfL xRUr64svXpyfJMScIQtBAm0ihWPltXkyITA92ngCmPdHa6M1hMh4RDX+Jf1fiWubzp1voAg0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: <20231027182217.3615211-3-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 30 Oct 2023 09:28:58 -0700 (PDT) On 10/27/23 20:21, Sean Christopherson wrote: > Move the assertion on the in-progress invalidation count from the primary > MMU's notifier path to KVM's common notification path, i.e. assert that > the count doesn't go negative even when the invalidation is coming from > KVM itself. > > Opportunistically convert the assertion to a KVM_BUG_ON(), i.e. kill only > the affected VM, not the entire kernel. A corrupted count is fatal to the > VM, e.g. the non-zero (negative) count will cause mmu_invalidate_retry() > to block any and all attempts to install new mappings. But it's far from > guaranteed that an end() without a start() is fatal or even problematic to > anything other than the target VM, e.g. the underlying bug could simply be > a duplicate call to end(). And it's much more likely that a missed > invalidation, i.e. a potential use-after-free, would manifest as no > notification whatsoever, not an end() without a start(). Reviewed-by: Paolo Bonzini > Signed-off-by: Sean Christopherson > --- > 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 0524933856d4..5a97e6c7d9c2 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -833,6 +833,7 @@ void kvm_mmu_invalidate_end(struct kvm *kvm, unsigned long start, > * in conjunction with the smp_rmb in mmu_invalidate_retry(). > */ > kvm->mmu_invalidate_in_progress--; > + KVM_BUG_ON(kvm->mmu_invalidate_in_progress < 0, kvm); > } > > static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, > @@ -863,8 +864,6 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, > */ > if (wake) > rcuwait_wake_up(&kvm->mn_memslots_update_rcuwait); > - > - BUG_ON(kvm->mmu_invalidate_in_progress < 0); > } > > static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,