From patchwork Sat Dec 4 18:23:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12656743 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 09F6EC433EF for ; Sat, 4 Dec 2021 18:24:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 750296B0081; Sat, 4 Dec 2021 13:23:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E5D16B0082; Sat, 4 Dec 2021 13:23:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5043F6B0083; Sat, 4 Dec 2021 13:23:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 3E6BD6B0081 for ; Sat, 4 Dec 2021 13:23:30 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 015D618098A1A for ; Sat, 4 Dec 2021 18:23:20 +0000 (UTC) X-FDA: 78880934160.07.B42886C Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf22.hostedemail.com (Postfix) with ESMTP id 18E8F1902 for ; Sat, 4 Dec 2021 18:23:19 +0000 (UTC) Received: by mail-qk1-f180.google.com with SMTP id m186so7061852qkb.4 for ; Sat, 04 Dec 2021 10:23:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=n0YxASesL46VAjA2z/ow7KiwVFM+As8nZthIAhuXqxc=; b=cZli0N6zOSpC45lUPq9JIwM3qMTdcJqy5cXESpOiwRbnre5M851x2er9c63mkwjv4Q uZ6zKOY/dgEq+9jE+eomZ2x8TJ91msWC7d2P1SSOobtxZ5UcJN3O5fzMjx+Le3PrA9wO e7uN/tRxynz9BBw95UC15OyqWsqJhGktg1lh7hTozhwb4A0lkxkLSJXZt8k/MQ5eXTgF uYQyrBzu5NQPMYVQ+wIH5Tr8SutWuNh+JvU/ijy742A+kPVWvk9N+JDOrqEjIHkS6oIm 7E2+8K0XR4s3PvG/2abBAbDRK9vYTbjiIqdAGO0OIJfUy8ybBYdSeLEIaZRgIXBYNQiL dqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n0YxASesL46VAjA2z/ow7KiwVFM+As8nZthIAhuXqxc=; b=sJ0Fbe1vQYooCBc24unslppjJ9BGJ+EoLL03AMfX1v9puoql/5SRkAHuu5tgmvUE4t foLgim9KsBXKnHdggRUJt/rayJXqQBB1owzAGGNnsRWtCWRPnpXVrx2DMq1q56R/hONd rlNp+YEpGYnu2kWZGie8ARG2vYhcpcnL6R9v6kWGgmiwLt8ZAgOuf2rkiL9J++NTyhOa IHeWsNUmYQjkya7m5iFBD/UEvUZjicWJzJqb/7NqcrpENq/ATzb7RNnHY0snrnzA3TgL Onstp/uFM2SvVUnNwV7oDbuONdPqaXknfGYYcPQGKKddGoKsrVC5B4UafsiE7Vzw07Ot XvPw== X-Gm-Message-State: AOAM531r3vDrpuMfzEn+DEHdYVngj+JDXy2TLqW8+sfTha/tbyeju+ID 95cTHsfhpjYf93TBdSUxL5UqbQ== X-Google-Smtp-Source: ABdhPJxPsFEDpwBIvnp31rmo1LtzlRi+tnB4h7nFDAuMVVnO2bCon47rS34C6Luf9oKpBoZsxJ0Eqg== X-Received: by 2002:a37:b182:: with SMTP id a124mr24022872qkf.135.1638642198919; Sat, 04 Dec 2021 10:23:18 -0800 (PST) Received: from soleen.c.googlers.com.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id a24sm4394728qtp.95.2021.12.04.10.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Dec 2021 10:23:18 -0800 (PST) From: Pasha Tatashin To: pasha.tatashin@soleen.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org, rientjes@google.com, pjt@google.com, weixugc@google.com, gthelen@google.com, mingo@redhat.com, corbet@lwn.net, will@kernel.org, rppt@kernel.org, keescook@chromium.org, tglx@linutronix.de, peterz@infradead.org, masahiroy@kernel.org, samitolvanen@google.com, dave.hansen@linux.intel.com, x86@kernel.org, frederic@kernel.org, hpa@zytor.com, aneesh.kumar@linux.ibm.com, jirislaby@kernel.org, songmuchun@bytedance.com, qydwhotmail@gmail.com Subject: [PATCH v2 2/4] mm: ptep_clear() page table helper Date: Sat, 4 Dec 2021 18:23:12 +0000 Message-Id: <20211204182314.1470076-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211204182314.1470076-1-pasha.tatashin@soleen.com> References: <20211204182314.1470076-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 18E8F1902 X-Stat-Signature: co7t5k48fe4nwcdkfroej83cc6f89je6 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=cZli0N6z; dmarc=none; spf=pass (imf22.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1638642199-302198 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: We have ptep_get_and_clear() and ptep_get_and_clear_full() helpers to clear PTE from user page tables, but there is no variant for simple clear of a present PTE from user page tables without using a low level pte_clear() which can be either native or para-virtualised. Add a new ptep_clear() that can be used in common code to clear PTEs from page table. We will need this call later in order to add a hook for page table check. Signed-off-by: Pasha Tatashin --- Documentation/vm/arch_pgtable_helpers.rst | 6 ++++-- include/linux/pgtable.h | 8 ++++++++ mm/debug_vm_pgtable.c | 2 +- mm/khugepaged.c | 12 ++---------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Documentation/vm/arch_pgtable_helpers.rst b/Documentation/vm/arch_pgtable_helpers.rst index 552567d863b8..fbe06ec75370 100644 --- a/Documentation/vm/arch_pgtable_helpers.rst +++ b/Documentation/vm/arch_pgtable_helpers.rst @@ -66,9 +66,11 @@ PTE Page Table Helpers +---------------------------+--------------------------------------------------+ | pte_mknotpresent | Invalidates a mapped PTE | +---------------------------+--------------------------------------------------+ -| ptep_get_and_clear | Clears a PTE | +| ptep_clear | Clears a PTE | +---------------------------+--------------------------------------------------+ -| ptep_get_and_clear_full | Clears a PTE | +| ptep_get_and_clear | Clears and returns PTE | ++---------------------------+--------------------------------------------------+ +| ptep_get_and_clear_full | Clears and returns PTE (batched PTE unmap) | +---------------------------+--------------------------------------------------+ | ptep_test_and_clear_young | Clears young from a PTE | +---------------------------+--------------------------------------------------+ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index e24d2c992b11..bc8713a76e03 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -258,6 +258,14 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma, #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif +#ifndef __HAVE_ARCH_PTEP_CLEAR +static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep) +{ + pte_clear(mm, addr, ptep); +} +#endif + #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long address, diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 228e3954b90c..cd48a34c87a4 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -652,7 +652,7 @@ static void __init pte_clear_tests(struct pgtable_debug_args *args) set_pte_at(args->mm, args->vaddr, args->ptep, pte); flush_dcache_page(page); barrier(); - pte_clear(args->mm, args->vaddr, args->ptep); + ptep_clear(args->mm, args->vaddr, args->ptep); pte = ptep_get(args->ptep); WARN_ON(!pte_none(pte)); } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index dd807261ed9f..c78242d15406 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -756,11 +756,7 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page, * ptl mostly unnecessary. */ spin_lock(ptl); - /* - * paravirt calls inside pte_clear here are - * superfluous. - */ - pte_clear(vma->vm_mm, address, _pte); + ptep_clear(vma->vm_mm, address, _pte); spin_unlock(ptl); } } else { @@ -774,11 +770,7 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page, * inside page_remove_rmap(). */ spin_lock(ptl); - /* - * paravirt calls inside pte_clear here are - * superfluous. - */ - pte_clear(vma->vm_mm, address, _pte); + ptep_clear(vma->vm_mm, address, _pte); page_remove_rmap(src_page, false); spin_unlock(ptl); free_page_and_swap_cache(src_page);