From patchwork Thu Nov 21 11:22:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13881883 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 65A3FD6ED09 for ; Thu, 21 Nov 2024 11:23:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58BE36B009E; Thu, 21 Nov 2024 06:22:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 44D896B009C; Thu, 21 Nov 2024 06:22:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 953CE6B00A0; Thu, 21 Nov 2024 06:22:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B4C9B6B0099 for ; Thu, 21 Nov 2024 06:22:31 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4DCC8AEC82 for ; Thu, 21 Nov 2024 11:22:31 +0000 (UTC) X-FDA: 82809863556.28.2CC863D Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf29.hostedemail.com (Postfix) with ESMTP id CBBA6120013 for ; Thu, 21 Nov 2024 11:21:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732188013; a=rsa-sha256; cv=none; b=SLKWxyKGG0NPc3v95g5e9gZS1bovpih6/ZknMyBfkdtHAKf27uWZPyPlq2ATEJme/Hm8d7 MA/x9bPSNEJAN3eOOK/AbqYDsuiIWgp95i9Xm9QGeNFdVjx0PktMqAceoJVyeLwEF4CAxd Yp+i3BUEfSoZ16TAVyznZtzRQJ0nHNU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732188013; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z952gM8z+JIWiAOg+kkzwbYw8zzE7VFYNM9AheOhVPY=; b=Q8D6SgtjaeQDxCRtqhHazVhaAtzVbtvk+0V7BiVQ8qgOsL7C8XCiD9T7pWCTwQuauyUj9a XRIa43YqJxdUA74H7fXBYTEvCPIGlD9x+O+NUy/dgWoYiuT5wo0nex15VfgDzcWixULDh9 bgyD/EoRQwSTDmxwAET+RKvvAgNHgB8= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A13C51F801; Thu, 21 Nov 2024 11:22:24 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8C59213ACC; Thu, 21 Nov 2024 11:22:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id s9NLIvAXP2c/fwAAD6G6ig (envelope-from ); Thu, 21 Nov 2024 11:22:24 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 3B47BA089E; Thu, 21 Nov 2024 12:22:24 +0100 (CET) From: Jan Kara To: Cc: Amir Goldstein , Josef Bacik , brauner@kernel.org, Linus Torvalds , Al Viro , linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, Jan Kara Subject: [PATCH 14/19] mm: don't allow huge faults for files with pre content watches Date: Thu, 21 Nov 2024 12:22:13 +0100 Message-Id: <20241121112218.8249-15-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241121112218.8249-1-jack@suse.cz> References: <20241121112218.8249-1-jack@suse.cz> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Queue-Id: CBBA6120013 X-Stat-Signature: o6drex9tw593jigqw5if5mjmrdgraa5p X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732188077-767891 X-HE-Meta: U2FsdGVkX1/3ZuGX3avS7QE6G7FL4Lj1xL65/DaXPZD0S5Af9J7FyPl+v7ZYoAh6DDgUsHejNh7YU1XcqHR6mkQETisMAr77t586faAc2vNwuAbmSrH5x1ACv+97AN+h7PKwkHqZiZcAnMa6wC0WZ5PiFdPpM4g8lgK71pBf7IVTeY8GP59/WM7aIe2bVKlo1CBR5oRYhl+RQt4aJXqG34SRAX8JkzvZOZBEUPWPCWH+wV3Sddk0r7Lo+CycvfqDzIVFZZZ6sZr53MWJWi1KD/ilr9p0y7Jwf2D9505sArVROD85fNOXsHFpKEEYbmc8L/p7ahR4qM6lrb9SeXyepUAGnNDD2+ROSyuZqhOKehqgVxAOM6p0wI+xnJs/8IHGqNgNpOlFi12zBY2CMoWveZUMmjBNHp9gGIx/iXL7oVjXV/UG2QHGaknBB6HA4V7AokqEmpT2ipmxz8/HVr64dYcJ8dNWRcgTdjOIosqavlxSISSNbr9A+tWh4Mushfw0cBGHX64xpTQ2bWDhee49uSwEL8iIXUSo5R6/fX9ppN/VHp9/0X0/xfGmgt6SKXstEfjVlPdj8KZGvpwVDTDhmg5FX5QPp/VsmXWbuwaaPPA+mOX0x4NC9CV/v2KwhPUWjsKB1LJPCrd9trMM9qOL+jA8JfDt3a/kJT6t7bnirbnSAQ7PgM1huIAj7yhdOwS0gH02PuKiIQ/9OkAG9eBeir/y9AevH5uxWBYte5SNIhzoQ2JeQyEGZUQrZ+FYKlbGifDfL5r9vLvEglTfRxidFOCYtFyxt9MX6zVjYiB6c+ETcp5gfk2r0xIAh9mPoUwdTQvkmwq5TYDLNK/a9pspVv1YQd0IT698Wxd6ddx+x11+i5PiaqFVj/8Bld7g/RThk88nCn/9xbW3uw2O8e95Bm1LtPVBSa9s2KRIeJTxVi0WpUlxhK+3cOKbYdaezCbjwAw0XUWWSTlhFNFCHFE JTDMSh6k u7lyZnwoKqCFuMChE50f4ZoySzJXkzIfZQCg5RefhASKTpMYB+Ox5mhkkmMOYDRqf0bA0Ja5YNjcWU8phl9xcSbcDHVEWdYwKGZSNtaVzieLL3RjnBVnXXEIftF2yMVdw4WXmkoEly3iURBPGtg4lskRZqHMBtsy4Gamd6Rry2FBStQmAwQO2txq3qNQY1ySnWIj6BQ2DH3MOeke5V/spYYZXBY8MB1XE2bvkMkJpT3k08s+h6HFxbDDTxCdHdECAJMtGWjXtNLy+vgJh3I49FaIftw== 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: From: Josef Bacik There's nothing stopping us from supporting this, we could simply pass the order into the helper and emit the proper length. However currently there's no tests to validate this works properly, so disable it until there's a desire to support this along with the appropriate tests. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik Signed-off-by: Jan Kara Link: https://patch.msgid.link/9035b82cff08a3801cef3d06bbf2778b2e5a4dba.1731684329.git.josef@toxicpanda.com --- mm/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 2366578015ad..111ba20a22e7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -5622,8 +5623,17 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; if (vma_is_anonymous(vma)) return do_huge_pmd_anonymous_page(vmf); + /* + * Currently we just emit PAGE_SIZE for our fault events, so don't allow + * a huge fault if we have a pre content watch on this file. This would + * be trivial to support, but there would need to be tests to ensure + * this works properly and those don't exist currently. + */ + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PMD_ORDER); return VM_FAULT_FALLBACK; @@ -5633,6 +5643,7 @@ static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; const bool unshare = vmf->flags & FAULT_FLAG_UNSHARE; vm_fault_t ret; @@ -5647,6 +5658,9 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) } if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PMD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) @@ -5666,9 +5680,13 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) return VM_FAULT_FALLBACK; + /* See comment in create_huge_pmd. */ + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PUD_ORDER); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -5680,12 +5698,16 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; vm_fault_t ret; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) goto split; if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PUD_ORDER); if (!(ret & VM_FAULT_FALLBACK))