From patchwork Wed Jul 14 22:25:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12377979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A971C47E4E for ; Wed, 14 Jul 2021 22:25:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F29B2613C9 for ; Wed, 14 Jul 2021 22:25:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F29B2613C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 50B976B00D0; Wed, 14 Jul 2021 18:25:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E36B6B00D1; Wed, 14 Jul 2021 18:25:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35C416B00D2; Wed, 14 Jul 2021 18:25:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 138FB6B00D0 for ; Wed, 14 Jul 2021 18:25:19 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0DC651C943 for ; Wed, 14 Jul 2021 22:25:18 +0000 (UTC) X-FDA: 78362625516.22.0B7EFFF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id A31A19000253 for ; Wed, 14 Jul 2021 22:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626301517; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FG94X/udzrS/4H8a9ROacZylO2qMwKMDk77nG92mz5U=; b=Kpyj3P1g1XHu52rO2ZEgbk6oAov94oPE1JsekJ3m9Lb1oSXkpSIgJ9mec6WNqkEErto2kY fH+GpgQV1pBRdutcfphQv/3g31OBWQrWNljaBbyWZx+wxNpsUydOSM9raHq70HBwimiBPH UuGuu+NV3l1bPIS5j7T0KwaW3Hxfhc0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-516-40SMe_o_N0WjjftH6w5EYg-1; Wed, 14 Jul 2021 18:25:16 -0400 X-MC-Unique: 40SMe_o_N0WjjftH6w5EYg-1 Received: by mail-qk1-f197.google.com with SMTP id j9-20020a05620a0009b02903b770762a3cso2280434qki.17 for ; Wed, 14 Jul 2021 15:25:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FG94X/udzrS/4H8a9ROacZylO2qMwKMDk77nG92mz5U=; b=ra+gV6qPCb3G44LE6QuBvCcB0Czk3lhpwT/BYCGBYeWuG+NHimq4Xo3EYlC0gXIIi7 vtmgqteg267X2d3KKvqsy7sNULql89CKZnU6hEEkKFJUU493fA7GLIlFJeGZsnJNQYqh pIaJEbNPN0WzJAat7sV22BclkNl6mH9W7ueh8ZmWSv9xBK2n2Qlb94mdGveN0DlIPC+L w8zfBABTN9x4mEo7BUOqE9CHHFSeeNciLt4b81rYnMjVSXGanFoK/lLB0FrUT91eMBe6 o49RyE6whIKycdsSybS0EWrdsmDgH0MMmEYr9cOk501erwyErUvRDScb6fW53o/c1u2s IQ4g== X-Gm-Message-State: AOAM532EnRCZzO7eNhAd2yj0YGsUWM1ieqNTtR6g4I1zRQ3XV2icrdWh Fl4dHD96gFMzJIYDL+tO00rDr5fxn8MOUg3zuh3YL0loHaSC/ntXj8G5cw5vEBdY8ydjzKWa8Rd cA4gzYsgwoB2X3B8hS/rMR1tfhEt/J1i7aDBAQWx0NWYvVe1I8J+D0O30lMdF X-Received: by 2002:ac8:4e95:: with SMTP id 21mr342292qtp.234.1626301515557; Wed, 14 Jul 2021 15:25:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXR+Vu/+o0F5Ebn+71mCKuvUYN3/uYB7J35r5bAygeXC05i/PyQzKZDPriZMgwiauQ0WseFw== X-Received: by 2002:ac8:4e95:: with SMTP id 21mr342258qtp.234.1626301515288; Wed, 14 Jul 2021 15:25:15 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id f62sm1662862qke.135.2021.07.14.15.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 15:25:14 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Mike Kravetz , Axel Rasmussen , Miaohe Lin , "Kirill A . Shutemov" , Hugh Dickins , Jason Gunthorpe , Alistair Popple , Matthew Wilcox , peterx@redhat.com, Jerome Glisse , Andrea Arcangeli , Mike Rapoport , Nadav Amit , David Hildenbrand Subject: [PATCH v4 20/26] mm/hugetlb: Introduce huge version of special swap pte helpers Date: Wed, 14 Jul 2021 18:25:11 -0400 Message-Id: <20210714222511.49094-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210714222117.47648-1-peterx@redhat.com> References: <20210714222117.47648-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Kpyj3P1g; spf=none (imf29.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A31A19000253 X-Stat-Signature: whijrydh1bfp9krrnd1nxi3jasnzj3gd X-HE-Tag: 1626301517-32978 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: This is to let hugetlbfs be prepared to also recognize swap special ptes just like uffd-wp special swap ptes. Reviewed-by: Mike Kravetz Signed-off-by: Peter Xu --- mm/hugetlb.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7d3558265b6f..6a66b598245e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -95,6 +95,26 @@ static inline bool subpool_is_free(struct hugepage_subpool *spool) return true; } +/* + * These are sister versions of is_swap_pte() and pte_has_swap_entry(). We + * need standalone ones because huge_pte_none() is handled differently from + * pte_none(). For more information, please refer to comments above + * is_swap_pte() and pte_has_swap_entry(). + * + * Here we directly reuse the pte level of swap special ptes, for example, the + * pte_swp_uffd_wp_special(). It just stands for a huge page rather than a + * small page for hugetlbfs pages. + */ +static inline bool is_huge_swap_pte(pte_t pte) +{ + return !huge_pte_none(pte) && !pte_present(pte); +} + +static inline bool huge_pte_has_swap_entry(pte_t pte) +{ + return is_huge_swap_pte(pte) && !is_swap_special_pte(pte); +} + static inline void unlock_or_release_subpool(struct hugepage_subpool *spool, unsigned long irq_flags) { @@ -4138,7 +4158,7 @@ bool is_hugetlb_entry_migration(pte_t pte) { swp_entry_t swp; - if (huge_pte_none(pte) || pte_present(pte)) + if (!huge_pte_has_swap_entry(pte)) return false; swp = pte_to_swp_entry(pte); if (is_migration_entry(swp)) @@ -4151,7 +4171,7 @@ static bool is_hugetlb_entry_hwpoisoned(pte_t pte) { swp_entry_t swp; - if (huge_pte_none(pte) || pte_present(pte)) + if (!huge_pte_has_swap_entry(pte)) return false; swp = pte_to_swp_entry(pte); if (is_hwpoison_entry(swp))