Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp33488468rwd; Sat, 8 Jul 2023 13:10:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHnOQ8gBmgBURBPUb3CdWpLUGz6C/ttvWYEI+b58x4TKPMPDfX/kVz2YZunx70AE58ZoHdi X-Received: by 2002:adf:de0a:0:b0:313:eb81:d2f6 with SMTP id b10-20020adfde0a000000b00313eb81d2f6mr10288621wrm.4.1688847057781; Sat, 08 Jul 2023 13:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688847057; cv=none; d=google.com; s=arc-20160816; b=B2pvVCKvYBQ+dBTSi5sCzrMGFyvnyPyKJzlQPxLS7NywYx/KI+/aXKc8kzoduhXxim 3pEin/AEN+QbDCZsOMArUX7ESM0EHQHlPCmE0darCOZgdoazXYIDNrXKQHY5nJe3HTwP kLzZ8e1rnEPK5UdVVroHnncqGfOQFF4cyEnt9c42Y9AjexmAB8IVawGYXpIAnlmF0vYS Vc7gNJAb+WCW7s9oC9IoL6YuJyhtmXoH4Okkij+ob5rD0YUnE+DTpVATaeteol3aQ1Cu 0AIU5EYrEluZ7orB7pIlOcOCvNen1R8C3wPUbQn3+ibnoD4BBOf3CJIi4b8suE/5OXZ7 aluQ== 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=2FxH4Sn2IVEMSRJMI6h54/CoL9VNO3HIcD6stV0UszU=; fh=IsTE916d58rYQJX2oOGuJ8PlkI8BncTdIXbpHGLpKLc=; b=MFhbiDgTQSqm4MtMdUvceg+7py1oqR9cU5UyqWikYIB/rJaMyfZn0w9WIJtWz74yWy Bkd+4J0OeU0UD/V/PrnOXDYZAqfMci2THsGnJ/v+/OnfH83DK2VUJ3E/5/ekNOVMpjfl 5cfANdEgoR30kGCitsqBUIOroa21CSREHv1mON5ppGf3Prx7EQ78DV9P4QjrffLJ/21T liHK8JnQf/uUXNT+YeI4+/yHvIDiexf+ZpTzkP8U8h7qlOEdF4L/ab+ZerQvtUTmfG70 WDxyQw9M9fBWO0kCyVCfB5aayauEZIPn8sTjjX8FZ1Qfa0p1ml5mLve5vQQ2GDA+0yCU reNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=yZP9mqmp; 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 e22-20020a056402089600b0051e52c1ffc9si984396edy.523.2023.07.08.13.10.34; Sat, 08 Jul 2023 13:10:57 -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=yZP9mqmp; 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 S229468AbjGHTW1 (ORCPT + 99 others); Sat, 8 Jul 2023 15:22:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjGHTW0 (ORCPT ); Sat, 8 Jul 2023 15:22:26 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44C82FF for ; Sat, 8 Jul 2023 12:22:25 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-579ed2829a8so36464927b3.1 for ; Sat, 08 Jul 2023 12:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688844144; x=1691436144; 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=2FxH4Sn2IVEMSRJMI6h54/CoL9VNO3HIcD6stV0UszU=; b=yZP9mqmpeQMLkFovdtEmI4WKMEtko+pAQ1BEDfa+W5OHCr7jJVo29zKlMe4dc5y4+/ ctYdxCnqqkyKx9WIui1Qqv5Ci88AGheDwsXz2NaxdeLoR4MDhJacff2brnbgaJOICM0/ FUirKv//hF+3UgB0qF4zsmJdaL2b4sPGgHQwVh5lM+8VF9WIzAMiuuZ3N12zpITmJW2P bwvS7I0B45kBtMhXgHGcTY3U6QrBUujNiAIQ4YtZb+FEXhaB5xpVyoqlik6jHJ2HE/rE iQRENfjy1+wSccJQm6AdI6rIf3TRZOKTIXbalO5K2RUxxGox0Tcs59Z6qdZpfnU1mAbL 9T/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688844144; x=1691436144; 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=2FxH4Sn2IVEMSRJMI6h54/CoL9VNO3HIcD6stV0UszU=; b=QG5afe3MNfW4CRBbBntHPj7HjTdZpZYhZ/atPFJxArve9TH83JJqRrPAvRpkluDl3P +K9nLiiHpOHqRIFlPeRBYbRXZ6p5zFdP8kad/RvGGOV3lMbOQROjAfPgS/g1/VbdI+lC +KujaTm/aPECHJiXAaPntr2/wuhKvQUJtfOdXdkAkGwsn/TgZ0jmqadGXF627lMZhOdQ efdNQGe1dl3fEPrJcOsX8Cxq4i7x+Yrt8IHBAmW/cP2sx7MskK68pXu8meajaT2gb4cS b+OZ+HCwglPx8R3KAhmnZf0bfDbQyTcBBXam9izG4K/XAWpoPhAiESebK1J2oug5ez3v WJ/A== X-Gm-Message-State: ABy/qLaz+SBq8M+ekd3fqW4+ihhlkwoGctrS4CGuWsKVNZ5qwLm2jhy8 zoNYibkSc14Rs+3Ur25xXZfVUu4idqsx4cAQdC8F5g== X-Received: by 2002:a0d:dc83:0:b0:570:8482:4074 with SMTP id f125-20020a0ddc83000000b0057084824074mr10341749ywe.42.1688844144270; Sat, 08 Jul 2023 12:22:24 -0700 (PDT) MIME-Version: 1.0 References: <20230708191212.4147700-1-surenb@google.com> <20230708191212.4147700-3-surenb@google.com> In-Reply-To: <20230708191212.4147700-3-surenb@google.com> From: Suren Baghdasaryan Date: Sat, 8 Jul 2023 12:22:13 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking To: torvalds@linux-foundation.org Cc: 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, T_SCC_BODY_TEXT_LINE,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 Sat, Jul 8, 2023 at 12:12=E2=80=AFPM Suren Baghdasaryan wrote: > > When forking a child process, parent write-protects an anonymous page > and COW-shares it with the child being forked using copy_present_pte(). > Parent's TLB is flushed right before we drop the parent's mmap_lock in > dup_mmap(). If we get a write-fault before that TLB flush in the parent, > and we end up replacing that anonymous page in the parent process in > do_wp_page() (because, COW-shared with the child), this might lead to > some stale writable TLB entries targeting the wrong (old) page. > Similar issue happened in the past with userfaultfd (see flush_tlb_page() > call inside do_wp_page()). > Lock VMAs of the parent process when forking a child, which prevents > concurrent page faults during fork operation and avoids this issue. > This fix can potentially regress some fork-heavy workloads. Kernel build > time did not show noticeable regression on a 56-core machine while a > stress test mapping 10000 VMAs and forking 5000 times in a tight loop > shows ~5% regression. If such fork time regression is unacceptable, > disabling CONFIG_PER_VMA_LOCK should restore its performance. Further > optimizations are possible if this regression proves to be problematic. Sending this earlier version of the patch per request from Linus and with his explanation here: https://lore.kernel.org/all/CAHk-=3Dwi-99-DyMOGywTbjRnRRC+XfpPm=3Dr=3Dpei4A= =3DMEL0QDBXA@mail.gmail.com/ > > Suggested-by: David Hildenbrand > Reported-by: Jiri Slaby > Closes: https://lore.kernel.org/all/dbdef34c-3a07-5951-e1ae-e9c6e3cdf51b@= kernel.org/ > Reported-by: Holger Hoffst=C3=A4tte > Closes: https://lore.kernel.org/all/b198d649-f4bf-b971-31d0-e8433ec2a34c@= applied-asynchrony.com/ > Reported-by: Jacob Young > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=3D217624 > Fixes: 0bff0aaea03e ("x86/mm: try VMA lock-based page fault handling firs= t") > Cc: stable@vger.kernel.org > Signed-off-by: Suren Baghdasaryan > --- > kernel/fork.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/fork.c b/kernel/fork.c > index b85814e614a5..d2e12b6d2b18 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -686,6 +686,7 @@ static __latent_entropy int dup_mmap(struct mm_struct= *mm, > for_each_vma(old_vmi, mpnt) { > struct file *file; > > + vma_start_write(mpnt); > if (mpnt->vm_flags & VM_DONTCOPY) { > vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mp= nt)); > continue; > -- > 2.41.0.390.g38632f3daf-goog >