From patchwork Wed Jan 23 22:23:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10777997 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 9BB891399 for ; Wed, 23 Jan 2019 22:23:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5620B29207 for ; Wed, 23 Jan 2019 22:23:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4914F28DE2; Wed, 23 Jan 2019 22:23:48 +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=unavailable 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 CA50F2D37E for ; Wed, 23 Jan 2019 22:23:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD0D18E0053; Wed, 23 Jan 2019 17:23:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9E3798E0047; Wed, 23 Jan 2019 17:23:45 -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 834FC8E0053; Wed, 23 Jan 2019 17:23:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 5131B8E0047 for ; Wed, 23 Jan 2019 17:23:45 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id k90so4384403qte.0 for ; Wed, 23 Jan 2019 14:23:45 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=9wi7YLiorG0zg+O0dNIqm0yoV34mSK8NVO5rYlqWX4Q=; b=nmFscXRvPv5prLx7uW8ekGejDLoTZI9VHhvIiHDhGmhiAk64rUTh6e/1ZBuce3954y Gyt7c9twmL/en+DUiX3xiHouO7DBQ4GhoyhJ0hpqRIrky3XdDWCjiReu73lhKaaoMbc9 nvXWT86T8oQEegwlMhUb7inu4XpJ8PUa026JYIgvcJceXVnBsCg3XTHagokcu+4BPlvB vnt9DDCzbWiKZ7vTHsfHCxSNMibMRyugntVLICk878BbCljbcXKobCuhaGFmh2kzTUfE mGvO0aLP9tg18jRr994J2UpOYGB6guqQNfUrIWaQECKe9o91SGC9ukQAACM6yw4cvSes lBFg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUukeBf0oRL2EFknhM846spCrB9lFt3jkz5y/grT19VQfJ0fQqqjeb hda+QzUBOEi8vbUAgby8UlZsC8ijKOE1HcqaJU9EbU93eAyHCCct2qAIJhUt6jrvQgbUHDieyKh 7V4YhzCDfusYOTGaw87KAKoO9qBFi2rJtm2V2w3mrmjZfQECv6jm6q4C5N/f5uM7RdA== X-Received: by 2002:a37:2714:: with SMTP id n20mr3403667qkn.349.1548282225096; Wed, 23 Jan 2019 14:23:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN6nER88iiIX+r/X5d4SCFI+KMh7aOvrdI+e+MIUxDtjI6vKm0jVEc0mLRXHxNmHRn+5HO5R X-Received: by 2002:a37:2714:: with SMTP id n20mr3403646qkn.349.1548282224664; Wed, 23 Jan 2019 14:23:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282224; cv=none; d=google.com; s=arc-20160816; b=RGpLNRZQkK/Zg6YuFKpqjkyNZvx5tfqMmN5VFFVJCfQMqqKtUvUdEfGQ8K/OqlLUmC jRHoV5QTPBbNjEu8vdA+1/JRYVM4l1bMP4N2pDCMnmOnQm7Q2QK4OxDHQrNk6VATigTx 9BR940jpWIhxGNX62JkIpMfPkLy1VizVA80tD5pxKwVbBUFUXMNYc7soQaECRggxiTXl PaQ352CaCi5faICZRui5aARRsgcA0ZNQFx7bmsJscyCxQOCuMi1+AQ31MoxWcqISyhC+ lOQgFHSTyDksV3M2l1cJhNiH0mUQoUjJDb5K4TjujygF+uUHUse9seMx+zAaIvYefFzi 7WBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=9wi7YLiorG0zg+O0dNIqm0yoV34mSK8NVO5rYlqWX4Q=; b=D9tlP/TwMqLHObNFck0TKZxNEA8vPl9yzkHYH1DLdZCiSDQECR6vDpNOLyZr3LpJSO US6s5P3E4RB+yZ2qEo7s8HeYLNukvwv/RfZndlY43qZzbnkKcrC6nfW7hRr1cRFcIp4o Jsu7Iq2Pd9p0MgbfwJblIvLI4popQ6aqC05ZOu7FrNp52wGXnmcsENq/ZziyjBI2i8hX d4j+Hk0l36M1qBBhmsVIIX9vnqf9tXhV8Oc+GjBlT0FXpr5lk+JgJnX9RI8cgEFOTHei HF0xvo2uwZOIU/KIJ3PC4OpKKMsJhLnXw5NzvG78/2BWCYSgMNbv4mRbm/5idBsf5Rso UGSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@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 h12si6136349qto.184.2019.01.23.14.23.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 14:23:44 -0800 (PST) Received-SPF: pass (google.com: domain of jglisse@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 jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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?b?SsOpcsO0bWUgR2xpc3Nl?= , =?utf-8?q?Christian_?= =?utf-8?q?K=C3=B6nig?= , Jan Kara , Felix Kuehling , Jason Gunthorpe , Matthew Wilcox , Ross Zwisler , Dan Williams , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , 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 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) 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 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);