From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47D6A2741CC for ; Tue, 29 Apr 2025 08:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745916003; cv=none; b=Sf8InK0wjSwL/NNAD4tnCz7pMll1Ys9rSFDx9mMznLY1IdWsV3IVtI7JleFcfDQ8VfoR3wttwEPh0cyTPzSGduqf3pjToF6ouI4Pc15EmCgaFYYrGFgkQxFNaQONne3Or6bWKBnRO59GW1t7x0xmPEvThluVxfnbV6d8BoyJVfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745916003; c=relaxed/simple; bh=M1c6jlLbe4Ax87QcLh2zMwyAKz1WIbajcF4qOaYlfoI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ncroVpXA2puGx43sTjDg8dZT1drWlmyxpqsfgeMeJq5eqyVVya+pxdOtdqvB53FK9yNk4XQTlh8dkLkYX4oyhGZ6PQMSEORxszSXre6psrGSHgwdQqbEtIW1h+pzGZUjsaQ+Gj5iHvlfAqXH3DzdhXt3DgODwc/ZV5EXHQFPKzY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.