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 X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9630EC433C1 for ; Tue, 23 Mar 2021 02:48:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 276C36191F for ; Tue, 23 Mar 2021 02:48:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 276C36191F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8ED596B011B; Mon, 22 Mar 2021 22:48:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89E556B0131; Mon, 22 Mar 2021 22:48:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 718396B0138; Mon, 22 Mar 2021 22:48:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id 53C296B011B for ; Mon, 22 Mar 2021 22:48:10 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 18E7218021B82 for ; Tue, 23 Mar 2021 02:48:10 +0000 (UTC) X-FDA: 77949604740.19.4CDB3D0 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf23.hostedemail.com (Postfix) with ESMTP id 44EADA0000FC for ; Tue, 23 Mar 2021 02:48:09 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id u19so10245429pgh.10 for ; Mon, 22 Mar 2021 19:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UVzK1Lu9V581sbflxnU+woWz13QCeLb0leH55CLeWYw=; b=nGanR4KeudMZ0LjbytrBwDCLDpehXrSeYAESc7Ja+c3IlC7g4ol+nch9rdL6+hxCJa Wj0iZToOYKddaDtQYMFd49RpVgQdqZz7imVrKPzuuhjXM5elMdokCJpKM1KPOjV1rlCp N6lRnKoD2mlfRRtUy2xIdR1cP/x/wzqg/b1vOAWNtBDqlAXDKZ2+6MYz5CfeZrjZrWzI G0V1vs498BbCNp2kiApaCQbCd5P2ORez+/vzze+uRxb+W7nsn9+TEZ1sDl90xPlTh+8b Vn1FKHJm5/up7lcBdhBvW6xmwvL2Wzbb3me1lLX34aNiJ3+lOK0oDTfDWeJnknqpWxOL ZsFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UVzK1Lu9V581sbflxnU+woWz13QCeLb0leH55CLeWYw=; b=ULZHqCvjLUiA4o6EF3NKqhejrcaRmk+QYnvuCIhn1UhsbbX16uJ4T8BwX9sJ6Btk9v 7h5Tzav2CdiXpqasC46zmZExXcdYdEVoxgJySYJjM5abkEtSkU6iJ0fhuT11Oci93mzz CeM9ln+3Z+izTE1Ppc101M4cH90Kkcz2vcsgnF1yVUxNW8n9ko9euQQipN5Zakg4R06f KbKAIQJUHOG7fN/br3z1cnfg1jpHAsOyFHpo+6f/B6WkRqeer1MBBnSND9ER1K5tn5O5 UIgAr22MQW4O9jxnC8NKlpzVjt5IfP0BbPSgZdf6W7/lVM1W1XuTjLncmAWZAFmNNn7N C0Tw== X-Gm-Message-State: AOAM532L/CGI96DRg3kc4oYg/vXHEgr9XYBwMYu2xCKM5pHLjrIJd0Jz rx/3dGLn+nBfMf9uJ6csLec= X-Google-Smtp-Source: ABdhPJwVR1tBgyGmBdToVxYt/amDpbqwAFNDUF7uS1vL51UTFuWe010hqQXSrBYVIrkEyGhIKg0vmw== X-Received: by 2002:a63:4b5e:: with SMTP id k30mr2045826pgl.130.1616467688614; Mon, 22 Mar 2021 19:48:08 -0700 (PDT) Received: from local ([113.172.241.1]) by smtp.gmail.com with ESMTPSA id b186sm15425399pfb.170.2021.03.22.19.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 19:48:08 -0700 (PDT) Date: Tue, 23 Mar 2021 09:48:03 +0700 From: Bui Quang Minh To: Mike Rapoport Cc: Michal Hocko , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrea Arcangeli , Peter Xu Subject: Re: [PATCH] userfaultfd: Write protect when virtual memory range has no page table entry Message-ID: <20210323024803.GA3365@local> References: <20210319152428.52683-1-minhquangbui99@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: iqrjumdjfnb4fexmgp3s65kw43qwb91s X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 44EADA0000FC Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail-pg1-f181.google.com; client-ip=209.85.215.181 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616467689-316089 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Mar 22, 2021 at 03:00:37PM +0200, Mike Rapoport wrote: > On Mon, Mar 22, 2021 at 11:14:37AM +0100, Michal Hocko wrote: > > Le'ts Andrea and Mike > > > > On Fri 19-03-21 22:24:28, Bui Quang Minh wrote: > > > userfaultfd_writeprotect() use change_protection() to clear write bit in > > > page table entries (pte/pmd). So, later write to this virtual address > > > range causes a page fault, which is then handled by userspace program. > > > However, change_protection() has no effect when there is no page table > > > entries associated with that virtual memory range (a newly mapped memory > > > range). As a result, later access to that memory range causes allocating a > > > page table entry with write bit still set (due to VM_WRITE flag in > > > vma->vm_flags). > > > > > > Add checks for VM_UFFD_WP in vma->vm_flags when allocating new page table > > > entry in missing page table entry page fault path. > > > > From the above it is not really clear whether this is a usability > > problem or a bug of the interface. > > I'd say it's usability/documentation clarity issue. > Userspace can register an area with > > UFFDIO_REGISTER_MODE_MISSING | UFFDIO_REGISTER_MODE_WP > > and then it will be notified either when page table has no entry for a > virtual address or when there is a write to a write protected address. Yes, you are right. I saw a patch from Peter to linux-man and saw that "When there is only UFFDIO_REGISTER_MODE_WP registered, the userspace will not receive any message when a missing page is written" It's my mistake that I didn't look at the documentation carefully when playing around. Thanks, Quang Minh.