From patchwork Mon Jul 10 20:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 118091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp66506vqm; Mon, 10 Jul 2023 13:55:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGyMsagxO6PeUrfCC4+ySbXuzUAEOHCpRCDQKw9HMHB2+So2Ad7xWqYXZFpgBthYXW9yw2U X-Received: by 2002:ac2:5f9c:0:b0:4f8:58af:ebd7 with SMTP id r28-20020ac25f9c000000b004f858afebd7mr10108350lfe.39.1689022512687; Mon, 10 Jul 2023 13:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689022512; cv=none; d=google.com; s=arc-20160816; b=VU9Sth3kqcK81UCS4LIbA3Z5pWHLUhkG958qhdUddms8vQlNiAchoco1eCOzEWQFJz VH4/kzt6s7BB2fRfMpLdrCKmlGN3CwnLwCAPd+O2qGSJtDr5hFSmhQxISXAgz41yxvip nnvQxKVysLt2pKca5pTPwzcD7koFoTsvRObjVTFbqnbjtC+jG8beGwfOZ6oeFz+xSbqj mBQ9cMttyzCq1gm30QjkSaRR4pJSzc8sTjkyEl8qlfbUSgW/2ahE37SmCT9V6BjIJz/z qmhw/riaa5EQ3lFxD7SN559tdwDtHGYSP7BtU6xiRkfU0GJVL48ualxVWORmASXPeQ1C KgWw== 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=eJelxPmopSzMoFe/Y1tUG0sLrpgQ5fNaEOVpyq/ur+g=; fh=o5Gq1WLGnnFTlNdb8t4YCP7HM0H9d2hN3YCEdtj1R/Q=; b=k8gjbkG2ed+VdWxmoLhtn5aCO0PYtGZ+juD7/afGHvGLabV0IBM3sLaTLGVv15TplP /XspaaibsGTQVkvCJ6GGThkRRe1nNL/YIlx4hiNzgNo8c8NRXsD6gCqfBhKtpGoiD+9G 8jw2dlZmcE9Lv4a9SyWYjlsJ+qHbgKLL9u8BNsZ+4AAqwCp1UMtw72zQDY5pMtDy9Hwn XkTqQNfOUi8w9ajaB4EkB2NuyHY8J9Nm20q97dsWxR3YW5KW/MLvvC8Hty9VqVJ3VJdp k5BoAEl8PG2i0D3GFu8SnCFsFgo5IR/XdJ6kL7byh08HoB11MelXSAjGtztKtL7/I9sB Xdzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=P8TzmlbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g20-20020aa7d1d4000000b0051e2a1ef7dbsi349481edp.495.2023.07.10.13.54.49; Mon, 10 Jul 2023 13:55:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=P8TzmlbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233389AbjGJUql (ORCPT + 99 others); Mon, 10 Jul 2023 16:46:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232792AbjGJUpF (ORCPT ); Mon, 10 Jul 2023 16:45:05 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DEE910C8; Mon, 10 Jul 2023 13:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=eJelxPmopSzMoFe/Y1tUG0sLrpgQ5fNaEOVpyq/ur+g=; b=P8TzmlbAwVhkTAwvj62gZ58sNq O6eAnY9zcJYyxX99bxIBcqqcHA6SMUID/AoEDWb8lvwCDN9uLo8mbJTdZ0/7ngKUF61ujoqPsmp6j epZ0CN27OLg0Mzv/zsUzJXIdj7am3CWhIQiHbO0Zg800SSUO6BirLjovPQaZ2eOrspS61MEF8cufx AMzNbAAW9ZGEHCK0fIQ2bnmZmZWx9kM7Kjt8Hd4NOwitJp41cFz1PkENpBLJ1fjO/gp6ChaO0g6DC vvX6k0YrZzXjjD0DWD04HKzOoy4ap9z9w1vMUYtmdsiKtnjv/TkcUelAXmFKRhjGgkbqAE+P2S9pk c04rTxwQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoG-77; Mon, 10 Jul 2023 20:43:41 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Rapoport , Pasha Tatashin , Anshuman Khandual Subject: [PATCH v5 02/38] mm: Convert page_table_check_pte_set() to page_table_check_ptes_set() Date: Mon, 10 Jul 2023 21:43:03 +0100 Message-Id: <20230710204339.3554919-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230710204339.3554919-1-willy@infradead.org> References: <20230710204339.3554919-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771068470689699682 X-GMAIL-MSGID: 1771068470689699682 Tell the page table check how many PTEs & PFNs we want it to check. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Mike Rapoport (IBM) Acked-by: Pasha Tatashin Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable.h | 2 +- include/linux/page_table_check.h | 14 +++++++------- mm/page_table_check.c | 14 ++++++++------ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index e8a252e62b12..a44a150e0318 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -348,7 +348,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) { - page_table_check_pte_set(mm, addr, ptep, pte); + page_table_check_ptes_set(mm, addr, ptep, pte, 1); return __set_pte_at(mm, addr, ptep, pte); } diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 75970ee2bda2..2137e36595b3 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -499,7 +499,7 @@ static inline void __set_pte_at(struct mm_struct *mm, static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval) { - page_table_check_pte_set(mm, addr, ptep, pteval); + page_table_check_ptes_set(mm, addr, ptep, pteval, 1); __set_pte_at(mm, addr, ptep, pteval); } diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 5700bb337987..c6242bc58a71 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1023,7 +1023,7 @@ static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp) static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) { - page_table_check_pte_set(mm, addr, ptep, pte); + page_table_check_ptes_set(mm, addr, ptep, pte, 1); set_pte(ptep, pte); } diff --git a/include/linux/page_table_check.h b/include/linux/page_table_check.h index 01e16c7696ec..ba269c7009e4 100644 --- a/include/linux/page_table_check.h +++ b/include/linux/page_table_check.h @@ -20,8 +20,8 @@ void __page_table_check_pmd_clear(struct mm_struct *mm, unsigned long addr, pmd_t pmd); void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr, pud_t pud); -void __page_table_check_pte_set(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte); +void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr); void __page_table_check_pmd_set(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd); void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr, @@ -73,14 +73,14 @@ static inline void page_table_check_pud_clear(struct mm_struct *mm, __page_table_check_pud_clear(mm, addr, pud); } -static inline void page_table_check_pte_set(struct mm_struct *mm, +static inline void page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr, pte_t *ptep, - pte_t pte) + pte_t pte, unsigned int nr) { if (static_branch_likely(&page_table_check_disabled)) return; - __page_table_check_pte_set(mm, addr, ptep, pte); + __page_table_check_ptes_set(mm, addr, ptep, pte, nr); } static inline void page_table_check_pmd_set(struct mm_struct *mm, @@ -138,9 +138,9 @@ static inline void page_table_check_pud_clear(struct mm_struct *mm, { } -static inline void page_table_check_pte_set(struct mm_struct *mm, +static inline void page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr, pte_t *ptep, - pte_t pte) + pte_t pte, unsigned int nr) { } diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 93ec7690a0d8..662b3f5d31b4 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -190,20 +190,22 @@ void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr, } EXPORT_SYMBOL(__page_table_check_pud_clear); -void __page_table_check_pte_set(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) +void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) { + unsigned int i; + if (&init_mm == mm) return; - __page_table_check_pte_clear(mm, addr, ptep_get(ptep)); + for (i = 0; i < nr; i++) + __page_table_check_pte_clear(mm, addr, ptep_get(ptep + i)); if (pte_user_accessible_page(pte)) { - page_table_check_set(mm, addr, pte_pfn(pte), - PAGE_SIZE >> PAGE_SHIFT, + page_table_check_set(mm, addr, pte_pfn(pte), nr, pte_write(pte)); } } -EXPORT_SYMBOL(__page_table_check_pte_set); +EXPORT_SYMBOL(__page_table_check_ptes_set); void __page_table_check_pmd_set(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd)