From patchwork Thu Dec 5 14:30:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjiang Tu X-Patchwork-Id: 13895445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E7CCE7716D for ; Thu, 5 Dec 2024 14:33:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72D1C8D000F; Thu, 5 Dec 2024 09:33:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DD498D0007; Thu, 5 Dec 2024 09:33:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CB8F8D000F; Thu, 5 Dec 2024 09:33:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 41A258D0007 for ; Thu, 5 Dec 2024 09:33:49 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B8A1DC15FC for ; Thu, 5 Dec 2024 14:33:48 +0000 (UTC) X-FDA: 82861149210.14.E9EEF0B Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf14.hostedemail.com (Postfix) with ESMTP id A412F100003 for ; Thu, 5 Dec 2024 14:33:27 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733409219; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=jWZ2BTb3YAhTb4ZTvK1zBly73ISdnBsvTNbvxc82zmA=; b=FcMNaYL0TMzw4hwjUVTlaUoyyb4hvKTMFzm5ukJukCWEPgufG4Fs7WgomL5WvMmSk/7Q0o SRZBEMMmkicKj1gaRyD2y/bVNO/KM7bGK8jYyX4tM0OG6M0hPsnmB4Tsvxv1xwU8jLEUoA hzMwKvWKsn8DlIepNl7m2Z5IkzbFto0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733409219; a=rsa-sha256; cv=none; b=ygz4YMSQLSmfsrEEcf2tE2AFjcAP6ZEAFpM5WOzXTR6XjGppGF9/r1dMZLr3Iv+GGEgGbf utGJxh3N+5cpb65PA5ZXOcDvD6LNxyvht5BO7UlasTJRbF5v3t1FoUz2Rh/3w9tE5+K9LL n/WK4gZ1xREC5WaL4COh53HkdbrCRQE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Y3xf04ZNhz2FbvX; Thu, 5 Dec 2024 22:31:20 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id F24701402C7; Thu, 5 Dec 2024 22:33:38 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 5 Dec 2024 22:33:38 +0800 From: Jinjiang Tu To: , , , , , CC: , , , , , Subject: [PATCH -next] ovl: respect underlying filesystem's get_unmapped_area() Date: Thu, 5 Dec 2024 22:30:38 +0800 Message-ID: <20241205143038.3260233-1-tujinjiang@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500011.china.huawei.com (7.185.36.84) X-Stat-Signature: kf88skgbdq4to7hqxegbwmuutw1e6bbe X-Rspamd-Queue-Id: A412F100003 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733409207-944116 X-HE-Meta: U2FsdGVkX1/qjyMTV88NJ4ORDbvZRxeiKpzuiYyZxOdFHOIGXqZFcosy/aPF4/122PfqTKR0mVzq+iAMJuACnwyRgpHpMPhQqfY2AmegL4uD4ovaVDMx1OZHeoGPAx26lI+jWwnzHA+PboN/l8UrnUdsB3kQB68TZiVLOfYCknOVM2CSXNeyjc/s5gE/5SFOpCip1bdhQrvEgYqJ9GP75lab4hlYBtmwbxqCZcfxtipH9//i6BMz3Hbu6zgnwrMlZiYMWwDGFE0WHgxWIdW3I2sbp58bLg9g9FBWXmv5f1Abv42Hb62tRQFwCbFMeHTbclpdMDRADpXhHCiqvf2njYJdKeEmhFy89EeJGvbM7/OIfHQ0sqb8GdiMeCQRNkWiTZ9WI9aJABz+vDE+/FbpvTKkYE/ZO2tZwTds325+pIVWqNnYaYsDRi5Zt3vQ5QX00dSN7IneZXbLl3qL1AVatJffUucVTuJ/xzrqtGlMOq2zhReAANGjhXglLXxH0O54UPtOUOgZwrulUQASOpjD+tVTJO8ex71BcI17nDV/ZcYhSHdU0bTAXx9op67xtJ1B7aiK7MtX1ETnBx4+bpNewWAwHBltaTT5x8EKDTfVGNMF5X0pslmSNxxQjk31/PvZ1vewCqTsCA74WV0VM4+0ix4WJxTMiWfBoNbyncNgbZ2GgCGT89nhZvFiYCrKEVbZj44W2WHO1LQIGHlJ2E1r2/QRYFihsDmW5qUyGZwXEtudDnrEfahke3AvdIFy4BOEbdsq0AwyRACdT8jrxhmWv33kHuBE4lkdyUarlgwXBRlVw9g0tfqOXK/C2u9u1TZDPLoWgVDoqMJZ4uqKLuVjkJwZqraNGfZuruufshdvAPvKeOcQtbh7cP8drlUxHl14ME2wD/OnzPs0FL2538fJJHsDmuLwKg8EqlSkYvY0pQJQpDNh+w+3XT+heJRCuuvF20j7Mejri+JFwnl0bH/ cCv0OO1m e5QMv4nltoab97VaNrSBGPWqOj9SI+I/zjzHtDDpoyj6OqstrOEUtUrw8Y3A1qQoSB2rsCxY64ZPAzSzF1AOSZrpZu+9xuatCV+83Aua1LMcN2+rjla5qO9P0cwe38qLAFcWaaM1GaaexONcwpM9aGiP1hvBTT/fCaR1ePSSy9OmW4gfpSNESpPRT6++Z6kRSHyZd 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: List-Subscribe: List-Unsubscribe: During our tests in containers, there is a read-only file (i.e., shared libraies) in the overlayfs filesystem, and the underlying filesystem is ext4, which supports large folio. We mmap the file with PROT_READ prot, and then call madvise(MADV_COLLAPSE) for it. However, the madvise call fails and returns EINVAL. The reason is that the mapping address isn't aligned to PMD size. Since overlayfs doesn't support large folio, __get_unmapped_area() doesn't call thp_get_unmapped_area() to get a THP aligned address. To fix it, call get_unmapped_area() with the realfile. Besides, since overlayfs may be built with CONFIG_OVERLAY_FS=m, we should export get_unmapped_area(). Signed-off-by: Jinjiang Tu Acked-by: Amir Goldstein --- fs/overlayfs/file.c | 20 ++++++++++++++++++++ mm/mmap.c | 1 + 2 files changed, 21 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 969b458100fe..d0dcf675ebe8 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -653,6 +653,25 @@ static int ovl_flush(struct file *file, fl_owner_t id) return err; } +static unsigned long ovl_get_unmapped_area(struct file *file, + unsigned long addr, unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + struct file *realfile; + const struct cred *old_cred; + unsigned long ret; + + realfile = ovl_real_file(file); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); + + old_cred = ovl_override_creds(file_inode(file)->i_sb); + ret = get_unmapped_area(realfile, addr, len, pgoff, flags); + ovl_revert_creds(old_cred); + + return ret; +} + const struct file_operations ovl_file_operations = { .open = ovl_open, .release = ovl_release, @@ -661,6 +680,7 @@ const struct file_operations ovl_file_operations = { .write_iter = ovl_write_iter, .fsync = ovl_fsync, .mmap = ovl_mmap, + .get_unmapped_area = ovl_get_unmapped_area, .fallocate = ovl_fallocate, .fadvise = ovl_fadvise, .flush = ovl_flush, diff --git a/mm/mmap.c b/mm/mmap.c index 16f8e8be01f8..60eb1ff7c9a8 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -913,6 +913,7 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, error = security_mmap_addr(addr); return error ? error : addr; } +EXPORT_SYMBOL(__get_unmapped_area); unsigned long mm_get_unmapped_area(struct mm_struct *mm, struct file *file,