linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Kagan <rkagan@virtuozzo.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	<x86@kernel.org>, Haiyang Zhang <haiyangz@microsoft.com>,
	<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devel@linuxdriverproject.org>,
	"Denis V . Lunev" <den@openvz.org>,
	Roman Kagan <rkagan@virtuozzo.com>
Subject: [PATCH 06/15] hyperv: avoid unnecessary vmalloc
Date: Tue, 20 Dec 2016 18:55:53 +0300	[thread overview]
Message-ID: <20161220155602.6298-7-rkagan@virtuozzo.com> (raw)
In-Reply-To: <20161220155602.6298-1-rkagan@virtuozzo.com>

Make hypercall and tsc page allocation similar to the rest of the
Hyper-V shared memory stuff instead of vmalloc-ing them.

Also perform cleanup unconditionally which is safe.

TODO: the skipping of free in case of a crash is probably no longer
necessary, too.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 drivers/hv/hv.c | 42 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 6bbc0b09..b40c7d9 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -29,6 +29,7 @@
 #include <linux/version.h>
 #include <linux/interrupt.h>
 #include <linux/clockchips.h>
+#include <asm/cacheflush.h>
 #include <asm/hyperv.h>
 #include <asm/mshyperv.h>
 #include "hyperv_vmbus.h"
@@ -208,14 +209,15 @@ int hv_init(void)
 	/* See if the hypercall page is already set */
 	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
 
-	virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
-
-	if (!virtaddr)
+	virtaddr = (void *)get_zeroed_page(GFP_KERNEL);
+	if (!virtaddr || set_memory_x((unsigned long)virtaddr, 1))
 		goto cleanup;
+	hv_context.hypercall_page = virtaddr;
 
 	hypercall_msr.enable = 1;
 
-	hypercall_msr.guest_physical_address = vmalloc_to_pfn(virtaddr);
+	hypercall_msr.guest_physical_address =
+				virt_to_phys(virtaddr) >> PAGE_SHIFT;
 	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
 
 	/* Confirm that hypercall page did get setup. */
@@ -225,14 +227,12 @@ int hv_init(void)
 	if (!hypercall_msr.enable)
 		goto cleanup;
 
-	hv_context.hypercall_page = virtaddr;
-
 #ifdef CONFIG_X86_64
 	if (ms_hyperv.features & HV_X64_MSR_REFERENCE_TSC_AVAILABLE) {
 		union hv_x64_msr_hypercall_contents tsc_msr;
 		void *va_tsc;
 
-		va_tsc = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL);
+		va_tsc = (void *)get_zeroed_page(GFP_KERNEL);
 		if (!va_tsc)
 			goto cleanup;
 		hv_context.tsc_page = va_tsc;
@@ -240,7 +240,8 @@ int hv_init(void)
 		rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
 
 		tsc_msr.enable = 1;
-		tsc_msr.guest_physical_address = vmalloc_to_pfn(va_tsc);
+		tsc_msr.guest_physical_address =
+				virt_to_phys(va_tsc) >> PAGE_SHIFT;
 
 		wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
 		clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
@@ -249,14 +250,9 @@ int hv_init(void)
 	return 0;
 
 cleanup:
-	if (virtaddr) {
-		if (hypercall_msr.enable) {
-			hypercall_msr.as_uint64 = 0;
-			wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-		}
-
-		vfree(virtaddr);
-	}
+	hypercall_msr.as_uint64 = 0;
+	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	free_page((unsigned long)virtaddr);
 
 	return -ENOTSUPP;
 }
@@ -273,13 +269,11 @@ void hv_cleanup(bool crash)
 	/* Reset our OS id */
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
 
