Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp562303rwb; Fri, 4 Aug 2023 18:28:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMfUAnYtww2c2pB+q3frxOiEZ3ADjtB2FpySV091a86LnyfBdQKLHjp3IjhgtfQQrymHNu X-Received: by 2002:a05:6808:8cb:b0:3a7:1e86:e83f with SMTP id k11-20020a05680808cb00b003a71e86e83fmr3874994oij.51.1691198890641; Fri, 04 Aug 2023 18:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691198890; cv=none; d=google.com; s=arc-20160816; b=ccNbPV/7qku9dk/unGNOY11L5YjdovB0F5Cyhs59AO504L+KyoOVMvmcuFMTRrI2hM WroylNUpbfm6eUZgkt9TVQhE3GsLHQ6tXuMdk3x+9MWvYHN9WPkGxJ1+RXdCXlGBEzFA QE9yPNb+K9baSI3BTXHsCUciuXk/GmEyR+CoBxxmOzToVr6e/G8KSUbzi2+Rdng0JtiK MHQt+JJAVK/v+O/wpkXspXIkPt1RNhTaebHXgQV4wp7qam5drA6lZQ1vPUSSUnL7QDN/ G2UmBzCQ6zzZvnCJdHK6CkQI8ngVG4G3Xh+Nt6SkCR/SLeplllSti8D2rZVFcTnWeA1M TkmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GE6BW9pFYdezUl7cDS0TzP1DYFsIzJQ0ypEfGdJ3TBg=; fh=EA2+NtHoz8bhR9VEETVqaRDZ02eDDQ8a+760cSOtB/M=; b=y+0FqzicZ+fhpdteaUNX97aM8iEgkOQf5CQ4l3C09o5Qu8++Fq1d4sv2ap1Wo7QTea KAIwHwE/PL4kNCf8KN0uj59io+TDOj/hDcz4uFvnwihcC680/3QIkkgUiMA2HPT5RNL8 H7qxWJQpwhSR+TtYQN0YzcjL3kOWrD2B+chi0zpphdcJoweo6FKSHnFW2B9jIZiFJocU 2/bLGtb2rabAzBAscindfntalkal4a6+CqV433x+dPw8C3FpCcdNSN2HowfiPgHKH2GK PnD7JUYKwNGulYSh+XfnGQnKSgUloOrFnwKL0p9QStiKV4LaunaOvqnSxLipWkrrMPOM slXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=h0TxxwCK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p16-20020a056a000a1000b006797c2c00besi2574452pfh.144.2023.08.04.18.27.31; Fri, 04 Aug 2023 18:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=h0TxxwCK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229798AbjHEAeY (ORCPT + 99 others); Fri, 4 Aug 2023 20:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjHEAeW (ORCPT ); Fri, 4 Aug 2023 20:34:22 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8044ED3 for ; Fri, 4 Aug 2023 17:34:21 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-d1fb9107036so2922858276.0 for ; Fri, 04 Aug 2023 17:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691195661; x=1691800461; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GE6BW9pFYdezUl7cDS0TzP1DYFsIzJQ0ypEfGdJ3TBg=; b=h0TxxwCKVye0DQdqW8QciL6a/cGS644vYZUx3RI0OE1671HBfkLOeCjBNqcVrLOU2b ycUmZSGLpA9J5ensM11f+iadX9Igk/HzJLsetwc9ly0gURsAFjMfewFY/ZbbuNvVegBO zzsxkPT9b50kkszDh+PkQ3GspK2tIZt+I3X+8usJTbDu2o7JkhwHvqL4jBShd4IfGcpl UvUXcNV5NlwO1ex/P6Q99K1X+l1eVkU1QU5hcPg4wm2SkhYzjGIIbU58/izBoxYFf7Y/ H2/yj5m5CuBBcYn7Gjr7Dd36TjaoDemXFlAk5O+znIBaWL3JFXYYXipgVBaiJa9ssh/c YgvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691195661; x=1691800461; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GE6BW9pFYdezUl7cDS0TzP1DYFsIzJQ0ypEfGdJ3TBg=; b=JusUepy1mbT7rKL+4i1sdNuGcq1AcT8mPS1qrKjQ+o42oh3oQSFdghND2pI3t5o2XK rfUTCLhc9Q+hCvHjXWRne9PJif41C7L9phmZpjiU6OtdooorgpKapZitgJhLaYs/sRnq LCGrKBUMoRrIdVyXz0W351ia5wroQ67x2FuPxWw2b1LN7te/wJNODhEejfiM0SKGRgWe CeVdLs3gMZXmhvKGm4W3kDGY0qxFQJfEpfBbsg5C6kOvrN9HMp3uVmbybblKz//Cfp2x UpX/tPNut0+RX0dFOoGazotUcNGXn0qYhFpvrAMzz3BxPxprHFLiW9h8528ZXSQRdKRI vh1Q== X-Gm-Message-State: AOJu0YwH8yLxa/RagD1vE4GomuarXhP2STzgKrqM13vQZF07fbs0i6pW ReH1G8y75wIH3JTrEjwbQxvxrDs64dDMhIK/6XClAw== X-Received: by 2002:a25:250c:0:b0:c14:68fd:6e30 with SMTP id l12-20020a25250c000000b00c1468fd6e30mr2908586ybl.16.1691195660786; Fri, 04 Aug 2023 17:34:20 -0700 (PDT) MIME-Version: 1.0 References: <20230708191212.4147700-1-surenb@google.com> <20230708191212.4147700-3-surenb@google.com> <20230804214620.btgwhsszsd7rh6nf@f> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 4 Aug 2023 17:34:06 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking To: Linus Torvalds Cc: Mateusz Guzik , akpm@linux-foundation.org, regressions@leemhuis.info, bagasdotme@gmail.com, jacobly.alt@gmail.com, willy@infradead.org, liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, regressions@lists.linux.dev, Jiri Slaby , =?UTF-8?Q?Holger_Hoffst=C3=A4tte?= , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 4, 2023 at 5:26=E2=80=AFPM Suren Baghdasaryan wrote: > > On Fri, Aug 4, 2023 at 5:15=E2=80=AFPM Linus Torvalds > wrote: > > > > On Fri, 4 Aug 2023 at 16:25, Mateusz Guzik wrote: > > > > > > I know of these guys, I think they are excluded as is -- they go > > > through access_remote_vm, starting with: > > > if (mmap_read_lock_killable(mm)) > > > return 0; > > > > > > while dup_mmap already write locks the parent's mm. > > > > Oh, you're only worried about vma_start_write()? > > > > That's a non-issue. It doesn't take the lock normally, since it starts = off with > > > > if (__is_vma_write_locked(vma, &mm_lock_seq)) > > return; > > > > which catches on the lock sequence number already being set. > > That check will prevent re-locking but if vma is not already locked > then the call will proceed with obtaining the lock and setting > vma->vm_lock_seq to mm->mm_lock_seq. The optimization Mateusz describes looks valid to me. If there is nobody else to fault a page and mm_users is stable (which I think it is because we are holding mmap_lock for write) then we can skip vma locking, I think. > > > > > So no extra locking there. > > > > Well, technically there's extra locking because the code stupidly > > doesn't initialize new vma allocations to the right sequence number, > > but that was talked about here: > > > > https://lore.kernel.org/all/CAHk-=3DwiCrWAoEesBuoGoqqufvesicbGp3cX0= LyKgEvsFaZNpDA@mail.gmail.com/ > > > > and it's a separate issue. > > > > Linus