From nobody Tue Apr 16 07:07:37 2024 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 4VJZqY2krwz5G0pT; Tue, 16 Apr 2024 07:07:37 +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 4VJZqY2GDCz4mg3; Tue, 16 Apr 2024 07:07:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713251257; 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=NWDNMpGfZGzdca4TbYY9BJsuM7xtxMjI7LBRCk0TU28=; b=w+H8KSnvUlhLYgs13gscg4kxHpYtpyiihYxjEgwLRPZOqKuc6Jj++l30gUpUdRF9YGV5/s sbmeBn2WTSiW7DBUE2dq6N7XZ19LqCt87UNymUsUIVZga1NaIvTRaUfLJzAtR3KecHgAS2 Fy+FKDAXOzv0xHJcvmQVQpnBzLx+KkiE6YsK0PPYZgIIw1G49FZvJv1X+9s5z5jAAJhoTP i08LLndXPm1wOT1yGo4EGVzjT7VObsbKBxlRAtNgDXMMoidbPWpkghwspd701A8CC1wfyu hbbUHcVtX4gRTx6u+lCxdcHPV8NCtEZuEIASJDsfe/GKOcIBLnb7aP9rV2kEkQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713251257; a=rsa-sha256; cv=none; b=sNkni7aEdMRAnvc/OajfKkZkB8eGLsxkMR7uDfpQSceaZCXCtaWMvb0SwDbJhFdMbSbV5u NMAzKsNxOUGzAQxP2SX43EYe9GIGz3bW2spdBrPJz9fvlLVf/RhYkLQVkcMKaiVhn/2lzI 2I2H9D+LaxPc8vRfk2/d6NKjD4n38a/2GqTS3zE+z61ESJZXWH1Feyg1i9ReZ3e4SAViXg Bnjmfn1QRqTfiM7tcCjiZVWP/Otd6z9Q37xop/er8eU+H1p6ROT+9VWPsg+1AFFjDCqwQr N6oLDyv+i+/5EY320VuS75eoYAmgLunXUcpk4NQLj6jwzRWVPt6PT1+9PO+cxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713251257; 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=NWDNMpGfZGzdca4TbYY9BJsuM7xtxMjI7LBRCk0TU28=; b=f4vZ45adOfqYLx1ORXPL2wlpoyAY4AuPM2Z14VOTq4OCCv04eKHVhqY/YljxCSc7vhMWx+ VAt2CbrCQDGE8h52JRnP8ga2XtwJaJ+4yshKgAWgPisDAqbBJUzi6ZHRuqWnijQfQlqqux 5BpMv4AN3RnBSgRRHTaF9Dx+RZ2IpJ3LkMWvI/uzXdJUzu6QyvBZGlB7n5f+Hr6eHJpN6b Rm5k8NchkzCWcSxbXAJ58B/yezO+QHkE9ePOXehZquKAalTfhVNE5OBfT2fUmGsz5vMRCr P4RdCBX5Rd/3HMrgy5L7cSweIJ7LMo7CNWudYIjw8QlcelMUJMwxkbMmYNHVbw== 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 4VJZqY1sPzzYgw; Tue, 16 Apr 2024 07:07:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43G77bP3097173; Tue, 16 Apr 2024 07:07:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43G77b5U097170; Tue, 16 Apr 2024 07:07:37 GMT (envelope-from git) Date: Tue, 16 Apr 2024 07:07:37 GMT Message-Id: <202404160707.43G77b5U097170@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: f750dce972ef - main - x86/xen: fix accounted interrupt time 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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: f750dce972efaea614aa6d03ecdb24aa962a38a4 Auto-Submitted: auto-generated The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=f750dce972efaea614aa6d03ecdb24aa962a38a4 commit f750dce972efaea614aa6d03ecdb24aa962a38a4 Author: Roger Pau Monné AuthorDate: 2024-03-05 13:15:03 +0000 Commit: Roger Pau Monné CommitDate: 2024-04-16 07:06:33 +0000 x86/xen: fix accounted interrupt time The current addition to the interrupt nesting level in xen_arch_intr_handle_upcall() needs to be compensated in xen_intr_handle_upcall(), otherwise interrupts dispatched by the upcall handler end up seeing a td_intr_nesting_level of 2 or more, which makes them assume there's been an interrupt nesting. Such extra interrupt nesting count lead to statclock() reporting idle time as interrupt, as the call from interrupt context will always be seen as a nested one (td->td_intr_nesting_level >= 2) due to the nesting count increase done by both xen_arch_intr_handle_upcall() and intr_execute_handlers(). Fix this by adjusting the nested interrupt count before dispatching interrupts from xen_intr_handle_upcall(). PR: 277231 Reported by: Matthew Grooms Fixes: af610cabf1f4 ('xen/intr: adjust xen_intr_handle_upcall() to match driver filter') Sponsored by: Cloud Software Group Reviewed by: Elliott Mitchell --- sys/dev/xen/bus/xen_intr.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sys/dev/xen/bus/xen_intr.c b/sys/dev/xen/bus/xen_intr.c index 609f31b5418a..bfe080b16f03 100644 --- a/sys/dev/xen/bus/xen_intr.c +++ b/sys/dev/xen/bus/xen_intr.c @@ -341,7 +341,7 @@ xen_intr_active_ports(const struct xen_intr_pcpu_data *const pcpu, /** * Interrupt handler for processing all Xen event channel events. * - * \param trap_frame The trap frame context for the current interrupt. + * \param unused */ int xen_intr_handle_upcall(void *unused __unused) @@ -354,6 +354,15 @@ xen_intr_handle_upcall(void *unused __unused) struct xen_intr_pcpu_data *pc; u_long l1, l2; + /* + * The upcall handler is an interrupt handler itself (that calls other + * interrupt handlers), hence the caller has the responsibility to + * increase td_intr_nesting_level ahead of dispatching the upcall + * handler. + */ + KASSERT(curthread->td_intr_nesting_level > 0, + ("Unexpected thread context")); + /* We must remain on the same vCPU during this function */ CRITICAL_ASSERT(curthread); @@ -417,7 +426,17 @@ xen_intr_handle_upcall(void *unused __unused) ("Received unexpected event on vCPU#%u, event bound to vCPU#%u", PCPU_GET(cpuid), isrc->xi_cpu)); + /* + * Reduce interrupt nesting level ahead of calling the + * per-arch interrupt dispatch helper. This is + * required because the per-arch dispatcher will also + * increase td_intr_nesting_level, and then handlers + * would wrongly see td_intr_nesting_level = 2 when + * there's no nesting at all. + */ + curthread->td_intr_nesting_level--; xen_arch_intr_execute_handlers(isrc, trap_frame); + curthread->td_intr_nesting_level++; /* * If this is the final port processed,