From patchwork Tue Jan 19 07:51:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12029425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D739C433DB for ; Tue, 19 Jan 2021 07:51:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8443922D71 for ; Tue, 19 Jan 2021 07:51:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8443922D71 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B5E9A8D0017; Tue, 19 Jan 2021 02:51:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0E7C6B00CE; Tue, 19 Jan 2021 02:51:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A247B8D0017; Tue, 19 Jan 2021 02:51:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 898496B00B0 for ; Tue, 19 Jan 2021 02:51:39 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 42EA51EE6 for ; Tue, 19 Jan 2021 07:51:39 +0000 (UTC) X-FDA: 77721755118.19.train28_1e12d6d27550 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 220E71ACC2C for ; Tue, 19 Jan 2021 07:51:39 +0000 (UTC) X-HE-Tag: train28_1e12d6d27550 X-Filterd-Recvd-Size: 3755 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Jan 2021 07:51:38 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id n8so12038162ljg.3 for ; Mon, 18 Jan 2021 23:51:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=uuGQRAJRZZ+5+wnwR/xXDjgCBVhuAJlZaw/GcYybCFE=; b=Jqt8ZWYUYoKKxhy7QdzJO78nPwlCkdM9OGHclNMkAVnG4Xydmy9mqnHlXmQn2TKUbH SIGxRlT/N0QdDJKn233ZZsEtO1Ipguw//upni9KZVytexOFNXJ/Sl7i6zFK3f1gFP9yp ifAfcoRrzrAXvVC1JZJVt5aZusH/I1iW0KDPW6xVmSYHAsezJubJGFs0jvdB6si0UH5v RkpzbM8ix0ND2MKwfoA3mIVxj6Gz29+jpyLohgpcO1M1JvLBBbIjBPw8iV+gU4DsDlcb WnxdlHEO+oHVx5suF+sqUojQ0VsjOvlQ2Vl5FDY2fKMGoMY8XEzjRDTtm4ehs2NLjlmx k4lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uuGQRAJRZZ+5+wnwR/xXDjgCBVhuAJlZaw/GcYybCFE=; b=WlUaf2/Su+WZY42/wozenpYhFbZOh5IHocc7XSTo4/q470pDFoM3yuepd7IOrDz3kg M0CXyDR5zEhAsizDbeNoPrc1wwnZtr6Y3ntdG9nwDbTvW5fdMuSu0icO8D5ZiaXRETuo JlNLPCtAoV72ZGXzyU+8GJ8pHELj2Ug9KVoQ8XUM9tLp1liqd+oWRXPMNz23XEosnD9M GLy1oYoutTVk7q0q0kxfsr89diPYy+SrlRTxgv+XU8dHOX09Mumre/Z+l8R0rEyVUDQz PY4bIMduI054OXv1qfuwmK9K9FsNJ3Nkxo2eApjPnWki5xCfBD7RNZfseeJqB9pRMNy9 ueXA== X-Gm-Message-State: AOAM533+C6aoTaAgRZYEWaZwhzC6P7eUVg8Qvltvh+BOhMUkSki5QYrV mAtf78/jgZkgPW1O82hH+Bw4x4h93NU= X-Google-Smtp-Source: ABdhPJwLFyvR/5h7ZFRpSsp+rKtwdFcrplkQnIKJCf7RitjDUgDs22gKTCh8ieGCu5Z+bZ28pBHZBQ== X-Received: by 2002:a2e:984c:: with SMTP id e12mr1348131ljj.71.1611042696996; Mon, 18 Jan 2021 23:51:36 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id s1sm1955108ljs.0.2021.01.18.23.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 23:51:36 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Date: Tue, 19 Jan 2021 15:51:25 +0800 Message-Id: <20210119075126.3513154-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In case the vma will continue to be used after unlink its relevant anon_vma, we need to reset the vma->anon_vma pointer to NULL. So, later when fault happen within this vma again, a new anon_vma will be prepared. By this way, the vma will only be checked for reverse mapping of pages which been fault in after the unlink_anon_vmas call. Currently, the mremap with MREMAP_DONTUNMAP scenario will continue use the vma after moved its page table entries to a new vma. For other scenarios, the vma itself will be freed after call unlink_anon_vmas. Signed-off-by: Li Xinhai --- mm/rmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 08c56aaf72eb..31ef76180c53 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -413,8 +413,15 @@ void unlink_anon_vmas(struct vm_area_struct *vma) list_del(&avc->same_vma); anon_vma_chain_free(avc); } - if (vma->anon_vma) + if (vma->anon_vma) { vma->anon_vma->degree--; + + /* + * vma would still be needed after unlink, and anon_vma will be prepared + * when handle fault. + */ + vma->anon_vma = NULL; + } unlock_anon_vma_root(root); /*