Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp881742rdb; Tue, 30 Jan 2024 01:04:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgncZ1Db2S2n4nAI7JPi4VxzHoFroEUF249Ahn5pgedXKTcBam13SGrgi20N9BZdUR+W6a X-Received: by 2002:a17:906:298d:b0:a31:7aca:a429 with SMTP id x13-20020a170906298d00b00a317acaa429mr5947670eje.4.1706605471685; Tue, 30 Jan 2024 01:04:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706605471; cv=pass; d=google.com; s=arc-20160816; b=vLyD6URXy3Ig5Lu3xm4JqE64CI1Q2pQYCA8RhRVAT6ksdTrXech8gZNGSSpzI+dRtn K+VZAM8Zy7Iwx0PLp6Oc+EGCtfNk9RHQHkKcTrfE1vHIHp0xE3AsbKZO5HS4RcgB+EEW wIrGDyLRNZYV6uLLHjuLlaD1FWajF1dDr+JVoR2WETJ724Q6VgdEyyZMP+jIByD83zRt rv+XlIJnvBEoY9xFGkNZPim8gVwdqfwn59H9MMAdaNSHbaEB+ODWFb4EpobG9amH6sX+ R+tqtPit2vo7fbKsLcS+gqiqu+BsTdgbpYq0QkIUJzHp2UIL6U5pToTgaMQoYKAT1pBW DQEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=eF8XcVDoh8qeGnwwo+1/Vlp78kwMrQNdgnyzGZIrGVQ=; fh=VVjuivqjwQTGD3KqdtfMHM2u5ZCac4G8eN8eVGHfbQw=; b=pVZL/dnjUg3KCg1JdERQaTfVs7rppu+HD+RaLHIFC4kXQhHiC+O9C9YoCnuZ1gaSZw V0P9p20rb91EaDxH/fbfZ1LSNRWa8vKKJAI2xs/8YPU4QyvOr6CI1iPXejypxny9llC5 aioSzXPy14BJ0Szl+fjaZeEbIIeXGL7JngUaNz7cUjBqAQVD2y+6z+rxLgo7LQ4OPPw1 Z6Io+exK258NjIdDEUomvKkC3Gi02pjt8LMOyrUFaWpoqlIyPGYGjS1XNslZqeRGZm3A DLVh3oVpPE0ilWtZfb5ce1T8Gheybqg7X1PWRZ39AvQN54Yg9MoJGb3UwuSs0GqkmF5f EmGw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-44197-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44197-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v27-20020a17090606db00b00a35dbeaac35si1357622ejb.853.2024.01.30.01.04.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 01:04:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44197-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-44197-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44197-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 68C5C1F2B199 for ; Tue, 30 Jan 2024 09:04:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCE6760876; Tue, 30 Jan 2024 09:03:43 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66EB6605CF; Tue, 30 Jan 2024 09:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706605423; cv=none; b=ab5W//+uVBz54c99z6K7Qi1CBImG+5iUfx1ch4gjaWzYdP+4aWSdzveC8jIwIlhTL+mnxi+WDSj3ttc2nJHDG3QgBDQNfzBK62qnF8yE/PG9yCw5KUWm2ssKvVV98b+Vkt4lK53khHemelqlOVukVBG5WW5MDHwz95Sd8qWD11M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706605423; c=relaxed/simple; bh=nBml0oiJ6D0UQzvGSde6AYnzRvh5VcdeBvdq6qBUeYg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=h+vhLJLTyYKkdJiMLfrDZv4avSsWiCOirj9gcSQUmHNJVZMlEJmbAtcbHlcXQ5L3ftaUc058yvRozBloYHld3MPkfx+IozyQMLOKUSQbBZ8BwpJ0fQGqeaB0Cya3l9MW9+JO5xgntkE63aHL+PtO6gLbAVJK0ZF+R75RjeLyN6c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 7DCEA139F; Tue, 30 Jan 2024 01:04:24 -0800 (PST) Received: from [10.57.79.54] (unknown [10.57.79.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA66B3F738; Tue, 30 Jan 2024 01:03:37 -0800 (PST) Message-ID: <075975db-a59b-483a-95d7-0990442ebe6f@arm.com> Date: Tue, 30 Jan 2024 09:03:36 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 6/9] mm/mmu_gather: define ENCODED_PAGE_FLAG_DELAY_RMAP Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Catalin Marinas , 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 References: <20240129143221.263763-1-david@redhat.com> <20240129143221.263763-7-david@redhat.com> From: Ryan Roberts In-Reply-To: <20240129143221.263763-7-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 29/01/2024 14:32, David Hildenbrand wrote: > 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. > > Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts > --- > 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;