From mboxrd@z Thu Jan 1 00:00:00 1970 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 5AD10C433EF for ; Sun, 8 May 2022 13:15:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9A556B0072; Sun, 8 May 2022 09:15:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C49096B0073; Sun, 8 May 2022 09:15:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B10F36B0074; Sun, 8 May 2022 09:15:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A25F56B0072 for ; Sun, 8 May 2022 09:15:09 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76B10B2C for ; Sun, 8 May 2022 13:15:09 +0000 (UTC) X-FDA: 79442621538.29.E2C98EB Received: from out203-205-221-210.mail.qq.com (out203-205-221-210.mail.qq.com [203.205.221.210]) by imf18.hostedemail.com (Postfix) with ESMTP id D38991C0042 for ; Sun, 8 May 2022 13:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1652015701; bh=epFvnBFt+8HAM8RAr630RFgNW+v7xLmsHNe6Vg8Vo00=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dt0+dt7JiZFdoS8HbZUMwHbBWibaYXoLn8ZuaNGoA7bghnCSDbqoC6cRNTzvGwP+5 5612bFYx7Frc79A11na4B6b2AtaV+YFH0VZZhkr1gEtH0BB3wixRePdrKFRhXhBJeg fOtgpwP8+XqKDD89/iAhbanQSoT98WSe7B6EXv0U= Received: from fyin-linux.localnet ([101.228.227.122]) by newxmesmtplogicsvrszc9.qq.com (NewEsmtp) with SMTP id 3BA36278; Sun, 08 May 2022 21:14:58 +0800 X-QQ-mid: xmsmtpt1652015698tpbnsa0d3 Message-ID: X-QQ-XMAILINFO: NiDupExshEc7dDqEAK/EV/+ASXjIqSq6o8PNi9ynuEPOZOeGLKk7gDdnmwtVY3 8fNxj9XfRDXagxfsD8BnHa/+PpUy/9HW2bUcThrxmSUxpK/SGlyc/xlEjnnuWdYgF4+L13zDLawQ EST3VUxKv0ZD08TyTfh9pkM5OF08eAPh2nVlHPgwYfGy4pXyeN0ar9cWjuprSoq5xLmJggK8kBHc TDVindQlOlbr/XMOxP9pbZSikXlNImFkm0XDALNY9/YrHDQWk6Pk7uzINXLWB2NmJX2V8mdactBl 5D7mkca46LBZe3kBLlPI5fPJt0HnqjIBeLucNoEL13tw5LrJfI2tSjk+4Oe9gHrlbf7MuanltXr1 YIgCnR8ateig2LMVHJCkba2/C7NaQDgitqK9K9ocZZjxA5FkQ4GTZbusdKd8DXwSsUq9S/sXrXUy YhrAuXLvZAk7+stlVoSSWOCA2o/YpfV4dlJtIXF3WykQSlowx5LggUOccwDJyN6RmEVjOyUVac+H RDOEXHgLyovF5PlCG8WdD1HtoWGoJPs1RjFO3u2lKiREEkrQrwWlMSV6qQfY3AJYjP1z69P5N/Pf TA3+FrBih/KxfP5WlWMTvaLG6AYk971xKjI/xz/ad8aIFA1ng3njP+NfzeYD19NsLxBdqFqfGF40 8Cwfq7VxmDqUu8tnSgaANd46ZBbErc7Ga89wOGwUtWWPcjKIlWHuNIlx1il14eOqH9RRtqDU0Oqq aUVxDSYHj1/QtQ3Ugmo47YQTBqVnsc5ssQnxDWUt/msEw8/1ZuPAQPOa2e8p7w9Mv7ma5abFLX2/ dTD4cilHsdyy+fQwsMCQ00L+JRsdGhA1oOW30Js+ppHh7CXZmOP3Z6PacH2SFjhSxyfcIflWUj8J 12tnpjWWnD From: nh26223@qq.com To: catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, mike.kravetz@oracle.com, akpm@linux-foundation.org, sj@kernel.org, Baolin Wang Cc: baolin.wang@linux.alibaba.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH 1/3] arm64/hugetlb: Introduce new huge_ptep_get_access_flags() interface Date: Sun, 08 May 2022 21:14:58 +0800 X-OQ-MSGID: <7909541.4c64ST1Ond@fyin-linux> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=dt0+dt7J; spf=pass (imf18.hostedemail.com: domain of nh26223@qq.com designates 203.205.221.210 as permitted sender) smtp.mailfrom=nh26223@qq.com; dmarc=pass (policy=quarantine) header.from=qq.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D38991C0042 X-Stat-Signature: 3tka5ddcthztg9wowncxnois5bpf5rt3 X-HE-Tag: 1652015698-923356 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: On 2022=E5=B9=B45=E6=9C=888=E6=97=A5=E6=98=9F=E6=9C=9F=E6=97=A5 CST =E4=B8= =8B=E5=8D=884:58:52 Baolin Wang wrote: > Now we use huge_ptep_get() to get the pte value of a hugetlb page, > however it will only return one specific pte value for the CONT-PTE > or CONT-PMD size hugetlb on ARM64 system, which can contain seravel > continuous pte or pmd entries with same page table attributes. And it > will not take into account the subpages' dirty or young bits of a > CONT-PTE/PMD size hugetlb page. >=20 > So the huge_ptep_get() is inconsistent with huge_ptep_get_and_clear(), > which already takes account the dirty or young bits for any subpages > in this CONT-PTE/PMD size hugetlb [1]. Meanwhile we can miss dirty or > young flags statistics for hugetlb pages with current huge_ptep_get(), > such as the gather_hugetlb_stats() function. >=20 > Thus introduce a new huge_ptep_get_access_flags() interface and define > an ARM64 specific implementation, that will take into account any subpage= s' > dirty or young bits for CONT-PTE/PMD size hugetlb page, for those functio= ns > that want to check the dirty and young flags of a hugetlb page. >=20 > [1] > https://lore.kernel.org/linux-mm/85bd80b4-b4fd-0d3f-a2e5-149559f2f387@ora= cl > e.com/ >=20 > Signed-off-by: Baolin Wang > --- > arch/arm64/include/asm/hugetlb.h | 2 ++ > arch/arm64/mm/hugetlbpage.c | 24 ++++++++++++++++++++++++ > include/asm-generic/hugetlb.h | 7 +++++++ > 3 files changed, 33 insertions(+) >=20 > diff --git a/arch/arm64/include/asm/hugetlb.h > b/arch/arm64/include/asm/hugetlb.h index 616b2ca..a473544 100644 > --- a/arch/arm64/include/asm/hugetlb.h > +++ b/arch/arm64/include/asm/hugetlb.h > @@ -44,6 +44,8 @@ extern pte_t huge_ptep_clear_flush(struct vm_area_struct > *vma, #define __HAVE_ARCH_HUGE_PTE_CLEAR > extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr, > pte_t *ptep, unsigned long sz); > +#define __HAVE_ARCH_HUGE_PTEP_GET_ACCESS_FLAGS > +extern pte_t huge_ptep_get_access_flags(pte_t *ptep, unsigned long sz); > extern void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long add= r, > pte_t *ptep, pte_t pte, unsigned long=20 sz); > #define set_huge_swap_pte_at set_huge_swap_pte_at > diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c > index ca8e65c..ce39699 100644 > --- a/arch/arm64/mm/hugetlbpage.c > +++ b/arch/arm64/mm/hugetlbpage.c > @@ -158,6 +158,30 @@ static inline int num_contig_ptes(unsigned long size, > size_t *pgsize) return contig_ptes; > } >=20 > +pte_t huge_ptep_get_access_flags(pte_t *ptep, unsigned long sz) The function name looks to me that it returns access flags of PTE. > +{ > + int ncontig, i; > + size_t pgsize; > + pte_t orig_pte =3D ptep_get(ptep); > + > + if (!pte_cont(orig_pte)) > + return orig_pte; > + > + ncontig =3D num_contig_ptes(sz, &pgsize); > + > + for (i =3D 0; i < ncontig; i++, ptep++) { > + pte_t pte =3D ptep_get(ptep); > + > + if (pte_dirty(pte)) > + orig_pte =3D pte_mkdirty(orig_pte); > + > + if (pte_young(pte)) > + orig_pte =3D pte_mkyoung(orig_pte); > + } > + > + return orig_pte; > +} Not sure whether it's worthy being changed to: bool dirty =3D false, young =3D false; for (i =3D 0; i < ncontig; i++, ptep++) { pte_t pte =3D ptep_get(ptep); if (pte_dirty(pte)) dirty =3D true; if (pte_young(pte)) young =3D true; if (dirty && young) break; } if (dirty) orig_pte =3D pte_mkdirty(orig_pte); if (young) orig_pte =3D pte_mkyoung(orit_pte); return orig_pte; > + > /* > * Changing some bits of contiguous entries requires us to follow a > * Break-Before-Make approach, breaking the whole contiguous set > diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h > index a57d667..bb77fb0 100644 > --- a/include/asm-generic/hugetlb.h > +++ b/include/asm-generic/hugetlb.h > @@ -150,6 +150,13 @@ static inline pte_t huge_ptep_get(pte_t *ptep) > } > #endif >=20 > +#ifndef __HAVE_ARCH_HUGE_PTEP_GET_ACCESS_FLAGS > +static inline pte_t huge_ptep_get_access_flags(pte_t *ptep, unsigned long > sz) +{ > + return ptep_get(ptep); Should be: return huge_ptep_get(ptep) ? Regards Yin, Fengwei > +} > +#endif > + > #ifndef __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED > static inline bool gigantic_page_runtime_supported(void) > {