Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759690AbcLUTTn (ORCPT ); Wed, 21 Dec 2016 14:19:43 -0500 Received: from mail-by2nam01on0099.outbound.protection.outlook.com ([104.47.34.99]:43150 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753095AbcLUTTm (ORCPT ); Wed, 21 Dec 2016 14:19:42 -0500 From: KY Srinivasan To: Roman Kagan , Paolo Bonzini , =?iso-8859-2?Q?Radim_Kr=E8m=E1=F8?= , Vitaly Kuznetsov CC: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "x86@kernel.org" , "Haiyang Zhang" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "devel@linuxdriverproject.org" , "Denis V . Lunev" Subject: RE: [PATCH 06/15] hyperv: avoid unnecessary vmalloc Thread-Topic: [PATCH 06/15] hyperv: avoid unnecessary vmalloc Thread-Index: AQHSWtmwboleRSgxy0SHm0T207NOMKESxckw Date: Wed, 21 Dec 2016 19:19:39 +0000 Message-ID: References: <20161220155602.6298-1-rkagan@virtuozzo.com> <20161220155602.6298-7-rkagan@virtuozzo.com> In-Reply-To: <20161220155602.6298-7-rkagan@virtuozzo.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=kys@microsoft.com; x-originating-ip: [2601:600:8c00:1040:b076:3b2a:409c:285e] x-ms-office365-filtering-correlation-id: 5d23b268-3f50-4c59-be6f-08d429d64f81 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BLUPR03MB1411; x-microsoft-exchange-diagnostics: 1;BLUPR03MB1411;7:meVhsHi/oAtMA0ZkjiU8FA8xSbtEPmEu+SFA+8xMxugaIR83og9ze5N0O3kziA1ANRbjzlDNFLoXwA8HJOP/ZTpy5F6Lzj+WBOglqbpmE7zl55buIKhDdFiUPTypIXy0rznM6HxD71hyyNqfXu6aajuTkyHce9xDoSedX60NkIrgRqG+ypT64sfBsUKOs3AYZ3v+AzJi0H0wTC5p5ZIwm4fETFpCYVeBr6UjmEsQUjSTxRbzI+ftAIEy9Dbt2qxibksW1ZizNEGf3hRX7lE7f3pYW47nNMBK48xYAT487S29y60qZZZ6aeP2i8im93Fy8rSRa9Pz6xlYbiwMwca4gap4tq0QVWVQx7me2+Ow6DQG1POhANHOge40+wWk1/jFaqnLPJ6voVKrJgzjdUuf2UdBMpMG5pNieuXIAgOG/z2oG4b/1UxerovuxhkWqbCJBIvwjqylXHOc73/NcUaCfp3rlZ2JM8JS5GhxwS7SrWw= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041248)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(6072148)(6047074);SRVR:BLUPR03MB1411;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1411; x-forefront-prvs: 01630974C0 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(39850400002)(39840400002)(39410400002)(39450400003)(39860400002)(377454003)(199003)(13464003)(189002)(6116002)(81156014)(81166006)(102836003)(2906002)(92566002)(50986999)(8676002)(4326007)(7416002)(3660700001)(3280700002)(76176999)(9686002)(68736007)(8936002)(2900100001)(101416001)(54356999)(6436002)(6506006)(229853002)(77096006)(38730400001)(7696004)(25786008)(76576001)(189998001)(86612001)(5001770100001)(33656002)(97736004)(86362001)(575784001)(2950100002)(305945005)(7736002)(10090500001)(74316002)(99286002)(122556002)(106116001)(5005710100001)(105586002)(106356001)(5660300001)(8990500004)(10290500002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB1411;H:DM5PR03MB2490.namprd03.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Dec 2016 19:19:39.8514 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1411 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uBLJJmR3018066 Content-Length: 4495 Lines: 145 > -----Original Message----- > From: Roman Kagan [mailto:rkagan@virtuozzo.com] > Sent: Tuesday, December 20, 2016 7:56 AM > To: Paolo Bonzini ; Radim Kr?m?? > ; KY Srinivasan ; Vitaly > Kuznetsov > Cc: Thomas Gleixner ; Ingo Molnar > ; H. Peter Anvin ; x86@kernel.org; > Haiyang Zhang ; kvm@vger.kernel.org; linux- > kernel@vger.kernel.org; devel@linuxdriverproject.org; Denis V . Lunev > ; Roman Kagan > Subject: [PATCH 06/15] hyperv: avoid unnecessary vmalloc > > 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. Please breakup these patches. > > 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; Have you tested this patch. > + 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