Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3025186ybk; Mon, 18 May 2020 13:59:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmfVXYFGzefuwO2zsxABB706TY8nvSAJfvvSumIXppoGUBti++C9BxGKzEX2ECmzPTvTIy X-Received: by 2002:a17:906:19d2:: with SMTP id h18mr17278806ejd.147.1589835583413; Mon, 18 May 2020 13:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589835583; cv=none; d=google.com; s=arc-20160816; b=VRWtJEFoEX0PdBDEOWbClRE2TTJuDwHv1k8Y6+LwDlsAHSOkgRCje9JiEmJBnkU/Ha rn39v1raKVen34b+bM9AZlGx90bWyuIT5DgQkYapL6TleUZUzUaxOqWfiBdT1tVxwpnS hENcJ6llykVsuaX8I3V4q+EsccL5XoFYwIRudwGoHtezocDrnUsaiI3AtK8PFLwKLUUB EPOS7LRu0mnDl4J66kiRkMnrvyPnDZWLCpfJGW0X7VByvn/uYX9sP/cnHqVf0L69Wr9N MfUYtUsFfsMPtqV+vO+RXcll5sxq2M+9cWDTqsjjVn/EW2OZlo0nqur1plMSCqvmIuyY uMOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=IMSQ2H2jSXWauUBkUXi/O1cTkYfG5cKzQ8WdlxN0DpM=; b=WIjQpUviOtwC8L6N1pJEI1dz0rcIvldTtwzVDZyl6yxJIJAA7Wykp94d5b6dO1wNfX xZ/F1VHHv2VFRjI+AOuJ/Wbs0DfpfxWhNvQ6gCKZ95sfGXhS/vX+MBf1kW7vwpqsjAev LftfZG4ENnAY2yPcFqkD/ggtS2Py1Q3nWt72J9ZO+uiQv3LLPx/IJv8VaEb/BBRA7q0a GZLL8SiBp/7uXF74eKRZAZw05S8F/v9kzgENdBFk0csYwkHdqt/UE4e9gEY7T3/cYCIj lWVvkex5VWssuJ69sue2N27TLv2nQLlSZs2ykEl+/iMAe5w6hDrxnNdvW6sIUPx5Tkcn A6+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LrMMimDm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si7380736edj.235.2020.05.18.13.59.19; Mon, 18 May 2020 13:59:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LrMMimDm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727831AbgERU5t (ORCPT + 99 others); Mon, 18 May 2020 16:57:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:36556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbgERU5t (ORCPT ); Mon, 18 May 2020 16:57:49 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EEF9420756; Mon, 18 May 2020 20:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589835468; bh=yFKL6q0Ss/A6Efr5StLQDz3hK+V4GQL8fArvDWrB8Iw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LrMMimDmiD2wKcJAwj8KJkVTOLP7zSYVhM0nSgkv2dxAoziNsQtUCrv+e6Ygu2g7v HTQD6cDF7KorRQxy+qKJWsPpx7dcdp/nanguSzYFJgrd4P/bJxRDyBCGFgNp0xWmrJ ajuEkib91P8ef9WiGs4TMRVcr84hLgRV9Z4IN3Iw= Date: Mon, 18 May 2020 13:57:47 -0700 From: Andrew Morton To: Bibo Mao Cc: Thomas Bogendoerfer , Jiaxun Yang , Huacai Chen , Paul Burton , Dmitry Korotin , Philippe =?ISO-8859-1?Q?Mathieu-Daud=E9?= , Stafford Horne , Steven Price , Anshuman Khandual , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , Sergei Shtylyov , "Maciej W. Rozycki" , linux-mm@kvack.org, David Hildenbrand Subject: Re: [PATCH v3 3/3] mm/memory.c: Add memory read privilege before filling PTE entry Message-Id: <20200518135747.d8837ba6742b2d193e14fbb0@linux-foundation.org> In-Reply-To: <1589778529-25627-3-git-send-email-maobibo@loongson.cn> References: <1589778529-25627-1-git-send-email-maobibo@loongson.cn> <1589778529-25627-3-git-send-email-maobibo@loongson.cn> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 18 May 2020 13:08:49 +0800 Bibo Mao wrote: > On mips platform, hw PTE entry valid bit is set in pte_mkyoung > function, it is used to set physical page with readable privilege. pte_mkyoung() seems to be a strange place to set the pte's valid bit. Why is it done there? Can it be done within mips's mk_pte()? > Here add pte_mkyoung function to make page readable on MIPS platform > during page fault handling. This patch improves page fault latency > about 10% on my MIPS machine with lmbench lat_pagefault case. > > ... > > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2704,6 +2704,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) > } > flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); > entry = mk_pte(new_page, vma->vm_page_prot); > + entry = pte_mkyoung(entry); > entry = maybe_mkwrite(pte_mkdirty(entry), vma); What is the effect on non-mips machines? If it's only "additional overhead" then it would be better to add a new pte_mkvalid() (or whatever) and arrange for it to be a no-op on all but mips? > /* > * Clear the pte entry and flush it first, before updating the > @@ -3378,6 +3379,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > __SetPageUptodate(page); > > entry = mk_pte(page, vma->vm_page_prot); > + entry = pte_mkyoung(entry); > if (vma->vm_flags & VM_WRITE) > entry = pte_mkwrite(pte_mkdirty(entry)); > > @@ -3660,6 +3662,7 @@ vm_fault_t alloc_set_pte(struct vm_fault *vmf, struct mem_cgroup *memcg, > > flush_icache_page(vma, page); > entry = mk_pte(page, vma->vm_page_prot); > + entry = pte_mkyoung(entry); > if (write) > entry = maybe_mkwrite(pte_mkdirty(entry), vma); > /* copy-on-write page */ > diff --git a/mm/mprotect.c b/mm/mprotect.c > index 494192ca..673f1cd 100644 > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -131,6 +131,8 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, > ptent = pte_clear_uffd_wp(ptent); > } > > + if (vma->vm_flags & VM_READ) > + ptent = pte_mkyoung(ptent); > /* Avoid taking write faults for known dirty pages */ > if (dirty_accountable && pte_dirty(ptent) && > (pte_soft_dirty(ptent) ||