From patchwork Tue Feb 19 20:04:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10820771 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 AADB91399 for ; Tue, 19 Feb 2019 20:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BEBF2D4E2 for ; Tue, 19 Feb 2019 20:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 904AD2CC25; Tue, 19 Feb 2019 20:05:58 +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 166E52D474 for ; Tue, 19 Feb 2019 20:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 075668E000C; Tue, 19 Feb 2019 15:05:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 024DC8E0002; Tue, 19 Feb 2019 15:05:56 -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 E7F608E000C; Tue, 19 Feb 2019 15:05:56 -0500 (EST) 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 BFCF88E0002 for ; Tue, 19 Feb 2019 15:05:56 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id k37so21085645qtb.20 for ; Tue, 19 Feb 2019 12:05:56 -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=1rXUTed8CnGwTcmPq0oCfhnLKbGw3aW6rBbzJhdygy8=; b=OvinrxoLH6511Q1lB4R3vQOdYyQNLHNoCC+L8/RhkpARDfZmD7L5x0qaFc0yHZpW3j Wz0kkEp3ekfpIvspAikNPUOoj73Ci9z5fYC2ULMNuFZlWwUJkhJTeabfvl0ZyW/oeFBd mhToYWYkzz9Y8nKKvnQDskQOIQbbbvLRaMNt+vOvXJcoaUZbT7hDMooq1PN8S3xKryYl eP0BziNwD2qpYDo3Mtu0ernPk8T5UIHv9QrXkle5v6wgRTNicCyqj8F8dY+NS7jx5D4b +L+gVy5m3rk9HOKpt2nBA1FB1BjYToQ9KAeIasfAlT6ZN0FU4YhFWpGOLI7ePFOdeMCd BZXw== 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: AHQUAub2ii0luO2O+lJfGRPSPufJulmJGCO1gfSeW+SmMgbcISjGiMKg vuNunTbRORBIHDC91bHxTTdAIuPf7t0+4JUSsJPfFlBZHUsg+xpOjXyKaAv/PfHL0KR/LxbpOFP WSglIjMguqvfCLFQDXYj60s8vFcMncecMarJwiL473OQ86kch6ie/NlsXpoQb5HvaBg== X-Received: by 2002:ae9:f712:: with SMTP id s18mr21289866qkg.83.1550606756572; Tue, 19 Feb 2019 12:05:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IZTmRlwxO6eLrs5XFaoipVg3Usx61wFfpSW8neSkhankA3qBVcSfi/CYl40/27QjW9JYuPd X-Received: by 2002:ae9:f712:: with SMTP id s18mr21289643qkg.83.1550606753137; Tue, 19 Feb 2019 12:05:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550606753; cv=none; d=google.com; s=arc-20160816; b=YaewFunTXgzL4shZLZKm44noUWnwnHyWzsdBpwHyjBfnn+rwxY7m6lCLS+c4euDcvc vYpLz05f7eEt+3lwPTP7tpy13R4Wjbd8wme5uTW91U5OTp7yurh+C/G2GOZN2Nx3Pylw ce3EtABmaAn4VoSwn8tBK0QdNB4G12CyGJBzMR2V1jGstC5//wWGWGGviQP0BbaXlXNm euHeBC+XMecVgsF8sBVh8Tqu5AqV2YLIUIO+DHD3V3d/E85uES9w8aJcPC8tk4VY3KU0 jxob19nByyRdeku8a4FvjyzaYFhHXGmFifBFDO41bzYA5oTp2wWsvemQ9x/+80TnSDLQ uvUA== 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=1rXUTed8CnGwTcmPq0oCfhnLKbGw3aW6rBbzJhdygy8=; b=th+JWHhY0ksHW64edDGzHY5J3lfFR7Jp6MiswbpE//4icwjMJ/Vrxb/U5gl1/P/DiM V4K+RV6E6Z8iG9bP0x4SX29byr515tjPvb/EUbB7o+URj4xq+SuhTQNE/LjO+99cVGqv C6owOXQ/OuraxT/3w8o8XGgG1JcFFb+gGGM9+2EL/J6qjtfxCAkqWRDA2cdrf15asg4X olDWwAvuGIJAUWQOkggDbOA+8xKP/BGZzp3bsdwEgrrtGRMEQmOvRY5nJPfoUcFBC82/ cVG+TjkBj2qASgf7XHWF6PNyVvyCjl720aggTgs8+T820Q/5tO4m/VHVp46ZyKeYDxo3 +hEQ== 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 b21si1399457qvd.134.2019.02.19.12.05.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 12:05:53 -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-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?b?SsOpcsO0bWUgR2xpc3Nl?= , =?utf-8?q?Christian_?= =?utf-8?q?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 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 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) 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: 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 Reviewed-by: Ralph Campbell --- 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);