From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932521AbcGLBbm (ORCPT ); Mon, 11 Jul 2016 21:31:42 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:3081 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751698AbcGLBbl (ORCPT ); Mon, 11 Jul 2016 21:31:41 -0400 Message-ID: <57844872.1060806@huawei.com> Date: Tue, 12 Jul 2016 09:31:30 +0800 From: Xishi Qiu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: "Kirill A. Shutemov" CC: , Linux MM , LKML Subject: Re: a question about protection_map[] References: <5783710E.3070602@huawei.com> <20160711133015.GA8028@node.shutemov.name> In-Reply-To: <20160711133015.GA8028@node.shutemov.name> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.25.179] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.57844879.0091,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: de3eed97340d260b4f21745e2606cc23 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2016/7/11 21:30, Kirill A. Shutemov wrote: > On Mon, Jul 11, 2016 at 06:12:30PM +0800, Xishi Qiu wrote: >> Hi, >> >> We can use mprotect to set read only or read/write. >> >> mprotect_fixup() >> vma_set_page_prot() >> vm_pgprot_modify() >> vm_get_page_prot() >> protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)] >> >> The following code shows that prots from __P001(PROT_READ) and __P010(PROT_WRITE) >> are the same, so how does it distinguish read only or read/write from mprotect? > > It doesn't. > > Write protection will be removed by fault handler on next write access to > the page. Somewhat suboptiomal, but zero page implemenation relies on this > to work properly. > Hi Kirill, I know, PAGE_READONLY and PAGE_COPY are both missed _PAGE_RW, so it will cause page fault, then we will set new prot flag from vma, right? Thanks, Xishi Qiu