Message ID | 20230620235726.3873043-3-surenb@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4033838vqr; Tue, 20 Jun 2023 17:39:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oFRxn6rlMn0ZW9dJ7HKbT8PL04DpwaTKVyNjV14xP9XR8rgFgXixoFDPZIRssL0M9byTx X-Received: by 2002:a05:620a:808b:b0:75d:4f25:29d1 with SMTP id ef11-20020a05620a808b00b0075d4f2529d1mr16764216qkb.66.1687307966831; Tue, 20 Jun 2023 17:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687307966; cv=none; d=google.com; s=arc-20160816; b=RBk4PpAv8Vy037+TNEDTr902P+guvb9zpD7hSoxqtHjHq+ASSPghnxFtOoAxwbrdm9 oM11sy8WW2opMqocSOzIPEL2kOVAT0pauRllWvRRiGnMJliNO78P4ZKjpoZRs4xTAkw4 tfSkYOKopY77Fwp0EAO+RVOiZ7+8buEotVIOkQB3OLZUp8lQjQTGMgO4XF2NjONyv8fc fzqCjyxFsd79V5JRkn9d4542X9XbiwxCZCvKjQjdOvUE08O1bkKX7pubSuDLevM9WcZU R7wf9CW+AAcJgrPXyKxVeJz5m9jb4qx13R9VbtACjl9c1zP5TmZqvwXMXY/rjvtTpBV1 W3XA== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=BGbrY/f1fvBNW9z8go6Nnz06u29111qaAGQndqYmZbI=; b=XvF51suGOLv5AfFy7+t2sUii310g+JwO4nGpl3X8GGqtMmSN/2vNJrzPgZ4NIocF8q vXzu0K/ufZ7dCRvAcVD4iMxeOaTUR4bHKB6EgIBgD7XQ0iRJoekiZjpvjhGImKj+egBF hd45sZkI8lWpOsaDwtGY6j7NdUtsD/9rWfO2leaGppmBvXE6v2QYlsjHJ9/AyK8sCD3b vMbPFCslP+HOQVV2wsjjBMWei63YE4xhYjI7zhemuNh21/IfyhJko+r2vDEvc5rdgEfw 4Ppi4O5lLitEndVab6wjMskaRnryBkf/G+7r80A/yvReLa33yvjBAaAYVw3+KiN2bXHo D3cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=P9ZGKNT+; 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 y17-20020aa79e11000000b006642e5dd553si2766847pfq.221.2023.06.20.17.39.14; Tue, 20 Jun 2023 17:39:26 -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=P9ZGKNT+; 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 S229852AbjFTX5j (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Tue, 20 Jun 2023 19:57:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjFTX5g (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 20 Jun 2023 19:57:36 -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 0DDF819F for <linux-kernel@vger.kernel.org>; Tue, 20 Jun 2023 16:57:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bf34588085bso3242704276.0 for <linux-kernel@vger.kernel.org>; Tue, 20 Jun 2023 16:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687305454; x=1689897454; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BGbrY/f1fvBNW9z8go6Nnz06u29111qaAGQndqYmZbI=; b=P9ZGKNT+TEzfnNjgXfWsFMxrjrmo19InxA9Ltzw94eBOzcf0DrJjIadY39g5B1ARES UM8Tb66YAZoM1qvWyjNLmdfb7GBwdGln7qA5RgXbZWXGaZHvI0XHaH/HBL1QpJNOQgUm 6OloW5Gfvh2xzMIEA3ALlJsZDF0ta5gG6htWRcVitzaGC/HTclOzVZESltb69EPM+Vbp ulOrRqMr+3gQkWyLLTEaVyZRb1j645qYTNnqpW50MZl/4SibKrzjz7laJRB/LZnjYsyE XMOaY7sjsOrxZl8Y6VKGCVQZWc8BmHDWraN0TJszAdVqPx1QEoL6EPZTqJhDF1Ftewq7 eOYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687305454; x=1689897454; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BGbrY/f1fvBNW9z8go6Nnz06u29111qaAGQndqYmZbI=; b=IwOWlrT8F0vRn91nCBV0pb8nDFj7HfW3lUTIoN+Qc9c8g70aN19WpVI/Uuv/wVU0Dn igbSYKOdwDfxywZkAkvTxID9pcXAN1ZbCHZjKq3F+DcwZzD4UOZSyl00tWk8td8+je3W MRTXleCE0GVrYNbpFw0ReCPsVVzpEQJbdcSMmU1zU2V6sjw1XR3qSN/KzqG32EnrC1E+ aQHCyaqNoiI5tHOt7ft4QnfY3k0b21qVId+osLg7MA1PzotyMvFOnisoecDv3vOmdtVQ m9MK686vjDFE1mM6PHj1kw3NDegvJRrMgw43/JbhrHe63zusYMSzm7KA0oShbydpe6Y9 z6KQ== X-Gm-Message-State: AC+VfDxDaD6KJODSd+koF4j7p71HKxSB+gKkBSarZIyICUGE4RnmRK9m sAIHmEAH05yoUL5qh6WTmnDo++T0HZM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:3f57:9854:e19:8906]) (user=surenb job=sendgmr) by 2002:a5b:bc9:0:b0:bad:41b:f343 with SMTP id c9-20020a5b0bc9000000b00bad041bf343mr5127082ybr.1.1687305454340; Tue, 20 Jun 2023 16:57:34 -0700 (PDT) Date: Tue, 20 Jun 2023 16:57:26 -0700 In-Reply-To: <20230620235726.3873043-1-surenb@google.com> Mime-Version: 1.0 References: <20230620235726.3873043-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230620235726.3873043-3-surenb@google.com> Subject: [PATCH 3/3] mm: check for VMA being detached before destroying it From: Suren Baghdasaryan <surenb@google.com> To: akpm@linux-foundation.org Cc: willy@infradead.org, torvalds@linuxfoundation.org, vegard.nossum@oracle.com, mpe@ellerman.id.au, Liam.Howlett@oracle.com, lrh2000@pku.edu.cn, mgorman@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com Content-Type: text/plain; charset="UTF-8" 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769270395609736634?= X-GMAIL-MSGID: =?utf-8?q?1769270638262782923?= |
Series |
[1/3] mm: change vma_start_read to fail if VMA got detached from under it
|
|
Commit Message
Suren Baghdasaryan
June 20, 2023, 11:57 p.m. UTC
By the time VMA is freed it has to be detached with the exception of
exit_mmap which is destroying the whole VMA tree. Enforce this
requirement before freeing the VMA. exit_mmap in the only user calling
__vm_area_free directly, therefore it won't trigger the new check.
Change VMA initialization to mark new VMAs as detached and change that
flag once the VMA is added into a tree.
Suggested-by: Linus Torvalds <torvalds@linuxfoundation.org>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
include/linux/mm.h | 4 ++--
kernel/fork.c | 2 ++
mm/internal.h | 1 +
3 files changed, 5 insertions(+), 2 deletions(-)
Comments
Hi Suren, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-change-vma_start_read-to-fail-to-lock-a-detached-VMA/20230621-075833 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230620235726.3873043-3-surenb%40google.com patch subject: [PATCH 3/3] mm: check for VMA being detached before destroying it config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211007.hQoEsMrP-lkp@intel.com/config) compiler: alpha-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211007.hQoEsMrP-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306211007.hQoEsMrP-lkp@intel.com/ All errors (new ones prefixed by >>): scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr] scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr] scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples In file included from include/linux/pid_namespace.h:7, from include/linux/ptrace.h:10, from arch/alpha/kernel/asm-offsets.c:11: include/linux/mm.h: In function 'vma_init': >> include/linux/mm.h:753:12: error: 'struct vm_area_struct' has no member named 'detached' 753 | vma->detached = true; | ^~ arch/alpha/kernel/asm-offsets.c: At top level: arch/alpha/kernel/asm-offsets.c:15:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes] 15 | void foo(void) | ^~~ make[2]: *** [scripts/Makefile.build:114: arch/alpha/kernel/asm-offsets.s] Error 1 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:1287: prepare0] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:226: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. vim +753 include/linux/mm.h 740 741 /* 742 * WARNING: vma_init does not initialize vma->vm_lock. 743 * Use vm_area_alloc()/vm_area_free() if vma needs locking. 744 */ 745 static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) 746 { 747 static const struct vm_operations_struct dummy_vm_ops = {}; 748 749 memset(vma, 0, sizeof(*vma)); 750 vma->vm_mm = mm; 751 vma->vm_ops = &dummy_vm_ops; 752 INIT_LIST_HEAD(&vma->anon_vma_chain); > 753 vma->detached = true; 754 vma_numab_state_init(vma); 755 } 756
Hi Suren, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-change-vma_start_read-to-fail-to-lock-a-detached-VMA/20230621-075833 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230620235726.3873043-3-surenb%40google.com patch subject: [PATCH 3/3] mm: check for VMA being detached before destroying it config: sparc-randconfig-r022-20230620 (https://download.01.org/0day-ci/archive/20230621/202306211345.Xt94CVTt-lkp@intel.com/config) compiler: sparc64-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211345.Xt94CVTt-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306211345.Xt94CVTt-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from include/sound/pcm.h:15, from sound/drivers/aloop.c:27: include/linux/mm.h: In function 'vma_init': include/linux/mm.h:753:12: error: 'struct vm_area_struct' has no member named 'detached' 753 | vma->detached = true; | ^~ In file included from include/linux/init.h:5, from sound/drivers/aloop.c:18: sound/drivers/aloop.c: At top level: >> include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) | ^ include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 231 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) | ^~~~~~~~~~~~~~~~~ include/linux/kernel.h:56:59: note: in expansion of macro '__must_be_array' 56 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) | ^~~~~~~~~~~~~~~ include/linux/moduleparam.h:517:20: note: in expansion of macro 'ARRAY_SIZE' 517 | = { .max = ARRAY_SIZE(array), .num = nump, \ | ^~~~~~~~~~ include/linux/moduleparam.h:501:9: note: in expansion of macro 'module_param_array_named' 501 | module_param_array_named(name, name, type, nump, perm) | ^~~~~~~~~~~~~~~~~~~~~~~~ sound/drivers/aloop.c:46:1: note: in expansion of macro 'module_param_array' 46 | module_param_array(index, int, NULL, 0444); | ^~~~~~~~~~~~~~~~~~ sound/drivers/aloop.c:39:12: warning: 'index' defined but not used [-Wunused-variable] 39 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | ^~~~~ -- In file included from include/sound/pcm.h:15, from sound/drivers/dummy.c:20: include/linux/mm.h: In function 'vma_init': include/linux/mm.h:753:12: error: 'struct vm_area_struct' has no member named 'detached' 753 | vma->detached = true; | ^~ In file included from include/linux/init.h:5, from sound/drivers/dummy.c:7: sound/drivers/dummy.c: At top level: >> include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) | ^ include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 231 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) | ^~~~~~~~~~~~~~~~~ include/linux/kernel.h:56:59: note: in expansion of macro '__must_be_array' 56 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) | ^~~~~~~~~~~~~~~ include/linux/moduleparam.h:517:20: note: in expansion of macro 'ARRAY_SIZE' 517 | = { .max = ARRAY_SIZE(array), .num = nump, \ | ^~~~~~~~~~ include/linux/moduleparam.h:501:9: note: in expansion of macro 'module_param_array_named' 501 | module_param_array_named(name, name, type, nump, perm) | ^~~~~~~~~~~~~~~~~~~~~~~~ sound/drivers/dummy.c:62:1: note: in expansion of macro 'module_param_array' 62 | module_param_array(index, int, NULL, 0444); | ^~~~~~~~~~~~~~~~~~ sound/drivers/dummy.c:48:12: warning: 'index' defined but not used [-Wunused-variable] 48 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | ^~~~~ vim +16 include/linux/build_bug.h bc6245e5efd70c Ian Abbott 2017-07-10 6 bc6245e5efd70c Ian Abbott 2017-07-10 7 #ifdef __CHECKER__ bc6245e5efd70c Ian Abbott 2017-07-10 8 #define BUILD_BUG_ON_ZERO(e) (0) bc6245e5efd70c Ian Abbott 2017-07-10 9 #else /* __CHECKER__ */ bc6245e5efd70c Ian Abbott 2017-07-10 10 /* bc6245e5efd70c Ian Abbott 2017-07-10 11 * Force a compilation error if condition is true, but also produce a 8788994376d84d Rikard Falkeborn 2019-12-04 12 * result (of value 0 and type int), so the expression can be used bc6245e5efd70c Ian Abbott 2017-07-10 13 * e.g. in a structure initializer (or where-ever else comma expressions bc6245e5efd70c Ian Abbott 2017-07-10 14 * aren't permitted). bc6245e5efd70c Ian Abbott 2017-07-10 15 */ 8788994376d84d Rikard Falkeborn 2019-12-04 @16 #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) 527edbc18a70e7 Masahiro Yamada 2019-01-03 17 #endif /* __CHECKER__ */ 527edbc18a70e7 Masahiro Yamada 2019-01-03 18
On Tue, Jun 20, 2023 at 7:15 PM kernel test robot <lkp@intel.com> wrote: > > Hi Suren, > > kernel test robot noticed the following build errors: > > [auto build test ERROR on akpm-mm/mm-everything] > > url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-change-vma_start_read-to-fail-to-lock-a-detached-VMA/20230621-075833 > base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything > patch link: https://lore.kernel.org/r/20230620235726.3873043-3-surenb%40google.com > patch subject: [PATCH 3/3] mm: check for VMA being detached before destroying it > config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211007.hQoEsMrP-lkp@intel.com/config) > compiler: alpha-linux-gcc (GCC) 12.3.0 > reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211007.hQoEsMrP-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202306211007.hQoEsMrP-lkp@intel.com/ > > All errors (new ones prefixed by >>): > > scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr] > scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr] > scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples > In file included from include/linux/pid_namespace.h:7, > from include/linux/ptrace.h:10, > from arch/alpha/kernel/asm-offsets.c:11: > include/linux/mm.h: In function 'vma_init': > >> include/linux/mm.h:753:12: error: 'struct vm_area_struct' has no member named 'detached' > 753 | vma->detached = true; > | ^~ Yep, missed #ifdef CONFIG_PER_VMA_LOCK here. Will fix it in the next version but will wait a bit for possible feedback. > arch/alpha/kernel/asm-offsets.c: At top level: > arch/alpha/kernel/asm-offsets.c:15:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes] > 15 | void foo(void) > | ^~~ > make[2]: *** [scripts/Makefile.build:114: arch/alpha/kernel/asm-offsets.s] Error 1 > make[2]: Target 'prepare' not remade because of errors. > make[1]: *** [Makefile:1287: prepare0] Error 2 > make[1]: Target 'prepare' not remade because of errors. > make: *** [Makefile:226: __sub-make] Error 2 > make: Target 'prepare' not remade because of errors. > > > vim +753 include/linux/mm.h > > 740 > 741 /* > 742 * WARNING: vma_init does not initialize vma->vm_lock. > 743 * Use vm_area_alloc()/vm_area_free() if vma needs locking. > 744 */ > 745 static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) > 746 { > 747 static const struct vm_operations_struct dummy_vm_ops = {}; > 748 > 749 memset(vma, 0, sizeof(*vma)); > 750 vma->vm_mm = mm; > 751 vma->vm_ops = &dummy_vm_ops; > 752 INIT_LIST_HEAD(&vma->anon_vma_chain); > > 753 vma->detached = true; > 754 vma_numab_state_init(vma); > 755 } > 756 > > -- > 0-DAY CI Kernel Test Service > https://github.com/intel/lkp-tests/wiki
diff --git a/include/linux/mm.h b/include/linux/mm.h index 74e3033c9fc2..9a10fcdb134e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -247,7 +247,7 @@ void setup_initial_init_mm(void *start_code, void *end_code, struct vm_area_struct *vm_area_alloc(struct mm_struct *); struct vm_area_struct *vm_area_dup(struct vm_area_struct *); void vm_area_free(struct vm_area_struct *); -/* Use only if VMA has no other users */ +/* Use only if VMA has no other users and might still be attached to a tree */ void __vm_area_free(struct vm_area_struct *vma); #ifndef CONFIG_MMU @@ -751,7 +751,7 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) vma->vm_mm = mm; vma->vm_ops = &dummy_vm_ops; INIT_LIST_HEAD(&vma->anon_vma_chain); - vma_mark_detached(vma, false); + vma->detached = true; vma_numab_state_init(vma); } diff --git a/kernel/fork.c b/kernel/fork.c index 41c964104b58..000fc429345c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -540,6 +540,7 @@ static void vm_area_free_rcu_cb(struct rcu_head *head) /* The vma should not be locked while being destroyed. */ VM_BUG_ON_VMA(rwsem_is_locked(&vma->vm_lock->lock), vma); + WARN_ON_ONCE(!vma->detached); __vm_area_free(vma); } #endif @@ -549,6 +550,7 @@ void vm_area_free(struct vm_area_struct *vma) #ifdef CONFIG_PER_VMA_LOCK call_rcu(&vma->vm_rcu, vm_area_free_rcu_cb); #else + WARN_ON_ONCE(!vma->detached); __vm_area_free(vma); #endif } diff --git a/mm/internal.h b/mm/internal.h index 68410c6d97ac..728189e6c703 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1068,6 +1068,7 @@ static inline void vma_iter_store(struct vma_iterator *vmi, vmi->mas.index = vma->vm_start; vmi->mas.last = vma->vm_end - 1; mas_store_prealloc(&vmi->mas, vma); + vma_mark_detached(vma, false); } static inline int vma_iter_store_gfp(struct vma_iterator *vmi,