Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1565774imm; Fri, 7 Sep 2018 02:27:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbKY6ZJjve5DmWhbiF5SYZ6oZ1WCNcITtA4sdSxk1y30CH2Nwnq2ruHTHLgE/tENqp53s3m X-Received: by 2002:a62:c288:: with SMTP id w8-v6mr7515069pfk.92.1536312426736; Fri, 07 Sep 2018 02:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536312426; cv=none; d=google.com; s=arc-20160816; b=F4FBz6zPLcXJBiXj5OosVfsUr3pW0qQ09a6bvUKkUtxS+woPROUco4VQnjitP1I4mL wjnGWCH4Jxr1XskHM6U1+WOwUE9ggi4jxyyr63YwmE/xkGJRebDhdAybn6ViQBm7SmfC HewmJjN44/nqPdOL0qUtXH9YF7nKEYehK9Ww33p9NkxgO7mtufKaU0CH4aYiwZltpY9h LSYDcrC9dM4G8hJV//BDtWROLavMR7iMi9ioDjHs4Y9/OJjlMByokHBw0A4M+sFV+sn5 eX6sgjXRJmJnbL8/dqVpQTa2SmQy0BGZWtAezdX0+lk7L1bTUT0DriipJuOIkWdP/g/N ORew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LytyC9t3+sNwUdANecEL3nPD2TALvqL+VTkhxu7fwHA=; b=YoDDV0TCo/TFXvuDDW+XAmZFlac2NYB5LATfG527QR26TuZwxyXXDUnBImDTL54YEq fjZd6boMKnfzSvh+N3wXQ60D6UF6sbIHJVNyMpL0LxWiRblerXLkX3ELuw8Rf5G4NeQO ujR+agrYcTaVD5wyN7TbP2yEayjWpNZB83q0t5XKb0kfKK3eYzytb74xb/o6eM6j5AN4 aOXqEg8xWWuHVYOlD+c1O24Nf1M8jluKaZKAlx7e7jkwZn8QPEkSQw3fyqe1k6fR1sUU lcEGKkMU0+ntIf7hrvTWut2JYa6O/213Ri9lxdt3X7I9oa/ipzZC8EmyTzZNjYC0i6+7 JqfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f97-v6si8103130plb.507.2018.09.07.02.26.51; Fri, 07 Sep 2018 02:27:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728410AbeIGOFJ (ORCPT + 99 others); Fri, 7 Sep 2018 10:05:09 -0400 Received: from mga14.intel.com ([192.55.52.115]:32754 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbeIGOFI (ORCPT ); Fri, 7 Sep 2018 10:05:08 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.7.4