From nobody Thu May 2 07:06:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1582719647; cv=none; d=zohomail.com; s=zohoarc; b=UvtyeHSLg4et8rcdyJElDpVKq2PfGoSi5vr4MAik4NgtABpB9Bdtukc/2do7DaiKTOlnsb7VEBYZMksuc7BiEa/PHTMfy9yv04ZkEmkI6ggYirU5MAMB5GQ44u/7AjGZQj/dsY0+a4tlb6GGdOGgEEQQLPcxIepPSndr4QXK1JY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582719647; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gztqCU3Z9XV5ZNlBYqDw03bPqjQQavRejE1BNHRPyDc=; b=Oqal+fyCJAz361sXYoFgwKu140B72DIWi2QKNh/BgSVHSajOD8PqPCF732jWYz0Rdx2UxlC81z9REBAdkRSeNtYQN71aD07u24tm5PZE5j2hBs4VWD/yHdIWadeMY0SQuzctCyrsHgaDTAEwfk8IEFssRN73T+ZG1r8rx5cQ40I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582719647627508.0037520665703; Wed, 26 Feb 2020 04:20:47 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfX-0007iB-S2; Wed, 26 Feb 2020 12:20:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfW-0007a7-Ni for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 12:20:02 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4f96bcb8-5892-11ea-9405-12813bfff9fa; Wed, 26 Feb 2020 12:20:01 +0000 (UTC) X-Inumbo-ID: 4f96bcb8-5892-11ea-9405-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582719601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wv/vxk0u0VbbLGUWa/SXKuvSSwAq6bOO4pDv/657Jok=; b=epxwsUlcsvlpxhAMce7eMT8mbwgp1uXmT9epXA80PvDe1gYbBEsue391 +Jr87OXVxuzzjvxLHNAyv7Yzi3uftkYkn7aZovedxqDVNOKvwZoOvtfJZ ynv5rRnB+56mETDyov3ShrYWliniHzm0XDHcRdlGXuF8Ek590oKZ2ocjb o=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Hdx9BAEX+6189xWIiTtwXHjOb7dSV/S3JvLXHOB0OxW/VZNSGQgv1pTbS/PXLBr0a08Al7pKlS lsgkZpfYxCWtVjkoEaFzeOg++vOOOmrdHR6OGpl+iD2LSiIEq2pKTKlefcfame1K0xIK0RelDD S6DKtXh8aOxm6vtoQLT4IiRY2m4NvHoC6e62HOjN9/gT51zaq5DaSAl5kZ50ty2CcK5yX9QWA0 oNaz1M9gXWCX7Pifmxubd0CtRkHiVubedO2exmFropfY+lUdXr4K96cRwsR49+EYxngvhZTyPd 9zU= X-SBRS: 2.7 X-MesageID: 13386968 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,488,1574139600"; d="scan'208";a="13386968" From: Roger Pau Monne To: Date: Wed, 26 Feb 2020 13:19:18 +0100 Message-ID: <20200226121921.28627-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200226121921.28627-1-roger.pau@citrix.com> References: <20200226121921.28627-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 1/4] x86: introduce a nmi_count tracking variable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is modeled after the irq_count variable, and is used to account for all the NMIs handled by the system. This will allow to repurpose the nmi_count() helper so it can be used in a similar manner as local_irq_count(): account for the NMIs currently in service. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Remove nmi_count macro and __nmi_count field in irq_cpustat_t. --- xen/arch/x86/nmi.c | 11 +++++------ xen/arch/x86/traps.c | 4 +++- xen/include/asm-x86/hardirq.h | 1 - xen/include/asm-x86/nmi.h | 2 ++ xen/include/xen/irq_cpustat.h | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/nmi.c b/xen/arch/x86/nmi.c index a69b91a924..c3f92ed231 100644 --- a/xen/arch/x86/nmi.c +++ b/xen/arch/x86/nmi.c @@ -151,15 +151,14 @@ int nmi_active; =20 static void __init wait_for_nmis(void *p) { - unsigned int cpu =3D smp_processor_id(); - unsigned int start_count =3D nmi_count(cpu); + unsigned int start_count =3D this_cpu(nmi_count); unsigned long ticks =3D 10 * 1000 * cpu_khz / nmi_hz; unsigned long s, e; =20 s =3D rdtsc(); do { cpu_relax(); - if ( nmi_count(cpu) >=3D start_count + 2 ) + if ( this_cpu(nmi_count) >=3D start_count + 2 ) break; e =3D rdtsc(); } while( e - s < ticks ); @@ -177,7 +176,7 @@ void __init check_nmi_watchdog(void) printk("Testing NMI watchdog on all CPUs:"); =20 for_each_online_cpu ( cpu ) - prev_nmi_count[cpu] =3D nmi_count(cpu); + prev_nmi_count[cpu] =3D per_cpu(nmi_count, cpu); =20 /* * Wait at most 10 ticks for 2 watchdog NMIs on each CPU. @@ -188,7 +187,7 @@ void __init check_nmi_watchdog(void) =20 for_each_online_cpu ( cpu ) { - if ( nmi_count(cpu) - prev_nmi_count[cpu] < 2 ) + if ( per_cpu(nmi_count, cpu) - prev_nmi_count[cpu] < 2 ) { printk(" %d", cpu); ok =3D false; @@ -593,7 +592,7 @@ static void do_nmi_stats(unsigned char key) =20 printk("CPU\tNMI\n"); for_each_online_cpu ( cpu ) - printk("%3u\t%3u\n", cpu, nmi_count(cpu)); + printk("%3u\t%3u\n", cpu, per_cpu(nmi_count, cpu)); =20 if ( !hardware_domain || !(v =3D domain_vcpu(hardware_domain, 0)) ) return; diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 56067f85d1..3dbc66bb64 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1683,13 +1683,15 @@ static int dummy_nmi_callback(const struct cpu_user= _regs *regs, int cpu) =20 static nmi_callback_t *nmi_callback =3D dummy_nmi_callback; =20 +DEFINE_PER_CPU(unsigned int, nmi_count); + void do_nmi(const struct cpu_user_regs *regs) { unsigned int cpu =3D smp_processor_id(); unsigned char reason =3D 0; bool handle_unknown =3D false; =20 - ++nmi_count(cpu); + this_cpu(nmi_count)++; =20 if ( nmi_callback(regs, cpu) ) return; diff --git a/xen/include/asm-x86/hardirq.h b/xen/include/asm-x86/hardirq.h index 34e1b49260..802f91cfdf 100644 --- a/xen/include/asm-x86/hardirq.h +++ b/xen/include/asm-x86/hardirq.h @@ -7,7 +7,6 @@ typedef struct { unsigned int __softirq_pending; unsigned int __local_irq_count; - unsigned int __nmi_count; bool_t __mwait_wakeup; } __cacheline_aligned irq_cpustat_t; =20 diff --git a/xen/include/asm-x86/nmi.h b/xen/include/asm-x86/nmi.h index f9dfca6afb..a288f02a50 100644 --- a/xen/include/asm-x86/nmi.h +++ b/xen/include/asm-x86/nmi.h @@ -31,5 +31,7 @@ nmi_callback_t *set_nmi_callback(nmi_callback_t *callback= ); * Remove the handler previously set. */ void unset_nmi_callback(void); + +DECLARE_PER_CPU(unsigned int, nmi_count); =20 #endif /* ASM_NMI_H */ diff --git a/xen/include/xen/irq_cpustat.h b/xen/include/xen/irq_cpustat.h index 73629f6ec8..b9629f25c2 100644 --- a/xen/include/xen/irq_cpustat.h +++ b/xen/include/xen/irq_cpustat.h @@ -24,7 +24,6 @@ extern irq_cpustat_t irq_stat[]; /* arch independent irq_stat fields */ #define softirq_pending(cpu) __IRQ_STAT((cpu), __softirq_pending) #define local_irq_count(cpu) __IRQ_STAT((cpu), __local_irq_count) -#define nmi_count(cpu) __IRQ_STAT((cpu), __nmi_count) #define mwait_wakeup(cpu) __IRQ_STAT((cpu), __mwait_wakeup) =20 #endif /* __irq_cpustat_h */ --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 07:06:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1582719646; cv=none; d=zohomail.com; s=zohoarc; b=BZ//sBT0R5hfRAIwdu5gZgKmtP+s3E+6ThxM7qWhz1Auy5LQWEXnLxxri1PaqbnsHQhQRKzDcpNoC5XrjTJUH0mPZe8sOgGi2F/bbfshbdnY9heARPXVAjIsTl5GL4lcN80Hzu3vrk/9CGQMx4QkJ4g+xxV2z8NGQCsQCIAYHjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582719646; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WGpGYaNHpuUpKqVmsCENyQDHw8MNI4aByT1z/kQcVgU=; b=WkTi1cer/pcYbtUCtMdHtwLUHDNUAkQlZX/mGKNPUPLnRtRczyUXGTB6UXZXk2J2mZ4ZP5mAhfS8SDNO2XCjJcsL0F+gEm0aHcJthGH4UOYDLLXx88q9pM9P8V8EKCIi8H1QAC+m1FwihLg8hihQQuPuWqd44d4SAZCC1N3otP0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582719646638243.78881697651798; Wed, 26 Feb 2020 04:20:46 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfc-0007zp-5u; Wed, 26 Feb 2020 12:20:08 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfb-0007vz-Nl for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 12:20:07 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 50924a6a-5892-11ea-9405-12813bfff9fa; Wed, 26 Feb 2020 12:20:03 +0000 (UTC) X-Inumbo-ID: 50924a6a-5892-11ea-9405-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582719603; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kt3IzNk6zIe/5QGWPbC+79ZzpGyafp44OJArdpw2w1I=; b=cOCInGHBQxWtA/UyIVvqBba6ikCw56bCrevXwwd0nzVudJczsRmxwYdW lQB6XZBaGJ68IH2vIEvuNXcooRIoTyyoS1Ybw08Xh+3NOgJcSlZrdz/da n2Bu68yFGf+mP/dNZGi1cE8GCm9uRVh9O5qonEsUQ3seE0SLwaHFLGueS 4=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: NNiSMpKxrbedS/BuW1+JplYU33nj875M1hKE1pOn5OPOIjfYd7Yuys/3zL/ilUJGrRVZqT8dkU gf7CpWlvHnCje8JcG8IXmdFft6PH1kcHu6PbkjAs0xDiRVMmgQaAmpvscszbOKmh9dB6dVJzjS 2fEiU0s4ggGqqIP5+pY2OPrppV4Uh0Y/GNR+1bY5LPRFeeYo94bK19HACmeXvr8DoCLs5FfvGo D0QfCcKUR3gcR40UQ7kviN5zUaT1fVHxqM30nLdepIJfEOpPHaCuJ36Ab85Dxs5vMdNt82/rUi OhM= X-SBRS: 2.7 X-MesageID: 13014350 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,488,1574139600"; d="scan'208";a="13014350" From: Roger Pau Monne To: Date: Wed, 26 Feb 2020 13:19:19 +0100 Message-ID: <20200226121921.28627-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200226121921.28627-1-roger.pau@citrix.com> References: <20200226121921.28627-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 2/4] x86: track when in NMI context X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add helpers to track when running in NMI handler context. This is modeled after the in_irq helpers. The SDM states that no NMI can be delivered while handling a NMI until the processor has executed an iret instruction. It's possible however that another fault is received while handling the NMI (a #MC for example), and thus the iret from that fault would allow further NMIs to be injected while still processing the previous one, and hence an integer is needed in order to keep track of in service NMIs. The added macros only track when the execution context is in the NMI handler, but that doesn't mean NMIs are blocked for the reasons listed above. Note that there are no users of in_nmi_handler() introduced by the change, further users will be added by followup changes. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Rename to in_nmi_context. - Drop parentheses around cpu in nmi_count. Changes since v2: - Use an integer instead of a boolean to keep track of in service #NMIs. - Move nmi_count into x86 specific header. - Drop leading underscores from __nmi_count field. --- xen/arch/x86/traps.c | 6 ++++++ xen/include/asm-x86/hardirq.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 3dbc66bb64..f4f2c13ae9 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1692,9 +1692,13 @@ void do_nmi(const struct cpu_user_regs *regs) bool handle_unknown =3D false; =20 this_cpu(nmi_count)++; + nmi_enter(); =20 if ( nmi_callback(regs, cpu) ) + { + nmi_exit(); return; + } =20 /* * Accessing port 0x61 may trap to SMM which has been actually @@ -1720,6 +1724,8 @@ void do_nmi(const struct cpu_user_regs *regs) if ( !(reason & 0xc0) && handle_unknown ) unknown_nmi_error(regs, reason); } + + nmi_exit(); } =20 nmi_callback_t *set_nmi_callback(nmi_callback_t *callback) diff --git a/xen/include/asm-x86/hardirq.h b/xen/include/asm-x86/hardirq.h index 802f91cfdf..069e48fce9 100644 --- a/xen/include/asm-x86/hardirq.h +++ b/xen/include/asm-x86/hardirq.h @@ -7,6 +7,7 @@ typedef struct { unsigned int __softirq_pending; unsigned int __local_irq_count; + unsigned int nmi_count; bool_t __mwait_wakeup; } __cacheline_aligned irq_cpustat_t; =20 @@ -17,6 +18,11 @@ typedef struct { #define irq_enter() (local_irq_count(smp_processor_id())++) #define irq_exit() (local_irq_count(smp_processor_id())--) =20 +#define nmi_count(cpu) __IRQ_STAT(cpu, nmi_count) +#define in_nmi_handler() (nmi_count(smp_processor_id()) !=3D 0) +#define nmi_enter() (nmi_count(smp_processor_id())++) +#define nmi_exit() (nmi_count(smp_processor_id())--) + void ack_bad_irq(unsigned int irq); =20 extern void apic_intr_init(void); --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 07:06:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1582719643; cv=none; d=zohomail.com; s=zohoarc; b=D4j9GFILzAmEpw2Rz162Jubr9dsMZixBvtw1ElTcxjmoMW22J0+c/cz8zFQx/TkKvs8+QsaCGADotRhsN6Dq5Qhrx2leCNzhWAZMKey1rC4d2N1rNRsT6jxuP88fRPFYsn5sZ41Q83f2ZOH2xZ9e/WaG61wSXMlGQCpiFF7HnHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582719643; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uIxN7jxkdfbfBnnsYoti1WMD/n8a4AA3X2YctE8IGTk=; b=gaDBjGji7fGcc3zSblhXQCBXrvsE+xtiawIHXg2uLPrM/D0ZdcS9WOO3Xpgl9GGR7JqInIoEEUT3TlmdTMcplFhGSU0rkpmuF2E0iRnOQFkqYbPKINHvykftfffWrvykanFP5Ca0mqIh8ltj++dUJqwuSE+t03qznptovOZyodI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582719643695445.04153694759657; Wed, 26 Feb 2020 04:20:43 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfh-0008B3-G5; Wed, 26 Feb 2020 12:20:13 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfg-0008Am-Ns for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 12:20:12 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 523d8c30-5892-11ea-9405-12813bfff9fa; Wed, 26 Feb 2020 12:20:05 +0000 (UTC) X-Inumbo-ID: 523d8c30-5892-11ea-9405-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582719605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IKEtPSnXfA44eXD2NPBehJJ5n/yi/a97G9Ak/ipF+d8=; b=fH0b4UI41m35Y828aByabHr9htiYwK9bxhzYS7XEpWgN02VunPk8InDS EgIVhthH0S8A+RGxx9oS9Etnc+eKvQJ7ZPm3Dza9WG/FNjdaAjDZfLt6K jSTja2GJvpW77Fo3uBZgh20ByFzEnpgQy1AqEypKO3ydvwYUEoRAUVsxO s=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: BL0oi4FL44WwaP1uFUmA1+5gOTXdI+MwOnvHcCIz1icbZUU1wH/TI8rOg6PSYFXmxfWcBixynF BXBRk5XYBsxGkqPJRoGuTlbKOVNnFhQ9TG0gVKugHkvGflVeLjwID6HAs+wD2m3IbWWLzc/OZt 4d9qxqQ+Xs1LHOxSG9Q6Cr6noEKBFcUADm7QPjykQuZINN/PvUNNlR1fIITXFi2hegtsLmbT0m WSMNizE3cBdfGZKr5Pi5Aq5vAgDjXkSKeG1MMJcgJUhHRj/z1zqEpLz36ALTaOZD/wXItpHMkP yw0= X-SBRS: 2.7 X-MesageID: 13386971 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,488,1574139600"; d="scan'208";a="13386971" From: Roger Pau Monne To: Date: Wed, 26 Feb 2020 13:19:20 +0100 Message-ID: <20200226121921.28627-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200226121921.28627-1-roger.pau@citrix.com> References: <20200226121921.28627-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 3/4] x86: track when in #MC context X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add helpers to track when executing in #MC handler context. This is modeled after the in_irq helpers. Note that there are no users of in_mce_handler() introduced by the change, further users will be added by followup changes. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Rename to in_mce_handler. - Drop parentheses around cpu in macro. Changes since v2: - Move definition of mc_count to x86 hardirq.h. --- xen/arch/x86/cpu/mcheck/mce.c | 2 ++ xen/include/asm-x86/hardirq.h | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c index d61e582af3..e5bd4f542c 100644 --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -93,7 +93,9 @@ void x86_mce_vector_register(x86_mce_vector_t hdlr) =20 void do_machine_check(const struct cpu_user_regs *regs) { + mce_enter(); _machine_check_vector(regs); + mce_exit(); } =20 /* diff --git a/xen/include/asm-x86/hardirq.h b/xen/include/asm-x86/hardirq.h index 069e48fce9..276e3419d7 100644 --- a/xen/include/asm-x86/hardirq.h +++ b/xen/include/asm-x86/hardirq.h @@ -8,6 +8,7 @@ typedef struct { unsigned int __softirq_pending; unsigned int __local_irq_count; unsigned int nmi_count; + unsigned int mce_count; bool_t __mwait_wakeup; } __cacheline_aligned irq_cpustat_t; =20 @@ -23,6 +24,11 @@ typedef struct { #define nmi_enter() (nmi_count(smp_processor_id())++) #define nmi_exit() (nmi_count(smp_processor_id())--) =20 +#define mce_count(cpu) __IRQ_STAT(cpu, mce_count) +#define in_mce_handler() (mce_count(smp_processor_id()) !=3D 0) +#define mce_enter() (mce_count(smp_processor_id())++) +#define mce_exit() (mce_count(smp_processor_id())--) + void ack_bad_irq(unsigned int irq); =20 extern void apic_intr_init(void); --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 07:06:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1582719658; cv=none; d=zohomail.com; s=zohoarc; b=mVgp9KnOK9mcYPKl+6zv7n03uND4Bskq4fQzbBUocrNNwFVF2NRou/On0wTJRfQR5/qyG97MVk7IY4q70jVxI3lPaKDZ92X9BOxXWBcoFoewNkICtPo0l7RsczktXuCbDkxOHBeoHkj5u3V/WpGhXb4S4gEhiJ/8l/57DeQjKAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582719658; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wGNIrgQPDZvWtbJj6V6ti6zGYdDNwZITEQhLdmu+FyY=; b=O9kAQ0HYNxF9i1tLs5cWj0ahm9q2DrAMWFqd/CwrbumD7M5rVGckyETk4CVAqO2Of7zK40MWD/QbSbay1YsZxCMO9/jBW3IRHYkJEy2gBfHpM6v4ThFuPW1Ia27/3B/F7D+bR4FifZZoaz3zgKwbMALMhXp6UPmDDelmlYObB20= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582719658183923.8956243306595; Wed, 26 Feb 2020 04:20:58 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfj-0008C8-Q8; Wed, 26 Feb 2020 12:20:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vfi-0008Be-Ft for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 12:20:14 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 56eda4ea-5892-11ea-8cb6-bc764e2007e4; Wed, 26 Feb 2020 12:20:14 +0000 (UTC) X-Inumbo-ID: 56eda4ea-5892-11ea-8cb6-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582719614; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QLqmgx5Dkvpg14/6NDnlCJdFLL9NI3RbIxt80YtkH4I=; b=Z9Ijaim4l29uKt5mVxSX/2b6ZA+RRgNQHnzPPXA9WWI5zqFME++UWrJR lkTG17SQUa/NuM98REEgJu97wqEbc7t8m5RgxjgTrUdxoE9DggOV4YeYk T7CuZNwa53H9k1NJxdbEk1PxSo7py4vn4OFYQ3APTSciI8icP1j4yCXCD o=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 7FvUuyh9OnB47C8WqBEivpz7Zd9bsnWTM+La+rItXbcLbixPYrP/U5rkJHjTa5OZJBXPTZX+fs tPv9qLdBl8N2ULd5+R1sj1nlgFQ9ybSzI/eif+lZQ0qzpTBhwo19zi/DsuDqmBLbZf9aDWFhWi 5BjHckAQUjtH5FCbcvUeZF7fmpVJU9SIsRwDr03/YXsXN1vmuoFHK5ip66yxBimMuWETdditkk nYNTQseSRQV0Sx0SILMTbYKef9ysokbO7L3AlG+sFuC6QZ1/UiJnZOtLf7prBzuryUZzzGovZW Fxw= X-SBRS: 2.7 X-MesageID: 13014362 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,488,1574139600"; d="scan'208";a="13014362" From: Roger Pau Monne To: Date: Wed, 26 Feb 2020 13:19:21 +0100 Message-ID: <20200226121921.28627-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200226121921.28627-1-roger.pau@citrix.com> References: <20200226121921.28627-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 4/4] x86/smp: do not use scratch_cpumask when in interrupt or exception context X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Sander Eikelenboom , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Using scratch_cpumask in send_IPI_mask is not safe in IRQ or exception context because it can nest, and hence send_IPI_mask could be overwriting another user scratch cpumask data when used in such contexts. Instead introduce a new cpumask to be used by send_IPI_mask, and disable interrupts while using it. Fallback to not using the scratch cpumask (and hence not attemping to optimize IPI sending by using a shorthand) when in IRQ or exception context. Note that the scratch cpumask cannot be used when non-maskable interrupts are being serviced (NMI or #MC) and hence fallback to not using the shorthand in that case, like it was done previously. Fixes: 5500d265a2a8 ('x86/smp: use APIC ALLBUT destination shorthand when p= ossible') Reported-by: Sander Eikelenboom Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - Do not use a dedicated cpumask, and instead prevent usage when in IRQ context. Changes since v2: - Fallback to the previous IPI sending mechanism in #MC or #NMI context. Changes since v1: - Don't use the shorthand when in #MC or #NMI context. --- xen/arch/x86/smp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index 55d08c9d52..fa9bfe4d54 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -69,6 +69,18 @@ void send_IPI_mask(const cpumask_t *mask, int vector) bool cpus_locked =3D false; cpumask_t *scratch =3D this_cpu(scratch_cpumask); =20 + if ( in_irq() ||=C2=A0in_mce() || in_nmi() ) + { + /* + * When in IRQ, NMI or #MC context fallback to the old (and simple= r) + * IPI sending routine, and avoid doing any performance optimizati= ons + * (like using a shorthand) in order to avoid using the scratch + * cpumask which cannot be used in interrupt context. + */ + alternative_vcall(genapic.send_IPI_mask, mask, vector); + return; + } + /* * This can only be safely used when no CPU hotplug or unplug operatio= ns * are taking place, there are no offline CPUs (unless those have been --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel