Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp2426264pja; Thu, 26 Mar 2020 15:10:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuuSCFNSILLlm4v3uMlKA+EsQ2Jjx3RqFR8CTYzIaltLJO5C/mxTG+xeCn5bAF0j4Q2rYMV X-Received: by 2002:aca:55ce:: with SMTP id j197mr1915966oib.84.1585260624971; Thu, 26 Mar 2020 15:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585260624; cv=none; d=google.com; s=arc-20160816; b=05xVnf7lnzds+X5oQd0deNPBRWWxbU7unwCVJdpUB4Q/jBqnTH6NXRcYCfZF3LJwZH EBESH8SPwx8gCo7MNfFjb6rYYgqudW8JNLEHb5kQz3tDJUv/P2mhnIBtv6wfVtwyDjyC SozKVIlfTsbi6+6W2IEVQLJfpA4mOD+cwT3MYZIUhOpdQKyOkqxDCfUYBwx5BAnaOHIZ x4Ph/IphniEMez+Im/thU5kwfeKhdgOzRyAi2Fadaqxkts96u3l5uucRega8IJ+tdJFM IPioTuEZ7K/5ym4JZQN9ZVeeSh80mCHALxcyfvELQQdXfNpvZtVtZ7K6fRvvBAgi4HV6 n70A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=kn2WIN8QO5W0o3GwWRwvCngYE1iUlvZV7DjAfzZNk4Y=; b=sxIT7JIFTeqiibLATLyEVmvM3O4Bj6+g23zatgSwj39+kJIcaHAiyLUfLfCl4s1o92 nDFBVkR8gXd7Q0cMQKq2QrNZIMwlOxD0tXys2dleDd5IIQfBF+XjxYbkEONXt95zBDyV Qs/Xo66+jkGfBM0yGmTCXbI6GcrurdwJZ2GJYTwVk2OFgTGBoqDjbiIaZrtxjJGUm1U3 NGvmOL16DJiNBvTqaSQM8TcBCahu4UlRq4oYsNmvRwLd68eoMz4noze2UaI+CnLnFyHd /ZLpaXWs6h3SofxYnxAiaf33m5pd/BOVwaX//r408qG8a6u/sbGDLQ/Mocvkj4T8hbp0 Kk+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SKw+PWvC; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si1574841oib.201.2020.03.26.15.10.11; Thu, 26 Mar 2020 15:10:24 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=SKw+PWvC; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727655AbgCZWJ2 (ORCPT + 99 others); Thu, 26 Mar 2020 18:09:28 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:36669 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727541AbgCZWJ2 (ORCPT ); Thu, 26 Mar 2020 18:09:28 -0400 Received: by mail-yb1-f196.google.com with SMTP id i4so3504925ybl.3 for ; Thu, 26 Mar 2020 15:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kn2WIN8QO5W0o3GwWRwvCngYE1iUlvZV7DjAfzZNk4Y=; b=SKw+PWvCw12GGiUc78HNQOrdcBLILk9gtKEUUBLb5YgvnMEBi9QQlBJw/px2g4zxkb lVy4BzBzdo6zSNY9ReR388SUKDBrjGHX12X7HjcGACPWYgF+MmAji9E8oY2bSVqZQHUQ aDJmKRwQkXvzXv2kU+1/5jBylz001PwVYBu7J73fzTbuAE6E9t00F1gYYzMqd4CyuJxI 1Dp1Cp0T1cZlI22IYQ7A6m0MmC9UfSCFOrBQeuEYoSxB9/fjRy5fFfNRYP5/dY0Dj/zN EdL//hQQnI8e0RXG2vhOKhqokNsWyMAMv7vJtJH+HMmYIMHKqHgh+GaYwit4MCRI+57U 3Qpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kn2WIN8QO5W0o3GwWRwvCngYE1iUlvZV7DjAfzZNk4Y=; b=bor1SYfTZ1Xgn7zG/lLXs7MUZNqzxz7HBNQAhju9RnaqrNRLwkrlpwPkzrHRppknVW 6M81e5XZE8P4KI3e9X9ijTti00aH4uDLURv9EzY5vRZqxwwe9UCF0uCjIGjoV9iT75+S /Ds06qPeA286A0szmTUJPX92UoZA5L2NdNfaKSrpAlXfefDlN+qsWgW248q4AGXKmDgW f/ffQ9VlTdUI5Z1PEf5zsoTll41ciDrK8m+hWQdY4lzmjdWLCR6tfMPjCFxIiCPv/kjF KvOk6ilILCyEWBEK5WfqqieVk45j8BY9lrRQI7weHl6pj6w6FbyUQWv6wIi1yBYMMDRF zDWg== X-Gm-Message-State: ANhLgQ0F0oVsDqU7Q3k1jalPObZkkZIzevHTeb+whWtriGVxUthSNwi8 MmhvBLBRvFTbHfNCB0dO7q8MNmauSYWPx8jS45wRAw== X-Received: by 2002:a25:ccd0:: with SMTP id l199mr16214330ybf.446.1585260566392; Thu, 26 Mar 2020 15:09:26 -0700 (PDT) MIME-Version: 1.0 References: <20200326070236.235835-1-walken@google.com> <20200326070236.235835-2-walken@google.com> <20200326175644.GN20941@ziepe.ca> <20200326180621.GK22483@bombadil.infradead.org> <20200326180916.GL22483@bombadil.infradead.org> In-Reply-To: <20200326180916.GL22483@bombadil.infradead.org> From: Michel Lespinasse Date: Thu, 26 Mar 2020 15:09:13 -0700 Message-ID: Subject: Re: [PATCH 1/8] mmap locking API: initial implementation as rwsem wrappers To: Matthew Wilcox Cc: Jason Gunthorpe , Andrew Morton , linux-mm , LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I don't think we strongly need an API for such assertions at this point. There are actually a number of them (mostly the lockdep form) being handled in the last patch renaming the mmap_sem field. If a new form of lock is introduced in the future, it is doable to implement it in such a way that lockdep assertions will work on it (I have that working in my range locking patchset). For a range lock you would probably want to add a new API anyway so that the assert can verify that the specific range is locked, but IMO there is no strong justification for new assertion APIs until we get there. If there is no opposition to replacing rwsem_is_locked with lockdep_assert_held, then I think that is workable. mmap_is_locked() only has 5 call sites, so that's not a very large change. On Thu, Mar 26, 2020 at 11:09 AM Matthew Wilcox wrote: > > On Thu, Mar 26, 2020 at 11:06:21AM -0700, Matthew Wilcox wrote: > > On Thu, Mar 26, 2020 at 02:56:44PM -0300, Jason Gunthorpe wrote: > > > On Thu, Mar 26, 2020 at 12:02:29AM -0700, Michel Lespinasse wrote: > > > > > > > +static inline bool mmap_is_locked(struct mm_struct *mm) > > > > +{ > > > > + return rwsem_is_locked(&mm->mmap_sem) != 0; > > > > +} > > > > > > I've been wondering if the various VM_BUG(rwsem_is_locked()) would be > > > better as lockdep expressions? Certainly when lockdep is enabled it > > > should be preferred, IMHO. > > > > > > So, I think if inlines are to be introduced this should be something > > > similar to netdev's ASSERT_RTNL which seems to have worked well. > > > > > > Maybe ASSERT_MMAP_SEM_READ/WRITE/HELD() and do the VM_BUG or > > > lockdep_is_held as appropriate? > > > > I'd rather see lockdep_assert_held() used directly rather than have > > a wrapper. This API includes options to check for it beind explicitly > > held for read/write/any, which should be useful. > > ... oh, but that requires naming the lock, which we're trying to get > away from. > > I guess we need a wrapper, but yes, by all means, let's level it up > to put the VM_BUG_ON inside the wrapper, as that means we can get the > mm dumped everywhere, rather than just the few places that have done > VM_BUG_ON_MM instead of plain VM_BUG_ON. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.