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 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23586C4332F for ; Wed, 1 Nov 2023 12:51:56 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=hY9LBBZh; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SL6Mt5htfz3cb8 for ; Wed, 1 Nov 2023 23:51:54 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=hY9LBBZh; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=google.com (client-ip=2607:f8b0:4864:20::f2e; helo=mail-qv1-xf2e.google.com; envelope-from=tabba@google.com; receiver=lists.ozlabs.org) Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4SL6Lz1Zfbz3bhc for ; Wed, 1 Nov 2023 23:51:06 +1100 (AEDT) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-66d0252578aso43233006d6.0 for ; Wed, 01 Nov 2023 05:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698843062; x=1699447862; darn=lists.ozlabs.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DytdUoCbq8poGHKLHOEtAO0D5dohgKyWvCysCxFt+wY=; b=hY9LBBZhWyrSrBbY80hgMFWtOTNFIoZFpyhnzjBMk2AaD3tiZixu7UzJL7b7/2KS3I 8j/bdgw2Namo/RP/QNr9VsoSBrvXDDVYgWhUjIQKnuVf27arryviWMNTzlnQonNQ5TTJ tkoeasAST5MD8Yt8dQ2/iWsDYBbwABwhPUZQd4sv1UKkPKTDKEL8PIr4V2FgA3xaq9NC 8w1uQ7BDy9PjrWJMTcK2LVLZzThaAnnYNGudSSP9GfoaclUUFGloVFxcvjLEK6d08skn iON+me527mxo3WD+sURuvMz5oOY4xqfLHmVRGjdOwcsG/RW83NGQBMDhjjirjqLJpTEh rPJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843062; x=1699447862; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DytdUoCbq8poGHKLHOEtAO0D5dohgKyWvCysCxFt+wY=; b=QSSJsMvFSaRu9CCMnND9WZaZ+Pg44HCqQZcfLwrOqYrOIk72PXOF8SrQRQ2XnVfx6y 5zRgpcC7ahc0AXtzIZI6cbyHCsEI6cHQ4zeP/BZaNINcUbGOD0mdpUkhZC3EBQEEVv7R YmJzfZ8muQRJzwPaG0YNEvnj2Wfv8kqhDSjHKB2I4/arYVmPIfnJEAgupfqoizAz+Y0r MLLr7BhUOcOK/SsHbOBV5IHs6xKjyakhYfhbrnl5ZiDF2COsEvoj7w3t9DuHgCCc4Z/M 2KkxzoVgvoJ7uKzLl7/ey+/rdPUiodoEbHzluv6iCL+xF2L+l03ytELi8XvDHd2Y4uo/ NJVQ== X-Gm-Message-State: AOJu0YzdJQvdba4dyoJxoDAaIPQ0ZS+oBMUEF90ta0EHUgKCEGvDIU5q r8TAMuH2Z+awCMnPyoD8L2p9jkPRrybZwzzB2+dk2w== X-Google-Smtp-Source: AGHT+IF4xR6L8cVnqFnyZjdEh5XAFhWOV7M0s6Xt9NyBBttGvtAf21ACAZmexGcVd+eTPklAY7PiFjol+SoHUZLf4NM= X-Received: by 2002:a05:6214:262e:b0:66f:bd35:e889 with SMTP id gv14-20020a056214262e00b0066fbd35e889mr16003984qvb.60.1698843062295; Wed, 01 Nov 2023 05:51:02 -0700 (PDT) MIME-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-5-seanjc@google.com> In-Reply-To: <20231027182217.3615211-5-seanjc@google.com> From: Fuad Tabba Date: Wed, 1 Nov 2023 12:50:26 +0000 Message-ID: Subject: Re: [PATCH v13 04/35] KVM: WARN if there are dangling MMU invalidations at VM destruction To: Sean Christopherson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chao Peng , linux-riscv@lists.infradead.org, Isaku Yamahata , Marc Zyngier , Huacai Chen , Xiaoyao Li , "Matthew Wilcox \(Oracle\)" , Wang , Vlastimil Babka , Yu Zhang , Maciej Szmigiero , Albert Ou , Michael Roth , Ackerley Tng , Alexander Viro , Paul Walmsley , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Isaku Yamahata , Christian Brauner , Quentin Perret , Liam Merwick , linux-mips@vger.kernel.org, Oliver Upton , David Matlack , Jarkko Sakkinen , Palmer Dabbelt , "Kirill A . Shutemov" , kvm-riscv@lists.infradead.org, Anup Patel , linux-fsdevel@vger.kernel.org, Paolo Bonzini , Andrew Morton , Vishal Annapurve , linuxppc-dev@lists.ozlabs.org, Xu Yilun , Anish Moorthy Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, Oct 27, 2023 at 7:22=E2=80=AFPM Sean Christopherson wrote: > > 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 an= d > 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@li= nux.intel.com > Signed-off-by: Sean Christopherson > --- Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Cheers, /fuad > 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 1a577a25de47..4dba682586ee 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1356,9 +1356,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 =3D 0; > + if (kvm->mn_active_invalidate_count) > + kvm->mn_active_invalidate_count =3D 0; > + else > + WARN_ON(kvm->mmu_invalidate_in_progress); > #else > kvm_flush_shadow_all(kvm); > #endif > -- > 2.42.0.820.g83a721a137-goog >