Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp308634imu; Mon, 10 Dec 2018 22:30:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/WqY/B1Z2HsROhTD5aB928sdUh1H36hGHKC73L1zpc33OCe+kFdMFMSAin/HuEM78xQcZKj X-Received: by 2002:a17:902:f64:: with SMTP id 91mr14830817ply.132.1544509837202; Mon, 10 Dec 2018 22:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544509837; cv=none; d=google.com; s=arc-20160816; b=O1zdao+5foXpAjQrRN1RxFcR8rUAmpnTivivlMDkDU2CaUv2UGClpMJdBq+p+QxnaO 1VeuBH4puw8dI2J+A6zVQblbBTxrrWvGjoHVGfC05ues0lOfYbJtteGRR+BMg2GlY2xP 0NbEOmAnHFd/07ztI9nfeV537hK2monXOX4yZhO1rJJVYaME83kvtV07BQZZzXvd+IW4 0EZ2isUE0hvddOFl9op5Z/wOUONNFzrXq/ronAQhvPy8StxPGt4XfoW6xAsmKR3oQs6Q nGzuxIEPBlUx8gS2u22BkwJLt2aWqvHr8qMPicxT7HgHq6vymaNbQItk+LL5/o4b1X8U 587Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=gSJM4/a0Xt9pFUqzJ0ZfAekB92G2x7FXat1mAaT8kHk=; b=D5lFmFakwB3Iz7l9ObLU/tNE9uzhlVz2fBMkWq6Fvhwj3vwltsOWzKTCBcVZNwZcya jA6LF79z5NXOSTclZdUIhgnCBDqAXzVx3BqVY3CrQeauxgzAmVjJSR4qylSq3Ihh2s91 rNDywMUjJyTHOk0+p5DAA/wCe9p+qeKVdjBX+B1UQ1527l+8rxS1WgkmeUDPzbD1nDbr Q93DIAsM39jxXeyXPdAXLHwVfaqA6ETj1X9nheXFRlSUdwiXbOGyHfNPRhURPLuDh2Wr NVDlrPLlEVSlTZm9aXsF/8jl96695NwwX0m31kOhV/Cxu26J1CDI/AXGEVo7nxVD+Wal 6T2w== 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 28si10637842pgz.593.2018.12.10.22.30.22; Mon, 10 Dec 2018 22:30:37 -0800 (PST) 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 S1728844AbeLKFeR (ORCPT + 99 others); Tue, 11 Dec 2018 00:34:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59062 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727952AbeLKFeR (ORCPT ); Tue, 11 Dec 2018 00:34:17 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB5B758E45; Tue, 11 Dec 2018 05:34:16 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B46719752; Tue, 11 Dec 2018 05:34:10 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Andrea Arcangeli , Andrew Morton , Mike Rapoport , "Kirill A . Shutemov" , Hugh Dickins , Pavel Emelyanov , Pravin Shedge , linux-mm@kvack.org Subject: [PATCH v2] userfaultfd: clear flag if remap event not enabled Date: Tue, 11 Dec 2018 13:34:09 +0800 Message-Id: <20181211053409.20317-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 11 Dec 2018 05:34:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the process being tracked do mremap() without UFFD_FEATURE_EVENT_REMAP on the corresponding tracking uffd file handle, we should not generate the remap event, and at the same time we should clear all the uffd flags on the new VMA. Without this patch, we can still have the VM_UFFD_MISSING|VM_UFFD_WP flags on the new VMA even the fault handling process does not even know the existance of the VMA. CC: Andrea Arcangeli CC: Andrew Morton CC: Mike Rapoport CC: Kirill A. Shutemov CC: Hugh Dickins CC: Pavel Emelyanov CC: Pravin Shedge CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org Acked-by: Mike Rapoport Reviewed-by: Andrea Arcangeli Signed-off-by: Peter Xu --- fs/userfaultfd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index cd58939dc977..4567b5b6fd32 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -736,10 +736,18 @@ void mremap_userfaultfd_prep(struct vm_area_struct *vma, struct userfaultfd_ctx *ctx; ctx = vma->vm_userfaultfd_ctx.ctx; - if (ctx && (ctx->features & UFFD_FEATURE_EVENT_REMAP)) { + + if (!ctx) + return; + + if (ctx->features & UFFD_FEATURE_EVENT_REMAP) { vm_ctx->ctx = ctx; userfaultfd_ctx_get(ctx); WRITE_ONCE(ctx->mmap_changing, true); + } else { + /* Drop uffd context if remap feature not enabled */ + vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; + vma->vm_flags &= ~(VM_UFFD_WP | VM_UFFD_MISSING); } } -- 2.17.1