From patchwork Sat Aug 29 09:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 11744321 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 BAD9113B6 for ; Sat, 29 Aug 2020 09:52:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 886482075B for ; Sat, 29 Aug 2020 09:52:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mykernel.net header.i=cgxu519@mykernel.net header.b="f462YgeL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 886482075B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mykernel.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 48E206B0006; Sat, 29 Aug 2020 05:52:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3F1306B0007; Sat, 29 Aug 2020 05:52:01 -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 21C396B0008; Sat, 29 Aug 2020 05:52:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 068256B0006 for ; Sat, 29 Aug 2020 05:52:01 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B741412E5 for ; Sat, 29 Aug 2020 09:52:00 +0000 (UTC) X-FDA: 77203140000.06.can19_531514e2707d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 7A88010062C94 for ; Sat, 29 Aug 2020 09:52:00 +0000 (UTC) X-Spam-Summary: 30,2,0,3addae72f2cfc92a,d41d8cd98f00b204,cgxu519@mykernel.net,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1513:1515:1516:1518:1521:1535:1543:1593:1594:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:2731:3138:3139:3140:3141:3142:3355:3865:3867:3868:3870:3871:3872:4250:4321:4605:5007:6120:6261:6653:8660:9592:10010:10400:11026:11473:11658:11914:12043:12291:12296:12297:12438:12555:12895:12986:13148:13230:14096:14097:14181:14721:21080:21324:21444:21451:21611:21627:21939:21987:21990:30003:30054:30070,0,RBL:163.53.93.243:@mykernel.net:.lbl8.mailshell.net-62.2.2.100 64.100.201.201;04y8zjkxwwryag9hd89zdsbzm4nsuop6dca19i3n94cgakecqd7grn3tukek1ys.cfuirgrongmagwmdwqyskk81ft4bgykis8z3rmjcbnmfyxz5r9kqdresrmtw5kf.r-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:1:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: can19_531514e2707d X-Filterd-Recvd-Size: 5986 Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Sat, 29 Aug 2020 09:51:59 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1598694691; cv=none; d=zoho.com.cn; s=zohoarc; b=e6IcCG4tFosqzZgL/24g7rTR8CwHArbFn8gqoyeP0usMaoVI6u6AceplXcn6hbW69hHYTCP4L1IzblceuMvXyosITHt8bWStg5jdPiODCObfFX5vScf/wRUodv5P9LVXq2BQ+P5pdYhuWGFGRHyW0s3yKwa2jRkxnEFsqzxXqmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1598694691; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ccEWT3RLuwiPMu/BBIgZh5/ZgyfZBB6tStaJtH+L+JY=; b=LyzBXJnBuVVu6950HiaP7Fwrfz5g4BSeqm4kwWZGEa02R+JuXLeSpYdNh90xhJmcsLqMHNeK+VVG3mQtz9x8ZWlBbn++dEft84k6cUUWVmbddciR+BeIk2cVFAMm5Ca79aGeKIQGFhkjneKuNjIkA3AzbtpSVfXxhwmjnYWIZ+k= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=mykernel.net; spf=pass smtp.mailfrom=cgxu519@mykernel.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1598694691; s=zohomail; d=mykernel.net; i=cgxu519@mykernel.net; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=ccEWT3RLuwiPMu/BBIgZh5/ZgyfZBB6tStaJtH+L+JY=; b=f462YgeLswSRXtYIq+DvgwbLsEFk5nGTD1bHb+XueyiqlOt1/vAUH/qKwya3brpu 0UF3EModFvQfCwiHAU1nO9n9rnEyxIYz9xWBoNhxRpnMCvdtd+djaZK6y+x2ve6i+SC Mdx1wvDvj8FNOF0UwZi0X/QNCrla4UaH9o2L23AA= Received: from localhost.localdomain (116.30.194.36 [116.30.194.36]) by mx.zoho.com.cn with SMTPS id 1598694689422660.411788621191; Sat, 29 Aug 2020 17:51:29 +0800 (CST) From: Chengguang Xu To: linux-unionfs@vger.kernel.org, linux-mm@kvack.org Cc: miklos@szeredi.hu, akpm@linux-foundation.org, amir73il@gmail.com, riteshh@linux.ibm.com, Chengguang Xu Message-ID: <20200829095101.25350-2-cgxu519@mykernel.net> Subject: [RFC PATCH 1/3] mm: mmap: export necessary functions for overlayfs' mmap Date: Sat, 29 Aug 2020 17:50:59 +0800 X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200829095101.25350-1-cgxu519@mykernel.net> References: <20200829095101.25350-1-cgxu519@mykernel.net> MIME-Version: 1.0 X-ZohoCNMailClient: External X-Rspamd-Queue-Id: 7A88010062C94 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 shared mode mmap, if overlayfs' inode does not have data in upper layer, it should call maybe_unlock_mmap_for_io() to release lock and waiting for IO in ->fault handler. Meanwhile, in order to avoid endless retry we should also check flag FAULT_FLAG_TRIED carefully in ->fault handler. Signed-off-by: Chengguang Xu --- include/linux/mm.h | 2 ++ mm/filemap.c | 28 ++++++++++++++++++++++++++++ mm/internal.h | 22 ---------------------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index dc7b87310c10..214b23734eed 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1656,6 +1656,8 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t nr, bool even_cows); void unmap_mapping_range(struct address_space *mapping, loff_t const holebegin, loff_t const holelen, int even_cows); +struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf, struct file *fpin); +bool fault_flag_check(struct vm_fault *vmf, unsigned int flag); #else static inline vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, unsigned int flags) diff --git a/mm/filemap.c b/mm/filemap.c index f0ae9a6308cb..8a226f8ca262 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2704,6 +2704,34 @@ int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma) return -EINVAL; return generic_file_mmap(file, vma); } + +struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf, + struct file *fpin) +{ + int flags = vmf->flags; + + if (fpin) + return fpin; + + /* + * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or + * anything, so we only pin the file and drop the mmap_lock if only + * FAULT_FLAG_ALLOW_RETRY is set, while this is the first attempt. + */ + if (fault_flag_allow_retry_first(flags) && + !(flags & FAULT_FLAG_RETRY_NOWAIT)) { + fpin = get_file(vmf->vma->vm_file); + mmap_read_unlock(vmf->vma->vm_mm); + } + return fpin; +} +EXPORT_SYMBOL(maybe_unlock_mmap_for_io); + +bool fault_flag_check(struct vm_fault *vmf, unsigned int flag) +{ + return vmf->flags & flag; +} +EXPORT_SYMBOL(fault_flag_check); #else vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf) { diff --git a/mm/internal.h b/mm/internal.h index 9886db20d94f..ef19235c6bf1 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -402,28 +402,6 @@ vma_address(struct page *page, struct vm_area_struct *vma) return max(start, vma->vm_start); } - -static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf, - struct file *fpin) -{ - int flags = vmf->flags; - - if (fpin) - return fpin; - - /* - * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or - * anything, so we only pin the file and drop the mmap_lock if only - * FAULT_FLAG_ALLOW_RETRY is set, while this is the first attempt. - */ - if (fault_flag_allow_retry_first(flags) && - !(flags & FAULT_FLAG_RETRY_NOWAIT)) { - fpin = get_file(vmf->vma->vm_file); - mmap_read_unlock(vmf->vma->vm_mm); - } - return fpin; -} - #else /* !CONFIG_MMU */ static inline void clear_page_mlock(struct page *page) { } static inline void mlock_vma_page(struct page *page) { }