Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp880329rdb; Wed, 1 Nov 2023 05:47:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAfjy83sVOGPKlC6fcwR7Yg6vsL8k7b3eStRS1C9u/OvrdSmqISkI63y9XgNgJqw7UswGz X-Received: by 2002:a05:6a20:da88:b0:174:af85:954b with SMTP id iy8-20020a056a20da8800b00174af85954bmr17040636pzb.22.1698842838852; Wed, 01 Nov 2023 05:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698842838; cv=none; d=google.com; s=arc-20160816; b=R+vJhdHQgnpE9rRo/AX9cXb0fdFmL2cY9GJVu9zELztb63XgUcBoFsRY/C8nnW0p4P TzPNj0BQWyV7PaPiGwHh06P+yuurg2aSqnXRAY3X5GJDVNdg925tQCSSybPBRIKKrsDc fLfBZVySardBXAI0GXZpksARrDzpCEoxq2kmMTT3d/eMUamtKmhnBzzFV/AxQDUXzlRU v6GpHbJKh+9RofPkwxyWYG6IHn76ZlRh5KL39DInJmYTcxr/HhS7x1+oqK5HNfKMvQkw KW3xRaDHrh4SYkPGtQutkjIXAQPRzSe7mF0uGKWB1TbkjXJCgnqskE9DMS83M+9M32bn HaMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=i1rvjvqySA8gfoAJ2h4xCVn6r+FVikEwY0ryqbt6qgE=; fh=xK+wiX2TTq7O2X4TlNj4MXVc7h6ma8eyuy1Ur/RMLHE=; b=Ycllj/GbpaRCtesq9NpqzBZ/8fHiIdbubVW4RaV8F8bpEVbqvECJlInfGujYU00YOC udC3AcAyTjW+LzrIiACglF0yraKT+gzW4CpMN6Kj5BAu+Glr6sumGpHWInj0aOcdCu2D Yq/04PpRv6fajwwOQ39426s7Jw8YBpMej/wAr1stntEtj98waI1ZtUzVT35MQplt51yy Ro+1/ObCjFLcB98umoAU7MZzsMoVRcGzE2bokK2g27cnImQfFS8Ybou6e4iOMksayujn k9P715aCsvbF7/v/gcfZF1CTFOWS1r901VRr+JzjFMd9nfL0e6HoBvc41RKwgIx4zWNB hjjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tkZvBXUU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k11-20020aa788cb000000b0068fdeb84453si1623558pff.265.2023.11.01.05.47.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:47:18 -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=@google.com header.s=20230601 header.b=tkZvBXUU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 36EB980A18F1; Wed, 1 Nov 2023 05:47:16 -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 S1343681AbjKAMrI (ORCPT + 99 others); Wed, 1 Nov 2023 08:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235166AbjKAMrG (ORCPT ); Wed, 1 Nov 2023 08:47:06 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C155183 for ; Wed, 1 Nov 2023 05:47:02 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-672096e0e89so21767716d6.1 for ; Wed, 01 Nov 2023 05:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698842822; x=1699447622; darn=vger.kernel.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=i1rvjvqySA8gfoAJ2h4xCVn6r+FVikEwY0ryqbt6qgE=; b=tkZvBXUU99Y6DGHqlV7CmraXsSkiESOXpXjHCqzaKtwOaO25j+k+op3nuWbLqAzLJv msff5vgM4xSZGonWvuWKFT/X2NUlwOri+dw2rbRjgxDXjPkef20VwIeful3u/iFk+ZEf tvWyN8ZIVEdnb2ds+/NaelJwumxeiLs924jPtosp40oDqOC1W8+ebv8ACD69AmjtNOn/ U2uu/w6nzTzmwhfFI37qaV2Gu0NWrErmtjh4mvJgEYX5mh/eBhRmL/2p0lRRVZeGvDfI KctXwUfDd6Yof1leqTQuWhsPISmIpLC/BGFxNNCTKyjMni9XTcTJZwY5LdOWf7FXWTV9 Wptw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698842822; x=1699447622; 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=i1rvjvqySA8gfoAJ2h4xCVn6r+FVikEwY0ryqbt6qgE=; b=YUK3ngP+LRF2ESSb42kFDsaL/vbeHy6P6Wxe9UpmyA26Owh388BV8BdBUPkCuZOemC X9S4SAdCXOubGPZIE7k4cEqBOSk/LUIoLXQ84zpfd4Mlt4+k4vZlTLLYe/iteNjZGv5h 9jcpO86gtvzBDzS4bTkka2ePOdQ27cAew8wNZQrs6y7ji3XFkd3g7KM2Dc4tcL96MDIG eNS7ykgJi7WmOmOmvTehfTHu0EQF9RI33pedBDaTM/VtyFZdd/BEvnSBFbccrOBYSnND eXea7GW82Dy4f2xFNkOi6PwNWxHFdrFHxQC1tOyxKEiaY0TCBp/6KoDU8BZZ5sLaE27g XEIg== X-Gm-Message-State: AOJu0YwXCDOogjL0+tHM7FxezitucP4PSQm9WAT5Xcm333rpgRVKAkG2 aIrrVsYF4VROqA1cn0q21q1BB+2hylcro8kfuToX3Q== X-Received: by 2002:ad4:5de9:0:b0:65d:31e:b810 with SMTP id jn9-20020ad45de9000000b0065d031eb810mr19758846qvb.34.1698842821613; Wed, 01 Nov 2023 05:47:01 -0700 (PDT) MIME-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-3-seanjc@google.com> In-Reply-To: <20231027182217.3615211-3-seanjc@google.com> From: Fuad Tabba Date: Wed, 1 Nov 2023 12:46:25 +0000 Message-ID: Subject: Re: [PATCH v13 02/35] KVM: Assert that mmu_invalidate_in_progress *never* goes negative To: Sean Christopherson Cc: Paolo Bonzini , 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 , 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 , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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]); Wed, 01 Nov 2023 05:47:16 -0700 (PDT) On Fri, Oct 27, 2023 at 7:22=E2=80=AFPM 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 th= e > 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 t= o > anything other than the target VM, e.g. the underlying bug could simply b= e > 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(). > > Signed-off-by: Sean Christopherson > --- Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Cheers, /fuad > 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 *m= n, > @@ -863,8 +864,6 @@ static void kvm_mmu_notifier_invalidate_range_end(str= uct 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, > -- > 2.42.0.820.g83a721a137-goog >