-	if (hv_context.hypercall_page) {
-		hypercall_msr.as_uint64 = 0;
-		wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
-		if (!crash)
-			vfree(hv_context.hypercall_page);
-		hv_context.hypercall_page = NULL;
-	}
+	hypercall_msr.as_uint64 = 0;
+	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+	if (!crash)
+		free_page((unsigned long)hv_context.hypercall_page);
+	hv_context.hypercall_page = NULL;
 
 #ifdef CONFIG_X86_64
 	/*
@@ -298,7 +292,7 @@ void hv_cleanup(bool crash)
 		hypercall_msr.as_uint64 = 0;
 		wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
 		if (!crash)
-			vfree(hv_context.tsc_page);
+			free_page((unsigned long)hv_context.tsc_page);
 		hv_context.tsc_page = NULL;
 	}
 #endif
-- 
2.9.3

  parent reply	other threads:[~2016-12-20 18:28 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-20 15:55 [PATCH 00/15] hyperv: more stuff to uapi + cleanup Roman Kagan
2016-12-20 15:55 ` [PATCH 01/15] hyperv: consolidate TSC ref page definitions Roman Kagan
2016-12-20 20:57   ` KY Srinivasan
2016-12-21  6:25     ` Roman Kagan
2016-12-20 15:55 ` [PATCH 02/15] hyperv: uapi-fy synic event flags definitions Roman Kagan
2016-12-20 17:24   ` Stephen Hemminger
2016-12-21  6:33     ` Roman Kagan
2016-12-21 10:58   ` kbuild test robot
2016-12-21 18:58   ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 03/15] hyperv: use standard bitops Roman Kagan
2016-12-21 12:00   ` Olaf Hering
2016-12-21 13:23     ` Roman Kagan
2016-12-22 12:33       ` Paolo Bonzini
2016-12-21 19:08   ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 04/15] hyperv: define VMBus message type Roman Kagan
2016-12-20 15:55 ` [PATCH 05/15] hyperv: GFP_ATOMIC -> GFP_KERNEL Roman Kagan
2016-12-20 15:55 ` Roman Kagan [this message]
2016-12-21 19:19   ` [PATCH 06/15] hyperv: avoid unnecessary vmalloc KY Srinivasan
2016-12-20 15:55 ` [PATCH 07/15] hyperv: dedup cpuid definitions Roman Kagan
2016-12-20 15:55 ` [PATCH 08/15] hyperv: dedup crash msr related definitions Roman Kagan
2016-12-20 15:55 ` [PATCH 09/15] hyperv: unify Hyper-V msr definitions Roman Kagan
2016-12-20 15:55 ` [PATCH 10/15] hyperv: uapi-fy PostMessage and SignalEvent hypercall structures Roman Kagan
2016-12-21 19:27   ` KY Srinivasan
2016-12-20 15:55 ` [PATCH 11/15] hyperv: uapi-fy monitored notification structures Roman Kagan
2016-12-20 15:55 ` [PATCH 12/15] hyperv: move VMBus connection ids to uapi Roman Kagan
2016-12-20 17:25   ` Stephen Hemminger
2016-12-21  6:29     ` Roman Kagan
2016-12-21 12:18       ` Christoph Hellwig
2016-12-21 12:59         ` Roman Kagan
2016-12-21 14:26           ` Christoph Hellwig
2016-12-21 14:39             ` Roman Kagan
2016-12-21 15:39             ` Paolo Bonzini
2016-12-21 15:43               ` Christoph Hellwig
2016-12-21 17:25                 ` Paolo Bonzini
2016-12-21 17:50                 ` Stephen Hemminger
2016-12-21 17:53                   ` Paolo Bonzini
2016-12-21 17:58                   ` Christoph Hellwig
2016-12-21 18:02                     ` Stephen Hemminger
2016-12-21 19:54                       ` KY Srinivasan
2016-12-28 17:09                         ` Roman Kagan
2016-12-29 18:29                           ` Stephen Hemminger
2017-01-02  8:19                           ` Paolo Bonzini
2017-01-09  8:32                             ` Roman Kagan
2017-01-09  8:40                               ` hpa
2017-01-09  8:58                                 ` Roman Kagan
2017-01-09  9:02                                 ` Paolo Bonzini
2017-01-02 19:39                           ` Stephen Hemminger
2017-01-03  9:32                             ` Paolo Bonzini
2016-12-20 15:56 ` [PATCH 13/15] hyperv: move function close to its only callsite Roman Kagan
2016-12-20 15:56 ` [PATCH 14/15] hyperv_vmbus: drop unused definitions Roman Kagan
2016-12-20 15:56 ` [PATCH 15/15] hyperv: redefine hv_message without bitfields Roman Kagan
2016-12-21 18:00 ` [PATCH 00/15] hyperv: more stuff to uapi + cleanup KY Srinivasan
2016-12-28 16:57   ` Roman Kagan
2016-12-30 19:45     ` KY Srinivasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161220155602.6298-7-rkagan@virtuozzo.com \
    --to=rkagan@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).