Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35882163rwd; Mon, 10 Jul 2023 14:15:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlGEhI+pJHQH6Y4ZA6uzjg7DWeYFTfWP0RsuvtEmKli5W9QqTGj5mkykpVX2JGV3j6+48wPi X-Received: by 2002:a17:902:c94c:b0:1b5:674d:2aa5 with SMTP id i12-20020a170902c94c00b001b5674d2aa5mr20903493pla.13.1689023744784; Mon, 10 Jul 2023 14:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689023744; cv=none; d=google.com; s=arc-20160816; b=Jtdj6kqMRq7XLNUFOuwyQzxmysxIJx6ERRt7G7LarFZLNNZH0cO7e1xb40muGdcQOM TIUDNOqNXXmWPT8QQarcxQ7a1ZnRqV6uhjXgk95VbKsc6VCxZl3kXjMeEk+0xwLBWRZS 0N69ZdPCMAZbU7m7cjCQxj/aNrPin8n1+agYBSaLOjLmItFvjGI5dgBk7AveuvoVeFEw IZqzCOucoW5XaMsMb0TJE8ygRbjdU/Qwopu38OPt7dKFxdizHHw6FNFIkuAMEEnsUdHt apDoOWEkNdf1ZjfwYf9mDQ6CtyCn1OgFTtaLvt6O+B87B1noNph0sMaJl3dkjRj2V3nk 2xoQ== 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=MleiOB+O8ZU6a0dknzCAyzLly2run5bVw1iBj0akiwE=; fh=wWC1SXvMoe0DNkeabIUy9Bh6clPuvng1++evCi/x+a0=; b=M/9oSy0l8tcOjDlzMeJy22IE8ITa/zQGSvWSIAzEtRmqqUmcnw8s9f9JCG8BAmV2As biUMYlUN8wsGhA/0IVbg4tpMWwFcoFAm+H6vtAxCScW3r4VFNTkQ4usvGpIxghBIBknx RSnKwq8tBWGntBgdJVeKVuxw0qjYV1gyDO1etSa2p3EaTMd5szjLGPqL1UKa1iZzbrV1 PfWDjW314O4FypqWSH1VDL914Mcs+3lsaADMqzd/oKT1M9gsCONEojygKPXekmJvk52p g7igs3wD3COiGjKXWVZnOWCB48EeXN1GrCJPpWUb240kKsn4/onliAFB4Cd00eeHWCSE gs5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hOrOl8ZD; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a170902cec900b001b9e9b21249si349171plg.649.2023.07.10.14.15.31; Mon, 10 Jul 2023 14:15:44 -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=hOrOl8ZD; 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 S232650AbjGJUqi (ORCPT + 99 others); Mon, 10 Jul 2023 16:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232752AbjGJUpE (ORCPT ); Mon, 10 Jul 2023 16:45:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73ACFE7C; Mon, 10 Jul 2023 13:43:59 -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=MleiOB+O8ZU6a0dknzCAyzLly2run5bVw1iBj0akiwE=; b=hOrOl8ZD1/O2pyYUqReAOMC00Z Ieo+CK8byYZFLkPXVV02AsvgNqzM+M+5Hs5ddbEByzw4jdlmGhQdp/hYbYc0Chtr6YA7X44zkC7cb pe1kzZ6zaYXY/tk5Mknp8cFObie3KrY7PSTLOEQQfbeyPHvptTFJwVuzbRs9qu2Ux/zoeLgExVs3H qBCGNpyIdQBTjcwA8Q/IVBK/VUN1JxCd6Hmdi8nqnJI7p7gN2OpW9rnno24Xe89fsiFv+1diNHG6N fi+zCWa8Rzk4rDRFMEoz3N6WnIjgreib+8dORaFDF9C9KDTy6dgeIOpB8RoUxuYjip9hX3iORp+Xt tu/fo7mw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoP-KM; 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 Subject: [PATCH v5 06/38] mm: Add default definition of set_ptes() Date: Mon, 10 Jul 2023 21:43:07 +0100 Message-Id: <20230710204339.3554919-7-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 Content-Transfer-Encoding: 8bit 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 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 5063b482e34f..22f48f9997d5 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -180,6 +180,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, -- 2.39.2