Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2006938rwr; Fri, 28 Apr 2023 05:06:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PUxNrZR7E02f8BTWpn5X/BL3teVF4Slz6BemTIPUq72A5S+09ACJIh7Dj7pn5pSLK3kvo X-Received: by 2002:a05:6a00:848:b0:63d:23dc:7760 with SMTP id q8-20020a056a00084800b0063d23dc7760mr8083572pfk.2.1682683562568; Fri, 28 Apr 2023 05:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682683562; cv=none; d=google.com; s=arc-20160816; b=qEl5Itu5eF0tZlEF4Gg6w+5I5G8biuARuXVliNj/MNsmulj+iTENvCqOT9i1XswiRr 7gulSCeM5pnsE22AMwqi4szE+wnGdGX1sjb2YQBFntzB7XAeONMECvn3iy4uF7PKfc57 hpr7Lzybz04QhQ4QtfQx4+AAqtDNQmPwNSfd8oNku1HWfZldg6DlWrWISVNvQyp9pJEQ /4SSJ9TROVtZqHe8VQol/OU7asWhaMqD++JfveCp3xxzVbTHCZ/6ukslf4Ttp3eZ/HaO dPyZdzYUnnuzh7JbLcrXC2xBJIdrvqAUFPIaIHFA2wr8/fjJt/BmUgFITgONEBOsnzGG r5vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i+IhJdlbzPopAgcnIQcMyy0yuzqBnz1h8mDocxofWCY=; b=t9Z+QQHTVTyyUExT5CclrUEnVeznrYmLIFOURhIDeJyGJUvHtnkv41ABcjPzkhSTeu MI7gEoCvCLjAMRjMPd3emf6Jt6nvwrrjaHqBNMXCwNe3L5vmyMy66eXIUrQR29nLhhpB U/JVRQS7cytrIPuRM4fExIcN1hSEvD9MDFL+pIsB3uBwxiF43kxmAUGK5LkKl3tFtXzB yEuoyT4/hd+hvhzoy2XuHCFdS9Gkc4UvCMOHISJYb3n+hdpW3t/sJGC8F/BXC/A9xTDq B8Lwb7Yyf2Y/ewwEBfHEUUJlVD1uaeFPLlOq6Y8lTXo5NhMe2jVQREr3UcczM5nmklsI bt1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=aLYgN7Vl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020aa797a9000000b005931febf7c0si21026536pfq.225.2023.04.28.05.05.48; Fri, 28 Apr 2023 05:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=aLYgN7Vl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231510AbjD1MC3 (ORCPT + 99 others); Fri, 28 Apr 2023 08:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjD1MC1 (ORCPT ); Fri, 28 Apr 2023 08:02:27 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63CC31FF0 for ; Fri, 28 Apr 2023 05:02:26 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f315712406so57950445e9.0 for ; Fri, 28 Apr 2023 05:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682683345; x=1685275345; 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=i+IhJdlbzPopAgcnIQcMyy0yuzqBnz1h8mDocxofWCY=; b=aLYgN7VlR46N9WcDi53goFnZv+vG6n3pLEhhSP9AnlnYDiiuuH7hkDMkrbFyl/q8IU QqyxBo3ttSlxPV99BPEA855FtbCjlLBq+2yUTvTQrQdE3zs6TkyppYM8+4iJm0cSlyTZ 4kJvdtC6YfTYisDIciOvBeSXMzj6JftKhpHLkM7+dbEncXDxKStkW/Yeosa1Ci8x2Xew TRKfi2Xbgzs5uPExZM9N2S626aiDKkYDfPfeLt0iG40V81YMQo2BzohjA180oQd3gl9r zn5JUkkEJIGXv7OzhafPO6q+n3QKY7b0LRP/qIzGwu7mBU9lh01fnfzJTPUA2ueO4c+s Tysw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682683345; x=1685275345; 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=i+IhJdlbzPopAgcnIQcMyy0yuzqBnz1h8mDocxofWCY=; b=QPTQa7Y3uRum3RBslLyZAfmN6vJUlwqBweXe0RjYLd/oAAcdD1l34uCI3S7AXtmgCC fNLfok5rVlBL6R5Cl99sp7Bdnwb/q6dSLJBpk7lM7vmDrTnDrOZSDgALVHqmnIXjIgaI b4jQafgvPSCCc3O0+ibS6aE8h6byqqgICJT1ntQVCWJQomUZkrY1iu9bOr4p/FzTwkmJ 4SnSe/xT9YpaL7IRKXADpF07ZubbIQGvKT7i2ljdZ8bGWs8XaEjzI7+y0YLsh4HtdsOY iBYXcG1M+2mfKnsh+NeyW6pV/O4onHpJLmRev1/WwubQaRGUZEalSRWeSU0YF5dGpNSS iiHQ== X-Gm-Message-State: AC+VfDyRaVSlZDhevSXzipsmW/E4hW2AIaL1rGylZOE6NnIn0ugvvo8V p0ce5waOhQdc3SScj7wdZZNx5g== X-Received: by 2002:a5d:68cb:0:b0:2f0:2c3c:b858 with SMTP id p11-20020a5d68cb000000b002f02c3cb858mr6046924wrw.31.1682683344886; Fri, 28 Apr 2023 05:02:24 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id x8-20020a05600c21c800b003f2390bdd0csm15487607wmj.32.2023.04.28.05.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 05:02:24 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Qinglin Pan , Andrew Jones , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH -fixes 2/2] riscv: Implement missing huge_ptep_get Date: Fri, 28 Apr 2023 14:01:20 +0200 Message-Id: <20230428120120.21620-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230428120120.21620-1-alexghiti@rivosinc.com> References: <20230428120120.21620-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org huge_ptep_get must be reimplemented in order to go through all the PTEs of a NAPOT region: this is needed because the HW can update the A/D bits of any of the PTE that constitutes the NAPOT region. Fixes: f2aeb0118ddd ("riscv: mm: support Svnapot in hugetlb page") Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/hugetlb.h | 3 +++ arch/riscv/mm/hugetlbpage.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index fe6f23006641..ce1ebda1a49a 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -36,6 +36,9 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte, int dirty); +#define __HAVE_ARCH_HUGE_PTEP_GET +pte_t huge_ptep_get(pte_t *ptep); + pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags); #define arch_make_huge_pte arch_make_huge_pte diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index 238d00bdac14..e0ef56dc57b9 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -3,6 +3,30 @@ #include #ifdef CONFIG_RISCV_ISA_SVNAPOT +pte_t huge_ptep_get(pte_t *ptep) +{ + unsigned long pte_num; + int i; + pte_t orig_pte = ptep_get(ptep); + + if (!pte_present(orig_pte) || !pte_napot(orig_pte)) + return orig_pte; + + pte_num = napot_pte_num(napot_cont_order(orig_pte)); + + for (i = 0; i < pte_num; i++, ptep++) { + pte_t pte = ptep_get(ptep); + + if (pte_dirty(pte)) + orig_pte = pte_mkdirty(orig_pte); + + if (pte_young(pte)) + orig_pte = pte_mkyoung(orig_pte); + } + + return orig_pte; +} + pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, -- 2.37.2