From patchwork Tue Mar 26 16:47:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10871643 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 5BF33186D for ; Tue, 26 Mar 2019 16:48:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BAD928D5D for ; Tue, 26 Mar 2019 16:48:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 401F428DCC; Tue, 26 Mar 2019 16:48:36 +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 B815628DB8 for ; Tue, 26 Mar 2019 16:48:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86BB56B0297; Tue, 26 Mar 2019 12:48:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 81F826B0298; Tue, 26 Mar 2019 12:48:28 -0400 (EDT) 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 70F156B0299; Tue, 26 Mar 2019 12:48:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 391026B0297 for ; Tue, 26 Mar 2019 12:48:28 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id 35so14059494qty.12 for ; Tue, 26 Mar 2019 09:48:28 -0700 (PDT) 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=jnvlAV+GWfMx/7xQbFXaF0JgvpgKRF2qvBTJuIYTYOk=; b=D76z0XJ5uO/yoYIMbDnWQx63DTyNH0Bjs5Xdvya4ZGp6WgDfKjBpvptf5gBe6HtI1B ev5KHAVyZBQ/b2XOYXhAVdNFRKGJG8KNtSNI0lcrMg7m/TDA+KK7f8s327G38hgW5ZWD 9ee8fSH2qhdWQB9xQNzrKcR+b1rxB0LTaZ/nE7/SPXhEsW0ZhE38QDF7/+wo4+nYHC7H ZEABkAPdpAM0WHeyVY2D/FNNuoDGOItoBazUkAaRDNO1XKE+opJxF6zBt7U5x6to80dE BOqiOB3pnIqwl70rImJtWb/e332UO7uFQBDcvFK7QHl7EnczBC/oRcGAfGzQxgkejrXh TsGA== 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: APjAAAWlFQGi5HIp8QHQWFhGbbbqpnJJiJY7ya1s0sPRDzkb9yqZDMj0 csxnVx9DaG5ff6+nh7oQ6nZSZTGXiqwHfLiVkESd0QlXLhGprm4bPJ8WAEwzHOWucu7+xo8GkOx DwQtmhPqmyCx9PycXUHvPEKKyhefhMbTxmB1S7HCeI78kISIRgQOYNAQ9lQJ+ieHyIg== X-Received: by 2002:a37:784:: with SMTP id 126mr24287211qkh.10.1553618908011; Tue, 26 Mar 2019 09:48:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqx55GVNwmoFPjHG9+7g6vF5xHLfb9AH86ZrSYRkOI4V2NJmqECy3VkHTyg7UyHMjj9clmKi X-Received: by 2002:a37:784:: with SMTP id 126mr24287174qkh.10.1553618907430; Tue, 26 Mar 2019 09:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553618907; cv=none; d=google.com; s=arc-20160816; b=R1kozFGrKbJFishz2n3MdnZMZegfuNgoX1VF2KTCgy2jtNwKa4Qr+hLkRYr1eLm6bD wWEKAVX23RQJa4pR0xRc3J+kAZl7kVcSLv8yzm4DObdUCFvYw8ydfZ23FS5wouy2nTWq ZkPlOOzG4dcHkb28puQFGPjmmbMY2UA7lL5SWiKlu5WmbKbW4UrZxpJg15wL2oVSf4LA jJ99yCFApNhbTmlPYKYdIpyCi0+hgeB/iq2CP2cCB8mOkbe0Tajx3xWx29pBYay3c3rj kAav3BLt/5s1llm2G/VhscNv1dAWEu7d/QRU1I9G90azMDe+YOQhKR8E1j44WuNi2QDs Bnjw== 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=jnvlAV+GWfMx/7xQbFXaF0JgvpgKRF2qvBTJuIYTYOk=; b=Dv6ITq7bnQ/gUW2hVcvcPI7ea6d1Y+j21nNveq57O7xMaPygOnBGJuuB+AW/J/61U7 /b8qNnyCYOf+DOYkTFM2//g4v6toJHvriFb8vIm1RSn5cuI/vbPs1Zy3ZIi8AGqGuRnw A0edqf2tNZxbOj9fjHNTvYLtdt1eS1tjNUi2yk0fJLicorzh35u2WNnvi+dPmb5agixK /U8CvpbGmssVtgbmJipUChBHEYRepTRlqLtx2myX/vEO1By5QVJ+GsbAfVIcD1/lTAGq pNR6LYSdaOD2/7vCHApiTz4FMlLZmX6LT8wY1DJ1Yu1qLWrs8uEalI/F7rtLMx9Y6HHg MSAQ== 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 k26si11111636qve.94.2019.03.26.09.48.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 09:48:27 -0700 (PDT) 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-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 7399A3086212; Tue, 26 Mar 2019 16:48:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.20.6.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 485878428A; Tue, 26 Mar 2019 16:48:24 +0000 (UTC) From: jglisse@redhat.com To: linux-kernel@vger.kernel.org Cc: =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Andrew Morton , linux-mm@kvack.org, =?utf-8?q?Ch?= =?utf-8?q?ristian_K=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?b?UmFkaW0gS3LEjW3DocWZ?= , Michal Hocko , Ralph Campbell , John Hubbard , kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, Arnd Bergmann Subject: [PATCH v6 8/8] mm/mmu_notifier: mmu_notifier_range_update_to_read_only() helper Date: Tue, 26 Mar 2019 12:47:47 -0400 Message-Id: <20190326164747.24405-9-jglisse@redhat.com> In-Reply-To: <20190326164747.24405-1-jglisse@redhat.com> References: <20190326164747.24405-1-jglisse@redhat.com> MIME-Version: 1.0 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.42]); Tue, 26 Mar 2019 16:48:26 +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: Andrew Morton Cc: linux-mm@kvack.org 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);