From mboxrd@z Thu Jan 1 00:00:00 1970 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 1ABA6C433EF for ; Mon, 9 May 2022 11:18:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EE4A6B0071; Mon, 9 May 2022 07:18:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 876196B0073; Mon, 9 May 2022 07:18:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 763F46B0074; Mon, 9 May 2022 07:18:21 -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 68BFA6B0071 for ; Mon, 9 May 2022 07:18:21 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 2FEA7120E37 for ; Mon, 9 May 2022 11:18:21 +0000 (UTC) X-FDA: 79445956002.25.54030D9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id E84C9C00A1 for ; Mon, 9 May 2022 11:18:18 +0000 (UTC) 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 84A161480; Mon, 9 May 2022 04:18:19 -0700 (PDT) Received: from [10.163.34.187] (unknown [10.163.34.187]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CDBF3F66F; Mon, 9 May 2022 04:18:15 -0700 (PDT) Message-ID: <84b579b2-7528-3d3c-02e4-29586791432f@arm.com> Date: Mon, 9 May 2022 16:49:25 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: VM_BUG_ON(!tlb->end) on munmap() with CONT hugetlb pages Content-Language: en-US To: Will Deacon , Steve Capper Cc: Catalin Marinas , David Hildenbrand , Mike Kravetz , "linux-mm@kvack.org" , "Aneesh Kumar K . V" , Peter Zijlstra , nd@arm.com References: <811c5c8e-b3a2-85d2-049c-717f17c3a03a@redhat.com> <993f1258-6550-e5d7-1e6f-72e2a24b60f0@oracle.com> <3ba18a1d-d5d8-558f-9576-8119c210e98a@oracle.com> <881efece-c362-af41-4dea-77db71ec9928@arm.com> <20220506124909.GA22892@willie-the-truck> From: Anshuman Khandual In-Reply-To: <20220506124909.GA22892@willie-the-truck> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E84C9C00A1 X-Stat-Signature: zjpr6kh37mynca4eeogrgbeywh9ojkuq X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com X-HE-Tag: 1652095098-659076 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: On 5/6/22 18:19, Will Deacon wrote: > On Wed, Mar 23, 2022 at 04:34:26PM +0000, Steve Capper wrote: >> >> >> On 23/03/2022 16:21, Catalin Marinas wrote: >>> On Wed, Mar 23, 2022 at 11:51:25AM +0000, Steve Capper wrote: >>>> On 22/03/2022 17:56, Catalin Marinas wrote: >>>>> At a quick look, we wouldn't have a problem with missing TLB flushing >>>>> since huge_ptep_get_and_clear() does this for contiguous PTEs. Not sure >>>>> why it needs this though, Steve added it in commit d8bdcff28764. I think >>>>> we can defer this flushing to tlb_remove_page_size(). >>>> >>>> The TLB flush in huge_ptep_get_and_clear() was added because it was called >>>> by hugetlb_change_protection() without any flushing. The concern was that, >>>> without the flush, it would be possible to get to different views of the >>>> same contiguous huge page. (Being contiguous they were not changed en masse >>>> atomically). >>> >>> Maybe the code paths have been changed since but looking at >>> hugetlb_change_protection(), we have huge_ptep_modify_prot_start() >>> calling huge_ptep_get_and_clear() which AFAICT only needs to clear the >>> ptes. huge_ptep_modify_prot_commit() calls set_huge_pte_at() which does >>> another pte clearing + TLBI (clear_flush()) before setting the new ptes. >>> So we do the pte clearing and TLBI twice already. >>> >> >> Thanks, yeah indeed the code has changed and the flush should be removed >> from the arm64 huge_ptep_get_and_clear. > > Did anybody send a patch for this? Planning to send a patch which drops TLB flushing from get_clear_flush() and also renames it as required. Something like this but just slightly tested. diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index cbace1c9e137..acdaeb3b9356 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -166,7 +166,7 @@ static inline int num_contig_ptes(unsigned long size, size_t *pgsize) * * This helper performs the break step. */ -static pte_t get_clear_flush(struct mm_struct *mm, +static pte_t get_clear_contig(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned long pgsize, @@ -190,11 +190,6 @@ static pte_t get_clear_flush(struct mm_struct *mm, if (pte_young(pte)) orig_pte = pte_mkyoung(orig_pte); } - - if (valid) { - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - flush_tlb_range(&vma, saddr, addr); - } return orig_pte; } @@ -392,7 +387,7 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm, ncontig = find_num_contig(mm, addr, ptep, &pgsize); - return get_clear_flush(mm, addr, ptep, pgsize, ncontig); + return get_clear_contig(mm, addr, ptep, pgsize, ncontig); } /* @@ -443,7 +438,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, if (!__cont_access_flags_changed(ptep, pte, ncontig)) return 0; - orig_pte = get_clear_flush(vma->vm_mm, addr, ptep, pgsize, ncontig); + orig_pte = get_clear_contig(vma->vm_mm, addr, ptep, pgsize, ncontig); /* Make sure we don't lose the dirty or young state */ if (pte_dirty(orig_pte)) @@ -476,7 +471,7 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm, ncontig = find_num_contig(mm, addr, ptep, &pgsize); dpfn = pgsize >> PAGE_SHIFT; - pte = get_clear_flush(mm, addr, ptep, pgsize, ncontig); + pte = get_clear_contig(mm, addr, ptep, pgsize, ncontig); pte = pte_wrprotect(pte); hugeprot = pte_pgprot(pte);