Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp135952pxb; Fri, 15 Jan 2021 09:13:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2bGJCqAVX7Oib/IZS5PG5a1Oz31ulrF+f5cZ4yvCzKo8QHC0yzdv1d3eZAd1KB7f0tgMX X-Received: by 2002:a05:6402:46:: with SMTP id f6mr10529909edu.163.1610730837314; Fri, 15 Jan 2021 09:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610730837; cv=none; d=google.com; s=arc-20160816; b=HHQM+WitjG1suZvC8Euq9s2yT6Tzr0+xU+MPZcNSUZJcDKVtGzNP3+JOhd5SSDk25i B081ACDynSBkOWN0f7DGx6j4zg9JV1ZuyH8AFAeKYVPZjH4jj+wHxmEXrl+ZwZRbvLmn IRN29I68mUBx12D/aystGEw8rtttNQF2dcRxHBMXcfYfjsuzr/jmf2UHR9KldcuTKpRX dGXcC4Qlt6C8tY72p6R/2O9yMnXbwkMpeZy/eAXlFetoaO+UztKy4foHW/pCnbINJLSA qYsRxPmdrc5hVGsYtK0x0LzXDBT4AEUuS6ZecPr7jBWZaqLca2tmKO4x0ToajM0vjsUH 6HKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xbapPq1ojGk8GME+3Q5hIrqVuXOJyakklI0BdH5xjl0=; b=OfKrSMMFGr8EAGe6C/kWzcO8BhC/aNmruOV8g+k1fG6sv7JFXhflsKRsIde+NPstzm NwpSRTUvZlYKN6x7sMBEHUeJfNrm7l1xclM2RJevR+8HU6S0BseoqvGOKnSgK1W2VM3I WuVPj4Gpbde1XPht2LlFjRQCx+0xkoEvb25R42qXhLp9L3zz25gMJJnavPS2+PJqHbQC Ec6J0n3mW3I5cc5uUFzjmwEn28VEwSBwON5RASkX6sOFn1C1lIktz0gB7GruCe43hweF EBB1ojrUUVfUphufyikSWgastE+D0QWTRNdcEnaeNzM81W5E3yeDKxOpUIZ4+LOYzHre ZKfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RPvO9DAH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si4013971ejx.605.2021.01.15.09.13.33; Fri, 15 Jan 2021 09:13:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RPvO9DAH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387404AbhAORLZ (ORCPT + 99 others); Fri, 15 Jan 2021 12:11:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45140 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733304AbhAORLY (ORCPT ); Fri, 15 Jan 2021 12:11:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610730597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xbapPq1ojGk8GME+3Q5hIrqVuXOJyakklI0BdH5xjl0=; b=RPvO9DAHzNPX9jbxZh82wlZbpKC/kbAayXirvdDPyWlo4K33UgBGAAmrrNF76W8PcCmAar wTKRF3tyks7iCJTwpcgAH+bgVjI+MUrc15c50kCVtHE46PHSLW3W/BMmm156EZmz8UjHZL ZwyZCf0L7L+jfE7u/x044np4WnoxQoc= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-DaPw4eWDOFqjZaGWKxnRyQ-1; Fri, 15 Jan 2021 12:09:56 -0500 X-MC-Unique: DaPw4eWDOFqjZaGWKxnRyQ-1 Received: by mail-qt1-f200.google.com with SMTP id l7so7871259qth.15 for ; Fri, 15 Jan 2021 09:09:56 -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=MuCNp9cuVqc3u+tIHVwEW5yDKZUdfZhnmt1Rp6SBGr3uot24NDSar++BEcHKZNNyPP 0s38VVmXaUvybihnLRV2R5al25Z+DxOSOZTFBnDuDn4LVAZ1yUT1OLTjP7WSGnJE4UQ9 2/shia53Kgx7u0OPoIX76eWaEDSm4YYj8GpzZU+1X7jsNrjpQkvd3fpnk6JZ3nd34qRt 9QPONCiCoeWi8RZm7JF69AxNcw2yiZJaxStVUpzbM1SMw/mmOIJCI3Gn+MroMqmkDdjH qTa4Sg6jVNssTkujJqPXd0WGn7TWFvrTxuNW5A3IbW8idLMKjB5noKrMa+4QxGOFxaRE 0XQg== X-Gm-Message-State: AOAM532EnaGUe8K1pnoOaoMlBSCRzwJp6D1GlP84U4JhzsvjQULeOXkB WO8o6tSDcVYV3LKrN1R6LO+7cDnOBaTkIlpz4zZ2Fs73g92vYNXhPUhN/fDWBNRG84+fclB13D7 mo8/rO1Yf4EF/wfOXzTtqSCocTUwIDaDsYYNJNnxd41rzzvWYjSY8pmasznhy8BCUAfSYFP9wHA == X-Received: by 2002:a37:d13:: with SMTP id 19mr13531605qkn.93.1610730595287; Fri, 15 Jan 2021 09:09:55 -0800 (PST) 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)) -- 2.26.2