From patchwork Thu Jul 6 22:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13304275 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 EFB8AEB64D9 for ; Thu, 6 Jul 2023 22:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 893AA8D0007; Thu, 6 Jul 2023 18:51:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81E008D0002; Thu, 6 Jul 2023 18:51:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FAB48D0007; Thu, 6 Jul 2023 18:51:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5018C8D0002 for ; Thu, 6 Jul 2023 18:51:03 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2577EB07B5 for ; Thu, 6 Jul 2023 22:51:03 +0000 (UTC) X-FDA: 80982684006.28.8AC5251 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf23.hostedemail.com (Postfix) with ESMTP id 5BFE3140007 for ; Thu, 6 Jul 2023 22:51:01 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Y2yizmMp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3VEWnZA0KCKcHeLSYHZTbZZLUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--axelrasmussen.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3VEWnZA0KCKcHeLSYHZTbZZLUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688683861; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Qwjh0UAlAYXVze8TCXBt1h/rZKLWFE0vCD0k3jVLMVk=; b=0mrJa0+X4XhE9P1JqEh8AWMTbdtX0w+/nz18hQEQ1MjjOefHYFxB/0hef4hvWdXqbOcAYn dZaT2p/F3eA7yS/sQZ/bzvXtbWQCX5Oi7TcltZaLauoHz3az4tWqXWTajKxrR/VuB6LTbH sRo08EZQRyD2EtoXwSy18oxEmRVThMw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Y2yizmMp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3VEWnZA0KCKcHeLSYHZTbZZLUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--axelrasmussen.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3VEWnZA0KCKcHeLSYHZTbZZLUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688683861; a=rsa-sha256; cv=none; b=CauUBlzsmVhhD8Qhscc4IY93lSLj1YQ/7spuBX20+8apdZScd+/2ZGEJSxevm/v8oThB1b K3lm44vxpd5ankfApIj3Lod9S8IGb6rknAc8grGjEvIQ1V+vFUdagw/rsvG02gnr1Uf/NN rEeOiIGEQ/6cTXATVNiuYxAajV1LANU= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5704995f964so14134017b3.2 for ; Thu, 06 Jul 2023 15:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688683860; x=1691275860; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Qwjh0UAlAYXVze8TCXBt1h/rZKLWFE0vCD0k3jVLMVk=; b=Y2yizmMpjzL0EwPNfj1fzhhPy4fB1Fio/333NC+Pl3+CabD5WvQiBObIAnbDvfdIz0 55qqIyoV/B43yRJQMgc5PRzcnEO7oZ13pzUFcnMsRpYGZDSVSZeMWMJRv9WA6h3i6GfT TXaYPaz84vks82iZ0vbDvAGXP/Ef7g9EhKOVR1CvAJFhj45Vp0/ta+dk/HgbDOBioOwa 2BKF9RsPqJx9l5jS/r3knSsrH/fNyDrHo/fZURqQr/YXnDI5GwojI2TLVLkJxGr1ous4 fBuKAKMZ/SIafScZO/gr72YFQKtZJ6oKMnuQ1yiJQjaFtVwKCY9iv6k7Pl0tvv06AM6a 3A8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688683860; x=1691275860; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qwjh0UAlAYXVze8TCXBt1h/rZKLWFE0vCD0k3jVLMVk=; b=Dn+ZPuyDWC1DQAAAq2yKxUET/rTyvkGz7KuAPeVHa14tiFhe6e9Ovy6kmGKLKw9nYt VYc+tg+1mGuVKGoDLc+uaPGq6mJmv+mvzpj2j8Vqpxq5QtMKrdem9inrs7yJcQA8hKo1 ANv1xLTCdlZfi0frJN7eVojccgPcU+Fe3ghjSXoA/F9IAIJvzp1YLcLdUTQ1vGBssjpW HEcs//my4x2eu/9z3c1So7k5BDLQwoLVjwj45TBKOblWZy289CrPAqFtbxo97ltW4H8t NVJg0H/2xNDWjjeE1LZd0b1LNOPrxsknES1IpB8l2uJWNMh1qitSqTwoHulMlj2+owU8 2oOQ== X-Gm-Message-State: ABy/qLZEDllUi65pSR8K6B3WPY6VP8xhaX4OabZvy4BHOLn4W4ZswJQ+ LaN6YY+WfaRJ5xtxGe2rFbWfjfyYllAPHff4enHF X-Google-Smtp-Source: APBJJlEpiTBdlhXFZSaqCdtDMzVQ5W4G5GGFJKBbdNzbEaJCnt1GA18H5a/L9p5DQaoHYiuhi3h9J1K3iDtJg/4EMWJg X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:bec3:2b1c:87a:fca2]) (user=axelrasmussen job=sendgmr) by 2002:a81:c642:0:b0:576:d9ea:1331 with SMTP id q2-20020a81c642000000b00576d9ea1331mr27910ywj.4.1688683860327; Thu, 06 Jul 2023 15:51:00 -0700 (PDT) Date: Thu, 6 Jul 2023 15:50:33 -0700 In-Reply-To: <20230706225037.1164380-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20230706225037.1164380-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230706225037.1164380-6-axelrasmussen@google.com> Subject: [PATCH v3 5/8] mm: userfaultfd: support UFFDIO_POISON for hugetlbfs From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Brian Geffon , Christian Brauner , David Hildenbrand , Gaosheng Cui , Huang Ying , Hugh Dickins , James Houghton , "Jan Alexander Steffens (heftig)" , Jiaqi Yan , Jonathan Corbet , Kefeng Wang , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Peter Xu , Ryan Roberts , Shuah Khan , Suleiman Souhlal , Suren Baghdasaryan , "T.J. Alumbaugh" , Yu Zhao , ZhangPeng Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen X-Rspamd-Queue-Id: 5BFE3140007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 9n95my3546yxwunzz8afn6pw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XXVMpnfQkcvFxParuBhQ/3mAoH+LOExBgLvt1g3f0OQ6HaOdAh0lu4yDdeivkZRVIFe+c7E2XbPGjb0K96sTBHlGNKQ/uQ8ZoTHDmHrYyZ46bZF0r2jbXkrVezYhKQ4YjIEOHlAxfdse1DdnUKTZNm4DVGws/zjhsJZLy/QTpGDR55O2J+NVJQ5BcxTZOR7DvDIvZK4IXAnvsB+iCBavXFdu2iu2Wx6Ex9Aek8Vcp3PTHSQpDgBjfAhYnm/UYFSP5NpnqVLgn06o95Ta1vq1U3uaHgR4vNTRMsP6y+SHp5EUQq4MuHOp9xl2KpxUOayIlhWHyN83fhs/5jj1c7ZX5UEB1ZEhOWCRiFtHco/33mm1G2N+F9o7s7UzGlgtuE4AF81h9ePJss5rMDCn3JZ50cfpQZV4C0gtupnNT6bVI/6zy+SZGHNHpTgKUEzGVI9wiKEYuFCWTt5do+Yeryqv5hTZLLSniNNamIroYdHK2nRkJcQtnkVB9LgSwFSdpJt8fKjOOYBYh7hn+Mot0P2Q9O3q8JpJPZQba2OCqtnYEZ5cum/R3B2n8KUfdqAp73jfpZIqSUxKF/bK3JNuTf1B0GYeVnnYbW+xOGgWeOTTWBRoDXYO9wP402hOC+/UA9oFfRFkJRgUU8kbALNLsG2S5oET4tUz3p/g== 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: The behavior here is the same as it is for anon/shmem. This is done separately because hugetlb pte marker handling is a bit different. Signed-off-by: Axel Rasmussen Acked-by: Peter Xu --- mm/hugetlb.c | 19 +++++++++++++++++++ mm/userfaultfd.c | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 934e129d9939..20c5f6a5420a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6263,6 +6263,25 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, int writable; bool folio_in_pagecache = false; + if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { + ptl = huge_pte_lock(h, dst_mm, dst_pte); + + /* Don't overwrite any existing PTEs (even markers) */ + if (!huge_pte_none(huge_ptep_get(dst_pte))) { + spin_unlock(ptl); + return -EEXIST; + } + + _dst_pte = make_pte_marker(PTE_MARKER_ERROR); + set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); + + /* No need to invalidate - it was non-present before */ + update_mmu_cache(dst_vma, dst_addr, dst_pte); + + spin_unlock(ptl); + return 0; + } + if (is_continue) { ret = -EFAULT; folio = filemap_lock_folio(mapping, idx); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 899aa621d7c1..9ce129fdd596 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -373,8 +373,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( * by THP. Since we can not reliably insert a zero page, this * feature is not supported. */ - if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE) || - uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { + if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE)) { mmap_read_unlock(dst_mm); return -EINVAL; }