From patchwork Tue Oct 13 01:34:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 11834687 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 CF774697 for ; Tue, 13 Oct 2020 01:34:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7D53120870 for ; Tue, 13 Oct 2020 01:34:26 +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="J2rOTWZ8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D53120870 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 3E017900003; Mon, 12 Oct 2020 21:34:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 34269940007; Mon, 12 Oct 2020 21:34:23 -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 1B9D2900003; Mon, 12 Oct 2020 21:34:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id D4DAD940007 for ; Mon, 12 Oct 2020 21:34:22 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 77FA51EF1 for ; Tue, 13 Oct 2020 01:34:22 +0000 (UTC) X-FDA: 77365181964.07.need50_370b2a5271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 596E41803F9A4 for ; Tue, 13 Oct 2020 01:34:22 +0000 (UTC) X-Spam-Summary: 1,0,0,885fc17e0ee643d4,d41d8cd98f00b204,dima@arista.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1540:1711:1730:1747:1777:1792:2393:2559:2562:2890:2899:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3872:4042:4250:4321:5007:6261:6653:6742:6743:9036:10004:11026:11658:11914:12297:12517:12519:12555:12679:12895:12986:13069:13227:13229:13311:13357:13894:14181:14384:14394:14721:21080:21444:21450:21451:21627:21660:21966:30001:30054:30079,0,RBL:209.85.128.65:@arista.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yfwo7c5yrkct45zfkrjne7du7wjyp34ond6uebxbac66brcmsyej7zzfteair.6u16q485cf6q3utrcsgrgxku886n4rcw3x9xsgwp5619wm8tumhqh9hwdn5nahf.s-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: need50_370b2a5271ff X-Filterd-Recvd-Size: 4668 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:21 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id a72so8673179wme.5 for ; Mon, 12 Oct 2020 18:34:21 -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=DaxIr5597WF0kxpEElTZVLTN61vAhnpO/2r1W4YxrO0=; b=J2rOTWZ8Lr5Wf2QMpwxeIwTk31F0CcPsxAE+ecneTuceI94efNcmEIgFo7sgQ5lmkn zLqcJTHbLpzPMw8OtVmyeRDaSk7WV69pJ35WU8S/Ni5BQSLXCGOMFKIr7yCZ95uiklXu AhGmVvlhf//oWpBLnP9Pbi9S9Pwm1hZ5YPKuv0zyUoCV3Fn+Aha/78ZfCxKT06boM6hV CEQgE4qDGlvBcUzSZvJQRXYHTypYqNFf9/hCzW4zFumXGHjPHoQ4nsxJGEqUsifC9zB+ ggvSzmzm+sUfR8KHUE7y6WLZ12vUAGmWR+1sz/qeHvP3y5XGFPLwNBoyR9cfLfWhG3fx qTYw== 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=DaxIr5597WF0kxpEElTZVLTN61vAhnpO/2r1W4YxrO0=; b=OIzG7/Zhcra5CUjYFg35+/6QN4NZ3sMK/FluNBi3JAkNMXnCvU0PYCfXJfO2pS1kRM fA+aDP5Z/6+qmEtkMVGAth2xHxzq3TdaQPOOfSOip0SaSH4oD6FnQu3NzPCnrhZL5l23 hpmb8OJGSQO1gccYCrXTpSHAvVk8GLVp74ERcpywNjezJESGFd20HZDbcpjekxFwqjDQ zD0+86D9a1jH2exzAgljomiOxzIP204CNRgIo//4dMYGnQmE2940zUxBQG4qCJfBfaWc P2DD73UCzTu1vK77nRiG8udo9vaTBVzcHM+4ElzM0Jy6sUrSCvW46CEqL0ko8whOo+qo 3VAw== X-Gm-Message-State: AOAM530fBq+4t5yaKMDAEAN2oBeOVYvjLyQvCrjludtDh5GbEXIN6/KR G0MxJWjygSbuQi2x7LnghewxHg== X-Google-Smtp-Source: ABdhPJwGpJy4DdZ/eC/fCwJjqmeUbVJXNMLzWnkwR0hTzvknEAdfYsGaIbJtZWKk1I+xy8WZjoA44w== X-Received: by 2002:a1c:48d4:: with SMTP id v203mr10067253wma.122.1602552860468; Mon, 12 Oct 2020 18:34:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:19 -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 1/6] mm/mremap: Account memory on do_munmap() failure Date: Tue, 13 Oct 2020 02:34:11 +0100 Message-Id: <20201013013416.390574-2-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: move_vma() copies VMA without adding it to account, then unmaps old part of VMA. On failure it unmaps the new VMA. With hacks accounting in munmap is disabled as it's a copy of existing VMA. Account the memory on munmap() failure which was previously copied into a new VMA. Fixes: commit e2ea83742133 ("[PATCH] mremap: move_vma fixes and cleanup") Signed-off-by: Dmitry Safonov --- mm/mremap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 138abbae4f75..03d31a0d4c67 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -450,7 +450,8 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (do_munmap(mm, old_addr, old_len, uf_unmap) < 0) { /* OOM: unable to split vma, just get accounts right */ - vm_unacct_memory(excess >> PAGE_SHIFT); + if (vm_flags & VM_ACCOUNT) + vm_acct_memory(new_len >> PAGE_SHIFT); excess = 0; } From patchwork Tue Oct 13 01:34:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 11834689 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 6C342697 for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2E76621D7F for ; Tue, 13 Oct 2020 01:34:29 +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="FGKDY4+X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E76621D7F 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 8BA31940007; Mon, 12 Oct 2020 21:34:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7FABF94000B; Mon, 12 Oct 2020 21:34:24 -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 676A4940007; Mon, 12 Oct 2020 21:34:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 29C2494000A for ; Mon, 12 Oct 2020 21:34:24 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AB01E181AE865 for ; Tue, 13 Oct 2020 01:34:23 +0000 (UTC) X-FDA: 77365182006.04.bear15_050ef6a271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 9086580061E1 for ; Tue, 13 Oct 2020 01:34:23 +0000 (UTC) X-Spam-Summary: 1,0,0,efc1ff3fdb2e088d,d41d8cd98f00b204,dima@arista.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2393:2553:2559:2562:2890:2910:3138:3139:3140:3141:3142:3355:3865:3866:3867:3870:3871:3872:3874:4118:4250:4321:5007:6261:6653:6742:6743:9036:9592:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12679:12683:12895:12986:13255:13894:14181:14394:14721:21080:21220:21444:21450:21451:21627:21990:30054:30069:30070:30079:30090,0,RBL:209.85.128.67:@arista.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yfu1tj1w7g8zjd8wfzqo5g43pgbop84yw1n4dh6bw78tkk1rxuq4iu8h9axow.p8kw8dmnn8wo7fr9ij9mdnyp8otjk79cgzsfqoh79jfd9e7mp6hb9wnzxgof6c1.q-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: bear15_050ef6a271ff X-Filterd-Recvd-Size: 7077 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:22 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id e23so12248154wme.2 for ; Mon, 12 Oct 2020 18:34:22 -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=N0dBjMGQZwr5fzpQZu0PyDC9RTW1+FomX32MrbIIN2c=; b=FGKDY4+X3JgwoUoN1C/3HtoPUDzAwaeKRnm9weDnUEBjEuPWSOeILJ5WitdE7ezOUP Z8h6z8QjmHrQkKSfvP/CqOKrMe2VeWaoWuM1DTGhWnLuZk1g88dKU5Im4GTOJwORpW2f UuV18UZCz944g3qypRZ2XQhlg6JzVZmLhMr5Bs/tnrm1RAUdEgB/WdGaLZGTdqqhIMgV pfG53+RblNOsJA22ZNjqtEkKPrKzJBc7Og2rE+hr0YIrlaORjXWV2alA7tDY1jhP1fno 43O1Nu5NaFD+pRDCg3zxhKfu0Owyg1VkXKC8ZVHZFjGsiuAaTBtUv+EuEgHOsI8dOIdW j1Xw== 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=N0dBjMGQZwr5fzpQZu0PyDC9RTW1+FomX32MrbIIN2c=; b=b8QonqZko8MabQ6AN+IGaZWQnP/Ot//qtAfSzKtp9118PFC6kagLIRLEfRpIJuDwW0 Dchxr0ByYNyd7KMAjpU3AtuqtjyITaI6B81kxTezbbcfVtVZmnox2dVTH2R+i9WcgTqG t5U/i2YezgrcbS5IqDRImQVEWTWVCr9hdswS+1Bcm1xzkKpZlycmiEoJFiODsWZZeU9e Zbxmqxhon2L+h81esD382i6cNNyZl2EapL+bWnZbcSLxtIAPRkRKtiWsvMZcWATe3OcZ DSrcUgmX4IipJg5m1V04dbM+3Idnngll684wS3d4jMaSvGsFMYk9RbGan9tX3kGCNZdX fyIg== X-Gm-Message-State: AOAM531XuGSP9T4SdzR8QZPyXFnFQf4qsVMs+RHS8VCGNfF0uScRHzVv B3r86jCMEXQ8g+f3RFUYvhludg== X-Google-Smtp-Source: ABdhPJzYLde4t7k258XJEoIwmIIg3SOE4QcEX3b/iLBAwsA51BD5ldG7hvxtYYzYqpyGbgSwcygcoQ== X-Received: by 2002:a7b:c0c8:: with SMTP id s8mr12752537wmh.78.1602552862013; Mon, 12 Oct 2020 18:34:22 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:21 -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 2/6] mm/mremap: For MREMAP_DONTUNMAP check security_vm_enough_memory_mm() Date: Tue, 13 Oct 2020 02:34:12 +0100 Message-Id: <20201013013416.390574-3-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: Currently memory is accounted post-mremap() with MREMAP_DONTUNMAP, which may break overcommit policy. So, check if there's enough memory before doing actual VMA copy. Don't unset VM_ACCOUNT on MREMAP_DONTUNMAP. By semantics, such mremap() is actually a memory allocation. That also simplifies the error-path a little. Also, as it's memory allocation on success don't reset hiwater_vm value. Fixes: commit e346b3813067 ("mm/mremap: add MREMAP_DONTUNMAP to mremap()") Signed-off-by: Dmitry Safonov --- mm/mremap.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 03d31a0d4c67..c248f9a52125 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -365,11 +365,19 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (err) return err; + if (unlikely(flags & MREMAP_DONTUNMAP && vm_flags & VM_ACCOUNT)) { + if (security_vm_enough_memory_mm(mm, new_len >> PAGE_SHIFT)) + return -ENOMEM; + } + new_pgoff = vma->vm_pgoff + ((old_addr - vma->vm_start) >> PAGE_SHIFT); new_vma = copy_vma(&vma, new_addr, new_len, new_pgoff, &need_rmap_locks); - if (!new_vma) + if (!new_vma) { + if (unlikely(flags & MREMAP_DONTUNMAP && vm_flags & VM_ACCOUNT)) + vm_unacct_memory(new_len >> PAGE_SHIFT); return -ENOMEM; + } moved_len = move_page_tables(vma, old_addr, new_vma, new_addr, old_len, need_rmap_locks); @@ -398,7 +406,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, } /* Conceal VM_ACCOUNT so old reservation is not undone */ - if (vm_flags & VM_ACCOUNT) { + if (vm_flags & VM_ACCOUNT && !(flags & MREMAP_DONTUNMAP)) { vma->vm_flags &= ~VM_ACCOUNT; excess = vma->vm_end - vma->vm_start - old_len; if (old_addr > vma->vm_start && @@ -423,34 +431,16 @@ static unsigned long move_vma(struct vm_area_struct *vma, untrack_pfn_moved(vma); if (unlikely(!err && (flags & MREMAP_DONTUNMAP))) { - if (vm_flags & VM_ACCOUNT) { - /* Always put back VM_ACCOUNT since we won't unmap */ - vma->vm_flags |= VM_ACCOUNT; - - vm_acct_memory(new_len >> PAGE_SHIFT); - } - - /* - * VMAs can actually be merged back together in copy_vma - * calling merge_vma. This can happen with anonymous vmas - * which have not yet been faulted, so if we were to consider - * this VMA split we'll end up adding VM_ACCOUNT on the - * next VMA, which is completely unrelated if this VMA - * was re-merged. - */ - if (split && new_vma == vma) - split = 0; - /* We always clear VM_LOCKED[ONFAULT] on the old vma */ vma->vm_flags &= VM_LOCKED_CLEAR_MASK; /* Because we won't unmap we don't need to touch locked_vm */ - goto out; + return new_addr; } if (do_munmap(mm, old_addr, old_len, uf_unmap) < 0) { /* OOM: unable to split vma, just get accounts right */ - if (vm_flags & VM_ACCOUNT) + if (vm_flags & VM_ACCOUNT && !(flags & MREMAP_DONTUNMAP)) vm_acct_memory(new_len >> PAGE_SHIFT); excess = 0; } @@ -459,7 +449,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, mm->locked_vm += new_len >> PAGE_SHIFT; *locked = true; } -out: + mm->hiwater_vm = hiwater_vm; /* Restore VM_ACCOUNT if one or two pieces of vma left */ From patchwork Tue Oct 13 01:34:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 11834691 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 A564316BC for ; Tue, 13 Oct 2020 01:34:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 66C032087E for ; Tue, 13 Oct 2020 01:34:32 +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="jh6Shp34" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66C032087E 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 2105194000E; Mon, 12 Oct 2020 21:34:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0D5D394000A; Mon, 12 Oct 2020 21:34:26 -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 E3EB894000D; Mon, 12 Oct 2020 21:34:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id B093294000A for ; Mon, 12 Oct 2020 21:34:25 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 528611EE6 for ; Tue, 13 Oct 2020 01:34:25 +0000 (UTC) X-FDA: 77365182090.17.debt53_3a04b80271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 393D1180D0180 for ; Tue, 13 Oct 2020 01:34:25 +0000 (UTC) X-Spam-Summary: 1,0,0,49110d499938ca5b,d41d8cd98f00b204,dima@arista.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:1801:2194:2196:2199:2200:2393:2553:2559:2562:2689:3138:3139:3140:3141:3142:3354:3865:3866:3867:3872:4118:4321:4385:4605:5007:6261:6653:6742:6743:7903:10004:11026:11473:11657:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13894:14096:14181:14394:14721:21080:21220:21444:21451:21627:21987:21990:30029:30054:30090,0,RBL:209.85.221.65:@arista.com:.lbl8.mailshell.net-66.100.201.201 62.2.0.100;04y81gmomdbfr36gd1y6sc5rgtyxhocipysq5ik3gbnghupdh1i5e3ar3s8gf8c.qxaqhxudyb3qb9fdjwcz6i9bmr8ws5yz194rg5um9fpydm5rcjxit7jy3ze8wyj.1-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: debt53_3a04b80271ff X-Filterd-Recvd-Size: 7266 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:24 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id e17so21806020wru.12 for ; Mon, 12 Oct 2020 18:34:24 -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=VQFsEpWuF4crrAFVUaO/CXC4VHrsA3+ZAZo85Yi/pU0=; b=jh6Shp34HrXFqwhbRrxN+YgzPDA8OoKF04HoFiyNjYZbVjAQaB03yWzpCRAqet1tBl qznQQVvt39gfc+rca19EffWNQulmC0gW4kOZ8oTyFIs115lHAaCkdHebfOmk4vwVJUR1 d2bQ9UoW57Nh9V9EzhGNzvekxXH9NTWdA1QVVsRmgMdO4ONwKofcPq8xEzaBF3S4R5jg jdusZLNIDiReYRlgKGWx6Z/UqIV8WzrGb6kyLnbpUec/Bapgh5SfttlYv6fPecZcoanq byDqDGINOzYslI8U3EIjdSphlS2zzm6PJPCEHPm660qZ4fQUqAT8u67Dx5YXCG+X9fLu uI9A== 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=VQFsEpWuF4crrAFVUaO/CXC4VHrsA3+ZAZo85Yi/pU0=; b=frtbwDHYlQafgQFunrBp4It1oX/8MJpZWOQLPEl5v0qH63Fm019Is4xbApq8y/dFKI fOmAR9FDNbAC0YlVEbExxjHjKnYwe9zxhZk7P6t6v/9wX83wtb61LhigCVod3jiP/C8A 9bn07aundN+0YWq1R39TsM3p4ShySdHQZ4/3KttEgDAPJuzDyjhyk1czK6/vV8LcmOw5 o86fj1KcRYMuIAhViqw1R/fWtYSD04e6Qv+KH9ca3BCgbWYrDOQtg/CHfkIW09WGi6p7 Hj/rPOhdJ/MOFrA1ndSKVjHQE6t15PNG3i8R1S/MtVGLpYB1D34hSaealAJOsPW02KCT wgcg== X-Gm-Message-State: AOAM531pJwEPEFkXdU0NyxaoIG1RyE+db7fYp0iJp87v0CZgH5azA84Q jCa9opzysOZ6Z+bIP8R5S+PT6A== X-Google-Smtp-Source: ABdhPJw5vKLkrkjcJCNIMOOzrKmqWdjiE3iZi/mIzmQ8aAHgnoINflz5eE8APWdVPpZyrKnFlUqGEw== X-Received: by 2002:adf:e881:: with SMTP id d1mr21447682wrm.395.1602552863641; Mon, 12 Oct 2020 18:34:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:23 -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 3/6] mremap: Don't allow MREMAP_DONTUNMAP on special_mappings and aio Date: Tue, 13 Oct 2020 02:34:13 +0100 Message-Id: <20201013013416.390574-4-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: As kernel expect to see only one of such mappings, any further operations on the VMA-copy may be unexpected by the kernel. Maybe it's being on the safe side, but there doesn't seem to be any expected use-case for this, so restrict it now. Fixes: commit e346b3813067 ("mm/mremap: add MREMAP_DONTUNMAP to mremap()") Signed-off-by: Dmitry Safonov --- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- fs/aio.c | 5 ++++- include/linux/mm.h | 2 +- mm/mmap.c | 6 +++++- mm/mremap.c | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index 0daf2f1cf7a8..e916646adc69 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -1458,7 +1458,7 @@ static int pseudo_lock_dev_release(struct inode *inode, struct file *filp) return 0; } -static int pseudo_lock_dev_mremap(struct vm_area_struct *area) +static int pseudo_lock_dev_mremap(struct vm_area_struct *area, unsigned long flags) { /* Not supported */ return -EINVAL; diff --git a/fs/aio.c b/fs/aio.c index d5ec30385566..3be3c0f77548 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -324,13 +324,16 @@ static void aio_free_ring(struct kioctx *ctx) } } -static int aio_ring_mremap(struct vm_area_struct *vma) +static int aio_ring_mremap(struct vm_area_struct *vma, unsigned long flags) { struct file *file = vma->vm_file; struct mm_struct *mm = vma->vm_mm; struct kioctx_table *table; int i, res = -EINVAL; + if (flags & MREMAP_DONTUNMAP) + return -EINVAL; + spin_lock(&mm->ioctx_lock); rcu_read_lock(); table = rcu_dereference(mm->ioctx_table); diff --git a/include/linux/mm.h b/include/linux/mm.h index 16b799a0522c..fd51a4a1f722 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -550,7 +550,7 @@ struct vm_operations_struct { void (*open)(struct vm_area_struct * area); void (*close)(struct vm_area_struct * area); int (*split)(struct vm_area_struct * area, unsigned long addr); - int (*mremap)(struct vm_area_struct * area); + int (*mremap)(struct vm_area_struct *area, unsigned long flags); vm_fault_t (*fault)(struct vm_fault *vmf); vm_fault_t (*huge_fault)(struct vm_fault *vmf, enum page_entry_size pe_size); diff --git a/mm/mmap.c b/mm/mmap.c index bdd19f5b994e..50f853b0ec39 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3372,10 +3372,14 @@ static const char *special_mapping_name(struct vm_area_struct *vma) return ((struct vm_special_mapping *)vma->vm_private_data)->name; } -static int special_mapping_mremap(struct vm_area_struct *new_vma) +static int special_mapping_mremap(struct vm_area_struct *new_vma, + unsigned long flags) { struct vm_special_mapping *sm = new_vma->vm_private_data; + if (flags & MREMAP_DONTUNMAP) + return -EINVAL; + if (WARN_ON_ONCE(current->mm != new_vma->vm_mm)) return -EFAULT; diff --git a/mm/mremap.c b/mm/mremap.c index c248f9a52125..898e9818ba6d 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -384,7 +384,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (moved_len < old_len) { err = -ENOMEM; } else if (vma->vm_ops && vma->vm_ops->mremap) { - err = vma->vm_ops->mremap(new_vma); + err = vma->vm_ops->mremap(new_vma, flags); } if (unlikely(err)) { From patchwork Tue Oct 13 01:34:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 11834693 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 0F1DF16BC for ; Tue, 13 Oct 2020 01:34:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BBE8B21741 for ; Tue, 13 Oct 2020 01:34:35 +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="YferU0tb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBE8B21741 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 935C894000D; Mon, 12 Oct 2020 21:34:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8E85A94000B; Mon, 12 Oct 2020 21:34:27 -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 7142F94000D; Mon, 12 Oct 2020 21:34:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 3D2F994000B for ; Mon, 12 Oct 2020 21:34:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D4B7F8249980 for ; Tue, 13 Oct 2020 01:34:26 +0000 (UTC) X-FDA: 77365182132.07.tent41_34042f9271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id B35C01803F9A8 for ; Tue, 13 Oct 2020 01:34:26 +0000 (UTC) X-Spam-Summary: 1,0,0,52c0f3200e0ff971,d41d8cd98f00b204,dima@arista.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3355:3865:3867:3871:3872:3874:4118:4321:4605:5007:6119:6261:6653:6742:6743:10004:11026:11473:11658:11914:12296:12297:12438:12517:12519:12555:12895:12986:13894:14096:14181:14394:14721:21080:21212:21444:21451:21627:21987:21990:30054:30070,0,RBL:209.85.221.66:@arista.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04ygm8xi3kqguxuigqskw4a34jmtzocjq6aakomcpkuzr4u9khagi4qqo4mjot3.a5eu3td5jud97zi9cj8b317xzmmgey9opmoidxhmwxjd7gakysqzjaqqx1yjptq.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:23,LUA_SUMMARY:none X-HE-Tag: tent41_34042f9271ff X-Filterd-Recvd-Size: 7545 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:26 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id n6so21536620wrm.13 for ; Mon, 12 Oct 2020 18:34:26 -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=pPwHwZEP2PqHjnQGol/aPrlKhQ+v52jFp6WQVgPqijE=; b=YferU0tbNRf+gxmODbnA9Mqj4CpE0dtIAEistHAFS9i3faI1yKc65RMZjMueeuAd6K v90BcKD8EX8QrUHOBuc4RWU+YiTI127qs5q/pJVwzTOsSBeMcxB+oU2aVU55wR6pUlRv SK4XoL4NVCK1yi9eXXrxvr+Hj+52qancDHwYD07EaxXrNrtycjOMzvm0DxsjDe0Yr0Ym fy/5nhiDgsBYbPKPmos1hfATHBYfbuDpAX3q/tHFinsU09UpL8L6CMHFoHKZdGQST4Fx VqAQoWLpkvmc+4PZzRrMb/5p1F7aQWI0x1fji1HYeph0/+jjPTkmcPOZJhw2LejVQqoH 0K7Q== 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=pPwHwZEP2PqHjnQGol/aPrlKhQ+v52jFp6WQVgPqijE=; b=OAxjRc95QuI3CUrvUJOj7rTUO3BpTKUN7nCgUtRM5YqtMsvC1nU+PTR135p+DfClUU yYxwwLSzNKHLWkS063XtFiYpdpbI939w/jNMKtUX2npipAm+OritQeTV+yKO9O2vGGkU VdslWSN2fEmncJqZKp7pN3Jr4Ct+INQCHsm1/fmFHnmuraOtvwWTFZkn9wKh+aT2hqaX kY8Hlx5ybIx4KKDjscjjXqCCqu9AYOsi8U2ZIKFGSNg7w6C2QCfVEfj/qOWl0W4gUPOm Gv1aVCF7Owcxq3jcj9gaoGJr7rkTq/QsnHsih1eqyvfaHkm/RTyXl19Tx5N6/V1DYUJv 5Wzg== X-Gm-Message-State: AOAM530qcen1r3AF12AtxhYB4J6SJxy3OUM0O//BrdyqlUf0qlAplehz 1aHADDTgPIE1vR6paRVzRvI0tA== X-Google-Smtp-Source: ABdhPJx2Iz5ia07SkXg8JuVb45XrLxBzUgObuPt4vpXjnHItp8RoscX39wxroX44gq9L0v4LP5bsSA== X-Received: by 2002:adf:fc8b:: with SMTP id g11mr480698wrr.300.1602552865214; Mon, 12 Oct 2020 18:34:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:24 -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 4/6] vm_ops: Rename .split() callback to .may_split() Date: Tue, 13 Oct 2020 02:34:14 +0100 Message-Id: <20201013013416.390574-5-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: Rename the callback to reflect that it's not called *on* or *after* split, but rather some time before the splitting to check if it's possible. Signed-off-by: Dmitry Safonov --- drivers/dax/device.c | 4 ++-- include/linux/mm.h | 3 ++- ipc/shm.c | 8 ++++---- mm/hugetlb.c | 2 +- mm/mmap.c | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 1e89513f3c59..223dd1d13d5c 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -276,7 +276,7 @@ static vm_fault_t dev_dax_fault(struct vm_fault *vmf) return dev_dax_huge_fault(vmf, PE_SIZE_PTE); } -static int dev_dax_split(struct vm_area_struct *vma, unsigned long addr) +static int dev_dax_may_split(struct vm_area_struct *vma, unsigned long addr) { struct file *filp = vma->vm_file; struct dev_dax *dev_dax = filp->private_data; @@ -299,7 +299,7 @@ static unsigned long dev_dax_pagesize(struct vm_area_struct *vma) static const struct vm_operations_struct dax_vm_ops = { .fault = dev_dax_fault, .huge_fault = dev_dax_huge_fault, - .split = dev_dax_split, + .may_split = dev_dax_may_split, .pagesize = dev_dax_pagesize, }; diff --git a/include/linux/mm.h b/include/linux/mm.h index fd51a4a1f722..90887661ef44 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -549,7 +549,8 @@ enum page_entry_size { struct vm_operations_struct { void (*open)(struct vm_area_struct * area); void (*close)(struct vm_area_struct * area); - int (*split)(struct vm_area_struct * area, unsigned long addr); + /* Called any time before splitting to check if it's allowed */ + int (*may_split)(struct vm_area_struct *area, unsigned long addr); int (*mremap)(struct vm_area_struct *area, unsigned long flags); vm_fault_t (*fault)(struct vm_fault *vmf); vm_fault_t (*huge_fault)(struct vm_fault *vmf, diff --git a/ipc/shm.c b/ipc/shm.c index e25c7c6106bc..febd88daba8c 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -434,13 +434,13 @@ static vm_fault_t shm_fault(struct vm_fault *vmf) return sfd->vm_ops->fault(vmf); } -static int shm_split(struct vm_area_struct *vma, unsigned long addr) +static int shm_may_split(struct vm_area_struct *vma, unsigned long addr) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); - if (sfd->vm_ops->split) - return sfd->vm_ops->split(vma, addr); + if (sfd->vm_ops->may_split) + return sfd->vm_ops->may_split(vma, addr); return 0; } @@ -582,7 +582,7 @@ static const struct vm_operations_struct shm_vm_ops = { .open = shm_open, /* callback for a new vm-area open */ .close = shm_close, /* callback for when the vm-area is released */ .fault = shm_fault, - .split = shm_split, + .may_split = shm_may_split, .pagesize = shm_pagesize, #if defined(CONFIG_NUMA) .set_policy = shm_set_policy, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 67fc6383995b..c4dc0e453be1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3759,7 +3759,7 @@ const struct vm_operations_struct hugetlb_vm_ops = { .fault = hugetlb_vm_op_fault, .open = hugetlb_vm_op_open, .close = hugetlb_vm_op_close, - .split = hugetlb_vm_op_split, + .may_split = hugetlb_vm_op_split, .pagesize = hugetlb_vm_op_pagesize, }; diff --git a/mm/mmap.c b/mm/mmap.c index 50f853b0ec39..a62cb3ccafce 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2693,8 +2693,8 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_area_struct *new; int err; - if (vma->vm_ops && vma->vm_ops->split) { - err = vma->vm_ops->split(vma, addr); + if (vma->vm_ops && vma->vm_ops->may_split) { + err = vma->vm_ops->may_split(vma, addr); if (err) return err; } 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 From patchwork Tue Oct 13 01:34:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 11834697 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 B2A7D16BC for ; Tue, 13 Oct 2020 01:34:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6CA3B20870 for ; Tue, 13 Oct 2020 01:34:41 +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="YoPP5Gks" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CA3B20870 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 84FE5940014; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 73EDC940013; Mon, 12 Oct 2020 21:34:30 -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 59E7A94000F; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1D4FE94000F for ; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BBF971EF1 for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) X-FDA: 77365182258.03.snail69_2b13d7c271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id A482128A4EC for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) X-Spam-Summary: 1,0,0,6a7b03881eea477c,d41d8cd98f00b204,dima@arista.com,,RULES_HIT:1:2:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1500:1515:1605:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:2901:2918:3138:3139:3140:3141:3142:3865:3866:3868:3870:3872:3874:4050:4250:4321:4605:5007:6261:6653:6742:6743:7875:7903:8603:9592:10004:11026:11473:11657:11658:11914:12043:12296:12297:12438:12517:12519:12555:12683:12895:12986:13161:13229:13894:14096:14110:14394:21080:21324:21325:21433:21444:21451:21627:21990:30003:30012:30029:30034:30051:30054,0,RBL:209.85.221.65:@arista.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04ygg6xqnb9ws9r7memcj3sma1yipyceua36wgcpbt58t8xffge7bdp1w587qfc.gyaqe83ujo9gp7w51ku7jkqy6eri9i8pwkrgrjckxsuixuupjp3jh5pxxwycbis.6-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: snail69_2b13d7c271ff X-Filterd-Recvd-Size: 11573 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id e18so21821829wrw.9 for ; Mon, 12 Oct 2020 18:34:29 -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=QI03JfUdAeqx8H20V8QB+drTDnXgJr9KGaylcrY6E98=; b=YoPP5GksBayPf3YA7iKAhJRnUEw9hLY1epr3iRj1JZcb8AczM+hA8gE9m8KN3op2hH oJsdXJN/juKuz/IX0LfynhImiuc5BXLZODpopg9/dKr6AO5DRbo9eA+/Tnk/Gabp3M32 tkI9HX8Xfzgr1+RZ8d30CYRYuDbqOlpwz4S6/cLFPpzLykgpt4SgsKyVRhuDvdZU7s4v NAO+0SFtu8dVFDXQeh+Auwyk497u1Pq+RVy+QnuzyxP0dcf8CWnY74eu++KCgV7f6NBm tPhM5ye4nI4QHXHZl0BXKrOGmccM9xxAGF+qOIqP9KaDmawf/AP/lR7OtcjlGuH0ZUil +mlw== 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=QI03JfUdAeqx8H20V8QB+drTDnXgJr9KGaylcrY6E98=; b=EJaHPQ7w85mTa/aEWOkIobEKW6dnTSSpqy+trCPmwnZiC6LIrfpi8B4IfakuTxM5IK gGJCS9YXwEw62Y0Vh4ufpAl8tnFdpfcwTYm8SnArUh8CyA7sN4Xz9hwXseyekQ4gycvC sZhsBQY95+IGtVWruEbdHtAVA4E+y3HZU5czAJwxJ9HHPTlYSAUolxqi0bDFk2NtLho9 TXIiV/1Nvcw1k3tznF9MDjxORWNX8ThHjkSF1OD2f7wy1bE8zH7ep+AXBsFwZK+Rodqw 37Sw1vEJGcwAKCuTAUPgM0e0B50gU+OeGwiIyEAcGX+dyigtaErSAErOPrHHTHoTe7IX KRCQ== X-Gm-Message-State: AOAM532nF6Ii1wgBqDtV3HNYBpq4rGF08cYG/z+qntO6NjOJABJBjkmN ajal8uGr26RPDBB1iVPwAnEIww== X-Google-Smtp-Source: ABdhPJzRUrGoqc2gRFrRPbwBQLI+3EviW230fK5qUbXR+5lWN/w2oMhECQzgHSMuyap8rQ2Z9wPpZQ== X-Received: by 2002:adf:e64e:: with SMTP id b14mr7124845wrn.68.1602552868235; Mon, 12 Oct 2020 18:34:28 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:27 -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 6/6] mm: Forbid splitting special mappings Date: Tue, 13 Oct 2020 02:34:16 +0100 Message-Id: <20201013013416.390574-7-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: Don't allow splitting of vm_special_mapping's. It affects vdso/vvar areas. Uprobes have only one page in xol_area so they aren't affected. Those restrictions were enforced by checks in .mremap() callbacks. Restrict resizing with generic .split() callback. Signed-off-by: Dmitry Safonov Acked-by: Will Deacon --- arch/arm/kernel/vdso.c | 9 --------- arch/arm64/kernel/vdso.c | 41 +++------------------------------------ arch/mips/vdso/genvdso.c | 4 ---- arch/s390/kernel/vdso.c | 11 +---------- arch/x86/entry/vdso/vma.c | 17 ---------------- mm/mmap.c | 12 ++++++++++++ 6 files changed, 16 insertions(+), 78 deletions(-) diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index fddd08a6e063..3408269d19c7 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -50,15 +50,6 @@ static const struct vm_special_mapping vdso_data_mapping = { static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { - unsigned long new_size = new_vma->vm_end - new_vma->vm_start; - unsigned long vdso_size; - - /* without VVAR page */ - vdso_size = (vdso_total_pages - 1) << PAGE_SHIFT; - - if (vdso_size != new_size) - return -EINVAL; - current->mm->context.vdso = new_vma->vm_start; return 0; diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index d4202a32abc9..a1a4220a405b 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -82,17 +82,9 @@ static union { } vdso_data_store __page_aligned_data; struct vdso_data *vdso_data = vdso_data_store.data; -static int __vdso_remap(enum vdso_abi abi, - const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) +static int vdso_mremap(const struct vm_special_mapping *sm, + struct vm_area_struct *new_vma) { - unsigned long new_size = new_vma->vm_end - new_vma->vm_start; - unsigned long vdso_size = vdso_info[abi].vdso_code_end - - vdso_info[abi].vdso_code_start; - - if (vdso_size != new_size) - return -EINVAL; - current->mm->context.vdso = (void *)new_vma->vm_start; return 0; @@ -223,17 +215,6 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, return vmf_insert_pfn(vma, vmf->address, pfn); } -static int vvar_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - unsigned long new_size = new_vma->vm_end - new_vma->vm_start; - - if (new_size != VVAR_NR_PAGES * PAGE_SIZE) - return -EINVAL; - - return 0; -} - static int __setup_additional_pages(enum vdso_abi abi, struct mm_struct *mm, struct linux_binprm *bprm, @@ -284,14 +265,6 @@ static int __setup_additional_pages(enum vdso_abi abi, /* * Create and map the vectors page for AArch32 tasks. */ -#ifdef CONFIG_COMPAT_VDSO -static int aarch32_vdso_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - return __vdso_remap(VDSO_ABI_AA32, sm, new_vma); -} -#endif /* CONFIG_COMPAT_VDSO */ - enum aarch32_map { AA32_MAP_VECTORS, /* kuser helpers */ #ifdef CONFIG_COMPAT_VDSO @@ -313,11 +286,10 @@ static struct vm_special_mapping aarch32_vdso_maps[] = { [AA32_MAP_VVAR] = { .name = "[vvar]", .fault = vvar_fault, - .mremap = vvar_mremap, }, [AA32_MAP_VDSO] = { .name = "[vdso]", - .mremap = aarch32_vdso_mremap, + .mremap = vdso_mremap, }, #endif /* CONFIG_COMPAT_VDSO */ [AA32_MAP_SIGPAGE] = { @@ -465,12 +437,6 @@ int aarch32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) } #endif /* CONFIG_COMPAT */ -static int vdso_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - return __vdso_remap(VDSO_ABI_AA64, sm, new_vma); -} - enum aarch64_map { AA64_MAP_VVAR, AA64_MAP_VDSO, @@ -480,7 +446,6 @@ static struct vm_special_mapping aarch64_vdso_maps[] __ro_after_init = { [AA64_MAP_VVAR] = { .name = "[vvar]", .fault = vvar_fault, - .mremap = vvar_mremap, }, [AA64_MAP_VDSO] = { .name = "[vdso]", diff --git a/arch/mips/vdso/genvdso.c b/arch/mips/vdso/genvdso.c index abb06ae04b40..09e30eb4be86 100644 --- a/arch/mips/vdso/genvdso.c +++ b/arch/mips/vdso/genvdso.c @@ -263,10 +263,6 @@ int main(int argc, char **argv) fprintf(out_file, " const struct vm_special_mapping *sm,\n"); fprintf(out_file, " struct vm_area_struct *new_vma)\n"); fprintf(out_file, "{\n"); - fprintf(out_file, " unsigned long new_size =\n"); - fprintf(out_file, " new_vma->vm_end - new_vma->vm_start;\n"); - fprintf(out_file, " if (vdso_image.size != new_size)\n"); - fprintf(out_file, " return -EINVAL;\n"); fprintf(out_file, " current->mm->context.vdso =\n"); fprintf(out_file, " (void *)(new_vma->vm_start);\n"); fprintf(out_file, " return 0;\n"); diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c index c4baefaa6e34..291ead792d64 100644 --- a/arch/s390/kernel/vdso.c +++ b/arch/s390/kernel/vdso.c @@ -59,17 +59,8 @@ static vm_fault_t vdso_fault(const struct vm_special_mapping *sm, static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *vma) { - unsigned long vdso_pages; - - vdso_pages = vdso64_pages; - - if ((vdso_pages << PAGE_SHIFT) != vma->vm_end - vma->vm_start) - return -EINVAL; - - if (WARN_ON_ONCE(current->mm != vma->vm_mm)) - return -EFAULT; - current->mm->context.vdso_base = vma->vm_start; + return 0; } diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 9185cb1d13b9..0c942b31825d 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -89,30 +89,14 @@ static void vdso_fix_landing(const struct vdso_image *image, static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { - unsigned long new_size = new_vma->vm_end - new_vma->vm_start; const struct vdso_image *image = current->mm->context.vdso_image; - if (image->size != new_size) - return -EINVAL; - vdso_fix_landing(image, new_vma); current->mm->context.vdso = (void __user *)new_vma->vm_start; return 0; } -static int vvar_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - const struct vdso_image *image = new_vma->vm_mm->context.vdso_image; - unsigned long new_size = new_vma->vm_end - new_vma->vm_start; - - if (new_size != -image->sym_vvar_start) - return -EINVAL; - - return 0; -} - #ifdef CONFIG_TIME_NS static struct page *find_timens_vvar_page(struct vm_area_struct *vma) { @@ -252,7 +236,6 @@ static const struct vm_special_mapping vdso_mapping = { static const struct vm_special_mapping vvar_mapping = { .name = "[vvar]", .fault = vvar_fault, - .mremap = vvar_mremap, }; /* diff --git a/mm/mmap.c b/mm/mmap.c index a62cb3ccafce..41100f6505ff 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3389,6 +3389,17 @@ static int special_mapping_mremap(struct vm_area_struct *new_vma, return 0; } +static int special_mapping_split(struct vm_area_struct *vma, unsigned long addr) +{ + /* + * Forbid splitting special mappings - kernel has expectations over + * the number of pages in mapping. Together with VM_DONTEXPAND + * the size of vma should stay the same over the special mapping's + * lifetime. + */ + return -EINVAL; +} + static const struct vm_operations_struct special_mapping_vmops = { .close = special_mapping_close, .fault = special_mapping_fault, @@ -3396,6 +3407,7 @@ static const struct vm_operations_struct special_mapping_vmops = { .name = special_mapping_name, /* vDSO code relies that VVAR can't be accessed remotely */ .access = NULL, + .may_split = special_mapping_split, }; static const struct vm_operations_struct legacy_special_mapping_vmops = {