Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp622298rwb; Fri, 4 Aug 2023 20:08:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWl8oZIPPQU5DqumpAcYAY6u9A70sjNocO83Os2iV7P9NC9Eh3hStejRBWZ731XhLgaP+E X-Received: by 2002:a05:6808:288a:b0:3a4:4b42:612b with SMTP id eu10-20020a056808288a00b003a44b42612bmr4096814oib.42.1691204889472; Fri, 04 Aug 2023 20:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691204889; cv=none; d=google.com; s=arc-20160816; b=eWMT7r//D55tVdJXaAB1xS6PV8H2srB06IiuyNXGXQwJYU6aoPWO5KExWo+08ypILp MaWVCfIRmRZwo4BMyNuXvtWm7uOlffEab7xLQQynNIOFxuGv7Tv/7qso2O5w2gzaYdY4 fgMRQtSimKar617kt1DYvhfGhNMi4Spo4Wjk0LNxHSMdLTevOd56fReHHSlGfQ7AZqOz dTntp2EjlOfUf0mzSIpaensf1YTLH8xtCnHv+5/UYXEvAVTcNdOSVVC072yzAKxf21iJ EERXv1Vq9fzBn1QXLrb+5by423RB0cWHWv2FWdq9NnFvEwd22JQPgSEJhM5vo8tGCaO3 U5PQ== 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=+rSm29+3cw5ZqZkXj3qFSUuwbm7CIlxZaN5vcndHFEY=; fh=MyAfGONXyUqjX07eXfKS/mDPkBD0PylW2glSBuL3t04=; b=0S3Uc4jy9XHibWeApO8hU8yS1ezgapyIBgWn+lSJuiwwczy1xr58nYYMB/R/Rh8pom 6A+oAjcP6HuLp01PejyWNVWCFQPr221lINU9Hyw9MpavQPUASmeLiDs6H2MLE9zCAyjR fGAxca/jNSucVxNmgImUcvne9ChD5jPevpLCmiPBsvGklKHPiag1HCSxTKM8ih2z52J9 jKTSD53ggUlumO6875WRKmxAiq4Uwau/jw+Vuahw5V2Z4hMIE73ytnPTO7H/5s50hxsq FsFIRKk5uRlSrG2itShf9sR1tZRqOaEi5AsRuQY3qle75/VYoUl4dxIYjv80RCbZrJKQ rPUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=plN7Lmsf; 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 b15-20020a056a00114f00b0067d204bf281si2588501pfm.3.2023.08.04.20.07.57; Fri, 04 Aug 2023 20:08:09 -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=plN7Lmsf; 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 S229615AbjHEBml (ORCPT + 99 others); Fri, 4 Aug 2023 21:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjHEBmi (ORCPT ); Fri, 4 Aug 2023 21:42:38 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A3434EE2 for ; Fri, 4 Aug 2023 18:42:37 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5860c7fc2fcso30469717b3.2 for ; Fri, 04 Aug 2023 18:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691199756; x=1691804556; 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=+rSm29+3cw5ZqZkXj3qFSUuwbm7CIlxZaN5vcndHFEY=; b=plN7LmsfHyvXpPp/HAgS7nXgIXteE8264IDa/o2tjDOX8unsmYk7EojQmTU5cUe+jV cjliykudifFvc7dLk6/DwgOH7+9X4MDhzMIsMQm/onYSQqKdwNZX8UqVTYKuJYl6Ha+O 9WZhXR18J7XAaXbGAAwEXZ6ix0+UBKlzsTvo5jb05KSoRLL7qXvNBl5pNC1d6tXmVHMW SXIZLO8BP/DYmu5uEYaOUv39DLoLQlpwPV7BHp0dSXWIa4usOAk1N8w9mKX5V2IkcGwp 8LnltCq2ELwZcpwu4a4wWAkmF+JXVmG8o9gLjlgrYUu/NaekCF94WvOvLo4XO9zaSpD4 kw3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691199756; x=1691804556; 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=+rSm29+3cw5ZqZkXj3qFSUuwbm7CIlxZaN5vcndHFEY=; b=RmIf6McExoIHd7JnSI0lhP6oE0cNTZznRJPITRLnt5uTTKS1Kq57mQBCTGtFrZNnKS tIs9WYy+ulSXYVNEh6QejxU8v2iIassW1qR4mRaNQIe6wj1QpOf73lEiQCIcsWl5UGFL nkQUkiWBAURVU3QEMpUBK4MCVIpC60PYhVezhHjVx6rebi2515OSEilRghSWKmyXfrLI +j4S8btBiPAdM/E1HlHsVGEVBH1OqQuRfmZVIaOv3VkTSSoOCKpHxahCZ1YlDbYMwvmr zJRbpGO7+r3Pckm+Z1r2n4vRDpPJeZ9YD4sNOTmaJLLnizskj4qdGZF12Gv5fZqCeQoI 039Q== X-Gm-Message-State: AOJu0YzDOWF+ukv3JO6R0L1IoIS+Khw0kUk7hbhlG7x4olIPpLMNAQfA bwuAbic4lbYb+lxyZedPhJIERK84DHl2r8QhZ0XfbA== X-Received: by 2002:a0d:db41:0:b0:570:2568:15e with SMTP id d62-20020a0ddb41000000b005702568015emr3945027ywe.43.1691199756040; Fri, 04 Aug 2023 18:42:36 -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 18:42:23 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking To: Mateusz Guzik Cc: Linus Torvalds , 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=unavailable 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 6:06=E2=80=AFPM Mateusz Guzik wr= ote: > > On 8/5/23, 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. > > > > 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-=3DwiCrWAoEesBuoGoqqufvesicbGp3cX0LyKg= EvsFaZNpDA@mail.gmail.com/ > > > > and it's a separate issue. > > > > I'm going to bet one beer this is the issue. > > The patch I'm responding to only consists of adding the call to > vma_start_write and claims the 5% slowdown from it, while fixing > crashes if the forking process is multithreaded. > > For the fix to work it has to lock something against the parent. > > VMA_ITERATOR(old_vmi, oldmm, 0); > [..] > for_each_vma(old_vmi, mpnt) { > [..] > vma_start_write(mpnt); > > the added line locks an obj in the parent's vm space. > > The problem you linked looks like pessimization for freshly allocated > vmas, but that's what is being operated on here. Sorry, now I'm having trouble understanding the problem you are describing. We are locking the parent's vma before copying it and the newly created vma is locked before it's added into the vma tree. What is the problem then? > > -- > Mateusz Guzik