From patchwork Fri Mar 1 09:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13578202 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 DA912C5475B for ; Fri, 1 Mar 2024 09:23:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75F526B00A0; Fri, 1 Mar 2024 04:23:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 70F806B00A2; Fri, 1 Mar 2024 04:23:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D7D86B00A3; Fri, 1 Mar 2024 04:23:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4EB2C6B00A0 for ; Fri, 1 Mar 2024 04:23:24 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1268CA1B15 for ; Fri, 1 Mar 2024 09:23:24 +0000 (UTC) X-FDA: 81847931928.15.5B7C629 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by imf01.hostedemail.com (Postfix) with ESMTP id 445D340014 for ; Fri, 1 Mar 2024 09:23:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ieOlSQ+r; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.174 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709285002; 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=+Bwm42ASg+Pn4jchqsA5u8tprYh0PuExgujdSk24Zd8=; b=M+4gk9i342UWLa1p9idwbk+Za/1OlXWiUk9J+2l3M89Jb6CP8X9+g+MFyFyNTw9dsSfuid aL/U9eLm3LS3T8G7YcSQ3kypUqbOf9n7aj9OMTXVKvQMnlB2mgR6JiMQ3zvJZ0Pof3eNgu x93y5BUK/cj2jRccOWgPQNp6Y4PYWz4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709285002; a=rsa-sha256; cv=none; b=jdTyfyw8I2OpbJakVnE+CNo7RPsXLfsKi5JefuRZFZgoiLl4CtT8EKxxG7f6pmYhr0zWS6 pWacTjAJSOdOBn/fYDl/GSzMw2iIBlsSFFJDcj8H7b5WyOLpUqwr92bsBeSZT0o1xjDZxV mzuSkDEpE0pFbTa4AbhLaJgTzRnPAx4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ieOlSQ+r; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.174 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d28464c554so22607121fa.3 for ; Fri, 01 Mar 2024 01:23:21 -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=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=+Bwm42ASg+Pn4jchqsA5u8tprYh0PuExgujdSk24Zd8=; b=ieOlSQ+rs23ApNfVtlCx/buFmrSho5/hCC1Nz+JgpymP9unrZNYra06VdUCRE4VwHB zLIiCWfYGz5LO1VsIvJ0kd4yue17W9tQabsfsM26UWYW/v4MiWQHvg93a3vO65UzbHfp Wy32nNgTWaIGHtsQadUzIcutDuMzM6voaW+bvy3Hvwqh7W7ZMz5vDSD+/51EgorM+Ogk 63n8WSOqY14UKlkEimcI06KAw4ic6+oXq+lF39gzb5Ni0Y6A0Ui9YL8DDWrCB1UFOo0M FHppqhPG2M9gzz9L5Z0Ew4ztvoY8T8oLLyY81kFjGa6fwXmclvCYNky2Fm4Xv3fEvOd1 VKdA== 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=mqjR+L9Fb+VYB7rC/ZQMue6ti5ccZfm6OdRXkOnqC7V99s21eFzilZzBFf0QSF7vSq sRH/htwwgXt5XcCYxr1vw394bAXHoH7g8Rf3gOvHc/f5eaWUml4K2Mp/F+Mg+mvwho3d f0TFtgt0emtXhFuRRUg6z2t0ai4jllDda8VMJqvUdfku8w/OHvqLekjKkxR1CK/84V68 xMbX6z38TtDU6hkyCRBCqL0RY7a8Fo/ji3mSeLE/+wzmOkVk7YFXwO8QgS7WXrs2bfly 3XTnKpUMCXqMeW1nzrLi0rzHJUXc4JTxtkpk9gMPEBLLA/wk5u7x+lFwjpIONKDiJWvv 1A5Q== X-Forwarded-Encrypted: i=1; AJvYcCXfo705k4D4DVnnKwpw39ldfzxnxEUOo6TkjMjL23jcGjeftYUWJJPmGJZJzPg4NMYVl2rfHPSvkV0e0mOknuzBTtQ= X-Gm-Message-State: AOJu0YzgLETtrSQHLIuRQnXN/DnzPQERxViaCVhnZy6EQ63qOB5mT9sy pFGtBRQmWC8n2FcNHXdhzEFNTslnsSxzX9nY7JZmdc0O++2u/pHL+USMd8WShVU= X-Google-Smtp-Source: AGHT+IFkOrueHwu+dCituNGudpmJQSWFJOG3RRqM9+lTLTigiW3MgJH56JMq1RpUEmcE9Sa98B2xOQ== 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 445D340014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 94qbogueerkxtfeaisrgjoiwu34ryd5z X-HE-Tag: 1709285002-318335 X-HE-Meta: U2FsdGVkX1+aEp+SwObHH43yT/BT424f9gNQckZTdweShezL/qxpzC73/J4EjMiijAZ5z1HEf4xrk55RmavSkz3P/5YX1B66W/hZUACCy1jMsdP6zSSjw+SbnDVEzKpIqm3DY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osity: 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 | 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); +}