From patchwork Wed Jan 27 08:39:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12049343 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.7 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 7E2C8C433DB for ; Wed, 27 Jan 2021 08:39:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 23F7A20719 for ; Wed, 27 Jan 2021 08:39:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23F7A20719 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 F03C76B000A; Wed, 27 Jan 2021 03:39:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB46C6B000C; Wed, 27 Jan 2021 03:39:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9226B000D; Wed, 27 Jan 2021 03:39:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id C6EAE6B000A for ; Wed, 27 Jan 2021 03:39:24 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9210B180AD83B for ; Wed, 27 Jan 2021 08:39:24 +0000 (UTC) X-FDA: 77750905848.05.care25_2f0b72827595 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 6B50B18045E8F for ; Wed, 27 Jan 2021 08:39:24 +0000 (UTC) X-HE-Tag: care25_2f0b72827595 X-Filterd-Recvd-Size: 3783 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 08:39:23 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id y11so1135414ljk.1 for ; Wed, 27 Jan 2021 00:39:23 -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=P9lsVAKuBeBy2NX/pLEuuHxAXZwhA0q0v6LjUigA9EE=; b=tPPtxq2C0rnzakrAue8RUnc/cYNQycZEWSjqIe12+D0acBd7JVrnwtz0l08bXST059 qU9ghvOoXBEINqButtZ46DcKKehka4fH9mxqI+xEenb1RnJ8/XMpSAJxQnophnLy8fNC Xb+brmbcQ/U5XAVsMFVXAvSCW6Tm5whDZYRokTplLY6vsV5LDdcTVDdl14kTmUL8JjOo RLzvjm3NZbxgacRbfdpLXUo5xqaVQmvQIbUpVoiyong7IOeR7O0jYsoc7ZFGzUz6xQhn cRiwJ2IKn1dwrOQFRjn8Fx5InCPV7GcnQTafw02cuaJ3kJ8AUjgJLx3tL0qLeuZNBtmC glug== 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=P9lsVAKuBeBy2NX/pLEuuHxAXZwhA0q0v6LjUigA9EE=; b=ebyGADrup7fsOpU0wWAtWiZnGXzaS9lktn2E3RHPAv3TiIu7PsKuWG1d6QTZVz5fCa zPFW37ZaMr5Rwnm1IGMwSi7OugnD8lMvEpanenPsLbZ+QqDy4Yhq+F1ZgHdpJ6BEwIYY WicRfWN+RuSKLxhgPsvQJZHJBQxVrs3B/rbJqm8kb8PuAsPoAVlHGzpUj7lI6Zs7XmMO NgwfKK4lxlR5hg1hPOFoioV3kRVd7zz20O78cC9C2muJ9YkCJJcuw5bdMCoZcX4g8Pjj np5Xre90mbYiQKeiutxzR58kVU4zt5eimrpMrBr4NKSOsLFVCjpsuTz9obfNpTG0ROYj SOZg== X-Gm-Message-State: AOAM531ekDy84SzmMdJsRdbhgwkL0gvSx5iQJ42b/HcmF09OLCqrnbLo wCmlxHSu1Jd+Gaa//UZQCKr2wNXSils= X-Google-Smtp-Source: ABdhPJw8lRLLD12bDPjd3bzlcAQTPU9VKVUeUDR721tBg3D6W8juBw8DpSjE/v1XelSKuHNSKc7SWg== X-Received: by 2002:a2e:b819:: with SMTP id u25mr4960144ljo.458.1611736762221; Wed, 27 Jan 2021 00:39:22 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id e10sm394458ljn.79.2021.01.27.00.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 00:39:21 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Date: Wed, 27 Jan 2021 16:39:16 +0800 Message-Id: <20210127083917.309264-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 --- v1->v2: No chnages. 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); /*