From patchwork Fri Apr 14 13:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13211464 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 62E38C77B76 for ; Fri, 14 Apr 2023 13:03:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8D7C280003; Fri, 14 Apr 2023 09:03:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1749280001; Fri, 14 Apr 2023 09:03:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A42CF280003; Fri, 14 Apr 2023 09:03:36 -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 7A790280001 for ; Fri, 14 Apr 2023 09:03:36 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5A0EC1C5D44 for ; Fri, 14 Apr 2023 13:03:36 +0000 (UTC) X-FDA: 80680013232.25.82DD15F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id E32161C002F for ; Fri, 14 Apr 2023 13:03:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681477414; a=rsa-sha256; cv=none; b=w00nxDLcUBAz0eMpDne0JIODxQlroGOGLJplhXyq2lC78yZ9xmb4Pey2phtYvVcRePnov9 Q9Q8hhaSek6O1vGJa3VvTRe9NZpJuSaN5LWnDMw9rRL9zBGSUOz3ZDIuzf49NzG1lBHJyL nFtJFKL/s5uPZ46B4WvvVkGNdKhTh/Q= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681477414; 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; bh=32I9Jpfj7syNSZBFmF24OmcYCe67NGKuiEzjjsNeU1Q=; b=u5wLmWyKaXu0gv3EO2IM1oDzjKCukGuWkmZQWU8DmOARgr0U56MhqgN8riogIj8iUChLDN sTZWr33+7ir3K7Bqhm1NAY9A9yo01eCPFIyrNvXWIes076eiTiVlQ0onL5fItE/Sw0O8FI wr7a2/3byXeJGXpiVs7t0v6LnycR8TQ= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1C74816F8; Fri, 14 Apr 2023 06:04:18 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 980903F6C4; Fri, 14 Apr 2023 06:03:32 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao , "Yin, Fengwei" Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v2 PATCH 12/17] mm: ptep_clear_flush_range_notify() macro for batch operation Date: Fri, 14 Apr 2023 14:02:58 +0100 Message-Id: <20230414130303.2345383-13-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414130303.2345383-1-ryan.roberts@arm.com> References: <20230414130303.2345383-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: E32161C002F X-Rspamd-Server: rspam01 X-Stat-Signature: x9goyz5bedaz3z1atfxiuhb88jhtmjuo X-HE-Tag: 1681477413-789933 X-HE-Meta: U2FsdGVkX18mPO2kEJnjnUZZtjiMd86IIY50UVG15gpFNokMshDG/VMgSajE8UPqcGe+fqU1JGVVBhOCUkNtqo0oGG7k0pH2u/y80BZ+UAFyI4Nx4zlv2tv/Z12Si41bE9jFeoG2HnF0msXQfA4lP55wWeCNhiveWh4y0cpX1kxqWG7ckFQAlqLY5EG8GejLP1pqjfoyxfL8WoFB8y/xA9oO1QNtDZU3xYUHsEmcC+E3eCS4fph71kQg7xQuBTUWhlAEmAht3Q7ozA+O7mUf7nng+/NMMuLvYj+WY9+ctees9fL5Jzngredkvo9ZDvx8Kon6L/mT7ehT7RJoNb1rwWfUwu9f/BnNUDB6OpH7hbLbIq3BUENaq/jbw2Yt7Y5C5IiwFrP/2ObvUzkT9TgcwuihFGlzh+GxLhmuf+WsKSPhh64bDnJhYnYfGKMtYhU/bQgR1bzx/h1rrNi+dkaWIi/51KURYxYwBCw0rFIUo6RLnbMszcugJ7cLK29Gvmd5lxDX0LEuqfwriliGc6PE72HHJRFc0GExs7Kcb+NKMv62TG6s13at9uja0b86KkBb8+mjxpKj1fzWgNnDxJlqLnsWUyImRIxoILPEhK2QEgwibJh7iBxe9rq17LgBfU+8Rj7/vUo0lKfeySGrQasshVFyt7s9Y9DS7XX2WvK17cg2iJOU7ABWFWUVdM6KaB1XhCKBXTqpmiL5O0QY8KxHNcNe0MD113zgeFgZIhd9f7KLAHgSxs9mF63wyHFuzCf6iaPjfpQZqxhTWF37/IS/TqawOsOd56ahbF8AxmhB1vdKYG48gZwfgyAhB4usjeOz6ooaqA8BSjWMe/KbeuhVoRkNnm/yYpSiw3FgyOfpUC0eIeJphMCrFU47JpWPsx2ihMDeA65IjKX8smMXJNdP7FXcyoq0zBX0pVfechTsqlsGiDSLHqvlSXWF8Eg8zE7v3QKwt6UAMWTeNq34XZL bnNBdAE/ uT5ofsdZhJIhDR+FFxRFqxi5WjqeEBiXvT8maO6ATfyay7sVU8Ix1b/GdqgUQ6heFosn9i3pQ1wis5iLJ/SzOqdWpG+fDEQEJSpyekZ1zxtFhhsEXlOFA8+b9VjBPN0nUV9UNibWpQL/1pL4NxdvuZ5XmUgMDaJb0BOetaxDoOFkgYTRzfzhVJx0CLv6wRYs6kwo3/YFxkD5uprLEFil3gK520y9W6jAnqnwN 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: We will soon add support for CoWing large anonymous folios, so create a ranged version of the ptep_clear_flush_notify() macro in preparation for that. It is able call mmu_notifier_invalidate_range() once for the entire range, but still calls ptep_clear_flush() per page since there is no arch support for a batched version of this API yet. No functional change intended. Signed-off-by: Ryan Roberts --- include/linux/mmu_notifier.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) -- 2.25.1 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 64a3e051c3c4..527aa89959b4 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -595,6 +595,24 @@ static inline void mmu_notifier_range_init_owner( ___pte; \ }) +#define ptep_clear_flush_range_notify(__vma, __address, __ptep, __nr) \ +({ \ + struct vm_area_struct *___vma = (__vma); \ + unsigned long ___addr = (__address) & PAGE_MASK; \ + pte_t *___ptep = (__ptep); \ + int ___nr = (__nr); \ + struct mm_struct *___mm = ___vma->vm_mm; \ + int ___i; \ + \ + for (___i = 0; ___i < ___nr; ___i++) \ + ptep_clear_flush(___vma, \ + ___addr + (___i << PAGE_SHIFT), \ + ___ptep + ___i); \ + \ + mmu_notifier_invalidate_range(___mm, ___addr, \ + ___addr + (___nr << PAGE_SHIFT)); \ +}) + #define pmdp_huge_clear_flush_notify(__vma, __haddr, __pmd) \ ({ \ unsigned long ___haddr = __haddr & HPAGE_PMD_MASK; \ @@ -736,6 +754,19 @@ static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm) #define ptep_clear_young_notify ptep_test_and_clear_young #define pmdp_clear_young_notify pmdp_test_and_clear_young #define ptep_clear_flush_notify ptep_clear_flush +#define ptep_clear_flush_range_notify(__vma, __address, __ptep, __nr) \ +({ \ + struct vm_area_struct *___vma = (__vma); \ + unsigned long ___addr = (__address) & PAGE_MASK; \ + pte_t *___ptep = (__ptep); \ + int ___nr = (__nr); \ + int ___i; \ + \ + for (___i = 0; ___i < ___nr; ___i++) \ + ptep_clear_flush(___vma, \ + ___addr + (___i << PAGE_SHIFT), \ + ___ptep + ___i); \ +}) #define pmdp_huge_clear_flush_notify pmdp_huge_clear_flush #define pudp_huge_clear_flush_notify pudp_huge_clear_flush #define set_pte_at_notify set_pte_at