From patchwork Mon Jan 21 07:57:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10772825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F16986C2 for ; Mon, 21 Jan 2019 08:00:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E311B29CB7 for ; Mon, 21 Jan 2019 08:00:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D767D29CD1; Mon, 21 Jan 2019 08:00:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAE7629CBB for ; Mon, 21 Jan 2019 08:00:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C75A68E0010; Mon, 21 Jan 2019 03:00:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BD7108E0001; Mon, 21 Jan 2019 03:00:12 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9F778E0010; Mon, 21 Jan 2019 03:00:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id 7E8008E0001 for ; Mon, 21 Jan 2019 03:00:12 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id y83so18337742qka.7 for ; Mon, 21 Jan 2019 00:00:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=jxlEHcEGe3kHekh99WP30Nd+yDOg4/Ym/8a55AV+thA=; b=dMTT9Lw+U+mmuArrPAAYqpG7M63jFCJBqEVusiFH3ZChGLIXeVlMe5rew26wblDwvi 8d6ia9q//UgsmvJq1/Wy5MNZQhCBJpxHCzHhbYnN4Q4kbotIYbGmxc9fGOyBMmNd5nZm X/sIc5RnYuUrJbo7rcmC4uyVcJLVNJZzftmlQUeSzgSD1fBRSPBkaqPeBirgM72k+CgN mriY8iKR9ynMq9MjcWVCJElKSrFnyqM6O4bB17nwxkjlkjk0w+9coKNM9xXe/Ux//dFA Bxg5J85w9A6hSgtQ3VMzQni8vg2kDwGpX/vjSS56CSBZ2wDQr54H5IAmWqM27FhjWtbR HA5Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUukfZl9r3UlqmrbgwvOKQUaj832VcZWz941qYAqi1FY/KFgGOM6Tc 7wBlCiDcKlncIlEZ0ouecTrGGCC6wYgC6gsxjHHsBOZhouFmNR7s0n9V1ytZkEoydnXwKjtPx98 3Kzw8JBoryxL2DlvV2qxVHNST5NBsOuyVCQ4pdH9u12QY4X9KxAYiBt7BY23eSB1p+Q== X-Received: by 2002:ac8:3038:: with SMTP id f53mr25430157qte.45.1548057612330; Mon, 21 Jan 2019 00:00:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN60KTtye2EtrPJ5SsIrq7tCLhnLpQ28ljDC75hCPgsVNi1FInjiO8jSBJcfeEmk+8jc3yaj X-Received: by 2002:ac8:3038:: with SMTP id f53mr25430126qte.45.1548057611738; Mon, 21 Jan 2019 00:00:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057611; cv=none; d=google.com; s=arc-20160816; b=Jsk4uo4RIYnG/FMHYAS9TYxDW6p6iGUOPe2ArMQjyjjj8cri1G5Q9MlJRungGsb/if wUWBDG/lMIzV+QgDRJWoklGqmCRr6+9e/4VdUxSdpKrHYZvJj7dbA+W3LoyTnVV3beyt OBayKTtjWE3JTQb6GONZN4tyLrlcDsXssRfpwO7F4qd9/pjezLAnEyB5LT3v67fjq5Rt JhRiNnL4XGbfjMzypDkDkSNBYnRLQTf+cm4g066n+YZij0mIDdIPTPzu8Wicl3MiHYPk wZabauZvPYZAPL/2MuoiGel5CCuxjW8VjjYtveu8ey7mcOgBaZvdOjMxWDBKb0maW0Im woHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=jxlEHcEGe3kHekh99WP30Nd+yDOg4/Ym/8a55AV+thA=; b=QzsEk5fZun6nciloD0NZsSpfEf3sn3RKIsdv0Cn6cIp9lIbdDGR2/uhN+MSMyvkJIQ xkcrm8HYDfYWYOrxKENqPOpHVycn6vGKlPQmSoDfMecmmTQPZgl+m/bNr2LZ7GaUFUFR ymUWErkLItrn/aT+CpbAj32BH7L9/p43ogpJc5JKVJuKgQzfV+uUMhc66/1FEMdgZLU2 l4z9Bc7t7UQeaD5qrIYy9wgPCC6MXGfNsipTGFMn5a4oUiGmyfQTf7JSvmuysakZya7d Jj8SnnjynEBKwLotbHzDEssqIXnoMNiA4Fb/+eu00xOutSUqgLz1cw/X3SKTE+s2ZCbw Oxxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id p42si2997749qtc.174.2019.01.21.00.00.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 00:00:11 -0800 (PST) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC7C187620; Mon, 21 Jan 2019 08:00:10 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-116.nay.redhat.com [10.66.14.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EF28608C7; Mon, 21 Jan 2019 07:59:59 +0000 (UTC) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Maya Gokhale , Jerome Glisse , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Denis Plotnikov , Shaohua Li , Andrea Arcangeli , Pavel Emelyanov , Mike Kravetz , Marty McFadden , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH RFC 20/24] userfaultfd: wp: don't wake up when doing write protect Date: Mon, 21 Jan 2019 15:57:18 +0800 Message-Id: <20190121075722.7945-21-peterx@redhat.com> In-Reply-To: <20190121075722.7945-1-peterx@redhat.com> References: <20190121075722.7945-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 21 Jan 2019 08:00:11 +0000 (UTC) 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: X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 455b87c0596f..e54ab6076e13 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1771,6 +1771,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; user_uffdio_wp = (struct uffdio_writeprotect __user *) arg; @@ -1786,17 +1787,19 @@ 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); 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);