Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2958329imm; Fri, 24 Aug 2018 08:11:00 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdae5acjnCqGPqUvD2okjyRPT9P5KjtLe96I+zZu01wEbxnYaxqvidzILDTQtOJfVPeYJu+z X-Received: by 2002:a63:8241:: with SMTP id w62-v6mr2022491pgd.230.1535123460089; Fri, 24 Aug 2018 08:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535123460; cv=none; d=google.com; s=arc-20160816; b=qLazh5aawon4fUDQsehT171v/dHSxzlNQXhlstpLm6Ied6pLJsLEDVltUUPK0Q04Xg 0nEjkJ0HG2L1yl+ks/JTsl7atCymPbqhG7KmwvI/E7vd5623R01DUGzQ/19Ml1Irzddu EWN0QTY4rFJGIOQFU5H4OzwraKgwpXkW8KLESkXdzTXPMzjhwnPos+JJ6r/hEYb81OLo /Zfkk5akxKSjeWyF5bMuo9wrTv22diP9qLFJBrThgQOBBJZqWJ0xVYYPin/+CZ2ikfdW g5Ejqbj/cQi9Ej9VY4DBTs4NjpmCzUvrUQH8tDn05YnwICv2OStTWTN0Mh6FwCOB2BOW Vx6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=zANxwAT7hROqWzjlaiwJ6Bjyt9OhOtoZxtJd3BmTcTc=; b=U+qxwhH3TBpenfGRl0uEh6MusQGAMauqRmn8dbbU8jdt+AeOQ/e/AaaVGue9grcsf9 +x3jHxzofoNooACnfVtrvFLrp3Vei9JwVHvCXtiz4PSeCQoBZmMESTMluBBxgw7kn/oD JB72NxxesFD7sAf3vBtcbv496wzM8e1vxtKK6yVSTuCOI2Q3SOA+ZOeA/zqpZTfYLxtL O+LaW8Xhyu0kO457Qchmy+dBJx9qk6i2FVetFkPyDovmwLDai/tcGUpoNZqaD54ff86N 0h9qBkgIG8eUz2EnaAOLG+Y2vwtUGxDGq5t/yZLsHiOHc+lkVvh6NtNMs5B6aK5XaTZS CvzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15-v6si6784879plr.470.2018.08.24.08.10.45; Fri, 24 Aug 2018 08:11:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728014AbeHXSoH (ORCPT + 99 others); Fri, 24 Aug 2018 14:44:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34134 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726374AbeHXSoH (ORCPT ); Fri, 24 Aug 2018 14:44:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C39887DAC9; Fri, 24 Aug 2018 15:09:02 +0000 (UTC) Received: from redhat.com (ovpn-125-224.rdu2.redhat.com [10.10.125.224]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9863510073B5; Fri, 24 Aug 2018 15:09:00 +0000 (UTC) Date: Fri, 24 Aug 2018 11:08:59 -0400 From: Jerome Glisse To: Michal Hocko Cc: Christian =?iso-8859-1?Q?K=F6nig?= , kvm@vger.kernel.org, Radim =?utf-8?B?S3LEjW3DocWZ?= , Tetsuo Handa , Joonas Lahtinen , Sudeep Dutt , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Andrea Arcangeli , "David (ChunMing) Zhou" , Dimitri Sivanich , Jason Gunthorpe , linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, David Airlie , Doug Ledford , David Rientjes , xen-devel@lists.xenproject.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Leon Romanovsky , Rodrigo Vivi , Boris Ostrovsky , Juergen Gross , Mike Marciniszyn , Dennis Dalessandro , LKML , Ashutosh Dixit , Alex Deucher , Paolo Bonzini , Andrew Morton , Felix Kuehling Subject: Re: [PATCH] mm, oom: distinguish blockable mode for mmu notifiers Message-ID: <20180824150858.GB4244@redhat.com> References: <20180716115058.5559-1-mhocko@kernel.org> <8cbfb09f-0c5a-8d43-1f5e-f3ff7612e289@I-love.SAKURA.ne.jp> <20180824113248.GH29735@dhcp22.suse.cz> <20180824115226.GK29735@dhcp22.suse.cz> <20180824120339.GL29735@dhcp22.suse.cz> <20180824123341.GN29735@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180824123341.GN29735@dhcp22.suse.cz> User-Agent: Mutt/1.10.0 (2018-05-17) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 24 Aug 2018 15:09:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 24 Aug 2018 15:09:03 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jglisse@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 24, 2018 at 02:33:41PM +0200, Michal Hocko wrote: > On Fri 24-08-18 14:18:44, Christian K?nig wrote: > > Am 24.08.2018 um 14:03 schrieb Michal Hocko: > > > On Fri 24-08-18 13:57:52, Christian K?nig wrote: > > > > Am 24.08.2018 um 13:52 schrieb Michal Hocko: > > > > > On Fri 24-08-18 13:43:16, Christian K?nig wrote: > > > [...] > > > > > > That won't work like this there might be multiple > > > > > > invalidate_range_start()/invalidate_range_end() pairs open at the same time. > > > > > > E.g. the lock might be taken recursively and that is illegal for a > > > > > > rw_semaphore. > > > > > I am not sure I follow. Are you saying that one invalidate_range might > > > > > trigger another one from the same path? > > > > No, but what can happen is: > > > > > > > > invalidate_range_start(A,B); > > > > invalidate_range_start(C,D); > > > > ... > > > > invalidate_range_end(C,D); > > > > invalidate_range_end(A,B); > > > > > > > > Grabbing the read lock twice would be illegal in this case. > > > I am sorry but I still do not follow. What is the context the two are > > > called from? > > > > I don't have the slightest idea. > > > > > Can you give me an example. I simply do not see it in the > > > code, mostly because I am not familiar with it. > > > > I'm neither. > > > > We stumbled over that by pure observation and after discussing the problem > > with Jerome came up with this solution. > > > > No idea where exactly that case comes from, but I can confirm that it indeed > > happens. > > Thiking about it some more, I can imagine that a notifier callback which > performs an allocation might trigger a memory reclaim and that in turn > might trigger a notifier to be invoked and recurse. But notifier > shouldn't really allocate memory. They are called from deep MM code > paths and this would be extremely deadlock prone. Maybe Jerome can come > up some more realistic scenario. If not then I would propose to simplify > the locking here. We have lockdep to catch self deadlocks and it is > always better to handle a specific issue rather than having a code > without a clear indication how it can recurse. Multiple concurrent mmu notifier, for overlapping range or not, is common (each concurrent threads can trigger some). So you might have multiple invalidate_range_start() in flight for same mm and thus might complete in different order (invalidate_range_end()). IIRC this is what this lock was trying to protect against. I can't think of a reason for recursive mmu notifier call right now. I will ponder see if i remember something about it. Cheers, J?r?me