From patchwork Mon Jul 10 20:43:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307629 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 18A43EB64DA for ; Mon, 10 Jul 2023 20:44:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 693418E001F; Mon, 10 Jul 2023 16:44:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 643878E001B; Mon, 10 Jul 2023 16:44:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50B638E001F; Mon, 10 Jul 2023 16:44:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 359BF8E001B for ; Mon, 10 Jul 2023 16:44:02 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D368F1A017E for ; Mon, 10 Jul 2023 20:44:01 +0000 (UTC) X-FDA: 80996879082.25.1F3C211 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 141BA140009 for ; Mon, 10 Jul 2023 20:43:59 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hOrOl8ZD; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021840; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MleiOB+O8ZU6a0dknzCAyzLly2run5bVw1iBj0akiwE=; b=BQc3hIlVtlMU7n3zPzVemGcKzMxSUjXEof34rM6/YqUyKJFabobCRgG8cxTNqeJKr2bPLI ZaLKlFwKRPggTqrrfCsJx4jsDy8YDoaLNLhhc0HetwEYEoLZtqLhx/+krncz7tkcJnBfyQ Bn+XfLN/Bmi4tnGLphmuIKJ349lfPEk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hOrOl8ZD; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021840; a=rsa-sha256; cv=none; b=qACJtaMTHQMFvtGbqXnGMHhHkgia30m+0p9PnPOONpImr6juVrz6fHpG0kV+QVU8gT50ff //iB5xgiqF3Hral4hbOi0ADZy+B+QPmlinPOnDRfno0ykFyHXgETpxPBLMZFEMS5vbDriS 8AxphdUueDPSHUwai7cRSBHSSqP755s= 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 X-Rspamd-Queue-Id: 141BA140009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bqbgwguu3dqy1ysrcf5quromanywtnwe X-HE-Tag: 1689021839-383237 X-HE-Meta: U2FsdGVkX18I7oa7gTU2ryXKNavfAtnLqfrAWDAckGmUxlvoHhT9K6qL20sz6Ue6NuWJXLHnC2m4xO/aN3LCo3xrFDxxem1qLgmd2mOEhPCO5ZbTfCp7wo2AXek6PaPKhPLF4zSPxrHCp4ILKaUXc5UXqY1Vh0KT1t7TZYf5UE5AfZ8nbkjLjsfZIfw8VGroP4fowXYJYp0BFbZwCVdrPg5AqflVdAD7L3VSHermv9LDlRlSiqcqrQ558gwSvbEQMqexGLeej8B1Z5D/6jhOxovSvH++j4grkkMms1CXMODognToatedE7q2o2p5SW6SSwOKch/Aiuypgo372LHEAthfH1RlIfj7ihU4J6RbYdFDXbg2o5HujR9A70V2MJzT2lo9aw25inhkPPHw+OJt62HLuu0XNF6682YboRDqNqCKyUkQXp+sCq5dthV50hgAiVUGcPvXc8OI7VSy66f6nUfvshuFJ4CoxMi8xlFEProcA6Ye0VzUYze7VMIdYwX96C/PzSPQe7EShy1bauGcP67gmmiXc2k1RkcHU1h6gnw6kNgjI6f8SGSBMMlgH6fIt9iJYMIy/G1+3OydjEJcRXBjIlSffOGHS40oMQVc5xF20+JLKXjlTwpxdDTrkOk2RT5IzvCiksMBQigz/aGpPg6N5VxF5aUhNCLQYcm6kDzzHUHXZsJXymYFdHP2lr1kDLyKm72GEckkJCIFKCqEM2TT2/MVajJwmhYiWRkQ1GjbjetxsoSH3JlOaJ1AIYjCjaN/HpuhfQgo9HVMczvZJBNIp55W3Pn2YTJmhPPJrHVBVOCYKoCuMpHrSTkX7WXoXcJavOZ8LxTV2nRofi6jvvia5SvHp054WIuGdIOQoScVXmJVZmFABseSFGT8kfUZPmzBt+2x8H5rWV2Sxm7FfssvT5UUqTeQEWY5ozfDQS7Pe6L2u210koLGagparkNATk7wdHvYMUAsgoKebVt +6Kp8sJm 4SAHTejnm6HLcthrerQ3q6nbwooD2cL9T6xlyrZXjGd9tsl2I5knuMoQpCaFGfaxjrqp/E8PmYUNDw0LHxS/5/lC20NTVX63IIafUB6wE9XcZdXkCylX/DmEY833bt0iAknbZu3H7yVXTf5p6MqzPpyOuWZPDSI2wsnA2g+erja1jM93xUiVL0y9mzRj6D620dtPPXE4u8yvFTlX7w/KG8vUVv5u3c8FObfcmOj4IBCVe6dCb4Qi4LE1hZs5nKIUJX5bHK+ws9N+S3TIjwC09dHZwuWBt0IXs6oQW 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: 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,