Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4291854ima; Mon, 4 Feb 2019 13:46:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IaQ4Dj+sVilAONMSTlDz/F+c3LMhgPRZuHbc/PW/ea4eQQI99dBuAp5E9LUk2QiJwxJD4/G X-Received: by 2002:a62:190e:: with SMTP id 14mr1514552pfz.70.1549316759972; Mon, 04 Feb 2019 13:45:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549316759; cv=none; d=google.com; s=arc-20160816; b=tMbbyY7Xto93ibvVNc+mkBBCqci2V317cy1k3Xc+7ZCS9Unb4g9SAcMuPxEl/8wt6A yHLGY33TxZ77wPoFEAF/aKb8pJhTsq69tAq7Y9PFa8QPApIJBT+OLO7RfIFww+9u0q2k VRDDUBqqO1UR4mvi2OWBOc+rwPBzhRY4djB3q6jZYTb1aX9AyQumFOPKyL1F56r/nwhh Jxv4MXy3gHcotCD4hBYM8rNAtr+WjVyOtFTQYb1kKpR6IeCFrhDlUDpB5gbA57xYBAQF 5gcXfjA2znAkIeUFMaJPEaXSOGV/8J7piJ1nPXWZpCbloUdlNnV7hah/ObbNaQVb9deB 2Z/Q== 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:to:from; bh=nDKFub+0NhB5XR1/C+/QfKP+yklDfmjZb3BxN5sRL7w=; b=Ugqug9RUB/ci97xyD4MpfICH8w/yOytTGgFbbU3Mx2oJF6Kc98EdBBbiJKWkRfvQFM UqyE1vJ1a2/vnEexbCzBBEaD55vQK9x2iyTk/MeNsBHHiqrmldsh+t/4ye/VoFRAes29 FLKNN0Qtgo0QARMWRcgGEO+h+FfA2D3ZmSKcJ5DAGk+d8X/BUvHR3UJLmKKET2B9ogmd aVUZ4p+Hy1HNif+6DtU2KY7ifP0zB7wJwylcF1huUjVz1SnDM4Sx7ugfdnCxxrzPjvUm 4Na1f0WR1/A/KE0bHTawSwvZjFCNHQxi5deTcX/U+y/Igd2Fy6IuIiCX0hB5l83SomRP NIAQ== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 79si1053760pgb.351.2019.02.04.13.45.44; Mon, 04 Feb 2019 13:45:59 -0800 (PST) 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728316AbfBDUT7 (ORCPT + 99 others); Mon, 4 Feb 2019 15:19:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46878 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727795AbfBDUTm (ORCPT ); Mon, 4 Feb 2019 15:19:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2C7458E40; Mon, 4 Feb 2019 20:19:41 +0000 (UTC) Received: from virtlab420.virt.lab.eng.bos.redhat.com (virtlab420.virt.lab.eng.bos.redhat.com [10.19.152.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F0A375C79; Mon, 4 Feb 2019 20:19:39 +0000 (UTC) From: Nitesh Narayan Lal To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com, david@redhat.com, mst@redhat.com, dodgen@google.com, konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com Subject: [RFC][Patch v8 3/7] KVM: Guest free page hinting functional skeleton Date: Mon, 4 Feb 2019 15:18:50 -0500 Message-Id: <20190204201854.2328-4-nitesh@redhat.com> In-Reply-To: <20190204201854.2328-1-nitesh@redhat.com> References: <20190204201854.2328-1-nitesh@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 04 Feb 2019 20:19:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the functional skeleton for the guest implementation. It also enables the guest to maintain the list of pages which are freed by the guest. Once the list is full guest_free_page invokes scan_array() which wakes up the kernel thread responsible for further processing. Signed-off-by: Nitesh Narayan Lal --- include/linux/page_hinting.h | 3 ++ virt/kvm/page_hinting.c | 60 +++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/include/linux/page_hinting.h b/include/linux/page_hinting.h index 9bdcf63e1306..2d7ff59f3f6a 100644 --- a/include/linux/page_hinting.h +++ b/include/linux/page_hinting.h @@ -1,3 +1,5 @@ +#include + /* * Size of the array which is used to store the freed pages is defined by * MAX_FGPT_ENTRIES. If possible, we have to find a better way using which @@ -16,6 +18,7 @@ struct hypervisor_pages { extern int guest_page_hinting_flag; extern struct static_key_false guest_page_hinting_key; +extern struct smp_hotplug_thread hinting_threads; int guest_page_hinting_sysctl(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos); diff --git a/virt/kvm/page_hinting.c b/virt/kvm/page_hinting.c index 4a34ea8db0c8..636990e7fbb3 100644 --- a/virt/kvm/page_hinting.c +++ b/virt/kvm/page_hinting.c @@ -1,7 +1,7 @@ #include #include -#include #include +#include /* * struct kvm_free_pages - Tracks the pages which are freed by the guest. @@ -37,6 +37,7 @@ EXPORT_SYMBOL(guest_page_hinting_key); static DEFINE_MUTEX(hinting_mutex); int guest_page_hinting_flag; EXPORT_SYMBOL(guest_page_hinting_flag); +static DEFINE_PER_CPU(struct task_struct *, hinting_task); int guest_page_hinting_sysctl(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, @@ -54,6 +55,63 @@ int guest_page_hinting_sysctl(struct ctl_table *table, int write, return ret; } +static void hinting_fn(unsigned int cpu) +{ + struct page_hinting *page_hinting_obj = this_cpu_ptr(&hinting_obj); + + page_hinting_obj->kvm_pt_idx = 0; + put_cpu_var(hinting_obj); +} + +void scan_array(void) +{ + struct page_hinting *page_hinting_obj = this_cpu_ptr(&hinting_obj); + + if (page_hinting_obj->kvm_pt_idx == MAX_FGPT_ENTRIES) + wake_up_process(__this_cpu_read(hinting_task)); +} + +static int hinting_should_run(unsigned int cpu) +{ + struct page_hinting *page_hinting_obj = this_cpu_ptr(&hinting_obj); + int free_page_idx = page_hinting_obj->kvm_pt_idx; + + if (free_page_idx == MAX_FGPT_ENTRIES) + return 1; + else + return 0; +} + +struct smp_hotplug_thread hinting_threads = { + .store = &hinting_task, + .thread_should_run = hinting_should_run, + .thread_fn = hinting_fn, + .thread_comm = "hinting/%u", + .selfparking = false, +}; +EXPORT_SYMBOL(hinting_threads); + void guest_free_page(struct page *page, int order) { + unsigned long flags; + struct page_hinting *page_hinting_obj = this_cpu_ptr(&hinting_obj); + /* + * use of global variables may trigger a race condition between irq and + * process context causing unwanted overwrites. This will be replaced + * with a better solution to prevent such race conditions. + */ + + local_irq_save(flags); + if (page_hinting_obj->kvm_pt_idx != MAX_FGPT_ENTRIES) { + page_hinting_obj->kvm_pt[page_hinting_obj->kvm_pt_idx].pfn = + page_to_pfn(page); + page_hinting_obj->kvm_pt[page_hinting_obj->kvm_pt_idx].zonenum = + page_zonenum(page); + page_hinting_obj->kvm_pt[page_hinting_obj->kvm_pt_idx].order = + order; + page_hinting_obj->kvm_pt_idx += 1; + if (page_hinting_obj->kvm_pt_idx == MAX_FGPT_ENTRIES) + scan_array(); + } + local_irq_restore(flags); } -- 2.17.2