From patchwork Wed May 8 11:34:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13658624 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 8AE6AC04FFE for ; Wed, 8 May 2024 11:43:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26A176B016B; Wed, 8 May 2024 07:43:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21B206B016C; Wed, 8 May 2024 07:43:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10A306B016D; Wed, 8 May 2024 07:43:41 -0400 (EDT) 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 E742A6B016B for ; Wed, 8 May 2024 07:43:40 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8DFE3141449 for ; Wed, 8 May 2024 11:43:40 +0000 (UTC) X-FDA: 82095043800.14.497769D Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by imf07.hostedemail.com (Postfix) with ESMTP id A5BCD40004 for ; Wed, 8 May 2024 11:43:38 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=mxjZf9pJ; dmarc=none; spf=pass (imf07.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.175 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=1715168618; 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=zkDF3kPVXJf4AqMK0ZqTYH7UgAMmNVObdoVU0G1Ynu8=; b=ly3+L2XDbK/Fa2dg6bBh19uFJ+IcAbRy0c3elnWC3dSUk6x00J5L99DLtywXBGMqFDGQQK NX3OIr1RqdhTXU6/Y7l/AvnVTV3wN7fOCZl9HxvaJ95VLPY+1wd4XhFJgcAZopD267NQtX sINJUJn1Kpz2mmlhUShfvWwO0984ArI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715168618; a=rsa-sha256; cv=none; b=hd9oA2D/5z/YqHdRFHCS4F+/RfajmYs62LyeiZtygdQnV0igsF99b3RA2nDdo0TyFg+Jxn LFXGgV8ChVwWYIznJ66mzQWDQVNLxkiJZQT/8fSqRKvPkD1NZsP6Eyu6GlJ00eJKBdJrQQ 5SyUN1T9Ve1r8i/sqaiG+rmzrAsaESw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=mxjZf9pJ; dmarc=none; spf=pass (imf07.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2db13ca0363so64193921fa.3 for ; Wed, 08 May 2024 04:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715168617; x=1715773417; 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=zkDF3kPVXJf4AqMK0ZqTYH7UgAMmNVObdoVU0G1Ynu8=; b=mxjZf9pJOJrXYS65uoN2AV6SJNUuhmc7x9QShm7xTGboTZ/ASrHT5S9YQefaLc09EY 0uhGp0MUM08kaSeFfcp+fBZQxA6hBLBLe31cdjEl53Ceul7yEb7iLBV2fa7zAQ2lu4gl +onbIitbUogmlW5jr+AVpSFldi0VuNV2mWh7k/5d8UYq0xrEC4xfN2y4sGIGHg1pR2IZ Jobg9p8EXeeCz6zJREnd7ZwMGYQSoSQBqShRYTYi5Mp4TEFqgZelVZ1rS1A2/gHsMmgR fLhMwUz5croxSDGCPcIknt3xlb7TZ52IJegfJMCPypFzGCejv1Mc4DHAldBb9GUIM54D 3SOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715168617; x=1715773417; 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=zkDF3kPVXJf4AqMK0ZqTYH7UgAMmNVObdoVU0G1Ynu8=; b=W3vBuDwpEzOF0t87v+Cpu9j9nwyv7yVpmhNlxhqo6BivpOQfU1nIG9jpngU8MEHWPi GqO3Lcxmna3Nh85Ocz5ZfzbuTuE1JPfP/i5il+vRrcphtaqfvL55AY7GZpbzfEU0CbSD +Y211OhHFPUqOg1i9hpkEmc2Ui2UaPXocYvW1/b/MfU3wqYb2fJFHJ1QtdmIicvT8W5w 2/8slEx3TG2QvCig8JYXatZiyixiDvR4DonAc9SaoTO4+LdXq0qHhIqkNMfiOBGNyPkJ 3qdDhzW9xJmSIBE8L1eAT1OoAMmK4oLA6tIMO/madxQSQ6mscSWMp4BrQnvZhs2QXRA+ lOsg== X-Forwarded-Encrypted: i=1; AJvYcCV/yx/C/XgClyIYziqGsM2ojjXPdK0xGjYjhTV4vxzovVmv5khNNT0WR6Ld+c3qyj2K67KGhiut1XSOiOTeX7EEIxg= X-Gm-Message-State: AOJu0YwNRCcH0aN0OvyYNWbUb+Dso11G1Kbl4sCoPkQ0/6GuT07kRivB 6RHbY+cQ2ftVdD+Su/Gqpncpfz2YpJk6UCYk/uKBX9bIH5r+QsOary1mnQag+QU= X-Google-Smtp-Source: AGHT+IGXkVEaOMFBHx/baYrBz9derdknpbq9as3brbpiTEdPwh/hYAl2dlBH3Ljix5Ca772CLWwlVQ== X-Received: by 2002:a2e:9257:0:b0:2e1:a504:f9ec with SMTP id 38308e7fff4ca-2e44708423amr19911671fa.23.1715168616936; Wed, 08 May 2024 04:43:36 -0700 (PDT) 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 5b1f17b1804b1-41f88111028sm20610245e9.33.2024.05.08.04.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:43:36 -0700 (PDT) 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 RESEND v2 9/9] mm: Use common huge_ptep_clear_flush() function for riscv/arm64 Date: Wed, 8 May 2024 13:34:19 +0200 Message-Id: <20240508113419.18620-10-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240508113419.18620-1-alexghiti@rivosinc.com> References: <20240508113419.18620-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A5BCD40004 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: mnwxzapddr5a6n6uuticjoxstdtkyx3n X-HE-Tag: 1715168618-557157 X-HE-Meta: U2FsdGVkX1+F1vAhGQChSsIjv9gdyXDAxPtGJQbSB+wBBfnc74HvbVIMl9o/8IwlwnPXjdQXThaTefGCCm32vDyNdJVqjI/S55AbwrN4F5BkFbYfpim2Jv3rOqybMErvYHTPgDKKciVJhi9ho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SaJJZbTm/6oLjc9het83Lit+I5Onf/nD6ctFUWd6+kcC3XSShpgrTo2RWa7duk0qRUbdPr8by6ZUzofFSPMa1XVAlJP8tPTz6h9inpr331CW3+xrsoeJc2QeVp6Gd3ksq91hme8HJuG/tEXDOF/QzE2182QkKD0lmea0XgrLnJAWxTz0aR/PWh0e4rHMYL911hWq5gOIxSSBQTKpppJlwERR82lAgeEI0dZ/WMVNnpiLvXuN6D5AgLwPWZt2XhVVK1zOO79qD6+VwtTg== 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 e56f2c8ec7e7..5869f20ca28e 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -112,53 +112,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) { @@ -277,20 +230,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(__ptep_get(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 440d3bde88f2..47333efa2d83 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 8ad2a3099dfd..15791f6d9c41 100644 --- a/mm/contpte.c +++ b/mm/contpte.c @@ -27,6 +27,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) @@ -255,3 +256,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); +}