From patchwork Wed Feb 14 20:44:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13557009 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 89650C48BC1 for ; Wed, 14 Feb 2024 20:45:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B53B6B00AD; Wed, 14 Feb 2024 15:45:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 163186B00AE; Wed, 14 Feb 2024 15:45:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAA096B00B0; Wed, 14 Feb 2024 15:45:11 -0500 (EST) 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 D4B2F6B00AD for ; Wed, 14 Feb 2024 15:45:11 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A8083160E1F for ; Wed, 14 Feb 2024 20:45:11 +0000 (UTC) X-FDA: 81791589222.29.CD33E12 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 040D340013 for ; Wed, 14 Feb 2024 20:45:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dWS7Tlj5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707943510; 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=BfteBvWtn9YL0u+ZWWzLkAZQ9TqgPhMIROF4I2AA+84=; b=erg2XXtNkAqoFrjEKeg6lJ3hI8QVyl3JSYB0AzuhN9lA3NE01d7lADvPizNDX04FtaYON9 mMmB+36/vCwkOLz8zmxr8jrcGEp6+kQMgy9bzBzPs/WHktdKNtRc4mEYMu/mz5hdjzRmSf YgwhG3cdMNlxlPlQ/mrN13xtmPZIvlU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dWS7Tlj5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707943510; a=rsa-sha256; cv=none; b=rxrv33g2PK9MpcF1dB/kTfE7NWMRapP79Z3e3zBopxQxR5qztR77UK0EH0Vwqf9FSaQubQ KfYBVafnOYdNMhV5HTFGhsBbgAZV0CkCUcdTEtnLo5N7Mn/TWSRq+BVHDehAyouR9HpcZO Zi7m9Nz5I3v5hG2972ckDS0CPYfxQMw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707943509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BfteBvWtn9YL0u+ZWWzLkAZQ9TqgPhMIROF4I2AA+84=; b=dWS7Tlj5hvo++IKBwEcAZX8N1kyu5MFiYG5LceV724qhzHlhlWnCbuVYOcjmSFNc3hjRAH NvInRkO6BO9Jkw7pznPvqg7Wc8TXzrt/R8/GGIlh/4WSOSJJ0LwueRiKvzE0v9HgAg0f5v X682/Nf1TSZAb4roDM0/bce9MOD6bOs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-502-FFKMi1htPsyeY2_wWYIuqQ-1; Wed, 14 Feb 2024 15:45:06 -0500 X-MC-Unique: FFKMi1htPsyeY2_wWYIuqQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 768353C29A67; Wed, 14 Feb 2024 20:45:04 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id C376E1C060B1; Wed, 14 Feb 2024 20:45:00 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Ryan Roberts , Catalin Marinas , Yin Fengwei , Michal Hocko , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org Subject: [PATCH v3 06/10] mm/mmu_gather: define ENCODED_PAGE_FLAG_DELAY_RMAP Date: Wed, 14 Feb 2024 21:44:31 +0100 Message-ID: <20240214204435.167852-7-david@redhat.com> In-Reply-To: <20240214204435.167852-1-david@redhat.com> References: <20240214204435.167852-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Queue-Id: 040D340013 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: jk13gg7ju1t38cg85jc67nrr7jbi54gw X-HE-Tag: 1707943509-590703 X-HE-Meta: U2FsdGVkX1/QUf4Hcg02Nk7LLN35GKpJT+D34hrJzGBO0idkKI3SEV605s7ORVAxOS8nP9HkAokj1c2H2UknSF/rIvhE7y7icxLULdq0twGjDF7fbJce4Y1ClQ34HkVwkyGiy25Dto1IqVEoxR62R3LcFxU+hjkC0U2w8n4hgMiUoPqDVGlBpb54bKkqUbpwaXfWzEssFEZueHtKjRMCB53Cv1GCGUD2msW3SdDXTgz79cVIg/3jyXiOQ8sD4FF0NJPgP/0EEShINPT29uO980B3uq6g1ojiajytQogqpV9Ao6WNl1tabM8QugxpbaYghWYCqZNYzdADbQmxAS6Q6+kh+jYL2NcciIX66m1QB57hY708prR9GUOB3iLMSmksM5ojsy6I88TDSymOcjM0kfBmQmgwxRerKNRd1TtAd3aw8RAQdUfelHeIrdN7cxzstLMpqjfT3sv1qzPpPhLOWSuKeUiKC+c2+v6B31ZOELkkZLJacz/aVmhqMwVmnUHPfQlYLA3GvLb5AfjF8vOXYKyRvfLZoFasIqiN4hIhh/n7B6HbiwxhcGqja8JILQLmtbynT+QPswrXZcIYQk0wgzz2yeW9cNIdacJ1Ih/us1JDbsqPpOupVPf1+mpY5Xwt5p2DeW3cJPQdp/ZszOBzwzgZDzpfFoTWfr7XBcFxqxCAE5eQ5ZOYTJZ42qZw2VUyIpRn5O7y17BmAinP4lRnFINYG/vugmFgDzynjHZo81AL6FzdQnewEdx6Tf/wuWiK2wE9p5ir5OQ4NikZ4XverbN+0VmDwXHmzYvRf0C8iytz/ujr3Qkw6J49fMJl89WNT+r/8OrzX903FRMzii4B+4epwjyx7160aJC4vzf+O+1rdrdSm2h//OLdzlvWmao1VWfkiejENF9z+mNHJW5Bf+dNxJYSvdfAIZfsGznpTnsL/23kdx9AI9KJOW4tkbGKCYFToilPxioZVcFhSJV rjCwi5eZ V75Yd+OPigW5uRRxmmDljqZiZvPXcyYkytHRnRH1c+p5irqfAYyUn72RgcghbsiBqg2EvgYtLTnDnxjd2flr5RuNcCRRWfCgjRyMArRVdo4l/h8ElM8SQ/NVnmzCmX4w9W8k+2rqVbb4c1JSOzQLew7ShT9vfl4c/SHcgoNQe4Rs7keV66LoDtsUt4a6CJlwxczLpa5Xvb+BYtMw7lsOQvhRUSJ5nMhhfI6/u8ZHVqq/23sta6NbDhRjwNEYAL/HYzVB+pzI2CPheLKAsq6RJfUtAMg== 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: List-Subscribe: List-Unsubscribe: Nowadays, encoded pages are only used in mmu_gather handling. Let's update the documentation, and define ENCODED_PAGE_BIT_DELAY_RMAP. While at it, rename ENCODE_PAGE_BITS to ENCODED_PAGE_BITS. If encoded page pointers would ever be used in other context again, we'd likely want to change the defines to reflect their context (e.g., ENCODED_PAGE_FLAG_MMU_GATHER_DELAY_RMAP). For now, let's keep it simple. This is a preparation for using the remaining spare bit to indicate that the next item in an array of encoded pages is a "nr_pages" argument and not an encoded page. Reviewed-by: Ryan Roberts Signed-off-by: David Hildenbrand --- include/linux/mm_types.h | 17 +++++++++++------ mm/mmu_gather.c | 5 +++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 8b611e13153e..1b89eec0d6df 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -210,8 +210,8 @@ struct page { * * An 'encoded_page' pointer is a pointer to a regular 'struct page', but * with the low bits of the pointer indicating extra context-dependent - * information. Not super-common, but happens in mmu_gather and mlock - * handling, and this acts as a type system check on that use. + * information. Only used in mmu_gather handling, and this acts as a type + * system check on that use. * * We only really have two guaranteed bits in general, although you could * play with 'struct page' alignment (see CONFIG_HAVE_ALIGNED_STRUCT_PAGE) @@ -220,21 +220,26 @@ struct page { * Use the supplied helper functions to endcode/decode the pointer and bits. */ struct encoded_page; -#define ENCODE_PAGE_BITS 3ul + +#define ENCODED_PAGE_BITS 3ul + +/* Perform rmap removal after we have flushed the TLB. */ +#define ENCODED_PAGE_BIT_DELAY_RMAP 1ul + static __always_inline struct encoded_page *encode_page(struct page *page, unsigned long flags) { - BUILD_BUG_ON(flags > ENCODE_PAGE_BITS); + BUILD_BUG_ON(flags > ENCODED_PAGE_BITS); return (struct encoded_page *)(flags | (unsigned long)page); } static inline unsigned long encoded_page_flags(struct encoded_page *page) { - return ENCODE_PAGE_BITS & (unsigned long)page; + return ENCODED_PAGE_BITS & (unsigned long)page; } static inline struct page *encoded_page_ptr(struct encoded_page *page) { - return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page); + return (struct page *)(~ENCODED_PAGE_BITS & (unsigned long)page); } /* diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index ac733d81b112..6540c99c6758 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -53,7 +53,7 @@ static void tlb_flush_rmap_batch(struct mmu_gather_batch *batch, struct vm_area_ for (int i = 0; i < batch->nr; i++) { struct encoded_page *enc = batch->encoded_pages[i]; - if (encoded_page_flags(enc)) { + if (encoded_page_flags(enc) & ENCODED_PAGE_BIT_DELAY_RMAP) { struct page *page = encoded_page_ptr(enc); folio_remove_rmap_pte(page_folio(page), page, vma); } @@ -119,6 +119,7 @@ static void tlb_batch_list_free(struct mmu_gather *tlb) bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, bool delay_rmap, int page_size) { + int flags = delay_rmap ? ENCODED_PAGE_BIT_DELAY_RMAP : 0; struct mmu_gather_batch *batch; VM_BUG_ON(!tlb->end); @@ -132,7 +133,7 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, * Add the page and check if we are full. If so * force a flush. */ - batch->encoded_pages[batch->nr++] = encode_page(page, delay_rmap); + batch->encoded_pages[batch->nr++] = encode_page(page, flags); if (batch->nr == batch->max) { if (!tlb_next_batch(tlb)) return true;