From patchwork Mon Dec 10 06:51:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10720667 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 1132691E for ; Mon, 10 Dec 2018 06:51:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02AC129C4A for ; Mon, 10 Dec 2018 06:51:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00AFF29C5C; Mon, 10 Dec 2018 06:51:35 +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 3C4C129CCE for ; Mon, 10 Dec 2018 06:51:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 030718E0002; Mon, 10 Dec 2018 01:51:34 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EFB908E0001; Mon, 10 Dec 2018 01:51:33 -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 DC3868E0002; Mon, 10 Dec 2018 01:51:33 -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 ADE758E0001 for ; Mon, 10 Dec 2018 01:51:33 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id d196so9514510qkb.6 for ; Sun, 09 Dec 2018 22:51:33 -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; bh=fD2V19YCc1GKpWL59Ads2PCMEh3glA1/W1QaATF/YvI=; b=cfODpe6vjn5qY8pqu6KSJ9o7Ak0W9Pl2NTkWs/689FfpjALzTmBMK4aoQ3QLcx2dxp 9ooF9Esu5VNvru542ELG+FRmlRnjMSuE6ccDF00QN7zzYhY9HZ7iBZcP8w/yerAYhIrQ 87qjJIHczlqYfWcpEEQcAIOVi4AcpqWi1A1t+7wvfqtJCr/j8K1W72nys188jlN+K2ky dzIxnYP2/KT3DSMPY7U+g1U7XPrhGVxilQ6CfQu+8lPu1Nae0nNAoNmTZSpb6ZinWHZX OJ2lgNu2zFsA587LRePtszDc5RpzPVHXceXDjNywGhxZCWM1qhgk8wbKdYEHGga7zzgJ b2Jg== 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: AA+aEWZlsGh2YzEZdcop6cWyOHGdkv/lYPxa3xrTdx5Aehq9WJHdVK2O CTeGqHm3CiQj6e3S4gPSPKJf+1Q/nRB0g1E/O11wk4NwS/AK2s02PaMae7wvH7Oce0wZ4TTWvPO FJkb5WlVA7z8xIbqalT6c9p12uSMoc4AI353qTsFsZvadHsv+NM7dbvYHa3qvzVa97A== X-Received: by 2002:a37:a141:: with SMTP id k62mr9776950qke.280.1544424693363; Sun, 09 Dec 2018 22:51:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XF2iny7F6LG1bmQZxHOBRJU79OVAC8ri2OuGmkMYU6QdyKc/7eJlHw5mkbL5aWVNns10PU X-Received: by 2002:a37:a141:: with SMTP id k62mr9776934qke.280.1544424692791; Sun, 09 Dec 2018 22:51:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544424692; cv=none; d=google.com; s=arc-20160816; b=BAy/0ovquC181wSjTAX46csG7QHQ38u9NQ2DNa1TMbdED4l7fSVh1tmCcuJeJ60c4N UPa2NYu+sy2SGLMyqi7JughwBxRGQec/eePoakTC+z1FRzihXQaxUuu3KVCv+qnjpA9I 34DhrHkITztMrokPnBAXffyAV6JQuj/BoAI9M0OtG3QyFTxUIITwyAylE1oTH/jKG1xv GhnwYGpfx7kmXzwHZkoZ6HOmhSC9pyl8WRmkAuFERtgz1WH+l/ZOP5vnO1tH153fZM3T iP/RWgZyI8M0Ye2LkC7nA0nANq83BxsBHBbWR/wNcJrvq3lNwuMOB2qqE0qsYArklogu 8qSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=fD2V19YCc1GKpWL59Ads2PCMEh3glA1/W1QaATF/YvI=; b=stPZzLA+tY2bxquml4azGHkqLv0XHGkiGe4AagUFhLlaNHvEaKQajuoTXYAjvq46aQ FE6DwGTqwyiHfe2yXI5/H2ipnb3nv+smQ/X+48NBt8IsOUqT8yUaCVaEeFPz7ydYUX+/ wANze40b/Adbcniiv48vVkr535UXz4SCvN2lXE5A3sf9VsDc4ytq/XwRRCAyD+4J3muz BkGiFQmYiF3ksIUzWc/iGo+Hc5xNrm/B/da4/OBmQg0n4Rl0+zfv7c7RHgby1LQEYTjF x/niXHU3NNyeR9plRpdZQRCzKT3KficZf+NTi6Bz8uJv4nv0vj8kX3/RQh8fyWjUK4B2 8SwQ== 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 i2si6462165qvg.76.2018.12.09.22.51.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Dec 2018 22:51:32 -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-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9321158E52; Mon, 10 Dec 2018 06:51:31 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F04D5D759; Mon, 10 Dec 2018 06:51:23 +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] userfaultfd: clear flag if remap event not enabled Date: Mon, 10 Dec 2018 14:51:21 +0800 Message-Id: <20181210065121.14984-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 10 Dec 2018 06:51:31 +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 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 Signed-off-by: Peter Xu Acked-by: Mike Rapoport Reviewed-by: Andrea Arcangeli --- fs/userfaultfd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index cd58939dc977..798ae8a438ff 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -740,6 +740,9 @@ void mremap_userfaultfd_prep(struct vm_area_struct *vma, vm_ctx->ctx = ctx; userfaultfd_ctx_get(ctx); WRITE_ONCE(ctx->mmap_changing, true); + } else if (ctx) { + vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; + vma->vm_flags &= ~(VM_UFFD_WP | VM_UFFD_MISSING); } }