From patchwork Mon Jul 10 20:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307628 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 01E26EB64DC for ; Mon, 10 Jul 2023 20:44:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C5658E001E; Mon, 10 Jul 2023 16:43:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2273C8E001B; Mon, 10 Jul 2023 16:43:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0286A8E001E; Mon, 10 Jul 2023 16:43:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E3FDA8E001B for ; Mon, 10 Jul 2023 16:43:57 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 75D1680250 for ; Mon, 10 Jul 2023 20:43:57 +0000 (UTC) X-FDA: 80996878914.03.D2546CD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id D05A91C0015 for ; Mon, 10 Jul 2023 20:43:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=WgSSkXyo; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021835; a=rsa-sha256; cv=none; b=Plarq9s+n+XjZc/TQ6IHW2MMqPV/hCFSWb+aBZj7hWYv6a2XsLxn9ETVCNIx7Oc1kfYZ7o oc9XlSG+agAc1sm9KC/sUEa1Pe4NEKILZcXilmYB/cV+UNaR0YNGBfBO/YpFX7BqoDmu+S yy2onlJ60BHK47Em9R4pIm3cacBHl4c= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=WgSSkXyo; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021835; 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=A7RcetqmNW3btMImHl/BZfdcqRl9coUa9L9XZZv1508=; b=n+d5IB7YhxEYOdYb1p9tp3WHQdmnemKPANYANPx+t2MBQ55S8M68BnhOGjXHWOmZ609fcx ukYUsE4j2Dir9WicIp/JAjKzrbimEggrxM8d+VWLJJ0doJkRszhb01x/0sxciA9X+UDb3N /6aiY6oPJ1Nk6KED7s+2bcYYolHMM0c= 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=A7RcetqmNW3btMImHl/BZfdcqRl9coUa9L9XZZv1508=; b=WgSSkXyo6wHIO77DHamsAtL5yS QPw+3CNlMjYUWUL/cmn1npceGfaf+29pfTh1AWihDxltm3qKIFPVy5zVYjvclsnFpXKYetM/YBD+t pDQiNiNl9LpEoGB8KmBRwWmkDxMJDuHj5GlmENIK0nNp8MTh/wrwhCI2z1kpRHwF5n0P8/2o0TOIw lnX0H/DLnXPWpzmVouo1J7c0g3n5+cegiGdOuSGV97zLi9NShKpz20OELw2TBUrUBocDgTJYn7oY0 d4t9+1dGZsxpyK/6oTDLRRXJ10U4eXy3U5L8PQIq7FLntXSPG6i3HPw2LOBx3gqBtNDv1YMvvQTgb wQnxk6dA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoE-3L; 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 Subject: [PATCH v5 01/38] minmax: Add in_range() macro Date: Mon, 10 Jul 2023 21:43:02 +0100 Message-Id: <20230710204339.3554919-2-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-Server: rspam08 X-Rspamd-Queue-Id: D05A91C0015 X-Stat-Signature: ucuk9hjg3imjkbpswicyrrems48x7ky4 X-Rspam-User: X-HE-Tag: 1689021835-384370 X-HE-Meta: U2FsdGVkX18vtk9Mxe+9tTDPvnSmqwJYysqfCTQLKAaahv/D8hXLx+Hao9BGqZi0DuX5EVSDbp51G63XKkf538dS6kSHPHwQPLEr7nwqAxifKiWPAIVGWs7PNbHbT+aPO/9kRXHr+8lDq7Z+WpmW9+MZwtc6I5QKWiFqhUgBCAaz3siFZyihdhWHxvqQQSlqZybeIshIawsYHQYB88fQM1hmj+nA6+gUo+bCmuE7TWdmdD8ZiMw9T0221tsz2nkg9SjdsuNMZaw9iv2BaBIw0Nm4Rp+uICbihTIzmMP+vduIiB7fp39PpFTPuA35ono8QaF9xu8I+tk7OSYcv/t+45YdPcZHj9iOAOnejG62YafsQyDV1dTNS6CscbC7eIykK+Mr12vH01Gg+qvv2CBzDiIuD9jUAPvQH0rJXmjh3yDWAl7FCWsANpcB4FxmFQOohHbGao4uPJX9hUzh/IUmMZSCbhauNROCVxDo+AwSXxsVRh3v4suXB3kNvbgf3Vsg/IKi1nO5gXG2zWxJNDCfvenPfCNjwkjJh5C0iXrSPjS3hs54icZGZ3/B1zUh+klRAf4wlvBZ70767lsM8dVGMKLeurKq2acBptm0l1IZA5q8RJ9s3ymeQxUiCCm7+45+UFjRo1w0rVpI5PcpjapBeYMSiB3NZIw9ZZrCK8sSkzvkBEkNf2fj+Kn1Zi66o/ghEgTBLloyzWurcVCj4xLaom+WFhZv6xo7+YVgDlz3TbLK10sI7YB9N9z75/gOj/j3B0fCNFmxfWgR9MEJGW2wDlMRnNdeXFmjqK1GOIIft9H73yt8afQwet48iGuSMNl0EpeSUXp5g9DMtFObtqC77TWTJ2/1vzo8bTVk+rbzM+o5pK0LJvD/tdWohww0zGwBGSwKE0/KI0kJEp+MgiSmAkcSi0LyhUhID6G3oWIEQ59BMZgab/nhhkSHdtBPSw1FebETqLXM7eF+KEcMu9c kwSHETij VsuWvikecEhBRNuVg2r3GzJVNyRW6Gydlt/lgnbUQn89BAWhrqOOfec2JQBjH/MVCsFK4hqvOyiFILdyztAaZqGMfS8Sp6ofO2t2T2/BfexHg7pBTx3O0ObTn+hj5uSIGFrNlT09OGwnNTc65OmtwF+UvvhexVId3ILQkazZJoGf6XEz93YSSawcSouwgJq8ii3hkWRkVPDO19AQLxx9HTn6+28k9Kzjly3fy 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: Determine if a value lies within a range more efficiently (subtraction + comparison vs two comparisons and an AND). It also has useful (under some circumstances) behaviour if the range exceeds the maximum value of the type. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/minmax.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 396df1121bff..028069a1f7ef 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -158,6 +158,32 @@ */ #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) +static inline bool in_range64(u64 val, u64 start, u64 len) +{ + return (val - start) < len; +} + +static inline bool in_range32(u32 val, u32 start, u32 len) +{ + return (val - start) < len; +} + +/** + * in_range - Determine if a value lies within a range. + * @val: Value to test. + * @start: First value in range. + * @len: Number of values in range. + * + * This is more efficient than "if (start <= val && val < (start + len))". + * It also gives a different answer if @start + @len overflows the size of + * the type by a sufficient amount to encompass @val. Decide for yourself + * which behaviour you want, or prove that start + len never overflow. + * Do not blindly replace one form with the other. + */ +#define in_range(val, start, len) \ + sizeof(start) <= sizeof(u32) ? in_range32(val, start, len) : \ + in_range64(val, start, len) + /** * swap - swap values of @a and @b * @a: first value 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: 13307637 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 D5E17C00528 for ; Mon, 10 Jul 2023 20:45:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F7988E0027; Mon, 10 Jul 2023 16:44:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A71E8E001B; Mon, 10 Jul 2023 16:44:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4200D8E0027; Mon, 10 Jul 2023 16:44:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 29C828E001B for ; Mon, 10 Jul 2023 16:44:13 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 039FEC0267 for ; Mon, 10 Jul 2023 20:44:12 +0000 (UTC) X-FDA: 80996879586.20.A7C9082 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id CF54C10001C for ; Mon, 10 Jul 2023 20:44:10 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=P8TzmlbA; dmarc=none; spf=none (imf14.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=1689021851; a=rsa-sha256; cv=none; b=pYe53zGRpOOW5ajTCUQZm3EW58PnpXW+Yz41jvK97Qlc2hH/f6GaQHiNk0nysDo5AaVsJ/ yDPGG5Wwd2viEzWywze/yPUcnmM5tpthpPG9nggvZySnZ5VMg5GTFhff+4g7kR0evNdLc2 06pLOW/sBdkUPkHP8dN2HAIfUfU5Zl4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=P8TzmlbA; dmarc=none; spf=none (imf14.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=1689021851; 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=eJelxPmopSzMoFe/Y1tUG0sLrpgQ5fNaEOVpyq/ur+g=; b=a/9GOIrUEVBgnpajK2akT9p7YsY+lfcZZ4VwO/kmc2GIM+DH+6pMcTbgo/FozR4mc/CjRW q2eDOkPJDB2IOJqBtqlAVeOl6qfJHmwC/qyNsw0lSWcdwJAmDueS0XTU/ETLby1dt5rMl6 F3nsKXVkP2EYkaSgWfOiVAM0HK9H3nA= 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CF54C10001C X-Stat-Signature: 378d8npytciz1cjnzrp69w484nstt3tq X-HE-Tag: 1689021850-42375 X-HE-Meta: U2FsdGVkX18IuQCEjJgmi1frimQq9Brmam/ItKMkpoaV01QzTjQMgt2l4CnCdvAUofnqGA5+HD76TGMYoMQ338hUcZkVcdqt/C0HL+uuEFFLj61JWlUQg6Hmq1BZCxoF6yEL/GKhz1895vUZ2ACSbFB53Dzksb/AsI7obODAI+M+vSdEPuvxMoJbjD1JPUkwoXLJ5BIDCm5xgO3AYQTAfpqCKqxJNlQyF9ZCk1RU0vqmyfA7eCVeHY+dga77gn4AYjba8Z1UEW9utFPEKPcut6neFNhkFJZ4ol5yuId0rn4LEnfpcWa5DsQPd/S+AerH3VloOvP1xGvNqlwQ8necN/Q7EE34ESq2UMYPahGyCn4OxNn/k7BW/o6ls7jd+aG2Huu0QRJ5GCE2Y3b0yBP2SUA+woPjept+ie371p7+6k9f33mIRLGQKOOYjeF5QK17z7UIEP64p0Suf5V6r5c57aWebZePwYMkfkBUC3QvkpnfdHWI26srTHXW1T7yCa2ynwAfVk6j/VsQ+/NVrqGK4JSgbBcIhVcifVyv9fKZOzwY6EK6/hi3zkeUJCNjaHsXG9WuPdDGw7+a4YFKWIwpQvCfSTP9qQSDs2TpqkFw7+IKsdNipu/vQvJ1Qlvn8EM/Nyf9fMqGS76WL9tkx9y5SREzqvCtslAap4VbanOcmBe0l/h+AJqjCLTm5A3RmmWaGMMBrWTLaJ6Q7KDz/l0OI3s31M9O/rYsf+Ckmxhf7XO0reKQ1WMsa9qiKNtmHJA4q2xpGQ2Eg31FaLTqgO/uHN+b51cR0do2kV+ftAw/DfsjRRVhSVAYnq2nCPA0IUzPRHV4Ic0yKfjgts0j6NEj8Rj3cfZHg6oJbLs1/B2tlQwFBUPqKiS4pGdT0A16ksW5Irkc7PaHLuCwpjSg3440flYfnQROam0FMfeG/uS4HLKiwrFtsXmwKd/5bkKSDOQF7uJgP8Lnmijycd/wNR1 VMskrwla PE0LWG2Negf6H6u4OcAi/Hzu0S/ezgFPO/ncj4HJJ2VOhZnExmobcxwyArsitSx+80k1QABOUc25wtAneFwoRbH8SroMvwOThmBJ9ZGxgRQJY2sfQ9XCM4d1PqgpZKDhQYjOEf2JgbZDst9oBbQvF3+Cf0AAKeZRTxw1Tmqje0INB2iAduv5OzUBm1HPWqGOOOeNw7t9p6mnmQelgD6Bwv3bFJxPL0y82JW5fqBKJqIZT7WFkfAFOwUmdOR/Cj4VWC816Ytf3OVb0xvKISpUlpVlzICi0JfqyNNAWlmgDa9n4156o3FTI1QHAAP1WqJTcPJsi3u97fXyMHJJZA714z8zBdDuFjlSDcRfLZEmQQRNe9k6w3zrcaFyopdZQ7ADcaTSN1cXZuBIsjHBDaZ52OlNM/A== 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: 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) From patchwork Mon Jul 10 20:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307621 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 C922CEB64DA for ; Mon, 10 Jul 2023 20:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24D208E0019; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FAB48E0013; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAC7C8E001A; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B377F8E0017 for ; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8871D140266 for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) X-FDA: 80996878662.18.BB92C06 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id D864B20017 for ; Mon, 10 Jul 2023 20:43:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cQSu1fAY; dmarc=none; spf=none (imf13.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=1689021830; 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=YVryiR3XtoiyFiUlRMFGMnu0rhdwK+sF8PTJzbuMMJE=; b=zrTUnFfZih5o8j9/Ovc+mjMM0tsBVDdtG925Zz2XDLKEuhlVj+9TvFS/AiQcdwPPWMpiKN apFA7n7SknqrGbmXO9yzDcVscXtf7QqrH2vgEtApQaakSfB+H8A8kwkN3YZh99bc0/+2l0 WuKqptZewKGDpH/PX5qgmsRiOw++TGI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cQSu1fAY; dmarc=none; spf=none (imf13.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=1689021830; a=rsa-sha256; cv=none; b=NYgkMY5AaqxpRmihKt605G5FN2wnGLrfSbx+rTSQyRVrOFqP9yo83hKWM/VHwNteVzDfH8 OWHFJRuKEbTZeCLhBS8vQF5+f7a/qyQgH6buB4lsD5URrS7v0g65/Bul0xS6FQ0EsTzr6N 2cU80k1bYiILtifIJLgMegETrl6T5io= 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=YVryiR3XtoiyFiUlRMFGMnu0rhdwK+sF8PTJzbuMMJE=; b=cQSu1fAYjR+TiMmvRB+FLhQ9VZ dsKNLEH2eO+40qj1H1+SavyWnV5+amvjA/AhrbeWX/K4/wtT+3j2fFa69/prVbe1UZSyQaBq6jzmB H2+cJXFFy8UHtpl6N4Gch1Ixd0IFCKgOgHptrgwAHYlt6KpxiO1ldUzQP+osBB96120oB0vtwE+i/ oi078x9gLqcljH1xnPXdEDEYPQ9BN5HMqcnU+FGPZlsQZA5HCrT1PEZNqax5MGPGON1xh2zrdXya4 6Q7uEFlqiFvJJJ26lw+kK9j153qORPoU8+H+huhdweYsbKw8Ta5ZKrlR7R7ObA2g9/E/P7+T+bJLA PUYGo1AQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoI-Db; 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 , Anshuman Khandual Subject: [PATCH v5 03/38] mm: Add generic flush_icache_pages() and documentation Date: Mon, 10 Jul 2023 21:43:04 +0100 Message-Id: <20230710204339.3554919-4-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: D864B20017 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: jrzmf3rzm9arsss63cnnzydxx4bm8gos X-HE-Tag: 1689021829-125149 X-HE-Meta: U2FsdGVkX1//Of5NI/DQISJGL/NOwoLYMbK+aWikvvSEje+1/Z+voI+YfDlmq98Xz/u5Vd4OBLLsmo5EI/9/zgIxSDD48LPqT0teVsgZG/rUyiq3cq63LvYbmyyvMWAwVOf/eVGYV+eUySoba1rALOaO9TAMFRCBoPPUz6uPCAZN6Wqd44kKbBrqbjJlAsX701AUYInZ9+ElakP1nohc5MOsUzrqoJJWwNRBBe81p1Mtbgz7a7b+gTZFBbDj1mM+TKlqAXi1WnhYIYj3QXQKBri3f/srcbAZmMoT1tY3km9jTiKvWRtcMlSoHVLv37aQOASFr9c9qlNMSR2da8Tj06Jl8OSr0MNzg2FFm7VaBFD/+jLfpd6+QgsQoQdG+3ijVmCseguFeKHtE6HbqE7SFa98VE7iDN1ZdFhXlAecT/rHJZZpBWJFpfKUitMdYpZaogrJDASW/v9EWhUNJ50s5aXUdD51bmKJlaB/ILUtEYCEXXPYqQZKxh+oAarL3A0EVrIyTyPaGANrxyZyn+rLux4d7AORpER2QND1mg13SGQbGDnx2soJlUBRNxZI/mUn75kQY91xsY3GtUNRmiw2wqQJ9/53V2oO0JLA/JKR/zWdOo+yOs7IuZ5COu/dpspWFfXer+lOOL3Gd+u9Vh3PVyyWsFCIGw+vSRUBmjCl9fzBKxjQGEFVCmywBsu5frFtdmQ7sdMYGbChsjGuTqCctJQpLosk8dvUZq/EIQ3Yqy0O81AfN5FUzuvHyhmTh+l0Vphspfn47iqi9pC4g0cieRNiRf03WTZdt6S7qLEfctxds4hZzu440EYoCDztYQGJzwZVIIoW6pls4vT5rP7hG7FvFddwXEBiYoUnw7ZBRkzhadM1qSX6qyhH6murX+FZeLsKkgYLGqOF8bBWHjMBzKikYZK4IRQwSkNgDYylCrxufnVF+68dtbL/pEC0189rh4ZPHk+/y3Pw4pHClhs cAdZIdT9 E725BjyxZaQf/XbF/ZJi8frOu2jxaR7T8bn5Ov6c3tmbu65OJTuYcKjUgVi9lBlMSrjhGZ9a+BLCrSj6aa59Q9TwbUtBIoi6F2B/3YaRP7b9TJQdQM2QYd3lN/v7npM7UcuC2/pZ7/x8HJyzQdYzpAjEvbnli1VQ/lF04zsFKjqSOnS1teBxWwvEEgEh59LGcSqDEvCuixIe3ES5aMVOXcxkGSf6lB3efcpj8GR6ofkadx6RE5wFinE0zvX0pF6svKjKSVvoVWayyc36PMApcwmdryoF33EIvQjV0HvD2T95jla2aSeQkJTBI4tFZADM12gdRPvBYXmxPabL5z0j2p/rAPToaAIfksmXq 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: flush_icache_page() is deprecated but not yet removed, so add a range version of it. Change the documentation to refer to update_mmu_cache_range() instead of update_mmu_cache(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Reviewed-by: Anshuman Khandual --- Documentation/core-api/cachetlb.rst | 39 ++++++++++++++++------------- include/asm-generic/cacheflush.h | 5 ++++ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Documentation/core-api/cachetlb.rst b/Documentation/core-api/cachetlb.rst index 5c0552e78c58..b645947954fb 100644 --- a/Documentation/core-api/cachetlb.rst +++ b/Documentation/core-api/cachetlb.rst @@ -88,13 +88,17 @@ changes occur: This is used primarily during fault processing. -5) ``void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep)`` +5) ``void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, pte_t *ptep, + unsigned int nr)`` - At the end of every page fault, this routine is invoked to - tell the architecture specific code that a translation - now exists at virtual address "address" for address space - "vma->vm_mm", in the software page tables. + At the end of every page fault, this routine is invoked to tell + the architecture specific code that translations now exists + in the software page tables for address space "vma->vm_mm" + at virtual address "address" for "nr" consecutive pages. + + This routine is also invoked in various other places which pass + a NULL "vmf". A port may use this information in any way it so chooses. For example, it could use this event to pre-load TLB @@ -306,17 +310,18 @@ maps this page at its virtual address. private". The kernel guarantees that, for pagecache pages, it will clear this bit when such a page first enters the pagecache. - This allows these interfaces to be implemented much more efficiently. - It allows one to "defer" (perhaps indefinitely) the actual flush if - there are currently no user processes mapping this page. See sparc64's - flush_dcache_page and update_mmu_cache implementations for an example - of how to go about doing this. + This allows these interfaces to be implemented much more + efficiently. It allows one to "defer" (perhaps indefinitely) the + actual flush if there are currently no user processes mapping this + page. See sparc64's flush_dcache_page and update_mmu_cache_range + implementations for an example of how to go about doing this. - The idea is, first at flush_dcache_page() time, if page_file_mapping() - returns a mapping, and mapping_mapped on that mapping returns %false, - just mark the architecture private page flag bit. Later, in - update_mmu_cache(), a check is made of this flag bit, and if set the - flush is done and the flag bit is cleared. + The idea is, first at flush_dcache_page() time, if + page_file_mapping() returns a mapping, and mapping_mapped on that + mapping returns %false, just mark the architecture private page + flag bit. Later, in update_mmu_cache_range(), a check is made + of this flag bit, and if set the flush is done and the flag bit + is cleared. .. important:: @@ -369,7 +374,7 @@ maps this page at its virtual address. ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` All the functionality of flush_icache_page can be implemented in - flush_dcache_page and update_mmu_cache. In the future, the hope + flush_dcache_page and update_mmu_cache_range. In the future, the hope is to remove this interface completely. The final category of APIs is for I/O to deliberately aliased address diff --git a/include/asm-generic/cacheflush.h b/include/asm-generic/cacheflush.h index f46258d1a080..09d51a680765 100644 --- a/include/asm-generic/cacheflush.h +++ b/include/asm-generic/cacheflush.h @@ -78,6 +78,11 @@ static inline void flush_icache_range(unsigned long start, unsigned long end) #endif #ifndef flush_icache_page +static inline void flush_icache_pages(struct vm_area_struct *vma, + struct page *page, unsigned int nr) +{ +} + static inline void flush_icache_page(struct vm_area_struct *vma, struct page *page) { From patchwork Mon Jul 10 20:43:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307608 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 991A1EB64DC for ; Mon, 10 Jul 2023 20:44:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFF458E0001; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3B538E000A; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE48D8E0006; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C81FD8E0009 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A342A1A0248 for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.20.5453DFA Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 4D74118000F for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hnJ+NuJo; spf=none (imf16.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021826; 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=aGQ2GHttWzJ+Nk3XqgE1qMHvrVsWPVFdkiJHip5axuY=; b=Lv3fTIl9/E8fwbPZ0BN/rUsqHomd9w9PqCze6PC2tbZzk0tz2zQlH6nhx4KJmdm/h6mtpT y/IYtVCMp2uzE9XXaQPxB0LzJ8+7j0MbX3upwFwsk2m7oYOGuozuz/aG8OwPbmhbrDg148 ZI/wmbuhoY3DA+j+GC5XWesa7xdavtY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021826; a=rsa-sha256; cv=none; b=JceugOt6T5xtYQSXMoS9sZTn/YHtZ1l+hObT4xfyzn1KLt41K4u1j62CzHaeCPzxce/y+Q ZgMHBPs1/7ZrJMplEl4//pH/4Rr8bFdzC6SEd4tfKN/Wz5kkzay/jGClvLYuke16u7im26 N0OHUGw87OQ4DPmvqCahAwoy61MHE0c= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hnJ+NuJo; spf=none (imf16.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=aGQ2GHttWzJ+Nk3XqgE1qMHvrVsWPVFdkiJHip5axuY=; b=hnJ+NuJoHrGWnFQIHj5mwikc3Y f+ynvhq+4B/aEwy8FCPsgFshOQWVrWerLCxpuQBbeUnTyyz1X0U1Nqmo5shKPFaE2oMcX+P2NwLlm Hx6TYojYAi/XeM3hRmgQle7OUe0P4VkJ/Tt345eZQ34NwKAAmjbTCS8gD+17k8LCVxA5Uw2bKNxGK 2pBd5RYRhgtJ8EnVR9p6jVnQj2YQK6aJ3WeDQX+ZdDJGeDEqNezcYGk0XiuPM9EbIuKOpAhQmmDC0 VsWF9mJJKPpNAkiMNKSDiBc99gmwms10qIVtaqz0HiRd1zfD+6eV29vnvCGa1faKf7Aum+Nodg8wh gzQnfLWQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoL-Fj; 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 , Anshuman Khandual Subject: [PATCH v5 04/38] mm: Add folio_flush_mapping() Date: Mon, 10 Jul 2023 21:43:05 +0100 Message-Id: <20230710204339.3554919-5-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: 4D74118000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7n5s3za9cinz6qpiufjwnwnmkpb7y3cz X-HE-Tag: 1689021825-824120 X-HE-Meta: U2FsdGVkX19yVVXJwCHfLX8VIb+N/2sXNT7Znq6Uh32PL0yG4DLeiqqu7EnuynHGWcm3TJZsRZqWLA7koR0D9vgR5DywOdQCs0LtcId+W+v5f2SZoTpxyDikyeVWOaDuxY+tgICkNh+UD+0+59uvIO/oib8ZyCREX2qaU9TVN6JnZHu3Ik07uUEpBdcq5ADm3RkUvraeDdmhWfhK2AE8Vrtw5EMp+VV6qNPNKZkFHGMkINcqZkg/k49EvseJg57Yps0/h9B79EP3xQvD4WDj84sXbAMcLnbWTTnjgfTwFXlyZJxD/RaX0BLgxbW/9UYR4BQpnqULPzzw0GDj/shMmM59tYHFAAKJhyRG5t3ep1nBjwg0bwF4LoSSfhrRKRclordincSuGzgNBIP1i9d78HrqrEP+jh3ggb4iNA2gJYC18b78lx1AnjkQfwAvKp3723TMh6IKHLM8bWWh+7uBCyUy8s0doVpvXTKvZPK8elgrABmwRRm5CDWlsgpdu2bIADYF8gGUKbCW6UcfNIqkonM2mFEEG/1eIbOBYqkca8Zsi4CVp3TfNk+YwTK8ymnInmewCKmusoUxipbkbo8ub1i/QtWfxXRHoBhtlmIgs1+yFmYCN+YDzZwamTrjc06lw6tqjVgMMVEvR811txbdsm4hRt2QmH5WGZ6ZtcUkvGPBiuqQzIQRyiPnIUpLFLD5MoIorlIS3p377icwIAifnO7gboii1kxL9RBBvfWvFxXzgdisdjmLmddmnjXy93zWMGl8MuSSh+rnPktNDXeXg8Pa+YO2Sh6BGloDGnlTg2af7MZt8ZjeYQ8s80IluVamnxD2bCC1DmEk9m5qCQ6HPMrEzUXgKu4eb8HGql+KV5qpCPzaKOmX5j+IrfEckgRqu1oKnymFHJCRIHW7duHZH/Gi4rTbNUYw7StfNlW2EyUDo1ZifA73q41es8XsHXnOVO2WxVsJ8emTsgEn3av xNwFxVuY qnGBtjzbzBQ5+Crz0eE9yfA63PtiOT4u4sls3pFXxELfMFPV9MbHQKymeTGElnihmdRTM5bNZB2GnsmfH7k71wUHh+1ANm3mAWRwD1G2LRtsQqS7r7+c9IkTHbLyWfTvvwv1/MxlFnjCd+tG6cBLuR6567opzh9pKivQXBQYn9ZzYA/D5oKq0LObgK2siPj+6xMezvvU0jEPFGX5T7zzwP1WzsQ4UfQTwwsizAfOqQBdfbq1P3ONld8RD42DsdhhevE3Ep0WjEayG/ZAeC1TjdfIjEhD+V/KIGahEhZl3JRaQFgz+YZcxKKXNGOrRnpKCc6JCc5A3fAv0s77AAE+SqJNAWA== 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: This is the folio equivalent of page_mapping_file(), but rename it to make it clear that it's very different from page_file_mapping(). Theoretically, there's nothing flush-only about it, but there are no other users today, and I doubt there will be; it's almost always more useful to know the swapfile's mapping or the swapcache's mapping. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Reviewed-by: Anshuman Khandual --- include/linux/pagemap.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 69b99b61ed72..794e4e55dc38 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -389,6 +389,26 @@ static inline struct address_space *folio_file_mapping(struct folio *folio) return folio->mapping; } +/** + * folio_flush_mapping - Find the file mapping this folio belongs to. + * @folio: The folio. + * + * For folios which are in the page cache, return the mapping that this + * page belongs to. Anonymous folios return NULL, even if they're in + * the swap cache. Other kinds of folio also return NULL. + * + * This is ONLY used by architecture cache flushing code. If you aren't + * writing cache flushing code, you want either folio_mapping() or + * folio_file_mapping(). + */ +static inline struct address_space *folio_flush_mapping(struct folio *folio) +{ + if (unlikely(folio_test_swapcache(folio))) + return NULL; + + return folio_mapping(folio); +} + static inline struct address_space *page_file_mapping(struct page *page) { return folio_file_mapping(page_folio(page)); @@ -399,11 +419,7 @@ static inline struct address_space *page_file_mapping(struct page *page) */ static inline struct address_space *page_mapping_file(struct page *page) { - struct folio *folio = page_folio(page); - - if (unlikely(folio_test_swapcache(folio))) - return NULL; - return folio_mapping(folio); + return folio_flush_mapping(page_folio(page)); } /** From patchwork Mon Jul 10 20:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307634 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 8EB73EB64DC for ; Mon, 10 Jul 2023 20:44:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50F458E0024; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 496168E001B; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 336A48E0024; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 24B038E001B for ; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F38F51C7CEC for ; Mon, 10 Jul 2023 20:44:08 +0000 (UTC) X-FDA: 80996879376.24.F0D4D1B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id D789D10000F for ; Mon, 10 Jul 2023 20:44:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ppPLHwkc; dmarc=none; spf=none (imf14.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=1689021847; a=rsa-sha256; cv=none; b=nQVqaJnm0sQIQQI3kWX40d7gIAaFBknQJuNlMXAkz53XU85uuJ6YwPmB92fI3LJcSkeqYT eSEJORGMoRZzu+8BOpvfZG+rT4u8rCRJB60ZFcjrJD1A79hDwNql1xprPLpEBE+3XxbFF1 fnUEeVRdKvcX95C7WUU3kajdrxepsL8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ppPLHwkc; dmarc=none; spf=none (imf14.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=1689021847; 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=ynZRvvhfxJbLcCtmfVp5saL88qGUbGsuSyWQAo7RARA=; b=uchZBLAzCrAugf/4bKWACLi+Tszvfbkg/WZ8dHbLKNFgttah/qC5x2zhL+o8r3Z/LU/aqB M2Utcv4YdK3dpDn+v1SDy1Fv6LmFJoCwEGXiaamI9baDYih8/Tqkn5j76f5gkUh8Gt7bpS 9p98OG0IEgDHZpJeWJsTR/lSXwscjW0= 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=ynZRvvhfxJbLcCtmfVp5saL88qGUbGsuSyWQAo7RARA=; b=ppPLHwkc8PkE5KTNl7AKQdgBW4 c4iELF8cC+JKAEjLxJ+VvwuPt8I1Bkn/wUOZt/lGDQP7PmZZnQhjzSldS6l+jFtPadqFz6Fvj/yYo CA0CNCuv0zIxgNykGwxtwMyEh08s8iMfnFLwJTefF5Ke2lQ7ewfGPUSt5V0bbquZ7bvpaM6DXkjBd hBCicFnOyUrKcbJBMtKHYfXsI3f6jNl9lSF7XUDik389BDsG8ZBHYld/8T3ZmWJI+PMvsxUTZLRB3 1MOctuRbVKfNuo9Jtc964irIvPwm5z5eL5eBbWoSRYGK3ADd8udnc98e94on+6qKF02DI0aV3K4yr mB2ZZIxA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoN-Hy; 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 , Anshuman Khandual Subject: [PATCH v5 05/38] mm: Remove ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO Date: Mon, 10 Jul 2023 21:43:06 +0100 Message-Id: <20230710204339.3554919-6-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D789D10000F X-Stat-Signature: n5grqrhwywagebttfewr1wthpyzsphq1 X-HE-Tag: 1689021846-643138 X-HE-Meta: U2FsdGVkX1+rMaFcm5Ddie5W9fMzYY1CJ7kSqPobP8GVC0Ylm9fEjl4mmPxjHI93jea+Gmhu9N5qA3pSfiISWKM1D9A0Vvx2B3tkC97qBqQPeaj4Hzli0wQN8suUq7Rp5uhBrn9xS0JKOG5lhXTU+qDxE/qzEpQ6J/YVg35hCqlx0JsDUF6xNwLuh4/jhZQGz0fIEjstOTwW9iM5ZnDgURpezZSREHMSjr/4PwX2BLTRw5mYGzN8strug/pbxczmJr4vDg7Yb2rTqHVFFkvVvhHqE83C7PI9riUZHHCNIROnbJTWiLwwOmEK230jLTZcoxmJ/f+T3lqhTld7GnwdStIIKLauBAvp6X9rXPQDThMO+KdfA6FS+Gju/wDaA+QY4F3KCrC4y8Hxkx0DA+fmG2nIxR20b2ElbWlX/zGwJq3SGfHriMxDhDCLVjn2Jfp0UFxWPWI0uj+dWfmo+6xUbXWmDEyuoqZKe5G2jXJZGxTqdQu1aQ83gsuKO4w6Px7F4G5ogiqHoQD8C+26Z9fvB1MfNO8p+6K/9Ngcw6wM8zNEZrSWSXzrZASk6GLv8MqE0AStWyRRVAXBYv3rhJfALMEvfWPAggqdfIf3K8G7f598LsItq8ctxM3paUuWbSw73MkfV+sDo6w+s7BhPtWz+ZMQgJvg0cszYG72kYgAJEwYOWaId5SAnQQJ02aMp0FUeA50OLGYmnpZjTH+lxjotGLdfxLkRKQgAuvMv3ARdGdTMnY8K4jTL/fLKgVUt4QVf72m5Qbb8NR0bg2kMDeLnJJmLJ66qHtOsjt5bfCNMzwoKgpuEgTTSzJjg4nQiCLcBd8oYrIBhlkHC4IqBcvMY9GudNV29LHwv2ks4inxJh17iBFp63RLAPQaA1WfKmOzkevNVpXXHtNMZBmwupjVTThRJzMQcTyzcFgt5EF4Kav1mabv8k3mjF455cER9Wxh9NFISXEtiDnPAG2Nmge VB5ks3Sd A9jpt3IeZlneIrkKV99qr+GckvPD0F87DKA0O6muQhtGpjfzpCPxFtzLwDKxxahTknGAqcZ9X+Kv1rrQeNzOZnThImKNBau/m8DkwYodxKNUmGsP8aFpHbdRQqekn/xdvOaEYyoWtauXANKw7xxA8JAt6BdjO2i7Fx4Jng6RQqUaLWNsApMYcEmsJnnSbJ5lDyg+1DHQm2qGYAkH34kF04Wy+tBhhVdnNZKlj8zRpe6tPlIIOroDGaVe1SGfOt2E2Aa1pIbZ/n3FygDdkvq5GttcgkKOuKapecRzWzyYe9+v+3HKDn8nqq02lDDFIu/+35WevBnj9gSCAnjavq6j7vtQUwxXH4ujtE897 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: Current best practice is to reuse the name of the function as a define to indicate that the function is implemented by the architecture. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Reviewed-by: Anshuman Khandual --- Documentation/core-api/cachetlb.rst | 24 +++++++++--------------- include/linux/cacheflush.h | 4 ++-- mm/util.c | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Documentation/core-api/cachetlb.rst b/Documentation/core-api/cachetlb.rst index b645947954fb..889fc84ccd1b 100644 --- a/Documentation/core-api/cachetlb.rst +++ b/Documentation/core-api/cachetlb.rst @@ -273,7 +273,7 @@ maps this page at its virtual address. If D-cache aliasing is not an issue, these two routines may simply call memcpy/memset directly and do nothing more. - ``void flush_dcache_page(struct page *page)`` + ``void flush_dcache_folio(struct folio *folio)`` This routines must be called when: @@ -281,7 +281,7 @@ maps this page at its virtual address. and / or in high memory b) the kernel is about to read from a page cache page and user space shared/writable mappings of this page potentially exist. Note - that {get,pin}_user_pages{_fast} already call flush_dcache_page + that {get,pin}_user_pages{_fast} already call flush_dcache_folio on any page found in the user address space and thus driver code rarely needs to take this into account. @@ -295,7 +295,7 @@ maps this page at its virtual address. The phrase "kernel writes to a page cache page" means, specifically, that the kernel executes store instructions that dirty data in that - page at the page->virtual mapping of that page. It is important to + page at the kernel virtual mapping of that page. It is important to flush here to handle D-cache aliasing, to make sure these kernel stores are visible to user space mappings of that page. @@ -306,18 +306,18 @@ maps this page at its virtual address. If D-cache aliasing is not an issue, this routine may simply be defined as a nop on that architecture. - There is a bit set aside in page->flags (PG_arch_1) as "architecture + There is a bit set aside in folio->flags (PG_arch_1) as "architecture private". The kernel guarantees that, for pagecache pages, it will clear this bit when such a page first enters the pagecache. This allows these interfaces to be implemented much more efficiently. It allows one to "defer" (perhaps indefinitely) the actual flush if there are currently no user processes mapping this - page. See sparc64's flush_dcache_page and update_mmu_cache_range + page. See sparc64's flush_dcache_folio and update_mmu_cache_range implementations for an example of how to go about doing this. - The idea is, first at flush_dcache_page() time, if - page_file_mapping() returns a mapping, and mapping_mapped on that + The idea is, first at flush_dcache_folio() time, if + folio_flush_mapping() returns a mapping, and mapping_mapped() on that mapping returns %false, just mark the architecture private page flag bit. Later, in update_mmu_cache_range(), a check is made of this flag bit, and if set the flush is done and the flag bit @@ -331,12 +331,6 @@ maps this page at its virtual address. dirty. Again, see sparc64 for examples of how to deal with this. - ``void flush_dcache_folio(struct folio *folio)`` - This function is called under the same circumstances as - flush_dcache_page(). It allows the architecture to - optimise for flushing the entire folio of pages instead - of flushing one page at a time. - ``void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long user_vaddr, void *dst, void *src, int len)`` ``void copy_from_user_page(struct vm_area_struct *vma, struct page *page, @@ -357,7 +351,7 @@ maps this page at its virtual address. When the kernel needs to access the contents of an anonymous page, it calls this function (currently only - get_user_pages()). Note: flush_dcache_page() deliberately + get_user_pages()). Note: flush_dcache_folio() deliberately doesn't work for an anonymous page. The default implementation is a nop (and should remain so for all coherent architectures). For incoherent architectures, it should flush @@ -374,7 +368,7 @@ maps this page at its virtual address. ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` All the functionality of flush_icache_page can be implemented in - flush_dcache_page and update_mmu_cache_range. In the future, the hope + flush_dcache_folio and update_mmu_cache_range. In the future, the hope is to remove this interface completely. The final category of APIs is for I/O to deliberately aliased address diff --git a/include/linux/cacheflush.h b/include/linux/cacheflush.h index a6189d21f2ba..82136f3fcf54 100644 --- a/include/linux/cacheflush.h +++ b/include/linux/cacheflush.h @@ -7,14 +7,14 @@ struct folio; #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE -#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO +#ifndef flush_dcache_folio void flush_dcache_folio(struct folio *folio); #endif #else static inline void flush_dcache_folio(struct folio *folio) { } -#define ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO 0 +#define flush_dcache_folio flush_dcache_folio #endif /* ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE */ #endif /* _LINUX_CACHEFLUSH_H */ diff --git a/mm/util.c b/mm/util.c index 5e9305189c3f..cde229b05eb3 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1119,7 +1119,7 @@ void page_offline_end(void) } EXPORT_SYMBOL(page_offline_end); -#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO +#ifndef flush_dcache_folio void flush_dcache_folio(struct folio *folio) { long i, nr = folio_nr_pages(folio); 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, From patchwork Mon Jul 10 20:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307601 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 D77BDC001B0 for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 347848E0002; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29A138E0003; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1E9E8E0002; Mon, 10 Jul 2023 16:43:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DD14F8D0002 for ; Mon, 10 Jul 2023 16:43:46 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AB66714027E for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) X-FDA: 80996878452.27.18E7BBD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id F3FC9A000D for ; Mon, 10 Jul 2023 20:43:44 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="E8a7/eIM"; dmarc=none; spf=none (imf15.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=1689021825; a=rsa-sha256; cv=none; b=ompLz8w2i/6UaIvUFk8sILPpFwVzQ1doCjE2rwz2/csrGvjm5OKKjyjCJIF3xfLe+6Ta/f fCR76AnuX6Kn3P2rxjuQMENGE/l/eGwgNlHS+4AV2cHFReHvEgxnodAJU3KjsxCMDNixwY pf23ZS/xag0JMEJAkzn6B29OICROOx4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="E8a7/eIM"; dmarc=none; spf=none (imf15.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=1689021825; 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=NROTlL6IHKcHVr5IJzwMhJiAK5XHIL/ixXU1imRUdQ4=; b=79dRCkB/yUiBogKaynqzajC8xooIv2yddTozMWwTxNjQwysGDHjCS5YMkpUA1EvhIfloMQ yHHC4nNpBojV9vN9tXwQjNDHDo9fZseq+4RGgx5YrKjU6ermUqPHDM6XsB6uYNW3EJDDh/ tkwfyjRTawliGrYizXT+zqsw2J4S1ug= 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=NROTlL6IHKcHVr5IJzwMhJiAK5XHIL/ixXU1imRUdQ4=; b=E8a7/eIMgmOjsWrBHysNQXo1Ni ggvEuhfIneD9rq41HR/VUHUxXTJXr/lSG839FvzdGonh++4SxvKlk43T6taeXoogmOYrwjQbJwbnH E+5D6BjuHj4ufh0T8ojX9/RPH2n4+tDnWdrTf2UwwdZGxe/V04uHxgGLik7rPhCZstHGKAt7jbdQX w49Chx2oydHYYjGyyXLvrCsLKhhb8ZMySs9Dnt44+D1TB7jlCCGiLYpHM78Ol1RFiA1yIwML3s9JR 6bhbxgAAtiAyQST7teIYKdsEOFVgso9+5RoiI7smGYFo9KanW2IL36S7lXKxlSJFLpuzp1Kfjr1ip 7p9jiTQw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjR-00EuoR-Md; 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 , Richard Henderson , Ivan Kokshaysky , Matt Turner , linux-alpha@vger.kernel.org Subject: [PATCH v5 07/38] alpha: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:08 +0100 Message-Id: <20230710204339.3554919-8-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F3FC9A000D X-Stat-Signature: 1insdpj3mmedmsaeqwkcwnd1nkdayk7o X-HE-Tag: 1689021824-740262 X-HE-Meta: U2FsdGVkX1+nkTIHSP8Lf9RYmKrsBM+54IVzkDOkx7rto3J8h90akp1oOjHbRJUxSXClCQGjtEge340MaJ/u6mRttz91oIpT9QdF8Z2hvD5MpPX0+ZdK0o1dXJaWAQqJiCJonqk+mru8XpqzVqjdev5J3SdnQ5a6awrrdZFpIU0otyMQjU63/VPtBHqForZXoIDwTBQ4U9byR9fiG08sv4os/YtesTMWh/8/VoNqAif51oAITxkX5rhIH9uLwSOsJ7fhiXeMq2QJGBTTRB4QhGd9En7ia6dFPFRhnbjrjpFAkIPYi33uPQQzo3QZPinky0coJOw2TO9Jku5wPwf5sZ41au2eGntX5smoKIzZ5O6CAeDT1kUP4jEhNUw0NEcVV0ihp8YKQImfNpiJW0QaRD249paxM+SZe9jKyRtJ3nD+H+qAIWqUNO3wRozWT0/uFD2x6Vi7MN4kooqDynsB4FZ2c3RKQR8eRAZX2rMhe4TkSSwefbzy9elaBLKGY7tksq1DAz+55vAA28FJs/uozJswpGRsRqMzYeQL98bhbXd8vugSQeDGY1RiPVz35g7hSV2964AirsbgmxqFMtnWi3lY4FptYnEQUy3GLNjxJpRPIQqmcRw4cREvszxSCNfJCqUgDmDDH+UDrco1ZAZbu7KxPaGyxzOmBeLJ1qXEyr/vY3rhSW5LK14kJb+byLc0rSwq2YwRBldFQOR/MU51Eijau380OKbSxjbZEKoFK9NcVn2hjO7PIycI50Sr2ptbfIsj2CDVdottaTUhfcKe8kf7Dncm5K+eDpiKSYpQzgHKZQJBevUDx2QWdc9yqV6VZ8T69UIbSD9le1aJXjEazAMBy7nTbW0R1tDC1reHDPVrbu41RKA6CgNejTlEgyiuKXG3qdGKHdscwo4JCbfd83hu1Hq/R4tfy8fupZdeZ0ReLWgQE44XNgQs0p8oULE9ooQoy45gMWWMAMYGv96 mcaeZ3SE H4UeKEcfqARRd8vvBompFPXrcHUa6nyhodrwkiI4JMXIoRJwfwouY9Zf8xnPj4VV2UjOC92Xdj7DmcLrjFXVC4I6Gv4AqbjgMACE0JYROB3pIuQBSj5rqXeHOJdmQ5YGiiL3E0zpNwCrmAGp99KoDwlXsXCBFHRUDAyc2mBidvmjz2TCuHJ2GrqdlgGf0DdFXQyOzhkDGd81MkiPbFMz4dTfAKnBGDNg6LfTwYDBQbA30sBUi74XkNGAta+u3WjZWYhUt3rUVMLBu+tc5JnaOeCUHn2BoqNLPCUZBbxIu4XlN6vmBSKZ34zGhZxmq+uLGZvzTvvcRHnGA0M5rYeNnPuni0ckG07PoEwv0h1p08g6xBqor5maMpyebkrpWHWTIy0bD 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: Add PFN_PTE_SHIFT, update_mmu_cache_range() and flush_icache_pages(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: linux-alpha@vger.kernel.org --- arch/alpha/include/asm/cacheflush.h | 10 ++++++++++ arch/alpha/include/asm/pgtable.h | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/alpha/include/asm/cacheflush.h b/arch/alpha/include/asm/cacheflush.h index 9945ff483eaf..3956460e69e2 100644 --- a/arch/alpha/include/asm/cacheflush.h +++ b/arch/alpha/include/asm/cacheflush.h @@ -57,6 +57,16 @@ extern void flush_icache_user_page(struct vm_area_struct *vma, #define flush_icache_page(vma, page) \ flush_icache_user_page((vma), (page), 0, 0) +/* + * Both implementations of flush_icache_user_page flush the entire + * address space, so one call, no matter how many pages. + */ +static inline void flush_icache_pages(struct vm_area_struct *vma, + struct page *page, unsigned int nr) +{ + flush_icache_user_page(vma, page, 0, 0); +} + #include #endif /* _ALPHA_CACHEFLUSH_H */ diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h index ba43cb841d19..747b5f706c47 100644 --- a/arch/alpha/include/asm/pgtable.h +++ b/arch/alpha/include/asm/pgtable.h @@ -26,7 +26,6 @@ struct vm_area_struct; * hook is made available. */ #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval)) -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) /* PMD_SHIFT determines the size of the area a second-level page table can map */ #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3)) @@ -189,7 +188,8 @@ extern unsigned long __zero_page(void); * and a page entry and page directory to the page they refer to. */ #define page_to_pa(page) (page_to_pfn(page) << PAGE_SHIFT) -#define pte_pfn(pte) (pte_val(pte) >> 32) +#define PFN_PTE_SHIFT 32 +#define pte_pfn(pte) (pte_val(pte) >> PFN_PTE_SHIFT) #define pte_page(pte) pfn_to_page(pte_pfn(pte)) #define mk_pte(page, pgprot) \ @@ -303,6 +303,12 @@ extern inline void update_mmu_cache(struct vm_area_struct * vma, { } +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) +{ +} + /* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that * are !pte_none() && !pte_present(). From patchwork Mon Jul 10 20:43:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307604 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 2D94DC001DF for ; Mon, 10 Jul 2023 20:43:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE8568E0009; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6EEF8E0001; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94FF88E0006; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5073C8E0006 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1C18514027E for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.22.450B899 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id A3B7980004 for ; Mon, 10 Jul 2023 20:43:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=H7ttB9il; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021825; 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=7+64kl8AtPPKnIA0PMupGgsqWzV9xsZVv5WpgpJ16tY=; b=KvuM3XrXfJSFkMYTFAiFCppcB7g6DQSahYDgMbljp9BktDcwtyQzwgECH2CLlHQKOQRFFY eHAve3z+CIJVrP9zZ4oeyzZagngRwpAgl3znna17i5KXjVulphQ57XgZM+PAua3aR2ZiYT n5HbiagqC5/qo/109msnxvC/kA5dKRI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021825; a=rsa-sha256; cv=none; b=isF4CtcbLUMcQXwDggKJi30l7zD3h7fd+RuV0Xmy9QjPRNxxfA4URRTCHGfiwc/XxEjqqh dVAQvjYl0pB1p+Px5ehvgGtXbdmLSxoEqw9LSNKxX2pltDM1mB2D6ZJxo7mkRvhf3bmR1Z cxaVXebAp7FxS61o56siE9NIvVqSNP8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=H7ttB9il; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=7+64kl8AtPPKnIA0PMupGgsqWzV9xsZVv5WpgpJ16tY=; b=H7ttB9ilSWCZ8hi9ISL9t+VLpn IbMF8/ekgcgFarpPdL+gTuB6TrDPdZstwSQXntyb68j3d0lD9k7WUKootTOe8buILYOiN2hD2HQ3k BG5Fo+xpj2VP5Cgb8r9DYnzmX0E6moXGMonP5kvQwgw+gVBp2EthW4SNZ+WHc0xwoj3IWve6ozdDe 79lTJj4tVIFnipXaGEFXlCE/27hJk6TyuHvo8Yc6gpraeUVkRmrKCN1vnhIPR4S/5T9Pun57NLqpV U8wiT1DLjjTBG1xFABEXXxjp9xzG51LnVJJpLd81Y5NgVi9OY2f29oWffPhZguDSqXCSb+7y0ZP3P 1B5aWK+A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Euoc-18; Mon, 10 Jul 2023 20:43:42 +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 , Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [PATCH v5 08/38] arc: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:09 +0100 Message-Id: <20230710204339.3554919-9-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: A3B7980004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qnj9mqarhkt145rhmscqktuo6pcu6ujb X-HE-Tag: 1689021824-929521 X-HE-Meta: U2FsdGVkX19HCjZgz25fijZPegRMVMuAqZ4XDJDj6xbTTNw0WUnGAbKuJVa0B/1R4vP1+lrnkeitpjekLLsh1H/UEBmm8RPAgykehDjmhpoROF9eazuYfS57U7lBa6ElC/cqKvGvcm3/Tk0joAtKRL3w4LUGJjdpvG2T2BAOXJuZTupgCozfU0+ppKgJsMYoJNR4iSxaAMLgyv3eTSv4LaRrekzUAFH3kgfEeqZduuDp1oIMvjg1KPJJQ2Ue7QN9KkfgXo9nmJyHOs8R+S19m5Eir/3ynskErgRUF5Ddapt4FGcpeQWF4zgKihtWa2pBrTmCiRkXaexmxvh4sZuO+v9I2SVrbe+PvYKHzLsNyvI6KyN7dhhUXni3HAFUAKiHd5+p5/vLf51XLNZ+GBm6X2MNAloEWplylJARS40EDLTdr9FeXCQBg8FF4BX4ihh/eI4a4kSAfi3TfC0IItbU+Od+fm5+WqdHgsGrShs7Hc9hzTDzriFO3my3K6poHNdv0No5/oOEGhsq3G69FfEXEggWsg9JlK5c8pRSgP4pLj9cMICQiWSQeQiHfwprLoSUW17Gr7Lc2gldjkc6mqZ3oSpNqQ+2cQrgw7F05/BRYfMgJ+YulBABr0cqYCNVCqr32Kz9pbYENrbcH6ILPauWIUzNKjYDfxFCj7gZh0T4aFzZC4DVhh3ZfSYiG/vPxTWjD81ZU01INup4di19YOWaGOSTKZhtgnh6qPYuf36wK7n4ngry4ghBRNBKUPgPy6vTPuX5ZjVkhTkT/3ZXUFihmWT33uUojVb9BMFIppssT9f0H+7OsXHT1/yI9AoAmMcfrFrm1e0mizfVOGmu3O2tIZF1SQRQGdjhSzHscSDG4RMIr2h8Gt7lUyNunOZh2bQ4da89nMuPdiUJU8DuPOfCRKzdvfFZ2DOjWR8LOW7sHh5tDdvCxybTfJ9fI3gjUEHqnj1NeAJiLaUYlxLTkpZ d3GuMCRV GFIm793b8crcwOAiw+g6LAermny1SazTVX0Ik1cuD1rMbdqzzhCbbeazCvgA4NOfrb9q5RMu/JqrC1nOwxmYxJue1XSwwkmy2JzvmbHQLISJAbz0xhtl0WVawdXQ7uQRwhZ4nfYn633OMHttp4purf8fcBcfI8bI0E8k/CpYRWHAfQ+3dhNDjGC8tdtr8ucJhNtfeqJ4MvpmBVf218TGiVkudK1P/w8e5Bti9l6pekcteX5QGp+kkW+mfzw== 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: Add PFN_PTE_SHIFT, update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_dc_clean flag from being per-page to per-folio (which means it cannot always be set as we don't know that all pages in this folio were cleaned). Enhance the internal flush routines to take the number of pages to flush. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Vineet Gupta Cc: linux-snps-arc@lists.infradead.org --- arch/arc/include/asm/cacheflush.h | 7 ++- arch/arc/include/asm/pgtable-bits-arcv2.h | 12 ++--- arch/arc/include/asm/pgtable-levels.h | 1 + arch/arc/mm/cache.c | 61 ++++++++++++++--------- arch/arc/mm/tlb.c | 18 ++++--- 5 files changed, 59 insertions(+), 40 deletions(-) diff --git a/arch/arc/include/asm/cacheflush.h b/arch/arc/include/asm/cacheflush.h index e201b4b1655a..04f65f588510 100644 --- a/arch/arc/include/asm/cacheflush.h +++ b/arch/arc/include/asm/cacheflush.h @@ -25,17 +25,20 @@ * in update_mmu_cache() */ #define flush_icache_page(vma, page) +#define flush_icache_pages(vma, page, nr) void flush_cache_all(void); void flush_icache_range(unsigned long kstart, unsigned long kend); void __sync_icache_dcache(phys_addr_t paddr, unsigned long vaddr, int len); -void __inv_icache_page(phys_addr_t paddr, unsigned long vaddr); -void __flush_dcache_page(phys_addr_t paddr, unsigned long vaddr); +void __inv_icache_pages(phys_addr_t paddr, unsigned long vaddr, unsigned nr); +void __flush_dcache_pages(phys_addr_t paddr, unsigned long vaddr, unsigned nr); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 void flush_dcache_page(struct page *page); +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio void dma_cache_wback_inv(phys_addr_t start, unsigned long sz); void dma_cache_inv(phys_addr_t start, unsigned long sz); diff --git a/arch/arc/include/asm/pgtable-bits-arcv2.h b/arch/arc/include/asm/pgtable-bits-arcv2.h index 6e9f8ca6d6a1..ee78ab30958d 100644 --- a/arch/arc/include/asm/pgtable-bits-arcv2.h +++ b/arch/arc/include/asm/pgtable-bits-arcv2.h @@ -100,14 +100,12 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)); } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval) -{ - set_pte(ptep, pteval); -} +struct vm_fault; +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr); -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, - pte_t *ptep); +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) /* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that diff --git a/arch/arc/include/asm/pgtable-levels.h b/arch/arc/include/asm/pgtable-levels.h index ef68758b69f7..fc417c75c24d 100644 --- a/arch/arc/include/asm/pgtable-levels.h +++ b/arch/arc/include/asm/pgtable-levels.h @@ -169,6 +169,7 @@ #define pte_ERROR(e) \ pr_crit("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pte_none(x) (!pte_val(x)) #define pte_present(x) (pte_val(x) & _PAGE_PRESENT) #define pte_clear(mm,addr,ptep) set_pte_at(mm, addr, ptep, __pte(0)) diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c index 55c6de138eae..3c16ee942a5c 100644 --- a/arch/arc/mm/cache.c +++ b/arch/arc/mm/cache.c @@ -752,17 +752,17 @@ static inline void arc_slc_enable(void) * There's a corollary case, where kernel READs from a userspace mapped page. * If the U-mapping is not congruent to K-mapping, former needs flushing. */ -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { struct address_space *mapping; if (!cache_is_vipt_aliasing()) { - clear_bit(PG_dc_clean, &page->flags); + clear_bit(PG_dc_clean, &folio->flags); return; } /* don't handle anon pages here */ - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); if (!mapping) return; @@ -771,17 +771,27 @@ void flush_dcache_page(struct page *page) * Make a note that K-mapping is dirty */ if (!mapping_mapped(mapping)) { - clear_bit(PG_dc_clean, &page->flags); - } else if (page_mapcount(page)) { - + clear_bit(PG_dc_clean, &folio->flags); + } else if (folio_mapped(folio)) { /* kernel reading from page with U-mapping */ - phys_addr_t paddr = (unsigned long)page_address(page); - unsigned long vaddr = page->index << PAGE_SHIFT; + phys_addr_t paddr = (unsigned long)folio_address(folio); + unsigned long vaddr = folio_pos(folio); + /* + * vaddr is not actually the virtual address, but is + * congruent to every user mapping. + */ if (addr_not_cache_congruent(paddr, vaddr)) - __flush_dcache_page(paddr, vaddr); + __flush_dcache_pages(paddr, vaddr, + folio_nr_pages(folio)); } } +EXPORT_SYMBOL(flush_dcache_folio); + +void flush_dcache_page(struct page *page) +{ + return flush_dcache_folio(page_folio(page)); +} EXPORT_SYMBOL(flush_dcache_page); /* @@ -921,18 +931,18 @@ void __sync_icache_dcache(phys_addr_t paddr, unsigned long vaddr, int len) } /* wrapper to compile time eliminate alignment checks in flush loop */ -void __inv_icache_page(phys_addr_t paddr, unsigned long vaddr) +void __inv_icache_pages(phys_addr_t paddr, unsigned long vaddr, unsigned nr) { - __ic_line_inv_vaddr(paddr, vaddr, PAGE_SIZE); + __ic_line_inv_vaddr(paddr, vaddr, nr * PAGE_SIZE); } /* * wrapper to clearout kernel or userspace mappings of a page * For kernel mappings @vaddr == @paddr */ -void __flush_dcache_page(phys_addr_t paddr, unsigned long vaddr) +void __flush_dcache_pages(phys_addr_t paddr, unsigned long vaddr, unsigned nr) { - __dc_line_op(paddr, vaddr & PAGE_MASK, PAGE_SIZE, OP_FLUSH_N_INV); + __dc_line_op(paddr, vaddr & PAGE_MASK, nr * PAGE_SIZE, OP_FLUSH_N_INV); } noinline void flush_cache_all(void) @@ -962,10 +972,10 @@ void flush_cache_page(struct vm_area_struct *vma, unsigned long u_vaddr, u_vaddr &= PAGE_MASK; - __flush_dcache_page(paddr, u_vaddr); + __flush_dcache_pages(paddr, u_vaddr, 1); if (vma->vm_flags & VM_EXEC) - __inv_icache_page(paddr, u_vaddr); + __inv_icache_pages(paddr, u_vaddr, 1); } void flush_cache_range(struct vm_area_struct *vma, unsigned long start, @@ -978,9 +988,9 @@ void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long u_vaddr) { /* TBD: do we really need to clear the kernel mapping */ - __flush_dcache_page((phys_addr_t)page_address(page), u_vaddr); - __flush_dcache_page((phys_addr_t)page_address(page), - (phys_addr_t)page_address(page)); + __flush_dcache_pages((phys_addr_t)page_address(page), u_vaddr, 1); + __flush_dcache_pages((phys_addr_t)page_address(page), + (phys_addr_t)page_address(page), 1); } @@ -989,6 +999,8 @@ void flush_anon_page(struct vm_area_struct *vma, struct page *page, void copy_user_highpage(struct page *to, struct page *from, unsigned long u_vaddr, struct vm_area_struct *vma) { + struct folio *src = page_folio(from); + struct folio *dst = page_folio(to); void *kfrom = kmap_atomic(from); void *kto = kmap_atomic(to); int clean_src_k_mappings = 0; @@ -1005,7 +1017,7 @@ void copy_user_highpage(struct page *to, struct page *from, * addr_not_cache_congruent() is 0 */ if (page_mapcount(from) && addr_not_cache_congruent(kfrom, u_vaddr)) { - __flush_dcache_page((unsigned long)kfrom, u_vaddr); + __flush_dcache_pages((unsigned long)kfrom, u_vaddr, 1); clean_src_k_mappings = 1; } @@ -1019,17 +1031,17 @@ void copy_user_highpage(struct page *to, struct page *from, * non copied user pages (e.g. read faults which wire in pagecache page * directly). */ - clear_bit(PG_dc_clean, &to->flags); + clear_bit(PG_dc_clean, &dst->flags); /* * if SRC was already usermapped and non-congruent to kernel mapping * sync the kernel mapping back to physical page */ if (clean_src_k_mappings) { - __flush_dcache_page((unsigned long)kfrom, (unsigned long)kfrom); - set_bit(PG_dc_clean, &from->flags); + __flush_dcache_pages((unsigned long)kfrom, + (unsigned long)kfrom, 1); } else { - clear_bit(PG_dc_clean, &from->flags); + clear_bit(PG_dc_clean, &src->flags); } kunmap_atomic(kto); @@ -1038,8 +1050,9 @@ void copy_user_highpage(struct page *to, struct page *from, void clear_user_page(void *to, unsigned long u_vaddr, struct page *page) { + struct folio *folio = page_folio(page); clear_page(to); - clear_bit(PG_dc_clean, &page->flags); + clear_bit(PG_dc_clean, &folio->flags); } EXPORT_SYMBOL(clear_user_page); diff --git a/arch/arc/mm/tlb.c b/arch/arc/mm/tlb.c index 5f71445f26bd..6f40f37e6550 100644 --- a/arch/arc/mm/tlb.c +++ b/arch/arc/mm/tlb.c @@ -467,8 +467,8 @@ void create_tlb(struct vm_area_struct *vma, unsigned long vaddr, pte_t *ptep) * Note that flush (when done) involves both WBACK - so physical page is * in sync as well as INV - so any non-congruent aliases don't remain */ -void update_mmu_cache(struct vm_area_struct *vma, unsigned long vaddr_unaligned, - pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long vaddr_unaligned, pte_t *ptep, unsigned int nr) { unsigned long vaddr = vaddr_unaligned & PAGE_MASK; phys_addr_t paddr = pte_val(*ptep) & PAGE_MASK_PHYS; @@ -491,15 +491,19 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long vaddr_unaligned, */ if ((vma->vm_flags & VM_EXEC) || addr_not_cache_congruent(paddr, vaddr)) { - - int dirty = !test_and_set_bit(PG_dc_clean, &page->flags); + struct folio *folio = page_folio(page); + int dirty = !test_and_set_bit(PG_dc_clean, &folio->flags); if (dirty) { + unsigned long offset = offset_in_folio(folio, paddr); + nr = folio_nr_pages(folio); + paddr -= offset; + vaddr -= offset; /* wback + inv dcache lines (K-mapping) */ - __flush_dcache_page(paddr, paddr); + __flush_dcache_pages(paddr, paddr, nr); /* invalidate any existing icache lines (U-mapping) */ if (vma->vm_flags & VM_EXEC) - __inv_icache_page(paddr, vaddr); + __inv_icache_pages(paddr, vaddr, nr); } } } @@ -531,7 +535,7 @@ void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd) { pte_t pte = __pte(pmd_val(*pmd)); - update_mmu_cache(vma, addr, &pte); + update_mmu_cache_range(NULL, vma, addr, &pte, HPAGE_PMD_NR); } void local_flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, From patchwork Mon Jul 10 20:43:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307605 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 64CDAEB64DA for ; Mon, 10 Jul 2023 20:43:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CFED8E0005; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A45C8E000C; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD69A8E0005; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 81B4D8E0001 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5A75516023E for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.20.2DB2458 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 511BD4000A for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="HNhvvT/8"; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021825; 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=cTS1arWDtVYlUGrue9zB009GiMjCb8eg49buEtJoGPA=; b=3nZ2ltEeY5m8ozZEWdkhuwhHn6idynKMf5cBwqHlIhf2yEIGwiALJcfqM6sGbBHUS7A7o8 TAnuL8+oaYkDPFRPQIP45vjkxqPCM+fyvmG7BP+UOHnCUSM1khBZ9ME98/nMgAcukj3cX9 iztrtyf7T5wPTPUWqRy5zzuIEm6gjdA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021825; a=rsa-sha256; cv=none; b=Am3VXdiivnlcjDwACNVfn0AQ1+v3Wpfmmpy0TqjYXjOlbZ3BgKEXssg8fFSk20jYwsPjro 5YAYub9Td359YUfWthK7fjKQLTUVyGAKZXIUS3l23MCU8pCcnkSO92yLZO4KT7DiiqsVK0 ZcNJ357OilbPoVQtC5Dus2uoxyLKEP4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="HNhvvT/8"; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=cTS1arWDtVYlUGrue9zB009GiMjCb8eg49buEtJoGPA=; b=HNhvvT/8F6pyDRuyUXtdCeZ4XO exX87aVgsKwY0R0a1Hyc8zlFH4V9Hxnw9siYGyad7io+m4Hr1N20rPpx2TDjCsOYvSt6mH6oE1y1M 4zGRbKefT6Ydup0b3QSjdldyhxWOECa2kZD/91xtY+1izjJZwLQqp3qshMuB+FskPBG5c5JtZ1h3X wJX8O5yc/xsrtIoUdVda18Hruq2CKx9f5K7N0ofZyWadE5AHpkLTSjmxYnNXuGW4flbAMwHWO9tZ0 CVAzSQXpAZ3zaYkEBhToQscCXMHthlN8HJgOPZlNWBqYZ3i7FwFNa3LdND0E9VNOCFB0nzaxeQDlc AwrRCmFQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Euoh-5H; Mon, 10 Jul 2023 20:43:42 +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 , Russell King , linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 09/38] arm: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:10 +0100 Message-Id: <20230710204339.3554919-10-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: 511BD4000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zxkopw7u6q6mfxde3tjm7pny34g8ixue X-HE-Tag: 1689021825-373823 X-HE-Meta: U2FsdGVkX18xQ0JVyiv6gAHwMlf377x+dyRQXhSkTGJeVLV4jl2rmBaWo0g7ZCXGLjCx2KOS4h4rKV8ANsXi5hnzO4Yt+QcQe5ymB9UvLP/EknRenlxDAG3gZvSZjlJLr1CyToD7lvsC5wIhEKXSwmeUAQwqjbYCv5JUf99FIM/+2U/tP3w5fbE+AedRrkVTTUceNr1ZHkrg+C4s5TZKA1DzFl08Dtkve+w98W+oCrABztMiFpTfor2983clX6k2h7K4MsJBNOB8A67yRDOjZscDBZ4HgNJBpB8VIEwsKOHk/St6f2YMddjcb+DT2zQWunMPI/umEFQRz56p1EzlYNhG/MbIkV40Wlbb2vJI/jqGGEAeCHjzkjTqfIz06Mn4NIuRDfWJANLhEw9rQio6cHx2Bqe810Sg0jRK+9FkjejXnAxpNVESgBMFJ2ioqzMGA2ZLKhL3oP/h3oJOaCZeg5780fbIoW8o8IAuPEdaW6b8Jds6fuhIWyIB14UNeOJ1L4K3PyhS9noi+Wu8ynHQ6xO6ad5d9kdjGQ99uqEhhYULNz1bKdzsDdfcu1Bl4NDoPjMfK+dR8M+l2tte9oPY6a7wAHwRzcAPaonl4N8e3QxaRGEXt62u0UH1vVk1Mn9+cI1RnAS9OpHWIwTL6E+yjLhLVbWTBWKlwhTYY0OxZRk242h4TbOsfXwoiOcSpkFLFAT6ebpN/VT4tj/pe4DIpgW2aVIpJNc1FdzepphB2jjBF6gT6Vxaz1j2oqgyq4ek4P/RdV/jkuagYXiyh1whk1P48M9Jx4YyxLWYHRrg3VUEFDIt7qscxTshjbfF9fhQl+sagq45AkFmcBhrYdna2jpznCCb4aFJhjdfEw/AtwPDhqtBrtUq1qKrBaKjYE5YDaPkNOh596+td1HUW+T8p8nIbt7s3cVs0ksWYfQoivXwITPri+8AcIKZa0k13SjApRVPrg/CIZ5zg922yoM SyjgyKNB CZSXVuEMDOiIZwTHTQKNUpDo8JbylD7O/W+516PcsHBo2EQvkflf2s/jYhjYUtvFldscRjVIuj1nUpodTrjmznymh5wpUPVO+CyATCkYWHkP3A9Wpd5WWZplGsVd7w1GvcF0alLkSdAdPVAMXGRvzUzX+Vg3Ao1T8kX7Fb9QHeY2HrNKRB+KXXh6LoVw6YKLC+19KePFEA29DF4WMylcDPHlsZrI8VkvDcSqaGUUZ2ioOMYf68kM6fFI/vj+gVa6Nav5F4mijU/Fsv0/SkNwf3xGJcaBZav8o4ATQGtXhylIuoBCOsYYgaM70nOJ/S9LHGXEwfK/feGz9wOcRwWL1yWVIoFZMIvJFP/xU1jLx9iWHgXu99ePcjw6jfwbVYKeaKr/+ 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: Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_dcache_clear flag from being per-page to per-folio which makes __dma_page_dev_to_cpu() a bit more exciting. Also add flush_cache_pages(), even though this isn't used by generic code (yet?) Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Reviewed-by: Russell King (Oracle) Cc: linux-arm-kernel@lists.infradead.org --- arch/arm/include/asm/cacheflush.h | 24 +++++--- arch/arm/include/asm/pgtable.h | 5 +- arch/arm/include/asm/tlbflush.h | 14 +++-- arch/arm/mm/copypage-v4mc.c | 5 +- arch/arm/mm/copypage-v6.c | 5 +- arch/arm/mm/copypage-xscale.c | 5 +- arch/arm/mm/dma-mapping.c | 24 ++++---- arch/arm/mm/fault-armv.c | 16 ++--- arch/arm/mm/flush.c | 99 +++++++++++++++++++------------ arch/arm/mm/mm.h | 2 +- arch/arm/mm/mmu.c | 14 +++-- arch/arm/mm/nommu.c | 6 ++ 12 files changed, 133 insertions(+), 86 deletions(-) diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h index a094f964c869..841e268d2374 100644 --- a/arch/arm/include/asm/cacheflush.h +++ b/arch/arm/include/asm/cacheflush.h @@ -231,14 +231,15 @@ vivt_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned vma->vm_flags); } -static inline void -vivt_flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn) +static inline void vivt_flush_cache_pages(struct vm_area_struct *vma, + unsigned long user_addr, unsigned long pfn, unsigned int nr) { struct mm_struct *mm = vma->vm_mm; if (!mm || cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm))) { unsigned long addr = user_addr & PAGE_MASK; - __cpuc_flush_user_range(addr, addr + PAGE_SIZE, vma->vm_flags); + __cpuc_flush_user_range(addr, addr + nr * PAGE_SIZE, + vma->vm_flags); } } @@ -247,15 +248,17 @@ vivt_flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsig vivt_flush_cache_mm(mm) #define flush_cache_range(vma,start,end) \ vivt_flush_cache_range(vma,start,end) -#define flush_cache_page(vma,addr,pfn) \ - vivt_flush_cache_page(vma,addr,pfn) +#define flush_cache_pages(vma, addr, pfn, nr) \ + vivt_flush_cache_pages(vma, addr, pfn, nr) #else -extern void flush_cache_mm(struct mm_struct *mm); -extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); -extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn); +void flush_cache_mm(struct mm_struct *mm); +void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); +void flush_cache_pages(struct vm_area_struct *vma, unsigned long user_addr, + unsigned long pfn, unsigned int nr); #endif #define flush_cache_dup_mm(mm) flush_cache_mm(mm) +#define flush_cache_page(vma, addr, pfn) flush_cache_pages(vma, addr, pfn, 1) /* * flush_icache_user_range is used when we want to ensure that the @@ -289,7 +292,9 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr * See update_mmu_cache for the user space part. */ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -extern void flush_dcache_page(struct page *); +void flush_dcache_page(struct page *); +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio #define ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE 1 static inline void flush_kernel_vmap_range(void *addr, int size) @@ -321,6 +326,7 @@ static inline void flush_anon_page(struct vm_area_struct *vma, * duplicate cache flushing elsewhere performed by flush_dcache_page(). */ #define flush_icache_page(vma,page) do { } while (0) +#define flush_icache_pages(vma, page, nr) do { } while (0) /* * flush_cache_vmap() is used when creating mappings (eg, via vmap, diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index 34662a9d4cab..ba573f22d7cc 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -207,8 +207,9 @@ static inline void __sync_icache_dcache(pte_t pteval) extern void __sync_icache_dcache(pte_t pteval); #endif -void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval); +void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pteval, unsigned int nr); +#define set_ptes set_ptes static inline pte_t clear_pte_bit(pte_t pte, pgprot_t prot) { diff --git a/arch/arm/include/asm/tlbflush.h b/arch/arm/include/asm/tlbflush.h index 0ccc985b90af..38c6e4a2a0b6 100644 --- a/arch/arm/include/asm/tlbflush.h +++ b/arch/arm/include/asm/tlbflush.h @@ -619,18 +619,22 @@ extern void flush_bp_all(void); * If PG_dcache_clean is not set for the page, we need to ensure that any * cache entries for the kernels virtual memory range are written * back to the page. On ARMv6 and later, the cache coherency is handled via - * the set_pte_at() function. + * the set_ptes() function. */ #if __LINUX_ARM_ARCH__ < 6 -extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep); +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr); #else -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, + unsigned int nr) { } #endif +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + #define update_mmu_cache_pmd(vma, address, pmd) do { } while (0) #endif diff --git a/arch/arm/mm/copypage-v4mc.c b/arch/arm/mm/copypage-v4mc.c index f1da3b439b96..7ddd82b9fe8b 100644 --- a/arch/arm/mm/copypage-v4mc.c +++ b/arch/arm/mm/copypage-v4mc.c @@ -64,10 +64,11 @@ static void mc_copy_user_page(void *from, void *to) void v4_mc_copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) { + struct folio *src = page_folio(from); void *kto = kmap_atomic(to); - if (!test_and_set_bit(PG_dcache_clean, &from->flags)) - __flush_dcache_page(page_mapping_file(from), from); + if (!test_and_set_bit(PG_dcache_clean, &src->flags)) + __flush_dcache_folio(folio_flush_mapping(src), src); raw_spin_lock(&minicache_lock); diff --git a/arch/arm/mm/copypage-v6.c b/arch/arm/mm/copypage-v6.c index d8a115de5507..a1a71f36d850 100644 --- a/arch/arm/mm/copypage-v6.c +++ b/arch/arm/mm/copypage-v6.c @@ -69,11 +69,12 @@ static void discard_old_kernel_data(void *kto) static void v6_copy_user_highpage_aliasing(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) { + struct folio *src = page_folio(from); unsigned int offset = CACHE_COLOUR(vaddr); unsigned long kfrom, kto; - if (!test_and_set_bit(PG_dcache_clean, &from->flags)) - __flush_dcache_page(page_mapping_file(from), from); + if (!test_and_set_bit(PG_dcache_clean, &src->flags)) + __flush_dcache_folio(folio_flush_mapping(src), src); /* FIXME: not highmem safe */ discard_old_kernel_data(page_address(to)); diff --git a/arch/arm/mm/copypage-xscale.c b/arch/arm/mm/copypage-xscale.c index bcb485620a05..f1e29d3e8193 100644 --- a/arch/arm/mm/copypage-xscale.c +++ b/arch/arm/mm/copypage-xscale.c @@ -84,10 +84,11 @@ static void mc_copy_user_page(void *from, void *to) void xscale_mc_copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) { + struct folio *src = page_folio(from); void *kto = kmap_atomic(to); - if (!test_and_set_bit(PG_dcache_clean, &from->flags)) - __flush_dcache_page(page_mapping_file(from), from); + if (!test_and_set_bit(PG_dcache_clean, &src->flags)) + __flush_dcache_folio(folio_flush_mapping(src), src); raw_spin_lock(&minicache_lock); diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 033a1bce2b17..70cb7e63a9a5 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -695,6 +695,7 @@ static void __dma_page_cpu_to_dev(struct page *page, unsigned long off, static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, size_t size, enum dma_data_direction dir) { + struct folio *folio = page_folio(page); phys_addr_t paddr = page_to_phys(page) + off; /* FIXME: non-speculating: not required */ @@ -709,19 +710,18 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, * Mark the D-cache clean for these pages to avoid extra flushing. */ if (dir != DMA_TO_DEVICE && size >= PAGE_SIZE) { - unsigned long pfn; - size_t left = size; - - pfn = page_to_pfn(page) + off / PAGE_SIZE; - off %= PAGE_SIZE; - if (off) { - pfn++; - left -= PAGE_SIZE - off; + ssize_t left = size; + size_t offset = offset_in_folio(folio, paddr); + + if (offset) { + left -= folio_size(folio) - offset; + folio = folio_next(folio); } - while (left >= PAGE_SIZE) { - page = pfn_to_page(pfn++); - set_bit(PG_dcache_clean, &page->flags); - left -= PAGE_SIZE; + + while (left >= (ssize_t)folio_size(folio)) { + set_bit(PG_dcache_clean, &folio->flags); + left -= folio_size(folio); + folio = folio_next(folio); } } } diff --git a/arch/arm/mm/fault-armv.c b/arch/arm/mm/fault-armv.c index ca5302b0b7ee..36f26f38cb30 100644 --- a/arch/arm/mm/fault-armv.c +++ b/arch/arm/mm/fault-armv.c @@ -181,12 +181,12 @@ make_coherent(struct address_space *mapping, struct vm_area_struct *vma, * * Note that the pte lock will be held. */ -void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr) { unsigned long pfn = pte_pfn(*ptep); struct address_space *mapping; - struct page *page; + struct folio *folio; if (!pfn_valid(pfn)) return; @@ -195,13 +195,13 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - page = pfn_to_page(pfn); - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(pfn)) return; - mapping = page_mapping_file(page); - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) - __flush_dcache_page(mapping, page); + folio = page_folio(pfn_to_page(pfn)); + mapping = folio_flush_mapping(folio); + if (!test_and_set_bit(PG_dcache_clean, &folio->flags)) + __flush_dcache_folio(mapping, folio); if (mapping) { if (cache_is_vivt()) make_coherent(mapping, vma, addr, ptep, pfn); diff --git a/arch/arm/mm/flush.c b/arch/arm/mm/flush.c index 2508be91b7a0..d19d140a10c7 100644 --- a/arch/arm/mm/flush.c +++ b/arch/arm/mm/flush.c @@ -95,10 +95,10 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned __flush_icache_all(); } -void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn) +void flush_cache_pages(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn, unsigned int nr) { if (cache_is_vivt()) { - vivt_flush_cache_page(vma, user_addr, pfn); + vivt_flush_cache_pages(vma, user_addr, pfn, nr); return; } @@ -196,29 +196,31 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page, #endif } -void __flush_dcache_page(struct address_space *mapping, struct page *page) +void __flush_dcache_folio(struct address_space *mapping, struct folio *folio) { /* * Writeback any data associated with the kernel mapping of this * page. This ensures that data in the physical page is mutually * coherent with the kernels mapping. */ - if (!PageHighMem(page)) { - __cpuc_flush_dcache_area(page_address(page), page_size(page)); + if (!folio_test_highmem(folio)) { + __cpuc_flush_dcache_area(folio_address(folio), + folio_size(folio)); } else { unsigned long i; if (cache_is_vipt_nonaliasing()) { - for (i = 0; i < compound_nr(page); i++) { - void *addr = kmap_atomic(page + i); + for (i = 0; i < folio_nr_pages(folio); i++) { + void *addr = kmap_local_folio(folio, + i * PAGE_SIZE); __cpuc_flush_dcache_area(addr, PAGE_SIZE); - kunmap_atomic(addr); + kunmap_local(addr); } } else { - for (i = 0; i < compound_nr(page); i++) { - void *addr = kmap_high_get(page + i); + for (i = 0; i < folio_nr_pages(folio); i++) { + void *addr = kmap_high_get(folio_page(folio, i)); if (addr) { __cpuc_flush_dcache_area(addr, PAGE_SIZE); - kunmap_high(page + i); + kunmap_high(folio_page(folio, i)); } } } @@ -230,15 +232,14 @@ void __flush_dcache_page(struct address_space *mapping, struct page *page) * userspace colour, which is congruent with page->index. */ if (mapping && cache_is_vipt_aliasing()) - flush_pfn_alias(page_to_pfn(page), - page->index << PAGE_SHIFT); + flush_pfn_alias(folio_pfn(folio), folio_pos(folio)); } -static void __flush_dcache_aliases(struct address_space *mapping, struct page *page) +static void __flush_dcache_aliases(struct address_space *mapping, struct folio *folio) { struct mm_struct *mm = current->active_mm; - struct vm_area_struct *mpnt; - pgoff_t pgoff; + struct vm_area_struct *vma; + pgoff_t pgoff, pgoff_end; /* * There are possible user space mappings of this page: @@ -246,21 +247,36 @@ static void __flush_dcache_aliases(struct address_space *mapping, struct page *p * data in the current VM view associated with this page. * - aliasing VIPT: we only need to find one mapping of this page. */ - pgoff = page->index; + pgoff = folio->index; + pgoff_end = pgoff + folio_nr_pages(folio) - 1; flush_dcache_mmap_lock(mapping); - vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { - unsigned long offset; + vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff_end) { + unsigned long start, offset, pfn; + unsigned int nr; /* * If this VMA is not in our MM, we can ignore it. */ - if (mpnt->vm_mm != mm) + if (vma->vm_mm != mm) continue; - if (!(mpnt->vm_flags & VM_MAYSHARE)) + if (!(vma->vm_flags & VM_MAYSHARE)) continue; - offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT; - flush_cache_page(mpnt, mpnt->vm_start + offset, page_to_pfn(page)); + + start = vma->vm_start; + pfn = folio_pfn(folio); + nr = folio_nr_pages(folio); + offset = pgoff - vma->vm_pgoff; + if (offset > -nr) { + pfn -= offset; + nr += offset; + } else { + start += offset * PAGE_SIZE; + } + if (start + nr * PAGE_SIZE > vma->vm_end) + nr = (vma->vm_end - start) / PAGE_SIZE; + + flush_cache_pages(vma, start, pfn, nr); } flush_dcache_mmap_unlock(mapping); } @@ -269,7 +285,7 @@ static void __flush_dcache_aliases(struct address_space *mapping, struct page *p void __sync_icache_dcache(pte_t pteval) { unsigned long pfn; - struct page *page; + struct folio *folio; struct address_space *mapping; if (cache_is_vipt_nonaliasing() && !pte_exec(pteval)) @@ -279,14 +295,14 @@ void __sync_icache_dcache(pte_t pteval) if (!pfn_valid(pfn)) return; - page = pfn_to_page(pfn); + folio = page_folio(pfn_to_page(pfn)); if (cache_is_vipt_aliasing()) - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); else mapping = NULL; - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) - __flush_dcache_page(mapping, page); + if (!test_and_set_bit(PG_dcache_clean, &folio->flags)) + __flush_dcache_folio(mapping, folio); if (pte_exec(pteval)) __flush_icache_all(); @@ -312,7 +328,7 @@ void __sync_icache_dcache(pte_t pteval) * Note that we disable the lazy flush for SMP configurations where * the cache maintenance operations are not automatically broadcasted. */ -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { struct address_space *mapping; @@ -320,31 +336,36 @@ void flush_dcache_page(struct page *page) * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(folio_pfn(folio))) return; if (!cache_ops_need_broadcast() && cache_is_vipt_nonaliasing()) { - if (test_bit(PG_dcache_clean, &page->flags)) - clear_bit(PG_dcache_clean, &page->flags); + if (test_bit(PG_dcache_clean, &folio->flags)) + clear_bit(PG_dcache_clean, &folio->flags); return; } - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); if (!cache_ops_need_broadcast() && - mapping && !page_mapcount(page)) - clear_bit(PG_dcache_clean, &page->flags); + mapping && !folio_mapped(folio)) + clear_bit(PG_dcache_clean, &folio->flags); else { - __flush_dcache_page(mapping, page); + __flush_dcache_folio(mapping, folio); if (mapping && cache_is_vivt()) - __flush_dcache_aliases(mapping, page); + __flush_dcache_aliases(mapping, folio); else if (mapping) __flush_icache_all(); - set_bit(PG_dcache_clean, &page->flags); + set_bit(PG_dcache_clean, &folio->flags); } } -EXPORT_SYMBOL(flush_dcache_page); +EXPORT_SYMBOL(flush_dcache_folio); +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} +EXPORT_SYMBOL(flush_dcache_page); /* * Flush an anonymous page so that users of get_user_pages() * can safely access the data. The expected sequence is: diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h index d7ffccb7fea7..419316316711 100644 --- a/arch/arm/mm/mm.h +++ b/arch/arm/mm/mm.h @@ -45,7 +45,7 @@ struct mem_type { const struct mem_type *get_mem_type(unsigned int type); -extern void __flush_dcache_page(struct address_space *mapping, struct page *page); +void __flush_dcache_folio(struct address_space *mapping, struct folio *folio); /* * ARM specific vm_struct->flags bits. diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 13fc4bb5f792..c9981c23e8e9 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1788,7 +1788,7 @@ void __init paging_init(const struct machine_desc *mdesc) bootmem_init(); empty_zero_page = virt_to_page(zero_page); - __flush_dcache_page(NULL, empty_zero_page); + __flush_dcache_folio(NULL, page_folio(empty_zero_page)); } void __init early_mm_init(const struct machine_desc *mdesc) @@ -1797,8 +1797,8 @@ void __init early_mm_init(const struct machine_desc *mdesc) early_paging_init(mdesc); } -void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval) +void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pteval, unsigned int nr) { unsigned long ext = 0; @@ -1808,5 +1808,11 @@ void set_pte_at(struct mm_struct *mm, unsigned long addr, ext |= PTE_EXT_NG; } - set_pte_ext(ptep, pteval, ext); + for (;;) { + set_pte_ext(ptep, pteval, ext); + if (--nr == 0) + break; + ptep++; + pte_val(pteval) += PAGE_SIZE; + } } diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index 43cfd06bbeba..c415f3859b20 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c @@ -180,6 +180,12 @@ void setup_mm_for_reboot(void) { } +void flush_dcache_folio(struct folio *folio) +{ + __cpuc_flush_dcache_area(folio_address(folio), folio_size(folio)); +} +EXPORT_SYMBOL(flush_dcache_folio); + void flush_dcache_page(struct page *page) { __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE); From patchwork Mon Jul 10 20:43:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307602 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 6B636C001DC for ; Mon, 10 Jul 2023 20:43:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 631938E0003; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5805D8E0007; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D2E08E0005; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1D3358E0001 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DAA6A1A021C for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) X-FDA: 80996878452.26.D02E24D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id 3000C4000E for ; Mon, 10 Jul 2023 20:43:44 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="lPuyuN9/"; dmarc=none; spf=none (imf07.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=1689021825; 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=Ppdmkbhn3pdci2A5T+8/PDoAOO4tRHFDpMfgtHEjIi8=; b=bOhZCQ43ov6liXZuyon3mdVKLhbxnfd7SEbvKyb+rBRp0+/K2URe+65zk4C4F1f5sIy93Q ArE5k8w8cMqVkl2H3+ehLnbc4rn1p9RnEqvWsdKQSm+YgxNzAQ8zxZ0HU58HH8KNTd0o50 bin9seoqznydpbqHcmiFjvp4qGE0Nw8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="lPuyuN9/"; dmarc=none; spf=none (imf07.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=1689021825; a=rsa-sha256; cv=none; b=Pn1ol9GSbQr432JfAYhI43w6tCJNnRGLySORnwc7psnU1oH/RNravThenvuWUU/xD9oyGO YbfT2yJkqlIrzmtsB6Iw5bAQD8osb3h2pS6NcPzf7tgUxlC/6rtCR9DsceU/4DSB6XixQS DPahnRt3dOmdICmUGSc0ixKaXnvcGW8= 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=Ppdmkbhn3pdci2A5T+8/PDoAOO4tRHFDpMfgtHEjIi8=; b=lPuyuN9/kfzzegkfuFmcsaU9fF Lc/9z5kp4JaqUHiiCtO4bct9lDeuZEuBbGVmD75jHyod+q5OS9/E33T+yVfXQq56C7GARJp6DyjIR o3UuxEY0HJslmfgdR+bF9veKcWu1b4C+HRsH7/UYSDnz5jP8cDnvYdYrQQcgREzKagDeWJNfCOHL1 ZwfyY7vuDOw4waS2NW2CPa2NjUUcSm0wjYA9qAvsyhqfVtNiBplyeqAYGg44dbIwl3lVtJ3jc3T7f oQ1o/qpbmedQ7/dlvUjfDX9dJeYTDR6bleepVfHIh67aOcZYvrfvBEeXRe2a+li5dwtQXgjm2SZ/3 VDeFgVJQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Euon-AG; Mon, 10 Jul 2023 20:43:42 +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, Catalin Marinas , Mike Rapoport , linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 10/38] arm64: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:11 +0100 Message-Id: <20230710204339.3554919-11-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-Server: rspam09 X-Rspamd-Queue-Id: 3000C4000E X-Stat-Signature: wnz8qfpb5nbnyhcft8pf3sxk3sxec1na X-Rspam-User: X-HE-Tag: 1689021824-98836 X-HE-Meta: U2FsdGVkX19H6NcrEBM1zNLZNpguvW+5ZJkDL6vd8x/JBxmbeMg1KQu3UuRl1G9ndJFSIo/ebY6gbMQ3pityaO+zx7U5bfF27/eRPvSXXqeWZtubydpN2CD5PUgzjHuiab6Px32X2ey384yzrMYUBksuUlKS/O9IUkm+X4Glq8g3i5gkY6TqzhU0u7f9UkE84BJLzZtSNrm+exPm9LwCwVhTlRsmE0cobsx+L45KhqBzH2YY52BV9V6kS1DYoV/+DIyiSv11/UYnMoInoP6fMl9y1eFpZdSDQHF6dObgxejH0exiIrF7GG3XOA0tXTK8kEeVfC9D7pxIqV4HYcPkq3lDo2ubSRwBo9I1o1aBChNuELyLdxtqZBBrmDqA431plvW/AXbaTXJK12L7oKEb3SCkHPbdRz/yr3IUy/3PdYZcCoj0TuwmmkNF2ALUexcQHSqMfdLDZ+Z/0ATpniHLjfEjtp44HlWILTizyLy49ygZ8TIgfj11ZCaXCqJDorb7752g5EEHnsrQOXsv2XKbdD9v+H4L6Bvsaf267HLYozKL3Ozpb5aTJaOULBLcBmB3ry4PdTz4jvLoE5b7ULrdwE0uy3rS37LhVCrYI08ARnSepzbZ2/rCmSFrPZhXIFr9s0sPFzP6a+LNuRLsNgWPx2/gd65MRCxhbHz1Wl3i9446Xa+OOtP7GAdPKzTUyevESwI06rx216xO64eLU83CdTQflBt9sQVBueJ+qFL0709nzJxUMp+kBjTNjwL+zif2coVkrFUh3hpdTRm8Z1N9PRwqE8QPndkN0q6X5JxtgMksEZMA+tZ8mXE136vtBDrZi09cH1UrVkIaT2q+ehETjOXCr1U9eraQz/f75G9cdHi+LHulhSI9qG3J32CVoGdApN2cj0/8eJT1eKE6tbuYct32ueGFnlyVyQz8TBpAPD/doCafFm7cQgskrrhTbGGQklRt+kvHTmfsQQHQznw Bld4xy3t AgGHNdEGSNjjwLqQyCKtkTB9GZhfgyypRc3C87bTk1j4dfXRHDmgF57rO/SfNwARdt8yvrpxP5FT3OnmzhVK4AlSESE+Gfk8h/9pzEYGb0MfNRkcK+PrD2WgDKx4xl9KlzmPqZ1Rm7vCdymWM7N81qqYmVYF1WZR1OX40u0bFpSbtyuXHDWVZDKihFyQJU+g2n1g72EV2WKB92e7su0+esZ/cNzQJV3abM4vMPqmq+T4Q4ST40Ij9XxmnCNMQ/y7hy4pKr0HNHhjz+9hKVc2w6jIaSSWlkXFk2rYri4uqGTkM62E= 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: Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Catalin Marinas Acked-by: Mike Rapoport (IBM) Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/cacheflush.h | 4 +++- arch/arm64/include/asm/pgtable.h | 26 +++++++++++++++------ arch/arm64/mm/flush.c | 36 +++++++++++------------------ 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h index 37185e978aeb..d115451ed263 100644 --- a/arch/arm64/include/asm/cacheflush.h +++ b/arch/arm64/include/asm/cacheflush.h @@ -114,7 +114,7 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *, #define copy_to_user_page copy_to_user_page /* - * flush_dcache_page is used when the kernel has written to the page + * flush_dcache_folio is used when the kernel has written to the page * cache page at virtual address page->virtual. * * If this page isn't mapped (ie, page_mapping == NULL), or it might @@ -127,6 +127,8 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *, */ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 extern void flush_dcache_page(struct page *); +void flush_dcache_folio(struct folio *); +#define flush_dcache_folio flush_dcache_folio static __always_inline void icache_inval_all_pou(void) { diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index a44a150e0318..c1c4abf75217 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -345,12 +345,21 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, set_pte(ptep, pte); } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) -{ - page_table_check_ptes_set(mm, addr, ptep, pte, 1); - return __set_pte_at(mm, addr, ptep, pte); +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_at(mm, addr, ptep, pte); + if (--nr == 0) + break; + ptep++; + addr += PAGE_SIZE; + pte_val(pte) += PAGE_SIZE; + } } +#define set_ptes set_ptes /* * Huge pte definitions. @@ -1049,8 +1058,9 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio) /* * On AArch64, the cache coherency is handled via the set_pte_at() function. */ -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, + unsigned int nr) { /* * We don't do anything here, so there's a very small chance of @@ -1059,6 +1069,8 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, */ } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define update_mmu_cache_pmd(vma, address, pmd) do { } while (0) #ifdef CONFIG_ARM64_PA_BITS_52 diff --git a/arch/arm64/mm/flush.c b/arch/arm64/mm/flush.c index 4e6476094952..013eead9b695 100644 --- a/arch/arm64/mm/flush.c +++ b/arch/arm64/mm/flush.c @@ -51,20 +51,13 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page, void __sync_icache_dcache(pte_t pte) { - struct page *page = pte_page(pte); + struct folio *folio = page_folio(pte_page(pte)); - /* - * HugeTLB pages are always fully mapped, so only setting head page's - * PG_dcache_clean flag is enough. - */ - if (PageHuge(page)) - page = compound_head(page); - - if (!test_bit(PG_dcache_clean, &page->flags)) { - sync_icache_aliases((unsigned long)page_address(page), - (unsigned long)page_address(page) + - page_size(page)); - set_bit(PG_dcache_clean, &page->flags); + if (!test_bit(PG_dcache_clean, &folio->flags)) { + sync_icache_aliases((unsigned long)folio_address(folio), + (unsigned long)folio_address(folio) + + folio_size(folio)); + set_bit(PG_dcache_clean, &folio->flags); } } EXPORT_SYMBOL_GPL(__sync_icache_dcache); @@ -74,17 +67,16 @@ EXPORT_SYMBOL_GPL(__sync_icache_dcache); * it as dirty for later flushing when mapped in user space (if executable, * see __sync_icache_dcache). */ -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { - /* - * HugeTLB pages are always fully mapped and only head page will be - * set PG_dcache_clean (see comments in __sync_icache_dcache()). - */ - if (PageHuge(page)) - page = compound_head(page); + if (test_bit(PG_dcache_clean, &folio->flags)) + clear_bit(PG_dcache_clean, &folio->flags); +} +EXPORT_SYMBOL(flush_dcache_folio); - if (test_bit(PG_dcache_clean, &page->flags)) - clear_bit(PG_dcache_clean, &page->flags); +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); } EXPORT_SYMBOL(flush_dcache_page); From patchwork Mon Jul 10 20:43:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307600 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 B61C1EB64DA for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13BB98D0002; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C4A68D0001; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA7378E0001; Mon, 10 Jul 2023 16:43:46 -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 D8C318D0001 for ; Mon, 10 Jul 2023 16:43:46 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B1A7E40249 for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) X-FDA: 80996878452.30.E3B5077 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id 268904001E for ; Mon, 10 Jul 2023 20:43:43 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=MHajTy9m; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021825; 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=+EcwG3CtD3KBn2kUGDuNHyIiThEOsdBdS/s6lb4peVI=; b=evB1rDc7/SlLKF8tQ3sywTVnd1wJebiZbMGa+q3MCX5U54lwURSTYTJc+1OKUPu7esQfZ5 dwyUn5ITMzbnrpxZ6KBUTeRjWwE64NSg9iRHF1ZryrudS2fPW00wcIzVyKCly/Pt7hUaEz g4Cwvu8SOJAmM+IqjuViL7wYD170FnM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021825; a=rsa-sha256; cv=none; b=8azWE8hUEpw0IK00fWnqJgfdkwUn10CLYp0X0yEFvx8WszDw18dHPLBBefNEfhm83Uu0Wq NdJQvubSeXSyrCJoedEandaV/8MjkjgQ+HMdNC6YMhb+xrm4Rst27Sb6EjK0WC5K5lvrh4 V9m1jcbko3WJOXBow7PUUqdEZ1BSr80= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=MHajTy9m; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=+EcwG3CtD3KBn2kUGDuNHyIiThEOsdBdS/s6lb4peVI=; b=MHajTy9mQDBZfuIizARiN1nkqJ 1lwGZUAXEWBiZydy6ZJaVH97vWtG3lC4o+VEGkLa/d6pKVr5cL8UlmzoF1QTOB4otT7/ttE/TP6Y/ kPyvvuLpuOjr8Rc9TtbCJq6jxdrxbdEBmyd12QDDuiaLqky/O+Ah4wyCF9Sd4DUb8H4VAEjZsA6o5 ZnyliBzDLtoQKZk2qLcY33XL8iROFBhgBb/EIEJtTl7uj4TVaBHUNB7afZhMbIVnWZUsk+r4zMbEo jESnCZXmpjdwFLTGisHvw3BlVrR8wTEmYs0cI0/qMVaDAdHsjOzDPcTApY26OLCgVzZNf9114zLEk OzSg4SOg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Euoq-Dc; Mon, 10 Jul 2023 20:43:42 +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, Guo Ren , Mike Rapoport , linux-csky@vger.kernel.org Subject: [PATCH v5 11/38] csky: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:12 +0100 Message-Id: <20230710204339.3554919-12-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-Stat-Signature: a5ojm8ayrck3sxxa93dic8drw8gf1n7s X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 268904001E X-Rspam-User: X-HE-Tag: 1689021823-898072 X-HE-Meta: U2FsdGVkX18nKaNub7NG1qsrfdZeoQ9LO4N98+am5xsgw8SegIMT+A3CTHsRDdy1IPyz7p+Q5ZH4eQIbVA8DlAkkEJTIMxRoa4sLXLhj82Fnb/xESyV3f8r//hDfiWcN7fRn5WBz3FEis1AtDCGE3dIoWrGaC5xgbR11CvWIYMawQK8HiJC3USsXKx8OEnZDJukiNUnodby/mG4l66Ccg/JKFSkGjT9qYfIDUo8Z4xKrZogfGskrkPnSwqobrbyGftmP97mkMADuhMLs0oMNAf1JDVneh4z9zteLsZQYeEkMiSe97Ge5kqC2jxEJV2Lm4ERycsInuzEA3uyImOJhwtcHF7OyhGLP75Q9I7HapD0LeJyRZXfBefk3TmDHxj4w4HtOHgYb5iFAVchJiepVxjMj8SetUY0lhDPyIqCiI/qKijFQxQpWBZkg5gdm9aZICjCNqxgsMM6q7nRME1dbwStozmdROvd/VlAhkJWd3WJQ3+ITDmmqk8p2zxtJE35T/44aA0L4MyN9LPc70qoNWr7SIfdbjFVk0Wt09/6GD9wmbDEEOamWvvLwC44VbrN3xlmG/maF0BG90YYkH8ezgT+VjTx64DMAovSoUEEBgLULLsCEB/NoVpgKwRUjmpw50WVYDyAgGWnavGe6y4qY3aUfiOV12mxJQ+SYRD3nssNZi72i2SG1nsPf2tIZGapygEsuzo0tiNMNTkpLW6pfeuB7NP3S1iRqbg7cqbxFcf1c+xmeDNGK8yanE9L6ru4kHcz+7j+4oWzeA94QL9lxptqLxl/WKGpJrSZ5qXpbgA+6SL76M8mqu8oIzbgc1Oa+lvlOYQq/ULP4l4wxZRaUcVrmtLUbpNQy9Znk2tJ5bjKl4J9cRLv4X/Ww856PtkXU1u1PfiqzFe0k/qEFrVdnH4wBjQnhWfv1Wm7GPrjHqWcBoQq51bvCfuBDB5KQWH/Sn6kJI6BLrUTi7sGvCA8 L3X+bNoK kx6UrnZYxu5ZXPkqG9zKnAmsejeJUQ4iYJDLwH/eF0pASWjdP0ilIKrXAISHsXjk5E5JyEZt6J8ENcQWykHGjgR6Cw9sBdNV5eqhtLROljqfA1+9NHBFEfP/zOOQXwwihfCSWf/4BN3mZq7QCxXcc8euJph+ulQ9rqbyKu+6GgHUS6NS4f3qYCjRUsl4i2fPvrlaZPlrGewoeIZ8sHaRAB89lA1g069ts9ckQMKpws3faMYWZGz16Sg0MdQ== 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: Add PFN_PTE_SHIFT, update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Guo Ren Acked-by: Mike Rapoport (IBM) Cc: linux-csky@vger.kernel.org --- arch/csky/abiv1/cacheflush.c | 32 +++++++++++++++++----------- arch/csky/abiv1/inc/abi/cacheflush.h | 2 ++ arch/csky/abiv2/cacheflush.c | 32 ++++++++++++++-------------- arch/csky/abiv2/inc/abi/cacheflush.h | 10 +++++++-- arch/csky/include/asm/pgtable.h | 8 ++++--- 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/arch/csky/abiv1/cacheflush.c b/arch/csky/abiv1/cacheflush.c index 94fbc03cbe70..171e8fb32285 100644 --- a/arch/csky/abiv1/cacheflush.c +++ b/arch/csky/abiv1/cacheflush.c @@ -15,45 +15,51 @@ #define PG_dcache_clean PG_arch_1 -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { struct address_space *mapping; - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(folio_pfn(folio))) return; - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); - if (mapping && !page_mapcount(page)) - clear_bit(PG_dcache_clean, &page->flags); + if (mapping && !folio_mapped(folio)) + clear_bit(PG_dcache_clean, &folio->flags); else { dcache_wbinv_all(); if (mapping) icache_inv_all(); - set_bit(PG_dcache_clean, &page->flags); + set_bit(PG_dcache_clean, &folio->flags); } } +EXPORT_SYMBOL(flush_dcache_folio); + +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} EXPORT_SYMBOL(flush_dcache_page); -void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr) { unsigned long pfn = pte_pfn(*ptep); - struct page *page; + struct folio *folio; flush_tlb_page(vma, addr); if (!pfn_valid(pfn)) return; - page = pfn_to_page(pfn); - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(pfn)) return; - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) + folio = page_folio(pfn_to_page(pfn)); + if (!test_and_set_bit(PG_dcache_clean, &folio->flags)) dcache_wbinv_all(); - if (page_mapping_file(page)) { + if (folio_flush_mapping(folio)) { if (vma->vm_flags & VM_EXEC) icache_inv_all(); } diff --git a/arch/csky/abiv1/inc/abi/cacheflush.h b/arch/csky/abiv1/inc/abi/cacheflush.h index ed62e2066ba7..0d6cb65624c4 100644 --- a/arch/csky/abiv1/inc/abi/cacheflush.h +++ b/arch/csky/abiv1/inc/abi/cacheflush.h @@ -9,6 +9,8 @@ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 extern void flush_dcache_page(struct page *); +void flush_dcache_folio(struct folio *); +#define flush_dcache_folio flush_dcache_folio #define flush_cache_mm(mm) dcache_wbinv_all() #define flush_cache_page(vma, page, pfn) cache_wbinv_all() diff --git a/arch/csky/abiv2/cacheflush.c b/arch/csky/abiv2/cacheflush.c index 9923cd24db58..d05a551af5d5 100644 --- a/arch/csky/abiv2/cacheflush.c +++ b/arch/csky/abiv2/cacheflush.c @@ -7,32 +7,32 @@ #include #include -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, - pte_t *pte) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *pte, unsigned int nr) { - unsigned long addr; - struct page *page; + unsigned long pfn = pte_pfn(*pte); + struct folio *folio; + unsigned int i; flush_tlb_page(vma, address); - if (!pfn_valid(pte_pfn(*pte))) + if (!pfn_valid(pfn)) return; - page = pfn_to_page(pte_pfn(*pte)); - if (page == ZERO_PAGE(0)) - return; + folio = page_folio(pfn_to_page(pfn)); - if (test_and_set_bit(PG_dcache_clean, &page->flags)) + if (test_and_set_bit(PG_dcache_clean, &folio->flags)) return; - addr = (unsigned long) kmap_atomic(page); - - dcache_wb_range(addr, addr + PAGE_SIZE); + for (i = 0; i < folio_nr_pages(folio); i++) { + unsigned long addr = (unsigned long) kmap_local_folio(folio, + i * PAGE_SIZE); - if (vma->vm_flags & VM_EXEC) - icache_inv_range(addr, addr + PAGE_SIZE); - - kunmap_atomic((void *) addr); + dcache_wb_range(addr, addr + PAGE_SIZE); + if (vma->vm_flags & VM_EXEC) + icache_inv_range(addr, addr + PAGE_SIZE); + kunmap_local((void *) addr); + } } void flush_icache_deferred(struct mm_struct *mm) diff --git a/arch/csky/abiv2/inc/abi/cacheflush.h b/arch/csky/abiv2/inc/abi/cacheflush.h index a565e00c3f70..9c728933a776 100644 --- a/arch/csky/abiv2/inc/abi/cacheflush.h +++ b/arch/csky/abiv2/inc/abi/cacheflush.h @@ -18,11 +18,17 @@ #define PG_dcache_clean PG_arch_1 +static inline void flush_dcache_folio(struct folio *folio) +{ + if (test_bit(PG_dcache_clean, &folio->flags)) + clear_bit(PG_dcache_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 static inline void flush_dcache_page(struct page *page) { - if (test_bit(PG_dcache_clean, &page->flags)) - clear_bit(PG_dcache_clean, &page->flags); + flush_dcache_folio(page_folio(page)); } #define flush_dcache_mmap_lock(mapping) do { } while (0) diff --git a/arch/csky/include/asm/pgtable.h b/arch/csky/include/asm/pgtable.h index d4042495febc..42405037c871 100644 --- a/arch/csky/include/asm/pgtable.h +++ b/arch/csky/include/asm/pgtable.h @@ -28,6 +28,7 @@ #define pgd_ERROR(e) \ pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pmd_pfn(pmd) (pmd_phys(pmd) >> PAGE_SHIFT) #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT)) #define pte_clear(mm, addr, ptep) set_pte((ptep), \ @@ -90,7 +91,6 @@ static inline void set_pte(pte_t *p, pte_t pte) /* prevent out of order excution */ smp_mb(); } -#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval) static inline pte_t *pmd_page_vaddr(pmd_t pmd) { @@ -263,8 +263,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; extern void paging_init(void); -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, - pte_t *pte); +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *pte, unsigned int nr); +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ remap_pfn_range(vma, vaddr, pfn, size, prot) From patchwork Mon Jul 10 20:43: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: 13307653 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 C42E0EB64D9 for ; Mon, 10 Jul 2023 21:04:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37D0C8E0001; Mon, 10 Jul 2023 17:04:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32CBE8D0001; Mon, 10 Jul 2023 17:04:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21C498E0001; Mon, 10 Jul 2023 17:04:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1385A8D0001 for ; Mon, 10 Jul 2023 17:04:42 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C1B59160251 for ; Mon, 10 Jul 2023 21:04:41 +0000 (UTC) X-FDA: 80996931162.01.85DA072 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 3AB4EA001A for ; Mon, 10 Jul 2023 21:04:37 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l4H0Sp2I; dmarc=none; spf=none (imf25.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=1689023079; 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=5+4G9ihnAATxhE+mN/TPHluvKQf1KT1lzbSAkqtjj8A=; b=7n/XjNpbCYHT3U8HVVuX82vLAAvJdbmZKvfC0serCbMnqysK2Pi2IPTjHBc32LtXHTCcSE JtmkC9TcdoqngsiuaFtfFyGPiv5lv/IIge5/LsYp+rgbJUQSgyEl0Q5bRDxdkr8L6Lz6GU +bHqct95WlIYHBeND0IQfhAPFl6X7Jg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l4H0Sp2I; dmarc=none; spf=none (imf25.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=1689023079; a=rsa-sha256; cv=none; b=DhslxFkt5D6sCRIaYbLurdvciFDlcP4JGqNDcldYf3nlt5s29TgyVKgmtQ1CEDZoV2ZP2w bfR6mvbB+5SRBwhPIBilrfGwAfjM1rD1of1G7uLRF1/blqL6zjOEf04A07qpzN0aEwwt3k CvD/nUAHam5oIO/ndIQ/7n0la0kIrsk= 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=5+4G9ihnAATxhE+mN/TPHluvKQf1KT1lzbSAkqtjj8A=; b=l4H0Sp2I2O9RCZTb8AEFCido2i /8+Ddvb+sUKF9z6mUxpBDYoYWqmnn4aOWQoC7IexYAgrTe0or6WgViwvP1KZrum7pKC0NOyGJMjKc jS3v+NHyWt+f7/mkUsWrCpSYRHNryr7mAx2T4t4pn1KFR9CzjiR8sVoYxSpyp2I8S0LcdEgx28c8P FTRsQ/uuPuwZVhuPDfVoBpNPH5Htib4iP2kNco+O4QZOTn2boDt/9vMQrP9jZcj11dptab20jY6Vo gIYwsr6sUvBHhjFaYk8ylIhtnJewm+KSd+85pjtQ6UTRdq3blHrsC3Q/rhYDK9ngjZGucFuR3KFwq 4E6+Do7A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Euoz-H5; Mon, 10 Jul 2023 20:43:42 +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, Brian Cain , Mike Rapoport Subject: [PATCH v5 12/38] hexagon: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:13 +0100 Message-Id: <20230710204339.3554919-13-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3AB4EA001A X-Stat-Signature: huwz713pjcrorh665hquh3opgczqo7xp X-HE-Tag: 1689023077-903686 X-HE-Meta: U2FsdGVkX1+Y3GS9BUVpWsZjeolW0uJ/NBXWKmhMlGMqZnjzeBuxaoVLuAUZ1bwGHkm6F9epn4HmV27Srsb3Z3d2YJK82mKQaCfAjgITStJuiRvWyxefvGRYT2jsqtwa1ScaCji4ZV7ussjj3rfdHvNiWWA4PDG637j1I82Abk6Wr6w34t6MmgC7iuWAj2Hb9r1ePa78zZeME+vbx8/5i20oBRn5cM9dHHOX/TEpHzCOw/XcnhkedIwH/EtdurcoaQxOobbRTLAA5hgyEbjsURrl61Is+50BO09Rz2kURydayyYHlgoXtbAxPeg0LoAUCyddsxvg4jJxkC5tx7MFmkjm8kqWnbtNtPupi40Le0SRNP534k/AWUmmoJNSLJfli1p6WOnShVQu2U3H9LrKv8EdEgXM/BWbmJAfXyU/xMIVeD/hD2h+/E3I7OHEdt93ZgR6enk+MG/HE84hbrSn1Sbzmr2MScJXBRa7M3eAWNPKoE2R11BE3ogzBSF+DsgfktRNGruFpRR+cD5fcBhipqnZATlEvETyeDvo+qLd9kb4cjBWWqc413ugCgURFV5k+Hlyyg1xUywqVUNhcRKk2jMxGVn5r1BWC0OGxZ0CP0mcJUQ1DN+PA6TRIrbG2BvH/GGW4T8VYNEBF3ZEub4mYBTNtIn85P4jKDrhUu6La14oRBqPSK5EhdvqzjZdAKD+N8jNSEdqP8GbpXLdc0gFC2cJlr1Ja72xsoSB74SJDJLgLZQk5pRBePrxeo7tEgfaX4H338ZzmIohBC9ecUSWUS8L+h/3oIwr3B4eEOFF3VTMPmpzyDWwH8eVNFRkhp8TUt/NtersMSBQ6XQjz6I9FSdwUY+XOooVeFioYx4HCKxFtC9U1IFNy8uY1QgnZzd45+xyO/G6t8WROv6NhYA6SW4pmmDFI/VWmq+uHRaFXwN8CGnTrANLs0RKqRrEdPK1W/tmjzv19AIXMAIRUYc 7Jl8WSzS FoO2AYkApSiRqLMpIeieHEYKiXfI747oh7me8iR2DfbmwsdnPn67geNUzWoF/n3sRmAPv9iCFATs/OxVyPDGszsbAOxV0gKfk08L1mF00IVj+mcHw+CLH19MDWM3vQzEnP965qWrdDn19JKiifhRLg+xapfZd+3vHz+BCq5iBiYD8u+G8+L2c6LA2oRXBnARwU/MN0SGhtjFX7wKmrFeeUUToh8DXS++JkXbRmgZtIVeiTjc0JbjsKHs0qEOqptT7ztDYhDHQbLEIxY3H1HaP6wG5eP5rhELTSLIMX4N0B/3eckA= 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: Add PFN_PTE_SHIFT and update_mmu_cache_range(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Brian Cain Acked-by: Mike Rapoport (IBM) --- arch/hexagon/include/asm/cacheflush.h | 8 ++++++-- arch/hexagon/include/asm/pgtable.h | 9 +-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/arch/hexagon/include/asm/cacheflush.h b/arch/hexagon/include/asm/cacheflush.h index 6eff0730e6ef..dc3f500a5a01 100644 --- a/arch/hexagon/include/asm/cacheflush.h +++ b/arch/hexagon/include/asm/cacheflush.h @@ -58,12 +58,16 @@ extern void flush_cache_all_hexagon(void); * clean the cache when the PTE is set. * */ -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { /* generic_ptrace_pokedata doesn't wind up here, does it? */ } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, void *src, int len); #define copy_to_user_page copy_to_user_page diff --git a/arch/hexagon/include/asm/pgtable.h b/arch/hexagon/include/asm/pgtable.h index 59393613d086..dd05dd71b8ec 100644 --- a/arch/hexagon/include/asm/pgtable.h +++ b/arch/hexagon/include/asm/pgtable.h @@ -338,6 +338,7 @@ static inline int pte_exec(pte_t pte) /* __swp_entry_to_pte - extract PTE from swap entry */ #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) +#define PFN_PTE_SHIFT PAGE_SHIFT /* pfn_pte - convert page number and protection value to page table entry */ #define pfn_pte(pfn, pgprot) __pte((pfn << PAGE_SHIFT) | pgprot_val(pgprot)) @@ -345,14 +346,6 @@ static inline int pte_exec(pte_t pte) #define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval)) -/* - * set_pte_at - update page table and do whatever magic may be - * necessary to make the underlying hardware/firmware take note. - * - * VM may require a virtual instruction to alert the MMU. - */ -#define set_pte_at(mm, addr, ptep, pte) set_pte(ptep, pte) - static inline unsigned long pmd_page_vaddr(pmd_t pmd) { return (unsigned long)__va(pmd_val(pmd) & PAGE_MASK); From patchwork Mon Jul 10 20:43:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307603 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 596D2EB64DA for ; Mon, 10 Jul 2023 20:43:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 952758E0008; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DA7B8E0007; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72CC88E0008; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4E6298E0001 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F05CB16024D for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) X-FDA: 80996878452.24.260E292 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 3B32C40009 for ; Mon, 10 Jul 2023 20:43:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dGHT51LM; dmarc=none; spf=none (imf04.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=1689021825; 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=5gt+3Xe9De1Yff1oJDu3SmVusJ4BF3xtLN8hDiFU6E0=; b=0mMuzwhJ7eVJPbKjan3gitgZ8hvAwfkEGn+XJ6RVbi7dNvrq00Mrxm8jDW6fRCaLlTgnS+ 1d7PrPGffV01Y/723XIouQgntzUZzdPJDzhCBKy3u4Fn0/lI35KayOaPnSTJb3Kypx4pOE zpm0DMvZ5GmhhFvzR+BJvlYvJuErXeY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dGHT51LM; dmarc=none; spf=none (imf04.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=1689021825; a=rsa-sha256; cv=none; b=FQLcQQHZM2bcHmRGX0EfM1YdYHnacJm+SLbvHTWgpXT0kiOQlDgXalmpbZnJJfKPoKpf5P E7Wclsc9A0+jiXQCC6lXEvxqPZ1AqlpC9mY/CcaUfkMzu8Rcd5Pzq5cI5+Uny9oqa/PuVl e7YPQQw4hL8y8i/rOkQhLgca1D8ktaU= 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=5gt+3Xe9De1Yff1oJDu3SmVusJ4BF3xtLN8hDiFU6E0=; b=dGHT51LMU6SlQXei6rkZXyExJi p1aFtkyf4pEDSYgYiZ/k2gJQpuEtvPQuWOrzfE7rqxmCY0lOiBf3KNuaByGkvb2JKVrxNOYDk8HKJ x2pM848J4epxGkcJGcefxsEHJvwSCEM8aHiumMhIWD4J9OGQsVh1o0gsIDgaK84JaxtSxWw0T+CiQ NnV5uJ372hxvssehPX0qG4WVDx0cELUoDYmiZtlfScLXJ1WqS0llR5Pe7y5/k9vifGRLPvc4zSYwB M6HPvdZ3lv6t+Uhrhjy1GY7lCRbQfjPaADhpVyNLhzYU2zL/7VO3wz1rFSy0dNv1bMtGw9xIMEZ2k GaMyVtIg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Eup5-Kh; Mon, 10 Jul 2023 20:43:42 +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 , linux-ia64@vger.kernel.org Subject: [PATCH v5 13/38] ia64: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:14 +0100 Message-Id: <20230710204339.3554919-14-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: 3B32C40009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 56yoi5e573g19gitjaskqgtumnnbufha X-HE-Tag: 1689021824-443703 X-HE-Meta: U2FsdGVkX1+w3GPtNTgOGNPYjFpX0NL+fWHvfunsc15zc8Ifp4kdmhZs58cJrA9AQ27pfp8uNYlkv/6af62N93Am7aFrUKjDlSuCo6gVtpp8OT0qtRS5YdK+6TRZpybz2w9b2cBsczAcbh4Fj6sGIZT3QhO/vtp1ZWrF4LrkwyNpPdHNMFbSMRz4cWlMjLZcpeP6p72xFGHO7HkV5yU4xG6OlTZw/+oI+c4wSAlmih36kBKxxSao/u36zPfMmc0rzmZwbGn35MZkM6SsIOAn4Ap6Cb61l3bp41tOPDfY5/q1vn8K+buf1G7uzzAKQFLBGWXyLy0UvA8MvbX0lYQJgu+oq/NQ6PlD2mTrs2vuiqmTKZdUAWzV9NgG6GOFTlkJzQhn7025fnOU5t4FKe1gXJobEgdoVr9T80bMZDQ/pUQJvGHp0HaYFQBGHjheiuRTmMNKFxEO6P7DWbqKMPPP9XOWNDYIL6sZEsAEGgL8os+pTg7dR86hE81BGwsyexcFcfcC9EB8zXp9meEniLb2cwHhVhpshjov5esoMHluugPkuv32NrxhYSg+31BLa3xO/ul56k5tK+ufRgI8xqQzNsvwRUie6A5MiQ0GNFmUQetEqvmr9yi24A/XqewAag5hUyrKiyIFt9oHhYjBy0BcivqcZz5TJivn6ExfOFNp46d9S7XvHVHUubXG6JUg5U5wI/pQqY08SejlN5lScNrUkik6yWRR8D61ZqBPGmpc4ZjUhL2xwBjpQacG0dK1zs17esfnrYeGM53wMLqy2IZZ58sf3SlX4V3lUAFWVr6uFExkjGVOAfrZPkSSvC7DrFm9yfCr07px9H7x2pcmkZYjN07dWBfsle6Fhixdkwup/Wxeq2X6Bmlt7W3T71md/jrS1gcCUWnWeodcPguGu5hSi4E1B2XYdXWDeVDoFbiVlfXk1LA6Pkd6ScW/mAmtxCfHs8jxkSuxJ3XH7D8T6PK XJBrg6P7 eN2ouK8zTM9TJnZVDXwOGxIhT6HsBxABSTwDwzAVrSLuQJf8cWmQHnkmSLOL6a3JQGLPDYo+7VYf/1/TEdlrHkIcmea/Y76Wbb/vmPXCtrFQatprhfRLS/W2kcvKIyWY/eTs+GyC0pRA5Y8llGsllF7uI5U3Jyagx4jDBuu9DjW3pm4pubjNFPLnjxYBG+7CNFLOJOVNCbHAzFmo32XGmhkW1u23ElsfdJnfpriqWMWNseMoHzQvAaFgmIw== 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: Add PFN_PTE_SHIFT, update_mmu_cache_range() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_clean) flag from being per-page to per-folio, which makes arch_dma_mark_clean() and mark_clean() a little more exciting. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: linux-ia64@vger.kernel.org --- arch/ia64/hp/common/sba_iommu.c | 26 +++++++++++++++----------- arch/ia64/include/asm/cacheflush.h | 14 ++++++++++---- arch/ia64/include/asm/pgtable.h | 4 ++-- arch/ia64/mm/init.c | 28 +++++++++++++++++++--------- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c index 8ad6946521d8..48d475f10003 100644 --- a/arch/ia64/hp/common/sba_iommu.c +++ b/arch/ia64/hp/common/sba_iommu.c @@ -798,22 +798,26 @@ sba_io_pdir_entry(u64 *pdir_ptr, unsigned long vba) #endif #ifdef ENABLE_MARK_CLEAN -/** +/* * Since DMA is i-cache coherent, any (complete) pages that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ -static void -mark_clean (void *addr, size_t size) +static void mark_clean(void *addr, size_t size) { - unsigned long pg_addr, end; - - pg_addr = PAGE_ALIGN((unsigned long) addr); - end = (unsigned long) addr + size; - while (pg_addr + PAGE_SIZE <= end) { - struct page *page = virt_to_page((void *)pg_addr); - set_bit(PG_arch_1, &page->flags); - pg_addr += PAGE_SIZE; + struct folio *folio = virt_to_folio(addr); + ssize_t left = size; + size_t offset = offset_in_folio(folio, addr); + + if (offset) { + left -= folio_size(folio) - offset; + folio = folio_next(folio); + } + + while (left >= folio_size(folio)) { + set_bit(PG_arch_1, &folio->flags); + left -= folio_size(folio); + folio = folio_next(folio); } } #endif diff --git a/arch/ia64/include/asm/cacheflush.h b/arch/ia64/include/asm/cacheflush.h index 708c0fa5d975..eac493fa9e0d 100644 --- a/arch/ia64/include/asm/cacheflush.h +++ b/arch/ia64/include/asm/cacheflush.h @@ -13,10 +13,16 @@ #include #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page(page) \ -do { \ - clear_bit(PG_arch_1, &(page)->flags); \ -} while (0) +static inline void flush_dcache_folio(struct folio *folio) +{ + clear_bit(PG_arch_1, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} extern void flush_icache_range(unsigned long start, unsigned long end); #define flush_icache_range flush_icache_range diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h index 21c97e31a28a..4e5dd800ce1f 100644 --- a/arch/ia64/include/asm/pgtable.h +++ b/arch/ia64/include/asm/pgtable.h @@ -206,6 +206,7 @@ ia64_phys_addr_valid (unsigned long addr) #define RGN_MAP_SHIFT (PGDIR_SHIFT + PTRS_PER_PGD_SHIFT - 3) #define RGN_MAP_LIMIT ((1UL << RGN_MAP_SHIFT) - PAGE_SIZE) /* per region addr limit */ +#define PFN_PTE_SHIFT PAGE_SHIFT /* * Conversion functions: convert page frame number (pfn) and a protection value to a page * table entry (pte). @@ -303,8 +304,6 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) - /* * Make page protection values cacheable, uncacheable, or write- * combining. Note that "protection" is really a misnomer here as the @@ -396,6 +395,7 @@ pte_same (pte_t a, pte_t b) return pte_val(a) == pte_val(b); } +#define update_mmu_cache_range(vmf, vma, address, ptep, nr) do { } while (0) #define update_mmu_cache(vma, address, ptep) do { } while (0) extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c index 7f5353e28516..b95debabdc2a 100644 --- a/arch/ia64/mm/init.c +++ b/arch/ia64/mm/init.c @@ -50,30 +50,40 @@ void __ia64_sync_icache_dcache (pte_t pte) { unsigned long addr; - struct page *page; + struct folio *folio; - page = pte_page(pte); - addr = (unsigned long) page_address(page); + folio = page_folio(pte_page(pte)); + addr = (unsigned long)folio_address(folio); - if (test_bit(PG_arch_1, &page->flags)) + if (test_bit(PG_arch_1, &folio->flags)) return; /* i-cache is already coherent with d-cache */ - flush_icache_range(addr, addr + page_size(page)); - set_bit(PG_arch_1, &page->flags); /* mark page as clean */ + flush_icache_range(addr, addr + folio_size(folio)); + set_bit(PG_arch_1, &folio->flags); /* mark page as clean */ } /* - * Since DMA is i-cache coherent, any (complete) pages that were written via + * Since DMA is i-cache coherent, any (complete) folios that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ void arch_dma_mark_clean(phys_addr_t paddr, size_t size) { unsigned long pfn = PHYS_PFN(paddr); + struct folio *folio = page_folio(pfn_to_page(pfn)); + ssize_t left = size; + size_t offset = offset_in_folio(folio, paddr); - do { + if (offset) { + left -= folio_size(folio) - offset; + folio = folio_next(folio); + } + + while (left >= (ssize_t)folio_size(folio)) { set_bit(PG_arch_1, &pfn_to_page(pfn)->flags); - } while (++pfn <= PHYS_PFN(paddr + size - 1)); + left -= folio_size(folio); + folio = folio_next(folio); + } } inline void From patchwork Mon Jul 10 20:43:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307609 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 DCC37C001B0 for ; Mon, 10 Jul 2023 20:44:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 011C88E000A; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C35FD8E000C; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F7BF8E000E; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0606B8E000B for ; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D4DA0A0286 for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.19.0248B40 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 3CAEBC0013 for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QnpOdXIt; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021826; 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=xDSJ2LI5HRZuClnGzt1hdoG45riL6n6McweKjX1Jt7o=; b=V8PSn0qUti2m6q0xaE+q3gx+q+XNx7Z/jo9LK3Lz+E025PE4/Qadgz5w++oN4DD8c+r/bm 5FlMc/+iQMgMip0inIue9DYqNS+izODeJzD394eEdSfZGHk5qLVtCDy7DSt/ghhuZj06mD fK9Q3Gjb/sWzR1olGjBaimB7P7bhirE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021826; a=rsa-sha256; cv=none; b=G3b9XAhZqFoSm3sHKvsGC2MvefoRjOo+Eg5USdjKfl6EJmkXLqrrcdF0yk1LG26EURUt8S G9N5wpQFiq+6vlwYUlDaBifBJoRzAV7z1lwIbyzKx1U2LnHTBIjjGA2pt7gD3/Nij2q1ir F3lqG7SFuzlF/BDw5RTt8V6acqQ/Ml0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QnpOdXIt; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=xDSJ2LI5HRZuClnGzt1hdoG45riL6n6McweKjX1Jt7o=; b=QnpOdXItCSyXnIcQN4lLoMCi9G APaag4+NpG4VceTEAmfTs2AOr/sDMZ9JgR+lDE7sfAZT/YiLnVm22GAjpbaGpR8xtfeOhQzCMjKl1 r0gg/00IPWfEt6lwVEPvjMR1uhgVz+a2WkI9MD+ql+GK0Oc82um2HYSxnWMhQSpOszmb3/OWThI0C d8GUGPnQzwS9007VurYnDf3NiHRiSoR6hTvrTPW3iDyRonBG5R0gD2+fLJX63iJSMNgdxcjw6L0Mu 7S57uDsLbv1vM8m1P2Op8/b5WltnHiilk1ZZXyNsfar3UJejwaHfmnxtaK4ql6GgGTXpTZDklziHi ovW2HfbA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00EupA-Nc; Mon, 10 Jul 2023 20:43:42 +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 , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev Subject: [PATCH v5 14/38] loongarch: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:15 +0100 Message-Id: <20230710204339.3554919-15-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: 3CAEBC0013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: xkr7u363aqidan5wkoqthntzhneof8eo X-HE-Tag: 1689021825-265215 X-HE-Meta: U2FsdGVkX1+69nSHvWWicbcXfO4nyUa+tW1ZJ+2P5w9YwCkiqahgLPalBj37RJ9vvR1Jwc0xXopLnTz1IemtoxSMZrjd7hpJBQbel3u+vUiUSbLR4hmVPEhY4sYdwvmKNgroNpoYNqqsLcy2/jH4Fjw7XHOe+CJbsjNcKPybRHouArdtPfvN1x+JkEzKFGuIUxOx0SK2iSVg3qw5xhfQFvfJiRSs2Se0qVCSBbbygqp5bMvbhJC2JgTwaZE8I33i/S9s8cgzkJyzhaIcnY+RVmwUyBTcjax8TEODGGhlO1kGZUmMdouJCw/QewuAC9nuQCXDgZI5A/MWLZRjMNyrPidFBuRvzUFe0cuGoR2AR6fyAZUDgx0qAvhwQtAe8VI7OPYeaquPRnabYh2WVbe1vOSU2KvnTN2wWX4pDhGi0N8uo7dbP7OFDk1Z6nVE5HQY4dQdGuOlp1lGy+BKAsHnN1VoVg91x1vwg8tdewXhr64rUIuOdNY953kPwkOc4Icr/yu5TJC0/7zrBFMV1NgSulJmZoyT5DqNEjiEbkCf8O4W+uZKrju/p9837wHRjEVlmYlTkFj7Qn+PwXxcB2OaEGPgZX/oTTnOaLypEcQg8vPaJbxDDzFm1n7ZVvYrrGvVVt/c9D5RPxI3aODhn7npy0K4W16ZrPqQKWlF64NOTvCzQfnN9kewbLOOtS1mSjB70xd05n4UQNyO/I4Wjl+Oc9fi4sj7Oz8b8jPhR09BH9NJ6px5J2UcQyIDLBdVeerKQGvARzNmsjaWSbMRcLqlzjJxMdMZK9I0B8tpIKeSlYemFn76UBhZk5nuwc7uU9gaavmOmPdm7iKIzMKXkyQwW5hEjxpLu8d47mbtoCtnZTNk+sNhe+h3+loJ7dp2EL/Tt07oCZpdOX14wzFMmZKBSxp9cyz/hQOYGDj5kIyv+bz3mV6VtqaM3P1lBB4YchAOCb72qTQcueJZ7/Jf9ec RXuNnEKm qFCS9MyGmAGF3BbylQzXNEfGtYL+vPX3oftl8eefxrAnDdCH863qcv1GQPwY5bo/J0nAZBKS38cd72QhuYgMENsvcZrt018ktzSRPm3DOWhU/tcfi4quBH0tDtnPSKHRCRbUeHlZvHXzwczKykz64b4WZ+DDxalWweWAlAAdPvO5Dlwuf4N3P2awg570iiOBZg9XioWcFtHdBImkZsvygJ+L/Vzs7h5AIpFgnrKRVZrBL09yO73o8hK+6Pw== 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: Add update_mmu_cache_range() and change _PFN_SHIFT to PFN_PTE_SHIFT. It would probably be more efficient to implement __update_tlb() by flushing the entire folio instead of calling __update_tlb() N times, but I'll leave that for someone who understands the architecture better. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Huacai Chen Cc: WANG Xuerui Cc: loongarch@lists.linux.dev --- arch/loongarch/include/asm/cacheflush.h | 1 + arch/loongarch/include/asm/pgtable-bits.h | 4 +-- arch/loongarch/include/asm/pgtable.h | 33 ++++++++++++----------- arch/loongarch/mm/pgtable.c | 2 +- arch/loongarch/mm/tlb.c | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/arch/loongarch/include/asm/cacheflush.h b/arch/loongarch/include/asm/cacheflush.h index 0681788eb474..88a44da50a3b 100644 --- a/arch/loongarch/include/asm/cacheflush.h +++ b/arch/loongarch/include/asm/cacheflush.h @@ -47,6 +47,7 @@ void local_flush_icache_range(unsigned long start, unsigned long end); #define flush_cache_vmap(start, end) do { } while (0) #define flush_cache_vunmap(start, end) do { } while (0) #define flush_icache_page(vma, page) do { } while (0) +#define flush_icache_pages(vma, page) do { } while (0) #define flush_icache_user_page(vma, page, addr, len) do { } while (0) #define flush_dcache_page(page) do { } while (0) #define flush_dcache_mmap_lock(mapping) do { } while (0) diff --git a/arch/loongarch/include/asm/pgtable-bits.h b/arch/loongarch/include/asm/pgtable-bits.h index de46a6b1e9f1..35348d4c4209 100644 --- a/arch/loongarch/include/asm/pgtable-bits.h +++ b/arch/loongarch/include/asm/pgtable-bits.h @@ -50,12 +50,12 @@ #define _PAGE_NO_EXEC (_ULCAST_(1) << _PAGE_NO_EXEC_SHIFT) #define _PAGE_RPLV (_ULCAST_(1) << _PAGE_RPLV_SHIFT) #define _CACHE_MASK (_ULCAST_(3) << _CACHE_SHIFT) -#define _PFN_SHIFT (PAGE_SHIFT - 12 + _PAGE_PFN_SHIFT) +#define PFN_PTE_SHIFT (PAGE_SHIFT - 12 + _PAGE_PFN_SHIFT) #define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT) #define _PAGE_KERN (PLV_KERN << _PAGE_PLV_SHIFT) -#define _PFN_MASK (~((_ULCAST_(1) << (_PFN_SHIFT)) - 1) & \ +#define _PFN_MASK (~((_ULCAST_(1) << (PFN_PTE_SHIFT)) - 1) & \ ((_ULCAST_(1) << (_PAGE_PFN_END_SHIFT)) - 1)) /* diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index 38afeb7dd58b..e7cf25e452c0 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -237,9 +237,9 @@ extern pmd_t mk_pmd(struct page *page, pgprot_t prot); extern void set_pmd_at(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd); #define pte_page(x) pfn_to_page(pte_pfn(x)) -#define pte_pfn(x) ((unsigned long)(((x).pte & _PFN_MASK) >> _PFN_SHIFT)) -#define pfn_pte(pfn, prot) __pte(((pfn) << _PFN_SHIFT) | pgprot_val(prot)) -#define pfn_pmd(pfn, prot) __pmd(((pfn) << _PFN_SHIFT) | pgprot_val(prot)) +#define pte_pfn(x) ((unsigned long)(((x).pte & _PFN_MASK) >> PFN_PTE_SHIFT)) +#define pfn_pte(pfn, prot) __pte(((pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) +#define pfn_pmd(pfn, prot) __pmd(((pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) /* * Initialize a new pgd / pud / pmd table with invalid pointers. @@ -334,19 +334,13 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) } } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval) -{ - set_pte(ptep, pteval); -} - static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { /* Preserve global status for the pair */ if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL) - set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL)); + set_pte(ptep, __pte(_PAGE_GLOBAL)); else - set_pte_at(mm, addr, ptep, __pte(0)); + set_pte(ptep, __pte(0)); } #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1) @@ -445,11 +439,20 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) extern void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep); -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { - __update_tlb(vma, address, ptep); + for (;;) { + __update_tlb(vma, address, ptep); + if (--nr == 0) + break; + address += PAGE_SIZE; + ptep++; + } } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define __HAVE_ARCH_UPDATE_MMU_TLB #define update_mmu_tlb update_mmu_cache @@ -462,7 +465,7 @@ static inline void update_mmu_cache_pmd(struct vm_area_struct *vma, static inline unsigned long pmd_pfn(pmd_t pmd) { - return (pmd_val(pmd) & _PFN_MASK) >> _PFN_SHIFT; + return (pmd_val(pmd) & _PFN_MASK) >> PFN_PTE_SHIFT; } #ifdef CONFIG_TRANSPARENT_HUGEPAGE diff --git a/arch/loongarch/mm/pgtable.c b/arch/loongarch/mm/pgtable.c index 36a6dc0148ae..1260cf30e3ee 100644 --- a/arch/loongarch/mm/pgtable.c +++ b/arch/loongarch/mm/pgtable.c @@ -107,7 +107,7 @@ pmd_t mk_pmd(struct page *page, pgprot_t prot) { pmd_t pmd; - pmd_val(pmd) = (page_to_pfn(page) << _PFN_SHIFT) | pgprot_val(prot); + pmd_val(pmd) = (page_to_pfn(page) << PFN_PTE_SHIFT) | pgprot_val(prot); return pmd; } diff --git a/arch/loongarch/mm/tlb.c b/arch/loongarch/mm/tlb.c index 00bb563e3c89..eb8572e201ea 100644 --- a/arch/loongarch/mm/tlb.c +++ b/arch/loongarch/mm/tlb.c @@ -252,7 +252,7 @@ static void output_pgtable_bits_defines(void) pr_define("_PAGE_WRITE_SHIFT %d\n", _PAGE_WRITE_SHIFT); pr_define("_PAGE_NO_READ_SHIFT %d\n", _PAGE_NO_READ_SHIFT); pr_define("_PAGE_NO_EXEC_SHIFT %d\n", _PAGE_NO_EXEC_SHIFT); - pr_define("_PFN_SHIFT %d\n", _PFN_SHIFT); + pr_define("PFN_PTE_SHIFT %d\n", PFN_PTE_SHIFT); pr_debug("\n"); } From patchwork Mon Jul 10 20:43:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307618 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 27FC1EB64D9 for ; Mon, 10 Jul 2023 20:44:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FEA08E0012; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99F9F8E0015; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72FC08E0012; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 35ED88E0014 for ; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 03D8A80258 for ; Mon, 10 Jul 2023 20:43:50 +0000 (UTC) X-FDA: 80996878620.30.B5D7139 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 5580F1C0011 for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Cvh1UbtT; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021828; 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=3eckwhASlJ5kB1LQ/if3Fo0Hxrj5Tti58CwpH+WVOLg=; b=ggo8ZOUOhFrqp0rPVrub+4tGHJwv0CpqgbB6pwFhfnJHQkhMyMAaBqX2ENjFZodJHy6d7w 9SqWFJRE3bcgFyOHEOfsZwmsVJW9dUSnhdqunQIw9NzwnU8i+V4l3ujACKMGU53CjJbA0I TkteUVesPGU1KgKys0+U/IGyC0wA38I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021828; a=rsa-sha256; cv=none; b=g3Ak1BWLAelnev7iJ14zOuCqSPjExgck3YFAxpEBJ/xFZA6GeC6P1SIJ7eKNBgkBe+v0Z5 HxgPU10AA61jYlR1QQWC4F8r/EPD+mYm7s197ET3Fj0X7wZECPmyz8ftLUjlYqcxllPE/I 1xeZ2xtDDjXvB026JVui/NSyOaCtn14= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Cvh1UbtT; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=3eckwhASlJ5kB1LQ/if3Fo0Hxrj5Tti58CwpH+WVOLg=; b=Cvh1UbtToEDk9/QV9A82rA+pgO ZTVGf7qezP8ORX82Pd9066sJeOM5dE7LJVSdU72VBPOJJePCnnmx2XPj4ovyJ6l2tseqYrpT30eCK U+OfkAb85sMFzp4gY6kAmZ3KHrVUGYUv1fcbj6hZfNkAAMJWS9kq6rLqMWHlXH3D8AU8Y4Fzo2ksa rYBNjIHm+ngWuRRZxot/g5zHA3FmaazW2bANzxCp7m6yvQvNfshhbM4XpxK/qAQ9ssoe/TgzTYC2B 1gy6zazOwafB2OLz5giRT6S2BdKpDM2fRB9CnJTd+dM1btzR+GYIvpVPyQG3p8ZOUcLjb7krJ5nyw 9ExiL9KQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00EupG-Rz; Mon, 10 Jul 2023 20:43:42 +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, Geert Uytterhoeven , Mike Rapoport , linux-m68k@lists.linux-m68k.org Subject: [PATCH v5 15/38] m68k: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:16 +0100 Message-Id: <20230710204339.3554919-16-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: 5580F1C0011 X-Rspam-User: X-Stat-Signature: x9nqh8jiyhm34fn6enn6k6p6gc9h89th X-Rspamd-Server: rspam03 X-HE-Tag: 1689021827-296206 X-HE-Meta: U2FsdGVkX19huY5qklNdx2RmK8dOEY/rlPk+TfGtWasVLi48FQxi2E873K4JkrDdHtgrgnZVL/xy+HA3ZB8FZCUMDqFs9bbyGJn5nSKZoRVpRPIXYQoV1Ubr7mnH7a4bQ3PIdtlj3xoYIzC0bN/PsYJU9iKh6Cm8XJollagazQfRsCVBDG8gZIzo46n/T3wicB6CsOFbWTzXcSMZtWTi7JboVEeZX86aI9/HsmtPsxOalMoNNJfcWeuEPu29wKiTS6N2hYTDSXmkeSc90PJNUaz9ZiQFGY10F17LAxJIziq1xMMfM+b7l9eedEXFcbFkvLsPgnnjBHDtwG2wE5H8+s72NAZ6/HH5p6STFJlcWXBUanuLMcMKlE4yHqWHldK3nx90WhAtne04IQeuP5inegYTSfjrfXOVWl6oXjUZU8Ol1KooQ2Bz5mfxYr7eD5gDHB2RAYNUz1aiGMgIBsTLGyZhb9OmRrY9vdVTiVZEEFpejHT+u0wL2BxLU6T7x2Rn8e/gYX5zrKwRu52DWba3PNrMeflLVmygReC01pdCXDdpmdzo1yU6lJDXaaXBQZOcNZQeCdKoraqeiCHGIEVDwR8+zgbiU7TXWo9DE/EEX5c48Vhdj+HTaWugOlP7+O6MN2djD6+YS5OYMZhRvgyeUZ2RniyKzlC1tJhDF2dF5tg2drf3DvyFN7xedQ8a4eniOkwPjSAq48W6WaduW0JLAbZJhno1UUSgjWFMTsM26UuV6Pbvyt+cUDY5q6umeorHpcYqIRn8mICf86lqrtUikaideroZr63K5yp+Fycva/a8RJzNRZtfkAWOWwiJV+2zUUDGqncuA0NZkzkMEzkPajfZclSihyEDyUQSJ2eKJkuPnsXaHzq+m0Y1OPw9O5xKEChbiX9MXPpu6aXKPB1FY/TQsx+OZHmdamwpAqddR513NlTm8FVvvmjzXbFf0W/if/JN/47RXbw48knXOVg 6Owsvx3Q DGiNm57Kdhd1QjhyjJR5HDlxJZyqFcX75Wi2eURtSIvVYTnGHSwB2DsDlmYLl/J49/0P1plu1OzMWtltF+95ErUxg37eKKM4OeZOq+219qgpYStqTt2QKgzfyzP2do0rEveniFac0dUee7etyubWjJOKMa9K155tR88tVY5AdXrIvNC7pEGVc36S7pzNjxZXwMkfNnWd02N36wP5uWc5nP6jARMjkTEtcw030LnkQUvg1QFhg0toTLBdG1kZY6rUTDxuEVyiU8ldIOWXQpyn+6K/aPut4QR3kaU2Fb8f72N1xP4Q= 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: Add PFN_PTE_SHIFT, update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Signed-off-by: Matthew Wilcox (Oracle) Tested-by: Geert Uytterhoeven Acked-by: Mike Rapoport (IBM) Cc: linux-m68k@lists.linux-m68k.org --- arch/m68k/include/asm/cacheflush_mm.h | 27 ++++++++++++++++-------- arch/m68k/include/asm/mcf_pgtable.h | 1 + arch/m68k/include/asm/motorola_pgtable.h | 1 + arch/m68k/include/asm/pgtable_mm.h | 10 +++++---- arch/m68k/include/asm/sun3_pgtable.h | 1 + arch/m68k/mm/motorola.c | 2 +- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/arch/m68k/include/asm/cacheflush_mm.h b/arch/m68k/include/asm/cacheflush_mm.h index 1ac55e7b47f0..88eb85e81ef6 100644 --- a/arch/m68k/include/asm/cacheflush_mm.h +++ b/arch/m68k/include/asm/cacheflush_mm.h @@ -220,24 +220,29 @@ static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm /* Push the page at kernel virtual address and clear the icache */ /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */ -static inline void __flush_page_to_ram(void *vaddr) +static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr) { if (CPU_IS_COLDFIRE) { unsigned long addr, start, end; addr = ((unsigned long) vaddr) & ~(PAGE_SIZE - 1); start = addr & ICACHE_SET_MASK; - end = (addr + PAGE_SIZE - 1) & ICACHE_SET_MASK; + end = (addr + nr * PAGE_SIZE - 1) & ICACHE_SET_MASK; if (start > end) { flush_cf_bcache(0, end); end = ICACHE_MAX_ADDR; } flush_cf_bcache(start, end); } else if (CPU_IS_040_OR_060) { - __asm__ __volatile__("nop\n\t" - ".chip 68040\n\t" - "cpushp %%bc,(%0)\n\t" - ".chip 68k" - : : "a" (__pa(vaddr))); + unsigned long paddr = __pa(vaddr); + + do { + __asm__ __volatile__("nop\n\t" + ".chip 68040\n\t" + "cpushp %%bc,(%0)\n\t" + ".chip 68k" + : : "a" (paddr)); + paddr += PAGE_SIZE; + } while (--nr); } else { unsigned long _tmp; __asm__ __volatile__("movec %%cacr,%0\n\t" @@ -249,10 +254,14 @@ static inline void __flush_page_to_ram(void *vaddr) } #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page(page) __flush_page_to_ram(page_address(page)) +#define flush_dcache_page(page) __flush_pages_to_ram(page_address(page), 1) +#define flush_dcache_folio(folio) \ + __flush_pages_to_ram(folio_address(folio), folio_nr_pages(folio)) #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) -#define flush_icache_page(vma, page) __flush_page_to_ram(page_address(page)) +#define flush_icache_pages(vma, page, nr) \ + __flush_pages_to_ram(page_address(page), nr) +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) extern void flush_icache_user_page(struct vm_area_struct *vma, struct page *page, unsigned long addr, int len); diff --git a/arch/m68k/include/asm/mcf_pgtable.h b/arch/m68k/include/asm/mcf_pgtable.h index 43e8da8465f9..772b7e7b0654 100644 --- a/arch/m68k/include/asm/mcf_pgtable.h +++ b/arch/m68k/include/asm/mcf_pgtable.h @@ -291,6 +291,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) return pte; } +#define PFN_PTE_SHIFT PAGE_SHIFT #define pmd_pfn(pmd) (pmd_val(pmd) >> PAGE_SHIFT) #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)) diff --git a/arch/m68k/include/asm/motorola_pgtable.h b/arch/m68k/include/asm/motorola_pgtable.h index ec0dc19ab834..38d5e5edc3e1 100644 --- a/arch/m68k/include/asm/motorola_pgtable.h +++ b/arch/m68k/include/asm/motorola_pgtable.h @@ -112,6 +112,7 @@ static inline void pud_set(pud_t *pudp, pmd_t *pmdp) #define pte_present(pte) (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE)) #define pte_clear(mm,addr,ptep) ({ pte_val(*(ptep)) = 0; }) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pte_page(pte) virt_to_page(__va(pte_val(pte))) #define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot)) diff --git a/arch/m68k/include/asm/pgtable_mm.h b/arch/m68k/include/asm/pgtable_mm.h index b93c41fe2067..dbdf1c2b2f66 100644 --- a/arch/m68k/include/asm/pgtable_mm.h +++ b/arch/m68k/include/asm/pgtable_mm.h @@ -31,8 +31,6 @@ do{ \ *(pteptr) = (pteval); \ } while(0) -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) - /* PMD_SHIFT determines the size of the area a second-level page table can map */ #if CONFIG_PGTABLE_LEVELS == 3 @@ -138,11 +136,15 @@ extern void kernel_set_cachemode(void *addr, unsigned long size, int cmode); * tables contain all the necessary information. The Sun3 does, but * they are updated on demand. */ -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + #endif /* !__ASSEMBLY__ */ /* MMU-specific headers */ diff --git a/arch/m68k/include/asm/sun3_pgtable.h b/arch/m68k/include/asm/sun3_pgtable.h index 9e7bf8a5f8f8..0cc39a88ce55 100644 --- a/arch/m68k/include/asm/sun3_pgtable.h +++ b/arch/m68k/include/asm/sun3_pgtable.h @@ -105,6 +105,7 @@ static inline void pte_clear (struct mm_struct *mm, unsigned long addr, pte_t *p pte_val (*ptep) = 0; } +#define PFN_PTE_SHIFT 0 #define pte_pfn(pte) (pte_val(pte) & SUN3_PAGE_PGNUM_MASK) #define pfn_pte(pfn, pgprot) \ ({ pte_t __pte; pte_val(__pte) = pfn | pgprot_val(pgprot); __pte; }) diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c index c75984e2d86b..8bca46e51e94 100644 --- a/arch/m68k/mm/motorola.c +++ b/arch/m68k/mm/motorola.c @@ -81,7 +81,7 @@ static inline void cache_page(void *vaddr) void mmu_page_ctor(void *page) { - __flush_page_to_ram(page); + __flush_pages_to_ram(page, 1); flush_tlb_kernel_page(page); nocache_page(page); } From patchwork Mon Jul 10 20:43:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307624 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 E0D09EB64DA for ; Mon, 10 Jul 2023 20:44:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DDA68E001A; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8664F8E0017; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66A408E001A; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 52E778E0017 for ; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1B913AFC40 for ; Mon, 10 Jul 2023 20:43:53 +0000 (UTC) X-FDA: 80996878746.07.01CE223 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 6464912000E for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=F3tIJGX3; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021831; 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=5z4wJk0QTIjcx4c+UwHHBLj4skJRBt0v1N12u1MFfd4=; b=jda6qsiCUZ29r2EH4IMwBmxRsulY2SEsjYvS54eqok16Y/Jd/9H4tR2v6JY1OetwaSdGha aGnGYLHI8TvEA8qd0TO6NU7UJ/3ynQd+UrQjhFSGEio8hda6yZUZ0cMai3nP6+T/pBDKmJ 7CNNikRyY98GTzs7HHC0R47yNwcsNTg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021831; a=rsa-sha256; cv=none; b=e+cF95Exmd+vTjQ5KTulZ1RYpmvrY5f0J3kp6yHsg9JkN3l7ej6TKat/aWQGvKEqKKBp7L jRQHlhoOtlm0oDxOiSAhcIT5dzY6GYWQRmVz2520hyZQvlCXP1qxslUAaz12R+gKWPR5HC GRF+Xnyts60jB2V8efZEBpQQn9K9QoI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=F3tIJGX3; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=5z4wJk0QTIjcx4c+UwHHBLj4skJRBt0v1N12u1MFfd4=; b=F3tIJGX3TcBd8jd37iFsFAx744 +Fg9zd01Ea63D7FffjdtHbZRmLMH1r81WylBxdustZ4JMXuUPwnYFR5pQFHmn37M9chwOI5Pcu4eV z11VZwus4IF3NTVCNup0zOEIFRPGlw0XRw/l5MD2SZmt+siplZn9psDbOO87IIHk/6sO73zwp3nQY OHpBuoINn3jHnlqe03bIALGblwIkdlqvgd4zp8aS1BcTvc/dXJo5oJJsqWZRgxk8R/PFVxTH12lQF adwHKSxlkTGhzuIZXvRjXm7rYoNngmHOVMlkoNJq7NJeEtLW8kHl5JAmoqabG3GVaRnwtiIKV0syu Ki84JZwA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00EupL-Ve; Mon, 10 Jul 2023 20:43:43 +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 , Michal Simek Subject: [PATCH v5 16/38] microblaze: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:17 +0100 Message-Id: <20230710204339.3554919-17-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-Stat-Signature: xb5k888p7j7ang3nezkfqpuw4jremwrf X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6464912000E X-Rspam-User: X-HE-Tag: 1689021831-617733 X-HE-Meta: U2FsdGVkX1+nqfg0h6p1GRWSHN1QhRYZ+2FrJg62J6Cb1erMdqqmT1lKykCL4oUkzZ2pIeFJBvW/kiClKc/0so9s33ini4KvmeYueu499e5EfsCYaTxHo2Zx3eyF3DSswGKzh97zwmz8DWuSD8TYa8rZFXU6eb4t0DKTCBnONmSUzB7ThgUQPLW5o5uU9rPc2l2zDWlY3SWPXfDfD9BbIXx9JBZyu4v7Y3WeLdbelDlpu25O87t+mdSFlNm1YXg8aZJl0dsgXbVY0mk6zAMwGsdmCVKXzHAXCXKfQTB2Y+prr69RdvUyuL5fCZWz2GfH8P9moT4GZ/H97FkDTSr8HGJM5mb0LEjoifXuqsBWI1MOzNYS/hT9D1MUpLtuwMX1I8b6wMsBdKtSN1g+m5MXjloj43CFgTURAkHofeaIVPKHo7ljqA60QWxMONzhRzXyMsoryBtTdptSDVCFrem3f9ixywnZxgw+7jTHkE6KqLia1HdIGyJqgc2ktSTpxEP+WVa+2GUPK9EN2g/0Urbqc6878J/GK+K1BzbWJq87xorRKuZHmUeguHzPkbbnRdptmpUIb4BSINRXGJT86SJGxAIQ2XWrpEFNXCJSiLxhTiSq/nxkltDbhYVC82vUu8/esbXrBY0zoXdLUTliaerftm1ypWLJTMoEqcIrE0Agv4lp6DNlWTxU//RXsavKBgCrEW8JuBZN9kuUnrXcxBSAX6I0Po7MQiIYXK69S9A8k+cKtaVPhOXaprzKnbNG0nI0d2b6on5qBqjOKEFDxniWiQIKBQsz4LthGueDUNBTZJQ+YM0IS69iYYgd8IFuLZEX7TkkGbrYzYQPlsxGfMCB4wm4x8okJDz7k0+aPUuG/8Ne4FHCYdQKJw+OqFY6Mqx2/hDTSJw6gVAW7nHgXtvPOXS1rK6zxJKMEHKT86xOabhFHIwVULqiOgJ9iXUj1nH4wrOl9cNWTneI6Y+PE8g ixOTFyn5 Q/MbfVSbqpblJUjJp8+wmYmN2/HAMteycqngJ0pOb2yOnAg/Qo3WIX+iklm4KXRzeLy/qE5WokzCxywrjHteB5DLug9P/GSfiBIvdSsDzuNw7+g4CEJgxvJ1Qtt+dLNolSQrOJN2D9l/OvZ1pCtqSDUDtEXGhrkbJEZaHLKL/UcyzTcNFjPdqG3XESRTVcDicucATRRGtPS1V6wCloQCPg6u6pX0zFbadhiv/zhYbLkrOky7J21Ipu2PYVKxh32XsxTnX6ZdMNZIs4ytm8pvFvS1+3STboudkDVkXXweyFzjma9s= 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: Rename PFN_SHIFT_OFFSET to PTE_PFN_SHIFT. Change the calling convention for set_pte() to be the same as other architectures. Add update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Michal Simek --- arch/microblaze/include/asm/cacheflush.h | 8 ++++++++ arch/microblaze/include/asm/pgtable.h | 15 ++++----------- arch/microblaze/include/asm/tlbflush.h | 4 +++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/arch/microblaze/include/asm/cacheflush.h b/arch/microblaze/include/asm/cacheflush.h index 39f8fb6768d8..e6641ff98cb3 100644 --- a/arch/microblaze/include/asm/cacheflush.h +++ b/arch/microblaze/include/asm/cacheflush.h @@ -74,6 +74,14 @@ do { \ flush_dcache_range((unsigned) (addr), (unsigned) (addr) + PAGE_SIZE); \ } while (0); +static void flush_dcache_folio(struct folio *folio) +{ + unsigned long addr = folio_pfn(folio) << PAGE_SHIFT; + + flush_dcache_range(addr, addr + folio_size(folio)); +} +#define flush_dcache_folio flush_dcache_folio + #define flush_cache_page(vma, vmaddr, pfn) \ flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE); diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h index d1b8272abcd9..6f9b99082518 100644 --- a/arch/microblaze/include/asm/pgtable.h +++ b/arch/microblaze/include/asm/pgtable.h @@ -230,12 +230,12 @@ extern unsigned long empty_zero_page[1024]; #define pte_page(x) (mem_map + (unsigned long) \ ((pte_val(x) - memory_start) >> PAGE_SHIFT)) -#define PFN_SHIFT_OFFSET (PAGE_SHIFT) +#define PFN_PTE_SHIFT PAGE_SHIFT -#define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET) +#define pte_pfn(x) (pte_val(x) >> PFN_PTE_SHIFT) #define pfn_pte(pfn, prot) \ - __pte(((pte_basic_t)(pfn) << PFN_SHIFT_OFFSET) | pgprot_val(prot)) + __pte(((pte_basic_t)(pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) #ifndef __ASSEMBLY__ /* @@ -330,14 +330,7 @@ static inline unsigned long pte_update(pte_t *p, unsigned long clr, /* * set_pte stores a linux PTE into the linux page table. */ -static inline void set_pte(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) -{ - *ptep = pte; -} - -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) +static inline void set_pte(pte_t *ptep, pte_t pte) { *ptep = pte; } diff --git a/arch/microblaze/include/asm/tlbflush.h b/arch/microblaze/include/asm/tlbflush.h index 2038168ed128..a31ae9d44083 100644 --- a/arch/microblaze/include/asm/tlbflush.h +++ b/arch/microblaze/include/asm/tlbflush.h @@ -33,7 +33,9 @@ static inline void local_flush_tlb_range(struct vm_area_struct *vma, #define flush_tlb_kernel_range(start, end) do { } while (0) -#define update_mmu_cache(vma, addr, ptep) do { } while (0) +#define update_mmu_cache_range(vmf, vma, addr, ptep, nr) do { } while (0) +#define update_mmu_cache(vma, addr, pte) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define flush_tlb_all local_flush_tlb_all #define flush_tlb_mm local_flush_tlb_mm From patchwork Mon Jul 10 20:43:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307607 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 AB71EEB64DA for ; Mon, 10 Jul 2023 20:44:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4FF68E000D; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EDA88E0001; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D20258E000A; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B3A9B8E0001 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 78053AFD2C for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.19.2EEDB78 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 9432A18001B for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OUdS+lkN; dmarc=none; spf=none (imf24.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=1689021825; 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=V6M6yuYxLKgLs0dM6txlVNLrG54L1bTI8jXyzPojSeg=; b=2uZXcHC5enF+JwpQdnK2z7TJKDaH4CFfynvFHCS3RTL+e6MUbRrhIYFbny7qhd/k2Tt+Hw d184/4XC2goDmgpkV1wEdRi91AFbdJG/U+NzPnX6wezZtb2+dRK3shjQSKoLC+Fd6gpHxg z6IeRalaLgWuaz8Gt8ZjE5c8DVRbz/s= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OUdS+lkN; dmarc=none; spf=none (imf24.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=1689021825; a=rsa-sha256; cv=none; b=dEvxRR+0SiK6hsipC766nzK9NEP2cxrBs8D8p7bl1zqozmNhGVd5b6RdYgMQSDdgPHZSRH vVsDU10GBOGwX3mz22C6MmPw9Mn3eiqRrY5G5e86tkxq/jMWfv7TVBse9E1vgsDBV1Jo11 tHLv5UwW+efX7T8CUaBm3v21CC8C2B8= 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=V6M6yuYxLKgLs0dM6txlVNLrG54L1bTI8jXyzPojSeg=; b=OUdS+lkNlp7fuw/1woNDc/REqs Aph0aluSvVzMpstH0jPPCbEiwo+MabIti+uEBTrtC3qTB1ZYI3zxNGPIam2iaqqdoTGy1urkLTfmM IY5FaVvC2Lgj/UCdvTxTuA5I/+NmE/agU+MASiUYS5c0KCPwAkHhZFeRbB6emLdRKs9S4NTJKJaIe n/X5OZibz3XMcF7WOHE7eFW7ikstRWkOh0EK+B7HAdzWM20sguXCno4+y1cEMNYwrpUJcGBLgiz4P /xuZHS+/IFN/pExYzv+jxU87kZwY06jtgth+HalyAE9f1fEN1fyDAi+rFCb9v4BS/TVe/InlDTp0L epzfagtA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00EupQ-3Q; Mon, 10 Jul 2023 20:43:43 +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 , Thomas Bogendoerfer , linux-mips@vger.kernel.org Subject: [PATCH v5 17/38] mips: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:18 +0100 Message-Id: <20230710204339.3554919-18-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-Rspam-User: X-Stat-Signature: dig96wjhewuo5gy48q8bidyyzf7gz6hy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9432A18001B X-HE-Tag: 1689021825-702417 X-HE-Meta: U2FsdGVkX198FnFG6zHl0uoSEnqOM6WPsLwAhQaHtpAwWHIJO7U4bPpVQUcJBghJxUcdXfsM6akV8T45VCdwLqHDUNdGwjWIR2rdxDrYyw0w1lknSJmop4dJUheLDv5lwqXDIpV/DgvvGFvGroMxEI+sn5TJ8vcisG3AdcvhX8NpVtLI34nvmdZuL6HjhoFv2NOkxHaoUWwKmxlqXuRuHYo84Pdin3gHE0qZ4D8HotdMWFpUXQXONYLQ+NQe3Alj5mMl/5MS5co5s4TI67+5y9RRv/ni6v/C5ZD8Rpt0GDFoOVEzqOckNhewcSIePZkLShsBIKlolhztgougcm9hSSGhPaDMyf0P8MCAMtev81tnDFoPDyZSQk5y+Q+NOoPVpSWnGFZoErr9DB0jdQhX5xJ/j1CKAtxZ5+t0/AYmOSf1qxjr0/rjO8e0FiW4nhtpOk8854a4clYyuKF+c4YoINFFn4RcyAgWWMasV+9VexLGjN8uXcNVVJ/sWIGRemshQ+sSszxavIt4PjjWmilDZdqKdjhtL6YZ53PLbLMaG0/oDn3IYYoTN/5y8uqji+ZhfA7ZRTkz7Jzoaz6ql29m7b1nEQYrW+7r8bYozrpKAuZsnqjkJIntAH246Fs33aVo1dMd5zEScMrf7o5RioR2SzHLZuV/jamILBOrYkln+QY4uWbS8nu6YxnaAcS1nd0aELpj8aeeLlRntRYeEBFv10K1RIfFwzQAf6qrYUHmYhB5dKKjhPBC6MJzWdFxLvKdTeJa0o96UuLkfFgZjmkJeEjr0j2ucDnx4HHtb4aNc/2cHMM498Uu9kA2fuPIU8wyU/14RZhTTshYDYUTZBraVBw9twTYTEqZPBBiwp+LJ0oMnehW8oqf0g6xu3IO/o4pzW/WDhDriXpSoNdU/6HWrkXewyaZdhif53okzyzEsTkyGitAAWmofm0hBKbAFRqW3Tbx6x3gjX7L+hYDbQT h/FIBXTE at3bXmfF4OWD+D4xlgle0kYXfOFMskgPRAVpRHCuqAkRy0W5ItBSZEENmZh2by5Dn59IFaTDrMSY96mWJuPG70J6LxYxMOHcMWzxWBGsLEJSCQZP7qrqHHat5H4x0mHhC0JZrI8PhzkadiFD6stVVVvt8ypDg5xHNZ3JuiPNyPSs/e7E0Jp9xN0UKlcD06CmC2uCYijGbW7BZkDkVTkmryf6/bgt+q3XvxFd+0RxTDSZBow09E2z/nB9evA== 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: Rename _PFN_SHIFT to PFN_PTE_SHIFT. Convert a few places to call set_pte() instead of set_pte_at(). Add set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org --- arch/mips/bcm47xx/prom.c | 2 +- arch/mips/include/asm/cacheflush.h | 32 +++++++++----- arch/mips/include/asm/pgtable-32.h | 10 ++--- arch/mips/include/asm/pgtable-64.h | 6 +-- arch/mips/include/asm/pgtable-bits.h | 6 +-- arch/mips/include/asm/pgtable.h | 63 ++++++++++++++++++---------- arch/mips/mm/c-r4k.c | 5 ++- arch/mips/mm/cache.c | 56 ++++++++++++------------- arch/mips/mm/init.c | 21 ++++++---- arch/mips/mm/pgtable-32.c | 2 +- arch/mips/mm/pgtable-64.c | 2 +- arch/mips/mm/tlbex.c | 2 +- 12 files changed, 121 insertions(+), 86 deletions(-) diff --git a/arch/mips/bcm47xx/prom.c b/arch/mips/bcm47xx/prom.c index a9bea411d928..99a1ba5394e0 100644 --- a/arch/mips/bcm47xx/prom.c +++ b/arch/mips/bcm47xx/prom.c @@ -116,7 +116,7 @@ void __init prom_init(void) #if defined(CONFIG_BCM47XX_BCMA) && defined(CONFIG_HIGHMEM) #define EXTVBASE 0xc0000000 -#define ENTRYLO(x) ((pte_val(pfn_pte((x) >> _PFN_SHIFT, PAGE_KERNEL_UNCACHED)) >> 6) | 1) +#define ENTRYLO(x) ((pte_val(pfn_pte((x) >> PFN_PTE_SHIFT, PAGE_KERNEL_UNCACHED)) >> 6) | 1) #include diff --git a/arch/mips/include/asm/cacheflush.h b/arch/mips/include/asm/cacheflush.h index d8d3f80f9fc0..0f389bc7cb90 100644 --- a/arch/mips/include/asm/cacheflush.h +++ b/arch/mips/include/asm/cacheflush.h @@ -36,12 +36,12 @@ */ #define PG_dcache_dirty PG_arch_1 -#define Page_dcache_dirty(page) \ - test_bit(PG_dcache_dirty, &(page)->flags) -#define SetPageDcacheDirty(page) \ - set_bit(PG_dcache_dirty, &(page)->flags) -#define ClearPageDcacheDirty(page) \ - clear_bit(PG_dcache_dirty, &(page)->flags) +#define folio_test_dcache_dirty(folio) \ + test_bit(PG_dcache_dirty, &(folio)->flags) +#define folio_set_dcache_dirty(folio) \ + set_bit(PG_dcache_dirty, &(folio)->flags) +#define folio_clear_dcache_dirty(folio) \ + clear_bit(PG_dcache_dirty, &(folio)->flags) extern void (*flush_cache_all)(void); extern void (*__flush_cache_all)(void); @@ -50,15 +50,24 @@ extern void (*flush_cache_mm)(struct mm_struct *mm); extern void (*flush_cache_range)(struct vm_area_struct *vma, unsigned long start, unsigned long end); extern void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn); -extern void __flush_dcache_page(struct page *page); +extern void __flush_dcache_pages(struct page *page, unsigned int nr); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +static inline void flush_dcache_folio(struct folio *folio) +{ + if (cpu_has_dc_aliases) + __flush_dcache_pages(&folio->page, folio_nr_pages(folio)); + else if (!cpu_has_ic_fills_f_dc) + folio_set_dcache_dirty(folio); +} +#define flush_dcache_folio flush_dcache_folio + static inline void flush_dcache_page(struct page *page) { if (cpu_has_dc_aliases) - __flush_dcache_page(page); + __flush_dcache_pages(page, 1); else if (!cpu_has_ic_fills_f_dc) - SetPageDcacheDirty(page); + folio_set_dcache_dirty(page_folio(page)); } #define flush_dcache_mmap_lock(mapping) do { } while (0) @@ -73,10 +82,11 @@ static inline void flush_anon_page(struct vm_area_struct *vma, __flush_anon_page(page, vmaddr); } -static inline void flush_icache_page(struct vm_area_struct *vma, - struct page *page) +static inline void flush_icache_pages(struct vm_area_struct *vma, + struct page *page, unsigned int nr) { } +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) extern void (*flush_icache_range)(unsigned long start, unsigned long end); extern void (*local_flush_icache_range)(unsigned long start, unsigned long end); diff --git a/arch/mips/include/asm/pgtable-32.h b/arch/mips/include/asm/pgtable-32.h index ba0016709a1a..0e196650f4f4 100644 --- a/arch/mips/include/asm/pgtable-32.h +++ b/arch/mips/include/asm/pgtable-32.h @@ -153,7 +153,7 @@ static inline void pmd_clear(pmd_t *pmdp) #if defined(CONFIG_XPA) #define MAX_POSSIBLE_PHYSMEM_BITS 40 -#define pte_pfn(x) (((unsigned long)((x).pte_high >> _PFN_SHIFT)) | (unsigned long)((x).pte_low << _PAGE_PRESENT_SHIFT)) +#define pte_pfn(x) (((unsigned long)((x).pte_high >> PFN_PTE_SHIFT)) | (unsigned long)((x).pte_low << _PAGE_PRESENT_SHIFT)) static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) { @@ -161,7 +161,7 @@ pfn_pte(unsigned long pfn, pgprot_t prot) pte.pte_low = (pfn >> _PAGE_PRESENT_SHIFT) | (pgprot_val(prot) & ~_PFNX_MASK); - pte.pte_high = (pfn << _PFN_SHIFT) | + pte.pte_high = (pfn << PFN_PTE_SHIFT) | (pgprot_val(prot) & ~_PFN_MASK); return pte; } @@ -184,9 +184,9 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) #else #define MAX_POSSIBLE_PHYSMEM_BITS 32 -#define pte_pfn(x) ((unsigned long)((x).pte >> _PFN_SHIFT)) -#define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot)) -#define pfn_pmd(pfn, prot) __pmd(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot)) +#define pte_pfn(x) ((unsigned long)((x).pte >> PFN_PTE_SHIFT)) +#define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) +#define pfn_pmd(pfn, prot) __pmd(((unsigned long long)(pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) #endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */ #define pte_page(x) pfn_to_page(pte_pfn(x)) diff --git a/arch/mips/include/asm/pgtable-64.h b/arch/mips/include/asm/pgtable-64.h index 98e24e3e7f2b..20ca48c1b606 100644 --- a/arch/mips/include/asm/pgtable-64.h +++ b/arch/mips/include/asm/pgtable-64.h @@ -298,9 +298,9 @@ static inline void pud_clear(pud_t *pudp) #define pte_page(x) pfn_to_page(pte_pfn(x)) -#define pte_pfn(x) ((unsigned long)((x).pte >> _PFN_SHIFT)) -#define pfn_pte(pfn, prot) __pte(((pfn) << _PFN_SHIFT) | pgprot_val(prot)) -#define pfn_pmd(pfn, prot) __pmd(((pfn) << _PFN_SHIFT) | pgprot_val(prot)) +#define pte_pfn(x) ((unsigned long)((x).pte >> PFN_PTE_SHIFT)) +#define pfn_pte(pfn, prot) __pte(((pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) +#define pfn_pmd(pfn, prot) __pmd(((pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) #ifndef __PAGETABLE_PMD_FOLDED static inline pmd_t *pud_pgtable(pud_t pud) diff --git a/arch/mips/include/asm/pgtable-bits.h b/arch/mips/include/asm/pgtable-bits.h index 1c576679aa87..421e78c30253 100644 --- a/arch/mips/include/asm/pgtable-bits.h +++ b/arch/mips/include/asm/pgtable-bits.h @@ -182,10 +182,10 @@ enum pgtable_bits { #if defined(CONFIG_CPU_R3K_TLB) # define _CACHE_UNCACHED (1 << _CACHE_UNCACHED_SHIFT) # define _CACHE_MASK _CACHE_UNCACHED -# define _PFN_SHIFT PAGE_SHIFT +# define PFN_PTE_SHIFT PAGE_SHIFT #else # define _CACHE_MASK (7 << _CACHE_SHIFT) -# define _PFN_SHIFT (PAGE_SHIFT - 12 + _CACHE_SHIFT + 3) +# define PFN_PTE_SHIFT (PAGE_SHIFT - 12 + _CACHE_SHIFT + 3) #endif #ifndef _PAGE_NO_EXEC @@ -195,7 +195,7 @@ enum pgtable_bits { #define _PAGE_SILENT_READ _PAGE_VALID #define _PAGE_SILENT_WRITE _PAGE_DIRTY -#define _PFN_MASK (~((1 << (_PFN_SHIFT)) - 1)) +#define _PFN_MASK (~((1 << (PFN_PTE_SHIFT)) - 1)) /* * The final layouts of the PTE bits are: diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h index 574fa14ac8b2..cbb93a834f52 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -66,7 +66,7 @@ extern void paging_init(void); static inline unsigned long pmd_pfn(pmd_t pmd) { - return pmd_val(pmd) >> _PFN_SHIFT; + return pmd_val(pmd) >> PFN_PTE_SHIFT; } #ifndef CONFIG_MIPS_HUGE_TLB_SUPPORT @@ -105,9 +105,6 @@ do { \ } \ } while(0) -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval); - #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) #ifdef CONFIG_XPA @@ -157,7 +154,7 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *pt null.pte_low = null.pte_high = _PAGE_GLOBAL; } - set_pte_at(mm, addr, ptep, null); + set_pte(ptep, null); htw_start(); } #else @@ -196,28 +193,41 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *pt #if !defined(CONFIG_CPU_R3K_TLB) /* Preserve global status for the pair */ if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL) - set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL)); + set_pte(ptep, __pte(_PAGE_GLOBAL)); else #endif - set_pte_at(mm, addr, ptep, __pte(0)); + set_pte(ptep, __pte(0)); htw_start(); } #endif -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval) +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) { + unsigned int i; + bool do_sync = false; - if (!pte_present(pteval)) - goto cache_sync_done; + for (i = 0; i < nr; i++) { + if (!pte_present(pte)) + continue; + if (pte_present(ptep[i]) && + (pte_pfn(ptep[i]) == pte_pfn(pte))) + continue; + do_sync = true; + } - if (pte_present(*ptep) && (pte_pfn(*ptep) == pte_pfn(pteval))) - goto cache_sync_done; + if (do_sync) + __update_cache(addr, pte); - __update_cache(addr, pteval); -cache_sync_done: - set_pte(ptep, pteval); + for (;;) { + set_pte(ptep, pte); + if (--nr == 0) + break; + ptep++; + pte = __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT)); + } } +#define set_ptes set_ptes /* * (pmds are folded into puds so this doesn't get actually called, @@ -486,7 +496,7 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma, pte_t entry, int dirty) { if (!pte_same(*ptep, entry)) - set_pte_at(vma->vm_mm, address, ptep, entry); + set_pte(ptep, entry); /* * update_mmu_cache will unconditionally execute, handling both * the case that the PTE changed and the spurious fault case. @@ -568,12 +578,21 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) extern void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte); -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) -{ - pte_t pte = *ptep; - __update_tlb(vma, address, pte); +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) +{ + for (;;) { + pte_t pte = *ptep; + __update_tlb(vma, address, pte); + if (--nr == 0) + break; + ptep++; + address += PAGE_SIZE; + } } +#define update_mmu_cache(vma, address, ptep) \ + update_mmu_cache_range(NULL, vma, address, ptep, 1) #define __HAVE_ARCH_UPDATE_MMU_TLB #define update_mmu_tlb update_mmu_cache diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c index 4b6554b48923..187d1c16361c 100644 --- a/arch/mips/mm/c-r4k.c +++ b/arch/mips/mm/c-r4k.c @@ -568,13 +568,14 @@ static inline void local_r4k_flush_cache_page(void *args) if ((mm == current->active_mm) && (pte_val(*ptep) & _PAGE_VALID)) vaddr = NULL; else { + struct folio *folio = page_folio(page); /* * Use kmap_coherent or kmap_atomic to do flushes for * another ASID than the current one. */ map_coherent = (cpu_has_dc_aliases && - page_mapcount(page) && - !Page_dcache_dirty(page)); + folio_mapped(folio) && + !folio_test_dcache_dirty(folio)); if (map_coherent) vaddr = kmap_coherent(page, addr); else diff --git a/arch/mips/mm/cache.c b/arch/mips/mm/cache.c index d21cf8c6cf6c..02042100e267 100644 --- a/arch/mips/mm/cache.c +++ b/arch/mips/mm/cache.c @@ -99,13 +99,15 @@ SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, bytes, return 0; } -void __flush_dcache_page(struct page *page) +void __flush_dcache_pages(struct page *page, unsigned int nr) { - struct address_space *mapping = page_mapping_file(page); + struct folio *folio = page_folio(page); + struct address_space *mapping = folio_flush_mapping(folio); unsigned long addr; + unsigned int i; if (mapping && !mapping_mapped(mapping)) { - SetPageDcacheDirty(page); + folio_set_dcache_dirty(folio); return; } @@ -114,25 +116,21 @@ void __flush_dcache_page(struct page *page) * case is for exec env/arg pages and those are %99 certainly going to * get faulted into the tlb (and thus flushed) anyways. */ - if (PageHighMem(page)) - addr = (unsigned long)kmap_atomic(page); - else - addr = (unsigned long)page_address(page); - - flush_data_cache_page(addr); - - if (PageHighMem(page)) - kunmap_atomic((void *)addr); + for (i = 0; i < nr; i++) { + addr = (unsigned long)kmap_local_page(page + i); + flush_data_cache_page(addr); + kunmap_local((void *)addr); + } } - -EXPORT_SYMBOL(__flush_dcache_page); +EXPORT_SYMBOL(__flush_dcache_pages); void __flush_anon_page(struct page *page, unsigned long vmaddr) { unsigned long addr = (unsigned long) page_address(page); + struct folio *folio = page_folio(page); if (pages_do_alias(addr, vmaddr)) { - if (page_mapcount(page) && !Page_dcache_dirty(page)) { + if (folio_mapped(folio) && !folio_test_dcache_dirty(folio)) { void *kaddr; kaddr = kmap_coherent(page, vmaddr); @@ -147,27 +145,29 @@ EXPORT_SYMBOL(__flush_anon_page); void __update_cache(unsigned long address, pte_t pte) { - struct page *page; + struct folio *folio; unsigned long pfn, addr; int exec = !pte_no_exec(pte) && !cpu_has_ic_fills_f_dc; + unsigned int i; pfn = pte_pfn(pte); if (unlikely(!pfn_valid(pfn))) return; - page = pfn_to_page(pfn); - if (Page_dcache_dirty(page)) { - if (PageHighMem(page)) - addr = (unsigned long)kmap_atomic(page); - else - addr = (unsigned long)page_address(page); - - if (exec || pages_do_alias(addr, address & PAGE_MASK)) - flush_data_cache_page(addr); - if (PageHighMem(page)) - kunmap_atomic((void *)addr); + folio = page_folio(pfn_to_page(pfn)); + address &= PAGE_MASK; + address -= offset_in_folio(folio, pfn << PAGE_SHIFT); + + if (folio_test_dcache_dirty(folio)) { + for (i = 0; i < folio_nr_pages(folio); i++) { + addr = (unsigned long)kmap_local_folio(folio, i); - ClearPageDcacheDirty(page); + if (exec || pages_do_alias(addr, address)) + flush_data_cache_page(addr); + kunmap_local((void *)addr); + address += PAGE_SIZE; + } + folio_clear_dcache_dirty(folio); } } diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c index 5a8002839550..5dcb525a8995 100644 --- a/arch/mips/mm/init.c +++ b/arch/mips/mm/init.c @@ -88,7 +88,7 @@ static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot) pte_t pte; int tlbidx; - BUG_ON(Page_dcache_dirty(page)); + BUG_ON(folio_test_dcache_dirty(page_folio(page))); preempt_disable(); pagefault_disable(); @@ -169,11 +169,12 @@ void kunmap_coherent(void) void copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) { + struct folio *src = page_folio(from); void *vfrom, *vto; vto = kmap_atomic(to); if (cpu_has_dc_aliases && - page_mapcount(from) && !Page_dcache_dirty(from)) { + folio_mapped(src) && !folio_test_dcache_dirty(src)) { vfrom = kmap_coherent(from, vaddr); copy_page(vto, vfrom); kunmap_coherent(); @@ -194,15 +195,17 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); + if (cpu_has_dc_aliases && - page_mapcount(page) && !Page_dcache_dirty(page)) { + folio_mapped(folio) && !folio_test_dcache_dirty(folio)) { void *vto = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); memcpy(vto, src, len); kunmap_coherent(); } else { memcpy(dst, src, len); if (cpu_has_dc_aliases) - SetPageDcacheDirty(page); + folio_set_dcache_dirty(folio); } if (vma->vm_flags & VM_EXEC) flush_cache_page(vma, vaddr, page_to_pfn(page)); @@ -212,15 +215,17 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); + if (cpu_has_dc_aliases && - page_mapcount(page) && !Page_dcache_dirty(page)) { + folio_mapped(folio) && !folio_test_dcache_dirty(folio)) { void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); memcpy(dst, vfrom, len); kunmap_coherent(); } else { memcpy(dst, src, len); if (cpu_has_dc_aliases) - SetPageDcacheDirty(page); + folio_set_dcache_dirty(folio); } } EXPORT_SYMBOL_GPL(copy_from_user_page); @@ -448,10 +453,10 @@ static inline void __init mem_init_free_highmem(void) void __init mem_init(void) { /* - * When _PFN_SHIFT is greater than PAGE_SHIFT we won't have enough PTE + * When PFN_PTE_SHIFT is greater than PAGE_SHIFT we won't have enough PTE * bits to hold a full 32b physical address on MIPS32 systems. */ - BUILD_BUG_ON(IS_ENABLED(CONFIG_32BIT) && (_PFN_SHIFT > PAGE_SHIFT)); + BUILD_BUG_ON(IS_ENABLED(CONFIG_32BIT) && (PFN_PTE_SHIFT > PAGE_SHIFT)); #ifdef CONFIG_HIGHMEM max_mapnr = highend_pfn ? highend_pfn : max_low_pfn; diff --git a/arch/mips/mm/pgtable-32.c b/arch/mips/mm/pgtable-32.c index f57fb69472f8..84dd5136d53a 100644 --- a/arch/mips/mm/pgtable-32.c +++ b/arch/mips/mm/pgtable-32.c @@ -35,7 +35,7 @@ pmd_t mk_pmd(struct page *page, pgprot_t prot) { pmd_t pmd; - pmd_val(pmd) = (page_to_pfn(page) << _PFN_SHIFT) | pgprot_val(prot); + pmd_val(pmd) = (page_to_pfn(page) << PFN_PTE_SHIFT) | pgprot_val(prot); return pmd; } diff --git a/arch/mips/mm/pgtable-64.c b/arch/mips/mm/pgtable-64.c index b4386a0e2ef8..c76d21f7dffb 100644 --- a/arch/mips/mm/pgtable-64.c +++ b/arch/mips/mm/pgtable-64.c @@ -93,7 +93,7 @@ pmd_t mk_pmd(struct page *page, pgprot_t prot) { pmd_t pmd; - pmd_val(pmd) = (page_to_pfn(page) << _PFN_SHIFT) | pgprot_val(prot); + pmd_val(pmd) = (page_to_pfn(page) << PFN_PTE_SHIFT) | pgprot_val(prot); return pmd; } diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c index 8d514a9082c6..b4e1c783e617 100644 --- a/arch/mips/mm/tlbex.c +++ b/arch/mips/mm/tlbex.c @@ -253,7 +253,7 @@ static void output_pgtable_bits_defines(void) pr_define("_PAGE_GLOBAL_SHIFT %d\n", _PAGE_GLOBAL_SHIFT); pr_define("_PAGE_VALID_SHIFT %d\n", _PAGE_VALID_SHIFT); pr_define("_PAGE_DIRTY_SHIFT %d\n", _PAGE_DIRTY_SHIFT); - pr_define("_PFN_SHIFT %d\n", _PFN_SHIFT); + pr_define("PFN_PTE_SHIFT %d\n", PFN_PTE_SHIFT); pr_debug("\n"); } From patchwork Mon Jul 10 20:43:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307606 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 B0EB8C001B0 for ; Mon, 10 Jul 2023 20:43:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B5A68E0007; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CF568E000D; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE7B78E0007; Mon, 10 Jul 2023 16:43:47 -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 6E8668E0005 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4D88E40264 for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) X-FDA: 80996878494.22.B133BA2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 217B9100018 for ; Mon, 10 Jul 2023 20:43:44 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hcQFSxZH; dmarc=none; spf=none (imf14.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=1689021825; 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=Wwwg3Ff0sEXoT+gpLjTlRY8CfhDSyXqIxaVQtu9/j9M=; b=Cx+wmKx/qSczqjm7Yikw4j4c7UB2MnXvcGPY47klVG1tZe456r7QbLwqWbRa2iARqZMzQV 2K3mIiSn9RtDFoK6GUKKXN8KO8ANjxojYaOyuzgpXzsOpe/z4/Szab6Y134V+vdd7Q5jsi jEIhmgog+e0616J6VH+q0WT3y+90KMc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hcQFSxZH; dmarc=none; spf=none (imf14.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=1689021825; a=rsa-sha256; cv=none; b=OhTH2hrKYCC5YsEDqQ9Y6OhyT9tT32KEn0Rpm9Vei55xjLeB6JQJJN50m32lyW1VB4ME/B 9dd9NNYLvbAT/Pq31yxpl6ibwQc4zgvrD25bzI7vM4Fmx+vxoIcQs+w1SGXOyjkCrGRR18 Q4WQ+UDzBS8vkom4Gnb8xs3G62LlNUY= 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=Wwwg3Ff0sEXoT+gpLjTlRY8CfhDSyXqIxaVQtu9/j9M=; b=hcQFSxZH1BUy1pekV1P0xDwPNc fi2coX6G0keIT4lFhynthoC81THCaUpZ9t9JtrYrw9KHtyZH4ukw+WZProSQw8fgbGgxdScNgka5c BxaNAQzneZyIWJMjfVBbxcv+wwnoOqiaLAttj/xR0MnJ8+1Tc3+O8dRYGRL9V2sGnR4KnQdoXxFT/ oukgnBz9iSXWedje+9zSd+A2ReCZ8v8kW3V5yt7zFWB4HqTh73MtDQG1ABYXaogzi8/y7Jv1BC5Qi xRHofb9HskVaYVuUuWAaB9HBSh83dKODGfB1xQgvKSS787jCRRM+YsRljg9YtmyEAWC22+Cqd9wie uqYPgm4A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00EupT-6u; Mon, 10 Jul 2023 20:43:43 +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 , Dinh Nguyen Subject: [PATCH v5 18/38] nios2: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:19 +0100 Message-Id: <20230710204339.3554919-19-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-Server: rspam09 X-Rspamd-Queue-Id: 217B9100018 X-Stat-Signature: q9td5iy15orahwbim7juu9bnsdsf4naq X-Rspam-User: X-HE-Tag: 1689021824-741983 X-HE-Meta: U2FsdGVkX18qPWJCpEONb1xk3AU+UWJfhLtFedXha/cL6ScO4Hk5X2UGFnbA7vklAJ4Pq25Z3FqkWYOnWJHe2bCQtnCQhZT1uhUvqwNK5HLpdsVx7+bJggnMhnpHlh/rjQJZrywLq3JE7yU8U5GyrTrFL2R1pS9u3uqeA6SNxl43fb1rCIZrodN+ZWatIxenQ39zZa5K3GW/urX5vNpG+gA94alHgQ6/LCcJwUBqBGMnOWeQltowwdw8g8suggCyIrDLxtxvPylNgtOJqwVSayKspTdvmT2m7wOy6gzxhrSm/6Jon4bGOJwGudK+/eJVa+GSGkB/mujSTqoWQPEP5UqTnhLbB0fv4U6BvHmH8ZX7ZTBCMtul9jTUIrAXQ4rESHqgtWlqNDBiUUuo7xTupfDNzEKGKF1WZYJhsjV//njgNaAervFm/zvgCzn76oR/J+BwmmMptvDf6Hn7gOjWrPc3zpebK9/uXKFENnY77eCoTZoWkR0JnBREKVhpi/QQQDCUOkZKe68dvHvyodeGVW9H93tefomaHyg5FQ3HM3HzPliHBuVLjn/W3suimKUJ+l9OIO/sdTU988JBnl7n+be+Ul5pa5ro/xy6Dx2hmHad0LVc4TWa8vT57/ZssFuTrfHgtC9IdhMQexyAGAnNq/f+qGznkPvt0zM9aUBno8NrycbWo5U7AfxMmffam4A1OSGUOPGDO8lGjvCcLAttPrJ5M0BO49eGDI7/bOslawpNSDXEJEJ2ja7rxRnS9PN1NEVuEgVdBZ17Uvyr+Ke8iMBunUpKYfyUjg4xPHC6KFqs/mXKqMBWtV65tjB61CRNpaYChLW4MKXBg8vR7kYXownrUjfE5HmzANJlPohIsRJeuv/cojuz8oVQJsqWycNGUTC3Izlx56GvV2ixJcxi9wCZCyfygYendchS2wyWUrPlB6K5bg+w/QuWj7BHWCMe4H7xdrp6pZxio+5iwI/ 1Saj0pfd /PBm6hAi59Qb39aTJyK6QsSgUK/Bfhai4xXK93PoLdtiroFEBccYgOpmTLJu5YcxdPEGdu/HN/OWWbf10BnL7/DG8YZLg2tzs0P68u+yt0+Su014cHo/iWTD1B0opk1zeqtukwzQWCmY8eWIK/fWlU9Bu004WZh9thgHpshdYGODQ0eGIZeT+VvXk0Y9CiO6KznfFg7VMzD4/DEa8zdRP2McSOsar+l6Sjbv6uNVfXUZfWqqEyLbg9MXLgw== 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: Add set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Dinh Nguyen Acked-by: Dinh Nguyen --- arch/nios2/include/asm/cacheflush.h | 6 ++- arch/nios2/include/asm/pgtable.h | 28 ++++++---- arch/nios2/mm/cacheflush.c | 79 ++++++++++++++++------------- 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h index d0b71dd71287..8624ca83cffe 100644 --- a/arch/nios2/include/asm/cacheflush.h +++ b/arch/nios2/include/asm/cacheflush.h @@ -29,9 +29,13 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 void flush_dcache_page(struct page *page); +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio extern void flush_icache_range(unsigned long start, unsigned long end); -extern void flush_icache_page(struct vm_area_struct *vma, struct page *page); +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr); +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1); #define flush_cache_vmap(start, end) flush_dcache_range(start, end) #define flush_cache_vunmap(start, end) flush_dcache_range(start, end) diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h index 0f5c2564e9f5..be6bf3e0bd7a 100644 --- a/arch/nios2/include/asm/pgtable.h +++ b/arch/nios2/include/asm/pgtable.h @@ -178,14 +178,21 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval) +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) { - unsigned long paddr = (unsigned long)page_to_virt(pte_page(pteval)); - - flush_dcache_range(paddr, paddr + PAGE_SIZE); - set_pte(ptep, pteval); + unsigned long paddr = (unsigned long)page_to_virt(pte_page(pte)); + + flush_dcache_range(paddr, paddr + nr * PAGE_SIZE); + for (;;) { + set_pte(ptep, pte); + if (--nr == 0) + break; + ptep++; + pte_val(pte) += 1; + } } +#define set_ptes set_ptes static inline int pmd_none(pmd_t pmd) { @@ -202,7 +209,7 @@ static inline void pte_clear(struct mm_struct *mm, pte_val(null) = (addr >> PAGE_SHIFT) & 0xf; - set_pte_at(mm, addr, ptep, null); + set_pte(ptep, null); } /* @@ -273,7 +280,10 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) extern void __init paging_init(void); extern void __init mmu_init(void); -extern void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *pte); +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr); + +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #endif /* _ASM_NIOS2_PGTABLE_H */ diff --git a/arch/nios2/mm/cacheflush.c b/arch/nios2/mm/cacheflush.c index 6aa9257c3ede..28b805f465a8 100644 --- a/arch/nios2/mm/cacheflush.c +++ b/arch/nios2/mm/cacheflush.c @@ -71,26 +71,26 @@ static void __flush_icache(unsigned long start, unsigned long end) __asm__ __volatile(" flushp\n"); } -static void flush_aliases(struct address_space *mapping, struct page *page) +static void flush_aliases(struct address_space *mapping, struct folio *folio) { struct mm_struct *mm = current->active_mm; - struct vm_area_struct *mpnt; + struct vm_area_struct *vma; pgoff_t pgoff; + unsigned long nr = folio_nr_pages(folio); - pgoff = page->index; + pgoff = folio->index; flush_dcache_mmap_lock(mapping); - vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { - unsigned long offset; + vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff + nr - 1) { + unsigned long start; - if (mpnt->vm_mm != mm) + if (vma->vm_mm != mm) continue; - if (!(mpnt->vm_flags & VM_MAYSHARE)) + if (!(vma->vm_flags & VM_MAYSHARE)) continue; - offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT; - flush_cache_page(mpnt, mpnt->vm_start + offset, - page_to_pfn(page)); + start = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); + flush_cache_range(vma, start, start + nr * PAGE_SIZE); } flush_dcache_mmap_unlock(mapping); } @@ -138,10 +138,11 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start, __flush_icache(start, end); } -void flush_icache_page(struct vm_area_struct *vma, struct page *page) +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr) { unsigned long start = (unsigned long) page_address(page); - unsigned long end = start + PAGE_SIZE; + unsigned long end = start + nr * PAGE_SIZE; __flush_dcache(start, end); __flush_icache(start, end); @@ -158,19 +159,19 @@ void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, __flush_icache(start, end); } -void __flush_dcache_page(struct address_space *mapping, struct page *page) +static void __flush_dcache_folio(struct folio *folio) { /* * Writeback any data associated with the kernel mapping of this * page. This ensures that data in the physical page is mutually * coherent with the kernels mapping. */ - unsigned long start = (unsigned long)page_address(page); + unsigned long start = (unsigned long)folio_address(folio); - __flush_dcache(start, start + PAGE_SIZE); + __flush_dcache(start, start + folio_size(folio)); } -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { struct address_space *mapping; @@ -178,32 +179,38 @@ void flush_dcache_page(struct page *page) * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(folio_pfn(folio))) return; - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); /* Flush this page if there are aliases. */ if (mapping && !mapping_mapped(mapping)) { - clear_bit(PG_dcache_clean, &page->flags); + clear_bit(PG_dcache_clean, &folio->flags); } else { - __flush_dcache_page(mapping, page); + __flush_dcache_folio(folio); if (mapping) { - unsigned long start = (unsigned long)page_address(page); - flush_aliases(mapping, page); - flush_icache_range(start, start + PAGE_SIZE); + unsigned long start = (unsigned long)folio_address(folio); + flush_aliases(mapping, folio); + flush_icache_range(start, start + folio_size(folio)); } - set_bit(PG_dcache_clean, &page->flags); + set_bit(PG_dcache_clean, &folio->flags); } } +EXPORT_SYMBOL(flush_dcache_folio); + +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} EXPORT_SYMBOL(flush_dcache_page); -void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr) { pte_t pte = *ptep; unsigned long pfn = pte_pfn(pte); - struct page *page; + struct folio *folio; struct address_space *mapping; reload_tlb_page(vma, address, pte); @@ -215,19 +222,19 @@ void update_mmu_cache(struct vm_area_struct *vma, * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - page = pfn_to_page(pfn); - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(pfn)) return; - mapping = page_mapping_file(page); - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) - __flush_dcache_page(mapping, page); + folio = page_folio(pfn_to_page(pfn)); + if (!test_and_set_bit(PG_dcache_clean, &folio->flags)) + __flush_dcache_folio(folio); - if(mapping) - { - flush_aliases(mapping, page); + mapping = folio_flush_mapping(folio); + if (mapping) { + flush_aliases(mapping, folio); if (vma->vm_flags & VM_EXEC) - flush_icache_page(vma, page); + flush_icache_pages(vma, &folio->page, + folio_nr_pages(folio)); } } From patchwork Mon Jul 10 20:43:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307636 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 17BDEEB64D9 for ; Mon, 10 Jul 2023 20:44:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35E838E0026; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30DC58E001B; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AFB88E0026; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0B2428E001B for ; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D399316023D for ; Mon, 10 Jul 2023 20:44:10 +0000 (UTC) X-FDA: 80996879460.07.7007C23 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id C8D7E10001C for ; Mon, 10 Jul 2023 20:44:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LstrdFs9; dmarc=none; spf=none (imf14.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=1689021849; a=rsa-sha256; cv=none; b=SCW/Hvxzq0C0McVxfxICm+6vqWfUKAgjPC4qsD53Bq9XCxtGLa9qBaIo30gyU717k1XHO2 aQH4BQZDTPY+/nOP2szG7nyjl+doMwmXVbotTdTfUt8/Ji9AwKIfBPjhAdnIiBdqkqm2Gm tzdFZCA1QgkqalrnroX7RKRVzSqcJQk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LstrdFs9; dmarc=none; spf=none (imf14.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=1689021849; 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=LkNLbBSWedZKYyPfN1pGuZQo5tC7Q714M9YkIGeohI8=; b=NBcr69aWpfxcXzfmBQ4xIR6kneRZ0Uy/HgL+Hp5/lKjrWMxgIB9sPqERj5zKZtxUlH0jAR MjsOtKsHgt+5z3caVmuFJCg4O+shpSeeBpO0d+AZdnhwFIYfUZeVJm0LJAE8sUfi5NLhtt d+w4zwVckQ8TDASqy0XQaKu9NT3AWJ4= 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=LkNLbBSWedZKYyPfN1pGuZQo5tC7Q714M9YkIGeohI8=; b=LstrdFs9UlKVnGLIEf/uAPHDQu pOcMiPmZPEJbQXp8d+wByOWnPshMUaJOCjYNfNldJhUqffupXq2qr8ZW2cIEmvQSvBMZBk4WZTWwx D+h9KKwgOJoSQv5oq9816YjDOxDh8LKWQTqQLYLMInOiJTbUxKGZjexoGn7JzrNc1CLeVnITSE7n7 jz4V7oRq0/Gll+bVW0g0QVkL+PoDSNhsfLO9kWfztiTTfuVf7WndNMFG5cpOgSme0XkSl0Xiox2R5 bU0RGm7kycVY3av7mjwaL0GDR6eAER8KIgTNLG4IrpJTHfaEWOCIWBqgqOZHA39mj7MRaicZpYCdR TEEB/kQQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00Eupe-BF; Mon, 10 Jul 2023 20:43:43 +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 , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-openrisc@vger.kernel.org Subject: [PATCH v5 19/38] openrisc: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:20 +0100 Message-Id: <20230710204339.3554919-20-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C8D7E10001C X-Stat-Signature: paqz7rxwu9w36fnoy3znscbg7zknyh96 X-HE-Tag: 1689021848-159070 X-HE-Meta: U2FsdGVkX1/8AFa4aY95Kg6Hl2+QxGzFRsid1ZD75ge+BlpdLHuu6PqvQ6Ic1LJklHjqacJBX6DBMX8w9XA9/e/V8DdQPjBBbtSzTegR17A2fp4p/b1YKrfcTu5t9ruYutsr1hD+srmz9UrxSUcEE3OxC5mIUWzho+98NXCaAoxB9JApoETGiihJoa/aiJZWzjlBVk2ekXqzs/2ReI5FC5gfKhN3GC/XO6TxSGhqJho9Ier6ye94F8wLhCUTyKlqnEscNvuXs/S2sFr+bFeiGbtZQEdZDbS8/xiKvwdHA3dkhAaaiJAvORK/zC9qLPqRrN59qe4KDRH4EGrG/hiU9iJxBJrpgFsp+2B2y7Z+Cko0zND60odIjmiDtqpRSearaIV6heNMd/Z1IJvk3p9wkBW6mqdN5tQnGwMy5VIYKweaOKngkpkcB25UtFNFAfZ3qX5RjKm2UvPgCCQLxJKCQR+GrwTHlr80L5B01GlPm6DgVqBLBvEUAXkaaTR8ICVZa+JKTxd2MXavci+m1fD3Ec80yC0JoEmkkYkML+TsC0gOYRKwJht7moODMkuhU9T2/66/8HxEv5PywL17XNIGu82N6pqRXrv1qkTRtZS+8j9CKrBJIi5qrPh4taaKXfwKr15GRehAF7HrwWrspxZ8y8aROtc5Hy4ES+2a8A0VfqVDUf8srDsgTuuWJ0QnNpKjaiz7VLEHkMyALTHtH+I31NmDrLmd9+eDZQV1oV/kQ0VNe7nIcBBez/iHz7PQEoMBkVvz9F5Yr03OVqxp6+OaRxysYLK5dDnLPkgzSdH3trL2A1zPn4Nv0JdEF4VrIqhbtIKOrZtWRXqszgN6DCJWrxjnqJ3EuTe28vvdYq2eA8DPSnm+Ex0luDaPL0pKs475Li/gXDI4gVS5F9n/m3DcXKPYO4YnjhlDWKvT61Yo9V2FwoaE61gN5182flHeMt+Vx/iGUi7w1K1rPKeNvvh MTdgijVo i/VJqoDPVn/6VfIhBbluOIeCFu2HJydiIUc0kKf/1xKwxiufHNNtnM9pVl8ml+4gWKcLYO6rcotfOND4671glh3xEyGjPuW44Ds/CJqBLeZthXjM70g0+5wASLKOj49/CyjbAphhYK7nucP2B0lGa7XV2I8H2vqYxe9RJN1vBMdzOpKhrO4wQZBgrxnmGJxFslmVge0U42awCV0BseC/FHp5ZsRBDFYhp+SDRBI6hBfZilvZBjizncoV8b/9riGZuaEKSI/5rYcBkLz0= 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: Add PFN_PTE_SHIFT, update_mmu_cache_range() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: linux-openrisc@vger.kernel.org --- arch/openrisc/include/asm/cacheflush.h | 8 +++++++- arch/openrisc/include/asm/pgtable.h | 15 ++++++++++----- arch/openrisc/mm/cache.c | 12 ++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/arch/openrisc/include/asm/cacheflush.h b/arch/openrisc/include/asm/cacheflush.h index eeac40d4a854..984c331ff5f4 100644 --- a/arch/openrisc/include/asm/cacheflush.h +++ b/arch/openrisc/include/asm/cacheflush.h @@ -56,10 +56,16 @@ static inline void sync_icache_dcache(struct page *page) */ #define PG_dc_clean PG_arch_1 +static inline void flush_dcache_folio(struct folio *folio) +{ + clear_bit(PG_dc_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 static inline void flush_dcache_page(struct page *page) { - clear_bit(PG_dc_clean, &page->flags); + flush_dcache_folio(page_folio(page)); } #define flush_icache_user_page(vma, page, addr, len) \ diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h index 3eb9b9555d0d..7bdf1bb0d177 100644 --- a/arch/openrisc/include/asm/pgtable.h +++ b/arch/openrisc/include/asm/pgtable.h @@ -46,7 +46,7 @@ extern void paging_init(void); * hook is made available. */ #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval)) -#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval) + /* * (pmds are folded into pgds so this doesn't get actually called, * but the define is needed for a generic inline function.) @@ -357,6 +357,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) #define __pmd_offset(address) \ (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pte_pfn(x) ((unsigned long)(((x).pte)) >> PAGE_SHIFT) #define pfn_pte(pfn, prot) __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(prot)) @@ -379,13 +380,17 @@ static inline void update_tlb(struct vm_area_struct *vma, extern void update_cache(struct vm_area_struct *vma, unsigned long address, pte_t *pte); -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *pte) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { - update_tlb(vma, address, pte); - update_cache(vma, address, pte); + update_tlb(vma, address, ptep); + update_cache(vma, address, ptep); } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + /* __PHX__ FIXME, SWAP, this probably doesn't work */ /* diff --git a/arch/openrisc/mm/cache.c b/arch/openrisc/mm/cache.c index 534a52ec5e66..eb43b73f3855 100644 --- a/arch/openrisc/mm/cache.c +++ b/arch/openrisc/mm/cache.c @@ -43,15 +43,19 @@ void update_cache(struct vm_area_struct *vma, unsigned long address, pte_t *pte) { unsigned long pfn = pte_val(*pte) >> PAGE_SHIFT; - struct page *page = pfn_to_page(pfn); - int dirty = !test_and_set_bit(PG_dc_clean, &page->flags); + struct folio *folio = page_folio(pfn_to_page(pfn)); + int dirty = !test_and_set_bit(PG_dc_clean, &folio->flags); /* * Since icaches do not snoop for updated data on OpenRISC, we * must write back and invalidate any dirty pages manually. We * can skip data pages, since they will not end up in icaches. */ - if ((vma->vm_flags & VM_EXEC) && dirty) - sync_icache_dcache(page); + if ((vma->vm_flags & VM_EXEC) && dirty) { + unsigned int nr = folio_nr_pages(folio); + + while (nr--) + sync_icache_dcache(folio_page(folio, nr)); + } } From patchwork Mon Jul 10 20:43:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307612 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 874CBC001E0 for ; Mon, 10 Jul 2023 20:44:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55C398E0010; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29CE18E0012; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B73F48E0006; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8C5238E000C for ; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4852C120219 for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) X-FDA: 80996878536.11.2980CC5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 57D72100019 for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=B3VIc80O; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021826; a=rsa-sha256; cv=none; b=7yxRrE/anbhdraldNc8kl6ew1Ub2WyEIPY99KzHfXDsi/pQLqSpXI8Z3H3gkktvLlLKGkk Wrvw+Buq44aNCvXcv0q5A3YZptXCFBzQuHnadoZRGdSb6sRj8fKZ62aN4xEzQySZYg/+aB 1soLceE77Wr1hUj1WiTBc3pv1rJR58c= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=B3VIc80O; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021826; 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=eXHV2JcA2dh0XcKNU/gzTdwGqE1v+tTzv2WVHsOGr9M=; b=pqNAjHF2LAqQieCMp238+EsqEWh/L+I5BXwQILVjpxQ5dkvXv3uRrVJAm5mhOf+44HnUMu XWaK8qDrf6j1ORDfCdSyDBpazSGWIl4jciqxaQ4CEPznsc9cIe5+8wzgh0susKXCN+Ndx1 JBYh3hy9afetQAMY9k/Hm8AqjASgmmA= 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=eXHV2JcA2dh0XcKNU/gzTdwGqE1v+tTzv2WVHsOGr9M=; b=B3VIc80OBWd43RjMo8M572CrEa zGyYC6wIXDYVAo+o+lgp6aTPkjpXshQX68hmVuFOWlBzoPnz3NatZSZVmXtuSWy2OAPZtPyf6z9J+ fHDLATzBpxfxXoTAXtgm1EkuAWXbAtk+OwLXcLoAE8VL04uXdUJzZCSqeJ4p0d+VNXo60/6rULD20 RNRix6CMP0fn7cmXnb3fmGcmhce36CU7xyFVHtOXlxI660M24oAr3q1QId6Bj+qdh4hhD3WCgw1XG /HpnF7VifeCQD/24RQatL/tYDDYAjuMJDGns+7CgNuNsY6Jzh1jIAxVYHqxg5TnoZwSD4xVQhnAqe JUJmn7IQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00Eupp-FK; Mon, 10 Jul 2023 20:43:43 +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 , "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org Subject: [PATCH v5 20/38] parisc: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:21 +0100 Message-Id: <20230710204339.3554919-21-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-Server: rspam08 X-Rspamd-Queue-Id: 57D72100019 X-Stat-Signature: opswm45stu7orjmdjsqrsdyjg9gqch4b X-Rspam-User: X-HE-Tag: 1689021825-273871 X-HE-Meta: U2FsdGVkX1+Z1Id5Ao8zFGr4ax72p/Vus6dIZ1K5WCsI6qnR7o4Tsmh8t7c2DmY8bO/wpzBbGWpAecgefTXz7NG9EaLUtSk5b9frZB7YNrstooqydjfd8uzAT6nZ4k/YZYKrfdpRmQAD8LQKeH5jaGofBjmWfkjsH9GMvPlN7C/C2YzK5GlEHlVJyfyr8ox3cpwXMx/t7mgt9Ud6IuJqc7mmlUuGTt4wsAv7Qi4to5LLEIga2Br7g+ckN/3Rw6OWsho1KOvooVmzjBSmh3SzjPuxZtXrgrAOMQx/1+Lof7sWxEHmCVbz3gObYoWm+nYHIdiaSFgj3ZB/NR8JnFW25HrQTcYC+aABkVxtWbUGgs1YlBSagxmNkOysvnF7PzorLzQKylqTIcApeiDAGxsqDBfxlod2bYlVbMA5M5/oYNVrvxLBWTvEotagtwwGAMHF78cDOO4HAg1mUdHLaO3QYqqmSIbxmFvMZo3PiecOy/3QSXhDzSzo3FUxfq/xhw5LS8gYcFgCxfpfBLxrdvgUZ8mDbWVC1HCf4+UA7XUKRqaMPicNusRMJ7/V+OlZD0NFNiDd8EZw8CnYuOv/C63UMbMjTQFJ/MH/w/Bm4z4NN0h8MaeaLGX5qqEmM+APTcDjg3PD7vM2NIumYQSWutW7CvVCI53+tFliTf/6u5ViJhqCt3ceaWVykzhJPDbG/4UtVdg36gK3gxwsG9nVoLL/93vxk1M4VoXzIZ0Ay0beU6zfJEdMPfsFaHICyR9K4WEw8k28gqqI0GaPe/5YcBgtb16eUiiDO42V2T42Zji9KLWscpkchhcV/yLITnBtDcxuIfKPVpJPKVsgI+Ai+Q19jxFoS92aky4IlNFPwqSu7lnVaYhTOFW3EnVK7VXbcPfYeXQwb9dgJSYEKhP8RBNZi1Ic09GMU3u45kqLG0U8Ifli4C/x+uVgFfz7Yr63VgQATkA9EBdn9UikTvNRnGK ttlR1/dA dY/TreXg74Woldugbgjexyl26lNtU1M4/o04yk2iQY3Sw2rAXWmacQ5X2a2D7nWRQtaBev0XBlyPajPjLcsn5KXeXFpLrg6784SSsg5D5p1bv+ARieKM2XfbhrMxcptZ32ZNOhkAsS13UFKR0XyRwpN+SPoXC5u8TBL8+MxHEydUCLOUMEu+Bh4uhtHFpJczk4eGIF4GJ51l5aYGgw/g6WbzmRQuy98kwMjMrWcnGIBUb3zRS3nT/R6/M0KWWAIYKkqYX8NvsJM1H9Uq73ER2sZ9mWI8WFJz+Tgn6ru87FC2OPrQ= 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: Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: linux-parisc@vger.kernel.org --- arch/parisc/include/asm/cacheflush.h | 14 ++-- arch/parisc/include/asm/pgtable.h | 37 +++++---- arch/parisc/kernel/cache.c | 107 ++++++++++++++++++--------- 3 files changed, 105 insertions(+), 53 deletions(-) diff --git a/arch/parisc/include/asm/cacheflush.h b/arch/parisc/include/asm/cacheflush.h index c8b6928cee1e..b77c3e0c37d3 100644 --- a/arch/parisc/include/asm/cacheflush.h +++ b/arch/parisc/include/asm/cacheflush.h @@ -43,8 +43,13 @@ void invalidate_kernel_vmap_range(void *vaddr, int size); #define flush_cache_vmap(start, end) flush_cache_all() #define flush_cache_vunmap(start, end) flush_cache_all() +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page(struct page *page); +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages) #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages) @@ -53,10 +58,9 @@ void flush_dcache_page(struct page *page); #define flush_dcache_mmap_unlock_irqrestore(mapping, flags) \ xa_unlock_irqrestore(&mapping->i_pages, flags) -#define flush_icache_page(vma,page) do { \ - flush_kernel_dcache_page_addr(page_address(page)); \ - flush_kernel_icache_page(page_address(page)); \ -} while (0) +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr); +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) #define flush_icache_range(s,e) do { \ flush_kernel_dcache_range_asm(s,e); \ diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h index 5656395c95ee..ce38bb375b60 100644 --- a/arch/parisc/include/asm/pgtable.h +++ b/arch/parisc/include/asm/pgtable.h @@ -73,15 +73,6 @@ extern void __update_cache(pte_t pte); mb(); \ } while(0) -#define set_pte_at(mm, addr, pteptr, pteval) \ - do { \ - if (pte_present(pteval) && \ - pte_user(pteval)) \ - __update_cache(pteval); \ - *(pteptr) = (pteval); \ - purge_tlb_entries(mm, addr); \ - } while (0) - #endif /* !__ASSEMBLY__ */ #define pte_ERROR(e) \ @@ -285,7 +276,7 @@ extern unsigned long *empty_zero_page; #define pte_none(x) (pte_val(x) == 0) #define pte_present(x) (pte_val(x) & _PAGE_PRESENT) #define pte_user(x) (pte_val(x) & _PAGE_USER) -#define pte_clear(mm, addr, xp) set_pte_at(mm, addr, xp, __pte(0)) +#define pte_clear(mm, addr, xp) set_pte(xp, __pte(0)) #define pmd_flag(x) (pmd_val(x) & PxD_FLAG_MASK) #define pmd_address(x) ((unsigned long)(pmd_val(x) &~ PxD_FLAG_MASK) << PxD_VALUE_SHIFT) @@ -391,11 +382,29 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) extern void paging_init (void); +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) +{ + if (pte_present(pte) && pte_user(pte)) + __update_cache(pte); + for (;;) { + *ptep = pte; + purge_tlb_entries(mm, addr); + if (--nr == 0) + break; + ptep++; + pte_val(pte) += 1 << PFN_PTE_SHIFT; + addr += PAGE_SIZE; + } +} +#define set_ptes set_ptes + /* Used for deferring calls to flush_dcache_page() */ #define PG_dcache_dirty PG_arch_1 -#define update_mmu_cache(vms,addr,ptep) __update_cache(*ptep) +#define update_mmu_cache_range(vmf, vma, addr, ptep, nr) __update_cache(*ptep) +#define update_mmu_cache(vma, addr, ptep) __update_cache(*ptep) /* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that @@ -450,7 +459,7 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned if (!pte_young(pte)) { return 0; } - set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte)); + set_pte(ptep, pte_mkold(pte)); return 1; } @@ -460,14 +469,14 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t old_pte; old_pte = *ptep; - set_pte_at(mm, addr, ptep, __pte(0)); + set_pte(ptep, __pte(0)); return old_pte; } static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { - set_pte_at(mm, addr, ptep, pte_wrprotect(*ptep)); + set_pte(ptep, pte_wrprotect(*ptep)); } #define pte_same(A,B) (pte_val(A) == pte_val(B)) diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c index b55b35c89d6a..442109a48940 100644 --- a/arch/parisc/kernel/cache.c +++ b/arch/parisc/kernel/cache.c @@ -94,11 +94,11 @@ static inline void flush_data_cache(void) /* Kernel virtual address of pfn. */ #define pfn_va(pfn) __va(PFN_PHYS(pfn)) -void -__update_cache(pte_t pte) +void __update_cache(pte_t pte) { unsigned long pfn = pte_pfn(pte); - struct page *page; + struct folio *folio; + unsigned int nr; /* We don't have pte special. As a result, we can be called with an invalid pfn and we don't need to flush the kernel dcache page. @@ -106,13 +106,17 @@ __update_cache(pte_t pte) if (!pfn_valid(pfn)) return; - page = pfn_to_page(pfn); - if (page_mapping_file(page) && - test_bit(PG_dcache_dirty, &page->flags)) { - flush_kernel_dcache_page_addr(pfn_va(pfn)); - clear_bit(PG_dcache_dirty, &page->flags); + folio = page_folio(pfn_to_page(pfn)); + pfn = folio_pfn(folio); + nr = folio_nr_pages(folio); + if (folio_flush_mapping(folio) && + test_bit(PG_dcache_dirty, &folio->flags)) { + while (nr--) + flush_kernel_dcache_page_addr(pfn_va(pfn + nr)); + clear_bit(PG_dcache_dirty, &folio->flags); } else if (parisc_requires_coherency()) - flush_kernel_dcache_page_addr(pfn_va(pfn)); + while (nr--) + flush_kernel_dcache_page_addr(pfn_va(pfn + nr)); } void @@ -366,6 +370,20 @@ static void flush_user_cache_page(struct vm_area_struct *vma, unsigned long vmad preempt_enable(); } +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr) +{ + void *kaddr = page_address(page); + + for (;;) { + flush_kernel_dcache_page_addr(kaddr); + flush_kernel_icache_page(kaddr); + if (--nr == 0) + break; + kaddr += PAGE_SIZE; + } +} + static inline pte_t *get_ptep(struct mm_struct *mm, unsigned long addr) { pte_t *ptep = NULL; @@ -394,27 +412,30 @@ static inline bool pte_needs_flush(pte_t pte) == (_PAGE_PRESENT | _PAGE_ACCESSED); } -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { - struct address_space *mapping = page_mapping_file(page); - struct vm_area_struct *mpnt; - unsigned long offset; + struct address_space *mapping = folio_flush_mapping(folio); + struct vm_area_struct *vma; unsigned long addr, old_addr = 0; + void *kaddr; unsigned long count = 0; - unsigned long flags; + unsigned long i, nr, flags; pgoff_t pgoff; if (mapping && !mapping_mapped(mapping)) { - set_bit(PG_dcache_dirty, &page->flags); + set_bit(PG_dcache_dirty, &folio->flags); return; } - flush_kernel_dcache_page_addr(page_address(page)); + nr = folio_nr_pages(folio); + kaddr = folio_address(folio); + for (i = 0; i < nr; i++) + flush_kernel_dcache_page_addr(kaddr + i * PAGE_SIZE); if (!mapping) return; - pgoff = page->index; + pgoff = folio->index; /* * We have carefully arranged in arch_get_unmapped_area() that @@ -424,20 +445,33 @@ void flush_dcache_page(struct page *page) * on machines that support equivalent aliasing */ flush_dcache_mmap_lock_irqsave(mapping, flags); - vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { - offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT; - addr = mpnt->vm_start + offset; - if (parisc_requires_coherency()) { - bool needs_flush = false; - pte_t *ptep; + vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff + nr - 1) { + unsigned long offset = pgoff - vma->vm_pgoff; + unsigned long pfn = folio_pfn(folio); + + addr = vma->vm_start; + nr = folio_nr_pages(folio); + if (offset > -nr) { + pfn -= offset; + nr += offset; + } else { + addr += offset * PAGE_SIZE; + } + if (addr + nr * PAGE_SIZE > vma->vm_end) + nr = (vma->vm_end - addr) / PAGE_SIZE; - ptep = get_ptep(mpnt->vm_mm, addr); - if (ptep) { - needs_flush = pte_needs_flush(*ptep); + if (parisc_requires_coherency()) { + for (i = 0; i < nr; i++) { + pte_t *ptep = get_ptep(vma->vm_mm, + addr + i * PAGE_SIZE); + if (!ptep) + continue; + if (pte_needs_flush(*ptep)) + flush_user_cache_page(vma, + addr + i * PAGE_SIZE); + /* Optimise accesses to the same table? */ pte_unmap(ptep); } - if (needs_flush) - flush_user_cache_page(mpnt, addr); } else { /* * The TLB is the engine of coherence on parisc: @@ -450,27 +484,32 @@ void flush_dcache_page(struct page *page) * in (until the user or kernel specifically * accesses it, of course) */ - flush_tlb_page(mpnt, addr); + for (i = 0; i < nr; i++) + flush_tlb_page(vma, addr + i * PAGE_SIZE); if (old_addr == 0 || (old_addr & (SHM_COLOUR - 1)) != (addr & (SHM_COLOUR - 1))) { - __flush_cache_page(mpnt, addr, page_to_phys(page)); + for (i = 0; i < nr; i++) + __flush_cache_page(vma, + addr + i * PAGE_SIZE, + (pfn + i) * PAGE_SIZE); /* * Software is allowed to have any number * of private mappings to a page. */ - if (!(mpnt->vm_flags & VM_SHARED)) + if (!(vma->vm_flags & VM_SHARED)) continue; if (old_addr) pr_err("INEQUIVALENT ALIASES 0x%lx and 0x%lx in file %pD\n", - old_addr, addr, mpnt->vm_file); - old_addr = addr; + old_addr, addr, vma->vm_file); + if (nr == folio_nr_pages(folio)) + old_addr = addr; } } WARN_ON(++count == 4096); } flush_dcache_mmap_unlock_irqrestore(mapping, flags); } -EXPORT_SYMBOL(flush_dcache_page); +EXPORT_SYMBOL(flush_dcache_folio); /* Defined in arch/parisc/kernel/pacache.S */ EXPORT_SYMBOL(flush_kernel_dcache_range_asm); From patchwork Mon Jul 10 20:43:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307619 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 DDB21EB64DA for ; Mon, 10 Jul 2023 20:44:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4710C8E0015; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 421F08E0013; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FD838E0015; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0EC688E0013 for ; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C42F6120241 for ; Mon, 10 Jul 2023 20:43:50 +0000 (UTC) X-FDA: 80996878620.19.884678B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 0315F1C001B for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l9kaSur2; dmarc=none; spf=none (imf20.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=1689021829; 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=j/7dUwRRHtvw/GvWecTN2dD8kupNRDePMFLGED6iGvE=; b=y/I172RoP2ErOMTBm+0hGbT0JVPu1+IMuNTk+bGUp2QB4pCrpDK2YUfvUr/PBtMHaZruR7 fa0nc0EoJw8IBSaNaQMe65yV3/hJHjaaoVO47PJdNZqBlUTv8bEzLNbSLVGX11LNyLFl+l Mv/WmzjBjVYepZf94ajQl460+9jHtsg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l9kaSur2; dmarc=none; spf=none (imf20.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=1689021829; a=rsa-sha256; cv=none; b=GQ9Pl8U5rXuJ++4PL/UfMvetFwO4j5JteA9enI0G1aipoGTiFDY9zbaY80CQjmTa1ioyIN 9d+C2eV+rCJ98yz2yTsSOBpmt99Nvg1p0UQ5e3loeHtuzrOJOtEoH4PPVk4N+j0yDmvlb8 A21pZSZvTocn3Z8QkM/AUMRjLOecdZQ= 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=j/7dUwRRHtvw/GvWecTN2dD8kupNRDePMFLGED6iGvE=; b=l9kaSur2Mas97HqlEi14GcqOKX oHghEDA7b9YPf5IiU02uYiOiueJPzhRmbq0LOidMuxyUveKyxiIGXeMZVOypVgyR0PTOYHyrd+DYE 55JDwzhlQxB/BucsOjkBO0iYTn8/e1sPmza7Rpiq7s7URszxOMKThKh1KupfNQOCD1sBkER3YvYOA FnZFvchFaiZaAI6R4IMQKtde4b6O3QmKbB+NqfKuKkX4dSPsvjzy9+rpcFQg56mJpoLnbSaOoXjNe Y4mm0/tVHs5XdQUkeFDqlt1YOqNVJb0Q+VXARukWQp1BVhZl5qeBQl6I5iW6tQHeJfEjXFJ41FE5f GM6XjuVg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00Eupu-JU; Mon, 10 Jul 2023 20:43:43 +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 , Michael Ellerman , Nicholas Piggin , Christophe Leroy , linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 21/38] powerpc: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:22 +0100 Message-Id: <20230710204339.3554919-22-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: 0315F1C001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: qbg3gatc5rkd95eptsqrhpfwnr87wte6 X-HE-Tag: 1689021828-876907 X-HE-Meta: U2FsdGVkX1/DPr1KhfAVR+pLFuXTKJnUjeOWnSXLriy/zt42pTDxcUyF7q+tY8Weelo+EfMwTzrerfRnr7bD56fb8HtUEl/Szb99OMGY+bxDMfvgi4BfVKABFjHhs9O+2kcIpfu6xT+8uAJeYnK/QU9D9Zwytjh1VTxF3hs7YRN8Weyuw6QnYjy4qnrFTHtSDkmx/p3a6ZLNXgkNViSBuSD0XaBIX5R5rv9IbGl4ZNILpHUZDS3Ovj8RKI/yzEdd/9lxI4IjpM0vadlGth13DROcc4Bh7GdRMkPeqVkszqX3J8bnpM+jWY14uqQ5/0SP5M/m3Yd7XBToMI8xRg457/G1EYug7qvC/0DQMP+hXqz3dEHxQhJgswPsAhHNHX3G3Y3ZvtlC+TRiIr8FHzvqjt/QRfeP2Ca3Q//01UezAlhM2a37iYLK22t2qlRHaXcUgZq3AHFKdi8yBxgwFOcQ/mT6mDn5oqQQSV+nVuSNf+rxgmckI6Ao66/229LXp0MOo+TTaK/mS1om+1YRaoIt6YvuvOEZaiYndcDPQIQx2X+Cerlgkpls0tMcB51MqB+flWfXXInWxy537abySlFYcjdLJ6+3WC43ckEXkmHdTmb+rFHdH/Q5W3rJ/g+rAuhBk2cDZ4opa9UmzJohGw8w30Yw78oHF8CD9WFI+gMLd53OIIKW3GvFJoraltOrfctRycjueBz5d2znl+ZjovN74ED736xOYCHOk8lAKQTCgPfuAyGDY7vpCtImKNZqya+2HYlEt7KeG3d0jq2vRTMVw6qF9Iogyu/LneGkpKZKo4Wnosf8lNJ+zJacjmt+hlsZNSGVQhq8zmswqFnP2WVAV0nuz5SRGs103ypypW9u/ssAYdIzXEP96a3BzNd+LW6zHBce99tDYOcZWU5kUbM7bZtEh78Zv3O0XylY/6N4UHjDlhy+V6+gTCzC4OCFimDobPcDTLjixJPu9cgdBW/ VaNlWfaJ tF8qgcOEQnGbndgUqsDoVyRrlIzflkQqzv767c+JgF1Sm3Vv/oxlcz8/uWWP/GP2pAW4XPOjT4asAIEcpPZcgkIqZ6lzzVKAHDnH8Op6BNpPikkQkuFRXfIRSL5mdXhvu9X7hb9fnCVA2/MP3Vx1dtdzfEI2m8cSqCc40nmND09rfgtIqjC8iOIBaO3fZjV/OGO4fNn0BORC3VKEo/PrdbCX+B9jwkuz13FWMoCnTj8Yjz1JmQB6LLV7B5T//HTqa8Xg8LHRedV5L1+3oItIZWB1F/AVLmRPiRE2WBey6u0mlCs2ASJaeNPnwvgXRnKN0yMA9vsGz4CgqY/smsMiGVgGsE5sTH6PeiOekMd+EDrGyVqUqM3bYngeGaisz6EwWzCLN 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: Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org Reviewed-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/pgtable.h | 5 -- arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +-- arch/powerpc/include/asm/book3s/pgtable.h | 11 ++--- arch/powerpc/include/asm/cacheflush.h | 14 ++++-- arch/powerpc/include/asm/kvm_ppc.h | 10 ++-- arch/powerpc/include/asm/nohash/pgtable.h | 16 ++---- arch/powerpc/include/asm/pgtable.h | 12 +++++ arch/powerpc/mm/book3s64/hash_utils.c | 11 +++-- arch/powerpc/mm/cacheflush.c | 40 +++++---------- arch/powerpc/mm/nohash/e500_hugetlbpage.c | 3 +- arch/powerpc/mm/pgtable.c | 51 +++++++++++--------- 11 files changed, 86 insertions(+), 93 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h index 7bf1fe7297c6..5f12b9382909 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -462,11 +462,6 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) pgprot_val(pgprot)); } -static inline unsigned long pte_pfn(pte_t pte) -{ - return pte_val(pte) >> PTE_RPN_SHIFT; -} - /* Generic modifiers for PTE bits */ static inline pte_t pte_wrprotect(pte_t pte) { diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index 4acc9690f599..c5baa3082a5a 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -104,6 +104,7 @@ * and every thing below PAGE_SHIFT; */ #define PTE_RPN_MASK (((1UL << _PAGE_PA_MAX) - 1) & (PAGE_MASK)) +#define PTE_RPN_SHIFT PAGE_SHIFT /* * set of bits not changed in pmd_modify. Even though we have hash specific bits * in here, on radix we expect them to be zero. @@ -569,11 +570,6 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) return __pte(((pte_basic_t)pfn << PAGE_SHIFT) | pgprot_val(pgprot) | _PAGE_PTE); } -static inline unsigned long pte_pfn(pte_t pte) -{ - return (pte_val(pte) & PTE_RPN_MASK) >> PAGE_SHIFT; -} - /* Generic modifiers for PTE bits */ static inline pte_t pte_wrprotect(pte_t pte) { diff --git a/arch/powerpc/include/asm/book3s/pgtable.h b/arch/powerpc/include/asm/book3s/pgtable.h index d18b748ea3ae..3b7bd36a2321 100644 --- a/arch/powerpc/include/asm/book3s/pgtable.h +++ b/arch/powerpc/include/asm/book3s/pgtable.h @@ -9,13 +9,6 @@ #endif #ifndef __ASSEMBLY__ -/* Insert a PTE, top-level function is out of line. It uses an inline - * low level function in the respective pgtable-* files - */ -extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, - pte_t pte); - - #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t entry, int dirty); @@ -36,7 +29,9 @@ void __update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t * corresponding HPTE into the hash table ahead of time, instead of * waiting for the inevitable extra hash-table miss exception. */ -static inline void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { if (IS_ENABLED(CONFIG_PPC32) && !mmu_has_feature(MMU_FTR_HPTE_TABLE)) return; diff --git a/arch/powerpc/include/asm/cacheflush.h b/arch/powerpc/include/asm/cacheflush.h index 7564dd4fd12b..ef7d2de33b89 100644 --- a/arch/powerpc/include/asm/cacheflush.h +++ b/arch/powerpc/include/asm/cacheflush.h @@ -35,13 +35,19 @@ static inline void flush_cache_vmap(unsigned long start, unsigned long end) * It just marks the page as not i-cache clean. We do the i-cache * flush later when the page is given to a user process, if necessary. */ -static inline void flush_dcache_page(struct page *page) +static inline void flush_dcache_folio(struct folio *folio) { if (cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) return; /* avoid an atomic op if possible */ - if (test_bit(PG_dcache_clean, &page->flags)) - clear_bit(PG_dcache_clean, &page->flags); + if (test_bit(PG_dcache_clean, &folio->flags)) + clear_bit(PG_dcache_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); } void flush_icache_range(unsigned long start, unsigned long stop); @@ -51,7 +57,7 @@ void flush_icache_user_page(struct vm_area_struct *vma, struct page *page, unsigned long addr, int len); #define flush_icache_user_page flush_icache_user_page -void flush_dcache_icache_page(struct page *page); +void flush_dcache_icache_folio(struct folio *folio); /** * flush_dcache_range(): Write any modified data cache blocks out to memory and diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index d16d80ad2ae4..b4da8514af43 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -894,7 +894,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids); static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn) { - struct page *page; + struct folio *folio; /* * We can only access pages that the kernel maps * as memory. Bail out for unmapped ones. @@ -903,10 +903,10 @@ static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn) return; /* Clear i-cache for new pages */ - page = pfn_to_page(pfn); - if (!test_bit(PG_dcache_clean, &page->flags)) { - flush_dcache_icache_page(page); - set_bit(PG_dcache_clean, &page->flags); + folio = page_folio(pfn_to_page(pfn)); + if (!test_bit(PG_dcache_clean, &folio->flags)) { + flush_dcache_icache_folio(folio); + set_bit(PG_dcache_clean, &folio->flags); } } diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h index a6caaaab6f92..56ea48276356 100644 --- a/arch/powerpc/include/asm/nohash/pgtable.h +++ b/arch/powerpc/include/asm/nohash/pgtable.h @@ -101,8 +101,6 @@ static inline bool pte_access_permitted(pte_t pte, bool write) static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) { return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) | pgprot_val(pgprot)); } -static inline unsigned long pte_pfn(pte_t pte) { - return pte_val(pte) >> PTE_RPN_SHIFT; } /* Generic modifiers for PTE bits */ static inline pte_t pte_exprotect(pte_t pte) @@ -166,12 +164,6 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) return __pte(pte_val(pte) & ~_PAGE_SWP_EXCLUSIVE); } -/* Insert a PTE, top-level function is out of line. It uses an inline - * low level function in the respective pgtable-* files - */ -extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, - pte_t pte); - /* This low level function performs the actual PTE insertion * Setting the PTE depends on the MMU type and other factors. It's * an horrible mess that I'm not going to try to clean up now but @@ -282,10 +274,12 @@ static inline int pud_huge(pud_t pud) * for the page which has just been mapped in. */ #if defined(CONFIG_PPC_E500) && defined(CONFIG_HUGETLB_PAGE) -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep); +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr); #else -static inline -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) {} +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) {} #endif #endif /* __ASSEMBLY__ */ diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h index 445a22987aa3..da5119dba8a4 100644 --- a/arch/powerpc/include/asm/pgtable.h +++ b/arch/powerpc/include/asm/pgtable.h @@ -41,6 +41,12 @@ struct mm_struct; #ifndef __ASSEMBLY__ +void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, + pte_t pte, unsigned int nr); +#define set_ptes set_ptes +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + #ifndef MAX_PTRS_PER_PGD #define MAX_PTRS_PER_PGD PTRS_PER_PGD #endif @@ -48,6 +54,12 @@ struct mm_struct; /* Keep these as a macros to avoid include dependency mess */ #define pte_page(x) pfn_to_page(pte_pfn(x)) #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) + +static inline unsigned long pte_pfn(pte_t pte) +{ + return (pte_val(pte) & PTE_RPN_MASK) >> PTE_RPN_SHIFT; +} + /* * Select all bits except the pfn */ diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index fedffe3ae136..ad2afa08e62e 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -1307,18 +1307,19 @@ void hash__early_init_mmu_secondary(void) */ unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap) { - struct page *page; + struct folio *folio; if (!pfn_valid(pte_pfn(pte))) return pp; - page = pte_page(pte); + folio = page_folio(pte_page(pte)); /* page is dirty */ - if (!test_bit(PG_dcache_clean, &page->flags) && !PageReserved(page)) { + if (!test_bit(PG_dcache_clean, &folio->flags) && + !folio_test_reserved(folio)) { if (trap == INTERRUPT_INST_STORAGE) { - flush_dcache_icache_page(page); - set_bit(PG_dcache_clean, &page->flags); + flush_dcache_icache_folio(folio); + set_bit(PG_dcache_clean, &folio->flags); } else pp |= HPTE_R_N; } diff --git a/arch/powerpc/mm/cacheflush.c b/arch/powerpc/mm/cacheflush.c index 0e9b4879c0f9..8760d2223abe 100644 --- a/arch/powerpc/mm/cacheflush.c +++ b/arch/powerpc/mm/cacheflush.c @@ -148,44 +148,30 @@ static void __flush_dcache_icache(void *p) invalidate_icache_range(addr, addr + PAGE_SIZE); } -static void flush_dcache_icache_hugepage(struct page *page) +void flush_dcache_icache_folio(struct folio *folio) { - int i; - int nr = compound_nr(page); + unsigned int i, nr = folio_nr_pages(folio); - if (!PageHighMem(page)) { + if (flush_coherent_icache()) + return; + + if (!folio_test_highmem(folio)) { + void *addr = folio_address(folio); for (i = 0; i < nr; i++) - __flush_dcache_icache(lowmem_page_address(page + i)); - } else { + __flush_dcache_icache(addr + i * PAGE_SIZE); + } else if (IS_ENABLED(CONFIG_BOOKE) || sizeof(phys_addr_t) > sizeof(void *)) { for (i = 0; i < nr; i++) { - void *start = kmap_local_page(page + i); + void *start = kmap_local_folio(folio, i * PAGE_SIZE); __flush_dcache_icache(start); kunmap_local(start); } - } -} - -void flush_dcache_icache_page(struct page *page) -{ - if (flush_coherent_icache()) - return; - - if (PageCompound(page)) - return flush_dcache_icache_hugepage(page); - - if (!PageHighMem(page)) { - __flush_dcache_icache(lowmem_page_address(page)); - } else if (IS_ENABLED(CONFIG_BOOKE) || sizeof(phys_addr_t) > sizeof(void *)) { - void *start = kmap_local_page(page); - - __flush_dcache_icache(start); - kunmap_local(start); } else { - flush_dcache_icache_phys(page_to_phys(page)); + unsigned long pfn = folio_pfn(folio); + for (i = 0; i < nr; i++) + flush_dcache_icache_phys((pfn + i) * PAGE_SIZE); } } -EXPORT_SYMBOL(flush_dcache_icache_page); void clear_user_page(void *page, unsigned long vaddr, struct page *pg) { diff --git a/arch/powerpc/mm/nohash/e500_hugetlbpage.c b/arch/powerpc/mm/nohash/e500_hugetlbpage.c index 58c8d9849cb1..6b30e40d4590 100644 --- a/arch/powerpc/mm/nohash/e500_hugetlbpage.c +++ b/arch/powerpc/mm/nohash/e500_hugetlbpage.c @@ -178,7 +178,8 @@ book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea, pte_t pte) * * This must always be called with the pte lock held. */ -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr) { if (is_vm_hugetlb_page(vma)) book3e_hugetlb_preload(vma, address, *ptep); diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index cb2dcdb18f8e..db236b494845 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -58,7 +58,7 @@ static inline int pte_looks_normal(pte_t pte) return 0; } -static struct page *maybe_pte_to_page(pte_t pte) +static struct folio *maybe_pte_to_folio(pte_t pte) { unsigned long pfn = pte_pfn(pte); struct page *page; @@ -68,7 +68,7 @@ static struct page *maybe_pte_to_page(pte_t pte) page = pfn_to_page(pfn); if (PageReserved(page)) return NULL; - return page; + return page_folio(page); } #ifdef CONFIG_PPC_BOOK3S @@ -84,12 +84,12 @@ static pte_t set_pte_filter_hash(pte_t pte) pte = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS); if (pte_looks_normal(pte) && !(cpu_has_feature(CPU_FTR_COHERENT_ICACHE) || cpu_has_feature(CPU_FTR_NOEXECUTE))) { - struct page *pg = maybe_pte_to_page(pte); - if (!pg) + struct folio *folio = maybe_pte_to_folio(pte); + if (!folio) return pte; - if (!test_bit(PG_dcache_clean, &pg->flags)) { - flush_dcache_icache_page(pg); - set_bit(PG_dcache_clean, &pg->flags); + if (!test_bit(PG_dcache_clean, &folio->flags)) { + flush_dcache_icache_folio(folio); + set_bit(PG_dcache_clean, &folio->flags); } } return pte; @@ -107,7 +107,7 @@ static pte_t set_pte_filter_hash(pte_t pte) { return pte; } */ static inline pte_t set_pte_filter(pte_t pte) { - struct page *pg; + struct folio *folio; if (radix_enabled()) return pte; @@ -120,18 +120,18 @@ static inline pte_t set_pte_filter(pte_t pte) return pte; /* If you set _PAGE_EXEC on weird pages you're on your own */ - pg = maybe_pte_to_page(pte); - if (unlikely(!pg)) + folio = maybe_pte_to_folio(pte); + if (unlikely(!folio)) return pte; /* If the page clean, we move on */ - if (test_bit(PG_dcache_clean, &pg->flags)) + if (test_bit(PG_dcache_clean, &folio->flags)) return pte; /* If it's an exec fault, we flush the cache and make it clean */ if (is_exec_fault()) { - flush_dcache_icache_page(pg); - set_bit(PG_dcache_clean, &pg->flags); + flush_dcache_icache_folio(folio); + set_bit(PG_dcache_clean, &folio->flags); return pte; } @@ -142,7 +142,7 @@ static inline pte_t set_pte_filter(pte_t pte) static pte_t set_access_flags_filter(pte_t pte, struct vm_area_struct *vma, int dirty) { - struct page *pg; + struct folio *folio; if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) return pte; @@ -168,17 +168,17 @@ static pte_t set_access_flags_filter(pte_t pte, struct vm_area_struct *vma, #endif /* CONFIG_DEBUG_VM */ /* If you set _PAGE_EXEC on weird pages you're on your own */ - pg = maybe_pte_to_page(pte); - if (unlikely(!pg)) + folio = maybe_pte_to_folio(pte); + if (unlikely(!folio)) goto bail; /* If the page is already clean, we move on */ - if (test_bit(PG_dcache_clean, &pg->flags)) + if (test_bit(PG_dcache_clean, &folio->flags)) goto bail; /* Clean the page and set PG_dcache_clean */ - flush_dcache_icache_page(pg); - set_bit(PG_dcache_clean, &pg->flags); + flush_dcache_icache_folio(folio); + set_bit(PG_dcache_clean, &folio->flags); bail: return pte_mkexec(pte); @@ -187,8 +187,8 @@ static pte_t set_access_flags_filter(pte_t pte, struct vm_area_struct *vma, /* * set_pte stores a linux PTE into the linux page table. */ -void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, - pte_t pte) +void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, + pte_t pte, unsigned int nr) { /* * Make sure hardware valid bit is not set. We don't do @@ -203,7 +203,14 @@ void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte = set_pte_filter(pte); /* Perform the setting of the PTE */ - __set_pte_at(mm, addr, ptep, pte, 0); + for (;;) { + __set_pte_at(mm, addr, ptep, pte, 0); + if (--nr == 0) + break; + ptep++; + pte = __pte(pte_val(pte) + (1UL << PTE_RPN_SHIFT)); + addr += PAGE_SIZE; + } } void unmap_kernel_page(unsigned long va) From patchwork Mon Jul 10 20:43:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307614 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 72E2EEB64DA for ; Mon, 10 Jul 2023 20:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E396E8E000B; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D958A8E0015; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 696968E0011; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D87C58E000E for ; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A34BF1A017E for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) X-FDA: 80996878536.09.0DCCC89 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id 982C9140005 for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=v6vtdEYG; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021827; a=rsa-sha256; cv=none; b=E9YF1k0U0zu8FyRZcRtVZiS3X6qygxfTqODQYB6yDnir95Jx4OFT/5m8BrfxiJPr4wcWIu 1mc4mLyt/zYIpxvMYZlM9MkazpwD7GbBuqmrp3rMIsFLoji2J/HxPAr2vGFgMC9yV2+WyU vBMdcEeo78BBNc/EkKuShQdVCrButTo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=v6vtdEYG; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021826; 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=n5JuGTxMehujF2hW5yjYC2rYcF2MyOBRN8Ek1lm+OQ8=; b=Q24YFr8i+xluymkMOBMxED2rA1xrYHrJh3J37gZ3k+Yp2lXkDsYv+eQyLxaf/+7fcXyTXt f8LkmQWcDiBafFPh/IcnFqrdcGd45EkmfpZLoXfM8H5cq5F/1hJ1Oyuhod9LVI3rBZZ2Oa WaO6232EYc2X6jcFOyG7PYpOtKvH2m0= 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=n5JuGTxMehujF2hW5yjYC2rYcF2MyOBRN8Ek1lm+OQ8=; b=v6vtdEYGO07DAE5iFQ66CUz422 4gRsIdrkhM465InPQ8/JnqOq0IG7KzUhaCoe3gRmSP4XJCbA1zUml/Y4VS6dAKxZZ4N/5RZjHuN87 qFAsrNfw7teoWxYTYbZCiF8pFZnjmUgiRCzzjcwDtmgtr8VAUvFeuhmF6ab90f3xCGgsog6KA9feL W5DhRN/ugE2aKKCau9+a+puGlTUVZRO+aEhD4bYP+PsCwD2qvvkUWtuFTy9VYMt8pfiQ9Y3V/60BF /hxmrNg806AS1AMQX5X5zpKy/CC56VqSPSMoXWpMaWWUUVHCgBTLtfpRRCK/7rtJ4XjW3BA93ABwT inAW3qHA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00Eupy-NG; Mon, 10 Jul 2023 20:43:43 +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, Alexandre Ghiti , Mike Rapoport , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Subject: [PATCH v5 22/38] riscv: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:23 +0100 Message-Id: <20230710204339.3554919-23-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-Server: rspam08 X-Rspamd-Queue-Id: 982C9140005 X-Stat-Signature: rhw3g9sq7tnbsjycn4xtxap1x8cre9km X-Rspam-User: X-HE-Tag: 1689021826-560492 X-HE-Meta: U2FsdGVkX1/eXdYduRDtQDk4FqMQBb8QxcE9GES3omr7p0yRJ3GsXdP/wC/eJON8DRbYRlkPChJXVXn4RG3s/z+4XuMgbX2+PkQp2vFL4SoibB/fw2Rf1JH2/DvviV69WdTIJ/aE9zrFYTbpRflq5iheBPLQRv36LiOFn+o4w5rm1x7+ihZF3Tq0c2Nez3ybT1D+kcwZ6EQnUl+2M2vuDJYC6wMeYXJRCfeGs701Ngy6MUEZ8ecoMAGlkgiH5GjPng5UyyBKIVOeM4iD0YVSUhpfewbTTjg3cd8wZiwx21TC3uc7TpLDtsYlb6JcSV+PqEX4sKI+9AufWczWfx/RnrdWMTxgXyEU+llFYcahpQw+wBYPD9Xqf4tf2Qpwb4+IHkR90uXEAiPfkzzGM8pN4ESk9z6SpZaCcsLyOFjR3EsquCcwalOh6nm1qi5/wkGINGY4Ko5cHmqMT729SwVi733kYWvNJBJ0X9mRLzcjVfb/jFJkLKYCWk4Rg29GzUDFiQgi+4zF7L4w3n5zZ4XR/rrAz6B1s7iWqfe1LGl75IDKXJotmBydG4K45Cbsz9aMEzmHC9V+Ow0VTz2ZhwbkDTcsmV0xI7qtzZFeGWBl/COPbC8J8/PvKzbgU8Gn8046gIiQWDGtDYk3UQ1VKrGmBhHvqvYO1MoCuo5NL7VBe0eM7B+S3QCt9JG1CHIqU7Qs6k/MVkON+L6DMGV9yX5IU3cntZEJH3nAmaWSq9e+rdc5dCZJCNMlkrHWabOLCddBe4Bbv6K+Jk4lGLe9Y3JKzskOynkXXz+XuNIwajBc/czFYb/E/8b65q5CaWoppmeDy93Icuhg4rfAPWP3qXLmBQ4mf3fIKzRnBAP6SdT8W6Duek+5gHPoi/q9/2rBHp9loiy8u14X1YAIriAENfxkd9c+pf1S9+N/GHabHmeI+Tx8J/3pqnu1MUbya5Cg27kyM0C5RWSI0JXqjP5KnKn Kv+Lotwx WSa2j2+nViODoxh0udUd7i02i8NIFdxAVg+B6bTUwF+1TenQEYN43Vnlg2gwIKfnGw2/ywfepvlTplvtE86cTRdA70cjLNuK3ftzown5yXR466I9wKYE3y5MVJEEoLMKiTsz5cZLH/1osivOZs0EC+lzniSE6urosC8PBlwzbWfiNREn7XFF1tgI8FPHclYyZ8SGkhZ6HOQFa/h8dwAoYBzJVmNGqfgb498lduS6PwsIlOQnrUZyHN0oS1xpcW+S63r5rD1RHxsvsWFk9dAgCQ1/qqSJJA3HgtI437ssOLzDJyN2gX+lZBFRTUF/YC2uQ2RiFUQ3tBU3ynXF4dBOI8p6IK0gW/sXtBJAjuOGtSozLjobxrJxQKQeFi/gZ1tHoOrntVrq5zy9Pgl2mOyq04uWw9D68vk8e0ailMjKznM2vCho= 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: Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Alexandre Ghiti Acked-by: Mike Rapoport (IBM) Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: linux-riscv@lists.infradead.org Acked-by: Palmer Dabbelt --- arch/riscv/include/asm/cacheflush.h | 19 +++++++-------- arch/riscv/include/asm/pgtable.h | 38 +++++++++++++++++++---------- arch/riscv/mm/cacheflush.c | 13 +++------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index 8091b8bf4883..0d8c92c5dfb7 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -15,20 +15,19 @@ static inline void local_flush_icache_all(void) #define PG_dcache_clean PG_arch_1 -static inline void flush_dcache_page(struct page *page) +static inline void flush_dcache_folio(struct folio *folio) { - /* - * HugeTLB pages are always fully mapped and only head page will be - * set PG_dcache_clean (see comments in flush_icache_pte()). - */ - if (PageHuge(page)) - page = compound_head(page); - - if (test_bit(PG_dcache_clean, &page->flags)) - clear_bit(PG_dcache_clean, &page->flags); + if (test_bit(PG_dcache_clean, &folio->flags)) + clear_bit(PG_dcache_clean, &folio->flags); } +#define flush_dcache_folio flush_dcache_folio #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} + /* * RISC-V doesn't have an instruction to flush parts of the instruction cache, * so instead we just flush the whole thing. diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 2137e36595b3..c8f897ed5fd0 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -445,8 +445,9 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) /* Commit new configuration to MMU hardware */ -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { /* * The kernel assumes that TLBs don't cache invalid entries, but @@ -455,8 +456,11 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, * Relying on flush_tlb_fix_spurious_fault would suffice, but * the extra traps reduce performance. So, eagerly SFENCE.VMA. */ - local_flush_tlb_page(address); + while (nr--) + local_flush_tlb_page(address + nr * PAGE_SIZE); } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define __HAVE_ARCH_UPDATE_MMU_TLB #define update_mmu_tlb update_mmu_cache @@ -487,8 +491,7 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) void flush_icache_pte(pte_t pte); -static inline void __set_pte_at(struct mm_struct *mm, - unsigned long addr, pte_t *ptep, pte_t pteval) +static inline void __set_pte_at(pte_t *ptep, pte_t pteval) { if (pte_present(pteval) && pte_exec(pteval)) flush_icache_pte(pteval); @@ -496,17 +499,26 @@ static inline void __set_pte_at(struct mm_struct *mm, set_pte(ptep, pteval); } -static inline void set_pte_at(struct mm_struct *mm, - unsigned long addr, pte_t *ptep, pte_t pteval) +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pteval, unsigned int nr) { - page_table_check_ptes_set(mm, addr, ptep, pteval, 1); - __set_pte_at(mm, addr, ptep, pteval); + page_table_check_ptes_set(mm, addr, ptep, pteval, nr); + + for (;;) { + __set_pte_at(ptep, pteval); + if (--nr == 0) + break; + ptep++; + addr += PAGE_SIZE; + pte_val(pteval) += 1 << _PAGE_PFN_SHIFT; + } } +#define set_ptes set_ptes static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { - __set_pte_at(mm, addr, ptep, __pte(0)); + __set_pte_at(ptep, __pte(0)); } #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS @@ -515,7 +527,7 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma, pte_t entry, int dirty) { if (!pte_same(*ptep, entry)) - set_pte_at(vma->vm_mm, address, ptep, entry); + __set_pte_at(ptep, entry); /* * update_mmu_cache will unconditionally execute, handling both * the case that the PTE changed and the spurious fault case. @@ -688,14 +700,14 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd) { page_table_check_pmd_set(mm, addr, pmdp, pmd); - return __set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd)); + return __set_pte_at((pte_t *)pmdp, pmd_pte(pmd)); } static inline void set_pud_at(struct mm_struct *mm, unsigned long addr, pud_t *pudp, pud_t pud) { page_table_check_pud_set(mm, addr, pudp, pud); - return __set_pte_at(mm, addr, (pte_t *)pudp, pud_pte(pud)); + return __set_pte_at((pte_t *)pudp, pud_pte(pud)); } #ifdef CONFIG_PAGE_TABLE_CHECK diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index fbc59b3f69f2..f1387272a551 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -82,18 +82,11 @@ void flush_icache_mm(struct mm_struct *mm, bool local) #ifdef CONFIG_MMU void flush_icache_pte(pte_t pte) { - struct page *page = pte_page(pte); + struct folio *folio = page_folio(pte_page(pte)); - /* - * HugeTLB pages are always fully mapped, so only setting head page's - * PG_dcache_clean flag is enough. - */ - if (PageHuge(page)) - page = compound_head(page); - - if (!test_bit(PG_dcache_clean, &page->flags)) { + if (!test_bit(PG_dcache_clean, &folio->flags)) { flush_icache_all(); - set_bit(PG_dcache_clean, &page->flags); + set_bit(PG_dcache_clean, &folio->flags); } } #endif /* CONFIG_MMU */ From patchwork Mon Jul 10 20:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307610 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 E5078EB64D9 for ; Mon, 10 Jul 2023 20:44:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33F588E000C; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 033A88E0011; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BA848E000B; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2F1388E0001 for ; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0BDA6A028B for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) X-FDA: 80996878536.13.697DEF8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 5AD98140014 for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tiHU73Gt; dmarc=none; spf=none (imf23.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=1689021826; a=rsa-sha256; cv=none; b=NimU1+vgcxnHEhJE9pDqO5yxqZGmC0MNX/KjtswJbmyH6OG1uLUOyy8nbLV+1WY2/jG69S x9dIuQik2QNlwW2ym18MyxLPeEA6CVnAeAqKdAZJMrnY64oEE6ZnAixHnYccjlhMdyRqGt ZXKbnytL3Jg606PtS7bX/cTM/5mZ4Qg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tiHU73Gt; dmarc=none; spf=none (imf23.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=1689021826; 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=9mxVcCkW583JrlzbOMVQaZnB0bjf4NUO5YrFMq87KVA=; b=FKpyXssm7zJGkHaQxMqCPtX26JIAdkr53AUnW+0j/nY1PmijG69D1QxGXN0WSv/gKrxFlp 7AWvjV3f2UxDbHJldBj3ol9n2QXkvc4H8Av4prKF/iij/bLM5yvifoOa1cgDA6C4ymmHZ3 s+XUehJidfVbrHG9vwqqAWled2kd/GE= 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=9mxVcCkW583JrlzbOMVQaZnB0bjf4NUO5YrFMq87KVA=; b=tiHU73GtBk0CdV4R8NECb7nrWG rlw/hDC8XD9b2zjAZwna48outBRoVxu2IWG4ZicdNlUuRYBDKZRUemkoPgiXlrkf0kVB/sx3qjfs0 KkxCLgeBb0dGeLCejf0eJpZyZUb0QAlMhBZF+E3fcYghEbOccZYeYRtjGSz0QvTXnX52XdAJw1TXs dD9qFxvpT4uZslcdHGUINiZkGgdG7bUfWf+eV3k8ld7aPrcsNPTW5Ce0qlVAzV58FK0Y85gBRJU9t +h+io5vedYA2iPQhdC9XJcsDOkWmkXsYFq638vvxWop58dOIBFBXxPiLMZOQ82sbNU0OuAiljU1om x2DyixKQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00EuqC-Se; Mon, 10 Jul 2023 20:43:43 +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, Gerald Schaefer , Mike Rapoport , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org Subject: [PATCH v5 23/38] s390: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:24 +0100 Message-Id: <20230710204339.3554919-24-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5AD98140014 X-Stat-Signature: 7wni9c96qphpc65jwjmkgn17qsdzu8qk X-HE-Tag: 1689021826-30848 X-HE-Meta: U2FsdGVkX18lM+xzplgQmE0e0ugHKJ+DCvLBU9j2lwhRlis5jqgnRD717h+g0PVkPR8AjenEt7kBY4TflWdYJXVDRvjAcQMIBHZFgGBgbghcT27dXBUSZ2RD+NP5phwe5IBf7mIpDhLBHNeMAFeEXpVXhrdJo+0Dfxie41jcl0OLi9OYXq0WIf+qOWprScDmkz9QocYSujarrRyACVtuPSdv1Bjn6dRpGw0y0OygfBAbVt2/QLaZR0OfnVeNWzcJyekN1Ty4+VFN2gMFd+2viaLZo/je2TqC/aUVbgyKp/nOeftoF9ScBIh+uFvxNGzzKAhBsrcgeJIlVyTKjZz/Oz90MzwErOP2ai8PmZP5hgvNSXlA41D2E7Ewu7J52QyBpemRqJooweZc0VDz9BgWSnWgeoAhTXwu1FZLqm2tVX3/PwK6eKvLef9/2kQjuCfBOuVkGLlT2E2yd9wHDUgmQyn3oVg9oI2pTn1h3eV1kzDlfUVuW1diP4waxqybJBKMRsMh8PxGUNUF1lEUBm97xfhA/qhiCLkJCOHdKpk4nkuxY/bfqjIA5umo0resnxVtoXYGoNIz0AOXIUpwqW7m9PV6Ked5ypubBqkO3MBofhmRUstfXCXRKi0AfeifFkTPg4lpGYOsKnYANV9RYjSlE/vPqPdH+pN+m60lP7TPFGYVbK8Y7tJSoZUxsOqd+Ky7jBoAsf/91prGyJoYcClQmd797B7+i3VSEmDlRrMAPc410a8cIw6jdJVwmCMZnu+F0VeQdU7pWzeAjAqhoUjp6zg74t+qA0N0wkZLbnL4nHfOwsrdNj7cq/74566BGa5ajcMZjvhKobj/KwBUTkN3XImsJX+cdwqmO78QPAHl00oTmORObW4LouqxvEMXcqvyYfVqtbtfd+xERelu4sV4cWp9KdeMl/8DXQO7KJWUeniwXgl7uQfkZZljPAl9vU1WfXnkB+SAv6BzphrlLZX o1G9d/ug YZywUGSMYzLervA+DN7zccPzRy6hxQ4k/C0Ygyaz9ZvsR7CJK9NQxDQqz3WHQPoa+AkUuAr5GnQG4R+MT3qyk8f6ubpkypAM5DHF8UKpitTOQXO9rBWVeSFbxExgiv39n2Emo3HIs9CgyUks1ST0P4m7aueKajoI9jfCZFFyfwPwAncfCkxxDsMTDCX2aTDDGHnMN9uassaHsZt+hmcVBUt390Z58Rm/oFuEahrrNIm1aUK2fIqGK9B7auRzQ3CbpXUn5DOiMS8z/sAM= 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: Add set_ptes() and update_mmu_cache_range(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Gerald Schaefer Acked-by: Mike Rapoport (IBM) Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Christian Borntraeger Cc: Sven Schnelle Cc: linux-s390@vger.kernel.org --- arch/s390/include/asm/pgtable.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index c55f3c3365af..02973c740a5b 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -47,6 +47,7 @@ static inline void update_page_count(int level, long count) * tables contain all the necessary information. */ #define update_mmu_cache(vma, address, ptep) do { } while (0) +#define update_mmu_cache_range(vmf, vma, addr, ptep, nr) do { } while (0) #define update_mmu_cache_pmd(vma, address, ptep) do { } while (0) /* @@ -1316,20 +1317,34 @@ pgprot_t pgprot_writecombine(pgprot_t prot); pgprot_t pgprot_writethrough(pgprot_t prot); /* - * Certain architectures need to do special things when PTEs - * within a page table are directly modified. Thus, the following - * hook is made available. + * Set multiple PTEs to consecutive pages with a single call. All PTEs + * are within the same folio, PMD and VMA. */ -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t entry) +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t entry, unsigned int nr) { if (pte_present(entry)) entry = clear_pte_bit(entry, __pgprot(_PAGE_UNUSED)); - if (mm_has_pgste(mm)) - ptep_set_pte_at(mm, addr, ptep, entry); - else - set_pte(ptep, entry); + if (mm_has_pgste(mm)) { + for (;;) { + ptep_set_pte_at(mm, addr, ptep, entry); + if (--nr == 0) + break; + ptep++; + entry = __pte(pte_val(entry) + PAGE_SIZE); + addr += PAGE_SIZE; + } + } else { + for (;;) { + set_pte(ptep, entry); + if (--nr == 0) + break; + ptep++; + entry = __pte(pte_val(entry) + PAGE_SIZE); + } + } } +#define set_ptes set_ptes /* * Conversion functions: convert a page and protection to a page entry, From patchwork Mon Jul 10 20:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307620 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 B4392EB64D9 for ; Mon, 10 Jul 2023 20:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C64498E0016; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9CB18E0018; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 929468E0016; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 728288E0013 for ; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B5681A025E for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) X-FDA: 80996878662.25.CA8E302 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 60C364000E for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BiK3aJKU; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021828; a=rsa-sha256; cv=none; b=hoaLg8agttshXAWFg2GyYFZMx4OWYOk/iNE7CWPLxh2HCbz+d9+Z0CZSB0uF9mO7Ww8pd5 U80OkrByo462xswPBpYkRbe6ZYnsWERqPrg6E56cJFb76J7lBB1xG0c0V62dPIHYEmzB+7 ksHMthd6t+TPU7+1F6rvbKsvfB2zLa4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BiK3aJKU; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021828; 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=ueXixPUpzkyHVw6Q1Uf0w0UoKSG6KS3y+zNsVFthAW0=; b=pxqfZohPhIlRXZbNOSfpMu2+BXnlu9/z4lRr4O8GZzYAqFcOXWjqxibpnaZA22Gez1hgM1 yXWSf07etVMNFG6OvJE2F8gKvuZeIrCV/OwYUbkMMMAfZcyVIoRgOWb/BeXwqqvMCSsHY8 D8LDCCPX9xLPQ+ewhzJPRe3ykBMy8kY= 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=ueXixPUpzkyHVw6Q1Uf0w0UoKSG6KS3y+zNsVFthAW0=; b=BiK3aJKU41a3pJdC5u6MSc53uB aj3dlae196KGglZG8EqZfO3w2EpZve4xJsy+ucJ5OfnqzWtvDZc9WN6BR83c70twEA1pmqf2pFRos 8MRnZMHLflk64aWV4HslzXthJcye9M6V2Cm+kbfnO4gVbaJu3MudBP69smxKx6CSZlaYgHrlU4rKn PB/bMHvePTtR9VwZdLtIGApmGThS5c+FewWx4eCEoRKEKy0wLDGHKxvPCECgLbRRZDyS5IXUJucLc b3Yu3mqeDi38pXCKolC8cGhMAXx6zrwAjbk9DGdg4EGux5q3Ge56O8zhi9LwyRMEQe8h52l9H3sHH 2FPp4z7Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00EuqJ-0B; Mon, 10 Jul 2023 20:43:44 +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 , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , linux-sh@vger.kernel.org Subject: [PATCH v5 24/38] sh: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:25 +0100 Message-Id: <20230710204339.3554919-25-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-Server: rspam08 X-Rspamd-Queue-Id: 60C364000E X-Stat-Signature: e4b6z8wkrux14wtwdzah4nsf59s4w38h X-Rspam-User: X-HE-Tag: 1689021828-605607 X-HE-Meta: U2FsdGVkX18tQPRKxBdLrDNhuLNqXY6Vzruf8MRtazEZ2W/azDHV9Q9YgLNJMwOu8Uy/OhyIJlh7sfxmykYPfouj2GKoIWpacL5y2IN0VN1pcZqPsdAXhKjKxIXMJTrcIardYqhkhc069uSEgfOgQ7yhAMN6gp19FTNuN9ddSOzOExE6CcO3ZfcPjB7SWcGahYiBMZ4KWc6isD6i6HFjljMoLgLGPfqOLxQGXlAKf/Mf/iP7rCYJvi3Py/+eOvvMXNrkEKk5TcPwKKmsKrRo1oJwHZ/t2spQrRUE7JuChIl4Te7HgKsuSWPcN1Q/em2MpZWipeBIST66n9tJ1lHmE31p0Tl9M1g5rdFWTvjuZAJTpVll2pRZZLAbP0KpR1ISId3uvxOJViLHBMN29/BAg1vGlByd0amjfmzRhweio8I6Z+hFpyXK0mwu48nDoi9oDsZAhCVZ0G3UQup8LCC4FUWRzSUbBT/BGlzFzEoAELqI1T+kVZ7rhNQl8Rd8nFilJjPOLCuMCPyO/aWk5w2DPiu9mGFFjJZm3yyjHDeEsJZ3vWlJ+X4x4WWhRgrjl20XZIm8OZwbbFD0AS46vuJTVxuvnCGPf08BktjUmUb+HdEZ+72fmn0kkRY4OoRHLPCmkRk5m3s1jKtOqDMpjlzPvgGwP8YeXppt/7N2ohT2EzOxmD6COD58a/hl5zy3+HuT2/g6KG64zwTjNv5pFPXqtXTKEgpKqPAU1rwFrIfcZUsB3qs0XHZS6kn1Z8wOIjeDOnffRsKkMgiJzcUyykB1qsiT91+faGuKbAsYDSetsW96cNEfdfQf6qoUxP2eM1t3VAfzXmh9resLVTfq9liXAtt25We+08FOp+KzzUrvbX9QAPUNSnsXq2Jo5R9Al/ZywBdgbj1tPnie9CCk1dmdCCjX86s0u8IsdeOygvX44vnPuSgA7ID7EwsWUOiRKh1MEYozNrNJGFPmDBTlnLS WQoPBWWe lng9YorTslw1avtwOTEA8Qcb0NES4JM80R438kZiEDVl1H8wQET5gDuOVmzL6iEHmHNhdyzWKf0zM1HlJH443l1lpZ87zcPMt+ZlttdzMOwWQccYBk7+jdrWTEHmw+o/1BtUk+CQL8MvmYVOcae7sfuelq92XS/HMFZi41LK7hvgElb+vJS7TbQJqqM6ZhurLL0jocRxlh2x1/TFHU7DZpPhC+HxCQ91uGpHYP7bTa/K655LvT7WlbWYeoKY7RfjWZYVvPNh0eeaCB7/FCJVjJpnduqudFi3JJIVB6Fao6Mi3MoM= 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: Add PFN_PTE_SHIFT, update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_dcache_clean flag from being per-page to per-folio. Flush the entire folio containing the pages in flush_icache_pages() for ease of implementation. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Yoshinori Sato Cc: Rich Felker Cc: John Paul Adrian Glaubitz Cc: linux-sh@vger.kernel.org --- arch/sh/include/asm/cacheflush.h | 21 ++++++++----- arch/sh/include/asm/pgtable.h | 7 +++-- arch/sh/include/asm/pgtable_32.h | 5 ++- arch/sh/mm/cache-j2.c | 4 +-- arch/sh/mm/cache-sh4.c | 26 +++++++++++----- arch/sh/mm/cache-sh7705.c | 26 ++++++++++------ arch/sh/mm/cache.c | 52 ++++++++++++++++++-------------- arch/sh/mm/kmap.c | 3 +- 8 files changed, 89 insertions(+), 55 deletions(-) diff --git a/arch/sh/include/asm/cacheflush.h b/arch/sh/include/asm/cacheflush.h index 481a664287e2..9fceef6f3e00 100644 --- a/arch/sh/include/asm/cacheflush.h +++ b/arch/sh/include/asm/cacheflush.h @@ -13,9 +13,9 @@ * - flush_cache_page(mm, vmaddr, pfn) flushes a single page * - flush_cache_range(vma, start, end) flushes a range of pages * - * - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache + * - flush_dcache_folio(folio) flushes(wback&invalidates) a folio for dcache * - flush_icache_range(start, end) flushes(invalidates) a range for icache - * - flush_icache_page(vma, pg) flushes(invalidates) a page for icache + * - flush_icache_pages(vma, pg, nr) flushes(invalidates) pages for icache * - flush_cache_sigtramp(vaddr) flushes the signal trampoline */ extern void (*local_flush_cache_all)(void *args); @@ -23,9 +23,9 @@ extern void (*local_flush_cache_mm)(void *args); extern void (*local_flush_cache_dup_mm)(void *args); extern void (*local_flush_cache_page)(void *args); extern void (*local_flush_cache_range)(void *args); -extern void (*local_flush_dcache_page)(void *args); +extern void (*local_flush_dcache_folio)(void *args); extern void (*local_flush_icache_range)(void *args); -extern void (*local_flush_icache_page)(void *args); +extern void (*local_flush_icache_folio)(void *args); extern void (*local_flush_cache_sigtramp)(void *args); static inline void cache_noop(void *args) { } @@ -42,11 +42,18 @@ extern void flush_cache_page(struct vm_area_struct *vma, extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page(struct page *page); +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} + extern void flush_icache_range(unsigned long start, unsigned long end); #define flush_icache_user_range flush_icache_range -extern void flush_icache_page(struct vm_area_struct *vma, - struct page *page); +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr); +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) extern void flush_cache_sigtramp(unsigned long address); struct flusher_data { diff --git a/arch/sh/include/asm/pgtable.h b/arch/sh/include/asm/pgtable.h index 3ce30becf6df..729f5c6225fb 100644 --- a/arch/sh/include/asm/pgtable.h +++ b/arch/sh/include/asm/pgtable.h @@ -102,13 +102,16 @@ extern void __update_cache(struct vm_area_struct *vma, extern void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte); -static inline void -update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { pte_t pte = *ptep; __update_cache(vma, address, pte); __update_tlb(vma, address, pte); } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; extern void paging_init(void); diff --git a/arch/sh/include/asm/pgtable_32.h b/arch/sh/include/asm/pgtable_32.h index 21952b094650..676f3d4ef6ce 100644 --- a/arch/sh/include/asm/pgtable_32.h +++ b/arch/sh/include/asm/pgtable_32.h @@ -307,14 +307,13 @@ static inline void set_pte(pte_t *ptep, pte_t pte) #define set_pte(pteptr, pteval) (*(pteptr) = pteval) #endif -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) - /* * (pmds are folded into pgds so this doesn't get actually called, * but the define is needed for a generic inline function.) */ #define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pfn_pte(pfn, prot) \ __pte(((unsigned long long)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) #define pfn_pmd(pfn, prot) \ @@ -323,7 +322,7 @@ static inline void set_pte(pte_t *ptep, pte_t pte) #define pte_none(x) (!pte_val(x)) #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE)) -#define pte_clear(mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0) +#define pte_clear(mm, addr, ptep) set_pte(ptep, __pte(0)) #define pmd_none(x) (!pmd_val(x)) #define pmd_present(x) (pmd_val(x)) diff --git a/arch/sh/mm/cache-j2.c b/arch/sh/mm/cache-j2.c index f277862a11f5..9ac960214380 100644 --- a/arch/sh/mm/cache-j2.c +++ b/arch/sh/mm/cache-j2.c @@ -55,9 +55,9 @@ void __init j2_cache_init(void) local_flush_cache_dup_mm = j2_flush_both; local_flush_cache_page = j2_flush_both; local_flush_cache_range = j2_flush_both; - local_flush_dcache_page = j2_flush_dcache; + local_flush_dcache_folio = j2_flush_dcache; local_flush_icache_range = j2_flush_icache; - local_flush_icache_page = j2_flush_icache; + local_flush_icache_folio = j2_flush_icache; local_flush_cache_sigtramp = j2_flush_icache; pr_info("Initial J2 CCR is %.8x\n", __raw_readl(j2_ccr_base)); diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c index 72c2e1b46c08..862046f26981 100644 --- a/arch/sh/mm/cache-sh4.c +++ b/arch/sh/mm/cache-sh4.c @@ -107,19 +107,29 @@ static inline void flush_cache_one(unsigned long start, unsigned long phys) * Write back & invalidate the D-cache of the page. * (To avoid "alias" issues) */ -static void sh4_flush_dcache_page(void *arg) +static void sh4_flush_dcache_folio(void *arg) { - struct page *page = arg; - unsigned long addr = (unsigned long)page_address(page); + struct folio *folio = arg; #ifndef CONFIG_SMP - struct address_space *mapping = page_mapping_file(page); + struct address_space *mapping = folio_flush_mapping(folio); if (mapping && !mapping_mapped(mapping)) - clear_bit(PG_dcache_clean, &page->flags); + clear_bit(PG_dcache_clean, &folio->flags); else #endif - flush_cache_one(CACHE_OC_ADDRESS_ARRAY | - (addr & shm_align_mask), page_to_phys(page)); + { + unsigned long pfn = folio_pfn(folio); + unsigned long addr = (unsigned long)folio_address(folio); + unsigned int i, nr = folio_nr_pages(folio); + + for (i = 0; i < nr; i++) { + flush_cache_one(CACHE_OC_ADDRESS_ARRAY | + (addr & shm_align_mask), + pfn * PAGE_SIZE); + addr += PAGE_SIZE; + pfn++; + } + } wmb(); } @@ -379,7 +389,7 @@ void __init sh4_cache_init(void) __raw_readl(CCN_PRR)); local_flush_icache_range = sh4_flush_icache_range; - local_flush_dcache_page = sh4_flush_dcache_page; + local_flush_dcache_folio = sh4_flush_dcache_folio; local_flush_cache_all = sh4_flush_cache_all; local_flush_cache_mm = sh4_flush_cache_mm; local_flush_cache_dup_mm = sh4_flush_cache_mm; diff --git a/arch/sh/mm/cache-sh7705.c b/arch/sh/mm/cache-sh7705.c index 9b63a53a5e46..b509a407588f 100644 --- a/arch/sh/mm/cache-sh7705.c +++ b/arch/sh/mm/cache-sh7705.c @@ -132,15 +132,20 @@ static void __flush_dcache_page(unsigned long phys) * Write back & invalidate the D-cache of the page. * (To avoid "alias" issues) */ -static void sh7705_flush_dcache_page(void *arg) +static void sh7705_flush_dcache_folio(void *arg) { - struct page *page = arg; - struct address_space *mapping = page_mapping_file(page); + struct folio *folio = arg; + struct address_space *mapping = folio_flush_mapping(folio); if (mapping && !mapping_mapped(mapping)) - clear_bit(PG_dcache_clean, &page->flags); - else - __flush_dcache_page(__pa(page_address(page))); + clear_bit(PG_dcache_clean, &folio->flags); + else { + unsigned long pfn = folio_pfn(folio); + unsigned int i, nr = folio_nr_pages(folio); + + for (i = 0; i < nr; i++) + __flush_dcache_page((pfn + i) * PAGE_SIZE); + } } static void sh7705_flush_cache_all(void *args) @@ -176,19 +181,20 @@ static void sh7705_flush_cache_page(void *args) * Not entirely sure why this is necessary on SH3 with 32K cache but * without it we get occasional "Memory fault" when loading a program. */ -static void sh7705_flush_icache_page(void *page) +static void sh7705_flush_icache_folio(void *arg) { - __flush_purge_region(page_address(page), PAGE_SIZE); + struct folio *folio = arg; + __flush_purge_region(folio_address(folio), folio_size(folio)); } void __init sh7705_cache_init(void) { local_flush_icache_range = sh7705_flush_icache_range; - local_flush_dcache_page = sh7705_flush_dcache_page; + local_flush_dcache_folio = sh7705_flush_dcache_folio; local_flush_cache_all = sh7705_flush_cache_all; local_flush_cache_mm = sh7705_flush_cache_all; local_flush_cache_dup_mm = sh7705_flush_cache_all; local_flush_cache_range = sh7705_flush_cache_all; local_flush_cache_page = sh7705_flush_cache_page; - local_flush_icache_page = sh7705_flush_icache_page; + local_flush_icache_folio = sh7705_flush_icache_folio; } diff --git a/arch/sh/mm/cache.c b/arch/sh/mm/cache.c index 3aef78ceb820..9bcaa5619eab 100644 --- a/arch/sh/mm/cache.c +++ b/arch/sh/mm/cache.c @@ -20,9 +20,9 @@ void (*local_flush_cache_mm)(void *args) = cache_noop; void (*local_flush_cache_dup_mm)(void *args) = cache_noop; void (*local_flush_cache_page)(void *args) = cache_noop; void (*local_flush_cache_range)(void *args) = cache_noop; -void (*local_flush_dcache_page)(void *args) = cache_noop; +void (*local_flush_dcache_folio)(void *args) = cache_noop; void (*local_flush_icache_range)(void *args) = cache_noop; -void (*local_flush_icache_page)(void *args) = cache_noop; +void (*local_flush_icache_folio)(void *args) = cache_noop; void (*local_flush_cache_sigtramp)(void *args) = cache_noop; void (*__flush_wback_region)(void *start, int size); @@ -61,15 +61,17 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { - if (boot_cpu_data.dcache.n_aliases && page_mapcount(page) && - test_bit(PG_dcache_clean, &page->flags)) { + struct folio *folio = page_folio(page); + + if (boot_cpu_data.dcache.n_aliases && folio_mapped(folio) && + test_bit(PG_dcache_clean, &folio->flags)) { void *vto = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); memcpy(vto, src, len); kunmap_coherent(vto); } else { memcpy(dst, src, len); if (boot_cpu_data.dcache.n_aliases) - clear_bit(PG_dcache_clean, &page->flags); + clear_bit(PG_dcache_clean, &folio->flags); } if (vma->vm_flags & VM_EXEC) @@ -80,27 +82,30 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); + if (boot_cpu_data.dcache.n_aliases && page_mapcount(page) && - test_bit(PG_dcache_clean, &page->flags)) { + test_bit(PG_dcache_clean, &folio->flags)) { void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); memcpy(dst, vfrom, len); kunmap_coherent(vfrom); } else { memcpy(dst, src, len); if (boot_cpu_data.dcache.n_aliases) - clear_bit(PG_dcache_clean, &page->flags); + clear_bit(PG_dcache_clean, &folio->flags); } } void copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) { + struct folio *src = page_folio(from); void *vfrom, *vto; vto = kmap_atomic(to); - if (boot_cpu_data.dcache.n_aliases && page_mapcount(from) && - test_bit(PG_dcache_clean, &from->flags)) { + if (boot_cpu_data.dcache.n_aliases && folio_mapped(src) && + test_bit(PG_dcache_clean, &src->flags)) { vfrom = kmap_coherent(from, vaddr); copy_page(vto, vfrom); kunmap_coherent(vfrom); @@ -136,27 +141,28 @@ EXPORT_SYMBOL(clear_user_highpage); void __update_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte) { - struct page *page; unsigned long pfn = pte_pfn(pte); if (!boot_cpu_data.dcache.n_aliases) return; - page = pfn_to_page(pfn); if (pfn_valid(pfn)) { - int dirty = !test_and_set_bit(PG_dcache_clean, &page->flags); + struct folio *folio = page_folio(pfn_to_page(pfn)); + int dirty = !test_and_set_bit(PG_dcache_clean, &folio->flags); if (dirty) - __flush_purge_region(page_address(page), PAGE_SIZE); + __flush_purge_region(folio_address(folio), + folio_size(folio)); } } void __flush_anon_page(struct page *page, unsigned long vmaddr) { + struct folio *folio = page_folio(page); unsigned long addr = (unsigned long) page_address(page); if (pages_do_alias(addr, vmaddr)) { - if (boot_cpu_data.dcache.n_aliases && page_mapcount(page) && - test_bit(PG_dcache_clean, &page->flags)) { + if (boot_cpu_data.dcache.n_aliases && folio_mapped(folio) && + test_bit(PG_dcache_clean, &folio->flags)) { void *kaddr; kaddr = kmap_coherent(page, vmaddr); @@ -164,7 +170,8 @@ void __flush_anon_page(struct page *page, unsigned long vmaddr) /* __flush_purge_region((void *)kaddr, PAGE_SIZE); */ kunmap_coherent(kaddr); } else - __flush_purge_region((void *)addr, PAGE_SIZE); + __flush_purge_region(folio_address(folio), + folio_size(folio)); } } @@ -215,11 +222,11 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start, } EXPORT_SYMBOL(flush_cache_range); -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { - cacheop_on_each_cpu(local_flush_dcache_page, page, 1); + cacheop_on_each_cpu(local_flush_dcache_folio, folio, 1); } -EXPORT_SYMBOL(flush_dcache_page); +EXPORT_SYMBOL(flush_dcache_folio); void flush_icache_range(unsigned long start, unsigned long end) { @@ -233,10 +240,11 @@ void flush_icache_range(unsigned long start, unsigned long end) } EXPORT_SYMBOL(flush_icache_range); -void flush_icache_page(struct vm_area_struct *vma, struct page *page) +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr) { - /* Nothing uses the VMA, so just pass the struct page along */ - cacheop_on_each_cpu(local_flush_icache_page, page, 1); + /* Nothing uses the VMA, so just pass the folio along */ + cacheop_on_each_cpu(local_flush_icache_folio, page_folio(page), 1); } void flush_cache_sigtramp(unsigned long address) diff --git a/arch/sh/mm/kmap.c b/arch/sh/mm/kmap.c index 73fd7cc99430..fa50e8f6e7a9 100644 --- a/arch/sh/mm/kmap.c +++ b/arch/sh/mm/kmap.c @@ -27,10 +27,11 @@ void __init kmap_coherent_init(void) void *kmap_coherent(struct page *page, unsigned long addr) { + struct folio *folio = page_folio(page); enum fixed_addresses idx; unsigned long vaddr; - BUG_ON(!test_bit(PG_dcache_clean, &page->flags)); + BUG_ON(!test_bit(PG_dcache_clean, &folio->flags)); preempt_disable(); pagefault_disable(); From patchwork Mon Jul 10 20:43:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307622 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 75AC0EB64D9 for ; Mon, 10 Jul 2023 20:44:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 445878E0013; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ABEA8E001A; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13ADA8E0017; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A3B1F8E0013 for ; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F7608024A for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) X-FDA: 80996878662.17.52823FB Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id D362218001D for ; Mon, 10 Jul 2023 20:43:49 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KQOV3xnx; dmarc=none; spf=none (imf06.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=1689021829; 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=ACu0coWtToHgVmiLGofuGFdkSZdUJPASY/IVnZUUiqI=; b=YMzW77kOYzjaXuHzPix3qNQANQQ1dd1WNhkq2h1fg+ZB4OsT1VZZLv5jKGO8ZnuH06Fufl dam7OguC2pwp9uVT4nm0X6JJbXIjpqIMJ1bXWGzevyRRzA6cqofKfx6/aOF66D6IUlLbtI Jrg9OVUJ80Gtmv0ND0XD2ovqqZTlgbA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KQOV3xnx; dmarc=none; spf=none (imf06.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=1689021829; a=rsa-sha256; cv=none; b=3RTxLHFImsz6cijOVzUm73Tk9X34HaFnpmL0uk0JrQ4c3+zk6xh+CdLTtGseTxVytUo4Yf Cw4W2fCfLfrmVadSK2SMbiT4Z6RNhMHA2lWro0DfzM5peDGmKzvUokR3GVe8PRVInMcuGN 09lLSBFI+faR5LakYP3098TeHf7old8= 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=ACu0coWtToHgVmiLGofuGFdkSZdUJPASY/IVnZUUiqI=; b=KQOV3xnxHjVz1lKBWRN/GFYNE1 GTBdXlh6aD0aeos173WgoFubkYCHUodGZDmayFlE9FTXCLuhz5xIE+AadrazVBmXfKT39tbNfgOw2 K0iRfSZnxTkWs/5gE9dfpnjaeyyhaWQ54RdmXki7k6/fHGo7TvY2BI+m+rMPm9kpT6ET/U9ve5HvC kigmCWilg4GNeA6mHkAZu+vCFDNFdVxEPrfAjlY70cViC7O6jSSM5hCzEcYZMOvfO8aZ7LjRdXxo8 1+HNso/FGePI0Jwzvi2mfP0b60fd1N7ZvvDiphtMsH5/Byk3Ia3ED0/XU4GFchyjsgBz4v9l4J535 pnYQNKyw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00EuqN-3M; Mon, 10 Jul 2023 20:43:44 +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 , "David S. Miller" , sparclinux@vger.kernel.org Subject: [PATCH v5 25/38] sparc32: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:26 +0100 Message-Id: <20230710204339.3554919-26-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: D362218001D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ctbu4q6et6rwbhszxfg7r1gizphkpis8 X-HE-Tag: 1689021829-857966 X-HE-Meta: U2FsdGVkX19kCNGiwytbhYTO5OpqFISEDYV3Gx9KzIhfkjquhjcE7xkqqsx+DUHn4ZmBqSUsSYCpab6fQb7zt9/D+jnNRp5lXNZi2UpRQ1C1hhgBRR9ZZY2fAnrxY8eiOTgNleFnrzHhAhEwGwhCYB//HV7OXppsWm3O8gd+OjOCGJOpqW+0BhNryj8+oN0x6sobgUpLKTNtqT4PDKFBQ0udvMsncpMcpxasRggJXbKN4x5yTB/hrLz6feqiPMUS5ym8vZGiEXXUwKbUlgkWQa7GO+X+3n1wWdoF9oVI+jN0xtt34IOHq/kuNKcnR5N3Y5B093ysYmLGbNVOMvLxKLLRl8pyU4acmVqNlgBjA7UX35Oa9JhR5lxff2JlBGUKH8oIaVCMkJw6HGeT1PVM29XPS8r9oAew2813vNtQKVdSVFdkC26v0tSjtyMZUmNXNSkoRtuVqJaYjTwrtPkUg986nKJWfpolna7nHlRXfYQlNHsIkAeBEQU3tSsFUPt5/ZRhX39laK2Kc0oq1zIqpW7p2Tmr9e/M0R9ukvh1WX3WYK6pOzxhfxgHV2E5GFc48X9O+43xvUxJApmYIKz4BZnhrmZsrB0tX9IuQq6Ac5Q+cNwpeLahpmUGBkeUfy9mdtZMZgyImnFHv+EGlE/64yidUznqder3G6JCUsv/C08rQ/dTd0sk+2Ucem0oJsUUoCHSecnXaSRG9TvZ99c8xephC0c1ZgPgwkuPkLsx6HxNAgm0fNBlZu973ROhMjlCHOwQvfg43JlgLZKoBXlFhylpGiB0iPbGmQI/Q9W6rk4s1Ip8Ou0WF0a2IIzqe0WGiK8YEEhb12TSGbcZHRLwJYrw/j4dYwmNlY26VEat3HWvewhWCSrj9EyVKVhRpq2ZiHxyIwG2+VICLfCTUaofNm0KxxbV2Jl+OcM3ljmCZ/o8TRFRszOnruyJmT11tvIUDU3E7l102XokOUqRVVZ I1/ioF2Y ToqT0ZapJatN714E2qbxjTKG5OVt1rc/l04Itl5rGeP9hIzOB9CJKC0U6tP6kvu/l14IN4aXUkVolZ8Ix+LsThSTLWlRQP8bTqYmCtRj/D3+fm8+cYi7YUdWaofoVHmZXfE33TCvWyyIMksjyeqE/wt1T0c005QhH0Z6IC/CkRir7CPd3o7dQd17olZ4+HNvBQ+0cXqD05SkCfcAMy751o/ZNNwtUjphs/WNPZg534+Yqib8Ez+MVC4Sf5+NNwd/IqKXnBIp9cTc6CRMwafZSzl/Pssm5uZnOvlW8z91SA2TkAY8= 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: Add PFN_PTE_SHIFT, update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: "David S. Miller" Cc: sparclinux@vger.kernel.org --- arch/sparc/include/asm/cacheflush_32.h | 9 +++++++-- arch/sparc/include/asm/pgtable_32.h | 8 ++++---- arch/sparc/mm/init_32.c | 13 +++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/sparc/include/asm/cacheflush_32.h b/arch/sparc/include/asm/cacheflush_32.h index adb6991d0455..8dba35d63328 100644 --- a/arch/sparc/include/asm/cacheflush_32.h +++ b/arch/sparc/include/asm/cacheflush_32.h @@ -16,6 +16,7 @@ sparc32_cachetlb_ops->cache_page(vma, addr) #define flush_icache_range(start, end) do { } while (0) #define flush_icache_page(vma, pg) do { } while (0) +#define flush_icache_pages(vma, pg, nr) do { } while (0) #define copy_to_user_page(vma, page, vaddr, dst, src, len) \ do { \ @@ -35,11 +36,15 @@ #define flush_page_for_dma(addr) \ sparc32_cachetlb_ops->page_for_dma(addr) -struct page; void sparc_flush_page_to_ram(struct page *page); +void sparc_flush_folio_to_ram(struct folio *folio); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page(page) sparc_flush_page_to_ram(page) +#define flush_dcache_folio(folio) sparc_flush_folio_to_ram(folio) +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h index d4330e3c57a6..315d316614ca 100644 --- a/arch/sparc/include/asm/pgtable_32.h +++ b/arch/sparc/include/asm/pgtable_32.h @@ -101,8 +101,6 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) srmmu_swap((unsigned long *)ptep, pte_val(pteval)); } -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) - static inline int srmmu_device_memory(unsigned long x) { return ((x & 0xF0000000) != 0); @@ -256,6 +254,7 @@ static inline pte_t pte_mkyoung(pte_t pte) return __pte(pte_val(pte) | SRMMU_REF); } +#define PFN_PTE_SHIFT (PAGE_SHIFT - 4) #define pfn_pte(pfn, prot) mk_pte(pfn_to_page(pfn), prot) static inline unsigned long pte_pfn(pte_t pte) @@ -268,7 +267,7 @@ static inline unsigned long pte_pfn(pte_t pte) */ return ~0UL; } - return (pte_val(pte) & SRMMU_PTE_PMASK) >> (PAGE_SHIFT-4); + return (pte_val(pte) & SRMMU_PTE_PMASK) >> PFN_PTE_SHIFT; } #define pte_page(pte) pfn_to_page(pte_pfn(pte)) @@ -318,6 +317,7 @@ void mmu_info(struct seq_file *m); #define FAULT_CODE_USER 0x4 #define update_mmu_cache(vma, address, ptep) do { } while (0) +#define update_mmu_cache_range(vmf, vma, address, ptep, nr) do { } while (0) void srmmu_mapiorange(unsigned int bus, unsigned long xpa, unsigned long xva, unsigned int len); @@ -422,7 +422,7 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, ({ \ int __changed = !pte_same(*(__ptep), __entry); \ if (__changed) { \ - set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \ + set_pte(__ptep, __entry); \ flush_tlb_page(__vma, __address); \ } \ __changed; \ diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c index 9c0ea457bdf0..d96a14ffceeb 100644 --- a/arch/sparc/mm/init_32.c +++ b/arch/sparc/mm/init_32.c @@ -297,11 +297,20 @@ void sparc_flush_page_to_ram(struct page *page) { unsigned long vaddr = (unsigned long)page_address(page); - if (vaddr) - __flush_page_to_ram(vaddr); + __flush_page_to_ram(vaddr); } EXPORT_SYMBOL(sparc_flush_page_to_ram); +void sparc_flush_folio_to_ram(struct folio *folio) +{ + unsigned long vaddr = (unsigned long)folio_address(folio); + unsigned int i, nr = folio_nr_pages(folio); + + for (i = 0; i < nr; i++) + __flush_page_to_ram(vaddr + i * PAGE_SIZE); +} +EXPORT_SYMBOL(sparc_flush_folio_to_ram); + static const pgprot_t protection_map[16] = { [VM_NONE] = PAGE_NONE, [VM_READ] = PAGE_READONLY, From patchwork Mon Jul 10 20:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307627 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 89818C001DC for ; Mon, 10 Jul 2023 20:44:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 422768E001D; Mon, 10 Jul 2023 16:43:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35D028E001B; Mon, 10 Jul 2023 16:43:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 188D48E001D; Mon, 10 Jul 2023 16:43:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F0B228E001B for ; Mon, 10 Jul 2023 16:43:54 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C3F45120219 for ; Mon, 10 Jul 2023 20:43:54 +0000 (UTC) X-FDA: 80996878788.23.541A8E2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 74234100014 for ; Mon, 10 Jul 2023 20:43:52 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Hri9iFmt; dmarc=none; spf=none (imf14.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=1689021833; 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=YRhp3xK+lrYd9ylsYOmm8heTEVlrJyLMg7UrXZJoO+M=; b=eadiBmngpvERNYCxedZe2mf4buIhG+/3RK3iV9LxgLD42LTFjMQucn/cWnO5lO7qS6e9qL 1z/dw15pG/cgmPQyttIAwixzXsgJoc2XVHvCltU1wpv0UrSpVwb4JDTPIzqZPS0vDqmhMk C+LGBA7cEiu97KWSTYBYefMgfOz+G7I= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Hri9iFmt; dmarc=none; spf=none (imf14.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=1689021833; a=rsa-sha256; cv=none; b=z/XRZO6wbtK/9HfWnAME8LV87tEULp0uqV1RBTdhQygi7dv7V1c5NvC9Wcfc7ZBRm7cUnE +q1MezSNRL4vAlA7Tlc2o+OtN8ullexzftrRbFDFp1j9UHlKdpObOWRyffCjPV8hqYaEfn 0ysYLUTc3fRlZG4LAXjHVAoUNRQClVQ= 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=YRhp3xK+lrYd9ylsYOmm8heTEVlrJyLMg7UrXZJoO+M=; b=Hri9iFmtPT5TdLtCeKU7kF22ed 1ICiSTlAOc9KMB+MyOt53Nq+6h7zxcHzHDHZiwU1Y122DImxtWiYGBHPfWd8TJDjEkbBUCLAi2tbQ GA+zRDqyHHYGa3b+uZmKKB5DnV2NhHIQ383FVBPThCUfq0hWMB0af+MpFtxCntuI51HNVjZHpV2Cu LLr2KY32+CHuoFXwiihzr2TkZudHTOuBwRRXDmoFn2/tBUP9lBOhmVEgq1C1G2eD8I8ufMSm2zqZY OXzYkWcPfeYsdivPjfSDP3UxazeHC1jsIPCR7XE7ONN0EvQvug0S9qzpnnw8DdovZWPnsRAVFcCi4 hWrnU/ZA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00EuqU-88; Mon, 10 Jul 2023 20:43:44 +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 , "David S. Miller" , sparclinux@vger.kernel.org Subject: [PATCH v5 26/38] sparc64: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:27 +0100 Message-Id: <20230710204339.3554919-27-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-Server: rspam09 X-Rspamd-Queue-Id: 74234100014 X-Stat-Signature: ouknn754b6prmmoq3qp3qpk8mjmbxccp X-Rspam-User: X-HE-Tag: 1689021832-562991 X-HE-Meta: U2FsdGVkX19q3XVEgNefUnklcCinGiv6Sph1YLHg55/baJ/rZvf4oG3iRjJRmhNl66dGUc66DpHv5y1QaA/VXTv58JQSmsyi8e0o/Cmbf664kM5LroEWD4jzmztO2BBTCp78NszWoVdzVwDp34Z8JcBWmTo2zkDr8JmLgL8BOV/DGj1bLNmm4q5Z9haGb6BoyuWvo9arfEBpG+c9IgsAxqoUE76VWwS5W8QeGDc6Dvi5/LOMJVidyErdKCAs4DlebOxu+cvb+B+4u7j/fuzXO8E58/aPitQZgJ0OUq2IiS04ePdxs+UiR5FlzSiU14M+FUB+715taQwr/4XjUMt0+nWj7E2AFyztGqO+gAIVgEQd7gWjXo4qzesfs2rckd7/QhcfIlnsltvteKgdHDZlsaeWiNsWXxJ+2UHaP0M5a1pqEUtmR7+KJwFzc1mqf9hHowHEbJSeFG6L/6huS5vx7nw5yXyeEVqdFHNhw3xZlx6Jt+wWFs0zLHfQ87YzgGBRFHR5Rsseo1m+ebL1NLYTCCHrxnAdUPoMD23G0XMGE/LR9Ts/5OdHbXqwUgZa74MsqdX1Zmwh0UF4jjU/QDPItVzFDgx5KcFrZwHcBdab2QLI5SbIVF/8PCxseJ9dASWW0dZJHlsD7tSazaMY3bfzOywk0yu9ZKWRnGF5CwYgDK5NxYYqJMrJNzyaHqIhb8TjyXscKLIVMMkDMFmn7No+JdSzhAixbXDuW4/9//RMHS7JQp4czfytMcKuv3kU4yqUgQJsriWjACpX3zVvTe7OhMqToUM21lxm6olD6BEMqARjSGONQ7o24J6/AQwBahaA0MryVhvOeCyhBuGCCoAqDidC7wz8cwhG7u2HVJUiLJrgCjhNEJdz8SBULsSxMfqFs1TVGABVIJkEE5K1uSns3W8ti9yaEzssffMjpHUlTLh/qzKKRZHbMRLd4Blnv5Gt3Vw0q4BZxEA6DXdCTCs 7/S7So64 GI1M66JdrZ2dsDKOLSl5OCfEZsN/xpde+g6RNbySJwEeQRZ2Kf1KhaMWZrnnibp5pVE0NLmf4/CBqBvzQ2HZ62EnII7PE0b5c6M98FQZPNiuw3AFuPGc5XKoCCx7WUsLIuZUfvMDtw6FjBDqJ53Ng1ev0XBn8g1i1dRZo7MCTAHzSZEJ+aUQMgOfUaUY6gojHsV/MfYFY39m+szTsb+uJmbvowdK5vmTQlvwakKwoY8jkp4aUMzJ0OkmHV+dBlHmiEZ1m5i2rp2MB76Luv2aIKjS3mbzzNKN9i5XHhtMr1gsYFL4= 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: Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Convert the PG_dcache_dirty flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: "David S. Miller" Cc: sparclinux@vger.kernel.org --- arch/sparc/include/asm/cacheflush_64.h | 18 ++++-- arch/sparc/include/asm/pgtable_64.h | 24 ++++++-- arch/sparc/kernel/smp_64.c | 56 +++++++++++------- arch/sparc/mm/init_64.c | 78 +++++++++++++++----------- arch/sparc/mm/tlb.c | 5 +- 5 files changed, 116 insertions(+), 65 deletions(-) diff --git a/arch/sparc/include/asm/cacheflush_64.h b/arch/sparc/include/asm/cacheflush_64.h index b9341836597e..a9a719f04d06 100644 --- a/arch/sparc/include/asm/cacheflush_64.h +++ b/arch/sparc/include/asm/cacheflush_64.h @@ -35,20 +35,26 @@ void flush_icache_range(unsigned long start, unsigned long end); void __flush_icache_page(unsigned long); void __flush_dcache_page(void *addr, int flush_icache); -void flush_dcache_page_impl(struct page *page); +void flush_dcache_folio_impl(struct folio *folio); #ifdef CONFIG_SMP -void smp_flush_dcache_page_impl(struct page *page, int cpu); -void flush_dcache_page_all(struct mm_struct *mm, struct page *page); +void smp_flush_dcache_folio_impl(struct folio *folio, int cpu); +void flush_dcache_folio_all(struct mm_struct *mm, struct folio *folio); #else -#define smp_flush_dcache_page_impl(page,cpu) flush_dcache_page_impl(page) -#define flush_dcache_page_all(mm,page) flush_dcache_page_impl(page) +#define smp_flush_dcache_folio_impl(folio, cpu) flush_dcache_folio_impl(folio) +#define flush_dcache_folio_all(mm, folio) flush_dcache_folio_impl(folio) #endif void __flush_dcache_range(unsigned long start, unsigned long end); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page(struct page *page); +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} #define flush_icache_page(vma, pg) do { } while(0) +#define flush_icache_pages(vma, pg, nr) do { } while(0) void flush_ptrace_access(struct vm_area_struct *, struct page *, unsigned long uaddr, void *kaddr, diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h index 5563efa1a19f..c6c31631cdb0 100644 --- a/arch/sparc/include/asm/pgtable_64.h +++ b/arch/sparc/include/asm/pgtable_64.h @@ -927,8 +927,19 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, maybe_tlb_batch_add(mm, addr, ptep, orig, fullmm, PAGE_SHIFT); } -#define set_pte_at(mm,addr,ptep,pte) \ - __set_pte_at((mm), (addr), (ptep), (pte), 0) +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) +{ + for (;;) { + __set_pte_at(mm, addr, ptep, pte, 0); + if (--nr == 0) + break; + ptep++; + pte_val(pte) += PAGE_SIZE; + addr += PAGE_SIZE; + } +} +#define set_ptes set_ptes #define pte_clear(mm,addr,ptep) \ set_pte_at((mm), (addr), (ptep), __pte(0UL)) @@ -947,8 +958,8 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, \ if (pfn_valid(this_pfn) && \ (((old_addr) ^ (new_addr)) & (1 << 13))) \ - flush_dcache_page_all(current->mm, \ - pfn_to_page(this_pfn)); \ + flush_dcache_folio_all(current->mm, \ + page_folio(pfn_to_page(this_pfn))); \ } \ newpte; \ }) @@ -963,7 +974,10 @@ struct seq_file; void mmu_info(struct seq_file *); struct vm_area_struct; -void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *); +void update_mmu_cache_range(struct vm_fault *, struct vm_area_struct *, + unsigned long addr, pte_t *ptep, unsigned int nr); +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #ifdef CONFIG_TRANSPARENT_HUGEPAGE void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd); diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c index e5964d1d8b37..f3969a3600db 100644 --- a/arch/sparc/kernel/smp_64.c +++ b/arch/sparc/kernel/smp_64.c @@ -921,20 +921,26 @@ extern unsigned long xcall_flush_dcache_page_cheetah; #endif extern unsigned long xcall_flush_dcache_page_spitfire; -static inline void __local_flush_dcache_page(struct page *page) +static inline void __local_flush_dcache_folio(struct folio *folio) { + unsigned int i, nr = folio_nr_pages(folio); + #ifdef DCACHE_ALIASING_POSSIBLE - __flush_dcache_page(page_address(page), + for (i = 0; i < nr; i++) + __flush_dcache_page(folio_address(folio) + i * PAGE_SIZE, ((tlb_type == spitfire) && - page_mapping_file(page) != NULL)); + folio_flush_mapping(folio) != NULL)); #else - if (page_mapping_file(page) != NULL && - tlb_type == spitfire) - __flush_icache_page(__pa(page_address(page))); + if (folio_flush_mapping(folio) != NULL && + tlb_type == spitfire) { + unsigned long pfn = folio_pfn(folio) + for (i = 0; i < nr; i++) + __flush_icache_page((pfn + i) * PAGE_SIZE); + } #endif } -void smp_flush_dcache_page_impl(struct page *page, int cpu) +void smp_flush_dcache_folio_impl(struct folio *folio, int cpu) { int this_cpu; @@ -948,14 +954,14 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu) this_cpu = get_cpu(); if (cpu == this_cpu) { - __local_flush_dcache_page(page); + __local_flush_dcache_folio(folio); } else if (cpu_online(cpu)) { - void *pg_addr = page_address(page); + void *pg_addr = folio_address(folio); u64 data0 = 0; if (tlb_type == spitfire) { data0 = ((u64)&xcall_flush_dcache_page_spitfire); - if (page_mapping_file(page) != NULL) + if (folio_flush_mapping(folio) != NULL) data0 |= ((u64)1 << 32); } else if (tlb_type == cheetah || tlb_type == cheetah_plus) { #ifdef DCACHE_ALIASING_POSSIBLE @@ -963,18 +969,23 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu) #endif } if (data0) { - xcall_deliver(data0, __pa(pg_addr), - (u64) pg_addr, cpumask_of(cpu)); + unsigned int i, nr = folio_nr_pages(folio); + + for (i = 0; i < nr; i++) { + xcall_deliver(data0, __pa(pg_addr), + (u64) pg_addr, cpumask_of(cpu)); #ifdef CONFIG_DEBUG_DCFLUSH - atomic_inc(&dcpage_flushes_xcall); + atomic_inc(&dcpage_flushes_xcall); #endif + pg_addr += PAGE_SIZE; + } } } put_cpu(); } -void flush_dcache_page_all(struct mm_struct *mm, struct page *page) +void flush_dcache_folio_all(struct mm_struct *mm, struct folio *folio) { void *pg_addr; u64 data0; @@ -988,10 +999,10 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page) atomic_inc(&dcpage_flushes); #endif data0 = 0; - pg_addr = page_address(page); + pg_addr = folio_address(folio); if (tlb_type == spitfire) { data0 = ((u64)&xcall_flush_dcache_page_spitfire); - if (page_mapping_file(page) != NULL) + if (folio_flush_mapping(folio) != NULL) data0 |= ((u64)1 << 32); } else if (tlb_type == cheetah || tlb_type == cheetah_plus) { #ifdef DCACHE_ALIASING_POSSIBLE @@ -999,13 +1010,18 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page) #endif } if (data0) { - xcall_deliver(data0, __pa(pg_addr), - (u64) pg_addr, cpu_online_mask); + unsigned int i, nr = folio_nr_pages(folio); + + for (i = 0; i < nr; i++) { + xcall_deliver(data0, __pa(pg_addr), + (u64) pg_addr, cpu_online_mask); #ifdef CONFIG_DEBUG_DCFLUSH - atomic_inc(&dcpage_flushes_xcall); + atomic_inc(&dcpage_flushes_xcall); #endif + pg_addr += PAGE_SIZE; + } } - __local_flush_dcache_page(page); + __local_flush_dcache_folio(folio); preempt_enable(); } diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c index 04f9db0c3111..c48d189aaffd 100644 --- a/arch/sparc/mm/init_64.c +++ b/arch/sparc/mm/init_64.c @@ -195,21 +195,26 @@ atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0); #endif #endif -inline void flush_dcache_page_impl(struct page *page) +inline void flush_dcache_folio_impl(struct folio *folio) { + unsigned int i, nr = folio_nr_pages(folio); + BUG_ON(tlb_type == hypervisor); #ifdef CONFIG_DEBUG_DCFLUSH atomic_inc(&dcpage_flushes); #endif #ifdef DCACHE_ALIASING_POSSIBLE - __flush_dcache_page(page_address(page), - ((tlb_type == spitfire) && - page_mapping_file(page) != NULL)); + for (i = 0; i < nr; i++) + __flush_dcache_page(folio_address(folio) + i * PAGE_SIZE, + ((tlb_type == spitfire) && + folio_flush_mapping(folio) != NULL)); #else - if (page_mapping_file(page) != NULL && - tlb_type == spitfire) - __flush_icache_page(__pa(page_address(page))); + if (folio_flush_mapping(folio) != NULL && + tlb_type == spitfire) { + for (i = 0; i < nr; i++) + __flush_icache_page((pfn + i) * PAGE_SIZE); + } #endif } @@ -218,10 +223,10 @@ inline void flush_dcache_page_impl(struct page *page) #define PG_dcache_cpu_mask \ ((1UL<flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask) +#define dcache_dirty_cpu(folio) \ + (((folio)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask) -static inline void set_dcache_dirty(struct page *page, int this_cpu) +static inline void set_dcache_dirty(struct folio *folio, int this_cpu) { unsigned long mask = this_cpu; unsigned long non_cpu_bits; @@ -238,11 +243,11 @@ static inline void set_dcache_dirty(struct page *page, int this_cpu) "bne,pn %%xcc, 1b\n\t" " nop" : /* no outputs */ - : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags) + : "r" (mask), "r" (non_cpu_bits), "r" (&folio->flags) : "g1", "g7"); } -static inline void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu) +static inline void clear_dcache_dirty_cpu(struct folio *folio, unsigned long cpu) { unsigned long mask = (1UL << PG_dcache_dirty); @@ -260,7 +265,7 @@ static inline void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu) " nop\n" "2:" : /* no outputs */ - : "r" (cpu), "r" (mask), "r" (&page->flags), + : "r" (cpu), "r" (mask), "r" (&folio->flags), "i" (PG_dcache_cpu_mask), "i" (PG_dcache_cpu_shift) : "g1", "g7"); @@ -284,9 +289,10 @@ static void flush_dcache(unsigned long pfn) page = pfn_to_page(pfn); if (page) { + struct folio *folio = page_folio(page); unsigned long pg_flags; - pg_flags = page->flags; + pg_flags = folio->flags; if (pg_flags & (1UL << PG_dcache_dirty)) { int cpu = ((pg_flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask); @@ -296,11 +302,11 @@ static void flush_dcache(unsigned long pfn) * in the SMP case. */ if (cpu == this_cpu) - flush_dcache_page_impl(page); + flush_dcache_folio_impl(folio); else - smp_flush_dcache_page_impl(page, cpu); + smp_flush_dcache_folio_impl(folio, cpu); - clear_dcache_dirty_cpu(page, cpu); + clear_dcache_dirty_cpu(folio, cpu); put_cpu(); } @@ -388,12 +394,14 @@ bool __init arch_hugetlb_valid_size(unsigned long size) } #endif /* CONFIG_HUGETLB_PAGE */ -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr) { struct mm_struct *mm; unsigned long flags; bool is_huge_tsb; pte_t pte = *ptep; + unsigned int i; if (tlb_type != hypervisor) { unsigned long pfn = pte_pfn(pte); @@ -440,15 +448,21 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t * } } #endif - if (!is_huge_tsb) - __update_mmu_tsb_insert(mm, MM_TSB_BASE, PAGE_SHIFT, - address, pte_val(pte)); + if (!is_huge_tsb) { + for (i = 0; i < nr; i++) { + __update_mmu_tsb_insert(mm, MM_TSB_BASE, PAGE_SHIFT, + address, pte_val(pte)); + address += PAGE_SIZE; + pte_val(pte) += PAGE_SIZE; + } + } spin_unlock_irqrestore(&mm->context.lock, flags); } -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { + unsigned long pfn = folio_pfn(folio); struct address_space *mapping; int this_cpu; @@ -459,35 +473,35 @@ void flush_dcache_page(struct page *page) * is merely the zero page. The 'bigcore' testcase in GDB * causes this case to run millions of times. */ - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(pfn)) return; this_cpu = get_cpu(); - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); if (mapping && !mapping_mapped(mapping)) { - int dirty = test_bit(PG_dcache_dirty, &page->flags); + bool dirty = test_bit(PG_dcache_dirty, &folio->flags); if (dirty) { - int dirty_cpu = dcache_dirty_cpu(page); + int dirty_cpu = dcache_dirty_cpu(folio); if (dirty_cpu == this_cpu) goto out; - smp_flush_dcache_page_impl(page, dirty_cpu); + smp_flush_dcache_folio_impl(folio, dirty_cpu); } - set_dcache_dirty(page, this_cpu); + set_dcache_dirty(folio, this_cpu); } else { /* We could delay the flush for the !page_mapping * case too. But that case is for exec env/arg * pages and those are %99 certainly going to get * faulted into the tlb (and thus flushed) anyways. */ - flush_dcache_page_impl(page); + flush_dcache_folio_impl(folio); } out: put_cpu(); } -EXPORT_SYMBOL(flush_dcache_page); +EXPORT_SYMBOL(flush_dcache_folio); void __kprobes flush_icache_range(unsigned long start, unsigned long end) { @@ -2280,10 +2294,10 @@ void __init paging_init(void) setup_page_offset(); /* These build time checkes make sure that the dcache_dirty_cpu() - * page->flags usage will work. + * folio->flags usage will work. * * When a page gets marked as dcache-dirty, we store the - * cpu number starting at bit 32 in the page->flags. Also, + * cpu number starting at bit 32 in the folio->flags. Also, * functions like clear_dcache_dirty_cpu use the cpu mask * in 13-bit signed-immediate instruction fields. */ diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c index 7ecf8556947a..0d41c94ec3ac 100644 --- a/arch/sparc/mm/tlb.c +++ b/arch/sparc/mm/tlb.c @@ -118,6 +118,7 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, unsigned long paddr, pfn = pte_pfn(orig); struct address_space *mapping; struct page *page; + struct folio *folio; if (!pfn_valid(pfn)) goto no_cache_flush; @@ -127,13 +128,13 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, goto no_cache_flush; /* A real file page? */ - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); if (!mapping) goto no_cache_flush; paddr = (unsigned long) page_address(page); if ((paddr ^ vaddr) & (1 << 13)) - flush_dcache_page_all(mm, page); + flush_dcache_folio_all(mm, folio); } no_cache_flush: From patchwork Mon Jul 10 20:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307617 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 7F429EB64DA for ; Mon, 10 Jul 2023 20:44:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F4C58E0014; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77F4A8E0013; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C89B8E0013; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A2B7A8E0013 for ; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 74D91AFD1D for ; Mon, 10 Jul 2023 20:43:49 +0000 (UTC) X-FDA: 80996878578.04.2C5BEDF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id C4895C001D for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=N43G73nI; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021827; 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=Syy9e2c8ZW8YV+TAzwjXxuMyXTj35iZpxEM63ZAjrDs=; b=0CRI9/wytCoUyD6oZkpBHMspgGFX61O8d4kWBgmRAYl99PcnJzA9haz73k7pQyEkAoAx+7 oQHe72bFpqq5/5m1g8bWQGeSJ18WnmMgURXS+QhEHkI/jIutJoBdsR9Xdb+lCqqjxTtqS9 n+EQTd5+NJiyr2I5ZDx67QR0fReQLec= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021827; a=rsa-sha256; cv=none; b=Z2qLNKTdbHnP5r3aiWu6ASDEyG2zwGQIW0ibv2RHzCtlGit4GhjAcqd7BT9nW8h3ivjVk2 z4YQm8rI709euAkmrZ6N8SeBzm/LzCtZOl4yD2BZ7eQiyExjNoZjQRZAmg7GA0CpszU9zU aKHueXJ2O9RYOs8jObP51uiemnwEZM8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=N43G73nI; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=Syy9e2c8ZW8YV+TAzwjXxuMyXTj35iZpxEM63ZAjrDs=; b=N43G73nIZ0b/OqOtMEkUld9RHI F4Mgrg1TmEBFXnr4M6ztPSKvHtYp5heEnvbw/0hdHJHAAUm4WwDFWqMOlv8p6EKECfnJjrdxEvb9v WVjvfctXnRh9p5Fv/zakRG1KBwzkzEk5iNhl7/qEbHgEzKNMZV+aq8+HdlTJYZ6g/rUY7s6ZU28ti wZWGNUgAEO29XNQYuRytMNAPJ3L3OYnn72bzL+kT640TxmZXe9sVZw57VvJDm+ufECLq1c7hlFBdx w4UqBYuwIpNPdbRwfUbzHZLDARxk4Jfk5F7VFE5ZqvgBTJ4sK9dUmqf2XUc+UnFJq0w5HLdb+eFQi Deu2w/Mw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Euqb-Aj; Mon, 10 Jul 2023 20:43:44 +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 , Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org Subject: [PATCH v5 27/38] um: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:28 +0100 Message-Id: <20230710204339.3554919-28-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-Stat-Signature: tsh8gutn14urcrbyg16i8ngbhissdaoc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C4895C001D X-Rspam-User: X-HE-Tag: 1689021827-890222 X-HE-Meta: U2FsdGVkX19r7QlhfdgMdFf3ygzaEuwEkp3O0YzfSnwattYWS4Xe6uxYN3cFGhLALODvL+LRO7A+iHlh/9ICDiTu7QDWnnZMk3MKLY9RpqDeUg3YWbeRP4LwDhdF3sKNMDQVuBHZPayjJnMHTd1r/1gdYaLobtrdrsOdgefny6gThqu+ZgBxeetQ/l8Nc+QrN9mhwWlAhxCHQeZt44AaRIZ8qNL0U41lyAsfroeVy6kwnpPP8icvW0BAWZE/5w5P7G5lCfuqUqKSI5FhL86xVwT30H1FwJ38/w1o5qljodAuvuF+kviumxd7yRz5r/1E13V+wg0wuh/izvmyW41QZrh13jX3qLDsJpGtOkBGSJVyFJpbgS3Bbfk36qBVzMCY72YscS20296AmFAB8VKO0c7KsqRAV/j36i7B99tTynOapaly5+fuXjzHA48M5RFvLJ+N0yEuJ7uSH12PRUEUsIR7Y2tJBq/inonusNFlAIUu0r5nXKdPDUlQGrPQy9a6M3zuxtiV0U1lAAKOcmgXv+RjJpxpyXjLSa4sYEKmbiLBGsbaxt5oytzyexJ+PdFiYpb7NrUNGKVGCuFZTS+bWiDa2iYTuEjy2GxR0c05rTRbapz05ZVjz14s3El56i8vw2wzKrwy2U9/NPdvLs0MZP/vVtg4oAXM6LYjzNMlQ+puMO0Kr0Mn9Jnke/Y88EerMAdICBqZQLqJyDUvb+6LGN3NsOz1NNDDQTqWMgebpASDaxWfwmEQpuNmR4Dm5Nn9PiorupeXwRaucxFGzSUVTNXcJNefWn1K9dBhCfsatZbjgFF0PeeHXYKCaesIRJeHcCPUA2KswqBVOkq6ufIsMcsd9buE4VsgeKXyhCRXS3IdEH8X2bIPblE6YsIoaH/O9ZdBKyL7XZQ6tMnzqLcBhKKMDkDfyFe2bFQvpmSWbx9d57T4lciRKtMhzX7sOm+IYgKaLhRUPy9RYlFHrDd wZwbOTkr UrZuiUBH4XYF3Qor8d6PIMU25zhh9ZxPFOUBqovTBMuropWnCE72ZsTSdISN86K7sefxS/drnCaDYcgK43Bou9JL6nxWKOE95cZA5wD+yJzcnVZ4/JrMFu3iWRaURdS+VO/0h5vbf7lhu6CFM1WBiGfoDpGEwy7gJqiy0mg/LUeE5HUrfAZ09ZuDMw70RzJGG8GKYd0/VXVr0XZbleSsmUhOyjRLiOD3NG4CFqW0swcn5SRZCwvStTyZqikMucBrlCk4Gl2g7S80kJTB9TsY5YoUtUy2ahEjMwgWCX2uAA0KuFOdUH+Jin9G7Th/5QEh/GRd4hMPZdmwyIh3qyo7ZZq2zbqm8qhcwey/Ti1/TLWwytiQ= 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: Add PFN_PTE_SHIFT and update_mmu_cache_range(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Richard Weinberger Cc: Anton Ivanov Cc: Johannes Berg Cc: linux-um@lists.infradead.org --- arch/um/include/asm/pgtable.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/um/include/asm/pgtable.h b/arch/um/include/asm/pgtable.h index a70d1618eb35..44f6c76167d9 100644 --- a/arch/um/include/asm/pgtable.h +++ b/arch/um/include/asm/pgtable.h @@ -242,11 +242,7 @@ static inline void set_pte(pte_t *pteptr, pte_t pteval) if(pte_present(*pteptr)) *pteptr = pte_mknewprot(*pteptr); } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *pteptr, pte_t pteval) -{ - set_pte(pteptr, pteval); -} +#define PFN_PTE_SHIFT PAGE_SHIFT #define __HAVE_ARCH_PTE_SAME static inline int pte_same(pte_t pte_a, pte_t pte_b) @@ -290,6 +286,7 @@ struct mm_struct; extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr); #define update_mmu_cache(vma,address,ptep) do {} while (0) +#define update_mmu_cache_range(vmf, vma, address, ptep, nr) do {} while (0) /* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that From patchwork Mon Jul 10 20:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307635 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 6D6CFEB64DA for ; Mon, 10 Jul 2023 20:44:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1E578E0025; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA86F8E001B; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF94C8E0025; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C16388E001B for ; Mon, 10 Jul 2023 16:44:09 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 969471C7F9C for ; Mon, 10 Jul 2023 20:44:09 +0000 (UTC) X-FDA: 80996879418.16.217628C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id D31B314000F for ; Mon, 10 Jul 2023 20:44:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=n3OahCLr; 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=1689021848; 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=sMQRt4vH1ObkP1bKXMUZ8zoM72SIlxiZjD55fkj3j0k=; b=4sOU71EPcPzp7k5/cAifpU55h6moVk+f0les5UqB5tNcDZ8S9g23QS67gYE60+8qCWKXpf gcThutLsPls7Y0ncJFD8Nh+SIA1Pox6zlDLaJYKKwM45ySpeE9uQ1eIt79HtNyyjANxwIK tvlgFWdqKCReaaO+McpuLDAbnnqgSIE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=n3OahCLr; 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=1689021848; a=rsa-sha256; cv=none; b=CcEoPtvro2cwcgMHgfOX+6yssOvkecNhPRcVlJSLguoHqkHTc4cx3f0gvFrfz2w8+2Efch gGyP457mUPaMvqlmK//3BapfEP0CyitHrbLIwQFclEPAekb/gqqNdDHUhkB0+js62ke+2b Lg+wkYwcJCSdYkjVwcZ6i5XplEnWh68= 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=sMQRt4vH1ObkP1bKXMUZ8zoM72SIlxiZjD55fkj3j0k=; b=n3OahCLrH5ynSGq4TtitzKFZCm tCz7WUYXNr5RD1i/rXpMMwliW4bONdC7+C/iFgM/tLwwAtd+drGtecPi8nyKP+4KpGdkBguM8BzBL qm4OC/hSWVz0SYJS3P3id1s7KFaaC/BcXTAHQVR6MJP3POJnWrGtle2JD+xi7BusE+ns41ORyEKVr F1fyClyXhHiAK6uepDxgQX68J0kwUgdcAvl4PT8gRA/6kG2RUQrpaj+XO96r5BPI3XrTI9t9sTWWz Z3wad0zjHfsvX1okoo2p+8FuF/jgzM9RVpF49eI4rQ7zbzJbLiurc6Sr6UEju5X1kggGqjnRewSWo 7Hw+7bSg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Euqd-Cy; Mon, 10 Jul 2023 20:43:44 +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 , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v5 28/38] x86: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:29 +0100 Message-Id: <20230710204339.3554919-29-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: D31B314000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fk5s74o59rf86cg538auy64gfkyzw6ip X-HE-Tag: 1689021847-249906 X-HE-Meta: U2FsdGVkX1+B0ROE1gBC+HkPHpJJXwFQspcwhwQI7VpguDjifQfkzkCU56YTz2alFk3vUAQM02/cM5j8GjJMeByH6DDJFhgcKUN1gUWhfQRGSIQ3P9Ry3b8fqqj59Jvz1OcwNpE0qzNpTgplHcLm2v6QJGG3eHQrc2LnEzTJ6Yl606BDYhNEWUEQrLLNJAZ5ku8KvkM035VdaMgJYfw99zAa98Wd45SazAcobLWEZgnNQyuJ8MSJAZEw68mwWWlHqXCCa2VOltwU15AErR3X/aynu7bEX8jXgTtrpQ+MGzoQ6dTGNErM7JqmHYJJxo/q2mjV7XY778UnVaLbOGHOuM0Ue898D4OPPIL/JwmWFXFn6v0ourO77oVvXs7Vek1IwG6M39lSDuRtYKqrWNom59b28S4dOU5JjK6jWBfURQGjmxyhTP8nnOrET84GYfWIY8cRT6IQa1dvfcE6KvOuKnC51M07nHvIjp7aVzhiTQocl7i5Cse+xsbLjYIC6ECj7KmHFwzwB4lRUOynnQnH0jqmbWDyQR6jb1UINepViZIMiSBBr9cmDFyzRJDt8WtYtF+43pKb4yqlihc3EDly1KaVUf+PsTRIwtIx5cgscGZ6W0KlWiY/ZeBNn5L6T844Mr1RGhyKCPgK5WaVEsXNYKPpsYWJBRBqJEMBMaII809cwubsola7Tv37I/4iualLa+2qUi+IgvYWxhBIi6msa2tLowRIl4+7enR6dn9tLntwYS9QDooGrb2vyGgQ5IpF0Nix/2vMDZ1TY3erdSkm7Vhf2Rh2sxxs7cgXaoSouXnjPdjJPvVdM14TCkUhvMD2bVJQLUiBdK10VtK+GsA65vRyFU5GK8CDICUXmclpiQbj44bfFEub6L1YiNtir+bQmYwqcTjP3WNr0WTkZ+3TaCuxQFSrmhl6zH2FdMPE3vs4Slei+JguvY2SnUfDNIjUyAUp1keDV+mpFVeKuoH RNfjf0N5 6sutZ+DkQqeJ1z6IrEf/f0YrpWkKLShewClS+zK2fb5KZy8guSOA8UgNZ3m1KvTf/nlL69I6DuyIBBjN5q0Y0qmO8a5hWsuuW/mN/xU1q5/y4XtcRBZ8p1l7Gr8UmqXhZyZE/FxV04VZgQ887mDbcMu+tMtvEpb0HdfeA+HycbZknHdmv5jctlDvNZZDKMTTZS8sZs+dqaN459H82RDtI363gKIw0GBNRbS12qfrOzLknFNTKhVYrQgfag/SrDo81ZQ/QTlWC3pWnzqlYRAqMaKS3XwzKe49NGBZQ+4YDQuLVdwR8qmX+xSp1yaAkl5P5yhM2V6xExhWza1N4AmHkrMeuqqZ1+eMqXviv 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: Add PFN_PTE_SHIFT and a noop update_mmu_cache_range(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" --- arch/x86/include/asm/pgtable.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index c6242bc58a71..9818f13bfa09 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -185,6 +185,8 @@ static inline int pte_special(pte_t pte) static inline u64 protnone_mask(u64 val); +#define PFN_PTE_SHIFT PAGE_SHIFT + static inline unsigned long pte_pfn(pte_t pte) { phys_addr_t pfn = pte_val(pte); @@ -1020,13 +1022,6 @@ static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp) return res; } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) -{ - page_table_check_ptes_set(mm, addr, ptep, pte, 1); - set_pte(ptep, pte); -} - static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd) { @@ -1292,6 +1287,11 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { } +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, unsigned int nr) +{ +} static inline void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd) { From patchwork Mon Jul 10 20:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307623 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 16753EB64DC for ; Mon, 10 Jul 2023 20:44:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EF618E0018; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61E9A8E0017; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24B108E0018; Mon, 10 Jul 2023 16:43:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D470D8E0019 for ; Mon, 10 Jul 2023 16:43:51 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9D3C4120247 for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) X-FDA: 80996878662.13.671074D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id CFE5D14000F for ; Mon, 10 Jul 2023 20:43:49 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=C9TSROXS; dmarc=none; spf=none (imf23.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=1689021830; 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=cPCd6cun2Qq+jg4xfMvT7i67deMTX4AKGcyftDmfVKA=; b=dgyxU54JetXzqk0ElIm3Myyh23QAgSMuDdvmEqjGEOnEmqiuuRSM/tzqP8AkdbOJo73mjG zrkExY5vr6VF409IvaUstaVSSQ0RN06WPL8MK44EH3cHdKf0esfct14AtZeiB08P5WlNww 6gIN86Snn9amLWF6OQ8GzdKV71xqjTU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=C9TSROXS; dmarc=none; spf=none (imf23.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=1689021830; a=rsa-sha256; cv=none; b=ys/C00EMVu/vgopAtFB+UEFmsGkhVmaoQgUPAkyE6vmZx/WHqEpmvCV/Un2dPE93yuKRc0 L+8ZLzCI9ChVs5L1QSQZA3iAazqikkznRtGDwZ9JpCJqUy47KTtLSSajDee6MMAlNrlJdb 7TzzEAmTQid/Tw3nNS1ApXHV21Q0aNM= 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=cPCd6cun2Qq+jg4xfMvT7i67deMTX4AKGcyftDmfVKA=; b=C9TSROXSunzG3cB3FVg0vhwjCE YgmwcMCux99SPh+GxYxHk3AlIpRjvDf35Dzcd+hFlpbMupPuhvzorw+hrAixznhcikQzs7/63ir80 wJeXXRvpz11TsZkzFWAwHpmRMOboz1asiiDtglKNC+hSgwiJrSt79ufQmkB27WNBM2WJUY5L+W1Dj iKk91117x9cIhMuI+eAanjtJbWR9qM8GNcARzrUptagmoTQdzCpyl5tYnd4iDVkXJD6/dEUQX+qsA kszHZ67VpOrbYHYqtV1Qcsozcizy840BVWqZclQlU1IrssvuddvRZPni9wHqyR3es+cfJuJX6chcC 71T/9+QQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Euqf-Fc; Mon, 10 Jul 2023 20:43:44 +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 , Max Filippov , linux-xtensa@linux-xtensa.org Subject: [PATCH v5 29/38] xtensa: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:30 +0100 Message-Id: <20230710204339.3554919-30-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-Rspam-User: X-Stat-Signature: umn5ak69ijg1j9r7p6gipriqmroq5okg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CFE5D14000F X-HE-Tag: 1689021829-766254 X-HE-Meta: U2FsdGVkX19DONondA57c222WVjvawPVJB9MS/xqECpw7UsPYHPdvCvji+jfbHXEFNcuXFtT50H8p2LDagLfeS0OAtWOThlK/JuHrHUGz2WnccT1mhj6qcZiEr/G+Bkwi8W08+May4lQyZtFo+2UCDH0gD8Idjdx9cDxXvtPjWMn6Hkfre64ag7gZS5nnL5PhM59CxMtW92BwqKhCxyLtz9NUPx1DZszbKMm6A01Rbub/eF/2Rf0TiwmtCUJkawehTfP91jUVQhuLm6sMVlpQGvFkkZvf1feH4vvB4ZYuPEquAMYsRxEXq71IUmaeBZigVXqhxboMKnRxRLWlaVnK2ML3CdMnEQM05KB7t9xK0ZkVCjIVE2MoCvGb2S2kBWGDtpatSXO1ikU2BiXqTvurJs/K1kgQTAw2IABLTMk+QfEL8FsnZIMz/LElIQQOZ6wp6hutmr2u6fcPNjyxg7u4pa4G/eFnJDUgBVrfYvfC+ZH6NEjPmR8LRw5dtMcuYx0nEPUMj4aYM4VX9dZ4v+zeWckcQ6XSD0YQu10h9oDS917kyjG6XNHPpPrHDvMP8teuVwzumuXhyo9qqDqgqSF0si4Qx9PWx9ygxlOGfagJgCTBzzDdU+TEUtd/qd9x1ryt33LIdnwFMBqrNGvq40Upat93zBdXQBtyMIeiVajQFK4llM5Ga6WKXvSEruPouqkUzPTppJR/LnwcZGEVDm2P+7fryCpjWaeq877sx7vcc43dF1KVuil4d54itoQDgsUavoLmiunBULr79cq6xPSnGFn9ZAJYGX0L82kPiyJVN3HuohsSjWWE9bvD6z1DC85dtBDiyimPNWvzZaTpUgjCDBT71DUrsShXZrXpAxdAXG/lKUY9k0uyT7TsG5ppl1BkefwPYmhPURsG1WGtWRTYE4lGYCqUgyxoht8GiwYa3O7/IPP8zxY2t3dyMiTz0cqh7c/HaEtngJxJPWnDag F2uv0fmu XQFNtUhU2A9bhviOGXYPtB+y9f8K0HI3ooSZU4I+I1iOIZsBpgVg6W5C53IkkRviM9R1HwMuUEOx52unqXfTRQGP5HpvSgFDnrREcA8UUTl6emxc/TQ4OO7X94Jg01YzpNw6kV6eWATIeEM2YoKJhEXOeQdfkdlFHFBmwea3oJyYZjISKTyPNbTj5NUAzMgkbuROsMcmnzncz0LDKsRDcvP33ZG1MJgTXVmFZQojyy4IBOvws3LR81giMuzJ3uFnqgmu99Um56gTb2FsklkBIqBwIgalVtneLb+rMOv6aAlkLkkAaNW4m43BCmwcI5R63MjMG 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: Add PFN_PTE_SHIFT, update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Max Filippov Cc: linux-xtensa@linux-xtensa.org --- arch/xtensa/include/asm/cacheflush.h | 9 ++- arch/xtensa/include/asm/pgtable.h | 18 +++--- arch/xtensa/mm/cache.c | 83 ++++++++++++++++------------ 3 files changed, 63 insertions(+), 47 deletions(-) diff --git a/arch/xtensa/include/asm/cacheflush.h b/arch/xtensa/include/asm/cacheflush.h index 7b4359312c25..35153f6725e4 100644 --- a/arch/xtensa/include/asm/cacheflush.h +++ b/arch/xtensa/include/asm/cacheflush.h @@ -119,8 +119,14 @@ void flush_cache_page(struct vm_area_struct*, #define flush_cache_vmap(start,end) flush_cache_all() #define flush_cache_vunmap(start,end) flush_cache_all() +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio + #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page(struct page *); +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} void local_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); @@ -156,6 +162,7 @@ void local_flush_cache_page(struct vm_area_struct *vma, /* This is not required, see Documentation/core-api/cachetlb.rst */ #define flush_icache_page(vma,page) do { } while (0) +#define flush_icache_pages(vma, page, nr) do { } while (0) #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h index fc7a14884c6c..ef79cb6c20dc 100644 --- a/arch/xtensa/include/asm/pgtable.h +++ b/arch/xtensa/include/asm/pgtable.h @@ -274,6 +274,7 @@ static inline pte_t pte_mkwrite(pte_t pte) * and a page entry and page directory to the page they refer to. */ +#define PFN_PTE_SHIFT PAGE_SHIFT #define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) #define pte_same(a,b) (pte_val(a) == pte_val(b)) #define pte_page(x) pfn_to_page(pte_pfn(x)) @@ -301,15 +302,9 @@ static inline void update_pte(pte_t *ptep, pte_t pteval) struct mm_struct; -static inline void -set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval) -{ - update_pte(ptep, pteval); -} - -static inline void set_pte(pte_t *ptep, pte_t pteval) +static inline void set_pte(pte_t *ptep, pte_t pte) { - update_pte(ptep, pteval); + update_pte(ptep, pte); } static inline void @@ -407,8 +402,11 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) #else -extern void update_mmu_cache(struct vm_area_struct * vma, - unsigned long address, pte_t *ptep); +struct vm_fault; +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr); +#define update_mmu_cache(vma, address, ptep) \ + update_mmu_cache_range(NULL, vma, address, ptep, 1) typedef pte_t *pte_addr_t; diff --git a/arch/xtensa/mm/cache.c b/arch/xtensa/mm/cache.c index 19e5a478a7e8..7ec66a79f472 100644 --- a/arch/xtensa/mm/cache.c +++ b/arch/xtensa/mm/cache.c @@ -121,9 +121,9 @@ EXPORT_SYMBOL(copy_user_highpage); * */ -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { - struct address_space *mapping = page_mapping_file(page); + struct address_space *mapping = folio_flush_mapping(folio); /* * If we have a mapping but the page is not mapped to user-space @@ -132,14 +132,14 @@ void flush_dcache_page(struct page *page) */ if (mapping && !mapping_mapped(mapping)) { - if (!test_bit(PG_arch_1, &page->flags)) - set_bit(PG_arch_1, &page->flags); + if (!test_bit(PG_arch_1, &folio->flags)) + set_bit(PG_arch_1, &folio->flags); return; } else { - - unsigned long phys = page_to_phys(page); - unsigned long temp = page->index << PAGE_SHIFT; + unsigned long phys = folio_pfn(folio) * PAGE_SIZE; + unsigned long temp = folio_pos(folio); + unsigned int i, nr = folio_nr_pages(folio); unsigned long alias = !(DCACHE_ALIAS_EQ(temp, phys)); unsigned long virt; @@ -154,22 +154,26 @@ void flush_dcache_page(struct page *page) return; preempt_disable(); - virt = TLBTEMP_BASE_1 + (phys & DCACHE_ALIAS_MASK); - __flush_invalidate_dcache_page_alias(virt, phys); + for (i = 0; i < nr; i++) { + virt = TLBTEMP_BASE_1 + (phys & DCACHE_ALIAS_MASK); + __flush_invalidate_dcache_page_alias(virt, phys); - virt = TLBTEMP_BASE_1 + (temp & DCACHE_ALIAS_MASK); + virt = TLBTEMP_BASE_1 + (temp & DCACHE_ALIAS_MASK); - if (alias) - __flush_invalidate_dcache_page_alias(virt, phys); + if (alias) + __flush_invalidate_dcache_page_alias(virt, phys); - if (mapping) - __invalidate_icache_page_alias(virt, phys); + if (mapping) + __invalidate_icache_page_alias(virt, phys); + phys += PAGE_SIZE; + temp += PAGE_SIZE; + } preempt_enable(); } /* There shouldn't be an entry in the cache for this page anymore. */ } -EXPORT_SYMBOL(flush_dcache_page); +EXPORT_SYMBOL(flush_dcache_folio); /* * For now, flush the whole cache. FIXME?? @@ -207,45 +211,52 @@ EXPORT_SYMBOL(local_flush_cache_page); #endif /* DCACHE_WAY_SIZE > PAGE_SIZE */ -void -update_mmu_cache(struct vm_area_struct * vma, unsigned long addr, pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr) { unsigned long pfn = pte_pfn(*ptep); - struct page *page; + struct folio *folio; + unsigned int i; if (!pfn_valid(pfn)) return; - page = pfn_to_page(pfn); + folio = page_folio(pfn_to_page(pfn)); - /* Invalidate old entry in TLBs */ - - flush_tlb_page(vma, addr); + /* Invalidate old entries in TLBs */ + for (i = 0; i < nr; i++) + flush_tlb_page(vma, addr + i * PAGE_SIZE); + nr = folio_nr_pages(folio); #if (DCACHE_WAY_SIZE > PAGE_SIZE) - if (!PageReserved(page) && test_bit(PG_arch_1, &page->flags)) { - unsigned long phys = page_to_phys(page); + if (!folio_test_reserved(folio) && test_bit(PG_arch_1, &folio->flags)) { + unsigned long phys = folio_pfn(folio) * PAGE_SIZE; unsigned long tmp; preempt_disable(); - tmp = TLBTEMP_BASE_1 + (phys & DCACHE_ALIAS_MASK); - __flush_invalidate_dcache_page_alias(tmp, phys); - tmp = TLBTEMP_BASE_1 + (addr & DCACHE_ALIAS_MASK); - __flush_invalidate_dcache_page_alias(tmp, phys); - __invalidate_icache_page_alias(tmp, phys); + for (i = 0; i < nr; i++) { + tmp = TLBTEMP_BASE_1 + (phys & DCACHE_ALIAS_MASK); + __flush_invalidate_dcache_page_alias(tmp, phys); + tmp = TLBTEMP_BASE_1 + (addr & DCACHE_ALIAS_MASK); + __flush_invalidate_dcache_page_alias(tmp, phys); + __invalidate_icache_page_alias(tmp, phys); + phys += PAGE_SIZE; + } preempt_enable(); - clear_bit(PG_arch_1, &page->flags); + clear_bit(PG_arch_1, &folio->flags); } #else - if (!PageReserved(page) && !test_bit(PG_arch_1, &page->flags) + if (!folio_test_reserved(folio) && !test_bit(PG_arch_1, &folio->flags) && (vma->vm_flags & VM_EXEC) != 0) { - unsigned long paddr = (unsigned long)kmap_atomic(page); - __flush_dcache_page(paddr); - __invalidate_icache_page(paddr); - set_bit(PG_arch_1, &page->flags); - kunmap_atomic((void *)paddr); + for (i = 0; i < nr; i++) { + void *paddr = kmap_local_folio(folio, i * PAGE_SIZE); + __flush_dcache_page((unsigned long)paddr); + __invalidate_icache_page((unsigned long)paddr); + kunmap_local(paddr); + } + set_bit(PG_arch_1, &folio->flags); } #endif } From patchwork Mon Jul 10 20:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307630 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 BC494EB64D9 for ; Mon, 10 Jul 2023 20:44:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 448FE8E0020; Mon, 10 Jul 2023 16:44:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F8DF8E001B; Mon, 10 Jul 2023 16:44:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C2208E0020; Mon, 10 Jul 2023 16:44:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 14E748E001B for ; Mon, 10 Jul 2023 16:44:04 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BA4D614028A for ; Mon, 10 Jul 2023 20:44:03 +0000 (UTC) X-FDA: 80996879166.09.2CB464D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id E6C0B140009 for ; Mon, 10 Jul 2023 20:44:01 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HN1p+gEF; 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=1689021842; 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=F+ZlOZYXfLNjysRkosLQAF/h5hJm/ZmBQd5bhit3iG0=; b=DbPGmnJrnotbnSC77eZgh+fvsrYEmZkouL+TJKjQgUDnAZrMuYmCp5R9njFYuk5AJeJlNq 9HG+qUE6ikXsL1zgv4Q2MR//8D2hZnUBA+t3zwmUVe4Z8B7gZLQS0sAX+Clj+n9BCHTLMC baQSYo2ZFESQFcUAWwbVEOoxObst6dw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HN1p+gEF; 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=1689021842; a=rsa-sha256; cv=none; b=FN0CEhlcD1ScTNi7wbY/5bHZtlA23mnpXHUUfvJNX+8knl3pBcL28uXLhdzZtcUFWX9KY4 fcWJ3AY8C3T0tQBIFbxKCS2VJNiyt1oJ7ZbY7sgxthAh/YOOX7hABIHlVNOHNcz4qxFtD9 6VS5Jsf7QVpBrNrPsALDkO3Xf2cBBUk= 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=F+ZlOZYXfLNjysRkosLQAF/h5hJm/ZmBQd5bhit3iG0=; b=HN1p+gEFEXL2I8SdOVwCy+Eoad oY5wyMKzIMjZhTic3XvCdeipBjThposExOtkyN4oekrhLmxN6ZymyArLOYJ+VSl4KhakWOI1/1nqE RT2qar+hBM7Ne2vF8t5D9eCiEWKvSlKQKsfaWCBBY8AXd2aK4IbGnhp+TV3Jr7h3xHeiff8XDrGUQ sLOPCde6Y2M2iPruUMowU4SXdBEYtZGRNPfhkrbNNKbDu4x6hdXhIyE7RnlxTSgySRCZJ27lXH73L 3txlvo0r36dhsc3FNV1+BDXkTUctkFzxPOdMqCsWjJk5/j4m7pnssMhA8pQqbyPSBa2owsXhLEDo8 dAV4KQLw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Euqh-I4; Mon, 10 Jul 2023 20:43:44 +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, Anshuman Khandual Subject: [PATCH v5 30/38] mm: Remove page_mapping_file() Date: Mon, 10 Jul 2023 21:43:31 +0100 Message-Id: <20230710204339.3554919-31-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: E6C0B140009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: nguc5fd5pm3astp5861i6febc4bo81d4 X-HE-Tag: 1689021841-848220 X-HE-Meta: U2FsdGVkX1/lG5KQMFKh70aNO3asYzkEwH+9WoFjA86MfDVHKiFnGUBjU4w1vcbVO+09wQh0ckzzUk0UoyLouZy/ZHimAV7diUyd1Qs1Mplu2gDc+rqVnNJPRNP90yizdowc2eX7plDuA5L3mYMbkasTtuop0t/PqVpcuvOtqhNojsFJjCO7imbL+s5MkHHdw43umrbs7Ptomvw/+fg/pu9PfjMDYAXzN2oqYe+LnMDMiEsH6FOtTX6la6PKwCGEKCv1CsJLE+ZWUjAfoZ5UUJtfEMIIsZGNHxUqtuglwB+04fWVsnADxqMviFyDxr9s09CLpqBwdccQOpXg8U7Zg47C9uoSokuJPgFujX3bphnT8li2vzX1AAu0gSqsdCF9ckyAuQjg2MI35smRSuU7cmh1885ThqeO1fLwj7tlSJjlNJAzIIvL8JF3HJiRSsPnUvflvbAGT33nkyfI/nIu/ZnuArFKx5MwdFm2gwFHN4pux+8j2T2oS2gO5930DTqDQ20URRR7i0SUeSDHeHgqGTcMM7ZXl2sJwiIUYyjJN8TK8xznzpMzXv393zKfg2gp9jNax6siYsDCh2hY+nc6ViIZg1ZeAZQ3F2eWBXyGyQbFeiYseszmFotZdHkfV8//uzNHWmgVEJScVHyAypaH/5gDexvwnmK8qQisi3A36UbNHoF9wCP1aMyvk4q915yymoylZtXbezDIZ22cU8wqwaFAlzNji6ZRa1PCkr9JaaSAbxGlKZcaUhko8tPejmUBU5UOIwqY8tCjfNZJj/zmAfrn9as3vteZbEd2e2L3sMsvH3yiML1XGPh8ZTzWFHNjIC/P8seyyZxjZL+Iq4WqB7yRrFV/2LPdpFmoAhaHuXHMNlK6L876u03gKPaHxyTZknV3rOG+dWW/fExhkmuSrQqZRKmeP0Vdp5XvUcV4MFSvqYG9dJ+jMPlEyJYarLABSvN5MwA61d9P6t2xUkh RByh2ed9 SRoZA+OlsEYxPCFQyPOO8lIJPN03zCMZXOjC/K8X7IVXQhkG1OmrAOfdYlgnJru3NGLoYaX1FwXYt37Jlx3iuaU/q0lI4nKAS4Q/CGfVwxckVHhrvCEHzlb0f59DC5j9zYLswDu5cYn2IzvkBwDKWjQoX9y1t/MN11uzeF38jzdHdf8hyJPgHYJRo6J6CfNiD2wFcL3WyUKS66JgggRObczEzq9wzYJOgJ8+SOwXuE4QB/KzvD8mpJK9s9M0sEuZvdVQVn+dKe/tw8PqES5SOL/g9YPbx/wURBau6 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: This function has no more users. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Anshuman Khandual --- include/linux/pagemap.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 794e4e55dc38..71dd79b4ae0a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -414,14 +414,6 @@ static inline struct address_space *page_file_mapping(struct page *page) return folio_file_mapping(page_folio(page)); } -/* - * For file cache pages, return the address_space, otherwise return NULL - */ -static inline struct address_space *page_mapping_file(struct page *page) -{ - return folio_flush_mapping(page_folio(page)); -} - /** * folio_inode - Get the host inode for this folio. * @folio: The folio. From patchwork Mon Jul 10 20:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307611 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 80E02EB64D9 for ; Mon, 10 Jul 2023 20:44:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8178C8E0006; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 757898E000E; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 336668E0006; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D887A8E000F for ; Mon, 10 Jul 2023 16:43:48 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A136480258 for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) X-FDA: 80996878536.07.528AA12 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 1084CA0011 for ; Mon, 10 Jul 2023 20:43:45 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vnFHLham; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021827; 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=UHpZ6SH0+WkPUL5bpjXDkOmNFMUyMh29y7ULEhoyDL8=; b=lr/US9xp5No0IZzd3Au7BO9WhTPHYTDX02uSH+YroCuqxnYXbgjZJunIJF+3kzLlJ84jA5 0DNgUGsA+p5nFUhY/wA4UieSAnmQ5oJLtP+DUJP9FJhuAYgZRXcZ0UsSQdFziPe9J4XoOY r4U386v9q4jERC3ZtsyxwEGfDYgW2OY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021827; a=rsa-sha256; cv=none; b=HoTxbmlOAt4PxMts8YOhedWxcUGOfSSso2KbpU8I7M6/w2hSQyzuzw1q3hYiZrCwjcYUhs 4Mqx8+S/iOUHvAobBAORhZdKBh2ZnQmPX75h5NJ1Rj1YcUYNh7YKdLZIIOv1n1yIKm7Ufq nU56gWIxGZNVB6jJnXXMKiVv6yAEsGA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vnFHLham; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=UHpZ6SH0+WkPUL5bpjXDkOmNFMUyMh29y7ULEhoyDL8=; b=vnFHLhamhUuJx0XVkHEr5iDcu2 +3TJfoCbjKyZ6MYJWfL+lRo5VdBtcZ3o3ErEP71IBepVWG5QEcktOE64SGuwbKhI2TCNJy2jSUr3S XUdOYIzfjjZpYt21j2rO+RsnS3qFE18u8bltgkl7lJuHO6cpLA6wpdidTuFE82lFB899X/avx3efl wuwaJ8F5jzkTFJknU8FZMdIIE4XzZIBI/6INfraNfqH9T4oT9p9gcyypEMXe09QySrPxQDV6Yuf06 VyHnvza0hQMTgJM+PJrtzKBa7QGc2QTjnTKQ6j6nSJElgEJgdaXIJX31I7n7Tl2yJRfXhmIyteKz4 +mjospSg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Euql-KC; Mon, 10 Jul 2023 20:43:44 +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 Subject: [PATCH v5 31/38] mm: Rationalise flush_icache_pages() and flush_icache_page() Date: Mon, 10 Jul 2023 21:43:32 +0100 Message-Id: <20230710204339.3554919-32-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: 1084CA0011 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ws7wng88n96xwrjdawdpqhqo5woixim3 X-HE-Tag: 1689021825-536089 X-HE-Meta: U2FsdGVkX1+V9yUTxQ1eScrKkqxbXB6WTJYMxreyTnwIOG973R/rYfRNH87KDsN8YLCSNlGAOEYBMkpONajiW53ZWW9j1AtvMmE/zFpHjEDRZVwPqraBh1JLpGgFS6kZzWrr1140e8SlDgz7TK4RVBQS8LdxKz+ailb2MlP7FDrKPHqJllwlKf/Kkp8xSXxVXSHCMKEh9ZA6UkunR4AbQW43qKm0bmoWFcIeDW9ujnmATytM1m6A61aoXUzPFLUYa6URpx997Glc437psSO/J7vRceigOuMZOMX3klojb3MdKCbF3kFE+tiTrpzvF66SkJA2XHfPcCoOJH6xk3YO/4LkYBsXuDjHonaobzMZ7x+0Jj29Id5V+vGzFQFctqTAB1KYLD0zEQi/1BAcBFuk3AHhlqzOvUpDxqPVJycEOhYKWSUWar/vApOHeylAaxxdy1w/QYUwT1yCaIXc31VIjdc2gkFHZJe/CsDPQvGcs1SKH3nOZuYy2rMrNbPJnN8IP6ziRTagm6MIalkAg0+Xp2/mdfqzyB+zpXxUTro7pFTnui2oirI+XlwKWaqhQOfh5K85rO9DNkeObGD0v4aDsGggx/rWGNWBhr6jOJXyRu64vCuBD4W8U7jzP/SUDsFXEPiwf//gJEfFPvcZt1nICTpzHdNY2gAmuE592gXUGK83goOYq08tSeGC80RDIrsmv/ivXAQ6gXnxrrdEBhDZ30BKP0Sszq0fgKrFQoj3ii7UxGlSR3I6kQXF6JiBTbxo8FArb9YZppdg6l35wNnSPZNfD9p1akKty/htZ35GNCNtSg7Jl0YJoe9wZu/YoYMev1A8GCpDHaHDn+SvZzgaxvpNAm4fkWAwl43AfuT3Wg04jAiaEuJguDM2mGH2i4ymjK9n6pMnchF1923d2LZl+g6PLwZ8tEQXKLaDns5G58PwdT5X14Yjm98V4FfrPJhmglMMlk90SEjC374XFPy PrkdOHPV /tiovKQ6aNHuz3w4Ml6+sTo2zb19UA04qrpqbNg8BNGujqSNA5eJKcFjfuuyS8QXb3LyBWC2VQ/jSFPxbERakj2X3LLVLAJHL5WU4r1s/Ck6XFfXcA89x4MiC2sPODaZVIscbzMGy8rVZZXJ/EEHqRi7foMjaWR2qSBTHvajZJeATJlp5eF7+PsaiA4trNBE50wQzywFzKxdTqkfBQ5K5QrUR5gtXpJ0CoT+l 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: Move the default (no-op) implementation of flush_icache_pages() to from . Remove the flush_icache_page() wrapper from each architecture into . Signed-off-by: Matthew Wilcox (Oracle) --- arch/alpha/include/asm/cacheflush.h | 5 +---- arch/arc/include/asm/cacheflush.h | 9 --------- arch/arm/include/asm/cacheflush.h | 7 ------- arch/csky/abiv1/inc/abi/cacheflush.h | 1 - arch/csky/abiv2/inc/abi/cacheflush.h | 1 - arch/hexagon/include/asm/cacheflush.h | 2 +- arch/loongarch/include/asm/cacheflush.h | 2 -- arch/m68k/include/asm/cacheflush_mm.h | 1 - arch/mips/include/asm/cacheflush.h | 6 ------ arch/nios2/include/asm/cacheflush.h | 2 +- arch/parisc/include/asm/cacheflush.h | 2 +- arch/sh/include/asm/cacheflush.h | 2 +- arch/sparc/include/asm/cacheflush_32.h | 2 -- arch/sparc/include/asm/cacheflush_64.h | 3 --- arch/xtensa/include/asm/cacheflush.h | 4 ---- include/asm-generic/cacheflush.h | 12 ------------ include/linux/cacheflush.h | 9 +++++++++ 17 files changed, 14 insertions(+), 56 deletions(-) diff --git a/arch/alpha/include/asm/cacheflush.h b/arch/alpha/include/asm/cacheflush.h index 3956460e69e2..36a7e924c3b9 100644 --- a/arch/alpha/include/asm/cacheflush.h +++ b/arch/alpha/include/asm/cacheflush.h @@ -53,10 +53,6 @@ extern void flush_icache_user_page(struct vm_area_struct *vma, #define flush_icache_user_page flush_icache_user_page #endif /* CONFIG_SMP */ -/* This is used only in __do_fault and do_swap_page. */ -#define flush_icache_page(vma, page) \ - flush_icache_user_page((vma), (page), 0, 0) - /* * Both implementations of flush_icache_user_page flush the entire * address space, so one call, no matter how many pages. @@ -66,6 +62,7 @@ static inline void flush_icache_pages(struct vm_area_struct *vma, { flush_icache_user_page(vma, page, 0, 0); } +#define flush_icache_pages flush_icache_pages #include diff --git a/arch/arc/include/asm/cacheflush.h b/arch/arc/include/asm/cacheflush.h index 04f65f588510..bd5b1a9a0544 100644 --- a/arch/arc/include/asm/cacheflush.h +++ b/arch/arc/include/asm/cacheflush.h @@ -18,15 +18,6 @@ #include #include -/* - * Semantically we need this because icache doesn't snoop dcache/dma. - * However ARC Cache flush requires paddr as well as vaddr, latter not available - * in the flush_icache_page() API. So we no-op it but do the equivalent work - * in update_mmu_cache() - */ -#define flush_icache_page(vma, page) -#define flush_icache_pages(vma, page, nr) - void flush_cache_all(void); void flush_icache_range(unsigned long kstart, unsigned long kend); diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h index 841e268d2374..f6181f69577f 100644 --- a/arch/arm/include/asm/cacheflush.h +++ b/arch/arm/include/asm/cacheflush.h @@ -321,13 +321,6 @@ static inline void flush_anon_page(struct vm_area_struct *vma, #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages) #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages) -/* - * We don't appear to need to do anything here. In fact, if we did, we'd - * duplicate cache flushing elsewhere performed by flush_dcache_page(). - */ -#define flush_icache_page(vma,page) do { } while (0) -#define flush_icache_pages(vma, page, nr) do { } while (0) - /* * flush_cache_vmap() is used when creating mappings (eg, via vmap, * vmalloc, ioremap etc) in kernel space for pages. On non-VIPT diff --git a/arch/csky/abiv1/inc/abi/cacheflush.h b/arch/csky/abiv1/inc/abi/cacheflush.h index 0d6cb65624c4..908d8b0bc4fd 100644 --- a/arch/csky/abiv1/inc/abi/cacheflush.h +++ b/arch/csky/abiv1/inc/abi/cacheflush.h @@ -45,7 +45,6 @@ extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, u #define flush_cache_vmap(start, end) cache_wbinv_all() #define flush_cache_vunmap(start, end) cache_wbinv_all() -#define flush_icache_page(vma, page) do {} while (0); #define flush_icache_range(start, end) cache_wbinv_range(start, end) #define flush_icache_mm_range(mm, start, end) cache_wbinv_range(start, end) #define flush_icache_deferred(mm) do {} while (0); diff --git a/arch/csky/abiv2/inc/abi/cacheflush.h b/arch/csky/abiv2/inc/abi/cacheflush.h index 9c728933a776..40be16907267 100644 --- a/arch/csky/abiv2/inc/abi/cacheflush.h +++ b/arch/csky/abiv2/inc/abi/cacheflush.h @@ -33,7 +33,6 @@ static inline void flush_dcache_page(struct page *page) #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) -#define flush_icache_page(vma, page) do { } while (0) #define flush_icache_range(start, end) cache_wbinv_range(start, end) diff --git a/arch/hexagon/include/asm/cacheflush.h b/arch/hexagon/include/asm/cacheflush.h index dc3f500a5a01..bfff514a81c8 100644 --- a/arch/hexagon/include/asm/cacheflush.h +++ b/arch/hexagon/include/asm/cacheflush.h @@ -18,7 +18,7 @@ * - flush_cache_range(vma, start, end) flushes a range of pages * - flush_icache_range(start, end) flush a range of instructions * - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache - * - flush_icache_page(vma, pg) flushes(invalidates) a page for icache + * - flush_icache_pages(vma, pg, nr) flushes(invalidates) nr pages for icache * * Need to doublecheck which one is really needed for ptrace stuff to work. */ diff --git a/arch/loongarch/include/asm/cacheflush.h b/arch/loongarch/include/asm/cacheflush.h index 88a44da50a3b..80bd74106985 100644 --- a/arch/loongarch/include/asm/cacheflush.h +++ b/arch/loongarch/include/asm/cacheflush.h @@ -46,8 +46,6 @@ void local_flush_icache_range(unsigned long start, unsigned long end); #define flush_cache_page(vma, vmaddr, pfn) do { } while (0) #define flush_cache_vmap(start, end) do { } while (0) #define flush_cache_vunmap(start, end) do { } while (0) -#define flush_icache_page(vma, page) do { } while (0) -#define flush_icache_pages(vma, page) do { } while (0) #define flush_icache_user_page(vma, page, addr, len) do { } while (0) #define flush_dcache_page(page) do { } while (0) #define flush_dcache_mmap_lock(mapping) do { } while (0) diff --git a/arch/m68k/include/asm/cacheflush_mm.h b/arch/m68k/include/asm/cacheflush_mm.h index 88eb85e81ef6..ed12358c4783 100644 --- a/arch/m68k/include/asm/cacheflush_mm.h +++ b/arch/m68k/include/asm/cacheflush_mm.h @@ -261,7 +261,6 @@ static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr) #define flush_dcache_mmap_unlock(mapping) do { } while (0) #define flush_icache_pages(vma, page, nr) \ __flush_pages_to_ram(page_address(page), nr) -#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) extern void flush_icache_user_page(struct vm_area_struct *vma, struct page *page, unsigned long addr, int len); diff --git a/arch/mips/include/asm/cacheflush.h b/arch/mips/include/asm/cacheflush.h index 0f389bc7cb90..f36c2519ed97 100644 --- a/arch/mips/include/asm/cacheflush.h +++ b/arch/mips/include/asm/cacheflush.h @@ -82,12 +82,6 @@ static inline void flush_anon_page(struct vm_area_struct *vma, __flush_anon_page(page, vmaddr); } -static inline void flush_icache_pages(struct vm_area_struct *vma, - struct page *page, unsigned int nr) -{ -} -#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) - extern void (*flush_icache_range)(unsigned long start, unsigned long end); extern void (*local_flush_icache_range)(unsigned long start, unsigned long end); extern void (*__flush_icache_user_range)(unsigned long start, diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h index 8624ca83cffe..7c48c5213fb7 100644 --- a/arch/nios2/include/asm/cacheflush.h +++ b/arch/nios2/include/asm/cacheflush.h @@ -35,7 +35,7 @@ void flush_dcache_folio(struct folio *folio); extern void flush_icache_range(unsigned long start, unsigned long end); void flush_icache_pages(struct vm_area_struct *vma, struct page *page, unsigned int nr); -#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1); +#define flush_icache_pages flush_icache_pages #define flush_cache_vmap(start, end) flush_dcache_range(start, end) #define flush_cache_vunmap(start, end) flush_dcache_range(start, end) diff --git a/arch/parisc/include/asm/cacheflush.h b/arch/parisc/include/asm/cacheflush.h index b77c3e0c37d3..b4006f2a9705 100644 --- a/arch/parisc/include/asm/cacheflush.h +++ b/arch/parisc/include/asm/cacheflush.h @@ -60,7 +60,7 @@ static inline void flush_dcache_page(struct page *page) void flush_icache_pages(struct vm_area_struct *vma, struct page *page, unsigned int nr); -#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) +#define flush_icache_pages flush_icache_pages #define flush_icache_range(s,e) do { \ flush_kernel_dcache_range_asm(s,e); \ diff --git a/arch/sh/include/asm/cacheflush.h b/arch/sh/include/asm/cacheflush.h index 9fceef6f3e00..878b6b551bd2 100644 --- a/arch/sh/include/asm/cacheflush.h +++ b/arch/sh/include/asm/cacheflush.h @@ -53,7 +53,7 @@ extern void flush_icache_range(unsigned long start, unsigned long end); #define flush_icache_user_range flush_icache_range void flush_icache_pages(struct vm_area_struct *vma, struct page *page, unsigned int nr); -#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) +#define flush_icache_pages flush_icache_pages extern void flush_cache_sigtramp(unsigned long address); struct flusher_data { diff --git a/arch/sparc/include/asm/cacheflush_32.h b/arch/sparc/include/asm/cacheflush_32.h index 8dba35d63328..21f6c918238b 100644 --- a/arch/sparc/include/asm/cacheflush_32.h +++ b/arch/sparc/include/asm/cacheflush_32.h @@ -15,8 +15,6 @@ #define flush_cache_page(vma,addr,pfn) \ sparc32_cachetlb_ops->cache_page(vma, addr) #define flush_icache_range(start, end) do { } while (0) -#define flush_icache_page(vma, pg) do { } while (0) -#define flush_icache_pages(vma, pg, nr) do { } while (0) #define copy_to_user_page(vma, page, vaddr, dst, src, len) \ do { \ diff --git a/arch/sparc/include/asm/cacheflush_64.h b/arch/sparc/include/asm/cacheflush_64.h index a9a719f04d06..0e879004efff 100644 --- a/arch/sparc/include/asm/cacheflush_64.h +++ b/arch/sparc/include/asm/cacheflush_64.h @@ -53,9 +53,6 @@ static inline void flush_dcache_page(struct page *page) flush_dcache_folio(page_folio(page)); } -#define flush_icache_page(vma, pg) do { } while(0) -#define flush_icache_pages(vma, pg, nr) do { } while(0) - void flush_ptrace_access(struct vm_area_struct *, struct page *, unsigned long uaddr, void *kaddr, unsigned long len, int write); diff --git a/arch/xtensa/include/asm/cacheflush.h b/arch/xtensa/include/asm/cacheflush.h index 35153f6725e4..785a00ce83c1 100644 --- a/arch/xtensa/include/asm/cacheflush.h +++ b/arch/xtensa/include/asm/cacheflush.h @@ -160,10 +160,6 @@ void local_flush_cache_page(struct vm_area_struct *vma, __invalidate_icache_range(start,(end) - (start)); \ } while (0) -/* This is not required, see Documentation/core-api/cachetlb.rst */ -#define flush_icache_page(vma,page) do { } while (0) -#define flush_icache_pages(vma, page, nr) do { } while (0) - #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) diff --git a/include/asm-generic/cacheflush.h b/include/asm-generic/cacheflush.h index 09d51a680765..84ec53ccc450 100644 --- a/include/asm-generic/cacheflush.h +++ b/include/asm-generic/cacheflush.h @@ -77,18 +77,6 @@ static inline void flush_icache_range(unsigned long start, unsigned long end) #define flush_icache_user_range flush_icache_range #endif -#ifndef flush_icache_page -static inline void flush_icache_pages(struct vm_area_struct *vma, - struct page *page, unsigned int nr) -{ -} - -static inline void flush_icache_page(struct vm_area_struct *vma, - struct page *page) -{ -} -#endif - #ifndef flush_icache_user_page static inline void flush_icache_user_page(struct vm_area_struct *vma, struct page *page, diff --git a/include/linux/cacheflush.h b/include/linux/cacheflush.h index 82136f3fcf54..55f297b2c23f 100644 --- a/include/linux/cacheflush.h +++ b/include/linux/cacheflush.h @@ -17,4 +17,13 @@ static inline void flush_dcache_folio(struct folio *folio) #define flush_dcache_folio flush_dcache_folio #endif /* ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE */ +#ifndef flush_icache_pages +static inline void flush_icache_pages(struct vm_area_struct *vma, + struct page *page, unsigned int nr) +{ +} +#endif + +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1) + #endif /* _LINUX_CACHEFLUSH_H */ From patchwork Mon Jul 10 20:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307632 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 826BCEB64D9 for ; Mon, 10 Jul 2023 20:44:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 693528E0022; Mon, 10 Jul 2023 16:44:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61D8A8E001B; Mon, 10 Jul 2023 16:44:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 447768E0022; Mon, 10 Jul 2023 16:44:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2CFEE8E001B for ; Mon, 10 Jul 2023 16:44:07 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0395E80246 for ; Mon, 10 Jul 2023 20:44:06 +0000 (UTC) X-FDA: 80996879334.13.0A310E7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 055B110000F for ; Mon, 10 Jul 2023 20:44:04 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=h5hg1vuQ; dmarc=none; spf=none (imf14.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=1689021845; a=rsa-sha256; cv=none; b=EAGifej1a2/p7sMrQsgKMsKQbH/rs9Ed2tuBy4xruRqAlSMMMMEY6QfPZfcJcZTtqQBrIJ B93ncbw0bDwb2dxWsEdY6VhU8UTKluY2+bh9FqGhaf83pHVd/7Ja1QtidQ/Mwu81SsPr/b MMtXvCiSDHf3bhLGT2RZ4tt/OcKi4do= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=h5hg1vuQ; dmarc=none; spf=none (imf14.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=1689021845; 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=zInuUFQyhX5p7DpW3QqqQDh+iQp8HWHqrOQDZ/8fecU=; b=Jfjs3BzCJdCtoIvLCP8B/GnOYv+rTXZQ91YA2jrhDUXX9qAwSwIIJFpL0RvxGm8P3qNc3Y NOw8JGNHd8LKgz1h0AFDy7ey5fvj3nLAFJpZmV9OlVkAnXmcgzrEpF2jow8fiEsvmTqoPv UzAwbfRcJPnj7fqZL9pSBPq4ppZ3IW0= 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=zInuUFQyhX5p7DpW3QqqQDh+iQp8HWHqrOQDZ/8fecU=; b=h5hg1vuQKj8IikMBDz/QMQ5zbM BU94LS/OWLcKkW6MxRnbHPLCfyRZ2Lr6xBmEK9Rx6BXDSf1Sra6nL03pUpr/aTtubBUTbTjg4XQH+ VdLL8HvPmHmq79BaL5uIRw16OPQJX1cm4deBVvW+FjCaqQha73lKU2GtIOfjnBeGaQnYkCRUB+4/G aYjSnWAwOzf+4ATQRUlE040bdRBIC74jAE4rASNqAsBSG2GrOBj/+eN1MgBa+07KdCQCYEQA7VSOI 8V/56S2yFOPY+Hc8geU/XDl1km87/OOnNr1GGaCAOUC1zRM0wAZJVqzCjQWNAdN+VV2gt9Shqf+aI vZ94wgIA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Euqu-P3; Mon, 10 Jul 2023 20:43:44 +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, Anshuman Khandual Subject: [PATCH v5 32/38] mm: Tidy up set_ptes definition Date: Mon, 10 Jul 2023 21:43:33 +0100 Message-Id: <20230710204339.3554919-33-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 055B110000F X-Stat-Signature: 1c55hubo8onikebozb8u6hobzxpxs4tf X-HE-Tag: 1689021844-284960 X-HE-Meta: U2FsdGVkX1/32cb5pnYiTDTkB+Suh5UvEXBXdQJRBI2kvrOqK0Jv7M4nRXMfw678CUC8XZ3tzzs95yeGSt7FaVu6q/XelDSmQCJ7yeSYBDCkHMQPN//iXV3cpCWkiPo6rX4CFi/HevnL59/88lOd21aSePf4HpspvY1LhPk7V4gfT+VMkOUZAFWA3d9OAY53H68wc+r19OB/BIdA32UM5wx2tTtBPZWc8xz0FhllLn2cmFE5eEvttphHStIpuQ1QDFTfqbTUiHVpVfNKiMi0WbmLDK2PEX21rpCiJPG+PE9IUKSya98w1z2eq+qTPs2TJotaTQqqJatOUAO39IGR+8OfM+Mj5W5zGzqODC6FYOS33t/pLUNc5D4dwQZIjOZ2mPK9dfs1YBCb8XJcrYlVWpOZnEyQ1uF5vRZRgpFRfm35wx6J66qcov2sbpiecRsZEEy/HW6SBbHuQ3JuVGNqJH8uH04s7Itcfa5jovO5KhfxfLhBH8HHjwoxZJxO7hK3jdb/ksIbR3pS5EEelP2rS+exo918qxFPqhjbIDSznJeg04kF0qrMOsq6cxrR3WjuBT0TbOPRirf9xvWlmwRLV+zCjd2nUTdeCvWro+yfWuNWNQRJaj8ybty8R1ubECl60X3/wgc6cO7OWo48sGakajR4Z/s6pd4jRCFMg1MSC2t+F7Y3LmxbHGG6mBseosZAxZIbRZLrZzLWVC8NZaXY3BuPg2ZugYwBac5dzCokEU+MR0A3LNDSymgYl4AaZ9i67TeO5EyXCpl9z+B5sNhlRyC7GZQk8HokLg75jwleKpkxDnZC3PI/DzWBIeSDxEzXdJQlmDuXFuYKVL0aBSGmhcfkHsP+RS84+cwDwuBfaqaRVr/bJyv96mf/uOkfoNkLmbwyf3m+3NNjI2DW7btA8Esl3JbscDTnbTlP3kfkrA56XLu+9LkIHLGTJMTmajM0gBCj4FXSlwb046zMNyP dVcALKlH t4mDry5FY47rbbwCA8QrqlptK+BCdSn7Z3kJQDsuXRoeAdWyvI0nT7qaEvntajvq2TGWKoBn0LuVmm0W1zG6NmCipspEkBuc+kl25968+bK2lKz1aR2AJgyFh/6Dtwjm+6IbV+TN3e/iz2O3FqVdHoQEX4GFf9xmssCBYPUwNg25zxRa5qs9oP+1u0qlT2vWfvXSVy2+mV5uh4j5+mSqzNAAqsXM5CuuSfID9rsOQcJKnV2hO+flqRS8rmOxkGzRHa4lG/aNOpkD7RF29cP0sas4vRQtXXIfOtEud 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: Now that all architectures are converted, we can remove the PFN_PTE_SHIFT ifdef and we can define set_pte_at() unconditionally. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Anshuman Khandual --- include/linux/pgtable.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 22f48f9997d5..e2a0bd5941be 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -181,7 +181,6 @@ 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. @@ -209,13 +208,8 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, 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, From patchwork Mon Jul 10 20:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307615 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 3A4C5EB64DC for ; Mon, 10 Jul 2023 20:44:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 161EE8E000F; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F04D88E0011; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F0E18E0012; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1C4C18E000B for ; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EAD37AFAB9 for ; Mon, 10 Jul 2023 20:43:48 +0000 (UTC) X-FDA: 80996878536.08.02B7DFD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 3778C2000B for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QUlAJhWR; dmarc=none; spf=none (imf03.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=1689021827; 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=paPNbsDhrgFpFK66NfUXWHVPB3cHJyjAQhVhGRR5N+U=; b=Py10z7d/CnUkUVuXTcyAfEJmexmnaGGz9xmCr4WncoWhOQwZbAMdvXCMj4tqGwtUBwl7Al Hf3w2VYLAGtk1fleKAm3vXVK5NrRgVxgsQXu42/GHbN1dajGmEmk4ZA9dMFnLRbjJbSzRH QE2LkASp0/akHp3wo0F/e54RujWu3WQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QUlAJhWR; dmarc=none; spf=none (imf03.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=1689021827; a=rsa-sha256; cv=none; b=fG+eh3R2QL0cQ1wSqo0ArEYw54Xj4+LnQBuDydWKuiwKxgfyeuj+pYEnAt3lvu0Lq19m2C zs8PeGW3c2E04zv7vQyclWCBRPVsJcYN6YxooYPDoAKxQfXdo8uAMEeI7exo5MU1wxWiXg ePybDz9JAUiJa9ZDoeyUln6ay+KRwzA= 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=paPNbsDhrgFpFK66NfUXWHVPB3cHJyjAQhVhGRR5N+U=; b=QUlAJhWRNtFfmO7LZAtZUSyWv3 Yj6u2SE4iI6rFGiFOGHlKsUXxIapWLmZWsYfFAYfENSbb4vLwByEs/6XN1nlTK/hyUof5bWAqj1dj LAku+E4ib0zFnv5xeOROvKW4KEucJNW8DbWcT3FawboddIGTkkMdxX4Bs8w+dO3NhVWk2WVx6hLdJ kFvVs8KfTUMemf+kCGffTtHBOEI0wVNJSzi+cXICOq1HuBI6x+sns9KcpYKYB016jvQ5PEw2PlHJ+ UhkJM6mqe3VtGclFhhf+B9SFjdYsrGwJt82VnL86dE6lfhahmjlfo6re3zLgz8LCtNU5D8iJrUlh9 LshlmaPw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjU-00Eur6-Sh; Mon, 10 Jul 2023 20:43:44 +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, Anshuman Khandual Subject: [PATCH v5 33/38] mm: Use flush_icache_pages() in do_set_pmd() Date: Mon, 10 Jul 2023 21:43:34 +0100 Message-Id: <20230710204339.3554919-34-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-Server: rspam09 X-Rspamd-Queue-Id: 3778C2000B X-Stat-Signature: a71edyam8rfou99u1mq88jokkygc7s6a X-Rspam-User: X-HE-Tag: 1689021826-923627 X-HE-Meta: U2FsdGVkX1+EBLupb+5jgMqRFiodGeeUZKAXs7Zs5jYYBxpZe6lGAaxwIbZmieacrGADOv7Lw3muDfZDnEi9s2EY5vMuRKYZlnXG+oRvZBjsiCqB/i8lB5tvefoiDMZ2Eua5kjb4sT6JXssoXeqfxqWVQW1ZgqRVIHqg1dvnDev2pLXAaRqC9SOpvcv2NYKMal8GTTjrFs0f+zA5KHfPcV9M8PnXDCz3tskahpvJl+2wYrbKQ6ra+UXPkoOLtMM68CmQwfbFmowjN98AXiFxqijk1tVjxeH4eM6Ni1/roQ2RJLwmxkFJ3e23o2x5iXbGcCBGRTM6v/m4YuYiMIIcZihVP96hPY4jFnW2Jk/PnDtBZUNP8uJFlQffQGdHXPniX/qSYL/+weeQtdXfgw7Kuo2dPCTvel6ldrSf0GZSqNYVMbnFqBA3cWrIG2cQGq49fcQAOaRFM3xLNSRbor4Efna/JDjPMqkAnLem66xHMWsOo0CkK66DdJgOV8P/5lun30+N+kyKfyQ9rBlI2/fnkRXEaShkJ//5Ju56WuT432yRZUTUDJv5dAq2CVsH4ZRNxTZkdNxh0HGGgvf6ekqFOUOBr4I2yYmWRWS6wzxN9zWaczgBD6pxmnCpQ3eAk0jIhyadzuQdhIlScE7B7EE0ENfIqdt/8j4LLZdtEaTV3TJCbyel2NJ/wWfVwUpYCWzcbED5JOTc2dFchEvJ/llwmQYNlBVRSjitJYeXDwbCi8nbtu9e2+aThHcpH6PDRFZgBiFO0m2bNHETIRYiDBgAJME6XaHOk9EMH7T0T9xyXC9p6EvJvZX2WrBEh7/VTuv5G+hIIb/L+5YMChwVYrFrY9EbV33gpWXEq79H3+hiRL/WEwjFgHpekkp42IIxjVDccKYU+zO3uupp9NChZY0UtWRYU4gOOXHyo1uc06WfQXfYWTsQnKHqoXxJpH75HqfF3QNyuZXuZwliZyOMDYf nf9rH8+H YgAPAHOpzQo3VBjOBESxXibx5C2WPgRg6xhQTVLpN65q/p0SAFTylmaM1YpMJOjiT4vaitBeC65WPXU4KZOVY0SjZxGqB3RIBPJ2EZzd3gvYEWj3wAmAca31YJPIk8VrQL9yPRm+ZqtALLsfO67NaYHJOc6slErTRjL5mJaVrk7dlfDA61/sDhNYvuUHIUDupUCaEqEIyEPFPaqVZkWDQlosHddoP/laxbIbTVhHOcDKJIFYad8ufYRTaQxEtuaV3i82/SO2i7NfNy+mvXK/Oo5gCspscYXTBdS9R 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: Push the iteration over each page down to the architectures (many can flush the entire THP without iteration). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Anshuman Khandual --- mm/memory.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1dada20e3995..ebb4138acdb2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4258,7 +4258,6 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) bool write = vmf->flags & FAULT_FLAG_WRITE; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; pmd_t entry; - int i; vm_fault_t ret = VM_FAULT_FALLBACK; if (!transhuge_vma_suitable(vma, haddr)) @@ -4291,8 +4290,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) if (unlikely(!pmd_none(*vmf->pmd))) goto out; - for (i = 0; i < HPAGE_PMD_NR; i++) - flush_icache_page(vma, page + i); + flush_icache_pages(vma, page, HPAGE_PMD_NR); entry = mk_huge_pmd(page, vma->vm_page_prot); if (write) From patchwork Mon Jul 10 20:43:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307625 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 AB1D5C001B0 for ; Mon, 10 Jul 2023 20:44:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D73608E0017; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CDDD58E001B; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9A3A8E0017; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9FA288E001B for ; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7C0CA1A021C for ; Mon, 10 Jul 2023 20:43:53 +0000 (UTC) X-FDA: 80996878746.02.278F14C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 2F1FF180014 for ; Mon, 10 Jul 2023 20:43:50 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UZGRwuNv; dmarc=none; spf=none (imf16.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=1689021831; 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=LZXcBnkSopupOjRiXEH3IjaRoI8hYxfLxhTdnrJE7/E=; b=gzeqAWaafYCvkVtzXbrGDTOtYcJt+NXX9AnvbitmXPCHgUokJ+Bbvwj6EJU3cB/x93F/kW p/cmYzGkXj1PtgEEY1LJzAYBstlDwRbnfHdrXkjDm3zYYRAw3aNvPTd/bUJFfUXM3x9hjc Rfiyb25G2/Sa5reWoHY4zqPqjrFf1sQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UZGRwuNv; dmarc=none; spf=none (imf16.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=1689021831; a=rsa-sha256; cv=none; b=SYeDKwHmKzgqMlxGUN/RRlIWvto92TIxXSpOBpKJgfIGemXrkXs/DEmvCasHciBhXUwBjr Uwo82bzj3FwdULr4cmj/GSXHedLOWCgUH5eLygg7UoGi77qk1GdiBFJmcl3Sg24pqzn64S 1eqw3RdINuaxZSiMC2lH4a40igOx598= 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=LZXcBnkSopupOjRiXEH3IjaRoI8hYxfLxhTdnrJE7/E=; b=UZGRwuNvpDEO6LgiTtVda6Le3s 8V37WDV4IfgqmT9LGcaQms1+Yk3cLoG2A9KbAfSe7Zu8NeuBDEN6ErcwCrCkw9dcBn4cYyRvuPRZr Jo9VtQkdKqShHWEOW0l06/c0HvvzKnZATErnunpUS8LoBMVlHlTOTIG2ZyBlqqylUDkogeF1xJwCf OlKJu7iSmyX7JGks9C0DDMHv1rEL48wUH5KRJcKgpx6pC2RbyT2o+ycJsWUwUKjbOaleBzWKenZ6u 7PWFgAZCI1jLFzp9FbolUcv/FaJP8Jf9qxtRccd6BjYahFeP0VEV1rHYVQh6pa/NU/900MqLtqgCv jvEi83Ew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjV-00EurD-0w; Mon, 10 Jul 2023 20:43:45 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: Yin Fengwei , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v5 34/38] filemap: Add filemap_map_folio_range() Date: Mon, 10 Jul 2023 21:43:35 +0100 Message-Id: <20230710204339.3554919-35-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: 2F1FF180014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: tbwtmt9zjtusqbqagws7czq8wezzdhx8 X-HE-Tag: 1689021830-883662 X-HE-Meta: U2FsdGVkX18Sad83RH6nLGiKDKAFFgKSq6mUO3KpVjz9KerAd7QxFlzZEy/Wet9Uz3cp3L0jX8KaC5iTnbekLkqW0hBN+C3/FJuRZtfqxyU6jQRYFwGTD0VqQurQHyFFDNfk105tNGPdIzfl+/ApRNDLTWrmNwONaTMzvrwmYareF1+8/RK/Lltxa4csN+PLIIZ7pVvEtZ5WN7HE0bBWN2xh0HulYLnmK5r6LNjTX7m0XhwuA7SVTEP24feZN38hA/C4YMLNXoYaL9MIYdFVzW3fc+OxkM70+Aau2ncx8XWglMzUAX44Ba1D2UqALFNUgRI9aZ/gtN6aTL7c6JpXu+9nBCrELaJrnZfUz3jweXNWRz0lBKg3BK4DZtcO6dNIsbdkJSbAzBndldwOo5gPqJXsblXhX4Zskj9esFmdBzDJiT3+exejMbN9Jpavv3o+HPQeebaQ4qOQnDD5gxzORe6yoadqE/DC/bGTA/8MXTftWHcz9OT3D2+p3lEQuAVOm428misHB8j0w/VLwMpYh6yIDcjVPsVZlx6eOmoEhXeFeLl4ADrXrsAdZd9X4bd1HKLXDrlhxqYAEwfmMEeTG7rbgEk/4V04v8xFornuFcGlVjMAGWGXvOkRfmYn1xXOoF/X6BePGLMUuDuwk50oSo75fsmrC9Y0f1W4333zdh+gCobm/EYi5i1c+Waav9m7ST6cMTABvABnJa09U/zuNU6gE7JrPSRc/2fQtBgrQBm0yLw6AxpoN6YDiKbpFr6WabyQUl9TZxIQV5ISLM4bI1SjDGfzuJ58etItpmVY1YSjLvxHRFJ8Rf+a/3Hla+bKBB3M26j9TragleFSGl1nIjjgPA32swveKdsuIrytl7u3u1BpcShWW90F/NmWI14W6dunR6dS/CIaf/5Wgo490nz4wBeKzzKnwQMdtBZeTw9y3bqqNdnYgCQKrGKqiXLZ4QxF6ecOz9wLiQsLhxA k3b96TBo aCq9KLMP5WO6lpbUdvp3opAqgWl9vibvmwd+tv6OSm+dy0Pr7vmJdtEHxz8YDq8AgpsD/FMvrfmIuDuD2SYVG071asgHRFtsbnqjlQqqyhlZl5adVC70mdqeCEjjC2CYcHzrORy2nXqsSECvuo90SaNeAlM885WZx6bTcN1BjqhuE7Ivur//j48rQjGBMYAUb+2FCHYCT4UFIfwDcj1vuf/F2pa10kkok6QC3uuROlGl3DIoLkFu5ZrbP4AsCGY48cL8x9zW3dqHie4Q= 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: From: Yin Fengwei filemap_map_folio_range() maps partial/full folio. Comparing to original filemap_map_pages(), it updates refcount once per folio instead of per page and gets minor performance improvement for large folio. With a will-it-scale.page_fault3 like app (change file write fault testing to read fault testing. Trying to upstream it to will-it-scale at [1]), got 2% performance gain on a 48C/96T Cascade Lake test box with 96 processes running against xfs. [1]: https://github.com/antonblanchard/will-it-scale/pull/37 Signed-off-by: Yin Fengwei Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 109 ++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8040545954bc..bdc1e0b811bf 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2168,16 +2168,6 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start, } EXPORT_SYMBOL(filemap_get_folios); -static inline -bool folio_more_pages(struct folio *folio, pgoff_t index, pgoff_t max) -{ - if (!folio_test_large(folio) || folio_test_hugetlb(folio)) - return false; - if (index >= max) - return false; - return index < folio_next_index(folio) - 1; -} - /** * filemap_get_folios_contig - Get a batch of contiguous folios * @mapping: The address_space to search @@ -3436,10 +3426,10 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, return false; } -static struct folio *next_uptodate_page(struct folio *folio, - struct address_space *mapping, - struct xa_state *xas, pgoff_t end_pgoff) +static struct folio *next_uptodate_folio(struct xa_state *xas, + struct address_space *mapping, pgoff_t end_pgoff) { + struct folio *folio = xas_next_entry(xas, end_pgoff); unsigned long max_idx; do { @@ -3477,20 +3467,51 @@ static struct folio *next_uptodate_page(struct folio *folio, return NULL; } -static inline struct folio *first_map_page(struct address_space *mapping, - struct xa_state *xas, - pgoff_t end_pgoff) +/* + * Map page range [start_page, start_page + nr_pages) of folio. + * start_page is gotten from start by folio_page(folio, start) + */ +static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, + struct folio *folio, unsigned long start, + unsigned long addr, unsigned int nr_pages) { - return next_uptodate_page(xas_find(xas, end_pgoff), - mapping, xas, end_pgoff); -} + vm_fault_t ret = 0; + struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; + struct page *page = folio_page(folio, start); + unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); + unsigned int ref_count = 0, count = 0; -static inline struct folio *next_map_page(struct address_space *mapping, - struct xa_state *xas, - pgoff_t end_pgoff) -{ - return next_uptodate_page(xas_next_entry(xas, end_pgoff), - mapping, xas, end_pgoff); + do { + if (PageHWPoison(page)) + continue; + + if (mmap_miss > 0) + mmap_miss--; + + /* + * NOTE: If there're PTE markers, we'll leave them to be + * handled in the specific fault path, and it'll prohibit the + * fault-around logic. + */ + if (!pte_none(*vmf->pte)) + continue; + + if (vmf->address == addr) + ret = VM_FAULT_NOPAGE; + + ref_count++; + do_set_pte(vmf, page, addr); + update_mmu_cache(vma, addr, vmf->pte); + } while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages); + + /* Restore the vmf->pte */ + vmf->pte -= nr_pages; + + folio_ref_add(folio, ref_count); + WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); + + return ret; } vm_fault_t filemap_map_pages(struct vm_fault *vmf, @@ -3503,12 +3524,11 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, unsigned long addr; XA_STATE(xas, &mapping->i_pages, start_pgoff); struct folio *folio; - struct page *page; - unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); vm_fault_t ret = 0; + int nr_pages = 0; rcu_read_lock(); - folio = first_map_page(mapping, &xas, end_pgoff); + folio = next_uptodate_folio(&xas, mapping, end_pgoff); if (!folio) goto out; @@ -3525,17 +3545,13 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, goto out; } do { -again: - page = folio_file_page(folio, xas.xa_index); - if (PageHWPoison(page)) - goto unlock; - - if (mmap_miss > 0) - mmap_miss--; + unsigned long end; addr += (xas.xa_index - last_pgoff) << PAGE_SHIFT; vmf->pte += xas.xa_index - last_pgoff; last_pgoff = xas.xa_index; + end = folio->index + folio_nr_pages(folio) - 1; + nr_pages = min(end, end_pgoff) - xas.xa_index + 1; /* * NOTE: If there're PTE markers, we'll leave them to be @@ -3545,32 +3561,17 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, if (!pte_none(ptep_get(vmf->pte))) goto unlock; - /* We're about to handle the fault */ - if (vmf->address == addr) - ret = VM_FAULT_NOPAGE; + ret |= filemap_map_folio_range(vmf, folio, + xas.xa_index - folio->index, addr, nr_pages); - do_set_pte(vmf, page, addr); - /* no need to invalidate: a not-present page won't be cached */ - update_mmu_cache(vma, addr, vmf->pte); - if (folio_more_pages(folio, xas.xa_index, end_pgoff)) { - xas.xa_index++; - folio_ref_inc(folio); - goto again; - } - folio_unlock(folio); - continue; unlock: - if (folio_more_pages(folio, xas.xa_index, end_pgoff)) { - xas.xa_index++; - goto again; - } folio_unlock(folio); folio_put(folio); - } while ((folio = next_map_page(mapping, &xas, end_pgoff)) != NULL); + folio = next_uptodate_folio(&xas, mapping, end_pgoff); + } while (folio); pte_unmap_unlock(vmf->pte, vmf->ptl); out: rcu_read_unlock(); - WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret; } EXPORT_SYMBOL(filemap_map_pages); From patchwork Mon Jul 10 20:43:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307633 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 EFECAEB64D9 for ; Mon, 10 Jul 2023 20:44:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C6678E0023; Mon, 10 Jul 2023 16:44:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 077AE8E001B; Mon, 10 Jul 2023 16:44:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E80AA8E0023; Mon, 10 Jul 2023 16:44:07 -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 CA00F8E001B for ; Mon, 10 Jul 2023 16:44:07 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A0ADA1A017E for ; Mon, 10 Jul 2023 20:44:07 +0000 (UTC) X-FDA: 80996879334.08.030C017 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id DE53614000F for ; Mon, 10 Jul 2023 20:44:05 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ByTAb8QL; 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=1689021846; 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=tse6c+PyGQiNNj587rPbXI3VeCMysTQLdbxkBMTFw2U=; b=RrryZoFxizFhTptBKE/afLEoPYzy/0lGXAgNMf2UW6BpD/oq+IVnTuBWqWeV+VA17mixv6 mQ8ThNJIycDvgsHgD2wCcQuOeaQS7FOa0fGqAcyH/ltSzMeZP0s70xv6MBk1EsUXgloWuc pt98HUqWaWrRl5oSmvwVe5gcdY+3K7E= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ByTAb8QL; 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=1689021846; a=rsa-sha256; cv=none; b=l4xIZ4Ci9pbqbeZlobG9FRXdSxNtHHql47eh7SrOvuulCyMElatI8263bFX0uTcWQwaYG3 164T+mTJuevNsQCf7BGyj1ZNHZLQ023W21sjH+PmFowTnx6HNYyY+ReQ5wibRYuAp8xFi7 BUQx085LN5yQlhOL4WXC+yE6LAycOLw= 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=tse6c+PyGQiNNj587rPbXI3VeCMysTQLdbxkBMTFw2U=; b=ByTAb8QLCEfj5LUw8NRweblA0g IWcJ9mcvelPbcUNEc/gRgpW6n4ttTTktmyu3V7EmrnW0an+1JIqhmeCeyRQBWmDPJuFHUwjzFDWpo XAB1S/E03sxX4yFKmTZaX+54W5iyrUP3Co8NFiKEQfVqMdDBwutG450DZAYzgF4pCRF6XxL4ZmNwA N9WKG1uQmnB8U8rygg5WlNYdy5feYokVBgqd+1DtKuYcoWmWh+pL3pdz30uR+RgEeTguP6cjlmefw 71UTFiAkQLzksnwO8aPUFBJy4ZdRrZcfBsOz5IlsZVF5NRmRO55SF3NP3Vg1E93vlS+J6o3/PcAqu a09WvaTg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjV-00EurO-7T; Mon, 10 Jul 2023 20:43:45 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: Yin Fengwei , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v5 35/38] rmap: add folio_add_file_rmap_range() Date: Mon, 10 Jul 2023 21:43:36 +0100 Message-Id: <20230710204339.3554919-36-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: DE53614000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: pynsmr3usbe34yjobq3q3uzcze8sakc8 X-HE-Tag: 1689021845-638320 X-HE-Meta: U2FsdGVkX1+sDxzPFbSjMP1kZENSUPo4VlQLAXKKfGmZQIfWAyALIV23DN9eDstGvhE8c1659ZNddJ7TGihNW+Ofy1zlj/tzdoCpFAwsamuWjPLhPfzZnA1NhM5BwKzFhyR+n0dsCtjy8MaxRkGdFsY9M7sB9uyHUs8diWq2LNWAB8dtkAXArKEYdmemI8txIJZJxt42F3J3Y4as+UgjtpWd/mbeI4UpyLTM0oM+4iZPfvl/9pohsxeMNpkHsXpGYYidTLFafu4KFqysLYhGagerJI8Iwzz2yTGTValjSxXltq2sgQcg/WjKz7T/IcKvDV6F5R0yver8UEiTuQ1Sb8KFFSPzaiwgwf2BNVAy4BPfYORoO686IixU4+pzHSl2uEGcDO6erMoFBs+3WiDWcQlQAChVWHPzFCQRM0n6Y6Aq5wQu/bsnQlIk45y4wzmTzx0fWwo9nVjIYgBs5nJ2zmeqEc/z65a+D85UmNnfZ3DFnZIIEW9HOE4a27o4ERwL5/28ASTn5Cz6BxKGzHGJfMp48s1JRmSXnk8Wz3krqUV2n0FNFHSABbrCMArvowSTY12sqBcPOt5LKzjUmFlX/OlWjMh6yRJYsaBtJ/kzCKyDi+HSlguC9eeB0biVr492YuDlT7ONXo9KDrFLEZEN56DnyjB1Mz6PfVIPARwNDwutwkO7WngAzxPulgNbxNSenULnsLgRG3EtNCwAY9Y9mqpTlCcx3oxU37jffDNZlU+JOGly1er3VCU3nbttmARCkx/6niTegPFm+iLikEhOO5lD4GfvS4ADF/qD4E+/byiE/9YvkHagv18bLWMdxjfctU1XPf95+ri5hgpzUuv6ybfnWCJK221JnQTnS/j83uOoj1efVnPl599+vNNl5Oajb8rrEKreQt0nS10fDr3XyXXkrdQEtbuxZWy5s0RAvAWypbSwFB6yORdHEWp9pyLHgv27snXoPRYSV6dKK+i Q/ZFYPul Hy3afNb40QdZxY2c4sTRHZTfxShKnNFsveaPHBVpeuFMRZCrfja73vnnb9WFfPoN6ckPghmQ8WgvPVPF9MHYzYQHDlqb/dO7F2ILiHTxxOtVeHmATnMVt10hpmnz3ZLczgbsSHv8xyRaj3a12FAU8FNlBf7/3Cn9Rt7VeRVJ0KNWDpK5axF8N8otMEF64X2ojHES+Oo2Ldm59bctZLdppx8TiJXw1Ra+EX5rhDBFGjKe4jmbuNp9ml4mnUg== 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: From: Yin Fengwei folio_add_file_rmap_range() allows to add pte mapping to a specific range of file folio. Comparing to page_add_file_rmap(), it batched updates __lruvec_stat for large folio. Signed-off-by: Yin Fengwei Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/rmap.h | 2 ++ mm/rmap.c | 60 +++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b87d01660412..a3825ce81102 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -198,6 +198,8 @@ void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); void page_add_file_rmap(struct page *, struct vm_area_struct *, bool compound); +void folio_add_file_rmap_range(struct folio *, struct page *, unsigned int nr, + struct vm_area_struct *, bool compound); void page_remove_rmap(struct page *, struct vm_area_struct *, bool compound); diff --git a/mm/rmap.c b/mm/rmap.c index 2668f5ea3534..642b3ad8bb1a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1306,31 +1306,39 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, } /** - * page_add_file_rmap - add pte mapping to a file page - * @page: the page to add the mapping to + * folio_add_file_rmap_range - add pte mapping to page range of a folio + * @folio: The folio to add the mapping to + * @page: The first page to add + * @nr_pages: The number of pages which will be mapped * @vma: the vm area in which the mapping is added * @compound: charge the page as compound or small page * + * The page range of folio is defined by [first_page, first_page + nr_pages) + * * The caller needs to hold the pte lock. */ -void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, - bool compound) +void folio_add_file_rmap_range(struct folio *folio, struct page *page, + unsigned int nr_pages, struct vm_area_struct *vma, + bool compound) { - struct folio *folio = page_folio(page); atomic_t *mapped = &folio->_nr_pages_mapped; - int nr = 0, nr_pmdmapped = 0; - bool first; + unsigned int nr_pmdmapped = 0, first; + int nr = 0; - VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); + VM_WARN_ON_FOLIO(compound && !folio_test_pmd_mappable(folio), folio); /* Is page being mapped by PTE? Is this its first map to be added? */ if (likely(!compound)) { - first = atomic_inc_and_test(&page->_mapcount); - nr = first; - if (first && folio_test_large(folio)) { - nr = atomic_inc_return_relaxed(mapped); - nr = (nr < COMPOUND_MAPPED); - } + do { + first = atomic_inc_and_test(&page->_mapcount); + if (first && folio_test_large(folio)) { + first = atomic_inc_return_relaxed(mapped); + first = (first < COMPOUND_MAPPED); + } + + if (first) + nr++; + } while (page++, --nr_pages > 0); } else if (folio_test_pmd_mappable(folio)) { /* That test is redundant: it's for safety or to optimize out */ @@ -1359,6 +1367,30 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, mlock_vma_folio(folio, vma, compound); } +/** + * page_add_file_rmap - add pte mapping to a file page + * @page: the page to add the mapping to + * @vma: the vm area in which the mapping is added + * @compound: charge the page as compound or small page + * + * The caller needs to hold the pte lock. + */ +void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, + bool compound) +{ + struct folio *folio = page_folio(page); + unsigned int nr_pages; + + VM_WARN_ON_ONCE_PAGE(compound && !PageTransHuge(page), page); + + if (likely(!compound)) + nr_pages = 1; + else + nr_pages = folio_nr_pages(folio); + + folio_add_file_rmap_range(folio, page, nr_pages, vma, compound); +} + /** * page_remove_rmap - take down pte mapping from a page * @page: page to remove mapping from From patchwork Mon Jul 10 20:43:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307631 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 17771EB64DA for ; Mon, 10 Jul 2023 20:44:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0EDE18E0021; Mon, 10 Jul 2023 16:44:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09D758E001B; Mon, 10 Jul 2023 16:44:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0B2F8E0021; Mon, 10 Jul 2023 16:44:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CD4498E001B for ; Mon, 10 Jul 2023 16:44:05 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9BE51AFD38 for ; Mon, 10 Jul 2023 20:44:05 +0000 (UTC) X-FDA: 80996879250.20.F03D9E1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id DD58E140016 for ; Mon, 10 Jul 2023 20:44:03 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sIIIXaBA; 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=1689021844; 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=WrqzHXPjiFBpxLGjYvBy8RYTw/0aGQBc23U0HQPGcW8=; b=enSs4bwahQSE4jnpVlKYZP0g+USFYZvnd9BGBf9I4PkQPxZnjuPupnB9u1ni+mqLLaQ3yJ G+iKOj98Rt2lpbIxD3/2c6IRgWEUT2niRCYx8ex1LIDEE8Gcp1rNQLjjMDGNKURhUoYf1j tsmQDxeZmNp/KCixfzs7XFWt+gwIZzc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sIIIXaBA; 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=1689021844; a=rsa-sha256; cv=none; b=Wwe7vsmkTVayL0lbR0SlEu6QINqy85q7RTPImLSzOu1ExpAVrAZ4+rnL+G+sy8WaBYHaz+ NMhx8sAHy4l5LIvjhMcZMiqUzyYGdmQtI8HL9H9Vxqr8VExU9HGD/U2PAbt00Xt2ClEqPb cR6CmODTSmDLo/nm9iWvYFt58RDUGOU= 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=WrqzHXPjiFBpxLGjYvBy8RYTw/0aGQBc23U0HQPGcW8=; b=sIIIXaBAvEZhZh4uxJnWMQ5+Pc npP0DZ6HmpXBCr26kwW6ZIWEIYBFLBKcCXU9TqGQNOXKmiqEN+jKNSC8Z9HX/cPYfE7m02dacuYud wKh6ttMmQBuM/rIifVS2Pz+d0ohGhEqc3T2T0iJTuUH7KQi8v/ym+tGS9rOCyaeXObjgR3QqJOHxm 8vIsImmc1dsWvnj/nSgi/1LxdYBySXkzS4DtzFU2k+ESBlnDRke/Ba9/+XMiz+v+soCRM0C5X4N3V tTqXfiq7fdOrx9OF8KiFD8hBxpdxBn9jN5+qDoBsFptNWgNjIxDZgn9D7oQBpla75++vL/cMKYYnN 6r8rSi/Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjV-00EurW-Bs; Mon, 10 Jul 2023 20:43:45 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: Yin Fengwei , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v5 36/38] mm: Convert do_set_pte() to set_pte_range() Date: Mon, 10 Jul 2023 21:43:37 +0100 Message-Id: <20230710204339.3554919-37-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: DD58E140016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 64ifkdzdpma48d1nyqg16kwrmxjszoxw X-HE-Tag: 1689021843-36633 X-HE-Meta: U2FsdGVkX19Y8RhnrhbUX+QZUxEmrm5mMLfhbUr7Fld6HF/l1A8kf87rBmbtCP5ZdBtcjpfm629eOkiMzMny0YAk503tmXeRr55wSLVxm+vbl81371t4a9Negb+XzeGsRoDQNw2HcLok1EuibzTTwmWstkDGcohwmvJfBcRfNrPiS3A8j83o/7BGzd8INyNkTk62YcjaN7dYbFgki1hNyKcpMO4Ywd/4tpRQHKfacAcX34cuz7i17AKkw4gn/cRxN1lWf5ls38r5m/xUi1/zmlQWj/SeEZKaSLCHh+x1AOQjyu/o5AAJt4SZ5hvWI2VSTsUClV/fizBbcpcY4Yvr9OlWi0xtO6rwof+e4obfsae0VQSdsfvSQuWWIp4czoODLkUrV/W9pe4CSjKonwfar5JNDJlllLDlTs2omBUcmqaGXG2ZhHIwb7+Gv5SK8/Nx7/B6RbcdijABMhGPOWEl/Fs2/cUE/j4SRJ1JPQtk8byuLumWEklSUjy5CQmxNDWbqzYDx+fkET29BrD+tsT1GFIyYmcDd77pWlex0CAypLk+aE6sTF46cNGwSYXAGoG5qbj7szZOl1x5GunfJJSLshh2RMErcJbOikViO3FXYmtsUkdAfauESkbFsqlBWD1JThMFWnpbQHu99rzydoHS/hh2ZVltFIPaL4F+47rmkt/O/FKT5mfQjwJotFAl5GpRODnvc9XT1vMIO3rIUuUbnCs7CeOgUalHJnvphF/8RfvYv5lmhvcPcOTSi790Np3aIJgCMBURUP9biVCx2buQyOHBpAqGlqtkYpBXt3cHAN2c3kkx9EJnxAM0SscUbWu7eo2MXox4rx4NP7u2rZENlV12urKRNGPW22YCBrc5ymnim3qCmP1xcHYI/zvZEi0/8TqneRsvZ+aVisO63SJSvBBRUlp5PttflowjchvlrBbp3qlL9hkNl903vNppc9tJr8S+jtCOa8Hj1MylEdP 8r7lE326 U35Ja17ygZ7fPn/VsY91r9neo3/8dLIP7jDFnAXmj5w8UD60rgFArmTBYqPrpxLw6x/d9p2lHSPLsjmLqAsIRla69ja7vZLpLODAlH9iFQef6fsLo/I4tAw8Tw1cLll5m+FsCqhaU3uP2gtFQrBkt6l0YuYJvU98Z9O21mAnNdDzhLsKscrlE/Lyf7f0AkyxM8mZkpQIhI3MxXzka5OteViYw2nJ8URZoEvbUF3l+V4fOUNhnl2yrR6LdgA== 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: From: Yin Fengwei set_pte_range() allows to setup page table entries for a specific range. It takes advantage of batched rmap update for large folio. It now takes care of calling update_mmu_cache_range(). Signed-off-by: Yin Fengwei Signed-off-by: Matthew Wilcox (Oracle) --- Documentation/filesystems/locking.rst | 2 +- include/linux/mm.h | 3 ++- mm/filemap.c | 3 +-- mm/memory.c | 37 +++++++++++++++++---------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst index ed148919e11a..211a03053992 100644 --- a/Documentation/filesystems/locking.rst +++ b/Documentation/filesystems/locking.rst @@ -661,7 +661,7 @@ locked. The VM will unlock the page. Filesystem should find and map pages associated with offsets from "start_pgoff" till "end_pgoff". ->map_pages() is called with the RCU lock held and must not block. If it's not possible to reach a page without blocking, -filesystem should skip it. Filesystem should use do_set_pte() to setup +filesystem should skip it. Filesystem should use set_pte_range() to setup page table entry. Pointer to entry associated with the page is passed in "pte" field in vm_fault structure. Pointers to entries for other offsets should be calculated relative to "pte". diff --git a/include/linux/mm.h b/include/linux/mm.h index 9687b48dfb1b..525a7e16850a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1314,7 +1314,8 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) } vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page); -void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr); +void set_pte_range(struct vm_fault *vmf, struct folio *folio, + struct page *page, unsigned int nr, unsigned long addr); vm_fault_t finish_fault(struct vm_fault *vmf); vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf); diff --git a/mm/filemap.c b/mm/filemap.c index bdc1e0b811bf..c06e9d331416 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3501,8 +3501,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, ret = VM_FAULT_NOPAGE; ref_count++; - do_set_pte(vmf, page, addr); - update_mmu_cache(vma, addr, vmf->pte); + set_pte_range(vmf, folio, page, 1, addr); } while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages); /* Restore the vmf->pte */ diff --git a/mm/memory.c b/mm/memory.c index ebb4138acdb2..e712e5fda56e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4323,15 +4323,24 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) } #endif -void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr) +/** + * set_pte_range - Set a range of PTEs to point to pages in a folio. + * @vmf: Fault decription. + * @folio: The folio that contains @page. + * @page: The first page to create a PTE for. + * @nr: The number of PTEs to create. + * @addr: The first address to create a PTE for. + */ +void set_pte_range(struct vm_fault *vmf, struct folio *folio, + struct page *page, unsigned int nr, unsigned long addr) { struct vm_area_struct *vma = vmf->vma; bool uffd_wp = vmf_orig_pte_uffd_wp(vmf); bool write = vmf->flags & FAULT_FLAG_WRITE; - bool prefault = vmf->address != addr; + bool prefault = in_range(vmf->address, addr, nr * PAGE_SIZE); pte_t entry; - flush_icache_page(vma, page); + flush_icache_pages(vma, page, nr); entry = mk_pte(page, vma->vm_page_prot); if (prefault && arch_wants_old_prefaulted_pte()) @@ -4345,14 +4354,18 @@ void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr) entry = pte_mkuffd_wp(entry); /* copy-on-write page */ if (write && !(vma->vm_flags & VM_SHARED)) { - inc_mm_counter(vma->vm_mm, MM_ANONPAGES); - page_add_new_anon_rmap(page, vma, addr); - lru_cache_add_inactive_or_unevictable(page, vma); + add_mm_counter(vma->vm_mm, MM_ANONPAGES, nr); + VM_BUG_ON_FOLIO(nr != 1, folio); + folio_add_new_anon_rmap(folio, vma, addr); + folio_add_lru_vma(folio, vma); } else { - inc_mm_counter(vma->vm_mm, mm_counter_file(page)); - page_add_file_rmap(page, vma, false); + add_mm_counter(vma->vm_mm, mm_counter_file(page), nr); + folio_add_file_rmap_range(folio, page, nr, vma, false); } - set_pte_at(vma->vm_mm, addr, vmf->pte, entry); + set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr); + + /* no need to invalidate: a not-present page won't be cached */ + update_mmu_cache_range(vmf, vma, addr, vmf->pte, nr); } static bool vmf_pte_changed(struct vm_fault *vmf) @@ -4420,11 +4433,9 @@ vm_fault_t finish_fault(struct vm_fault *vmf) /* Re-check under ptl */ if (likely(!vmf_pte_changed(vmf))) { - do_set_pte(vmf, page, vmf->address); - - /* no need to invalidate: a not-present page won't be cached */ - update_mmu_cache(vma, vmf->address, vmf->pte); + struct folio *folio = page_folio(page); + set_pte_range(vmf, folio, page, 1, vmf->address); ret = 0; } else { update_mmu_tlb(vma, vmf->address, vmf->pte); From patchwork Mon Jul 10 20:43:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307626 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 8A025EB64DC for ; Mon, 10 Jul 2023 20:44:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EA558E001C; Mon, 10 Jul 2023 16:43:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 274828E001B; Mon, 10 Jul 2023 16:43:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02EB88E001D; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E03A48E001C for ; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B94B4025F for ; Mon, 10 Jul 2023 20:43:53 +0000 (UTC) X-FDA: 80996878746.01.72C2607 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id 9E02C140010 for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=c4AwRiQV; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021832; 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=3MITzrjsscz3EOfHnUvCpgkBiqSORw5f6CrRiwc69RA=; b=wastEwV8y54oq3eMmbRwnMA448I+P/PDPXQCN5gA0zpS/u7RddRfdpSCRlu7H8km4c5k1w wfPxx5zTd6SPhegPyISZw6cnkna6Wo8M6TreZ3PahMFUe9vvnTbsr7rv3LG1SmEIGPE/kP ufFsfHVcVsH2JcVLA8sSm7iOA7MVg1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021832; a=rsa-sha256; cv=none; b=Fkcy7o0xO5RhbilR8DSCvapp9WzfnvvMLGwdTBOsFm4wwdVGjjjO3cK5VXysh5pK0YYGUo OFQWkhLHOYydinpgAFhXuHpQEgGqz2s06G6+ogMJHmWVP/SxycyYMxooONxX89dxmOW5Ou pvoPWmnyArEmgnncmM9RMjfzS8HCFgs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=c4AwRiQV; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=3MITzrjsscz3EOfHnUvCpgkBiqSORw5f6CrRiwc69RA=; b=c4AwRiQVrDhrNfG53FzdnE3K+f r0ZI918ORvWE+/rlklI90tC0rTzLt/bZqIrIPosed6W8sSGZxn5juLhXXar5zemsZK9Vcqxkkq584 hDoHHqbFMo7S/5Kft9b2sm/K+b4TNB+bz5U1evgEm9J9ZpskVhypF9jwxVDDkfidplEasdsIZjYqO hH7enTDz4wEm9cPzJr4rkEdVKpTkoNXBC4520HuxwPXnYULE3dtoqo3/DlkNRUpSSrtJge5TyrO3P 66GSziBTrEilNJlA1FCPqBoUjxKyXL04BGstWBXnLIjizU1uhiKJbsmRFrSuJbkOfbXM/ZC6jW7yK Q5ywJ05w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjV-00Eurk-IK; Mon, 10 Jul 2023 20:43:45 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: Yin Fengwei , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v5 37/38] filemap: Batch PTE mappings Date: Mon, 10 Jul 2023 21:43:38 +0100 Message-Id: <20230710204339.3554919-38-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: 9E02C140010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: jeub9ej8sg9x1i54omz1xsqppio6tnxc X-HE-Tag: 1689021831-305164 X-HE-Meta: U2FsdGVkX19BVSexMAC+y3KyKX6amU/EANk08RudFeYdieqET/NA6IjarZOm+IbyVFTwh1LO81jUk7NmiHh9vKRtCyoG12bpgIghrK9yY+lRvD4p6WwnJcTtr1If6kTx43THoF5rWHPoSOeNzivpoYJ7+HzwNgY1H6pHtaA5mSXfOiauLFm5cgpe/fhkbxpvJaIcHDOeVCkF+0L/+44k5CLJZ6Fv67b+oYICd41MqrDtd0cX2lZNSpGREIJbu9DlNI6RMl1hWeXFqkFY7CdOcJLbAhEIX4juvqQsUbVdgNjic3v8oPKbYl3G0CA+SiFy+iz5IcoQ0ZIjIn0yZ4LEBl6RMz18snkEl8ZmSwvVpO3FjO8n5WhE4/opk7/sKH0YDd3n+XpPSqx9CteM8zlbxlpXbvrUrRYpAVAR2QZFqoEADy5yeqt9DslcvDwX3Su9DrV0dT1wcD/JAbUW1mDRF9oIGNPfdzB087jBwBYjHznD2JZ7sD13dsiSGdx8R6s9RsJMXGQFpeXFarOr1pwGBFsixsPOW2z28RajxHOnZsEgTnDirD0dg+VfHWCQ3vcaOoiI8aeOUPTBe6HFj8zoGnbTGribi4GxpiBpWtWQn8G3xjZErBWlhzAna/pCsEdQsP3WS/qxyrfU/C+d38F2Uvufu+y6Vtode+HrdiCrVKdLZ5MhFISAyX4cshQIIKJqbdKI/HeyfWVyAAj7/TJhw22TM+iKPeqxZrlzArxIwfkYMYWTFA0krmy4KCSs8q3cln6/LJaj+UVQok+W8Uzzu7rq2xMOTfjK5d4IYJ7a8ZD8aeKxRBY361K2f6ADECxgNzben8f7FSCygq2QgaLSZDpAlh0cP+QyG5xs8dk+bsTiwptTiDqMiO8CtMhSeqHPPjnr1oE9V9eGm0ymix7Zc6b+Xxwj6vyQVQIGpgYCSlwvB3vHmBP7WNzpXGb5dVxcO2IzHdDCBv1YJ96Y/cS U2TSfM/5 rl1gSVLumfghAjA1GR2iEGWp+dWw0nzt5AH9WL9Lf36KDjw+CNNpVoNTwKBHKMUJYU/XsyqOFFKmhIVGMhuXySXhGAUg76GpH0Yx9llDcV72B5Y/r64rgwO3ATTvN6MKFi4xlowQ2UjeoEerlp4CfWhgisfG84nOuqfxKRfyDgsLBl7hR5U0d7QSRQYZ1/DVDQQ3+n0OTaW5/9GYU/2uluNurW4QIdfK3ilTA 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: From: Yin Fengwei Call set_pte_range() once per contiguous range of the folio instead of once per page. This batches the updates to mm counters and the rmap. With a will-it-scale.page_fault3 like app (change file write fault testing to read fault testing. Trying to upstream it to will-it-scale at [1]) got 15% performance gain on a 48C/96T Cascade Lake test box with 96 processes running against xfs. Perf data collected before/after the change: 18.73%--page_add_file_rmap | --11.60%--__mod_lruvec_page_state | |--7.40%--__mod_memcg_lruvec_state | | | --5.58%--cgroup_rstat_updated | --2.53%--__mod_lruvec_state | --1.48%--__mod_node_page_state 9.93%--page_add_file_rmap_range | --2.67%--__mod_lruvec_page_state | |--1.95%--__mod_memcg_lruvec_state | | | --1.57%--cgroup_rstat_updated | --0.61%--__mod_lruvec_state | --0.54%--__mod_node_page_state The running time of __mode_lruvec_page_state() is reduced about 9%. [1]: https://github.com/antonblanchard/will-it-scale/pull/37 Signed-off-by: Yin Fengwei Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index c06e9d331416..014b73eb96a1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3480,11 +3480,12 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, struct file *file = vma->vm_file; struct page *page = folio_page(folio, start); unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); - unsigned int ref_count = 0, count = 0; + unsigned int count = 0; + pte_t *old_ptep = vmf->pte; do { - if (PageHWPoison(page)) - continue; + if (PageHWPoison(page + count)) + goto skip; if (mmap_miss > 0) mmap_miss--; @@ -3494,20 +3495,34 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, * handled in the specific fault path, and it'll prohibit the * fault-around logic. */ - if (!pte_none(*vmf->pte)) - continue; - - if (vmf->address == addr) - ret = VM_FAULT_NOPAGE; + if (!pte_none(vmf->pte[count])) + goto skip; - ref_count++; - set_pte_range(vmf, folio, page, 1, addr); - } while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages); + count++; + continue; +skip: + if (count) { + set_pte_range(vmf, folio, page, count, addr); + folio_ref_add(folio, count); + if (in_range(vmf->address, addr, count)) + ret = VM_FAULT_NOPAGE; + } - /* Restore the vmf->pte */ - vmf->pte -= nr_pages; + count++; + page += count; + vmf->pte += count; + addr += count * PAGE_SIZE; + count = 0; + } while (--nr_pages > 0); + + if (count) { + set_pte_range(vmf, folio, page, count, addr); + folio_ref_add(folio, count); + if (in_range(vmf->address, addr, count)) + ret = VM_FAULT_NOPAGE; + } - folio_ref_add(folio, ref_count); + vmf->pte = old_ptep; WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret; From patchwork Mon Jul 10 20:43:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307616 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 AC47FEB64D9 for ; Mon, 10 Jul 2023 20:44:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3504B8E0011; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F1158E0012; Mon, 10 Jul 2023 16:43:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D48918E000F; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9A9E98E000B for ; Mon, 10 Jul 2023 16:43:49 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 751F5C0263 for ; Mon, 10 Jul 2023 20:43:49 +0000 (UTC) X-FDA: 80996878578.02.F7B76BD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id CEBF4140010 for ; Mon, 10 Jul 2023 20:43:47 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=TyH0uCOA; 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=1689021827; a=rsa-sha256; cv=none; b=UVIuT4FkO2EbueBDGUUPzGGBvNFquICJZn9fTQRyjA1WmgT/dba7KKd/RUHb34taybsa+Z izvre6cwLpEeTD94G4zgkdYJbgBav/HKhICS6v/GzAKMgZqQiZaU+jSyXXABfkUHLNFMw0 v8gAwrYsS2ccCRIr0trZf+5sjZL4rww= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=TyH0uCOA; 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=1689021827; 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=nV5u7fUN7eLvvulKehuO2ZLa6X1ni8Kq3NCH3wI1W68=; b=ri1acMx+pwWwPuZM5BMB33RyPhna3MDi4KrN9y7J8DywTN2Errwz1PoOPl3K5Q+tXY5/aQ yd/54lMaQakhkHH1FC/Sixevrd2DMXTur3dYWkdMFY4gP4l2EQ9pGWXVit+EItaKicsaEs ylRpV1eDgf8Twyi8LmZ0VLBga/2baYI= 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=nV5u7fUN7eLvvulKehuO2ZLa6X1ni8Kq3NCH3wI1W68=; b=TyH0uCOAc3cacwsNtSZ03toNxz /ldDgYNddIyTOMMCZ1doy4k1qRn3NKk9gaueXlr9Q9ZVwH7d6MVaJwERahiAgCAgQAxDi5JRsVFDi 3eHBvfR1ifNIth5VmyFLKtzah2dSw0acjuFg5RowKxVCVLH2xhcDXdP5tmz+HHmuLnfag6TRgXq0C dDUGPZDTEpllcYWbCHppyfSaiB6v5Mq+VWBJB8++zjxej6Zzy2RAjB9w/UOfYIH27C4iZJqdMPgje lL8zXH5n6a9ozIhoQ12ZP4f/qyLyI35Z5owqmkGKE52ljgsHGgjeLRIaU1mxeXq43+5KR7nDuWuP4 DjHkWKSA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjV-00Euru-MR; Mon, 10 Jul 2023 20:43:45 +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 Subject: [PATCH v5 38/38] mm: Call update_mmu_cache_range() in more page fault handling paths Date: Mon, 10 Jul 2023 21:43:39 +0100 Message-Id: <20230710204339.3554919-39-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CEBF4140010 X-Stat-Signature: 5kjemgpwctdfm5d9151qwh41u4z6tduu X-HE-Tag: 1689021827-149359 X-HE-Meta: U2FsdGVkX1/GTOy02sLhM9GlGmkmiuadI71HUc9vRB/03c+5jq2EXMOhkBZAFIIBC+0urBuyk+RNNA18asK2FzgoO0I6+NsNUl7QfhlvkuB1jhYUxgOAVVXqdiS4fSD5+awh4LsYjUEBu08/bBkkrcouD2yYQwzbFMXcTIWQMNJagTSUT/0t4Yd8IsCd+EyIAwc/gb2kzwyHKy7/pPDSw0P72njqyfRnfUBXS+EpkWPYYIu07HKOtEQa5ZDg1650vpH8KQvPj0DTR3+KarSLQX7CKGpfuSB4Vnvg8usroYqOHvDDx/LUpabdf0YmbpQtxqD8LA941ONhWyPcK7GbIfZO18ubx4hE9GmkUwDQSBMf9bGtFElRivmhCAa116KRiANPIYJIv3r2V8Vod127RertgIDMvJ4RdmfRsyXFb3qd6TP+UYuAzBkT7Np1NgHR4TAsax7bAHPVeovV9yOmtItL161aB4Qw1EFiJYCvq7AqGpH1wdxTnVe+PuoRfXi8olaMrMGI2Q6OdQEZeoHsi7sSMuk6m0zIcukddnfD6z76WJtf1mKLMWTPgQFvougq59p1SXs/CkXOW2C6uyGUE1H2GFe7C7J48MtTdneCbil3whZm5sEsv/moVaMiqSDM/qbSKcOBDopSKtbEByt+XugNGFn//1+38FP3Zb/6f29yDkAj2smTnh+YgpSUSGlNNCXqFc1lCwLQ/N3RaUbNYdDn8+oHljKR+8gVoH0naF8GPCNUpA55MKTb0SlNCPZGweFWi5UU/ooymfdPEdObAl6Xs9iP9uU31YTDpttB/5ZAhvNjTneuFN6RJ96djTc33Hawk6z+7jPFnDy7yLRc+tRuCpU1iJJWFsHEldhD/09KftuZNXNwMlfFAhAr3BNTEtoGX0/3nzP2l5xuu93yDRc/2cBfYRoeoZ2RiCGtkSV4NBkoWvmWj7fe6+bQ55YkLxMOTo7r94l/dWqYQJ3 u3OElg+N o1TKNm6yHVYKgvh51h+FcAPl/CnswaOQ3lKMicHUeItFnA6e42pjtzhaC0GjI6L4XYowrT9cZWyUA5s1Ps/H+smnR8E4iW92d05BW2tVYxJJM/2SEWSEcg9hY+On1i9IJnqziJxpTLe0zqTRSnpZgXfhMh0gWxDj2h15JUqF3YYepJgaL0rAyBorKaG3kdDAPDK2I377Kp/x+NC7fPURZ5At6ZPbAuUaPTsIR 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: Pass the vm_fault to the architecture to help it make smarter decisions about which PTEs to insert into the TLB. Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index e712e5fda56e..8dc54e412269 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2867,7 +2867,7 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, entry = pte_mkyoung(vmf->orig_pte); if (ptep_set_access_flags(vma, addr, vmf->pte, entry, 0)) - update_mmu_cache(vma, addr, vmf->pte); + update_mmu_cache_range(vmf, vma, addr, vmf->pte, 1); } /* @@ -3045,7 +3045,7 @@ static inline void wp_page_reuse(struct vm_fault *vmf) entry = pte_mkyoung(vmf->orig_pte); entry = maybe_mkwrite(pte_mkdirty(entry), vma); if (ptep_set_access_flags(vma, vmf->address, vmf->pte, entry, 1)) - update_mmu_cache(vma, vmf->address, vmf->pte); + update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); pte_unmap_unlock(vmf->pte, vmf->ptl); count_vm_event(PGREUSE); } @@ -3169,7 +3169,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) */ BUG_ON(unshare && pte_write(entry)); set_pte_at_notify(mm, vmf->address, vmf->pte, entry); - update_mmu_cache(vma, vmf->address, vmf->pte); + update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); if (old_folio) { /* * Only after switching the pte to the new page may @@ -4039,7 +4039,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) } /* No need to invalidate - it was non-present before */ - update_mmu_cache(vma, vmf->address, vmf->pte); + update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); unlock: if (vmf->pte) pte_unmap_unlock(vmf->pte, vmf->ptl); @@ -4163,7 +4163,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) set_pte_at(vma->vm_mm, vmf->address, vmf->pte, entry); /* No need to invalidate - it was non-present before */ - update_mmu_cache(vma, vmf->address, vmf->pte); + update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); unlock: if (vmf->pte) pte_unmap_unlock(vmf->pte, vmf->ptl); @@ -4837,7 +4837,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) if (writable) pte = pte_mkwrite(pte); ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); - update_mmu_cache(vma, vmf->address, vmf->pte); + update_mmu_cache_range(vmf, vma, vmf->address, vmf->pte, 1); pte_unmap_unlock(vmf->pte, vmf->ptl); goto out; } @@ -4986,7 +4986,8 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) entry = pte_mkyoung(entry); if (ptep_set_access_flags(vmf->vma, vmf->address, vmf->pte, entry, vmf->flags & FAULT_FLAG_WRITE)) { - update_mmu_cache(vmf->vma, vmf->address, vmf->pte); + update_mmu_cache_range(vmf, vmf->vma, vmf->address, + vmf->pte, 1); } else { /* Skip spurious TLB flush for retried page fault */ if (vmf->flags & FAULT_FLAG_TRIED)