From patchwork Fri Nov 15 15:30:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876452 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 209A9D68BC8 for ; Fri, 15 Nov 2024 15:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47C0B6B00A4; Fri, 15 Nov 2024 10:31:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42B9E6B00A5; Fri, 15 Nov 2024 10:31:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27DA36B00A6; Fri, 15 Nov 2024 10:31:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 05BF06B00A4 for ; Fri, 15 Nov 2024 10:31:55 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B61A31C71CE for ; Fri, 15 Nov 2024 15:31:55 +0000 (UTC) X-FDA: 82788718068.25.39EFFDD Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 869BDC0012 for ; Fri, 15 Nov 2024 15:31:07 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=lujG8jlj; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.161.51) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684537; 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=UmMh2R9TaZZeTO+3Pa04+NECyzvSza2nfFK0oCoLtcs=; b=metnpF0Lp00S+7lRnKKdoumP6WHc4j0B66DA6By05YF7EhZ/aDY09f5f06BMG7LFYGB/zw 9S45V0FeNVMZ4Ry3LL8IibgD/HaQ+DGrcYw5zuMHS1gdk6ni9CXA6r+UUUeNJaD6Kxdv2j fIOdTz16Sm5TTmSC4lCBEgtEYEO1qOw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=lujG8jlj; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.161.51) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684537; a=rsa-sha256; cv=none; b=cbt1Y8ZjsNP3GAXyfr/FD1DKWBe4KhvROEKL90+Mh81I/ZaAkVi042F1JF5fpONqmlGZjR Lsj4QpVl+8AS6E1BXb7GoX01Y7iTd4p9f3Ly/6lZKMb6MWumDEr4D5+MCP1Va4BJQc010F PojPJZ8Y8iOgJmLCtfRxiQgQMzoRxDQ= Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5ebc0dbc65dso871576eaf.1 for ; Fri, 15 Nov 2024 07:31:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684713; x=1732289513; 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=UmMh2R9TaZZeTO+3Pa04+NECyzvSza2nfFK0oCoLtcs=; b=lujG8jljBGz+M5Hk77P4oe/nxrZwhmloMdatI2EUwfzFT8AunjA4aiiPdYHCsqq2fM GmP07p1dbk0cD7wxkp1GL1PH9i02yNo9PtAz8Bq0/a+FKnQMdLjEtrcgsOPU8a8QdwFH b8PXjDB9lh9RU2L9yRg+83XudDL1/OlIHOBNx5PL8f+sHBlmXuIXEhAFW9W6hOqskfzM k1sxdWeD8HmB2U7PeXEmUznvaY1t9Qblih82Xh04yPbfMmQhS3VFAu9mwzbt27c6yliq C0/xvepI8nmCQyzfzOBLI+ILhblBCfPVu/h+m3gTi/nbnztbmrPD9nnWB9FW+3asGPGB gcEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684713; x=1732289513; 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=UmMh2R9TaZZeTO+3Pa04+NECyzvSza2nfFK0oCoLtcs=; b=TjokCUPvLZm/IJc8oGr8hs0LTDo9XFbgFrDfQhpAx96hRrgeajBNAbXEFN878Ofpry /HZVbUFAx8u2fZpAawWNHE/zA1aAvBXdRkdBwv9yijuhZgGKP1BkEgCBkNSAVv/KzEdq wWt3bsNmJtCl3km5WxYb5fYxysKDRZrQkDtXveLG3DP58uNTmy34X2JcdFxjUA5OVM1L SyyWZmwIzWhd+ZIhLoYY5RNXVaNt6saAS5I2bC0nO5kTaM5GiRnm5/glYNJpySbU2A3U RKog/Bu3VceeCPVGFe52w6xjA1b9ZsfDjxTruPc7WgFWZ2jHQw+9PE4mxjH8FfkQWB4f Mdjg== X-Forwarded-Encrypted: i=1; AJvYcCV6jOXn8SjeuWSMOBxnRww3gTh5k6VGPuiih9G4OGvc6NNSUzvFuDDCil6+F/ffFyqKOp9Dct1l+Q==@kvack.org X-Gm-Message-State: AOJu0YzIbKOPWxYvhPR2uEzc4fyHcUBh2nlDVqzi/V/XnGzIU/4iHtm7 +arogWw2o5u8h18b4WATtCYVeJj92FYf4gzbJz7ZU+R35KCmRxTJzkCG964UM0ctuQOZl4I/bXb U X-Google-Smtp-Source: AGHT+IHtKZ3WiG2a6Yh90R7O7Da3Go40IEKMQxser6w6wpGF8sO84iqOBIyuVxo5A9VSaCx3/txhnw== X-Received: by 2002:a05:6830:d8c:b0:718:9df:997f with SMTP id 46e09a7af769-71a779b2c25mr3850260a34.14.1731684712917; Fri, 15 Nov 2024 07:31:52 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee4400c6e6sm7807317b3.9.2024.11.15.07.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:52 -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, viro@zeniv.linux.org.uk, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v8 15/19] mm: don't allow huge faults for files with pre content watches Date: Fri, 15 Nov 2024 10:30:28 -0500 Message-ID: <9035b82cff08a3801cef3d06bbf2778b2e5a4dba.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 869BDC0012 X-Stat-Signature: ypyzxg3ncjynh55h3fstp4xjjp1pfwah X-Rspam-User: X-HE-Tag: 1731684667-551340 X-HE-Meta: U2FsdGVkX1+25pxvURho950qhl6AWTvf/fapbzthJZrUSNUiEoePSc4VWRdavK9Nc+yRn5bKuvF09e7t1B6zV6nKe+uzEb6tMkogjwGaFPvsmEVJyheii4OVWXDO9E7tY/83CwxnpyWImKDVdGaTxXr/ws+QyivDZovXq1J1OGnoN38hO26FrsryXbUxywl+9WrLgptdV9s5eZ4eynLGf8kjDSllh0eFc9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9EthTz6t1pwnHDKehNMe5IgJHjNVBs4wuYf2PEabB82dtghax9wCVdEZbIzeXu0/l8a4FktcysSC09KmaY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.008877, 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..843ad75a4148 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 (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 (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 (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 (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))