Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3936054imj; Tue, 19 Feb 2019 12:07:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IY+9hkbSnI8PIG9ChLMEVi2xR3Y8mCr0riXN+428I+Bzwzzq0hCaAfBXaK47cR9z6C/TVLW X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr32594876plo.194.1550606838545; Tue, 19 Feb 2019 12:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550606838; cv=none; d=google.com; s=arc-20160816; b=haR49R2xXl/ys5zoThAYrojDppHU6t+hLokLYhnzqwyb6BdT7L2JFbbG9E3CBKbQSQ 2JZtqblRtyYr8SwTVJ8Qrn0l/iU4uz5zyzW+NstJh/AvFvOEVFENkVT+fJL6smWEIErO sX1A7ZAe4EQknLErsCA0hF5cjAeUk7djuWpXWV+bg1sTMEktYgOLl5d6NyZVP/2eYT3x KWmvoU3PRCwVSgdkRRlSZpqS+MFvi0KSVYUEhGWXRrp7uXIKVTKO3iEclhMzsWc4N1lq 1q7gJvO6ivZFGhsAK1IgM/XsC5BhYHwympZxpm7GOeRjgvcgb7p+/zP0iwZDhUm5M7tn x4jw== 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=1rXUTed8CnGwTcmPq0oCfhnLKbGw3aW6rBbzJhdygy8=; b=li162Vz8BCwSJj1Yao0Yi7B6bdJ1eQZ7lKMpYWuz2vOi4wYuvmgmlIpacSBmDE/DXX 4xvcMlarNY9SEzyhpJFfxlv5+QuO1nuc63kNmpW0rWQ5CfpU3LyOqP3MvV48mLDnQzOC WvbR5toS6Wbb1umY6LIbulCcGs8vvco3KcQf5FM2OAbKEYV3oJ7KhxyOkqgsh6I1yzse RMJAmhWLGgMxHby8nMVA2+32cj30im1X21AOxsIlZjXlE4KNitNhMa5LNPoX/G0peEn5 sfx4Ds+zTyjrK8zQEs/eb4UgtROPSEligi6YSvH6kli3YwUaJzW8+HvzVACrgjodwnjm I6Hg== 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 h3si11568959pgl.468.2019.02.19.12.07.03; Tue, 19 Feb 2019 12:07:18 -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 S1730068AbfBSUFx (ORCPT + 99 others); Tue, 19 Feb 2019 15:05:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49336 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726610AbfBSUFw (ORCPT ); Tue, 19 Feb 2019 15:05:52 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D706C074132; Tue, 19 Feb 2019 20:05:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-122-134.rdu2.redhat.com [10.10.122.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1DEA6013C; Tue, 19 Feb 2019 20:05:30 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org, Andrew Morton Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Joonas Lahtinen , Jani Nikula , Rodrigo Vivi , Jan Kara , Andrea Arcangeli , Peter Xu , Felix Kuehling , Jason Gunthorpe , Ross Zwisler , Dan Williams , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Michal Hocko , Ralph Campbell , John Hubbard , kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, Arnd Bergmann Subject: [PATCH v5 8/9] mm/mmu_notifier: mmu_notifier_range_update_to_read_only() helper Date: Tue, 19 Feb 2019 15:04:29 -0500 Message-Id: <20190219200430.11130-9-jglisse@redhat.com> In-Reply-To: <20190219200430.11130-1-jglisse@redhat.com> References: <20190219200430.11130-1-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 19 Feb 2019 20:05:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Glisse Helper to test if a range is updated to read only (it is still valid to read from the range). This is useful for device driver or anyone who wish to optimize out update when they know that they already have the range map read only. Signed-off-by: Jérôme Glisse Cc: Christian König Cc: Joonas Lahtinen Cc: Jani Nikula Cc: Rodrigo Vivi Cc: Jan Kara Cc: Andrea Arcangeli Cc: Peter Xu Cc: Felix Kuehling Cc: Jason Gunthorpe Cc: Ross Zwisler Cc: Dan Williams Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Michal Hocko Cc: Christian Koenig Cc: Ralph Campbell Cc: John Hubbard Cc: kvm@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linux-rdma@vger.kernel.org Cc: Arnd Bergmann --- include/linux/mmu_notifier.h | 4 ++++ mm/mmu_notifier.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 0379956fff23..b6c004bd9f6a 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -259,6 +259,8 @@ extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r, bool only_end); extern void __mmu_notifier_invalidate_range(struct mm_struct *mm, unsigned long start, unsigned long end); +extern bool +mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range); static inline bool mmu_notifier_range_blockable(const struct mmu_notifier_range *range) @@ -568,6 +570,8 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm) { } +#define mmu_notifier_range_update_to_read_only(r) false + #define ptep_clear_flush_young_notify ptep_clear_flush_young #define pmdp_clear_flush_young_notify pmdp_clear_flush_young #define ptep_clear_young_notify ptep_test_and_clear_young diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index abd88c466eb2..ee36068077b6 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -395,3 +395,13 @@ void mmu_notifier_unregister_no_release(struct mmu_notifier *mn, mmdrop(mm); } EXPORT_SYMBOL_GPL(mmu_notifier_unregister_no_release); + +bool +mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range) +{ + if (!range->vma || range->event != MMU_NOTIFY_PROTECTION_VMA) + return false; + /* Return true if the vma still have the read flag set. */ + return range->vma->vm_flags & VM_READ; +} +EXPORT_SYMBOL_GPL(mmu_notifier_range_update_to_read_only); -- 2.17.2