From nobody Fri Apr 19 23:21:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1602077443; cv=none; d=zohomail.com; s=zohoarc; b=Un5RD6KwioEq7WTXzckBDpct3LOLJko9QcplxBFv9cIf+DQ9nh+O/x8FiuqBT3DWpbAr1yY43oxTSdp5RdTSRRGOIChtzOKEdQ1WPr4Lt4DdWlEgSx7zKZ2pAuzRBAzwmup/5IT+KkiL0DIcVJ5kPC+ad8VdGRXTOlUIYadwkes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602077443; h=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=3mWN7Jm1cNuFETK+fgXLvgGY+7f39A/ML24lxKYie30=; b=HAfRiZzNEuZzY2TBtkf3nUM1DYLBpjUBiehEiFPaOHnWmGoegIdBUrLiMW9Aij6PcnVzjs2FEIW3sWDYOGrmILriWV/+7pFJ46AH1sMCKei5pmLBuJOwp2NKU0xVzFyFTrFkpySH/Qatg7Z3B6FWT6VuozcZHWExA1tuKl4dfJA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass 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 1602077443715896.1185974625668; Wed, 7 Oct 2020 06:30:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.3510.10079 (Exim 4.92) (envelope-from ) id 1kQ9WV-0007vY-Aq; Wed, 07 Oct 2020 13:30:27 +0000 Received: by outflank-mailman (output) from mailman id 3510.10079; Wed, 07 Oct 2020 13:30:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9WV-0007vR-6s; Wed, 07 Oct 2020 13:30:27 +0000 Received: by outflank-mailman (input) for mailman id 3510; Wed, 07 Oct 2020 13:30:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9WT-0007q4-Ss for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:30:25 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 803b2796-2b01-4962-970d-9d3c4ba9ea5f; Wed, 07 Oct 2020 13:30:15 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 541FEAF27; Wed, 7 Oct 2020 13:30:14 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9WT-0007q4-Ss for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:30:25 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 803b2796-2b01-4962-970d-9d3c4ba9ea5f; Wed, 07 Oct 2020 13:30:15 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 541FEAF27; Wed, 7 Oct 2020 13:30:14 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 803b2796-2b01-4962-970d-9d3c4ba9ea5f X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602077414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3mWN7Jm1cNuFETK+fgXLvgGY+7f39A/ML24lxKYie30=; b=sgXW1lw2xTYycx2+CiKHRUPRqfY7jshh3bK5pJhK8uBciUXE/wbknecRq6JpCtiXtDHJmX dh8zNvgrMFerWngwxWYFBITJzGkJhL8/k0ReHRoH6wL1RYXr9jwg8PHqQRYRYjaLM4UXCE 7Q+BVFm/77kfL4Dx1pRlk/mzM2T9YSw= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini Subject: [PATCH v2 1/2] xen/x86: add nmi continuation framework Date: Wed, 7 Oct 2020 15:30:10 +0200 Message-Id: <20201007133011.18871-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201007133011.18871-1-jgross@suse.com> References: <20201007133011.18871-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Actions in NMI context are rather limited as e.g. locking is rather fragile. Add a generic framework to continue processing in softirq context after leaving NMI processing. This is working for NMIs happening in guest context as NMI exit handling will issue an IPI to itself in case a softirq is pending, resulting in the continuation running before the guest gets control again. Signed-off-by: Juergen Gross --- xen/arch/x86/traps.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/nmi.h | 8 +++++++- xen/include/xen/softirq.h | 5 ++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index bc5b8f8ea3..f433fe5acb 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1799,6 +1799,42 @@ void unset_nmi_callback(void) nmi_callback =3D dummy_nmi_callback; } =20 +static DEFINE_PER_CPU(void (*)(void *), nmi_cont_func); +static DEFINE_PER_CPU(void *, nmi_cont_par); + +static void nmi_cont_softirq(void) +{ + unsigned int cpu =3D smp_processor_id(); + void (*func)(void *par) =3D per_cpu(nmi_cont_func, cpu); + void *par =3D per_cpu(nmi_cont_par, cpu); + + /* Reads must be done before following write (local cpu ordering only)= . */ + barrier(); + + per_cpu(nmi_cont_func, cpu) =3D NULL; + + if ( func ) + func(par); +} + +int set_nmi_continuation(void (*func)(void *par), void *par) +{ + unsigned int cpu =3D smp_processor_id(); + + if ( per_cpu(nmi_cont_func, cpu) ) + { + printk("Trying to set NMI continuation while still one active!\n"); + return -EBUSY; + } + + per_cpu(nmi_cont_func, cpu) =3D func; + per_cpu(nmi_cont_par, cpu) =3D par; + + raise_softirq(NMI_CONT_SOFTIRQ); + + return 0; +} + void do_device_not_available(struct cpu_user_regs *regs) { #ifdef CONFIG_PV @@ -2132,6 +2168,7 @@ void __init trap_init(void) =20 cpu_init(); =20 + open_softirq(NMI_CONT_SOFTIRQ, nmi_cont_softirq); open_softirq(PCI_SERR_SOFTIRQ, pci_serr_softirq); } =20 diff --git a/xen/include/asm-x86/nmi.h b/xen/include/asm-x86/nmi.h index a288f02a50..da40fb6599 100644 --- a/xen/include/asm-x86/nmi.h +++ b/xen/include/asm-x86/nmi.h @@ -33,5 +33,11 @@ nmi_callback_t *set_nmi_callback(nmi_callback_t *callbac= k); void unset_nmi_callback(void); =20 DECLARE_PER_CPU(unsigned int, nmi_count); -=20 + +/** + * set_nmi_continuation + * + * Schedule a function to be started in softirq context after NMI handling. + */ +int set_nmi_continuation(void (*func)(void *par), void *par); #endif /* ASM_NMI_H */ diff --git a/xen/include/xen/softirq.h b/xen/include/xen/softirq.h index 1f6c4783da..14c744bbf7 100644 --- a/xen/include/xen/softirq.h +++ b/xen/include/xen/softirq.h @@ -3,7 +3,10 @@ =20 /* Low-latency softirqs come first in the following list. */ enum { - TIMER_SOFTIRQ =3D 0, +#ifdef CONFIG_X86 + NMI_CONT_SOFTIRQ, +#endif + TIMER_SOFTIRQ, RCU_SOFTIRQ, SCHED_SLAVE_SOFTIRQ, SCHEDULE_SOFTIRQ, --=20 2.26.2 From nobody Fri Apr 19 23:21:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1602077440; cv=none; d=zohomail.com; s=zohoarc; b=EqhsqKZQWifopIajvofUc4L1Yqkdal9MRUFhBbBHzTPIiHGuEulTx8+zDJzOm10id+jKrukUpK4Gj6zQ7w0uJix5KyyTc/+iuncGV8iw+kkEiN5zSjapXHZ2uGD8MKFHAXGgX1cT2ofiJNn3Qbse0p51dADfUHM0Mbdc2kmQ4so= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602077440; h=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=A/ul8OKsqutALOib25CsZA6bXQqNHW0GneGeZqHG7q8=; b=ixGsjmtJl6JD9oCTX6vNDELyKLYimLInrjyMXdzdSefs2MtdyIbePvOpdOtDt27e9mlsSerV1/soxhf0urhnERAW84WpK6oxdbzwiJaKSy4RFGDX1NLWFQsxmoGSH8rKqEEVRBwsDaiZ6uW2CUn58F4u+V2mhuEdoircY66TGzI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass 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 1602077440063964.8513159239557; Wed, 7 Oct 2020 06:30:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.3508.10054 (Exim 4.92) (envelope-from ) id 1kQ9WL-0007qG-Kn; Wed, 07 Oct 2020 13:30:17 +0000 Received: by outflank-mailman (output) from mailman id 3508.10054; Wed, 07 Oct 2020 13:30:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9WL-0007q9-Hm; Wed, 07 Oct 2020 13:30:17 +0000 Received: by outflank-mailman (input) for mailman id 3508; Wed, 07 Oct 2020 13:30:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9WJ-0007q4-VW for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:30:15 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5771a15b-b98b-4cad-8cce-ad1e87e22a25; Wed, 07 Oct 2020 13:30:15 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 757FCB234; Wed, 7 Oct 2020 13:30:14 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9WJ-0007q4-VW for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:30:15 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5771a15b-b98b-4cad-8cce-ad1e87e22a25; Wed, 07 Oct 2020 13:30:15 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 757FCB234; Wed, 7 Oct 2020 13:30:14 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5771a15b-b98b-4cad-8cce-ad1e87e22a25 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602077414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A/ul8OKsqutALOib25CsZA6bXQqNHW0GneGeZqHG7q8=; b=TEdU2k071jf8kt1UTSAibopkjVoC1AFCBimdUlaguWnZ/OSyCXE/vMqE3ye6u+nlZBzIr3 EJvc4PEbA7d4Sqakuk2YxQXNpdFyYtT3LrlEiIufiegDeKc0eap+JumxzHIcNhnCajiZt9 eDofBqBFBltEK+umlJCJWiuwPpjk3v4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 2/2] xen/oprofile: use set_nmi_continuation() for sending virq to guest Date: Wed, 7 Oct 2020 15:30:11 +0200 Message-Id: <20201007133011.18871-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201007133011.18871-1-jgross@suse.com> References: <20201007133011.18871-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Instead of calling send_guest_vcpu_virq() from NMI context use the NMI continuation framework for that purpose. Signed-off-by: Juergen Gross --- xen/arch/x86/oprofile/nmi_int.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/oprofile/nmi_int.c b/xen/arch/x86/oprofile/nmi_in= t.c index 0f103d80a6..659e31fe19 100644 --- a/xen/arch/x86/oprofile/nmi_int.c +++ b/xen/arch/x86/oprofile/nmi_int.c @@ -83,6 +83,13 @@ void passive_domain_destroy(struct vcpu *v) model->free_msr(v); } =20 +static void nmi_oprofile_send_virq(void *par) +{ + struct vcpu *v =3D par; + + send_guest_vcpu_virq(v, VIRQ_XENOPROF); +} + static int nmi_callback(const struct cpu_user_regs *regs, int cpu) { int xen_mode, ovf; @@ -90,7 +97,7 @@ static int nmi_callback(const struct cpu_user_regs *regs,= int cpu) ovf =3D model->check_ctrs(cpu, &cpu_msrs[cpu], regs); xen_mode =3D ring_0(regs); if ( ovf && is_active(current->domain) && !xen_mode ) - send_guest_vcpu_virq(current, VIRQ_XENOPROF); + set_nmi_continuation(nmi_oprofile_send_virq, current); =20 if ( ovf =3D=3D 2 ) current->arch.nmi_pending =3D true; --=20 2.26.2