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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F61FC3ABA9 for ; Tue, 29 Apr 2025 08:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WDoi6k7sqtgxQYJqKHtEcH9BVLqdMs88OozTGG6SCcE=; b=HRWDjqHv+gwQ0sclgMb6AIxZXG 29DQA1ddLvE0xPGluRDwIYO8/5ANf7pFxLnGIYNeqdeiW7j12oo2PxTmSiZ2kcIoe1chhQoV9fAX3 mbCgF+BzANhJYbGgeUGi8TOdGX2ieohXLT0AbITDJ9sOAdlNcHpdFCf1q7VDQBClkrHlM17ai+oWb Hc73XUI3hBqZwUnXkiyrDG6TxGKFyN3fNGOldzXIG3VlUYFgBAAvM7+kVSqN/FwdwHq1mlMmEmqnz Agnxyokue3g/nG8/p8EZIWvf4go0p/PauQ8aAHNzAvi47PJaCPeFTu7UaOk/YbySInWyXAI9UuyeM +cmHgV8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9gas-00000008zCS-40Fd; Tue, 29 Apr 2025 08:45:34 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9gVW-00000008yMM-0cRc for linux-arm-kernel@lists.infradead.org; Tue, 29 Apr 2025 08:40:07 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D69421515; Tue, 29 Apr 2025 01:39:53 -0700 (PDT) Received: from [10.163.52.122] (unknown [10.163.52.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 97EBB3F66E; Tue, 29 Apr 2025 01:39:50 -0700 (PDT) Message-ID: <93411699-2e36-4a4e-bc3a-3efeb8e2260b@arm.com> Date: Tue, 29 Apr 2025 14:09:46 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/7] mm: Add batched versions of ptep_modify_prot_start/commit To: Dev Jain , akpm@linux-foundation.org Cc: ryan.roberts@arm.com, david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, peterx@redhat.com, joey.gouly@arm.com, ioworker0@gmail.com, baohua@kernel.org, kevin.brodsky@arm.com, quic_zhenhuah@quicinc.com, christophe.leroy@csgroup.eu, yangyicong@hisilicon.com, linux-arm-kernel@lists.infradead.org, namit@vmware.com, hughd@google.com, yang@os.amperecomputing.com, ziy@nvidia.com References: <20250429052336.18912-1-dev.jain@arm.com> <20250429052336.18912-4-dev.jain@arm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20250429052336.18912-4-dev.jain@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_014002_238468_F53C50BF X-CRM114-Status: GOOD ( 18.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 4/29/25 10:53, Dev Jain wrote: > Batch ptep_modify_prot_start/commit in preparation for optimizing mprotect. > Architecture can override these helpers. > > Signed-off-by: Dev Jain > --- > include/linux/pgtable.h | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index b50447ef1c92..ed287289335f 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -891,6 +891,44 @@ static inline void wrprotect_ptes(struct mm_struct *mm, unsigned long addr, > } > #endif > > +/* See the comment for ptep_modify_prot_start */ > +#ifndef modify_prot_start_ptes > +static inline pte_t modify_prot_start_ptes(struct vm_area_struct *vma, > + unsigned long addr, pte_t *ptep, unsigned int nr) > +{ > + pte_t pte, tmp_pte; > + > + pte = ptep_modify_prot_start(vma, addr, ptep); > + while (--nr) { > + ptep++; > + addr += PAGE_SIZE; > + tmp_pte = ptep_modify_prot_start(vma, addr, ptep); > + if (pte_dirty(tmp_pte)) > + pte = pte_mkdirty(pte); > + if (pte_young(tmp_pte)) > + pte = pte_mkyoung(pte); > + } > + return pte; > +} > +#endif > + > +/* See the comment for ptep_modify_prot_commit */ > +#ifndef modify_prot_commit_ptes > +static inline void modify_prot_commit_ptes(struct vm_area_struct *vma, unsigned long addr, > + pte_t *ptep, pte_t old_pte, pte_t pte, unsigned int nr) > +{ > + for (;;) { > + ptep_modify_prot_commit(vma, addr, ptep, old_pte, pte); > + if (--nr == 0) > + break; > + ptep++; > + addr += PAGE_SIZE; > + old_pte = pte_next_pfn(old_pte); > + pte = pte_next_pfn(pte); > + } > +} > +#endif Is there any particular reason why the first loop here is while { } based where as the second one is a for { } loop ? > + > /* > * On some architectures hardware does not set page access bit when accessing > * memory page, it is responsibility of software setting this bit. It brings These helpers should be added with at least a single caller using them.