Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1367820ybi; Wed, 19 Jun 2019 19:25:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzi2ObO/whPwBmtALh9HMV30YuWYPdKaGhl/LW3ZmjEls6O4rC17HuHH8vsIKiMxYQGKWOu X-Received: by 2002:a17:902:d695:: with SMTP id v21mr103619612ply.342.1560997537364; Wed, 19 Jun 2019 19:25:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560997537; cv=none; d=google.com; s=arc-20160816; b=ogNUWw7a4JJiS9YXWBoME02B2j2MS+Z8yznMuOqjBzf/5gcid+b3+xS98BCFyem/JG 0CjeEVTvw+iqu/5Y3aKckN4KbBHUcs1jVHMelqL771RW8Ap0S7K2h3tpaINnIxclcjnZ cqSBzIiy4I6cCJRU8ro0qQJ9QlST+gICwyQ7t0bDb8OdSp+zUOxFVgkGsB5QabN4u+95 S65rLAaX1r1tOC2sqNhLrv/BqgeFMXdr4MnMSDQhtrJSnkXhcB4M8Mft+tdluQRFLKtr TwGdJpVzeIoDxWnuQuwPQVyvozYMp2OPFBFAgUh5UHCoSfcMV/zOUgiF7Huln40UACv7 zq6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e7eX1RveEOqtNN+ZGUkmQs0zHK+DZjZtAYbM/evoIws=; b=DIcFRFH2F2llXpPuds0kGIThCZH+U7juFjkqXFgPgFSWnO7hJjYfM+PE7otlfp/Cpp MPXrjpLH/N7ppX07YeJp1+4WOdOY5xxrdFWeziWePYZ9kmc/htlTV7AqGA+KwrdEpfx+ sBKwKSZt+ju5a7QmeDDxJ6XmSAY/mtiWjaVHWKsTWpdNpvEfflNjzEwhLwibm79of1bB E3bb+OD0Qoxgv9qd1FUKVgY+ivdJhiAVdXlqOLxKDAm0QsBvAhqDO1cI9CtOipWd4vIb PenQhl3Zb2dQHfZCi+bX6e7Cl4koDWoVUGE9mKMa2pyCK5yr15tMJkn7l5UYmUgH4OaY oqyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a123si19664971pfd.114.2019.06.19.19.25.22; Wed, 19 Jun 2019 19:25:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731608AbfFTCYq (ORCPT + 99 others); Wed, 19 Jun 2019 22:24:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44216 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbfFTCYq (ORCPT ); Wed, 19 Jun 2019 22:24:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 354BF307844A; Thu, 20 Jun 2019 02:24:46 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-78.pek2.redhat.com [10.72.12.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 899C21001E6F; Thu, 20 Jun 2019 02:24:38 +0000 (UTC) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Denis Plotnikov , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Marty McFadden , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH v5 21/25] userfaultfd: wp: don't wake up when doing write protect Date: Thu, 20 Jun 2019 10:20:04 +0800 Message-Id: <20190620022008.19172-22-peterx@redhat.com> In-Reply-To: <20190620022008.19172-1-peterx@redhat.com> References: <20190620022008.19172-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 20 Jun 2019 02:24:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It does not make sense to try to wake up any waiting thread when we're write-protecting a memory region. Only wake up when resolving a write protected page fault. Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- fs/userfaultfd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 3cf19aeaa0e0..498971fa9163 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1782,6 +1782,7 @@ static int userfaultfd_writeprotect(struct userfaultfd_ctx *ctx, struct uffdio_writeprotect uffdio_wp; struct uffdio_writeprotect __user *user_uffdio_wp; struct userfaultfd_wake_range range; + bool mode_wp, mode_dontwake; if (READ_ONCE(ctx->mmap_changing)) return -EAGAIN; @@ -1800,18 +1801,20 @@ static int userfaultfd_writeprotect(struct userfaultfd_ctx *ctx, if (uffdio_wp.mode & ~(UFFDIO_WRITEPROTECT_MODE_DONTWAKE | UFFDIO_WRITEPROTECT_MODE_WP)) return -EINVAL; - if ((uffdio_wp.mode & UFFDIO_WRITEPROTECT_MODE_WP) && - (uffdio_wp.mode & UFFDIO_WRITEPROTECT_MODE_DONTWAKE)) + + mode_wp = uffdio_wp.mode & UFFDIO_WRITEPROTECT_MODE_WP; + mode_dontwake = uffdio_wp.mode & UFFDIO_WRITEPROTECT_MODE_DONTWAKE; + + if (mode_wp && mode_dontwake) return -EINVAL; ret = mwriteprotect_range(ctx->mm, uffdio_wp.range.start, - uffdio_wp.range.len, uffdio_wp.mode & - UFFDIO_WRITEPROTECT_MODE_WP, + uffdio_wp.range.len, mode_wp, &ctx->mmap_changing); if (ret) return ret; - if (!(uffdio_wp.mode & UFFDIO_WRITEPROTECT_MODE_DONTWAKE)) { + if (!mode_wp && !mode_dontwake) { range.start = uffdio_wp.range.start; range.len = uffdio_wp.range.len; wake_userfault(ctx, &range); -- 2.21.0