From patchwork Tue Nov 16 22:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12623229 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A384C433EF for ; Tue, 16 Nov 2021 22:01:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 123B06140A for ; Tue, 16 Nov 2021 22:01:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 123B06140A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CFC616B0072; Tue, 16 Nov 2021 17:00:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CAB926B0073; Tue, 16 Nov 2021 17:00:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4D506B0074; Tue, 16 Nov 2021 17:00:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id A79A66B0072 for ; Tue, 16 Nov 2021 17:00:54 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 71A441820BA65 for ; Tue, 16 Nov 2021 22:00:44 +0000 (UTC) X-FDA: 78816163650.10.34120E4 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf30.hostedemail.com (Postfix) with ESMTP id 27BD7E001987 for ; Tue, 16 Nov 2021 22:00:42 +0000 (UTC) Received: by mail-qk1-f173.google.com with SMTP id de30so502223qkb.0 for ; Tue, 16 Nov 2021 14:00:43 -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=G1vrXLeEkHaL38rZeKIone4HWwJFBBENMbtQcmlY9TE=; b=g43F9JAkc38jKChhi+Enq5azWqDCveDPFo9GQvxs1HOambiVhd/Q9/G2nOkgHQ90+/ VdJSyJObxRWYtrGT8OX+1tXaMocpk279N1krNbEkZQ5ZYz+vD9Cr1NRFfAkHy6cy0Qp5 B7cF6yANqoD3FiElqjsCvFhA+lkUmtv+T96aeTaf0MRYhn2yr+zoUVm7fDlTEu5fNIb7 EmY28xIYxBP25lvZS7/V/Ut9l/61MormaCrfPZjsBUrlTuhK3LO/EKuaG8/MBZuSMLUv CAW3lP3q/SnjGSfXquWdLJtGHuVkZPJd+BbzBZcvNDtRwJz542CU8hZnat5MN186NduJ itZA== 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=G1vrXLeEkHaL38rZeKIone4HWwJFBBENMbtQcmlY9TE=; b=h/LK5xVWw7XVBck+hHPFJIscjlbvvbM6th5O276guLlq/61jIxFXQ9CMlrKLwWS77f ohGFYH8j8/OscTcSfYWRCtAz8IHRDm+jJ8IMPvs/nHVfMz0Y8L2ODU7uV1iAihiJNHyR 0zvh55PRx6+TKEm8NWP8qqENc6thoZEOMeXZPdHayK0i4ZtZVzfrprCkdgpc4y+PzkRy nkYM7eEJBcE0r5mlDMkhGGbjHsnbB4lUVWCBo3TKSLPjhp2GtEYIEQnPRIvHxg7LXTc0 aXA2/DtI1z57wzo4Ac/pmNzyKbdICSj2xbYlNxHFm63CnM5qqUzC4+k/T62SSdYxLtmx +RSA== X-Gm-Message-State: AOAM5305+h23HTwQVrbLKeEE36fVaTWKV+VvhgSp0hLo3aN7SdjwjGN3 AuPlK/DLKhBfKeDtgN9w6QL82g== X-Google-Smtp-Source: ABdhPJz5PqqO+f+EAo1gNP40S4S3NrRDchCV410DLqkX5Ry47U4kOjvGRk8RnnGN+BMTTwB90ZGRUw== X-Received: by 2002:a05:620a:150a:: with SMTP id i10mr8663279qkk.252.1637100043405; Tue, 16 Nov 2021 14:00:43 -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 i11sm2975655qko.116.2021.11.16.14.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 14:00:42 -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 Subject: [RFC 1/3] mm: ptep_clear() page table helper Date: Tue, 16 Nov 2021 22:00:36 +0000 Message-Id: <20211116220038.116484-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211116220038.116484-1-pasha.tatashin@soleen.com> References: <20211116220038.116484-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 27BD7E001987 X-Stat-Signature: 5o47zk7ai7dbq5gq4ct7dip7d18qsg7g Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=g43F9JAk; dmarc=none; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.173 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1637100042-975662 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/khugepaged.c | 12 ++---------- 3 files changed, 14 insertions(+), 12 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/khugepaged.c b/mm/khugepaged.c index 5f02fda6f265..6ae659ef7e08 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);