Message ID | 20231105163040.14904-5-pbonzini@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2207418vqu; Sun, 5 Nov 2023 08:33:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuW+mgkyCmyDCf7C9FUza2bOV+EaQ1XVnKIjage20Mjhh9cEBXbZoPHWr9ETsteOPzp1ZF X-Received: by 2002:a17:90b:50c:b0:280:4829:52d6 with SMTP id r12-20020a17090b050c00b00280482952d6mr18751328pjz.29.1699201991034; Sun, 05 Nov 2023 08:33:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699201991; cv=none; d=google.com; s=arc-20160816; b=wlOBEbDZXCrUkp4eogSxbhe7bNDo/meCxjxFQehqb+fl+dZCQriGkIEYGY7YEjA0V1 mR8qyVpaDsEl11KIuDGnGpteONQ6riKsanaXSKUMjnPBztM58HUpoGbgCQWwmeMei5mP V1bgIlXTCgt3FRkyv24ray2g0NKjPOcH5b5qX6TqLMtzjVOqvodAUWldX3h88g59lAsw YWPlIPsQFJTk2ByEMHdmfMMGiSsGenN1TxAwgv3CG+wOuG4F0e9STQM0OAoAev7mpwuE C1RwkawfQJTSVZqMd6eqaILn/NIf++qDwn1Btp/yuEyg4RPa3YSAhjtMrMmyWqJGQFde 0acQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ts/ge04a2OEPPQrJdr5ialSNwsy6vefm6EL3ylmuQZA=; fh=HrMuB0qA2qw4RqBwyiyN+RBlGw+Ob1hcALwHW/PphXs=; b=ugwMX1KKlUDJMAEwXad12AuFS+KgWI1X1bDLkJze7dzcJE8De+0cHmTGG3l9DhhVTd nNulu/y2a6oheaRUr89gjajocyxu+WbANSFsQAjgcip+L9uxuVmJow6He8txGvf3aq7X Ge4uXmYELoiIPR/YglHieJ4EaeWL0ggOPWs1xWA2al2M4irvmRC7GvWDX0mTV6uBemOd 7ZHaVASMt9xP9zThBPv7ckYejDalhjzUsbhfs9HGl81uKHhTft0T0SvbcgiDqjxYLMwN eiCF0mGVm+yA8K8ojZRQMbr3yAa+sV071/7sTZCyOY+s7ddqkpwbLF4HIAdIlW3tT4sN 8emQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XPLcUrwy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u2-20020a17090341c200b001cc4efcc852si6770763ple.427.2023.11.05.08.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:33:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XPLcUrwy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id AB1DC8057B02; Sun, 5 Nov 2023 08:33:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbjKEQcS (ORCPT <rfc822;heyuhang3455@gmail.com> + 34 others); Sun, 5 Nov 2023 11:32:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbjKEQcJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 5 Nov 2023 11:32:09 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DD66100 for <linux-kernel@vger.kernel.org>; Sun, 5 Nov 2023 08:31:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699201884; 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=ts/ge04a2OEPPQrJdr5ialSNwsy6vefm6EL3ylmuQZA=; b=XPLcUrwy2KTfH1NMMrnmlvV+iklSb8p+AHM6jEnH1eV9ICTFOey3lmbYxgnst7jM0qhij/ wpRBGmbSSySkYV41dYjDKvY+X5ETW7wPb1unUNoqe1gahUyAO4GLPCjjNaMi4XR+t4b5j3 BTkfh1cw3lSMLHBEfaQeCxGFMSp7zJU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-o8kgVV1dP5GILnrn4TVhRA-1; Sun, 05 Nov 2023 11:31:21 -0500 X-MC-Unique: o8kgVV1dP5GILnrn4TVhRA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3AD20101A529; Sun, 5 Nov 2023 16:31:19 +0000 (UTC) Received: from avogadro.redhat.com (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E18E2166B26; Sun, 5 Nov 2023 16:31:12 +0000 (UTC) From: Paolo Bonzini <pbonzini@redhat.com> To: Paolo Bonzini <pbonzini@redhat.com>, Marc Zyngier <maz@kernel.org>, Oliver Upton <oliver.upton@linux.dev>, Huacai Chen <chenhuacai@kernel.org>, Michael Ellerman <mpe@ellerman.id.au>, Anup Patel <anup@brainfault.org>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Sean Christopherson <seanjc@google.com>, Alexander Viro <viro@zeniv.linux.org.uk>, Christian Brauner <brauner@kernel.org>, "Matthew Wilcox (Oracle)" <willy@infradead.org>, Andrew Morton <akpm@linux-foundation.org> 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 <xiaoyao.li@intel.com>, Xu Yilun <yilun.xu@intel.com>, Chao Peng <chao.p.peng@linux.intel.com>, Fuad Tabba <tabba@google.com>, Jarkko Sakkinen <jarkko@kernel.org>, Anish Moorthy <amoorthy@google.com>, David Matlack <dmatlack@google.com>, Yu Zhang <yu.c.zhang@linux.intel.com>, Isaku Yamahata <isaku.yamahata@intel.com>, =?utf-8?q?Micka=C3=ABl_Sala?= =?utf-8?q?=C3=BCn?= <mic@digikod.net>, Vlastimil Babka <vbabka@suse.cz>, Vishal Annapurve <vannapurve@google.com>, Ackerley Tng <ackerleytng@google.com>, Maciej Szmigiero <mail@maciej.szmigiero.name>, David Hildenbrand <david@redhat.com>, Quentin Perret <qperret@google.com>, Michael Roth <michael.roth@amd.com>, Wang <wei.w.wang@intel.com>, Liam Merwick <liam.merwick@oracle.com>, Isaku Yamahata <isaku.yamahata@gmail.com>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Subject: [PATCH 04/34] KVM: WARN if there are dangling MMU invalidations at VM destruction Date: Sun, 5 Nov 2023 17:30:07 +0100 Message-ID: <20231105163040.14904-5-pbonzini@redhat.com> In-Reply-To: <20231105163040.14904-1-pbonzini@redhat.com> References: <20231105163040.14904-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Spam-Status: No, score=-1.4 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:33:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781742426901129992 X-GMAIL-MSGID: 1781742426901129992 |
Series |
KVM: guest_memfd() and per-page attributes
|
|
Commit Message
Paolo Bonzini
Nov. 5, 2023, 4:30 p.m. UTC
From: Sean Christopherson <seanjc@google.com> Add an assertion that there are no in-progress MMU invalidations when a VM is being destroyed, with the exception of the scenario where KVM unregisters its MMU notifier between an .invalidate_range_start() call and the corresponding .invalidate_range_end(). KVM can't detect unpaired calls from the mmu_notifier due to the above exception waiver, but the assertion can detect KVM bugs, e.g. such as the bug that *almost* escaped initial guest_memfd development. Link: https://lore.kernel.org/all/e397d30c-c6af-e68f-d18e-b4e3739c5389@linux.intel.com Signed-off-by: Sean Christopherson <seanjc@google.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fuad Tabba <tabba@google.com> Tested-by: Fuad Tabba <tabba@google.com> Message-Id: <20231027182217.3615211-5-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- virt/kvm/kvm_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9cc57b23ec81..5422ce20dcba 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1358,9 +1358,16 @@ static void kvm_destroy_vm(struct kvm *kvm) * No threads can be waiting in kvm_swap_active_memslots() as the * last reference on KVM has been dropped, but freeing * memslots would deadlock without this manual intervention. + * + * If the count isn't unbalanced, i.e. KVM did NOT unregister its MMU + * notifier between a start() and end(), then there shouldn't be any + * in-progress invalidations. */ WARN_ON(rcuwait_active(&kvm->mn_memslots_update_rcuwait)); - kvm->mn_active_invalidate_count = 0; + if (kvm->mn_active_invalidate_count) + kvm->mn_active_invalidate_count = 0; + else + WARN_ON(kvm->mmu_invalidate_in_progress); #else kvm_flush_shadow_all(kvm); #endif