Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1296990imu; Wed, 23 Jan 2019 14:24:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN4XJlEW+n8tkEY0vqxqUqSBtb68j12w0ibLAGcWaaD+0X20FyWknqvxNSWEL20xCQPAU1UH X-Received: by 2002:a63:4d66:: with SMTP id n38mr3680182pgl.270.1548282260020; Wed, 23 Jan 2019 14:24:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282259; cv=none; d=google.com; s=arc-20160816; b=GVAKYvMCZIoB1YCTe9L6dq62tNJCitwklhC6oKJyvzZqf20CkNpNLoNdX7T8RdTVO8 +dcGoijmxHpNKPoEjR67OSExIa++urtng6koGPHIDIhlAP/suW5otug0SOyl1SRPcXgF BtcuJFQWiV7tMycPsR5VX+7RjyIurZY5mZMDif/qi3KCMD6EV0mBqlAqPEXqMJtzPROl ClXJB8gKoVnoZCL+Cd+qyFtG5XwgITZoMM+nEpVcxsfdWsHVE1Esj2+6Y3aI99VPB+M6 wWxQuqnYVMEbxYeAX3UEzAaR1gjVwYQQd69CNGbBw+RYEeGb7PGen3RsJ/V3gSP7LmTm mhEQ== 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=9wi7YLiorG0zg+O0dNIqm0yoV34mSK8NVO5rYlqWX4Q=; b=NPP7z8P4BsHvPy7ENnQwRC1pCYn8SzYJGyIrhLgC3rZ6bWERftgFG7hk3P/aLbB1+g uTDRLyN0IUQsbMcnu1qK/w24dJNqFX7MIlBjtzjgm/Jfn5ZLHvs1Iler8lcMwiRHmYv7 ubBQci3cg1/UmygwVA3Qck8lqwhfE4JJdZNNnkx9v9WWHIorSOCmlDiEcJIw2g08IMxZ b7NzAXWozytIK/z4nd0U2yV8kiTQ5eljTp4mUj4mTRBePtHXsmAfiWaDNYbxVrM8R8AC Q4fS3iJvhL+cE6mQanfR2ks6VBSadQVjNGbvJujCPlT9c6E3MB+tZ9TnGEJrDx73znUb irJQ== 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 y40si21208321pla.251.2019.01.23.14.24.05; Wed, 23 Jan 2019 14:24:19 -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 S1727276AbfAWWXr (ORCPT + 99 others); Wed, 23 Jan 2019 17:23:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46752 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727228AbfAWWXo (ORCPT ); Wed, 23 Jan 2019 17:23:44 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86234CC0A8; Wed, 23 Jan 2019 22:23:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-127.rdu2.redhat.com [10.10.120.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id E90475D964; Wed, 23 Jan 2019 22:23:40 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jan Kara , Felix Kuehling , Jason Gunthorpe , Matthew Wilcox , 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, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v4 5/9] mm/mmu_notifier: mmu_notifier_range_update_to_read_only() helper Date: Wed, 23 Jan 2019 17:23:11 -0500 Message-Id: <20190123222315.1122-6-jglisse@redhat.com> In-Reply-To: <20190123222315.1122-1-jglisse@redhat.com> References: <20190123222315.1122-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 23 Jan 2019 22:23:43 +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: Jan Kara Cc: Felix Kuehling Cc: Jason Gunthorpe Cc: Andrew Morton Cc: Matthew Wilcox Cc: Ross Zwisler Cc: Dan Williams Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Michal Hocko Cc: Ralph Campbell Cc: John Hubbard Cc: kvm@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linux-rdma@vger.kernel.org Cc: linux-fsdevel@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 7514775817de..be873c431886 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -257,6 +257,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 void mmu_notifier_release(struct mm_struct *mm) { @@ -553,6 +555,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 9c884abc7850..0b2f77715a08 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