Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp170902lqg; Fri, 1 Mar 2024 01:23:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxAf2thd8p/vGqmWe/qb0mTOHkWVO5MBMqYwozxA6nvH737XLp8AKg2Cyy1VOMMJ5n/O5IVH3t6WLGwpTUar2VGh9BeFSygfA5w8ygaQ== X-Google-Smtp-Source: AGHT+IHcJRuB//W0jPn2DSJdJj25sulo1UJWTioreeUGXTDa61tjx3gxBZkDT3qALnhDW9EG76HI X-Received: by 2002:a05:6122:2191:b0:4d3:3818:8894 with SMTP id j17-20020a056122219100b004d338188894mr1064013vkd.9.1709285010389; Fri, 01 Mar 2024 01:23:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709285010; cv=pass; d=google.com; s=arc-20160816; b=kxyX/OjKM6WjMzwRWfEND9oVJIfaAcel2io4VEqCdfOjx1Ysy/T7uKX661K0Q+Unc0 92cWdoUL9vF4YwZIKpvCQBBeXusabVpPRtQ8G2B4qFmlgBK0TjV5QyIE+eYRr2ySm7pj 7vKZkfRxpSfTvkjRUTFYQK0hdx191UqQhFw9igAOPX248MGF33FVJgBixFobazGf0Sad C0Bvgo5NirU38np8hi04P8QbD4tb69I/chhSFzwgQNo+h538PPaRKKSo6vhJve3MGJJw I+1hf102+Iym2vhb6wJoRvf+t4iqFN1bHppPt6b9mycGPpxr+N2mS2L8fmHITXqy0pVB DuOg== 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=+Bwm42ASg+Pn4jchqsA5u8tprYh0PuExgujdSk24Zd8=; fh=Gd/G1tVncat0/wMba+T7jM3F/jTJGRdYDOgUxFhZoWM=; b=Acwx5Q6ZOFei7FxQmbBxhNQBK8k/pcu7gay9xQh6CWP7viLfbr7Z1sLWkn55Le4qdQ aReZOFk8juOCnQnRpus5wzR89VAz1D47rArLyvOgACIDyDPKXRAUG+C3KT4RjPi57ehw Z905fQ3dnQMZdp35za4T+06AGrzzgYijz2YMyZbO776suqxed8NaMITz/St1bA2z1vYA jb3TdeKOhaTWeyhE9lqQ6h58zDRC5ilPlWEHHBugSQoYvorf/6AQPsnm+Q2xVQhb6K1v yCPduTfsu7EzuQzgLHMxUFiJIz2O0VRoI9fkok4IQ9CYB4fVNoAiFzg9Z2ALpLBy9ZNg AU+w==; 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=hrytu87r; 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-88169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88169-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f27-20020a05622a1a1b00b0042ed09d50afsi37628qtb.92.2024.03.01.01.23.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:23:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hrytu87r; 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-88169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88169-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0C35A1C2255B for ; Fri, 1 Mar 2024 09:23:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D47EA6A33C; Fri, 1 Mar 2024 09:23:24 +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="hrytu87r" Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 50D341E886 for ; Fri, 1 Mar 2024 09:23:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709285004; cv=none; b=DmQWnLbYqRk+o9w+v45B20FmrJ2ZHHZE8mLGPOrZ0c3YV55QUISRxTc7hPDajkv94AB6Ej3fZ6UoF2adY+8CpTdCSXLKn18Z8G8yPKIR1o9s98GidOyH6Y69Cybi9GmstZhaEWLRX/dzrwTLqDspSrxCk4bPT3gQJRkumG+kbm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709285004; c=relaxed/simple; bh=GXAk2kN1CTNZcSPb0xo/khVDgAjh/yl/yqVe3qPZCWw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hMGQPOi4u5OjVDGMWdCTBMIPAAkxegJMGVlRCf4FVCCCG5kRk3P6eN7SUXrYdhg52OSAyO443F65ulVaFuqnX/u8yp6LhUXjVnS/pPalfXtL/raLgONk3aBwoL64aWcK6s7O4lD5UPMjtqWDlhlPZ7mCN6uZiLu405speu/lXSo= 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=hrytu87r; arc=none smtp.client-ip=209.85.208.172 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-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d22b8801b9so23166141fa.0 for ; Fri, 01 Mar 2024 01:23:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709285000; x=1709889800; 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=+Bwm42ASg+Pn4jchqsA5u8tprYh0PuExgujdSk24Zd8=; b=hrytu87rixLQYgV1MR6B5Go6MbsecCNyDU8wutYVMIaP67Dx+eIYH43Gfip7lo+71y ZMcPF1kUqjUG2RZqrTNI2brU9CneXP8QD1lv7tB6qADON4O58gEgox7HWBlYO5V+6aXX BCbLi32Fudvfo8947uzFYGXiJUTY1xXk8DuS9W6v2/PM+gSTBqc1gIiH1LqBVlcfbKY5 NGaSYShAYdZw0fz/fhECIPFK3WRQctxAXiB/0TJzv6ZyUhi5631Uoj/P022pcGPRcdzh LU1wxRBiHbVe4YdxS/92I7Zml1dfopPMKG8ksnQiZRXmcWMuG/acOaAhmlanjEsaKVmZ 38UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709285000; x=1709889800; 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=+Bwm42ASg+Pn4jchqsA5u8tprYh0PuExgujdSk24Zd8=; b=hmlhCHY1HYbNnh7je/tFfrdmqkW2y2PJb9H58ho84X5ZSJUtL0Uic0GbPBN1LR3gBw 8UhsUHVtbm/Jt+9291sE80lDbgV5YXKXZ26jbvvxBPkMgdfwtiVMByPzDOkOKWj9UnK4 kh8EOntybH/dr+aAuGAXmhNuXR9NflzVLhT81cF1Tg4gfBBe9z7HIvrFpyGzflK2IoUr qmAe5C/JfjHAYR1xGYcCkcxds5rLzFMDWRNEvcaHKF62YWxwjDBJbG2HRQ2yP7hq6p7t qlMQDZcXKMXEMzpeiWmGcOMDbH4wb7ya7g2TKzrlbVZJZYKE/Yt4gSh5nbqO42tkOhqP A+Bg== X-Forwarded-Encrypted: i=1; AJvYcCXg1fbTxX5QngY2ZubfNCf9z1pMrM4b794v7qAecLWuGKwWLnGHmzayNWaqJyZFPTj5scc2ViKIQOaJjgy8FWGQwueLfc4ipsNZIjTP X-Gm-Message-State: AOJu0YyLjuE+WfTLbRzvucWYwOVnYzsXoEEk7AmvTwmabC1Eucr0CCOG V0E/kuz8+zPkaAjyoI76ShfIZdxRSfnSgwl8Qff8kNccch1J1b/C73o2YuFbA4s= X-Received: by 2002:a2e:a4cb:0:b0:2d3:365e:9d02 with SMTP id p11-20020a2ea4cb000000b002d3365e9d02mr635537ljm.28.1709285000535; Fri, 01 Mar 2024 01:23:20 -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 l33-20020a05600c1d2100b00412ca88537dsm374810wms.0.2024.03.01.01.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:23:20 -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 8/9] mm: Use common huge_ptep_set_wrprotect() function for riscv/arm64 Date: Fri, 1 Mar 2024 10:14:54 +0100 Message-Id: <20240301091455.246686-9-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 | 27 --------------------------- arch/riscv/mm/hugetlbpage.c | 22 ---------------------- mm/contpte.c | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index b8abbd5ace4f..d6ddaf282a94 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -284,33 +284,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -void huge_ptep_set_wrprotect(struct mm_struct *mm, - unsigned long addr, pte_t *ptep) -{ - unsigned long pfn, dpfn; - pgprot_t hugeprot; - int ncontig, i; - size_t pgsize; - pte_t pte; - - if (!pte_cont(READ_ONCE(*ptep))) { - ptep_set_wrprotect(mm, addr, ptep); - return; - } - - ncontig = find_num_contig(mm, addr, ptep, &pgsize); - dpfn = pgsize >> PAGE_SHIFT; - - pte = get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); - pte = pte_wrprotect(pte); - - hugeprot = pte_pgprot(pte); - pfn = pte_pfn(pte); - - for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn) - set_pte_at(mm, addr, ptep, pfn_pte(pfn, hugeprot)); -} - pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index fdb633844d4b..e6cbb6fb2904 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -173,28 +173,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -void huge_ptep_set_wrprotect(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep) -{ - pte_t pte = ptep_get(ptep); - size_t pgsize; - pte_t orig_pte; - int pte_num; - - if (!pte_napot(pte)) { - ptep_set_wrprotect(mm, addr, ptep); - return; - } - - pte_num = arch_contpte_get_num_contig(mm, addr, ptep, 0, &pgsize); - - orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num); - orig_pte = pte_wrprotect(orig_pte); - - set_ptes(mm, addr, ptep, orig_pte, pte_num); -} - pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/mm/contpte.c b/mm/contpte.c index 3b65c49c6d4b..f7f26d2cfa23 100644 --- a/mm/contpte.c +++ b/mm/contpte.c @@ -22,6 +22,7 @@ * huge_pte_clear() * huge_ptep_get_and_clear() * huge_ptep_set_access_flags() + * huge_ptep_set_wrprotect() */ pte_t huge_ptep_get(pte_t *ptep) @@ -230,3 +231,23 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, return 1; } + +void huge_ptep_set_wrprotect(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) +{ + int ncontig; + size_t pgsize; + pte_t pte; + + if (!pte_cont(ptep_get(ptep))) { + ptep_set_wrprotect(mm, addr, ptep); + return; + } + + ncontig = arch_contpte_get_num_contig(mm, addr, ptep, 0, &pgsize); + + pte = get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); + pte = pte_wrprotect(pte); + + set_contptes(mm, addr, ptep, pte, ncontig, pgsize); +} -- 2.39.2