From patchwork Tue Oct 13 01:34:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 11834695 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 37E90697 for ; Tue, 13 Oct 2020 01:34:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F01D021D7F for ; Tue, 13 Oct 2020 01:34:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=arista.com header.i=@arista.com header.b="CYzWXkjH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F01D021D7F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=arista.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2AA26940010; Mon, 12 Oct 2020 21:34:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2583394000F; Mon, 12 Oct 2020 21:34:29 -0400 (EDT) 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 F2C08940011; Mon, 12 Oct 2020 21:34:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id BF2CC94000F for ; Mon, 12 Oct 2020 21:34:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 691C3180AD807 for ; Tue, 13 Oct 2020 01:34:28 +0000 (UTC) X-FDA: 77365182216.25.river37_3a04f4e271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 2D9E31804E3A0 for ; Tue, 13 Oct 2020 01:34:28 +0000 (UTC) X-Spam-Summary: 1,0,0,7e737a3a43330b4c,d41d8cd98f00b204,dima@arista.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1541:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:4250:4321:5007:6119:6261:6653:6742:6743:7903:10004:11026:11658:11914:12296:12297:12438:12517:12519:12555:12895:12986:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21444:21451:21627:21990:30003:30054:30070:30079:30090,0,RBL:209.85.221.67:@arista.com:.lbl8.mailshell.net-66.100.201.201 62.2.0.100;04yfy7uwta1h4od6i66sq7exq1gzxoc7bxrises5i3b353axm4nay71io736ep4.45sjgm1cjy7dn49efijst39twunj7xwjtubsqaxdpuegern8sp4nyrdxugx7mek.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: river37_3a04f4e271ff X-Filterd-Recvd-Size: 5142 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:27 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id n6so21536667wrm.13 for ; Mon, 12 Oct 2020 18:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o+hT7zzmskqvyrywNbGv1SqYy6yeRy0QTDltdgYSbdc=; b=CYzWXkjHBNX+YU71eO5qpuuPH6qwUIdqJ/91p3uYMEMCdZAKCSTrNpq5TVbhmE0CD3 I/VxDj5wkbfpz7t0kQmbILNl/5EseAGLKDK8dCemcemqrzP3b56toQhhE3rNbnkWmkmm AICs1qLVVt2lax+VdQCmztePp5r0dg4+rFYAPJGdEALV5rSwyMg9LJiqUmL79gPixms9 ntjlR6MHQ1kYOjnTSbioqJvPiK4/DfA2peP3dpqJYRhN6pOfIolRGMfCAz3AdiWY+SBD Hjd8PJdjC3spCD+xAvw0TX9aA0hdWnJyRznCUfgv2rcesWONvNxkVjwNeIhJxKvga2lq sbdA== 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:mime-version:content-transfer-encoding; bh=o+hT7zzmskqvyrywNbGv1SqYy6yeRy0QTDltdgYSbdc=; b=GB5tjOWvJ4cZgUhRaP60E0xHsE/BHtaeo446x+81RJXhjGKg/8jhfstUZfgwphL6yA pCZL+VbQbv4jR+URMXR6+Wv+jYD1WKw2IJEDNp7tyUH+Xs+UTHFupLUyae15zo4RytE6 vJqIB9SlYgsxOGtQN6OmUc9ZbNMmjs+AF4wF/INNPFaky1bYQjZ3ddOpaeL8iMSdCxbd GFtGD09Ou7fuLRYpAoDOPmvQ+bpRGfbvuCc+QpUPexGBV4PbCnQXTOWdjCKWCQpbpAUf +xyDJ6wUH4jKPhTXdNZH2m77ZDQl4ZhMsraW4WAwkC5bBbrC5FXSsYI3TMafvOsFEKwy MmZg== X-Gm-Message-State: AOAM532SljZAAC/5P2MaPH95a53btOAiAeb/1ezXM/5Vy6/JJ1dO+OSI 85lbLRDwNIRx80ZATeEyVFzPhg== X-Google-Smtp-Source: ABdhPJx/eA0xaURdD39kuIvNIumfP2FJFkk5wEpy22MoNkD2iAsN3onMEMvZoLmBi3z0b1VkhtsO1w== X-Received: by 2002:a5d:4c8d:: with SMTP id z13mr16731759wrs.412.1602552866741; Mon, 12 Oct 2020 18:34:26 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:e84:2480:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id d23sm24825325wmb.6.2020.10.12.18.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:26 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Alexander Viro , Andrew Morton , Andy Lutomirski , Brian Geffon , Catalin Marinas , Dan Williams , Dave Jiang , Hugh Dickins , Ingo Molnar , "Kirill A. Shutemov" , Mike Kravetz , Minchan Kim , Russell King , Thomas Bogendoerfer , Thomas Gleixner , Vishal Verma , Vlastimil Babka , Will Deacon , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/6] mremap: Check if it's possible to split original vma Date: Tue, 13 Oct 2020 02:34:15 +0100 Message-Id: <20201013013416.390574-6-dima@arista.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201013013416.390574-1-dima@arista.com> References: <20201013013416.390574-1-dima@arista.com> MIME-Version: 1.0 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: If original VMA can't be split at the desired address, do_munmap() will fail and leave both new-copied VMA and old VMA. De-facto it's MREMAP_DONTUNMAP behaviour, which is unexpected. Currently, it may fail such way for hugetlbfs and dax device mappings. Minimize such unpleasant situations to OOM by checking .may_split() before attempting to create a VMA copy. Signed-off-by: Dmitry Safonov --- mm/mremap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 898e9818ba6d..3c4047c23673 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -343,7 +343,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, unsigned long excess = 0; unsigned long hiwater_vm; int split = 0; - int err; + int err = 0; bool need_rmap_locks; /* @@ -353,6 +353,15 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (mm->map_count >= sysctl_max_map_count - 3) return -ENOMEM; + if (vma->vm_ops && vma->vm_ops->may_split) { + if (vma->vm_start != old_addr) + err = vma->vm_ops->may_split(vma, old_addr); + if (!err && vma->vm_end != old_addr + old_len) + err = vma->vm_ops->may_split(vma, old_addr + old_len); + if (err) + return err; + } + /* * Advise KSM to break any KSM pages in the area to be moved: * it would be confusing if they were to turn up at the new