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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 8A3A7C433ED for ; Wed, 31 Mar 2021 14:49:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F18B61019 for ; Wed, 31 Mar 2021 14:49:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F18B61019 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9A0496B0087; Wed, 31 Mar 2021 10:49:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94FF76B0088; Wed, 31 Mar 2021 10:49:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F0AA6B0089; Wed, 31 Mar 2021 10:49:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 5F3B66B0087 for ; Wed, 31 Mar 2021 10:49:30 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 14A6B181AEF3C for ; Wed, 31 Mar 2021 14:49:30 +0000 (UTC) X-FDA: 77980452900.35.4DE2AF8 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf18.hostedemail.com (Postfix) with ESMTP id 98A2A200024C for ; Wed, 31 Mar 2021 14:49:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1617202168; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tfJA+TZ9qD+uLNeSPxgFvSUB6YHzcDNmhesxVbtiM78=; b=rjVi1+kLoItHEcYK0qZA68TaaHcXVmKEVe3A4lvDfumVUvd5U2wi9hVHA8aiPXu2a78wO3 KJEjJzHcFeMO3sOm3NUDoY1fBXqVpICxBxs7gBHFM3mwwfDZvkdjY2AebTMwG3A0hT8Kbr WbgAfk51AZm0qEpp7uPaeVeG4fT6yjo= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 74C1FB315; Wed, 31 Mar 2021 14:49:28 +0000 (UTC) Date: Wed, 31 Mar 2021 16:49:27 +0200 From: Michal Hocko To: akpm@linux-foundation.org Cc: Mike Rapoport , Bui Quang Minh , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrea Arcangeli Subject: Re: [PATCH] userfaultfd: Write protect when virtual memory range has no page table entry Message-ID: 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: ucaiap9ur3pkysbuoyqppeerinp688t5 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 98A2A200024C Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf18; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617202168-931818 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 22-03-21 14:49:35, Michal Hocko wrote: > On Mon 22-03-21 15:00:37, 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. > > Thanks for the clarification! I have suspected this to be the case but > I am not really familiar with the interface to have any strong statement > here. Maybe we want to document this explicitly. Btw. Andrew the patch still seems to be in mmotm. Do you plan to keep it there? -- Michal Hocko SUSE Labs