From patchwork Fri Mar 1 09:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13578215 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 21A8CC5475B for ; Fri, 1 Mar 2024 09:24:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A95126B00A5; Fri, 1 Mar 2024 04:24:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A45066B00A6; Fri, 1 Mar 2024 04:24:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E5D46B00A7; Fri, 1 Mar 2024 04:24:25 -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 79E036B00A5 for ; Fri, 1 Mar 2024 04:24:25 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 19D64803B4 for ; Fri, 1 Mar 2024 09:24:25 +0000 (UTC) X-FDA: 81847934490.06.583BD06 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by imf05.hostedemail.com (Postfix) with ESMTP id 2C85010000B for ; Fri, 1 Mar 2024 09:24:22 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Nz8b1kiB; dmarc=none; spf=pass (imf05.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709285063; 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=K12kuYfal65hYkuTm7CnsK9zS+VdU7mNn9HZDxR8IYY=; b=nfhznasb1dC4OUmpZuWAyNdYOIbvV9CWjV+299Ouur9ZC9OyrDQ9z1EYsJuwlxj9Pfti4P 10fZ7pxWPIaS1bcGoc00OZ9rBekcjasNcF3jgklibKig5WyZ6FHkmPD8bO3xqsQG2MCQN2 Cn3rrCbbGpGV8oKt4Ae7yXgNPzg+kVQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Nz8b1kiB; dmarc=none; spf=pass (imf05.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709285063; a=rsa-sha256; cv=none; b=rlTfVlxpbdEjtfIeLbbcsRQEzYxk7HcuflhOa4wajl31yR5clReRWvXJRjiUJWe2HixBcT z42lEIcJQgl22KSqrlkRBBDvvNHyWewbIw/x5tpzdboefdi1TMyapLC4YFpaAuxTSgDSZU rwUzOHys1TGx0hI5wiPxSh5Hw0xLxLY= Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d28464c554so22619191fa.3 for ; Fri, 01 Mar 2024 01:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709285061; x=1709889861; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K12kuYfal65hYkuTm7CnsK9zS+VdU7mNn9HZDxR8IYY=; b=Nz8b1kiBLOuqHUDiuvYIEM7dK8sk9ygb8t7HHJhxnkuBNqW3CCCepAnN1u6Pl+5CYG R6SHzaCqPlsCGSh0Ye3+p3+I/9hHAT0xT3+SQVLU8se4LA+K9CUTh+0k9/VSHH49wuuV OW5G8xAApPN8i/YO7wgknMTq0Tkdb1pQ2FC17WoFj/a9KnEejcwN7NSq1ou7ICz6tb5/ dE6kO+mFl7U5ullXorsKpbNQW+gl8UhxnGaitzcqtf74xsEjxhSFogpt2j4HWg8YUJDr jmPmDMKVOt57HXm3tdECcC58t/kIGgvoc/54fn1DOLn2cKTp6CyqqylPQUdvANrf4MAg j17g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709285061; x=1709889861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K12kuYfal65hYkuTm7CnsK9zS+VdU7mNn9HZDxR8IYY=; b=vJ5cMDGA4e1LcKOFYe393WH4uHlzjk3715qgVO2dj8sqCm/O5RrEYSFNIk2LQ1sdPE 3YXwbFI5FKFWXVEP4aTN4JNgqnmygYFjma+8zRETvJPd67TGQQGSEBJerS9mMTOVPB42 g44DrbvGzcd2PpxmX4P7vhWsUXMHF9vlV++FvX8EkBXFWdaZnLQBCn9Yt5o724yI03gb aMyXVK36y7y+xwqKyk8CPlYu4dkqm4D7Wm8V95TtN0B7BXZtvBJDdWCPx3sA/RlMe75i Nk5wdb5wEwfjdfS5aeH6Q324Gc62SoXau/yNaXdEOsK4Z61y0noDO9frmOsMtcUWdJel 6aBA== X-Forwarded-Encrypted: i=1; AJvYcCVwbVeOtnIW97XIlhj0L/qON5MvXblSON9QeJ9aOBPAvzFge4x7atHzJsMhQm9Rnlnwdhph0JP+cHzmTBlUwjRR2H8= X-Gm-Message-State: AOJu0YxFqC6BaYwb94plXwlJDxGwn1fHCe5uGvL+PxvsHhpAhB01OOCc PDDf9hzLAVTBE8kd3BNtx9kWCbkTrYxz+tD846A2X9gYyeQ4U07onC5O/y5LoII= X-Google-Smtp-Source: AGHT+IFt+kCs8abRI8MZlthQ5rKNhpeiYCQtIBul4mlcyfPmRwi1Z8kSKZm+NO/gjQvAypId4axWxw== X-Received: by 2002:a2e:9909:0:b0:2d2:92a2:9a84 with SMTP id v9-20020a2e9909000000b002d292a29a84mr731669lji.43.1709285061585; Fri, 01 Mar 2024 01:24:21 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id w15-20020a05600c474f00b00412ca1dc2e4sm649267wmo.7.2024.03.01.01.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:24:21 -0800 (PST) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Ryan Roberts , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH 9/9] mm: Use common huge_ptep_clear_flush() function for riscv/arm64 Date: Fri, 1 Mar 2024 10:14:55 +0100 Message-Id: <20240301091455.246686-10-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240301091455.246686-1-alexghiti@rivosinc.com> References: <20240301091455.246686-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2C85010000B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oepc6bf5t6d8udn3fccqquz7aroncosc X-HE-Tag: 1709285062-698138 X-HE-Meta: U2FsdGVkX1+gnvvBK1C3zCngrdTwBt1wRbrDnoziYJt0Er4yEAHgoogU3PgUDgXwaYCL4tBHDkbZ0GaokpUOZRFEnBYxgypfF2TAStbiG8dloBpTTfRU+3tBMFQJbxSSsHdxqdbmslIWpovtOT9gdD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IjiUOtUyCLASf7miCwmwYOwlEpThNwwzNlIJoVXWE+TDbmkREGsg2+qXhKCzymY5l36q+JjWPJEZ91DPUyB5HzR66J3st5Lgc3erzNHupgi+HDvz7CQpicL+ujh5J0zO26dM9zYS9MD0YSJjf+Wue4m068nNdTMzoupwaCYa9Myf95tXaehj6AQMqAQ1P461hDM9I/5z1to7XYF1BvaKrb1gEw2DZa3Y7z+YFFUTS6/eRkShUThlImRWdDLko7aOVR6t0hg== 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: After some adjustments, both architectures have the same implementation so move it to the generic code. Signed-off-by: Alexandre Ghiti --- arch/arm64/mm/hugetlbpage.c | 61 ------------------------------------- arch/riscv/mm/hugetlbpage.c | 51 ------------------------------- mm/contpte.c | 15 +++++++++ 3 files changed, 15 insertions(+), 112 deletions(-) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index d6ddaf282a94..8a273b9816d7 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -119,53 +119,6 @@ int find_num_contig(struct mm_struct *mm, unsigned long addr, return CONT_PTES; } -/* - * Changing some bits of contiguous entries requires us to follow a - * Break-Before-Make approach, breaking the whole contiguous set - * before we can change any entries. See ARM DDI 0487A.k_iss10775, - * "Misprogramming of the Contiguous bit", page D4-1762. - * - * This helper performs the break step. - */ -static pte_t get_clear_contig(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pgsize, - unsigned long ncontig) -{ - pte_t orig_pte = ptep_get(ptep); - unsigned long i; - - for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) { - pte_t pte = ptep_get_and_clear(mm, addr, ptep); - - /* - * If HW_AFDBM is enabled, then the HW could turn on - * the dirty or accessed bit for any page in the set, - * so check them all. - */ - if (pte_dirty(pte)) - orig_pte = pte_mkdirty(orig_pte); - - if (pte_young(pte)) - orig_pte = pte_mkyoung(orig_pte); - } - return orig_pte; -} - -static pte_t get_clear_contig_flush(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pgsize, - unsigned long ncontig) -{ - pte_t orig_pte = get_clear_contig(mm, addr, ptep, pgsize, ncontig); - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - - flush_tlb_range(&vma, addr, addr + (pgsize * ncontig)); - return orig_pte; -} - pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long sz) { @@ -284,20 +237,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep) -{ - struct mm_struct *mm = vma->vm_mm; - size_t pgsize; - int ncontig; - - if (!pte_cont(READ_ONCE(*ptep))) - return ptep_clear_flush(vma, addr, ptep); - - ncontig = find_num_contig(mm, addr, ptep, &pgsize); - return get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); -} - static int __init hugetlbpage_init(void) { if (pud_sect_supported()) diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index e6cbb6fb2904..caf1db6f8f20 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -121,42 +121,6 @@ unsigned long hugetlb_mask_last_page(struct hstate *h) return 0UL; } -static pte_t get_clear_contig(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pte_num) -{ - pte_t orig_pte = ptep_get(ptep); - unsigned long i; - - for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) { - pte_t pte = ptep_get_and_clear(mm, addr, ptep); - - if (pte_dirty(pte)) - orig_pte = pte_mkdirty(orig_pte); - - if (pte_young(pte)) - orig_pte = pte_mkyoung(orig_pte); - } - - return orig_pte; -} - -static pte_t get_clear_contig_flush(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pte_num) -{ - pte_t orig_pte = get_clear_contig(mm, addr, ptep, pte_num); - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - bool valid = !pte_none(orig_pte); - - if (valid) - flush_tlb_range(&vma, addr, addr + (PAGE_SIZE * pte_num)); - - return orig_pte; -} - pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) { unsigned long order; @@ -173,21 +137,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, - unsigned long addr, - pte_t *ptep) -{ - pte_t pte = ptep_get(ptep); - int pte_num; - - if (!pte_napot(pte)) - return ptep_clear_flush(vma, addr, ptep); - - pte_num = arch_contpte_get_num_contig(vma->vm_mm, addr, ptep, 0, NULL); - - return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num); -} - static bool is_napot_size(unsigned long size) { unsigned long order; diff --git a/mm/contpte.c b/mm/contpte.c index f7f26d2cfa23..445e5ebe46b4 100644 --- a/mm/contpte.c +++ b/mm/contpte.c @@ -23,6 +23,7 @@ * huge_ptep_get_and_clear() * huge_ptep_set_access_flags() * huge_ptep_set_wrprotect() + * huge_ptep_clear_flush() */ pte_t huge_ptep_get(pte_t *ptep) @@ -251,3 +252,17 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm, set_contptes(mm, addr, ptep, pte, ncontig, pgsize); } + +pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep) +{ + struct mm_struct *mm = vma->vm_mm; + size_t pgsize; + int ncontig; + + if (!pte_cont(ptep_get(ptep))) + return ptep_clear_flush(vma, addr, ptep); + + ncontig = arch_contpte_get_num_contig(mm, addr, ptep, 0, &pgsize); + return get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); +}