Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3453600pxf; Mon, 22 Mar 2021 06:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4MJw4uMHYop/zSXBKQmMijW/7ueJcfDy2qtZVkx8SMPJEioH0g2NLD8FvkAwsyPtSWRnJ X-Received: by 2002:aa7:d954:: with SMTP id l20mr25902881eds.1.1616421201359; Mon, 22 Mar 2021 06:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616421201; cv=none; d=google.com; s=arc-20160816; b=nnuOPgARrORhtNUgTWKgi0jRhbF2+LVCav9OzcA8OiyLHOTsLGfrAD0wZyDOTpMvnh 8Qfvzc6HUBcsmeFmF0P1EGU3jIaym3roFVZzJAQc1G/+TaLh9rqadYFNy3GSwqO7dGku 63B4A8t8/xLMhJcj9eXAJI5/1zTBARNVPsrLealD7M/C/2jjNhEGSeiCfKxC4HK2cOhR cyRIO39UNkT9gOdCD5JGLFFYWQJ44nwxV8SWghyQ2B9AV+Gr/OQ3YFSYlu528sRBIQnY YJU2fSasCJXBY1XRxtTR10WilXLdAu8CQUNSSwV2We6rqkg4Gvn4Zy1lQWs0AVsY8Mhn qosQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5aJOCSImLqPAApaY0++1sOTv38yGygKLihUtVg+NGj4=; b=QR4h/MOElAqvBOmfG8ItkLexfscWpV/X/MAQbIBniE+/8qwC4pBKsIy1wi2PWWvLxM CQCDvuu0KGaPwQBlF0Opb/BTUUPxEEvbYKFPo9Pztf9rNiJrub+/Eg65h3SIE7Ly7ZqI azVS0Ccrb0LROYQ7qJqXpXVVbyH9MKU4h0OeWqu3zn4D8I7Ff8bwhKjRcXYukIvuEAlI OjXNDoIzZYVhUtoKUA+c6AXqgZOtkpymscML3TQL7K0GEycnbLR5oPFxMYLJWcA/Kowl OTxGYpbfQ4P33A6bNXfNfXnvkd/x0xlXSqZhmUol7uxn3vNT8qX8K2x9QHNu9fTBuZ7t GQUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Bfh0Z3YB; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hd34si11193604ejc.197.2021.03.22.06.52.58; Mon, 22 Mar 2021 06:53:21 -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=@suse.com header.s=susede1 header.b=Bfh0Z3YB; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbhCVNtv (ORCPT + 99 others); Mon, 22 Mar 2021 09:49:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:37004 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229467AbhCVNtg (ORCPT ); Mon, 22 Mar 2021 09:49:36 -0400 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=1616420975; 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=5aJOCSImLqPAApaY0++1sOTv38yGygKLihUtVg+NGj4=; b=Bfh0Z3YBO7L1DsnYWYefFxQ2lRzNUaof7O/l1GcCBrtxGvepR9goz2264zEC041xAnVSEb /mSE2m9DY8gAwvZE2R3QVFfC8afoAt17iVWFkzQ81+emRnTkCI/C1Np2q21SfyCfj43ic8 7K68RPMoN+7Xvy31vpojeJb5tOH18aA= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 55447AC1F; Mon, 22 Mar 2021 13:49:35 +0000 (UTC) Date: Mon, 22 Mar 2021 14:49:34 +0100 From: Michal Hocko To: Mike Rapoport Cc: Bui Quang Minh , akpm@linux-foundation.org, 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Michal Hocko SUSE Labs