Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp437607lqo; Wed, 8 May 2024 04:42:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwN+BpYsv9km3l6Xv5oB7aBqUP2k17DjwM12qzO43mnOi3M+W0uxxZj2myNCT2bnLP83as5JIW2IIr/6kivNwW07DI/i0Ux7Ij3Zopew== X-Google-Smtp-Source: AGHT+IFE/0SJ7VoNqaSwL50Kar/ZA8rb80uhjP+QBZGX5as6+79xuv9TG0WBExtcaaXCAaIEQtqq X-Received: by 2002:a17:902:e806:b0:1e4:17e4:3a1f with SMTP id d9443c01a7336-1eeb03a568fmr27883945ad.4.1715168539162; Wed, 08 May 2024 04:42:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715168539; cv=pass; d=google.com; s=arc-20160816; b=0y2G0+Ve3l48co6LJ4KMOQ4LiBQowVVx9KEWALv9IJrhUhsDE/JsUqzvCQABgVtrK7 8naL078vWbW22PCaLczjkjC1lgXl3XviGkfJEdiNDiaRP9ZO5VdvCIBCdSzd0hEOgpis lJLgpeN0Ugc0/g0VCNV8LR+pq5Tfu8JWadwe3Ue+qQH17irUWYulKWeTg4NJsS2r8qLu E1/JSkFvAtFDizMiqNL7imy1NFKW2PV6fD4ZvZQ7aXGQ+BAx6JEl6Cpoj+sbKT1Jnn9y 92donx5Odeh7exSi9/o6h8vzddKGJC9PTNXDeoU+cLZsAzYwwIjhnV5zGJYluWq6BZy0 ENMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hkOJ479CewvDdU5HWPEgLgm2sAjKEVUPHaCHVUUKnDI=; fh=ZspMR8u8PEZ3yvihXafenJVuEqBvJyN+ceXtHpn6jA0=; b=AXjouA+1S4DZYsFk+g0uA4XMc8kzPNeB5FhMqqQ8JvDfyHYtoBsHqzLVYIWCyBRbgX zDY3hwNBmA3JGDZhbnXM1HCbJkyceHWhHJBbwW87K6/eKo5k0U7jEzS6VYIJ8jKVcrUx 1oaZLimOVQdfYcKF/XFI6+SvPtGOa3lJjKVKcKJYS44BI78fUKqEhrETbG1uVlLaSzA1 0IEyw217OCRbMrKLapTqwFiOAtLeHdkW1NhxJPUjE1eptJv49S+RokaYRhknFv8qixf7 CvVeDGjk+eNORQVS0vT/pFE4SXaLoBFE4I01uS9lh/E68zqYyG2RTAr5egSODMWvYq/w OZzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PtJNC531; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-173158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173158-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u11-20020a170903124b00b001ea964dfbbasi12858279plh.206.2024.05.08.04.42.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:42:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PtJNC531; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-173158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173158-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1193DB2307F for ; Wed, 8 May 2024 11:39:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40AA38248F; Wed, 8 May 2024 11:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="PtJNC531" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64801823D1 for ; Wed, 8 May 2024 11:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715168373; cv=none; b=S8po4BeN4QwlZwt5yWPW1ffbdKPzyx2I1MHVPDZr7pmJsGCAaVAYXl2IoQMNR8veKA0GD0+SWOvBF2z0qd3PoZooU5hLbDtCCmfRj+LxerYZrOBjjlF7cdDl3BKfLh/I/LVFmZGfsLB7GIuaW4xHid9us4JsFfe+FDOakMhoQ8M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715168373; c=relaxed/simple; bh=VcXd6zYXwEr2WPHeuoMzH4NNHOKAqqGKrEMxYOSoP+o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wzxj4ieOyEIbk7vQqSK6ADh2wV0+Q9AOhIaopiBs74IG4g2I0Gyx3VIMrLhCOmtUjGlbLYegQyL+qxOMH65RBkLUHkq3upvmcXgrpLsIdMaFt5ebuFrUaAl2Ca9EXFPFgUy2F0NNCVuWj1IIBt6dqHd26zUI4R6Aab0Vf4kCnCY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=PtJNC531; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-41bab13ca81so43858135e9.1 for ; Wed, 08 May 2024 04:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715168370; x=1715773170; darn=vger.kernel.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=hkOJ479CewvDdU5HWPEgLgm2sAjKEVUPHaCHVUUKnDI=; b=PtJNC531nvw14TSDwudd1ix+TWHgxDy1kUHhkvgqaF+9iKum0PsXMf3+Gz6YmN0nLM zsbafbI5HRrUA5BvopsPX+YrD5WwGoMcpD9JrmcxV9FQpbEydlVYZnf57Hte0mwvBH6Z /AB9qMPHhFON0KKRevnb7RxorspyC9lONdy6kPIieL+Ggrr4Ldh8YvAKhre7oZXUZ4xE G6KgeMizXqi2bodLZZMI7iCQ+oBvL0eqeDELpZG3mlI8toErpFuMaskQT0MvxxyVeCiD aG68I7ytfGrYbiuPprKMxmpjdj2CfEHQAfcCVfTXdHw+ISI1X6J0VgdclVABjpPDicdd zEFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715168370; x=1715773170; 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=hkOJ479CewvDdU5HWPEgLgm2sAjKEVUPHaCHVUUKnDI=; b=nwrZfWENK2hq/hla+uN0NhfQJJIEAEIOSG4+PSwoU+4+cuDrwklaUI6psFzUaxN0Ba ZaraiJXXH2NCrrZfjiPS50L7uLKJ1en+5Ww58wN7vgtwt4S+xObZLmAVhWDMK8MZyIxX r/Tlob0A7e5xwG12QE6nhTiW2sizr42h6LjEui66kHglrw8KhYcz6URk0Tnl1Db3n020 ZYejhasTNoOOsZrsTXshlUFOrQfSB6f3RtAwOVymyrWNN58APvkH2hf2+eeYMDEAblW1 NZ+3F15+zUtjkDUH4bbteySZyGt5pCpXkJoUBe6i6FAFflzFxEP2U2D6LTczZuCOujfW UODA== X-Forwarded-Encrypted: i=1; AJvYcCVHHhzLdUA+A6Ikss06+tlbLI+QfsyIusWCQthaDmaMpK8+CU5GimMAwBs3HqenY10XpgZOffldZ5EIp/ScGz4JlpSmqqvNkcdmJ4Dv X-Gm-Message-State: AOJu0YwUJOuipgrskfXjQuYdOyuzkMWLBlMxrqRb6TKbtOP9xWxVEkDm FWn8yBL6iN2KZi1i7C8Z5z5ys2lqBhEgCEJGxwcOnsNiHDxnZcIpFv4gVTtIaFQ= X-Received: by 2002:adf:e752:0:b0:34d:17f2:956d with SMTP id ffacd0b85a97d-34fca80dffcmr2356969f8f.66.1715168369782; Wed, 08 May 2024 04:39:29 -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-41f88110ff8sm20241365e9.38.2024.05.08.04.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:39:29 -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 5/9] mm: Use common huge_pte_clear() function for riscv/arm64 Date: Wed, 8 May 2024 13:34:15 +0200 Message-Id: <20240508113419.18620-6-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Both architectures have the same implementation so move it to generic code. Signed-off-by: Alexandre Ghiti --- arch/arm64/mm/hugetlbpage.c | 12 ------------ arch/riscv/include/asm/pgtable.h | 5 +++-- arch/riscv/mm/hugetlbpage.c | 19 ------------------- mm/contpte.c | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index b8353b0a273c..cf44837369be 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -277,18 +277,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -void huge_pte_clear(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, unsigned long sz) -{ - int i, ncontig; - size_t pgsize; - - ncontig = arch_contpte_get_num_contig(ptep, sz, &pgsize); - - for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) - __pte_clear(mm, addr, ptep); -} - pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 5d1d3a6c7c44..0847a7fb8661 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -644,8 +644,8 @@ static inline void __set_ptes(struct mm_struct *mm, unsigned long addr, #define set_contptes(mm, addr, ptep, pte, nr, pgsize) \ __set_ptes(mm, addr, ptep, pte, nr) -static inline void pte_clear(struct mm_struct *mm, - unsigned long addr, pte_t *ptep) +static inline void __pte_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) { __set_pte_at(mm, ptep, __pte(0)); } @@ -700,6 +700,7 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma, #define set_ptes __set_ptes #define __HAVE_ARCH_PTEP_GET_AND_CLEAR #define ptep_get_and_clear __ptep_get_and_clear +#define pte_clear __pte_clear #define pgprot_nx pgprot_nx static inline pgprot_t pgprot_nx(pgprot_t _prot) diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index d8f07aef758b..437b1df059eb 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -254,25 +254,6 @@ pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num); } -void huge_pte_clear(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long sz) -{ - size_t pgsize; - pte_t pte = ptep_get(ptep); - int i, pte_num; - - if (!pte_napot(pte)) { - pte_clear(mm, addr, ptep); - return; - } - - pte_num = arch_contpte_get_num_contig(ptep, 0, &pgsize); - for (i = 0; i < pte_num; i++, addr += pgsize, ptep++) - pte_clear(mm, addr, ptep); -} - static bool is_napot_size(unsigned long size) { unsigned long order; diff --git a/mm/contpte.c b/mm/contpte.c index 2320ee23478a..22e0de197bd3 100644 --- a/mm/contpte.c +++ b/mm/contpte.c @@ -12,6 +12,7 @@ * - __ptep_get() * - __set_ptes() * - __ptep_get_and_clear() + * - __pte_clear() * - pte_cont() * - arch_contpte_get_num_contig() */ @@ -20,6 +21,7 @@ * This file implements the following contpte aware API: * - huge_ptep_get() * - set_huge_pte_at() + * - huge_pte_clear() */ pte_t huge_ptep_get(pte_t *ptep) @@ -102,3 +104,15 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, set_contptes(mm, addr, ptep, pte, ncontig, pgsize); } + +void huge_pte_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, unsigned long sz) +{ + int i, ncontig; + size_t pgsize; + + ncontig = arch_contpte_get_num_contig(ptep, sz, &pgsize); + + for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) + __pte_clear(mm, addr, ptep); +} -- 2.39.2