Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp465615pxf; Wed, 31 Mar 2021 07:51:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztr/DdgO+Li1Hb6U/rkhK19YCMmz+6GgpnxfICAhxaWoN3LQz00AJqykDwNmdB3pmXXsbn X-Received: by 2002:a17:906:b747:: with SMTP id fx7mr4104060ejb.474.1617202281586; Wed, 31 Mar 2021 07:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617202281; cv=none; d=google.com; s=arc-20160816; b=tBOwciplOkPJtHL6NwFW6W/6hg/Yk60X992tgKtrHnlO63lapH0YZqePTotzBvPn6z //Ewl/daj5EUtkToVHzHuLWjDQXzWnAjmSS0XuKKdVFRclioeXCK6M0kx558xs7Oe3pY QB238wiZKXszm8aiKEb3Iul+QsJ0TaMa6SihN5j6Rj89Kmv7oQ20+wg/kgCo21wDlviC 110pUTfL2V0cOFVLUWU/MB0LQbKqiZETNjufj/PBeLMlz6adCvjewzbysbMu3i1Kt1i9 GcGI15lE+3V5jxBbCO3K6SCJrPEYDNcq+NOX9W6lwV3iPJ7yyKF6OA+vsg6OlIxZ2a29 r+1g== 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=tfJA+TZ9qD+uLNeSPxgFvSUB6YHzcDNmhesxVbtiM78=; b=wJvEm/oEqwvZ+v6kEcdX80LPEb1hcQTihnrULSw2u9SWvH6taMn0Zf1GJKUsQNeW20 4zGGSL+AQ+HfWwB9NS19KkO3AoVTXYPfRYmlSgZjjHsPANhux06N0lHHqadsiUI/fwRs G0LAUDfbaFL5ufPJ0OD089/Vu0Hsg4XpJ4dAt7VqSVZAOv3ke34rmZ+2zPIcZZ+Rq3UJ yNqp9h85J7eY1uZK1DrZVOT36w7CoXrSl1soow1hO2WhZcqDZ8y+4pu+hStz1O2Jsn0y V2/zeeSG7CLBDoVNJMfMC8MdywULkR7z+L5Lr2g9tKjXdGaJJw8SpwGbbC4A/DOkWQxD HCCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=rjVi1+kL; 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 z16si1951348edd.298.2021.03.31.07.50.58; Wed, 31 Mar 2021 07:51: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=rjVi1+kL; 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 S236158AbhCaOtm (ORCPT + 99 others); Wed, 31 Mar 2021 10:49:42 -0400 Received: from mx2.suse.de ([195.135.220.15]:46594 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236140AbhCaOt3 (ORCPT ); Wed, 31 Mar 2021 10:49:29 -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=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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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