Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764748AbcLTS2d (ORCPT ); Tue, 20 Dec 2016 13:28:33 -0500 Received: from mail-db5eur01on0115.outbound.protection.outlook.com ([104.47.2.115]:62528 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1764593AbcLTS2a (ORCPT ); Tue, 20 Dec 2016 13:28:30 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; From: Roman Kagan To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , "K. Y. Srinivasan" , Vitaly Kuznetsov CC: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Haiyang Zhang , , , , "Denis V . Lunev" , Roman Kagan Subject: [PATCH 06/15] hyperv: avoid unnecessary vmalloc Date: Tue, 20 Dec 2016 18:55:53 +0300 Message-ID: <20161220155602.6298-7-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161220155602.6298-1-rkagan@virtuozzo.com> References: <20161220155602.6298-1-rkagan@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM4PR01CA0030.eurprd01.prod.exchangelabs.com (10.164.74.168) To VI1PR0802MB2478.eurprd08.prod.outlook.com (10.175.26.21) X-MS-Office365-Filtering-Correlation-Id: bdebcb8e-304c-4c0a-1869-08d428f0cde4 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0802MB2478; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;3:RrHh4cFZPxf8yj/6/6CWV78JPB6X/rm5PbXqFM9jDxHKYRSQoNpgiLH/14uTzaiGvHVv1owEc0AaCeISILdzTJBc66aH2TcOHw2vGUCH0bGpX7ARxkT1IkC5jGhF7mhZx6wvjDaqBcIjVPmsF6IZ9abT9P8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2M339y8SrSummzGucNZ3rOo21EWR/G+3IbYKD2uBXMhcFF3fO5WO2oUC+0pLBEm9FlWbTPW7AW0PWcUudGqPLknIp8taM3qDDUr0+kA7N X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123555025)(20161123560025)(20161123558021)(20161123562025)(6072148);SRVR:VI1PR0802MB2478;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0802MB2478; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;4:79zOskO1cdGkhffmJY8Tsr2CCLIa9WPakCh/mhnyY+9CxcyWc8bpRhWVl+BVpQXU5FwWacN8mDF2pNjy/Q8Aa74CzpLh/CCQQsNiWj+fJUQwYbFjv6w+tWeu9gfpmiA89kAweG8A0RfuqPwHj1KTXwCwzaORRwwfVY5PaTkFiToO1M2HwUj48/J9K45PA0CR+SPigW7db03+0gZ/tyjethDULtCoWODPLYruLgRRUwKDSeHgdDSynhV29jCy8wfypNWWaGOq5rR7XUC4U3G5WJtDx4eEBBITPY83/L0xERbLvJFHBtGNEc+GO7bFuqghzJ1ZvWF512e9v5bbYIfFqswuT1p6BldcP7fE8JrsHLdRfdQdt8a9ar5dff4w3CBuvvZhEFnPchryT12mgz6kq6dUs/RdEc3X7xEUio9kvy3zXHcJ/YAGXPkYaFGK9hqMf/R3313rJXfaiNkTDo0octm70eJJHmQ/CuMBBG4eAhB+prTdLQrENX1SzH1GsaQs0xTXmHVHpFcusMqNu5b5zzd/HLk/BWIo81T2E4l1xza37xXr/sN9xXM1VKHTFTDkVoh2wGZSmC+0m+nv/3HRX9V5oRaYtnCfaDMHjYFsSmI= X-Forefront-PRVS: 0162ACCC24 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(199003)(189002)(6666003)(97736004)(189998001)(101416001)(5001770100001)(4001430100002)(5003940100001)(36756003)(81166006)(47776003)(50986999)(66066001)(1511001)(2950100002)(50466002)(76176999)(5660300001)(81156014)(2906002)(8666005)(305945005)(69596002)(48376002)(7736002)(92566002)(7416002)(106356001)(53416004)(25786008)(6116002)(105586002)(6486002)(2421001)(6506006)(1076002)(3846002)(575784001)(86362001)(4326007)(68736007)(8676002)(50226002)(42186005)(107886002)(2561002)(38730400001)(6512006)(33646002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0802MB2478;H:rkaganb.sw.ru;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR0802MB2478;23:39M2RyKRoGW1qw3NmaDo6IO/35a0FPawfu6UT+Z?= =?us-ascii?Q?PLpEs4avpmxRGo6nn+qXod4oYfQczEitrhRi1akJl6Wi4nUI6C8p0Ghshnoa?= =?us-ascii?Q?8QrBSHZcquzNraSKIrnFiwcyqVD1ToyBBtmG7TBHUDQkAPBux7WPB5BMVtl+?= =?us-ascii?Q?KJarF2XhyjbskWS+SAU/j4PKeDfj+GIDLyE6IrxZu1fc63TT8ew4zz3zUupe?= =?us-ascii?Q?g+jveFHJCK93osG4DzCBmgKDS8BcUkGT1gke203AhhCA9/lTzS4UuKxD7P4c?= =?us-ascii?Q?gs8hIwlHgxO/SnOL//dYuT9yQC2y/x/sLFi7Lj10OgPyIU29TBChEVz9kbGB?= =?us-ascii?Q?RSqCiENrirpu/4Cld326/BBLDsE34EQDq+NDQdfaFNsrWyLq7EhyOMSIlEGE?= =?us-ascii?Q?vjIuEGzKUK2FeAmTtscaWrQVC+QvDEw3dpMmL1C7gBktJccTyyYkuAb4XEwt?= =?us-ascii?Q?p94/WR0TnqHvSXnxu6JReuqwCVJu3P2nWkiZ9HUmykXl+gky+ccU1DfsLiU8?= =?us-ascii?Q?NZaKiowZ++imXjoeFmcJbtdbgvL/gnS8cuGgQtkIemyW8eHV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W+QIO1CNvxjbhr5Bpl66qIJ22jg1ou6vLMAjsnpus+l+6A+3vYhpXt7IcuPC3RgMWaA==;20:OwbyHOcX+ZxQq/cFvXg9Gt573Z/VeTDW2aDS2VvHEGZVa4Lc+OydkoH4BNkXjIQkZUScPkiVeZIBudMd7HADLEzRdB/5cNU/kkTfhdGQ9IFYNJ0Ak7RVc1VD4qH634tZ8o/MBZ4lKFJZfHnqVwbiT4ucviJH8BVGbkay7KBQ5vo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2016 15:56:46.7343 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2478 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3532 Lines: 119 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 --- 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 #include #include +#include #include #include #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