From patchwork Mon Nov 11 20:18:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871231 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 1578FD3ABF4 for ; Mon, 11 Nov 2024 20:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C0336B00A4; Mon, 11 Nov 2024 15:19:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 448D86B00A5; Mon, 11 Nov 2024 15:19:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EB156B00A6; Mon, 11 Nov 2024 15:19:36 -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 0F6806B00A4 for ; Mon, 11 Nov 2024 15:19:36 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C09691A1C2B for ; Mon, 11 Nov 2024 20:19:35 +0000 (UTC) X-FDA: 82774928376.12.87FDCDD Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf10.hostedemail.com (Postfix) with ESMTP id D0762C0010 for ; Mon, 11 Nov 2024 20:19:15 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qngBGmU8; spf=none (imf10.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.172) 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=1731356201; 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=Y0VNRwGnj+yC5fi+CBNkxhHKe+QNZM48w+yke9YcftlUj27ry2DxlEDo9qB1wGtSDW76HK yr9uwdjY0/35+5CxDnuYyYmYNCYXILgSVrJeFEFrA98MG/vGi7xDyWFIvmmKwl6s67JFru /rKs0aNoq6ukKDIz4hBMH4nUYx+olLA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qngBGmU8; spf=none (imf10.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356201; a=rsa-sha256; cv=none; b=Q1Y+ajG9tO1d6XOGGRgoogkuizGkrRgtCCYAASfmFEGBY5PVLTBtpM1TzjH6fy3J2mL6TL uUghkPmt1u8zIud7BkqSm4osCVNrQf6h12CfE9njfEBh8ZUYB+i+8gPrwZuybAeqd5+7Cv oVMG3C30EWO/zTA8DioyEKUURnZg7hQ= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b1601e853eso325312485a.2 for ; Mon, 11 Nov 2024 12:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356373; x=1731961173; 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=qngBGmU8rHufJmGT9WJSjtfAhhT5HA1GuoHO0tAkQRRpzw1ok6cQQKxwfvsVahOQJG 8D3bVSHq2R1uKD78YykyrMcNGpwV3IOc1S+dmNnfAJMlhA0uJkxJDKEz+kyu0KFDLW5D szbSpx6AqvjieZDKK0Wq2R2zzVINXquYGOj4idM0sqK1HvgRUSYAONMlnNh2UTaj8wQx Y66aPvbixnSyWvYVibk9YJmIJfvLsm085gQi3AxkULB9I8VpOdx4Z4StAkMRKv8hqv37 tIClujBhYYiIsvHapOGCTNFYgkvgNK7QJNhHTr3PRUZt5+aAAutq7D4gsVeShq1lJTeA 69OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356373; x=1731961173; 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=qfbHrMFjI50ZThLgE0ilhcsDxgHS+bkvbhtmF1MJuU99V+qVK7mSL4Z5HdmxpWRcZL r41V4NtDPY+Gj7gjkF8ZE8Ef01qsB7By2iKtRwD/R9GTxsG4ud6vDPXh3W5kXzMoAScH xNVfHBH2PMkJ0Dvt+hfu6rUBS2vVtaMsaAJ2n4vmmd1KCZbmAiPw08XQOh0hS+kDVeUb gLhE8zjN8kZ88IRVjyV6cw8DAxbkBHKMBsQTX83pHMw4jF4gGd0/Hi2LQNd0gsPGDZeM lTwazvcs9ob8FmeFeVnOSbUfaKxXRxRsTjAXkm3dquwiXvFJQQqg4BJL9V/5JFx0dpjP zwrQ== X-Forwarded-Encrypted: i=1; AJvYcCULK54auKKV98oX2+Qwzmd5iH5u8fe+vrufXSxlC3dqQOMb2JZLpNHiWUH/zFnCQe3cOjqXVgHpAQ==@kvack.org X-Gm-Message-State: AOJu0Yy1rAuS5Sd59rV4uIWUW9pvqrb6w5EeJxMzh9VgDL3XOYtDB2+j FX1xIcERfiYo9jsZEdfPwpiiP9ZE1OzLMinogwXkdaHiiqIP8pLMdFBpHRyD7gU= X-Google-Smtp-Source: AGHT+IEVZ5vmyN/LZmrG/1kTbJ7T1FWoFz0xAw/6r2wr8/vwFJmdfm3sS2snhEtpIWxC1ONY/ffBRQ== X-Received: by 2002:a05:620a:178b:b0:7b1:447f:d6f0 with SMTP id af79cd13be357-7b331eb87dbmr1968482385a.23.1731356371650; Mon, 11 Nov 2024 12:19:31 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acea072sm526763585a.114.2024.11.11.12.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:30 -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 v6 13/17] mm: don't allow huge faults for files with pre content watches Date: Mon, 11 Nov 2024 15:18:02 -0500 Message-ID: <5c64164cd1f16431edd1d468cb3204d29d86bbf4.1731355931.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: D0762C0010 X-Stat-Signature: gzpjs3wasx1nwkroeyifaw1u4qutfg9j X-Rspam-User: X-HE-Tag: 1731356355-651519 X-HE-Meta: U2FsdGVkX19I9/MbIGpKs+cWcvalOOBXZKjzLeme5vc+Xqljj0ToDeRgFJP6tGZ/a059f/m9KEBbk04MxDlINk9tT99Yfoy//X4Ky/bjTe4uAgyRUJ6oAg79+ek4rqcQrQni86EF6XMIAEgBOWqkGySp9amLzucXJKnhak7mym6moiLc273C9ZAu3y5MAJdBLnb7YLSntaJ4hnHtqd1LwfeKJdxckcQ/yoTqRnXp5u3baV3/7PQ3WEHA90ailo3CU3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4ldYfAkRzw6+J/Y16n2GQmiRNwLgjntknSkKe/D6HpV+urE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.011995, 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))