From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk0-f71.google.com (mail-vk0-f71.google.com [209.85.213.71]) by kanga.kvack.org (Postfix) with ESMTP id 57FF36B0005 for ; Mon, 11 Jul 2016 06:20:37 -0400 (EDT) Received: by mail-vk0-f71.google.com with SMTP id f7so215601036vkb.3 for ; Mon, 11 Jul 2016 03:20:37 -0700 (PDT) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com. [119.145.14.65]) by mx.google.com with ESMTP id 22si1210132qtq.132.2016.07.11.03.20.35 for ; Mon, 11 Jul 2016 03:20:36 -0700 (PDT) Message-ID: <5783710E.3070602@huawei.com> Date: Mon, 11 Jul 2016 18:12:30 +0800 From: Xishi Qiu MIME-Version: 1.0 Subject: a question about protection_map[] Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: alan@lxorguk.ukuu.org.uk Cc: Linux MM , LKML 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? pgprot_t protection_map[16] = { __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 }; #define __P001 PAGE_READONLY #define __P010 PAGE_COPY #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | \ _PAGE_ACCESSED | _PAGE_NX) #define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \ _PAGE_ACCESSED | _PAGE_NX) #define PAGE_COPY PAGE_COPY_NOEXEC Thanks, Xishi Qiu -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f71.google.com (mail-lf0-f71.google.com [209.85.215.71]) by kanga.kvack.org (Postfix) with ESMTP id 06CF76B0005 for ; Mon, 11 Jul 2016 09:30:20 -0400 (EDT) Received: by mail-lf0-f71.google.com with SMTP id p41so16945823lfi.0 for ; Mon, 11 Jul 2016 06:30:19 -0700 (PDT) Received: from mail-lf0-x231.google.com (mail-lf0-x231.google.com. [2a00:1450:4010:c07::231]) by mx.google.com with ESMTPS id l16si1927892lfi.366.2016.07.11.06.30.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2016 06:30:18 -0700 (PDT) Received: by mail-lf0-x231.google.com with SMTP id q132so73402132lfe.3 for ; Mon, 11 Jul 2016 06:30:18 -0700 (PDT) Date: Mon, 11 Jul 2016 16:30:15 +0300 From: "Kirill A. Shutemov" Subject: Re: a question about protection_map[] Message-ID: <20160711133015.GA8028@node.shutemov.name> References: <5783710E.3070602@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5783710E.3070602@huawei.com> Sender: owner-linux-mm@kvack.org List-ID: To: Xishi Qiu Cc: alan@lxorguk.ukuu.org.uk, Linux MM , LKML 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. -- Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by kanga.kvack.org (Postfix) with ESMTP id E22796B0253 for ; Mon, 11 Jul 2016 21:34:56 -0400 (EDT) Received: by mail-oi0-f72.google.com with SMTP id q62so3082143oih.0 for ; Mon, 11 Jul 2016 18:34:56 -0700 (PDT) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com. [58.251.152.64]) by mx.google.com with ESMTPS id w142si180782oia.276.2016.07.11.18.34.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Jul 2016 18:34:56 -0700 (PDT) Message-ID: <57844872.1060806@huawei.com> Date: Tue, 12 Jul 2016 09:31:30 +0800 From: Xishi Qiu MIME-Version: 1.0 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 Sender: owner-linux-mm@kvack.org List-ID: To: "Kirill A. Shutemov" Cc: alan@lxorguk.ukuu.org.uk, Linux MM , LKML 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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f69.google.com (mail-wm0-f69.google.com [74.125.82.69]) by kanga.kvack.org (Postfix) with ESMTP id 5CFD56B025F for ; Mon, 11 Jul 2016 21:46:54 -0400 (EDT) Received: by mail-wm0-f69.google.com with SMTP id r190so2707481wmr.0 for ; Mon, 11 Jul 2016 18:46:54 -0700 (PDT) Received: from mail-lf0-x22d.google.com (mail-lf0-x22d.google.com. [2a00:1450:4010:c07::22d]) by mx.google.com with ESMTPS id 81si12768214ljf.14.2016.07.11.18.46.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2016 18:46:52 -0700 (PDT) Received: by mail-lf0-x22d.google.com with SMTP id q132so1053088lfe.3 for ; Mon, 11 Jul 2016 18:46:52 -0700 (PDT) Date: Tue, 12 Jul 2016 04:46:50 +0300 From: "Kirill A. Shutemov" Subject: Re: a question about protection_map[] Message-ID: <20160712014650.GA18041@node> References: <5783710E.3070602@huawei.com> <20160711133015.GA8028@node.shutemov.name> <57844872.1060806@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57844872.1060806@huawei.com> Sender: owner-linux-mm@kvack.org List-ID: To: Xishi Qiu Cc: alan@lxorguk.ukuu.org.uk, Linux MM , LKML On Tue, Jul 12, 2016 at 09:31:30AM +0800, Xishi Qiu wrote: > 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? Yes. See wp_page_reuse(). -- Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758267AbcGKKM6 (ORCPT ); Mon, 11 Jul 2016 06:12:58 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:53170 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758218AbcGKKMx (ORCPT ); Mon, 11 Jul 2016 06:12:53 -0400 Message-ID: <5783710E.3070602@huawei.com> Date: Mon, 11 Jul 2016 18:12: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: CC: Linux MM , LKML Subject: a question about protection_map[] 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.57837117.001A,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: e9b024b317ce8934c49506716f34b74a Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? pgprot_t protection_map[16] = { __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 }; #define __P001 PAGE_READONLY #define __P010 PAGE_COPY #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | \ _PAGE_ACCESSED | _PAGE_NX) #define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \ _PAGE_ACCESSED | _PAGE_NX) #define PAGE_COPY PAGE_COPY_NOEXEC Thanks, Xishi Qiu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758872AbcGKNaV (ORCPT ); Mon, 11 Jul 2016 09:30:21 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:36337 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751565AbcGKNaT (ORCPT ); Mon, 11 Jul 2016 09:30:19 -0400 Date: Mon, 11 Jul 2016 16:30:15 +0300 From: "Kirill A. Shutemov" To: Xishi Qiu Cc: alan@lxorguk.ukuu.org.uk, Linux MM , LKML Subject: Re: a question about protection_map[] Message-ID: <20160711133015.GA8028@node.shutemov.name> References: <5783710E.3070602@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5783710E.3070602@huawei.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Kirill A. Shutemov 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932672AbcGLBqz (ORCPT ); Mon, 11 Jul 2016 21:46:55 -0400 Received: from mail-lf0-f52.google.com ([209.85.215.52]:33024 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932129AbcGLBqy (ORCPT ); Mon, 11 Jul 2016 21:46:54 -0400 Date: Tue, 12 Jul 2016 04:46:50 +0300 From: "Kirill A. Shutemov" To: Xishi Qiu Cc: alan@lxorguk.ukuu.org.uk, Linux MM , LKML Subject: Re: a question about protection_map[] Message-ID: <20160712014650.GA18041@node> References: <5783710E.3070602@huawei.com> <20160711133015.GA8028@node.shutemov.name> <57844872.1060806@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57844872.1060806@huawei.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2016 at 09:31:30AM +0800, Xishi Qiu wrote: > 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? Yes. See wp_page_reuse(). -- Kirill A. Shutemov