From patchwork Tue Nov 12 17:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872739 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 C1952D42BBA for ; Tue, 12 Nov 2024 17:57:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C14696B0105; Tue, 12 Nov 2024 12:56:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC4546B0106; Tue, 12 Nov 2024 12:56:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3E446B0108; Tue, 12 Nov 2024 12:56:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 846476B0105 for ; Tue, 12 Nov 2024 12:56:53 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 41487404D1 for ; Tue, 12 Nov 2024 17:56:53 +0000 (UTC) X-FDA: 82778197404.23.7451DAB Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf03.hostedemail.com (Postfix) with ESMTP id 2B4C32000A for ; Tue, 12 Nov 2024 17:56:31 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=V66aZR4Y; dmarc=none; spf=none (imf03.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434082; a=rsa-sha256; cv=none; b=yqaA5W6BIEuLVcOvLanAtrndatM9kHbaN0cD4JqtsKn+RSlf9nQ1Bg9fBS4MLF6n5slT7C LZjgS4Ly4bxe82nv/km/FbXjGIaSq9I6HiSRRLTQnhzKiM6DxMuYLlIGO1/lZ5qb+VpDtO xPn8H2umZYIEo9EQlVFpfLnXI9q+4pI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=V66aZR4Y; dmarc=none; spf=none (imf03.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434082; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=mnPTGdiaXaFLyq98ic7L/FnmCeR2aB59JeZV3cE8Zj75hInhOc3dWCQS+u4jIERRAJDYug L2cA9VapXEsL789TRVkf0PH0e78E8RvtlDxtFJ45sUuVN8nPbjEQlrT8SooO8FaWNQNAhL VBvcCJf3YAZMH4PKRQJ6fT3RdfQjzHw= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e28fa2807eeso5710441276.1 for ; Tue, 12 Nov 2024 09:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434210; x=1732039010; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=V66aZR4YK4g5EY7IgGTnFAi7yQ+LOvMTif9C4lE1rSwsZ2bMBBu0hAbl5pObv6BI6h RT3az57sdDCs0Y9xfRRf137lVqMeLxDhjV8hSU3aVuQ9F7HQgNli4F5fWW9Z5UUfgOSL HT8ZoRxUyk8SZLzmpCr+kb7MDLuvbmVbxmo5QkXb4ZSQGE8hHNQYafpB6raS8tY0rbIp Tz+dTAvO980Cba7eOyInKl1j+WPNNzE5BWxeBNONQcWuYuNqmWrYhDXMiCy8FLgfTprv 7/9mP3bJDk5Q54QYAQXc5N2Oy0VLSJjCqubFjkONjK1nno7THptuCnhE9V/jQUXcjV1n yeSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434210; x=1732039010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=bTQCTXUq38zh4HOdXW7puot8LBDE+eaGCJqlcDMUOTUkc6yQhoOdZjnFZCeu1kZtmS 5T6Z0AuHlfSiAYS/SWABejCXYm+VLEiUWMnr4rjkyWfPC+Mbvq7dvNalVuXI7ODtHsJc ytsAAuDfzGTkBiCAUBK5Qorq1xSFq6U7e9le6Hk/qVa9VlsAXjzhkCU9X+ddDfju5bzp sUzOE+n6NQOItoDosCOdH9Gd2SR0+aQ0Ux84wIFPPVIGYb3/+ZCmdZa+l9i4lDcFxBg8 WzdOB0ng8/IWGEQvsTLccsajNGsTOdkHO19T7MwNtnmRWbIpwX9LTluYZhr7tzYyMV/r mbzw== X-Forwarded-Encrypted: i=1; AJvYcCXgRmWHE0xGVImA/x3XogOnayXIuYVu5FH9UPxBMsYqYxvUKBqyqKRHZ3bgmODIp15+Gh/3B+mk3Q==@kvack.org X-Gm-Message-State: AOJu0Yy07mwRykNz2oQyRM6KVuntvMrErtFymBvSzmPkpNuP6bEI16/R K9Jv/eMEesqX+PngE1t7+BnhqCB7PQqJa+BcNzGM3yWNuE3s6xE2Rz/jXnY6JfE= X-Google-Smtp-Source: AGHT+IEKuDZzW/fvP8psHkg5hrvM/70eBZxELM8jsrhGXCGLQnsHGSpuUuvJ02++phM7o+afQ4JSUQ== X-Received: by 2002:a05:6902:20c4:b0:e33:25e2:4b1e with SMTP id 3f1490d57ef6-e337f86d626mr14917803276.19.1731434210511; Tue, 12 Nov 2024 09:56:50 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1ba835sm2880031276.47.2024.11.12.09.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:49 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 14/18] mm: don't allow huge faults for files with pre content watches Date: Tue, 12 Nov 2024 12:55:29 -0500 Message-ID: <532dfc336dc1b09e5604dee4f08b70577089b76a.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 2B4C32000A X-Stat-Signature: kchm4ig6fzx9hdtjn69ai99h11ni1h4c X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731434191-525497 X-HE-Meta: U2FsdGVkX18FFOaB1mY1bUdeVExPPhCfhbyB3tfrm+1lvOQ5IYpCf3uK/IFcK/QmTZpHCtvj/wivBSYILXKZLWnBP3lu8CgvdbuMee2bGhvUhHUynffHzqXlCiHoGPRRPDWg8MYmsVdqtu//r7lvrvyNIDv8WZMmoszA2gO/TG8TUATDaEKIKava0kXjjkuSOkljairZFtI2Jz7Jlp30PwarzseymzkUcZu7Wh/U54vJHrvETd0pePkIRtHTcfiZtStQWRK4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8MD/h+D8wQfT8P1Ng6mb0sgUxR9TsJDSl4heGrzTSddhKfnflx8+IhrZ5FaEpV7q0H6dtmnCLUpFjdoXg9h3frJZyhLm63mLWZAH3hrJ5EWaJtTwk/qy2+HG9Sohw2056tdHpCEprgyJLStvL0aOdoJTIkJXhIyA1Hly/zeV/Z/Ng= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001911, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- mm/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index bdf77a3ec47b..dc16a0b171e3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -5637,8 +5638,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 (file && fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PMD_ORDER); return VM_FAULT_FALLBACK; @@ -5648,6 +5658,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; @@ -5662,6 +5673,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 (file && fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PMD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) @@ -5681,9 +5695,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 (file && fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PUD_ORDER); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -5695,12 +5713,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 (file && fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PUD_ORDER); if (!(ret & VM_FAULT_FALLBACK))