From patchwork Tue Aug 1 20:48:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Lal X-Patchwork-Id: 9875489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AA82B60365 for ; Tue, 1 Aug 2017 20:49:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C5E920243 for ; Tue, 1 Aug 2017 20:49:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DDC028743; Tue, 1 Aug 2017 20:49:56 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B2B220243 for ; Tue, 1 Aug 2017 20:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752698AbdHAUty (ORCPT ); Tue, 1 Aug 2017 16:49:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37062 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752678AbdHAUtk (ORCPT ); Tue, 1 Aug 2017 16:49:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B517BCA39F; Tue, 1 Aug 2017 20:49:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B517BCA39F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=nilal@redhat.com Received: from Dungeon.bos.redhat.com (dhcp-17-195.bos.redhat.com [10.18.17.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92C4360BE9; Tue, 1 Aug 2017 20:49:39 +0000 (UTC) From: Nitesh Narayan Lal To: kvm@vger.kernel.org Cc: riel@redhat.com, mst@redhat.com, david@redhat.com, yang.zhang.wz@gmail.com, pagupta@redhat.com, wei.w.wang@intel.com, Nitesh Narayan Lal Subject: [PATCH 1/3] KVM: Support for guest page hinting Date: Tue, 1 Aug 2017 16:48:04 -0400 Message-Id: <20170801204806.23938-2-nilal@redhat.com> In-Reply-To: <20170801204806.23938-1-nilal@redhat.com> References: <20170801204806.23938-1-nilal@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 01 Aug 2017 20:49:40 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch includes the following: 1. Basic skeleton for the support 2. Enablement of x86 platform to use the same Signed-off-by: Nitesh Narayan Lal --- arch/x86/kvm/Makefile | 1 + include/linux/gfp.h | 7 +++++++ virt/kvm/Kconfig | 4 ++++ virt/kvm/page_hinting.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 virt/kvm/page_hinting.c diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile index 09d4b17..6f7c382 100644 --- a/arch/x86/kvm/Makefile +++ b/arch/x86/kvm/Makefile @@ -10,6 +10,7 @@ KVM := ../../../virt/kvm kvm-y += $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o \ $(KVM)/eventfd.o $(KVM)/irqchip.o $(KVM)/vfio.o kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o +kvm-$(CONFIG_KVM_FREE_PAGE_HINTING) += $(KVM)/page_hinting.o kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \ i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \ diff --git a/include/linux/gfp.h b/include/linux/gfp.h index a89d37e..37963b8 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -424,6 +424,13 @@ static inline struct zonelist *node_zonelist(int nid, gfp_t flags) return NODE_DATA(nid)->node_zonelists + gfp_zonelist(flags); } +#ifdef CONFIG_KVM_FREE_PAGE_HINTING +#define HAVE_ARCH_ALLOC_PAGE +#define HAVE_ARCH_FREE_PAGE +void arch_free_page(struct page *page, int order); +void arch_alloc_page(struct page *page, int order); +#endif + #ifndef HAVE_ARCH_FREE_PAGE static inline void arch_free_page(struct page *page, int order) { } #endif diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index b0cc1a3..57f1c7b 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -50,3 +50,7 @@ config KVM_COMPAT config HAVE_KVM_IRQ_BYPASS bool + +config KVM_FREE_PAGE_HINTING + def_bool m + depends on KVM diff --git a/virt/kvm/page_hinting.c b/virt/kvm/page_hinting.c new file mode 100644 index 0000000..39d2b1d --- /dev/null +++ b/virt/kvm/page_hinting.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +#include + +#define MAX_FGPT_ENTRIES 1000 +#define HYPERLIST_THRESHOLD 500 +/* + * struct kvm_free_pages - Tracks the pages which are freed by the guest. + * @pfn - page frame number for the page which is to be freed + * @pages - number of pages which are supposed to be freed. + * A global array object is used to hold the list of pfn and number of pages + * which are freed by the guest. This list may also have fragmentated pages so + * defragmentation is a must prior to the hypercall. + */ +struct kvm_free_pages { + unsigned long pfn; + unsigned int pages; +}; + +/* + * hypervisor_pages - It is a dummy structure passed with the hypercall. + * @pfn - page frame number for the page which is to be freed. + * @pages - number of pages which are supposed to be freed. + * A global array object is used to to hold the list of pfn and pages and is + * passed as part of the hypercall. + */ +struct hypervisor_pages { + unsigned long pfn; + unsigned int pages; +}; + +DEFINE_PER_CPU(struct kvm_free_pages [MAX_FGPT_ENTRIES], kvm_pt); +DEFINE_PER_CPU(int, kvm_pt_idx); +struct hypervisor_pages hypervisor_pagelist[MAX_FGPT_ENTRIES]; + +void arch_alloc_page(struct page *page, int order) +{ +} + +void arch_free_page(struct page *page, int order) +{ +}