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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 C235BC433DF for ; Sun, 18 Oct 2020 01:29:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2C13B214DB for ; Sun, 18 Oct 2020 01:29:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q94WZqkL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C13B214DB 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 57D0F6B005D; Sat, 17 Oct 2020 21:29:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52EE96B0068; Sat, 17 Oct 2020 21:29:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41BE16B006E; Sat, 17 Oct 2020 21:29:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 12FEE6B005D for ; Sat, 17 Oct 2020 21:29:02 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96C7B8249980 for ; Sun, 18 Oct 2020 01:29:01 +0000 (UTC) X-FDA: 77383312482.06.plant29_58031c42722a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 705311022508D for ; Sun, 18 Oct 2020 01:29:01 +0000 (UTC) X-HE-Tag: plant29_58031c42722a X-Filterd-Recvd-Size: 5271 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Sun, 18 Oct 2020 01:29:00 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id y16so7224941ljk.1 for ; Sat, 17 Oct 2020 18:29:00 -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=AoozY7xMWvoy65obt5Ou1wz1SBc/nwOL07qM4ibitso=; b=Q94WZqkL22RbrJy/uswl3e0u6xBD1nwP6KlgnqfzcgSyhSXxLRpQSLI5raHxUu84qm weNZx9GOu4VF3Nf7fUYlVoPki4Su+5zEMRfjIkp18wpvimSPlda97uNJUD4SUQTqg8c1 UPvE28gEQWJRIYIEIcbPTCWotcrksiWjE2kOoXSi99YVytvWfFbM/ZtJ+oDePdn9oiEm ZV8zKzBDP+tfseyPtK+aHrBtcZVdnk2p4DNwuUgbmFtANNePoArSl820KZRPcCzfveec AIWm0Nkq4i1nQ2TDbpqii55qaq3JTeXL7avoH91NQgitoZNjgFlG9HHNs0GDIeLt+Zr2 bs1A== 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=AoozY7xMWvoy65obt5Ou1wz1SBc/nwOL07qM4ibitso=; b=krR4EsYX0YFksY/ODrOXsPIVhoxNkcnjWeorr1T2qOrGXG55KkKRNSYskWUxU2beEU KiFMCJz7lcLD6hlE0Mz0MTbDN2nFSqsosmOI5f70gI6ZTnSkjBrq9Oo1/cKGvqM+Uihw VHTQugrErozO3RPCZ2f0WcAGHdNu3a9UX6/73y5c8EwYYlB1AwauIy+MU1Q9CwTO5LDT 2Ae/haT8lNnVjm3mcwK9syO44BKDyLwczE0klnBQsYlq8lLWRTBT6RezsQlQ9lbpFVyH z8CFlcuDtjBZmOddRMxtixftpRlmpof7AhNDCtrBB8siw75Vq6z0VhswtDshGHBAFdjm bpsw== X-Gm-Message-State: AOAM530fVl73Y2uvwRdHqcVy9gn/+WMjASIMRTkF0EinHMW+auVA+B/1 MiA4sQgJQXIo7K0MHQClj4C6SgJL2r7YuruXUtwO4Q== X-Google-Smtp-Source: ABdhPJy7y9dEAktO0ZXhwOLu/KjOxCk43zbbxjPkVURA4tKgdVhpJlJxV+2CcoSS/v7F5305r7EOEz882fSKkxA4Rgs= X-Received: by 2002:a2e:b6cf:: with SMTP id m15mr3795448ljo.74.1602984539161; Sat, 17 Oct 2020 18:28:59 -0700 (PDT) MIME-Version: 1.0 References: <20201017161314.88890b87fae7446ccc13c902@linux-foundation.org> <20201017231418.twQriq6_i%akpm@linux-foundation.org> In-Reply-To: <20201017231418.twQriq6_i%akpm@linux-foundation.org> From: Jann Horn Date: Sun, 18 Oct 2020 03:28:32 +0200 Message-ID: Subject: Re: [patch 14/40] mm/gup: assert that the mmap lock is held in __get_user_pages() To: Andrew Morton , Linus Torvalds Cc: "Eric W. Biederman" , Jason Gunthorpe , John Hubbard , Linux-MM , Mauro Carvalho Chehab , mm-commits@vger.kernel.org, Sakari Ailus , Michel Lespinasse Content-Type: text/plain; charset="UTF-8" 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 Sun, Oct 18, 2020 at 1:14 AM Andrew Morton wrote: > From: Jann Horn > Subject: mm/gup: assert that the mmap lock is held in __get_user_pages() > > After having cleaned up all GUP callers (except for the atomisp staging > driver, which currently gets mmap locking completely wrong [1]) to always > ensure that they hold the mmap lock when calling into GUP (unless the mm > is not yet globally visible), add an assertion to make sure it stays that > way going forward. Please hold this patch until the replacement for the previous patch in the series (original patch mmap-locking-api-dont-check-locking-if-the-mm-isnt-live-yet, which you are already holding back, and which is replaced by the series https://lore.kernel.org/linux-mm/20201016225713.1971256-1-jannh@google.com/ "Broad write-locking of nascent mm in execve") has gone into the mm tree. Otherwise I believe that this mmap_assert_lock() will cause new lockdep warnings in places like copy_strings(). (Going forward, is there something I should do differently if a similar issue happens again with a series of patches that has already landed in the mm tree but where, after further discussion, parts should be replaced?) > [1] https://lore.kernel.org/lkml/CAG48ez3tZAb9JVhw4T5e-i=h2_DUZxfNRTDsagSRCVazNXx5qA@mail.gmail.com/ > > Link: https://lkml.kernel.org/r/CAG48ez1GM==OnHpS=ghqZNJPn02FCDUEHc7GQmGRMXUD_aKudg@mail.gmail.com > Signed-off-by: Jann Horn > Reviewed-by: Jason Gunthorpe > Acked-by: Michel Lespinasse > Cc: "Eric W . Biederman" > Cc: John Hubbard > Cc: Mauro Carvalho Chehab > Cc: Sakari Ailus > Signed-off-by: Andrew Morton > --- > > mm/gup.c | 2 ++ > 1 file changed, 2 insertions(+) > > --- a/mm/gup.c~mm-gup-assert-that-the-mmap-lock-is-held-in-__get_user_pages > +++ a/mm/gup.c > @@ -1027,6 +1027,8 @@ static long __get_user_pages(struct mm_s > struct vm_area_struct *vma = NULL; > struct follow_page_context ctx = { NULL }; > > + mmap_assert_locked(mm); > + > if (!nr_pages) > return 0; > > _