From patchwork Thu Jun 23 23:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12893257 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 7BEEEC43334 for ; Thu, 23 Jun 2022 23:52:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 164458E01A8; Thu, 23 Jun 2022 19:52:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 114918E01A1; Thu, 23 Jun 2022 19:52:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1FF18E01A8; Thu, 23 Jun 2022 19:52:38 -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 E62428E01A1 for ; Thu, 23 Jun 2022 19:52:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B389A204B0 for ; Thu, 23 Jun 2022 23:52:38 +0000 (UTC) X-FDA: 79611152796.01.A489A82 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf22.hostedemail.com (Postfix) with ESMTP id 523BCC000D for ; Thu, 23 Jun 2022 23:52:38 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id go6so1171899pjb.0 for ; Thu, 23 Jun 2022 16:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gLXI0bFmtdpL1fm2aZ9vhvRpJm3p+mQNTKIlYsIrOjU=; b=n3EpWNne89DpkqcHeRXrJ15yy+IykIai7ornumZPTFP3oBklmi1A9IfZR2B/qtHRBE fEhmAFan4uUC7OrYWIDjV7OSRH6ALcWMbKnDZSnGBAIPyEKvGE2GD8iLzFiQWbhjOx8P IFNuSd9GajJZepS7jAVhRX8+KQZnAlpgD4YGn66q6n+VtWWRkfFQljjadM7UsZJhdNcu W5am1TruDf29uTRDkrxWzSbMs3OV9pweR6PMVYdkYTxMG98IlJmK7MRM3Pe2tLTOpxMP w9fq/O2WZelM6ft+W/kTXDjoHIMwggETk7IWGuE//bekvG8z5qhjUlCrGxuudfCbY2gV /lcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gLXI0bFmtdpL1fm2aZ9vhvRpJm3p+mQNTKIlYsIrOjU=; b=YedezYLqQC6HIXGTge0WRmXo7LYpTxbiZ7DWdrohGP3PG6u2pXGmnKBSCkaM9HNgZ5 TicMCpwdFZLEfmcxvICbCHMeGEYbONhdD0FUunMUkXUnQ1yr/a/TvDn5mgeE6NdJ5jSo 56HIHpMShyTSLd++w//dET1Q4cTtMficEx7nDPVXBJQZtv4Vkv1FR/QbDE3Nfb2YT3Bg K0Da9L0QwGXKdYndFL4aNxBfefP3flNT2duhX7C7suleeIxiKAtvVNoZinO3tTjnvp5E ljvYScsD1jP3cl2lDCH8dTvNR//LBJ1dKEdvHNaF2TYerYojgZftIGwvIel9WWuonvTx tP/A== X-Gm-Message-State: AJIora/i0QU+u4i9jMtii/liXTA9ao/NmDtneZDjRpfiPc88sudoq+fX 3U5hqVHlDdcFBJB0UdnrZIhntvlasQ== X-Google-Smtp-Source: AGRyM1swwZN4zwkDXsQnlRX7chaljh2k4qwXaQviyOxNxdAje8fNl06jiLeDO1ZeRVZ07VAF4OC9+g== X-Received: by 2002:a17:903:2350:b0:16a:4246:f1b6 with SMTP id c16-20020a170903235000b0016a4246f1b6mr12420841plh.35.1656028357207; Thu, 23 Jun 2022 16:52:37 -0700 (PDT) Received: from ik1-406-35019.vs.sakura.ne.jp (ik1-406-35019.vs.sakura.ne.jp. [153.127.16.23]) by smtp.gmail.com with ESMTPSA id r10-20020a170903020a00b00168eab11f67sm362571plh.94.2022.06.23.16.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 16:52:36 -0700 (PDT) From: Naoya Horiguchi X-Google-Original-From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/9] mm/hugetlb: make pud_huge() and huge_pud() aware of non-present pud entry Date: Fri, 24 Jun 2022 08:51:47 +0900 Message-Id: <20220623235153.2623702-4-naoya.horiguchi@linux.dev> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> References: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=n3EpWNne; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of nao.horiguchi@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=nao.horiguchi@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656028358; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gLXI0bFmtdpL1fm2aZ9vhvRpJm3p+mQNTKIlYsIrOjU=; b=QrrK1kV7xfODK1M0eReCLThoBUrBg3tKfN8XVnxFC4+0rCmLoe2cW1o3q7mQpq74maFZFW mB/ZfxCxkMzXq7E82+vAXs+MR5MjXFJekELiUQnjsl2n0rexwuF+Dhd1H38/ZyNQOAS69s lDa619G2gIZGJsJmJeikeLJ/knU95Ug= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656028358; a=rsa-sha256; cv=none; b=dUV7lyTFU2dEDfxizoI3chje/c98zdo/emCgNvnrMSjJEPbK9L9lB/1G6GH/i3zm0/iYyX 6X1yVpTAmHeg9JcDfT9zbcf9OGsyPZeDQicMMEbMC45oyc7jYty1RavgoOeZayH8+Wg7Dj hu7vACCFQL+TbLrr2DKKCqbKtp9nzVg= X-Stat-Signature: xtootxmrnnddtafd89huk79h15bic78t X-Rspamd-Queue-Id: 523BCC000D X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=n3EpWNne; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of nao.horiguchi@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=nao.horiguchi@gmail.com X-Rspamd-Server: rspam12 X-HE-Tag: 1656028358-204362 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: From: Naoya Horiguchi follow_pud_mask() does not support non-present pud entry now. As long as I tested on x86_64 server, follow_pud_mask() still simply returns no_page_table() for non-present_pud_entry() due to pud_bad(), so no severe user-visible effect should happen. But generally we should call follow_huge_pud() for non-present pud entry for 1GB hugetlb page. Update pud_huge() and huge_pud() to handle non-present pud entries. The changes are similar to previous works for pud entries commit e66f17ff7177 ("mm/hugetlb: take page table lock in follow_huge_pmd()") and commit cbef8478bee5 ("mm/hugetlb: pmd_huge() returns true for non-present hugepage"). Signed-off-by: Naoya Horiguchi --- arch/x86/mm/hugetlbpage.c | 3 ++- mm/hugetlb.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index a0d023cb4292..5fb86fb49ba8 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -70,7 +70,8 @@ int pmd_huge(pmd_t pmd) int pud_huge(pud_t pud) { - return !!(pud_val(pud) & _PAGE_PSE); + return !pud_none(pud) && + (pud_val(pud) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; } #endif diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f59f43c06601..b7ae5f73f3b2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6946,10 +6946,34 @@ struct page * __weak follow_huge_pud(struct mm_struct *mm, unsigned long address, pud_t *pud, int flags) { + struct page *page = NULL; + spinlock_t *ptl; + pte_t pte; + if (flags & (FOLL_GET | FOLL_PIN)) return NULL; - return pte_page(*(pte_t *)pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT); +retry: + ptl = huge_pte_lock(hstate_sizelog(PUD_SHIFT), mm, (pte_t *)pud); + if (!pud_huge(*pud)) + goto out; + pte = huge_ptep_get((pte_t *)pud); + if (pte_present(pte)) { + page = pud_page(*pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT); + if (WARN_ON_ONCE(!try_grab_page(page, flags))) { + page = NULL; + goto out; + } + } else { + if (is_hugetlb_entry_migration(pte)) { + spin_unlock(ptl); + __migration_entry_wait(mm, (pte_t *)pud, ptl); + goto retry; + } + } +out: + spin_unlock(ptl); + return page; } struct page * __weak