Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp362707lqo; Fri, 10 May 2024 02:05:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYRI3oeMN0kaXLxgVqUF1OdXxN42Oq6p/osWIOuYjB0Z42nhVEQ1xddGMU3xLPidjIsOi1w1r2X0NRQ2hO4jt9x+3A376d2gT7tx7AjA== X-Google-Smtp-Source: AGHT+IH9NJ4LbRRyiuz/dgj45LEb1+1hV40cumLHcgaiaah6Zo0ty4JFosmGgrIz7VVCkg+Y5Q2X X-Received: by 2002:aa7:c992:0:b0:572:b0a8:65fd with SMTP id 4fb4d7f45d1cf-573326eddfemr3752376a12.6.1715331947000; Fri, 10 May 2024 02:05:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715331946; cv=pass; d=google.com; s=arc-20160816; b=JRF3ckuKUvdbp8u/tG47eZp81A2Z7I3kM/Ho08MQb6QN8LQ0E9gcHaFqsGyAhNAwSH ZQcBxB0uhfRbYwlYR9Jj3BnV/RVC2zBFfuzgxhpVGHDLpTMsVcN+XVzHVM1To7wKhxag nRk0yd7e2fMCfr6m1vW93YbtIg018oNv2qViXsnI6ujiXmCcmQKrfm3kmN72OoT0cVFO +nG5oAPFvOyxFsbtHFGJNlAtB/RjIvv8WXllXGDd6o4l6BDXAKvSwUpRykj4hcbdjNAI Qokp+8AIBNSwOFRLM1XpADyJSYWZ9cuxKtCN3p1qe72s5sUhcrCkm6+gCLDhymiZdqKC ooPQ== 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=G83iPV+wQHOxowMpj1akcKwTDff3i5TU84YwdWeCLJg=; fh=wgfz8lZsO/dT8KxUaIScKewHAwhEMzEEg87pc4Q382A=; b=aWxM66wqPcXNKwbpCUrx4ZycBPtBSkySuYnFKCzlmkLw+bzsDct5TvfhmOPPeg+9KW ZBT481aONQGPXWbO4zqfOmaEZlePDE2nTiDV8pq1aF8dmXdKmb4YAQ5c/vqk8zj65FPL XTufuTiNxZOyXWsZgmxwkwLPsxCB0Jh1khSV10j5IUygisX+RHJudNuOtIhqdLngZAIT sXnGsTFcXPrnq2cqCS79QeeJLABhTK1k+ZBA8+veUbKRdI/4oLLes12mXGAOMwV6qsGm 5Mx/wjFFqWQEygCQaTigDDdVKLSrAnqm6A79IIUIGluTbQyUZnB2Ii7Pq0R9Btkm7LvR dQsA==; dara=google.com 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-175476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175476-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 4fb4d7f45d1cf-5733c2d547csi1859031a12.230.2024.05.10.02.05.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 02:05:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175476-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-175476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175476-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 B96CC1F22159 for ; Fri, 10 May 2024 09:05:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F3EB15FCF1; Fri, 10 May 2024 09:05:43 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3C0915F31F for ; Fri, 10 May 2024 09:05:39 +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=1715331943; cv=none; b=JoBB21FfDCF3pIHV5ZXq80pXSBH4papopJfQ0dEFe0lcNaMu3+55P8gLrYOhoohx4ekafO5uYPS/o8hGESAlfNPLwDB1JXODTPuUFN8QgBoKO39bSQrjZVOubprqtjzq5tuF3C4fhnuxkdUsYeMJBgYUprW+TZAed2ARnIPZyzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715331943; c=relaxed/simple; bh=i/NcnzjW+6NOTL/D83aSrla/ItONUS0hG37UNHK/HsE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rW9T6+dI51qlozcbqHTezNLhFIVA5jhlAEyte058eYfCyWR73xFcX2rT7rTCWgdcQ6fb/sF0yQ2WwDwEJjXupbrbWlXsHVjVpm0/QuTDsTgSU00S8Xb9yCDh6eH4jLGO3rCMEPEAEFkOPc5HZpOEPONsxlNt/8m9l4ymf7atzLY= 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 67B2B106F; Fri, 10 May 2024 02:06:02 -0700 (PDT) Received: from [10.57.65.1] (unknown [10.57.65.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E08003F762; Fri, 10 May 2024 02:05:34 -0700 (PDT) Message-ID: Date: Fri, 10 May 2024 10:05:33 +0100 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 v2 5/5] mm: Add update_mmu_tlb_range() Content-Language: en-GB To: Bang Li , akpm@linux-foundation.org, chenhuacai@kernel.org, tsbogend@alpha.franken.de, paul.walmsley@sifive.com, palmer@dabbelt.com, chris@zankel.net, jcmvbkbc@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, david@redhat.com, ioworker0@gmail.com, libang.linux@gmail.com References: <20240506155120.83105-1-libang.li@antgroup.com> <20240506155120.83105-6-libang.li@antgroup.com> From: Ryan Roberts In-Reply-To: <20240506155120.83105-6-libang.li@antgroup.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 06/05/2024 16:51, Bang Li wrote: > After the commit 19eaf44954df ("mm: thp: support allocation of anonymous > multi-size THP"), it may need to batch update tlb of an address range > through the update_mmu_tlb function. We can simplify this operation by > adding the update_mmu_tlb_range function, which may also reduce the > execution of some unnecessary code in some architectures. > > Signed-off-by: Bang Li > --- > include/linux/pgtable.h | 8 ++++++++ > mm/memory.c | 4 +--- > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index 18019f037bae..869bfe6054f1 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -737,6 +737,14 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma, > #define __HAVE_ARCH_UPDATE_MMU_TLB > #endif Given you are implementing update_mmu_tlb_range() in all the arches that currently override update_mmu_tlb() I wonder if it would be cleaner to remove update_mmu_tlb() from all those arches, and define generically, removing the ability for arches to override it: static inline void update_mmu_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { update_mmu_tlb_range(vma, address, ptep, 1); } > > +#ifndef __HAVE_ARCH_UPDATE_MMU_TLB_RANGE > +static inline void update_mmu_tlb_range(struct vm_area_struct *vma, > + unsigned long address, pte_t *ptep, unsigned int nr) > +{ > +} > +#define __HAVE_ARCH_UPDATE_MMU_TLB_RANGE > +#endif Then you could use the modern override scheme as Lance suggested and you won't have any confusion with __HAVE_ARCH_UPDATE_MMU_TLB because it won't exist anymore. > + > /* > * Some architectures may be able to avoid expensive synchronization > * primitives when modifications are made to PTE's which are already > diff --git a/mm/memory.c b/mm/memory.c > index eea6e4984eae..2d53e29cf76e 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4421,7 +4421,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > vm_fault_t ret = 0; > int nr_pages = 1; > pte_t entry; > - int i; > > /* File mapping without ->vm_ops ? */ > if (vma->vm_flags & VM_SHARED) > @@ -4491,8 +4490,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > update_mmu_tlb(vma, addr, vmf->pte); > goto release; > } else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) { > - for (i = 0; i < nr_pages; i++) > - update_mmu_tlb(vma, addr + PAGE_SIZE * i, vmf->pte + i); > + update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages); I certainly agree that this will be a useful helper to have. I expect there will be more users in future. > goto release; > } >