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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 564D8C433DB for ; Thu, 11 Mar 2021 01:20:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD70364FA6 for ; Thu, 11 Mar 2021 01:20:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD70364FA6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 613C88D025F; Wed, 10 Mar 2021 20:20:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EAAA8D0250; Wed, 10 Mar 2021 20:20:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 465508D025F; Wed, 10 Mar 2021 20:20:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 2B1698D0250 for ; Wed, 10 Mar 2021 20:20:10 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DA4B63635 for ; Thu, 11 Mar 2021 01:20:09 +0000 (UTC) X-FDA: 77905837338.07.6270467 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf23.hostedemail.com (Postfix) with ESMTP id B6512A0000FA for ; Thu, 11 Mar 2021 01:20:08 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id t29so13267998pfg.11 for ; Wed, 10 Mar 2021 17:20:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0ZkhEPXNpdhd7EV60+uxO7+s4em392s377dpq/Miruo=; b=EBBjJgEO35RWOBXTBuXClQYEGc1+xzuOlvc/7LHXyZG4dDzcfOuaRT7myDPt+gjRfT U3LNnOU7ejYFJXHfrysZ8b0p0SG1KWnwDTJ/lIdAstRg0sRN3KalQI6pcHXILu5rbskc 9RoiLLBUQHxjN5hcSpt0TvVmIN91IZYjAxB4tYIpzN+X7qpvXQ5AAOlcSmK5Jcxnkak7 Z6ffKi41Ho/GJUKO2u4bxgBoeNLYgZJHISf+JOBy2Q0+ytL7OOUL/bm5ThCTVxsa6QWz LFzGXy1QD36ZUtTL+uAxePmi1n7l1NgFoOVUFxzNUHzhDkGHKimDIgoTBIDJ5D7r4cZw NxZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0ZkhEPXNpdhd7EV60+uxO7+s4em392s377dpq/Miruo=; b=D0HUxPw8qvageMRIJRXWNCgiAjbRArhk325KKU7Jmx3WTpe1dMYJpbzg4BSujROu0G qW/Ck42N3F8ddYQi6e9w/3yh5QqZHv+/GCTghikKZLuhdpXmyJRt2Yh3qMum/J6zF+QR uiM04wvA2ksG0wuz/dYje6jW8SDEqTEYSJyeQfzV1JAdpYrOL04V+boByrWgKIeC36I7 YR/hhrWuuU4R4mpBqjbNh09trZYPRvdKBVV2HjltRyJVHt/mCJl4M87ljLZxKXJ1sQlo q4olven2It0qJWBpbJ5P42a20F+ruhLcbtgx3XGXp37V2ScYowtwqYRgb1aFRlStZdqI x+uw== X-Gm-Message-State: AOAM531M/0aSu5zHoMO3liVSVv70rj91m+DsB3+7hepRoJzoYpiRdK+S k6yzuQzfU2yHmt0c6jKCS+E2Dg== X-Google-Smtp-Source: ABdhPJy4oEPMcOroAyrlq+q9+5qM78TC1A3maqhY2DW8jxRIhcTfNtx+tLADENdj5/ze8zkDolTo+g== X-Received: by 2002:a63:ce18:: with SMTP id y24mr5100261pgf.246.1615425608150; Wed, 10 Mar 2021 17:20:08 -0800 (PST) Received: from google.com ([2620:15c:f:10:c4e3:28f1:33df:26ba]) by smtp.gmail.com with ESMTPSA id 35sm638412pgr.14.2021.03.10.17.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 17:20:07 -0800 (PST) Date: Wed, 10 Mar 2021 17:20:01 -0800 From: Sean Christopherson To: Jason Gunthorpe Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Rientjes , Ben Gardon , Michal Hocko , =?iso-8859-1?B?Suly9G1l?= Glisse , Andrea Arcangeli , Johannes Weiner , Dimitri Sivanich Subject: Re: [PATCH] mm/oom_kill: Ensure MMU notifier range_end() is paired with range_start() Message-ID: References: <20210310213117.1444147-1-seanjc@google.com> <20210311002807.GQ444867@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210311002807.GQ444867@ziepe.ca> X-Stat-Signature: 8fckonddimk53nbz3xbgtd57u5z1tzwr X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B6512A0000FA Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail-pf1-f173.google.com; client-ip=209.85.210.173 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615425608-126295 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Mar 10, 2021, Jason Gunthorpe wrote: > On Wed, Mar 10, 2021 at 01:31:17PM -0800, Sean Christopherson wrote: > > Invoke the MMU notifier's .invalidate_range_end() callbacks even if one > > of the .invalidate_range_start() callbacks failed. If there are multiple > > notifiers, the notifier that did not fail may have performed actions in > > its ...start() that it expects to unwind via ...end(). Per the > > mmu_notifier_ops documentation, ...start() and ...end() must be paired. > > No this is not OK, if invalidate_start returns EBUSY invalidate_end > should *not* be called. > > As you observed: > > > The only in-kernel usage that is fatally broken is the SGI UV GRU driver, > > which effectively blocks and sleeps fault handlers during ...start(), and > > unblocks/wakes the handlers during ...end(). But, the only users that > > can fail ...start() are the i915 and Nouveau drivers, which are unlikely > > to collide with the SGI driver. > > It used to be worse but I've since moved most of the other problematic > users to the itree notifier which doesn't have the problem. > > > KVM is the only other user of ...end(), and while KVM also blocks fault > > handlers in ...start(), the fault handlers do not sleep and originate in > > KVM will have its mmu_notifier_count become imbalanced: > > static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, > const struct mmu_notifier_range *range) > { > kvm->mmu_notifier_count++; > > static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, > const struct mmu_notifier_range *range) > { > kvm->mmu_notifier_count--; > > Which I believe is fatal to kvm? These notifiers certainly do not only > happen at process exit. My point about the process dying is that the existing bug that causes mmu_notifier_count to become imbalanced is benign only because the process is being killed, and thus KVM will stop running its vCPUs. > So, both of the remaining _end users become corrupted with this patch! I don't follow. mn_hlist_invalidate_range_start() iterates over all notifiers, even if a notifier earlier in the chain failed. How will KVM become imbalanced? The existing _end users never fail their _start. If KVM started failing its start, then yes, it could get corrupted. But my assumption/expection is that, if KVM were to ever reject _start, it would be responsible for knowing that it must also skip _end. I'm happy to kick that one down the road though, as I can't think of a scenario where KVM would _need_ to sleep. > I've tried to fix this before, the only thing that seems like it will > work is to sort the hlist and only call ends that have succeeded their > starts by comparing pointers with <. > > This is because the hlist can have items removed concurrently under > SRCU so there is no easy way to compute the subset that succeeded in > calling start. > > I had a prior effort to just ban more than 1 hlist notifier with end, > but it turns out kvm on ARM uses two all the time (IIRC) > > > Found by inspection. Verified by adding a second notifier in KVM > > that > > AFAIK it is a non-problem in real life because kvm is not mixed with > notifier_start's that fail (and GRU is dead?). Everything else was > fixed by moving to itree. > > Jason