From nobody Fri Apr 14 14:00:56 2023 X-Original-To: dev-commits-src-main@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 4PydQK3BLZz45JLm; Fri, 14 Apr 2023 14:00:57 +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 4PydQJ68xPz3K10; Fri, 14 Apr 2023 14:00:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681480856; 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=jquY8VlbcbPSzho70Wsk1POJ1Ym9bm1D5GkZZLsE/M0=; b=e8dqUZSysj59OSiIkcPXbJbZ+HBEvIgnKITXANwhjE/59Jrp5LX3mEs2P2n7KH2z0kUMhS CzpMlBSzVjwaRx1+NgUrEO2ZPAjwip8BkgHzZFdesr+lTU2zHuXnzctBvs0KhJvMEeGkGz yFBIwDp1UffpyX/zlpmuusRwyN9yBurczq4RraSv49aAsifXhBhTbkxzZiAUTjyH6aRd0V VrInPANj8Ki1ChZEw8hA2D5K9R2qMT4XWbXlixfUtMHgcC/YDqjjjf3tUPH+u/4uIjYUCi 2WegYNYR+L9SnjEvvthWA8xzC9zHGM2DwzS6s6GenRbxXNY9mc8n5FtIuVBUeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681480856; 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=jquY8VlbcbPSzho70Wsk1POJ1Ym9bm1D5GkZZLsE/M0=; b=OQVztGcNl+av8cWI5TKJtsEWBCcp/+pn4N5+gyM3JKNrGHX1tRpqSXtfRXpqS3afp1EQGF WGrEG+Hrx3oqsguauTNHWP/1qGKVTg/VxOgbSz/OiTSw/Bz4OTqwapajR+U4XGOpTomSEd 8ruoM1l0IQ3DfQn2ZQWz1YI8xAtOWHhz0fwOlxNmPKUM926HQFIqNCsCDJieosyL76JVhB xjeQ7uIukNxZtdQPMNOO0DZWYnPtfK1qEjjtoWGwd2uXv1CQ8WS41fJ0G0UFkGPNn3ADxC L2qhX2P7NNLysphKM8voCWQFnUBKmmvofdbc4PhVr0+keZ24hmR40sSnxufJgg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681480856; a=rsa-sha256; cv=none; b=Ww/Lz/gd4LHbx4wckmPag/Z4p0YxLuAuKxFFOUkTCdPBy75I7x7YunxnA94OJA68gdGyiV V56pOqIfEkVaoIfAW+wZu8ZKzZkEw4wXkz+OwyG6dSwCUnMmTpV0+DYIz1jqbKozcbohuP Xfwp62sdf6gfgYCSQdZtOTCYvKNQSkTS0f0ujhQBZqctRbiGD3LIRddT/ctwzM0yKb9ggp 2Gq1B4fUcrvMPC5Wi8ORVln5qqUHLMR4wOKzJx7h5g3EZQtaEQs1UqJYAPkA3Btsp89Nqx KFNGuLjX2OZ6Nv8aMs7yTaUV9EMfUGnuziA5MYw3SHvbdbvZo5CIy91q5P5jrw== 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 4PydQJ3RMBzRXB; Fri, 14 Apr 2023 14:00:56 +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 33EE0uWr083778; Fri, 14 Apr 2023 14:00:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33EE0uWK083777; Fri, 14 Apr 2023 14:00:56 GMT (envelope-from git) Date: Fri, 14 Apr 2023 14:00:56 GMT Message-Id: <202304141400.33EE0uWK083777@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: ff73b1d69b90 - main - xen/intr: split xen_intr_isrc_lock uses List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: ff73b1d69b90e33e18e60a10383b75058c7639c1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=ff73b1d69b90e33e18e60a10383b75058c7639c1 commit ff73b1d69b90e33e18e60a10383b75058c7639c1 Author: Elliott Mitchell AuthorDate: 2021-05-11 19:05:03 +0000 Commit: Roger Pau Monné CommitDate: 2023-04-14 13:58:51 +0000 xen/intr: split xen_intr_isrc_lock uses There are actually several distinct locking domains in xen_intr.c, but all were sharing the same lock. Both xen_intr_port_to_isrc[] and the x86 interrupt structures needed protection. Split these two apart as a precursor to splitting the architecture portions off the file. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30726 --- sys/x86/xen/xen_intr.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c index cf20f2cdcbf8..b3996e6cf1aa 100644 --- a/sys/x86/xen/xen_intr.c +++ b/sys/x86/xen/xen_intr.c @@ -73,6 +73,16 @@ __FBSDID("$FreeBSD$"); static MALLOC_DEFINE(M_XENINTR, "xen_intr", "Xen Interrupt Services"); +/* + * Lock for x86-related structures. Notably modifying + * xen_intr_auto_vector_count, and allocating interrupts require this lock be + * held. + * + * ->xi_type == EVTCHN_TYPE_UNBOUND indicates a xenisrc is under control of + * this lock and operations require it be held. + */ +static struct mtx xen_intr_x86_lock; + static u_int first_evtchn_irq; /** @@ -160,6 +170,16 @@ struct pic xen_intr_pic = { .pic_assign_cpu = xen_intr_pic_assign_cpu, }; +/* + * Lock for interrupt core data. + * + * Modifying xen_intr_port_to_isrc[], or isrc->xi_port (implies the former) + * requires this lock be held. Any time this lock is not held, the condition + * `!xen_intr_port_to_isrc[i] || (xen_intr_port_to_isrc[i]->ix_port == i)` + * MUST be true for all values of i which are valid indicies of the array. + * + * Acquire/release operations for isrc->xi_refcount require this lock be held. + */ static struct mtx xen_intr_isrc_lock; static u_int xen_intr_auto_vector_count; static struct xenisrc *xen_intr_port_to_isrc[NR_EVENT_CHANNELS]; @@ -274,7 +294,7 @@ xen_intr_find_unused_isrc(enum evtchn_type type) { int isrc_idx; - KASSERT(mtx_owned(&xen_intr_isrc_lock), ("Evtchn isrc lock not held")); + mtx_assert(&xen_intr_x86_lock, MA_OWNED); for (isrc_idx = 0; isrc_idx < xen_intr_auto_vector_count; isrc_idx ++) { struct xenisrc *isrc; @@ -317,10 +337,10 @@ xen_intr_alloc_isrc(enum evtchn_type type) unsigned int vector; int error; - mtx_lock(&xen_intr_isrc_lock); + mtx_lock(&xen_intr_x86_lock); isrc = xen_intr_find_unused_isrc(type); if (isrc != NULL) { - mtx_unlock(&xen_intr_isrc_lock); + mtx_unlock(&xen_intr_x86_lock); return (isrc); } @@ -329,7 +349,7 @@ xen_intr_alloc_isrc(enum evtchn_type type) warned = 1; printf("%s: Xen interrupts exhausted.\n", __func__); } - mtx_unlock(&xen_intr_isrc_lock); + mtx_unlock(&xen_intr_x86_lock); return (NULL); } @@ -339,7 +359,7 @@ xen_intr_alloc_isrc(enum evtchn_type type) KASSERT((intr_lookup_source(vector) == NULL), ("Trying to use an already allocated vector")); - mtx_unlock(&xen_intr_isrc_lock); + mtx_unlock(&xen_intr_x86_lock); isrc = malloc(sizeof(*isrc), M_XENINTR, M_WAITOK | M_ZERO); isrc->xi_intsrc.is_pic = &xen_intr_pic; isrc->xi_vector = vector; @@ -383,11 +403,16 @@ xen_intr_release_isrc(struct xenisrc *isrc) xen_intr_port_to_isrc[isrc->xi_port] = NULL; } + /* not reachable from xen_intr_port_to_isrc[], unlock */ + mtx_unlock(&xen_intr_isrc_lock); + isrc->xi_cpu = 0; - isrc->xi_type = EVTCHN_TYPE_UNBOUND; isrc->xi_port = INVALID_EVTCHN; isrc->xi_cookie = NULL; - mtx_unlock(&xen_intr_isrc_lock); + + mtx_lock(&xen_intr_x86_lock); + isrc->xi_type = EVTCHN_TYPE_UNBOUND; + mtx_unlock(&xen_intr_x86_lock); return (0); } @@ -634,6 +659,8 @@ xen_intr_init(void *dummy __unused) mtx_init(&xen_intr_isrc_lock, "xen-irq-lock", NULL, MTX_DEF); + mtx_init(&xen_intr_x86_lock, "xen-x86-table-lock", NULL, MTX_DEF); + /* * Set the per-cpu mask of CPU#0 to enable all, since by default all * event channels are bound to CPU#0.