From patchwork Thu Jul 6 01:13:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 11669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2248097vqx; Wed, 5 Jul 2023 18:34:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFtIxlNC0xMhGlRFVEIwENpzRF9MLra3Dwslb1djoOVGGLW/eM1e1Gjig3phJgeA17AF4VP X-Received: by 2002:a05:6a20:8e14:b0:12f:1b61:2570 with SMTP id y20-20020a056a208e1400b0012f1b612570mr363330pzj.59.1688607284127; Wed, 05 Jul 2023 18:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688607284; cv=none; d=google.com; s=arc-20160816; b=e+4sj+h2gBPnDLAf9AeFveI3DFpMK4gNbPh10lxLkMWyJresVue0YiCksMKDdrSSOn K0ZsRd9H0zOFZOUxM5XfqWZVAtZqgqWZ4AewGOFUMwUuhmGb/MzT7KBq/iV5ukLS8VCd /IOXsL28lyk0gP1rqAFTETodsJFAslRTvRe3iQrRpHo92pEBF31YfITNICv47N1yDKCD cqT+wxG6yn/ZD7qnFkMfCQQPiGv8KuJdCRh5k9ozAdtAvp4FshDGcRl4fQUN5ZP+bfLJ GFyDiaQu1TZgGiLpM6irZOdOi5K4RaOTdX1rJX9YSM3x/cZipThmP8w0iqXWlJRqaSl9 HWCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=/ZvjsLzR90/Ihxg7W2cQFYrdAaC3RTmM6cS2FPW4Hig=; fh=nzhkncz5xabQzrhgEb1MkFMbxxZbZAo75xFv/cDVpUE=; b=mfFMMZc8sLJ/x1HhhgogMLAco5kUC55T6GmkTJzLhIJMjNYjZhj6hdJFw0RuEtPGCi OTOzBrseLrO6lIr8wHz15bUp5tUXcHKhjjst19v9i4xU4NvRk6nvqBw8XYOPkfo/AJ/c BZm50+2vAgHJFC7fWI2opYkGpMM2N9cZ0RcEIH78dQaz1oGe2ZojAvhY9Vd3bMlzhRc/ WdCCUEMR4CfufAmLkfFshQcdHd6uJf06ydPBptK4vUGyii1DP09Nwl5W1EuBttxYWcvv 7QPcMOZ2+4oNPXoKneVKsjRR4ikArtiyzb5au4rqRfc4z2i8UtNP59sNtN1KMjT59BPr /0KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=M5IX75oa; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a18-20020a170902ecd200b0019e57f5a5aesi224883plh.567.2023.07.05.18.34.31; Wed, 05 Jul 2023 18:34:44 -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=M5IX75oa; 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 S232225AbjGFBOH (ORCPT + 99 others); Wed, 5 Jul 2023 21:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjGFBOF (ORCPT ); Wed, 5 Jul 2023 21:14:05 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 019221700 for ; Wed, 5 Jul 2023 18:14:05 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bb0d11a56abso104525276.2 for ; Wed, 05 Jul 2023 18:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688606044; x=1691198044; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=/ZvjsLzR90/Ihxg7W2cQFYrdAaC3RTmM6cS2FPW4Hig=; b=M5IX75oaI5+U+XxwObu9YSuPnYLffE9WfpI1afLQJyuZ8ZdqQzSucCDlj3g5M5PuYZ GsZp07pN00tTE+vWh7rvzdQ2h/PvSjrslMecjY9k8CxrDbycHpXPsX/eJlCQoGUrIPpz 5DjkcITZwm9WsevSIjZ5YrQVBsdE/akRWew0G7xNfaEdgcd2aG2WvNO2LOgCnmYUfkUx RZ7L0soWGM73GloOpd8UJJCcY4U+Nkb2yrVBeQGyNKQAVhdwZPP7lEjQzjA0VM9wmdPP hrLCj2TQXAmiBvtocX3y+KheOs+hqyBVAJUjvTR+A5I1O3diUYY/iVRtZGt06Dx+fZrK qc3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688606044; x=1691198044; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/ZvjsLzR90/Ihxg7W2cQFYrdAaC3RTmM6cS2FPW4Hig=; b=B3AHDrPQDqddfveSTe8lGdL9ch0MmihjPMwOPNfhroOdgE1T833x/f+hc4ud03NFpe cMR8gPhmFBv5GwiDX/DmMhkXTbU+Brk9fJax30phzB5ELbxUQeKp20fzPJeYH+WWBWyl rkzHa00jrWFM+YkBDvhnXYmmuzOKvRl/qDTJc8gjTIaNMqK4gJkrWUkfBoxHAHgOOQfl Gfx/oACNnd+J6+KXMdNGouGa2e8GnyhJv9Jcw7A42BeHpI4c9OSxdHUkqEG0PiVAyv45 TrNWoeRhTIY3lOINHHbusOa00v/es7wcSv9F8IGOpZtOj9OOD2IHJKxwyHA1+Dq8Y56J vr2g== X-Gm-Message-State: ABy/qLa2OXMdQ+KfcIzvRaZ8bR59M8gGrtekv7REbKIVAVyxqHt9Qq0p 2NP3uy2lfOPZ14lV+njp6qMoR8ThGQE= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:946c:be30:90d9:9093]) (user=surenb job=sendgmr) by 2002:a05:6902:30b:b0:c67:ebc5:de5d with SMTP id b11-20020a056902030b00b00c67ebc5de5dmr2439ybs.4.1688606044026; Wed, 05 Jul 2023 18:14:04 -0700 (PDT) Date: Wed, 5 Jul 2023 18:13:58 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230706011400.2949242-1-surenb@google.com> Subject: [PATCH v4 0/2] Avoid memory corruption caused by per-VMA locks From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: jirislaby@kernel.org, jacobly.alt@gmail.com, holger@applied-asynchrony.com, hdegoede@redhat.com, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Suren Baghdasaryan X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770564007057677981?= X-GMAIL-MSGID: =?utf-8?q?1770633071183275841?= A memory corruption was reported in [1] with bisection pointing to the patch [2] enabling per-VMA locks for x86. Based on the reproducer provided in [1] we suspect this is caused by the lack of VMA locking while forking a child process. Patch 1/2 in the series implements proper VMA locking during fork. I tested the fix locally using the reproducer and was unable to reproduce the memory corruption problem. 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 ~7% 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. Patch 2/2 disables per-VMA locks until the fix is tested and verified. Both patches apply cleanly over Linus' ToT and stable 6.4.y branch. Changes from v3 posted at [3]: - Replace vma_iter_init with vma_iter_set, per Liam R. Howlett - Update the regression number caused by additional VMA tree walk [1] https://bugzilla.kernel.org/show_bug.cgi?id=217624 [2] https://lore.kernel.org/all/20230227173632.3292573-30-surenb@google.com [3] https://lore.kernel.org/all/20230705171213.2843068-1-surenb@google.com Suren Baghdasaryan (2): fork: lock VMAs of the parent process when forking mm: disable CONFIG_PER_VMA_LOCK until its fixed kernel/fork.c | 6 ++++++ mm/Kconfig | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)