Received: by 2002:a4f:b056:0:0:0:0:0 with SMTP id m22csp1419264ivi; Fri, 2 Oct 2020 09:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0OLgXwTG7HCOENmp2rAeTd1GPhjU3tYk6A8OSSO6b0ExMMz0uTd4XQLidFl0INZWoElMG X-Received: by 2002:a05:6402:142c:: with SMTP id c12mr3397690edx.41.1601656639328; Fri, 02 Oct 2020 09:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601656639; cv=none; d=google.com; s=arc-20160816; b=l91d/slnA6Qd1jBxHWLp1P9MqK77HvZx4lfH3wI16aYL7LeWND0ZYKZnbzizWfBegQ +CW6ojQr7nxt2tSeBrPvN6A40Nocc+haNh6uMsZ+6t7d/U6VAPSK4KX7d+i4aRmH81sA f+rH3xO/JnznobBc371v4GpAoJ0YBKYT29mIGBc7iDiBbyeaJyuhgNnIijzictyM+Kuo B0Y/aislq3UoBmlr4EdBPyAfYjgMPAFxnsrl9QZjujsn1j33ZD1TnJs2/nF3DeR8Cqt9 zMaVTsgdMN41pVGjlQvtSYv7RefV6Hqci5SeuWod8qpz9+bvX9VdsC9/i7M4QRq+LESy aGSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5SVFNy1oh9mYZaze1/AxVhEs3Bssp/B/apnHoAiZ48k=; b=UVq/Q9EpNlV1FJSRs59Y+azNNWXuahnX3RMjHFKOfq994s7W1xD3xR//hAqkuYvssv cOlhrTByG4UxClUZVB1ITNW4PuNrsTLuKyhGKFwBqe0mhKiIhyJGrkOfZPmW38B8wmTg 7Jli56GwMUS0uuEZ7y63iCNTX5AaoGVYstIB9bgZI+Xzi6RAQi47ibRu23/xutwfwToX c7j6vV3xUdBX97Y/9/qFORrQXbIwmh71w2LpgvDv5Ox18yBC3+G+5IyFZ3BgAi735ix+ jZaM4kb5N6aEYCy70DGko+3UqMEuJ/rNpk6/QjfeRTKY4JOLh8gwHWkltXxPpPj0V138 AGjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=al9p87J+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id v22si631604ejj.27.2020.10.02.09.36.55; Fri, 02 Oct 2020 09:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=al9p87J+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2387789AbgJBQdy (ORCPT + 99 others); Fri, 2 Oct 2020 12:33:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgJBQdy (ORCPT ); Fri, 2 Oct 2020 12:33:54 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A38DC0613D0 for ; Fri, 2 Oct 2020 09:33:54 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id l24so2283471edj.8 for ; Fri, 02 Oct 2020 09:33:54 -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=5SVFNy1oh9mYZaze1/AxVhEs3Bssp/B/apnHoAiZ48k=; b=al9p87J+2nxtEoL5mL7fBOjKzyzi+xyjcQuKCNKeqVDl0CLxxJqeQrgM+2eINtL1M2 Igo7k0g13Xh6JcyPO1fMYP4UYEnWIuNRX/otgCKdIM6AcbtuisbtWyOKlZWQNFmzabAB DbsgUPEDX4Nfu4Xo9kym9GzzWqDB4xnvK3NtaSHB52+/WW4gKkBh+p6SzsiBX+UpMkRN oBvj4bysMC4KMW9Xtsi/hWzpOLbROGKs0kiAFruMJKLIujz9XcjgYPLvgj0JG/vyW/kH Q19nHdVl6lA1ohWvA4O/AZdDHtOf7u+z6vlEUNUPk4unObMEw7SZp2AhF71zhoyr0opR OgsQ== 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=5SVFNy1oh9mYZaze1/AxVhEs3Bssp/B/apnHoAiZ48k=; b=mQm7S0mqQq/sAU+XgFFN5Xqk2Vj00SVI6rI4blkGC5vrqPS/UxI2dq5xPaVFYYYCS3 +54eL+vz1FA28BlncYi2S/G3QdPFTsfumVR8Gai3yoq8pNNTVjHqEsLs0NeOHxm8Rlpx T7YovSH0jqU82ieJ7jp7JpmS8nAe5qxTosTkxlijK1KmMuN3P36QOMVdom8wnqyt0Of/ VpqMj33J6yaMpuryIZ2IPe+zI3DPr5tZL+2vbvEGXEVTtgraGe3RfL2expytKm7QcHXg Dze6NasLl1dQliMW+HuetX0miITYPJJZo4qeqqhb6+CwJ53zR38UQeZZ2eszvZEj7T/k xkZg== X-Gm-Message-State: AOAM532SWUzPTyhZXCbSkYuQ1mT0KG8M0SxvNW7+ONqhjoioiSP95Jfs yKEajqqhwM34EcGWGUinJYAAdZ91B3Rk4/kToRgcyi0vRLDPZQ== X-Received: by 2002:a50:fe98:: with SMTP id d24mr3157020edt.223.1601656432627; Fri, 02 Oct 2020 09:33:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jann Horn Date: Fri, 2 Oct 2020 18:33:26 +0200 Message-ID: Subject: Re: [PATCH 1/2] mmap locking API: Order lock of nascent mm outside lock of live mm To: Michel Lespinasse Cc: Andrew Morton , linux-mm , LKML , "Eric W . Biederman" , Mauro Carvalho Chehab , Sakari Ailus , Jeff Dike , Richard Weinberger , Anton Ivanov , linux-um@lists.infradead.org, Jason Gunthorpe , John Hubbard Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 2, 2020 at 11:18 AM Michel Lespinasse wrote: > On Thu, Oct 1, 2020 at 6:25 PM Jann Horn wrote: > > Until now, the mmap lock of the nascent mm was ordered inside the mmap lock > > of the old mm (in dup_mmap() and in UML's activate_mm()). > > A following patch will change the exec path to very broadly lock the > > nascent mm, but fine-grained locking should still work at the same time for > > the new mm. > > To do this in a way that lockdep is happy about, let's turn around the lock > > ordering in both places that currently nest the locks. > > Since SINGLE_DEPTH_NESTING is normally used for the inner nesting layer, > > make up our own lock subclass MMAP_LOCK_SUBCLASS_NASCENT and use that > > instead. > > > > The added locking calls in exec_mmap() are temporary; the following patch > > will move the locking out of exec_mmap(). > > Thanks for doing this. > > This is probably a silly question, but I am not sure exactly where we > lock the old MM while bprm is creating the new MM ? I am guessing this > would be only in setup_arg_pages(), copying the args and environment > from the old the the new MM ? If that is correct, then wouldn't it be > sufficient to use mmap_write_lock_nested in setup_arg_pages() ? Or, is > the issue that we'd prefer to have a killable version of it there ? We're also implicitly locking the old MM anytime we take page faults before exec_mmap(), which basically means the various userspace memory accesses in do_execveat_common(). This happens after bprm_mm_init(), so we've already set bprm->vma at that point. > Also FYI I was going to play with these patches a bit to help answer > these questions on my own, but wasn't able to easily apply them as > they came lightly mangled (whitespace issues) when I saved them. Uuugh, dammit, I see what happened. Sorry about the trouble. Thanks for telling me, guess I'll go back to sending patches the way I did it before. :/ I guess I'll go make a v2 of this with some extra comment about where the old MM is accessed, as Jason suggested, and without the whitespace issues?