Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1354238pxu; Fri, 27 Nov 2020 05:35:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdtiT6xfV0x+fc7aSnH7WE9N4BIsToUrVQ20belQkZYkY0l+IxAeJmDd2s714wQyHQ2pmz X-Received: by 2002:a05:6402:48d:: with SMTP id k13mr7615967edv.92.1606484131650; Fri, 27 Nov 2020 05:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606484131; cv=none; d=google.com; s=arc-20160816; b=HS6np/V7fY0M9QrBZy+R2tjoUmSpHU8G/uhORlq3O+Oo0tIylMAo5H1jrPChEWejrL Yx1vcN9BVk28Ys0jVFM1ZvnevWqaL8laQSV6Ph+vn8Gq4Y2U9eupztuVD3caLrBYEM+w 2W1LL9eKf18a9d/9/3GSNAAiY+oemvSL4oNCDhyBTqZuS+Tvy/BvOdHAua5eHo+Jkdea jEMbgFTvJN8mvzEaZs9l08HWV/Rz0IuQfwAmPsKVorvMzxdCKI4Bm5a+zM/Afb9Th23o w2trHzaJA9H8+Xto9o8CjH9l+KdivDSWDeIQaX7KJF8IDZOCi6bSdnV95vvlq4JspEpf Sy4A== 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=ED8t4Qy7PTQ/kC+YjFAEVvZVdG/aRP0VblcEzp2WkKo=; b=xWXHqpeqGFlM8ZSglkt5GhVe5w6UF0JYGzfydYrMNRFs2m0pVSBAB4BA4vA/Qj5ZAf rwNVDpFD8IKLKN7BDwuXg40v558ibepggEzD5vTASDwF22PXqxCnp3KpE/bs6L4m0gnj ZKoxjbackNFxvc4sX82T36B+kzUw5Sb/SimXtL0qClZ2opaPCj1nEbb8Qfwkl6TwktSi Tmcm/3GX97IC7m4fr4+IYVWzP1cyJgyk9xzPdHdpGjm38o8cxeDr/krcPVTepl5ow6OC Hx5wQGiu5eGrOfQNnL2qOOKMQgS5oHO1JlwT9D+y9NGxa4etksE46jn4Pw4xW8dVcS1M 9LPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RNIs5Qbu; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx25si5333491ejb.445.2020.11.27.05.35.08; Fri, 27 Nov 2020 05:35:31 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=RNIs5Qbu; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730355AbgK0NbN (ORCPT + 99 others); Fri, 27 Nov 2020 08:31:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26277 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730101AbgK0NbN (ORCPT ); Fri, 27 Nov 2020 08:31:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606483871; h=from:from:reply-to:subject:subject: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=ED8t4Qy7PTQ/kC+YjFAEVvZVdG/aRP0VblcEzp2WkKo=; b=RNIs5QbuVYNJQQOoj0IrSav2hbqN2E8+blTaIT74FwEsCwyjyqt4oyj87bjRsQGxTB9ijn nqN8f1TjpirKCXTDwPSLU2GjqZU/YVN/hoQ5IyqSlpalTYGPmnDQ53kM2yf1zyusIcbB5r Sp8+wwVe+P9yD6yzadlbnsopWSMwmm0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-A2o52v1nMqePDicUBfRBLw-1; Fri, 27 Nov 2020 08:31:10 -0500 X-MC-Unique: A2o52v1nMqePDicUBfRBLw-1 Received: by mail-qk1-f197.google.com with SMTP id p129so3671455qkc.20 for ; Fri, 27 Nov 2020 05:31:10 -0800 (PST) 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=ED8t4Qy7PTQ/kC+YjFAEVvZVdG/aRP0VblcEzp2WkKo=; b=Zx7vWshj483tDLgL7ymNYcAxBWeZF5A+oO4Gxp1qmPDR5zgTAktfg3IBhfMY0iTbAx p891Gbqh2GTbUEpoKwbvLhiHTCT8KynHu7Slkm0vddfAdD4kGG21XVzmBBBbucGVuIYb B+HyKtPJ1FyzwiyU0t7IRPNgoTFR9ckEtcf2vDITzM40XSULzv3u1g6PHEoLNCXhke8p E97F5StMBJFlKVJUL8QJTy3xzDzxgkCPzqiJr8hphtP1pGhUz7epzkH+/0gSoceVGwQ5 24sMkSbMaerDE8BBViYV1pvVz8laIc7bx6xjCv0ZbRQp0lkY/OM2i8guXE4VCxYP7hXf ZSCg== X-Gm-Message-State: AOAM533WEQ+qwOOkidUXGE5nAWL1TqLAWorud7vcX8eTMUd4sWr302Jt m2c6xasORoEVUC8c4a6PCvN+Vfkb+3RGGhFm51h52PhFwDL57G25I3kf5Q6AoPqRGgJYe0udh5a uC4567zk2pcubtta6XdD5P7rm X-Received: by 2002:ad4:4b01:: with SMTP id r1mr8236594qvw.51.1606483869219; Fri, 27 Nov 2020 05:31:09 -0800 (PST) X-Received: by 2002:ad4:4b01:: with SMTP id r1mr8236566qvw.51.1606483868918; Fri, 27 Nov 2020 05:31:08 -0800 (PST) Received: from xz-x1 ([142.126.81.247]) by smtp.gmail.com with ESMTPSA id p62sm6006251qkf.50.2020.11.27.05.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 05:31:08 -0800 (PST) Date: Fri, 27 Nov 2020 08:31:06 -0500 From: Peter Xu To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Hugh Dickins , Andrea Arcangeli , Mike Rapoport Subject: Re: [PATCH] mm: Don't fault around userfaultfd-registered regions on reads Message-ID: <20201127133106.GA6573@xz-x1> References: <20201126222359.8120-1-peterx@redhat.com> <20201127081605.GX123287@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201127081605.GX123287@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 27, 2020 at 10:16:05AM +0200, Mike Rapoport wrote: > On Thu, Nov 26, 2020 at 05:23:59PM -0500, Peter Xu wrote: > > Faulting around for reads are in most cases helpful for the performance so that > > continuous memory accesses may avoid another trip of page fault. However it > > may not always work as expected. > > > > For example, userfaultfd registered regions may not be the best candidate for > > pre-faults around the reads. > > > > For missing mode uffds, fault around does not help because if the page cache > > existed, then the page should be there already. If the page cache is not > > there, nothing else we can do, either. If the fault-around code is destined to > > be helpless for userfault-missing vmas, then ideally we can skip it. > > > > For wr-protected mode uffds, errornously fault in those pages around could lead > > to threads accessing the pages without uffd server's awareness. For example, > > when punching holes on uffd-wp registered shmem regions, we'll first try to > > unmap all the pages before evicting the page cache but without locking the > > page (please refer to shmem_fallocate(), where unmap_mapping_range() is called > > before shmem_truncate_range()). When fault-around happens near a hole being > > punched, we might errornously fault in the "holes" right before it will be > > punched. Then there's a small window before the page cache was finally > > dropped, and after the page will be writable again (NOTE: the uffd-wp protect > > information is totally lost due to the pre-unmap in shmem_fallocate(), so the > > page can be writable within the small window). That's severe data loss. > > > > Let's grant the userspace full control of the uffd-registered ranges, rather > > than trying to do the tricks. > > > > Cc: Hugh Dickins > > Cc: Andrea Arcangeli > > Cc: Andrew Morton > > Cc: Mike Rapoport > > Signed-off-by: Peter Xu > > One nit below, except that > > Reviewed-by: Mike Rapoport Thanks! > > +static inline bool vma_registered_userfaultfd(struct vm_area_struct *vma) > > +{ > > + return userfaultfd_missing(vma) || userfaultfd_wp(vma); > > +} > > We have userfaultfd_armed() that does exectly this, don't we? Yes, will fix that up. -- Peter Xu