From owner-svn-src-stable-10@freebsd.org Sun Jun 19 00:39:24 2016 Return-Path: Delivered-To: svn-src-stable-10@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 97E91A78344; Sun, 19 Jun 2016 00:39:24 +0000 (UTC) (envelope-from cy@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 4FC252264; Sun, 19 Jun 2016 00:39:24 +0000 (UTC) (envelope-from cy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5J0dNNE008713; Sun, 19 Jun 2016 00:39:23 GMT (envelope-from cy@FreeBSD.org) Received: (from cy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5J0dN8D008711; Sun, 19 Jun 2016 00:39:23 GMT (envelope-from cy@FreeBSD.org) Message-Id: <201606190039.u5J0dN8D008711@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cy set sender to cy@FreeBSD.org using -f From: Cy Schubert Date: Sun, 19 Jun 2016 00:39:23 +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: r302015 - stable/10/sys/contrib/ipfilter/netinet 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jun 2016 00:39:24 -0000 Author: cy Date: Sun Jun 19 00:39:23 2016 New Revision: 302015 URL: https://svnweb.freebsd.org/changeset/base/302015 Log: MFC r300259: Enable the two ip_frag tuneables. The code is there but the two ip_frag tuneables aren't registered in the ipf_tuners linked list. This commmit enables the two existing ip_frag tuneables by registering them. MFC r300260: Remove extraneous blank line. Modified: stable/10/sys/contrib/ipfilter/netinet/ip_frag.c stable/10/sys/contrib/ipfilter/netinet/ip_frag.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/contrib/ipfilter/netinet/ip_frag.c ============================================================================== --- stable/10/sys/contrib/ipfilter/netinet/ip_frag.c Sat Jun 18 23:18:04 2016 (r302014) +++ stable/10/sys/contrib/ipfilter/netinet/ip_frag.c Sun Jun 19 00:39:23 2016 (r302015) @@ -112,7 +112,7 @@ static void ipf_frag_free __P((ipf_frag_ static frentry_t ipfr_block; -const ipftuneable_t ipf_tuneables[] = { +static ipftuneable_t ipf_frag_tuneables[] = { { { (void *)offsetof(ipf_frag_softc_t, ipfr_size) }, "frag_size", 1, 0x7fffffff, stsizeof(ipf_frag_softc_t, ipfr_size), @@ -189,6 +189,18 @@ ipf_frag_soft_create(softc) RWLOCK_INIT(&softf->ipfr_frag, "ipf fragment rwlock"); RWLOCK_INIT(&softf->ipfr_natfrag, "ipf NAT fragment rwlock"); + softf->ipf_frag_tune = ipf_tune_array_copy(softf, + sizeof(ipf_frag_tuneables), + ipf_frag_tuneables); + if (softf->ipf_frag_tune == NULL) { + ipf_frag_soft_destroy(softc, softf); + return NULL; + } + if (ipf_tune_array_link(softc, softf->ipf_frag_tune) == -1) { + ipf_frag_soft_destroy(softc, softf); + return NULL; + } + softf->ipfr_size = IPFT_SIZE; softf->ipfr_ttl = IPF_TTLVAL(60); softf->ipfr_lock = 1; @@ -219,6 +231,12 @@ ipf_frag_soft_destroy(softc, arg) RW_DESTROY(&softf->ipfr_frag); RW_DESTROY(&softf->ipfr_natfrag); + if (softf->ipf_frag_tune != NULL) { + ipf_tune_array_unlink(softc, softf->ipf_frag_tune); + KFREES(softf->ipf_frag_tune, sizeof(ipf_frag_tuneables)); + softf->ipf_frag_tune = NULL; + } + KFREE(softf); } Modified: stable/10/sys/contrib/ipfilter/netinet/ip_frag.h ============================================================================== --- stable/10/sys/contrib/ipfilter/netinet/ip_frag.h Sat Jun 18 23:18:04 2016 (r302014) +++ stable/10/sys/contrib/ipfilter/netinet/ip_frag.h Sun Jun 19 00:39:23 2016 (r302015) @@ -78,6 +78,7 @@ typedef struct ipf_frag_softc_s { int ipfr_ttl; int ipfr_lock; int ipfr_inited; + ipftuneable_t *ipf_frag_tune; ipfr_t *ipfr_list; ipfr_t **ipfr_tail; ipfr_t *ipfr_natlist; From owner-svn-src-stable-10@freebsd.org Mon Jun 20 09:06:51 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8D072A7A838; Mon, 20 Jun 2016 09:06:51 +0000 (UTC) (envelope-from kib@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 5D84927A9; Mon, 20 Jun 2016 09:06:51 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5K96o9t033476; Mon, 20 Jun 2016 09:06:50 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5K96om0033475; Mon, 20 Jun 2016 09:06:50 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606200906.u5K96om0033475@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 20 Jun 2016 09:06:50 +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: r302027 - stable/10/sys/vm 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2016 09:06:51 -0000 Author: kib Date: Mon Jun 20 09:06:50 2016 New Revision: 302027 URL: https://svnweb.freebsd.org/changeset/base/302027 Log: MFC r301851: Explicitely initialize sw_alloc_sx. Modified: stable/10/sys/vm/swap_pager.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/vm/swap_pager.c ============================================================================== --- stable/10/sys/vm/swap_pager.c Mon Jun 20 06:45:42 2016 (r302026) +++ stable/10/sys/vm/swap_pager.c Mon Jun 20 09:06:50 2016 (r302027) @@ -498,6 +498,7 @@ swap_pager_init(void) TAILQ_INIT(&swap_pager_object_list[i]); mtx_init(&sw_alloc_mtx, "swap_pager list", NULL, MTX_DEF); mtx_init(&sw_dev_mtx, "swapdev", NULL, MTX_DEF); + sx_init(&sw_alloc_sx, "swspsx"); /* * Device Stripe, in PAGE_SIZE'd blocks From owner-svn-src-stable-10@freebsd.org Mon Jun 20 09:15:04 2016 Return-Path: Delivered-To: svn-src-stable-10@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 6B502A7AA68; Mon, 20 Jun 2016 09:15:04 +0000 (UTC) (envelope-from kib@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 3A3772D60; Mon, 20 Jun 2016 09:15:04 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5K9F3gv037189; Mon, 20 Jun 2016 09:15:03 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5K9F3Yf037188; Mon, 20 Jun 2016 09:15:03 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606200915.u5K9F3Yf037188@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 20 Jun 2016 09:15:03 +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: r302028 - stable/10/sys/amd64/amd64 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2016 09:15:04 -0000 Author: kib Date: Mon Jun 20 09:15:03 2016 New Revision: 302028 URL: https://svnweb.freebsd.org/changeset/base/302028 Log: MFC r301853: Do not access pv_table array for fictitious pages. Modified: stable/10/sys/amd64/amd64/pmap.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/amd64/pmap.c ============================================================================== --- stable/10/sys/amd64/amd64/pmap.c Mon Jun 20 09:06:50 2016 (r302027) +++ stable/10/sys/amd64/amd64/pmap.c Mon Jun 20 09:15:03 2016 (r302028) @@ -381,6 +381,7 @@ static TAILQ_HEAD(pch, pv_chunk) pv_chun static struct mtx pv_chunks_mutex; static struct rwlock pv_list_locks[NPV_LIST_LOCKS]; static struct md_page *pv_table; +static struct md_page pv_dummy; /* * All those kernel PT submaps that BSD is so fond of @@ -1100,6 +1101,7 @@ pmap_init(void) M_WAITOK | M_ZERO); for (i = 0; i < pv_npg; i++) TAILQ_INIT(&pv_table[i].pv_list); + TAILQ_INIT(&pv_dummy.pv_list); mtx_init(&cpage_lock, "cpage", NULL, MTX_DEF); cpage_a = kva_alloc(PAGE_SIZE); @@ -3808,9 +3810,8 @@ pmap_remove_all(vm_page_t m) ("pmap_remove_all: page %p is not managed", m)); SLIST_INIT(&free); rw_wlock(&pvh_global_lock); - if ((m->flags & PG_FICTITIOUS) != 0) - goto small_mappings; - pvh = pa_to_pvh(VM_PAGE_TO_PHYS(m)); + pvh = (m->flags & PG_FICTITIOUS) != 0 ? &pv_dummy : + pa_to_pvh(VM_PAGE_TO_PHYS(m)); while ((pv = TAILQ_FIRST(&pvh->pv_list)) != NULL) { pmap = PV_PMAP(pv); PMAP_LOCK(pmap); @@ -3819,7 +3820,6 @@ pmap_remove_all(vm_page_t m) (void)pmap_demote_pde(pmap, pde, va); PMAP_UNLOCK(pmap); } -small_mappings: while ((pv = TAILQ_FIRST(&m->md.pv_list)) != NULL) { pmap = PV_PMAP(pv); PMAP_LOCK(pmap); @@ -5677,11 +5677,10 @@ pmap_remove_write(vm_page_t m) return; rw_rlock(&pvh_global_lock); lock = VM_PAGE_TO_PV_LIST_LOCK(m); - pvh = pa_to_pvh(VM_PAGE_TO_PHYS(m)); + pvh = (m->flags & PG_FICTITIOUS) != 0 ? &pv_dummy : + pa_to_pvh(VM_PAGE_TO_PHYS(m)); retry_pv_loop: rw_wlock(lock); - if ((m->flags & PG_FICTITIOUS) != 0) - goto small_mappings; TAILQ_FOREACH_SAFE(pv, &pvh->pv_list, pv_next, next_pv) { pmap = PV_PMAP(pv); if (!PMAP_TRYLOCK(pmap)) { @@ -5705,7 +5704,6 @@ retry_pv_loop: lock, VM_PAGE_TO_PV_LIST_LOCK(m), m)); PMAP_UNLOCK(pmap); } -small_mappings: TAILQ_FOREACH(pv, &m->md.pv_list, pv_next) { pmap = PV_PMAP(pv); if (!PMAP_TRYLOCK(pmap)) { @@ -5807,13 +5805,12 @@ pmap_ts_referenced(vm_page_t m) cleared = 0; pa = VM_PAGE_TO_PHYS(m); lock = PHYS_TO_PV_LIST_LOCK(pa); - pvh = pa_to_pvh(pa); + pvh = (m->flags & PG_FICTITIOUS) != 0 ? &pv_dummy : pa_to_pvh(pa); rw_rlock(&pvh_global_lock); rw_wlock(lock); retry: not_cleared = 0; - if ((m->flags & PG_FICTITIOUS) != 0 || - (pvf = TAILQ_FIRST(&pvh->pv_list)) == NULL) + if ((pvf = TAILQ_FIRST(&pvh->pv_list)) == NULL) goto small_mappings; pv = pvf; do { @@ -6139,13 +6136,12 @@ pmap_clear_modify(vm_page_t m) */ if ((m->aflags & PGA_WRITEABLE) == 0) return; - pvh = pa_to_pvh(VM_PAGE_TO_PHYS(m)); + pvh = (m->flags & PG_FICTITIOUS) != 0 ? &pv_dummy : + pa_to_pvh(VM_PAGE_TO_PHYS(m)); rw_rlock(&pvh_global_lock); lock = VM_PAGE_TO_PV_LIST_LOCK(m); rw_wlock(lock); restart: - if ((m->flags & PG_FICTITIOUS) != 0) - goto small_mappings; TAILQ_FOREACH_SAFE(pv, &pvh->pv_list, pv_next, next_pv) { pmap = PV_PMAP(pv); if (!PMAP_TRYLOCK(pmap)) { @@ -6189,7 +6185,6 @@ restart: } PMAP_UNLOCK(pmap); } -small_mappings: TAILQ_FOREACH(pv, &m->md.pv_list, pv_next) { pmap = PV_PMAP(pv); if (!PMAP_TRYLOCK(pmap)) { From owner-svn-src-stable-10@freebsd.org Mon Jun 20 19:00:49 2016 Return-Path: Delivered-To: svn-src-stable-10@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 50608AC47C3; Mon, 20 Jun 2016 19:00:49 +0000 (UTC) (envelope-from truckman@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 090E02443; Mon, 20 Jun 2016 19:00:48 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5KJ0mMN059946; Mon, 20 Jun 2016 19:00:48 GMT (envelope-from truckman@FreeBSD.org) Received: (from truckman@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5KJ0mL3059944; Mon, 20 Jun 2016 19:00:48 GMT (envelope-from truckman@FreeBSD.org) Message-Id: <201606201900.u5KJ0mL3059944@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: truckman set sender to truckman@FreeBSD.org using -f From: Don Lewis Date: Mon, 20 Jun 2016 19:00:48 +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: r302032 - stable/10/sys/netinet 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2016 19:00:49 -0000 Author: truckman Date: Mon Jun 20 19:00:47 2016 New Revision: 302032 URL: https://svnweb.freebsd.org/changeset/base/302032 Log: MFC r300240 Change net.inet.tcp.ecn.enable sysctl mib from a binary off/on control to a three way setting. 0 - Totally disable ECN. (no change) 1 - Enable ECN if incoming connections request it. Outgoing connections will request ECN. (no change from present != 0 setting) 2 - Enable ECN if incoming connections request it. Outgoing conections will not request ECN. Change the default value of net.inet.tcp.ecn.enable from 0 to 2. Linux version 2.4.20 and newer, Solaris, and Mac OS X 10.5 and newer have similar capabilities. The actual values above match Linux, and the default matches the current Linux default. Reviewed by: eadler Relnotes: yes Differential Revision: https://reviews.freebsd.org/D6386 Modified: stable/10/sys/netinet/tcp_input.c stable/10/sys/netinet/tcp_output.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/netinet/tcp_input.c ============================================================================== --- stable/10/sys/netinet/tcp_input.c Mon Jun 20 18:14:51 2016 (r302031) +++ stable/10/sys/netinet/tcp_input.c Mon Jun 20 19:00:47 2016 (r302032) @@ -184,7 +184,7 @@ SYSCTL_VNET_INT(_net_inet_tcp, OID_AUTO, static SYSCTL_NODE(_net_inet_tcp, OID_AUTO, ecn, CTLFLAG_RW, 0, "TCP ECN"); -VNET_DEFINE(int, tcp_do_ecn) = 0; +VNET_DEFINE(int, tcp_do_ecn) = 2; SYSCTL_VNET_INT(_net_inet_tcp_ecn, OID_AUTO, enable, CTLFLAG_RW, &VNET_NAME(tcp_do_ecn), 0, "TCP ECN support"); Modified: stable/10/sys/netinet/tcp_output.c ============================================================================== --- stable/10/sys/netinet/tcp_output.c Mon Jun 20 18:14:51 2016 (r302031) +++ stable/10/sys/netinet/tcp_output.c Mon Jun 20 19:00:47 2016 (r302032) @@ -1109,7 +1109,7 @@ send: * resend those bits a number of times as per * RFC 3168. */ - if (tp->t_state == TCPS_SYN_SENT && V_tcp_do_ecn) { + if (tp->t_state == TCPS_SYN_SENT && V_tcp_do_ecn == 1) { if (tp->t_rxtshift >= 1) { if (tp->t_rxtshift <= V_tcp_ecn_maxretries) flags |= TH_ECE|TH_CWR; From owner-svn-src-stable-10@freebsd.org Tue Jun 21 02:36:04 2016 Return-Path: Delivered-To: svn-src-stable-10@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 B2AFDAC503B; Tue, 21 Jun 2016 02:36:04 +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 8E77113D6; Tue, 21 Jun 2016 02:36:04 +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 u5L2a3Ex030523; Tue, 21 Jun 2016 02:36:03 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L2a39L030518; Tue, 21 Jun 2016 02:36:03 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210236.u5L2a39L030518@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 02:36:03 +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: r302040 - in stable/10/sys/dev/hyperv: netvsc storvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 02:36:04 -0000 Author: sephe Date: Tue Jun 21 02:36:03 2016 New Revision: 302040 URL: https://svnweb.freebsd.org/changeset/base/302040 Log: MFC 297815,297841,297908,297913 297815 hyperv: Typo Noticed by: kib MFC after: 1 week Sponsored by: Microsoft OSTC 297841 hyperv: Replace 0 w/ NULL Submitted by: pfg MFC after: 1 week Sponsored by: Microsoft OSTC 297908 hyperv/vmbus: Merge duplicated version check for events Submitted by: Jun Su Reviewed by: sephe MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5911 297913 hyperv: device_get_softc does not return NULL MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 00:01:02 2016 (r302039) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 02:36:03 2016 (r302040) @@ -433,9 +433,6 @@ netvsc_attach(device_t dev) int tso_maxlen; sc = device_get_softc(dev); - if (sc == NULL) { - return (ENOMEM); - } bzero(sc, sizeof(hn_softc_t)); sc->hn_unit = unit; @@ -1186,10 +1183,6 @@ netvsc_linkstatus_callback(struct hv_dev { hn_softc_t *sc = device_get_softc(device_obj->device); - if (sc == NULL) { - return; - } - if (status == 1) { sc->hn_carrier = 1; } else { Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 00:01:02 2016 (r302039) +++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 02:36:03 2016 (r302040) @@ -324,9 +324,6 @@ get_stor_device(struct hv_device *device struct storvsc_softc *sc; sc = device_get_softc(device->device); - if (sc == NULL) { - return NULL; - } if (outbound) { /* @@ -1009,10 +1006,6 @@ storvsc_attach(device_t dev) root_mount_token = root_mount_hold("storvsc"); sc = device_get_softc(dev); - if (sc == NULL) { - ret = ENOMEM; - goto cleanup; - } stor_type = storvsc_get_storage_type(dev); Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Tue Jun 21 00:01:02 2016 (r302039) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Tue Jun 21 02:36:03 2016 (r302040) @@ -308,14 +308,18 @@ hv_vmbus_on_events(int cpu) KASSERT(cpu <= mp_maxid, ("VMBUS: hv_vmbus_on_events: " "cpu out of range!")); + page_addr = hv_vmbus_g_context.syn_ic_event_page[cpu]; + event = (hv_vmbus_synic_event_flags *) + page_addr + HV_VMBUS_MESSAGE_SINT; if ((hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008) || (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7)) { maxdword = HV_MAX_NUM_CHANNELS_SUPPORTED >> 5; /* * receive size is 1/2 page and divide that by 4 bytes */ - recv_interrupt_page = - hv_vmbus_g_connection.recv_interrupt_page; + if (synch_test_and_clear_bit(0, &event->flags32[0])) + recv_interrupt_page = + hv_vmbus_g_connection.recv_interrupt_page; } else { /* * On Host with Win8 or above, the event page can be @@ -323,9 +327,6 @@ hv_vmbus_on_events(int cpu) * that has the pending interrupt. */ maxdword = HV_EVENT_FLAGS_DWORD_COUNT; - page_addr = hv_vmbus_g_context.syn_ic_event_page[cpu]; - event = (hv_vmbus_synic_event_flags *) - page_addr + HV_VMBUS_MESSAGE_SINT; recv_interrupt_page = event->flags32; } Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Tue Jun 21 00:01:02 2016 (r302039) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Tue Jun 21 02:36:03 2016 (r302040) @@ -127,7 +127,7 @@ int hv_vmbus_init(void) { hv_vmbus_x64_msr_hypercall_contents hypercall_msr; - void* virt_addr = 0; + void* virt_addr = NULL; memset( hv_vmbus_g_context.syn_ic_event_page, @@ -445,7 +445,7 @@ hyperv_identify(void) "\003SYNIC" /* MSRs for SynIC */ "\004SYNTM" /* MSRs for SynTimer */ "\005APIC" /* MSR_{EOI,ICR,TPR} */ - "\006HYERCALL" /* MSR_{GUEST_OS_ID,HYPERCALL} */ + "\006HYPERCALL" /* MSR_{GUEST_OS_ID,HYPERCALL} */ "\007VPINDEX" /* MSR_VP_INDEX */ "\010RESET" /* MSR_RESET */ "\011STATS" /* MSR_STATS_ */ Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 00:01:02 2016 (r302039) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 02:36:03 2016 (r302040) @@ -145,7 +145,6 @@ hv_vmbus_isr(struct trapframe *frame) { int cpu; hv_vmbus_message* msg; - hv_vmbus_synic_event_flags* event; void* page_addr; cpu = PCPU_GET(cpuid); @@ -156,26 +155,7 @@ hv_vmbus_isr(struct trapframe *frame) * in Windows when running as a guest in Hyper-V */ - page_addr = hv_vmbus_g_context.syn_ic_event_page[cpu]; - event = (hv_vmbus_synic_event_flags*) - page_addr + HV_VMBUS_MESSAGE_SINT; - - if ((hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008) || - (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7)) { - /* Since we are a child, we only need to check bit 0 */ - if (synch_test_and_clear_bit(0, &event->flags32[0])) { - hv_vmbus_on_events(cpu); - } - } else { - /* - * On host with Win8 or above, we can directly look at - * the event page. If bit n is set, we have an interrupt - * on the channel with id n. - * Directly schedule the event software interrupt on - * current cpu. - */ - hv_vmbus_on_events(cpu); - } + hv_vmbus_on_events(cpu); /* Check if there are actual msgs to be process */ page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu]; @@ -672,7 +652,7 @@ vmbus_bus_exit(void) smp_rendezvous(NULL, hv_vmbus_synic_cleanup, NULL, NULL); for(i = 0; i < 2 * MAXCPU; i++) { - if (setup_args.page_buffers[i] != 0) + if (setup_args.page_buffers[i] != NULL) free(setup_args.page_buffers[i], M_DEVBUF); } From owner-svn-src-stable-10@freebsd.org Tue Jun 21 04:51:57 2016 Return-Path: Delivered-To: svn-src-stable-10@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 EC692A7AEF9; Tue, 21 Jun 2016 04:51:57 +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 9E7E22D75; Tue, 21 Jun 2016 04:51:57 +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 u5L4pueU082084; Tue, 21 Jun 2016 04:51:56 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L4ptYP082074; Tue, 21 Jun 2016 04:51:55 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210451.u5L4ptYP082074@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 04:51:55 +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: r302041 - in stable/10/sys: amd64/amd64 amd64/conf conf dev/hyperv/vmbus dev/hyperv/vmbus/amd64 dev/hyperv/vmbus/i386 i386/conf i386/i386 modules/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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 04:51:58 -0000 Author: sephe Date: Tue Jun 21 04:51:55 2016 New Revision: 302041 URL: https://svnweb.freebsd.org/changeset/base/302041 Log: MFC 297931,298022 297931 Expose doreti as a global symbol on amd64 and i386. doreti provides the common code path for returning from interrupt andlers on x86. Exposing doreti as a global symbol allows kernel modules to include low-level interrupt handlers instead of requiring all low-level handlers to be statically compiled into the kernel. Submitted by: Howard Su Reviewed by: kib 298022 hyperv: Deprecate HYPERV option by moving Hyper-V IDT vector into vmbus Submitted by: Jun Su Reviewed by: jhb, kib, sephe Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5910 Added: stable/10/sys/dev/hyperv/vmbus/amd64/ - copied from r298022, head/sys/dev/hyperv/vmbus/amd64/ stable/10/sys/dev/hyperv/vmbus/i386/ - copied from r298022, head/sys/dev/hyperv/vmbus/i386/ Modified: stable/10/sys/amd64/amd64/apic_vector.S stable/10/sys/amd64/amd64/exception.S stable/10/sys/amd64/conf/GENERIC stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/i386/conf/GENERIC stable/10/sys/i386/i386/apic_vector.s stable/10/sys/i386/i386/exception.s stable/10/sys/modules/hyperv/vmbus/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/amd64/apic_vector.S ============================================================================== --- stable/10/sys/amd64/amd64/apic_vector.S Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/amd64/amd64/apic_vector.S Tue Jun 21 04:51:55 2016 (r302041) @@ -150,22 +150,6 @@ IDTVEC(xen_intr_upcall) jmp doreti #endif -#ifdef HYPERV -/* - * This is the Hyper-V vmbus channel direct callback interrupt. - * Only used when it is running on Hyper-V. - */ - .text - SUPERALIGN_TEXT -IDTVEC(hv_vmbus_callback) - PUSH_FRAME - FAKE_MCOUNT(TF_RIP(%rsp)) - movq %rsp, %rdi - call hv_vector_handler - MEXITCOUNT - jmp doreti -#endif - #ifdef SMP /* * Global address space TLB shootdown. Modified: stable/10/sys/amd64/amd64/exception.S ============================================================================== --- stable/10/sys/amd64/amd64/exception.S Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/amd64/amd64/exception.S Tue Jun 21 04:51:55 2016 (r302041) @@ -661,6 +661,7 @@ MCOUNT_LABEL(eintr) .text SUPERALIGN_TEXT .type doreti,@function + .globl doreti doreti: FAKE_MCOUNT($bintr) /* init "from" bintr -> doreti */ /* Modified: stable/10/sys/amd64/conf/GENERIC ============================================================================== --- stable/10/sys/amd64/conf/GENERIC Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/amd64/conf/GENERIC Tue Jun 21 04:51:55 2016 (r302041) @@ -353,7 +353,6 @@ device virtio_scsi # VirtIO SCSI devic device virtio_balloon # VirtIO Memory Balloon device # HyperV drivers and enchancement support -# NOTE: HYPERV depends on hyperv. They must be added or removed together. options HYPERV # Hyper-V kernel infrastructure device hyperv # HyperV drivers Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/conf/files.amd64 Tue Jun 21 04:51:55 2016 (r302041) @@ -278,6 +278,7 @@ dev/hyperv/vmbus/hv_hv.c optional hyp dev/hyperv/vmbus/hv_et.c optional hyperv dev/hyperv/vmbus/hv_ring_buffer.c optional hyperv dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c optional hyperv +dev/hyperv/vmbus/amd64/hv_vector.S optional hyperv dev/kbd/kbd.c optional atkbd | sc | ukbd | vt dev/lindev/full.c optional lindev dev/lindev/lindev.c optional lindev Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/conf/files.i386 Tue Jun 21 04:51:55 2016 (r302041) @@ -254,6 +254,7 @@ dev/hyperv/vmbus/hv_hv.c optional hyp dev/hyperv/vmbus/hv_et.c optional hyperv dev/hyperv/vmbus/hv_ring_buffer.c optional hyperv dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c optional hyperv +dev/hyperv/vmbus/i386/hv_vector.S optional hyperv dev/ichwd/ichwd.c optional ichwd dev/if_ndis/if_ndis.c optional ndis dev/if_ndis/if_ndis_pccard.c optional ndis pccard Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 04:51:55 2016 (r302041) @@ -370,7 +370,6 @@ vmbus_probe(device_t dev) { return (BUS_PROBE_DEFAULT); } -#ifdef HYPERV extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback); /** @@ -430,21 +429,6 @@ vmbus_vector_free(int vector) setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0); } -#else /* HYPERV */ - -static int -vmbus_vector_alloc(void) -{ - return(0); -} - -static void -vmbus_vector_free(int vector) -{ -} - -#endif /* HYPERV */ - static void vmbus_cpuset_setthread_task(void *xmask, int pending __unused) { Modified: stable/10/sys/i386/conf/GENERIC ============================================================================== --- stable/10/sys/i386/conf/GENERIC Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/i386/conf/GENERIC Tue Jun 21 04:51:55 2016 (r302041) @@ -362,7 +362,6 @@ device virtio_scsi # VirtIO SCSI devic device virtio_balloon # VirtIO Memory Balloon device # HyperV drivers and enchancement support -# NOTE: HYPERV depends on hyperv. They must be added or removed together. options HYPERV # Hyper-V kernel infrastructure device hyperv # HyperV drivers Modified: stable/10/sys/i386/i386/apic_vector.s ============================================================================== --- stable/10/sys/i386/i386/apic_vector.s Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/i386/i386/apic_vector.s Tue Jun 21 04:51:55 2016 (r302041) @@ -157,25 +157,6 @@ IDTVEC(xen_intr_upcall) jmp doreti #endif -#ifdef HYPERV -/* - * This is the Hyper-V vmbus channel direct callback interrupt. - * Only used when it is running on Hyper-V. - */ - .text - SUPERALIGN_TEXT -IDTVEC(hv_vmbus_callback) - PUSH_FRAME - SET_KERNEL_SREGS - cld - FAKE_MCOUNT(TF_EIP(%esp)) - pushl %esp - call hv_vector_handler - add $4, %esp - MEXITCOUNT - jmp doreti -#endif - #ifdef SMP /* * Global address space TLB shootdown. Modified: stable/10/sys/i386/i386/exception.s ============================================================================== --- stable/10/sys/i386/i386/exception.s Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/i386/i386/exception.s Tue Jun 21 04:51:55 2016 (r302041) @@ -344,6 +344,7 @@ MCOUNT_LABEL(eintr) .text SUPERALIGN_TEXT .type doreti,@function + .globl doreti doreti: FAKE_MCOUNT($bintr) /* init "from" bintr -> doreti */ doreti_next: Modified: stable/10/sys/modules/hyperv/vmbus/Makefile ============================================================================== --- stable/10/sys/modules/hyperv/vmbus/Makefile Tue Jun 21 02:36:03 2016 (r302040) +++ stable/10/sys/modules/hyperv/vmbus/Makefile Tue Jun 21 04:51:55 2016 (r302041) @@ -1,7 +1,7 @@ # $FreeBSD$ .PATH: ${.CURDIR}/../../../dev/hyperv/vmbus \ - ${.CURDIR}/../../../dev/hyperv/utilities + ${.CURDIR}/../../../dev/hyperv/vmbus/${MACHINE_CPUARCH} KMOD= hv_vmbus SRCS= hv_channel.c \ @@ -14,8 +14,17 @@ SRCS= hv_channel.c \ hv_vmbus_priv.h SRCS+= acpi_if.h bus_if.h device_if.h opt_acpi.h +# XXX: for assym.s +SRCS+= opt_kstack_pages.h opt_nfs.h opt_apic.h opt_hwpmc_hooks.h opt_compat.h + +SRCS+= assym.s \ + hv_vector.S + +hv_vector.o: + ${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \ + ${.IMPSRC} -o ${.TARGET} + CFLAGS+= -I${.CURDIR}/../../../dev/hyperv/include \ - -I${.CURDIR}/../../../dev/hyperv/vmbus \ - -I${.CURDIR}/../../../dev/hyperv/utilities + -I${.CURDIR}/../../../dev/hyperv/vmbus .include From owner-svn-src-stable-10@freebsd.org Tue Jun 21 05:02:04 2016 Return-Path: Delivered-To: svn-src-stable-10@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 902ECAC41E3; Tue, 21 Jun 2016 05:02:04 +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 5CF48132D; Tue, 21 Jun 2016 05:02:04 +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 u5L523hD085150; Tue, 21 Jun 2016 05:02:03 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L5239i085149; Tue, 21 Jun 2016 05:02:03 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210502.u5L5239i085149@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 05:02:03 +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: r302042 - stable/10/sys/dev/hyperv/storvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 05:02:04 -0000 Author: sephe Date: Tue Jun 21 05:02:03 2016 New Revision: 302042 URL: https://svnweb.freebsd.org/changeset/base/302042 Log: MFC 298040 hyperv/stor: Use xpt_done_direct() upon I/O completion Reviewed by: mav MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5955 Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 04:51:55 2016 (r302041) +++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 05:02:03 2016 (r302042) @@ -2133,8 +2133,9 @@ storvsc_io_done(struct hv_storvsc_reques reqp->softc->hs_frozen = 0; } storvsc_free_request(sc, reqp); - xpt_done(ccb); mtx_unlock(&sc->hs_lock); + + xpt_done_direct(ccb); } /** From owner-svn-src-stable-10@freebsd.org Tue Jun 21 05:11:20 2016 Return-Path: Delivered-To: svn-src-stable-10@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 E99FDAC42D1; Tue, 21 Jun 2016 05:11:20 +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 8C1C21750; Tue, 21 Jun 2016 05:11:20 +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 u5L5BJAt086907; Tue, 21 Jun 2016 05:11:19 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L5BJLa086904; Tue, 21 Jun 2016 05:11:19 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210511.u5L5BJLa086904@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 05:11:19 +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: r302043 - in stable/10/sys/dev/hyperv: netvsc storvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 05:11:21 -0000 Author: sephe Date: Tue Jun 21 05:11:19 2016 New Revision: 302043 URL: https://svnweb.freebsd.org/changeset/base/302043 Log: MFC 298041,298259 298041 hyperv: No need to zero out softc MFC after: 1 week Sponsored by: Microsoft OSTC 298259 hyperv: Remove two assign-only local variables Submitted by: Jun Su MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:02:03 2016 (r302042) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:11:19 2016 (r302043) @@ -434,7 +434,6 @@ netvsc_attach(device_t dev) sc = device_get_softc(dev); - bzero(sc, sizeof(hn_softc_t)); sc->hn_unit = unit; sc->hn_dev = dev; Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 05:02:03 2016 (r302042) +++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 05:11:19 2016 (r302043) @@ -1014,8 +1014,6 @@ storvsc_attach(device_t dev) goto cleanup; } - bzero(sc, sizeof(struct storvsc_softc)); - /* fill in driver specific properties */ sc->hs_drv_props = &g_drv_props_table[stor_type]; Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:02:03 2016 (r302042) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:11:19 2016 (r302043) @@ -375,12 +375,6 @@ vmbus_channel_on_offer(hv_vmbus_channel_ offer = (hv_vmbus_channel_offer_channel*) hdr; - hv_guid *guidType; - hv_guid *guidInstance; - - guidType = &offer->offer.interface_type; - guidInstance = &offer->offer.interface_instance; - // copy offer data copied = malloc(sizeof(*copied), M_DEVBUF, M_NOWAIT); if (copied == NULL) { From owner-svn-src-stable-10@freebsd.org Tue Jun 21 05:16:23 2016 Return-Path: Delivered-To: svn-src-stable-10@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 5F58CAC449B; Tue, 21 Jun 2016 05:16:23 +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 33E931C1E; Tue, 21 Jun 2016 05:16:23 +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 u5L5GMul089756; Tue, 21 Jun 2016 05:16:22 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L5GMxa089753; Tue, 21 Jun 2016 05:16:22 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210516.u5L5GMxa089753@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 05:16:22 +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: r302044 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 05:16:23 -0000 Author: sephe Date: Tue Jun 21 05:16:21 2016 New Revision: 302044 URL: https://svnweb.freebsd.org/changeset/base/302044 Log: MFC 298260 hyperv/vmbus: Make device probe/attach synchronous w/ vmbus attach/SYSINIT Discussed with: Jun Su , Dexuan Cui MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:11:19 2016 (r302043) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:16:21 2016 (r302044) @@ -30,7 +30,10 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include +#include #include "hv_vmbus_priv.h" @@ -95,6 +98,14 @@ typedef struct hv_work_item { void* context; } hv_work_item; +static struct mtx vmbus_chwait_lock; +MTX_SYSINIT(vmbus_chwait_lk, &vmbus_chwait_lock, "vmbus primarych wait lock", + MTX_DEF); +static uint32_t vmbus_chancnt; +static uint32_t vmbus_devcnt; + +#define VMBUS_CHANCNT_DONE 0x80000000 + /** * Implementation of the work abstraction. */ @@ -279,6 +290,11 @@ vmbus_channel_process_offer(hv_vmbus_cha mtx_unlock(&hv_vmbus_g_connection.channel_lock); hv_vmbus_free_vmbus_channel(new_channel); } + + mtx_lock(&vmbus_chwait_lock); + vmbus_devcnt++; + mtx_unlock(&vmbus_chwait_lock); + wakeup(&vmbus_devcnt); } void @@ -384,6 +400,11 @@ vmbus_channel_on_offer(hv_vmbus_channel_ memcpy(copied, hdr, sizeof(*copied)); hv_queue_work_item(vmbus_channel_on_offer_internal, copied); + + mtx_lock(&vmbus_chwait_lock); + if ((vmbus_chancnt & VMBUS_CHANCNT_DONE) == 0) + vmbus_chancnt++; + mtx_unlock(&vmbus_chwait_lock); } static void @@ -475,6 +496,11 @@ vmbus_channel_on_offer_rescind_internal( static void vmbus_channel_on_offers_delivered(hv_vmbus_channel_msg_header* hdr) { + + mtx_lock(&vmbus_chwait_lock); + vmbus_chancnt |= VMBUS_CHANCNT_DONE; + mtx_unlock(&vmbus_chwait_lock); + wakeup(&vmbus_chancnt); } /** @@ -752,3 +778,18 @@ vmbus_select_outgoing_channel(struct hv_ return(outgoing_channel); } + +void +vmbus_scan(void) +{ + uint32_t chancnt; + + mtx_lock(&vmbus_chwait_lock); + while ((vmbus_chancnt & VMBUS_CHANCNT_DONE) == 0) + mtx_sleep(&vmbus_chancnt, &vmbus_chwait_lock, 0, "waitch", 0); + chancnt = vmbus_chancnt & ~VMBUS_CHANCNT_DONE; + + while (vmbus_devcnt != chancnt) + mtx_sleep(&vmbus_devcnt, &vmbus_chwait_lock, 0, "waitdev", 0); + mtx_unlock(&vmbus_chwait_lock); +} Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 05:11:19 2016 (r302043) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 05:16:21 2016 (r302044) @@ -326,7 +326,6 @@ int hv_vmbus_child_device_register(struct hv_device *child_dev) { device_t child; - int ret = 0; if (bootverbose) { char name[40]; @@ -338,10 +337,6 @@ hv_vmbus_child_device_register(struct hv child_dev->device = child; device_set_ivars(child, child_dev); - mtx_lock(&Giant); - ret = device_probe_and_attach(child); - mtx_unlock(&Giant); - return (0); } @@ -562,6 +557,11 @@ vmbus_bus_init(void) goto cleanup1; hv_vmbus_request_channel_offers(); + + vmbus_scan(); + bus_generic_attach(vmbus_devp); + device_printf(vmbus_devp, "device scan, probe and attach done\n"); + return (ret); cleanup1: Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Tue Jun 21 05:11:19 2016 (r302043) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Tue Jun 21 05:16:21 2016 (r302044) @@ -751,6 +751,9 @@ void hv_vmbus_on_events(int cpu); void hv_et_init(void); void hv_et_intr(struct trapframe*); +/* Wait for device creation */ +void vmbus_scan(void); + /* * The guest OS needs to register the guest ID with the hypervisor. * The guest ID is a 64 bit entity and the structure of this ID is From owner-svn-src-stable-10@freebsd.org Tue Jun 21 05:20:44 2016 Return-Path: Delivered-To: svn-src-stable-10@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 CF9A6AC46B1; Tue, 21 Jun 2016 05:20:44 +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 9CD1B1F1F; Tue, 21 Jun 2016 05:20:44 +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 u5L5Khm0089990; Tue, 21 Jun 2016 05:20:43 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L5Kf5v089965; Tue, 21 Jun 2016 05:20:41 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210520.u5L5Kf5v089965@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 05:20:41 +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: r302045 - in stable/10/sys/dev/hyperv: include netvsc storvsc utilities 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 05:20:44 -0000 Author: sephe Date: Tue Jun 21 05:20:41 2016 New Revision: 302045 URL: https://svnweb.freebsd.org/changeset/base/302045 Log: MFC 298446 hyperv: Update copyright to 2016 for the files Microsoft changed in 2016 Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6039 Modified: stable/10/sys/dev/hyperv/include/hyperv.h stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis.h stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c stable/10/sys/dev/hyperv/utilities/hv_kvp.c stable/10/sys/dev/hyperv/utilities/hv_kvp.h stable/10/sys/dev/hyperv/utilities/hv_shutdown.c stable/10/sys/dev/hyperv/utilities/hv_timesync.c stable/10/sys/dev/hyperv/utilities/hv_util.c stable/10/sys/dev/hyperv/utilities/hv_util.h stable/10/sys/dev/hyperv/vmbus/hv_channel.c stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_et.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/include/hyperv.h ============================================================================== --- stable/10/sys/dev/hyperv/include/hyperv.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/include/hyperv.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2010-2012 Citrix Inc. * Copyright (c) 2012 NetApp Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2010-2012 Citrix Inc. * Copyright (c) 2012 NetApp Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2010-2012 Citrix Inc. - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * All rights reserved. * Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2010-2012 Citrix Inc. * Copyright (c) 2012 NetApp Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2010-2012 Citrix Inc. * Copyright (c) 2012 NetApp Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2010-2012 Citrix Inc. * Copyright (c) 2012 NetApp Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014 Microsoft Corp. + * Copyright (c) 2014,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014 Microsoft Corp. + * Copyright (c) 2014,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014 Microsoft Corp. + * Copyright (c) 2014,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/utilities/hv_shutdown.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_shutdown.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_shutdown.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014 Microsoft Corp. + * Copyright (c) 2014,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/utilities/hv_timesync.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_timesync.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_timesync.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014 Microsoft Corp. + * Copyright (c) 2014,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/utilities/hv_util.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_util.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_util.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014 Microsoft Corp. + * Copyright (c) 2014,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/utilities/hv_util.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_util.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/utilities/hv_util.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_et.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_et.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2015 Microsoft Corp. + * Copyright (c) 2015,2016 Microsoft Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Tue Jun 21 05:16:21 2016 (r302044) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Tue Jun 21 05:20:41 2016 (r302045) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Microsoft Corp. + * Copyright (c) 2009-2012,2016 Microsoft Corp. * Copyright (c) 2012 NetApp Inc. * Copyright (c) 2012 Citrix Inc. * All rights reserved. From owner-svn-src-stable-10@freebsd.org Tue Jun 21 05:33:27 2016 Return-Path: Delivered-To: svn-src-stable-10@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 CBA4BAC4CF5; Tue, 21 Jun 2016 05:33:27 +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 8C5AC297A; Tue, 21 Jun 2016 05:33:27 +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 u5L5XQ8n097248; Tue, 21 Jun 2016 05:33:26 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L5XQV4097245; Tue, 21 Jun 2016 05:33:26 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210533.u5L5XQV4097245@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 05:33:26 +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: r302046 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 05:33:27 -0000 Author: sephe Date: Tue Jun 21 05:33:26 2016 New Revision: 302046 URL: https://svnweb.freebsd.org/changeset/base/302046 Log: MFC 298449,298568 298449 hyperv/et: Make Hyper-V event timer a device. Submitted by: Jun Su Reviewed by: sephe, Dexuan Cui MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5957 298568 hyperv/et: Strip extra white space in function name Reported by: Sascha Wildner MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_et.c Tue Jun 21 05:20:41 2016 (r302045) +++ stable/10/sys/dev/hyperv/vmbus/hv_et.c Tue Jun 21 05:33:26 2016 (r302046) @@ -28,6 +28,9 @@ __FBSDID("$FreeBSD$"); #include +#include +#include +#include #include #include #include @@ -40,8 +43,7 @@ __FBSDID("$FreeBSD$"); #define HV_MAX_DELTA_TICKS 0xffffffffLL #define HV_MIN_DELTA_TICKS 1LL -static struct eventtimer et; -static uint64_t periodticks[MAXCPU]; +static struct eventtimer *et; static inline uint64_t sbintime2tick(sbintime_t time) @@ -62,10 +64,6 @@ hv_et_start(struct eventtimer *et, sbint timer_cfg.auto_enable = 1; timer_cfg.sintx = HV_VMBUS_TIMER_SINT; - periodticks[curcpu] = sbintime2tick(periodtime); - if (firsttime == 0) - firsttime = periodtime; - current = rdmsr(HV_X64_MSR_TIME_REF_COUNT); current += sbintime2tick(firsttime); @@ -87,45 +85,77 @@ hv_et_stop(struct eventtimer *et) void hv_et_intr(struct trapframe *frame) { - union hv_timer_config timer_cfg; struct trapframe *oldframe; struct thread *td; - if (periodticks[curcpu] != 0) { - uint64_t tick = sbintime2tick(periodticks[curcpu]); - timer_cfg.as_uint64 = rdmsr(HV_X64_MSR_STIMER0_CONFIG); - timer_cfg.enable = 0; - timer_cfg.auto_enable = 1; - timer_cfg.periodic = 1; - periodticks[curcpu] = 0; - - wrmsr(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64); - wrmsr(HV_X64_MSR_STIMER0_COUNT, tick); - } - - if (et.et_active) { + if (et->et_active) { td = curthread; td->td_intr_nesting_level++; oldframe = td->td_intr_frame; td->td_intr_frame = frame; - et.et_event_cb(&et, et.et_arg); + et->et_event_cb(et, et->et_arg); td->td_intr_frame = oldframe; td->td_intr_nesting_level--; } } -void -hv_et_init(void) +static void +hv_et_identify(driver_t *driver, device_t parent) +{ + if (device_find_child(parent, "hv_et", -1) != NULL) + return; + + device_add_child(parent, "hv_et", -1); +} + +static int +hv_et_probe(device_t dev) +{ + device_set_desc(dev, "Hyper-V event timer"); + + return (BUS_PROBE_NOWILDCARD); +} + +static int +hv_et_attach(device_t dev) +{ + /* XXX: need allocate SINT and remove global et */ + et = device_get_softc(dev); + + et->et_name = "Hyper-V"; + et->et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERCPU; + et->et_quality = 1000; + et->et_frequency = HV_TIMER_FREQUENCY; + et->et_min_period = HV_MIN_DELTA_TICKS * ((1LL << 32) / HV_TIMER_FREQUENCY); + et->et_max_period = HV_MAX_DELTA_TICKS * ((1LL << 32) / HV_TIMER_FREQUENCY); + et->et_start = hv_et_start; + et->et_stop = hv_et_stop; + et->et_priv = dev; + + return (et_register(et)); +} + +static int +hv_et_detach(device_t dev) { - et.et_name = "HyperV"; - et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERCPU | ET_FLAGS_PERIODIC; - et.et_quality = 1000; - et.et_frequency = HV_TIMER_FREQUENCY; - et.et_min_period = (1LL << 32) / HV_TIMER_FREQUENCY; - et.et_max_period = HV_MAX_DELTA_TICKS * ((1LL << 32) / HV_TIMER_FREQUENCY); - et.et_start = hv_et_start; - et.et_stop = hv_et_stop; - et.et_priv = &et; - et_register(&et); + return (et_deregister(et)); } +static device_method_t hv_et_methods[] = { + DEVMETHOD(device_identify, hv_et_identify), + DEVMETHOD(device_probe, hv_et_probe), + DEVMETHOD(device_attach, hv_et_attach), + DEVMETHOD(device_detach, hv_et_detach), + + DEVMETHOD_END +}; + +static driver_t hv_et_driver = { + "hv_et", + hv_et_methods, + sizeof(struct eventtimer) +}; + +static devclass_t hv_et_devclass; +DRIVER_MODULE(hv_et, vmbus, hv_et_driver, hv_et_devclass, NULL, 0); +MODULE_VERSION(hv_et, 1); Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Tue Jun 21 05:20:41 2016 (r302045) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Tue Jun 21 05:33:26 2016 (r302046) @@ -171,8 +171,6 @@ hv_vmbus_init(void) hv_vmbus_g_context.hypercall_page = virt_addr; - hv_et_init(); - return (0); cleanup: Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 05:20:41 2016 (r302045) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue Jun 21 05:33:26 2016 (r302046) @@ -277,6 +277,9 @@ vmbus_child_pnpinfo_str(device_t dev, de char guidbuf[40]; struct hv_device *dev_ctx = device_get_ivars(child); + if (dev_ctx == NULL) + return (0); + strlcat(buf, "classid=", buflen); snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->class_id); strlcat(buf, guidbuf, buflen); @@ -606,6 +609,7 @@ vmbus_attach(device_t dev) if (!cold) vmbus_bus_init(); + bus_generic_probe(dev); return (0); } From owner-svn-src-stable-10@freebsd.org Tue Jun 21 05:49:08 2016 Return-Path: Delivered-To: svn-src-stable-10@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 D6C31AC4EDE; Tue, 21 Jun 2016 05:49:08 +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 980A52DDF; Tue, 21 Jun 2016 05:49:08 +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 u5L5n7ut001163; Tue, 21 Jun 2016 05:49:07 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L5n7L1001162; Tue, 21 Jun 2016 05:49:07 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210549.u5L5n7L1001162@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 05:49:07 +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: r302047 - stable/10/sys/dev/hyperv/netvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 05:49:08 -0000 Author: sephe Date: Tue Jun 21 05:49:07 2016 New Revision: 302047 URL: https://svnweb.freebsd.org/changeset/base/302047 Log: MFC 298561,298563 298561 hn: Increase odrops for if_transmit method if drbr_enqueue fails. MFC after: 1 week Sponsored by: Microsoft OSTC 298563 hyperv/hn: Allow users to configure ifq or bufring depth. MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:33:26 2016 (r302046) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:49:07 2016 (r302047) @@ -291,6 +291,10 @@ static int hn_tx_ring_cnt = 0; SYSCTL_INT(_hw_hn, OID_AUTO, tx_ring_cnt, CTLFLAG_RDTUN, &hn_tx_ring_cnt, 0, "# of TX rings to use"); +static int hn_tx_swq_depth = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, tx_swq_depth, CTLFLAG_RDTUN, + &hn_tx_swq_depth, 0, "Depth of IFQ or BUFRING"); + static u_int hn_cpu_index; /* @@ -352,6 +356,16 @@ hn_set_lro_lenlim(struct hn_softc *sc, i #endif static int +hn_get_txswq_depth(const struct hn_tx_ring *txr) +{ + + KASSERT(txr->hn_txdesc_cnt > 0, ("tx ring is not setup yet")); + if (hn_tx_swq_depth < txr->hn_txdesc_cnt) + return txr->hn_txdesc_cnt; + return hn_tx_swq_depth; +} + +static int hn_ifmedia_upd(struct ifnet *ifp __unused) { @@ -517,9 +531,11 @@ netvsc_attach(device_t dev) /* needed by hv_rf_on_device_add() code */ ifp->if_mtu = ETHERMTU; if (hn_use_if_start) { + int qdepth = hn_get_txswq_depth(&sc->hn_tx_ring[0]); + ifp->if_start = hn_start; - IFQ_SET_MAXLEN(&ifp->if_snd, 512); - ifp->if_snd.ifq_drv_maxlen = 511; + IFQ_SET_MAXLEN(&ifp->if_snd, qdepth); + ifp->if_snd.ifq_drv_maxlen = qdepth - 1; IFQ_SET_READY(&ifp->if_snd); } else { ifp->if_transmit = hn_transmit; @@ -2341,10 +2357,14 @@ hn_create_tx_ring(struct hn_softc *sc, i TASK_INIT(&txr->hn_tx_task, 0, hn_start_taskfunc, txr); TASK_INIT(&txr->hn_txeof_task, 0, hn_start_txeof_taskfunc, txr); } else { + int br_depth; + txr->hn_txeof = hn_xmit_txeof; TASK_INIT(&txr->hn_tx_task, 0, hn_xmit_taskfunc, txr); TASK_INIT(&txr->hn_txeof_task, 0, hn_xmit_txeof_taskfunc, txr); - txr->hn_mbuf_br = buf_ring_alloc(txr->hn_txdesc_cnt, M_NETVSC, + + br_depth = hn_get_txswq_depth(txr); + txr->hn_mbuf_br = buf_ring_alloc(br_depth, M_NETVSC, M_WAITOK, &txr->hn_tx_lock); } @@ -2756,8 +2776,10 @@ hn_transmit(struct ifnet *ifp, struct mb txr = &sc->hn_tx_ring[idx]; error = drbr_enqueue(ifp, txr->hn_mbuf_br, m); - if (error) + if (error) { + if_inc_counter(ifp, IFCOUNTER_OQDROPS, 1); return error; + } if (txr->hn_oactive) return 0; From owner-svn-src-stable-10@freebsd.org Tue Jun 21 06:18:43 2016 Return-Path: Delivered-To: svn-src-stable-10@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 9FB48A7B3CB; Tue, 21 Jun 2016 06:18:43 +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 6B27E1DB3; Tue, 21 Jun 2016 06:18:43 +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 u5L6IgqH013047; Tue, 21 Jun 2016 06:18:42 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L6IfA0013039; Tue, 21 Jun 2016 06:18:41 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210618.u5L6IfA0013039@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 06:18:41 +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: r302048 - in stable/10/sys/dev/hyperv: include netvsc storvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 06:18:43 -0000 Author: sephe Date: Tue Jun 21 06:18:41 2016 New Revision: 302048 URL: https://svnweb.freebsd.org/changeset/base/302048 Log: MFC 298569,298570,298571,298572,298574,298575,298613,298614,298615,298616,298617 298569 hyperv/channel: Remove the unnecessary 'new' flag MFC after: 1 week Sponsored by: Microsoft OSTC 298570 hyperv/channel: Minor style changes; no functional changes. MFC after: 1 week Sponsored by: Microsoft OSTC 298571 hyperv/channel: Remove unapplied comment MFC after: 1 week Sponsored by: Microsoft OSTC 298572 hyperv/channel: Log a warning about duplicated primary channel offer MFC after: 1 week Sponsored by: Microsoft OSTC 298574 hyperv/channel: Add functions to synchronize sub-channel offers MFC after: 1 week Sponsored by: Microsoft OSTC 298575 hyperv/hn: Synchronize sub-channel offers MFC after: 1 week Sponsored by: Microsoft OSTC 298613 hyperv/stor: Remove the useless hs_open_multi_channel This fixes the sub-channel offer race after Hyper-V device probe/attach is moved to vmbus SYSINIT/attach. MFC after: 1 week Sponsored by: Microsoft OSTC 298614 hyperv/stor: Synchronize sub-channel offers MFC after: 1 week Sponsored by: Microsoft OSTC 298615 hyperv/hn: Avoid sub-channel creation callback. Since the sub-channel offers are synchronized, we can do our own channel setup without using the sub-channel creation callback. This paves the way to whack the sub-channel creation callback. MFC after: 1 week Sponsored by: Microsoft OSTC 298616 hyperv/stor: Avoid sub-channel creation callback. Since the sub-channel offers are synchronized, we can do our own channel setup without using the sub-channel creation callback. This paves the way to whack the sub-channel creation callback. MFC after: 1 week Sponsored by: Microsoft OSTC 298617 hyperv/channel: Git rid of the sub-channel creation callback It is no longer used. MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/include/hyperv.h stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis.h stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_channel.c stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/include/hyperv.h ============================================================================== --- stable/10/sys/dev/hyperv/include/hyperv.h Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/include/hyperv.h Tue Jun 21 06:18:41 2016 (r302048) @@ -691,7 +691,6 @@ typedef struct { } hv_vmbus_ring_buffer_info; typedef void (*hv_vmbus_pfn_channel_callback)(void *context); -typedef void (*hv_vmbus_sc_creation_callback)(void *context); typedef enum { HV_CHANNEL_OFFER_STATE, @@ -804,13 +803,6 @@ typedef struct hv_vmbus_channel { * response on the same channel. */ - /* - * Multi-channel creation callback. This callback will be called in - * process context when a Multi-channel offer is received from the host. - * The guest can open the Multi-channel in the context of this callback. - */ - hv_vmbus_sc_creation_callback sc_creation_callback; - struct mtx sc_lock; /* @@ -818,6 +810,7 @@ typedef struct hv_vmbus_channel { */ TAILQ_HEAD(, hv_vmbus_channel) sc_list_anchor; TAILQ_ENTRY(hv_vmbus_channel) sc_list_entry; + int subchan_cnt; /* * The primary channel this sub-channle belongs to. @@ -914,6 +907,9 @@ int hv_vmbus_channel_teardown_gpdal( struct hv_vmbus_channel* vmbus_select_outgoing_channel(struct hv_vmbus_channel *promary); void vmbus_channel_cpu_set(struct hv_vmbus_channel *chan, int cpu); +struct hv_vmbus_channel ** + vmbus_get_subchan(struct hv_vmbus_channel *pri_chan, int subchan_cnt); +void vmbus_rel_subchan(struct hv_vmbus_channel **subchan, int subchan_cnt); /** * @brief Get physical address from virtual Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Tue Jun 21 06:18:41 2016 (r302048) @@ -660,30 +660,12 @@ hv_nv_disconnect_from_vsp(netvsc_dev *ne hv_nv_destroy_send_buffer(net_dev); } -/* - * Callback handler for subchannel offer - * @@param context new subchannel - */ -static void -hv_nv_subchan_callback(void *xchan) +void +hv_nv_subchan_attach(struct hv_vmbus_channel *chan) { - struct hv_vmbus_channel *chan = xchan; - netvsc_dev *net_dev; - uint16_t chn_index = chan->offer_msg.offer.sub_channel_index; - struct hv_device *device = chan->device; - hn_softc_t *sc = device_get_softc(device->device); - int ret; - - net_dev = sc->net_dev; - - if (chn_index >= net_dev->num_channel) { - /* Would this ever happen? */ - return; - } - netvsc_subchan_callback(sc, chan); chan->hv_chan_rdbuf = malloc(NETVSC_PACKET_SIZE, M_NETVSC, M_WAITOK); - ret = hv_vmbus_channel_open(chan, NETVSC_DEVICE_RING_BUFFER_SIZE, + hv_vmbus_channel_open(chan, NETVSC_DEVICE_RING_BUFFER_SIZE, NETVSC_DEVICE_RING_BUFFER_SIZE, NULL, 0, hv_nv_on_channel_callback, chan); } @@ -720,7 +702,6 @@ hv_nv_on_device_add(struct hv_device *de free(chan->hv_chan_rdbuf, M_NETVSC); goto cleanup; } - chan->sc_creation_callback = hv_nv_subchan_callback; /* * Connect with the NetVsp Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 06:18:41 2016 (r302048) @@ -1267,6 +1267,7 @@ int hv_nv_on_device_remove(struct hv_dev boolean_t destroy_channel); int hv_nv_on_send(struct hv_vmbus_channel *chan, netvsc_packet *pkt); int hv_nv_get_next_send_section(netvsc_dev *net_dev); +void hv_nv_subchan_attach(struct hv_vmbus_channel *chan); #endif /* __HV_NET_VSC_H__ */ Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 06:18:41 2016 (r302048) @@ -336,6 +336,7 @@ static void hn_create_rx_data(struct hn_ static void hn_destroy_rx_data(struct hn_softc *sc); static void hn_set_tx_chimney_size(struct hn_softc *, int); static void hn_channel_attach(struct hn_softc *, struct hv_vmbus_channel *); +static void hn_subchan_attach(struct hn_softc *, struct hv_vmbus_channel *); static int hn_transmit(struct ifnet *, struct mbuf *); static void hn_xmit_qflush(struct ifnet *); @@ -438,7 +439,7 @@ static int netvsc_attach(device_t dev) { struct hv_device *device_ctx = vmbus_get_devctx(dev); - struct hv_vmbus_channel *chan; + struct hv_vmbus_channel *pri_chan; netvsc_device_info device_info; hn_softc_t *sc; int unit = device_get_unit(dev); @@ -518,12 +519,12 @@ netvsc_attach(device_t dev) /* * Associate the first TX/RX ring w/ the primary channel. */ - chan = device_ctx->channel; - KASSERT(HV_VMBUS_CHAN_ISPRIMARY(chan), ("not primary channel")); - KASSERT(chan->offer_msg.offer.sub_channel_index == 0, + pri_chan = device_ctx->channel; + KASSERT(HV_VMBUS_CHAN_ISPRIMARY(pri_chan), ("not primary channel")); + KASSERT(pri_chan->offer_msg.offer.sub_channel_index == 0, ("primary channel subidx %u", - chan->offer_msg.offer.sub_channel_index)); - hn_channel_attach(sc, chan); + pri_chan->offer_msg.offer.sub_channel_index)); + hn_channel_attach(sc, pri_chan); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = hn_ioctl; @@ -578,6 +579,26 @@ netvsc_attach(device_t dev) device_printf(dev, "%d TX ring, %d RX ring\n", sc->hn_tx_ring_inuse, sc->hn_rx_ring_inuse); + if (sc->net_dev->num_channel > 1) { + struct hv_vmbus_channel **subchan; + int subchan_cnt = sc->net_dev->num_channel - 1; + int i; + + /* Wait for sub-channels setup to complete. */ + subchan = vmbus_get_subchan(pri_chan, subchan_cnt); + + /* Attach the sub-channels. */ + for (i = 0; i < subchan_cnt; ++i) { + /* NOTE: Calling order is critical. */ + hn_subchan_attach(sc, subchan[i]); + hv_nv_subchan_attach(subchan[i]); + } + + /* Release the sub-channels */ + vmbus_rel_subchan(subchan, subchan_cnt); + device_printf(dev, "%d sub-channels setup done\n", subchan_cnt); + } + #if __FreeBSD_version >= 1100099 if (sc->hn_rx_ring_inuse > 1) { /* @@ -2910,8 +2931,8 @@ hn_channel_attach(struct hn_softc *sc, s vmbus_channel_cpu_set(chan, (sc->hn_cpu + idx) % mp_ncpus); } -void -netvsc_subchan_callback(struct hn_softc *sc, struct hv_vmbus_channel *chan) +static void +hn_subchan_attach(struct hn_softc *sc, struct hv_vmbus_channel *chan) { KASSERT(!HV_VMBUS_CHAN_ISPRIMARY(chan), Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis.h Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis.h Tue Jun 21 06:18:41 2016 (r302048) @@ -1068,8 +1068,6 @@ struct hv_vmbus_channel; int netvsc_recv(struct hv_vmbus_channel *chan, netvsc_packet *packet, rndis_tcp_ip_csum_info *csum_info); void netvsc_channel_rollup(struct hv_vmbus_channel *chan); -void netvsc_subchan_callback(struct hn_softc *sc, - struct hv_vmbus_channel *chan); void* hv_set_rppi_data(rndis_msg *rndis_mesg, uint32_t rppi_size, Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 06:18:41 2016 (r302048) @@ -134,7 +134,6 @@ struct storvsc_softc { uint32_t hs_num_out_reqs; boolean_t hs_destroy; boolean_t hs_drain_notify; - boolean_t hs_open_multi_channel; struct sema hs_drain_sema; struct hv_storvsc_request hs_init_req; struct hv_storvsc_request hs_reset_req; @@ -347,29 +346,19 @@ get_stor_device(struct hv_device *device return sc; } -/** - * @brief Callback handler, will be invoked when receive mutil-channel offer - * - * @param context new multi-channel - */ static void -storvsc_handle_sc_creation(void *context) +storvsc_subchan_attach(struct hv_vmbus_channel *new_channel) { - hv_vmbus_channel *new_channel; struct hv_device *device; struct storvsc_softc *sc; struct vmstor_chan_props props; int ret = 0; - new_channel = (hv_vmbus_channel *)context; device = new_channel->device; sc = get_stor_device(device, TRUE); if (sc == NULL) return; - if (FALSE == sc->hs_open_multi_channel) - return; - memset(&props, 0, sizeof(props)); ret = hv_vmbus_channel_open(new_channel, @@ -392,11 +381,12 @@ storvsc_handle_sc_creation(void *context static void storvsc_send_multichannel_request(struct hv_device *dev, int max_chans) { + struct hv_vmbus_channel **subchan; struct storvsc_softc *sc; struct hv_storvsc_request *request; struct vstor_packet *vstor_packet; int request_channels_cnt = 0; - int ret; + int ret, i; /* get multichannels count that need to create */ request_channels_cnt = MIN(max_chans, mp_ncpus); @@ -410,9 +400,6 @@ storvsc_send_multichannel_request(struct request = &sc->hs_init_req; - /* Establish a handler for multi-channel */ - dev->channel->sc_creation_callback = storvsc_handle_sc_creation; - /* request the host to create multi-channel */ memset(request, 0, sizeof(struct hv_storvsc_request)); @@ -448,7 +435,15 @@ storvsc_send_multichannel_request(struct return; } - sc->hs_open_multi_channel = TRUE; + /* Wait for sub-channels setup to complete. */ + subchan = vmbus_get_subchan(dev->channel, request_channels_cnt); + + /* Attach the sub-channels. */ + for (i = 0; i < request_channels_cnt; ++i) + storvsc_subchan_attach(subchan[i]); + + /* Release the sub-channels. */ + vmbus_rel_subchan(subchan, request_channels_cnt); if (bootverbose) printf("Storvsc create multi-channel success!\n"); @@ -1067,7 +1062,6 @@ storvsc_attach(device_t dev) sc->hs_destroy = FALSE; sc->hs_drain_notify = FALSE; - sc->hs_open_multi_channel = FALSE; sema_init(&sc->hs_drain_sema, 0, "Store Drain Sema"); ret = hv_storvsc_connect_vsp(hv_dev); Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Jun 21 06:18:41 2016 (r302048) @@ -618,7 +618,6 @@ hv_vmbus_channel_close_internal(hv_vmbus hv_vmbus_channel_msg_info* info; channel->state = HV_CHANNEL_OPEN_STATE; - channel->sc_creation_callback = NULL; /* * set rxq to NULL to avoid more requests be scheduled Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 05:49:07 2016 (r302047) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Tue Jun 21 06:18:41 2016 (r302048) @@ -177,13 +177,10 @@ hv_vmbus_free_vmbus_channel(hv_vmbus_cha static void vmbus_channel_process_offer(hv_vmbus_channel *new_channel) { - boolean_t f_new; hv_vmbus_channel* channel; int ret; uint32_t relid; - f_new = TRUE; - channel = NULL; relid = new_channel->offer_msg.child_rel_id; /* * Make sure this is a new offer @@ -192,31 +189,24 @@ vmbus_channel_process_offer(hv_vmbus_cha hv_vmbus_g_connection.channels[relid] = new_channel; TAILQ_FOREACH(channel, &hv_vmbus_g_connection.channel_anchor, - list_entry) - { + list_entry) { if (memcmp(&channel->offer_msg.offer.interface_type, &new_channel->offer_msg.offer.interface_type, sizeof(hv_guid)) == 0 && memcmp(&channel->offer_msg.offer.interface_instance, &new_channel->offer_msg.offer.interface_instance, - sizeof(hv_guid)) == 0) { - f_new = FALSE; + sizeof(hv_guid)) == 0) break; - } } - if (f_new) { - /* Insert at tail */ - TAILQ_INSERT_TAIL( - &hv_vmbus_g_connection.channel_anchor, - new_channel, - list_entry); + if (channel == NULL) { + /* Install the new primary channel */ + TAILQ_INSERT_TAIL(&hv_vmbus_g_connection.channel_anchor, + new_channel, list_entry); } mtx_unlock(&hv_vmbus_g_connection.channel_lock); - /*XXX add new channel to percpu_list */ - - if (!f_new) { + if (channel != NULL) { /* * Check if this is a sub channel. */ @@ -227,10 +217,8 @@ vmbus_channel_process_offer(hv_vmbus_cha new_channel->primary_channel = channel; new_channel->device = channel->device; mtx_lock(&channel->sc_lock); - TAILQ_INSERT_TAIL( - &channel->sc_list_anchor, - new_channel, - sc_list_entry); + TAILQ_INSERT_TAIL(&channel->sc_list_anchor, + new_channel, sc_list_entry); mtx_unlock(&channel->sc_lock); if (bootverbose) { @@ -251,17 +239,25 @@ vmbus_channel_process_offer(hv_vmbus_cha "its primary channel is <%p>.\n", new_channel, new_channel->primary_channel); - /*XXX add it to percpu_list */ - new_channel->state = HV_CHANNEL_OPEN_STATE; - if (channel->sc_creation_callback != NULL) { - channel->sc_creation_callback(new_channel); - } + + /* + * Bump up sub-channel count and notify anyone that is + * interested in this sub-channel, after this sub-channel + * is setup. + */ + mtx_lock(&channel->sc_lock); + channel->subchan_cnt++; + mtx_unlock(&channel->sc_lock); + wakeup(channel); + return; } - hv_vmbus_free_vmbus_channel(new_channel); - return; + printf("VMBUS: duplicated primary channel%u\n", + new_channel->offer_msg.child_rel_id); + hv_vmbus_free_vmbus_channel(new_channel); + return; } new_channel->state = HV_CHANNEL_OPEN_STATE; @@ -283,10 +279,8 @@ vmbus_channel_process_offer(hv_vmbus_cha ret = hv_vmbus_child_device_register(new_channel->device); if (ret != 0) { mtx_lock(&hv_vmbus_g_connection.channel_lock); - TAILQ_REMOVE( - &hv_vmbus_g_connection.channel_anchor, - new_channel, - list_entry); + TAILQ_REMOVE(&hv_vmbus_g_connection.channel_anchor, + new_channel, list_entry); mtx_unlock(&hv_vmbus_g_connection.channel_lock); hv_vmbus_free_vmbus_channel(new_channel); } @@ -793,3 +787,41 @@ vmbus_scan(void) mtx_sleep(&vmbus_devcnt, &vmbus_chwait_lock, 0, "waitdev", 0); mtx_unlock(&vmbus_chwait_lock); } + +struct hv_vmbus_channel ** +vmbus_get_subchan(struct hv_vmbus_channel *pri_chan, int subchan_cnt) +{ + struct hv_vmbus_channel **ret, *chan; + int i; + + ret = malloc(subchan_cnt * sizeof(struct hv_vmbus_channel *), M_TEMP, + M_WAITOK); + + mtx_lock(&pri_chan->sc_lock); + + while (pri_chan->subchan_cnt < subchan_cnt) + mtx_sleep(pri_chan, &pri_chan->sc_lock, 0, "subch", 0); + + i = 0; + TAILQ_FOREACH(chan, &pri_chan->sc_list_anchor, sc_list_entry) { + /* TODO: refcnt chan */ + ret[i] = chan; + + ++i; + if (i == subchan_cnt) + break; + } + KASSERT(i == subchan_cnt, ("invalid subchan count %d, should be %d", + pri_chan->subchan_cnt, subchan_cnt)); + + mtx_unlock(&pri_chan->sc_lock); + + return ret; +} + +void +vmbus_rel_subchan(struct hv_vmbus_channel **subchan, int subchan_cnt __unused) +{ + + free(subchan, M_TEMP); +} From owner-svn-src-stable-10@freebsd.org Tue Jun 21 06:37:40 2016 Return-Path: Delivered-To: svn-src-stable-10@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 308E9A7B89E; Tue, 21 Jun 2016 06:37:40 +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 DA5E52843; Tue, 21 Jun 2016 06:37:39 +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 u5L6bdsr020604; Tue, 21 Jun 2016 06:37:39 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L6bcnT020601; Tue, 21 Jun 2016 06:37:38 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210637.u5L6bcnT020601@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 06:37:38 +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: r302049 - in stable/10/sys/dev/hyperv: netvsc storvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 06:37:40 -0000 Author: sephe Date: Tue Jun 21 06:37:38 2016 New Revision: 302049 URL: https://svnweb.freebsd.org/changeset/base/302049 Log: MFC 298618,298620,298688,298689 298618 hyperv/stor: Set description properly in probe devmethod MFC after: 1 week Sponsored by: Microsoft OSTC 298620 hyperv/hn: Change description to "Hyper-V Network Interface" This is consistent w/ other Hyper-V devices. MFC after: 1 week Sponsored by: Microsoft OSTC 298688 hyperv/hn: Restart sending earlier once we gathered some free TX descs This greatly reduces the oqdrops under heavy workload. For TCP send/recv test (10K concurrent connections): oqdrops is reduced by 17% on sending side, and 57% on receiving side. For nginx-1.8/wrk-4 1KB object test (10K concurrent connections, 4 requests/connection): oqdrops is reduced by 44% on nginx side, and 10% on wrk side. MFC after: 1 week Sponsored by: Microsoft OSTC 298689 hyperv/hn: Remove unapplied comment. Chimney sending buffers are shared across channels. MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 06:18:41 2016 (r302048) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 06:37:38 2016 (r302049) @@ -1185,7 +1185,8 @@ struct hn_tx_ring { #endif int hn_txdesc_cnt; int hn_txdesc_avail; - int hn_has_txeof; + u_short hn_has_txeof; + u_short hn_txdone_cnt; int hn_sched_tx; void (*hn_txeof)(struct hn_tx_ring *); Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 06:18:41 2016 (r302048) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 06:37:38 2016 (r302049) @@ -157,6 +157,8 @@ __FBSDID("$FreeBSD$"); #define HN_DIRECT_TX_SIZE_DEF 128 +#define HN_EARLY_TXEOF_THRESH 8 + struct hn_txdesc { #ifndef HN_USE_TXDESC_BUFRING SLIST_ENTRY(hn_txdesc) link; @@ -406,7 +408,7 @@ netvsc_probe(device_t dev) p = vmbus_get_type(dev); if (!memcmp(p, &g_net_vsc_device_type.data, sizeof(hv_guid))) { - device_set_desc(dev, "Synthetic Network Interface"); + device_set_desc(dev, "Hyper-V Network Interface"); if (bootverbose) printf("Netvsc probe... DONE \n"); @@ -805,6 +807,13 @@ hn_txdesc_hold(struct hn_txdesc *txd) atomic_add_int(&txd->refs, 1); } +static __inline void +hn_txeof(struct hn_tx_ring *txr) +{ + txr->hn_has_txeof = 0; + txr->hn_txeof(txr); +} + static void hn_tx_done(struct hv_vmbus_channel *chan, void *xpkt) { @@ -823,6 +832,13 @@ hn_tx_done(struct hv_vmbus_channel *chan txr->hn_has_txeof = 1; hn_txdesc_put(txr, txd); + + ++txr->hn_txdone_cnt; + if (txr->hn_txdone_cnt >= HN_EARLY_TXEOF_THRESH) { + txr->hn_txdone_cnt = 0; + if (txr->hn_oactive) + hn_txeof(txr); + } } void @@ -848,8 +864,8 @@ netvsc_channel_rollup(struct hv_vmbus_ch if (txr == NULL || !txr->hn_has_txeof) return; - txr->hn_has_txeof = 0; - txr->hn_txeof(txr); + txr->hn_txdone_cnt = 0; + hn_txeof(txr); } /* @@ -999,8 +1015,6 @@ hn_encap(struct hn_tx_ring *txr, struct /* * Chimney send, if the packet could fit into one chimney buffer. - * - * TODO: vRSS, chimney buffer should be per-channel. */ if (packet->tot_data_buf_len < txr->hn_tx_chimney_size) { netvsc_dev *net_dev = txr->hn_sc->net_dev; Modified: stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 06:18:41 2016 (r302048) +++ stable/10/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Tue Jun 21 06:37:38 2016 (r302049) @@ -957,6 +957,7 @@ storvsc_probe(device_t dev) if(bootverbose) device_printf(dev, "Enlightened ATA/IDE detected\n"); + device_set_desc(dev, g_drv_props_table[DRIVER_BLKVSC].drv_desc); ret = BUS_PROBE_DEFAULT; } else if(bootverbose) device_printf(dev, "Emulated ATA/IDE set (hw.ata.disk_enable set)\n"); @@ -964,6 +965,7 @@ storvsc_probe(device_t dev) case DRIVER_STORVSC: if(bootverbose) device_printf(dev, "Enlightened SCSI device detected\n"); + device_set_desc(dev, g_drv_props_table[DRIVER_STORVSC].drv_desc); ret = BUS_PROBE_DEFAULT; break; default: @@ -1015,7 +1017,6 @@ storvsc_attach(device_t dev) /* fill in device specific properties */ sc->hs_unit = device_get_unit(dev); sc->hs_dev = hv_dev; - device_set_desc(dev, g_drv_props_table[stor_type].drv_desc); LIST_INIT(&sc->hs_free_list); mtx_init(&sc->hs_lock, "hvslck", NULL, MTX_DEF); From owner-svn-src-stable-10@freebsd.org Tue Jun 21 06:45:31 2016 Return-Path: Delivered-To: svn-src-stable-10@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 17FF7A7BB29; Tue, 21 Jun 2016 06:45:31 +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 D76022C30; Tue, 21 Jun 2016 06:45:30 +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 u5L6jU9F024366; Tue, 21 Jun 2016 06:45:30 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L6jTLQ024362; Tue, 21 Jun 2016 06:45:29 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210645.u5L6jTLQ024362@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 06:45:29 +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: r302050 - in stable/10/sys/dev/hyperv: netvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 06:45:31 -0000 Author: sephe Date: Tue Jun 21 06:45:29 2016 New Revision: 302050 URL: https://svnweb.freebsd.org/changeset/base/302050 Log: MFC 298690,298693,298694 298690 hyperv/hn: Mark sysctls MPSAFE MFC after: 1 week Sponsored by: Microsoft OSTC 298693 hyperv/vmbus: Mark sysctls MPSAFE MFC after: 1 week Sponsored by: Microsoft OSTC 298694 hyperv/hn: Add stat for # of chimney sending tries MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_channel.c stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 06:37:38 2016 (r302049) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 06:45:29 2016 (r302050) @@ -1211,6 +1211,7 @@ struct hn_tx_ring { u_long hn_send_failed; u_long hn_txdma_failed; u_long hn_tx_collapsed; + u_long hn_tx_chimney_tried; u_long hn_tx_chimney; u_long hn_pkts; Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 06:37:38 2016 (r302049) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 06:45:29 2016 (r302050) @@ -216,7 +216,8 @@ struct hn_txdesc { int hv_promisc_mode = 0; /* normal mode by default */ -SYSCTL_NODE(_hw, OID_AUTO, hn, CTLFLAG_RD, NULL, "Hyper-V network interface"); +SYSCTL_NODE(_hw, OID_AUTO, hn, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, + "Hyper-V network interface"); /* Trust tcp segements verification on host side. */ static int hn_trust_hosttcp = 1; @@ -1020,6 +1021,7 @@ hn_encap(struct hn_tx_ring *txr, struct netvsc_dev *net_dev = txr->hn_sc->net_dev; uint32_t send_buf_section_idx; + txr->hn_tx_chimney_tried++; send_buf_section_idx = hv_nv_get_next_send_section(net_dev); if (send_buf_section_idx != @@ -2216,7 +2218,7 @@ hn_create_rx_data(struct hn_softc *sc, i /* Create dev.hn.UNIT.rx sysctl tree */ sc->hn_rx_sysctl_tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "rx", - CTLFLAG_RD, 0, ""); + CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); for (i = 0; i < sc->hn_rx_ring_cnt; ++i) { struct hn_rx_ring *rxr = &sc->hn_rx_ring[i]; @@ -2256,7 +2258,7 @@ hn_create_rx_data(struct hn_softc *sc, i snprintf(name, sizeof(name), "%d", i); rxr->hn_rx_sysctl_tree = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(sc->hn_rx_sysctl_tree), - OID_AUTO, name, CTLFLAG_RD, 0, ""); + OID_AUTO, name, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); if (rxr->hn_rx_sysctl_tree != NULL) { SYSCTL_ADD_ULONG(ctx, @@ -2268,7 +2270,7 @@ hn_create_rx_data(struct hn_softc *sc, i } SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "lro_queued", - CTLTYPE_U64 | CTLFLAG_RW, sc, + CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_lro.lro_queued), #if __FreeBSD_version < 1100095 hn_rx_stat_int_sysctl, @@ -2277,7 +2279,7 @@ hn_create_rx_data(struct hn_softc *sc, i #endif "LU", "LRO queued"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "lro_flushed", - CTLTYPE_U64 | CTLFLAG_RW, sc, + CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_lro.lro_flushed), #if __FreeBSD_version < 1100095 hn_rx_stat_int_sysctl, @@ -2286,51 +2288,53 @@ hn_create_rx_data(struct hn_softc *sc, i #endif "LU", "LRO flushed"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "lro_tried", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_lro_tried), hn_rx_stat_ulong_sysctl, "LU", "# of LRO tries"); #if __FreeBSD_version >= 1100099 SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "lro_length_lim", - CTLTYPE_UINT | CTLFLAG_RW, sc, 0, hn_lro_lenlim_sysctl, "IU", + CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, + hn_lro_lenlim_sysctl, "IU", "Max # of data bytes to be aggregated by LRO"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "lro_ackcnt_lim", - CTLTYPE_INT | CTLFLAG_RW, sc, 0, hn_lro_ackcnt_sysctl, "I", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, + hn_lro_ackcnt_sysctl, "I", "Max # of ACKs to be aggregated by LRO"); #endif SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "trust_hosttcp", - CTLTYPE_INT | CTLFLAG_RW, sc, HN_TRUST_HCSUM_TCP, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, HN_TRUST_HCSUM_TCP, hn_trust_hcsum_sysctl, "I", "Trust tcp segement verification on host side, " "when csum info is missing"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "trust_hostudp", - CTLTYPE_INT | CTLFLAG_RW, sc, HN_TRUST_HCSUM_UDP, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, HN_TRUST_HCSUM_UDP, hn_trust_hcsum_sysctl, "I", "Trust udp datagram verification on host side, " "when csum info is missing"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "trust_hostip", - CTLTYPE_INT | CTLFLAG_RW, sc, HN_TRUST_HCSUM_IP, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, HN_TRUST_HCSUM_IP, hn_trust_hcsum_sysctl, "I", "Trust ip packet verification on host side, " "when csum info is missing"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "csum_ip", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_csum_ip), hn_rx_stat_ulong_sysctl, "LU", "RXCSUM IP"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "csum_tcp", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_csum_tcp), hn_rx_stat_ulong_sysctl, "LU", "RXCSUM TCP"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "csum_udp", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_csum_udp), hn_rx_stat_ulong_sysctl, "LU", "RXCSUM UDP"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "csum_trusted", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_csum_trusted), hn_rx_stat_ulong_sysctl, "LU", "# of packets that we trust host's csum verification"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "small_pkts", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_small_pkts), hn_rx_stat_ulong_sysctl, "LU", "# of small packets received"); SYSCTL_ADD_INT(ctx, child, OID_AUTO, "rx_ring_cnt", @@ -2523,7 +2527,7 @@ hn_create_tx_ring(struct hn_softc *sc, i snprintf(name, sizeof(name), "%d", id); txr->hn_tx_sysctl_tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, - name, CTLFLAG_RD, 0, ""); + name, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); if (txr->hn_tx_sysctl_tree != NULL) { child = SYSCTL_CHILDREN(txr->hn_tx_sysctl_tree); @@ -2618,7 +2622,7 @@ hn_create_tx_data(struct hn_softc *sc, i /* Create dev.hn.UNIT.tx sysctl tree */ sc->hn_tx_sysctl_tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "tx", - CTLFLAG_RD, 0, ""); + CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); for (i = 0; i < sc->hn_tx_ring_cnt; ++i) { int error; @@ -2629,25 +2633,29 @@ hn_create_tx_data(struct hn_softc *sc, i } SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "no_txdescs", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_no_txdescs), hn_tx_stat_ulong_sysctl, "LU", "# of times short of TX descs"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "send_failed", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_send_failed), hn_tx_stat_ulong_sysctl, "LU", "# of hyper-v sending failure"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "txdma_failed", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_txdma_failed), hn_tx_stat_ulong_sysctl, "LU", "# of TX DMA failure"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_collapsed", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_tx_collapsed), hn_tx_stat_ulong_sysctl, "LU", "# of TX mbuf collapsed"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_chimney", - CTLTYPE_ULONG | CTLFLAG_RW, sc, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_tx_chimney), hn_tx_stat_ulong_sysctl, "LU", "# of chimney send"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_chimney_tried", + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, + __offsetof(struct hn_tx_ring, hn_tx_chimney_tried), + hn_tx_stat_ulong_sysctl, "LU", "# of chimney send tries"); SYSCTL_ADD_INT(ctx, child, OID_AUTO, "txdesc_cnt", CTLFLAG_RD, &sc->hn_tx_ring[0].hn_txdesc_cnt, 0, "# of total TX descs"); @@ -2655,15 +2663,16 @@ hn_create_tx_data(struct hn_softc *sc, i CTLFLAG_RD, &sc->hn_tx_chimney_max, 0, "Chimney send packet size upper boundary"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_chimney_size", - CTLTYPE_INT | CTLFLAG_RW, sc, 0, hn_tx_chimney_size_sysctl, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, + hn_tx_chimney_size_sysctl, "I", "Chimney send packet size limit"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "direct_tx_size", - CTLTYPE_INT | CTLFLAG_RW, sc, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_direct_tx_size), hn_tx_conf_int_sysctl, "I", "Size of the packet for direct transmission"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "sched_tx", - CTLTYPE_INT | CTLFLAG_RW, sc, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_tx_ring, hn_sched_tx), hn_tx_conf_int_sysctl, "I", "Always schedule transmission " Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Jun 21 06:37:38 2016 (r302049) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Tue Jun 21 06:45:29 2016 (r302050) @@ -118,21 +118,21 @@ vmbus_channel_sysctl_create(hv_vmbus_cha /* This creates dev.DEVNAME.DEVUNIT.channel tree */ devch_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), - OID_AUTO, "channel", CTLFLAG_RD, 0, ""); + OID_AUTO, "channel", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); /* This creates dev.DEVNAME.DEVUNIT.channel.CHANID tree */ snprintf(name, sizeof(name), "%d", ch_id); devch_id_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(devch_sysctl), - OID_AUTO, name, CTLFLAG_RD, 0, ""); + OID_AUTO, name, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); if (primary_ch != NULL) { devch_sub_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(devch_id_sysctl), - OID_AUTO, "sub", CTLFLAG_RD, 0, ""); + OID_AUTO, "sub", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); snprintf(name, sizeof(name), "%d", sub_ch_id); devch_id_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(devch_sub_sysctl), - OID_AUTO, name, CTLFLAG_RD, 0, ""); + OID_AUTO, name, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO, "chanid", CTLFLAG_RD, @@ -141,20 +141,20 @@ vmbus_channel_sysctl_create(hv_vmbus_cha SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO, "cpu", CTLFLAG_RD, &channel->target_cpu, 0, "owner CPU id"); SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO, - "monitor_allocated", CTLTYPE_INT | CTLFLAG_RD, channel, 0, - vmbus_channel_sysctl_monalloc, "I", + "monitor_allocated", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, + channel, 0, vmbus_channel_sysctl_monalloc, "I", "is monitor allocated to this channel"); devch_id_in_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO, "in", - CTLFLAG_RD, 0, ""); + CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); devch_id_out_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(devch_id_sysctl), OID_AUTO, "out", - CTLFLAG_RD, 0, ""); + CTLFLAG_RD | CTLFLAG_MPSAFE, 0, ""); hv_ring_buffer_stat(ctx, SYSCTL_CHILDREN(devch_id_in_sysctl), &(channel->inbound), Modified: stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c Tue Jun 21 06:37:38 2016 (r302049) +++ stable/10/sys/dev/hyperv/vmbus/hv_ring_buffer.c Tue Jun 21 06:45:29 2016 (r302050) @@ -78,7 +78,7 @@ hv_ring_buffer_stat( { SYSCTL_ADD_PROC(ctx, tree_node, OID_AUTO, "ring_buffer_stats", - CTLTYPE_STRING|CTLFLAG_RD, rbi, 0, + CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, rbi, 0, hv_rbi_sysctl_stats, "A", desc); } /** From owner-svn-src-stable-10@freebsd.org Tue Jun 21 06:52:22 2016 Return-Path: Delivered-To: svn-src-stable-10@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 56336A7BDEF; Tue, 21 Jun 2016 06:52:22 +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 25BD0121A; Tue, 21 Jun 2016 06:52:22 +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 u5L6qLOM027886; Tue, 21 Jun 2016 06:52:21 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L6qL7M027885; Tue, 21 Jun 2016 06:52:21 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210652.u5L6qL7M027885@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 06:52:21 +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: r302051 - stable/10/sys/netinet 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 06:52:22 -0000 Author: sephe Date: Tue Jun 21 06:52:21 2016 New Revision: 302051 URL: https://svnweb.freebsd.org/changeset/base/302051 Log: MFC 298696,298730 298696 tcp/lro: Fix typo. MFC after: 1 week Sponsored by: Microsoft OSTC 298730 tcp/lro: Fix more typo Noticed by: hiren MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/netinet/tcp_lro.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/netinet/tcp_lro.c ============================================================================== --- stable/10/sys/netinet/tcp_lro.c Tue Jun 21 06:45:29 2016 (r302050) +++ stable/10/sys/netinet/tcp_lro.c Tue Jun 21 06:52:21 2016 (r302051) @@ -451,7 +451,7 @@ tcp_lro_rx(struct lro_ctrl *lc, struct m if ((th->th_flags & ~(TH_ACK | TH_PUSH)) != 0) return (TCP_LRO_CANNOT); - /* XXX-BZ We lose a AKC|PUSH flag concatinating multiple segments. */ + /* XXX-BZ We lose a ACK|PUSH flag concatenating multiple segments. */ /* XXX-BZ Ideally we'd flush on PUSH? */ /* From owner-svn-src-stable-10@freebsd.org Tue Jun 21 06:56:10 2016 Return-Path: Delivered-To: svn-src-stable-10@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 EE0CFA7BE74; Tue, 21 Jun 2016 06:56:10 +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 A5AB613C0; Tue, 21 Jun 2016 06:56:10 +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 u5L6u9Zb028080; Tue, 21 Jun 2016 06:56:09 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L6u9JJ028079; Tue, 21 Jun 2016 06:56:09 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210656.u5L6u9JJ028079@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 06:56:09 +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: r302052 - stable/10/sys/dev/mxge 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 06:56:11 -0000 Author: sephe Date: Tue Jun 21 06:56:09 2016 New Revision: 302052 URL: https://svnweb.freebsd.org/changeset/base/302052 Log: MFC 299506 mxge: Setup mbuf flowid before calling tcp_lro_rx(). Reviewed by: gallatin MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6320 Modified: stable/10/sys/dev/mxge/if_mxge.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/mxge/if_mxge.c ============================================================================== --- stable/10/sys/dev/mxge/if_mxge.c Tue Jun 21 06:52:21 2016 (r302051) +++ stable/10/sys/dev/mxge/if_mxge.c Tue Jun 21 06:56:09 2016 (r302052) @@ -2701,8 +2701,12 @@ mxge_rx_done_big(struct mxge_slice_state if (eh->ether_type == htons(ETHERTYPE_VLAN)) { mxge_vlan_tag_remove(m, &csum); } + /* flowid only valid if RSS hashing is enabled */ + if (sc->num_slices > 1) { + m->m_pkthdr.flowid = (ss - sc->ss); + M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); + } /* if the checksum is valid, mark it in the mbuf header */ - if ((ifp->if_capenable & (IFCAP_RXCSUM_IPV6 | IFCAP_RXCSUM)) && (0 == mxge_rx_csum(m, csum))) { /* Tell the stack that the checksum is good */ @@ -2715,11 +2719,6 @@ mxge_rx_done_big(struct mxge_slice_state return; #endif } - /* flowid only valid if RSS hashing is enabled */ - if (sc->num_slices > 1) { - m->m_pkthdr.flowid = (ss - sc->ss); - M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); - } /* pass the frame up the stack */ (*ifp->if_input)(ifp, m); } @@ -2770,6 +2769,11 @@ mxge_rx_done_small(struct mxge_slice_sta if (eh->ether_type == htons(ETHERTYPE_VLAN)) { mxge_vlan_tag_remove(m, &csum); } + /* flowid only valid if RSS hashing is enabled */ + if (sc->num_slices > 1) { + m->m_pkthdr.flowid = (ss - sc->ss); + M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); + } /* if the checksum is valid, mark it in the mbuf header */ if ((ifp->if_capenable & (IFCAP_RXCSUM_IPV6 | IFCAP_RXCSUM)) && (0 == mxge_rx_csum(m, csum))) { @@ -2783,11 +2787,6 @@ mxge_rx_done_small(struct mxge_slice_sta return; #endif } - /* flowid only valid if RSS hashing is enabled */ - if (sc->num_slices > 1) { - m->m_pkthdr.flowid = (ss - sc->ss); - M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); - } /* pass the frame up the stack */ (*ifp->if_input)(ifp, m); } From owner-svn-src-stable-10@freebsd.org Tue Jun 21 07:05:51 2016 Return-Path: Delivered-To: svn-src-stable-10@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 36D94AC501A; Tue, 21 Jun 2016 07:05:51 +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 134BC1969; Tue, 21 Jun 2016 07:05:51 +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 u5L75orR031694; Tue, 21 Jun 2016 07:05:50 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5L75nrl031690; Tue, 21 Jun 2016 07:05:49 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606210705.u5L75nrl031690@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 21 Jun 2016 07:05:49 +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: r302053 - stable/10/sys/dev/hyperv/netvsc 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 07:05:51 -0000 Author: sephe Date: Tue Jun 21 07:05:49 2016 New Revision: 302053 URL: https://svnweb.freebsd.org/changeset/base/302053 Log: MFC 299401,299888 299401 hyperv/hn: Extract RSS hash value and type. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6287 299888 hyperv/hn: Combine per-packet-information parsing. MFC after: 1 week Sponsored by: Microsoft OSTC Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis.h stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 06:56:09 2016 (r302052) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Tue Jun 21 07:05:49 2016 (r302053) @@ -1164,6 +1164,7 @@ struct hn_rx_ring { u_long hn_lro_tried; u_long hn_small_pkts; u_long hn_pkts; + u_long hn_rss_pkts; /* Rarely used stuffs */ struct sysctl_oid *hn_rx_sysctl_tree; Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 06:56:09 2016 (r302052) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Tue Jun 21 07:05:49 2016 (r302053) @@ -142,7 +142,7 @@ __FBSDID("$FreeBSD$"); #define HN_RNDIS_MSG_LEN \ (sizeof(rndis_msg) + \ - RNDIS_HASH_PPI_SIZE + \ + RNDIS_HASHVAL_PPI_SIZE + \ RNDIS_VLAN_PPI_SIZE + \ RNDIS_TSO_PPI_SIZE + \ RNDIS_CSUM_PPI_SIZE) @@ -883,7 +883,7 @@ hn_encap(struct hn_tx_ring *txr, struct rndis_msg *rndis_mesg; rndis_packet *rndis_pkt; rndis_per_packet_info *rppi; - struct ndis_hash_info *hash_info; + struct rndis_hash_value *hash_value; uint32_t rndis_msg_size; packet = &txd->netvsc_pkt; @@ -909,16 +909,16 @@ hn_encap(struct hn_tx_ring *txr, struct rndis_msg_size = RNDIS_MESSAGE_SIZE(rndis_packet); /* - * Set the hash info for this packet, so that the host could + * Set the hash value for this packet, so that the host could * dispatch the TX done event for this packet back to this TX * ring's channel. */ - rndis_msg_size += RNDIS_HASH_PPI_SIZE; - rppi = hv_set_rppi_data(rndis_mesg, RNDIS_HASH_PPI_SIZE, + rndis_msg_size += RNDIS_HASHVAL_PPI_SIZE; + rppi = hv_set_rppi_data(rndis_mesg, RNDIS_HASHVAL_PPI_SIZE, nbl_hash_value); - hash_info = (struct ndis_hash_info *)((uint8_t *)rppi + + hash_value = (struct rndis_hash_value *)((uint8_t *)rppi + rppi->per_packet_info_offset); - hash_info->hash = txr->hn_tx_idx; + hash_value->hash_value = txr->hn_tx_idx; if (m_head->m_flags & M_VLANTAG) { ndis_8021q_info *rppi_vlan_info; @@ -1308,7 +1308,9 @@ hv_m_append(struct mbuf *m0, int len, c_ */ int netvsc_recv(struct hv_vmbus_channel *chan, netvsc_packet *packet, - rndis_tcp_ip_csum_info *csum_info) + const rndis_tcp_ip_csum_info *csum_info, + const struct rndis_hash_info *hash_info, + const struct rndis_hash_value *hash_value) { struct hn_rx_ring *rxr = chan->hv_chan_rxr; struct ifnet *ifp = rxr->hn_ifp; @@ -1417,7 +1419,6 @@ netvsc_recv(struct hv_vmbus_channel *cha CSUM_DATA_VALID | CSUM_PSEUDO_HDR); m_new->m_pkthdr.csum_data = 0xffff; } - /* Rely on SW csum verification though... */ do_lro = 1; } else if (pr == IPPROTO_UDP) { if (do_csum && @@ -1444,8 +1445,50 @@ skip: m_new->m_flags |= M_VLANTAG; } - m_new->m_pkthdr.flowid = rxr->hn_rx_idx; - M_HASHTYPE_SET(m_new, M_HASHTYPE_OPAQUE); + if (hash_info != NULL && hash_value != NULL) { + int hash_type = M_HASHTYPE_OPAQUE; + + rxr->hn_rss_pkts++; + m_new->m_pkthdr.flowid = hash_value->hash_value; + if ((hash_info->hash_info & NDIS_HASH_FUNCTION_MASK) == + NDIS_HASH_FUNCTION_TOEPLITZ) { + uint32_t type = + (hash_info->hash_info & NDIS_HASH_TYPE_MASK); + + switch (type) { + case NDIS_HASH_IPV4: + hash_type = M_HASHTYPE_RSS_IPV4; + break; + + case NDIS_HASH_TCP_IPV4: + hash_type = M_HASHTYPE_RSS_TCP_IPV4; + break; + + case NDIS_HASH_IPV6: + hash_type = M_HASHTYPE_RSS_IPV6; + break; + + case NDIS_HASH_IPV6_EX: + hash_type = M_HASHTYPE_RSS_IPV6_EX; + break; + + case NDIS_HASH_TCP_IPV6: + hash_type = M_HASHTYPE_RSS_TCP_IPV6; + break; + + case NDIS_HASH_TCP_IPV6_EX: + hash_type = M_HASHTYPE_RSS_TCP_IPV6_EX; + break; + } + } + M_HASHTYPE_SET(m_new, hash_type); + } else { + if (hash_value != NULL) + m_new->m_pkthdr.flowid = hash_value->hash_value; + else + m_new->m_pkthdr.flowid = rxr->hn_rx_idx; + M_HASHTYPE_SET(m_new, M_HASHTYPE_OPAQUE); + } /* * Note: Moved RX completion back to hv_nv_on_receive() so all @@ -2265,6 +2308,11 @@ hn_create_rx_data(struct hn_softc *sc, i SYSCTL_CHILDREN(rxr->hn_rx_sysctl_tree), OID_AUTO, "packets", CTLFLAG_RW, &rxr->hn_pkts, "# of packets received"); + SYSCTL_ADD_ULONG(ctx, + SYSCTL_CHILDREN(rxr->hn_rx_sysctl_tree), + OID_AUTO, "rss_pkts", CTLFLAG_RW, + &rxr->hn_rss_pkts, + "# of packets w/ RSS info received"); } } } Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis.h Tue Jun 21 06:56:09 2016 (r302052) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis.h Tue Jun 21 07:05:49 2016 (r302053) @@ -617,6 +617,7 @@ typedef enum ndis_per_pkt_infotype_ { } ndis_per_pkt_infotype; #define nbl_hash_value pkt_cancel_id +#define nbl_hash_info original_netbuf_list typedef struct ndis_8021q_info_ { union { @@ -630,10 +631,6 @@ typedef struct ndis_8021q_info_ { } u1; } ndis_8021q_info; -struct ndis_hash_info { - uint32_t hash; -} __packed; - struct rndis_object_header { uint8_t type; uint8_t revision; @@ -694,6 +691,28 @@ typedef struct rndis_tcp_ip_csum_info_ { }; } rndis_tcp_ip_csum_info; +struct rndis_hash_value { + uint32_t hash_value; +} __packed; + +struct rndis_hash_info { + uint32_t hash_info; +} __packed; + +#define NDIS_HASH_FUNCTION_MASK 0x000000FF /* see hash function */ +#define NDIS_HASH_TYPE_MASK 0x00FFFF00 /* see hash type */ + +/* hash function */ +#define NDIS_HASH_FUNCTION_TOEPLITZ 0x00000001 + +/* hash type */ +#define NDIS_HASH_IPV4 0x00000100 +#define NDIS_HASH_TCP_IPV4 0x00000200 +#define NDIS_HASH_IPV6 0x00000400 +#define NDIS_HASH_IPV6_EX 0x00000800 +#define NDIS_HASH_TCP_IPV6 0x00001000 +#define NDIS_HASH_TCP_IPV6_EX 0x00002000 + typedef struct rndis_tcp_tso_info_ { union { struct { @@ -727,8 +746,8 @@ typedef struct rndis_tcp_tso_info_ { }; } rndis_tcp_tso_info; -#define RNDIS_HASH_PPI_SIZE (sizeof(rndis_per_packet_info) + \ - sizeof(struct ndis_hash_info)) +#define RNDIS_HASHVAL_PPI_SIZE (sizeof(rndis_per_packet_info) + \ + sizeof(struct rndis_hash_value)) #define RNDIS_VLAN_PPI_SIZE (sizeof(rndis_per_packet_info) + \ sizeof(ndis_8021q_info)) @@ -1066,7 +1085,9 @@ typedef struct rndismp_rx_bufs_info_ { struct hv_vmbus_channel; int netvsc_recv(struct hv_vmbus_channel *chan, - netvsc_packet *packet, rndis_tcp_ip_csum_info *csum_info); + netvsc_packet *packet, const rndis_tcp_ip_csum_info *csum_info, + const struct rndis_hash_info *hash_info, + const struct rndis_hash_value *hash_value); void netvsc_channel_rollup(struct hv_vmbus_channel *chan); void* hv_set_rppi_data(rndis_msg *rndis_mesg, Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Tue Jun 21 06:56:09 2016 (r302052) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Tue Jun 21 07:05:49 2016 (r302053) @@ -50,6 +50,22 @@ __FBSDID("$FreeBSD$"); #include "hv_rndis.h" #include "hv_rndis_filter.h" +struct hv_rf_recvinfo { + const ndis_8021q_info *vlan_info; + const rndis_tcp_ip_csum_info *csum_info; + const struct rndis_hash_info *hash_info; + const struct rndis_hash_value *hash_value; +}; + +#define HV_RF_RECVINFO_VLAN 0x1 +#define HV_RF_RECVINFO_CSUM 0x2 +#define HV_RF_RECVINFO_HASHINF 0x4 +#define HV_RF_RECVINFO_HASHVAL 0x8 +#define HV_RF_RECVINFO_ALL \ + (HV_RF_RECVINFO_VLAN | \ + HV_RF_RECVINFO_CSUM | \ + HV_RF_RECVINFO_HASHINF | \ + HV_RF_RECVINFO_HASHVAL) /* * Forward declarations @@ -434,6 +450,84 @@ hv_rf_receive_indicate_status(rndis_devi } } +static int +hv_rf_find_recvinfo(const rndis_packet *rpkt, struct hv_rf_recvinfo *info) +{ + const rndis_per_packet_info *ppi; + uint32_t mask, len; + + info->vlan_info = NULL; + info->csum_info = NULL; + info->hash_info = NULL; + info->hash_value = NULL; + + if (rpkt->per_pkt_info_offset == 0) + return 0; + + ppi = (const rndis_per_packet_info *) + ((const uint8_t *)rpkt + rpkt->per_pkt_info_offset); + len = rpkt->per_pkt_info_length; + mask = 0; + + while (len != 0) { + const void *ppi_dptr; + uint32_t ppi_dlen; + + if (__predict_false(ppi->size < ppi->per_packet_info_offset)) + return EINVAL; + ppi_dlen = ppi->size - ppi->per_packet_info_offset; + ppi_dptr = (const uint8_t *)ppi + ppi->per_packet_info_offset; + + switch (ppi->type) { + case ieee_8021q_info: + if (__predict_false(ppi_dlen < sizeof(ndis_8021q_info))) + return EINVAL; + info->vlan_info = ppi_dptr; + mask |= HV_RF_RECVINFO_VLAN; + break; + + case tcpip_chksum_info: + if (__predict_false(ppi_dlen < + sizeof(rndis_tcp_ip_csum_info))) + return EINVAL; + info->csum_info = ppi_dptr; + mask |= HV_RF_RECVINFO_CSUM; + break; + + case nbl_hash_value: + if (__predict_false(ppi_dlen < + sizeof(struct rndis_hash_value))) + return EINVAL; + info->hash_value = ppi_dptr; + mask |= HV_RF_RECVINFO_HASHVAL; + break; + + case nbl_hash_info: + if (__predict_false(ppi_dlen < + sizeof(struct rndis_hash_info))) + return EINVAL; + info->hash_info = ppi_dptr; + mask |= HV_RF_RECVINFO_HASHINF; + break; + + default: + goto skip; + } + + if (mask == HV_RF_RECVINFO_ALL) { + /* All found; done */ + break; + } +skip: + if (__predict_false(len < ppi->size)) + return EINVAL; + len -= ppi->size; + ppi = (const rndis_per_packet_info *) + ((const uint8_t *)ppi + ppi->size); + } + return 0; +} + /* * RNDIS filter receive data */ @@ -442,10 +536,9 @@ hv_rf_receive_data(rndis_device *device, struct hv_vmbus_channel *chan, netvsc_packet *pkt) { rndis_packet *rndis_pkt; - ndis_8021q_info *rppi_vlan_info; uint32_t data_offset; - rndis_tcp_ip_csum_info *csum_info = NULL; device_t dev = device->net_dev->dev->device; + struct hv_rf_recvinfo info; rndis_pkt = &message->msg.packet; @@ -469,15 +562,18 @@ hv_rf_receive_data(rndis_device *device, pkt->tot_data_buf_len = rndis_pkt->data_length; pkt->data = (void *)((unsigned long)pkt->data + data_offset); - rppi_vlan_info = hv_get_ppi_data(rndis_pkt, ieee_8021q_info); - if (rppi_vlan_info) { - pkt->vlan_tci = rppi_vlan_info->u1.s1.vlan_id; - } else { - pkt->vlan_tci = 0; + if (hv_rf_find_recvinfo(rndis_pkt, &info)) { + pkt->status = nvsp_status_failure; + device_printf(dev, "recvinfo parsing failed\n"); + return; } - csum_info = hv_get_ppi_data(rndis_pkt, tcpip_chksum_info); - netvsc_recv(chan, pkt, csum_info); + if (info.vlan_info != NULL) + pkt->vlan_tci = info.vlan_info->u1.s1.vlan_id; + else + pkt->vlan_tci = 0; + + netvsc_recv(chan, pkt, info.csum_info, info.hash_info, info.hash_value); } /* From owner-svn-src-stable-10@freebsd.org Tue Jun 21 15:47:56 2016 Return-Path: Delivered-To: svn-src-stable-10@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 4DBF3AC540A; Tue, 21 Jun 2016 15:47:56 +0000 (UTC) (envelope-from pfg@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 1CCC02E44; Tue, 21 Jun 2016 15:47:56 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5LFltdp033908; Tue, 21 Jun 2016 15:47:55 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5LFlsx7033903; Tue, 21 Jun 2016 15:47:54 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201606211547.u5LFlsx7033903@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Tue, 21 Jun 2016 15:47:54 +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: r302061 - in stable/10: share/man/man4 sys/modules/netgraph/mppc sys/net 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 15:47:56 -0000 Author: pfg Date: Tue Jun 21 15:47:54 2016 New Revision: 302061 URL: https://svnweb.freebsd.org/changeset/base/302061 Log: MFC r301549, r301550: ng_mppc(4): Bring netgraph(3) MPPC compression support. Support for compression has been available from July 2007 but it was never imported due to concerns with patents once held by STAC/HiFn. The issues have clearly been resolved so bring it in now. Special thanks to Brett Glass for preserving the code and pointing documentation for the expiration case. Taken from: mav (through Brett Glass) Added: stable/10/sys/net/mppc.h - copied unchanged from r301549, head/sys/net/mppc.h stable/10/sys/net/mppcc.c - copied unchanged from r301549, head/sys/net/mppcc.c stable/10/sys/net/mppcd.c - copied unchanged from r301549, head/sys/net/mppcd.c Modified: stable/10/share/man/man4/ng_mppc.4 stable/10/sys/modules/netgraph/mppc/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/ng_mppc.4 ============================================================================== --- stable/10/share/man/man4/ng_mppc.4 Tue Jun 21 15:38:20 2016 (r302060) +++ stable/10/share/man/man4/ng_mppc.4 Tue Jun 21 15:47:54 2016 (r302061) @@ -35,7 +35,7 @@ .\" $Whistle: ng_mppc.8,v 1.1 1999/12/08 20:20:39 archie Exp $ .\" $FreeBSD$ .\" -.Dd December 8, 1999 +.Dd June 7, 2016 .Dt NG_MPPC 4 .Os .Sh NAME @@ -153,12 +153,6 @@ and are supplied to selectively compile in either or both capabilities. At least one of these must be defined, or else this node type is useless. .Pp -The MPPC protocol requires proprietary compression code available -from Hi/Fn (formerly STAC). -These files must be obtained elsewhere and added to the kernel -sources before this node type will compile with the -.Dv NETGRAPH_MPPC_COMPRESSION -option. .Sh SEE ALSO .Xr netgraph 4 , .Xr ng_ppp 4 , Modified: stable/10/sys/modules/netgraph/mppc/Makefile ============================================================================== --- stable/10/sys/modules/netgraph/mppc/Makefile Tue Jun 21 15:38:20 2016 (r302060) +++ stable/10/sys/modules/netgraph/mppc/Makefile Tue Jun 21 15:47:54 2016 (r302061) @@ -4,11 +4,10 @@ KMOD= ng_mppc SRCS= ng_mppc.c opt_netgraph.h -NETGRAPH_MPPC_COMPRESSION?= 0 +NETGRAPH_MPPC_COMPRESSION?= 1 NETGRAPH_MPPC_ENCRYPTION?= 1 .if ${NETGRAPH_MPPC_COMPRESSION} > 0 -# XXX These files don't exist yet, but hopefully someday they will... .PATH: ${.CURDIR}/../../../net SRCS+= mppcc.c mppcd.c .endif Copied: stable/10/sys/net/mppc.h (from r301549, head/sys/net/mppc.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/net/mppc.h Tue Jun 21 15:47:54 2016 (r302061, copy of r301549, head/sys/net/mppc.h) @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2007 Alexander Motin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * MPPC decompression library. + * Version 1.0 + * + * Note that Hi/Fn (later acquired by Exar Corporation) held US patents + * on some implementation-critical aspects of MPPC compression. + * These patents lapsed due to non-payment of fees in 2007 and by 2015 + * expired altogether. + */ + +#ifndef _NET_MPPC_H_ +#define _NET_MPPC_H_ + +#define MPPC_MANDATORY_COMPRESS_FLAGS 0 +#define MPPC_MANDATORY_DECOMPRESS_FLAGS 0 + +#define MPPC_SAVE_HISTORY 1 + +#define MPPC_OK 5 +#define MPPC_EXPANDED 8 +#define MPPC_RESTART_HISTORY 16 +#define MPPC_DEST_EXHAUSTED 32 + +extern size_t MPPC_SizeOfCompressionHistory(void); +extern size_t MPPC_SizeOfDecompressionHistory(void); + +extern void MPPC_InitCompressionHistory(char *history); +extern void MPPC_InitDecompressionHistory(char *history); + +extern int MPPC_Compress(u_char **src, u_char **dst, u_long *srcCnt, u_long *dstCnt, char *history, int flags, int undef); +extern int MPPC_Decompress(u_char **src, u_char **dst, u_long *srcCnt, u_long *dstCnt, char *history, int flags); + +#endif Copied: stable/10/sys/net/mppcc.c (from r301549, head/sys/net/mppcc.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/net/mppcc.c Tue Jun 21 15:47:54 2016 (r302061, copy of r301549, head/sys/net/mppcc.c) @@ -0,0 +1,299 @@ +/*- + * Copyright (c) 2002-2004 Jan Dubiec + * Copyright (c) 2007 Alexander Motin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * MPPC decompression library. + * Version 1.0 + * + * Note that Hi/Fn (later acquired by Exar Corporation) held US patents + * on some implementation-critical aspects of MPPC compression. + * These patents lapsed due to non-payment of fees in 2007 and by 2015 + * expired altogether. + */ + +#include +#include + +#include + +#define MPPE_HIST_LEN 8192 + +#define HASH(x) (((40543*(((((x)[0]<<4)^(x)[1])<<4)^(x)[2]))>>4) & 0x1fff) + +struct MPPC_comp_state { + uint8_t hist[2*MPPE_HIST_LEN]; + uint16_t histptr; + uint16_t hash[MPPE_HIST_LEN]; +}; + +/* Inserts 1 to 8 bits into the output buffer. */ +static void __inline +putbits8(uint8_t *buf, uint32_t val, const uint32_t n, uint32_t *i, uint32_t *l) +{ + buf += *i; + if (*l >= n) { + *l = (*l) - n; + val <<= *l; + *buf = *buf | (val & 0xff); + if (*l == 0) { + *l = 8; + (*i)++; + *(++buf) = 0; + } + } else { + (*i)++; + *l = 8 - n + (*l); + val <<= *l; + *buf = *buf | ((val >> 8) & 0xff); + *(++buf) = val & 0xff; + } +} + +/* Inserts 9 to 16 bits into the output buffer. */ +static void __inline +putbits16(uint8_t *buf, uint32_t val, const uint32_t n, uint32_t *i, uint32_t *l) +{ + buf += *i; + if (*l >= n - 8) { + (*i)++; + *l = 8 - n + (*l); + val <<= *l; + *buf = *buf | ((val >> 8) & 0xff); + *(++buf) = val & 0xff; + if (*l == 0) { + *l = 8; + (*i)++; + *(++buf) = 0; + } + } else { + (*i)++; (*i)++; + *l = 16 - n + (*l); + val <<= *l; + *buf = *buf | ((val >> 16) & 0xff); + *(++buf) = (val >> 8) & 0xff; + *(++buf) = val & 0xff; + } +} + +/* Inserts 17 to 24 bits into the output buffer. */ +static void __inline +putbits24(uint8_t *buf, uint32_t val, const uint32_t n, uint32_t *i, uint32_t *l) +{ + buf += *i; + if (*l >= n - 16) { + (*i)++; (*i)++; + *l = 16 - n + (*l); + val <<= *l; + *buf = *buf | ((val >> 16) & 0xff); + *(++buf) = (val >> 8) & 0xff; + *(++buf) = val & 0xff; + if (*l == 0) { + *l = 8; + (*i)++; + *(++buf) = 0; + } + } else { + (*i)++; (*i)++; (*i)++; + *l = 24 - n + (*l); + val <<= *l; + *buf = *buf | ((val >> 24) & 0xff); + *(++buf) = (val >> 16) & 0xff; + *(++buf) = (val >> 8) & 0xff; + *(++buf) = val & 0xff; + } +} + +size_t MPPC_SizeOfCompressionHistory(void) +{ + return (sizeof(struct MPPC_comp_state)); +} + +void MPPC_InitCompressionHistory(char *history) +{ + struct MPPC_comp_state *state = (struct MPPC_comp_state*)history; + + bzero(history, sizeof(struct MPPC_comp_state)); + state->histptr = MPPE_HIST_LEN; +} + +int MPPC_Compress(u_char **src, u_char **dst, u_long *srcCnt, u_long *dstCnt, char *history, int flags, int undef) +{ + struct MPPC_comp_state *state = (struct MPPC_comp_state*)history; + uint32_t olen, off, len, idx, i, l; + uint8_t *hist, *sbuf, *p, *q, *r, *s; + int rtn = MPPC_OK; + + /* + * At this point, to avoid possible buffer overflow caused by packet + * expansion during/after compression, we should make sure we have + * space for the worst case. + + * Maximum MPPC packet expansion is 12.5%. This is the worst case when + * all octets in the input buffer are >= 0x80 and we cannot find any + * repeated tokens. + */ + if (*dstCnt < (*srcCnt * 9 / 8 + 2)) { + rtn &= ~MPPC_OK; + return (rtn); + } + + /* We can't compress more then MPPE_HIST_LEN bytes in a call. */ + if (*srcCnt > MPPE_HIST_LEN) { + rtn &= ~MPPC_OK; + return (rtn); + } + + hist = state->hist + MPPE_HIST_LEN; + /* check if there is enough room at the end of the history */ + if (state->histptr + *srcCnt >= 2*MPPE_HIST_LEN) { + rtn |= MPPC_RESTART_HISTORY; + state->histptr = MPPE_HIST_LEN; + memcpy(state->hist, hist, MPPE_HIST_LEN); + } + /* Add packet to the history. */ + sbuf = state->hist + state->histptr; + memcpy(sbuf, *src, *srcCnt); + state->histptr += *srcCnt; + + /* compress data */ + r = sbuf + *srcCnt; + **dst = olen = i = 0; + l = 8; + while (i < *srcCnt - 2) { + s = q = sbuf + i; + + /* Prognose matching position using hash function. */ + idx = HASH(s); + p = hist + state->hash[idx]; + state->hash[idx] = (uint16_t) (s - hist); + if (p > s) /* It was before MPPC_RESTART_HISTORY. */ + p -= MPPE_HIST_LEN; /* Try previous history buffer. */ + off = s - p; + + /* Check our prognosis. */ + if (off > MPPE_HIST_LEN - 1 || off < 1 || *p++ != *s++ || + *p++ != *s++ || *p++ != *s++) { + /* No match found; encode literal byte. */ + if ((*src)[i] < 0x80) { /* literal byte < 0x80 */ + putbits8(*dst, (uint32_t) (*src)[i], 8, &olen, &l); + } else { /* literal byte >= 0x80 */ + putbits16(*dst, (uint32_t) (0x100|((*src)[i]&0x7f)), 9, + &olen, &l); + } + ++i; + continue; + } + + /* Find length of the matching fragment */ +#if defined(__amd64__) || defined(__i386__) + /* Optimization for CPUs without strict data aligning requirements */ + while ((*((uint32_t*)p) == *((uint32_t*)s)) && (s < (r - 3))) { + p+=4; + s+=4; + } +#endif + while((*p++ == *s++) && (s <= r)); + len = s - q - 1; + i += len; + + /* At least 3 character match found; code data. */ + /* Encode offset. */ + if (off < 64) { /* 10-bit offset; 0 <= offset < 64 */ + putbits16(*dst, 0x3c0|off, 10, &olen, &l); + } else if (off < 320) { /* 12-bit offset; 64 <= offset < 320 */ + putbits16(*dst, 0xe00|(off-64), 12, &olen, &l); + } else if (off < 8192) { /* 16-bit offset; 320 <= offset < 8192 */ + putbits16(*dst, 0xc000|(off-320), 16, &olen, &l); + } else { /* NOTREACHED */ + rtn &= ~MPPC_OK; + return rtn; + } + + /* Encode length of match. */ + if (len < 4) { /* length = 3 */ + putbits8(*dst, 0, 1, &olen, &l); + } else if (len < 8) { /* 4 <= length < 8 */ + putbits8(*dst, 0x08|(len&0x03), 4, &olen, &l); + } else if (len < 16) { /* 8 <= length < 16 */ + putbits8(*dst, 0x30|(len&0x07), 6, &olen, &l); + } else if (len < 32) { /* 16 <= length < 32 */ + putbits8(*dst, 0xe0|(len&0x0f), 8, &olen, &l); + } else if (len < 64) { /* 32 <= length < 64 */ + putbits16(*dst, 0x3c0|(len&0x1f), 10, &olen, &l); + } else if (len < 128) { /* 64 <= length < 128 */ + putbits16(*dst, 0xf80|(len&0x3f), 12, &olen, &l); + } else if (len < 256) { /* 128 <= length < 256 */ + putbits16(*dst, 0x3f00|(len&0x7f), 14, &olen, &l); + } else if (len < 512) { /* 256 <= length < 512 */ + putbits16(*dst, 0xfe00|(len&0xff), 16, &olen, &l); + } else if (len < 1024) { /* 512 <= length < 1024 */ + putbits24(*dst, 0x3fc00|(len&0x1ff), 18, &olen, &l); + } else if (len < 2048) { /* 1024 <= length < 2048 */ + putbits24(*dst, 0xff800|(len&0x3ff), 20, &olen, &l); + } else if (len < 4096) { /* 2048 <= length < 4096 */ + putbits24(*dst, 0x3ff000|(len&0x7ff), 22, &olen, &l); + } else if (len < 8192) { /* 4096 <= length < 8192 */ + putbits24(*dst, 0xffe000|(len&0xfff), 24, &olen, &l); + } else { /* NOTREACHED */ + rtn &= ~MPPC_OK; + return (rtn); + } + } + + /* Add remaining octets to the output. */ + while(*srcCnt - i > 0) { + if ((*src)[i] < 0x80) { /* literal byte < 0x80 */ + putbits8(*dst, (uint32_t) (*src)[i++], 8, &olen, &l); + } else { /* literal byte >= 0x80 */ + putbits16(*dst, (uint32_t) (0x100|((*src)[i++]&0x7f)), 9, &olen, + &l); + } + } + + /* Reset unused bits of the last output octet. */ + if ((l != 0) && (l != 8)) { + putbits8(*dst, 0, l, &olen, &l); + } + + /* If result is bigger then original, set flag and flush history. */ + if ((*srcCnt < olen) || ((flags & MPPC_SAVE_HISTORY) == 0)) { + if (*srcCnt < olen) + rtn |= MPPC_EXPANDED; + bzero(history, sizeof(struct MPPC_comp_state)); + state->histptr = MPPE_HIST_LEN; + } + + *src += *srcCnt; + *srcCnt = 0; + *dst += olen; + *dstCnt -= olen; + + return (rtn); +} Copied: stable/10/sys/net/mppcd.c (from r301549, head/sys/net/mppcd.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/net/mppcd.c Tue Jun 21 15:47:54 2016 (r302061, copy of r301549, head/sys/net/mppcd.c) @@ -0,0 +1,284 @@ +/*- + * Copyright (c) 2002-2004 Jan Dubiec + * Copyright (c) 2007 Alexander Motin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * MPPC decompression library. + * Version 1.0 + * + * Note that Hi/Fn (later acquired by Exar Corporation) held US patents + * on some implementation-critical aspects of MPPC compression. + * These patents lapsed due to non-payment of fees in 2007 and by 2015 + * expired altogether. + */ + +#include +#include + +#include + +#define MPPE_HIST_LEN 8192 + +struct MPPC_decomp_state { + uint8_t hist[2*MPPE_HIST_LEN]; + uint16_t histptr; +}; + +static uint32_t __inline +getbits(const uint8_t *buf, const uint32_t n, uint32_t *i, uint32_t *l) +{ + static const uint32_t m[] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; + uint32_t res, ol; + + ol = *l; + if (*l >= n) { + *l = (*l) - n; + res = (buf[*i] & m[ol]) >> (*l); + if (*l == 0) { + *l = 8; + (*i)++; + } + } else { + *l = 8 - n + (*l); + res = (buf[(*i)++] & m[ol]) << 8; + res = (res | buf[*i]) >> (*l); + } + + return (res); +} + +static uint32_t __inline +getbyte(const uint8_t *buf, const uint32_t i, const uint32_t l) +{ + if (l == 8) { + return (buf[i]); + } else { + return ((((buf[i] << 8) | buf[i+1]) >> l) & 0xff); + } +} + +static void __inline +lamecopy(uint8_t *dst, uint8_t *src, uint32_t len) +{ + while (len--) + *dst++ = *src++; +} + +size_t MPPC_SizeOfDecompressionHistory(void) +{ + return (sizeof(struct MPPC_decomp_state)); +} + +void MPPC_InitDecompressionHistory(char *history) +{ + struct MPPC_decomp_state *state = (struct MPPC_decomp_state*)history; + + bzero(history, sizeof(struct MPPC_decomp_state)); + state->histptr = MPPE_HIST_LEN; +} + +int MPPC_Decompress(u_char **src, u_char **dst, u_long *srcCnt, u_long *dstCnt, char *history, int flags) +{ + struct MPPC_decomp_state *state = (struct MPPC_decomp_state*)history; + uint32_t olen, off, len, bits, val, sig, i, l; + uint8_t *hist, *s; + u_char *isrc = *src; + int rtn = MPPC_OK; + + if ((flags & MPPC_RESTART_HISTORY) != 0) { + memcpy(state->hist, state->hist + MPPE_HIST_LEN, MPPE_HIST_LEN); + state->histptr = MPPE_HIST_LEN; + } + + hist = state->hist + state->histptr; + olen = len = i = 0; + l = 8; + bits = *srcCnt * 8; + while (bits >= 8) { + val = getbyte(isrc, i++, l); + if (val < 0x80) { /* literal byte < 0x80 */ + if (state->histptr < 2*MPPE_HIST_LEN) { + /* Copy uncompressed byte to the history. */ + (state->hist)[(state->histptr)++] = (uint8_t) val; + } else { + /* Buffer overflow; drop packet. */ + rtn &= ~MPPC_OK; + return rtn; + } + olen++; + bits -= 8; + continue; + } + + sig = val & 0xc0; + if (sig == 0x80) { /* literal byte >= 0x80 */ + if (state->histptr < 2*MPPE_HIST_LEN) { + /* Copy uncompressed byte to the history. */ + (state->hist)[(state->histptr)++] = + (uint8_t) (0x80|((val&0x3f)<<1)|getbits(isrc, 1 , &i ,&l)); + } else { + /* buffer overflow; drop packet */ + rtn &= ~MPPC_OK; + return (rtn); + } + olen++; + bits -= 9; + continue; + } + + /* Not a literal byte so it must be an (offset,length) pair */ + /* decode offset */ + sig = val & 0xf0; + if (sig == 0xf0) { /* 10-bit offset; 0 <= offset < 64 */ + off = (((val&0x0f)<<2)|getbits(isrc, 2 , &i ,&l)); + bits -= 10; + } else { + if (sig == 0xe0) { /* 12-bit offset; 64 <= offset < 320 */ + off = ((((val&0x0f)<<4)|getbits(isrc, 4 , &i ,&l))+64); + bits -= 12; + } else { + if ((sig&0xe0) == 0xc0) {/* 16-bit offset; 320 <= offset < 8192 */ + off = ((((val&0x1f)<<8)|getbyte(isrc, i++, l))+320); + bits -= 16; + if (off > MPPE_HIST_LEN - 1) { + rtn &= ~MPPC_OK; + return (rtn); + } + } else { /* NOTREACHED */ + rtn &= ~MPPC_OK; + return (rtn); + } + } + } + /* Decode length of match. */ + val = getbyte(isrc, i, l); + if ((val & 0x80) == 0x00) { /* len = 3 */ + len = 3; + bits--; + getbits(isrc, 1 , &i ,&l); + } else if ((val & 0xc0) == 0x80) { /* 4 <= len < 8 */ + len = 0x04 | ((val>>4) & 0x03); + bits -= 4; + getbits(isrc, 4 , &i ,&l); + } else if ((val & 0xe0) == 0xc0) { /* 8 <= len < 16 */ + len = 0x08 | ((val>>2) & 0x07); + bits -= 6; + getbits(isrc, 6 , &i ,&l); + } else if ((val & 0xf0) == 0xe0) { /* 16 <= len < 32 */ + len = 0x10 | (val & 0x0f); + bits -= 8; + i++; + } else { + bits -= 8; + val = (val << 8) | getbyte(isrc, ++i, l); + if ((val & 0xf800) == 0xf000) { /* 32 <= len < 64 */ + len = 0x0020 | ((val >> 6) & 0x001f); + bits -= 2; + getbits(isrc, 2 , &i ,&l); + } else if ((val & 0xfc00) == 0xf800) { /* 64 <= len < 128 */ + len = 0x0040 | ((val >> 4) & 0x003f); + bits -= 4; + getbits(isrc, 4 , &i ,&l); + } else if ((val & 0xfe00) == 0xfc00) { /* 128 <= len < 256 */ + len = 0x0080 | ((val >> 2) & 0x007f); + bits -= 6; + getbits(isrc, 6 , &i ,&l); + } else if ((val & 0xff00) == 0xfe00) { /* 256 <= len < 512 */ + len = 0x0100 | (val & 0x00ff); + bits -= 8; + i++; + } else { + bits -= 8; + val = (val << 8) | getbyte(isrc, ++i, l); + if ((val & 0xff8000) == 0xff0000) { /* 512 <= len < 1024 */ + len = 0x000200 | ((val >> 6) & 0x0001ff); + bits -= 2; + getbits(isrc, 2 , &i ,&l); + } else if ((val & 0xffc000) == 0xff8000) {/* 1024 <= len < 2048 */ + len = 0x000400 | ((val >> 4) & 0x0003ff); + bits -= 4; + getbits(isrc, 4 , &i ,&l); + } else if ((val & 0xffe000) == 0xffc000) {/* 2048 <= len < 4096 */ + len = 0x000800 | ((val >> 2) & 0x0007ff); + bits -= 6; + getbits(isrc, 6 , &i ,&l); + } else if ((val & 0xfff000) == 0xffe000) {/* 4096 <= len < 8192 */ + len = 0x001000 | (val & 0x000fff); + bits -= 8; + i++; + } else { /* NOTREACHED */ + rtn &= ~MPPC_OK; + return (rtn); + } + } + } + + s = state->hist + state->histptr; + state->histptr += len; + olen += len; + if (state->histptr < 2*MPPE_HIST_LEN) { + /* Copy uncompressed bytes to the history. */ + + /* + * In some cases len may be greater than off. It means that memory + * areas pointed by s and s-off overlap. To decode that strange case + * data should be copied exactly by address increasing to make + * some data repeated. + */ + lamecopy(s, s - off, len); + } else { + /* Buffer overflow; drop packet. */ + rtn &= ~MPPC_OK; + return (rtn); + } + } + + /* Do PFC decompression. */ + len = olen; + if ((hist[0] & 0x01) != 0) { + (*dst)[0] = 0; + (*dst)++; + len++; + } + + if (len <= *dstCnt) { + /* Copy uncompressed packet to the output buffer. */ + memcpy(*dst, hist, olen); + } else { + /* Buffer overflow; drop packet. */ + rtn |= MPPC_DEST_EXHAUSTED; + } + + *src += *srcCnt; + *srcCnt = 0; + *dst += len; + *dstCnt -= len; + + return (rtn); +} From owner-svn-src-stable-10@freebsd.org Tue Jun 21 20:13:21 2016 Return-Path: Delivered-To: svn-src-stable-10@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 682CFAC595E; Tue, 21 Jun 2016 20:13:21 +0000 (UTC) (envelope-from bdrewery@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 16B702D28; Tue, 21 Jun 2016 20:13:21 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5LKDKCA034488; Tue, 21 Jun 2016 20:13:20 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5LKDK15034484; Tue, 21 Jun 2016 20:13:20 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201606212013.u5LKDK15034484@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 21 Jun 2016 20:13:20 +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: r302066 - in stable/10: share/man/man4 sys/dev/filemon sys/kern sys/sys 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 20:13:21 -0000 Author: bdrewery Date: Tue Jun 21 20:13:19 2016 New Revision: 302066 URL: https://svnweb.freebsd.org/changeset/base/302066 Log: MFC r297156,r297157,r297158,r297159,r297161,r297172,r297200,r297201,r297202, r297203,r297256: r297156: Track filemon usage via a proc.p_filemon pointer rather than its own lists. r297157: Stop tracking stat(2). r297158: Consolidate open(2) and openat(2) code. r297159: Use curthread for vn_fullpath. r297161: Attempt to use the namecache for openat(2) path resolution. r297172: Consolidate common link(2) logic. r297200: Follow-up r297156: Close the log in filemon_dtr rather than in the last reference. r297201: Return any log write failure encountered when closing the filemon fd. r297202: Remove unused done argument to copyinstr(9). r297203: Handle copyin failures. r297256: Remove unneeded return left from refactoring. Relnotes: yes (filemon stability/performance updates) Sponsored by: EMC / Isilon Storage Division Deleted: stable/10/sys/dev/filemon/filemon_lock.c Modified: stable/10/share/man/man4/filemon.4 stable/10/sys/dev/filemon/filemon.c stable/10/sys/dev/filemon/filemon_wrapper.c stable/10/sys/kern/kern_fork.c stable/10/sys/sys/param.h stable/10/sys/sys/proc.h Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/filemon.4 ============================================================================== --- stable/10/share/man/man4/filemon.4 Tue Jun 21 18:16:45 2016 (r302065) +++ stable/10/share/man/man4/filemon.4 Tue Jun 21 20:13:19 2016 (r302066) @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 9, 2016 +.Dd June 21, 2016 .Dt FILEMON 4 .Os .Sh NAME @@ -83,8 +83,6 @@ System calls are denoted using the follo .It Ql R .Xr open 2 for read -.It Ql S -.Xr stat 2 .It Ql W .Xr open 2 for write @@ -116,6 +114,10 @@ Each takes a single argument. Write the internal tracing buffer to the supplied open file descriptor. .It Dv FILEMON_SET_PID Child process ID to trace. +This should normally be done under the control of a parent in the child after +.Xr fork 2 +but before anything else. +See the example below. .El .Sh RETURN VALUES .\" .Rv -std ioctl @@ -138,6 +140,35 @@ The .Nm handle is already associated with a file descriptor. .El +.Pp +The +.Fn ioctl +system call +with +.Dv FILEMON_SET_PID +will fail if: +.Bl -tag -width Er +.It Bq Er ESRCH +No process having the specified process ID exists. +.It Bq Er EBUSY +The process ID specified is already being traced and was not the current +process. +.El +.Pp +The +.Fn close +system call on the filemon file descriptor may fail with the errors from +.Xr write 2 +if any error is encountered while writing the log. +It may also fail if: +.Bl -tag -width Er +.It Bq Er EFAULT +An invalid address was used for a traced system call argument, resulting in +no log entry for the system call. +.It Bq Er ENAMETOOLONG +An argument for a traced system call was too long, resulting in +no log entry for the system call. +.El .Sh FILES .Bl -tag -width ".Pa /dev/filemon" .It Pa /dev/filemon @@ -198,14 +229,5 @@ A device appeared in .Fx 9.1 . .Sh BUGS -Loading -.Nm -may reduce system performance for the noted syscalls. -.Pp -Only children of the set process are logged. -Processes can escape being traced by double forking. -This is not seen as a problem as the intended use is build monitoring, which -does not make sense to have daemons for. -.Pp Unloading the module may panic the system, thus requires using .Ic kldunload -f . Modified: stable/10/sys/dev/filemon/filemon.c ============================================================================== --- stable/10/sys/dev/filemon/filemon.c Tue Jun 21 18:16:45 2016 (r302065) +++ stable/10/sys/dev/filemon/filemon.c Tue Jun 21 20:13:19 2016 (r302066) @@ -1,7 +1,7 @@ /*- * Copyright (c) 2011, David E. O'Brien. * Copyright (c) 2009-2011, Juniper Networks, Inc. - * Copyright (c) 2015, EMC Corp. + * Copyright (c) 2015-2016, EMC Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -80,23 +79,112 @@ static struct cdevsw filemon_cdevsw = { MALLOC_DECLARE(M_FILEMON); MALLOC_DEFINE(M_FILEMON, "filemon", "File access monitor"); +/* + * The filemon->lock protects several things currently: + * - fname1/fname2/msgbufr are pre-allocated and used per syscall + * for logging and copyins rather than stack variables. + * - Serializing the filemon's log output. + * - Preventing inheritance or removal of the filemon into proc.p_filemon. + */ struct filemon { - TAILQ_ENTRY(filemon) link; /* Link into the in-use list. */ - struct sx lock; /* Lock mutex for this filemon. */ + struct sx lock; /* Lock for this filemon. */ struct file *fp; /* Output file pointer. */ - struct proc *p; /* The process being monitored. */ char fname1[MAXPATHLEN]; /* Temporary filename buffer. */ char fname2[MAXPATHLEN]; /* Temporary filename buffer. */ char msgbufr[1024]; /* Output message buffer. */ + int error; /* Log write error, returned on close(2). */ + u_int refcnt; /* Pointer reference count. */ + u_int proccnt; /* Process count. */ }; -static TAILQ_HEAD(, filemon) filemons_inuse = TAILQ_HEAD_INITIALIZER(filemons_inuse); -static TAILQ_HEAD(, filemon) filemons_free = TAILQ_HEAD_INITIALIZER(filemons_free); -static struct sx access_lock; - static struct cdev *filemon_dev; +static void filemon_output(struct filemon *filemon, char *msg, size_t len); + +static __inline struct filemon * +filemon_acquire(struct filemon *filemon) +{ + + if (filemon != NULL) + refcount_acquire(&filemon->refcnt); + return (filemon); +} + +/* + * Release a reference and free on the last one. + */ +static void +filemon_release(struct filemon *filemon) +{ + + if (refcount_release(&filemon->refcnt) == 0) + return; + /* + * There are valid cases of releasing while locked, such as in + * filemon_untrack_processes, but none which are done where there + * is not at least 1 reference remaining. + */ + sx_assert(&filemon->lock, SA_UNLOCKED); + + sx_destroy(&filemon->lock); + free(filemon, M_FILEMON); +} + +/* + * Acquire the proc's p_filemon reference and lock the filemon. + * The proc's p_filemon may not match this filemon on return. + */ +static struct filemon * +filemon_proc_get(struct proc *p) +{ + struct filemon *filemon; + + PROC_LOCK(p); + filemon = filemon_acquire(p->p_filemon); + PROC_UNLOCK(p); + + if (filemon == NULL) + return (NULL); + /* + * The p->p_filemon may have changed by now. That case is handled + * by the exit and fork hooks and filemon_attach_proc specially. + */ + sx_xlock(&filemon->lock); + return (filemon); +} + +/* Remove and release the filemon on the given process. */ +static void +filemon_proc_drop(struct proc *p) +{ + struct filemon *filemon; + + KASSERT(p->p_filemon != NULL, ("%s: proc %p NULL p_filemon", + __func__, p)); + sx_assert(&p->p_filemon->lock, SA_XLOCKED); + PROC_LOCK(p); + filemon = p->p_filemon; + p->p_filemon = NULL; + --filemon->proccnt; + PROC_UNLOCK(p); + /* + * This should not be the last reference yet. filemon_release() + * cannot be called with filemon locked, which the caller expects + * will stay locked. + */ + KASSERT(filemon->refcnt > 1, ("%s: proc %p dropping filemon %p " + "with last reference", __func__, p, filemon)); + filemon_release(filemon); +} + +/* Unlock and release the filemon. */ +static __inline void +filemon_drop(struct filemon *filemon) +{ + + sx_xunlock(&filemon->lock); + filemon_release(filemon); +} -#include "filemon_lock.c" #include "filemon_wrapper.c" static void @@ -115,35 +203,151 @@ filemon_comment(struct filemon *filemon) filemon_output(filemon, filemon->msgbufr, len); } +/* + * Invalidate the passed filemon in all processes. + */ static void -filemon_dtr(void *data) +filemon_untrack_processes(struct filemon *filemon) { - struct filemon *filemon = data; + struct proc *p; - if (filemon != NULL) { - struct file *fp; + sx_assert(&filemon->lock, SA_XLOCKED); - /* Follow same locking order as filemon_pid_check. */ - filemon_lock_write(); - sx_xlock(&filemon->lock); + /* Avoid allproc loop if there is no need. */ + if (filemon->proccnt == 0) + return; + + /* + * Processes in this list won't go away while here since + * filemon_event_process_exit() will lock on filemon->lock + * which we hold. + */ + sx_slock(&allproc_lock); + FOREACH_PROC_IN_SYSTEM(p) { + /* + * No PROC_LOCK is needed to compare here since it is + * guaranteed to not change since we have its filemon + * locked. Everything that changes this p_filemon will + * be locked on it. + */ + if (p->p_filemon == filemon) + filemon_proc_drop(p); + } + sx_sunlock(&allproc_lock); + + /* + * It's possible some references were acquired but will be + * dropped shortly as they are restricted from being + * inherited. There is at least the reference in cdevpriv remaining. + */ + KASSERT(filemon->refcnt > 0, ("%s: filemon %p should have " + "references still.", __func__, filemon)); + KASSERT(filemon->proccnt == 0, ("%s: filemon %p should not have " + "attached procs still.", __func__, filemon)); +} - /* Remove from the in-use list. */ - TAILQ_REMOVE(&filemons_inuse, filemon, link); +/* + * Close out the log. + */ +static void +filemon_close_log(struct filemon *filemon) +{ + struct file *fp; + struct timeval now; + size_t len; - fp = filemon->fp; - filemon->fp = NULL; - filemon->p = NULL; + sx_assert(&filemon->lock, SA_XLOCKED); + if (filemon->fp == NULL) + return; - /* Add to the free list. */ - TAILQ_INSERT_TAIL(&filemons_free, filemon, link); + getmicrotime(&now); - /* Give up write access. */ - sx_xunlock(&filemon->lock); - filemon_unlock_write(); + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), + "# Stop %ju.%06ju\n# Bye bye\n", + (uintmax_t)now.tv_sec, (uintmax_t)now.tv_usec); + + filemon_output(filemon, filemon->msgbufr, len); + fp = filemon->fp; + filemon->fp = NULL; + + sx_xunlock(&filemon->lock); + fdrop(fp, curthread); + sx_xlock(&filemon->lock); +} - if (fp != NULL) - fdrop(fp, curthread); +/* + * The devfs file is being closed. Untrace all processes. It is possible + * filemon_close/close(2) was not called. + */ +static void +filemon_dtr(void *data) +{ + struct filemon *filemon = data; + + if (filemon == NULL) + return; + + sx_xlock(&filemon->lock); + /* + * Detach the filemon. It cannot be inherited after this. + */ + filemon_untrack_processes(filemon); + filemon_close_log(filemon); + filemon_drop(filemon); +} + +/* Attach the filemon to the process. */ +static int +filemon_attach_proc(struct filemon *filemon, struct proc *p) +{ + struct filemon *filemon2; + + sx_assert(&filemon->lock, SA_XLOCKED); + PROC_LOCK_ASSERT(p, MA_OWNED); + KASSERT((p->p_flag & P_WEXIT) == 0, + ("%s: filemon %p attaching to exiting process %p", + __func__, filemon, p)); + + if (p->p_filemon == filemon) + return (0); + /* + * Don't allow truncating other process traces. It is + * not really intended to trace procs other than curproc + * anyhow. + */ + if (p->p_filemon != NULL && p != curproc) + return (EBUSY); + /* + * Historic behavior of filemon has been to let a child initiate + * tracing on itself and cease existing tracing. Bmake + * .META + .MAKE relies on this. It is only relevant for attaching to + * curproc. + */ + while (p->p_filemon != NULL) { + PROC_UNLOCK(p); + sx_xunlock(&filemon->lock); + while ((filemon2 = filemon_proc_get(p)) != NULL) { + /* It may have changed. */ + if (p->p_filemon == filemon2) + filemon_proc_drop(p); + filemon_drop(filemon2); + } + sx_xlock(&filemon->lock); + PROC_LOCK(p); + /* + * It may have been attached to, though unlikely. + * Try again if needed. + */ } + + KASSERT(p->p_filemon == NULL, + ("%s: proc %p didn't detach filemon %p", __func__, p, + p->p_filemon)); + p->p_filemon = filemon_acquire(filemon); + ++filemon->proccnt; + + return (0); } static int @@ -178,10 +382,16 @@ filemon_ioctl(struct cdev *dev, u_long c /* Set the monitored process ID. */ case FILEMON_SET_PID: + /* Invalidate any existing processes already set. */ + filemon_untrack_processes(filemon); + error = pget(*((pid_t *)data), PGET_CANDEBUG | PGET_NOTWEXIT, &p); if (error == 0) { - filemon->p = p; + KASSERT(p->p_filemon != filemon, + ("%s: proc %p didn't untrack filemon %p", + __func__, p, filemon)); + error = filemon_attach_proc(filemon, p); PROC_UNLOCK(p); } break; @@ -199,49 +409,48 @@ static int filemon_open(struct cdev *dev, int oflags __unused, int devtype __unused, struct thread *td __unused) { + int error; struct filemon *filemon; - /* Get exclusive write access. */ - filemon_lock_write(); - - if ((filemon = TAILQ_FIRST(&filemons_free)) != NULL) - TAILQ_REMOVE(&filemons_free, filemon, link); - - /* Give up write access. */ - filemon_unlock_write(); - - if (filemon == NULL) { - filemon = malloc(sizeof(struct filemon), M_FILEMON, - M_WAITOK | M_ZERO); - sx_init(&filemon->lock, "filemon"); - } - - devfs_set_cdevpriv(filemon, filemon_dtr); + filemon = malloc(sizeof(*filemon), M_FILEMON, + M_WAITOK | M_ZERO); + sx_init(&filemon->lock, "filemon"); + refcount_init(&filemon->refcnt, 1); + + error = devfs_set_cdevpriv(filemon, filemon_dtr); + if (error != 0) + filemon_release(filemon); - /* Get exclusive write access. */ - filemon_lock_write(); - - /* Add to the in-use list. */ - TAILQ_INSERT_TAIL(&filemons_inuse, filemon, link); - - /* Give up write access. */ - filemon_unlock_write(); - - return (0); + return (error); } +/* Called on close of last devfs file handle, before filemon_dtr(). */ static int filemon_close(struct cdev *dev __unused, int flag __unused, int fmt __unused, struct thread *td __unused) { + struct filemon *filemon; + int error; - return (0); + if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0) + return (error); + + sx_xlock(&filemon->lock); + filemon_close_log(filemon); + error = filemon->error; + sx_xunlock(&filemon->lock); + /* + * Processes are still being traced but won't log anything + * now. After this call returns filemon_dtr() is called which + * will detach processes. + */ + + return (error); } static void filemon_load(void *dummy __unused) { - sx_init(&access_lock, "filemons_inuse"); /* Install the syscall wrappers. */ filemon_wrapper_install(); @@ -253,38 +462,11 @@ filemon_load(void *dummy __unused) static int filemon_unload(void) { - struct filemon *filemon; - int error = 0; - - /* Get exclusive write access. */ - filemon_lock_write(); - - if (TAILQ_FIRST(&filemons_inuse) != NULL) - error = EBUSY; - else { - destroy_dev(filemon_dev); - - /* Deinstall the syscall wrappers. */ - filemon_wrapper_deinstall(); - } - /* Give up write access. */ - filemon_unlock_write(); + destroy_dev(filemon_dev); + filemon_wrapper_deinstall(); - if (error == 0) { - /* free() filemon structs free list. */ - filemon_lock_write(); - while ((filemon = TAILQ_FIRST(&filemons_free)) != NULL) { - TAILQ_REMOVE(&filemons_free, filemon, link); - sx_destroy(&filemon->lock); - free(filemon, M_FILEMON); - } - filemon_unlock_write(); - - sx_destroy(&access_lock); - } - - return (error); + return (0); } static int Modified: stable/10/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- stable/10/sys/dev/filemon/filemon_wrapper.c Tue Jun 21 18:16:45 2016 (r302065) +++ stable/10/sys/dev/filemon/filemon_wrapper.c Tue Jun 21 20:13:19 2016 (r302066) @@ -1,7 +1,7 @@ /*- * Copyright (c) 2011, David E. O'Brien. * Copyright (c) 2009-2011, Juniper Networks, Inc. - * Copyright (c) 2015, EMC Corp. + * Copyright (c) 2015-2016, EMC Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,8 +29,9 @@ #include __FBSDID("$FreeBSD$"); -#include #include +#include +#include #include #include @@ -45,6 +46,7 @@ filemon_output(struct filemon *filemon, { struct uio auio; struct iovec aiov; + int error; if (filemon->fp == NULL) return; @@ -62,56 +64,33 @@ filemon_output(struct filemon *filemon, if (filemon->fp->f_type == DTYPE_VNODE) bwillwrite(); - fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); -} - -static struct filemon * -filemon_pid_check(struct proc *p) -{ - struct filemon *filemon; - - filemon_lock_read(); - if (TAILQ_EMPTY(&filemons_inuse)) { - filemon_unlock_read(); - return (NULL); - } - sx_slock(&proctree_lock); - while (p->p_pid != 0) { - TAILQ_FOREACH(filemon, &filemons_inuse, link) { - if (p == filemon->p) { - sx_sunlock(&proctree_lock); - sx_xlock(&filemon->lock); - filemon_unlock_read(); - return (filemon); - } - } - p = proc_realparent(p); - } - sx_sunlock(&proctree_lock); - filemon_unlock_read(); - return (NULL); + error = fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); + if (error != 0) + filemon->error = error; } static int filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap) { - int ret; - size_t done; + int error, ret; size_t len; struct filemon *filemon; if ((ret = sys_chdir(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), &done); + if ((filemon = filemon_proc_get(curproc)) != NULL) { + if ((error = copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) { + filemon->error = error; + goto copyfail; + } len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "C %d %s\n", curproc->p_pid, filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - - sx_xunlock(&filemon->lock); +copyfail: + filemon_drop(filemon); } } @@ -126,12 +105,11 @@ filemon_event_process_exec(void *arg __u char *fullpath, *freepath; size_t len; - if ((filemon = filemon_pid_check(p)) != NULL) { + if ((filemon = filemon_proc_get(p)) != NULL) { fullpath = ""; freepath = NULL; - vn_fullpath(FIRST_THREAD_IN_PROC(p), imgp->vp, &fullpath, - &freepath); + vn_fullpath(curthread, imgp->vp, &fullpath, &freepath); len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "E %d %s\n", @@ -139,321 +117,244 @@ filemon_event_process_exec(void *arg __u filemon_output(filemon, filemon->msgbufr, len); - sx_xunlock(&filemon->lock); + filemon_drop(filemon); free(freepath, M_TEMP); } } -static int -filemon_wrapper_open(struct thread *td, struct open_args *uap) +static void +_filemon_wrapper_openat(struct thread *td, char *upath, int flags, int fd) { - int ret; - size_t done; + int error; size_t len; + struct file *fp; struct filemon *filemon; + char *atpath, *freepath; + cap_rights_t rights; - if ((ret = sys_open(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), &done); - - if (uap->flags & O_RDWR) { - /* - * We'll get the W record below, but need - * to also output an R to distingish from - * O_WRONLY. - */ - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "R %d %s\n", - curproc->p_pid, filemon->fname1); - filemon_output(filemon, filemon->msgbufr, len); - } - + if ((filemon = filemon_proc_get(curproc)) != NULL) { + atpath = ""; + freepath = NULL; + fp = NULL; + if ((error = copyinstr(upath, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) { + filemon->error = error; + goto copyfail; + } + + if (filemon->fname1[0] != '/' && fd != AT_FDCWD) { + /* + * rats - we cannot do too much about this. + * the trace should show a dir we read + * recently.. output an A record as a clue + * until we can do better. + * XXX: This may be able to come out with + * the namecache lookup now. + */ len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "%c %d %s\n", - (uap->flags & O_ACCMODE) ? 'W':'R', + sizeof(filemon->msgbufr), "A %d %s\n", curproc->p_pid, filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - - sx_xunlock(&filemon->lock); + /* + * Try to resolve the path from the vnode using the + * namecache. It may be inaccurate, but better + * than nothing. + */ + if (getvnode(td->td_proc->p_fd, fd, + cap_rights_init(&rights, CAP_LOOKUP), &fp) == 0) { + vn_fullpath(td, fp->f_vnode, &atpath, + &freepath); + } + } + if (flags & O_RDWR) { + /* + * We'll get the W record below, but need + * to also output an R to distinguish from + * O_WRONLY. + */ + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "R %d %s%s%s\n", + curproc->p_pid, atpath, + atpath[0] != '\0' ? "/" : "", filemon->fname1); + filemon_output(filemon, filemon->msgbufr, len); } - } - return (ret); + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "%c %d %s%s%s\n", + (flags & O_ACCMODE) ? 'W':'R', + curproc->p_pid, atpath, + atpath[0] != '\0' ? "/" : "", filemon->fname1); + filemon_output(filemon, filemon->msgbufr, len); +copyfail: + filemon_drop(filemon); + if (fp != NULL) + fdrop(fp, td); + free(freepath, M_TEMP); + } } static int -filemon_wrapper_openat(struct thread *td, struct openat_args *uap) +filemon_wrapper_open(struct thread *td, struct open_args *uap) { int ret; - size_t done; - size_t len; - struct filemon *filemon; - - if ((ret = sys_openat(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), &done); - - filemon->fname2[0] = '\0'; - if (filemon->fname1[0] != '/' && uap->fd != AT_FDCWD) { - /* - * rats - we cannot do too much about this. - * the trace should show a dir we read - * recently.. output an A record as a clue - * until we can do better. - */ - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "A %d %s\n", - curproc->p_pid, filemon->fname1); - filemon_output(filemon, filemon->msgbufr, len); - } - if (uap->flag & O_RDWR) { - /* - * We'll get the W record below, but need - * to also output an R to distingish from - * O_WRONLY. - */ - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "R %d %s%s\n", - curproc->p_pid, filemon->fname2, filemon->fname1); - filemon_output(filemon, filemon->msgbufr, len); - } - - - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "%c %d %s%s\n", - (uap->flag & O_ACCMODE) ? 'W':'R', - curproc->p_pid, filemon->fname2, filemon->fname1); - filemon_output(filemon, filemon->msgbufr, len); - sx_xunlock(&filemon->lock); - } - } + if ((ret = sys_open(td, uap)) == 0) + _filemon_wrapper_openat(td, uap->path, uap->flags, AT_FDCWD); return (ret); } static int -filemon_wrapper_rename(struct thread *td, struct rename_args *uap) +filemon_wrapper_openat(struct thread *td, struct openat_args *uap) { int ret; - size_t done; - size_t len; - struct filemon *filemon; - if ((ret = sys_rename(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->from, filemon->fname1, - sizeof(filemon->fname1), &done); - copyinstr(uap->to, filemon->fname2, - sizeof(filemon->fname2), &done); - - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "M %d '%s' '%s'\n", - curproc->p_pid, filemon->fname1, filemon->fname2); - - filemon_output(filemon, filemon->msgbufr, len); - - sx_xunlock(&filemon->lock); - } - } + if ((ret = sys_openat(td, uap)) == 0) + _filemon_wrapper_openat(td, uap->path, uap->flag, uap->fd); return (ret); } static int -filemon_wrapper_link(struct thread *td, struct link_args *uap) +filemon_wrapper_rename(struct thread *td, struct rename_args *uap) { - int ret; - size_t done; + int error, ret; size_t len; struct filemon *filemon; - if ((ret = sys_link(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), &done); - copyinstr(uap->link, filemon->fname2, - sizeof(filemon->fname2), &done); + if ((ret = sys_rename(td, uap)) == 0) { + if ((filemon = filemon_proc_get(curproc)) != NULL) { + if (((error = copyinstr(uap->from, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) || + ((error = copyinstr(uap->to, filemon->fname2, + sizeof(filemon->fname2), NULL)) != 0)) { + filemon->error = error; + goto copyfail; + } len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "L %d '%s' '%s'\n", + sizeof(filemon->msgbufr), "M %d '%s' '%s'\n", curproc->p_pid, filemon->fname1, filemon->fname2); filemon_output(filemon, filemon->msgbufr, len); - - sx_xunlock(&filemon->lock); +copyfail: + filemon_drop(filemon); } } return (ret); } -static int -filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap) +static void +_filemon_wrapper_link(struct thread *td, char *upath1, char *upath2) { - int ret; - size_t done; - size_t len; struct filemon *filemon; + size_t len; + int error; - if ((ret = sys_symlink(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), &done); - copyinstr(uap->link, filemon->fname2, - sizeof(filemon->fname2), &done); - - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "L %d '%s' '%s'\n", - curproc->p_pid, filemon->fname1, filemon->fname2); + if ((filemon = filemon_proc_get(curproc)) != NULL) { + if (((error = copyinstr(upath1, filemon->fname1, + sizeof(filemon->fname1), NULL)) != 0) || + ((error = copyinstr(upath2, filemon->fname2, + sizeof(filemon->fname2), NULL)) != 0)) { + filemon->error = error; + goto copyfail; + } - filemon_output(filemon, filemon->msgbufr, len); + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "L %d '%s' '%s'\n", + curproc->p_pid, filemon->fname1, filemon->fname2); - sx_xunlock(&filemon->lock); - } + filemon_output(filemon, filemon->msgbufr, len); +copyfail: + filemon_drop(filemon); } - - return (ret); } static int -filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap) +filemon_wrapper_link(struct thread *td, struct link_args *uap) { int ret; - size_t done; - size_t len; - struct filemon *filemon; - - if ((ret = sys_linkat(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path1, filemon->fname1, - sizeof(filemon->fname1), &done); - copyinstr(uap->path2, filemon->fname2, - sizeof(filemon->fname2), &done); - - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "L %d '%s' '%s'\n", - curproc->p_pid, filemon->fname1, filemon->fname2); - - filemon_output(filemon, filemon->msgbufr, len); - sx_xunlock(&filemon->lock); - } - } + if ((ret = sys_link(td, uap)) == 0) + _filemon_wrapper_link(td, uap->path, uap->link); return (ret); } static int -filemon_wrapper_stat(struct thread *td, struct stat_args *uap) +filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap) { int ret; - size_t done; - size_t len; - struct filemon *filemon; - if ((ret = sys_stat(td, uap)) == 0) { - if ((filemon = filemon_pid_check(curproc)) != NULL) { - copyinstr(uap->path, filemon->fname1, - sizeof(filemon->fname1), &done); - - len = snprintf(filemon->msgbufr, - sizeof(filemon->msgbufr), "S %d %s\n", - curproc->p_pid, filemon->fname1); - - filemon_output(filemon, filemon->msgbufr, len); - - sx_xunlock(&filemon->lock); - } - } + if ((ret = sys_symlink(td, uap)) == 0) + _filemon_wrapper_link(td, uap->path, uap->link); return (ret); } -#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32) static int -filemon_wrapper_freebsd32_stat(struct thread *td, - struct freebsd32_stat_args *uap) +filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap) { int ret; - size_t done; - size_t len; - struct filemon *filemon; - - if ((ret = freebsd32_stat(td, uap)) == 0) { *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-10@freebsd.org Tue Jun 21 20:15:31 2016 Return-Path: Delivered-To: svn-src-stable-10@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 B4908AC5A5E; Tue, 21 Jun 2016 20:15:31 +0000 (UTC) (envelope-from bdrewery@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 8576D2FE7; Tue, 21 Jun 2016 20:15:31 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5LKFUJH034654; Tue, 21 Jun 2016 20:15:30 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5LKFU1g034653; Tue, 21 Jun 2016 20:15:30 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201606212015.u5LKFU1g034653@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 21 Jun 2016 20:15:30 +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: r302068 - stable/10/share/man/man4 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 20:15:31 -0000 Author: bdrewery Date: Tue Jun 21 20:15:30 2016 New Revision: 302068 URL: https://svnweb.freebsd.org/changeset/base/302068 Log: MFC r271049: Note that script(1) consumes filemon(4). Modified: stable/10/share/man/man4/filemon.4 Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/filemon.4 ============================================================================== --- stable/10/share/man/man4/filemon.4 Tue Jun 21 20:14:32 2016 (r302067) +++ stable/10/share/man/man4/filemon.4 Tue Jun 21 20:15:30 2016 (r302068) @@ -221,6 +221,7 @@ buffer contents to it. .Sh SEE ALSO .Xr dtrace 1 , .Xr ktrace 1 , +.Xr script 1 , .Xr truss 1 , .Xr ioctl 2 .Sh HISTORY From owner-svn-src-stable-10@freebsd.org Tue Jun 21 20:20:31 2016 Return-Path: Delivered-To: svn-src-stable-10@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 6E397AC5BAC; Tue, 21 Jun 2016 20:20:31 +0000 (UTC) (envelope-from bdrewery@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 3EBEB1670; Tue, 21 Jun 2016 20:20:31 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5LKKU42035037; Tue, 21 Jun 2016 20:20:30 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5LKKUcx035036; Tue, 21 Jun 2016 20:20:30 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201606212020.u5LKKUcx035036@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 21 Jun 2016 20:20:30 +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: r302070 - stable/10/share/man/man4 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 20:20:31 -0000 Author: bdrewery Date: Tue Jun 21 20:20:30 2016 New Revision: 302070 URL: https://svnweb.freebsd.org/changeset/base/302070 Log: MFC r297160,r297196: r297160: Document openat(2) behavior. r297196: Spell out 'system calls'. Modified: stable/10/share/man/man4/filemon.4 Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/filemon.4 ============================================================================== --- stable/10/share/man/man4/filemon.4 Tue Jun 21 20:18:19 2016 (r302069) +++ stable/10/share/man/man4/filemon.4 Tue Jun 21 20:20:30 2016 (r302070) @@ -51,7 +51,7 @@ calls. .Pp .Nm is not intended to be a security auditing tool. -Many syscalls are not tracked and binaries of foreign ABI will not be fully +Many system calls are not tracked and binaries of foreign ABI will not be fully audited. It is intended for auditing of processes for the purpose of determining its dependencies in an efficient and easily parsable format. @@ -64,6 +64,9 @@ to handle incremental builds more smartl System calls are denoted using the following single letters: .Pp .Bl -tag -width indent -compact +.It Ql A +.Xr openat 2 . +The next log entry may be lacking an absolute path or be inaccurate. .It Ql C .Xr chdir 2 .It Ql D @@ -82,9 +85,13 @@ System calls are denoted using the follo .Xr rename 2 .It Ql R .Xr open 2 +or +.Xr openat 2 for read .It Ql W .Xr open 2 +or +.Xr openat 2 for write .It Ql X .Xr _exit 2 From owner-svn-src-stable-10@freebsd.org Tue Jun 21 20:32:35 2016 Return-Path: Delivered-To: svn-src-stable-10@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 9748AAC5154; Tue, 21 Jun 2016 20:32:35 +0000 (UTC) (envelope-from bdrewery@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 7302E250D; Tue, 21 Jun 2016 20:32:35 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5LKWYld042591; Tue, 21 Jun 2016 20:32:34 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5LKWYCF042588; Tue, 21 Jun 2016 20:32:34 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201606212032.u5LKWYCF042588@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 21 Jun 2016 20:32:34 +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: r302072 - in stable/10/sys: dev/filemon modules 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2016 20:32:35 -0000 Author: bdrewery Date: Tue Jun 21 20:32:34 2016 New Revision: 302072 URL: https://svnweb.freebsd.org/changeset/base/302072 Log: MFC r300892,r300893,r301130,r301404,r301414,r301460: r300892: Rename function to be less generic. r300893: Don't truncate existing error when writing the log. r301130: Enable filemon on all architectures. r301404: Support all architectures by just using sysent. r301414: Fix build after r301404. r301460: Cleanup COMPAT_FREEBSD32 support. Modified: stable/10/sys/dev/filemon/filemon.c stable/10/sys/dev/filemon/filemon_wrapper.c stable/10/sys/modules/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/filemon/filemon.c ============================================================================== --- stable/10/sys/dev/filemon/filemon.c Tue Jun 21 20:28:30 2016 (r302071) +++ stable/10/sys/dev/filemon/filemon.c Tue Jun 21 20:32:34 2016 (r302072) @@ -54,16 +54,12 @@ __FBSDID("$FreeBSD$"); #include "filemon.h" -#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32) +#if defined(COMPAT_FREEBSD32) #include #include - -extern struct sysentvec ia32_freebsd_sysvec; +#include #endif -extern struct sysentvec elf32_freebsd_sysvec; -extern struct sysentvec elf64_freebsd_sysvec; - static d_close_t filemon_close; static d_ioctl_t filemon_ioctl; static d_open_t filemon_open; @@ -188,7 +184,7 @@ filemon_drop(struct filemon *filemon) #include "filemon_wrapper.c" static void -filemon_comment(struct filemon *filemon) +filemon_write_header(struct filemon *filemon) { int len; struct timeval now; @@ -377,7 +373,7 @@ filemon_ioctl(struct cdev *dev, u_long c &filemon->fp); if (error == 0) /* Write the file header. */ - filemon_comment(filemon); + filemon_write_header(filemon); break; /* Set the monitored process ID. */ Modified: stable/10/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- stable/10/sys/dev/filemon/filemon_wrapper.c Tue Jun 21 20:28:30 2016 (r302071) +++ stable/10/sys/dev/filemon/filemon_wrapper.c Tue Jun 21 20:32:34 2016 (r302072) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include "opt_compat.h" @@ -65,7 +66,7 @@ filemon_output(struct filemon *filemon, bwillwrite(); error = fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); - if (error != 0) + if (error != 0 && filemon->error == 0) filemon->error = error; } @@ -402,33 +403,26 @@ filemon_event_process_fork(void *arg __u static void filemon_wrapper_install(void) { -#if defined(__LP64__) - struct sysent *sv_table = elf64_freebsd_sysvec.sv_table; -#else - struct sysent *sv_table = elf32_freebsd_sysvec.sv_table; -#endif - - sv_table[SYS_chdir].sy_call = (sy_call_t *) filemon_wrapper_chdir; - sv_table[SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open; - sv_table[SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat; - sv_table[SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename; - sv_table[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink; - sv_table[SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link; - sv_table[SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink; - sv_table[SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat; - -#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32) - sv_table = ia32_freebsd_sysvec.sv_table; - - sv_table[FREEBSD32_SYS_chdir].sy_call = (sy_call_t *) filemon_wrapper_chdir; - sv_table[FREEBSD32_SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open; - sv_table[FREEBSD32_SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat; - sv_table[FREEBSD32_SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename; - sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink; - sv_table[FREEBSD32_SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link; - sv_table[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink; - sv_table[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat; -#endif /* COMPAT_ARCH32 */ + + sysent[SYS_chdir].sy_call = (sy_call_t *) filemon_wrapper_chdir; + sysent[SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open; + sysent[SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat; + sysent[SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename; + sysent[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink; + sysent[SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link; + sysent[SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink; + sysent[SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat; + +#if defined(COMPAT_FREEBSD32) + freebsd32_sysent[FREEBSD32_SYS_chdir].sy_call = (sy_call_t *) filemon_wrapper_chdir; + freebsd32_sysent[FREEBSD32_SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open; + freebsd32_sysent[FREEBSD32_SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat; + freebsd32_sysent[FREEBSD32_SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename; + freebsd32_sysent[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink; + freebsd32_sysent[FREEBSD32_SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link; + freebsd32_sysent[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink; + freebsd32_sysent[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat; +#endif /* COMPAT_FREEBSD32 */ filemon_exec_tag = EVENTHANDLER_REGISTER(process_exec, filemon_event_process_exec, NULL, EVENTHANDLER_PRI_LAST); @@ -441,33 +435,26 @@ filemon_wrapper_install(void) static void filemon_wrapper_deinstall(void) { -#if defined(__LP64__) - struct sysent *sv_table = elf64_freebsd_sysvec.sv_table; -#else - struct sysent *sv_table = elf32_freebsd_sysvec.sv_table; -#endif - - sv_table[SYS_chdir].sy_call = (sy_call_t *)sys_chdir; - sv_table[SYS_open].sy_call = (sy_call_t *)sys_open; - sv_table[SYS_openat].sy_call = (sy_call_t *)sys_openat; - sv_table[SYS_rename].sy_call = (sy_call_t *)sys_rename; - sv_table[SYS_unlink].sy_call = (sy_call_t *)sys_unlink; - sv_table[SYS_link].sy_call = (sy_call_t *)sys_link; - sv_table[SYS_symlink].sy_call = (sy_call_t *)sys_symlink; - sv_table[SYS_linkat].sy_call = (sy_call_t *)sys_linkat; - -#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32) - sv_table = ia32_freebsd_sysvec.sv_table; - - sv_table[FREEBSD32_SYS_chdir].sy_call = (sy_call_t *)sys_chdir; - sv_table[FREEBSD32_SYS_open].sy_call = (sy_call_t *)sys_open; - sv_table[FREEBSD32_SYS_openat].sy_call = (sy_call_t *)sys_openat; - sv_table[FREEBSD32_SYS_rename].sy_call = (sy_call_t *)sys_rename; - sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *)sys_unlink; - sv_table[FREEBSD32_SYS_link].sy_call = (sy_call_t *)sys_link; - sv_table[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *)sys_symlink; - sv_table[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *)sys_linkat; -#endif /* COMPAT_ARCH32 */ + + sysent[SYS_chdir].sy_call = (sy_call_t *)sys_chdir; + sysent[SYS_open].sy_call = (sy_call_t *)sys_open; + sysent[SYS_openat].sy_call = (sy_call_t *)sys_openat; + sysent[SYS_rename].sy_call = (sy_call_t *)sys_rename; + sysent[SYS_unlink].sy_call = (sy_call_t *)sys_unlink; + sysent[SYS_link].sy_call = (sy_call_t *)sys_link; + sysent[SYS_symlink].sy_call = (sy_call_t *)sys_symlink; + sysent[SYS_linkat].sy_call = (sy_call_t *)sys_linkat; + +#if defined(COMPAT_FREEBSD32) + freebsd32_sysent[FREEBSD32_SYS_chdir].sy_call = (sy_call_t *)sys_chdir; + freebsd32_sysent[FREEBSD32_SYS_open].sy_call = (sy_call_t *)sys_open; + freebsd32_sysent[FREEBSD32_SYS_openat].sy_call = (sy_call_t *)sys_openat; + freebsd32_sysent[FREEBSD32_SYS_rename].sy_call = (sy_call_t *)sys_rename; + freebsd32_sysent[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *)sys_unlink; + freebsd32_sysent[FREEBSD32_SYS_link].sy_call = (sy_call_t *)sys_link; + freebsd32_sysent[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *)sys_symlink; + freebsd32_sysent[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *)sys_linkat; +#endif /* COMPAT_FREEBSD32 */ EVENTHANDLER_DEREGISTER(process_exec, filemon_exec_tag); EVENTHANDLER_DEREGISTER(process_exit, filemon_exit_tag); Modified: stable/10/sys/modules/Makefile ============================================================================== --- stable/10/sys/modules/Makefile Tue Jun 21 20:28:30 2016 (r302071) +++ stable/10/sys/modules/Makefile Tue Jun 21 20:32:34 2016 (r302072) @@ -110,7 +110,7 @@ SUBDIR= \ fdc \ fdescfs \ ${_fe} \ - ${_filemon} \ + filemon \ firewire \ firmware \ fuse \ @@ -388,7 +388,6 @@ SUBDIR= \ zlib \ .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" -_filemon= filemon _imgact_binmisc= imgact_binmisc _vmware= vmware .endif From owner-svn-src-stable-10@freebsd.org Wed Jun 22 09:08:19 2016 Return-Path: Delivered-To: svn-src-stable-10@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 D6025A7A08F; Wed, 22 Jun 2016 09:08:19 +0000 (UTC) (envelope-from kib@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 8A335250C; Wed, 22 Jun 2016 09:08:19 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5M98Iae018908; Wed, 22 Jun 2016 09:08:18 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5M98IvT018907; Wed, 22 Jun 2016 09:08:18 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606220908.u5M98IvT018907@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 22 Jun 2016 09:08:18 +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: r302078 - stable/10/sys/fs/devfs 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2016 09:08:19 -0000 Author: kib Date: Wed Jun 22 09:08:18 2016 New Revision: 302078 URL: https://svnweb.freebsd.org/changeset/base/302078 Log: MFC r301928: Only access vp->v_rdev for VCHR vnodes in devfs_reclaim(). Modified: stable/10/sys/fs/devfs/devfs_vnops.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/devfs/devfs_vnops.c ============================================================================== --- stable/10/sys/fs/devfs/devfs_vnops.c Wed Jun 22 09:05:21 2016 (r302077) +++ stable/10/sys/fs/devfs/devfs_vnops.c Wed Jun 22 09:08:18 2016 (r302078) @@ -1325,10 +1325,10 @@ devfs_readlink(struct vop_readlink_args static int devfs_reclaim(struct vop_reclaim_args *ap) { - struct vnode *vp = ap->a_vp; + struct vnode *vp; struct devfs_dirent *de; - struct cdev *dev; + vp = ap->a_vp; mtx_lock(&devfs_de_interlock); de = vp->v_data; if (de != NULL) { @@ -1336,24 +1336,31 @@ devfs_reclaim(struct vop_reclaim_args *a vp->v_data = NULL; } mtx_unlock(&devfs_de_interlock); - vnode_destroy_vobject(vp); + return (0); +} + +static int +devfs_reclaim_vchr(struct vop_reclaim_args *ap) +{ + struct vnode *vp; + struct cdev *dev; + + vp = ap->a_vp; + MPASS(vp->v_type == VCHR); + + devfs_reclaim(ap); VI_LOCK(vp); dev_lock(); dev = vp->v_rdev; vp->v_rdev = NULL; - - if (dev == NULL) { - dev_unlock(); - VI_UNLOCK(vp); - return (0); - } - - dev->si_usecount -= vp->v_usecount; + if (dev != NULL) + dev->si_usecount -= vp->v_usecount; dev_unlock(); VI_UNLOCK(vp); - dev_rel(dev); + if (dev != NULL) + dev_rel(dev); return (0); } @@ -1791,7 +1798,7 @@ static struct vop_vector devfs_specops = .vop_readdir = VOP_PANIC, .vop_readlink = VOP_PANIC, .vop_reallocblks = VOP_PANIC, - .vop_reclaim = devfs_reclaim, + .vop_reclaim = devfs_reclaim_vchr, .vop_remove = devfs_remove, .vop_rename = VOP_PANIC, .vop_revoke = devfs_revoke, From owner-svn-src-stable-10@freebsd.org Wed Jun 22 09:10:54 2016 Return-Path: Delivered-To: svn-src-stable-10@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 31DEFA7A150; Wed, 22 Jun 2016 09:10:54 +0000 (UTC) (envelope-from kib@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 D8D762708; Wed, 22 Jun 2016 09:10:53 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5M9ArT3019062; Wed, 22 Jun 2016 09:10:53 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5M9Aric019061; Wed, 22 Jun 2016 09:10:53 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606220910.u5M9Aric019061@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 22 Jun 2016 09:10:52 +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: r302079 - stable/10/sys/kern 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2016 09:10:54 -0000 Author: kib Date: Wed Jun 22 09:10:52 2016 New Revision: 302079 URL: https://svnweb.freebsd.org/changeset/base/302079 Log: MFC r301929: Do not assume that we own the use reference on the covered vnode until we set MNTK_UNMOUNT flag on the mp. Modified: stable/10/sys/kern/vfs_mount.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/vfs_mount.c ============================================================================== --- stable/10/sys/kern/vfs_mount.c Wed Jun 22 09:08:18 2016 (r302078) +++ stable/10/sys/kern/vfs_mount.c Wed Jun 22 09:10:52 2016 (r302079) @@ -1222,7 +1222,6 @@ dounmount(struct mount *mp, int flags, s VI_LOCK(coveredvp); vholdl(coveredvp); vn_lock(coveredvp, LK_EXCLUSIVE | LK_INTERLOCK | LK_RETRY); - vdrop(coveredvp); /* * Check for mp being unmounted while waiting for the * covered vnode lock. @@ -1230,18 +1229,22 @@ dounmount(struct mount *mp, int flags, s if (coveredvp->v_mountedhere != mp || coveredvp->v_mountedhere->mnt_gen != mnt_gen_r) { VOP_UNLOCK(coveredvp, 0); + vdrop(coveredvp); vfs_rel(mp); return (EBUSY); } } + /* * Only privileged root, or (if MNT_USER is set) the user that did the * original mount is permitted to unmount this filesystem. */ error = vfs_suser(mp, td); if (error != 0) { - if (coveredvp) + if (coveredvp != NULL) { VOP_UNLOCK(coveredvp, 0); + vdrop(coveredvp); + } vfs_rel(mp); return (error); } @@ -1251,8 +1254,10 @@ dounmount(struct mount *mp, int flags, s if ((mp->mnt_kern_flag & MNTK_UNMOUNT) != 0 || !TAILQ_EMPTY(&mp->mnt_uppers)) { MNT_IUNLOCK(mp); - if (coveredvp) + if (coveredvp != NULL) { VOP_UNLOCK(coveredvp, 0); + vdrop(coveredvp); + } vn_finished_write(mp); return (EBUSY); } @@ -1285,6 +1290,16 @@ dounmount(struct mount *mp, int flags, s if (mp->mnt_flag & MNT_EXPUBLIC) vfs_setpublicfs(NULL, NULL, NULL); + /* + * From now, we can claim that the use reference on the + * coveredvp is ours, and the ref can be released only by + * successfull unmount by us, or left for later unmount + * attempt. The previously acquired hold reference is no + * longer needed to protect the vnode from reuse. + */ + if (coveredvp != NULL) + vdrop(coveredvp); + vfs_msync(mp, MNT_WAIT); MNT_ILOCK(mp); async_flag = mp->mnt_flag & MNT_ASYNC; From owner-svn-src-stable-10@freebsd.org Thu Jun 23 01:47:31 2016 Return-Path: Delivered-To: svn-src-stable-10@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 61513B72976; Thu, 23 Jun 2016 01:47:31 +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 3D3871E8A; Thu, 23 Jun 2016 01:47:31 +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 u5N1lUYe096036; Thu, 23 Jun 2016 01:47:30 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N1lUUc096034; Thu, 23 Jun 2016 01:47:30 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230147.u5N1lUUc096034@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 01:47:30 +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: r302107 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 01:47:31 -0000 Author: sephe Date: Thu Jun 23 01:47:30 2016 New Revision: 302107 URL: https://svnweb.freebsd.org/changeset/base/302107 Log: MFC 299889,299890,299892 299889 hyperv/vmbus: Simplify event processing While I'm here, remove useless comment and unnecessary return. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6332 299890 hyperv/vmbus: Simplify event processing For channel0, it will never be processed on event handling path, so there is no need to install it. After skipping in the channel0 installation, we could discard the channel0 check on event handling hot code path. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6333 299892 hyperv/vmbus: Fix event processing loop indentation. No functional changes. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6334 Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c stable/10/sys/dev/hyperv/vmbus/hv_connection.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Thu Jun 23 01:15:35 2016 (r302106) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Thu Jun 23 01:47:30 2016 (r302107) @@ -186,7 +186,14 @@ vmbus_channel_process_offer(hv_vmbus_cha * Make sure this is a new offer */ mtx_lock(&hv_vmbus_g_connection.channel_lock); - hv_vmbus_g_connection.channels[relid] = new_channel; + if (relid == 0) { + /* + * XXX channel0 will not be processed; skip it. + */ + printf("VMBUS: got channel0 offer\n"); + } else { + hv_vmbus_g_connection.channels[relid] = new_channel; + } TAILQ_FOREACH(channel, &hv_vmbus_g_connection.channel_anchor, list_entry) { Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 01:15:35 2016 (r302106) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 01:47:30 2016 (r302107) @@ -303,7 +303,6 @@ hv_vmbus_on_events(int cpu) int rel_id; int maxdword; hv_vmbus_synic_event_flags *event; - /* int maxdword = PAGE_SIZE >> 3; */ KASSERT(cpu <= mp_maxid, ("VMBUS: hv_vmbus_on_events: " "cpu out of range!")); @@ -317,9 +316,12 @@ hv_vmbus_on_events(int cpu) /* * receive size is 1/2 page and divide that by 4 bytes */ - if (synch_test_and_clear_bit(0, &event->flags32[0])) + if (synch_test_and_clear_bit(0, &event->flags32[0])) { recv_interrupt_page = hv_vmbus_g_connection.recv_interrupt_page; + } else { + return; + } } else { /* * On Host with Win8 or above, the event page can be @@ -333,36 +335,32 @@ hv_vmbus_on_events(int cpu) /* * Check events */ - if (recv_interrupt_page != NULL) { - for (dword = 0; dword < maxdword; dword++) { - if (recv_interrupt_page[dword]) { - for (bit = 0; bit < HV_CHANNEL_DWORD_LEN; bit++) { + for (dword = 0; dword < maxdword; dword++) { + if (recv_interrupt_page[dword] == 0) + continue; + + for (bit = 0; bit < HV_CHANNEL_DWORD_LEN; bit++) { if (synch_test_and_clear_bit(bit, - (uint32_t *) &recv_interrupt_page[dword])) { - rel_id = (dword << 5) + bit; - if (rel_id == 0) { - /* - * Special case - - * vmbus channel protocol msg. - */ - continue; - } else { - hv_vmbus_channel * channel = hv_vmbus_g_connection.channels[rel_id]; + (uint32_t *)&recv_interrupt_page[dword])) { + struct hv_vmbus_channel *channel; + + rel_id = (dword << 5) + bit; + channel = + hv_vmbus_g_connection.channels[rel_id]; + /* if channel is closed or closing */ if (channel == NULL || channel->rxq == NULL) continue; - if (channel->batched_reading) - hv_ring_buffer_read_begin(&channel->inbound); - taskqueue_enqueue_fast(channel->rxq, &channel->channel_task); - } + if (channel->batched_reading) { + hv_ring_buffer_read_begin( + &channel->inbound); + } + taskqueue_enqueue(channel->rxq, + &channel->channel_task); } - } - } - } + } } - - return; } /** From owner-svn-src-stable-10@freebsd.org Thu Jun 23 02:21:38 2016 Return-Path: Delivered-To: svn-src-stable-10@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 78BB9B7314F; Thu, 23 Jun 2016 02:21:38 +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 52C692E08; Thu, 23 Jun 2016 02:21:38 +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 u5N2Lb8o010585; Thu, 23 Jun 2016 02:21:37 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N2Lbtp010582; Thu, 23 Jun 2016 02:21:37 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230221.u5N2Lbtp010582@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 02:21:37 +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: r302108 - in stable/10: share/man/man9 sys/amd64/include sys/i386/include 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 02:21:38 -0000 Author: sephe Date: Thu Jun 23 02:21:37 2016 New Revision: 302108 URL: https://svnweb.freebsd.org/changeset/base/302108 Log: MFC 299912 atomic: Add testandclear on i386/amd64 Reviewed by: kib Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6381 Modified: stable/10/share/man/man9/atomic.9 stable/10/sys/amd64/include/atomic.h stable/10/sys/i386/include/atomic.h Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man9/atomic.9 ============================================================================== --- stable/10/share/man/man9/atomic.9 Thu Jun 23 01:47:30 2016 (r302107) +++ stable/10/share/man/man9/atomic.9 Thu Jun 23 02:21:37 2016 (r302108) @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 14, 2015 +.Dd May 12, 2016 .Dt ATOMIC 9 .Os .Sh NAME @@ -65,6 +65,8 @@ .Ft .Fn atomic_swap_ "volatile *p" " v" .Ft int +.Fn atomic_testandclear_ "volatile *p" "u_int v" +.Ft int .Fn atomic_testandset_ "volatile *p" "u_int v" .Sh DESCRIPTION Each of the atomic operations is guaranteed to be atomic across multiple @@ -313,6 +315,15 @@ and .Dq Li 16 and do not have any variants with memory barriers at this time. .Bl -hang +.It Fn atomic_testandclear p v +.Bd -literal -compact +bit = 1 << (v % (sizeof(*p) * NBBY)); +tmp = (*p & bit) != 0; +*p &= ~bit; +return (tmp); +.Ed +.El +.Bl -hang .It Fn atomic_testandset p v .Bd -literal -compact bit = 1 << (v % (sizeof(*p) * NBBY)); @@ -324,6 +335,8 @@ return (tmp); .Pp The .Fn atomic_testandset +and +.Fn atomic_testandclear functions are only implemented for the types .Dq Li int , .Dq Li long @@ -352,6 +365,8 @@ and functions return the value at the specified address. The .Fn atomic_testandset +and +.Fn atomic_testandclear function returns the result of the test operation. .Sh EXAMPLES This example uses the @@ -429,3 +444,6 @@ and .Fn atomic_testandset operations were added in .Fx 10.0 . +.Fn atomic_testandclear +operation was added in +.Fx 11.0 . Modified: stable/10/sys/amd64/include/atomic.h ============================================================================== --- stable/10/sys/amd64/include/atomic.h Thu Jun 23 01:47:30 2016 (r302107) +++ stable/10/sys/amd64/include/atomic.h Thu Jun 23 02:21:37 2016 (r302108) @@ -84,6 +84,8 @@ u_int atomic_fetchadd_int(volatile u_int u_long atomic_fetchadd_long(volatile u_long *p, u_long v); int atomic_testandset_int(volatile u_int *p, u_int v); int atomic_testandset_long(volatile u_long *p, u_int v); +int atomic_testandclear_int(volatile u_int *p, u_int v); +int atomic_testandclear_long(volatile u_long *p, u_int v); #define ATOMIC_LOAD(TYPE, LOP) \ u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p) @@ -241,6 +243,40 @@ atomic_testandset_long(volatile u_long * return (res); } +static __inline int +atomic_testandclear_int(volatile u_int *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btrl %2,%1 ; " + " setc %0 ; " + "# atomic_testandclear_int" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Ir" (v & 0x1f) /* 2 */ + : "cc"); + return (res); +} + +static __inline int +atomic_testandclear_long(volatile u_long *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btrq %2,%1 ; " + " setc %0 ; " + "# atomic_testandclear_long" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Jr" ((u_long)(v & 0x3f)) /* 2 */ + : "cc"); + return (res); +} + /* * We assume that a = b will do atomic loads and stores. Due to the * IA32 memory model, a simple store guarantees release semantics. @@ -462,6 +498,7 @@ u_long atomic_swap_long(volatile u_long #define atomic_readandclear_32 atomic_readandclear_int #define atomic_fetchadd_32 atomic_fetchadd_int #define atomic_testandset_32 atomic_testandset_int +#define atomic_testandclear_32 atomic_testandclear_int /* Operations on 64-bit quad words. */ #define atomic_set_64 atomic_set_long @@ -485,6 +522,7 @@ u_long atomic_swap_long(volatile u_long #define atomic_readandclear_64 atomic_readandclear_long #define atomic_fetchadd_64 atomic_fetchadd_long #define atomic_testandset_64 atomic_testandset_long +#define atomic_testandclear_64 atomic_testandclear_long /* Operations on pointers. */ #define atomic_set_ptr atomic_set_long Modified: stable/10/sys/i386/include/atomic.h ============================================================================== --- stable/10/sys/i386/include/atomic.h Thu Jun 23 01:47:30 2016 (r302107) +++ stable/10/sys/i386/include/atomic.h Thu Jun 23 02:21:37 2016 (r302108) @@ -86,6 +86,7 @@ void atomic_##NAME##_barr_##TYPE(volatil int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src); u_int atomic_fetchadd_int(volatile u_int *p, u_int v); int atomic_testandset_int(volatile u_int *p, u_int v); +int atomic_testandclear_int(volatile u_int *p, u_int v); #define ATOMIC_LOAD(TYPE, LOP) \ u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p) @@ -224,6 +225,23 @@ atomic_testandset_int(volatile u_int *p, return (res); } +static __inline int +atomic_testandclear_int(volatile u_int *p, u_int v) +{ + u_char res; + + __asm __volatile( + " " MPLOCKED " " + " btrl %2,%1 ; " + " setc %0 ; " + "# atomic_testandclear_int" + : "=q" (res), /* 0 */ + "+m" (*p) /* 1 */ + : "Ir" (v & 0x1f) /* 2 */ + : "cc"); + return (res); +} + /* * We assume that a = b will do atomic loads and stores. Due to the * IA32 memory model, a simple store guarantees release semantics. @@ -549,6 +567,13 @@ atomic_testandset_long(volatile u_long * return (atomic_testandset_int((volatile u_int *)p, v)); } +static __inline int +atomic_testandclear_long(volatile u_long *p, u_int v) +{ + + return (atomic_testandclear_int((volatile u_int *)p, v)); +} + /* Read the current value and store a new value in the destination. */ #ifdef __GNUCLIKE_ASM @@ -675,6 +700,7 @@ u_long atomic_swap_long(volatile u_long #define atomic_readandclear_32 atomic_readandclear_int #define atomic_fetchadd_32 atomic_fetchadd_int #define atomic_testandset_32 atomic_testandset_int +#define atomic_testandclear_32 atomic_testandclear_int /* Operations on pointers. */ #define atomic_set_ptr(p, v) \ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 02:37:26 2016 Return-Path: Delivered-To: svn-src-stable-10@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 448FAB7343C; Thu, 23 Jun 2016 02:37:26 +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 030D31702; Thu, 23 Jun 2016 02:37:25 +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 u5N2bP7T014472; Thu, 23 Jun 2016 02:37:25 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N2bO4X014467; Thu, 23 Jun 2016 02:37:24 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230237.u5N2bO4X014467@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 02:37:24 +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: r302109 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 02:37:26 -0000 Author: sephe Date: Thu Jun 23 02:37:24 2016 New Revision: 302109 URL: https://svnweb.freebsd.org/changeset/base/302109 Log: MFC 299927,300101,300102,300105,300107 299927 hyperv/vmbus: Use atomic_testandclear Prepare to use unsigned long for event channel bit array. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6382 300101 hyperv/vmbus: Use unsigned long for event bits. And move base channel id calculation out of inner loop. This prepares for more event processing optimization. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6384 300102 hyperv/vmbus: Reduce the # of event loops by recording event flag count Use vmbus softc to save vmbus per-cpu data. More stuffs will be moved into vmbus softc. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6403 300105 hyperv/vmbus: Use atomic swap and flsl to process event flags Greatly reduce the locked instructions and reduce number of inner loops. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6404 300107 hyperv/vmbus: Avoid two unnecessary protocol checks on isr handling path MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6405 Added: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h - copied, changed from r300102, head/sys/dev/hyperv/vmbus/vmbus_var.h Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Thu Jun 23 02:21:37 2016 (r302108) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Thu Jun 23 02:37:24 2016 (r302109) @@ -42,7 +42,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include "hv_vmbus_priv.h" +#include +#include static int vmbus_channel_create_gpadl_header( /* must be phys and virt contiguous*/ @@ -199,6 +200,8 @@ hv_vmbus_channel_open( new_channel->on_channel_callback = pfn_on_channel_callback; new_channel->channel_callback_context = context; + vmbus_on_channel_open(new_channel); + new_channel->rxq = hv_vmbus_g_context.hv_event_queue[new_channel->target_cpu]; TASK_INIT(&new_channel->channel_task, 0, VmbusProcessChannelEvent, new_channel); Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 02:21:37 2016 (r302108) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 02:37:24 2016 (r302109) @@ -36,11 +36,13 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include -#include "hv_vmbus_priv.h" +#include +#include /* * Globals @@ -290,76 +292,71 @@ hv_vmbus_disconnect(void) { return (ret); } -/** - * Handler for events - */ -void -hv_vmbus_on_events(int cpu) +static __inline void +vmbus_event_flags_proc(unsigned long *event_flags, int flag_cnt) { - int bit; - int dword; - void *page_addr; - uint32_t* recv_interrupt_page = NULL; - int rel_id; - int maxdword; - hv_vmbus_synic_event_flags *event; + int f; - KASSERT(cpu <= mp_maxid, ("VMBUS: hv_vmbus_on_events: " - "cpu out of range!")); + for (f = 0; f < flag_cnt; ++f) { + uint32_t rel_id_base; + unsigned long flags; + int bit; - page_addr = hv_vmbus_g_context.syn_ic_event_page[cpu]; - event = (hv_vmbus_synic_event_flags *) - page_addr + HV_VMBUS_MESSAGE_SINT; - if ((hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008) || - (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7)) { - maxdword = HV_MAX_NUM_CHANNELS_SUPPORTED >> 5; - /* - * receive size is 1/2 page and divide that by 4 bytes - */ - if (synch_test_and_clear_bit(0, &event->flags32[0])) { - recv_interrupt_page = - hv_vmbus_g_connection.recv_interrupt_page; - } else { - return; + if (event_flags[f] == 0) + continue; + + flags = atomic_swap_long(&event_flags[f], 0); + rel_id_base = f << HV_CHANNEL_ULONG_SHIFT; + + while ((bit = ffsl(flags)) != 0) { + struct hv_vmbus_channel *channel; + uint32_t rel_id; + + --bit; /* NOTE: ffsl is 1-based */ + flags &= ~(1UL << bit); + + rel_id = rel_id_base + bit; + channel = hv_vmbus_g_connection.channels[rel_id]; + + /* if channel is closed or closing */ + if (channel == NULL || channel->rxq == NULL) + continue; + + if (channel->batched_reading) + hv_ring_buffer_read_begin(&channel->inbound); + taskqueue_enqueue(channel->rxq, &channel->channel_task); } - } else { - /* - * On Host with Win8 or above, the event page can be - * checked directly to get the id of the channel - * that has the pending interrupt. - */ - maxdword = HV_EVENT_FLAGS_DWORD_COUNT; - recv_interrupt_page = event->flags32; } +} + +void +vmbus_event_proc(struct vmbus_softc *sc, int cpu) +{ + hv_vmbus_synic_event_flags *event; + + event = ((hv_vmbus_synic_event_flags *) + hv_vmbus_g_context.syn_ic_event_page[cpu]) + HV_VMBUS_MESSAGE_SINT; /* - * Check events + * On Host with Win8 or above, the event page can be checked directly + * to get the id of the channel that has the pending interrupt. */ - for (dword = 0; dword < maxdword; dword++) { - if (recv_interrupt_page[dword] == 0) - continue; + vmbus_event_flags_proc(event->flagsul, + VMBUS_SC_PCPU_GET(sc, event_flag_cnt, cpu)); +} - for (bit = 0; bit < HV_CHANNEL_DWORD_LEN; bit++) { - if (synch_test_and_clear_bit(bit, - (uint32_t *)&recv_interrupt_page[dword])) { - struct hv_vmbus_channel *channel; - - rel_id = (dword << 5) + bit; - channel = - hv_vmbus_g_connection.channels[rel_id]; - - /* if channel is closed or closing */ - if (channel == NULL || channel->rxq == NULL) - continue; - - if (channel->batched_reading) { - hv_ring_buffer_read_begin( - &channel->inbound); - } - taskqueue_enqueue(channel->rxq, - &channel->channel_task); - } - } +void +vmbus_event_proc_compat(struct vmbus_softc *sc __unused, int cpu) +{ + hv_vmbus_synic_event_flags *event; + + event = ((hv_vmbus_synic_event_flags *) + hv_vmbus_g_context.syn_ic_event_page[cpu]) + HV_VMBUS_MESSAGE_SINT; + + if (atomic_testandclear_int(&event->flags32[0], 0)) { + vmbus_event_flags_proc( + hv_vmbus_g_connection.recv_interrupt_page, + HV_MAX_NUM_CHANNELS_SUPPORTED >> HV_CHANNEL_ULONG_SHIFT); } } @@ -414,3 +411,30 @@ hv_vmbus_set_event(hv_vmbus_channel *cha return (ret); } + +void +vmbus_on_channel_open(const struct hv_vmbus_channel *chan) +{ + volatile int *flag_cnt_ptr; + int flag_cnt; + + flag_cnt = (chan->offer_msg.child_rel_id / HV_CHANNEL_ULONG_LEN) + 1; + flag_cnt_ptr = VMBUS_PCPU_PTR(event_flag_cnt, chan->target_cpu); + + for (;;) { + int old_flag_cnt; + + old_flag_cnt = *flag_cnt_ptr; + if (old_flag_cnt >= flag_cnt) + break; + if (atomic_cmpset_int(flag_cnt_ptr, old_flag_cnt, flag_cnt)) { + if (bootverbose) { + printf("VMBUS: channel%u update " + "cpu%d flag_cnt to %d\n", + chan->offer_msg.child_rel_id, + chan->target_cpu, flag_cnt); + } + break; + } + } +} Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 02:21:37 2016 (r302108) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 02:37:24 2016 (r302109) @@ -60,11 +60,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include "hv_vmbus_priv.h" +#include +#include #include #include "acpi_if.h" +struct vmbus_softc *vmbus_sc; + static device_t vmbus_devp; static int vmbus_inited; static hv_setup_args setup_args; /* only CPU 0 supported at this time */ @@ -143,6 +146,7 @@ handled: static inline int hv_vmbus_isr(struct trapframe *frame) { + struct vmbus_softc *sc = vmbus_get_softc(); int cpu; hv_vmbus_message* msg; void* page_addr; @@ -154,8 +158,7 @@ hv_vmbus_isr(struct trapframe *frame) * before checking for messages. This is the way they do it * in Windows when running as a guest in Hyper-V */ - - hv_vmbus_on_events(cpu); + sc->vmbus_event_proc(sc, cpu); /* Check if there are actual msgs to be process */ page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu]; @@ -455,6 +458,7 @@ vmbus_cpuset_setthread_task(void *xmask, static int vmbus_bus_init(void) { + struct vmbus_softc *sc; int i, j, n, ret; char buf[MAXCOMLEN + 1]; cpuset_t cpu_mask; @@ -463,6 +467,7 @@ vmbus_bus_init(void) return (0); vmbus_inited = 1; + sc = vmbus_get_softc(); ret = hv_vmbus_init(); @@ -559,6 +564,12 @@ vmbus_bus_init(void) if (ret != 0) goto cleanup1; + if (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008 || + hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7) + sc->vmbus_event_proc = vmbus_event_proc_compat; + else + sc->vmbus_event_proc = vmbus_event_proc; + hv_vmbus_request_channel_offers(); vmbus_scan(); @@ -593,12 +604,26 @@ vmbus_bus_init(void) return (ret); } +static void +vmbus_event_proc_dummy(struct vmbus_softc *sc __unused, int cpu __unused) +{ +} + static int vmbus_attach(device_t dev) { if(bootverbose) device_printf(dev, "VMBUS: attach dev: %p\n", dev); + vmbus_devp = dev; + vmbus_sc = device_get_softc(dev); + + /* + * Event processing logic will be configured: + * - After the vmbus protocol version negotiation. + * - Before we request channel offers. + */ + vmbus_sc->vmbus_event_proc = vmbus_event_proc_dummy; /* * If the system has already booted and thread @@ -616,7 +641,7 @@ vmbus_attach(device_t dev) static void vmbus_init(void) { - if (vm_guest != VM_GUEST_HV) + if (vm_guest != VM_GUEST_HV || vmbus_get_softc() == NULL) return; /* @@ -720,9 +745,11 @@ static device_method_t vmbus_methods[] = { 0, 0 } }; -static char driver_name[] = "vmbus"; -static driver_t vmbus_driver = { driver_name, vmbus_methods,0, }; - +static driver_t vmbus_driver = { + "vmbus", + vmbus_methods, + sizeof(struct vmbus_softc) +}; devclass_t vmbus_devclass; Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 02:21:37 2016 (r302108) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 02:37:24 2016 (r302109) @@ -57,10 +57,18 @@ typedef uint16_t hv_vmbus_status; #define HV_EVENT_FLAGS_COUNT (256 * 8) #define HV_EVENT_FLAGS_BYTE_COUNT (256) #define HV_EVENT_FLAGS_DWORD_COUNT (256 / sizeof(uint32_t)) +#define HV_EVENT_FLAGS_ULONG_COUNT (256 / sizeof(unsigned long)) /** * max channel count <== event_flags_dword_count * bit_of_dword */ +#ifdef __LP64__ +#define HV_CHANNEL_ULONG_LEN (64) +#define HV_CHANNEL_ULONG_SHIFT (6) +#else +#define HV_CHANNEL_ULONG_LEN (32) +#define HV_CHANNEL_ULONG_SHIFT (5) +#endif #define HV_CHANNEL_DWORD_LEN (32) #define HV_CHANNEL_MAX_COUNT \ ((HV_EVENT_FLAGS_DWORD_COUNT) * HV_CHANNEL_DWORD_LEN) @@ -575,7 +583,9 @@ typedef struct { typedef union { uint8_t flags8[HV_EVENT_FLAGS_BYTE_COUNT]; uint32_t flags32[HV_EVENT_FLAGS_DWORD_COUNT]; + unsigned long flagsul[HV_EVENT_FLAGS_ULONG_COUNT]; } hv_vmbus_synic_event_flags; +CTASSERT(sizeof(hv_vmbus_synic_event_flags) == HV_EVENT_FLAGS_BYTE_COUNT); #define HV_X64_CPUID_MIN (0x40000005) #define HV_X64_CPUID_MAX (0x4000ffff) @@ -743,7 +753,6 @@ int hv_vmbus_connect(void); int hv_vmbus_disconnect(void); int hv_vmbus_post_message(void *buffer, size_t buf_size); int hv_vmbus_set_event(hv_vmbus_channel *channel); -void hv_vmbus_on_events(int cpu); /** * Event Timer interfaces Copied and modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h (from r300102, head/sys/dev/hyperv/vmbus/vmbus_var.h) ============================================================================== --- head/sys/dev/hyperv/vmbus/vmbus_var.h Wed May 18 03:19:53 2016 (r300102, copy source) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 02:37:24 2016 (r302109) @@ -36,6 +36,7 @@ struct vmbus_pcpu_data { } __aligned(CACHE_LINE_SIZE); struct vmbus_softc { + void (*vmbus_event_proc)(struct vmbus_softc *, int); struct vmbus_pcpu_data vmbus_pcpu[MAXCPU]; }; @@ -47,11 +48,15 @@ vmbus_get_softc(void) return vmbus_sc; } -#define VMBUS_PCPU_GET(field, cpu) \ - (vmbus_get_softc())->vmbus_pcpu[cpu].field -#define VMBUS_PCPU_PTR(field, cpu) \ - &(vmbus_get_softc())->vmbus_pcpu[cpu].field +#define VMBUS_SC_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field +#define VMBUS_SC_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field +#define VMBUS_PCPU_GET(field, cpu) \ + VMBUS_SC_PCPU_GET(vmbus_get_softc(), field, (cpu)) +#define VMBUS_PCPU_PTR(field, cpu) \ + VMBUS_SC_PCPU_PTR(vmbus_get_softc(), field, (cpu)) void vmbus_on_channel_open(const struct hv_vmbus_channel *); +void vmbus_event_proc(struct vmbus_softc *, int); +void vmbus_event_proc_compat(struct vmbus_softc *, int); #endif /* !_VMBUS_VAR_H_ */ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 02:53:25 2016 Return-Path: Delivered-To: svn-src-stable-10@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 48010B7379B; Thu, 23 Jun 2016 02:53:25 +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 246E721A4; Thu, 23 Jun 2016 02:53:25 +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 u5N2rOX2021687; Thu, 23 Jun 2016 02:53:24 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N2rO6b021686; Thu, 23 Jun 2016 02:53:24 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230253.u5N2rO6b021686@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 02:53:24 +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: r302111 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 02:53:25 -0000 Author: sephe Date: Thu Jun 23 02:53:24 2016 New Revision: 302111 URL: https://svnweb.freebsd.org/changeset/base/302111 Log: MFC 300108,300111,300112,300120,300121 300108 hyperv/vmbus: Minor white space and style cleanup MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6407 300111 hyperv/vmbus: Utilize curcpu MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6408 300112 hyperv/vmbus: Function renaming vmbus_msg_swintr -> vmbus_msg_task It is not an SWI handler for a long time. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6409 300120 hyperv/vmbus: Remove useless modevent handler MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6410 300121 hyperv/vmbus: Nuke unnecessary function indirection MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6411 Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 02:53:00 2016 (r302110) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 02:53:24 2016 (r302111) @@ -74,28 +74,18 @@ static hv_setup_args setup_args; /* only static char *vmbus_ids[] = { "VMBUS", NULL }; -/** - * @brief Software interrupt thread routine to handle channel messages from - * the hypervisor. - */ static void -vmbus_msg_swintr(void *arg, int pending __unused) +vmbus_msg_task(void *arg __unused, int pending __unused) { - int cpu; - void* page_addr; - hv_vmbus_channel_msg_header *hdr; - hv_vmbus_channel_msg_table_entry *entry; - hv_vmbus_channel_msg_type msg_type; - hv_vmbus_message* msg; - - cpu = (int)(long)arg; - KASSERT(cpu <= mp_maxid, ("VMBUS: vmbus_msg_swintr: " - "cpu out of range!")); - - page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu]; - msg = (hv_vmbus_message*) page_addr + HV_VMBUS_MESSAGE_SINT; + hv_vmbus_message *msg; + msg = ((hv_vmbus_message *)hv_vmbus_g_context.syn_ic_msg_page[curcpu]) + + HV_VMBUS_MESSAGE_SINT; for (;;) { + const hv_vmbus_channel_msg_table_entry *entry; + hv_vmbus_channel_msg_header *hdr; + hv_vmbus_channel_msg_type msg_type; + if (msg->header.message_type == HV_MESSAGE_TYPE_NONE) break; /* no message */ @@ -108,32 +98,29 @@ vmbus_msg_swintr(void *arg, int pending } entry = &g_channel_message_table[msg_type]; - if (entry->messageHandler) entry->messageHandler(hdr); handled: - msg->header.message_type = HV_MESSAGE_TYPE_NONE; - - /* - * Make sure the write to message_type (ie set to - * HV_MESSAGE_TYPE_NONE) happens before we read the - * message_pending and EOMing. Otherwise, the EOMing will - * not deliver any more messages - * since there is no empty slot - * - * NOTE: - * mb() is used here, since atomic_thread_fence_seq_cst() - * will become compiler fence on UP kernel. - */ - mb(); - - if (msg->header.message_flags.u.message_pending) { + msg->header.message_type = HV_MESSAGE_TYPE_NONE; + /* + * Make sure the write to message_type (ie set to + * HV_MESSAGE_TYPE_NONE) happens before we read the + * message_pending and EOMing. Otherwise, the EOMing will + * not deliver any more messages + * since there is no empty slot + * + * NOTE: + * mb() is used here, since atomic_thread_fence_seq_cst() + * will become compiler fence on UP kernel. + */ + mb(); + if (msg->header.message_flags.u.message_pending) { /* * This will cause message queue rescan to possibly * deliver another msg from the hypervisor */ wrmsr(HV_X64_MSR_EOM, 0); - } + } } } @@ -147,11 +134,9 @@ static inline int hv_vmbus_isr(struct trapframe *frame) { struct vmbus_softc *sc = vmbus_get_softc(); - int cpu; - hv_vmbus_message* msg; - void* page_addr; - - cpu = PCPU_GET(cpuid); + int cpu = curcpu; + hv_vmbus_message *msg; + void *page_addr; /* * The Windows team has advised that we check for events @@ -162,7 +147,7 @@ hv_vmbus_isr(struct trapframe *frame) /* Check if there are actual msgs to be process */ page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu]; - msg = (hv_vmbus_message*) page_addr + HV_VMBUS_TIMER_SINT; + msg = ((hv_vmbus_message *)page_addr) + HV_VMBUS_TIMER_SINT; /* we call eventtimer process the message */ if (msg->header.message_type == HV_MESSAGE_TIMER_EXPIRED) { @@ -193,7 +178,7 @@ hv_vmbus_isr(struct trapframe *frame) } } - msg = (hv_vmbus_message*) page_addr + HV_VMBUS_MESSAGE_SINT; + msg = ((hv_vmbus_message *)page_addr) + HV_VMBUS_MESSAGE_SINT; if (msg->header.message_type != HV_MESSAGE_TYPE_NONE) { taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], &hv_vmbus_g_context.hv_msg_task[cpu]); @@ -534,7 +519,7 @@ vmbus_bus_init(void) taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[j], 1, PI_NET, "hvmsg%d", j); TASK_INIT(&hv_vmbus_g_context.hv_msg_task[j], 0, - vmbus_msg_swintr, (void *)(long)j); + vmbus_msg_task, NULL); CPU_SETOF(j, &cpu_mask); TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask); @@ -654,8 +639,8 @@ vmbus_init(void) vmbus_bus_init(); } -static void -vmbus_bus_exit(void) +static int +vmbus_detach(device_t dev) { int i; @@ -681,49 +666,6 @@ vmbus_bus_exit(void) vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector); - return; -} - -static void -vmbus_exit(void) -{ - vmbus_bus_exit(); -} - -static int -vmbus_detach(device_t dev) -{ - vmbus_exit(); - return (0); -} - -static void -vmbus_mod_load(void) -{ - if(bootverbose) - printf("VMBUS: load\n"); -} - -static void -vmbus_mod_unload(void) -{ - if(bootverbose) - printf("VMBUS: unload\n"); -} - -static int -vmbus_modevent(module_t mod, int what, void *arg) -{ - switch (what) { - - case MOD_LOAD: - vmbus_mod_load(); - break; - case MOD_UNLOAD: - vmbus_mod_unload(); - break; - } - return (0); } @@ -753,7 +695,7 @@ static driver_t vmbus_driver = { devclass_t vmbus_devclass; -DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, vmbus_modevent, 0); +DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL); MODULE_DEPEND(vmbus, acpi, 1, 1, 1); MODULE_VERSION(vmbus, 1); From owner-svn-src-stable-10@freebsd.org Thu Jun 23 03:14:11 2016 Return-Path: Delivered-To: svn-src-stable-10@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 3F206B73D5E; Thu, 23 Jun 2016 03:14:11 +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 ED75F2E25; Thu, 23 Jun 2016 03:14:10 +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 u5N3EAsi030113; Thu, 23 Jun 2016 03:14:10 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N3E9Qe030109; Thu, 23 Jun 2016 03:14:09 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230314.u5N3E9Qe030109@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 03:14:09 +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: r302112 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 03:14:11 -0000 Author: sephe Date: Thu Jun 23 03:14:09 2016 New Revision: 302112 URL: https://svnweb.freebsd.org/changeset/base/302112 Log: MFC 300122,300123,300124,300126,300127,300129,300455 300122 hyperv: Set vm_guest to VM_GUEST_VM, if hypervisor is not Hyper-V Reviewed by: kib MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6412 300123 hyperv/vmbus: Staticize vmbus_devclass Reviewed by: Jun Su MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6414 300124 hyperv/vmbus: Reindent and cleanup devmethods. While I'm here, use DEVMETHOD_END. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6415 300126 hyperv/vmbus: Fix SYSINIT function prototype and usage. Reviewed by: Jun Su MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6416 300127 hyperv/vmbus: Minor function definition style fixup Reviewed by: Jun Su MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6417 300129 hyperv/vmbus: Use consistent device description as other devices MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6418 300455 hyperv: Move guest id setup to early place And - Rework the guest id composition. - Nuke useless saved guest_id. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6430 Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 02:53:24 2016 (r302111) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 03:14:09 2016 (r302112) @@ -152,7 +152,8 @@ hv_vmbus_negotiate_version(hv_vmbus_chan * Send a connect request on the partition service connection */ int -hv_vmbus_connect(void) { +hv_vmbus_connect(void) +{ int ret = 0; uint32_t version; hv_vmbus_channel_msg_info* msg_info = NULL; @@ -274,7 +275,8 @@ hv_vmbus_connect(void) { * Send a disconnect request on the partition service connection */ int -hv_vmbus_disconnect(void) { +hv_vmbus_disconnect(void) +{ int ret = 0; hv_vmbus_channel_unload msg; @@ -398,7 +400,8 @@ int hv_vmbus_post_message(void *buffer, * Send an event notification to the parent */ int -hv_vmbus_set_event(hv_vmbus_channel *channel) { +hv_vmbus_set_event(hv_vmbus_channel *channel) +{ int ret = 0; uint32_t child_rel_id = channel->offer_msg.child_rel_id; Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 02:53:24 2016 (r302111) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 03:14:09 2016 (r302112) @@ -50,6 +50,35 @@ __FBSDID("$FreeBSD$"); #define HYPERV_INTERFACE 0x31237648 /* HV#1 */ +/* + * The guest OS needs to register the guest ID with the hypervisor. + * The guest ID is a 64 bit entity and the structure of this ID is + * specified in the Hyper-V specification: + * + * http://msdn.microsoft.com/en-us/library/windows/ + * hardware/ff542653%28v=vs.85%29.aspx + * + * While the current guideline does not specify how FreeBSD guest ID(s) + * need to be generated, our plan is to publish the guidelines for + * FreeBSD and other guest operating systems that currently are hosted + * on Hyper-V. The implementation here conforms to this yet + * unpublished guidelines. + * + * Bit(s) + * 63 - Indicates if the OS is Open Source or not; 1 is Open Source + * 62:56 - Os Type: FreeBSD is 0x02 + * 55:48 - Distro specific identification + * 47:16 - FreeBSD kernel version number + * 15:0 - Distro specific identification + */ +#define HYPERV_GUESTID_OSS (0x1ULL << 63) +#define HYPERV_GUESTID_FREEBSD (0x02ULL << 56) +#define HYPERV_GUESTID(id) \ + (HYPERV_GUESTID_OSS | HYPERV_GUESTID_FREEBSD | \ + (((uint64_t)(((id) & 0xff0000) >> 16)) << 48) |\ + (((uint64_t)__FreeBSD_version) << 16) | \ + ((uint64_t)((id) & 0x00ffff))) + static u_int hv_get_timecount(struct timecounter *tc); u_int hyperv_features; @@ -143,13 +172,6 @@ hv_vmbus_init(void) goto cleanup; /* - * Write our OS info - */ - uint64_t os_guest_info = HV_FREEBSD_GUEST_ID; - wrmsr(HV_X64_MSR_GUEST_OS_ID, os_guest_info); - hv_vmbus_g_context.guest_id = os_guest_info; - - /* * See if the hypercall page is already set */ hypercall_msr.as_uint64_t = rdmsr(HV_X64_MSR_HYPERCALL); @@ -192,16 +214,13 @@ hv_vmbus_init(void) void hv_vmbus_cleanup(void) { - hv_vmbus_x64_msr_hypercall_contents hypercall_msr; + if (hv_vmbus_g_context.hypercall_page != NULL) { + hv_vmbus_x64_msr_hypercall_contents hypercall_msr; - if (hv_vmbus_g_context.guest_id == HV_FREEBSD_GUEST_ID) { - if (hv_vmbus_g_context.hypercall_page != NULL) { hypercall_msr.as_uint64_t = 0; - wrmsr(HV_X64_MSR_HYPERCALL, - hypercall_msr.as_uint64_t); + wrmsr(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64_t); free(hv_vmbus_g_context.hypercall_page, M_DEVBUF); hv_vmbus_g_context.hypercall_page = NULL; - } } } @@ -501,8 +520,15 @@ hyperv_identify(void) static void hyperv_init(void *dummy __unused) { - if (!hyperv_identify()) + if (!hyperv_identify()) { + /* Not Hyper-V; reset guest id to the generic one. */ + if (vm_guest == VM_GUEST_HV) + vm_guest = VM_GUEST_VM; return; + } + + /* Write guest id */ + wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_GUESTID(0)); if (hyperv_features & HV_FEATURE_MSR_TIME_REFCNT) { /* Register virtual timecount */ Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 02:53:24 2016 (r302111) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 03:14:09 2016 (r302112) @@ -346,12 +346,13 @@ hv_vmbus_child_device_unregister(struct } static int -vmbus_probe(device_t dev) { +vmbus_probe(device_t dev) +{ if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL || device_get_unit(dev) != 0) return (ENXIO); - device_set_desc(dev, "Vmbus Devices"); + device_set_desc(dev, "Hyper-V Vmbus"); return (BUS_PROBE_DEFAULT); } @@ -624,7 +625,7 @@ vmbus_attach(device_t dev) } static void -vmbus_init(void) +vmbus_sysinit(void *arg __unused) { if (vm_guest != VM_GUEST_HV || vmbus_get_softc() == NULL) return; @@ -670,22 +671,23 @@ vmbus_detach(device_t dev) } static device_method_t vmbus_methods[] = { - /** Device interface */ - DEVMETHOD(device_probe, vmbus_probe), - DEVMETHOD(device_attach, vmbus_attach), - DEVMETHOD(device_detach, vmbus_detach), - DEVMETHOD(device_shutdown, bus_generic_shutdown), - DEVMETHOD(device_suspend, bus_generic_suspend), - DEVMETHOD(device_resume, bus_generic_resume), - - /** Bus interface */ - DEVMETHOD(bus_add_child, bus_generic_add_child), - DEVMETHOD(bus_print_child, bus_generic_print_child), - DEVMETHOD(bus_read_ivar, vmbus_read_ivar), - DEVMETHOD(bus_write_ivar, vmbus_write_ivar), - DEVMETHOD(bus_child_pnpinfo_str, vmbus_child_pnpinfo_str), + /* Device interface */ + DEVMETHOD(device_probe, vmbus_probe), + DEVMETHOD(device_attach, vmbus_attach), + DEVMETHOD(device_detach, vmbus_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD(device_suspend, bus_generic_suspend), + DEVMETHOD(device_resume, bus_generic_resume), + + /* Bus interface */ + DEVMETHOD(bus_add_child, bus_generic_add_child), + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_read_ivar, vmbus_read_ivar), + DEVMETHOD(bus_write_ivar, vmbus_write_ivar), + DEVMETHOD(bus_child_pnpinfo_str, vmbus_child_pnpinfo_str), - { 0, 0 } }; + DEVMETHOD_END +}; static driver_t vmbus_driver = { "vmbus", @@ -693,12 +695,16 @@ static driver_t vmbus_driver = { sizeof(struct vmbus_softc) }; -devclass_t vmbus_devclass; +static devclass_t vmbus_devclass; DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL); MODULE_DEPEND(vmbus, acpi, 1, 1, 1); MODULE_VERSION(vmbus, 1); -/* We want to be started after SMP is initialized */ -SYSINIT(vmb_init, SI_SUB_SMP + 1, SI_ORDER_FIRST, vmbus_init, NULL); +/* + * NOTE: + * We have to start as the last step of SI_SUB_SMP, i.e. after SMP is + * initialized. + */ +SYSINIT(vmbus_initialize, SI_SUB_SMP, SI_ORDER_ANY, vmbus_sysinit, NULL); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 02:53:24 2016 (r302111) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 03:14:09 2016 (r302112) @@ -198,7 +198,6 @@ enum { #define HV_HYPERCALL_PARAM_ALIGN sizeof(uint64_t) typedef struct { - uint64_t guest_id; void* hypercall_page; hv_bool_uint8_t syn_ic_initialized; @@ -763,44 +762,6 @@ void hv_et_intr(struct trapframe*); /* Wait for device creation */ void vmbus_scan(void); -/* - * The guest OS needs to register the guest ID with the hypervisor. - * The guest ID is a 64 bit entity and the structure of this ID is - * specified in the Hyper-V specification: - * - * http://msdn.microsoft.com/en-us/library/windows/ - * hardware/ff542653%28v=vs.85%29.aspx - * - * While the current guideline does not specify how FreeBSD guest ID(s) - * need to be generated, our plan is to publish the guidelines for - * FreeBSD and other guest operating systems that currently are hosted - * on Hyper-V. The implementation here conforms to this yet - * unpublished guidelines. - * - * Bit(s) - * 63 - Indicates if the OS is Open Source or not; 1 is Open Source - * 62:56 - Os Type; Linux is 0x100, FreeBSD is 0x200 - * 55:48 - Distro specific identification - * 47:16 - FreeBSD kernel version number - * 15:0 - Distro specific identification - * - */ - -#define HV_FREEBSD_VENDOR_ID 0x8200 -#define HV_FREEBSD_GUEST_ID hv_generate_guest_id(0,0) - -static inline uint64_t hv_generate_guest_id( - uint8_t distro_id_part1, - uint16_t distro_id_part2) -{ - uint64_t guest_id; - guest_id = (((uint64_t)HV_FREEBSD_VENDOR_ID) << 48); - guest_id |= (((uint64_t)(distro_id_part1)) << 48); - guest_id |= (((uint64_t)(__FreeBSD_version)) << 16); /* in param.h */ - guest_id |= ((uint64_t)(distro_id_part2)); - return guest_id; -} - typedef struct { unsigned int vector; void *page_buffers[2 * MAXCPU]; From owner-svn-src-stable-10@freebsd.org Thu Jun 23 03:25:20 2016 Return-Path: Delivered-To: svn-src-stable-10@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 40FBEAC4082; Thu, 23 Jun 2016 03:25:20 +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 1A73116E8; Thu, 23 Jun 2016 03:25:20 +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 u5N3PJgo033985; Thu, 23 Jun 2016 03:25:19 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N3PI6T033979; Thu, 23 Jun 2016 03:25:18 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230325.u5N3PI6T033979@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 03:25:18 +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: r302113 - in stable/10/sys: conf dev/hyperv/include dev/hyperv/netvsc dev/hyperv/vmbus modules/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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 03:25:20 -0000 Author: sephe Date: Thu Jun 23 03:25:18 2016 New Revision: 302113 URL: https://svnweb.freebsd.org/changeset/base/302113 Log: MFC 300478,300479 300478 hyperv: Add helpers for busdma(9) operation MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6443 300479 hyperv/hn: Use hyperv busdma(9) helper. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6444 Added: stable/10/sys/dev/hyperv/include/hyperv_busdma.h - copied unchanged from r300478, head/sys/dev/hyperv/include/hyperv_busdma.h stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c - copied unchanged from r300478, head/sys/dev/hyperv/vmbus/hyperv_busdma.c Modified: stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/modules/hyperv/vmbus/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Thu Jun 23 03:14:09 2016 (r302112) +++ stable/10/sys/conf/files.amd64 Thu Jun 23 03:25:18 2016 (r302113) @@ -278,6 +278,7 @@ dev/hyperv/vmbus/hv_hv.c optional hyp dev/hyperv/vmbus/hv_et.c optional hyperv dev/hyperv/vmbus/hv_ring_buffer.c optional hyperv dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c optional hyperv +dev/hyperv/vmbus/hyperv_busdma.c optional hyperv dev/hyperv/vmbus/amd64/hv_vector.S optional hyperv dev/kbd/kbd.c optional atkbd | sc | ukbd | vt dev/lindev/full.c optional lindev Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Thu Jun 23 03:14:09 2016 (r302112) +++ stable/10/sys/conf/files.i386 Thu Jun 23 03:25:18 2016 (r302113) @@ -254,6 +254,7 @@ dev/hyperv/vmbus/hv_hv.c optional hyp dev/hyperv/vmbus/hv_et.c optional hyperv dev/hyperv/vmbus/hv_ring_buffer.c optional hyperv dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c optional hyperv +dev/hyperv/vmbus/hyperv_busdma.c optional hyperv dev/hyperv/vmbus/i386/hv_vector.S optional hyperv dev/ichwd/ichwd.c optional ichwd dev/if_ndis/if_ndis.c optional ndis Copied: stable/10/sys/dev/hyperv/include/hyperv_busdma.h (from r300478, head/sys/dev/hyperv/include/hyperv_busdma.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/include/hyperv_busdma.h Thu Jun 23 03:25:18 2016 (r302113, copy of r300478, head/sys/dev/hyperv/include/hyperv_busdma.h) @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _HYPERV_BUSDMA_H_ +#define _HYPERV_BUSDMA_H_ + +struct hyperv_dma { + bus_addr_t hv_paddr; + bus_dma_tag_t hv_dtag; + bus_dmamap_t hv_dmap; +}; + +void hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs, int nseg, + int error); +void *hyperv_dmamem_alloc(bus_dma_tag_t parent_dtag, bus_size_t alignment, + bus_addr_t boundary, bus_size_t size, struct hyperv_dma *dma, + int flags); +void hyperv_dmamem_free(struct hyperv_dma *dma, void *ptr); + +#endif /* !_HYPERV_BUSDMA_H_ */ Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Thu Jun 23 03:14:09 2016 (r302112) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Thu Jun 23 03:25:18 2016 (r302113) @@ -115,6 +115,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "hv_net_vsc.h" #include "hv_rndis.h" #include "hv_rndis_filter.h" @@ -2217,18 +2218,6 @@ hn_check_iplen(const struct mbuf *m, int } static void -hn_dma_map_paddr(void *arg, bus_dma_segment_t *segs, int nseg, int error) -{ - bus_addr_t *paddr = arg; - - if (error) - return; - - KASSERT(nseg == 1, ("too many segments %d!", nseg)); - *paddr = segs->ds_addr; -} - -static void hn_create_rx_data(struct hn_softc *sc, int ring_cnt) { struct sysctl_oid_list *child; @@ -2528,7 +2517,7 @@ hn_create_tx_ring(struct hn_softc *sc, i error = bus_dmamap_load(txr->hn_tx_rndis_dtag, txd->rndis_msg_dmap, txd->rndis_msg, HN_RNDIS_MSG_LEN, - hn_dma_map_paddr, &txd->rndis_msg_paddr, + hyperv_dma_map_paddr, &txd->rndis_msg_paddr, BUS_DMA_NOWAIT); if (error) { device_printf(sc->hn_dev, Copied: stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c (from r300478, head/sys/dev/hyperv/vmbus/hyperv_busdma.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c Thu Jun 23 03:25:18 2016 (r302113, copy of r300478, head/sys/dev/hyperv/vmbus/hyperv_busdma.c) @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include + +#include + +#define HYPERV_DMA_WAITMASK (BUS_DMA_WAITOK | BUS_DMA_NOWAIT) + +void +hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + bus_addr_t *paddr = arg; + + if (error) + return; + + KASSERT(nseg == 1, ("too many segments %d!", nseg)); + *paddr = segs->ds_addr; +} + +void * +hyperv_dmamem_alloc(bus_dma_tag_t parent_dtag, bus_size_t alignment, + bus_addr_t boundary, bus_size_t size, struct hyperv_dma *dma, int flags) +{ + void *ret; + int error; + + error = bus_dma_tag_create(parent_dtag, /* parent */ + alignment, /* alignment */ + boundary, /* boundary */ + BUS_SPACE_MAXADDR, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + size, /* maxsize */ + 1, /* nsegments */ + size, /* maxsegsize */ + 0, /* flags */ + NULL, /* lockfunc */ + NULL, /* lockfuncarg */ + &dma->hv_dtag); + if (error) + return NULL; + + error = bus_dmamem_alloc(dma->hv_dtag, &ret, + (flags & HYPERV_DMA_WAITMASK) | BUS_DMA_COHERENT, &dma->hv_dmap); + if (error) { + bus_dma_tag_destroy(dma->hv_dtag); + return NULL; + } + + error = bus_dmamap_load(dma->hv_dtag, dma->hv_dmap, ret, size, + hyperv_dma_map_paddr, &dma->hv_paddr, BUS_DMA_NOWAIT); + if (error) { + bus_dmamem_free(dma->hv_dtag, ret, dma->hv_dmap); + bus_dma_tag_destroy(dma->hv_dtag); + return NULL; + } + return ret; +} + +void +hyperv_dmamem_free(struct hyperv_dma *dma, void *ptr) +{ + bus_dmamap_unload(dma->hv_dtag, dma->hv_dmap); + bus_dmamem_free(dma->hv_dtag, ptr, dma->hv_dmap); + bus_dma_tag_destroy(dma->hv_dtag); +} Modified: stable/10/sys/modules/hyperv/vmbus/Makefile ============================================================================== --- stable/10/sys/modules/hyperv/vmbus/Makefile Thu Jun 23 03:14:09 2016 (r302112) +++ stable/10/sys/modules/hyperv/vmbus/Makefile Thu Jun 23 03:25:18 2016 (r302113) @@ -11,7 +11,8 @@ SRCS= hv_channel.c \ hv_hv.c \ hv_ring_buffer.c \ hv_vmbus_drv_freebsd.c \ - hv_vmbus_priv.h + hv_vmbus_priv.h \ + hyperv_busdma.c SRCS+= acpi_if.h bus_if.h device_if.h opt_acpi.h # XXX: for assym.s From owner-svn-src-stable-10@freebsd.org Thu Jun 23 04:40:14 2016 Return-Path: Delivered-To: svn-src-stable-10@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 DE268AC4DF8; Thu, 23 Jun 2016 04:40:14 +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 A9E5D11A9; Thu, 23 Jun 2016 04:40:14 +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 u5N4eDMA060538; Thu, 23 Jun 2016 04:40:13 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N4eDxA060532; Thu, 23 Jun 2016 04:40:13 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230440.u5N4eDxA060532@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 04:40:13 +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: r302114 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 04:40:15 -0000 Author: sephe Date: Thu Jun 23 04:40:13 2016 New Revision: 302114 URL: https://svnweb.freebsd.org/changeset/base/302114 Log: MFC 300480,300481,300486 300480 hyperv: Move Hypercall setup to an early place. It does not belong to the vmbus. While I'm here rework the Hypercall setup, e.g. use busdma(9) and avoid bit fields. Discussed with: Jun Su MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6445 300481 hyperv/vmbus: Declare Synic message and event w/ proper types Avoid ugly casts. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6446 300486 hyperv/vmbus: Get rid of vmbus_devp While I'm here, nuke useless print in vmbus_attach(). MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6447 Added: stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h - copied unchanged from r300480, head/sys/dev/hyperv/vmbus/hyperv_reg.h Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 03:25:18 2016 (r302113) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 04:40:13 2016 (r302114) @@ -336,8 +336,8 @@ vmbus_event_proc(struct vmbus_softc *sc, { hv_vmbus_synic_event_flags *event; - event = ((hv_vmbus_synic_event_flags *) - hv_vmbus_g_context.syn_ic_event_page[cpu]) + HV_VMBUS_MESSAGE_SINT; + event = hv_vmbus_g_context.syn_ic_event_page[cpu] + + HV_VMBUS_MESSAGE_SINT; /* * On Host with Win8 or above, the event page can be checked directly @@ -352,8 +352,8 @@ vmbus_event_proc_compat(struct vmbus_sof { hv_vmbus_synic_event_flags *event; - event = ((hv_vmbus_synic_event_flags *) - hv_vmbus_g_context.syn_ic_event_page[cpu]) + HV_VMBUS_MESSAGE_SINT; + event = hv_vmbus_g_context.syn_ic_event_page[cpu] + + HV_VMBUS_MESSAGE_SINT; if (atomic_testandclear_int(&event->flags32[0], 0)) { vmbus_event_flags_proc( Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 03:25:18 2016 (r302113) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 04:40:13 2016 (r302114) @@ -43,8 +43,9 @@ __FBSDID("$FreeBSD$"); #include #include - -#include "hv_vmbus_priv.h" +#include +#include +#include #define HV_NANOSECONDS_PER_SEC 1000000000L @@ -79,6 +80,13 @@ __FBSDID("$FreeBSD$"); (((uint64_t)__FreeBSD_version) << 16) | \ ((uint64_t)((id) & 0x00ffff))) +struct hypercall_ctx { + void *hc_addr; + struct hyperv_dma hc_dma; +}; + +static struct hypercall_ctx hypercall_context; + static u_int hv_get_timecount(struct timecounter *tc); u_int hyperv_features; @@ -92,7 +100,6 @@ static u_int hyperv_features3; */ hv_vmbus_context hv_vmbus_g_context = { .syn_ic_initialized = FALSE, - .hypercall_page = NULL, }; static struct timecounter hv_timecounter = { @@ -116,7 +123,7 @@ hv_vmbus_do_hypercall(uint64_t control, uint64_t hv_status = 0; uint64_t input_address = (input) ? hv_get_phys_addr(input) : 0; uint64_t output_address = (output) ? hv_get_phys_addr(output) : 0; - volatile void* hypercall_page = hv_vmbus_g_context.hypercall_page; + volatile void *hypercall_page = hypercall_context.hc_addr; __asm__ __volatile__ ("mov %0, %%r8" : : "r" (output_address): "r8"); __asm__ __volatile__ ("call *%3" : "=a"(hv_status): @@ -134,7 +141,7 @@ hv_vmbus_do_hypercall(uint64_t control, uint64_t output_address = (output) ? hv_get_phys_addr(output) : 0; uint32_t output_address_high = output_address >> 32; uint32_t output_address_low = output_address & 0xFFFFFFFF; - volatile void* hypercall_page = hv_vmbus_g_context.hypercall_page; + volatile void *hypercall_page = hypercall_context.hc_addr; __asm__ __volatile__ ("call *%8" : "=d"(hv_status_high), "=a"(hv_status_low) : "d" (control_high), @@ -147,84 +154,6 @@ hv_vmbus_do_hypercall(uint64_t control, } /** - * @brief Main initialization routine. - * - * This routine must be called - * before any other routines in here are called - */ -int -hv_vmbus_init(void) -{ - hv_vmbus_x64_msr_hypercall_contents hypercall_msr; - void* virt_addr = NULL; - - memset( - hv_vmbus_g_context.syn_ic_event_page, - 0, - sizeof(hv_vmbus_handle) * MAXCPU); - - memset( - hv_vmbus_g_context.syn_ic_msg_page, - 0, - sizeof(hv_vmbus_handle) * MAXCPU); - - if (vm_guest != VM_GUEST_HV) - goto cleanup; - - /* - * See if the hypercall page is already set - */ - hypercall_msr.as_uint64_t = rdmsr(HV_X64_MSR_HYPERCALL); - virt_addr = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO); - - hypercall_msr.u.enable = 1; - hypercall_msr.u.guest_physical_address = - (hv_get_phys_addr(virt_addr) >> PAGE_SHIFT); - wrmsr(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64_t); - - /* - * Confirm that hypercall page did get set up - */ - hypercall_msr.as_uint64_t = 0; - hypercall_msr.as_uint64_t = rdmsr(HV_X64_MSR_HYPERCALL); - - if (!hypercall_msr.u.enable) - goto cleanup; - - hv_vmbus_g_context.hypercall_page = virt_addr; - - return (0); - - cleanup: - if (virt_addr != NULL) { - if (hypercall_msr.u.enable) { - hypercall_msr.as_uint64_t = 0; - wrmsr(HV_X64_MSR_HYPERCALL, - hypercall_msr.as_uint64_t); - } - - free(virt_addr, M_DEVBUF); - } - return (ENOTSUP); -} - -/** - * @brief Cleanup routine, called normally during driver unloading or exiting - */ -void -hv_vmbus_cleanup(void) -{ - if (hv_vmbus_g_context.hypercall_page != NULL) { - hv_vmbus_x64_msr_hypercall_contents hypercall_msr; - - hypercall_msr.as_uint64_t = 0; - wrmsr(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64_t); - free(hv_vmbus_g_context.hypercall_page, M_DEVBUF); - hv_vmbus_g_context.hypercall_page = NULL; - } -} - -/** * @brief Post a message using the hypervisor message IPC. * (This involves a hypercall.) */ @@ -304,9 +233,6 @@ hv_vmbus_synic_init(void *arg) cpu = PCPU_GET(cpuid); - if (hv_vmbus_g_context.hypercall_page == NULL) - return; - /* * TODO: Check the version */ @@ -537,3 +463,74 @@ hyperv_init(void *dummy __unused) } SYSINIT(hyperv_initialize, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, hyperv_init, NULL); + +static void +hypercall_memfree(void) +{ + hyperv_dmamem_free(&hypercall_context.hc_dma, + hypercall_context.hc_addr); + hypercall_context.hc_addr = NULL; +} + +static void +hypercall_create(void *arg __unused) +{ + uint64_t hc, hc_orig; + + 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; + } + + /* Get the 'reserved' bits, which requires preservation. */ + hc_orig = rdmsr(MSR_HV_HYPERCALL); + + /* + * Setup the Hypercall page. + * + * NOTE: 'reserved' bits MUST be preserved. + */ + hc = ((hypercall_context.hc_dma.hv_paddr >> PAGE_SHIFT) << + MSR_HV_HYPERCALL_PGSHIFT) | + (hc_orig & MSR_HV_HYPERCALL_RSVD_MASK) | + MSR_HV_HYPERCALL_ENABLE; + wrmsr(MSR_HV_HYPERCALL, hc); + + /* + * Confirm that Hypercall page did get setup. + */ + hc = rdmsr(MSR_HV_HYPERCALL); + if ((hc & MSR_HV_HYPERCALL_ENABLE) == 0) { + printf("hyperv: Hypercall setup failed\n"); + hypercall_memfree(); + /* Can't perform any Hyper-V specific actions */ + vm_guest = VM_GUEST_VM; + return; + } + if (bootverbose) + printf("hyperv: Hypercall created\n"); +} +SYSINIT(hypercall_ctor, SI_SUB_DRIVERS, SI_ORDER_FIRST, hypercall_create, NULL); + +static void +hypercall_destroy(void *arg __unused) +{ + if (hypercall_context.hc_addr == NULL) + return; + + /* Disable Hypercall */ + wrmsr(MSR_HV_HYPERCALL, 0); + hypercall_memfree(); + + if (bootverbose) + printf("hyperv: Hypercall destroyed\n"); +} +SYSUNINIT(hypercall_dtor, SI_SUB_DRIVERS, SI_ORDER_FIRST, hypercall_destroy, + NULL); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 03:25:18 2016 (r302113) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 04:40:13 2016 (r302114) @@ -68,7 +68,6 @@ __FBSDID("$FreeBSD$"); struct vmbus_softc *vmbus_sc; -static device_t vmbus_devp; static int vmbus_inited; static hv_setup_args setup_args; /* only CPU 0 supported at this time */ @@ -79,8 +78,9 @@ vmbus_msg_task(void *arg __unused, int p { hv_vmbus_message *msg; - msg = ((hv_vmbus_message *)hv_vmbus_g_context.syn_ic_msg_page[curcpu]) + + msg = hv_vmbus_g_context.syn_ic_msg_page[curcpu] + HV_VMBUS_MESSAGE_SINT; + for (;;) { const hv_vmbus_channel_msg_table_entry *entry; hv_vmbus_channel_msg_header *hdr; @@ -134,9 +134,8 @@ static inline int hv_vmbus_isr(struct trapframe *frame) { struct vmbus_softc *sc = vmbus_get_softc(); + hv_vmbus_message *msg, *msg_base; int cpu = curcpu; - hv_vmbus_message *msg; - void *page_addr; /* * The Windows team has advised that we check for events @@ -146,8 +145,8 @@ hv_vmbus_isr(struct trapframe *frame) sc->vmbus_event_proc(sc, cpu); /* Check if there are actual msgs to be process */ - page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu]; - msg = ((hv_vmbus_message *)page_addr) + HV_VMBUS_TIMER_SINT; + msg_base = hv_vmbus_g_context.syn_ic_msg_page[cpu]; + msg = msg_base + HV_VMBUS_TIMER_SINT; /* we call eventtimer process the message */ if (msg->header.message_type == HV_MESSAGE_TIMER_EXPIRED) { @@ -178,7 +177,7 @@ hv_vmbus_isr(struct trapframe *frame) } } - msg = ((hv_vmbus_message *)page_addr) + HV_VMBUS_MESSAGE_SINT; + msg = msg_base + HV_VMBUS_MESSAGE_SINT; if (msg->header.message_type != HV_MESSAGE_TYPE_NONE) { taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], &hv_vmbus_g_context.hv_msg_task[cpu]); @@ -324,7 +323,7 @@ hv_vmbus_child_device_register(struct hv printf("VMBUS: Class ID: %s\n", name); } - child = device_add_child(vmbus_devp, NULL, -1); + child = device_add_child(vmbus_get_device(), NULL, -1); child_dev->device = child; device_set_ivars(child, child_dev); @@ -340,7 +339,7 @@ hv_vmbus_child_device_unregister(struct * device_add_child() */ mtx_lock(&Giant); - ret = device_delete_child(vmbus_devp, child_dev->device); + ret = device_delete_child(vmbus_get_device(), child_dev->device); mtx_unlock(&Giant); return(ret); } @@ -349,7 +348,7 @@ static int vmbus_probe(device_t dev) { if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL || - device_get_unit(dev) != 0) + device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV) return (ENXIO); device_set_desc(dev, "Hyper-V Vmbus"); @@ -455,14 +454,6 @@ vmbus_bus_init(void) vmbus_inited = 1; sc = vmbus_get_softc(); - ret = hv_vmbus_init(); - - if (ret) { - if(bootverbose) - printf("Error VMBUS: Hypervisor Initialization Failed!\n"); - return (ret); - } - /* * Find a free IDT slot for vmbus callback. */ @@ -472,6 +463,7 @@ vmbus_bus_init(void) if(bootverbose) printf("Error VMBUS: Cannot find free IDT slot for " "vmbus callback!\n"); + ret = ENXIO; goto cleanup; } @@ -559,8 +551,8 @@ vmbus_bus_init(void) hv_vmbus_request_channel_offers(); vmbus_scan(); - bus_generic_attach(vmbus_devp); - device_printf(vmbus_devp, "device scan, probe and attach done\n"); + bus_generic_attach(sc->vmbus_dev); + device_printf(sc->vmbus_dev, "device scan, probe and attach done\n"); return (ret); @@ -585,8 +577,6 @@ vmbus_bus_init(void) vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector); cleanup: - hv_vmbus_cleanup(); - return (ret); } @@ -598,11 +588,8 @@ vmbus_event_proc_dummy(struct vmbus_soft static int vmbus_attach(device_t dev) { - if(bootverbose) - device_printf(dev, "VMBUS: attach dev: %p\n", dev); - - vmbus_devp = dev; vmbus_sc = device_get_softc(dev); + vmbus_sc->vmbus_dev = dev; /* * Event processing logic will be configured: @@ -655,8 +642,6 @@ vmbus_detach(device_t dev) free(setup_args.page_buffers[i], M_DEVBUF); } - hv_vmbus_cleanup(); - /* remove swi */ CPU_FOREACH(i) { if (hv_vmbus_g_context.hv_event_queue[i] != NULL) { Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 03:25:18 2016 (r302113) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 04:40:13 2016 (r302114) @@ -197,12 +197,14 @@ enum { #define HV_HYPERCALL_PARAM_ALIGN sizeof(uint64_t) +struct vmbus_message; +union vmbus_event_flags; + typedef struct { - void* hypercall_page; hv_bool_uint8_t syn_ic_initialized; - hv_vmbus_handle syn_ic_msg_page[MAXCPU]; - hv_vmbus_handle syn_ic_event_page[MAXCPU]; + struct vmbus_message *syn_ic_msg_page[MAXCPU]; + union vmbus_event_flags *syn_ic_event_page[MAXCPU]; /* * For FreeBSD cpuid to Hyper-V vcpuid mapping. */ @@ -304,7 +306,7 @@ typedef struct { /* * Define synthetic interrupt controller message format */ -typedef struct { +typedef struct vmbus_message { hv_vmbus_msg_header header; union { uint64_t payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; @@ -579,7 +581,7 @@ typedef struct { /* * Define the synthetic interrupt controller event flags format */ -typedef union { +typedef union vmbus_event_flags { uint8_t flags8[HV_EVENT_FLAGS_BYTE_COUNT]; uint32_t flags32[HV_EVENT_FLAGS_DWORD_COUNT]; unsigned long flagsul[HV_EVENT_FLAGS_ULONG_COUNT]; @@ -722,8 +724,6 @@ hv_vmbus_channel* hv_vmbus_allocate_chan void hv_vmbus_free_vmbus_channel(hv_vmbus_channel *channel); int hv_vmbus_request_channel_offers(void); void hv_vmbus_release_unattached_channels(void); -int hv_vmbus_init(void); -void hv_vmbus_cleanup(void); uint16_t hv_vmbus_post_msg_via_msg_ipc( hv_vmbus_connection_id connection_id, Copied: stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h (from r300480, head/sys/dev/hyperv/vmbus/hyperv_reg.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Thu Jun 23 04:40:13 2016 (r302114, copy of r300480, head/sys/dev/hyperv/vmbus/hyperv_reg.h) @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _HYPERV_REG_H_ +#define _HYPERV_REG_H_ + +#define MSR_HV_HYPERCALL 0x40000001 +#define MSR_HV_HYPERCALL_ENABLE 0x0001ULL +#define MSR_HV_HYPERCALL_RSVD_MASK 0x0ffeULL +#define MSR_HV_HYPERCALL_PGSHIFT 12 + +#endif /* !_HYPERV_REG_H_ */ Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 03:25:18 2016 (r302113) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 04:40:13 2016 (r302114) @@ -38,6 +38,7 @@ struct vmbus_pcpu_data { struct vmbus_softc { void (*vmbus_event_proc)(struct vmbus_softc *, int); struct vmbus_pcpu_data vmbus_pcpu[MAXCPU]; + device_t vmbus_dev; }; extern struct vmbus_softc *vmbus_sc; @@ -48,6 +49,12 @@ vmbus_get_softc(void) return vmbus_sc; } +static __inline device_t +vmbus_get_device(void) +{ + return vmbus_sc->vmbus_dev; +} + #define VMBUS_SC_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field #define VMBUS_SC_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field #define VMBUS_PCPU_GET(field, cpu) \ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 05:08:19 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8C266B72554; Thu, 23 Jun 2016 05:08:19 +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 3D02E22A9; Thu, 23 Jun 2016 05:08:19 +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 u5N58IEw071534; Thu, 23 Jun 2016 05:08:18 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N58Il7071530; Thu, 23 Jun 2016 05:08:18 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230508.u5N58Il7071530@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 05:08:18 +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: r302115 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 05:08:19 -0000 Author: sephe Date: Thu Jun 23 05:08:17 2016 New Revision: 302115 URL: https://svnweb.freebsd.org/changeset/base/302115 Log: MFC 300487 hyperv/vmbus: Move IDT vector to vmbus_softc Prepare to get rid of the hv_setup_arg. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6449 Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 04:40:13 2016 (r302114) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 05:08:17 2016 (r302115) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #define HV_NANOSECONDS_PER_SEC 1000000000L @@ -220,8 +221,8 @@ hv_vmbus_signal_event(void *con_id) */ void hv_vmbus_synic_init(void *arg) - { + struct vmbus_softc *sc = vmbus_get_softc(); int cpu; uint64_t hv_vcpu_index; hv_vmbus_synic_simp simp; @@ -266,7 +267,7 @@ hv_vmbus_synic_init(void *arg) /*HV_SHARED_SINT_IDT_VECTOR + 0x20; */ shared_sint.as_uint64_t = 0; - shared_sint.u.vector = setup_args->vector; + shared_sint.u.vector = sc->vmbus_idtvec; shared_sint.u.masked = FALSE; shared_sint.u.auto_eoi = TRUE; Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 04:40:13 2016 (r302114) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:08:17 2016 (r302115) @@ -455,26 +455,18 @@ vmbus_bus_init(void) sc = vmbus_get_softc(); /* - * Find a free IDT slot for vmbus callback. + * Find a free IDT vector for vmbus messages/events. */ - hv_vmbus_g_context.hv_cb_vector = vmbus_vector_alloc(); - - if (hv_vmbus_g_context.hv_cb_vector == 0) { - if(bootverbose) - printf("Error VMBUS: Cannot find free IDT slot for " - "vmbus callback!\n"); + sc->vmbus_idtvec = vmbus_vector_alloc(); + if (sc->vmbus_idtvec == 0) { + device_printf(sc->vmbus_dev, "cannot find free IDT vector\n"); ret = ENXIO; goto cleanup; } - - if(bootverbose) - printf("VMBUS: vmbus callback vector %d\n", - hv_vmbus_g_context.hv_cb_vector); - - /* - * Notify the hypervisor of our vector. - */ - setup_args.vector = hv_vmbus_g_context.hv_cb_vector; + if(bootverbose) { + device_printf(sc->vmbus_dev, "vmbus IDT vector %d\n", + sc->vmbus_idtvec); + } CPU_FOREACH(j) { snprintf(buf, sizeof(buf), "cpu%d:hyperv", j); @@ -574,7 +566,7 @@ vmbus_bus_init(void) } } - vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector); + vmbus_vector_free(sc->vmbus_idtvec); cleanup: return (ret); @@ -630,6 +622,7 @@ vmbus_sysinit(void *arg __unused) static int vmbus_detach(device_t dev) { + struct vmbus_softc *sc = device_get_softc(dev); int i; hv_vmbus_release_unattached_channels(); @@ -650,7 +643,7 @@ vmbus_detach(device_t dev) } } - vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector); + vmbus_vector_free(sc->vmbus_idtvec); return (0); } Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 04:40:13 2016 (r302114) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 05:08:17 2016 (r302115) @@ -216,11 +216,6 @@ typedef struct { struct taskqueue *hv_event_queue[MAXCPU]; struct taskqueue *hv_msg_tq[MAXCPU]; struct task hv_msg_task[MAXCPU]; - /* - * Host use this vector to intrrupt guest for vmbus channel - * event and msg. - */ - unsigned int hv_cb_vector; } hv_vmbus_context; /* @@ -763,7 +758,6 @@ void hv_et_intr(struct trapframe*); void vmbus_scan(void); typedef struct { - unsigned int vector; void *page_buffers[2 * MAXCPU]; } hv_setup_args; Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 04:40:13 2016 (r302114) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:08:17 2016 (r302115) @@ -39,6 +39,7 @@ struct vmbus_softc { void (*vmbus_event_proc)(struct vmbus_softc *, int); struct vmbus_pcpu_data vmbus_pcpu[MAXCPU]; device_t vmbus_dev; + int vmbus_idtvec; }; extern struct vmbus_softc *vmbus_sc; From owner-svn-src-stable-10@freebsd.org Thu Jun 23 05:35:10 2016 Return-Path: Delivered-To: svn-src-stable-10@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 39C54B729AD; Thu, 23 Jun 2016 05:35:10 +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 F25642FF8; Thu, 23 Jun 2016 05:35:09 +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 u5N5Z9MT082715; Thu, 23 Jun 2016 05:35:09 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N5Z83I082710; Thu, 23 Jun 2016 05:35:08 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230535.u5N5Z83I082710@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 05:35:08 +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: r302116 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 05:35:10 -0000 Author: sephe Date: Thu Jun 23 05:35:08 2016 New Revision: 302116 URL: https://svnweb.freebsd.org/changeset/base/302116 Log: MFC 300565,300567,300568,300570,300571 300565 hyperv/vmbus: Move vmbus interrupt counter into vmbus softc MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6497 300567 hyperv/vmbus: Pass vmbus_softc and curcpu to hv_vmbus_isr() MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6498 300568 hyperv/busdma: Take BUS_DMA_ZERO into account MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6499 300570 hyperv/vmbus: Rename local variable and break long lines No functional changes. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6500 300571 hyperv/vmbus: Move SynIC setup/teardown from hyperv file to vmbus file Avoid unnecessary exposure. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6501 Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 05:08:17 2016 (r302115) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 05:35:08 2016 (r302116) @@ -216,132 +216,6 @@ hv_vmbus_signal_event(void *con_id) return (status); } -/** - * @brief hv_vmbus_synic_init - */ -void -hv_vmbus_synic_init(void *arg) -{ - struct vmbus_softc *sc = vmbus_get_softc(); - int cpu; - uint64_t hv_vcpu_index; - hv_vmbus_synic_simp simp; - hv_vmbus_synic_siefp siefp; - hv_vmbus_synic_scontrol sctrl; - hv_vmbus_synic_sint shared_sint; - uint64_t version; - hv_setup_args* setup_args = (hv_setup_args *)arg; - - cpu = PCPU_GET(cpuid); - - /* - * TODO: Check the version - */ - version = rdmsr(HV_X64_MSR_SVERSION); - - hv_vmbus_g_context.syn_ic_msg_page[cpu] = - setup_args->page_buffers[2 * cpu]; - hv_vmbus_g_context.syn_ic_event_page[cpu] = - setup_args->page_buffers[2 * cpu + 1]; - - /* - * Setup the Synic's message page - */ - - simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); - simp.u.simp_enabled = 1; - simp.u.base_simp_gpa = ((hv_get_phys_addr( - hv_vmbus_g_context.syn_ic_msg_page[cpu])) >> PAGE_SHIFT); - - wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); - - /* - * Setup the Synic's event page - */ - siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); - siefp.u.siefp_enabled = 1; - siefp.u.base_siefp_gpa = ((hv_get_phys_addr( - hv_vmbus_g_context.syn_ic_event_page[cpu])) >> PAGE_SHIFT); - - wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); - - /*HV_SHARED_SINT_IDT_VECTOR + 0x20; */ - shared_sint.as_uint64_t = 0; - shared_sint.u.vector = sc->vmbus_idtvec; - shared_sint.u.masked = FALSE; - shared_sint.u.auto_eoi = TRUE; - - wrmsr(HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT, - shared_sint.as_uint64_t); - - wrmsr(HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT, - shared_sint.as_uint64_t); - - /* Enable the global synic bit */ - sctrl.as_uint64_t = rdmsr(HV_X64_MSR_SCONTROL); - sctrl.u.enable = 1; - - wrmsr(HV_X64_MSR_SCONTROL, sctrl.as_uint64_t); - - hv_vmbus_g_context.syn_ic_initialized = TRUE; - - /* - * Set up the cpuid mapping from Hyper-V to FreeBSD. - * The array is indexed using FreeBSD cpuid. - */ - hv_vcpu_index = rdmsr(HV_X64_MSR_VP_INDEX); - hv_vmbus_g_context.hv_vcpu_index[cpu] = (uint32_t)hv_vcpu_index; - - return; -} - -/** - * @brief Cleanup routine for hv_vmbus_synic_init() - */ -void hv_vmbus_synic_cleanup(void *arg) -{ - hv_vmbus_synic_sint shared_sint; - hv_vmbus_synic_simp simp; - hv_vmbus_synic_siefp siefp; - - if (!hv_vmbus_g_context.syn_ic_initialized) - return; - - shared_sint.as_uint64_t = rdmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT); - - shared_sint.u.masked = 1; - - /* - * Disable the interrupt 0 - */ - wrmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT, - shared_sint.as_uint64_t); - - shared_sint.as_uint64_t = rdmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT); - - shared_sint.u.masked = 1; - - /* - * Disable the interrupt 1 - */ - wrmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT, - shared_sint.as_uint64_t); - simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); - simp.u.simp_enabled = 0; - simp.u.base_simp_gpa = 0; - - wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); - - siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); - siefp.u.siefp_enabled = 0; - siefp.u.base_siefp_gpa = 0; - - wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); -} static bool hyperv_identify(void) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:08:17 2016 (r302115) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:35:08 2016 (r302116) @@ -131,11 +131,9 @@ handled: * message to process - an event or a channel message. */ static inline int -hv_vmbus_isr(struct trapframe *frame) +hv_vmbus_isr(struct vmbus_softc *sc, struct trapframe *frame, int cpu) { - struct vmbus_softc *sc = vmbus_get_softc(); hv_vmbus_message *msg, *msg_base; - int cpu = curcpu; /* * The Windows team has advised that we check for events @@ -186,12 +184,11 @@ hv_vmbus_isr(struct trapframe *frame) return (FILTER_HANDLED); } -u_long *hv_vmbus_intr_cpu[MAXCPU]; - void hv_vector_handler(struct trapframe *trap_frame) { - int cpu; + struct vmbus_softc *sc = vmbus_get_softc(); + int cpu = curcpu; /* * Disable preemption. @@ -201,10 +198,9 @@ hv_vector_handler(struct trapframe *trap /* * Do a little interrupt counting. */ - cpu = PCPU_GET(cpuid); - (*hv_vmbus_intr_cpu[cpu])++; + (*VMBUS_SC_PCPU_GET(sc, intr_cnt, cpu))++; - hv_vmbus_isr(trap_frame); + hv_vmbus_isr(sc, trap_frame, cpu); /* * Enable preemption. @@ -212,6 +208,126 @@ hv_vector_handler(struct trapframe *trap critical_exit(); } +static void +vmbus_synic_setup(void *arg) +{ + struct vmbus_softc *sc = vmbus_get_softc(); + int cpu; + uint64_t hv_vcpu_index; + hv_vmbus_synic_simp simp; + hv_vmbus_synic_siefp siefp; + hv_vmbus_synic_scontrol sctrl; + hv_vmbus_synic_sint shared_sint; + uint64_t version; + hv_setup_args* setup_args = (hv_setup_args *)arg; + + cpu = PCPU_GET(cpuid); + + /* + * TODO: Check the version + */ + version = rdmsr(HV_X64_MSR_SVERSION); + + hv_vmbus_g_context.syn_ic_msg_page[cpu] = + setup_args->page_buffers[2 * cpu]; + hv_vmbus_g_context.syn_ic_event_page[cpu] = + setup_args->page_buffers[2 * cpu + 1]; + + /* + * Setup the Synic's message page + */ + + simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); + simp.u.simp_enabled = 1; + simp.u.base_simp_gpa = ((hv_get_phys_addr( + hv_vmbus_g_context.syn_ic_msg_page[cpu])) >> PAGE_SHIFT); + + wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); + + /* + * Setup the Synic's event page + */ + siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); + siefp.u.siefp_enabled = 1; + siefp.u.base_siefp_gpa = ((hv_get_phys_addr( + hv_vmbus_g_context.syn_ic_event_page[cpu])) >> PAGE_SHIFT); + + wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); + + /*HV_SHARED_SINT_IDT_VECTOR + 0x20; */ + shared_sint.as_uint64_t = 0; + shared_sint.u.vector = sc->vmbus_idtvec; + shared_sint.u.masked = FALSE; + shared_sint.u.auto_eoi = TRUE; + + wrmsr(HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT, + shared_sint.as_uint64_t); + + wrmsr(HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT, + shared_sint.as_uint64_t); + + /* Enable the global synic bit */ + sctrl.as_uint64_t = rdmsr(HV_X64_MSR_SCONTROL); + sctrl.u.enable = 1; + + wrmsr(HV_X64_MSR_SCONTROL, sctrl.as_uint64_t); + + hv_vmbus_g_context.syn_ic_initialized = TRUE; + + /* + * Set up the cpuid mapping from Hyper-V to FreeBSD. + * The array is indexed using FreeBSD cpuid. + */ + hv_vcpu_index = rdmsr(HV_X64_MSR_VP_INDEX); + hv_vmbus_g_context.hv_vcpu_index[cpu] = (uint32_t)hv_vcpu_index; +} + +static void +vmbus_synic_teardown(void *arg) +{ + hv_vmbus_synic_sint shared_sint; + hv_vmbus_synic_simp simp; + hv_vmbus_synic_siefp siefp; + + if (!hv_vmbus_g_context.syn_ic_initialized) + return; + + shared_sint.as_uint64_t = rdmsr( + HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT); + + shared_sint.u.masked = 1; + + /* + * Disable the interrupt 0 + */ + wrmsr( + HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT, + shared_sint.as_uint64_t); + + shared_sint.as_uint64_t = rdmsr( + HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT); + + shared_sint.u.masked = 1; + + /* + * Disable the interrupt 1 + */ + wrmsr( + HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT, + shared_sint.as_uint64_t); + simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); + simp.u.simp_enabled = 0; + simp.u.base_simp_gpa = 0; + + wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); + + siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); + siefp.u.siefp_enabled = 0; + siefp.u.base_siefp_gpa = 0; + + wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); +} + static int vmbus_read_ivar( device_t dev, @@ -444,7 +560,7 @@ static int vmbus_bus_init(void) { struct vmbus_softc *sc; - int i, j, n, ret; + int i, n, ret, cpu; char buf[MAXCOMLEN + 1]; cpuset_t cpu_mask; @@ -468,54 +584,63 @@ vmbus_bus_init(void) sc->vmbus_idtvec); } - CPU_FOREACH(j) { - snprintf(buf, sizeof(buf), "cpu%d:hyperv", j); - intrcnt_add(buf, &hv_vmbus_intr_cpu[j]); + CPU_FOREACH(cpu) { + snprintf(buf, sizeof(buf), "cpu%d:hyperv", cpu); + intrcnt_add(buf, VMBUS_SC_PCPU_PTR(sc, intr_cnt, cpu)); for (i = 0; i < 2; i++) - setup_args.page_buffers[2 * j + i] = NULL; + setup_args.page_buffers[2 * cpu + i] = NULL; } /* * Per cpu setup. */ - CPU_FOREACH(j) { + CPU_FOREACH(cpu) { struct task cpuset_task; /* * Setup taskqueue to handle events */ - hv_vmbus_g_context.hv_event_queue[j] = taskqueue_create_fast("hyperv event", M_WAITOK, - taskqueue_thread_enqueue, &hv_vmbus_g_context.hv_event_queue[j]); - taskqueue_start_threads(&hv_vmbus_g_context.hv_event_queue[j], 1, PI_NET, - "hvevent%d", j); - - CPU_SETOF(j, &cpu_mask); - TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask); - taskqueue_enqueue(hv_vmbus_g_context.hv_event_queue[j], &cpuset_task); - taskqueue_drain(hv_vmbus_g_context.hv_event_queue[j], &cpuset_task); + hv_vmbus_g_context.hv_event_queue[cpu] = + taskqueue_create_fast("hyperv event", M_WAITOK, + taskqueue_thread_enqueue, + &hv_vmbus_g_context.hv_event_queue[cpu]); + taskqueue_start_threads(&hv_vmbus_g_context.hv_event_queue[cpu], + 1, PI_NET, "hvevent%d", cpu); + + CPU_SETOF(cpu, &cpu_mask); + TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, + &cpu_mask); + taskqueue_enqueue(hv_vmbus_g_context.hv_event_queue[cpu], + &cpuset_task); + taskqueue_drain(hv_vmbus_g_context.hv_event_queue[cpu], + &cpuset_task); /* * Setup per-cpu tasks and taskqueues to handle msg. */ - hv_vmbus_g_context.hv_msg_tq[j] = taskqueue_create_fast( + hv_vmbus_g_context.hv_msg_tq[cpu] = taskqueue_create_fast( "hyperv msg", M_WAITOK, taskqueue_thread_enqueue, - &hv_vmbus_g_context.hv_msg_tq[j]); - taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[j], 1, PI_NET, - "hvmsg%d", j); - TASK_INIT(&hv_vmbus_g_context.hv_msg_task[j], 0, + &hv_vmbus_g_context.hv_msg_tq[cpu]); + taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[cpu], 1, + PI_NET, "hvmsg%d", cpu); + TASK_INIT(&hv_vmbus_g_context.hv_msg_task[cpu], 0, vmbus_msg_task, NULL); - CPU_SETOF(j, &cpu_mask); - TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask); - taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[j], &cpuset_task); - taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[j], &cpuset_task); + CPU_SETOF(cpu, &cpu_mask); + TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, + &cpu_mask); + taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], + &cpuset_task); + taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], + &cpuset_task); /* - * Prepare the per cpu msg and event pages to be called on each cpu. + * Prepare the per cpu msg and event pages to be called on + * each cpu. */ for(i = 0; i < 2; i++) { - setup_args.page_buffers[2 * j + i] = + setup_args.page_buffers[2 * cpu + i] = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO); } } @@ -524,7 +649,7 @@ vmbus_bus_init(void) printf("VMBUS: Calling smp_rendezvous, smp_started = %d\n", smp_started); - smp_rendezvous(NULL, hv_vmbus_synic_init, NULL, &setup_args); + smp_rendezvous(NULL, vmbus_synic_setup, NULL, &setup_args); /* * Connect to VMBus in the root partition @@ -559,10 +684,10 @@ vmbus_bus_init(void) /* * remove swi and vmbus callback vector; */ - CPU_FOREACH(j) { - if (hv_vmbus_g_context.hv_event_queue[j] != NULL) { - taskqueue_free(hv_vmbus_g_context.hv_event_queue[j]); - hv_vmbus_g_context.hv_event_queue[j] = NULL; + CPU_FOREACH(cpu) { + if (hv_vmbus_g_context.hv_event_queue[cpu] != NULL) { + taskqueue_free(hv_vmbus_g_context.hv_event_queue[cpu]); + hv_vmbus_g_context.hv_event_queue[cpu] = NULL; } } @@ -628,7 +753,7 @@ vmbus_detach(device_t dev) hv_vmbus_release_unattached_channels(); hv_vmbus_disconnect(); - smp_rendezvous(NULL, hv_vmbus_synic_cleanup, NULL, NULL); + smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); for(i = 0; i < 2 * MAXCPU; i++) { if (setup_args.page_buffers[i] != NULL) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 05:08:17 2016 (r302115) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 05:35:08 2016 (r302116) @@ -727,8 +727,6 @@ uint16_t hv_vmbus_post_msg_via_msg_ipc( size_t payload_size); uint16_t hv_vmbus_signal_event(void *con_id); -void hv_vmbus_synic_init(void *irq_arg); -void hv_vmbus_synic_cleanup(void *arg); struct hv_device* hv_vmbus_child_device_create( hv_guid device_type, Modified: stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c Thu Jun 23 05:08:17 2016 (r302115) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_busdma.c Thu Jun 23 05:35:08 2016 (r302116) @@ -35,7 +35,7 @@ __FBSDID("$FreeBSD$"); #include -#define HYPERV_DMA_WAITMASK (BUS_DMA_WAITOK | BUS_DMA_NOWAIT) +#define HYPERV_DMA_MASK (BUS_DMA_WAITOK | BUS_DMA_NOWAIT | BUS_DMA_ZERO) void hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs, int nseg, int error) @@ -73,7 +73,7 @@ hyperv_dmamem_alloc(bus_dma_tag_t parent return NULL; error = bus_dmamem_alloc(dma->hv_dtag, &ret, - (flags & HYPERV_DMA_WAITMASK) | BUS_DMA_COHERENT, &dma->hv_dmap); + (flags & HYPERV_DMA_MASK) | BUS_DMA_COHERENT, &dma->hv_dmap); if (error) { bus_dma_tag_destroy(dma->hv_dtag); return NULL; Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:08:17 2016 (r302115) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:35:08 2016 (r302116) @@ -33,6 +33,7 @@ struct vmbus_pcpu_data { int event_flag_cnt; /* # of event flags */ + u_long *intr_cnt; } __aligned(CACHE_LINE_SIZE); struct vmbus_softc { From owner-svn-src-stable-10@freebsd.org Thu Jun 23 05:51:58 2016 Return-Path: Delivered-To: svn-src-stable-10@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 ED7FFB72E8E; Thu, 23 Jun 2016 05:51:58 +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 C9B4E1CF2; Thu, 23 Jun 2016 05:51:58 +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 u5N5pw2j089252; Thu, 23 Jun 2016 05:51:58 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N5pvrx089248; Thu, 23 Jun 2016 05:51:57 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230551.u5N5pvrx089248@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 05:51:57 +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: r302118 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 05:51:59 -0000 Author: sephe Date: Thu Jun 23 05:51:57 2016 New Revision: 302118 URL: https://svnweb.freebsd.org/changeset/base/302118 Log: MFC 300572 hyperv/vmbus: Use busdma(9) for messages and event flags And - Move message and event flags to vmbus_softc per-cpu data. - Get rid of hv_setup_arg, which serves no purpose now. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6502 Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 05:41:46 2016 (r302117) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 05:51:57 2016 (r302118) @@ -336,13 +336,11 @@ vmbus_event_proc(struct vmbus_softc *sc, { hv_vmbus_synic_event_flags *event; - event = hv_vmbus_g_context.syn_ic_event_page[cpu] + - HV_VMBUS_MESSAGE_SINT; - /* * On Host with Win8 or above, the event page can be checked directly * to get the id of the channel that has the pending interrupt. */ + event = VMBUS_SC_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; vmbus_event_flags_proc(event->flagsul, VMBUS_SC_PCPU_GET(sc, event_flag_cnt, cpu)); } @@ -352,9 +350,7 @@ vmbus_event_proc_compat(struct vmbus_sof { hv_vmbus_synic_event_flags *event; - event = hv_vmbus_g_context.syn_ic_event_page[cpu] + - HV_VMBUS_MESSAGE_SINT; - + event = VMBUS_SC_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; if (atomic_testandclear_int(&event->flags32[0], 0)) { vmbus_event_flags_proc( hv_vmbus_g_connection.recv_interrupt_page, Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:41:46 2016 (r302117) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:51:57 2016 (r302118) @@ -69,18 +69,16 @@ __FBSDID("$FreeBSD$"); struct vmbus_softc *vmbus_sc; static int vmbus_inited; -static hv_setup_args setup_args; /* only CPU 0 supported at this time */ static char *vmbus_ids[] = { "VMBUS", NULL }; static void -vmbus_msg_task(void *arg __unused, int pending __unused) +vmbus_msg_task(void *xsc, int pending __unused) { + struct vmbus_softc *sc = xsc; hv_vmbus_message *msg; - msg = hv_vmbus_g_context.syn_ic_msg_page[curcpu] + - HV_VMBUS_MESSAGE_SINT; - + msg = VMBUS_SC_PCPU_GET(sc, message, curcpu) + HV_VMBUS_MESSAGE_SINT; for (;;) { const hv_vmbus_channel_msg_table_entry *entry; hv_vmbus_channel_msg_header *hdr; @@ -143,7 +141,7 @@ hv_vmbus_isr(struct vmbus_softc *sc, str sc->vmbus_event_proc(sc, cpu); /* Check if there are actual msgs to be process */ - msg_base = hv_vmbus_g_context.syn_ic_msg_page[cpu]; + msg_base = VMBUS_SC_PCPU_GET(sc, message, cpu); msg = msg_base + HV_VMBUS_TIMER_SINT; /* we call eventtimer process the message */ @@ -209,7 +207,7 @@ hv_vector_handler(struct trapframe *trap } static void -vmbus_synic_setup(void *arg) +vmbus_synic_setup(void *arg __unused) { struct vmbus_softc *sc = vmbus_get_softc(); int cpu; @@ -219,7 +217,6 @@ vmbus_synic_setup(void *arg) hv_vmbus_synic_scontrol sctrl; hv_vmbus_synic_sint shared_sint; uint64_t version; - hv_setup_args* setup_args = (hv_setup_args *)arg; cpu = PCPU_GET(cpuid); @@ -228,19 +225,13 @@ vmbus_synic_setup(void *arg) */ version = rdmsr(HV_X64_MSR_SVERSION); - hv_vmbus_g_context.syn_ic_msg_page[cpu] = - setup_args->page_buffers[2 * cpu]; - hv_vmbus_g_context.syn_ic_event_page[cpu] = - setup_args->page_buffers[2 * cpu + 1]; - /* * Setup the Synic's message page */ - simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); simp.u.simp_enabled = 1; - simp.u.base_simp_gpa = ((hv_get_phys_addr( - hv_vmbus_g_context.syn_ic_msg_page[cpu])) >> PAGE_SHIFT); + simp.u.base_simp_gpa = + VMBUS_SC_PCPU_GET(sc, message_dma.hv_paddr, cpu) >> PAGE_SHIFT; wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); @@ -249,8 +240,8 @@ vmbus_synic_setup(void *arg) */ siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); siefp.u.siefp_enabled = 1; - siefp.u.base_siefp_gpa = ((hv_get_phys_addr( - hv_vmbus_g_context.syn_ic_event_page[cpu])) >> PAGE_SHIFT); + siefp.u.base_siefp_gpa = + VMBUS_SC_PCPU_GET(sc, event_flag_dma.hv_paddr, cpu) >> PAGE_SHIFT; wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); @@ -328,6 +319,47 @@ vmbus_synic_teardown(void *arg) wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); } +static void +vmbus_dma_alloc(struct vmbus_softc *sc) +{ + int cpu; + + CPU_FOREACH(cpu) { + /* + * Per-cpu messages and event flags. + */ + VMBUS_SC_PCPU_GET(sc, message, cpu) = hyperv_dmamem_alloc( + bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, + VMBUS_SC_PCPU_PTR(sc, message_dma, cpu), + BUS_DMA_WAITOK | BUS_DMA_ZERO); + VMBUS_SC_PCPU_GET(sc, event_flag, cpu) = hyperv_dmamem_alloc( + bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, + VMBUS_SC_PCPU_PTR(sc, event_flag_dma, cpu), + BUS_DMA_WAITOK | BUS_DMA_ZERO); + } +} + +static void +vmbus_dma_free(struct vmbus_softc *sc) +{ + int cpu; + + CPU_FOREACH(cpu) { + if (VMBUS_SC_PCPU_GET(sc, message, cpu) != NULL) { + hyperv_dmamem_free( + VMBUS_SC_PCPU_PTR(sc, message_dma, cpu), + VMBUS_SC_PCPU_GET(sc, message, cpu)); + VMBUS_SC_PCPU_GET(sc, message, cpu) = NULL; + } + if (VMBUS_SC_PCPU_GET(sc, event_flag, cpu) != NULL) { + hyperv_dmamem_free( + VMBUS_SC_PCPU_PTR(sc, event_flag_dma, cpu), + VMBUS_SC_PCPU_GET(sc, event_flag, cpu)); + VMBUS_SC_PCPU_GET(sc, event_flag, cpu) = NULL; + } + } +} + static int vmbus_read_ivar( device_t dev, @@ -560,7 +592,7 @@ static int vmbus_bus_init(void) { struct vmbus_softc *sc; - int i, n, ret, cpu; + int ret, cpu; char buf[MAXCOMLEN + 1]; cpuset_t cpu_mask; @@ -587,9 +619,6 @@ vmbus_bus_init(void) CPU_FOREACH(cpu) { snprintf(buf, sizeof(buf), "cpu%d:hyperv", cpu); intrcnt_add(buf, VMBUS_SC_PCPU_PTR(sc, intr_cnt, cpu)); - - for (i = 0; i < 2; i++) - setup_args.page_buffers[2 * cpu + i] = NULL; } /* @@ -623,9 +652,9 @@ vmbus_bus_init(void) "hyperv msg", M_WAITOK, taskqueue_thread_enqueue, &hv_vmbus_g_context.hv_msg_tq[cpu]); taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[cpu], 1, - PI_NET, "hvmsg%d", cpu); + PI_NET, "hvmsg%d", cpu); TASK_INIT(&hv_vmbus_g_context.hv_msg_task[cpu], 0, - vmbus_msg_task, NULL); + vmbus_msg_task, sc); CPU_SETOF(cpu, &cpu_mask); TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, @@ -634,22 +663,17 @@ vmbus_bus_init(void) &cpuset_task); taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], &cpuset_task); - - /* - * Prepare the per cpu msg and event pages to be called on - * each cpu. - */ - for(i = 0; i < 2; i++) { - setup_args.page_buffers[2 * cpu + i] = - malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO); - } } + /* + * Allocate vmbus DMA stuffs. + */ + vmbus_dma_alloc(sc); + if (bootverbose) printf("VMBUS: Calling smp_rendezvous, smp_started = %d\n", smp_started); - - smp_rendezvous(NULL, vmbus_synic_setup, NULL, &setup_args); + smp_rendezvous(NULL, vmbus_synic_setup, NULL, NULL); /* * Connect to VMBus in the root partition @@ -673,13 +697,8 @@ vmbus_bus_init(void) return (ret); - cleanup1: - /* - * Free pages alloc'ed - */ - for (n = 0; n < 2 * MAXCPU; n++) - if (setup_args.page_buffers[n] != NULL) - free(setup_args.page_buffers[n], M_DEVBUF); +cleanup1: + vmbus_dma_free(sc); /* * remove swi and vmbus callback vector; @@ -755,10 +774,7 @@ vmbus_detach(device_t dev) smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); - for(i = 0; i < 2 * MAXCPU; i++) { - if (setup_args.page_buffers[i] != NULL) - free(setup_args.page_buffers[i], M_DEVBUF); - } + vmbus_dma_free(sc); /* remove swi */ CPU_FOREACH(i) { Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 05:41:46 2016 (r302117) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 05:51:57 2016 (r302118) @@ -203,8 +203,6 @@ union vmbus_event_flags; typedef struct { hv_bool_uint8_t syn_ic_initialized; - struct vmbus_message *syn_ic_msg_page[MAXCPU]; - union vmbus_event_flags *syn_ic_event_page[MAXCPU]; /* * For FreeBSD cpuid to Hyper-V vcpuid mapping. */ @@ -755,8 +753,4 @@ void hv_et_intr(struct trapframe*); /* Wait for device creation */ void vmbus_scan(void); -typedef struct { - void *page_buffers[2 * MAXCPU]; -} hv_setup_args; - #endif /* __HYPERV_PRIV_H__ */ Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:41:46 2016 (r302117) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:51:57 2016 (r302118) @@ -30,10 +30,18 @@ #define _VMBUS_VAR_H_ #include +#include +#include struct vmbus_pcpu_data { - int event_flag_cnt; /* # of event flags */ - u_long *intr_cnt; + u_long *intr_cnt; /* Hyper-V interrupt counter */ + struct vmbus_message *message; /* shared messages */ + int event_flag_cnt; /* # of event flags */ + union vmbus_event_flags *event_flag; /* shared event flags */ + + /* Rarely used fields */ + struct hyperv_dma message_dma; /* busdma glue */ + struct hyperv_dma event_flag_dma; /* busdma glue */ } __aligned(CACHE_LINE_SIZE); struct vmbus_softc { From owner-svn-src-stable-10@freebsd.org Thu Jun 23 05:56:06 2016 Return-Path: Delivered-To: svn-src-stable-10@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 310C0B73044; Thu, 23 Jun 2016 05:56:06 +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 0D08120FD; Thu, 23 Jun 2016 05:56:05 +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 u5N5u5OD090099; Thu, 23 Jun 2016 05:56:05 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N5u584090096; Thu, 23 Jun 2016 05:56:05 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230556.u5N5u584090096@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 05:56:05 +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: r302119 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 05:56:06 -0000 Author: sephe Date: Thu Jun 23 05:56:04 2016 New Revision: 302119 URL: https://svnweb.freebsd.org/changeset/base/302119 Log: MFC 300573 hyperv/vmbus: Git rid of sc version of pcpu data extraction macro MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6503 Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 05:51:57 2016 (r302118) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 05:56:04 2016 (r302119) @@ -340,9 +340,9 @@ vmbus_event_proc(struct vmbus_softc *sc, * On Host with Win8 or above, the event page can be checked directly * to get the id of the channel that has the pending interrupt. */ - event = VMBUS_SC_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; + event = VMBUS_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; vmbus_event_flags_proc(event->flagsul, - VMBUS_SC_PCPU_GET(sc, event_flag_cnt, cpu)); + VMBUS_PCPU_GET(sc, event_flag_cnt, cpu)); } void @@ -350,7 +350,7 @@ vmbus_event_proc_compat(struct vmbus_sof { hv_vmbus_synic_event_flags *event; - event = VMBUS_SC_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; + event = VMBUS_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; if (atomic_testandclear_int(&event->flags32[0], 0)) { vmbus_event_flags_proc( hv_vmbus_g_connection.recv_interrupt_page, @@ -418,7 +418,8 @@ vmbus_on_channel_open(const struct hv_vm int flag_cnt; flag_cnt = (chan->offer_msg.child_rel_id / HV_CHANNEL_ULONG_LEN) + 1; - flag_cnt_ptr = VMBUS_PCPU_PTR(event_flag_cnt, chan->target_cpu); + flag_cnt_ptr = VMBUS_PCPU_PTR(vmbus_get_softc(), event_flag_cnt, + chan->target_cpu); for (;;) { int old_flag_cnt; Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:51:57 2016 (r302118) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:56:04 2016 (r302119) @@ -78,7 +78,7 @@ vmbus_msg_task(void *xsc, int pending __ struct vmbus_softc *sc = xsc; hv_vmbus_message *msg; - msg = VMBUS_SC_PCPU_GET(sc, message, curcpu) + HV_VMBUS_MESSAGE_SINT; + msg = VMBUS_PCPU_GET(sc, message, curcpu) + HV_VMBUS_MESSAGE_SINT; for (;;) { const hv_vmbus_channel_msg_table_entry *entry; hv_vmbus_channel_msg_header *hdr; @@ -141,7 +141,7 @@ hv_vmbus_isr(struct vmbus_softc *sc, str sc->vmbus_event_proc(sc, cpu); /* Check if there are actual msgs to be process */ - msg_base = VMBUS_SC_PCPU_GET(sc, message, cpu); + msg_base = VMBUS_PCPU_GET(sc, message, cpu); msg = msg_base + HV_VMBUS_TIMER_SINT; /* we call eventtimer process the message */ @@ -196,7 +196,7 @@ hv_vector_handler(struct trapframe *trap /* * Do a little interrupt counting. */ - (*VMBUS_SC_PCPU_GET(sc, intr_cnt, cpu))++; + (*VMBUS_PCPU_GET(sc, intr_cnt, cpu))++; hv_vmbus_isr(sc, trap_frame, cpu); @@ -231,7 +231,7 @@ vmbus_synic_setup(void *arg __unused) simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); simp.u.simp_enabled = 1; simp.u.base_simp_gpa = - VMBUS_SC_PCPU_GET(sc, message_dma.hv_paddr, cpu) >> PAGE_SHIFT; + VMBUS_PCPU_GET(sc, message_dma.hv_paddr, cpu) >> PAGE_SHIFT; wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); @@ -241,7 +241,7 @@ vmbus_synic_setup(void *arg __unused) siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); siefp.u.siefp_enabled = 1; siefp.u.base_siefp_gpa = - VMBUS_SC_PCPU_GET(sc, event_flag_dma.hv_paddr, cpu) >> PAGE_SHIFT; + VMBUS_PCPU_GET(sc, event_flag_dma.hv_paddr, cpu) >> PAGE_SHIFT; wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); @@ -328,13 +328,13 @@ vmbus_dma_alloc(struct vmbus_softc *sc) /* * Per-cpu messages and event flags. */ - VMBUS_SC_PCPU_GET(sc, message, cpu) = hyperv_dmamem_alloc( + VMBUS_PCPU_GET(sc, message, cpu) = hyperv_dmamem_alloc( bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, - VMBUS_SC_PCPU_PTR(sc, message_dma, cpu), + VMBUS_PCPU_PTR(sc, message_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); - VMBUS_SC_PCPU_GET(sc, event_flag, cpu) = hyperv_dmamem_alloc( + VMBUS_PCPU_GET(sc, event_flag, cpu) = hyperv_dmamem_alloc( bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, - VMBUS_SC_PCPU_PTR(sc, event_flag_dma, cpu), + VMBUS_PCPU_PTR(sc, event_flag_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); } } @@ -345,17 +345,17 @@ vmbus_dma_free(struct vmbus_softc *sc) int cpu; CPU_FOREACH(cpu) { - if (VMBUS_SC_PCPU_GET(sc, message, cpu) != NULL) { + if (VMBUS_PCPU_GET(sc, message, cpu) != NULL) { hyperv_dmamem_free( - VMBUS_SC_PCPU_PTR(sc, message_dma, cpu), - VMBUS_SC_PCPU_GET(sc, message, cpu)); - VMBUS_SC_PCPU_GET(sc, message, cpu) = NULL; + VMBUS_PCPU_PTR(sc, message_dma, cpu), + VMBUS_PCPU_GET(sc, message, cpu)); + VMBUS_PCPU_GET(sc, message, cpu) = NULL; } - if (VMBUS_SC_PCPU_GET(sc, event_flag, cpu) != NULL) { + if (VMBUS_PCPU_GET(sc, event_flag, cpu) != NULL) { hyperv_dmamem_free( - VMBUS_SC_PCPU_PTR(sc, event_flag_dma, cpu), - VMBUS_SC_PCPU_GET(sc, event_flag, cpu)); - VMBUS_SC_PCPU_GET(sc, event_flag, cpu) = NULL; + VMBUS_PCPU_PTR(sc, event_flag_dma, cpu), + VMBUS_PCPU_GET(sc, event_flag, cpu)); + VMBUS_PCPU_GET(sc, event_flag, cpu) = NULL; } } } @@ -618,7 +618,7 @@ vmbus_bus_init(void) CPU_FOREACH(cpu) { snprintf(buf, sizeof(buf), "cpu%d:hyperv", cpu); - intrcnt_add(buf, VMBUS_SC_PCPU_PTR(sc, intr_cnt, cpu)); + intrcnt_add(buf, VMBUS_PCPU_PTR(sc, intr_cnt, cpu)); } /* Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:51:57 2016 (r302118) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 05:56:04 2016 (r302119) @@ -65,12 +65,8 @@ vmbus_get_device(void) return vmbus_sc->vmbus_dev; } -#define VMBUS_SC_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field -#define VMBUS_SC_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field -#define VMBUS_PCPU_GET(field, cpu) \ - VMBUS_SC_PCPU_GET(vmbus_get_softc(), field, (cpu)) -#define VMBUS_PCPU_PTR(field, cpu) \ - VMBUS_SC_PCPU_PTR(vmbus_get_softc(), field, (cpu)) +#define VMBUS_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field +#define VMBUS_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field void vmbus_on_channel_open(const struct hv_vmbus_channel *); void vmbus_event_proc(struct vmbus_softc *, int); From owner-svn-src-stable-10@freebsd.org Thu Jun 23 06:18:34 2016 Return-Path: Delivered-To: svn-src-stable-10@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 20C8BB734F2; Thu, 23 Jun 2016 06:18:34 +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 D4EDB2D99; Thu, 23 Jun 2016 06:18:33 +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 u5N6IXe9097904; Thu, 23 Jun 2016 06:18:33 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N6IXwH097903; Thu, 23 Jun 2016 06:18:33 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230618.u5N6IXwH097903@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 06:18:33 +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: r302120 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 06:18:34 -0000 Author: sephe Date: Thu Jun 23 06:18:32 2016 New Revision: 302120 URL: https://svnweb.freebsd.org/changeset/base/302120 Log: MFC 300574 hyperv/vmbus: Factor out functions for vmbus interrupt set/teardown This paves way for further cleanup and fix. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6505 Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 05:56:04 2016 (r302119) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 06:18:32 2016 (r302120) @@ -72,6 +72,8 @@ static int vmbus_inited; static char *vmbus_ids[] = { "VMBUS", NULL }; +extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback); + static void vmbus_msg_task(void *xsc, int pending __unused) { @@ -360,6 +362,165 @@ vmbus_dma_free(struct vmbus_softc *sc) } } +/** + * @brief Find a free IDT slot and setup the interrupt handler. + */ +static int +vmbus_vector_alloc(void) +{ + int vector; + uintptr_t func; + struct gate_descriptor *ip; + + /* + * Search backwards form the highest IDT vector available for use + * as vmbus channel callback vector. We install 'hv_vmbus_callback' + * handler at that vector and use it to interrupt vcpus. + */ + vector = APIC_SPURIOUS_INT; + while (--vector >= APIC_IPI_INTS) { + ip = &idt[vector]; + func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); + if (func == (uintptr_t)&IDTVEC(rsvd)) { +#ifdef __i386__ + setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYS386IGT, + SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); +#else + setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYSIGT, + SEL_KPL, 0); +#endif + + return (vector); + } + } + return (0); +} + +/** + * @brief Restore the IDT slot to rsvd. + */ +static void +vmbus_vector_free(int vector) +{ + uintptr_t func; + struct gate_descriptor *ip; + + if (vector == 0) + return; + + KASSERT(vector >= APIC_IPI_INTS && vector < APIC_SPURIOUS_INT, + ("invalid vector %d", vector)); + + ip = &idt[vector]; + func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); + KASSERT(func == (uintptr_t)&IDTVEC(hv_vmbus_callback), + ("invalid vector %d", vector)); + + setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0); +} + +static void +vmbus_cpuset_setthread_task(void *xmask, int pending __unused) +{ + cpuset_t *mask = xmask; + int error; + + error = cpuset_setthread(curthread->td_tid, mask); + if (error) { + panic("curthread=%ju: can't pin; error=%d", + (uintmax_t)curthread->td_tid, error); + } +} + +static int +vmbus_intr_setup(struct vmbus_softc *sc) +{ + int cpu; + + /* + * Find a free IDT vector for vmbus messages/events. + */ + sc->vmbus_idtvec = vmbus_vector_alloc(); + if (sc->vmbus_idtvec == 0) { + device_printf(sc->vmbus_dev, "cannot find free IDT vector\n"); + return ENXIO; + } + if(bootverbose) { + device_printf(sc->vmbus_dev, "vmbus IDT vector %d\n", + sc->vmbus_idtvec); + } + + CPU_FOREACH(cpu) { + char buf[MAXCOMLEN + 1]; + + snprintf(buf, sizeof(buf), "cpu%d:hyperv", cpu); + intrcnt_add(buf, VMBUS_PCPU_PTR(sc, intr_cnt, cpu)); + } + + /* + * Per cpu setup. + */ + CPU_FOREACH(cpu) { + struct task cpuset_task; + cpuset_t cpu_mask; + + /* + * Setup taskqueue to handle events + */ + hv_vmbus_g_context.hv_event_queue[cpu] = + taskqueue_create_fast("hyperv event", M_WAITOK, + taskqueue_thread_enqueue, + &hv_vmbus_g_context.hv_event_queue[cpu]); + taskqueue_start_threads(&hv_vmbus_g_context.hv_event_queue[cpu], + 1, PI_NET, "hvevent%d", cpu); + + CPU_SETOF(cpu, &cpu_mask); + TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, + &cpu_mask); + taskqueue_enqueue(hv_vmbus_g_context.hv_event_queue[cpu], + &cpuset_task); + taskqueue_drain(hv_vmbus_g_context.hv_event_queue[cpu], + &cpuset_task); + + /* + * Setup per-cpu tasks and taskqueues to handle msg. + */ + hv_vmbus_g_context.hv_msg_tq[cpu] = taskqueue_create_fast( + "hyperv msg", M_WAITOK, taskqueue_thread_enqueue, + &hv_vmbus_g_context.hv_msg_tq[cpu]); + taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[cpu], 1, + PI_NET, "hvmsg%d", cpu); + TASK_INIT(&hv_vmbus_g_context.hv_msg_task[cpu], 0, + vmbus_msg_task, sc); + + CPU_SETOF(cpu, &cpu_mask); + TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, + &cpu_mask); + taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], + &cpuset_task); + taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], + &cpuset_task); + } + return 0; +} + +static void +vmbus_intr_teardown(struct vmbus_softc *sc) +{ + int cpu; + + /* + * remove swi and vmbus callback vector; + */ + CPU_FOREACH(cpu) { + if (hv_vmbus_g_context.hv_event_queue[cpu] != NULL) { + taskqueue_free(hv_vmbus_g_context.hv_event_queue[cpu]); + hv_vmbus_g_context.hv_event_queue[cpu] = NULL; + } + } + vmbus_vector_free(sc->vmbus_idtvec); +} + static int vmbus_read_ivar( device_t dev, @@ -504,78 +665,6 @@ vmbus_probe(device_t dev) return (BUS_PROBE_DEFAULT); } -extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback); - -/** - * @brief Find a free IDT slot and setup the interrupt handler. - */ -static int -vmbus_vector_alloc(void) -{ - int vector; - uintptr_t func; - struct gate_descriptor *ip; - - /* - * Search backwards form the highest IDT vector available for use - * as vmbus channel callback vector. We install 'hv_vmbus_callback' - * handler at that vector and use it to interrupt vcpus. - */ - vector = APIC_SPURIOUS_INT; - while (--vector >= APIC_IPI_INTS) { - ip = &idt[vector]; - func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); - if (func == (uintptr_t)&IDTVEC(rsvd)) { -#ifdef __i386__ - setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYS386IGT, - SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); -#else - setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYSIGT, - SEL_KPL, 0); -#endif - - return (vector); - } - } - return (0); -} - -/** - * @brief Restore the IDT slot to rsvd. - */ -static void -vmbus_vector_free(int vector) -{ - uintptr_t func; - struct gate_descriptor *ip; - - if (vector == 0) - return; - - KASSERT(vector >= APIC_IPI_INTS && vector < APIC_SPURIOUS_INT, - ("invalid vector %d", vector)); - - ip = &idt[vector]; - func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); - KASSERT(func == (uintptr_t)&IDTVEC(hv_vmbus_callback), - ("invalid vector %d", vector)); - - setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0); -} - -static void -vmbus_cpuset_setthread_task(void *xmask, int pending __unused) -{ - cpuset_t *mask = xmask; - int error; - - error = cpuset_setthread(curthread->td_tid, mask); - if (error) { - panic("curthread=%ju: can't pin; error=%d", - (uintmax_t)curthread->td_tid, error); - } -} - /** * @brief Main vmbus driver initialization routine. * @@ -592,9 +681,7 @@ static int vmbus_bus_init(void) { struct vmbus_softc *sc; - int ret, cpu; - char buf[MAXCOMLEN + 1]; - cpuset_t cpu_mask; + int ret; if (vmbus_inited) return (0); @@ -603,70 +690,14 @@ vmbus_bus_init(void) sc = vmbus_get_softc(); /* - * Find a free IDT vector for vmbus messages/events. + * Setup interrupt. */ - sc->vmbus_idtvec = vmbus_vector_alloc(); - if (sc->vmbus_idtvec == 0) { - device_printf(sc->vmbus_dev, "cannot find free IDT vector\n"); - ret = ENXIO; + ret = vmbus_intr_setup(sc); + if (ret != 0) goto cleanup; - } - if(bootverbose) { - device_printf(sc->vmbus_dev, "vmbus IDT vector %d\n", - sc->vmbus_idtvec); - } - - CPU_FOREACH(cpu) { - snprintf(buf, sizeof(buf), "cpu%d:hyperv", cpu); - intrcnt_add(buf, VMBUS_PCPU_PTR(sc, intr_cnt, cpu)); - } - - /* - * Per cpu setup. - */ - CPU_FOREACH(cpu) { - struct task cpuset_task; - - /* - * Setup taskqueue to handle events - */ - hv_vmbus_g_context.hv_event_queue[cpu] = - taskqueue_create_fast("hyperv event", M_WAITOK, - taskqueue_thread_enqueue, - &hv_vmbus_g_context.hv_event_queue[cpu]); - taskqueue_start_threads(&hv_vmbus_g_context.hv_event_queue[cpu], - 1, PI_NET, "hvevent%d", cpu); - - CPU_SETOF(cpu, &cpu_mask); - TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, - &cpu_mask); - taskqueue_enqueue(hv_vmbus_g_context.hv_event_queue[cpu], - &cpuset_task); - taskqueue_drain(hv_vmbus_g_context.hv_event_queue[cpu], - &cpuset_task); - - /* - * Setup per-cpu tasks and taskqueues to handle msg. - */ - hv_vmbus_g_context.hv_msg_tq[cpu] = taskqueue_create_fast( - "hyperv msg", M_WAITOK, taskqueue_thread_enqueue, - &hv_vmbus_g_context.hv_msg_tq[cpu]); - taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[cpu], 1, - PI_NET, "hvmsg%d", cpu); - TASK_INIT(&hv_vmbus_g_context.hv_msg_task[cpu], 0, - vmbus_msg_task, sc); - - CPU_SETOF(cpu, &cpu_mask); - TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, - &cpu_mask); - taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], - &cpuset_task); - taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], - &cpuset_task); - } /* - * Allocate vmbus DMA stuffs. + * Allocate DMA stuffs. */ vmbus_dma_alloc(sc); @@ -681,7 +712,7 @@ vmbus_bus_init(void) ret = hv_vmbus_connect(); if (ret != 0) - goto cleanup1; + goto cleanup; if (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008 || hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7) @@ -697,22 +728,10 @@ vmbus_bus_init(void) return (ret); -cleanup1: +cleanup: vmbus_dma_free(sc); + vmbus_intr_teardown(sc); - /* - * remove swi and vmbus callback vector; - */ - CPU_FOREACH(cpu) { - if (hv_vmbus_g_context.hv_event_queue[cpu] != NULL) { - taskqueue_free(hv_vmbus_g_context.hv_event_queue[cpu]); - hv_vmbus_g_context.hv_event_queue[cpu] = NULL; - } - } - - vmbus_vector_free(sc->vmbus_idtvec); - - cleanup: return (ret); } @@ -767,7 +786,6 @@ static int vmbus_detach(device_t dev) { struct vmbus_softc *sc = device_get_softc(dev); - int i; hv_vmbus_release_unattached_channels(); hv_vmbus_disconnect(); @@ -775,16 +793,7 @@ vmbus_detach(device_t dev) smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); vmbus_dma_free(sc); - - /* remove swi */ - CPU_FOREACH(i) { - if (hv_vmbus_g_context.hv_event_queue[i] != NULL) { - taskqueue_free(hv_vmbus_g_context.hv_event_queue[i]); - hv_vmbus_g_context.hv_event_queue[i] = NULL; - } - } - - vmbus_vector_free(sc->vmbus_idtvec); + vmbus_intr_teardown(sc); return (0); } From owner-svn-src-stable-10@freebsd.org Thu Jun 23 06:27:42 2016 Return-Path: Delivered-To: svn-src-stable-10@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 DB9F2B737B7; Thu, 23 Jun 2016 06:27:42 +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 9ECB716DE; Thu, 23 Jun 2016 06:27:42 +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 u5N6RfMx002809; Thu, 23 Jun 2016 06:27:41 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N6RfSw002808; Thu, 23 Jun 2016 06:27:41 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230627.u5N6RfSw002808@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 06:27:41 +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: r302122 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 06:27:43 -0000 Author: sephe Date: Thu Jun 23 06:27:41 2016 New Revision: 302122 URL: https://svnweb.freebsd.org/changeset/base/302122 Log: MFC 300576,300644 300576 hyperv/vmbus: Free message taskqueue during interrupt teardown MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6506 300644 hyperv/vmbus: Check hyperv_dmamem_alloc return value Though it is highly unlikely this function would fail w/ BUS_DMA_WAITOK, we had better to check its return value; better safe then sorry here. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6518 Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 06:22:48 2016 (r302121) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 06:27:41 2016 (r302122) @@ -321,24 +321,34 @@ vmbus_synic_teardown(void *arg) wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); } -static void +static int vmbus_dma_alloc(struct vmbus_softc *sc) { int cpu; CPU_FOREACH(cpu) { + void *ptr; + /* * Per-cpu messages and event flags. */ - VMBUS_PCPU_GET(sc, message, cpu) = hyperv_dmamem_alloc( - bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, + ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), + PAGE_SIZE, 0, PAGE_SIZE, VMBUS_PCPU_PTR(sc, message_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); - VMBUS_PCPU_GET(sc, event_flag, cpu) = hyperv_dmamem_alloc( - bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, + if (ptr == NULL) + return ENOMEM; + VMBUS_PCPU_GET(sc, message, cpu) = ptr; + + ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), + PAGE_SIZE, 0, PAGE_SIZE, VMBUS_PCPU_PTR(sc, event_flag_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); + if (ptr == NULL) + return ENOMEM; + VMBUS_PCPU_GET(sc, event_flag, cpu) = ptr; } + return 0; } static void @@ -517,6 +527,12 @@ vmbus_intr_teardown(struct vmbus_softc * taskqueue_free(hv_vmbus_g_context.hv_event_queue[cpu]); hv_vmbus_g_context.hv_event_queue[cpu] = NULL; } + if (hv_vmbus_g_context.hv_msg_tq[cpu] != NULL) { + taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], + &hv_vmbus_g_context.hv_msg_task[cpu]); + taskqueue_free(hv_vmbus_g_context.hv_msg_tq[cpu]); + hv_vmbus_g_context.hv_msg_tq[cpu] = NULL; + } } vmbus_vector_free(sc->vmbus_idtvec); } @@ -699,7 +715,9 @@ vmbus_bus_init(void) /* * Allocate DMA stuffs. */ - vmbus_dma_alloc(sc); + ret = vmbus_dma_alloc(sc); + if (ret != 0) + goto cleanup; if (bootverbose) printf("VMBUS: Calling smp_rendezvous, smp_started = %d\n", From owner-svn-src-stable-10@freebsd.org Thu Jun 23 07:09:45 2016 Return-Path: Delivered-To: svn-src-stable-10@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 9402FB72062; Thu, 23 Jun 2016 07:09:45 +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 6BA8F2EC1; Thu, 23 Jun 2016 07:09:45 +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 u5N79iKm017895; Thu, 23 Jun 2016 07:09:44 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N79iwQ017894; Thu, 23 Jun 2016 07:09:44 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230709.u5N79iwQ017894@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 07:09:44 +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: r302124 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 07:09:45 -0000 Author: sephe Date: Thu Jun 23 07:09:44 2016 New Revision: 302124 URL: https://svnweb.freebsd.org/changeset/base/302124 Log: MFC 300645 hyperv/vmbus: Allocate/setup IDT vector after all ISR resources are ready And release IDT vector before releasing ISR resources on interrupt teardown path. We still have some work to do on the interrupt tearing down path. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6519 Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:01:54 2016 (r302123) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:09:44 2016 (r302124) @@ -447,35 +447,18 @@ vmbus_intr_setup(struct vmbus_softc *sc) { int cpu; - /* - * Find a free IDT vector for vmbus messages/events. - */ - sc->vmbus_idtvec = vmbus_vector_alloc(); - if (sc->vmbus_idtvec == 0) { - device_printf(sc->vmbus_dev, "cannot find free IDT vector\n"); - return ENXIO; - } - if(bootverbose) { - device_printf(sc->vmbus_dev, "vmbus IDT vector %d\n", - sc->vmbus_idtvec); - } - CPU_FOREACH(cpu) { + struct task cpuset_task; char buf[MAXCOMLEN + 1]; + cpuset_t cpu_mask; + /* Allocate an interrupt counter for Hyper-V interrupt */ snprintf(buf, sizeof(buf), "cpu%d:hyperv", cpu); intrcnt_add(buf, VMBUS_PCPU_PTR(sc, intr_cnt, cpu)); - } - - /* - * Per cpu setup. - */ - CPU_FOREACH(cpu) { - struct task cpuset_task; - cpuset_t cpu_mask; /* - * Setup taskqueue to handle events + * Setup taskqueue to handle events. Task will be per- + * channel. */ hv_vmbus_g_context.hv_event_queue[cpu] = taskqueue_create_fast("hyperv event", M_WAITOK, @@ -493,7 +476,7 @@ vmbus_intr_setup(struct vmbus_softc *sc) &cpuset_task); /* - * Setup per-cpu tasks and taskqueues to handle msg. + * Setup tasks and taskqueues to handle messages. */ hv_vmbus_g_context.hv_msg_tq[cpu] = taskqueue_create_fast( "hyperv msg", M_WAITOK, taskqueue_thread_enqueue, @@ -511,6 +494,20 @@ vmbus_intr_setup(struct vmbus_softc *sc) taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], &cpuset_task); } + + /* + * All Hyper-V ISR required resources are setup, now let's find a + * free IDT vector for Hyper-V ISR and set it up. + */ + sc->vmbus_idtvec = vmbus_vector_alloc(); + if (sc->vmbus_idtvec == 0) { + device_printf(sc->vmbus_dev, "cannot find free IDT vector\n"); + return ENXIO; + } + if(bootverbose) { + device_printf(sc->vmbus_dev, "vmbus IDT vector %d\n", + sc->vmbus_idtvec); + } return 0; } @@ -519,9 +516,8 @@ vmbus_intr_teardown(struct vmbus_softc * { int cpu; - /* - * remove swi and vmbus callback vector; - */ + vmbus_vector_free(sc->vmbus_idtvec); + CPU_FOREACH(cpu) { if (hv_vmbus_g_context.hv_event_queue[cpu] != NULL) { taskqueue_free(hv_vmbus_g_context.hv_event_queue[cpu]); @@ -534,7 +530,6 @@ vmbus_intr_teardown(struct vmbus_softc * hv_vmbus_g_context.hv_msg_tq[cpu] = NULL; } } - vmbus_vector_free(sc->vmbus_idtvec); } static int @@ -706,16 +701,16 @@ vmbus_bus_init(void) sc = vmbus_get_softc(); /* - * Setup interrupt. + * Allocate DMA stuffs. */ - ret = vmbus_intr_setup(sc); + ret = vmbus_dma_alloc(sc); if (ret != 0) goto cleanup; /* - * Allocate DMA stuffs. + * Setup interrupt. */ - ret = vmbus_dma_alloc(sc); + ret = vmbus_intr_setup(sc); if (ret != 0) goto cleanup; @@ -747,8 +742,8 @@ vmbus_bus_init(void) return (ret); cleanup: - vmbus_dma_free(sc); vmbus_intr_teardown(sc); + vmbus_dma_free(sc); return (ret); } @@ -810,8 +805,8 @@ vmbus_detach(device_t dev) smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); - vmbus_dma_free(sc); vmbus_intr_teardown(sc); + vmbus_dma_free(sc); return (0); } From owner-svn-src-stable-10@freebsd.org Thu Jun 23 07:36:04 2016 Return-Path: Delivered-To: svn-src-stable-10@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 AE227B72890; Thu, 23 Jun 2016 07:36:04 +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 85FD82111; Thu, 23 Jun 2016 07:36:04 +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 u5N7a3eZ030542; Thu, 23 Jun 2016 07:36:03 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N7a3AU030538; Thu, 23 Jun 2016 07:36:03 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230736.u5N7a3AU030538@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 07:36:03 +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: r302126 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 07:36:04 -0000 Author: sephe Date: Thu Jun 23 07:36:03 2016 New Revision: 302126 URL: https://svnweb.freebsd.org/changeset/base/302126 Log: MFC 300646 hyperv/vmbus: Move event/message taskqueue/task to vmbus softc MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6520 Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Thu Jun 23 07:12:22 2016 (r302125) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Thu Jun 23 07:36:03 2016 (r302126) @@ -202,7 +202,8 @@ hv_vmbus_channel_open( vmbus_on_channel_open(new_channel); - new_channel->rxq = hv_vmbus_g_context.hv_event_queue[new_channel->target_cpu]; + new_channel->rxq = VMBUS_PCPU_GET(vmbus_get_softc(), event_tq, + new_channel->target_cpu); TASK_INIT(&new_channel->channel_task, 0, VmbusProcessChannelEvent, new_channel); /* Allocate the ring buffer */ Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:12:22 2016 (r302125) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:36:03 2016 (r302126) @@ -177,8 +177,8 @@ hv_vmbus_isr(struct vmbus_softc *sc, str msg = msg_base + HV_VMBUS_MESSAGE_SINT; if (msg->header.message_type != HV_MESSAGE_TYPE_NONE) { - taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], - &hv_vmbus_g_context.hv_msg_task[cpu]); + taskqueue_enqueue(VMBUS_PCPU_GET(sc, message_tq, cpu), + VMBUS_PCPU_PTR(sc, message_task, cpu)); } return (FILTER_HANDLED); @@ -460,38 +460,37 @@ vmbus_intr_setup(struct vmbus_softc *sc) * Setup taskqueue to handle events. Task will be per- * channel. */ - hv_vmbus_g_context.hv_event_queue[cpu] = - taskqueue_create_fast("hyperv event", M_WAITOK, - taskqueue_thread_enqueue, - &hv_vmbus_g_context.hv_event_queue[cpu]); - taskqueue_start_threads(&hv_vmbus_g_context.hv_event_queue[cpu], + VMBUS_PCPU_GET(sc, event_tq, cpu) = taskqueue_create_fast( + "hyperv event", M_WAITOK, taskqueue_thread_enqueue, + VMBUS_PCPU_PTR(sc, event_tq, cpu)); + taskqueue_start_threads(VMBUS_PCPU_PTR(sc, event_tq, cpu), 1, PI_NET, "hvevent%d", cpu); CPU_SETOF(cpu, &cpu_mask); TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask); - taskqueue_enqueue(hv_vmbus_g_context.hv_event_queue[cpu], + taskqueue_enqueue(VMBUS_PCPU_GET(sc, event_tq, cpu), &cpuset_task); - taskqueue_drain(hv_vmbus_g_context.hv_event_queue[cpu], + taskqueue_drain(VMBUS_PCPU_GET(sc, event_tq, cpu), &cpuset_task); /* * Setup tasks and taskqueues to handle messages. */ - hv_vmbus_g_context.hv_msg_tq[cpu] = taskqueue_create_fast( + VMBUS_PCPU_GET(sc, message_tq, cpu) = taskqueue_create_fast( "hyperv msg", M_WAITOK, taskqueue_thread_enqueue, - &hv_vmbus_g_context.hv_msg_tq[cpu]); - taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[cpu], 1, + VMBUS_PCPU_PTR(sc, message_tq, cpu)); + taskqueue_start_threads(VMBUS_PCPU_PTR(sc, message_tq, cpu), 1, PI_NET, "hvmsg%d", cpu); - TASK_INIT(&hv_vmbus_g_context.hv_msg_task[cpu], 0, + TASK_INIT(VMBUS_PCPU_PTR(sc, message_task, cpu), 0, vmbus_msg_task, sc); CPU_SETOF(cpu, &cpu_mask); TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask); - taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu], + taskqueue_enqueue(VMBUS_PCPU_GET(sc, message_tq, cpu), &cpuset_task); - taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], + taskqueue_drain(VMBUS_PCPU_GET(sc, message_tq, cpu), &cpuset_task); } @@ -519,15 +518,15 @@ vmbus_intr_teardown(struct vmbus_softc * vmbus_vector_free(sc->vmbus_idtvec); CPU_FOREACH(cpu) { - if (hv_vmbus_g_context.hv_event_queue[cpu] != NULL) { - taskqueue_free(hv_vmbus_g_context.hv_event_queue[cpu]); - hv_vmbus_g_context.hv_event_queue[cpu] = NULL; + if (VMBUS_PCPU_GET(sc, event_tq, cpu) != NULL) { + taskqueue_free(VMBUS_PCPU_GET(sc, event_tq, cpu)); + VMBUS_PCPU_GET(sc, event_tq, cpu) = NULL; } - if (hv_vmbus_g_context.hv_msg_tq[cpu] != NULL) { - taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[cpu], - &hv_vmbus_g_context.hv_msg_task[cpu]); - taskqueue_free(hv_vmbus_g_context.hv_msg_tq[cpu]); - hv_vmbus_g_context.hv_msg_tq[cpu] = NULL; + if (VMBUS_PCPU_GET(sc, message_tq, cpu) != NULL) { + taskqueue_drain(VMBUS_PCPU_GET(sc, message_tq, cpu), + VMBUS_PCPU_PTR(sc, message_task, cpu)); + taskqueue_free(VMBUS_PCPU_GET(sc, message_tq, cpu)); + VMBUS_PCPU_GET(sc, message_tq, cpu) = NULL; } } } Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 07:12:22 2016 (r302125) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 07:36:03 2016 (r302126) @@ -207,13 +207,6 @@ typedef struct { * For FreeBSD cpuid to Hyper-V vcpuid mapping. */ uint32_t hv_vcpu_index[MAXCPU]; - /* - * Each cpu has its own software interrupt handler for channel - * event and msg handling. - */ - struct taskqueue *hv_event_queue[MAXCPU]; - struct taskqueue *hv_msg_tq[MAXCPU]; - struct task hv_msg_task[MAXCPU]; } hv_vmbus_context; /* Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 07:12:22 2016 (r302125) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 07:36:03 2016 (r302126) @@ -42,11 +42,16 @@ struct vmbus_pcpu_data { /* Rarely used fields */ struct hyperv_dma message_dma; /* busdma glue */ struct hyperv_dma event_flag_dma; /* busdma glue */ + struct taskqueue *event_tq; /* event taskq */ + struct taskqueue *message_tq; /* message taskq */ + struct task message_task; /* message task */ } __aligned(CACHE_LINE_SIZE); struct vmbus_softc { void (*vmbus_event_proc)(struct vmbus_softc *, int); struct vmbus_pcpu_data vmbus_pcpu[MAXCPU]; + + /* Rarely used fields */ device_t vmbus_dev; int vmbus_idtvec; }; From owner-svn-src-stable-10@freebsd.org Thu Jun 23 07:54:00 2016 Return-Path: Delivered-To: svn-src-stable-10@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 42707B72D5F; Thu, 23 Jun 2016 07:54:00 +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 F3C822A18; Thu, 23 Jun 2016 07:53:59 +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 u5N7rxKf038189; Thu, 23 Jun 2016 07:53:59 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N7rwcG038183; Thu, 23 Jun 2016 07:53:58 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230753.u5N7rwcG038183@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 07:53:58 +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: r302127 - in stable/10/sys/dev/hyperv: include 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 07:54:00 -0000 Author: sephe Date: Thu Jun 23 07:53:58 2016 New Revision: 302127 URL: https://svnweb.freebsd.org/changeset/base/302127 Log: MFC 300647,300650,300651,300652,300653 300647 hyperv/vmbus: Move vcpuid into vmbus softc per-cpu data MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6521 300650 hyperv/vmbus: Move two global flags into vmbus softc And pack them into one flag field. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6522 300651 hyperv/vmbus: Minor style and white space cleanup MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6523 300652 hyperv/vmbus: Pass vmbus softc to vmbus_synic_setup MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6527 300653 hyperv/vmbus: Nuke unnecessary MSR read MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6528 Modified: stable/10/sys/dev/hyperv/include/hyperv_busdma.h stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/include/hyperv_busdma.h ============================================================================== --- stable/10/sys/dev/hyperv/include/hyperv_busdma.h Thu Jun 23 07:36:03 2016 (r302126) +++ stable/10/sys/dev/hyperv/include/hyperv_busdma.h Thu Jun 23 07:53:58 2016 (r302127) @@ -29,6 +29,10 @@ #ifndef _HYPERV_BUSDMA_H_ #define _HYPERV_BUSDMA_H_ +#include +#include +#include + struct hyperv_dma { bus_addr_t hv_paddr; bus_dma_tag_t hv_dtag; Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Thu Jun 23 07:36:03 2016 (r302126) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Thu Jun 23 07:53:58 2016 (r302127) @@ -35,7 +35,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include "hv_vmbus_priv.h" +#include +#include /* * Internal functions @@ -310,7 +311,7 @@ vmbus_channel_cpu_set(struct hv_vmbus_ch } chan->target_cpu = cpu; - chan->target_vcpu = hv_vmbus_g_context.hv_vcpu_index[cpu]; + chan->target_vcpu = VMBUS_PCPU_GET(vmbus_get_softc(), vcpuid, cpu); if (bootverbose) { printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n", @@ -751,7 +752,7 @@ vmbus_select_outgoing_channel(struct hv_ return outgoing_channel; } - cur_vcpu = hv_vmbus_g_context.hv_vcpu_index[smp_pro_id]; + cur_vcpu = VMBUS_PCPU_GET(vmbus_get_softc(), vcpuid, smp_pro_id); TAILQ_FOREACH(new_channel, &primary->sc_list_anchor, sc_list_entry) { if (new_channel->state != HV_CHANNEL_OPENED_STATE){ Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 07:36:03 2016 (r302126) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 07:53:58 2016 (r302127) @@ -96,13 +96,6 @@ u_int hyperv_recommends; static u_int hyperv_pm_features; static u_int hyperv_features3; -/** - * Globals - */ -hv_vmbus_context hv_vmbus_g_context = { - .syn_ic_initialized = FALSE, -}; - static struct timecounter hv_timecounter = { hv_get_timecount, 0, ~0u, HV_NANOSECONDS_PER_SEC/100, "Hyper-V", HV_NANOSECONDS_PER_SEC/100 }; Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:36:03 2016 (r302126) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:53:58 2016 (r302127) @@ -68,8 +68,6 @@ __FBSDID("$FreeBSD$"); struct vmbus_softc *vmbus_sc; -static int vmbus_inited; - static char *vmbus_ids[] = { "VMBUS", NULL }; extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback); @@ -209,25 +207,18 @@ hv_vector_handler(struct trapframe *trap } static void -vmbus_synic_setup(void *arg __unused) +vmbus_synic_setup(void *xsc) { - struct vmbus_softc *sc = vmbus_get_softc(); + struct vmbus_softc *sc = xsc; int cpu; - uint64_t hv_vcpu_index; hv_vmbus_synic_simp simp; hv_vmbus_synic_siefp siefp; hv_vmbus_synic_scontrol sctrl; hv_vmbus_synic_sint shared_sint; - uint64_t version; cpu = PCPU_GET(cpuid); /* - * TODO: Check the version - */ - version = rdmsr(HV_X64_MSR_SVERSION); - - /* * Setup the Synic's message page */ simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); @@ -265,14 +256,11 @@ vmbus_synic_setup(void *arg __unused) wrmsr(HV_X64_MSR_SCONTROL, sctrl.as_uint64_t); - hv_vmbus_g_context.syn_ic_initialized = TRUE; - /* * Set up the cpuid mapping from Hyper-V to FreeBSD. * The array is indexed using FreeBSD cpuid. */ - hv_vcpu_index = rdmsr(HV_X64_MSR_VP_INDEX); - hv_vmbus_g_context.hv_vcpu_index[cpu] = (uint32_t)hv_vcpu_index; + VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(HV_X64_MSR_VP_INDEX); } static void @@ -282,9 +270,6 @@ vmbus_synic_teardown(void *arg) hv_vmbus_synic_simp simp; hv_vmbus_synic_siefp siefp; - if (!hv_vmbus_g_context.syn_ic_initialized) - return; - shared_sint.as_uint64_t = rdmsr( HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT); @@ -532,16 +517,11 @@ vmbus_intr_teardown(struct vmbus_softc * } static int -vmbus_read_ivar( - device_t dev, - device_t child, - int index, - uintptr_t* result) +vmbus_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) { struct hv_device *child_dev_ctx = device_get_ivars(child); switch (index) { - case HV_VMBUS_IVAR_TYPE: *result = (uintptr_t) &child_dev_ctx->class_id; return (0); @@ -559,14 +539,9 @@ vmbus_read_ivar( } static int -vmbus_write_ivar( - device_t dev, - device_t child, - int index, - uintptr_t value) +vmbus_write_ivar(device_t dev, device_t child, int index, uintptr_t value) { switch (index) { - case HV_VMBUS_IVAR_TYPE: case HV_VMBUS_IVAR_INSTANCE: case HV_VMBUS_IVAR_DEVCTX: @@ -597,19 +572,16 @@ vmbus_child_pnpinfo_str(device_t dev, de return (0); } -struct hv_device* -hv_vmbus_child_device_create( - hv_guid type, - hv_guid instance, - hv_vmbus_channel* channel) +struct hv_device * +hv_vmbus_child_device_create(hv_guid type, hv_guid instance, + hv_vmbus_channel *channel) { - hv_device* child_dev; + hv_device *child_dev; /* * Allocate the new child device */ - child_dev = malloc(sizeof(hv_device), M_DEVBUF, - M_WAITOK | M_ZERO); + child_dev = malloc(sizeof(hv_device), M_DEVBUF, M_WAITOK | M_ZERO); child_dev->channel = channel; memcpy(&child_dev->class_id, &type, sizeof(hv_guid)); @@ -690,14 +662,12 @@ vmbus_probe(device_t dev) static int vmbus_bus_init(void) { - struct vmbus_softc *sc; + struct vmbus_softc *sc = vmbus_get_softc(); int ret; - if (vmbus_inited) + if (sc->vmbus_flags & VMBUS_FLAG_ATTACHED) return (0); - - vmbus_inited = 1; - sc = vmbus_get_softc(); + sc->vmbus_flags |= VMBUS_FLAG_ATTACHED; /* * Allocate DMA stuffs. @@ -713,10 +683,13 @@ vmbus_bus_init(void) if (ret != 0) goto cleanup; + /* + * Setup SynIC. + */ if (bootverbose) - printf("VMBUS: Calling smp_rendezvous, smp_started = %d\n", - smp_started); - smp_rendezvous(NULL, vmbus_synic_setup, NULL, NULL); + device_printf(sc->vmbus_dev, "smp_started = %d\n", smp_started); + smp_rendezvous(NULL, vmbus_synic_setup, NULL, sc); + sc->vmbus_flags |= VMBUS_FLAG_SYNIC; /* * Connect to VMBus in the root partition @@ -802,7 +775,10 @@ vmbus_detach(device_t dev) hv_vmbus_release_unattached_channels(); hv_vmbus_disconnect(); - smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); + if (sc->vmbus_flags & VMBUS_FLAG_SYNIC) { + sc->vmbus_flags &= ~VMBUS_FLAG_SYNIC; + smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL); + } vmbus_intr_teardown(sc); vmbus_dma_free(sc); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 07:36:03 2016 (r302126) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 07:53:58 2016 (r302127) @@ -200,15 +200,6 @@ enum { struct vmbus_message; union vmbus_event_flags; -typedef struct { - hv_bool_uint8_t syn_ic_initialized; - - /* - * For FreeBSD cpuid to Hyper-V vcpuid mapping. - */ - uint32_t hv_vcpu_index[MAXCPU]; -} hv_vmbus_context; - /* * Define hypervisor message types */ @@ -640,7 +631,6 @@ typedef enum { * Global variables */ -extern hv_vmbus_context hv_vmbus_g_context; extern hv_vmbus_connection hv_vmbus_g_connection; extern u_int hyperv_features; Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 07:36:03 2016 (r302126) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 07:53:58 2016 (r302127) @@ -30,12 +30,12 @@ #define _VMBUS_VAR_H_ #include -#include #include struct vmbus_pcpu_data { u_long *intr_cnt; /* Hyper-V interrupt counter */ struct vmbus_message *message; /* shared messages */ + uint32_t vcpuid; /* virtual cpuid */ int event_flag_cnt; /* # of event flags */ union vmbus_event_flags *event_flag; /* shared event flags */ @@ -54,8 +54,12 @@ struct vmbus_softc { /* Rarely used fields */ device_t vmbus_dev; int vmbus_idtvec; + uint32_t vmbus_flags; /* see VMBUS_FLAG_ */ }; +#define VMBUS_FLAG_ATTACHED 0x0001 /* vmbus was attached */ +#define VMBUS_FLAG_SYNIC 0x0002 /* SynIC was setup */ + extern struct vmbus_softc *vmbus_sc; static __inline struct vmbus_softc * From owner-svn-src-stable-10@freebsd.org Thu Jun 23 08:09:46 2016 Return-Path: Delivered-To: svn-src-stable-10@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 48E97AC6259; Thu, 23 Jun 2016 08:09:46 +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 0AEBD11D4; Thu, 23 Jun 2016 08:09:45 +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 u5N89jkC042639; Thu, 23 Jun 2016 08:09:45 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N89jOX042636; Thu, 23 Jun 2016 08:09:45 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230809.u5N89jOX042636@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 08:09:45 +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: r302128 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 08:09:46 -0000 Author: sephe Date: Thu Jun 23 08:09:44 2016 New Revision: 302128 URL: https://svnweb.freebsd.org/changeset/base/302128 Log: MFC 300654,300655,300708 300654 hyperv/vmbus: Rework SynIC setup and teardown - Avoid bit fields. - Fix SINT setup (preserve required bits). MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6529 300655 hyperv: Preserve required bits when disable Hypercall MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6530 300708 hyperv: Rework guest id settings according to Hyper-V spec MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6553 Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 07:53:58 2016 (r302127) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 08:09:44 2016 (r302128) @@ -52,34 +52,24 @@ __FBSDID("$FreeBSD$"); #define HYPERV_INTERFACE 0x31237648 /* HV#1 */ -/* - * The guest OS needs to register the guest ID with the hypervisor. - * The guest ID is a 64 bit entity and the structure of this ID is - * specified in the Hyper-V specification: - * - * http://msdn.microsoft.com/en-us/library/windows/ - * hardware/ff542653%28v=vs.85%29.aspx - * - * While the current guideline does not specify how FreeBSD guest ID(s) - * need to be generated, our plan is to publish the guidelines for - * FreeBSD and other guest operating systems that currently are hosted - * on Hyper-V. The implementation here conforms to this yet - * unpublished guidelines. - * - * Bit(s) - * 63 - Indicates if the OS is Open Source or not; 1 is Open Source - * 62:56 - Os Type: FreeBSD is 0x02 - * 55:48 - Distro specific identification - * 47:16 - FreeBSD kernel version number - * 15:0 - Distro specific identification - */ -#define HYPERV_GUESTID_OSS (0x1ULL << 63) -#define HYPERV_GUESTID_FREEBSD (0x02ULL << 56) -#define HYPERV_GUESTID(id) \ - (HYPERV_GUESTID_OSS | HYPERV_GUESTID_FREEBSD | \ - (((uint64_t)(((id) & 0xff0000) >> 16)) << 48) |\ - (((uint64_t)__FreeBSD_version) << 16) | \ - ((uint64_t)((id) & 0x00ffff))) +#define HYPERV_FREEBSD_BUILD 0ULL +#define HYPERV_FREEBSD_VERSION ((uint64_t)__FreeBSD_version) +#define HYPERV_FREEBSD_OSID 0ULL + +#define MSR_HV_GUESTID_BUILD_FREEBSD \ + (HYPERV_FREEBSD_BUILD & MSR_HV_GUESTID_BUILD_MASK) +#define MSR_HV_GUESTID_VERSION_FREEBSD \ + ((HYPERV_FREEBSD_VERSION << MSR_HV_GUESTID_VERSION_SHIFT) & \ + MSR_HV_GUESTID_VERSION_MASK) +#define MSR_HV_GUESTID_OSID_FREEBSD \ + ((HYPERV_FREEBSD_OSID << MSR_HV_GUESTID_OSID_SHIFT) & \ + MSR_HV_GUESTID_OSID_MASK) + +#define MSR_HV_GUESTID_FREEBSD \ + (MSR_HV_GUESTID_BUILD_FREEBSD | \ + MSR_HV_GUESTID_VERSION_FREEBSD | \ + MSR_HV_GUESTID_OSID_FREEBSD | \ + MSR_HV_GUESTID_OSTYPE_FREEBSD) struct hypercall_ctx { void *hc_addr; @@ -321,8 +311,8 @@ hyperv_init(void *dummy __unused) return; } - /* Write guest id */ - wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_GUESTID(0)); + /* Set guest id */ + wrmsr(MSR_HV_GUEST_OS_ID, MSR_HV_GUESTID_FREEBSD); if (hyperv_features & HV_FEATURE_MSR_TIME_REFCNT) { /* Register virtual timecount */ @@ -390,11 +380,14 @@ SYSINIT(hypercall_ctor, SI_SUB_DRIVERS, static void hypercall_destroy(void *arg __unused) { + uint64_t hc; + if (hypercall_context.hc_addr == NULL) return; /* Disable Hypercall */ - wrmsr(MSR_HV_HYPERCALL, 0); + hc = rdmsr(MSR_HV_HYPERCALL); + wrmsr(MSR_HV_HYPERCALL, (hc & MSR_HV_HYPERCALL_RSVD_MASK)); hypercall_memfree(); if (bootverbose) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 07:53:58 2016 (r302127) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 08:09:44 2016 (r302128) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -210,100 +211,97 @@ static void vmbus_synic_setup(void *xsc) { struct vmbus_softc *sc = xsc; - int cpu; - hv_vmbus_synic_simp simp; - hv_vmbus_synic_siefp siefp; - hv_vmbus_synic_scontrol sctrl; - hv_vmbus_synic_sint shared_sint; - - cpu = PCPU_GET(cpuid); + int cpu = curcpu; + uint64_t val, orig; + uint32_t sint; /* - * Setup the Synic's message page + * Save virtual processor id. */ - simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); - simp.u.simp_enabled = 1; - simp.u.base_simp_gpa = - VMBUS_PCPU_GET(sc, message_dma.hv_paddr, cpu) >> PAGE_SHIFT; - - wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); + VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX); /* - * Setup the Synic's event page + * Setup the SynIC message. */ - siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); - siefp.u.siefp_enabled = 1; - siefp.u.base_siefp_gpa = - VMBUS_PCPU_GET(sc, event_flag_dma.hv_paddr, cpu) >> PAGE_SHIFT; + orig = rdmsr(MSR_HV_SIMP); + val = MSR_HV_SIMP_ENABLE | (orig & MSR_HV_SIMP_RSVD_MASK) | + ((VMBUS_PCPU_GET(sc, message_dma.hv_paddr, cpu) >> PAGE_SHIFT) << + MSR_HV_SIMP_PGSHIFT); + wrmsr(MSR_HV_SIMP, val); - wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); - - /*HV_SHARED_SINT_IDT_VECTOR + 0x20; */ - shared_sint.as_uint64_t = 0; - shared_sint.u.vector = sc->vmbus_idtvec; - shared_sint.u.masked = FALSE; - shared_sint.u.auto_eoi = TRUE; - - wrmsr(HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT, - shared_sint.as_uint64_t); + /* + * Setup the SynIC event flags. + */ + orig = rdmsr(MSR_HV_SIEFP); + val = MSR_HV_SIEFP_ENABLE | (orig & MSR_HV_SIEFP_RSVD_MASK) | + ((VMBUS_PCPU_GET(sc, event_flag_dma.hv_paddr, cpu) >> PAGE_SHIFT) << + MSR_HV_SIEFP_PGSHIFT); + wrmsr(MSR_HV_SIEFP, val); - wrmsr(HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT, - shared_sint.as_uint64_t); - /* Enable the global synic bit */ - sctrl.as_uint64_t = rdmsr(HV_X64_MSR_SCONTROL); - sctrl.u.enable = 1; + /* + * Configure and unmask SINT for message and event flags. + */ + sint = MSR_HV_SINT0 + HV_VMBUS_MESSAGE_SINT; + orig = rdmsr(sint); + val = sc->vmbus_idtvec | MSR_HV_SINT_AUTOEOI | + (orig & MSR_HV_SINT_RSVD_MASK); + wrmsr(sint, val); - wrmsr(HV_X64_MSR_SCONTROL, sctrl.as_uint64_t); + /* + * Configure and unmask SINT for timer. + */ + sint = MSR_HV_SINT0 + HV_VMBUS_TIMER_SINT; + orig = rdmsr(sint); + val = sc->vmbus_idtvec | MSR_HV_SINT_AUTOEOI | + (orig & MSR_HV_SINT_RSVD_MASK); + wrmsr(sint, val); /* - * Set up the cpuid mapping from Hyper-V to FreeBSD. - * The array is indexed using FreeBSD cpuid. + * All done; enable SynIC. */ - VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(HV_X64_MSR_VP_INDEX); + orig = rdmsr(MSR_HV_SCONTROL); + val = MSR_HV_SCTRL_ENABLE | (orig & MSR_HV_SCTRL_RSVD_MASK); + wrmsr(MSR_HV_SCONTROL, val); } static void vmbus_synic_teardown(void *arg) { - hv_vmbus_synic_sint shared_sint; - hv_vmbus_synic_simp simp; - hv_vmbus_synic_siefp siefp; - - shared_sint.as_uint64_t = rdmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT); - - shared_sint.u.masked = 1; + uint64_t orig; + uint32_t sint; /* - * Disable the interrupt 0 + * Disable SynIC. */ - wrmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT, - shared_sint.as_uint64_t); - - shared_sint.as_uint64_t = rdmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT); - - shared_sint.u.masked = 1; + orig = rdmsr(MSR_HV_SCONTROL); + wrmsr(MSR_HV_SCONTROL, (orig & MSR_HV_SCTRL_RSVD_MASK)); /* - * Disable the interrupt 1 + * Mask message and event flags SINT. */ - wrmsr( - HV_X64_MSR_SINT0 + HV_VMBUS_TIMER_SINT, - shared_sint.as_uint64_t); - simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP); - simp.u.simp_enabled = 0; - simp.u.base_simp_gpa = 0; + sint = MSR_HV_SINT0 + HV_VMBUS_MESSAGE_SINT; + orig = rdmsr(sint); + wrmsr(sint, orig | MSR_HV_SINT_MASKED); - wrmsr(HV_X64_MSR_SIMP, simp.as_uint64_t); + /* + * Mask timer SINT. + */ + sint = MSR_HV_SINT0 + HV_VMBUS_TIMER_SINT; + orig = rdmsr(sint); + wrmsr(sint, orig | MSR_HV_SINT_MASKED); - siefp.as_uint64_t = rdmsr(HV_X64_MSR_SIEFP); - siefp.u.siefp_enabled = 0; - siefp.u.base_siefp_gpa = 0; + /* + * Teardown SynIC message. + */ + orig = rdmsr(MSR_HV_SIMP); + wrmsr(MSR_HV_SIMP, (orig & MSR_HV_SIMP_RSVD_MASK)); - wrmsr(HV_X64_MSR_SIEFP, siefp.as_uint64_t); + /* + * Teardown SynIC event flags. + */ + orig = rdmsr(MSR_HV_SIEFP); + wrmsr(MSR_HV_SIEFP, (orig & MSR_HV_SIEFP_RSVD_MASK)); } static int Modified: stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Thu Jun 23 07:53:58 2016 (r302127) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Thu Jun 23 08:09:44 2016 (r302128) @@ -29,9 +29,48 @@ #ifndef _HYPERV_REG_H_ #define _HYPERV_REG_H_ +#define MSR_HV_GUEST_OS_ID 0x40000000 +#define MSR_HV_GUESTID_BUILD_MASK 0xffffULL +#define MSR_HV_GUESTID_VERSION_MASK 0x0000ffffffff0000ULL +#define MSR_HV_GUESTID_VERSION_SHIFT 16 +#define MSR_HV_GUESTID_OSID_MASK 0x00ff000000000000ULL +#define MSR_HV_GUESTID_OSID_SHIFT 48 +#define MSR_HV_GUESTID_OSTYPE_MASK 0x7f00000000000000ULL +#define MSR_HV_GUESTID_OSTYPE_SHIFT 56 +#define MSR_HV_GUESTID_OPENSRC 0x8000000000000000ULL +#define MSR_HV_GUESTID_OSTYPE_LINUX \ + ((0x01ULL << MSR_HV_GUESTID_OSTYPE_SHIFT) | MSR_HV_GUESTID_OPENSRC) +#define MSR_HV_GUESTID_OSTYPE_FREEBSD \ + ((0x02ULL << MSR_HV_GUESTID_OSTYPE_SHIFT) | MSR_HV_GUESTID_OPENSRC) + #define MSR_HV_HYPERCALL 0x40000001 #define MSR_HV_HYPERCALL_ENABLE 0x0001ULL #define MSR_HV_HYPERCALL_RSVD_MASK 0x0ffeULL #define MSR_HV_HYPERCALL_PGSHIFT 12 +#define MSR_HV_VP_INDEX 0x40000002 + +#define MSR_HV_SCONTROL 0x40000080 +#define MSR_HV_SCTRL_ENABLE 0x0001ULL +#define MSR_HV_SCTRL_RSVD_MASK 0xfffffffffffffffeULL + +#define MSR_HV_SIEFP 0x40000082 +#define MSR_HV_SIEFP_ENABLE 0x0001ULL +#define MSR_HV_SIEFP_RSVD_MASK 0x0ffeULL +#define MSR_HV_SIEFP_PGSHIFT 12 + +#define MSR_HV_SIMP 0x40000083 +#define MSR_HV_SIMP_ENABLE 0x0001ULL +#define MSR_HV_SIMP_RSVD_MASK 0x0ffeULL +#define MSR_HV_SIMP_PGSHIFT 12 + +#define MSR_HV_SINT0 0x40000090 +#define MSR_HV_SINT_VECTOR_MASK 0x00ffULL +#define MSR_HV_SINT_RSVD1_MASK 0xff00ULL +#define MSR_HV_SINT_MASKED 0x00010000ULL +#define MSR_HV_SINT_AUTOEOI 0x00020000ULL +#define MSR_HV_SINT_RSVD2_MASK 0xfffffffffffc0000ULL +#define MSR_HV_SINT_RSVD_MASK (MSR_HV_SINT_RSVD1_MASK | \ + MSR_HV_SINT_RSVD2_MASK) + #endif /* !_HYPERV_REG_H_ */ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 08:26:08 2016 Return-Path: Delivered-To: svn-src-stable-10@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 C94E8AC6651; Thu, 23 Jun 2016 08:26:08 +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 9326C1D65; Thu, 23 Jun 2016 08:26:08 +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 u5N8Q7iw050184; Thu, 23 Jun 2016 08:26:07 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N8Q78O050178; Thu, 23 Jun 2016 08:26:07 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230826.u5N8Q78O050178@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 08:26:07 +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: r302129 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 08:26:08 -0000 Author: sephe Date: Thu Jun 23 08:26:07 2016 New Revision: 302129 URL: https://svnweb.freebsd.org/changeset/base/302129 Log: MFC 300825,300827,300830,300831,300832,300834 300825 hyperv: Move CPUID related bits to hyperv_reg.h and give them clean name MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6565 300827 hyperv: Move timer related MSRs into hyperv_reg.h And avoid bit fields for event timer. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6566 300830 hyperv/vmbus: Move MSR EOM to hyperv_reg.h MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6567 300831 hyperv: GC unneeded bits MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6568 300832 hyperv: Clean up Hyper-V timecounter a bit. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6569 300834 hyperv: Test features before enabling optional functionalities MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6571 Added: stable/10/sys/dev/hyperv/vmbus/hyperv_var.h - copied unchanged from r300834, head/sys/dev/hyperv/vmbus/hyperv_var.h Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_et.c Thu Jun 23 08:09:44 2016 (r302128) +++ stable/10/sys/dev/hyperv/vmbus/hv_et.c Thu Jun 23 08:26:07 2016 (r302129) @@ -37,12 +37,28 @@ __FBSDID("$FreeBSD$"); #include #include -#include "hv_vmbus_priv.h" +#include +#include +#include #define HV_TIMER_FREQUENCY (10 * 1000 * 1000LL) /* 100ns period */ #define HV_MAX_DELTA_TICKS 0xffffffffLL #define HV_MIN_DELTA_TICKS 1LL +#define MSR_HV_STIMER0_CFG_SINT \ + ((((uint64_t)HV_VMBUS_TIMER_SINT) << MSR_HV_STIMER_CFG_SINT_SHIFT) & \ + MSR_HV_STIMER_CFG_SINT_MASK) + +/* + * Two additionally required features: + * - SynIC is needed for interrupt generation. + * - Time reference counter is needed to set ABS reference count to + * STIMER0_COUNT. + */ +#define CPUID_HV_ET_MASK (CPUID_HV_MSR_TIME_REFCNT | \ + CPUID_HV_MSR_SYNIC | \ + CPUID_HV_MSR_SYNTIMER) + static struct eventtimer *et; static inline uint64_t @@ -57,18 +73,15 @@ sbintime2tick(sbintime_t time) static int hv_et_start(struct eventtimer *et, sbintime_t firsttime, sbintime_t periodtime) { - union hv_timer_config timer_cfg; - uint64_t current; + uint64_t current, config; - timer_cfg.as_uint64 = 0; - timer_cfg.auto_enable = 1; - timer_cfg.sintx = HV_VMBUS_TIMER_SINT; + config = MSR_HV_STIMER_CFG_AUTOEN | MSR_HV_STIMER0_CFG_SINT; - current = rdmsr(HV_X64_MSR_TIME_REF_COUNT); + current = rdmsr(MSR_HV_TIME_REF_COUNT); current += sbintime2tick(firsttime); - wrmsr(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64); - wrmsr(HV_X64_MSR_STIMER0_COUNT, current); + wrmsr(MSR_HV_STIMER0_CONFIG, config); + wrmsr(MSR_HV_STIMER0_COUNT, current); return (0); } @@ -76,8 +89,8 @@ hv_et_start(struct eventtimer *et, sbint static int hv_et_stop(struct eventtimer *et) { - wrmsr(HV_X64_MSR_STIMER0_CONFIG, 0); - wrmsr(HV_X64_MSR_STIMER0_COUNT, 0); + wrmsr(MSR_HV_STIMER0_CONFIG, 0); + wrmsr(MSR_HV_STIMER0_COUNT, 0); return (0); } @@ -102,7 +115,8 @@ hv_et_intr(struct trapframe *frame) static void hv_et_identify(driver_t *driver, device_t parent) { - if (device_find_child(parent, "hv_et", -1) != NULL) + if (device_find_child(parent, "hv_et", -1) != NULL || + (hyperv_features & CPUID_HV_ET_MASK) != CPUID_HV_ET_MASK) return; device_add_child(parent, "hv_et", -1); Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 08:09:44 2016 (r302128) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 08:26:07 2016 (r302129) @@ -46,12 +46,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #define HV_NANOSECONDS_PER_SEC 1000000000L -#define HYPERV_INTERFACE 0x31237648 /* HV#1 */ - #define HYPERV_FREEBSD_BUILD 0ULL #define HYPERV_FREEBSD_VERSION ((uint64_t)__FreeBSD_version) #define HYPERV_FREEBSD_OSID 0ULL @@ -76,25 +75,31 @@ struct hypercall_ctx { struct hyperv_dma hc_dma; }; -static struct hypercall_ctx hypercall_context; - -static u_int hv_get_timecount(struct timecounter *tc); +static u_int hyperv_get_timecount(struct timecounter *tc); -u_int hyperv_features; -u_int hyperv_recommends; +u_int hyperv_features; +u_int hyperv_recommends; static u_int hyperv_pm_features; static u_int hyperv_features3; -static struct timecounter hv_timecounter = { - hv_get_timecount, 0, ~0u, HV_NANOSECONDS_PER_SEC/100, "Hyper-V", HV_NANOSECONDS_PER_SEC/100 +static struct timecounter hyperv_timecounter = { + .tc_get_timecount = hyperv_get_timecount, + .tc_poll_pps = NULL, + .tc_counter_mask = 0xffffffff, + .tc_frequency = HV_NANOSECONDS_PER_SEC/100, + .tc_name = "Hyper-V", + .tc_quality = 2000, + .tc_flags = 0, + .tc_priv = NULL }; +static struct hypercall_ctx hypercall_context; + static u_int -hv_get_timecount(struct timecounter *tc) +hyperv_get_timecount(struct timecounter *tc __unused) { - u_int now = rdmsr(HV_X64_MSR_TIME_REF_COUNT); - return (now); + return rdmsr(MSR_HV_TIME_REF_COUNT); } /** @@ -204,26 +209,22 @@ static bool hyperv_identify(void) { u_int regs[4]; - unsigned int maxLeaf; - unsigned int op; + unsigned int maxleaf; if (vm_guest != VM_GUEST_HV) return (false); - op = HV_CPU_ID_FUNCTION_HV_VENDOR_AND_MAX_FUNCTION; - do_cpuid(op, regs); - maxLeaf = regs[0]; - if (maxLeaf < HV_CPU_ID_FUNCTION_MS_HV_IMPLEMENTATION_LIMITS) + do_cpuid(CPUID_LEAF_HV_MAXLEAF, regs); + maxleaf = regs[0]; + if (maxleaf < CPUID_LEAF_HV_LIMITS) return (false); - op = HV_CPU_ID_FUNCTION_HV_INTERFACE; - do_cpuid(op, regs); - if (regs[0] != HYPERV_INTERFACE) + do_cpuid(CPUID_LEAF_HV_INTERFACE, regs); + if (regs[0] != CPUID_HV_IFACE_HYPERV) return (false); - op = HV_CPU_ID_FUNCTION_MS_HV_FEATURES; - do_cpuid(op, regs); - if ((regs[0] & HV_FEATURE_MSR_HYPERCALL) == 0) { + do_cpuid(CPUID_LEAF_HV_FEATURES, regs); + if ((regs[0] & CPUID_HV_MSR_HYPERCALL) == 0) { /* * Hyper-V w/o Hypercall is impossible; someone * is faking Hyper-V. @@ -234,31 +235,30 @@ hyperv_identify(void) hyperv_pm_features = regs[2]; hyperv_features3 = regs[3]; - op = HV_CPU_ID_FUNCTION_MS_HV_VERSION; - do_cpuid(op, regs); + do_cpuid(CPUID_LEAF_HV_IDENTITY, regs); printf("Hyper-V Version: %d.%d.%d [SP%d]\n", regs[1] >> 16, regs[1] & 0xffff, regs[0], regs[2]); printf(" Features=0x%b\n", hyperv_features, "\020" - "\001VPRUNTIME" /* MSR_VP_RUNTIME */ - "\002TMREFCNT" /* MSR_TIME_REF_COUNT */ + "\001VPRUNTIME" /* MSR_HV_VP_RUNTIME */ + "\002TMREFCNT" /* MSR_HV_TIME_REF_COUNT */ "\003SYNIC" /* MSRs for SynIC */ "\004SYNTM" /* MSRs for SynTimer */ - "\005APIC" /* MSR_{EOI,ICR,TPR} */ - "\006HYPERCALL" /* MSR_{GUEST_OS_ID,HYPERCALL} */ - "\007VPINDEX" /* MSR_VP_INDEX */ - "\010RESET" /* MSR_RESET */ - "\011STATS" /* MSR_STATS_ */ - "\012REFTSC" /* MSR_REFERENCE_TSC */ - "\013IDLE" /* MSR_GUEST_IDLE */ - "\014TMFREQ" /* MSR_{TSC,APIC}_FREQUENCY */ - "\015DEBUG"); /* MSR_SYNTH_DEBUG_ */ - printf(" PM Features=max C%u, 0x%b\n", - HV_PM_FEATURE_CSTATE(hyperv_pm_features), - (hyperv_pm_features & ~HV_PM_FEATURE_CSTATE_MASK), + "\005APIC" /* MSR_HV_{EOI,ICR,TPR} */ + "\006HYPERCALL" /* MSR_HV_{GUEST_OS_ID,HYPERCALL} */ + "\007VPINDEX" /* MSR_HV_VP_INDEX */ + "\010RESET" /* MSR_HV_RESET */ + "\011STATS" /* MSR_HV_STATS_ */ + "\012REFTSC" /* MSR_HV_REFERENCE_TSC */ + "\013IDLE" /* MSR_HV_GUEST_IDLE */ + "\014TMFREQ" /* MSR_HV_{TSC,APIC}_FREQUENCY */ + "\015DEBUG"); /* MSR_HV_SYNTH_DEBUG_ */ + printf(" PM Features=0x%b [C%u]\n", + (hyperv_pm_features & ~CPUPM_HV_CSTATE_MASK), "\020" - "\005C3HPET"); /* HPET is required for C3 state */ + "\005C3HPET", /* HPET is required for C3 state */ + CPUPM_HV_CSTATE(hyperv_pm_features)); printf(" Features3=0x%b\n", hyperv_features3, "\020" "\001MWAIT" /* MWAIT */ @@ -276,24 +276,21 @@ hyperv_identify(void) "\015NPIEP" /* NPIEP */ "\016HVDIS"); /* disabling hypervisor */ - op = HV_CPU_ID_FUNCTION_MS_HV_ENLIGHTENMENT_INFORMATION; - do_cpuid(op, regs); + do_cpuid(CPUID_LEAF_HV_RECOMMENDS, regs); hyperv_recommends = regs[0]; if (bootverbose) printf(" Recommends: %08x %08x\n", regs[0], regs[1]); - op = HV_CPU_ID_FUNCTION_MS_HV_IMPLEMENTATION_LIMITS; - do_cpuid(op, regs); + do_cpuid(CPUID_LEAF_HV_LIMITS, regs); if (bootverbose) { printf(" Limits: Vcpu:%d Lcpu:%d Int:%d\n", regs[0], regs[1], regs[2]); } - if (maxLeaf >= HV_CPU_ID_FUNCTION_MS_HV_HARDWARE_FEATURE) { - op = HV_CPU_ID_FUNCTION_MS_HV_HARDWARE_FEATURE; - do_cpuid(op, regs); + if (maxleaf >= CPUID_LEAF_HV_HWFEATURES) { + do_cpuid(CPUID_LEAF_HV_HWFEATURES, regs); if (bootverbose) { - printf(" HW Features: %08x AMD: %08x\n", + printf(" HW Features: %08x, AMD: %08x\n", regs[0], regs[3]); } } @@ -314,9 +311,9 @@ hyperv_init(void *dummy __unused) /* Set guest id */ wrmsr(MSR_HV_GUEST_OS_ID, MSR_HV_GUESTID_FREEBSD); - if (hyperv_features & HV_FEATURE_MSR_TIME_REFCNT) { - /* Register virtual timecount */ - tc_init(&hv_timecounter); + if (hyperv_features & CPUID_HV_MSR_TIME_REFCNT) { + /* Register Hyper-V timecounter */ + tc_init(&hyperv_timecounter); } } SYSINIT(hyperv_initialize, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, hyperv_init, Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 08:09:44 2016 (r302128) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 08:26:07 2016 (r302129) @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -118,7 +119,7 @@ handled: * This will cause message queue rescan to possibly * deliver another msg from the hypervisor */ - wrmsr(HV_X64_MSR_EOM, 0); + wrmsr(MSR_HV_EOM, 0); } } } @@ -170,7 +171,7 @@ hv_vmbus_isr(struct vmbus_softc *sc, str * This will cause message queue rescan to possibly * deliver another msg from the hypervisor */ - wrmsr(HV_X64_MSR_EOM, 0); + wrmsr(MSR_HV_EOM, 0); } } @@ -215,10 +216,21 @@ vmbus_synic_setup(void *xsc) uint64_t val, orig; uint32_t sint; - /* - * Save virtual processor id. - */ - VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX); + if (hyperv_features & CPUID_HV_MSR_VP_INDEX) { + /* + * Save virtual processor id. + */ + VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX); + } else { + /* + * XXX + * Virtual processoor id is only used by a pretty broken + * channel selection code from storvsc. It's nothing + * critical even if CPUID_HV_MSR_VP_INDEX is not set; keep + * moving on. + */ + VMBUS_PCPU_GET(sc, vcpuid, cpu) = cpu; + } /* * Setup the SynIC message. @@ -637,7 +649,8 @@ static int vmbus_probe(device_t dev) { if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL || - device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV) + device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV || + (hyperv_features & CPUID_HV_MSR_SYNIC) == 0) return (ENXIO); device_set_desc(dev, "Hyper-V Vmbus"); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 08:09:44 2016 (r302128) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 08:26:07 2016 (r302129) @@ -356,32 +356,6 @@ typedef struct { } hv_vmbus_connection; typedef union { - uint64_t as_uint64_t; - struct { - uint64_t build_number : 16; - uint64_t service_version : 8; /* Service Pack, etc. */ - uint64_t minor_version : 8; - uint64_t major_version : 8; - /* - * HV_GUEST_OS_MICROSOFT_IDS (If Vendor=MS) - * HV_GUEST_OS_VENDOR - */ - uint64_t os_id : 8; - uint64_t vendor_id : 16; - } u; -} hv_vmbus_x64_msr_guest_os_id_contents; - - -typedef union { - uint64_t as_uint64_t; - struct { - uint64_t enable :1; - uint64_t reserved :11; - uint64_t guest_physical_address :52; - } u; -} hv_vmbus_x64_msr_hypercall_contents; - -typedef union { uint32_t as_uint32_t; struct { uint32_t group_enable :4; @@ -443,108 +417,6 @@ typedef struct { } hv_vmbus_monitor_page; /* - * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent - * is set by CPUID(HV_CPU_ID_FUNCTION_VERSION_AND_FEATURES). - */ -typedef enum { - HV_CPU_ID_FUNCTION_VERSION_AND_FEATURES = 0x00000001, - HV_CPU_ID_FUNCTION_HV_VENDOR_AND_MAX_FUNCTION = 0x40000000, - HV_CPU_ID_FUNCTION_HV_INTERFACE = 0x40000001, - /* - * The remaining functions depend on the value - * of hv_cpu_id_function_interface - */ - HV_CPU_ID_FUNCTION_MS_HV_VERSION = 0x40000002, - HV_CPU_ID_FUNCTION_MS_HV_FEATURES = 0x40000003, - HV_CPU_ID_FUNCTION_MS_HV_ENLIGHTENMENT_INFORMATION = 0x40000004, - HV_CPU_ID_FUNCTION_MS_HV_IMPLEMENTATION_LIMITS = 0x40000005, - HV_CPU_ID_FUNCTION_MS_HV_HARDWARE_FEATURE = 0x40000006 -} hv_vmbus_cpuid_function; - -#define HV_FEATURE_MSR_TIME_REFCNT 0x0002 /* MSR_TIME_REF_COUNT */ -#define HV_FEATURE_MSR_SYNIC 0x0004 /* MSRs for SynIC */ -#define HV_FEATURE_MSR_SYNTIMER 0x0008 /* MSRs for SynTimer */ -#define HV_FEATURE_MSR_APIC 0x0010 /* MSR_{EOI,ICR,TPR} */ -#define HV_FEATURE_MSR_HYPERCALL 0x0020 /* MSR_{GUEST_OS_ID,HYPERCALL} */ -#define HV_FEATURE_MSR_GUEST_IDLE 0x0400 /* MSR_GUEST_IDLE */ - -#define HV_PM_FEATURE_CSTATE_MASK 0x000f -#define HV_PM_FEATURE_C3_HPET 0x0010 /* C3 requires HPET */ -#define HV_PM_FEATURE_CSTATE(f) ((f) & HV_PM_FEATURE_CSTATE_MASK) - -#define HV_FEATURE3_MWAIT 0x0001 /* MWAIT */ -#define HV_FEATURE3_XMM_HYPERCALL 0x0010 /* hypercall input through XMM regs */ -#define HV_FEATURE3_GUEST_IDLE 0x0020 /* guest idle support */ -#define HV_FEATURE3_NUMA 0x0080 /* NUMA distance query support */ -#define HV_FEATURE3_TIME_FREQ 0x0100 /* timer frequency query (TSC, LAPIC) */ -#define HV_FEATURE3_MSR_CRASH 0x0400 /* MSRs for guest crash */ - -/* - * Define the format of the SIMP register - */ -typedef union { - uint64_t as_uint64_t; - struct { - uint64_t simp_enabled : 1; - uint64_t preserved : 11; - uint64_t base_simp_gpa : 52; - } u; -} hv_vmbus_synic_simp; - -/* - * Define the format of the SIEFP register - */ -typedef union { - uint64_t as_uint64_t; - struct { - uint64_t siefp_enabled : 1; - uint64_t preserved : 11; - uint64_t base_siefp_gpa : 52; - } u; -} hv_vmbus_synic_siefp; - -/* - * Define synthetic interrupt source - */ -typedef union { - uint64_t as_uint64_t; - struct { - uint64_t vector : 8; - uint64_t reserved1 : 8; - uint64_t masked : 1; - uint64_t auto_eoi : 1; - uint64_t reserved2 : 46; - } u; -} hv_vmbus_synic_sint; - -/* - * Timer configuration register. - */ -union hv_timer_config { - uint64_t as_uint64; - struct { - uint64_t enable:1; - uint64_t periodic:1; - uint64_t lazy:1; - uint64_t auto_enable:1; - uint64_t reserved_z0:12; - uint64_t sintx:4; - uint64_t reserved_z1:44; - }; -}; - -/* - * Define syn_ic control register - */ -typedef union _hv_vmbus_synic_scontrol { - uint64_t as_uint64_t; - struct { - uint64_t enable : 1; - uint64_t reserved : 63; - } u; -} hv_vmbus_synic_scontrol; - -/* * Define the hv_vmbus_post_message hypercall input structure */ typedef struct { @@ -565,60 +437,6 @@ typedef union vmbus_event_flags { } hv_vmbus_synic_event_flags; CTASSERT(sizeof(hv_vmbus_synic_event_flags) == HV_EVENT_FLAGS_BYTE_COUNT); -#define HV_X64_CPUID_MIN (0x40000005) -#define HV_X64_CPUID_MAX (0x4000ffff) - -/* - * Declare the MSR used to identify the guest OS - */ -#define HV_X64_MSR_GUEST_OS_ID (0x40000000) -/* - * Declare the MSR used to setup pages used to communicate with the hypervisor - */ -#define HV_X64_MSR_HYPERCALL (0x40000001) -/* MSR used to provide vcpu index */ -#define HV_X64_MSR_VP_INDEX (0x40000002) - -#define HV_X64_MSR_TIME_REF_COUNT (0x40000020) - -/* - * Define synthetic interrupt controller model specific registers - */ -#define HV_X64_MSR_SCONTROL (0x40000080) -#define HV_X64_MSR_SVERSION (0x40000081) -#define HV_X64_MSR_SIEFP (0x40000082) -#define HV_X64_MSR_SIMP (0x40000083) -#define HV_X64_MSR_EOM (0x40000084) - -#define HV_X64_MSR_SINT0 (0x40000090) -#define HV_X64_MSR_SINT1 (0x40000091) -#define HV_X64_MSR_SINT2 (0x40000092) -#define HV_X64_MSR_SINT3 (0x40000093) -#define HV_X64_MSR_SINT4 (0x40000094) -#define HV_X64_MSR_SINT5 (0x40000095) -#define HV_X64_MSR_SINT6 (0x40000096) -#define HV_X64_MSR_SINT7 (0x40000097) -#define HV_X64_MSR_SINT8 (0x40000098) -#define HV_X64_MSR_SINT9 (0x40000099) -#define HV_X64_MSR_SINT10 (0x4000009A) -#define HV_X64_MSR_SINT11 (0x4000009B) -#define HV_X64_MSR_SINT12 (0x4000009C) -#define HV_X64_MSR_SINT13 (0x4000009D) -#define HV_X64_MSR_SINT14 (0x4000009E) -#define HV_X64_MSR_SINT15 (0x4000009F) - -/* - * Synthetic Timer MSRs. Four timers per vcpu. - */ -#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0 -#define HV_X64_MSR_STIMER0_COUNT 0x400000B1 -#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2 -#define HV_X64_MSR_STIMER1_COUNT 0x400000B3 -#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4 -#define HV_X64_MSR_STIMER2_COUNT 0x400000B5 -#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6 -#define HV_X64_MSR_STIMER3_COUNT 0x400000B7 - /* * Declare the various hypercall operations */ @@ -633,9 +451,6 @@ typedef enum { extern hv_vmbus_connection hv_vmbus_g_connection; -extern u_int hyperv_features; -extern u_int hyperv_recommends; - typedef void (*vmbus_msg_handler)(hv_vmbus_channel_msg_header *msg); typedef struct hv_vmbus_channel_msg_table_entry { Modified: stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Thu Jun 23 08:09:44 2016 (r302128) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h Thu Jun 23 08:26:07 2016 (r302129) @@ -29,6 +29,10 @@ #ifndef _HYPERV_REG_H_ #define _HYPERV_REG_H_ +/* + * Hyper-V Synthetic MSRs + */ + #define MSR_HV_GUEST_OS_ID 0x40000000 #define MSR_HV_GUESTID_BUILD_MASK 0xffffULL #define MSR_HV_GUESTID_VERSION_MASK 0x0000ffffffff0000ULL @@ -50,6 +54,8 @@ #define MSR_HV_VP_INDEX 0x40000002 +#define MSR_HV_TIME_REF_COUNT 0x40000020 + #define MSR_HV_SCONTROL 0x40000080 #define MSR_HV_SCTRL_ENABLE 0x0001ULL #define MSR_HV_SCTRL_RSVD_MASK 0xfffffffffffffffeULL @@ -64,6 +70,8 @@ #define MSR_HV_SIMP_RSVD_MASK 0x0ffeULL #define MSR_HV_SIMP_PGSHIFT 12 +#define MSR_HV_EOM 0x40000084 + #define MSR_HV_SINT0 0x40000090 #define MSR_HV_SINT_VECTOR_MASK 0x00ffULL #define MSR_HV_SINT_RSVD1_MASK 0xff00ULL @@ -73,4 +81,53 @@ #define MSR_HV_SINT_RSVD_MASK (MSR_HV_SINT_RSVD1_MASK | \ MSR_HV_SINT_RSVD2_MASK) +#define MSR_HV_STIMER0_CONFIG 0x400000b0 +#define MSR_HV_STIMER_CFG_ENABLE 0x0001ULL +#define MSR_HV_STIMER_CFG_PERIODIC 0x0002ULL +#define MSR_HV_STIMER_CFG_LAZY 0x0004ULL +#define MSR_HV_STIMER_CFG_AUTOEN 0x0008ULL +#define MSR_HV_STIMER_CFG_SINT_MASK 0x000f0000ULL +#define MSR_HV_STIMER_CFG_SINT_SHIFT 16 + +#define MSR_HV_STIMER0_COUNT 0x400000b1 + +/* + * CPUID leaves + */ + +#define CPUID_LEAF_HV_MAXLEAF 0x40000000 + +#define CPUID_LEAF_HV_INTERFACE 0x40000001 +#define CPUID_HV_IFACE_HYPERV 0x31237648 /* HV#1 */ + +#define CPUID_LEAF_HV_IDENTITY 0x40000002 + +#define CPUID_LEAF_HV_FEATURES 0x40000003 +/* EAX: features */ +#define CPUID_HV_MSR_TIME_REFCNT 0x0002 /* MSR_HV_TIME_REF_COUNT */ +#define CPUID_HV_MSR_SYNIC 0x0004 /* MSRs for SynIC */ +#define CPUID_HV_MSR_SYNTIMER 0x0008 /* MSRs for SynTimer */ +#define CPUID_HV_MSR_APIC 0x0010 /* MSR_HV_{EOI,ICR,TPR} */ +#define CPUID_HV_MSR_HYPERCALL 0x0020 /* MSR_HV_GUEST_OS_ID + * MSR_HV_HYPERCALL */ +#define CPUID_HV_MSR_VP_INDEX 0x0040 /* MSR_HV_VP_INDEX */ +#define CPUID_HV_MSR_GUEST_IDLE 0x0400 /* MSR_HV_GUEST_IDLE */ +/* ECX: power management features */ +#define CPUPM_HV_CSTATE_MASK 0x000f /* deepest C-state */ +#define CPUPM_HV_C3_HPET 0x0010 /* C3 requires HPET */ +#define CPUPM_HV_CSTATE(f) ((f) & CPUPM_HV_CSTATE_MASK) +/* EDX: features3 */ +#define CPUID3_HV_MWAIT 0x0001 /* MWAIT */ +#define CPUID3_HV_XMM_HYPERCALL 0x0010 /* Hypercall input through + * XMM regs */ +#define CPUID3_HV_GUEST_IDLE 0x0020 /* guest idle */ +#define CPUID3_HV_NUMA 0x0080 /* NUMA distance query */ +#define CPUID3_HV_TIME_FREQ 0x0100 /* timer frequency query + * (TSC, LAPIC) */ +#define CPUID3_HV_MSR_CRASH 0x0400 /* MSRs for guest crash */ + +#define CPUID_LEAF_HV_RECOMMENDS 0x40000004 +#define CPUID_LEAF_HV_LIMITS 0x40000005 +#define CPUID_LEAF_HV_HWFEATURES 0x40000006 + #endif /* !_HYPERV_REG_H_ */ Copied: stable/10/sys/dev/hyperv/vmbus/hyperv_var.h (from r300834, head/sys/dev/hyperv/vmbus/hyperv_var.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_var.h Thu Jun 23 08:26:07 2016 (r302129, copy of r300834, head/sys/dev/hyperv/vmbus/hyperv_var.h) @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _HYPERV_VAR_H_ +#define _HYPERV_VAR_H_ + +extern u_int hyperv_features; +extern u_int hyperv_recommends; + +#endif /* !_HYPERV_VAR_H_ */ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 08:38:02 2016 Return-Path: Delivered-To: svn-src-stable-10@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 BD6DCAC692D; Thu, 23 Jun 2016 08:38:02 +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 7FB2B2687; Thu, 23 Jun 2016 08:38:02 +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 u5N8c1uM054459; Thu, 23 Jun 2016 08:38:01 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N8c1w8054458; Thu, 23 Jun 2016 08:38:01 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230838.u5N8c1w8054458@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 08:38:01 +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: r302132 - stable/10/sys/netinet 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 08:38:02 -0000 Author: sephe Date: Thu Jun 23 08:38:01 2016 New Revision: 302132 URL: https://svnweb.freebsd.org/changeset/base/302132 Log: MFC 300981 tcp: Don't prematurely drop receiving-only connections If the connection was persistent and receiving-only, several (12) sporadic device insufficient buffers would cause the connection be dropped prematurely: Upon ENOBUFS in tcp_output() for an ACK, retransmission timer is started. No one will stop this retransmission timer for receiving- only connection, so the retransmission timer promises to expire and t_rxtshift is promised to be increased. And t_rxtshift will not be reset to 0, since no RTT measurement will be done for receiving-only connection. If this receiving-only connection lived long enough (e.g. >350sec, given the RTO starts from 200ms), and it suffered 12 sporadic device insufficient buffers, i.e. t_rxtshift >= 12, this receiving-only connection would be dropped prematurely by the retransmission timer. We now assert that for data segments, SYNs or FINs either rexmit or persist timer was wired upon ENOBUFS. And don't set rexmit timer for other cases, i.e. ENOBUFS upon ACKs. Discussed with: lstewart, hiren, jtl, Mike Karels MFC after: 3 weeks Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D5872 Modified: stable/10/sys/netinet/tcp_output.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/netinet/tcp_output.c ============================================================================== --- stable/10/sys/netinet/tcp_output.c Thu Jun 23 08:28:13 2016 (r302131) +++ stable/10/sys/netinet/tcp_output.c Thu Jun 23 08:38:01 2016 (r302132) @@ -127,6 +127,16 @@ SYSCTL_VNET_INT(_net_inet_tcp, OID_AUTO, &VNET_NAME(tcp_autosndbuf_max), 0, "Max size of automatic send buffer"); +/* + * Make sure that either retransmit or persist timer is set for SYN, FIN and + * non-ACK. + */ +#define TCP_XMIT_TIMER_ASSERT(tp, len, th_flags) \ + KASSERT(((len) == 0 && ((th_flags) & (TH_SYN | TH_FIN)) == 0) ||\ + tcp_timer_active((tp), TT_REXMT) || \ + tcp_timer_active((tp), TT_PERSIST), \ + ("neither rexmt nor persist timer is set")) + static void inline hhook_run_tcp_est_out(struct tcpcb *tp, struct tcphdr *th, struct tcpopt *to, long len, int tso); @@ -1531,9 +1541,7 @@ timer: tp->t_softerror = error; return (error); case ENOBUFS: - if (!tcp_timer_active(tp, TT_REXMT) && - !tcp_timer_active(tp, TT_PERSIST)) - tcp_timer_activate(tp, TT_REXMT, tp->t_rxtcur); + TCP_XMIT_TIMER_ASSERT(tp, len, flags); tp->snd_cwnd = tp->t_maxseg; return (0); case EMSGSIZE: From owner-svn-src-stable-10@freebsd.org Thu Jun 23 09:00:59 2016 Return-Path: Delivered-To: svn-src-stable-10@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 CEED0B733D3; Thu, 23 Jun 2016 09:00:59 +0000 (UTC) (envelope-from kib@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 9EF1D168C; Thu, 23 Jun 2016 09:00:59 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5N90wKJ063685; Thu, 23 Jun 2016 09:00:58 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N90wQd063684; Thu, 23 Jun 2016 09:00:58 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606230900.u5N90wQd063684@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 23 Jun 2016 09:00:58 +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: r302133 - stable/10/sys/kern 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 09:00:59 -0000 Author: kib Date: Thu Jun 23 09:00:58 2016 New Revision: 302133 URL: https://svnweb.freebsd.org/changeset/base/302133 Log: MFC r301959: Remove code duplication. Modified: stable/10/sys/kern/kern_thread.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_thread.c ============================================================================== --- stable/10/sys/kern/kern_thread.c Thu Jun 23 08:38:01 2016 (r302132) +++ stable/10/sys/kern/kern_thread.c Thu Jun 23 09:00:58 2016 (r302133) @@ -613,11 +613,6 @@ weed_inhib(int mode, struct thread *td2, wakeup_swapper |= sleepq_abort(td2, EINTR); break; case SINGLE_BOUNDARY: - if (TD_IS_SUSPENDED(td2) && (td2->td_flags & TDF_BOUNDARY) == 0) - wakeup_swapper |= thread_unsuspend_one(td2, p, false); - if (TD_ON_SLEEPQ(td2) && (td2->td_flags & TDF_SINTR) != 0) - wakeup_swapper |= sleepq_abort(td2, ERESTART); - break; case SINGLE_NO_EXIT: if (TD_IS_SUSPENDED(td2) && (td2->td_flags & TDF_BOUNDARY) == 0) wakeup_swapper |= thread_unsuspend_one(td2, p, false); From owner-svn-src-stable-10@freebsd.org Thu Jun 23 09:02:52 2016 Return-Path: Delivered-To: svn-src-stable-10@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 21340B7344A; Thu, 23 Jun 2016 09:02:52 +0000 (UTC) (envelope-from kib@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 E5E4E1A2B; Thu, 23 Jun 2016 09:02:51 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5N92pTW065785; Thu, 23 Jun 2016 09:02:51 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N92pMF065784; Thu, 23 Jun 2016 09:02:51 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606230902.u5N92pMF065784@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 23 Jun 2016 09:02:51 +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: r302134 - stable/10/sys/kern 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 09:02:52 -0000 Author: kib Date: Thu Jun 23 09:02:50 2016 New Revision: 302134 URL: https://svnweb.freebsd.org/changeset/base/302134 Log: MFC r301960: Remove XXX comments from kern_thread.c. Modified: stable/10/sys/kern/kern_thread.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_thread.c ============================================================================== --- stable/10/sys/kern/kern_thread.c Thu Jun 23 09:00:58 2016 (r302133) +++ stable/10/sys/kern/kern_thread.c Thu Jun 23 09:02:50 2016 (r302134) @@ -424,7 +424,7 @@ thread_exit(void) * architecture specific resources that * would not be on a new untouched process. */ - cpu_thread_exit(td); /* XXXSMP */ + cpu_thread_exit(td); /* * The last thread is left attached to the process @@ -851,8 +851,8 @@ thread_suspend_check(int return_instead) /* * The only suspension in action is a * single-threading. Single threader need not stop. - * XXX Should be safe to access unlocked - * as it can only be set to be true by us. + * It is safe to access p->p_singlethread unlocked + * because it can only be set to our address by us. */ if (p->p_singlethread == td) return (0); /* Exempt from stopping. */ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 09:03:54 2016 Return-Path: Delivered-To: svn-src-stable-10@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 52F1AB73500; Thu, 23 Jun 2016 09:03:54 +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 23E5F1BD3; Thu, 23 Jun 2016 09:03:54 +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 u5N93rqH065884; Thu, 23 Jun 2016 09:03:53 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N93qjj065877; Thu, 23 Jun 2016 09:03:52 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606230903.u5N93qjj065877@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 23 Jun 2016 09:03:52 +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: r302135 - 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 09:03:54 -0000 Author: sephe Date: Thu Jun 23 09:03:52 2016 New Revision: 302135 URL: https://svnweb.freebsd.org/changeset/base/302135 Log: MFC 300987,300988,300989,300992,300993,300994,301009 300987 hyperv/et: Fix STIMER0 operations. - Make sure that STIMER0 is disabled before writting to it, since writing to an enabled STIMER will result in undefined behaviour. - It is unnecessary to reconfigure STIMER0 upon each et_start(). - Make sure that MSR_HV_REF_TIME_COUNT will not return 0, since writing 0 to STIMER_COUNT will disable the target STIMER. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6573 300988 hyperv/vmbus: Move SINT settings to vmbus_var.h While I'm here remove the event timer's dependency on hv_vmbus_priv.h MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6574 300989 hyperv/et: Make sure only one event timer will be registered This nullifies the need to use softc. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6591 300992 hyperv: Move timer frequency definition to common place. And cleanup event timer period settings. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6597 300993 hyperv/et: Device renaming; consistent w/ other Hyper-V utils While I'm here, prefix function names w/ vmbus, since unlike Hyper-V timecounter, Hyper-V event timer will not work w/o vmbus. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6598 300994 hyperv/et: Allow Hyper-V event timer be disabled MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6599 301009 hyperv/vmbus: Process event timer before checking events And update comment. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6600 Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_et.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/hyperv_var.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Thu Jun 23 09:03:52 2016 (r302135) @@ -340,7 +340,7 @@ vmbus_event_proc(struct vmbus_softc *sc, * On Host with Win8 or above, the event page can be checked directly * to get the id of the channel that has the pending interrupt. */ - event = VMBUS_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; + event = VMBUS_PCPU_GET(sc, event_flag, cpu) + VMBUS_SINT_MESSAGE; vmbus_event_flags_proc(event->flagsul, VMBUS_PCPU_GET(sc, event_flag_cnt, cpu)); } @@ -350,7 +350,7 @@ vmbus_event_proc_compat(struct vmbus_sof { hv_vmbus_synic_event_flags *event; - event = VMBUS_PCPU_GET(sc, event_flag, cpu) + HV_VMBUS_MESSAGE_SINT; + event = VMBUS_PCPU_GET(sc, event_flag, cpu) + VMBUS_SINT_MESSAGE; if (atomic_testandclear_int(&event->flags32[0], 0)) { vmbus_event_flags_proc( hv_vmbus_g_connection.recv_interrupt_page, Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_et.c Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/hv_et.c Thu Jun 23 09:03:52 2016 (r302135) @@ -37,16 +37,16 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include + #include #include +#include -#define HV_TIMER_FREQUENCY (10 * 1000 * 1000LL) /* 100ns period */ -#define HV_MAX_DELTA_TICKS 0xffffffffLL -#define HV_MIN_DELTA_TICKS 1LL +#define VMBUS_ET_NAME "hvet" #define MSR_HV_STIMER0_CFG_SINT \ - ((((uint64_t)HV_VMBUS_TIMER_SINT) << MSR_HV_STIMER_CFG_SINT_SHIFT) & \ + ((((uint64_t)VMBUS_SINT_TIMER) << MSR_HV_STIMER_CFG_SINT_SHIFT) & \ MSR_HV_STIMER_CFG_SINT_MASK) /* @@ -59,117 +59,140 @@ __FBSDID("$FreeBSD$"); CPUID_HV_MSR_SYNIC | \ CPUID_HV_MSR_SYNTIMER) -static struct eventtimer *et; +static struct eventtimer vmbus_et; -static inline uint64_t -sbintime2tick(sbintime_t time) +static __inline uint64_t +hyperv_sbintime2count(sbintime_t time) { struct timespec val; val = sbttots(time); - return val.tv_sec * HV_TIMER_FREQUENCY + val.tv_nsec / 100; + return (val.tv_sec * HYPERV_TIMER_FREQ) + + (val.tv_nsec / HYPERV_TIMER_NS_FACTOR); } static int -hv_et_start(struct eventtimer *et, sbintime_t firsttime, sbintime_t periodtime) +vmbus_et_start(struct eventtimer *et __unused, sbintime_t first, + sbintime_t period __unused) { - uint64_t current, config; - - config = MSR_HV_STIMER_CFG_AUTOEN | MSR_HV_STIMER0_CFG_SINT; + uint64_t current; current = rdmsr(MSR_HV_TIME_REF_COUNT); - current += sbintime2tick(firsttime); - - wrmsr(MSR_HV_STIMER0_CONFIG, config); + current += hyperv_sbintime2count(first); wrmsr(MSR_HV_STIMER0_COUNT, current); return (0); } -static int -hv_et_stop(struct eventtimer *et) -{ - wrmsr(MSR_HV_STIMER0_CONFIG, 0); - wrmsr(MSR_HV_STIMER0_COUNT, 0); - - return (0); -} - void -hv_et_intr(struct trapframe *frame) +vmbus_et_intr(struct trapframe *frame) { struct trapframe *oldframe; struct thread *td; - if (et->et_active) { + if (vmbus_et.et_active) { td = curthread; td->td_intr_nesting_level++; oldframe = td->td_intr_frame; td->td_intr_frame = frame; - et->et_event_cb(et, et->et_arg); + vmbus_et.et_event_cb(&vmbus_et, vmbus_et.et_arg); td->td_intr_frame = oldframe; td->td_intr_nesting_level--; } } static void -hv_et_identify(driver_t *driver, device_t parent) +vmbus_et_identify(driver_t *driver, device_t parent) { - if (device_find_child(parent, "hv_et", -1) != NULL || + if (device_get_unit(parent) != 0 || + device_find_child(parent, VMBUS_ET_NAME, -1) != NULL || (hyperv_features & CPUID_HV_ET_MASK) != CPUID_HV_ET_MASK) return; - device_add_child(parent, "hv_et", -1); + device_add_child(parent, VMBUS_ET_NAME, -1); } static int -hv_et_probe(device_t dev) +vmbus_et_probe(device_t dev) { + if (resource_disabled(VMBUS_ET_NAME, 0)) + return (ENXIO); + device_set_desc(dev, "Hyper-V event timer"); return (BUS_PROBE_NOWILDCARD); } +static void +vmbus_et_config(void *arg __unused) +{ + /* + * Make sure that STIMER0 is really disabled before writing + * to STIMER0_CONFIG. + * + * "Writing to the configuration register of a timer that + * is already enabled may result in undefined behaviour." + */ + for (;;) { + uint64_t val; + + /* Stop counting, and this also implies disabling STIMER0 */ + wrmsr(MSR_HV_STIMER0_COUNT, 0); + + val = rdmsr(MSR_HV_STIMER0_CONFIG); + if ((val & MSR_HV_STIMER_CFG_ENABLE) == 0) + break; + cpu_spinwait(); + } + wrmsr(MSR_HV_STIMER0_CONFIG, + MSR_HV_STIMER_CFG_AUTOEN | MSR_HV_STIMER0_CFG_SINT); +} + static int -hv_et_attach(device_t dev) +vmbus_et_attach(device_t dev) { - /* XXX: need allocate SINT and remove global et */ - et = device_get_softc(dev); + /* TODO: use independent IDT vector */ - et->et_name = "Hyper-V"; - et->et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERCPU; - et->et_quality = 1000; - et->et_frequency = HV_TIMER_FREQUENCY; - et->et_min_period = HV_MIN_DELTA_TICKS * ((1LL << 32) / HV_TIMER_FREQUENCY); - et->et_max_period = HV_MAX_DELTA_TICKS * ((1LL << 32) / HV_TIMER_FREQUENCY); - et->et_start = hv_et_start; - et->et_stop = hv_et_stop; - et->et_priv = dev; + vmbus_et.et_name = "Hyper-V"; + vmbus_et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERCPU; + vmbus_et.et_quality = 1000; + vmbus_et.et_frequency = HYPERV_TIMER_FREQ; + vmbus_et.et_min_period = (0x00000001ULL << 32) / HYPERV_TIMER_FREQ; + vmbus_et.et_max_period = (0xfffffffeULL << 32) / HYPERV_TIMER_FREQ; + vmbus_et.et_start = vmbus_et_start; + + /* + * Delay a bit to make sure that MSR_HV_TIME_REF_COUNT will + * not return 0, since writing 0 to STIMER0_COUNT will disable + * STIMER0. + */ + DELAY(100); + smp_rendezvous(NULL, vmbus_et_config, NULL, NULL); - return (et_register(et)); + return (et_register(&vmbus_et)); } static int -hv_et_detach(device_t dev) +vmbus_et_detach(device_t dev) { - return (et_deregister(et)); + return (et_deregister(&vmbus_et)); } -static device_method_t hv_et_methods[] = { - DEVMETHOD(device_identify, hv_et_identify), - DEVMETHOD(device_probe, hv_et_probe), - DEVMETHOD(device_attach, hv_et_attach), - DEVMETHOD(device_detach, hv_et_detach), +static device_method_t vmbus_et_methods[] = { + DEVMETHOD(device_identify, vmbus_et_identify), + DEVMETHOD(device_probe, vmbus_et_probe), + DEVMETHOD(device_attach, vmbus_et_attach), + DEVMETHOD(device_detach, vmbus_et_detach), DEVMETHOD_END }; -static driver_t hv_et_driver = { - "hv_et", - hv_et_methods, - sizeof(struct eventtimer) +static driver_t vmbus_et_driver = { + VMBUS_ET_NAME, + vmbus_et_methods, + 0 }; -static devclass_t hv_et_devclass; -DRIVER_MODULE(hv_et, vmbus, hv_et_driver, hv_et_devclass, NULL, 0); +static devclass_t vmbus_et_devclass; +DRIVER_MODULE(hv_et, vmbus, vmbus_et_driver, vmbus_et_devclass, NULL, NULL); MODULE_VERSION(hv_et, 1); Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Thu Jun 23 09:03:52 2016 (r302135) @@ -49,8 +49,6 @@ __FBSDID("$FreeBSD$"); #include #include -#define HV_NANOSECONDS_PER_SEC 1000000000L - #define HYPERV_FREEBSD_BUILD 0ULL #define HYPERV_FREEBSD_VERSION ((uint64_t)__FreeBSD_version) #define HYPERV_FREEBSD_OSID 0ULL @@ -87,7 +85,7 @@ static struct timecounter hyperv_timecou .tc_get_timecount = hyperv_get_timecount, .tc_poll_pps = NULL, .tc_counter_mask = 0xffffffff, - .tc_frequency = HV_NANOSECONDS_PER_SEC/100, + .tc_frequency = HYPERV_TIMER_FREQ, .tc_name = "Hyper-V", .tc_quality = 2000, .tc_flags = 0, Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Thu Jun 23 09:03:52 2016 (r302135) @@ -80,7 +80,7 @@ vmbus_msg_task(void *xsc, int pending __ struct vmbus_softc *sc = xsc; hv_vmbus_message *msg; - msg = VMBUS_PCPU_GET(sc, message, curcpu) + HV_VMBUS_MESSAGE_SINT; + msg = VMBUS_PCPU_GET(sc, message, curcpu) + VMBUS_SINT_MESSAGE; for (;;) { const hv_vmbus_channel_msg_table_entry *entry; hv_vmbus_channel_msg_header *hdr; @@ -124,34 +124,23 @@ handled: } } -/** - * @brief Interrupt filter routine for VMBUS. - * - * The purpose of this routine is to determine the type of VMBUS protocol - * message to process - an event or a channel message. - */ static inline int hv_vmbus_isr(struct vmbus_softc *sc, struct trapframe *frame, int cpu) { hv_vmbus_message *msg, *msg_base; - /* - * The Windows team has advised that we check for events - * before checking for messages. This is the way they do it - * in Windows when running as a guest in Hyper-V - */ - sc->vmbus_event_proc(sc, cpu); - - /* Check if there are actual msgs to be process */ msg_base = VMBUS_PCPU_GET(sc, message, cpu); - msg = msg_base + HV_VMBUS_TIMER_SINT; - /* we call eventtimer process the message */ + /* + * Check event timer. + * + * TODO: move this to independent IDT vector. + */ + msg = msg_base + VMBUS_SINT_TIMER; if (msg->header.message_type == HV_MESSAGE_TIMER_EXPIRED) { msg->header.message_type = HV_MESSAGE_TYPE_NONE; - /* call intrrupt handler of event timer */ - hv_et_intr(frame); + vmbus_et_intr(frame); /* * Make sure the write to message_type (ie set to @@ -175,8 +164,20 @@ hv_vmbus_isr(struct vmbus_softc *sc, str } } - msg = msg_base + HV_VMBUS_MESSAGE_SINT; - if (msg->header.message_type != HV_MESSAGE_TYPE_NONE) { + /* + * Check events. Hot path for network and storage I/O data; high rate. + * + * NOTE: + * As recommended by the Windows guest fellows, we check events before + * checking messages. + */ + sc->vmbus_event_proc(sc, cpu); + + /* + * Check messages. Mainly management stuffs; ultra low rate. + */ + msg = msg_base + VMBUS_SINT_MESSAGE; + if (__predict_false(msg->header.message_type != HV_MESSAGE_TYPE_NONE)) { taskqueue_enqueue(VMBUS_PCPU_GET(sc, message_tq, cpu), VMBUS_PCPU_PTR(sc, message_task, cpu)); } @@ -254,7 +255,7 @@ vmbus_synic_setup(void *xsc) /* * Configure and unmask SINT for message and event flags. */ - sint = MSR_HV_SINT0 + HV_VMBUS_MESSAGE_SINT; + sint = MSR_HV_SINT0 + VMBUS_SINT_MESSAGE; orig = rdmsr(sint); val = sc->vmbus_idtvec | MSR_HV_SINT_AUTOEOI | (orig & MSR_HV_SINT_RSVD_MASK); @@ -263,7 +264,7 @@ vmbus_synic_setup(void *xsc) /* * Configure and unmask SINT for timer. */ - sint = MSR_HV_SINT0 + HV_VMBUS_TIMER_SINT; + sint = MSR_HV_SINT0 + VMBUS_SINT_TIMER; orig = rdmsr(sint); val = sc->vmbus_idtvec | MSR_HV_SINT_AUTOEOI | (orig & MSR_HV_SINT_RSVD_MASK); @@ -292,14 +293,14 @@ vmbus_synic_teardown(void *arg) /* * Mask message and event flags SINT. */ - sint = MSR_HV_SINT0 + HV_VMBUS_MESSAGE_SINT; + sint = MSR_HV_SINT0 + VMBUS_SINT_MESSAGE; orig = rdmsr(sint); wrmsr(sint, orig | MSR_HV_SINT_MASKED); /* * Mask timer SINT. */ - sint = MSR_HV_SINT0 + HV_VMBUS_TIMER_SINT; + sint = MSR_HV_SINT0 + VMBUS_SINT_TIMER; orig = rdmsr(sint); wrmsr(sint, orig | MSR_HV_SINT_MASKED); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jun 23 09:03:52 2016 (r302135) @@ -189,8 +189,6 @@ enum { HV_VMBUS_EVENT_PORT_ID = 2, HV_VMBUS_MONITOR_CONNECTION_ID = 3, HV_VMBUS_MONITOR_PORT_ID = 3, - HV_VMBUS_MESSAGE_SINT = 2, - HV_VMBUS_TIMER_SINT = 4, }; #define HV_PRESENT_BIT 0x80000000 @@ -542,12 +540,6 @@ int hv_vmbus_disconnect(void); int hv_vmbus_post_message(void *buffer, size_t buf_size); int hv_vmbus_set_event(hv_vmbus_channel *channel); -/** - * Event Timer interfaces - */ -void hv_et_init(void); -void hv_et_intr(struct trapframe*); - /* Wait for device creation */ void vmbus_scan(void); Modified: stable/10/sys/dev/hyperv/vmbus/hyperv_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hyperv_var.h Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_var.h Thu Jun 23 09:03:52 2016 (r302135) @@ -29,6 +29,12 @@ #ifndef _HYPERV_VAR_H_ #define _HYPERV_VAR_H_ +#ifndef NANOSEC +#define NANOSEC 1000000000ULL +#endif +#define HYPERV_TIMER_NS_FACTOR 100ULL +#define HYPERV_TIMER_FREQ (NANOSEC / HYPERV_TIMER_NS_FACTOR) + extern u_int hyperv_features; extern u_int hyperv_recommends; Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 09:02:50 2016 (r302134) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jun 23 09:03:52 2016 (r302135) @@ -30,8 +30,21 @@ #define _VMBUS_VAR_H_ #include +#include + #include +/* + * NOTE: DO NOT CHANGE THIS. + */ +#define VMBUS_SINT_MESSAGE 2 +/* + * NOTE: + * - DO NOT set it to the same value as VMBUS_SINT_MESSAGE. + * - DO NOT set it to 0. + */ +#define VMBUS_SINT_TIMER 4 + struct vmbus_pcpu_data { u_long *intr_cnt; /* Hyper-V interrupt counter */ struct vmbus_message *message; /* shared messages */ @@ -77,8 +90,13 @@ vmbus_get_device(void) #define VMBUS_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field #define VMBUS_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field +struct hv_vmbus_channel; +struct trapframe; + void vmbus_on_channel_open(const struct hv_vmbus_channel *); void vmbus_event_proc(struct vmbus_softc *, int); void vmbus_event_proc_compat(struct vmbus_softc *, int); +void vmbus_et_intr(struct trapframe *); + #endif /* !_VMBUS_VAR_H_ */ From owner-svn-src-stable-10@freebsd.org Thu Jun 23 09:04:51 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8223DB7360A; Thu, 23 Jun 2016 09:04:51 +0000 (UTC) (envelope-from kib@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 59F8F1D46; Thu, 23 Jun 2016 09:04:51 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5N94oGL065974; Thu, 23 Jun 2016 09:04:50 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N94ovK065973; Thu, 23 Jun 2016 09:04:50 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606230904.u5N94ovK065973@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 23 Jun 2016 09:04:50 +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: r302136 - stable/10/sys/dev/cpuctl 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 09:04:51 -0000 Author: kib Date: Thu Jun 23 09:04:50 2016 New Revision: 302136 URL: https://svnweb.freebsd.org/changeset/base/302136 Log: MFC r301962: Always allow loading of cpuctl(4). Modified: stable/10/sys/dev/cpuctl/cpuctl.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/cpuctl/cpuctl.c ============================================================================== --- stable/10/sys/dev/cpuctl/cpuctl.c Thu Jun 23 09:03:52 2016 (r302135) +++ stable/10/sys/dev/cpuctl/cpuctl.c Thu Jun 23 09:04:50 2016 (r302136) @@ -67,9 +67,9 @@ static d_ioctl_t cpuctl_ioctl; static int cpuctl_do_msr(int cpu, cpuctl_msr_args_t *data, u_long cmd, struct thread *td); -static void cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, +static int cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, struct thread *td); -static void cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_count_args_t *data, +static int cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_count_args_t *data, struct thread *td); static int cpuctl_do_update(int cpu, cpuctl_update_args_t *data, struct thread *td); @@ -171,8 +171,7 @@ cpuctl_ioctl(struct cdev *dev, u_long cm ret = cpuctl_do_msr(cpu, (cpuctl_msr_args_t *)data, cmd, td); break; case CPUCTL_CPUID: - cpuctl_do_cpuid(cpu, (cpuctl_cpuid_args_t *)data, td); - ret = 0; + ret = cpuctl_do_cpuid(cpu, (cpuctl_cpuid_args_t *)data, td); break; case CPUCTL_UPDATE: ret = priv_check(td, PRIV_CPUCTL_UPDATE); @@ -181,9 +180,8 @@ cpuctl_ioctl(struct cdev *dev, u_long cm ret = cpuctl_do_update(cpu, (cpuctl_update_args_t *)data, td); break; case CPUCTL_CPUID_COUNT: - cpuctl_do_cpuid_count(cpu, (cpuctl_cpuid_count_args_t *)data, - td); - ret = 0; + ret = cpuctl_do_cpuid_count(cpu, + (cpuctl_cpuid_count_args_t *)data, td); break; default: ret = EINVAL; @@ -196,7 +194,7 @@ fail: /* * Actually perform cpuid operation. */ -static void +static int cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_count_args_t *data, struct thread *td) { @@ -210,23 +208,30 @@ cpuctl_do_cpuid_count(int cpu, cpuctl_cp bzero(data->data, sizeof(data->data)); DPRINTF("[cpuctl,%d]: retrieving cpuid lev %#0x type %#0x for %d cpu\n", __LINE__, data->level, data->level_type, cpu); +#ifdef __i386__ + if (cpu_id == 0) + return (ENODEV); +#endif oldcpu = td->td_oncpu; is_bound = cpu_sched_is_bound(td); set_cpu(cpu, td); cpuid_count(data->level, data->level_type, data->data); restore_cpu(oldcpu, is_bound, td); + return (0); } -static void +static int cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, struct thread *td) { cpuctl_cpuid_count_args_t cdata; + int error; cdata.level = data->level; /* Override the level type. */ cdata.level_type = 0; - cpuctl_do_cpuid_count(cpu, &cdata, td); + error = cpuctl_do_cpuid_count(cpu, &cdata, td); bcopy(cdata.data, data->data, sizeof(data->data)); /* Ignore error */ + return (error); } /* @@ -249,6 +254,10 @@ cpuctl_do_msr(int cpu, cpuctl_msr_args_t */ DPRINTF("[cpuctl,%d]: operating on MSR %#0x for %d cpu\n", __LINE__, data->msr, cpu); +#ifdef __i386__ + if ((cpu_feature & CPUID_MSR) == 0) + return (ENODEV); +#endif oldcpu = td->td_oncpu; is_bound = cpu_sched_is_bound(td); set_cpu(cpu, td); @@ -291,7 +300,9 @@ cpuctl_do_update(int cpu, cpuctl_update_ ("[cpuctl,%d]: bad cpu number %d", __LINE__, cpu)); DPRINTF("[cpuctl,%d]: XXX %d", __LINE__, cpu); - cpuctl_do_cpuid(cpu, &args, td); + ret = cpuctl_do_cpuid(cpu, &args, td); + if (ret != 0) + return (ret); ((uint32_t *)vendor)[0] = args.data[1]; ((uint32_t *)vendor)[1] = args.data[3]; ((uint32_t *)vendor)[2] = args.data[2]; @@ -518,11 +529,6 @@ cpuctl_modevent(module_t mod __unused, i switch(type) { case MOD_LOAD: - if ((cpu_feature & CPUID_MSR) == 0) { - if (bootverbose) - printf("cpuctl: not available.\n"); - return (ENODEV); - } if (bootverbose) printf("cpuctl: access to MSR registers/cpuid info.\n"); cpuctl_devs = malloc(sizeof(*cpuctl_devs) * mp_ncpus, M_CPUCTL, From owner-svn-src-stable-10@freebsd.org Thu Jun 23 09:06:13 2016 Return-Path: Delivered-To: svn-src-stable-10@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 0A3BAB736CC; Thu, 23 Jun 2016 09:06:13 +0000 (UTC) (envelope-from kib@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 D03151FB0; Thu, 23 Jun 2016 09:06:12 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5N96CLn066182; Thu, 23 Jun 2016 09:06:12 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5N96CFl066181; Thu, 23 Jun 2016 09:06:12 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606230906.u5N96CFl066181@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 23 Jun 2016 09:06:12 +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: r302137 - stable/10/usr.sbin/cpucontrol 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2016 09:06:13 -0000 Author: kib Date: Thu Jun 23 09:06:11 2016 New Revision: 302137 URL: https://svnweb.freebsd.org/changeset/base/302137 Log: MFC r301963: Return usual error indicator to shell. Modified: stable/10/usr.sbin/cpucontrol/cpucontrol.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/cpucontrol/cpucontrol.c ============================================================================== --- stable/10/usr.sbin/cpucontrol/cpucontrol.c Thu Jun 23 09:04:50 2016 (r302136) +++ stable/10/usr.sbin/cpucontrol/cpucontrol.c Thu Jun 23 09:06:11 2016 (r302137) @@ -481,5 +481,5 @@ main(int argc, char *argv[]) usage(); /* Only one command can be selected. */ } SLIST_FREE(&datadirs, next, free); - return (error); + return (error == 0 ? 0 : 1); } From owner-svn-src-stable-10@freebsd.org Fri Jun 24 01:20:35 2016 Return-Path: Delivered-To: svn-src-stable-10@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 BC4F2B72AF1; Fri, 24 Jun 2016 01:20:35 +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 80EA024F6; Fri, 24 Jun 2016 01:20:35 +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 u5O1KYPe039084; Fri, 24 Jun 2016 01:20:34 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5O1KYTB039078; Fri, 24 Jun 2016 01:20:34 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606240120.u5O1KYTB039078@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 24 Jun 2016 01:20:34 +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: r302165 - in stable/10/sys: amd64/include dev/hyperv/vmbus dev/hyperv/vmbus/amd64 dev/hyperv/vmbus/i386 i386/include 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2016 01:20:35 -0000 Author: sephe Date: Fri Jun 24 01:20:33 2016 New Revision: 302165 URL: https://svnweb.freebsd.org/changeset/base/302165 Log: MFC 301015 hyperv/vmbus: Rename ISR functions MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6601 Modified: stable/10/sys/amd64/include/apicvar.h stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S stable/10/sys/dev/hyperv/vmbus/vmbus_var.h stable/10/sys/i386/include/apicvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/include/apicvar.h ============================================================================== --- stable/10/sys/amd64/include/apicvar.h Fri Jun 24 00:05:45 2016 (r302164) +++ stable/10/sys/amd64/include/apicvar.h Fri Jun 24 01:20:33 2016 (r302165) @@ -216,7 +216,6 @@ int lapic_set_lvt_triggermode(u_int apic void lapic_set_tpr(u_int vector); void lapic_setup(int boot); void xen_intr_handle_upcall(struct trapframe *frame); -void hv_vector_handler(struct trapframe *frame); #endif /* !LOCORE */ #endif /* _MACHINE_APICVAR_H_ */ Modified: stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S Fri Jun 24 00:05:45 2016 (r302164) +++ stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S Fri Jun 24 01:20:33 2016 (r302165) @@ -37,10 +37,10 @@ */ .text SUPERALIGN_TEXT -IDTVEC(hv_vmbus_callback) +IDTVEC(vmbus_isr) PUSH_FRAME FAKE_MCOUNT(TF_RIP(%rsp)) movq %rsp, %rdi - call hv_vector_handler + call vmbus_handle_intr MEXITCOUNT jmp doreti Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Fri Jun 24 00:05:45 2016 (r302164) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Fri Jun 24 01:20:33 2016 (r302165) @@ -72,7 +72,7 @@ struct vmbus_softc *vmbus_sc; static char *vmbus_ids[] = { "VMBUS", NULL }; -extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback); +extern inthand_t IDTVEC(rsvd), IDTVEC(vmbus_isr); static void vmbus_msg_task(void *xsc, int pending __unused) @@ -124,8 +124,8 @@ handled: } } -static inline int -hv_vmbus_isr(struct vmbus_softc *sc, struct trapframe *frame, int cpu) +static __inline int +vmbus_handle_intr1(struct vmbus_softc *sc, struct trapframe *frame, int cpu) { hv_vmbus_message *msg, *msg_base; @@ -186,7 +186,7 @@ hv_vmbus_isr(struct vmbus_softc *sc, str } void -hv_vector_handler(struct trapframe *trap_frame) +vmbus_handle_intr(struct trapframe *trap_frame) { struct vmbus_softc *sc = vmbus_get_softc(); int cpu = curcpu; @@ -201,7 +201,7 @@ hv_vector_handler(struct trapframe *trap */ (*VMBUS_PCPU_GET(sc, intr_cnt, cpu))++; - hv_vmbus_isr(sc, trap_frame, cpu); + vmbus_handle_intr1(sc, trap_frame, cpu); /* * Enable preemption. @@ -389,10 +389,10 @@ vmbus_vector_alloc(void) func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); if (func == (uintptr_t)&IDTVEC(rsvd)) { #ifdef __i386__ - setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYS386IGT, + setidt(vector , IDTVEC(vmbus_isr), SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); #else - setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYSIGT, + setidt(vector , IDTVEC(vmbus_isr), SDT_SYSIGT, SEL_KPL, 0); #endif Modified: stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S Fri Jun 24 00:05:45 2016 (r302164) +++ stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S Fri Jun 24 01:20:33 2016 (r302165) @@ -37,13 +37,13 @@ */ .text SUPERALIGN_TEXT -IDTVEC(hv_vmbus_callback) +IDTVEC(vmbus_isr) PUSH_FRAME SET_KERNEL_SREGS cld FAKE_MCOUNT(TF_EIP(%esp)) pushl %esp - call hv_vector_handler + call vmbus_handle_intr add $4, %esp MEXITCOUNT jmp doreti Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Fri Jun 24 00:05:45 2016 (r302164) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Fri Jun 24 01:20:33 2016 (r302165) @@ -96,6 +96,7 @@ struct trapframe; void vmbus_on_channel_open(const struct hv_vmbus_channel *); void vmbus_event_proc(struct vmbus_softc *, int); void vmbus_event_proc_compat(struct vmbus_softc *, int); +void vmbus_handle_intr(struct trapframe *); void vmbus_et_intr(struct trapframe *); Modified: stable/10/sys/i386/include/apicvar.h ============================================================================== --- stable/10/sys/i386/include/apicvar.h Fri Jun 24 00:05:45 2016 (r302164) +++ stable/10/sys/i386/include/apicvar.h Fri Jun 24 01:20:33 2016 (r302165) @@ -215,7 +215,6 @@ int lapic_set_lvt_triggermode(u_int apic void lapic_set_tpr(u_int vector); void lapic_setup(int boot); void xen_intr_handle_upcall(struct trapframe *frame); -void hv_vector_handler(struct trapframe *frame); #endif /* !LOCORE */ #endif /* _MACHINE_APICVAR_H_ */ From owner-svn-src-stable-10@freebsd.org Fri Jun 24 01:50:01 2016 Return-Path: Delivered-To: svn-src-stable-10@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 EB79AB73262; Fri, 24 Jun 2016 01:50:01 +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 AFE5F1244; Fri, 24 Jun 2016 01:50:01 +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 u5O1o0Uc050036; Fri, 24 Jun 2016 01:50:00 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5O1nxAR050000; Fri, 24 Jun 2016 01:49:59 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606240149.u5O1nxAR050000@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 24 Jun 2016 01:49:59 +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: r302166 - in stable/10/sys/dev/hyperv: include utilities vmbus vmbus/i386 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2016 01:50:02 -0000 Author: sephe Date: Fri Jun 24 01:49:59 2016 New Revision: 302166 URL: https://svnweb.freebsd.org/changeset/base/302166 Log: MFC 301017,301018,301019,301020,301021,301022,301106 301017 hyperv/vmbus: Indentation cleanup No functional changes. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6602 301018 hyperv/vmbus: Move global vmbus id array to stack. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6603 301019 hyperv/vmbus: Redefine SynIC message. - Avoid unnecessary indirection. - Avoid bit fields. - Use __packed. Reviewed by: Jun Su MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6636 301020 hyperv/vmbus: White space cleanup No functional changes MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6637 301021 hyperv: Move guid2str from vmbus file to hyperv file - Use uint8_t for GUID byte array. - Define GUID string length. - Break long lines. - Nuke unnecessary stack variable. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6640 301022 hyperv/kvp: Use if_xname. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6641 301106 hyperv/vmbus: Redefine event flags. - Nuke unnecessary union. - Avoid convoluted macro indirection. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6671 Added: stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h - copied, changed from r301019, head/sys/dev/hyperv/vmbus/vmbus_reg.h Modified: stable/10/sys/dev/hyperv/include/hyperv.h stable/10/sys/dev/hyperv/utilities/hv_kvp.c stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/include/hyperv.h ============================================================================== --- stable/10/sys/dev/hyperv/include/hyperv.h Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/include/hyperv.h Fri Jun 24 01:49:59 2016 (r302166) @@ -121,10 +121,12 @@ typedef uint8_t hv_bool_uint8_t; HV_ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT ) typedef struct hv_guid { - unsigned char data[16]; + uint8_t data[16]; } __packed hv_guid; -int snprintf_hv_guid(char *, size_t, const hv_guid *); +#define HYPERV_GUID_STRLEN 40 + +int hyperv_guid2str(const struct hv_guid *, char *, size_t); #define HV_NIC_GUID \ .data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, \ Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.c Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.c Fri Jun 24 01:49:59 2016 (r302166) @@ -58,7 +58,10 @@ __FBSDID("$FreeBSD$"); #include #include #include + +#include #include +#include #include #include @@ -306,8 +309,7 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru int UNUSED_FLAG = 1; struct hv_device *hv_dev; /* GUID Data Structure */ hn_softc_t *sc; /* hn softc structure */ - char if_name[4]; - char buf[39]; + char buf[HYPERV_GUID_STRLEN]; device_t *devs; int devcnt; @@ -335,11 +337,12 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru /* Trying to find GUID of Network Device */ hv_dev = sc->hn_dev_obj; - snprintf_hv_guid(buf, sizeof(buf), &hv_dev->device_id); - sprintf(if_name, "%s%d", "hn", device_get_unit(devs[devcnt])); + hyperv_guid2str(&hv_dev->device_id, buf, sizeof(buf)); - if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id, 39) == 0) { - strcpy((char *)umsg->body.kvp_ip_val.adapter_id, if_name); + if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id, + HYPERV_GUID_STRLEN - 1) == 0) { + strlcpy((char *)umsg->body.kvp_ip_val.adapter_id, + sc->hn_ifp->if_xname, MAX_ADAPTER_ID_SIZE); break; } } Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Fri Jun 24 01:49:59 2016 (r302166) @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include /* @@ -720,8 +721,8 @@ hv_vmbus_release_unattached_channels(voi } hv_vmbus_free_vmbus_channel(channel); } - bzero(hv_vmbus_g_connection.channels, - sizeof(hv_vmbus_channel*) * HV_CHANNEL_MAX_COUNT); + bzero(hv_vmbus_g_connection.channels, + sizeof(hv_vmbus_channel*) * VMBUS_CHAN_MAX); mtx_unlock(&hv_vmbus_g_connection.channel_lock); } Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Fri Jun 24 01:49:59 2016 (r302166) @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include /* @@ -212,8 +213,7 @@ hv_vmbus_connect(void) M_DEVBUF, M_WAITOK | M_ZERO); hv_vmbus_g_connection.channels = malloc(sizeof(hv_vmbus_channel*) * - HV_CHANNEL_MAX_COUNT, - M_DEVBUF, M_WAITOK | M_ZERO); + VMBUS_CHAN_MAX, M_DEVBUF, M_WAITOK | M_ZERO); /* * Find the highest vmbus version number we can support. */ @@ -295,20 +295,20 @@ hv_vmbus_disconnect(void) } static __inline void -vmbus_event_flags_proc(unsigned long *event_flags, int flag_cnt) +vmbus_event_flags_proc(volatile u_long *event_flags, int flag_cnt) { int f; for (f = 0; f < flag_cnt; ++f) { uint32_t rel_id_base; - unsigned long flags; + u_long flags; int bit; if (event_flags[f] == 0) continue; flags = atomic_swap_long(&event_flags[f], 0); - rel_id_base = f << HV_CHANNEL_ULONG_SHIFT; + rel_id_base = f << VMBUS_EVTFLAG_SHIFT; while ((bit = ffsl(flags)) != 0) { struct hv_vmbus_channel *channel; @@ -334,27 +334,27 @@ vmbus_event_flags_proc(unsigned long *ev void vmbus_event_proc(struct vmbus_softc *sc, int cpu) { - hv_vmbus_synic_event_flags *event; + struct vmbus_evtflags *eventf; /* * On Host with Win8 or above, the event page can be checked directly * to get the id of the channel that has the pending interrupt. */ - event = VMBUS_PCPU_GET(sc, event_flag, cpu) + VMBUS_SINT_MESSAGE; - vmbus_event_flags_proc(event->flagsul, - VMBUS_PCPU_GET(sc, event_flag_cnt, cpu)); + eventf = VMBUS_PCPU_GET(sc, event_flags, cpu) + VMBUS_SINT_MESSAGE; + vmbus_event_flags_proc(eventf->evt_flags, + VMBUS_PCPU_GET(sc, event_flags_cnt, cpu)); } void vmbus_event_proc_compat(struct vmbus_softc *sc __unused, int cpu) { - hv_vmbus_synic_event_flags *event; + struct vmbus_evtflags *eventf; - event = VMBUS_PCPU_GET(sc, event_flag, cpu) + VMBUS_SINT_MESSAGE; - if (atomic_testandclear_int(&event->flags32[0], 0)) { + eventf = VMBUS_PCPU_GET(sc, event_flags, cpu) + VMBUS_SINT_MESSAGE; + if (atomic_testandclear_long(&eventf->evt_flags[0], 0)) { vmbus_event_flags_proc( hv_vmbus_g_connection.recv_interrupt_page, - HV_MAX_NUM_CHANNELS_SUPPORTED >> HV_CHANNEL_ULONG_SHIFT); + VMBUS_CHAN_MAX_COMPAT >> VMBUS_EVTFLAG_SHIFT); } } @@ -417,8 +417,8 @@ vmbus_on_channel_open(const struct hv_vm volatile int *flag_cnt_ptr; int flag_cnt; - flag_cnt = (chan->offer_msg.child_rel_id / HV_CHANNEL_ULONG_LEN) + 1; - flag_cnt_ptr = VMBUS_PCPU_PTR(vmbus_get_softc(), event_flag_cnt, + flag_cnt = (chan->offer_msg.child_rel_id / VMBUS_EVTFLAG_LEN) + 1; + flag_cnt_ptr = VMBUS_PCPU_PTR(vmbus_get_softc(), event_flags_cnt, chan->target_cpu); for (;;) { Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Fri Jun 24 01:49:59 2016 (r302166) @@ -202,6 +202,18 @@ hv_vmbus_signal_event(void *con_id) return (status); } +int +hyperv_guid2str(const struct hv_guid *guid, char *buf, size_t sz) +{ + const uint8_t *d = guid->data; + + return snprintf(buf, sz, "%02x%02x%02x%02x-" + "%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x", + d[3], d[2], d[1], d[0], + d[5], d[4], d[7], d[6], d[8], d[9], + d[10], d[11], d[12], d[13], d[14], d[15]); +} static bool hyperv_identify(void) Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Fri Jun 24 01:49:59 2016 (r302166) @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -70,15 +71,13 @@ __FBSDID("$FreeBSD$"); struct vmbus_softc *vmbus_sc; -static char *vmbus_ids[] = { "VMBUS", NULL }; - extern inthand_t IDTVEC(rsvd), IDTVEC(vmbus_isr); static void vmbus_msg_task(void *xsc, int pending __unused) { struct vmbus_softc *sc = xsc; - hv_vmbus_message *msg; + volatile struct vmbus_message *msg; msg = VMBUS_PCPU_GET(sc, message, curcpu) + VMBUS_SINT_MESSAGE; for (;;) { @@ -86,10 +85,12 @@ vmbus_msg_task(void *xsc, int pending __ hv_vmbus_channel_msg_header *hdr; hv_vmbus_channel_msg_type msg_type; - if (msg->header.message_type == HV_MESSAGE_TYPE_NONE) + if (msg->msg_type == VMBUS_MSGTYPE_NONE) break; /* no message */ - hdr = (hv_vmbus_channel_msg_header *)msg->u.payload; + /* XXX: update messageHandler interface */ + hdr = __DEVOLATILE(hv_vmbus_channel_msg_header *, + msg->msg_data); msg_type = hdr->message_type; if (msg_type >= HV_CHANNEL_MESSAGE_COUNT) { @@ -101,20 +102,20 @@ vmbus_msg_task(void *xsc, int pending __ if (entry->messageHandler) entry->messageHandler(hdr); handled: - msg->header.message_type = HV_MESSAGE_TYPE_NONE; + msg->msg_type = VMBUS_MSGTYPE_NONE; /* - * Make sure the write to message_type (ie set to - * HV_MESSAGE_TYPE_NONE) happens before we read the - * message_pending and EOMing. Otherwise, the EOMing will - * not deliver any more messages - * since there is no empty slot + * Make sure the write to msg_type (i.e. set to + * VMBUS_MSGTYPE_NONE) happens before we read the + * msg_flags and EOMing. Otherwise, the EOMing will + * not deliver any more messages since there is no + * empty slot * * NOTE: * mb() is used here, since atomic_thread_fence_seq_cst() * will become compiler fence on UP kernel. */ mb(); - if (msg->header.message_flags.u.message_pending) { + if (msg->msg_flags & VMBUS_MSGFLAG_PENDING) { /* * This will cause message queue rescan to possibly * deliver another msg from the hypervisor @@ -127,7 +128,8 @@ handled: static __inline int vmbus_handle_intr1(struct vmbus_softc *sc, struct trapframe *frame, int cpu) { - hv_vmbus_message *msg, *msg_base; + volatile struct vmbus_message *msg; + struct vmbus_message *msg_base; msg_base = VMBUS_PCPU_GET(sc, message, cpu); @@ -137,25 +139,24 @@ vmbus_handle_intr1(struct vmbus_softc *s * TODO: move this to independent IDT vector. */ msg = msg_base + VMBUS_SINT_TIMER; - if (msg->header.message_type == HV_MESSAGE_TIMER_EXPIRED) { - msg->header.message_type = HV_MESSAGE_TYPE_NONE; + if (msg->msg_type == VMBUS_MSGTYPE_TIMER_EXPIRED) { + msg->msg_type = VMBUS_MSGTYPE_NONE; vmbus_et_intr(frame); /* - * Make sure the write to message_type (ie set to - * HV_MESSAGE_TYPE_NONE) happens before we read the - * message_pending and EOMing. Otherwise, the EOMing will - * not deliver any more messages - * since there is no empty slot + * Make sure the write to msg_type (i.e. set to + * VMBUS_MSGTYPE_NONE) happens before we read the + * msg_flags and EOMing. Otherwise, the EOMing will + * not deliver any more messages since there is no + * empty slot * * NOTE: * mb() is used here, since atomic_thread_fence_seq_cst() * will become compiler fence on UP kernel. */ mb(); - - if (msg->header.message_flags.u.message_pending) { + if (msg->msg_flags & VMBUS_MSGFLAG_PENDING) { /* * This will cause message queue rescan to possibly * deliver another msg from the hypervisor @@ -177,7 +178,7 @@ vmbus_handle_intr1(struct vmbus_softc *s * Check messages. Mainly management stuffs; ultra low rate. */ msg = msg_base + VMBUS_SINT_MESSAGE; - if (__predict_false(msg->header.message_type != HV_MESSAGE_TYPE_NONE)) { + if (__predict_false(msg->msg_type != VMBUS_MSGTYPE_NONE)) { taskqueue_enqueue(VMBUS_PCPU_GET(sc, message_tq, cpu), VMBUS_PCPU_PTR(sc, message_task, cpu)); } @@ -247,8 +248,8 @@ vmbus_synic_setup(void *xsc) */ orig = rdmsr(MSR_HV_SIEFP); val = MSR_HV_SIEFP_ENABLE | (orig & MSR_HV_SIEFP_RSVD_MASK) | - ((VMBUS_PCPU_GET(sc, event_flag_dma.hv_paddr, cpu) >> PAGE_SHIFT) << - MSR_HV_SIEFP_PGSHIFT); + ((VMBUS_PCPU_GET(sc, event_flags_dma.hv_paddr, cpu) + >> PAGE_SHIFT) << MSR_HV_SIEFP_PGSHIFT); wrmsr(MSR_HV_SIEFP, val); @@ -338,11 +339,11 @@ vmbus_dma_alloc(struct vmbus_softc *sc) ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), PAGE_SIZE, 0, PAGE_SIZE, - VMBUS_PCPU_PTR(sc, event_flag_dma, cpu), + VMBUS_PCPU_PTR(sc, event_flags_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); if (ptr == NULL) return ENOMEM; - VMBUS_PCPU_GET(sc, event_flag, cpu) = ptr; + VMBUS_PCPU_GET(sc, event_flags, cpu) = ptr; } return 0; } @@ -359,11 +360,11 @@ vmbus_dma_free(struct vmbus_softc *sc) VMBUS_PCPU_GET(sc, message, cpu)); VMBUS_PCPU_GET(sc, message, cpu) = NULL; } - if (VMBUS_PCPU_GET(sc, event_flag, cpu) != NULL) { + if (VMBUS_PCPU_GET(sc, event_flags, cpu) != NULL) { hyperv_dmamem_free( - VMBUS_PCPU_PTR(sc, event_flag_dma, cpu), - VMBUS_PCPU_GET(sc, event_flag, cpu)); - VMBUS_PCPU_GET(sc, event_flag, cpu) = NULL; + VMBUS_PCPU_PTR(sc, event_flags_dma, cpu), + VMBUS_PCPU_GET(sc, event_flags, cpu)); + VMBUS_PCPU_GET(sc, event_flags, cpu) = NULL; } } } @@ -534,16 +535,19 @@ vmbus_read_ivar(device_t dev, device_t c switch (index) { case HV_VMBUS_IVAR_TYPE: - *result = (uintptr_t) &child_dev_ctx->class_id; + *result = (uintptr_t)&child_dev_ctx->class_id; return (0); + case HV_VMBUS_IVAR_INSTANCE: - *result = (uintptr_t) &child_dev_ctx->device_id; + *result = (uintptr_t)&child_dev_ctx->device_id; return (0); + case HV_VMBUS_IVAR_DEVCTX: - *result = (uintptr_t) child_dev_ctx; + *result = (uintptr_t)child_dev_ctx; return (0); + case HV_VMBUS_IVAR_NODE: - *result = (uintptr_t) child_dev_ctx->device; + *result = (uintptr_t)child_dev_ctx->device; return (0); } return (ENOENT); @@ -566,18 +570,18 @@ vmbus_write_ivar(device_t dev, device_t static int vmbus_child_pnpinfo_str(device_t dev, device_t child, char *buf, size_t buflen) { - char guidbuf[40]; struct hv_device *dev_ctx = device_get_ivars(child); + char guidbuf[HYPERV_GUID_STRLEN]; if (dev_ctx == NULL) return (0); strlcat(buf, "classid=", buflen); - snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->class_id); + hyperv_guid2str(&dev_ctx->class_id, guidbuf, sizeof(guidbuf)); strlcat(buf, guidbuf, buflen); strlcat(buf, " deviceid=", buflen); - snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->device_id); + hyperv_guid2str(&dev_ctx->device_id, guidbuf, sizeof(guidbuf)); strlcat(buf, guidbuf, buflen); return (0); @@ -602,30 +606,19 @@ hv_vmbus_child_device_create(hv_guid typ } int -snprintf_hv_guid(char *buf, size_t sz, const hv_guid *guid) -{ - int cnt; - const unsigned char *d = guid->data; - - cnt = snprintf(buf, sz, - "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6], - d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); - return (cnt); -} - -int hv_vmbus_child_device_register(struct hv_device *child_dev) { - device_t child; + device_t child, parent; + parent = vmbus_get_device(); if (bootverbose) { - char name[40]; - snprintf_hv_guid(name, sizeof(name), &child_dev->class_id); - printf("VMBUS: Class ID: %s\n", name); + char name[HYPERV_GUID_STRLEN]; + + hyperv_guid2str(&child_dev->class_id, name, sizeof(name)); + device_printf(parent, "add device, classid: %s\n", name); } - child = device_add_child(vmbus_get_device(), NULL, -1); + child = device_add_child(parent, NULL, -1); child_dev->device = child; device_set_ivars(child, child_dev); @@ -649,7 +642,9 @@ hv_vmbus_child_device_unregister(struct static int vmbus_probe(device_t dev) { - if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL || + char *id[] = { "VMBUS", NULL }; + + if (ACPI_ID_PROBE(device_get_parent(dev), dev, id) == NULL || device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV || (hyperv_features & CPUID_HV_MSR_SYNIC) == 0) return (ENXIO); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Fri Jun 24 01:49:59 2016 (r302166) @@ -51,28 +51,6 @@ typedef uint16_t hv_vmbus_status; #define HV_ANY_VP (0xFFFFFFFF) /* - * Synthetic interrupt controller flag constants. - */ - -#define HV_EVENT_FLAGS_COUNT (256 * 8) -#define HV_EVENT_FLAGS_BYTE_COUNT (256) -#define HV_EVENT_FLAGS_DWORD_COUNT (256 / sizeof(uint32_t)) -#define HV_EVENT_FLAGS_ULONG_COUNT (256 / sizeof(unsigned long)) - -/** - * max channel count <== event_flags_dword_count * bit_of_dword - */ -#ifdef __LP64__ -#define HV_CHANNEL_ULONG_LEN (64) -#define HV_CHANNEL_ULONG_SHIFT (6) -#else -#define HV_CHANNEL_ULONG_LEN (32) -#define HV_CHANNEL_ULONG_SHIFT (5) -#endif -#define HV_CHANNEL_DWORD_LEN (32) -#define HV_CHANNEL_MAX_COUNT \ - ((HV_EVENT_FLAGS_DWORD_COUNT) * HV_CHANNEL_DWORD_LEN) -/* * MessageId: HV_STATUS_INSUFFICIENT_BUFFERS * MessageText: * You did not supply enough message buffers to send a message. @@ -195,9 +173,6 @@ enum { #define HV_HYPERCALL_PARAM_ALIGN sizeof(uint64_t) -struct vmbus_message; -union vmbus_event_flags; - /* * Define hypervisor message types */ @@ -251,59 +226,9 @@ typedef union _hv_vmbus_port_id { } u ; } hv_vmbus_port_id; -/* - * Define synthetic interrupt controller message flag - */ -typedef union { - uint8_t as_uint8_t; - struct { - uint8_t message_pending:1; - uint8_t reserved:7; - } u; -} hv_vmbus_msg_flags; - typedef uint64_t hv_vmbus_partition_id; /* - * Define synthetic interrupt controller message header - */ -typedef struct { - hv_vmbus_msg_type message_type; - uint8_t payload_size; - hv_vmbus_msg_flags message_flags; - uint8_t reserved[2]; - union { - hv_vmbus_partition_id sender; - hv_vmbus_port_id port; - } u; -} hv_vmbus_msg_header; - -/* - * Define synthetic interrupt controller message format - */ -typedef struct vmbus_message { - hv_vmbus_msg_header header; - union { - uint64_t payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; - } u ; -} hv_vmbus_message; - -/* - * Maximum channels is determined by the size of the interrupt - * page which is PAGE_SIZE. 1/2 of PAGE_SIZE is for - * send endpoint interrupt and the other is receive - * endpoint interrupt. - * - * Note: (PAGE_SIZE >> 1) << 3 allocates 16348 channels - */ -#define HV_MAX_NUM_CHANNELS (PAGE_SIZE >> 1) << 3 - -/* - * (The value here must be in multiple of 32) - */ -#define HV_MAX_NUM_CHANNELS_SUPPORTED 256 - -/* * VM Bus connection states */ typedef enum { @@ -426,16 +351,6 @@ typedef struct { } hv_vmbus_input_post_message; /* - * Define the synthetic interrupt controller event flags format - */ -typedef union vmbus_event_flags { - uint8_t flags8[HV_EVENT_FLAGS_BYTE_COUNT]; - uint32_t flags32[HV_EVENT_FLAGS_DWORD_COUNT]; - unsigned long flagsul[HV_EVENT_FLAGS_ULONG_COUNT]; -} hv_vmbus_synic_event_flags; -CTASSERT(sizeof(hv_vmbus_synic_event_flags) == HV_EVENT_FLAGS_BYTE_COUNT); - -/* * Declare the various hypercall operations */ typedef enum { Modified: stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S Fri Jun 24 01:49:59 2016 (r302166) @@ -35,15 +35,15 @@ * This is the Hyper-V vmbus channel direct callback interrupt. * Only used when it is running on Hyper-V. */ - .text - SUPERALIGN_TEXT + .text + SUPERALIGN_TEXT IDTVEC(vmbus_isr) - PUSH_FRAME - SET_KERNEL_SREGS - cld - FAKE_MCOUNT(TF_EIP(%esp)) - pushl %esp - call vmbus_handle_intr - add $4, %esp - MEXITCOUNT - jmp doreti + PUSH_FRAME + SET_KERNEL_SREGS + cld + FAKE_MCOUNT(TF_EIP(%esp)) + pushl %esp + call vmbus_handle_intr + add $4, %esp + MEXITCOUNT + jmp doreti Copied and modified: stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h (from r301019, head/sys/dev/hyperv/vmbus/vmbus_reg.h) ============================================================================== --- head/sys/dev/hyperv/vmbus/vmbus_reg.h Tue May 31 05:18:55 2016 (r301019, copy source) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h Fri Jun 24 01:49:59 2016 (r302166) @@ -53,4 +53,30 @@ CTASSERT(sizeof(struct vmbus_message) == #define VMBUS_MSGFLAG_PENDING 0x01 +/* + * Hyper-V SynIC event flags + */ + +#ifdef __LP64__ +#define VMBUS_EVTFLAGS_MAX 32 +#define VMBUS_EVTFLAG_SHIFT 6 +#else +#define VMBUS_EVTFLAGS_MAX 64 +#define VMBUS_EVTFLAG_SHIFT 5 +#endif +#define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT) +#define VMBUS_EVTFLAGS_SIZE 256 + +struct vmbus_evtflags { + u_long evt_flags[VMBUS_EVTFLAGS_MAX]; +} __packed; +CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE); + +/* + * Channel + */ + +#define VMBUS_CHAN_MAX_COMPAT 256 +#define VMBUS_CHAN_MAX (VMBUS_EVTFLAG_LEN * VMBUS_EVTFLAGS_MAX) + #endif /* !_VMBUS_REG_H_ */ Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Fri Jun 24 01:20:33 2016 (r302165) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Fri Jun 24 01:49:59 2016 (r302166) @@ -49,12 +49,12 @@ struct vmbus_pcpu_data { u_long *intr_cnt; /* Hyper-V interrupt counter */ struct vmbus_message *message; /* shared messages */ uint32_t vcpuid; /* virtual cpuid */ - int event_flag_cnt; /* # of event flags */ - union vmbus_event_flags *event_flag; /* shared event flags */ + int event_flags_cnt;/* # of event flags */ + struct vmbus_evtflags *event_flags; /* shared event flags */ /* Rarely used fields */ struct hyperv_dma message_dma; /* busdma glue */ - struct hyperv_dma event_flag_dma; /* busdma glue */ + struct hyperv_dma event_flags_dma;/* busdma glue */ struct taskqueue *event_tq; /* event taskq */ struct taskqueue *message_tq; /* message taskq */ struct task message_task; /* message task */ From owner-svn-src-stable-10@freebsd.org Fri Jun 24 02:06:15 2016 Return-Path: Delivered-To: svn-src-stable-10@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 1B151B73515; Fri, 24 Jun 2016 02:06:15 +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 DA7811A86; Fri, 24 Jun 2016 02:06:14 +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 u5O26Eg8057313; Fri, 24 Jun 2016 02:06:14 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5O26Dxh057306; Fri, 24 Jun 2016 02:06:13 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606240206.u5O26Dxh057306@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 24 Jun 2016 02:06:13 +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: r302167 - in stable/10/sys: conf dev/hyperv/vmbus dev/hyperv/vmbus/amd64 dev/hyperv/vmbus/i386 modules/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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2016 02:06:15 -0000 Author: sephe Date: Fri Jun 24 02:06:13 2016 New Revision: 302167 URL: https://svnweb.freebsd.org/changeset/base/302167 Log: MFC 301113 hyperv: Rename some cleaned up/almost cleaned up files MFC after: 1 week Sponsored by: Microsoft OSTC Added: stable/10/sys/dev/hyperv/vmbus/amd64/vmbus_vector.S - copied unchanged from r302166, stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S stable/10/sys/dev/hyperv/vmbus/hyperv.c - copied unchanged from r302166, stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/i386/vmbus_vector.S - copied unchanged from r302166, stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S stable/10/sys/dev/hyperv/vmbus/vmbus.c - copied unchanged from r302166, stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/vmbus_et.c - copied unchanged from r302166, stable/10/sys/dev/hyperv/vmbus/hv_et.c Deleted: stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S stable/10/sys/dev/hyperv/vmbus/hv_et.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S Modified: stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/modules/hyperv/vmbus/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Fri Jun 24 01:49:59 2016 (r302166) +++ stable/10/sys/conf/files.amd64 Fri Jun 24 02:06:13 2016 (r302167) @@ -274,12 +274,12 @@ dev/hyperv/utilities/hv_util.c option dev/hyperv/vmbus/hv_channel.c optional hyperv dev/hyperv/vmbus/hv_channel_mgmt.c optional hyperv dev/hyperv/vmbus/hv_connection.c optional hyperv -dev/hyperv/vmbus/hv_hv.c optional hyperv -dev/hyperv/vmbus/hv_et.c optional hyperv dev/hyperv/vmbus/hv_ring_buffer.c optional hyperv -dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c optional hyperv +dev/hyperv/vmbus/hyperv.c optional hyperv dev/hyperv/vmbus/hyperv_busdma.c optional hyperv -dev/hyperv/vmbus/amd64/hv_vector.S optional hyperv +dev/hyperv/vmbus/vmbus.c optional hyperv +dev/hyperv/vmbus/vmbus_et.c optional hyperv +dev/hyperv/vmbus/amd64/vmbus_vector.S optional hyperv dev/kbd/kbd.c optional atkbd | sc | ukbd | vt dev/lindev/full.c optional lindev dev/lindev/lindev.c optional lindev Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Fri Jun 24 01:49:59 2016 (r302166) +++ stable/10/sys/conf/files.i386 Fri Jun 24 02:06:13 2016 (r302167) @@ -250,12 +250,12 @@ dev/hyperv/utilities/hv_util.c option dev/hyperv/vmbus/hv_channel.c optional hyperv dev/hyperv/vmbus/hv_channel_mgmt.c optional hyperv dev/hyperv/vmbus/hv_connection.c optional hyperv -dev/hyperv/vmbus/hv_hv.c optional hyperv -dev/hyperv/vmbus/hv_et.c optional hyperv dev/hyperv/vmbus/hv_ring_buffer.c optional hyperv -dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c optional hyperv +dev/hyperv/vmbus/hyperv.c optional hyperv dev/hyperv/vmbus/hyperv_busdma.c optional hyperv -dev/hyperv/vmbus/i386/hv_vector.S optional hyperv +dev/hyperv/vmbus/vmbus.c optional hyperv +dev/hyperv/vmbus/vmbus_et.c optional hyperv +dev/hyperv/vmbus/i386/vmbus_vector.S optional hyperv dev/ichwd/ichwd.c optional ichwd dev/if_ndis/if_ndis.c optional ndis dev/if_ndis/if_ndis_pccard.c optional ndis pccard Copied: stable/10/sys/dev/hyperv/vmbus/amd64/vmbus_vector.S (from r302166, stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/amd64/vmbus_vector.S Fri Jun 24 02:06:13 2016 (r302167, copy of r302166, stable/10/sys/dev/hyperv/vmbus/amd64/hv_vector.S) @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include + +#include "assym.s" + +/* + * This is the Hyper-V vmbus channel direct callback interrupt. + * Only used when it is running on Hyper-V. + */ + .text + SUPERALIGN_TEXT +IDTVEC(vmbus_isr) + PUSH_FRAME + FAKE_MCOUNT(TF_RIP(%rsp)) + movq %rsp, %rdi + call vmbus_handle_intr + MEXITCOUNT + jmp doreti Copied: stable/10/sys/dev/hyperv/vmbus/hyperv.c (from r302166, stable/10/sys/dev/hyperv/vmbus/hv_hv.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/hyperv.c Fri Jun 24 02:06:13 2016 (r302167, copy of r302166, stable/10/sys/dev/hyperv/vmbus/hv_hv.c) @@ -0,0 +1,404 @@ +/*- + * Copyright (c) 2009-2012,2016 Microsoft Corp. + * Copyright (c) 2012 NetApp Inc. + * Copyright (c) 2012 Citrix Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Implements low-level interactions with Hypver-V/Azure + */ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define HYPERV_FREEBSD_BUILD 0ULL +#define HYPERV_FREEBSD_VERSION ((uint64_t)__FreeBSD_version) +#define HYPERV_FREEBSD_OSID 0ULL + +#define MSR_HV_GUESTID_BUILD_FREEBSD \ + (HYPERV_FREEBSD_BUILD & MSR_HV_GUESTID_BUILD_MASK) +#define MSR_HV_GUESTID_VERSION_FREEBSD \ + ((HYPERV_FREEBSD_VERSION << MSR_HV_GUESTID_VERSION_SHIFT) & \ + MSR_HV_GUESTID_VERSION_MASK) +#define MSR_HV_GUESTID_OSID_FREEBSD \ + ((HYPERV_FREEBSD_OSID << MSR_HV_GUESTID_OSID_SHIFT) & \ + MSR_HV_GUESTID_OSID_MASK) + +#define MSR_HV_GUESTID_FREEBSD \ + (MSR_HV_GUESTID_BUILD_FREEBSD | \ + MSR_HV_GUESTID_VERSION_FREEBSD | \ + MSR_HV_GUESTID_OSID_FREEBSD | \ + MSR_HV_GUESTID_OSTYPE_FREEBSD) + +struct hypercall_ctx { + void *hc_addr; + struct hyperv_dma hc_dma; +}; + +static u_int hyperv_get_timecount(struct timecounter *tc); + +u_int hyperv_features; +u_int hyperv_recommends; + +static u_int hyperv_pm_features; +static u_int hyperv_features3; + +static struct timecounter hyperv_timecounter = { + .tc_get_timecount = hyperv_get_timecount, + .tc_poll_pps = NULL, + .tc_counter_mask = 0xffffffff, + .tc_frequency = HYPERV_TIMER_FREQ, + .tc_name = "Hyper-V", + .tc_quality = 2000, + .tc_flags = 0, + .tc_priv = NULL +}; + +static struct hypercall_ctx hypercall_context; + +static u_int +hyperv_get_timecount(struct timecounter *tc __unused) +{ + return rdmsr(MSR_HV_TIME_REF_COUNT); +} + +/** + * @brief Invoke the specified hypercall + */ +static uint64_t +hv_vmbus_do_hypercall(uint64_t control, void* input, void* output) +{ +#ifdef __x86_64__ + uint64_t hv_status = 0; + uint64_t input_address = (input) ? hv_get_phys_addr(input) : 0; + uint64_t output_address = (output) ? hv_get_phys_addr(output) : 0; + volatile void *hypercall_page = hypercall_context.hc_addr; + + __asm__ __volatile__ ("mov %0, %%r8" : : "r" (output_address): "r8"); + __asm__ __volatile__ ("call *%3" : "=a"(hv_status): + "c" (control), "d" (input_address), + "m" (hypercall_page)); + return (hv_status); +#else + uint32_t control_high = control >> 32; + uint32_t control_low = control & 0xFFFFFFFF; + uint32_t hv_status_high = 1; + uint32_t hv_status_low = 1; + uint64_t input_address = (input) ? hv_get_phys_addr(input) : 0; + uint32_t input_address_high = input_address >> 32; + uint32_t input_address_low = input_address & 0xFFFFFFFF; + uint64_t output_address = (output) ? hv_get_phys_addr(output) : 0; + uint32_t output_address_high = output_address >> 32; + uint32_t output_address_low = output_address & 0xFFFFFFFF; + volatile void *hypercall_page = hypercall_context.hc_addr; + + __asm__ __volatile__ ("call *%8" : "=d"(hv_status_high), + "=a"(hv_status_low) : "d" (control_high), + "a" (control_low), "b" (input_address_high), + "c" (input_address_low), + "D"(output_address_high), + "S"(output_address_low), "m" (hypercall_page)); + return (hv_status_low | ((uint64_t)hv_status_high << 32)); +#endif /* __x86_64__ */ +} + +/** + * @brief Post a message using the hypervisor message IPC. + * (This involves a hypercall.) + */ +hv_vmbus_status +hv_vmbus_post_msg_via_msg_ipc( + hv_vmbus_connection_id connection_id, + hv_vmbus_msg_type message_type, + void* payload, + size_t payload_size) +{ + struct alignedinput { + uint64_t alignment8; + hv_vmbus_input_post_message msg; + }; + + hv_vmbus_input_post_message* aligned_msg; + hv_vmbus_status status; + size_t addr; + + if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) + return (EMSGSIZE); + + addr = (size_t) malloc(sizeof(struct alignedinput), M_DEVBUF, + M_ZERO | M_NOWAIT); + KASSERT(addr != 0, + ("Error VMBUS: malloc failed to allocate message buffer!")); + if (addr == 0) + return (ENOMEM); + + aligned_msg = (hv_vmbus_input_post_message*) + (HV_ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); + + aligned_msg->connection_id = connection_id; + aligned_msg->message_type = message_type; + aligned_msg->payload_size = payload_size; + memcpy((void*) aligned_msg->payload, payload, payload_size); + + status = hv_vmbus_do_hypercall( + HV_CALL_POST_MESSAGE, aligned_msg, 0) & 0xFFFF; + + free((void *) addr, M_DEVBUF); + return (status); +} + +/** + * @brief Signal an event on the specified connection using the hypervisor + * event IPC. (This involves a hypercall.) + */ +hv_vmbus_status +hv_vmbus_signal_event(void *con_id) +{ + hv_vmbus_status status; + + status = hv_vmbus_do_hypercall( + HV_CALL_SIGNAL_EVENT, + con_id, + 0) & 0xFFFF; + + return (status); +} + +int +hyperv_guid2str(const struct hv_guid *guid, char *buf, size_t sz) +{ + const uint8_t *d = guid->data; + + return snprintf(buf, sz, "%02x%02x%02x%02x-" + "%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x", + d[3], d[2], d[1], d[0], + d[5], d[4], d[7], d[6], d[8], d[9], + d[10], d[11], d[12], d[13], d[14], d[15]); +} + +static bool +hyperv_identify(void) +{ + u_int regs[4]; + unsigned int maxleaf; + + if (vm_guest != VM_GUEST_HV) + return (false); + + do_cpuid(CPUID_LEAF_HV_MAXLEAF, regs); + maxleaf = regs[0]; + if (maxleaf < CPUID_LEAF_HV_LIMITS) + return (false); + + do_cpuid(CPUID_LEAF_HV_INTERFACE, regs); + if (regs[0] != CPUID_HV_IFACE_HYPERV) + return (false); + + do_cpuid(CPUID_LEAF_HV_FEATURES, regs); + if ((regs[0] & CPUID_HV_MSR_HYPERCALL) == 0) { + /* + * Hyper-V w/o Hypercall is impossible; someone + * is faking Hyper-V. + */ + return (false); + } + hyperv_features = regs[0]; + hyperv_pm_features = regs[2]; + hyperv_features3 = regs[3]; + + do_cpuid(CPUID_LEAF_HV_IDENTITY, regs); + printf("Hyper-V Version: %d.%d.%d [SP%d]\n", + regs[1] >> 16, regs[1] & 0xffff, regs[0], regs[2]); + + printf(" Features=0x%b\n", hyperv_features, + "\020" + "\001VPRUNTIME" /* MSR_HV_VP_RUNTIME */ + "\002TMREFCNT" /* MSR_HV_TIME_REF_COUNT */ + "\003SYNIC" /* MSRs for SynIC */ + "\004SYNTM" /* MSRs for SynTimer */ + "\005APIC" /* MSR_HV_{EOI,ICR,TPR} */ + "\006HYPERCALL" /* MSR_HV_{GUEST_OS_ID,HYPERCALL} */ + "\007VPINDEX" /* MSR_HV_VP_INDEX */ + "\010RESET" /* MSR_HV_RESET */ + "\011STATS" /* MSR_HV_STATS_ */ + "\012REFTSC" /* MSR_HV_REFERENCE_TSC */ + "\013IDLE" /* MSR_HV_GUEST_IDLE */ + "\014TMFREQ" /* MSR_HV_{TSC,APIC}_FREQUENCY */ + "\015DEBUG"); /* MSR_HV_SYNTH_DEBUG_ */ + printf(" PM Features=0x%b [C%u]\n", + (hyperv_pm_features & ~CPUPM_HV_CSTATE_MASK), + "\020" + "\005C3HPET", /* HPET is required for C3 state */ + CPUPM_HV_CSTATE(hyperv_pm_features)); + printf(" Features3=0x%b\n", hyperv_features3, + "\020" + "\001MWAIT" /* MWAIT */ + "\002DEBUG" /* guest debug support */ + "\003PERFMON" /* performance monitor */ + "\004PCPUDPE" /* physical CPU dynamic partition event */ + "\005XMMHC" /* hypercall input through XMM regs */ + "\006IDLE" /* guest idle support */ + "\007SLEEP" /* hypervisor sleep support */ + "\010NUMA" /* NUMA distance query support */ + "\011TMFREQ" /* timer frequency query (TSC, LAPIC) */ + "\012SYNCMC" /* inject synthetic machine checks */ + "\013CRASH" /* MSRs for guest crash */ + "\014DEBUGMSR" /* MSRs for guest debug */ + "\015NPIEP" /* NPIEP */ + "\016HVDIS"); /* disabling hypervisor */ + + do_cpuid(CPUID_LEAF_HV_RECOMMENDS, regs); + hyperv_recommends = regs[0]; + if (bootverbose) + printf(" Recommends: %08x %08x\n", regs[0], regs[1]); + + do_cpuid(CPUID_LEAF_HV_LIMITS, regs); + if (bootverbose) { + printf(" Limits: Vcpu:%d Lcpu:%d Int:%d\n", + regs[0], regs[1], regs[2]); + } + + if (maxleaf >= CPUID_LEAF_HV_HWFEATURES) { + do_cpuid(CPUID_LEAF_HV_HWFEATURES, regs); + if (bootverbose) { + printf(" HW Features: %08x, AMD: %08x\n", + regs[0], regs[3]); + } + } + + return (true); +} + +static void +hyperv_init(void *dummy __unused) +{ + if (!hyperv_identify()) { + /* Not Hyper-V; reset guest id to the generic one. */ + if (vm_guest == VM_GUEST_HV) + vm_guest = VM_GUEST_VM; + return; + } + + /* Set guest id */ + wrmsr(MSR_HV_GUEST_OS_ID, MSR_HV_GUESTID_FREEBSD); + + if (hyperv_features & CPUID_HV_MSR_TIME_REFCNT) { + /* Register Hyper-V timecounter */ + tc_init(&hyperv_timecounter); + } +} +SYSINIT(hyperv_initialize, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, hyperv_init, + NULL); + +static void +hypercall_memfree(void) +{ + hyperv_dmamem_free(&hypercall_context.hc_dma, + hypercall_context.hc_addr); + hypercall_context.hc_addr = NULL; +} + +static void +hypercall_create(void *arg __unused) +{ + uint64_t hc, hc_orig; + + 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; + } + + /* Get the 'reserved' bits, which requires preservation. */ + hc_orig = rdmsr(MSR_HV_HYPERCALL); + + /* + * Setup the Hypercall page. + * + * NOTE: 'reserved' bits MUST be preserved. + */ + hc = ((hypercall_context.hc_dma.hv_paddr >> PAGE_SHIFT) << + MSR_HV_HYPERCALL_PGSHIFT) | + (hc_orig & MSR_HV_HYPERCALL_RSVD_MASK) | + MSR_HV_HYPERCALL_ENABLE; + wrmsr(MSR_HV_HYPERCALL, hc); + + /* + * Confirm that Hypercall page did get setup. + */ + hc = rdmsr(MSR_HV_HYPERCALL); + if ((hc & MSR_HV_HYPERCALL_ENABLE) == 0) { + printf("hyperv: Hypercall setup failed\n"); + hypercall_memfree(); + /* Can't perform any Hyper-V specific actions */ + vm_guest = VM_GUEST_VM; + return; + } + if (bootverbose) + printf("hyperv: Hypercall created\n"); +} +SYSINIT(hypercall_ctor, SI_SUB_DRIVERS, SI_ORDER_FIRST, hypercall_create, NULL); + +static void +hypercall_destroy(void *arg __unused) +{ + uint64_t hc; + + if (hypercall_context.hc_addr == NULL) + return; + + /* Disable Hypercall */ + hc = rdmsr(MSR_HV_HYPERCALL); + wrmsr(MSR_HV_HYPERCALL, (hc & MSR_HV_HYPERCALL_RSVD_MASK)); + hypercall_memfree(); + + if (bootverbose) + printf("hyperv: Hypercall destroyed\n"); +} +SYSUNINIT(hypercall_dtor, SI_SUB_DRIVERS, SI_ORDER_FIRST, hypercall_destroy, + NULL); Copied: stable/10/sys/dev/hyperv/vmbus/i386/vmbus_vector.S (from r302166, stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/i386/vmbus_vector.S Fri Jun 24 02:06:13 2016 (r302167, copy of r302166, stable/10/sys/dev/hyperv/vmbus/i386/hv_vector.S) @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include + +#include "assym.s" + +/* + * This is the Hyper-V vmbus channel direct callback interrupt. + * Only used when it is running on Hyper-V. + */ + .text + SUPERALIGN_TEXT +IDTVEC(vmbus_isr) + PUSH_FRAME + SET_KERNEL_SREGS + cld + FAKE_MCOUNT(TF_EIP(%esp)) + pushl %esp + call vmbus_handle_intr + add $4, %esp + MEXITCOUNT + jmp doreti Copied: stable/10/sys/dev/hyperv/vmbus/vmbus.c (from r302166, stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/vmbus.c Fri Jun 24 02:06:13 2016 (r302167, copy of r302166, stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c) @@ -0,0 +1,833 @@ +/*- + * Copyright (c) 2009-2012,2016 Microsoft Corp. + * Copyright (c) 2012 NetApp Inc. + * Copyright (c) 2012 Citrix Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * VM Bus Driver Implementation + */ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include "acpi_if.h" + +struct vmbus_softc *vmbus_sc; + +extern inthand_t IDTVEC(rsvd), IDTVEC(vmbus_isr); + +static void +vmbus_msg_task(void *xsc, int pending __unused) +{ + struct vmbus_softc *sc = xsc; + volatile struct vmbus_message *msg; + + msg = VMBUS_PCPU_GET(sc, message, curcpu) + VMBUS_SINT_MESSAGE; + for (;;) { + const hv_vmbus_channel_msg_table_entry *entry; + hv_vmbus_channel_msg_header *hdr; + hv_vmbus_channel_msg_type msg_type; + + if (msg->msg_type == VMBUS_MSGTYPE_NONE) + break; /* no message */ + + /* XXX: update messageHandler interface */ + hdr = __DEVOLATILE(hv_vmbus_channel_msg_header *, + msg->msg_data); + msg_type = hdr->message_type; + + if (msg_type >= HV_CHANNEL_MESSAGE_COUNT) { + printf("VMBUS: unknown message type = %d\n", msg_type); + goto handled; + } + + entry = &g_channel_message_table[msg_type]; + if (entry->messageHandler) + entry->messageHandler(hdr); +handled: + msg->msg_type = VMBUS_MSGTYPE_NONE; + /* + * Make sure the write to msg_type (i.e. set to + * VMBUS_MSGTYPE_NONE) happens before we read the + * msg_flags and EOMing. Otherwise, the EOMing will + * not deliver any more messages since there is no + * empty slot + * + * NOTE: + * mb() is used here, since atomic_thread_fence_seq_cst() + * will become compiler fence on UP kernel. + */ + mb(); + if (msg->msg_flags & VMBUS_MSGFLAG_PENDING) { + /* + * This will cause message queue rescan to possibly + * deliver another msg from the hypervisor + */ + wrmsr(MSR_HV_EOM, 0); + } + } +} + +static __inline int +vmbus_handle_intr1(struct vmbus_softc *sc, struct trapframe *frame, int cpu) +{ + volatile struct vmbus_message *msg; + struct vmbus_message *msg_base; + + msg_base = VMBUS_PCPU_GET(sc, message, cpu); + + /* + * Check event timer. + * + * TODO: move this to independent IDT vector. + */ + msg = msg_base + VMBUS_SINT_TIMER; + if (msg->msg_type == VMBUS_MSGTYPE_TIMER_EXPIRED) { + msg->msg_type = VMBUS_MSGTYPE_NONE; + + vmbus_et_intr(frame); + + /* + * Make sure the write to msg_type (i.e. set to + * VMBUS_MSGTYPE_NONE) happens before we read the + * msg_flags and EOMing. Otherwise, the EOMing will + * not deliver any more messages since there is no + * empty slot + * + * NOTE: + * mb() is used here, since atomic_thread_fence_seq_cst() + * will become compiler fence on UP kernel. + */ + mb(); + if (msg->msg_flags & VMBUS_MSGFLAG_PENDING) { + /* + * This will cause message queue rescan to possibly + * deliver another msg from the hypervisor + */ + wrmsr(MSR_HV_EOM, 0); + } + } + + /* + * Check events. Hot path for network and storage I/O data; high rate. + * + * NOTE: + * As recommended by the Windows guest fellows, we check events before + * checking messages. + */ + sc->vmbus_event_proc(sc, cpu); + + /* + * Check messages. Mainly management stuffs; ultra low rate. + */ + msg = msg_base + VMBUS_SINT_MESSAGE; + if (__predict_false(msg->msg_type != VMBUS_MSGTYPE_NONE)) { + taskqueue_enqueue(VMBUS_PCPU_GET(sc, message_tq, cpu), + VMBUS_PCPU_PTR(sc, message_task, cpu)); + } + + return (FILTER_HANDLED); +} + +void +vmbus_handle_intr(struct trapframe *trap_frame) +{ + struct vmbus_softc *sc = vmbus_get_softc(); + int cpu = curcpu; + + /* + * Disable preemption. + */ + critical_enter(); + + /* + * Do a little interrupt counting. + */ + (*VMBUS_PCPU_GET(sc, intr_cnt, cpu))++; + + vmbus_handle_intr1(sc, trap_frame, cpu); + + /* + * Enable preemption. + */ + critical_exit(); +} + +static void +vmbus_synic_setup(void *xsc) +{ + struct vmbus_softc *sc = xsc; + int cpu = curcpu; + uint64_t val, orig; + uint32_t sint; + + if (hyperv_features & CPUID_HV_MSR_VP_INDEX) { + /* + * Save virtual processor id. + */ + VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX); + } else { + /* + * XXX + * Virtual processoor id is only used by a pretty broken + * channel selection code from storvsc. It's nothing + * critical even if CPUID_HV_MSR_VP_INDEX is not set; keep + * moving on. + */ + VMBUS_PCPU_GET(sc, vcpuid, cpu) = cpu; + } + + /* + * Setup the SynIC message. + */ + orig = rdmsr(MSR_HV_SIMP); + val = MSR_HV_SIMP_ENABLE | (orig & MSR_HV_SIMP_RSVD_MASK) | + ((VMBUS_PCPU_GET(sc, message_dma.hv_paddr, cpu) >> PAGE_SHIFT) << + MSR_HV_SIMP_PGSHIFT); + wrmsr(MSR_HV_SIMP, val); + + /* + * Setup the SynIC event flags. + */ + orig = rdmsr(MSR_HV_SIEFP); + val = MSR_HV_SIEFP_ENABLE | (orig & MSR_HV_SIEFP_RSVD_MASK) | + ((VMBUS_PCPU_GET(sc, event_flags_dma.hv_paddr, cpu) + >> PAGE_SHIFT) << MSR_HV_SIEFP_PGSHIFT); + wrmsr(MSR_HV_SIEFP, val); + + + /* + * Configure and unmask SINT for message and event flags. + */ + sint = MSR_HV_SINT0 + VMBUS_SINT_MESSAGE; + orig = rdmsr(sint); + val = sc->vmbus_idtvec | MSR_HV_SINT_AUTOEOI | + (orig & MSR_HV_SINT_RSVD_MASK); + wrmsr(sint, val); + + /* + * Configure and unmask SINT for timer. + */ + sint = MSR_HV_SINT0 + VMBUS_SINT_TIMER; + orig = rdmsr(sint); + val = sc->vmbus_idtvec | MSR_HV_SINT_AUTOEOI | + (orig & MSR_HV_SINT_RSVD_MASK); + wrmsr(sint, val); + + /* + * All done; enable SynIC. + */ + orig = rdmsr(MSR_HV_SCONTROL); + val = MSR_HV_SCTRL_ENABLE | (orig & MSR_HV_SCTRL_RSVD_MASK); + wrmsr(MSR_HV_SCONTROL, val); +} + +static void +vmbus_synic_teardown(void *arg) +{ + uint64_t orig; + uint32_t sint; + + /* + * Disable SynIC. + */ + orig = rdmsr(MSR_HV_SCONTROL); + wrmsr(MSR_HV_SCONTROL, (orig & MSR_HV_SCTRL_RSVD_MASK)); + + /* + * Mask message and event flags SINT. + */ + sint = MSR_HV_SINT0 + VMBUS_SINT_MESSAGE; + orig = rdmsr(sint); + wrmsr(sint, orig | MSR_HV_SINT_MASKED); + + /* + * Mask timer SINT. + */ + sint = MSR_HV_SINT0 + VMBUS_SINT_TIMER; + orig = rdmsr(sint); + wrmsr(sint, orig | MSR_HV_SINT_MASKED); + + /* + * Teardown SynIC message. + */ + orig = rdmsr(MSR_HV_SIMP); + wrmsr(MSR_HV_SIMP, (orig & MSR_HV_SIMP_RSVD_MASK)); + + /* + * Teardown SynIC event flags. + */ + orig = rdmsr(MSR_HV_SIEFP); + wrmsr(MSR_HV_SIEFP, (orig & MSR_HV_SIEFP_RSVD_MASK)); +} + +static int +vmbus_dma_alloc(struct vmbus_softc *sc) +{ + int cpu; + + CPU_FOREACH(cpu) { + void *ptr; + + /* + * Per-cpu messages and event flags. + */ + ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), + PAGE_SIZE, 0, PAGE_SIZE, + VMBUS_PCPU_PTR(sc, message_dma, cpu), + BUS_DMA_WAITOK | BUS_DMA_ZERO); + if (ptr == NULL) + return ENOMEM; + VMBUS_PCPU_GET(sc, message, cpu) = ptr; + + ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), + PAGE_SIZE, 0, PAGE_SIZE, + VMBUS_PCPU_PTR(sc, event_flags_dma, cpu), + BUS_DMA_WAITOK | BUS_DMA_ZERO); + if (ptr == NULL) + return ENOMEM; + VMBUS_PCPU_GET(sc, event_flags, cpu) = ptr; + } + return 0; +} + +static void +vmbus_dma_free(struct vmbus_softc *sc) +{ + int cpu; + + CPU_FOREACH(cpu) { + if (VMBUS_PCPU_GET(sc, message, cpu) != NULL) { + hyperv_dmamem_free( + VMBUS_PCPU_PTR(sc, message_dma, cpu), + VMBUS_PCPU_GET(sc, message, cpu)); + VMBUS_PCPU_GET(sc, message, cpu) = NULL; + } + if (VMBUS_PCPU_GET(sc, event_flags, cpu) != NULL) { + hyperv_dmamem_free( + VMBUS_PCPU_PTR(sc, event_flags_dma, cpu), + VMBUS_PCPU_GET(sc, event_flags, cpu)); + VMBUS_PCPU_GET(sc, event_flags, cpu) = NULL; + } + } +} + +/** + * @brief Find a free IDT slot and setup the interrupt handler. + */ +static int +vmbus_vector_alloc(void) +{ + int vector; + uintptr_t func; + struct gate_descriptor *ip; + + /* + * Search backwards form the highest IDT vector available for use + * as vmbus channel callback vector. We install 'hv_vmbus_callback' + * handler at that vector and use it to interrupt vcpus. + */ + vector = APIC_SPURIOUS_INT; + while (--vector >= APIC_IPI_INTS) { + ip = &idt[vector]; + func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); + if (func == (uintptr_t)&IDTVEC(rsvd)) { +#ifdef __i386__ + setidt(vector , IDTVEC(vmbus_isr), SDT_SYS386IGT, + SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); +#else + setidt(vector , IDTVEC(vmbus_isr), SDT_SYSIGT, + SEL_KPL, 0); +#endif + + return (vector); + } + } + return (0); +} + +/** + * @brief Restore the IDT slot to rsvd. + */ +static void +vmbus_vector_free(int vector) +{ + uintptr_t func; + struct gate_descriptor *ip; + + if (vector == 0) + return; + + KASSERT(vector >= APIC_IPI_INTS && vector < APIC_SPURIOUS_INT, + ("invalid vector %d", vector)); + + ip = &idt[vector]; + func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset); + KASSERT(func == (uintptr_t)&IDTVEC(hv_vmbus_callback), + ("invalid vector %d", vector)); + + setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0); +} + +static void +vmbus_cpuset_setthread_task(void *xmask, int pending __unused) +{ + cpuset_t *mask = xmask; + int error; + + error = cpuset_setthread(curthread->td_tid, mask); + if (error) { + panic("curthread=%ju: can't pin; error=%d", + (uintmax_t)curthread->td_tid, error); + } +} + +static int +vmbus_intr_setup(struct vmbus_softc *sc) +{ + int cpu; + + CPU_FOREACH(cpu) { + struct task cpuset_task; + char buf[MAXCOMLEN + 1]; + cpuset_t cpu_mask; + *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-10@freebsd.org Fri Jun 24 02:24:35 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8F5BAB73FCB; Fri, 24 Jun 2016 02:24:35 +0000 (UTC) (envelope-from pfg@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 67A1027FB; Fri, 24 Jun 2016 02:24:35 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5O2OYhq064512; Fri, 24 Jun 2016 02:24:34 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5O2OYXc064510; Fri, 24 Jun 2016 02:24:34 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201606240224.u5O2OYXc064510@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Fri, 24 Jun 2016 02:24:34 +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: r302168 - stable/10/lib/libc/regex 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2016 02:24:35 -0000 Author: pfg Date: Fri Jun 24 02:24:34 2016 New Revision: 302168 URL: https://svnweb.freebsd.org/changeset/base/302168 Log: MFC r300683: libc: regexec(3) adjustment. Change the behavior of when REG_STARTEND is combined with REG_NOTBOL. From the original posting[1]: "Enable the assumption that pmatch[0].rm_so is a continuation offset to a string and allows us to do a proper assessment of the character in regards to it's word position ('^' or '\<'), without risking going into unallocated memory." This change makes us similar to how glibc handles REG_STARTEND | REG_NOTBOL, and is closely related to a soon-to-land fix to sed. Special thanks to Martijn van Duren and Ingo Schwarze for working out some consistent behaviour. Differential Revision: https://reviews.freebsd.org/D6257 Taken from: openbsd-tech 2016-05-24 [1] (Martijn van Duren) Modified: stable/10/lib/libc/regex/engine.c stable/10/lib/libc/regex/regex.3 Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/regex/engine.c ============================================================================== --- stable/10/lib/libc/regex/engine.c Fri Jun 24 02:06:13 2016 (r302167) +++ stable/10/lib/libc/regex/engine.c Fri Jun 24 02:24:34 2016 (r302168) @@ -786,7 +786,7 @@ fast( struct match *m, ASSIGN(fresh, st); SP("start", st, *p); coldp = NULL; - if (start == m->beginp) + if (start == m->offp || (start == m->beginp && !(m->eflags®_NOTBOL))) c = OUT; else { /* @@ -891,7 +891,7 @@ slow( struct match *m, SP("sstart", st, *p); st = step(m->g, startst, stopst, st, NOTHING, st); matchp = NULL; - if (start == m->beginp) + if (start == m->offp || (start == m->beginp && !(m->eflags®_NOTBOL))) c = OUT; else { /* Modified: stable/10/lib/libc/regex/regex.3 ============================================================================== --- stable/10/lib/libc/regex/regex.3 Fri Jun 24 02:06:13 2016 (r302167) +++ stable/10/lib/libc/regex/regex.3 Fri Jun 24 02:24:34 2016 (r302168) @@ -32,7 +32,7 @@ .\" @(#)regex.3 8.4 (Berkeley) 3/20/94 .\" $FreeBSD$ .\" -.Dd August 17, 2005 +.Dd May 25, 2016 .Dt REGEX 3 .Os .Sh NAME @@ -235,11 +235,16 @@ The argument is the bitwise OR of zero or more of the following flags: .Bl -tag -width REG_STARTEND .It Dv REG_NOTBOL -The first character of -the string -is not the beginning of a line, so the -.Ql ^\& -anchor should not match before it. +The first character of the string is treated as the continuation +of a line. +This means that the anchors +.Ql ^\& , +.Ql [[:<:]] , +and +.Ql \e< +do not match before it; but see +.Dv REG_STARTEND +below. This does not affect the behavior of newlines under .Dv REG_NEWLINE . .It Dv REG_NOTEOL @@ -247,19 +252,16 @@ The NUL terminating the string does not end a line, so the .Ql $\& -anchor should not match before it. +anchor does not match before it. This does not affect the behavior of newlines under .Dv REG_NEWLINE . .It Dv REG_STARTEND The string is considered to start at -.Fa string -+ -.Fa pmatch Ns [0]. Ns Va rm_so -and to have a terminating NUL located at -.Fa string -+ -.Fa pmatch Ns [0]. Ns Va rm_eo -(there need not actually be a NUL at that location), +.Fa string No + +.Fa pmatch Ns [0]. Ns Fa rm_so +and to end before the byte located at +.Fa string No + +.Fa pmatch Ns [0]. Ns Fa rm_eo , regardless of the value of .Fa nmatch . See below for the definition of @@ -271,13 +273,37 @@ compatible with but not specified by .St -p1003.2 , and should be used with caution in software intended to be portable to other systems. -Note that a non-zero -.Va rm_so -does not imply -.Dv REG_NOTBOL ; -.Dv REG_STARTEND -affects only the location of the string, -not how it is matched. +.Pp +Without +.Dv REG_NOTBOL , +the position +.Fa rm_so +is considered the beginning of a line, such that +.Ql ^ +matches before it, and the beginning of a word if there is a word +character at this position, such that +.Ql [[:<:]] +and +.Ql \e< +match before it. +.Pp +With +.Dv REG_NOTBOL , +the character at position +.Fa rm_so +is treated as the continuation of a line, and if +.Fa rm_so +is greater than 0, the preceding character is taken into consideration. +If the preceding character is a newline and the regular expression was compiled +with +.Dv REG_NEWLINE , +.Ql ^ +matches before the string; if the preceding character is not a word character +but the string starts with a word character, +.Ql [[:<:]] +and +.Ql \e< +match before the string. .El .Pp See From owner-svn-src-stable-10@freebsd.org Fri Jun 24 02:30:17 2016 Return-Path: Delivered-To: svn-src-stable-10@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 18834B7311A; Fri, 24 Jun 2016 02:30:17 +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 A35AA2B36; Fri, 24 Jun 2016 02:30:16 +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 u5O2UFKh064836; Fri, 24 Jun 2016 02:30:15 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5O2UE3Z064822; Fri, 24 Jun 2016 02:30:14 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201606240230.u5O2UE3Z064822@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 24 Jun 2016 02:30:14 +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: r302170 - in stable/10/sys: conf dev/hyperv/vmbus dev/hyperv/vmbus/amd64 dev/hyperv/vmbus/i386 modules/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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2016 02:30:17 -0000 Author: sephe Date: Fri Jun 24 02:30:14 2016 New Revision: 302170 URL: https://svnweb.freebsd.org/changeset/base/302170 Log: MFC 301483,301484,301487,301488,301583,301588 301483 hyperv: Move machine dependent bits into machine dependent files. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6701 301484 hyperv/vmbus: Define type for channel messages. And fix message processing; only channel messages are supported. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6706 301487 hyperv/vmbus: Factor out channel message processing This paves the way for further cleanup. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6707 301488 hyperv/vmbus: Constify channel message MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6708 301583 hyperv/vmbus: Busdma-fy MNF and event flags. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6744 301588 hyperv/vmbus: Change tx_evtflags type to u_long to match vmbus_evtflags MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6745 Added: stable/10/sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c - copied unchanged from r301483, head/sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c stable/10/sys/dev/hyperv/vmbus/hyperv_machdep.h - copied unchanged from r301483, head/sys/dev/hyperv/vmbus/hyperv_machdep.h stable/10/sys/dev/hyperv/vmbus/i386/hyperv_machdep.c - copied unchanged from r301483, head/sys/dev/hyperv/vmbus/i386/hyperv_machdep.c Modified: stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/dev/hyperv/vmbus/hv_channel.c stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c stable/10/sys/dev/hyperv/vmbus/hv_connection.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h stable/10/sys/dev/hyperv/vmbus/hyperv.c stable/10/sys/dev/hyperv/vmbus/vmbus.c stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h stable/10/sys/dev/hyperv/vmbus/vmbus_var.h stable/10/sys/modules/hyperv/vmbus/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/conf/files.amd64 Fri Jun 24 02:30:14 2016 (r302170) @@ -279,6 +279,7 @@ dev/hyperv/vmbus/hyperv.c optional hy dev/hyperv/vmbus/hyperv_busdma.c optional hyperv dev/hyperv/vmbus/vmbus.c optional hyperv dev/hyperv/vmbus/vmbus_et.c optional hyperv +dev/hyperv/vmbus/amd64/hyperv_machdep.c optional hyperv dev/hyperv/vmbus/amd64/vmbus_vector.S optional hyperv dev/kbd/kbd.c optional atkbd | sc | ukbd | vt dev/lindev/full.c optional lindev Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/conf/files.i386 Fri Jun 24 02:30:14 2016 (r302170) @@ -255,6 +255,7 @@ dev/hyperv/vmbus/hyperv.c optional hy dev/hyperv/vmbus/hyperv_busdma.c optional hyperv dev/hyperv/vmbus/vmbus.c optional hyperv dev/hyperv/vmbus/vmbus_et.c optional hyperv +dev/hyperv/vmbus/i386/hyperv_machdep.c optional hyperv dev/hyperv/vmbus/i386/vmbus_vector.S optional hyperv dev/ichwd/ichwd.c optional ichwd dev/if_ndis/if_ndis.c optional ndis Copied: stable/10/sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c (from r301483, head/sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c Fri Jun 24 02:30:14 2016 (r302170, copy of r301483, head/sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c) @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +uint64_t +hypercall_md(volatile void *hc_addr, uint64_t in_val, + uint64_t in_paddr, uint64_t out_paddr) +{ + uint64_t status; + + __asm__ __volatile__ ("mov %0, %%r8" : : "r" (out_paddr): "r8"); + __asm__ __volatile__ ("call *%3" : "=a" (status) : + "c" (in_val), "d" (in_paddr), "m" (hc_addr)); + return (status); +} Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel.c Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel.c Fri Jun 24 02:30:14 2016 (r302170) @@ -37,12 +37,16 @@ __FBSDID("$FreeBSD$"); #include #include #include + +#include #include + #include #include #include #include +#include #include static int vmbus_channel_create_gpadl_header( @@ -62,17 +66,16 @@ static void VmbusProcessChannelEvent(voi static void vmbus_channel_set_event(hv_vmbus_channel *channel) { - hv_vmbus_monitor_page *monitor_page; - if (channel->offer_msg.monitor_allocated) { - /* Each uint32_t represents 32 channels */ - synch_set_bit((channel->offer_msg.child_rel_id & 31), - ((uint32_t *)hv_vmbus_g_connection.send_interrupt_page - + ((channel->offer_msg.child_rel_id >> 5)))); - - monitor_page = (hv_vmbus_monitor_page *) - hv_vmbus_g_connection.monitor_page_2; + struct vmbus_softc *sc = vmbus_get_softc(); + hv_vmbus_monitor_page *monitor_page; + uint32_t chanid = channel->offer_msg.child_rel_id; + + atomic_set_long( + &sc->vmbus_tx_evtflags[chanid >> VMBUS_EVTFLAG_SHIFT], + 1UL << (chanid & VMBUS_EVTFLAG_MASK)); + monitor_page = sc->vmbus_mnf2; synch_set_bit(channel->monitor_bit, (uint32_t *)&monitor_page-> trigger_group[channel->monitor_group].u.pending); Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Fri Jun 24 02:30:14 2016 (r302170) @@ -43,20 +43,34 @@ __FBSDID("$FreeBSD$"); * Internal functions */ -static void vmbus_channel_on_offer(hv_vmbus_channel_msg_header* hdr); -static void vmbus_channel_on_offer_internal(void* context); -static void vmbus_channel_on_open_result(hv_vmbus_channel_msg_header* hdr); -static void vmbus_channel_on_offer_rescind(hv_vmbus_channel_msg_header* hdr); -static void vmbus_channel_on_offer_rescind_internal(void* context); -static void vmbus_channel_on_gpadl_created(hv_vmbus_channel_msg_header* hdr); -static void vmbus_channel_on_gpadl_torndown(hv_vmbus_channel_msg_header* hdr); -static void vmbus_channel_on_offers_delivered(hv_vmbus_channel_msg_header* hdr); -static void vmbus_channel_on_version_response(hv_vmbus_channel_msg_header* hdr); +typedef void (*vmbus_msg_handler)(const hv_vmbus_channel_msg_header *msg); + +typedef struct hv_vmbus_channel_msg_table_entry { + hv_vmbus_channel_msg_type messageType; + vmbus_msg_handler messageHandler; +} hv_vmbus_channel_msg_table_entry; + +static void vmbus_channel_on_offer_internal(void *context); +static void vmbus_channel_on_offer_rescind_internal(void *context); + +static void vmbus_channel_on_offer(const hv_vmbus_channel_msg_header *hdr); +static void vmbus_channel_on_open_result( + const hv_vmbus_channel_msg_header *hdr); +static void vmbus_channel_on_offer_rescind( + const hv_vmbus_channel_msg_header *hdr); +static void vmbus_channel_on_gpadl_created( + const hv_vmbus_channel_msg_header *hdr); +static void vmbus_channel_on_gpadl_torndown( + const hv_vmbus_channel_msg_header *hdr); +static void vmbus_channel_on_offers_delivered( + const hv_vmbus_channel_msg_header *hdr); +static void vmbus_channel_on_version_response( + const hv_vmbus_channel_msg_header *hdr); /** * Channel message dispatch table */ -hv_vmbus_channel_msg_table_entry +static const hv_vmbus_channel_msg_table_entry g_channel_message_table[HV_CHANNEL_MESSAGE_COUNT] = { { HV_CHANNEL_MESSAGE_INVALID, NULL }, @@ -387,12 +401,12 @@ vmbus_channel_select_defcpu(struct hv_vm * object to process the offer synchronously */ static void -vmbus_channel_on_offer(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_offer(const hv_vmbus_channel_msg_header *hdr) { - hv_vmbus_channel_offer_channel* offer; - hv_vmbus_channel_offer_channel* copied; + const hv_vmbus_channel_offer_channel *offer; + hv_vmbus_channel_offer_channel *copied; - offer = (hv_vmbus_channel_offer_channel*) hdr; + offer = (const hv_vmbus_channel_offer_channel *)hdr; // copy offer data copied = malloc(sizeof(*copied), M_DEVBUF, M_NOWAIT); @@ -465,12 +479,12 @@ vmbus_channel_on_offer_internal(void* co * synchronously */ static void -vmbus_channel_on_offer_rescind(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_offer_rescind(const hv_vmbus_channel_msg_header *hdr) { - hv_vmbus_channel_rescind_offer* rescind; + const hv_vmbus_channel_rescind_offer *rescind; hv_vmbus_channel* channel; - rescind = (hv_vmbus_channel_rescind_offer*) hdr; + rescind = (const hv_vmbus_channel_rescind_offer *)hdr; channel = hv_vmbus_g_connection.channels[rescind->child_rel_id]; if (channel == NULL) @@ -497,7 +511,8 @@ vmbus_channel_on_offer_rescind_internal( * @brief Invoked when all offers have been delivered. */ static void -vmbus_channel_on_offers_delivered(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_offers_delivered( + const hv_vmbus_channel_msg_header *hdr __unused) { mtx_lock(&vmbus_chwait_lock); @@ -514,14 +529,14 @@ vmbus_channel_on_offers_delivered(hv_vmb * response and signal the requesting thread. */ static void -vmbus_channel_on_open_result(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_open_result(const hv_vmbus_channel_msg_header *hdr) { - hv_vmbus_channel_open_result* result; + const hv_vmbus_channel_open_result *result; hv_vmbus_channel_msg_info* msg_info; hv_vmbus_channel_msg_header* requestHeader; hv_vmbus_channel_open_channel* openMsg; - result = (hv_vmbus_channel_open_result*) hdr; + result = (const hv_vmbus_channel_open_result *)hdr; /* * Find the open msg, copy the result and signal/unblock the wait event @@ -556,14 +571,14 @@ vmbus_channel_on_open_result(hv_vmbus_ch * response and signal the requesting thread. */ static void -vmbus_channel_on_gpadl_created(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_gpadl_created(const hv_vmbus_channel_msg_header *hdr) { - hv_vmbus_channel_gpadl_created* gpadl_created; + const hv_vmbus_channel_gpadl_created *gpadl_created; hv_vmbus_channel_msg_info* msg_info; hv_vmbus_channel_msg_header* request_header; hv_vmbus_channel_gpadl_header* gpadl_header; - gpadl_created = (hv_vmbus_channel_gpadl_created*) hdr; + gpadl_created = (const hv_vmbus_channel_gpadl_created *)hdr; /* Find the establish msg, copy the result and signal/unblock * the wait event @@ -598,14 +613,14 @@ vmbus_channel_on_gpadl_created(hv_vmbus_ * response and signal the requesting thread */ static void -vmbus_channel_on_gpadl_torndown(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_gpadl_torndown(const hv_vmbus_channel_msg_header *hdr) { - hv_vmbus_channel_gpadl_torndown* gpadl_torndown; + const hv_vmbus_channel_gpadl_torndown *gpadl_torndown; hv_vmbus_channel_msg_info* msg_info; hv_vmbus_channel_msg_header* requestHeader; hv_vmbus_channel_gpadl_teardown* gpadlTeardown; - gpadl_torndown = (hv_vmbus_channel_gpadl_torndown*)hdr; + gpadl_torndown = (const hv_vmbus_channel_gpadl_torndown *)hdr; /* * Find the open msg, copy the result and signal/unblock the @@ -643,14 +658,14 @@ vmbus_channel_on_gpadl_torndown(hv_vmbus * response and signal the requesting thread. */ static void -vmbus_channel_on_version_response(hv_vmbus_channel_msg_header* hdr) +vmbus_channel_on_version_response(const hv_vmbus_channel_msg_header *hdr) { hv_vmbus_channel_msg_info* msg_info; hv_vmbus_channel_msg_header* requestHeader; hv_vmbus_channel_initiate_contact* initiate; - hv_vmbus_channel_version_response* versionResponse; + const hv_vmbus_channel_version_response *versionResponse; - versionResponse = (hv_vmbus_channel_version_response*)hdr; + versionResponse = (const hv_vmbus_channel_version_response *)hdr; mtx_lock(&hv_vmbus_g_connection.channel_msg_lock); TAILQ_FOREACH(msg_info, &hv_vmbus_g_connection.channel_msg_anchor, @@ -834,3 +849,24 @@ vmbus_rel_subchan(struct hv_vmbus_channe free(subchan, M_TEMP); } + +void +vmbus_chan_msgproc(struct vmbus_softc *sc, const struct vmbus_message *msg) +{ + const hv_vmbus_channel_msg_table_entry *entry; + const hv_vmbus_channel_msg_header *hdr; + hv_vmbus_channel_msg_type msg_type; + + hdr = (const hv_vmbus_channel_msg_header *)msg->msg_data; + msg_type = hdr->message_type; + + if (msg_type >= HV_CHANNEL_MESSAGE_COUNT) { + device_printf(sc->vmbus_dev, "unknown message type 0x%x\n", + msg_type); + return; + } + + entry = &g_channel_message_table[msg_type]; + if (entry->messageHandler) + entry->messageHandler(hdr); +} Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_connection.c Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c Fri Jun 24 02:30:14 2016 (r302170) @@ -77,8 +77,8 @@ hv_vmbus_get_next_version(uint32_t curre * Negotiate the highest supported hypervisor version. */ static int -hv_vmbus_negotiate_version(hv_vmbus_channel_msg_info *msg_info, - uint32_t version) +hv_vmbus_negotiate_version(struct vmbus_softc *sc, + hv_vmbus_channel_msg_info *msg_info, uint32_t version) { int ret = 0; hv_vmbus_channel_initiate_contact *msg; @@ -89,14 +89,9 @@ hv_vmbus_negotiate_version(hv_vmbus_chan msg->header.message_type = HV_CHANNEL_MESSAGE_INITIATED_CONTACT; msg->vmbus_version_requested = version; - msg->interrupt_page = hv_get_phys_addr( - hv_vmbus_g_connection.interrupt_page); - - msg->monitor_page_1 = hv_get_phys_addr( - hv_vmbus_g_connection.monitor_page_1); - - msg->monitor_page_2 = hv_get_phys_addr( - hv_vmbus_g_connection.monitor_page_2); + msg->interrupt_page = sc->vmbus_evtflags_dma.hv_paddr; + msg->monitor_page_1 = sc->vmbus_mnf1_dma.hv_paddr; + msg->monitor_page_2 = sc->vmbus_mnf2_dma.hv_paddr; /** * Add to list before we send the request since we may receive the @@ -153,7 +148,7 @@ hv_vmbus_negotiate_version(hv_vmbus_chan * Send a connect request on the partition service connection */ int -hv_vmbus_connect(void) +hv_vmbus_connect(struct vmbus_softc *sc) { int ret = 0; uint32_t version; @@ -179,34 +174,6 @@ hv_vmbus_connect(void) mtx_init(&hv_vmbus_g_connection.channel_lock, "vmbus channel", NULL, MTX_DEF); - /** - * Setup the vmbus event connection for channel interrupt abstraction - * stuff - */ - hv_vmbus_g_connection.interrupt_page = malloc( - PAGE_SIZE, M_DEVBUF, - M_WAITOK | M_ZERO); - - hv_vmbus_g_connection.recv_interrupt_page = - hv_vmbus_g_connection.interrupt_page; - - hv_vmbus_g_connection.send_interrupt_page = - ((uint8_t *) hv_vmbus_g_connection.interrupt_page + - (PAGE_SIZE >> 1)); - - /** - * Set up the monitor notification facility. The 1st page for - * parent->child and the 2nd page for child->parent - */ - hv_vmbus_g_connection.monitor_page_1 = malloc( - PAGE_SIZE, - M_DEVBUF, - M_WAITOK | M_ZERO); - hv_vmbus_g_connection.monitor_page_2 = malloc( - PAGE_SIZE, - M_DEVBUF, - M_WAITOK | M_ZERO); - msg_info = (hv_vmbus_channel_msg_info*) malloc(sizeof(hv_vmbus_channel_msg_info) + sizeof(hv_vmbus_channel_initiate_contact), @@ -220,7 +187,7 @@ hv_vmbus_connect(void) version = HV_VMBUS_VERSION_CURRENT; do { - ret = hv_vmbus_negotiate_version(msg_info, version); + ret = hv_vmbus_negotiate_version(sc, msg_info, version); if (ret == EWOULDBLOCK) { /* * We timed out. @@ -254,14 +221,6 @@ hv_vmbus_connect(void) mtx_destroy(&hv_vmbus_g_connection.channel_lock); mtx_destroy(&hv_vmbus_g_connection.channel_msg_lock); - if (hv_vmbus_g_connection.interrupt_page != NULL) { - free(hv_vmbus_g_connection.interrupt_page, M_DEVBUF); - hv_vmbus_g_connection.interrupt_page = NULL; - } - - free(hv_vmbus_g_connection.monitor_page_1, M_DEVBUF); - free(hv_vmbus_g_connection.monitor_page_2, M_DEVBUF); - if (msg_info) { sema_destroy(&msg_info->wait_sema); free(msg_info, M_DEVBUF); @@ -284,8 +243,6 @@ hv_vmbus_disconnect(void) ret = hv_vmbus_post_message(&msg, sizeof(hv_vmbus_channel_unload)); - free(hv_vmbus_g_connection.interrupt_page, M_DEVBUF); - mtx_destroy(&hv_vmbus_g_connection.channel_msg_lock); free(hv_vmbus_g_connection.channels, M_DEVBUF); @@ -346,14 +303,13 @@ vmbus_event_proc(struct vmbus_softc *sc, } void -vmbus_event_proc_compat(struct vmbus_softc *sc __unused, int cpu) +vmbus_event_proc_compat(struct vmbus_softc *sc, int cpu) { struct vmbus_evtflags *eventf; eventf = VMBUS_PCPU_GET(sc, event_flags, cpu) + VMBUS_SINT_MESSAGE; if (atomic_testandclear_long(&eventf->evt_flags[0], 0)) { - vmbus_event_flags_proc( - hv_vmbus_g_connection.recv_interrupt_page, + vmbus_event_flags_proc(sc->vmbus_rx_evtflags, VMBUS_CHAN_MAX_COMPAT >> VMBUS_EVTFLAG_SHIFT); } } @@ -376,8 +332,8 @@ int hv_vmbus_post_message(void *buffer, * insufficient resources. 20 times should suffice in practice. */ for (retries = 0; retries < 20; retries++) { - ret = hv_vmbus_post_msg_via_msg_ipc(connId, 1, buffer, - bufferLen); + ret = hv_vmbus_post_msg_via_msg_ipc(connId, + VMBUS_MSGTYPE_CHANNEL, buffer, bufferLen); if (ret == HV_STATUS_SUCCESS) return (0); @@ -398,14 +354,12 @@ int hv_vmbus_post_message(void *buffer, int hv_vmbus_set_event(hv_vmbus_channel *channel) { + struct vmbus_softc *sc = vmbus_get_softc(); int ret = 0; - uint32_t child_rel_id = channel->offer_msg.child_rel_id; - - /* Each uint32_t represents 32 channels */ + uint32_t chanid = channel->offer_msg.child_rel_id; - synch_set_bit(child_rel_id & 31, - (((uint32_t *)hv_vmbus_g_connection.send_interrupt_page - + (child_rel_id >> 5)))); + atomic_set_long(&sc->vmbus_tx_evtflags[chanid >> VMBUS_EVTFLAG_SHIFT], + 1UL << (chanid & VMBUS_EVTFLAG_MASK)); ret = hv_vmbus_signal_event(channel->signal_event_param); return (ret); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Fri Jun 24 02:30:14 2016 (r302170) @@ -244,25 +244,7 @@ typedef enum { typedef struct { hv_vmbus_connect_state connect_state; uint32_t next_gpadl_handle; - /** - * Represents channel interrupts. Each bit position - * represents a channel. - * When a channel sends an interrupt via VMBUS, it - * finds its bit in the send_interrupt_page, set it and - * calls Hv to generate a port event. The other end - * receives the port event and parse the - * recv_interrupt_page to see which bit is set - */ - void *interrupt_page; - void *send_interrupt_page; - void *recv_interrupt_page; - /* - * 2 pages - 1st page for parent->child - * notification and 2nd is child->parent - * notification - */ - void *monitor_page_1; - void *monitor_page_2; + TAILQ_HEAD(, hv_vmbus_channel_msg_info) channel_msg_anchor; struct mtx channel_msg_lock; /** @@ -364,16 +346,6 @@ typedef enum { extern hv_vmbus_connection hv_vmbus_g_connection; -typedef void (*vmbus_msg_handler)(hv_vmbus_channel_msg_header *msg); - -typedef struct hv_vmbus_channel_msg_table_entry { - hv_vmbus_channel_msg_type messageType; - - vmbus_msg_handler messageHandler; -} hv_vmbus_channel_msg_table_entry; - -extern hv_vmbus_channel_msg_table_entry g_channel_message_table[]; - /* * Private, VM Bus functions */ @@ -450,7 +422,8 @@ int hv_vmbus_child_device_unregister( /** * Connection interfaces */ -int hv_vmbus_connect(void); +struct vmbus_softc; +int hv_vmbus_connect(struct vmbus_softc *); int hv_vmbus_disconnect(void); int hv_vmbus_post_message(void *buffer, size_t buf_size); int hv_vmbus_set_event(hv_vmbus_channel *channel); Modified: stable/10/sys/dev/hyperv/vmbus/hyperv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hyperv.c Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/hyperv.c Fri Jun 24 02:30:14 2016 (r302170) @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -104,40 +105,17 @@ hyperv_get_timecount(struct timecounter * @brief Invoke the specified hypercall */ static uint64_t -hv_vmbus_do_hypercall(uint64_t control, void* input, void* output) +hv_vmbus_do_hypercall(uint64_t value, void *input, void *output) { -#ifdef __x86_64__ - uint64_t hv_status = 0; - uint64_t input_address = (input) ? hv_get_phys_addr(input) : 0; - uint64_t output_address = (output) ? hv_get_phys_addr(output) : 0; - volatile void *hypercall_page = hypercall_context.hc_addr; - - __asm__ __volatile__ ("mov %0, %%r8" : : "r" (output_address): "r8"); - __asm__ __volatile__ ("call *%3" : "=a"(hv_status): - "c" (control), "d" (input_address), - "m" (hypercall_page)); - return (hv_status); -#else - uint32_t control_high = control >> 32; - uint32_t control_low = control & 0xFFFFFFFF; - uint32_t hv_status_high = 1; - uint32_t hv_status_low = 1; - uint64_t input_address = (input) ? hv_get_phys_addr(input) : 0; - uint32_t input_address_high = input_address >> 32; - uint32_t input_address_low = input_address & 0xFFFFFFFF; - uint64_t output_address = (output) ? hv_get_phys_addr(output) : 0; - uint32_t output_address_high = output_address >> 32; - uint32_t output_address_low = output_address & 0xFFFFFFFF; - volatile void *hypercall_page = hypercall_context.hc_addr; - - __asm__ __volatile__ ("call *%8" : "=d"(hv_status_high), - "=a"(hv_status_low) : "d" (control_high), - "a" (control_low), "b" (input_address_high), - "c" (input_address_low), - "D"(output_address_high), - "S"(output_address_low), "m" (hypercall_page)); - return (hv_status_low | ((uint64_t)hv_status_high << 32)); -#endif /* __x86_64__ */ + uint64_t in_paddr = 0, out_paddr = 0; + + if (input != NULL) + in_paddr = hv_get_phys_addr(input); + if (output != NULL) + out_paddr = hv_get_phys_addr(output); + + return hypercall_md(hypercall_context.hc_addr, value, + in_paddr, out_paddr); } /** Copied: stable/10/sys/dev/hyperv/vmbus/hyperv_machdep.h (from r301483, head/sys/dev/hyperv/vmbus/hyperv_machdep.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/hyperv_machdep.h Fri Jun 24 02:30:14 2016 (r302170, copy of r301483, head/sys/dev/hyperv/vmbus/hyperv_machdep.h) @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _HYPERV_MACHDEP_H_ +#define _HYPERV_MACHDEP_H_ + +#include + +uint64_t hypercall_md(volatile void *hc_addr, uint64_t in_val, + uint64_t in_paddr, uint64_t out_paddr); + +#endif /* !_HYPERV_MACHDEP_H_ */ Copied: stable/10/sys/dev/hyperv/vmbus/i386/hyperv_machdep.c (from r301483, head/sys/dev/hyperv/vmbus/i386/hyperv_machdep.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/vmbus/i386/hyperv_machdep.c Fri Jun 24 02:30:14 2016 (r302170, copy of r301483, head/sys/dev/hyperv/vmbus/i386/hyperv_machdep.c) @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2016 Microsoft Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +uint64_t +hypercall_md(volatile void *hc_addr, uint64_t in_val, + uint64_t in_paddr, uint64_t out_paddr) +{ + uint32_t in_val_hi = in_val >> 32; + uint32_t in_val_lo = in_val & 0xFFFFFFFF; + uint32_t status_hi, status_lo; + uint32_t in_paddr_hi = in_paddr >> 32; + uint32_t in_paddr_lo = in_paddr & 0xFFFFFFFF; + uint32_t out_paddr_hi = out_paddr >> 32; + uint32_t out_paddr_lo = out_paddr & 0xFFFFFFFF; + + __asm__ __volatile__ ("call *%8" : "=d"(status_hi), "=a"(status_lo) : + "d" (in_val_hi), "a" (in_val_lo), + "b" (in_paddr_hi), "c" (in_paddr_lo), + "D"(out_paddr_hi), "S"(out_paddr_lo), + "m" (hc_addr)); + return (status_lo | ((uint64_t)status_hi << 32)); +} Modified: stable/10/sys/dev/hyperv/vmbus/vmbus.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus.c Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/vmbus.c Fri Jun 24 02:30:14 2016 (r302170) @@ -81,27 +81,15 @@ vmbus_msg_task(void *xsc, int pending __ msg = VMBUS_PCPU_GET(sc, message, curcpu) + VMBUS_SINT_MESSAGE; for (;;) { - const hv_vmbus_channel_msg_table_entry *entry; - hv_vmbus_channel_msg_header *hdr; - hv_vmbus_channel_msg_type msg_type; - - if (msg->msg_type == VMBUS_MSGTYPE_NONE) - break; /* no message */ - - /* XXX: update messageHandler interface */ - hdr = __DEVOLATILE(hv_vmbus_channel_msg_header *, - msg->msg_data); - msg_type = hdr->message_type; - - if (msg_type >= HV_CHANNEL_MESSAGE_COUNT) { - printf("VMBUS: unknown message type = %d\n", msg_type); - goto handled; + if (msg->msg_type == VMBUS_MSGTYPE_NONE) { + /* No message */ + break; + } else if (msg->msg_type == VMBUS_MSGTYPE_CHANNEL) { + /* Channel message */ + vmbus_chan_msgproc(sc, + __DEVOLATILE(const struct vmbus_message *, msg)); } - entry = &g_channel_message_table[msg_type]; - if (entry->messageHandler) - entry->messageHandler(hdr); -handled: msg->msg_type = VMBUS_MSGTYPE_NONE; /* * Make sure the write to msg_type (i.e. set to @@ -321,30 +309,50 @@ vmbus_synic_teardown(void *arg) static int vmbus_dma_alloc(struct vmbus_softc *sc) { + bus_dma_tag_t parent_dtag; + uint8_t *evtflags; int cpu; + parent_dtag = bus_get_dma_tag(sc->vmbus_dev); CPU_FOREACH(cpu) { void *ptr; /* * Per-cpu messages and event flags. */ - ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), - PAGE_SIZE, 0, PAGE_SIZE, - VMBUS_PCPU_PTR(sc, message_dma, cpu), + ptr = hyperv_dmamem_alloc(parent_dtag, PAGE_SIZE, 0, + PAGE_SIZE, VMBUS_PCPU_PTR(sc, message_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); if (ptr == NULL) return ENOMEM; VMBUS_PCPU_GET(sc, message, cpu) = ptr; - ptr = hyperv_dmamem_alloc(bus_get_dma_tag(sc->vmbus_dev), - PAGE_SIZE, 0, PAGE_SIZE, - VMBUS_PCPU_PTR(sc, event_flags_dma, cpu), + ptr = hyperv_dmamem_alloc(parent_dtag, PAGE_SIZE, 0, + PAGE_SIZE, VMBUS_PCPU_PTR(sc, event_flags_dma, cpu), BUS_DMA_WAITOK | BUS_DMA_ZERO); if (ptr == NULL) return ENOMEM; VMBUS_PCPU_GET(sc, event_flags, cpu) = ptr; } + + evtflags = hyperv_dmamem_alloc(parent_dtag, PAGE_SIZE, 0, + PAGE_SIZE, &sc->vmbus_evtflags_dma, BUS_DMA_WAITOK | BUS_DMA_ZERO); + if (evtflags == NULL) + return ENOMEM; + sc->vmbus_rx_evtflags = (u_long *)evtflags; + sc->vmbus_tx_evtflags = (u_long *)(evtflags + (PAGE_SIZE / 2)); + sc->vmbus_evtflags = evtflags; + + sc->vmbus_mnf1 = hyperv_dmamem_alloc(parent_dtag, PAGE_SIZE, 0, + PAGE_SIZE, &sc->vmbus_mnf1_dma, BUS_DMA_WAITOK | BUS_DMA_ZERO); + if (sc->vmbus_mnf1 == NULL) + return ENOMEM; + + sc->vmbus_mnf2 = hyperv_dmamem_alloc(parent_dtag, PAGE_SIZE, 0, + PAGE_SIZE, &sc->vmbus_mnf2_dma, BUS_DMA_WAITOK | BUS_DMA_ZERO); + if (sc->vmbus_mnf2 == NULL) + return ENOMEM; + return 0; } @@ -353,6 +361,21 @@ vmbus_dma_free(struct vmbus_softc *sc) { int cpu; + if (sc->vmbus_evtflags != NULL) { + hyperv_dmamem_free(&sc->vmbus_evtflags_dma, sc->vmbus_evtflags); + sc->vmbus_evtflags = NULL; + sc->vmbus_rx_evtflags = NULL; + sc->vmbus_tx_evtflags = NULL; + } + if (sc->vmbus_mnf1 != NULL) { + hyperv_dmamem_free(&sc->vmbus_mnf1_dma, sc->vmbus_mnf1); + sc->vmbus_mnf1 = NULL; + } + if (sc->vmbus_mnf2 != NULL) { + hyperv_dmamem_free(&sc->vmbus_mnf2_dma, sc->vmbus_mnf2); + sc->vmbus_mnf2 = NULL; + } + CPU_FOREACH(cpu) { if (VMBUS_PCPU_GET(sc, message, cpu) != NULL) { hyperv_dmamem_free( @@ -701,8 +724,7 @@ vmbus_bus_init(void) /* * Connect to VMBus in the root partition */ - ret = hv_vmbus_connect(); - + ret = hv_vmbus_connect(sc); if (ret != 0) goto cleanup; Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_reg.h Fri Jun 24 02:30:14 2016 (r302170) @@ -49,6 +49,7 @@ struct vmbus_message { CTASSERT(sizeof(struct vmbus_message) == VMBUS_MSG_SIZE); #define VMBUS_MSGTYPE_NONE 0 +#define VMBUS_MSGTYPE_CHANNEL 1 #define VMBUS_MSGTYPE_TIMER_EXPIRED 0x80000010 #define VMBUS_MSGFLAG_PENDING 0x01 @@ -65,6 +66,7 @@ CTASSERT(sizeof(struct vmbus_message) == #define VMBUS_EVTFLAG_SHIFT 5 #endif #define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT) +#define VMBUS_EVTFLAG_MASK (VMBUS_EVTFLAG_LEN - 1) #define VMBUS_EVTFLAGS_SIZE 256 struct vmbus_evtflags { Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h Fri Jun 24 02:30:14 2016 (r302170) @@ -50,7 +50,7 @@ struct vmbus_pcpu_data { struct vmbus_message *message; /* shared messages */ uint32_t vcpuid; /* virtual cpuid */ int event_flags_cnt;/* # of event flags */ - struct vmbus_evtflags *event_flags; /* shared event flags */ + struct vmbus_evtflags *event_flags; /* event flags from host */ /* Rarely used fields */ struct hyperv_dma message_dma; /* busdma glue */ @@ -62,12 +62,26 @@ struct vmbus_pcpu_data { struct vmbus_softc { void (*vmbus_event_proc)(struct vmbus_softc *, int); + u_long *vmbus_tx_evtflags; + /* event flags to host */ + void *vmbus_mnf2; /* monitored by host */ + + u_long *vmbus_rx_evtflags; + /* compat evtflgs from host */ struct vmbus_pcpu_data vmbus_pcpu[MAXCPU]; /* Rarely used fields */ device_t vmbus_dev; int vmbus_idtvec; uint32_t vmbus_flags; /* see VMBUS_FLAG_ */ + + /* Shared memory for vmbus_{rx,tx}_evtflags */ + void *vmbus_evtflags; + struct hyperv_dma vmbus_evtflags_dma; + + void *vmbus_mnf1; /* monitored by VM, unused */ + struct hyperv_dma vmbus_mnf1_dma; + struct hyperv_dma vmbus_mnf2_dma; }; #define VMBUS_FLAG_ATTACHED 0x0001 /* vmbus was attached */ @@ -92,6 +106,7 @@ vmbus_get_device(void) struct hv_vmbus_channel; struct trapframe; +struct vmbus_message; void vmbus_on_channel_open(const struct hv_vmbus_channel *); void vmbus_event_proc(struct vmbus_softc *, int); @@ -100,4 +115,6 @@ void vmbus_handle_intr(struct trapframe void vmbus_et_intr(struct trapframe *); +void vmbus_chan_msgproc(struct vmbus_softc *, const struct vmbus_message *); + #endif /* !_VMBUS_VAR_H_ */ Modified: stable/10/sys/modules/hyperv/vmbus/Makefile ============================================================================== --- stable/10/sys/modules/hyperv/vmbus/Makefile Fri Jun 24 02:28:24 2016 (r302169) +++ stable/10/sys/modules/hyperv/vmbus/Makefile Fri Jun 24 02:30:14 2016 (r302170) @@ -10,6 +10,7 @@ SRCS= hv_channel.c \ hv_ring_buffer.c \ hyperv.c \ hyperv_busdma.c \ + hyperv_machdep.c \ vmbus.c \ vmbus_et.c SRCS+= acpi_if.h bus_if.h device_if.h opt_acpi.h From owner-svn-src-stable-10@freebsd.org Sat Jun 25 09:32:36 2016 Return-Path: Delivered-To: svn-src-stable-10@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 E3028B803B8; Sat, 25 Jun 2016 09:32:36 +0000 (UTC) (envelope-from kib@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 AFAC21703; Sat, 25 Jun 2016 09:32:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5P9WZvL060717; Sat, 25 Jun 2016 09:32:35 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5P9WZ4C060716; Sat, 25 Jun 2016 09:32:35 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201606250932.u5P9WZ4C060716@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 25 Jun 2016 09:32:35 +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: r302192 - stable/10/sys/nlm 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2016 09:32:37 -0000 Author: kib Date: Sat Jun 25 09:32:35 2016 New Revision: 302192 URL: https://svnweb.freebsd.org/changeset/base/302192 Log: MFC r302013: After the vnode unlock, mount point might be destroyed immediately, dropping the reference on mnt_cred. Prevent this by referencing the temporal credentials before unlock. Modified: stable/10/sys/nlm/nlm_advlock.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/nlm/nlm_advlock.c ============================================================================== --- stable/10/sys/nlm/nlm_advlock.c Sat Jun 25 04:36:30 2016 (r302191) +++ stable/10/sys/nlm/nlm_advlock.c Sat Jun 25 09:32:35 2016 (r302192) @@ -210,7 +210,7 @@ nlm_advlock_internal(struct vnode *vp, v struct rpc_callextra ext; struct nlm_feedback_arg nf; AUTH *auth; - struct ucred *cred; + struct ucred *cred, *cred1; struct nlm_file_svid *ns; int svid; int error; @@ -240,15 +240,17 @@ nlm_advlock_internal(struct vnode *vp, v else retries = INT_MAX; - if (unlock_vp) - VOP_UNLOCK(vp, 0); - /* * We need to switch to mount-point creds so that we can send - * packets from a privileged port. + * packets from a privileged port. Reference mnt_cred and + * switch to them before unlocking the vnode, since mount + * point could be unmounted right after unlock. */ cred = td->td_ucred; td->td_ucred = vp->v_mount->mnt_cred; + crhold(td->td_ucred); + if (unlock_vp) + VOP_UNLOCK(vp, 0); host = nlm_find_host_by_name(servername, sa, vers); auth = authunix_create(cred); @@ -373,7 +375,9 @@ nlm_advlock_internal(struct vnode *vp, v if (ns) nlm_free_svid(ns); + cred1 = td->td_ucred; td->td_ucred = cred; + crfree(cred1); AUTH_DESTROY(auth); nlm_host_release(host); From owner-svn-src-stable-10@freebsd.org Sat Jun 25 10:08:05 2016 Return-Path: Delivered-To: svn-src-stable-10@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 B339CB80BEE; Sat, 25 Jun 2016 10:08:05 +0000 (UTC) (envelope-from ed@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 68F9D261E; Sat, 25 Jun 2016 10:08:05 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5PA84xd071938; Sat, 25 Jun 2016 10:08:04 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5PA84lN071937; Sat, 25 Jun 2016 10:08:04 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201606251008.u5PA84lN071937@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Sat, 25 Jun 2016 10:08:04 +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: r302193 - stable/10/lib/libc/stdlib 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-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2016 10:08:05 -0000 Author: ed Date: Sat Jun 25 10:08:04 2016 New Revision: 302193 URL: https://svnweb.freebsd.org/changeset/base/302193 Log: MFC r300775: Let l64a() properly null terminate its result. Though the buffer used by l64a() is initialized with null bytes, repetetive calls may end up having trailing garbage of previous invocations because we don't end up terminating the string. Instead of importing NetBSD's fix, use this opportunity to simplify this function dramatically, for example by just storing the Base64 character set in a string. There is also no need to do the bitmasking, as we can just use the proper integer type from . Modified: stable/10/lib/libc/stdlib/l64a.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdlib/l64a.c ============================================================================== --- stable/10/lib/libc/stdlib/l64a.c Sat Jun 25 09:32:35 2016 (r302192) +++ stable/10/lib/libc/stdlib/l64a.c Sat Jun 25 10:08:04 2016 (r302193) @@ -12,18 +12,13 @@ __RCSID("$NetBSD: l64a.c,v 1.13 2003/07/ #include __FBSDID("$FreeBSD$"); +#include #include -#define ADOT 46 /* ASCII '.' */ -#define ASLASH ADOT + 1 /* ASCII '/' */ -#define A0 48 /* ASCII '0' */ -#define AA 65 /* ASCII 'A' */ -#define Aa 97 /* ASCII 'a' */ - char * l64a(long value) { - static char buf[8]; + static char buf[7]; (void)l64a_r(value, buf, sizeof(buf)); return (buf); @@ -32,21 +27,18 @@ l64a(long value) int l64a_r(long value, char *buffer, int buflen) { - long v; - int digit; - - v = value & (long)0xffffffff; - for (; v != 0 && buflen > 1; buffer++, buflen--) { - digit = v & 0x3f; - if (digit < 2) - *buffer = digit + ADOT; - else if (digit < 12) - *buffer = digit + A0 - 2; - else if (digit < 38) - *buffer = digit + AA - 12; - else - *buffer = digit + Aa - 38; + static const char chars[] = + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + uint32_t v; + + v = value; + while (buflen-- > 0) { + if (v == 0) { + *buffer = '\0'; + return (0); + } + *buffer++ = chars[v & 0x3f]; v >>= 6; } - return (v == 0 ? 0 : -1); + return (-1); }