From patchwork Wed Aug 22 10:58:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10572537 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 F3AAB1390 for ; Wed, 22 Aug 2018 02:19:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8E822B338 for ; Wed, 22 Aug 2018 02:19:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCB322B337; Wed, 22 Aug 2018 02:19:22 +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 B7AF92B337 for ; Wed, 22 Aug 2018 02:19:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBEC16B21F6; Tue, 21 Aug 2018 22:19:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E6E466B21F7; Tue, 21 Aug 2018 22:19:20 -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 D5EDE6B21F8; Tue, 21 Aug 2018 22:19:20 -0400 (EDT) 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 8E4DB6B21F6 for ; Tue, 21 Aug 2018 22:19:20 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id l65-v6so290867pge.17 for ; Tue, 21 Aug 2018 19:19:20 -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=/S5I0vc4uBBKNzwfsj2Hye0o7S98ojvXNwNXYVIqaJA=; b=Xl3wbzEjZdn3LD07FVrHrZacG+bnmM9tC2mLvt6Vaqkb4+TfMIQQexPBdsoFokANZ0 TPvf0dCClYCJakHuncTUPAyvNtrz5Ph2oX4wp6osi+wU6qiwigGbyF/cbTPx9382wQIQ 6hztQWUsX5ncKdtNSPNRp5ozJdRZ91Qjgnt/Is8tFeJ+gm3Y7ydrMIlEi8tsC5D+bOew mOe/f4IzxDtmdv9hFMsAAsQhPTp4O2rE4f+ZgArKsy7u0qK4vc/rnzImI/p4ynjSzm78 Bc3n5jGo0+1IuYGMiNQkpgMrSKV5FSnJO2HqGzPs+m0PslMlbySwGF5m5PusPU/M0PIt NGDg== 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.65 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: AOUpUlFrINsT2xbioou5fNKadc68EnY/WKTbis4zjaNYdmTgRZmD4Wqe MCbXOZYypM3WXYRYMvbvEVfnRorfpALYZ7XJPNJzG9BMdGdNRS1kNOhwps3kAX0XhCBewXelw1t thTnOAniS3pNIlPierzBDb3GuhXpf7HJNhPT9GNNlrm09QjZy9+jZn4lJ37LbIvqT7A== X-Received: by 2002:a63:5856:: with SMTP id i22-v6mr10215757pgm.232.1534904360252; Tue, 21 Aug 2018 19:19:20 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyAQxk824oN6T7VHjvcZ900WwsJF800vyPxsUJyo6jQaDjE54BYU0B3XzIU5VX7b1p77Bz0 X-Received: by 2002:a63:5856:: with SMTP id i22-v6mr10215732pgm.232.1534904359598; Tue, 21 Aug 2018 19:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534904359; cv=none; d=google.com; s=arc-20160816; b=ruGiqLqbYcNPlPL2PGQoW6B3/KI8O9VIvIbbRXUMzjZf5Pf1ak88IkDO6xRI5mefMr DpfrY9ivx1n+jYu+xpEszdTd+wdTGjNAwDwG1WPLX1MWjA95OIBNJG1i7vy0w62qetFH fiweUAgh87wvHoZThsEpTew7U7Uiy7dLGcdy7ChhmkJknuQ7itI85KCCqHEqwNBV5+1L M8uOWvR6UcxxnE3nKQNwIOWoN5O5Ped4Slg1R4j4JaStEfAmT9svJoaYH5Qck/NRne4o ose9ArgSbWUvtSoXfbWebwDBgxNK9mT+gLFa/XXqXuX4f6BKM3DS6b5gD25PXeRm/Bnr MpJw== 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 :arc-authentication-results; bh=/S5I0vc4uBBKNzwfsj2Hye0o7S98ojvXNwNXYVIqaJA=; b=v6Bu3+1Zz8c24vKT5lY41EDHCqPaaYwDmom8PzYz4U33TdaVZJVvxJJOuCjvPDMpBd GlnP2g0MJfyctTYfNgHjQoU+dn0LN2PRLO1yiygbbeaC5p0VCfLUEG5fdFW6EQqPIuv+ n55H6UEQF/dc5EDEr2rbgeZg825jNk/12qLc8Y84z6vM/QcDsiRrYrZD7/8YfA82XREc yBPiQEjXFuy1sdru/7vi+OQ+Ke3jTay/ID8nv2OwBKHlWEwr9Yaov85l0JJLrgTbsrG4 Xo6hXyGxIQvr9D0J528X35mm9f+/J2a10dvT6fLt6pg590RaZxNs6eb4C75ZCBXJYhLT waJQ== 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.65 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 mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id 30-v6si451463pgt.678.2018.08.21.19.19.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 19:19:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of yi.z.zhang@linux.intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; 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.65 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 fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Aug 2018 19:19:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,272,1531810800"; d="scan'208";a="83404610" Received: from linux.intel.com ([10.54.29.200]) by fmsmga001.fm.intel.com with ESMTP; 21 Aug 2018 19:19:18 -0700 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.163]) by linux.intel.com (Postfix) with ESMTP id 95AB55802C8; Tue, 21 Aug 2018 19:19:15 -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 V4 4/4] kvm: add a check if pfn is from NVDIMM pmem. Date: Wed, 22 Aug 2018 18:58:10 +0800 Message-Id: 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 --- virt/kvm/kvm_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c44c406..969b6ca 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -147,8 +147,12 @@ __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); + return PageReserved(page) && !is_dax_page(page); + } return true; }