From patchwork Fri Jan 10 19:03:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11328265 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 69CB6930 for ; Fri, 10 Jan 2020 19:05:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 204DA20848 for ; Fri, 10 Jan 2020 19:05:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="eihdRw9s" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 204DA20848 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2CE778E000B; Fri, 10 Jan 2020 14:05:51 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 230ED8E0001; Fri, 10 Jan 2020 14:05:51 -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 0D58D8E000B; Fri, 10 Jan 2020 14:05:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id E44458E0001 for ; Fri, 10 Jan 2020 14:05:50 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id AD8205848 for ; Fri, 10 Jan 2020 19:05:50 +0000 (UTC) X-FDA: 76362654060.28.rock60_15dcb2c13162a X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,joao.m.martins@oracle.com,:linux-nvdimm@lists.01.org:dan.j.williams@intel.com:vishal.l.verma@intel.com:dave.jiang@intel.com:ira.weiny@intel.com:alex.williamson@redhat.com:cohuck@redhat.com:kvm@vger.kernel.org:akpm@linux-foundation.org::linux-kernel@vger.kernel.org:tglx@linutronix.de:mingo@redhat.com:bp@alien8.de:hpa@zytor.com:x86@kernel.org:liran.alon@oracle.com:nikita.leshchenko@oracle.com:brho@google.com:boris.ostrovsky@oracle.com:willy@infradead.org:konrad.wilk@oracle.com,RULES_HIT:30003:30054:30056:30064:30070:30080,0,RBL:141.146.126.78:@oracle.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10,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: rock60_15dcb2c13162a X-Filterd-Recvd-Size: 6530 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Jan 2020 19:05:49 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00AJ3IaH100963; Fri, 10 Jan 2020 19:05:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=C8D0pIaGNjjh2JphNwNEtO74QjeO7OaTgDpMn2oUCOQ=; b=eihdRw9sB5AAEspn7seM1U5ZcQbXLdkmwvsQYq2bO9Gh6HcrtIMT2X1++G3XqobSqNQJ 2th6fRWrI2JHwTh3bDyM3j7IFK/n4eaTF6XXuhcNM24OZw0++etfJw7hRiHC/FrZYrWq tXB3SxHo3dktk0cXhtdwWv+I3oeI3mjbpCxSvhgjVHD/nZ+c1/Een82LrDaX+2MSlm2z KBhhzugXijUeAt31lKRdngewyAINmeeKeg2nu1kGN93Iy/78Tlp81CmoCobLHGWW2xaa pn+lpZY2zX/iUxyX7w+gWnLRnd3lzaehmeXPVGVTarifoch91V/lvKx273jo77IMnCd9 eA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2xajnqm1cu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jan 2020 19:05:05 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00AJ4Dwn106360; Fri, 10 Jan 2020 19:05:05 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2xevfdhx8d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jan 2020 19:05:05 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00AJ54wI014657; Fri, 10 Jan 2020 19:05:04 GMT Received: from paddy.uk.oracle.com (/10.175.192.165) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 10 Jan 2020 11:05:03 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, Liran Alon , Nikita Leshenko , Barret Rhoden , Boris Ostrovsky , Matthew Wilcox , Konrad Rzeszutek Wilk Subject: [PATCH RFC 05/10] device-dax: Do not enforce MADV_DONTFORK on mmap() Date: Fri, 10 Jan 2020 19:03:08 +0000 Message-Id: <20200110190313.17144-6-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200110190313.17144-1-joao.m.martins@oracle.com> References: <20200110190313.17144-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9496 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001100154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9496 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001100154 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 check_vma() checks for VM_DONTCOPY for a device-dax when the dax region is not backed by devmap (i.e. PFN_MAP is not set). VM_DONTCOPY is set through madvise(MADV_DONTFORK) and it only sets it at an address returned from mmap(). check_vma() is called at devdax mmap hence checking VM_DONTCOPY prevents a process from mmap-ing the device. Let's not enforce MADV_DONTFORK at mmap(), but rather when it actually gets used (on fault). The assumptions don't change, as it is expected to still retain/madvise MADV_DONTFORK after mmap. Signed-off-by: Joao Martins --- drivers/dax/device.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 1af823b2fe6b..c6a7f5e12c54 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -14,7 +14,7 @@ #include "dax-private.h" #include "bus.h" -static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma, +static int check_vma_mmap(struct dev_dax *dev_dax, struct vm_area_struct *vma, const char *func) { struct dax_region *dax_region = dev_dax->region; @@ -41,17 +41,29 @@ static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma, return -EINVAL; } - if ((dax_region->pfn_flags & (PFN_DEV|PFN_MAP)) == PFN_DEV - && (vma->vm_flags & VM_DONTCOPY) == 0) { + if (!vma_is_dax(vma)) { dev_info_ratelimited(dev, - "%s: %s: fail, dax range requires MADV_DONTFORK\n", + "%s: %s: fail, vma is not DAX capable\n", current->comm, func); return -EINVAL; } - if (!vma_is_dax(vma)) { - dev_info_ratelimited(dev, - "%s: %s: fail, vma is not DAX capable\n", + return 0; +} + +static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma, + const char *func) +{ + int rc; + + rc = check_vma_mmap(dev_dax, vma, func); + if (rc < 0) + return rc; + + if ((dev_dax->region->pfn_flags & (PFN_DEV|PFN_MAP)) == PFN_DEV + && (vma->vm_flags & VM_DONTCOPY) == 0) { + dev_info_ratelimited(&dev_dax->dev, + "%s: %s: fail, dax range requires MADV_DONTFORK\n", current->comm, func); return -EINVAL; } @@ -315,7 +327,7 @@ static int dax_mmap(struct file *filp, struct vm_area_struct *vma) * fault time. */ id = dax_read_lock(); - rc = check_vma(dev_dax, vma, __func__); + rc = check_vma_mmap(dev_dax, vma, __func__); dax_read_unlock(id); if (rc) return rc;