From nobody Wed Jun 25 09:06:05 2025 X-Original-To: dev-commits-src-branches@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 4bRwsT6KFKz5ym2K; Wed, 25 Jun 2025 09:06:05 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bRwsT5PC8z3HZq; Wed, 25 Jun 2025 09:06:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750842365; 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=g2uQYsGawKI4XUi0XG+c0QNDSJncly4sU2o657AuPS8=; b=X0VoEFq5jZKyHadCerWntMDCL8jOJMRXtRNYo1FT/ECnNnTt+s5I4oNatR/aG06wPOmnt/ CG7O4CV2jrgT7Ndi6QLqHcEirOwH3JzxMbm6JZ3MJTu5eff4qMKWkdkfyiuc3kKjZ7Ge3d UUnjWombBc5kP5r5Viga6g+tewWqSL/R0XnmcpLMEZO+nGqfvKX+iBexmkACIYCPbXtIKx QEb8AbWWQN85WM6LXoEkZM37OuN/xdzoJr9gvDzpemCNoLgNXuUDlFFAiqRF7Oloewol5m 2LVkSfyICfBgb/E+VWfmkq/rf8gPwhndbdPNbvT6CgblHU8/7x2fPmVPjxDW8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750842365; 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=g2uQYsGawKI4XUi0XG+c0QNDSJncly4sU2o657AuPS8=; b=sEzt2l+yfZR9ETh9Hzc2bNyocRtqHyuLmwKr6ARKnnZvlYuxuKVQdvWUrKA1Qzu5EejM5a p2Kjfsm6+xF/1Rc5N70hhPri8KTRxmALGQCI5LG5vpBGmvDBi9l0eijxYV2UXhvifMA3L2 dxXMxHgd1STlvzlWwH2dVvv2PEPwO1Lsn6uRc/6hgy5CWDjdiQyXH6jWynXdqSWn+mVtqn RsXjmgRVmMuS1eLfb49KHdRSZ9b5ikH4jnOH/PtpmNLAqdU6MnrxcloZMnp3/Dm2+kPAO6 UYVY5DMaYNgdtg/ZAYFWSJzj/MKuWiusBNX9IXCg1Aej5hOaXcqB2DwTT2aCVg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750842365; a=rsa-sha256; cv=none; b=iVtqtNmrDAlR7aSI85/95VyDNEI/yh92g4ElZwOF6Mzq/ttnuLtB6ZNEgVGJEYvDjw/klE STP6YgU81b4zHd2cSHVy3OGORJIk1UKx9VEd9mMfb+bJIEAHp90D7spl0akwpqoALUJLys q1O4Zp98rqG5hnok3aymUsCebRFa64pgp1nWGrj2EYgoIupVskvLN8sfqBSf5sN3D8p+Qq Ew4v6tPEgNjRNvTeatn9ND86oE0dHjaXCY3u2ZZq4fzRnOH5qOM+6j7RbRiGcRgEG1/6bB qTnVkJo+TOGW71KXWJEbGn4JZly1z4N+J32wrrfo5SDn7gtjPJL34lRE0Mcf3w== 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 4bRwsT4sJzz1Q7D; Wed, 25 Jun 2025 09:06:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55P965xV040009; Wed, 25 Jun 2025 09:06:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55P965as040006; Wed, 25 Jun 2025 09:06:05 GMT (envelope-from git) Date: Wed, 25 Jun 2025 09:06:05 GMT Message-Id: <202506250906.55P965as040006@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: fad4064226b2 - stable/14 - x86/xen: fix accounted interrupt time List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: fad4064226b2aa3de6a6c83adb7e0e0108e69bd3 Auto-Submitted: auto-generated The branch stable/14 has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=fad4064226b2aa3de6a6c83adb7e0e0108e69bd3 commit fad4064226b2aa3de6a6c83adb7e0e0108e69bd3 Author: Roger Pau Monné AuthorDate: 2024-03-05 13:15:03 +0000 Commit: Roger Pau Monné CommitDate: 2025-06-25 08:31:14 +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 (cherry picked from commit f750dce972efaea614aa6d03ecdb24aa962a38a4) --- 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 db166a625610..62b921d06aea 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,