From patchwork Fri Aug 2 15:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13751652 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 4261DC52D6F for ; Fri, 2 Aug 2024 15:21:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D49346B0089; Fri, 2 Aug 2024 11:21:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF93F6B0093; Fri, 2 Aug 2024 11:21:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC1226B0099; Fri, 2 Aug 2024 11:21:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A105C6B0089 for ; Fri, 2 Aug 2024 11:21:47 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 546351C4480 for ; Fri, 2 Aug 2024 15:21:47 +0000 (UTC) X-FDA: 82407670254.18.8B0864F Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf10.hostedemail.com (Postfix) with ESMTP id 6394AC0029 for ; Fri, 2 Aug 2024 15:21:45 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="Ppzy/dJR"; dmarc=none; spf=pass (imf10.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722612062; a=rsa-sha256; cv=none; b=Wq4LayvrTdsK3EHpBiBXOhQb6EEGr0YAUMZxCWdN5Ru73J9ZJIr0VPHtxpakvxRDay+Sad upinJCbpARbxXuFttYe8IoANO77gwRsUlKtISmX8dibycTx+cR4/FZbrGnYX//+dKt4cj2 hvFbldZqBeCKYrhkiZZgmBV/CfcFqF8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="Ppzy/dJR"; dmarc=none; spf=pass (imf10.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.46 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=1722612062; 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=dJwxj4Q/epTCsuuoDx5TluW633PRo5bWcwGJkWSnI+E=; b=SGmTX3jP6Hclgwrh6C5/vMpj7h+KtfXPdxIkEAGBo2EjhqIYF7WBVYaZT1P8LKbJQqvoxI uJuGL4k4qs8qRPuJtSv7+YwhkauihZeYuDYN0cT1uCNSTXHftTP+rlm4GJrCxd9d1Cz67o vMvwtOQMuNE1rv58M1HiASR92rwTDYQ= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42816ca782dso54237795e9.2 for ; Fri, 02 Aug 2024 08:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722612104; x=1723216904; 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=dJwxj4Q/epTCsuuoDx5TluW633PRo5bWcwGJkWSnI+E=; b=Ppzy/dJRcKxZRp8ZPnSd268QxgJ0MsJQO0laJjHGbvSvrzGQfYb6P+f2EEvBma8VDb XkJZhW1+QM0MRIGdYUo2hCHkP+LvqflUVKHBLkYjC8uf5yT7ib97oM/BnKjgk6tG2RkU DtQBXxPZaUwF1s2CsYrXF6krc9vPKd8kKi30IPT8Iw86uc93X6jQB4eH7CVrpI2l80y3 GUUEaMPfkYkBlqnLkhJILQ/BbRwwLO39Ma145WX1dFXlwMM4jcc8jzb05C4uog7RP61x GdhJgxp4PCl9+2bc4D8BmJsFBJDpt/oEyfplUt2dyRQHChHF8xx2SshvJFcshpA9rh/9 QwMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722612104; x=1723216904; 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=dJwxj4Q/epTCsuuoDx5TluW633PRo5bWcwGJkWSnI+E=; b=gtHfR54GSblA8YZNcY/hOZQs/MiIGCToxjvqsdisMllLjoO3oY1l6rXiQBWt+Fq/4E N/F/7kO+ZJjSxbs9n71sLOxO9ry8KVyIaj3lbaUDzvbYUzlECNACBxxKYQy/B2uhLmbD QZd4TW+C1U5KtAk5QEwS2o7caM0UPXeZXWfA1El5x5S0Na+AbEJYAi12r6gAEkAomkiO djyHCx3fhfD/aw/6DXoyNDGZg1M10CmCP9wO5/mL9bBIK6lGAmdpS4xsRGwW7Xoy0LPg 1BWffDdMcgqQww7pyvsG0CF36iD1XUJVL03S9NlaZMl3T+x03k5bHCaU/r7E8rMQ0K/M UoRg== X-Forwarded-Encrypted: i=1; AJvYcCWjmiI9wGHFT04D0vPol+S9d53yvJmN0WenkUWzsQ6a1/O3PXx1zEtiHhu6pAi61SHY3Wx9x5yeYi0pakEEMRqhq64= X-Gm-Message-State: AOJu0Yxd1x50uzVPdqLHgn8q6dlaiPhzGZc/lrIOTbYEPX34myzsSy6k lZSFprpOwt6aK/vBJVCMveNcDyFAGkn4X5/9XLprnCbcSj/t7zfq8dbvUAf1BcE= X-Google-Smtp-Source: AGHT+IHs8c35/MVJPJWHbhThNLdZDWmclnMPyTlHp9e2Mj7pB+l3jgAdGFRRGTJ474zJ6huZaRujOg== X-Received: by 2002:a05:600c:a45:b0:428:1694:bd8c with SMTP id 5b1f17b1804b1-428e6b938dcmr22007775e9.37.1722612103839; Fri, 02 Aug 2024 08:21:43 -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-4282bb9d464sm98619985e9.42.2024.08.02.08.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 08:21:43 -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 v3 7/9] mm: Use common huge_ptep_set_access_flags() function for riscv/arm64 Date: Fri, 2 Aug 2024 17:14:28 +0200 Message-Id: <20240802151430.99114-8-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240802151430.99114-1-alexghiti@rivosinc.com> References: <20240802151430.99114-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6394AC0029 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: wx8d13y4hrxjdab9sz5odwdiidfanm8h X-HE-Tag: 1722612105-281742 X-HE-Meta: U2FsdGVkX1/32UT83lgue38ZVACsZgOX4RJocrl3jl6g58HTYV7BzNpMR5+08LPO08a8z5t2ThCZBtwg66DitE2HT2nje8JSgocD3vEkfUjdnYDr54clUbubP1a9j3pL8z8EFIJdspReF54gxe7wz1JQ9O4sQxZtviVgU6V7pL+kSKooBR5aESLCagavrKmTQmXvCnQN7j6LbQssB00/S4G9mPfNOtkuQKe+IYX0z2H0mqPMvXO1xq+93LeOfXxLDT27Z5rHilvVJrH9Nx6apqKmxURxbPi7clVkKNvu76120LDmaI4+Gpwp3FqsyLpYBmQkOA7xBI+j8V1J6EjGNp23ays14Pgm3LK13eNXMPC/eTs4j889XjLsvb0KQ4UuYKdsDM4OzzHkBLmorGjn9jTZnRu2o3WnBnAyrUPR4MUaTh2mYyfjRRg1zDCBJ1ZMMU+ptbtfWY4zJ7guASPtx+bADHm5AjdQqCaRy8kOJ+hD7UMQYEslHYCX7HaVGA96C+c1QqECnPTUGRrMRT9LISFsKdTgNBol6OJ6IQz2pktfrI9Qg8N2BKgYrYu9l4LdjURYNnzHQ/EDOi9OloHtlSwjqS5AI1PmM3lASmsiwv2BELmVK9JCYIJbYt4//EWAu8i4aZzNEEjbl3sdLjMVYjzZhx78Zp1vnX5kyf/BCHiYM4/b6Za/GWyVPDwaJPTCcti1TZ/dgahIdq9cy2562PaQAKg4NhQTfLyKiIf/qobCSZLVJGZwG59mfcl2EbAXWfHUq6eHw7l/qcLgKO4e7roh+BJ1+MW8zFV9h/n1JjcBiIm1juIzlEozYU+GZCtW8cHXJMGQGXIg0TLABxYlFa3shnrt8oHKpGdlE0oxg6+tHgBtmpnZ376AZlwC5dkdacZNyTCGd2yIbfjlFevLCy0wlnQpbGt5nQRifegTjKzIw+M7Q6dhhoF0AulCFvzsbxCD8cXe6trehdg/yXD 1riizJCQ /u7pGoRzvJUwuHCQTql3GODc5HvK5dgIQoKjWwjDJPEN5aAThB23414IBFGhSKJuftJ7ILqJ23XkaoSEo3HqjfeVD7pGWzGvLoDCOusa+STRMaQEYRemUw66zNEn2EzFH68bt4PgtvZXG1i53BoMZVGqpyH57Gwmr/iPZDS2PIW2KMQSpz7OX2JdsZ29pZ3uZhiXXKircfg02/9ZGJdCgBP7XDArVnpK3S+XHRlgzMQ+8opkewM5IsVRKJbrmhHfu71X5HPzSO/IUYdsKlL2NrUTAIMA6yncyfGwAHOFLukJD22Q+TCZ0HUpZfCSuXZQq1Kh/QbfqrxEewCb2ZTcReQgBUnsYnkC2KVO9sAuNsSGjFSuYC+o8ebKsVmnh1qbiJQbuQD99eUNN/zjw5M1I6dRWGQ== 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: Both architectures have almost the same implementation: __cont_access_flags_changed() is also correct on riscv and brings the same benefits (ie don't do anything if the flags are unchanged). As in the previous commit, get_clear_contig_flush() is duplicated in both the arch and the generic codes, it will be removed from the arch code when the last reference there gets moved to the generic code. Signed-off-by: Alexandre Ghiti --- arch/arm64/include/asm/hugetlb.h | 4 -- arch/arm64/mm/hugetlbpage.c | 65 --------------------------- arch/riscv/include/asm/hugetlb.h | 5 --- arch/riscv/include/asm/pgtable.h | 7 +-- arch/riscv/mm/hugetlbpage.c | 28 ------------ arch/riscv/mm/pgtable.c | 6 +-- include/linux/hugetlb_contpte.h | 5 +++ mm/hugetlb_contpte.c | 75 ++++++++++++++++++++++++++++++++ 8 files changed, 87 insertions(+), 108 deletions(-) diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index 04117a84dc04..6b84e287b72d 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -27,10 +27,6 @@ static inline void arch_clear_hugetlb_flags(struct folio *folio) 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 -#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS -extern 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_SET_WRPROTECT extern void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep); diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 2f3753c10c1f..658635022e4d 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -266,71 +266,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -/* - * huge_ptep_set_access_flags will update access flags (dirty, accesssed) - * and write permission. - * - * For a contiguous huge pte range we need to check whether or not write - * permission has to change only on the first pte in the set. Then for - * all the contiguous ptes we need to check whether or not there is a - * discrepancy between dirty or young. - */ -static int __cont_access_flags_changed(pte_t *ptep, pte_t pte, int ncontig) -{ - int i; - - if (pte_write(pte) != pte_write(__ptep_get(ptep))) - return 1; - - for (i = 0; i < ncontig; i++) { - pte_t orig_pte = __ptep_get(ptep + i); - - if (pte_dirty(pte) != pte_dirty(orig_pte)) - return 1; - - if (pte_young(pte) != pte_young(orig_pte)) - return 1; - } - - return 0; -} - -int huge_ptep_set_access_flags(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep, - pte_t pte, int dirty) -{ - int ncontig, i; - size_t pgsize = 0; - unsigned long pfn = pte_pfn(pte), dpfn; - struct mm_struct *mm = vma->vm_mm; - pgprot_t hugeprot; - pte_t orig_pte; - - if (!pte_cont(pte)) - return __ptep_set_access_flags(vma, addr, ptep, pte, dirty); - - ncontig = find_num_contig(mm, addr, ptep, &pgsize); - dpfn = pgsize >> PAGE_SHIFT; - - if (!__cont_access_flags_changed(ptep, pte, ncontig)) - return 0; - - orig_pte = get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); - - /* Make sure we don't lose the dirty or young state */ - if (pte_dirty(orig_pte)) - pte = pte_mkdirty(pte); - - if (pte_young(orig_pte)) - pte = pte_mkyoung(pte); - - hugeprot = pte_pgprot(pte); - for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn) - __set_ptes(mm, addr, ptep, pfn_pte(pfn, hugeprot), 1); - - return 1; -} - void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index 0fbb6b19df79..bf533c2cef84 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -28,11 +28,6 @@ pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS -int huge_ptep_set_access_flags(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep, - pte_t pte, int dirty); - 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/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 13e89348a46a..5d9b051ac51c 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -623,9 +623,8 @@ static inline void __pte_clear(struct mm_struct *mm, __set_pte_at(mm, ptep, __pte(0)); } -#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS /* defined in mm/pgtable.c */ -extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, - pte_t *ptep, pte_t entry, int dirty); +extern int __ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, pte_t entry, int dirty); #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG /* defined in mm/pgtable.c */ extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address, pte_t *ptep); @@ -734,6 +733,8 @@ static inline pte_t ptep_get(pte_t *ptep) #define __HAVE_ARCH_PTEP_GET_AND_CLEAR #define ptep_get_and_clear __ptep_get_and_clear #define pte_clear __pte_clear +#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS +#define ptep_set_access_flags __ptep_set_access_flags #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 b44023336fd9..0e2ca7327479 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -173,34 +173,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -int huge_ptep_set_access_flags(struct vm_area_struct *vma, - unsigned long addr, - pte_t *ptep, - pte_t pte, - int dirty) -{ - struct mm_struct *mm = vma->vm_mm; - pte_t orig_pte; - int pte_num; - - if (!pte_napot(pte)) - return ptep_set_access_flags(vma, addr, ptep, pte, dirty); - - pte_num = arch_contpte_get_num_contig(vma->vm_mm, addr, ptep, 0, NULL); - - orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num); - - if (pte_dirty(orig_pte)) - pte = pte_mkdirty(pte); - - if (pte_young(orig_pte)) - pte = pte_mkyoung(pte); - - set_ptes(mm, addr, ptep, pte, pte_num); - - return true; -} - void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c index 533ec9055fa0..e86df7ef193c 100644 --- a/arch/riscv/mm/pgtable.c +++ b/arch/riscv/mm/pgtable.c @@ -5,9 +5,9 @@ #include #include -int ptep_set_access_flags(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep, - pte_t entry, int dirty) +int __ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, + pte_t entry, int dirty) { if (!pte_same(ptep_get(ptep), entry)) __set_pte_at(vma->vm_mm, ptep, entry); diff --git a/include/linux/hugetlb_contpte.h b/include/linux/hugetlb_contpte.h index 20d3a3e14e14..fea47035ac38 100644 --- a/include/linux/hugetlb_contpte.h +++ b/include/linux/hugetlb_contpte.h @@ -22,4 +22,9 @@ extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr, extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); +#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS +extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t pte, int dirty); + #endif /* _LINUX_HUGETLB_CONTPTE_H */ diff --git a/mm/hugetlb_contpte.c b/mm/hugetlb_contpte.c index 9df98d1a59a1..21f5c89daa6b 100644 --- a/mm/hugetlb_contpte.c +++ b/mm/hugetlb_contpte.c @@ -13,6 +13,7 @@ * - __set_ptes() * - __ptep_get_and_clear() * - __pte_clear() + * - __ptep_set_access_flags() * - pte_cont() * - arch_contpte_get_num_contig() */ @@ -23,6 +24,7 @@ * - set_huge_pte_at() * - huge_pte_clear() * - huge_ptep_get_and_clear() + * - huge_ptep_set_access_flags() */ pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep) @@ -157,3 +159,76 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm, return get_clear_contig(mm, addr, ptep, pgsize, ncontig); } + +/* + * huge_ptep_set_access_flags will update access flags (dirty, accesssed) + * and write permission. + * + * For a contiguous huge pte range we need to check whether or not write + * permission has to change only on the first pte in the set. Then for + * all the contiguous ptes we need to check whether or not there is a + * discrepancy between dirty or young. + */ +static int __cont_access_flags_changed(pte_t *ptep, pte_t pte, int ncontig) +{ + int i; + + if (pte_write(pte) != pte_write(__ptep_get(ptep))) + return 1; + + for (i = 0; i < ncontig; i++) { + pte_t orig_pte = __ptep_get(ptep + i); + + if (pte_dirty(pte) != pte_dirty(orig_pte)) + return 1; + + if (pte_young(pte) != pte_young(orig_pte)) + return 1; + } + + return 0; +} + +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; +} + +int huge_ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t pte, int dirty) +{ + int ncontig; + size_t pgsize = 0; + struct mm_struct *mm = vma->vm_mm; + pte_t orig_pte; + + if (!pte_cont(pte)) + return __ptep_set_access_flags(vma, addr, ptep, pte, dirty); + + ncontig = arch_contpte_get_num_contig(vma->vm_mm, addr, ptep, 0, &pgsize); + + if (!__cont_access_flags_changed(ptep, pte, ncontig)) + return 0; + + orig_pte = get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); + + /* Make sure we don't lose the dirty or young state */ + if (pte_dirty(orig_pte)) + pte = pte_mkdirty(pte); + + if (pte_young(orig_pte)) + pte = pte_mkyoung(pte); + + set_contptes(mm, addr, ptep, pte, ncontig, pgsize); + + return 1; +}