From patchwork Sat Feb 8 08:35:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11371495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6229B1398 for ; Sat, 8 Feb 2020 08:37:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 251FE21741 for ; Sat, 8 Feb 2020 08:37:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s6x2kWbj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 251FE21741 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 8F6406B0007; Sat, 8 Feb 2020 03:37:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8CDF16B0008; Sat, 8 Feb 2020 03:37:39 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E2E56B000A; Sat, 8 Feb 2020 03:37:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 60EE36B0007 for ; Sat, 8 Feb 2020 03:37:39 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AF951249F for ; Sat, 8 Feb 2020 08:37:37 +0000 (UTC) X-FDA: 76466306154.17.push69_8566aca5274a X-Spam-Summary: 40,2.5,0,83b3f539ff93c244,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:riel@redhat.com:kirill.shutemov@linux.intel.com:willy@infradead.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3352:3865:3866:3868:3870:3871:3874:4321:5007:6261:6653:7514:7903:8660:9413:10011:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13069:13148:13230:13311:13357:14181:14384:14394:14687:14721:21080:21324:21444:21451:21627:21666:21740:30054:30079,0,RBL:209.85.208.196:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:1:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: push69_8566aca5274a X-Filterd-Recvd-Size: 4429 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Sat, 8 Feb 2020 08:37:37 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id q8so1746056ljj.11 for ; Sat, 08 Feb 2020 00:37:37 -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:in-reply-to:references; bh=bRKoUkWzGWG5sS+nRLMaxwUJGw4R0/AKLKdIHTJDorY=; b=s6x2kWbjyZ3+8C/AQVm8ADPAgYVvZdSl4y2QbvDc3FhRsywHxkxH7Kg97wAow3XH6F fomfBob/Pm6fnv+YBmbgF3vK++C73S65VIynP7brg7GPaWaiZYM5KEoVl/zgxsCRkkLT tDO7oZTMLAnHf+Vi7fVmjjUjhL2gABBUHY4UlU48S20Yg0l47eT7havl3vWh6RbX9c18 X+8uUuXSwVwzL82NvmBo4zDtrjqOnnShgcxWPM5xSzJT5Jioc5N/H9c/J/L2/whWL4Me qezuhlJalY0jLJwcBHA+nUqfQqkCpu0TcLAVyy3lr7WdmAGwcM/W+DIajXemEAm0vwnf pOiw== 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:in-reply-to :references; bh=bRKoUkWzGWG5sS+nRLMaxwUJGw4R0/AKLKdIHTJDorY=; b=mHNXsXTip4JB/lrVLhVwE7CElp6hLVA+F+cIgooiG4jqleD4++XVscRS7BKZcyGoFt O8NNoeXR9ugSuZSuFaP4td5NaFeWQWMjK3YAXWSRGUlgxn7z234qOuPf2l05zqt/GaRe 2PpkMvp4gZtQVm3+/CbyuOm57VC2SVFAz61nt2PusCl/hGYDga1qLDTYKkxE47yUp7yD lc7RWgXNFM5yEcWIbYFTPsEuG4AUO7JVTuoa8ifNZN4bo+DnREmSRoRbqXDTNVnjxaoF EG4rGtsj8I1r6fClGJ2HmnIB3ae/T0iEW4gt7Z3q7gqHkuuT/eTUjT4wliXptVjPeWhK 0R1g== X-Gm-Message-State: APjAAAXWewHR2SdiqBXcdZ06cvRuGGwPI1EFr0VHAKRBbXf4nkvWPDQp kK4WWEE6KhjLx5eYqN9sjhhYkqQr6gM= X-Google-Smtp-Source: APXvYqyp6uYhllh8Dihy6/ot72Nb8OuirQjGffaGvPvrPnC7fwZZA/cl1vUfQNkHfWM+g6CXuHAkyg== X-Received: by 2002:a2e:804b:: with SMTP id p11mr2075653ljg.235.1581151055645; Sat, 08 Feb 2020 00:37:35 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id n11sm2663404ljg.15.2020.02.08.00.37.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 00:37:35 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Rik van Riel , "Kirill A. Shutemov" , Matthew Wilcox Subject: [PATCH 1/3] mm: don't prepare anon_vma if vma has VM_WIPEONFORK Date: Sat, 8 Feb 2020 08:35:26 +0000 Message-Id: <1581150928-3214-2-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> References: <1581150928-3214-1-git-send-email-lixinhai.lxh@gmail.com> 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 dup_mmap(), anon_vma_prepare() is called for vma has VM_WIPEONFORK, and parameter 'tmp' (i.e., the new vma of child) has same ->vm_next and ->vm_prev as its parent vma. That allows anon_vma used by parent been mistakenly shared by child (find_mergeable_anon_vma() will do this reuse work). Besides this issue, call anon_vma_prepare() should be avoided because we don't copy page for this vma. Preparing anon_vma will be handled during fault. Fixes: d2cd9ede6e19 ("mm,fork: introduce MADV_WIPEONFORK") Signed-off-by: Li Xinhai Cc: Rik van Riel Cc: Kirill A. Shutemov Cc: Matthew Wilcox Acked-by: Kirill A. Shutemov --- kernel/fork.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 0808095..1bbd49a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -552,10 +552,12 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto fail_nomem_anon_vma_fork; if (tmp->vm_flags & VM_WIPEONFORK) { - /* VM_WIPEONFORK gets a clean slate in the child. */ + /* + * VM_WIPEONFORK gets a clean slate in the child. + * Don't prepare anon_vma until fault since we don't + * copy page for current vma. + */ tmp->anon_vma = NULL; - if (anon_vma_prepare(tmp)) - goto fail_nomem_anon_vma_fork; } else if (anon_vma_fork(tmp, mpnt)) goto fail_nomem_anon_vma_fork; tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);