From owner-svn-src-stable@freebsd.org Wed Apr 19 03:06:29 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 37645D45980; Wed, 19 Apr 2017 03:06:29 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DE0EFB18; Wed, 19 Apr 2017 03:06:28 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3J36S48047774; Wed, 19 Apr 2017 03:06:28 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3J36SCF047773; Wed, 19 Apr 2017 03:06:28 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201704190306.v3J36SCF047773@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Wed, 19 Apr 2017 03:06:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r317115 - stable/10/sys/dev/hyperv/vmbus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Apr 2017 03:06:29 -0000 Author: sephe Date: Wed Apr 19 03:06:27 2017 New Revision: 317115 URL: https://svnweb.freebsd.org/changeset/base/317115 Log: MFC 317107 hyperv: Use kmem_malloc for hypercall memory due to NX bit change. Reported by: dexuan@ Sponsored by: Microsoft Modified: stable/10/sys/dev/hyperv/vmbus/hyperv.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hyperv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hyperv.c Wed Apr 19 03:03:46 2017 (r317114) +++ stable/10/sys/dev/hyperv/vmbus/hyperv.c Wed Apr 19 03:06:27 2017 (r317115) @@ -34,9 +34,15 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include +#include +#include +#include +#include + #include #include #include @@ -64,7 +70,7 @@ __FBSDID("$FreeBSD$"); struct hypercall_ctx { void *hc_addr; - struct hyperv_dma hc_dma; + vm_paddr_t hc_paddr; }; static u_int hyperv_get_timecount(struct timecounter *); @@ -255,8 +261,8 @@ SYSINIT(hyperv_initialize, SI_SUB_HYPERV static void hypercall_memfree(void) { - hyperv_dmamem_free(&hypercall_context.hc_dma, - hypercall_context.hc_addr); + kmem_free(kernel_arena, (vm_offset_t)hypercall_context.hc_addr, + PAGE_SIZE); hypercall_context.hc_addr = NULL; } @@ -268,14 +274,15 @@ hypercall_create(void *arg __unused) if (vm_guest != VM_GUEST_HV) return; - hypercall_context.hc_addr = hyperv_dmamem_alloc(NULL, PAGE_SIZE, 0, - PAGE_SIZE, &hypercall_context.hc_dma, BUS_DMA_WAITOK); - if (hypercall_context.hc_addr == NULL) { - printf("hyperv: Hypercall page allocation failed\n"); - /* Can't perform any Hyper-V specific actions */ - vm_guest = VM_GUEST_VM; - return; - } + /* + * NOTE: + * - busdma(9), i.e. hyperv_dmamem APIs, can _not_ be used due to + * the NX bit. + * - Assume kmem_malloc() returns properly aligned memory. + */ + hypercall_context.hc_addr = (void *)kmem_malloc(kernel_arena, PAGE_SIZE, + M_WAITOK); + hypercall_context.hc_paddr = vtophys(hypercall_context.hc_addr); /* Get the 'reserved' bits, which requires preservation. */ hc_orig = rdmsr(MSR_HV_HYPERCALL); @@ -285,7 +292,7 @@ hypercall_create(void *arg __unused) * * NOTE: 'reserved' bits MUST be preserved. */ - hc = ((hypercall_context.hc_dma.hv_paddr >> PAGE_SHIFT) << + hc = ((hypercall_context.hc_paddr >> PAGE_SHIFT) << MSR_HV_HYPERCALL_PGSHIFT) | (hc_orig & MSR_HV_HYPERCALL_RSVD_MASK) | MSR_HV_HYPERCALL_ENABLE;