From patchwork Tue Dec 11 05:34:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10723077 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 83F0815A6 for ; Tue, 11 Dec 2018 05:34:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 656152A2C0 for ; Tue, 11 Dec 2018 05:34:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5976D2A397; Tue, 11 Dec 2018 05:34:20 +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 E7F462A2C0 for ; Tue, 11 Dec 2018 05:34:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0F1B8E0053; Tue, 11 Dec 2018 00:34:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DBE428E004D; Tue, 11 Dec 2018 00:34:18 -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 CAD638E0053; Tue, 11 Dec 2018 00:34:18 -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 9F41D8E004D for ; Tue, 11 Dec 2018 00:34:18 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id c84so12319783qkb.13 for ; Mon, 10 Dec 2018 21:34:18 -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=gSJM4/a0Xt9pFUqzJ0ZfAekB92G2x7FXat1mAaT8kHk=; b=OqYP+TTuJZelMJRFYQtfYqE9Hxt2a+x4vM0EBt3iPK7Bu00yyk9fc20+lVG5792Cn6 GpZCW2i0HI0PHUYNUW3jQJa95CnBrWdvs/gEsUU90cOufd78Jhl2+LUpSvR1zlzgNUs/ rYLQGM2n4bpWjogzSCwmCqrbuVnTjq+0tRQ7jKjdQgvN3xjPfd0cc9WCk+UFZZTEEvlc Rq43tFVa83YexyhPzRzhZOfyLfBPP/45bAEGXOcwvW36vUe6MJE0VUQRVrk6ELfqjlSN 22CZ4sqkiDf6GUwlcgGTRMaKRcLQsu7e6V///jO+5z29RPQv7nicNJn3l/ol5vyQRdn8 vo+w== 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+aEWYy59I80GTrcCjicR07c9Hvk3eXXHYHwqdZvyVIk2+7oDJzUEt3 +uzcmcAcqJIWkt1Pkd9PcplnJYiakl8EShGix072Jvm4NjetsVar6OCbjwoK+XJn01nYYZCo6H+ I7kJOgxrVFfDzPWyLaEY14XwSRQpHnbWzh+8WGg4tFcxarZyxgnxV/Rp4MkDhQehYvQ== X-Received: by 2002:ac8:f2a:: with SMTP id e39mr15093458qtk.262.1544506458407; Mon, 10 Dec 2018 21:34:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/W1EpG5eODe+P/s2n8s+Vw7YxWCHm6PIjC90sm2OpoDPXdNkkgUSO7hIYrpmteRpWNqjuZf X-Received: by 2002:ac8:f2a:: with SMTP id e39mr15093435qtk.262.1544506457867; Mon, 10 Dec 2018 21:34:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544506457; cv=none; d=google.com; s=arc-20160816; b=yPWec9rawYdn8l3esZlCjXxCr0m+o3qxtL03Ia4ApF5tgnotJlnJUaFzXVhhF7pQ5n WMf+PtlPKEJo2HKftHHkL+ggxa7rG3c/qMpCpZ4LYVR/KZY8xNQy1LynoJBJZZOYqK3u V+geDLIkybNjydBxzU1L+QLsqAOOz7R271LI/UnM7P7zMpBJxSNrWDzUKPHs0KNOUBpz mnEmCTn39ZHQdUQVWsyDKcA8id/C3R7udYconVjZVcqhymRlDqr+7V+0pcpI0IScZ9fF kuYcHnDwSsLjPOJnw0bTPRhGxQXbLL96Z5qcgfB/ijPnWqogB/qvSxvktFonY1rJ7Orp PlBw== 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=gSJM4/a0Xt9pFUqzJ0ZfAekB92G2x7FXat1mAaT8kHk=; b=AvE9Z/kJs7Ft4LrTLuJS/GNWPARKgfG6rP6+iPJCwaNYeodwyHWxSDzZV6N5WdAC8P Im/sCrwtZSlgitFZ7ugUiEYi2flvs6mEw/DEoSpHxS47/SaWbPl57Eocz+P/++MZe/B5 /GsQ5ew24JH6eH+uWjgD2+4Xr+Q1VAnh0tZWdCp+2FcQaZDNNNXX1Qrgk61RDn37pHkQ seLwythT3rL4rjZG1msTmnXWmpRD/cp2gUfWUD7IOGlq8WKmNP05zt+IUJamDnsX0iXS Ra5BlguHvw2xyq2cxHC45BeHeBcSzpCuDBzSCBPRrZUViEeFPe3EQ+w3xrVbRTS5HrGQ bfbg== 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 u2si246862qvd.172.2018.12.10.21.34.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 21:34:17 -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-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) 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 Acked-by: Mike Rapoport Reviewed-by: Andrea Arcangeli Signed-off-by: Peter Xu Reviewed-by: William Kucharski --- 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); } }