From patchwork Mon Dec 3 19:25:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10710405 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 D138B13BF for ; Mon, 3 Dec 2018 19:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C28452A962 for ; Mon, 3 Dec 2018 19:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B62382AF77; Mon, 3 Dec 2018 19:25:30 +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 7D1C72A962 for ; Mon, 3 Dec 2018 19:25:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 871CA6B6ABE; Mon, 3 Dec 2018 14:25:28 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 81FAE6B6ABF; Mon, 3 Dec 2018 14:25:28 -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 7370A6B6AC0; Mon, 3 Dec 2018 14:25:28 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 329826B6ABE for ; Mon, 3 Dec 2018 14:25:28 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id v12so10794570plp.16 for ; Mon, 03 Dec 2018 11:25:28 -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:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=LDJ3fWIOYbcK6NTRumfGpPe3ndEpu9Og6F4cNR00A3k=; b=TDIGEL2gXwk7pyR3xJs5Cgm9AYZLKCiJHnmXIgtG5V9W9FfzPTdleK/Tx8Tc7yVUqU p3EoL/GmD4LXasPInggHjkwx3VMNzvXGvGh79QMuPjvD/M7SnFevGsVZjBcnC1uIjGWk 7gcK7mQXlrwFKJTN5S9L5wGHAe0hW4wmiSPbC9Cs026UvwHlBGXAWZV1UVHf55TRZQTp LA0tfNHG9EQRaAmn2FnWDTzMZyhepuaLc4z2RxRuJWAlag2F6NrlAZv8eKwN/QBQklSv sqpOvoBUeirNK56gBEGj34TGJsX1ofFiei6kFDU4wok86g4bq8nHAY+2MfaX9raWr0iI PpkQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWbbIfcfWviLrn8T1QxzNON3Ig5nvCEKvW6tThp6vZ3ToXtAWIJD SFLbFBFRrJKhZRMPqtaWDK03/5HaqQe5qY/m53wvcTnXP4zH5sifEUtvioqbAGFS423XCGEBsLt WuxDSCP79CaVHBf5EJIMRA8+pXtkeciipfVk1YsH5xAcMZ+3WhmgHtrMqARiVuXatQQ== X-Received: by 2002:a17:902:b494:: with SMTP id y20mr17514641plr.178.1543865127842; Mon, 03 Dec 2018 11:25:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/X1ls3pCLM+hwx7wFh4EwQf5KYlXJyPTrfQyvAIRWIYTd5pwg0c03e02YiJ4uP6+d2v2ait X-Received: by 2002:a17:902:b494:: with SMTP id y20mr17514582plr.178.1543865126931; Mon, 03 Dec 2018 11:25:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543865126; cv=none; d=google.com; s=arc-20160816; b=k2cveHwTfx/ywFS0yVEkYam+pAUwBJKrFK1nL0ItonoFSos/BadyH4l1Eu0Wcwy5Zn QF+oisSXIEAbE1doSEHxOwqljnDsFrASUPAgyXhHcnXwx+6TdoVjl6Hiha263veHf5ny qMry8ALQ/3iOH4k5BS/Jp/yOR/4EVJahSv/aEQ3A9uXSk0YefS2A9h1rWHPJitrxBKk4 lZgYbjPW97wNZgCy3xjARZhvfao6AZ2eA1A2C+zELqH1yx/n+xthmKhlcrMRQVgLbVKB BJzKJGfA+oMiPzydyceLqkWIgxqkilNcvRMqJfVCIVfgZ6snqSI17mAw6ldiqwq4fdjn 4/GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject; bh=LDJ3fWIOYbcK6NTRumfGpPe3ndEpu9Og6F4cNR00A3k=; b=z2RKLxh2XB4VbYBW6yNtM/+NqLGbPzzt/QeOtNTSyCui3RmkzCjW49mbq0N5wKrmfk 2IlMwKTO4fPXaC77oamlLv5uIsOUMNYWdzavOX6hW0BnlPYUbnXekb0W3RiSGo0XTe71 ACtPLZBiivhETX8irT5ntrBDJPKlGdhIaQZPYUn9tWYugewcl5wvD+1+vZIvALElxuL2 duLyxvSikrN7ALlTC5EiMd9K1FI3JypR2L60JTNxUNzHswP9laOdl9nUoe+/pIhSlnCE 8brXW/rhwRR6bLLZuar9O36iy9wYtHNRWojPofwbLdxJ3/sDulKOdI1rgtczXqpsZgDd i0gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id f63si16103419pfg.136.2018.12.03.11.25.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 11:25:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2018 11:25:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,311,1539673200"; d="scan'208";a="115600470" Received: from ahduyck-desk1.amr.corp.intel.com ([10.7.198.76]) by orsmga001.jf.intel.com with ESMTP; 03 Dec 2018 11:25:26 -0800 Subject: [PATCH RFC 1/3] kvm: Split use cases for kvm_is_reserved_pfn to kvm_is_refcounted_pfn From: Alexander Duyck To: dan.j.williams@intel.com, pbonzini@redhat.com, yi.z.zhang@linux.intel.com, brho@google.com, kvm@vger.kernel.org, linux-nvdimm@lists.01.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dave.jiang@intel.com, yu.c.zhang@intel.com, pagupta@redhat.com, david@redhat.com, jack@suse.cz, hch@lst.de, rkrcmar@redhat.com, jglisse@redhat.com Date: Mon, 03 Dec 2018 11:25:26 -0800 Message-ID: <154386512606.27193.13867450982940890636.stgit@ahduyck-desk1.amr.corp.intel.com> In-Reply-To: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> References: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 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 The function kvm_is_reserved_pfn really has two uses. One is to test for if we should be updating the reference count on a page when we are accessing it. The other is to determine if we should be updating the dirty flag or marking pages as accessed. In preparation for blurring the lines between ZONE_DEVICE and system RAM I am splitting out the dirty/accessed cases into their own checks. Doing this allows us to add ZONE_DEVICE to the list of refcounted pages without having to worry about us introducing possible issues with pages being marked as dirty or accessed and possibly causing any issues with attempted LRU accesses on the ZONE_DEVICE pages. Signed-off-by: Alexander Duyck --- arch/x86/kvm/mmu.c | 6 +++--- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c | 22 +++++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 7c03c0f35444..7c61cc260c23 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -798,7 +798,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep) * kvm mmu, before reclaiming the page, we should * unmap it from mmu first. */ - WARN_ON(!kvm_is_reserved_pfn(pfn) && !page_count(pfn_to_page(pfn))); + WARN_ON(kvm_is_refcounted_pfn(pfn) && !page_count(pfn_to_page(pfn))); if (is_accessed_spte(old_spte)) kvm_set_pfn_accessed(pfn); @@ -3166,7 +3166,7 @@ static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu, * PT_PAGE_TABLE_LEVEL and there would be no adjustment done * here. */ - if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn) && + if (!is_error_noslot_pfn(pfn) && kvm_is_refcounted_pfn(pfn) && level == PT_PAGE_TABLE_LEVEL && PageTransCompoundMap(pfn_to_page(pfn)) && !mmu_gfn_lpage_is_disallowed(vcpu, gfn, PT_DIRECTORY_LEVEL)) { @@ -5668,7 +5668,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, * mapping if the indirect sp has level = 1. */ if (sp->role.direct && - !kvm_is_reserved_pfn(pfn) && + kvm_is_refcounted_pfn(pfn) && PageTransCompoundMap(pfn_to_page(pfn))) { pte_list_remove(rmap_head, sptep); need_tlb_flush = 1; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c926698040e0..132e5dbc9049 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -906,7 +906,7 @@ void kvm_arch_sync_events(struct kvm *kvm); int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu); void kvm_vcpu_kick(struct kvm_vcpu *vcpu); -bool kvm_is_reserved_pfn(kvm_pfn_t pfn); +bool kvm_is_refcounted_pfn(kvm_pfn_t pfn); struct kvm_irq_ack_notifier { struct hlist_node link; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2679e476b6c3..5e666df5666d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -146,7 +146,15 @@ __weak int kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, return 0; } -bool kvm_is_reserved_pfn(kvm_pfn_t pfn) +bool kvm_is_refcounted_pfn(kvm_pfn_t pfn) +{ + if (pfn_valid(pfn)) + return !PageReserved(pfn_to_page(pfn)); + + return false; +} + +static bool kvm_is_reserved_pfn(kvm_pfn_t pfn) { if (pfn_valid(pfn)) return PageReserved(pfn_to_page(pfn)); @@ -1678,7 +1686,7 @@ EXPORT_SYMBOL_GPL(kvm_release_page_clean); void kvm_release_pfn_clean(kvm_pfn_t pfn) { - if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn)) + if (!is_error_noslot_pfn(pfn) && kvm_is_refcounted_pfn(pfn)) put_page(pfn_to_page(pfn)); } EXPORT_SYMBOL_GPL(kvm_release_pfn_clean); @@ -1700,12 +1708,8 @@ EXPORT_SYMBOL_GPL(kvm_release_pfn_dirty); void kvm_set_pfn_dirty(kvm_pfn_t pfn) { - if (!kvm_is_reserved_pfn(pfn)) { - struct page *page = pfn_to_page(pfn); - - if (!PageReserved(page)) - SetPageDirty(page); - } + if (!kvm_is_reserved_pfn(pfn)) + SetPageDirty(pfn_to_page(pfn)); } EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty); @@ -1718,7 +1722,7 @@ EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed); void kvm_get_pfn(kvm_pfn_t pfn) { - if (!kvm_is_reserved_pfn(pfn)) + if (kvm_is_refcounted_pfn(pfn)) get_page(pfn_to_page(pfn)); } EXPORT_SYMBOL_GPL(kvm_get_pfn); From patchwork Mon Dec 3 19:25:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10710409 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 0034414BD for ; Mon, 3 Dec 2018 19:25:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5F672A962 for ; Mon, 3 Dec 2018 19:25:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA1062B20E; Mon, 3 Dec 2018 19:25:35 +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=ham 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 C471D2AF6C for ; Mon, 3 Dec 2018 19:25:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2F1F6B6ABF; Mon, 3 Dec 2018 14:25:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ADE5D6B6AC0; Mon, 3 Dec 2018 14:25:33 -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 9A7E56B6AC1; Mon, 3 Dec 2018 14:25:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 56C7F6B6ABF for ; Mon, 3 Dec 2018 14:25:33 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id t2so12016598pfj.15 for ; Mon, 03 Dec 2018 11:25:33 -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:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=+JW37OLA1PzhppomMkQAHxM+9jcH+WF9d6PlioQUTMQ=; b=Q/fym0+9yMry4WU/YtHSNrXpN6vk6eTTAs+ZG6U7m7YF9CyEwi9Bj8pdmkPZLV1zeZ 4gOjiBKsKcL5LC0AmzJ1v3twxo7A27Hnq1plom73xRVVE259mwFZjCYMqt1/h6i3B/K3 dMHvxm05L6JDNn1KxnuQ7RtnTG1bPFoF/lYp11OVHM4pYAlJI7UFrpxFm74nSBlmdTkw 9sussz1HLQ3lsw9UCg1sEtnOJcEzTB2DTKOBE+ZUo8rNiOTgqMxl2qT746b5+7GD1yzA hZDk66pcopC0Sn+0YpfUI/qpUeFRFON049UfUmfltbd3bcEKV+B00TyAQdqS4WAOw5p8 JkXg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWYchyf7YmgkmgBEGSMt8a9wRK1w9/Xn+B3dCCNtaCqL7rKijDE/ WJEgDAXepGtQktky8k/YbaNmuFOFpAzEJvrQRgJ0q6GZoOEDWit+CVfQJKKgNuBWb8mVIwcbQBJ VKyTPSIIWkmsB39+VnNVvymgURU3/dad18r07+05oXRYSF4HQSi0DwGmMaVLenObmHA== X-Received: by 2002:a65:5286:: with SMTP id y6mr14365833pgp.439.1543865132944; Mon, 03 Dec 2018 11:25:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/VIXfWtKblUkgCHm78BJtuxeCHb3q/exv9YzjT1rgIeltbA6hUW6oq4FFwf19iriRxFGdbz X-Received: by 2002:a65:5286:: with SMTP id y6mr14365781pgp.439.1543865132144; Mon, 03 Dec 2018 11:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543865132; cv=none; d=google.com; s=arc-20160816; b=B0/ioeKF3SyZMeWwKZOvnOa8NCNtx4geevnRAQrvYJEUz3OzwUJHnaO2hfXwSbBVTp C+Mt/YvKL4dhqxv2QfSiXhZtJxpE+VIoGr20sV5uaN0IurkNuBYzL57JXO7MzZ3i2Iwq kBaGS7LY5shj1oljr+eEFJ4O1Q+b32Fnxw8LKFB9lDE4yBiYejWjRNmF6Pvsx6pMincd vXdHsm5bR1lr2UfdRr9QKMpaVouZyu5+4p+xZdUk/prsFr2vkhq1dPrFy3iqBxcDjcPi aC/+ztGc2FmE2BO6WskNDzcN35K8eES4Ltoh+UDu8V+lv7cYrola5ycCYIzUNHhCenkU 0RhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject; bh=+JW37OLA1PzhppomMkQAHxM+9jcH+WF9d6PlioQUTMQ=; b=FUW6cTP1iEwfKvlUOjAxPMFV6pobMjsGmkBEq0JumViDBKbasEL280Rs8ms/JT7C/M CdeO6lvOYHE5gYaZDZrLQerJ9vjSZ6q9PSShHNlRqkDjdU0uQ+DvadS4jAixjNuddXqr FQzaH4WokHPzW2w9WdYNK0KXj1pK8h8iQL0yvyNKlx9wbftggcymllb0QPjOlPOKH6cv +g3x8bGXlpsGJW0r8BMfOZ0G7UYHoEQj+wAmaiB6l3M7dDenmwM5+hn8nSVpisbg2Pe0 T75s+ppyWpq2iC8gxJC6KdKM8SclLI8MY3Echc8PewDxswUmMIZMau6uswQ2YggA0uSM F4HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id f63si16103419pfg.136.2018.12.03.11.25.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 11:25:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2018 11:25:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,311,1539673200"; d="scan'208";a="115600505" Received: from ahduyck-desk1.amr.corp.intel.com ([10.7.198.76]) by orsmga001.jf.intel.com with ESMTP; 03 Dec 2018 11:25:31 -0800 Subject: [PATCH RFC 2/3] mm: Add support for exposing if dev_pagemap supports refcount pinning From: Alexander Duyck To: dan.j.williams@intel.com, pbonzini@redhat.com, yi.z.zhang@linux.intel.com, brho@google.com, kvm@vger.kernel.org, linux-nvdimm@lists.01.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dave.jiang@intel.com, yu.c.zhang@intel.com, pagupta@redhat.com, david@redhat.com, jack@suse.cz, hch@lst.de, rkrcmar@redhat.com, jglisse@redhat.com Date: Mon, 03 Dec 2018 11:25:31 -0800 Message-ID: <154386513120.27193.7977541941078967487.stgit@ahduyck-desk1.amr.corp.intel.com> In-Reply-To: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> References: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 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 Add a means of exposing if a pagemap supports refcount pinning. I am doing this to expose if a given pagemap has backing struct pages that will allow for the reference count of the page to be incremented to lock the page into place. The KVM code already has several spots where it was trying to use a pfn_valid check combined with a PageReserved check to determien if it could take a reference on the page. I am adding this check so in the case of the page having the reserved flag checked we can check the pagemap for the page to determine if we might fall into the special DAX case. Signed-off-by: Alexander Duyck --- drivers/nvdimm/pfn_devs.c | 2 ++ include/linux/memremap.h | 5 ++++- include/linux/mm.h | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 6f22272e8d80..7a4a85bcf7f4 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -640,6 +640,8 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap) } else return -ENXIO; + pgmap->support_refcount_pinning = true; + return 0; } diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 55db66b3716f..6e7b85542208 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -109,6 +109,8 @@ typedef void (*dev_page_free_t)(struct page *page, void *data); * @page_fault: callback when CPU fault on an unaddressable device page * @page_free: free page callback when page refcount reaches 1 * @altmap: pre-allocated/reserved memory for vmemmap allocations + * @altmap_valid: bitflag indicating if altmap is valid + * @support_refcount_pinning: bitflag indicating if we support refcount pinning * @res: physical address range covered by @ref * @ref: reference count that pins the devm_memremap_pages() mapping * @kill: callback to transition @ref to the dead state @@ -120,7 +122,8 @@ struct dev_pagemap { dev_page_fault_t page_fault; dev_page_free_t page_free; struct vmem_altmap altmap; - bool altmap_valid; + bool altmap_valid:1; + bool support_refcount_pinning:1; struct resource res; struct percpu_ref *ref; void (*kill)(struct percpu_ref *ref); diff --git a/include/linux/mm.h b/include/linux/mm.h index 3eb3bf7774f1..5faf66dd4559 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -970,6 +970,12 @@ static inline bool is_pci_p2pdma_page(const struct page *page) } #endif /* CONFIG_PCI_P2PDMA */ +static inline bool is_device_pinnable_page(const struct page *page) +{ + return is_zone_device_page(page) && + page->pgmap->support_refcount_pinning; +} + #else /* CONFIG_DEV_PAGEMAP_OPS */ static inline void dev_pagemap_get_ops(void) { @@ -998,6 +1004,11 @@ static inline bool is_pci_p2pdma_page(const struct page *page) { return false; } + +static inline bool is_device_pinnable_page(const struct page *page) +{ + return false; +} #endif /* CONFIG_DEV_PAGEMAP_OPS */ static inline void get_page(struct page *page) From patchwork Mon Dec 3 19:25:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10710415 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 C8BCC13BF for ; Mon, 3 Dec 2018 19:25:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA49B2AF6C for ; Mon, 3 Dec 2018 19:25:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADDF82B1A4; Mon, 3 Dec 2018 19:25:40 +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=ham 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 4EE972AF6C for ; Mon, 3 Dec 2018 19:25:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C2FB6B6AC0; Mon, 3 Dec 2018 14:25:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 671836B6AC1; Mon, 3 Dec 2018 14:25:39 -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 561B86B6AC2; Mon, 3 Dec 2018 14:25:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 145F06B6AC0 for ; Mon, 3 Dec 2018 14:25:39 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id s27so7439656pgm.4 for ; Mon, 03 Dec 2018 11:25:39 -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:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=STy7w+8gswWjStbq2Q93YOGUS6JNeR4D5R0c0fVb3MM=; b=d6CCHBDO0cFJvVK0J4S07zYgnBTDxu6P1X6+UNki1BgmVFifdlCTnQ1M1QQbkVuRod hRk+4NI6yYhstG+olKvZv0Q/zW+0qwq/2WLD4WKdD1OXeq+SWK6h4BlzXq4tfwlyKdfY PP7UiGvosYNqiC1rnl/hr87rftwYR0Tf53cAZfabWOuwNTO++rH00wDkC7c3CHnxJ/W/ NUZAQNqtZ4ShzhO5ysm2kflygLhVhKYbMFoUAOOe/oqX7l2wLuSDJqG89A5aNEQAxxoL mJ7U10ITPIkRBQXr5u9cC0IEuf0JECY94rQ+DeshrWPYMifZvqlomC602Pjv2WZs/0dV ERDA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWb7AOEDb7tP019C6sMIQsTveSfUNxf7MXtyDKhVLSm8unMnjmVf dGoeuarISmopCY6thDHfXNvFozJn/Hhq5FFC/bpfJIXMVZYyE9jisoACK5FFGg7QETqac1RmCYR SjfXp1ayf7e+04oVKleokonkpvgHUpVpyGD5Q+uuTtj3Ibf/s08bALQLjwqe/lsK7KQ== X-Received: by 2002:a62:ea09:: with SMTP id t9mr12719343pfh.228.1543865138743; Mon, 03 Dec 2018 11:25:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/Udoelu6ArLex9MoltZ/3rMals8QrYRqXNbSQ+mkRpeRZkMOF2dXgAqKnvk905gd2NhuPNq X-Received: by 2002:a62:ea09:: with SMTP id t9mr12719289pfh.228.1543865138011; Mon, 03 Dec 2018 11:25:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543865137; cv=none; d=google.com; s=arc-20160816; b=jFkSAOeCYnU1a9jEphf2CrDr3E4FKxBQkaN682qZQrUJ6iIcvwbB7wOxUdgWT6rLQP 8TfHSu+Wh28HbdPZ8Ob3XfyYbl7qwQ6hwPpua83WoyTnEYGGrdqDqenVcyG0j+OKJsPc O3HloSO0awU4HojkMkHI5tDAQjThusgNYc7ESzVVWwKS2521s6bdz1qITdajvqlmntHT 1ACuh6P+zRB8qhWHOHZjQzaW+CV8PRudItBrVpTDgaSauMGgsVu6TDrzKObkLjYLzliy ftjDFxcBG+SmTss636G4FMXH0XEGtgN4N2v4KWTnwqOUEOI/QC/Yf92y7v/PwGRAUYwa +pvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject; bh=STy7w+8gswWjStbq2Q93YOGUS6JNeR4D5R0c0fVb3MM=; b=Ec9TJ6xx44uPa9t7r7ytJ5Idlng71Y3m2YKHEJ4U9bInuX7Cubive6hbAChZV9B415 SBvH0Mol+gNVLOmwq7PgCyKdC7rKxbQbk0mjREQpPpFbRzWhwFlty3Mx93jrqk0K4edl tr+UyZxQQ879GMk6ObhbrEc3HTG+Rbiu+19qAq9bfxLiqtE8FfPIh7akbythXefQGlqr myGg4MDX6+7caD0WmzeXq/Jrl+Fxi4ma6CEDjuLxzDG7vNNuJWIh1u26PiZ4zdS9HcvV CoLj8k9t5MBV0ZBZcezUTI0IqI8wy7uMpuj9fRH8/FITLkyCDJo4yxYU3jbDCgSFKa3W Zmpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id g184si15031204pfb.288.2018.12.03.11.25.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 11:25:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2018 11:25:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,311,1539673200"; d="scan'208";a="97705143" Received: from ahduyck-desk1.amr.corp.intel.com ([10.7.198.76]) by orsmga006.jf.intel.com with ESMTP; 03 Dec 2018 11:25:36 -0800 Subject: [PATCH RFC 3/3] kvm: Add additional check to determine if a page is refcounted From: Alexander Duyck To: dan.j.williams@intel.com, pbonzini@redhat.com, yi.z.zhang@linux.intel.com, brho@google.com, kvm@vger.kernel.org, linux-nvdimm@lists.01.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dave.jiang@intel.com, yu.c.zhang@intel.com, pagupta@redhat.com, david@redhat.com, jack@suse.cz, hch@lst.de, rkrcmar@redhat.com, jglisse@redhat.com Date: Mon, 03 Dec 2018 11:25:36 -0800 Message-ID: <154386513636.27193.9038916677163713072.stgit@ahduyck-desk1.amr.corp.intel.com> In-Reply-To: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> References: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 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 The function kvm_is_refcounted_page is used primarily to determine if KVM is allowed to take a reference on the page. It was using the PG_reserved flag to determine this previously, however in the case of DAX the page has the PG_reserved flag set, but supports pinning by taking a reference on the page. As such I have updated the check to add a special case for ZONE_DEVICE pages that have the new support_refcount_pinning flag set. Signed-off-by: Alexander Duyck --- virt/kvm/kvm_main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5e666df5666d..2e7e9fbb67bf 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -148,8 +148,20 @@ __weak int kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, bool kvm_is_refcounted_pfn(kvm_pfn_t pfn) { - if (pfn_valid(pfn)) - return !PageReserved(pfn_to_page(pfn)); + if (pfn_valid(pfn)) { + struct page *page = pfn_to_page(pfn); + + /* + * The reference count for MMIO pages are not updated. + * Previously this was being tested for with just the + * PageReserved check, however now ZONE_DEVICE pages may + * also allow for the refcount to be updated for the sake + * of pinning the pages so use the additional check provided + * to determine if the reference count on the page can be + * used to pin it. + */ + return !PageReserved(page) || is_device_pinnable_page(page); + } return false; }