From patchwork Wed Mar 15 05:14:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 69958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2146176wrd; Tue, 14 Mar 2023 22:20:43 -0700 (PDT) X-Google-Smtp-Source: AK7set+yrs/vsGyi2k1ZjypED1HpK4VFddNBN3ke2hufhvZkSVhtlTlQS3pJD7czphsQIN4YtNlJ X-Received: by 2002:a17:90a:fc87:b0:23d:a2a:3ae4 with SMTP id ci7-20020a17090afc8700b0023d0a2a3ae4mr9328077pjb.44.1678857642965; Tue, 14 Mar 2023 22:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678857642; cv=none; d=google.com; s=arc-20160816; b=wr15M2W+OLTbdkBHyd+54lFKKUhwepOhFTzpTR4UW9R0IJ0GFOvFptI7aQUEclm4s8 1EhBCF2r9KS7LoqqJJafzGuisAq3E1vw4ccS4RVn4i8SAd9AOeYl/3LeCESuaQQxTZQv u0puftjVdDTW/7vmllAV2z2812i+RjxljeCpj0E+wlnAs+RH/+to2KBJ6OqQqL8+pNDA ouoB36aQfeygLmYVLw1jrm9Shj1D6xjb5v19F0fCYZXEAJTA9RZKceqRrtgYz9INB+8C Fb+F+wluSBElVKOoM3SA/p/pLadjyB3L7x11jL2L7QVbehrMcREdZyUFjneR4d0TY/HU xhlA== 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=X05vtzdRVOUEmVQt9LM7AcBEpxNUJlW1nSjcvx+k4II=; b=By3dVArOmoPn5ZcPQ2SOhSlqzf2bp5vIYGqG1O/jTD4UbTTLKMUtHnHudcWUWHMAJQ Hx9CUgXgqjekHjZsoD8x1KhVacp+zlJdbzT6JdjYMpKFts0lnBgFmTyfIx2Bq7wlvbnE M1UrBYBZCtsuS0nlw1FlsD8FaQrQjl+Un3C8KfRQiTD3pgz0yCdNN/jfMYu/RbHsWGvP ZyjWF2jWhhvWl/HEHtiMIw01Gr17TgG/qvCvpXNHBKlb9453ogpwSreqMQMFn+EKe2BO 2i+2mGFQ34SwQhWOKYEIrXSD8b2pK2CfG3NNpyhq8abLba5jLjBvT13O+/dd7clnW95/ 9SKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ZBRpDJQf; 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 jz3-20020a170903430300b0019ad7bad651si3946739plb.4.2023.03.14.22.20.28; Tue, 14 Mar 2023 22:20:42 -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=ZBRpDJQf; 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 S231264AbjCOFOz (ORCPT + 99 others); Wed, 15 Mar 2023 01:14:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjCOFOt (ORCPT ); Wed, 15 Mar 2023 01:14:49 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B629E1ACFF; Tue, 14 Mar 2023 22:14:48 -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=X05vtzdRVOUEmVQt9LM7AcBEpxNUJlW1nSjcvx+k4II=; b=ZBRpDJQfOF7dP3sJ9sUGQlY4E8 Wd8C+NXeZORB60wcJXsshX0L6WAkHB4NpK9zDfaQqAbYw0JJZV7N07uJp2EomGOpgBy9gfRTk3lg/ Ox+YILpn/XDq0gn2XR8EhTlSWztyzXp+irDBpVS7R1MHTA27ryXzwUjDzLAKIYJHTKC6TAFQ2fg4Y T6A23P2KcdW4SSUO2o3P5VaPVXw2jTWXijCa5fiXyZPotPa67xVomAze7tB4zplYixC4Od/95hGLo LRn3w1db8qtNliXIYmFz7fWIJWpYeRWP3KCroHCN4OLdSxm/wTND17EAjE+rBnFJebCCC+nEBhkqD K7FsR6Tg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pcJTK-00DYB3-SQ; Wed, 15 Mar 2023 05:14:46 +0000 From: "Matthew Wilcox (Oracle)" To: linux-arch@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Rapoport Subject: [PATCH v4 05/36] mm: Add default definition of set_ptes() Date: Wed, 15 Mar 2023 05:14:13 +0000 Message-Id: <20230315051444.3229621-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230315051444.3229621-1-willy@infradead.org> References: <20230315051444.3229621-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760409831635354791?= X-GMAIL-MSGID: =?utf-8?q?1760409831635354791?= Most architectures can just define set_pte() and PFN_PTE_SHIFT to use this definition. It's also a handy spot to document the guarantees provided by the MM. Suggested-by: Mike Rapoport (IBM) Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Mike Rapoport (IBM) --- include/linux/pgtable.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index c5a51481bbb9..a755fe94b4b4 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -172,6 +172,43 @@ static inline int pmd_young(pmd_t pmd) } #endif +#ifndef set_ptes +#ifdef PFN_PTE_SHIFT +/** + * set_ptes - Map consecutive pages to a contiguous range of addresses. + * @mm: Address space to map the pages into. + * @addr: Address to map the first page at. + * @ptep: Page table pointer for the first entry. + * @pte: Page table entry for the first page. + * @nr: Number of pages to map. + * + * May be overridden by the architecture, or the architecture can define + * set_pte() and PFN_PTE_SHIFT. + * + * Context: The caller holds the page table lock. The pages all belong + * to the same folio. The PTEs are all in the same PMD. + */ +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) +{ + page_table_check_ptes_set(mm, addr, ptep, pte, nr); + + for (;;) { + set_pte(ptep, pte); + if (--nr == 0) + break; + ptep++; + pte = __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT)); + } +} +#ifndef set_pte_at +#define set_pte_at(mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#endif +#endif +#else +#define set_pte_at(mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#endif + #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep,