From patchwork Fri Jan 15 17:09:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12023355 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,SPF_PASS,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 92783C433E0 for ; Fri, 15 Jan 2021 17:10:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D5BC2333E for ; Fri, 15 Jan 2021 17:10:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D5BC2333E 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 A646F8D01B1; Fri, 15 Jan 2021 12:09:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A13C68D01AE; Fri, 15 Jan 2021 12:09:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 904108D01B1; Fri, 15 Jan 2021 12:09:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 764F78D01AE for ; Fri, 15 Jan 2021 12:09:59 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4078A801AD4B for ; Fri, 15 Jan 2021 17:09:59 +0000 (UTC) X-FDA: 77708646918.22.glove73_030c00627531 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 188851810DA3A for ; Fri, 15 Jan 2021 17:09:59 +0000 (UTC) X-HE-Tag: glove73_030c00627531 X-Filterd-Recvd-Size: 5825 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 17:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610730598; 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=xbapPq1ojGk8GME+3Q5hIrqVuXOJyakklI0BdH5xjl0=; b=AZ+6V318A0ZD0vAGxCuKkGBxei7iRJywlXJtUQZocXw+rQYW78inKk0wF/FdCiVa4nrKmc fa5tnmjrX07linCeGl3NDAvwJqS4q/rjXgW+F1WXgwZVenHcPhuxgOSCowt9i5tadpaDK/ rcd/9R5bcaPqFQC5cJQUjuWQAk9yN6k= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-FckXlN_hONOSIpBFPYxJew-1; Fri, 15 Jan 2021 12:09:55 -0500 X-MC-Unique: FckXlN_hONOSIpBFPYxJew-1 Received: by mail-qv1-f71.google.com with SMTP id l3so8258257qvr.10 for ; Fri, 15 Jan 2021 09:09:55 -0800 (PST) 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=xbapPq1ojGk8GME+3Q5hIrqVuXOJyakklI0BdH5xjl0=; b=Q7F4obuxY+183W8hW51nstjqIpHkzZNpSoA42YC/hNa4It00I4QbvLxpgcDUE/7Pft zlaZohxuKNegipJkpFtlyPQQBLSQadtlDY1c3XR9B6nTh9m56TyxzKJn67cTxzpVD8jm DqnAT+ZyVmshUX2xwY0B1ovzVYTC2zBNncoEYgh53D+Ounh0yriaIGkp7bpsZNZhPoci FB6bQn6GMAEsJaMYYeDC2S5wQzSBP/29bR+LqUbB8LbMUjfrefPfydl6b8Nipu3ct3DS J4AeAw36aD6jOi3NBXvyLKpZSmvkRg34xSiB2GlHVppaTR5j3A68ObzvI7qG73lZo/HL cenQ== X-Gm-Message-State: AOAM532PqtbSr38mDA5F3Wx5lCVVwOc6PfW7onCN7q8pbyOBxOcbMIR0 HhJscuh3Peb98VeRXOYLiwMJsqWDXx5/l8JZAtWdyOsV251ws5P8YN+6AJ1s6MlbtCE8Pjggy49 cS2Zm/RGj86g= X-Received: by 2002:a37:d13:: with SMTP id 19mr13531587qkn.93.1610730595178; Fri, 15 Jan 2021 09:09:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJykF/E1p80aUABfZGvXlMxL3xP2NWVwmUQdTiVuy3IF0dNtbXolMRMz6g1eiLbW1PrGID+lQw== X-Received: by 2002:a37:d13:: with SMTP id 19mr13531559qkn.93.1610730594964; Fri, 15 Jan 2021 09:09:54 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id d123sm5187840qke.95.2021.01.15.09.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:09:54 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Rapoport , Mike Kravetz , peterx@redhat.com, Jerome Glisse , "Kirill A . Shutemov" , Hugh Dickins , Axel Rasmussen , Matthew Wilcox , Andrew Morton , Andrea Arcangeli , Nadav Amit Subject: [PATCH RFC 23/30] mm/hugetlb: Introduce huge version of special swap pte helpers Date: Fri, 15 Jan 2021 12:09:00 -0500 Message-Id: <20210115170907.24498-24-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115170907.24498-1-peterx@redhat.com> References: <20210115170907.24498-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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. Signed-off-by: Peter Xu --- mm/hugetlb.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index dd2acb8b3f0f..16a07f41880e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -82,6 +82,25 @@ struct mutex *hugetlb_fault_mutex_table ____cacheline_aligned_in_smp; /* Forward declaration */ static int hugetlb_acct_memory(struct hstate *h, long delta); +/* + * 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) { bool free = (spool->count == 0) && (spool->used_hpages == 0); @@ -3710,7 +3729,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)) @@ -3723,7 +3742,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))