From nobody Fri Apr 14 14:00:55 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PydQJ4LdKz45JK7; Fri, 14 Apr 2023 14:00:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PydQH47TPz3KG6; Fri, 14 Apr 2023 14:00:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681480855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sueghzpuZJTulqzkQAQe9AOFXykPaR/Pi9AIFGQulEo=; b=Zgp1ZDGOZFha/cNcWHMCog9x7BVWUQHXQQLFgzZ+CcOCIdSk3GWTlF8F0rI68FrRTj01ze hNVdYxzsNyvkKbAiu4g5sQSB+4T0NQeizB37e0v4QcUOLRvjU+Qhm6jq1XVdu4QtQ8jK4w LWYDMiDjnN+jpW84SMXMeVQcQdv1Aj/2QZFE8PjEaAgO33upScb2NkXiAMbeC5rtJ3d4JZ pOw4BVVSTowDeQO2aPMMCkivSTZtJCaqNo5LG17mNddtGM66ay6MH9PnYFha076ec04hif 6OXAnDKq3egyUKf6Xe4ne2T9hqv5oCrr5FzMNA0YsniIGubVB3asjVqrGgrVgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681480855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sueghzpuZJTulqzkQAQe9AOFXykPaR/Pi9AIFGQulEo=; b=EvNRzU3PE11XrAdh5RfCwGol9QTAr23QljFWHwFufqrQSDUgcHl8v4ZHi945PVJejdldlm yaGdIvwgdRi5FbOaZ6EBnIuyeSg/maRAJEDWrUjJlRhp5Ay2X51iNsdsImV9uJ9gCyz+f4 p0xY0/S1bsHb5klO0S/0FkO1eHeJXa/fduEZOBpsQhYsMru6n2rev1Cugf+0OwscRH+Y/6 VknKPp1+tqm/F/BBtb3dUYeSiEQ/xX2+eqEqHcSPsC3m3eGQ+1ZBiBZj4BtsYblGgviaUP YLSOg3H7PAYxOGybRqLlUrYmwGD7Sj4bUKULxdT0REA4Nae/pnBU6tNKHHeNGA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681480855; a=rsa-sha256; cv=none; b=VKlfoqBlWtUmFbx53s2YR/VEioXeS06VpfMj9hd8xPxFOY8yzc5Cu8dBFZne3OMLBKaZSW 9j6buN6Zk60J4XW7LDHjXehHlD5U5ImkU8K3YVRFSPPQPZusnizShWndOM+ATMabWtO1Ca Ubj7t9W+kne+LsBH5EhFyxKto4LnZu/AVYBrH4Ad/2Q7Lpjrvm3yV9eZ3fm/gznWHS76hL JnPK0MiHaysMYaArutgpghlyqJL1IhcJw13vom19zn5U0tMDw+zFWTPCQbyXx1QBDFyIhm N+FzXWNXOJbh0cdShBt1pUJfDaXnqdGhsFahRQXRdfHPTtcMQFKKQCDF5j1tlQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PydQH2yMQzRX9; Fri, 14 Apr 2023 14:00:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33EE0t5A083752; Fri, 14 Apr 2023 14:00:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33EE0tEQ083751; Fri, 14 Apr 2023 14:00:55 GMT (envelope-from git) Date: Fri, 14 Apr 2023 14:00:55 GMT Message-Id: <202304141400.33EE0tEQ083751@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Roger=20Pau=20Monn=C3=A9?= Subject: git: 834013dea2d2 - main - xen/intr: rework xen_intr_alloc_isrc() locking List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 834013dea2d29ef943620bfaf7f269f9e581e170 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=834013dea2d29ef943620bfaf7f269f9e581e170 commit 834013dea2d29ef943620bfaf7f269f9e581e170 Author: Elliott Mitchell AuthorDate: 2021-05-11 19:05:03 +0000 Commit: Roger Pau Monné CommitDate: 2023-04-14 13:58:50 +0000 xen/intr: rework xen_intr_alloc_isrc() locking Locking for allocation was being done in xen_intr_bind_isrc(), but the unlock was inside xen_intr_alloc_isrc(). While the lock acquisition at the end of xen_intr_alloc_isrc() was to modify xen_intr_port_to_isrc[], NOT allocation. Fix this garbled (though working) locking scheme. Now locking for allocation is strictly in xen_intr_alloc_isrc(), while locking to modify xen_intr_port_to_isrc[] is in xen_intr_bind_isrc(). Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30726 --- sys/x86/xen/xen_intr.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c index 6e4b1d9df1f8..cf20f2cdcbf8 100644 --- a/sys/x86/xen/xen_intr.c +++ b/sys/x86/xen/xen_intr.c @@ -317,9 +317,10 @@ xen_intr_alloc_isrc(enum evtchn_type type) unsigned int vector; int error; - KASSERT(mtx_owned(&xen_intr_isrc_lock), ("Evtchn alloc lock not held")); + mtx_lock(&xen_intr_isrc_lock); isrc = xen_intr_find_unused_isrc(type); if (isrc != NULL) { + mtx_unlock(&xen_intr_isrc_lock); return (isrc); } @@ -328,6 +329,7 @@ xen_intr_alloc_isrc(enum evtchn_type type) warned = 1; printf("%s: Xen interrupts exhausted.\n", __func__); } + mtx_unlock(&xen_intr_isrc_lock); return (NULL); } @@ -346,7 +348,6 @@ xen_intr_alloc_isrc(enum evtchn_type type) if (error != 0) panic("%s(): failed registering interrupt %u, error=%d\n", __func__, vector, error); - mtx_lock(&xen_intr_isrc_lock); return (isrc); } @@ -427,16 +428,14 @@ xen_intr_bind_isrc(struct xenisrc **isrcp, evtchn_port_t local_port, } *port_handlep = NULL; - mtx_lock(&xen_intr_isrc_lock); isrc = xen_intr_alloc_isrc(type); - if (isrc == NULL) { - mtx_unlock(&xen_intr_isrc_lock); + if (isrc == NULL) return (ENOSPC); - } isrc->xi_port = local_port; isrc->xi_close = false; - xen_intr_port_to_isrc[local_port] = isrc; refcount_init(&isrc->xi_refcount, 1); + mtx_lock(&xen_intr_isrc_lock); + xen_intr_port_to_isrc[isrc->xi_port] = isrc; mtx_unlock(&xen_intr_isrc_lock); #ifdef SMP