From patchwork Fri Sep 7 18:04:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10591935 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 5C18D13BB for ; Fri, 7 Sep 2018 09:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5535A2861C for ; Fri, 7 Sep 2018 09:25:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 492392AD9C; Fri, 7 Sep 2018 09:25:08 +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=-1.0 required=2.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, 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 DADC22861C for ; Fri, 7 Sep 2018 09:25:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C174B6B7DA6; Fri, 7 Sep 2018 05:25:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BC5F76B7DA7; Fri, 7 Sep 2018 05:25:06 -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 ADD816B7DA8; Fri, 7 Sep 2018 05:25:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 69C516B7DA6 for ; Fri, 7 Sep 2018 05:25:06 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id l65-v6so6926264pge.17 for ; Fri, 07 Sep 2018 02:25:06 -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; bh=LytyC9t3+sNwUdANecEL3nPD2TALvqL+VTkhxu7fwHA=; b=J7GVZaB0fuZF4AI9eDOU5fDTb3rrXwGaxRUfs8vEl52/Gtbus30eFiolOIdPO87zoY AGrgtDMrgJ3M9lefKsJc3Ah6K36o2oV7zKp95Ck/y8U/4+PW9AxldSndPXS6uNOA81Bt ZK6A6p/7yueV5R6Spr4ppa0oXBFOd8vxtRQJvOATIFKR0cAhi+CsVZfpX71SwFQKRdQs W1SmT/M/UJ4kaqnF2IYctW0TWe8Do9NhhCi2Tgxls8TAW/dX9RpC+QjpaDEPPnSFLoGX /wkjeLIfvuYgZnsim8sqzy0n5MU/zK7Re58DiZVx1KLYr4Ms5fI3uFETCQY5w0iWt7x5 8wUw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of yi.z.zhang@linux.intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=yi.z.zhang@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APzg51ArzSghh+Cb3pQgn/Qr8nfK1ZaqrklICWTseZsH4u6YbLW0Vz/j tMw6ctT6fsMtk1PglMW0Lbwpuq6NQ+gkBEBNPCsVjRjYSWhpxWUQhDjROFTWqXPcC3CBK81sIzu +xxU5uu3Gq3fYl42vjDZJvgXZ0uybmQc/g1vGHnODgwO/oEucXcUhyLSVaRbAqJsstQ== X-Received: by 2002:a17:902:b115:: with SMTP id q21-v6mr7023171plr.333.1536312306092; Fri, 07 Sep 2018 02:25:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZQxEuaDygbmGvUKlDZ+K3W2gEEaNi3fwhX+z7FuJKixBEajZTNId7UPwnxcMsKiEWVZakm X-Received: by 2002:a17:902:b115:: with SMTP id q21-v6mr7023112plr.333.1536312305399; Fri, 07 Sep 2018 02:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536312305; cv=none; d=google.com; s=arc-20160816; b=0Z5sL3UT/JSdiKglI9oArg1KOw3uA6IajHpGpi64yNYCdVXUeGA3P5YVi2gydNs+GQ T6SGm/p0b7wju+kTBSpJOkmNk5gdhxXon7epxfeccPfhpyYz+lSwohAjt0nkg+Dp62U1 Au4qUJAtF9DAb92D7rw8ZjVEH7DlFMirulh+np9IyRykTr/CknaUhHFO2RG738NYf8KM Pq8yIWdQstiuN3IEO4UzA3cSE22pK8Uaht2Sc7q1LL2mRkxY+WjtI6iedH6nCASicjj2 J8JjJm8BLdwiF2ArxCsdSHAoXxxC2OikYZtuk5dc6AK0xF+PkceewLjCH4tN62A3NuqX EYbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=LytyC9t3+sNwUdANecEL3nPD2TALvqL+VTkhxu7fwHA=; b=KmNYKEMP+ZxcVkWh/FKIUmYM+bvymrs0dseaAbr4ANFPNsFZAbiSpEx/QkQhnDt4A4 +PuTALLxylhDYpTEVg5WxTZzIAUGjr6wnj+L00G8YQcqbFep+VICLGJ0gYfBmqxJgOkn ScchoBllykiTayp9TIW53E7HRv3ZHV4z8eUz/Hse41j36WABZ9aIOdoGTJOA74JfGxZ3 tm6EWIj9aE8za9eahHPviScrEtEJL/IrqWbb71ozGOZ1fF5vzKZ8zo7hXVwfXex8meTC vIT60IhbP1qrlztqxCN9wtDCbrf53H0LVTBg5r7hkHZarz0f+phoDz9Fy5BhRSbCcpN0 qFMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of yi.z.zhang@linux.intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=yi.z.zhang@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id d11-v6si8006684pgh.564.2018.09.07.02.25.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 02:25:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of yi.z.zhang@linux.intel.com designates 134.134.136.24 as permitted sender) client-ip=134.134.136.24; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of yi.z.zhang@linux.intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=yi.z.zhang@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 orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2018 02:25:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,341,1531810800"; d="scan'208";a="81637128" Received: from linux.intel.com ([10.54.29.200]) by orsmga003.jf.intel.com with ESMTP; 07 Sep 2018 02:25:04 -0700 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.163]) by linux.intel.com (Postfix) with ESMTP id 5C75C5803DA; Fri, 7 Sep 2018 02:25:02 -0700 (PDT) From: Zhang Yi To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, pbonzini@redhat.com, dan.j.williams@intel.com, dave.jiang@intel.com, yu.c.zhang@intel.com, pagupta@redhat.com, david@redhat.com, jack@suse.cz, hch@lst.de Cc: linux-mm@kvack.org, rkrcmar@redhat.com, jglisse@redhat.com, yi.z.zhang@intel.com, Zhang Yi Subject: [PATCH V5 4/4] kvm: add a check if pfn is from NVDIMM pmem. Date: Sat, 8 Sep 2018 02:04:08 +0800 Message-Id: <4e8c2e0facd46cfaf4ab79e19c9115958ab6f218.1536342881.git.yi.z.zhang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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 For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem. Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved, the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to identify these pages are from NVDIMM pmem and let kvm treat these as normal pages. Without this patch, many operations will be missed due to this mistreatment to pmem pages, for example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean), not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc. Signed-off-by: Zhang Yi Acked-by: Pankaj Gupta 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 c44c406..9c49634 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -147,8 +147,20 @@ __weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, bool kvm_is_reserved_pfn(kvm_pfn_t pfn) { - if (pfn_valid(pfn)) - return PageReserved(pfn_to_page(pfn)); + struct page *page; + + if (pfn_valid(pfn)) { + page = pfn_to_page(pfn); + + /* + * For device specific memory space, there is a case + * which we need pass MEMORY_DEVICE_FS[DEV]_DAX pages + * to kvm, these pages marked reserved flag as it is a + * zone device memory, we need to identify these pages + * and let kvm treat these as normal pages + */ + return PageReserved(page) && !is_dax_page(page); + } return true; }