From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095653; cv=pass; d=zohomail.com; s=zohoarc; b=ZcOo0B9VEa1Nce2dbVBxgwJlL6knV3m/fjzQvOrAwLU2baPdqYrDYcz6eKAPA3zg7N0gjGV5mqRjJ3i15iSMpvrx5pChqHYrgnDjTC1kzF7JKqKFg+cA/ne8t7OscB3lKFb0X2bN7BDUHJBh880e7Obam1wwbDybC5Zw2o4y1aI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095653; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=j/x0rT1oB7OVwr8zqPawvId6h6lac1Z+SScMfAw/LeE=; b=V5lPoP/F3dU5DwYYrmTJGH9KcEfvkNb8eFL6xaqmuR2OTRPK21Zrvu4TzxY5AIepTQwwFMWWC2Nmu0FrPm66+Ttm2X8Vzv+on+F7Jnd17ZZRCpzUM1dEetJCgXQBJ/v4TK10+fJxG+Ztv7DuUN4pf3N07BwrMRsO9y8gYbUSfG0= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095653684351.3265648532489; Wed, 10 Jun 2026 05:47:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334255.1597343 (Exim 4.92) (envelope-from ) id 1wXIKm-0001Le-Lm; Wed, 10 Jun 2026 12:47:04 +0000 Received: by outflank-mailman (output) from mailman id 1334255.1597343; Wed, 10 Jun 2026 12:47:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKm-0001L2-HC; Wed, 10 Jun 2026 12:47:04 +0000 Received: by outflank-mailman (input) for mailman id 1334255; Wed, 10 Jun 2026 12:45:15 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJ0-00018L-Rp for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:14 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJ0-007rhd-1Y for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:14 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c4f-2eae-0a2a0a5409dd-0a2a4508b56c-36 for ; Wed, 10 Jun 2026 14:45:13 +0200 Received: from [52.101.66.72] (helo=DUZPR83CU001.outbound.protection.outlook.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c59-63b5-0a2a45080019-3465424806ab-3 for ; Wed, 10 Jun 2026 14:45:13 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by DB9PR03MB7706.eurprd03.prod.outlook.com (2603:10a6:10:2c8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:11 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:11 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CAzuTfeSUc4P/MiEmlPkECyD1hNXFpooh5GYiiQnkDUtJbhTbZBLTsW6J7EOyxqSChJkuzt9DUDOWs322E+LcjKM/PE7nnc0bPTsBgtvE5M2EA1Lz/4zjFt+ZREnQ5QghnzUgwjTGNEUQyxOgN4Jlur38oXcyXkVQKXv61AiVUkSccRmrectw7nZg2TeDFRQnmR93joU06N3SVAtl4M5o35JPfhlj9jtrVVWAMvPkv753h8f8tFuQ9Ynidhic76Tzah6vOWGBxGfmPhmYoT7aG539pQOf0J2gIp9wjlg7rDjQtj1ViOcJKbNRv5Dkhh/8PUGdwdvQ5CHutp1mwgM6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=j/x0rT1oB7OVwr8zqPawvId6h6lac1Z+SScMfAw/LeE=; b=LRud86CaDjRzQQhiS9xFRq+bPjAkkx3mNjskn5gpyHKZVG0rz7upjlayGOG6EAmFOV4SSBlwMe/IuBKh+oYdWonmLpG1mraUCUPv9nkbrGLv02LBybHnGLIMhGDkxvBM+Wocv8+SL79XonnC28/a282nsYZmQWAsn6KSw333cZjSlUkiFghiHkx3KqoWy4d9UMm+yO7CdM1tOzJGuf/qernsCAtw3EcZdRdHiF4T87poHk5Eyr2RK0tT5cloqDDKJ7R5TYuVpMHqxaJOa6e9U+zBMbvvVGag/MEhSg0ms79LKzTdzEUkinFArDEAlKSGE38SewzfbE+amPNK/4xhtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j/x0rT1oB7OVwr8zqPawvId6h6lac1Z+SScMfAw/LeE=; b=JRqJ3b57fpOO8zntxFNyuZZNpqPONRlFbV+ycfMAZ++wvMNgwMqEbx6GENFKQ5AZ7N89g/hAxoVTxoEYMPjDjVfHa5BtcQ1KMFph8oCQtjAw5LWj0jGC/sEV5CAcWhzft6gEmzgBJ1JdREQflb5LQVvG/pT6i4M9i6KhEQRFBp+mgRA/daDheruitgEyD4pTlxT18zsLhozMolFHtrNUR8FhUzUQllu60GIXz5LAZ4F7aXLppnGcXBeXmzDMlE2XXUaB3i9C0DBB6GX91n/jQx60jM6FkwjmlyS9sEKpyuOmC6Jx7WSB4F1DAguScJdhr7seIvwpRmvWI0n12OSxUQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Julien Grall , Luca Fancellu Subject: [PATCH v11 01/13] xen/arm: Add suspend and resume timer helpers Date: Wed, 10 Jun 2026 15:44:21 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|DB9PR03MB7706:EE_ X-MS-Office365-Filtering-Correlation-Id: 77c52398-2fef-4888-487d-08dec6ee1c87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|1800799024|376014|366016|3023799007|56012099006|11063799006|18002099003|22082099003|6133799003; X-Microsoft-Antispam-Message-Info: Ol+8jfu3EV6t1S9G7B7hocjuuZ+LxeWyanHXnFUqrJhjfA0iHbVuZ9iO+03WxNnRZPNvx1BvCL23RJ4H4uTulK+/AE59Z1vdo/dy22cEYw62F79GWPHmJ1n/oVCRNpst2T9+ptlfxGszPeitnKMIbZYeHVJHu90I18KrD07R2k1nxDEFa/PENGTquoW+zzgsHZ8UnUEuAZofqTilJAV0tBa2joKJ+XocbqUkUdkPyXRZnDwN5TPbmn3mF5Gi3YXzkV0RUt6jyOxdkFJ3dtQg+L7d1W5RfXtU4tmCG3T6taoVRKau/r7OalixVkSm+F8XJRU274IKunhrRuGe2R+3c3BAfk7B6MhmQKiKEIWiW2orjhZbOV3gZxiDpMUAeJhq0GJJvdJX5qzWX98OeYWx2yDyUHk70gGLoQkAzpo+ytxzOPcb7aMTolROlq1f6f4ZkrQoaA4ERTLnOuG6JN5YgDVw0GYC+v8jfDGsoZpzeD0fQrOtffVw7Nl1phnBA0Fx5rI33FRtF2l0UiVPCWhT3JY/KhZubrNyurfOsLhvgud8HMD1L0F2QqxKfXd62u303a0zo79eZDwp1PbGaMOnzd0M4oFbcmwfiyHm/iG6yMe3QSD0seSrUmgAzygproHAi4/2X2S7w+qoxKa+Cr2NmdMqpvQODnPR1y6KJreLDepObB+hPSnU1dq+Z6MTavoz X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(1800799024)(376014)(366016)(3023799007)(56012099006)(11063799006)(18002099003)(22082099003)(6133799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?P+SVnulLqut7slHm0nXwtAdhWpljY9N+RSLhuyPRPPkZuBePuh2/Cjb3pHB1?= =?us-ascii?Q?xpI5H+MW7V/ZfolGbyPAPEaruiREe0spP/DKw1XHIp6txhtmhNtZCFd4JOL4?= =?us-ascii?Q?bAJ0OIeJEie/MCEHkV1UzKsWdQ/mAewaUiQkSms5evtzddCczSzNiBXH+12J?= =?us-ascii?Q?npQcO4YrgnXqNOMigcLUL6dBNqMIvGdARkSSXXbpHFLyQFEmxMnbfEoqHZnA?= =?us-ascii?Q?g50hSY/r5AnzKiJif1thMgYKAwjOIK8leEXppKq0am1B50xU4c1YpCHncokQ?= =?us-ascii?Q?6H6jRlGWro6s3g2bUCSyObhCw0IQ0Vq59FtVMjT/RIdm3a3phSi4u7b56sS+?= =?us-ascii?Q?dTsSbcNlAu3imFYj2B0cxr7t8kIbtJ9RQX0S+D4958kNgwSwq+6SyJdNQZ3T?= =?us-ascii?Q?m7A/FvOmrL2Z/QxntCyI2bRAogZYz00b+65DonNEjWVm9geUQu7/szCxl/Ji?= =?us-ascii?Q?x2+Rcled0WNWyH2AiLuaRrZ3IEoWaAhCV4P8DUo6y58vXZ2xNLHH8sQacgc0?= =?us-ascii?Q?RA23TPw5wYDU/EMHFOjKJP4C5ampaOOpk3oUxR3zKBSjElj3sTbVXuTeRRCr?= =?us-ascii?Q?sduaPX3ZmfcCuxajFv+GGQB4E/SKehZwgOXB6y+lTygyLA1KAJY2Q8JHtM0i?= =?us-ascii?Q?7d4aE6aE9hmiiRl/Zu6sU2nSGR7+NhEu5os5AX9x8mZSZeG7/6uowHmByxdx?= =?us-ascii?Q?u9lOIV3Hg/0z1GFOdbYnoxoYnTPQH1d8iKQA96mjL3SDE6DedLG0zrXyo8wl?= =?us-ascii?Q?IM/TEtOgdqUo4lUkBipJkNImv8M5a+wdcs1cIkRHpi7oA5gdHelzE2hLdUma?= =?us-ascii?Q?wdJfradrojLUo4IJarhSM3LW2R/k7WAb8Yb647SdPS7JnI0CZ5VAdmOOCuC0?= =?us-ascii?Q?LovHL+2nC7fQswe5CMC8feEPG5Ej6i5/Zebd1qlPysH7XZa5X71buA7fu0FB?= =?us-ascii?Q?fVUQwtAnl0oVkKbMWfeVt6uGJ3jfwtGPBebo0GNrubtwYCDOOPq0iBYwZk+j?= =?us-ascii?Q?3Gw4qooihYNyD3qfmY9oFFR29udfa2km/HT2Z9TekdLGhcpoATYxWtqMLK7A?= =?us-ascii?Q?4kyXOwwMRVGja3kNf/jnGbYv79QWy9hxz65B9wHRM9FgPoJUxg75/NHw/4FS?= =?us-ascii?Q?l/HiR4PXey6Bz3Ji6We1gdMVYlYl8iCtCYGtbLwToCgp/Vlie6+7Hvftenrf?= =?us-ascii?Q?neg2VZZFkNRBxr4a8VDm+1bBRWUh2tREz9m5fOHX1WQKsMFpUVEGS0mXJzGu?= =?us-ascii?Q?bxsfyED1SmV5wNGxtQozDdb1ZDHvfCaNez7fvRZII+b7CTwh//TnLO+507sL?= =?us-ascii?Q?8NoSf7O7e4TxW+ZBFbDUxmBQS2wfrgrnvSiERndaFaGvEdq8Tvbvpf5bWgm7?= =?us-ascii?Q?WjDFJSkD6OccLXXq6/o7Ky5gtERKs0yyG/FYcaiPmK4KfUkyWkhN2NEijJ2H?= =?us-ascii?Q?CiC+zoRV/lHhZbCYv2NhU/NPaDnpm17cto843O8HRSTUJAQyjjlOCZ0/Q+rS?= =?us-ascii?Q?aB0KsGpSOd32OS0fbEe9qzqglRrTY2mTAWwjySFEPyVrGLnAEWtf+TYa8Fu0?= =?us-ascii?Q?DCzrp5Z6kqIfSVurVPcM23bMC/Bfrpz/7JBfuS6lM8xytVCr9jJqW4uadj2h?= =?us-ascii?Q?fAcnwpOhn9042Xz/5/eO64RIMbZUA9lYg6gBWHPXlV7V2kUzP5jlEkEla8Q5?= =?us-ascii?Q?7VI3PyLODFOdrD14YqgyZXGaAz8wlNVkj8eMQLtCEL/LqRRa9HJRXhaokHLp?= =?us-ascii?Q?3LFbaaKnAw=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77c52398-2fef-4888-487d-08dec6ee1c87 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:11.7839 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DB721hZWBwKcinEDQskQE576MKSSHCTw/61XlPMljuAPqkBqPcT+e8BqRoZGDEDw01vZaVcoPvZLLyJljSDnXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB7706 X-purgate-ID: tlsNG-c1860d/1781095513-BCB64DB1-9DF22876/0/0 X-purgate-type: clean X-purgate-size: 5064 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095656603154100 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic Timer interrupts must be disabled while the system is suspended to prevent spurious wake-ups. Suspending timers in Xen consists of disabling the physical timer and the hypervisor timer on the current CPU. The virtual timer does not need explicit handling here, as it is already disabled on vCPU context switch and its state is restored per-vCPU on the next context restore. Resuming consists of raising TIMER_SOFTIRQ, which prompts the generic timer code to reprogram the hypervisor timer with the correct timeout. Xen does not use or expose the physical timer, so it remains disabled across suspend/resume. Introduce a new helper, disable_phys_hyp_timers(), to encapsulate disabling of the physical and hypervisor timers. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykola Kvach Acked-by: Julien Grall Reviewed-by: Luca Fancellu --- Changes in V7: - Dropped EL1/EL2 wording; use "physical timer" and "hypervisor timer" - Renamed helper to disable_phys_hyp_timers() to reflect its actual scope - Clarified virtual timer handling (disabled on vCPU switch-out, restored on context restore) and added comments in suspend/resume paths - Added resume comment explaining which timers are restored by TIMER_SOFTIRQ --- xen/arch/arm/include/asm/time.h | 5 ++++ xen/arch/arm/time.c | 44 ++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/include/asm/time.h b/xen/arch/arm/include/asm/tim= e.h index c194dbb9f5..9313b157ea 100644 --- a/xen/arch/arm/include/asm/time.h +++ b/xen/arch/arm/include/asm/time.h @@ -105,6 +105,11 @@ void preinit_xen_time(void); =20 void force_update_vcpu_system_time(struct vcpu *v); =20 +#ifdef CONFIG_SYSTEM_SUSPEND +void time_suspend(void); +void time_resume(void); +#endif /* CONFIG_SYSTEM_SUSPEND */ + #endif /* __ARM_TIME_H__ */ /* * Local variables: diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index 6955b2788f..fff8e4aca6 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -296,6 +296,14 @@ static void check_timer_irq_cfg(unsigned int irq, cons= t char *which) static DEFINE_PER_CPU_READ_MOSTLY(struct irqaction, irq_hyp); static DEFINE_PER_CPU_READ_MOSTLY(struct irqaction, irq_virt); =20 +/* Disable physical and hypervisor timers on the current CPU */ +static inline void disable_phys_hyp_timers(void) +{ + WRITE_SYSREG(0, CNTP_CTL_EL0); /* Physical timer disabled */ + WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */ + isb(); +} + /* Set up the timer interrupt on this CPU */ void init_timer_interrupt(void) { @@ -306,9 +314,7 @@ void init_timer_interrupt(void) WRITE_SYSREG64(0, CNTVOFF_EL2); /* No VM-specific offset */ /* Do not let the VMs program the physical timer, only read the physic= al counter */ WRITE_SYSREG(CNTHCTL_EL2_EL1PCTEN, CNTHCTL_EL2); - WRITE_SYSREG(0, CNTP_CTL_EL0); /* Physical timer disabled */ - WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */ - isb(); + disable_phys_hyp_timers(); =20 hyp_action->name =3D "hyptimer"; hyp_action->handler =3D htimer_interrupt; @@ -333,9 +339,7 @@ void init_timer_interrupt(void) */ static void deinit_timer_interrupt(void) { - WRITE_SYSREG(0, CNTP_CTL_EL0); /* Disable physical timer */ - WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Disable hypervisor's timer */ - isb(); + disable_phys_hyp_timers(); =20 release_irq(timer_irq[TIMER_HYP_PPI], NULL); release_irq(timer_irq[TIMER_VIRT_PPI], NULL); @@ -375,6 +379,34 @@ void domain_set_time_offset(struct domain *d, int64_t = time_offset_seconds) /* XXX update guest visible wallclock time */ } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +void time_suspend(void) +{ + /* CNTV already disabled by virt_timer_save() during vcpu context swit= ch. */ + disable_phys_hyp_timers(); +} + +void time_resume(void) +{ + /* + * Raising TIMER_SOFTIRQ triggers generic timer code to reprogram the + * hypervisor timer with the correct timeout (not known here). + * + * Xen doesn't use or expose the physical timer, so it remains disabled + * across suspend/resume. + * + * The virtual timer state is restored per-vCPU on the next context sw= itch. + * + * No further action is needed to restore timekeeping after power down, + * since the system counter is unaffected. See ARM DDI 0487 L.a, D12.1= .2 + * "The system counter must be implemented in an always-on power domai= n." + */ + raise_softirq(TIMER_SOFTIRQ); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ + static int cpu_time_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095654; cv=pass; d=zohomail.com; s=zohoarc; b=XoejBLv/vyOjIdEAzf/LNjYrIh91M5IBgYTUfNfTH4A7xYBP4YyQrIdXDxZeIhJSndgh08s/5vgvzopeEW+nj8+vT4XbhnnY4OBIz+7d6kyLzIFHP73iMNxK7KqLvCnAdlZuTVyttgW7tWZAIB0Mc/xYuJNjfvF+qrpIhBrDPvA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095654; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hFH8jnaLS3sxcH//YEoJ5xUIiJKXTPNp5wgdig2F9i0=; b=Gb4FLpeNAIHVHBhTxOsg/GabNqzpzuvRoX8V75JEPLu34uyj86aYl2s3ChhnvryVUoPIJHth8MK5nKhJialor2v67ZsPP+3c4QKFJj1LSk4q8wsiCpU0v5I/YjaNLJ14cRo414d6rstbvk/SWvbXXf6mAQWuf1XSTpWZsBXYkpE= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095654732886.8544522539976; Wed, 10 Jun 2026 05:47:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334257.1597349 (Exim 4.92) (envelope-from ) id 1wXIKm-0001QZ-VG; Wed, 10 Jun 2026 12:47:04 +0000 Received: by outflank-mailman (output) from mailman id 1334257.1597349; Wed, 10 Jun 2026 12:47:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKm-0001Ou-Os; Wed, 10 Jun 2026 12:47:04 +0000 Received: by outflank-mailman (input) for mailman id 1334257; Wed, 10 Jun 2026 12:45:20 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJ6-00018v-KG for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:20 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJ6-007rhd-0F for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:20 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c52-2eae-0a2a0a5409dd-0a2a4506e28e-44 for ; Wed, 10 Jun 2026 14:45:19 +0200 Received: from [52.101.69.129] (helo=AM0PR83CU005.outbound.protection.outlook.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c5f-7371-0a2a45060019-346545819085-3 for ; Wed, 10 Jun 2026 14:45:19 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:16 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:16 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=K/hhWj5WJd5hc85c6PXMB+N0EUi607sahOxlc4iK2BtVQ8SquVflO2n1+KUB+omBU3S2vXBG/2SG9aAs95k0ZEV4OsaCk/kYuXbeieXfQKeQlHJQvBxyYFxA7yTCsBp95mXimpcOJhOtpjf2MTfZpoy6vrod+8i5leVUrr2RuG1qef5Bbg1YR/OL0hXe9NkOCvj195/lMTLO4eBNXhBYBWzwOr5KIEA6MuN09Y5xl3HHb8Oz3j7tjazMiU4op7ce6Bc8DwgJyUB6LWlOh2MBhbhG7VwiV82PXhcF47VeVQYVAaoD1A/ecemCoqwLoJNfexPof7AdnqT2yaszxuijSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hFH8jnaLS3sxcH//YEoJ5xUIiJKXTPNp5wgdig2F9i0=; b=N9yKyIfg0/lExcnDXkTNtiD+1wVj7PkgjgUido9mqxddNwr6A3rmWxnsF/LH7K1N77+C9AP8BSiqommwUy64LaCoEFEFCkEiB8vq/AKxsJuDP3YEMKbXJzrpBXc0zJfsRmlVShn9gGXxK6sIKG803uewinV56ETNOfVJEeZmV//ZdXAULHD9lv2+k4iYNWdz3sXr7s6hjIzuoP3FaQQHqoxlO/rIvaMKKFdW/fzhrAkrKYkTGWcrQoornfX+r/i4qNZlr3bAw5oVndal2gZUNttJOJRNEkt3nbxoRJzONz2nyHvzZv0/zwgI2FTJvaR9I8z76lElBQCrbJDmf1Ogsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hFH8jnaLS3sxcH//YEoJ5xUIiJKXTPNp5wgdig2F9i0=; b=IjzzpeQMfILK2LYUv6/MIpxDVDMKnJT/QWDXFwaUOe7GS1v/EvOudHf6RRkKnKYkeOoiyrkwgJXN0IhjHYvpqzognusaSRMkwLfThfPSZs+xbdM7eC4THlaz7KyDmifLwJMDs48scnNFPRrZCZedOtOmRacEfmp00ZNkGPMxBlGucjldy+KcFAc79VeSPWQVGRLTCMLhhozcO8M9JJus7thw2LYIY4EWv52Dftq239JnHwwgnPJRgPYzUcO60F43Ixc6HWdayZa4N/jrAzPLEd3ZoWL5bSZSbc6EOdn30VtOitS02Gn887NUlSBQywUPAXQQz+QN9Gcn4NtzpC14WQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Luca Fancellu Subject: [PATCH v11 02/13] xen/arm: gic-v2: Implement GIC suspend/resume functions Date: Wed, 10 Jun 2026 15:44:22 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: dc26a7e2-55f7-46b3-0479-08dec6ee1f52 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|20046099003|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: sMAHFHteUnyIFhFo+S39iU3/oNWgXAnXo5eBcsceyXVNPycAmnaxqU/P26ZsIixyBEiot12FgvJK7qIXBhUQPA6B8SBnoIVGjrMxt5qlAALat67S3uZLna79gfjua5jPhIpujqqv7sxhAwdkd94B1ay+H9y0pJTlGm56ZnjvdUe/ZphAHmynJEMs6+hxd21PCCd7zZy5zl160XjfZAhE5CsG0b3Owv/SuWO1R1M++sK2huw2llqGZySffSdq5r1VpXgjjhJ7NTuh2INHPyks7hDqzvdCgdTN9IDqwGpug5b8OySAOaod85VP3dsg+y7NU3/+63xz11RGwu83HH7SG0kqT33C2Y4fHSMl+6YONu2jn1iBW/hVleoOYQa89ood4ZDRzOmp63BPG+yciPzUIguLjQ/1TXskslSf95nccQZV/sr5XigAF6Q/9isgQrWPer4y9C6lXVcdM99DpeR1E+YEzt+AvcjmSQoeNf8vJ792hHtPrIKtxj1fmuaoOB68gPB42Tz+BAalVz/pISJGkrsPopwENQVuzsyGE2VXSbZu/hthPb8RhifaI8KhKkkbN/hKaXds2n5oKwrOcP88l+7v8syXx2G+0Lgh0nQjbwKfhIx3wPpuwLooLWnro0pt66WObXB4qzyPWuftfqcMKEddQzFn/YceAQgcsV/sSwCi53NlrKkECXZwo2ejEbEE X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(20046099003)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Wpe5BZiXIAy0KoSasViuJqF8COV9zuF/y9j9m/UoN2USJqa9Jy/M3fTF7jcs?= =?us-ascii?Q?m8K3Qav9sOgF7DvVqvluPrNhNzA71ubqOW0owvRuoB+C0ybXJ5lo3NphdvQn?= =?us-ascii?Q?mrLz2X+6K2HCTGhGYPHV7yI4BbRoFSaJl381f/7BCAvGQb0aQvsFfpIIJCKR?= =?us-ascii?Q?W1dWAxg+zBsP1Oz8a9T3VmX9XiVrbajJSf+2awlJT1LyD+zKacjcBiUWrM85?= =?us-ascii?Q?9ESmzQqyp5dG5tloEBLEtQUtH6XA5wAXfdS4h533H+qdRproPAWoOTaEQrIi?= =?us-ascii?Q?xngK8sGFAevS+YF8fuB3UJxThb4zVUkyNptoz8nvLAd+BMrqe7RCdZFRUDdR?= =?us-ascii?Q?X7CcIv8si/+VpgRzFJvXZ4T91cdCFWz/wOjBt4mqJbrpy67EjWPTIbWpBrm8?= =?us-ascii?Q?3mY/53xklnr/3RPNzLfdxGR5GsWH+E33CxNCmPnd4rK1pEcsDTG9OpqYpfPn?= =?us-ascii?Q?7c+4O9lQmjsFBFiq8eGNmGJUfspe+5bQrapbT4fqFHNsM4RIMmV/LpgwrUh2?= =?us-ascii?Q?XysMEOrHDlgU1B73qYkvD3A1hPfvX2dFjR4df5fhem7o39rdCLGTE+SDKQ+G?= =?us-ascii?Q?hhRVHYESJ1whTjU66YlGY1I1dHfPzNN2PPI3L05Ilh0Nrb3TcRvnu+KwEJZq?= =?us-ascii?Q?mB0/UXHBZkFsTE1GkKWP+yMsEMrw1dSmPI0jzZLjS+cwM+PtOCFxtYgvprHL?= =?us-ascii?Q?EbW27CXbNxad4LiwaJmu0YHVk5ehXZb1kbUw6N9hAayeFAo8nGTgebrhQlBC?= =?us-ascii?Q?9FRXQ7O37hVS56xNid2ibESxyniizbv5D+kdQCTBHQ5nbEkSgfo8g3hIYeXQ?= =?us-ascii?Q?CIrA4e/r6AX4LxTMbOdHnfI99HL7eTdfTd1g81b92hL9BtOxn5boV11iCA0g?= =?us-ascii?Q?1TLrhxwBePuqdGW/MlrtpIu+hVcgdRou3R6LAt/CgFbkxzzHczqxaDzyDYKp?= =?us-ascii?Q?xYaZDiHsratdu+rL4Xo5dab4WSpfjB4K4mEbjvR0QSn7mRYZOVJPm1pAcgvj?= =?us-ascii?Q?t8OE0VC6GljrG+QwUyLMNT1H9I7BaGEPUJ5HP2RImZRpDAm+W7EsIYb/Iopt?= =?us-ascii?Q?N5zHEnGPAJ3fvhoC/N0vOfQVX88R8GkIQFuJDu6eThBRtXFi2tob3DDdSH7J?= =?us-ascii?Q?NisjWQ7RAfW33DLoD0l0JXe3mecim0tGDsz51tDAw3Zzd6cuEFRX18V/JOdK?= =?us-ascii?Q?h50g0+1zq7xWvFvFS1j4LFCWjbK+u7zmkyVeXWpq1GjmOcvEMHXSCTKTbSj6?= =?us-ascii?Q?0DdYOkdo+gvNGET45NXv6gDDkxhV3+fD7MjcUeX/wQY9amR1tKGs2QVJ+qSS?= =?us-ascii?Q?GMn+Y57mKfXQf4NPNcsbqyorcesVkxwb9fDkr3GLQ8QkSbYSwyOdVqA9qdXq?= =?us-ascii?Q?Qe7Mw/HPjwWwrcGpLquWDJWCfbLAOHqIa+ySUb4rbvfOq0eFX3AD7knPbp32?= =?us-ascii?Q?hf8KgN5YWxjVl2ZOePLwS3pjnJokFMiy+z61vlwIOAyA7VhBuWsVkL65a3WF?= =?us-ascii?Q?5sDkG4FW+7eSNbPF/sH+JSIIPPNUAoqMkO77GiEFNT6W6jYEq14GYTQGBBpP?= =?us-ascii?Q?ZbI8pJCnFniusxxp0eRoexGezqYiH1+J1eAEBuwPrmBpG4ZWnjLy9/t5ry6L?= =?us-ascii?Q?STEZAROD4ClNdl2ONbHfqoGngizHg7pH5v/RrluvrQjkYY7afXQ8Dft8voZw?= =?us-ascii?Q?kIoONay4cx5yewLl1WeB0YMkd0xxchPTd30/jzjDdFPO5ZL3bKzkjEQ6AT+c?= =?us-ascii?Q?Og8IkJWW2g=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc26a7e2-55f7-46b3-0479-08dec6ee1f52 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:16.4596 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: p1q+d8Vl18SXyCwU3glgXzM3qxWh73sErasTFoumNW1WZuhgpzvNQuzpFNFnJIQtf/cykAIdOdnV5/8Gajzctg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-16d1c6/1781095519-86974D75-4C6A66A1/0/0 X-purgate-type: clean X-purgate-size: 13573 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095655588158500 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume. Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch. Transient physical SGI pending state (GICD_CPENDSGIRn/GICD_SPENDSGIRn) is intentionally excluded. CPU-interface active-priority state is also not restored across suspend/resume. Xen reaches the final suspend path at a quiescent point, so there is no active-priority execution context to replay after resume. Enforce this with a runtime check after disabling the CPU interface: if any implemented GICC_APRn word is still non-zero, restore GICC_CTLR and abort suspend with -EBUSY. This does not apply to distributor active state. With GICv2 EOImode=3D=3D1, EOIR only drops the interrupt priority; final deactivation is a separate step. For guest-routed interrupts, Xen can have already EOIed the physical IRQ while deactivation is still pending on the vGIC/GICV path. Therefore GICD_ISACTIVER is preserved as architectural in-flight interrupt state. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykyta Poturai Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in V10: - Limit GICC_APR active-priority checks to APR bits visible from the Xen CPU-interface view. - Avoid touching reserved GICD_IPRIORITYR/GICD_ITARGETSR words when the last implemented interrupt block is partial. - Restore distributor configuration before restoring interrupt enable state, so GICD_ICFGR is written while the corresponding interrupts are disabled. Changes in V9: - Skip saving/restoring GICD_ITARGETSR0..7 because SGI/PPI target registers hold no state (read-only on MP, RAZ/WI on UP). - Add a runtime GICC_APRn quiescence check after disabling the CPU interface, and restore GICC_CTLR before returning -EBUSY. Changes in V8: - disable cpu interface + distributor before suspend - change 0xffffffff to GENMASK; - cosmetic changes; Changes in V7: - Allocate one contiguous memory block for the GICv2 dist suspend context. - gicv2_resume() no longer unconditionally re-enables the distributor/CPU interface; it now writes back the saved CTLR values as-is. - gicv2_alloc_context() now returns 0 on success and panics on failure, since suspend context allocation is not recoverable. --- xen/arch/arm/gic-v2.c | 226 +++++++++++++++++++++++++++++++++ xen/arch/arm/gic.c | 29 +++++ xen/arch/arm/include/asm/gic.h | 12 ++ 3 files changed, 267 insertions(+) diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index 43a379fdda..a0ef6ffc7f 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -1108,6 +1108,223 @@ static int gicv2_iomem_deny_access(struct domain *d) return iomem_deny_access(d, mfn, mfn + nr - 1); } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +/* This struct represents block of 32 IRQs */ +struct irq_block { + uint32_t icfgr[2]; /* 2 registers of 16 IRQs each */ + uint32_t ipriorityr[8]; + uint32_t isenabler; + uint32_t isactiver; + uint32_t itargetsr[8]; +}; + +/* GICv2 registers to be saved/restored on system suspend/resume */ +struct gicv2_context { + /* GICC context */ + struct cpu_ctx { + uint32_t ctlr; + uint32_t pmr; + uint32_t bpr; + } cpu; + + /* GICD context */ + struct dist_ctx { + uint32_t ctlr; + /* Includes banked SGI/PPI state for the boot CPU. */ + struct irq_block *irqs; + } dist; +}; + +static struct gicv2_context gic_ctx; + +#define GICV2_NR_APRS 4 +#define GICV2_APR_BITS_PER_REG 32U + +static int gicv2_check_active_priorities(uint32_t bpr) +{ + unsigned int i, apr_bits, nr_aprs; + + /* + * Xen writes GICC_BPR to 0 during CPU init and does not change it. Per + * IHI0048B.b, a write below the implementation minimum reads back as = the + * minimum supported BPR value. Table 4-47 maps that Xen-visible BPR v= alue + * to the visible GICC_APR bits. Avoid reading APR registers outside + * that visible range. + * + * This covers both GICv2 with and without Security Extensions. + */ + apr_bits =3D 1U << (7 - (bpr & 0x7)); + nr_aprs =3D DIV_ROUND_UP(apr_bits, GICV2_APR_BITS_PER_REG); + + ASSERT(nr_aprs <=3D GICV2_NR_APRS); + + for ( i =3D 0; i < nr_aprs; i++ ) + { + unsigned int bits =3D min(GICV2_APR_BITS_PER_REG, + apr_bits - i * GICV2_APR_BITS_PER_REG); + uint32_t mask =3D GENMASK(bits - 1, 0); + uint32_t apr =3D readl_gicc(GICC_APR + i * 4) & mask; + + if ( !apr ) + continue; + + printk(XENLOG_ERR "GICv2: suspend aborted: GICC_APR%u=3D%#08x\n", + i, apr); + return -EBUSY; + } + + return 0; +} + +static int gicv2_suspend(void) +{ + unsigned int i, blocks =3D DIV_ROUND_UP(gicv2_info.nr_lines, 32); + int ret; + + /* Save GICC_CTLR configuration. */ + gic_ctx.cpu.ctlr =3D readl_gicc(GICC_CTLR); + + /* Quiesce the GIC CPU interface before suspend. */ + gicv2_cpu_disable(); + + gic_ctx.cpu.bpr =3D readl_gicc(GICC_BPR); + + /* + * Check the active-priority state for the group Xen drives through the + * CPU interface. GICC_CTL_ENABLE enables Group 0 without SecurityExtn= and + * Group 1 in Xen's Non-secure view with SecurityExtn, and in both cas= es + * the relevant state is visible through GICC_APRn. The APR layout is + * implementation-defined, so only test the bits visible from Xen's CPU + * interface view instead of reading every possible APR register. + */ + ret =3D gicv2_check_active_priorities(gic_ctx.cpu.bpr); + if ( ret ) + { + writel_gicc(gic_ctx.cpu.ctlr, GICC_CTLR); + return ret; + } + + gic_ctx.cpu.pmr =3D readl_gicc(GICC_PMR); + + /* Save GICD configuration */ + gic_ctx.dist.ctlr =3D readl_gicd(GICD_CTLR); + writel_gicd(0, GICD_CTLR); + + for ( i =3D 0; i < blocks; i++ ) + { + struct irq_block *irqs =3D gic_ctx.dist.irqs + i; + size_t j, off =3D i * sizeof(irqs->isenabler); + size_t nr_regs =3D ARRAY_SIZE(irqs->ipriorityr); + + if ( i =3D=3D blocks - 1 ) + nr_regs =3D DIV_ROUND_UP(gicv2_info.nr_lines - i * 32, 4); + + irqs->isenabler =3D readl_gicd(GICD_ISENABLER + off); + + /* + * Save distributor active state as part of the hypervisor-owned + * physical interrupt state. In GICv2 EOImode=3D=3D1, EOIR only dr= ops the + * priority; final deactivation is separate. For guest-routed + * interrupts, Xen may have EOIed the physical IRQ while the guest= /vGIC + * side still owns the deactivate step. Therefore GICD_ISACTIVER c= an + * legitimately remain set even though transient SGI pending state= and + * CPU-interface active-priority state are expected to be quiesced= here. + */ + irqs->isactiver =3D readl_gicd(GICD_ISACTIVER + off); + + off =3D i * sizeof(irqs->ipriorityr); + for ( j =3D 0; j < nr_regs; j++ ) + irqs->ipriorityr[j] =3D readl_gicd(GICD_IPRIORITYR + off + j *= 4); + + /* + * GICD_ITARGETSR0..7 cover SGIs/PPIs and hold no state to save: + * they are read-only on multiprocessor implementations and RAZ/WI + * on uniprocessor implementations. + */ + if ( i ) + { + off =3D i * sizeof(irqs->itargetsr); + for ( j =3D 0; j < nr_regs; j++ ) + irqs->itargetsr[j] =3D readl_gicd(GICD_ITARGETSR + off + j= * 4); + } + + off =3D i * sizeof(irqs->icfgr); + for ( j =3D 0; j < ARRAY_SIZE(irqs->icfgr); j++ ) + irqs->icfgr[j] =3D readl_gicd(GICD_ICFGR + off + j * 4); + } + + return 0; +} + +static void gicv2_resume(void) +{ + unsigned int i, blocks =3D DIV_ROUND_UP(gicv2_info.nr_lines, 32); + + gicv2_cpu_disable(); + /* Disable distributor */ + writel_gicd(0, GICD_CTLR); + + for ( i =3D 0; i < blocks; i++ ) + { + struct irq_block *irqs =3D gic_ctx.dist.irqs + i; + size_t j, off =3D i * sizeof(irqs->isenabler); + size_t nr_regs =3D ARRAY_SIZE(irqs->ipriorityr); + + if ( i =3D=3D blocks - 1 ) + nr_regs =3D DIV_ROUND_UP(gicv2_info.nr_lines - i * 32, 4); + + writel_gicd(GENMASK(31, 0), GICD_ICENABLER + off); + + off =3D i * sizeof(irqs->icfgr); + for ( j =3D 0; j < ARRAY_SIZE(irqs->icfgr); j++ ) + writel_gicd(irqs->icfgr[j], GICD_ICFGR + off + j * 4); + + off =3D i * sizeof(irqs->ipriorityr); + for ( j =3D 0; j < nr_regs; j++ ) + writel_gicd(irqs->ipriorityr[j], GICD_IPRIORITYR + off + j * 4= ); + + /* + * GICD_ITARGETSR0..7 cover SGIs/PPIs and hold no state to save: + * they are read-only on multiprocessor implementations and RAZ/WI + * on uniprocessor implementations. + */ + if ( i ) + { + off =3D i * sizeof(irqs->itargetsr); + for ( j =3D 0; j < nr_regs; j++ ) + writel_gicd(irqs->itargetsr[j], GICD_ITARGETSR + off + j *= 4); + } + + off =3D i * sizeof(irqs->isenabler); + writel_gicd(irqs->isenabler, GICD_ISENABLER + off); + + writel_gicd(GENMASK(31, 0), GICD_ICACTIVER + off); + writel_gicd(irqs->isactiver, GICD_ISACTIVER + off); + } + + /* Restore distributor control state. */ + writel_gicd(gic_ctx.dist.ctlr, GICD_CTLR); + + /* Restore GIC CPU interface configuration */ + writel_gicc(gic_ctx.cpu.pmr, GICC_PMR); + writel_gicc(gic_ctx.cpu.bpr, GICC_BPR); + + /* Enable GIC CPU interface */ + writel_gicc(gic_ctx.cpu.ctlr, GICC_CTLR); +} + +static void __init gicv2_alloc_context(void) +{ + uint32_t blocks =3D DIV_ROUND_UP(gicv2_info.nr_lines, 32); + + gic_ctx.dist.irqs =3D xzalloc_array(struct irq_block, blocks); + if ( !gic_ctx.dist.irqs ) + panic("Failed to allocate memory for GICv2 suspend context\n"); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ + #ifdef CONFIG_ACPI static unsigned long gicv2_get_hwdom_extra_madt_size(const struct domain *= d) { @@ -1312,6 +1529,11 @@ static int __init gicv2_init(void) =20 spin_unlock(&gicv2.lock); =20 +#ifdef CONFIG_SYSTEM_SUSPEND + /* Allocate memory to be used for saving GIC context during the suspen= d */ + gicv2_alloc_context(); +#endif /* CONFIG_SYSTEM_SUSPEND */ + return 0; } =20 @@ -1355,6 +1577,10 @@ static const struct gic_hw_operations gicv2_ops =3D { .map_hwdom_extra_mappings =3D gicv2_map_hwdom_extra_mappings, .iomem_deny_access =3D gicv2_iomem_deny_access, .do_LPI =3D gicv2_do_LPI, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend =3D gicv2_suspend, + .resume =3D gicv2_resume, +#endif /* CONFIG_SYSTEM_SUSPEND */ }; =20 /* Set up the GIC */ diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index ee75258fc3..7727ffed5a 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -432,6 +432,35 @@ int gic_iomem_deny_access(struct domain *d) return gic_hw_ops->iomem_deny_access(d); } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +int gic_suspend(void) +{ + /* Must be called by boot CPU#0 with interrupts disabled */ + ASSERT(!local_irq_is_enabled()); + ASSERT(!smp_processor_id()); + + if ( !gic_hw_ops->suspend || !gic_hw_ops->resume ) + return -ENOSYS; + + return gic_hw_ops->suspend(); +} + +void gic_resume(void) +{ + /* + * Must be called by boot CPU#0 with interrupts disabled after gic_sus= pend + * has returned successfully. + */ + ASSERT(!local_irq_is_enabled()); + ASSERT(!smp_processor_id()); + ASSERT(gic_hw_ops->resume); + + gic_hw_ops->resume(); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ + static int cpu_gic_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) diff --git a/xen/arch/arm/include/asm/gic.h b/xen/arch/arm/include/asm/gic.h index ff22dea40d..fbf0d69edd 100644 --- a/xen/arch/arm/include/asm/gic.h +++ b/xen/arch/arm/include/asm/gic.h @@ -301,6 +301,12 @@ extern int gicv_setup(struct domain *d); extern void gic_save_state(struct vcpu *v); extern void gic_restore_state(struct vcpu *v); =20 +#ifdef CONFIG_SYSTEM_SUSPEND +/* Suspend/resume */ +extern int gic_suspend(void); +extern void gic_resume(void); +#endif /* CONFIG_SYSTEM_SUSPEND */ + /* SGI (AKA IPIs) */ enum gic_sgi { GIC_SGI_EVENT_CHECK, @@ -444,6 +450,12 @@ struct gic_hw_operations { int (*iomem_deny_access)(struct domain *d); /* Handle LPIs, which require special handling */ void (*do_LPI)(unsigned int lpi); +#ifdef CONFIG_SYSTEM_SUSPEND + /* Save GIC configuration due to the system suspend */ + int (*suspend)(void); + /* Restore GIC configuration due to the system resume */ + void (*resume)(void); +#endif /* CONFIG_SYSTEM_SUSPEND */ }; =20 extern const struct gic_hw_operations *gic_hw_ops; --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095654; cv=pass; d=zohomail.com; s=zohoarc; b=fv80mn/n4A4NtnzngFVXgxAjF5LjUNnjYbQzCbB4xrwXRuYDnh2mSF1fL3U9GG5G1iBOHUCIkZRRmuCMF9KSyvxfFOV8p5iEPKTP01IAtLGY7pO7jT9qSPzBwG7+JDbg/7N0p/kMivwDdwGmTjj3+DLmkm24aL9bvqW54mOeNRM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095654; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bykUR/xLFuasoQUfLUvHqdOV3+AtF8rtSjNfXAIXxmQ=; b=FZ+NMF2IVy58VaW+A8o6UlbRgQKvONC75vf/6Gpzto2uFYs4KJkdPl8iSVVtlexlURLTghyz93UQnJlk5Scugzcm8r3FOX8P2ssNuYfLmTlZJ5MMOombdESVFwpqe6nWVjUOIg0GY6bF9mF2QFHmqPmor9hCal1/EKsfCV7ZuLY= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095654906129.49757276664172; Wed, 10 Jun 2026 05:47:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334260.1597354 (Exim 4.92) (envelope-from ) id 1wXIKn-0001XR-5j; Wed, 10 Jun 2026 12:47:05 +0000 Received: by outflank-mailman (output) from mailman id 1334260.1597354; Wed, 10 Jun 2026 12:47:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKn-0001Vw-1d; Wed, 10 Jun 2026 12:47:05 +0000 Received: by outflank-mailman (input) for mailman id 1334260; Wed, 10 Jun 2026 12:45:22 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJ8-000198-Ce for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:22 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJ7-007rhd-PW for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:21 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c52-2eae-0a2a0a5409dd-0a2a4506e28e-48 for ; Wed, 10 Jun 2026 14:45:21 +0200 Received: from [40.107.162.86] (helo=PA4PR04CU001.outbound.protection.outlook.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c61-7371-0a2a45060019-286ba256b90f-3 for ; Wed, 10 Jun 2026 14:45:21 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:19 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:19 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oNPULTbuKpQUrV4rM2awB6yB43Uf2rsJ6TO9gLqRhBiXbJftBMvjVEKeR+daIZ/pceRHgQKOgyGJd+PbVoeAVFtdPTGACbQcIzh13uPpwn0prPfyckhlo6Kdo2jXbFQq8fb1mQB7zT/91iC1fBxpiSeJZlVyGYJr0vQPxcFtm2CrewdyksF5F52G2WdlGr13NFFksGPP9+miBfCxC54RCVZavy9siKhj/EZNw0894NtqHbeyv168s5pRC5qwSBP/vQXPy7DHOAql6/e7yRIwN59XZEiR+skI1hlbeE+ezteOSQHoZ9GkOVQ4ulSnWoaA+tWvX4xn9RFkF8zittfa7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bykUR/xLFuasoQUfLUvHqdOV3+AtF8rtSjNfXAIXxmQ=; b=PQCitOZ0R0lcRnqBVTOpZS2KOggTGfExJQ+zSBhVCvSqhgBxAyLv8IRWak844tXHvJrGiLP6lVU7tKClYv6l3h6myUa/R5z5E9EIdZthoRw0Vyr8otXsbJ3U+6srAVtK+U1Ez5BLwi1M0OOm95HePFvG4imSY1pJRzLqfcgChgk6NOrlR35osTmBz7ifPbvngKtqBAuF3IOGluruK9nWUn12ZJObV/mrGCcOzvxYZquD+K4pUn19Ch9QFFT6ENZw26W4b65/fCwds8tt7CcQD4w8pDuDL9/Kn0vckym/jNCp58Ti21kd0hsPJLIoiArASfWsD9mVssTxu+0U/ebIGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bykUR/xLFuasoQUfLUvHqdOV3+AtF8rtSjNfXAIXxmQ=; b=Uj/nOgwvoWOIkLH0/YDRwOFA23RDi50CYyL5VYCdA2WthlMCjjBRBthfpCHxsEesnfI9BxPX1izVcvEA1Na9wMymVD13WAkI25GTQHOYyemCDNuixegsleTnxu99oYjFaEaJ36gX/iX1+c7YoINBDSsQ9DfWaEgQGI5SG9xNMOek5HRCgTHhgGVaefgFCo1ycLVjwlQX106+hgF6zmfUsCaXxf0jaxd3gYQjbgiooMFw3HUiaNxLQWxeeCnJ8yXpwA1IcCLGWMzoff6OmCEsjWMYCK3UAEZAVnQN9QDdU4arLpgVWPCIFF95+Vr63ztcYWhUx5bEBKAvcBfPhecSDQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Luca Fancellu Subject: [PATCH v11 03/13] xen/arm: gic-v3: tolerate retained redistributor LPI state across CPU_OFF Date: Wed, 10 Jun 2026 15:44:23 +0300 Message-ID: <74b4ab2e7957e16a0b922dc5431a9ef6406acffa.1781084290.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 531d3c5f-fd17-4b77-ac2a-08dec6ee211b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: IxwgL4M3TROMdrecNUHjKb7eB+gIKPCOCKacM36Ulw5DwNGBc+M6PCMLonm3tf83ZAZn46QrmngB6OkQ7D3P32MMd6wUvj3k82RE4Q1dKg1tBlVUdJqEd61w4/Y5wBqbzEdLFeY9M81SmxBzjjiE+JjPZBDDjmRp/eZDQqQWyCpunckPAN41+qLTfGaoRO26SkKa/nH1QR3vDx//+vYZrzVjmGvs5bLFiFCJjxH65C1PDkPQQmEdvhSkW2giD6z9gxRic4HBdZjJ7ahBU9426pBUtxhmiJSMV+Li1VAwdV4k3ZtZDGiwIqPkDU5EGQzxMlxjfenQEtIt7VUYNJHiDlzeHX0nj5x7RDL38RmqEgZDeWlIPXjlXnS7IiS9FLvrURmLIbK3L6RMErmsE1dRQLklgY72lH7LiDdNS8xZbcF/uyROE7KRHF+RmiyWcewh7xNmUhOtwE2becshbVAedpW45CgvzNg8tEHRob04zXnV6h4LrEsEdYVlSTdJ+Abg918f1f4zq58ZzE+aHzWQ1NnwqCU3QUvCnYfCq4y+aEGsZRs+PBKHTZCTjHHYwvWQRfaj08jCqYhJIhox0gX1ISc7V3Gez0WsHnW2ZJUvK+eaT8ZW9dkfO9Jlq7gyXttIlWsIbWD6gboCvfT6At1xGeq3NCXg2l021CIkc6njw4SDHfKjHI5ZPrwv5+0Gab4S X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?N6n/+sjLH8vU5wdBGCZBexT/ucXyQn1b0AGNUzEbiG2tTkbKeCdpYuPHQnFI?= =?us-ascii?Q?lVlMH36qViTf2V0B6KuZSiBCM+mHzHM5KUlq5wFyJqQ95IlGh49PREQY49dR?= =?us-ascii?Q?t/oHXH4X+w0JrwwDFKrZIk9mwn3mKHdtMr9Cy0P61xJIgEJemue0/AR+E5Ez?= =?us-ascii?Q?L2NBcxDjJb0E/jMdByr8a5tvFdajrIDlDzw4qajCjr2U51vWVjgJKUd1va8n?= =?us-ascii?Q?OGaHCTQ1sVjKSVr+VUzO7Ys7ReahNLRFXDh5nmPoFRMhj38F6fFVh06XJqW1?= =?us-ascii?Q?iUuLBLYeorGN5XCYAS+5ai1y/e7hCiqYcVInpB26oiKxYdzVQp/mwb3mtqCi?= =?us-ascii?Q?LcdsTx+Ml8Oe56Q9Xdkt43YhcPhJtyZKqK7dU1xpXRVeid7wpjgHz0n4Xekm?= =?us-ascii?Q?SdBEZD8dhre08VxYyoOPX4a/o6PsCz0BNIWt3LgbOewMXL0WbncAskEI4rJt?= =?us-ascii?Q?EbmifODj4RMP2CfUVg0Gq3NADEibc/nSTIxNSgiWSW0FuWvH3PrNODM39ngZ?= =?us-ascii?Q?0sG5yPsQz44SM0mbaJT0snGQtYV+0UdmVyKeUJc3sI80iU910HmuNv0WzQTR?= =?us-ascii?Q?Hg+cg4e18dzOCTQlM0v2aPI8yR6nR696VxKf4DQJNevReJARcrxluhcbY6Lo?= =?us-ascii?Q?UJrSl9SNnkjkJCHQZsyHbaSP8gLezHx/zFHFi3LqOEmAzc2cJ/VfN1DkLdr+?= =?us-ascii?Q?8dMLMA7DtTCl0DdhcOcCdBxrmDB+6Y7s7a7Jz8VAXvFbtXOUixqXfg8oyI5I?= =?us-ascii?Q?uTVxphmz6oYsNobEDZduUv1YqZkWd7LucrFuQNcwbVFbVSe54C0dGF2Yyaxe?= =?us-ascii?Q?I0DQNnOW8K3hgf5UTcHykPUbObggz8cdyfmb7Hp/l1T1muctgqrr95iS4Pv3?= =?us-ascii?Q?T9N50jIKa/8ZUs6fQcJEBQ1svgUp0v95efRdyuRxmCT/nRTXV7lPqkihjQOA?= =?us-ascii?Q?Cvq4dSqAiX9JiSpHzKLYP/VmhJWqef5WcK/wsTwoLNFSr/ixLT3JS2kM25K8?= =?us-ascii?Q?rSmJEc6TTH2IIdr/wjLsMRot9JlTjTLwJtPSqyVuhuJwQLsV1gB+SIPCWpCj?= =?us-ascii?Q?NWHQn2xIsX9SCLPEAFt4nlSXgc/UdKR44yEzNha4rGLHe3mg+f3ZhFaH9yxl?= =?us-ascii?Q?vn2L7JRKOztyeFnSl6+9G4NZfpbeCi/jyEcqYpWFKVhahMlIt+ou+Net/mKO?= =?us-ascii?Q?pv+F6URXSfFDD9GaJRPTqVxLoPKGmm87Ybc0A4qlgqJBWKXf+MQfzYT//quw?= =?us-ascii?Q?t2CDpB4ZHeDIpW+Brxoo1qfuPnnR7e6CiGoXh4HDCuoWEUwGwY7b9HwDOOvo?= =?us-ascii?Q?OrDzP4juGkdTDFhiWeujQXdKHyRCwaP/TL4lfnD3hfg3HghVDR/qawF5/Tad?= =?us-ascii?Q?Wu19f3yDHvbMP9qxO72Q0sMVyxVYU5kLUFBzON5XxkbPkwQ3e2xslGbtaf4B?= =?us-ascii?Q?HOVq3gkpANS+diWLcFFg+cSqcl8sfM9fu38q4bAPLdlW8EDhjlMcbhEqqqcn?= =?us-ascii?Q?8EQ2xNdLbqWCtOG/CSDZIf7TljkHeLRUq/uW5fVEoKrcetRF9tb6RSLnEkbv?= =?us-ascii?Q?bawbg5bLPIoZ6vaGDCijIL6BTj+XjSTJuehIehci0owxvW3IH/eZjfWflTLB?= =?us-ascii?Q?M3qM1t4AU0zDI49pTNHUUX5SPKHemga3Qhc5ODyokIdVT0Ii+fdTWWXKhhGP?= =?us-ascii?Q?ctZrxf8ul4AANbS/01xbZ6yOkpWwSVTVeEHF8EMNT6J9f5awrJcdYLlCGhr+?= =?us-ascii?Q?7Fzp7QDutw=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 531d3c5f-fd17-4b77-ac2a-08dec6ee211b X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:19.4427 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /fKHJ0L1tV7aXttg9KOqJXAjlTuJN5Vf1l2nikbUoGBH7SvWfk5JEput8+rMNnDLYQAovoJffEgGXazh6ndUHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-16d1c6/1781095521-7F77FD75-6431D11C/0/0 X-purgate-type: clean X-purgate-size: 9556 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095656678154100 Content-Type: text/plain; charset="utf-8" PSCI does not guarantee that a GICv3 redistributor is powered down across CPU_OFF -> CPU_ON. DEN0022F.b says CPU_OFF powers down the calling core (5.5) and CPU_ON brings the core back with a defined initial CPU state (5.6, 6.4). However, PSCI leaves interrupt migration and GIC re-initialization to the supervisory software/firmware stack: the caller must migrate interrupts away before CPU_OFF (5.5.2), and the execution context that is lost in a powerdown state must be saved and restored by software (6.8). PSCI also calls out GIC management explicitly in 6.8, including retargeting SPIs, preventing PPIs/SGIs from targeting a powered down CPU, and reinitializing the CPU interface after CPU_ON. This matches the GIC architecture. IHI0069H.b Chapter 11.1 requires the PE and CPU interface to share a power domain, but explicitly allows the associated redistributor, distributor, and ITS to remain powered while the PE and CPU interface are off. All other GIC power-management behavior is IMPLEMENTATION DEFINED. DEN0050D Chapter 4.2, "Generic Interrupt Controller (GIC)", says the GICv3 redistributor may live either in the AP core power domain or in a relatively always-on parent domain. So after CPU_OFF -> CPU_ON a secondary CPU can legitimately come back to a live redistributor with GICR_CTLR.EnableLPIs still set. Handle that case in the LPI setup path instead of assuming a fully reset redistributor. The LPI path needs special care because the GIC spec makes redistributor LPI state sticky and partially implementation defined. IHI0069H.b 5.1.1 and 5.1.2 say that changing GICR_PROPBASER or GICR_PENDBASER while GICR_CTLR.EnableLPIs =3D=3D 1 is UNPREDICTABLE. After clearing EnableLPIs, software must wait for GICR_CTLR.RWP =3D=3D 0 before touching the pending table. The architecture also permits implementations where, once EnableLPIs has been set, clearing it again is not guaranteed to work. Where an ITS is present, the spec strongly recommends moving LPIs to another redistributor before clearing EnableLPIs. Because of that, treat a retained EnableLPIs state as valid when the redistributor still points at Xen's expected PROPBASER/PENDBASER tables. Only try to clear EnableLPIs when the retained configuration does not match Xen's state, and wait for RWP before reprogramming the tables. This is also consistent with platform firmware reality: PSCI and the GIC architecture allow platform-specific redistributor power handling, and not all platform firmware implementations force a full redistributor power-off through implementation-defined controls during CPU_OFF. Xen therefore needs to tolerate retained redistributor state on secondary CPU bring-up. Keep gicv3_populate_rdist() resident as well, because gicv3_cpu_init() reuses it on secondary CPU bring-up after init. Tested using Xen's non-boot CPU disable/enable path on Arm FVP_Base_RevC-2xAEMvA, both with and without: -C gic_distributor.allow-LPIEN-clear=3D1 -C gic_distributor.GICR-clear-enable-supported=3D1 and on Orange Pi 5. Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in v10: - Drop unrelated gicv3_populate_rdist() printk() format cleanups to keep the patch focused on retained redistributor LPI state. Changes in v9: - move gicv3_do_wait_for_rwp prototype from its related header to gic.h - drop __init from gicv3_populate_rdist(), which is reused on secondary CPU bring-up after boot - changed print format for smp_processor_id in gicv3_populate_rdist func - cosmetic changes --- xen/arch/arm/gic-v3-lpi.c | 77 +++++++++++++++++++++++++++++++++- xen/arch/arm/gic-v3.c | 15 ++++--- xen/arch/arm/include/asm/gic.h | 4 ++ 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/gic-v3-lpi.c b/xen/arch/arm/gic-v3-lpi.c index 9ee338edc2..847da26ff7 100644 --- a/xen/arch/arm/gic-v3-lpi.c +++ b/xen/arch/arm/gic-v3-lpi.c @@ -81,6 +81,13 @@ static DEFINE_PER_CPU(struct lpi_redist_data, lpi_redist= ); #define MAX_NR_HOST_LPIS (lpi_data.max_host_lpi_ids - LPI_OFFSET) #define HOST_LPIS_PER_PAGE (PAGE_SIZE / sizeof(union host_lpi)) =20 +#define GICR_PROPBASER_XEN_MASK GENMASK_ULL(51, 12) +/* + * For retained redistributor state, match the pending table by address on= ly. + * Attribute bits such as PTZ may not read back with the programmed value. + */ +#define GICR_PENDBASER_XEN_MASK GENMASK_ULL(51, 16) + static union host_lpi *gic_get_host_lpi(uint32_t plpi) { union host_lpi *block; @@ -296,6 +303,60 @@ static int gicv3_lpi_set_pendtable(void __iomem *rdist= _base) return 0; } =20 +static uint64_t gicv3_lpi_expected_proptable(void) +{ + return virt_to_maddr(lpi_data.lpi_property); +} + +static uint64_t gicv3_lpi_expected_pendtable(void) +{ + return virt_to_maddr(this_cpu(lpi_redist).pending_table); +} + +static bool gicv3_lpi_tables_match(void __iomem *rdist_base) +{ + uint64_t propbase, pendbase; + + if ( !lpi_data.lpi_property || !this_cpu(lpi_redist).pending_table ) + return false; + + propbase =3D readq_relaxed(rdist_base + GICR_PROPBASER); + pendbase =3D readq_relaxed(rdist_base + GICR_PENDBASER); + + return ((propbase & GICR_PROPBASER_XEN_MASK) =3D=3D + (gicv3_lpi_expected_proptable() & GICR_PROPBASER_XEN_MASK)) && + ((pendbase & GICR_PENDBASER_XEN_MASK) =3D=3D + (gicv3_lpi_expected_pendtable() & GICR_PENDBASER_XEN_MASK)); +} + +static int gicv3_lpi_disable_lpis(void __iomem *rdist_base) +{ + uint32_t reg =3D readl_relaxed(rdist_base + GICR_CTLR); + int ret; + + if ( !(reg & GICR_CTLR_ENABLE_LPIS) ) + return 0; + + writel_relaxed(reg & ~GICR_CTLR_ENABLE_LPIS, rdist_base + GICR_CTLR); + + /* + * The spec only guarantees programmability when we have observed the = bit + * cleared. Where clearing is supported, RWP must reach 0 before touch= ing + * PROPBASER/PENDBASER again. + */ + wmb(); + + ret =3D gicv3_do_wait_for_rwp(rdist_base, GICR_CTLR_RWP); + if ( ret ) + return ret; + + reg =3D readl_relaxed(rdist_base + GICR_CTLR); + if ( reg & GICR_CTLR_ENABLE_LPIS ) + return -EBUSY; + + return 0; +} + /* * Tell a redistributor about the (shared) property table, allocating one * if not already done. @@ -374,7 +435,21 @@ int gicv3_lpi_init_rdist(void __iomem * rdist_base) /* Make sure LPIs are disabled before setting up the tables. */ reg =3D readl_relaxed(rdist_base + GICR_CTLR); if ( reg & GICR_CTLR_ENABLE_LPIS ) - return -EBUSY; + { + if ( gicv3_lpi_tables_match(rdist_base) ) + return -EBUSY; + + ret =3D gicv3_lpi_disable_lpis(rdist_base); + if ( ret =3D=3D -EBUSY ) + { + printk(XENLOG_ERR + "GICv3: CPU%u: LPIs still enabled with unexpected redis= tributor tables\n", + smp_processor_id()); + return -EINVAL; + } + if ( ret ) + return ret; + } =20 ret =3D gicv3_lpi_set_pendtable(rdist_base); if ( ret ) diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index 17ff85ef5d..cae4ec28a1 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -275,7 +275,7 @@ static void gicv3_enable_sre(void) } =20 /* Wait for completion of a distributor/redistributor change */ -static void gicv3_do_wait_for_rwp(void __iomem *base, uint32_t rwp_bit) +int gicv3_do_wait_for_rwp(void __iomem *base, uint32_t rwp_bit) { uint32_t val; bool timeout =3D false; @@ -299,17 +299,22 @@ static void gicv3_do_wait_for_rwp(void __iomem *base,= uint32_t rwp_bit) } while ( 1 ); =20 if ( timeout ) + { dprintk(XENLOG_ERR, "RWP timeout\n"); + return -ETIMEDOUT; + } + + return 0; } =20 static void gicv3_dist_wait_for_rwp(void) { - gicv3_do_wait_for_rwp(GICD, GICD_CTLR_RWP); + (void)gicv3_do_wait_for_rwp(GICD, GICD_CTLR_RWP); } =20 static void gicv3_redist_wait_for_rwp(void) { - gicv3_do_wait_for_rwp(GICD_RDIST_BASE, GICR_CTLR_RWP); + (void)gicv3_do_wait_for_rwp(GICD_RDIST_BASE, GICR_CTLR_RWP); } =20 static void gicv3_wait_for_rwp(int irq) @@ -866,7 +871,7 @@ static bool gicv3_enable_lpis(void) return true; } =20 -static int __init gicv3_populate_rdist(void) +static int gicv3_populate_rdist(void) { int i; uint32_t aff; @@ -934,7 +939,7 @@ static int __init gicv3_populate_rdist(void) gicv3_set_redist_address(rdist_addr, procnum); =20 ret =3D gicv3_lpi_init_rdist(ptr); - if ( ret && ret !=3D -ENODEV ) + if ( ret && ret !=3D -ENODEV && ret !=3D -EBUSY ) { printk("GICv3: CPU%d: Cannot initialize LPIs: %u\n= ", smp_processor_id(), ret); diff --git a/xen/arch/arm/include/asm/gic.h b/xen/arch/arm/include/asm/gic.h index fbf0d69edd..84e146b832 100644 --- a/xen/arch/arm/include/asm/gic.h +++ b/xen/arch/arm/include/asm/gic.h @@ -301,6 +301,10 @@ extern int gicv_setup(struct domain *d); extern void gic_save_state(struct vcpu *v); extern void gic_restore_state(struct vcpu *v); =20 +#ifdef CONFIG_GICV3 +int gicv3_do_wait_for_rwp(void __iomem *base, uint32_t rwp_bit); +#endif + #ifdef CONFIG_SYSTEM_SUSPEND /* Suspend/resume */ extern int gic_suspend(void); --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095658; cv=pass; d=zohomail.com; s=zohoarc; b=eRbqdBacm9Uv2q2zWFsFpzHnZ/MPVrMjeN1ufDmYN4Do1E/8Vl5qzFCneLTdUVu3dCBQX+zzZ0VNXEmWeMJvSYWbAMu/WcJoryoudXFVEiDycYQhDkq0Mcdv/r20mfWeykL2XtemcBWVg9zxlsAwpMHrFEXFn8RhcDqvw8du3SM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095658; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dh3U6cg6sHHug97rKagQGLrX6CLgD+gnss748WpNxZQ=; b=FIIMlH00+SLUR6SEM2HWFUAHKZKUfEIVi8SSKDmZEwZeLBuuDe2w/ZQZ+WllC19qnxRtoSlopXq5idtRQyYbmqUw85nW8wT61ufBIJ0N8GwvqpPHszNKJ60OrV4vSQ7Y8S4vfujl9rZyLWM608ogEPbcZSQSCqYc7fB+zrTnDSk= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095658167727.4909777009992; Wed, 10 Jun 2026 05:47:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334262.1597360 (Exim 4.92) (envelope-from ) id 1wXIKn-0001cm-H3; Wed, 10 Jun 2026 12:47:05 +0000 Received: by outflank-mailman (output) from mailman id 1334262.1597360; Wed, 10 Jun 2026 12:47:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKn-0001bO-8d; Wed, 10 Jun 2026 12:47:05 +0000 Received: by outflank-mailman (input) for mailman id 1334262; Wed, 10 Jun 2026 12:45:26 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJC-0001BR-FD for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:26 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJB-007rkt-SI for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:25 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c63-e002-0a2a0a5209dd-0a2a4509d228-14 for ; Wed, 10 Jun 2026 14:45:25 +0200 Received: from [52.101.83.85] (helo=GVXPR05CU001.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c64-2497-0a2a45090019-3465535525e5-3 for ; Wed, 10 Jun 2026 14:45:25 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:22 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:22 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qy4btD1g19thg/5ndVWseDM7RDshRK1JCBA7zwZujGtdEJRN7Fz59HX4jvgUaFZlDp2rda4/ves/k9N34bbzVuBmy/HwXmU+uO0Ar98ZRem1e+V1p+8poJtFQPKH5wK/EO5zDhowoUtiUOoaOLiLT9uXXTbQ9ms9I0EUTkPLLg/y+gRlyFHzChM6fRlRXH7XVqoWSs6l5cpqfwGY6vwktpq+9n24XNuh7gcpXPN8MPC2XtE97/DDkwXsJEyCeiD+STjkInDRfMESFSM5B9kIdEQsXfNm0ch52botRrDi/9OcNcUR+Su4wYLY/4YR92fP97OYaolOn065twiNopjZjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dh3U6cg6sHHug97rKagQGLrX6CLgD+gnss748WpNxZQ=; b=QPiyIhKJiqhxJEK3o/SeEcpBPEOmEqmp7qBFrvn4WT1jSixx3jt/jhxV9W7LY8/9VOpCvTEH4/ADl6ovx8wA52yWR4JgtMAPXWaqyw37j0htcwZ9QXkkDF7SvKuCmSR5LGqbnduQJn1Sj/HfT10TiWNZM/8BWV/T/RjHT7/TUCH1umpx86WEeg2r+roGqs3I92X75kN5Z3hgsKUhKFnZ3YNK9oCiiuSAjiQMk9cbFZpyJQdWDqMvAuo7kBFWsl6kybBypoYjmMYtkhUi2aIPoVFIdlPnbm08bnTQEapV4gD7VjkwC2dtky0weMrsaArDdiHQPLQ1/kK/1pryNkR+sw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dh3U6cg6sHHug97rKagQGLrX6CLgD+gnss748WpNxZQ=; b=IB7KvO2sIvl96NC4E3kvRZwIg5d2te25hE/I5Y/4J3AgoQkGyFT/kJ7YdCmNyg0jTNpvm33ZWtyRJf9FEdgeskv/i4woJiqIRH5TWVx5coXhdMLjZyYFK5DM2j4uhkWK92rdTo/e4OAXegqZ4fzJOhqMcFiSLKCpp+XfqShQdzhWy2Kx3VDJspUEjZ8nEyH0hJYJD7T8PAxlb0XIpx5jFzmOmX4Bvq3CwnIk1AjnBjA41Ak7eDiWqFEXT/RBgweKe8IsfEjmSfBQznp8Oz321b3dsuEPiJczLHyPZkAHULWRwtz14O8KQLEN4iSzR2veKPJKB19oXRuuYV7gfeTjNw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Luca Fancellu Subject: [PATCH v11 04/13] xen/arm: gic-v3: Implement GICv3 suspend/resume functions Date: Wed, 10 Jun 2026 15:44:24 +0300 Message-ID: <51618361a911b527c1aaa4ab6a96bd1bd2239006.1781084290.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: ca39d394-72d2-4762-4d76-08dec6ee22ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|5023799004|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 58OIdrEZlRntCfwn5jBxKsoFpmLtkg4ySRJIZZjWAg+OayzHu0D3IvqsL1qsx1DaLcPIDgq5Tt1UgseHdOua8RSrA84EZFp1wOqK8HS1ANny71S69k4TezP9E7UoYtR0clDX4cISoQW5w6vVDAt81FijF4VbWhpIf50aUcNuN3IRFAIAkymgsppph2YSlDDFoKRu1xPG1EYAz9GMAgCjEdJ0rcXMKAkj69ZvDH5FdPEYt1zwJWgk/AKUpUw7fOxWmnRiKhhPKSSeimV0DSuo9uws8lU9hy61qKIdrjG7Pi0bkuJIyH/NwDgc2hyoYlUEUq++0lhKbpKPUKm9d24wjzZmz51tL9ps4cSs0pD6x/5LYbhzgha5fTNiqOQIeX9RfgZIwJaRBD1yRwEdu7OsYVNFF/AZC4C/4FF1tnVXw3aPmxk6Dddm7YhIwJVX4kIG8jnYT1lkN7jiEVeEzL7/8RpBdW1NA3seLNV/eROOUCWhLRgk7pwtO+E7mwi4IrdKt7p3T+7QAYg6LBD13cVFxAqCJ2KA87nCjG/sOCNSteB6HGNLfsuNBtkpXYUJRHe75HcKtF8SX2AMtAZN6PkTL8BKmIrscL7jml50ubMUCX5sQBlPJ4tKF95izTJ4KvCUQZ5arZTscpikeWCryI2nchi6XDP4G2687OlfI+iYm4Qhj4pPWFSvJJO2c7Fme9lP X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(5023799004)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iUP2L6+IoMutcS9Uq/hrcM6wAIGfQ/ck+U7znda4iobeP90rjFonrTdwsVNo?= =?us-ascii?Q?uyB3woarOW0hykaYhtJ3wFUxj3gIRGYcAIVHDbc+r2cvjXo6lhHRzg6o5KUG?= =?us-ascii?Q?69NF9gWYilrXoWNFcGT2G3yNF13G473TIjLLSLt6XcFhHHm2m1SGdf3lwGNs?= =?us-ascii?Q?mg0tTHAZvGZv3SyehPpvo0VozfSi7BRnPDSz2hJD0RdYMNp1Yl6BexUYw+JT?= =?us-ascii?Q?I8twd/GLD7zxT5DRpangoy+vH1tfAAMThXtwcKvNVqzZ6hrYnHQbH3sCUByN?= =?us-ascii?Q?dOQDsQ84U9kk/rF9Niz1WukV6eFmRPAoKRfcv+iBQzFcTpSGxyeHLwY3apjP?= =?us-ascii?Q?kzIOMRnMQ+FJfxR/3pBvtCasZj0lVMps/cjT8itBqN1uC6Y0PlPl6FZXL7rC?= =?us-ascii?Q?lXTlSx3hDUC15PaYp2/I4UUJ3Jf3nD0o0ZoM3VjhoY90i3j/tGK+qqDfg8U2?= =?us-ascii?Q?0PLmqSy8MloEwK7jgkjfRhJ1YhPbBKEZzAseaJ6vBuAfs8hsUNd3VkaMy0M1?= =?us-ascii?Q?PJb0RjRoy1lf5bH6WHHgs2dyRNrytp807nisIG20uBwA0tJ/cNjugQBLncwi?= =?us-ascii?Q?T0LR7/oeXhEoff3n/hiEE3wKgQ+9pwqMxrXsHOHfYuE2oUJeO+HikXSvCLCs?= =?us-ascii?Q?JhWLsaGGnTg5uA3YaKx4deCPOsCb1mpmAyvaZCTGJKGf0FyfgcqINgKMByS9?= =?us-ascii?Q?UOY7aRlFK7h/gHVa6MRdTvmZNveanzY1kizZU8Tid7l5Mb9X4aedp1B2SQyk?= =?us-ascii?Q?xMYjb2PfZAsDr9MnIKNxWXJIrr0e62PrrY8XD5KatRTnHtn8wS20Blvl9eUo?= =?us-ascii?Q?ONaEzXK59eslWeNKgizREJUZ5LdPPvS9tO3tkabbQuUf5wnJtUJqgiPC0++e?= =?us-ascii?Q?tAp4y5MYKdtre681+Fl/jwpuKWdMu65v9b/eQYBt3WSi6WbhdRM8CUa/oZFc?= =?us-ascii?Q?86MLhYWdhOzZZQxyStUclDloivesZlqjj0tr4/W88axidSC7KML1J0N5lxKW?= =?us-ascii?Q?R+8VxPtpiY8pZJWcar5qzV2QDzKNBPOJUFEfIkPUbogGK+lwSzPv0e01Myt4?= =?us-ascii?Q?PenRWBnScoDUWUtSVNplg43fqBMpolSeWPpl4Kdrkcw5PdvITBe8I+pWplmV?= =?us-ascii?Q?4of3Bs6ZAtjQPEc2CS6I5F4K4gVAgYK2xbiM+vnKg7FEsrRN2Payjy8WfWcw?= =?us-ascii?Q?zm9U4TscHjVT3KnrekQr85NgJkxN31iP/24bDZL1cF8Ur2NlU3LjwR8OJmIk?= =?us-ascii?Q?AXoQKS+pLQK/zXF3nFF5Ue80ooRJH6tvzYO2XqobZJiGmH3i/aHSEird02SP?= =?us-ascii?Q?fiCWRXrRVPpGtFKBf+l/m9swLqHfyqunS2qJKSuWaOqsEsD7KU3OTImG4KQy?= =?us-ascii?Q?VSsqRG9mfo0AL+C82i5o2FyeGYxSaDtuVnstbPOEtyvAg/oSjPzdredcziq9?= =?us-ascii?Q?Ewb5mW/rRiEhx9MtWs7e7Ec7aUjzUUH0zcss5V0WRF1R0fIynuptdw6TsqBs?= =?us-ascii?Q?JhOZR2OTMsQ6OTqjKQQ1Kk4BTf86ssKozAiMs+4i4s31t+0YKQ5FRHEq1KaZ?= =?us-ascii?Q?yFjpxTzvoTpcmnEXCEB6q0gfGt3BgUaOvIWc4KiufrqmnhGBJxskKAbC3HzU?= =?us-ascii?Q?mtH+7bYxo+Yf3FrkH4mOizHsoiTS3xR9XeTjze8NWw9OZm9o6WjUeeaf3u3W?= =?us-ascii?Q?i3nRFZ8cNNvegnaErGQrbo+pF5tLiiJNdq4nL6Dmfd8ZmeC3PBhrsA0SGiKy?= =?us-ascii?Q?EiXSr0+zaQ=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca39d394-72d2-4762-4d76-08dec6ee22ea X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:22.5409 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wLVB+1Yulgb/KqEtY2vH0zFW2aaaTaAqvXuI94XGybV51R5ItDrm5n9zf3bpPzYezK32L0OXVsh9IOpIsUtH9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-bad1c0/1781095525-4015DA53-57EBD25A/0/0 X-purgate-type: clean X-purgate-size: 21035 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095660516154100 Content-Type: text/plain; charset="utf-8" System suspend may lead to a state where GIC would be powered down. Therefore, Xen should save/restore the context of GIC on suspend/resume. Note that the context consists of states of registers which are controlled by the hypervisor. Other GIC registers which are accessible by guests are saved/restored on context switch. Before continuing suspend, also verify that the physical CPU interface has no Group 1 active-priority state left. Use ICC_CTLR_EL1.PRIbits to decide which ICC_AP1R_EL1 registers are implemented, so Xen does not read an unimplemented AP1R register. Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in V10: - abort suspend when the physical Group 1 active-priority state is still present, deriving accessible ICC_AP1R_EL1 registers from ICC_CTLR_EL1.PRIbits; - re-enable the redistributor before restoring CPU and virtual interface state on the suspend abort path; - panic if the redistributor cannot be re-enabled on the suspend abort path; - avoid saving/restoring reserved GICD_IPRIORITYR and GICD_IROUTER entries for a partially populated last SPI block; - disable Distributor group forwarding while preserving affinity routing state before restoring Distributor configuration; - disable SPI/eSPI forwarding and wait for RWP before restoring GICD_ICFGR.Int_config. Changes in V9: - fix the suspend-context comment typo and split dist_ctx declarations; - restore ICC_IGRPEN1_EL1 on the suspend error path; - re-initialize GICD_IGROUPRnE during resume; - restore GICD_IROUTER only after re-enabling ARE_NS during resume. Changes in V8: - use right rdist base for prop/pend baser and ctrl Changes in V7: - restore LPI regs on resume - add timeout during redist disabling - squash with suspend/resume handling for GICv3 eSPI registers - drop ITS guard paths so suspend/resume always runs; switch missing ctx allocation to panic - trim TODO comments; narrow redistributor storage to PPI icfgr - keep distributor context allocation even without ITS; adjust resume to use GENMASK(31, 0) for clearing enables - drop storage of the SGI configuration register, as SGIs are always edge-triggered --- xen/arch/arm/gic-v3-lpi.c | 3 + xen/arch/arm/gic-v3.c | 458 ++++++++++++++++++++++- xen/arch/arm/include/asm/arm64/sysregs.h | 5 + xen/arch/arm/include/asm/gic_v3_defs.h | 3 + 4 files changed, 466 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/gic-v3-lpi.c b/xen/arch/arm/gic-v3-lpi.c index 847da26ff7..a63c8c4979 100644 --- a/xen/arch/arm/gic-v3-lpi.c +++ b/xen/arch/arm/gic-v3-lpi.c @@ -467,6 +467,9 @@ static int cpu_callback(struct notifier_block *nfb, uns= igned long action, switch ( action ) { case CPU_UP_PREPARE: + if ( system_state =3D=3D SYS_STATE_resume ) + break; + rc =3D gicv3_lpi_allocate_pendtable(cpu); if ( rc ) printk(XENLOG_ERR "Unable to allocate the pendtable for CPU%lu= \n", diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index cae4ec28a1..be223dd915 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -1081,12 +1081,12 @@ out: return res; } =20 -static void gicv3_hyp_disable(void) +static void gicv3_hyp_enable(bool enable) { register_t hcr; =20 hcr =3D READ_SYSREG(ICH_HCR_EL2); - hcr &=3D ~GICH_HCR_EN; + hcr =3D enable ? (hcr | GICH_HCR_EN) : (hcr & ~GICH_HCR_EN); WRITE_SYSREG(hcr, ICH_HCR_EL2); isb(); } @@ -1193,7 +1193,7 @@ static void gicv3_disable_interface(void) spin_lock(&gicv3.lock); =20 gicv3_cpu_disable(); - gicv3_hyp_disable(); + gicv3_hyp_enable(false); =20 spin_unlock(&gicv3.lock); } @@ -1929,6 +1929,450 @@ static bool gic_dist_supports_lpis(void) return (readl_relaxed(GICD + GICD_TYPER) & GICD_TYPE_LPIS); } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +/* This struct represents a block of 32 IRQs */ +struct dist_irq_block { + uint32_t icfgr[2]; + uint32_t ipriorityr[8]; + uint64_t irouter[32]; + uint32_t isactiver; + uint32_t isenabler; +}; + +struct redist_ctx { + uint32_t ctlr; + uint32_t icfgr; /* only PPIs stored */ + uint32_t igroupr; + uint32_t ipriorityr[8]; + uint32_t isactiver; + uint32_t isenabler; + + uint64_t pendbase; + uint64_t propbase; +}; + +/* GICv3 registers to be saved/restored on system suspend/resume */ +struct gicv3_ctx { + struct dist_ctx { + uint32_t ctlr; + struct dist_irq_block *irqs; + struct dist_irq_block *espi_irqs; + } dist; + + /* have only one rdist structure for last running CPU during suspend */ + struct redist_ctx rdist; + + struct cpu_ctx { + uint32_t ctlr; + uint32_t pmr; + uint32_t bpr; + uint32_t sre_el2; + uint32_t grpen; + } cpu; +}; + +static struct gicv3_ctx gicv3_ctx; + +static void __init gicv3_alloc_context(void) +{ + uint32_t blocks =3D DIV_ROUND_UP(gicv3_info.nr_lines, 32); + + /* The spec allows for systems without any SPIs */ + if ( blocks > 1 ) + { + gicv3_ctx.dist.irqs =3D xzalloc_array(struct dist_irq_block, block= s - 1); + if ( !gicv3_ctx.dist.irqs ) + panic("Failed to allocate memory for GICv3 suspend context\n"); + } + +#ifdef CONFIG_GICV3_ESPI + if ( !gic_number_espis() ) + return; + + blocks =3D gic_number_espis() / 32; + gicv3_ctx.dist.espi_irqs =3D xzalloc_array(struct dist_irq_block, bloc= ks); + if ( !gicv3_ctx.dist.espi_irqs ) + panic("Failed to allocate memory for GICv3 eSPI suspend context\n"= ); +#endif +} + +static int gicv3_disable_redist(void) +{ + void __iomem *waker =3D GICD_RDIST_BASE + GICR_WAKER; + s_time_t deadline; + + /* + * Avoid infinite loop if Non-secure does not have access to GICR_WAKE= R. + * See Arm IHI 0069H.b, 12.11.42 GICR_WAKER: + * When GICD_CTLR.DS =3D=3D 0 and an access is Non-secure accesses= to this + * register are RAZ/WI. + */ + if ( !(readl_relaxed(GICD + GICD_CTLR) & GICD_CTLR_DS) ) + return 0; + + deadline =3D NOW() + MILLISECS(1000); + + writel_relaxed(readl_relaxed(waker) | GICR_WAKER_ProcessorSleep, waker= ); + while ( (readl_relaxed(waker) & GICR_WAKER_ChildrenAsleep) =3D=3D 0 ) + { + if ( NOW() > deadline ) + { + printk("GICv3: Timeout waiting for redistributor to sleep\n"); + return -ETIMEDOUT; + } + cpu_relax(); + udelay(10); + } + + return 0; +} + +#define GET_SPI_REG_OFFSET(name, is_espi) \ + ((is_espi) ? GICD_##name##nE : GICD_##name) + +static void gicv3_store_spi_irq_block(struct dist_irq_block *irqs, + unsigned int i, unsigned int nr_irqs, + bool is_espi) +{ + void __iomem *base; + unsigned int irq, nr_priority_regs; + + ASSERT(nr_irqs && nr_irqs <=3D 32); + nr_priority_regs =3D DIV_ROUND_UP(nr_irqs, 4); + + base =3D GICD + GET_SPI_REG_OFFSET(ICFGR, is_espi) + i * sizeof(irqs->= icfgr); + irqs->icfgr[0] =3D readl_relaxed(base); + irqs->icfgr[1] =3D readl_relaxed(base + 4); + + base =3D GICD + GET_SPI_REG_OFFSET(IPRIORITYR, is_espi); + base +=3D i * sizeof(irqs->ipriorityr); + for ( irq =3D 0; irq < nr_priority_regs; irq++ ) + irqs->ipriorityr[irq] =3D readl_relaxed(base + 4 * irq); + + base =3D GICD + GET_SPI_REG_OFFSET(IROUTER, is_espi); + base +=3D i * sizeof(irqs->irouter); + for ( irq =3D 0; irq < nr_irqs; irq++ ) + irqs->irouter[irq] =3D readq_relaxed_non_atomic(base + 8 * irq); + + base =3D GICD + GET_SPI_REG_OFFSET(ISACTIVER, is_espi); + base +=3D i * sizeof(irqs->isactiver); + irqs->isactiver =3D readl_relaxed(base); + + base =3D GICD + GET_SPI_REG_OFFSET(ISENABLER, is_espi); + base +=3D i * sizeof(irqs->isenabler); + irqs->isenabler =3D readl_relaxed(base); +} + +static void gicv3_restore_spi_irq_config(struct dist_irq_block *irqs, + unsigned int i, unsigned int nr_i= rqs, + bool is_espi) +{ + void __iomem *base; + unsigned int irq, nr_priority_regs; + + ASSERT(nr_irqs && nr_irqs <=3D 32); + nr_priority_regs =3D DIV_ROUND_UP(nr_irqs, 4); + + base =3D GICD + GET_SPI_REG_OFFSET(ICFGR, is_espi) + i * sizeof(irqs->= icfgr); + writel_relaxed(irqs->icfgr[0], base); + writel_relaxed(irqs->icfgr[1], base + 4); + + base =3D GICD + GET_SPI_REG_OFFSET(IPRIORITYR, is_espi); + base +=3D i * sizeof(irqs->ipriorityr); + for ( irq =3D 0; irq < nr_priority_regs; irq++ ) + writel_relaxed(irqs->ipriorityr[irq], base + 4 * irq); +} + +static void gicv3_restore_spi_irq_routing(struct dist_irq_block *irqs, + unsigned int i, unsigned int nr_= irqs, + bool is_espi) +{ + void __iomem *base; + unsigned int irq; + + ASSERT(nr_irqs && nr_irqs <=3D 32); + + base =3D GICD + GET_SPI_REG_OFFSET(IROUTER, is_espi); + base +=3D i * sizeof(irqs->irouter); + for ( irq =3D 0; irq < nr_irqs; irq++ ) + writeq_relaxed_non_atomic(irqs->irouter[irq], base + 8 * irq); +} + +static void gicv3_disable_spi_irq_block(unsigned int i, bool is_espi) +{ + void __iomem *base; + + base =3D GICD + GET_SPI_REG_OFFSET(ICENABLER, is_espi) + i * 4; + writel_relaxed(GENMASK(31, 0), base); +} + +static void gicv3_restore_spi_irq_state(struct dist_irq_block *irqs, + unsigned int i, bool is_espi) +{ + void __iomem *base; + + base =3D GICD + GET_SPI_REG_OFFSET(ISENABLER, is_espi); + base +=3D i * sizeof(irqs->isenabler); + writel_relaxed(irqs->isenabler, base); + + base =3D GICD + GET_SPI_REG_OFFSET(ICACTIVER, is_espi) + i * 4; + writel_relaxed(GENMASK(31, 0), base); + + base =3D GICD + GET_SPI_REG_OFFSET(ISACTIVER, is_espi); + base +=3D i * sizeof(irqs->isactiver); + writel_relaxed(irqs->isactiver, base); +} + +static int gicv3_check_ap1r(unsigned int n, register_t apr) +{ + if ( !apr ) + return 0; + + printk(XENLOG_ERR "GICv3: suspend aborted: ICC_AP1R%u_EL1=3D%#" + PRIregister"\n", n, apr); + + return -EBUSY; +} + +static int gicv3_check_active_priorities(register_t ctlr) +{ + unsigned int pribits =3D MASK_EXTR(ctlr, ICC_CTLR_EL1_PRIBITS_MASK) + = 1; + int ret; + + /* + * Xen enables physical Group 1 interrupts through ICC_IGRPEN1_EL1, + * so only the physical Group 1 active-priority registers are relevant + * here. Use ICC_CTLR_EL1.PRIbits for the physical CPU interface, not + * ICH_VTR_EL2, which describes the virtual interface. ICC_AP1R1_EL1 is + * only implemented with at least 6 physical priority bits, and + * ICC_AP1R2_EL1/ICC_AP1R3_EL1 with at least 7. + */ + switch ( pribits ) + { + case 8: + case 7: + ret =3D gicv3_check_ap1r(3, READ_SYSREG(ICC_AP1R3_EL1)); + if ( ret ) + return ret; + ret =3D gicv3_check_ap1r(2, READ_SYSREG(ICC_AP1R2_EL1)); + if ( ret ) + return ret; + /* Fall through */ + case 6: + ret =3D gicv3_check_ap1r(1, READ_SYSREG(ICC_AP1R1_EL1)); + if ( ret ) + return ret; + /* Fall through */ + default: + return gicv3_check_ap1r(0, READ_SYSREG(ICC_AP1R0_EL1)); + } +} + +static int gicv3_suspend(void) +{ + unsigned int i, nr_irqs; + void __iomem *base; + int ret; + struct redist_ctx *rdist =3D &gicv3_ctx.rdist; + + /* Save GICC configuration */ + gicv3_ctx.cpu.ctlr =3D READ_SYSREG(ICC_CTLR_EL1); + gicv3_ctx.cpu.pmr =3D READ_SYSREG(ICC_PMR_EL1); + gicv3_ctx.cpu.bpr =3D READ_SYSREG(ICC_BPR1_EL1); + gicv3_ctx.cpu.sre_el2 =3D READ_SYSREG(ICC_SRE_EL2); + gicv3_ctx.cpu.grpen =3D READ_SYSREG(ICC_IGRPEN1_EL1); + + gicv3_disable_interface(); + + ret =3D gicv3_check_active_priorities(gicv3_ctx.cpu.ctlr); + if ( ret ) + goto out_enable_iface; + + ret =3D gicv3_disable_redist(); + if ( ret ) + goto out_enable_iface; + + /* Save GICR configuration */ + gicv3_redist_wait_for_rwp(); + + base =3D GICD_RDIST_BASE; + + rdist->ctlr =3D readl_relaxed(base + GICR_CTLR); + + rdist->propbase =3D readq_relaxed(base + GICR_PROPBASER); + rdist->pendbase =3D readq_relaxed(base + GICR_PENDBASER); + + base =3D GICD_RDIST_SGI_BASE; + + /* Save priority on PPI and SGI interrupts */ + for ( i =3D 0; i < NR_GIC_LOCAL_IRQS / 4; i++ ) + rdist->ipriorityr[i] =3D readl_relaxed(base + GICR_IPRIORITYR0 + 4= * i); + + rdist->isactiver =3D readl_relaxed(base + GICR_ISACTIVER0); + rdist->isenabler =3D readl_relaxed(base + GICR_ISENABLER0); + rdist->igroupr =3D readl_relaxed(base + GICR_IGROUPR0); + rdist->icfgr =3D readl_relaxed(base + GICR_ICFGR1); + + /* Save GICD configuration */ + gicv3_dist_wait_for_rwp(); + gicv3_ctx.dist.ctlr =3D readl_relaxed(GICD + GICD_CTLR); + + for ( i =3D 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ ) + { + nr_irqs =3D min(32U, gicv3_info.nr_lines - i * 32); + gicv3_store_spi_irq_block(gicv3_ctx.dist.irqs + i - 1, i, nr_irqs, + false); + } + +#ifdef CONFIG_GICV3_ESPI + for ( i =3D 0; i < gic_number_espis() / 32; i++ ) + gicv3_store_spi_irq_block(gicv3_ctx.dist.espi_irqs + i, i, 32, tru= e); +#endif + + return 0; + + out_enable_iface: + if ( gicv3_enable_redist() ) + panic("GICv3: Failed to re-enable redistributor after suspend abor= t\n"); + + gicv3_hyp_enable(true); + WRITE_SYSREG(gicv3_ctx.cpu.grpen, ICC_IGRPEN1_EL1); + isb(); + + return ret; +} + +static void gicv3_resume(void) +{ + int ret; + unsigned int i, nr_irqs; + uint32_t dist_ctlr; + void __iomem *base; + struct redist_ctx *rdist =3D &gicv3_ctx.rdist; + + dist_ctlr =3D gicv3_ctx.dist.ctlr & GICD_CTLR_ARE_NS; + + /* Disable group forwarding while preserving affinity routing state. */ + writel_relaxed(dist_ctlr, GICD + GICD_CTLR); + gicv3_dist_wait_for_rwp(); + + /* + * IHI0069H.b 12.9.9 says changing GICD_ICFGR.Int_config + * while the interrupt is individually enabled is UNPREDICTABLE. + * Disable SPIs first; 4.7.1 defines GICD_ICENABLER, n > 0, + * as the per-SPI disable mechanism. + */ + for ( i =3D 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ ) + gicv3_disable_spi_irq_block(i, false); + +#ifdef CONFIG_GICV3_ESPI + for ( i =3D 0; i < gic_number_espis() / 32; i++ ) + gicv3_disable_spi_irq_block(i, true); +#endif + + gicv3_dist_wait_for_rwp(); + + for ( i =3D NR_GIC_LOCAL_IRQS; i < gicv3_info.nr_lines; i +=3D 32 ) + writel_relaxed(GENMASK(31, 0), GICD + GICD_IGROUPR + (i / 32) * 4); + + for ( i =3D 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ ) + { + nr_irqs =3D min(32U, gicv3_info.nr_lines - i * 32); + gicv3_restore_spi_irq_config(gicv3_ctx.dist.irqs + i - 1, i, nr_ir= qs, + false); + } + +#ifdef CONFIG_GICV3_ESPI + for ( i =3D 0; i < gic_number_espis() / 32; i++ ) + { + writel_relaxed(GENMASK(31, 0), GICD + GICD_IGROUPRnE + i * 4); + gicv3_restore_spi_irq_config(gicv3_ctx.dist.espi_irqs + i, i, 32, + true); + } +#endif + + if ( dist_ctlr ) + { + for ( i =3D 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ ) + { + nr_irqs =3D min(32U, gicv3_info.nr_lines - i * 32); + gicv3_restore_spi_irq_routing(gicv3_ctx.dist.irqs + i - 1, i, + nr_irqs, false); + } + +#ifdef CONFIG_GICV3_ESPI + for ( i =3D 0; i < gic_number_espis() / 32; i++ ) + gicv3_restore_spi_irq_routing(gicv3_ctx.dist.espi_irqs + i, i, + 32, true); +#endif + } + + for ( i =3D 1; i < DIV_ROUND_UP(gicv3_info.nr_lines, 32); i++ ) + gicv3_restore_spi_irq_state(gicv3_ctx.dist.irqs + i - 1, i, false); + +#ifdef CONFIG_GICV3_ESPI + for ( i =3D 0; i < gic_number_espis() / 32; i++ ) + gicv3_restore_spi_irq_state(gicv3_ctx.dist.espi_irqs + i, i, true); +#endif + + writel_relaxed(gicv3_ctx.dist.ctlr, GICD + GICD_CTLR); + gicv3_dist_wait_for_rwp(); + + ret =3D gicv3_lpi_init_rdist(GICD_RDIST_BASE); + /* + * If LPIs are already enabled, assume firmware or the still-powered + * redistributor has valid PROPBASER/PENDBASER and skip reprogramming. + * Return -EBUSY so callers can ignore this case. + */ + if ( ret && ret !=3D -ENODEV && ret !=3D -EBUSY ) + panic("GICv3: Failed to re-initialize LPIs during resume\n"); + else if ( ret =3D=3D -EBUSY ) /* extra checks, just to be sure */ + { + base =3D GICD_RDIST_BASE; + if ( readq_relaxed(base + GICR_PROPBASER) !=3D rdist->propbase || + readq_relaxed(base + GICR_PENDBASER) !=3D rdist->pendbase ) + panic("GICv3: LPIs already enabled with unexpected PROPBASER/P= ENDBASER during resume\n"); + } + + /* Restore GICR (Redistributor) configuration */ + if ( gicv3_enable_redist() ) + panic("GICv3: Failed to re-enable redistributor during resume\n"); + + base =3D GICD_RDIST_SGI_BASE; + + writel_relaxed(GENMASK(31, 0), base + GICR_ICENABLER0); + gicv3_redist_wait_for_rwp(); + + for ( i =3D 0; i < NR_GIC_LOCAL_IRQS / 4; i++ ) + writel_relaxed(rdist->ipriorityr[i], base + GICR_IPRIORITYR0 + i *= 4); + + writel_relaxed(rdist->isactiver, base + GICR_ISACTIVER0); + writel_relaxed(rdist->igroupr, base + GICR_IGROUPR0); + writel_relaxed(rdist->icfgr, base + GICR_ICFGR1); + + gicv3_redist_wait_for_rwp(); + + writel_relaxed(rdist->isenabler, base + GICR_ISENABLER0); + writel_relaxed(rdist->ctlr, GICD_RDIST_BASE + GICR_CTLR); + + gicv3_redist_wait_for_rwp(); + + WRITE_SYSREG(gicv3_ctx.cpu.sre_el2, ICC_SRE_EL2); + isb(); + + /* Restore CPU interface (System registers) */ + WRITE_SYSREG(gicv3_ctx.cpu.pmr, ICC_PMR_EL1); + WRITE_SYSREG(gicv3_ctx.cpu.bpr, ICC_BPR1_EL1); + WRITE_SYSREG(gicv3_ctx.cpu.ctlr, ICC_CTLR_EL1); + WRITE_SYSREG(gicv3_ctx.cpu.grpen, ICC_IGRPEN1_EL1); + isb(); + + gicv3_hyp_init(); +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ + /* Set up the GIC */ static int __init gicv3_init(void) { @@ -2003,6 +2447,10 @@ static int __init gicv3_init(void) =20 gicv3_hyp_init(); =20 +#ifdef CONFIG_SYSTEM_SUSPEND + gicv3_alloc_context(); +#endif + out: spin_unlock(&gicv3.lock); =20 @@ -2042,6 +2490,10 @@ static const struct gic_hw_operations gicv3_ops =3D { #endif .iomem_deny_access =3D gicv3_iomem_deny_access, .do_LPI =3D gicv3_do_LPI, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend =3D gicv3_suspend, + .resume =3D gicv3_resume, +#endif }; =20 static int __init gicv3_dt_preinit(struct dt_device_node *node, const void= *data) diff --git a/xen/arch/arm/include/asm/arm64/sysregs.h b/xen/arch/arm/includ= e/asm/arm64/sysregs.h index f3c11d871e..2261620316 100644 --- a/xen/arch/arm/include/asm/arm64/sysregs.h +++ b/xen/arch/arm/include/asm/arm64/sysregs.h @@ -16,6 +16,11 @@ #define ICC_SRE_EL1 S3_0_C12_C12_5 #define ICC_IGRPEN1_EL1 S3_0_C12_C12_7 =20 +#define ICC_AP1R0_EL1 S3_0_C12_C9_0 +#define ICC_AP1R1_EL1 S3_0_C12_C9_1 +#define ICC_AP1R2_EL1 S3_0_C12_C9_2 +#define ICC_AP1R3_EL1 S3_0_C12_C9_3 + #define ICH_VSEIR_EL2 S3_4_C12_C9_4 #define ICC_SRE_EL2 S3_4_C12_C9_5 #define ICH_HCR_EL2 S3_4_C12_C11_0 diff --git a/xen/arch/arm/include/asm/gic_v3_defs.h b/xen/arch/arm/include/= asm/gic_v3_defs.h index 3714cfeb7d..f741587322 100644 --- a/xen/arch/arm/include/asm/gic_v3_defs.h +++ b/xen/arch/arm/include/asm/gic_v3_defs.h @@ -94,12 +94,15 @@ #define GICD_TYPE_LPIS (1U << 17) =20 #define GICD_CTLR_RWP (1UL << 31) +#define GICD_CTLR_DS (1U << 6) #define GICD_CTLR_ARE_NS (1U << 4) #define GICD_CTLR_ENABLE_G1A (1U << 1) #define GICD_CTLR_ENABLE_G1 (1U << 0) #define GICD_IROUTER_SPI_MODE_ANY (1UL << 31) =20 #define GICC_CTLR_EL1_EOImode_drop (1U << 1) +#define ICC_CTLR_EL1_PRIBITS_SHIFT 8 +#define ICC_CTLR_EL1_PRIBITS_MASK (0x7U << ICC_CTLR_EL1_PRIBITS_SHIFT) =20 #define GICR_WAKER_ProcessorSleep (1U << 1) #define GICR_WAKER_ChildrenAsleep (1U << 2) --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095645; cv=pass; d=zohomail.com; s=zohoarc; b=DkOS/v2vk15ts7EJKplFm+DTFdxva2+WdMV9PMrkF3nPhSLem0coL68N9Pqwlea1mONfNNfzKyTn+SMQ8wnOllSg6RBcmVoB7EXVge+hSeG/mgtpyEDcrt22yuGOw65BITn2Nv+3ilU/bGS6+Q5x5W0Z7PhUVG5lPTHj6IsrXac= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095645; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4t1Xm4aK6uMytKQzSuYsfAastWOi/MneAuLBcif8+7Y=; b=dm+u1KIrAAwdFw03qY2xUlgCdCxVAUzn0chBTvehNIek+ghyYfo600SNIga3lXeZhcyKr+WGFvjOBWwyyu4WuDmZNKWmCCnqlOUu0tCBDYXxtomrrtFjpJHSZ8eNGFmDspYRyYiJ/+DhprJFPyD7py3dASDxGSs9+vZ4qi7etmE= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095645497798.0232497958732; Wed, 10 Jun 2026 05:47:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334264.1597368 (Exim 4.92) (envelope-from ) id 1wXIKn-0001jp-Tg; Wed, 10 Jun 2026 12:47:05 +0000 Received: by outflank-mailman (output) from mailman id 1334264.1597368; Wed, 10 Jun 2026 12:47:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKn-0001he-JJ; Wed, 10 Jun 2026 12:47:05 +0000 Received: by outflank-mailman (input) for mailman id 1334264; Wed, 10 Jun 2026 12:45:28 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJE-0001Bl-81 for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:28 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJD-007rkt-Kn for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:27 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c60-e002-0a2a0a5209dd-0a2a450ce894-28 for ; Wed, 10 Jun 2026 14:45:27 +0200 Received: from [40.107.162.84] (helo=PA4PR04CU001.outbound.protection.outlook.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c67-62f1-0a2a450c0019-286ba25465a7-3 for ; Wed, 10 Jun 2026 14:45:27 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:25 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:25 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XH0n3vjXwU05fwa3RYrpg47RDGakN+O+g/GkMBgEH3GV/EMSMA/BrE2WeQVBtG714k+hM5CcPoEGyltcEFA0vu0PePdK/k012TGL0Lb3bLzqpCqCpz7gihaqNp5/ByPQvkI+Y0bp3n9QJUahnf7b3xgfrUu8rndtIOKKfzkc967IPEKCSRGzADd1a6S33TefQRzoTYNZrFVAOvbBMtnI4AePsfDhav79x7muKzChvH5V0InUZ+m52o2jgaLrmrGitj8lDwGVjFIQRxo7aPJKBCiQVR+gqp3QgRrd8lNmZQzaiiuspoewgWpABHr248+uAYHpb90hkyob77I8xlMu7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4t1Xm4aK6uMytKQzSuYsfAastWOi/MneAuLBcif8+7Y=; b=r1q9FwhoFjZU4jcAjbXbvX66gRVlMTh5xAIYZhV//frKYZ0e6ZcBze9r0EjwshZIgOnd2W3CmezNiC2c11nQWFo9y9Z7mgM+8qT+h8txbzu+p6Q4eNK7P1CDcum6az/x0Pak4vErVq+Mijp6Gmo7RAMHGFfAT3OlzINBPW7va0z3xZnUwAuC2GlZk8/E17Zq6hJ0h80SUJs7MdlghMYyuncAKA8F6V+j9L95LF0HtpPRa8zfeIzjNM1BIrQ8oI90U467Tdsrds9nq/xnQj6zu2Q8ri7vcz17XSTs9MLpsiXTwb0tQvOJZPBVs+yO8DUc40NExMZdvv027HuPOVAV3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4t1Xm4aK6uMytKQzSuYsfAastWOi/MneAuLBcif8+7Y=; b=Z2xYLGRYPkGXxQwxDOXF/Bv66E6wFw0LSiqz5kJ+3gCdzmW187R72KZCrMEuRGzylpg6T16TO7+Fn/9I/3CnSgVFx9/9jreYVYU9OiSQZa1M5u7SSjoB7meP45OQD0CXeCcaoxVIUcBD0Ms0BxPHXP/h7kVakuJsdXjleBE67+9mg1Eqb6XVcC/ZPgvXurHzok+1SCg4BjVSKD4C2Qz/ymuONdfY9bEL6YrB29j2y7yZKw6CMigjFsXbbc9/b5lVFmltXLT8ifmcPkmFOyOigeIBrJmwBghE3PqWcM7PkWPukqt2isVUvrta8z/C8Kt6NrHzGaJ9oDbbOHt2Qd05Cw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Luca Fancellu Subject: [PATCH v11 05/13] xen/arm: gic-v3: add ITS suspend/resume support Date: Wed, 10 Jun 2026 15:44:25 +0300 Message-ID: <1e1bc01dad04d8b4e94af1cffc0afef51dc030e2.1781084290.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: dc3e2d95-a38f-4a51-4f4c-08dec6ee2485 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|7416014|376014|3023799007|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: Q7S7CoxM+LJEIRmx90GfBtOwlhR1+EaMSWPqOMZMNGTai4TULCEzY/5NXQrOZOQETZZDTb0gZ512NUaUZz+MovmGy9ePLzHKH3L7CSut52WcTptZ6zHGoUB+6XoyVCDy5Ni2uqtvFvtIYJzaS6WmtMkKFjMMyXqJt0+2rv2sF7BYBupkZrDPYM/yaYa32mh1g8CeNdyx2s1/d3hlkTcWXIA680dtbhMgId4gxQXowTjexBdXJhYp++Sz2PjwY9pqCnvqfjpWdFymOb1Lg3Xj1BpUvZ+gvRfzud3J4oKES+vxqwpB9/AHjiX/5r0nMpO7wuQka4M+FJEYdSGqpFXv1za8tOzBZiuvxNe64EXsap8sE+Balyvknp5jxnpCt2EkbeEVhro4NUF41gdzMg5mAVXuH9L+a6DbcGwEUqNK96CVaV5DiQr2ZMLbbS7CVnowSxS0xTdOXW0KZ30WC3lOZlCbiEI+TT+hNjmjWVr4pG2TPyn4uzXrUEZn/GeRzIQFztItlH/5PlJCflmJevPeAUNVB41IvxlJMo+cbqEeVrZp5Dzzy9SF8lhV+zqCeAy3xMfZkqi53GP33Vy67JCGE8UMumAfUdj6VBcP8pqnWT3ynM60jb+VVOuetUWkfoPlMLSXlfVwS3gg5ng7yofQLZ3izhWrojDw9mpxBdvnFdAjHBtNNbZqBhNYnWVXvm0w X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(7416014)(376014)(3023799007)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/w0eVdyQGbDQYXUqymz+rM1c/3NQdeDR0ujAgM/vV3Lv7s4klYu8qVffzyDD?= =?us-ascii?Q?Qpq2dINklpFfnix6oV5SZy4Wn+iTdYk+q5iD7jAO3W9gXYmeKh9k3IfZ04aR?= =?us-ascii?Q?lFrpPD7gMtrq1BwC/rcExIF/48+Ek85lO/zjbd5bEodEilnZUnlgrxLH7yk+?= =?us-ascii?Q?MiQwEyUrfgNwpHh7CtfznSF67iidSkRI8bE961vmbKMpEACPwM6+ZmEFt8Jt?= =?us-ascii?Q?A9oevqzAwDivcQqESsVyfEGpph3ERPICM1zoGVTMdcIv0bsq0AYhrUEyG/gV?= =?us-ascii?Q?wzdSUfRbSdi4D17cdBouQdxg6uOx+xqbfaOBijWNOfruAfIrnr7R4YcD8FWo?= =?us-ascii?Q?EraAZ4mKRJfis9aPiEAbfOiFEd49fCLN9WW2/HJOque/U6Tn1AspH9rcXCNN?= =?us-ascii?Q?JrHsLCbsJclwQY3Ngo0Te1W+o3mZknIfEqcWWQAK0MsMuBPM0ZozX7422780?= =?us-ascii?Q?OpaH4+JhVolIDstaTAqI0WaQYSqfSnI8u5OMvyj14B6mDsV9dF59g+0Wv4iS?= =?us-ascii?Q?F3Be8NnOH/t6G2o/gEeM1skmgHNzxe9HXJHpLhkIsT36/JKvSvcfqVWAWy4N?= =?us-ascii?Q?EAJtAr226H/HWrfJozTrMMozVUzkDlrv/VQcLv0rA0QWifKAAMEqKiiR4veF?= =?us-ascii?Q?82LpMSE7MnwOSoaEmhw/OU2EgZQh1TKNLVFNoWwrCW8rukEMPyYmMiqWD5EH?= =?us-ascii?Q?486wz/amP5cM6euk8dF/Ty3ZphS3NVQbgJi1yhY0DxXM2fsTodFNX/19ZTsw?= =?us-ascii?Q?rkGugQ0zPYGgKYxL0OhH5RRB8atR7d923Oqtnuf0IpL10zP/y6eHNbcE2tOk?= =?us-ascii?Q?c9PVM8u7RjH15IRRjNeZ06wkmVQ/LdV+OOAXUVFymfL+ha/w2j/cK/IfBYpV?= =?us-ascii?Q?FQv7QF6gE7ExB7++3Eq6A/P/c7OU8jJ0mQr8cjQEI8x3rf/ScEw7xoRqPb3K?= =?us-ascii?Q?cnekAbYVEBcVKEsytCARfvuM+isGJDzxiqQmFnl4o83P4VT/E4xknYtiRvWx?= =?us-ascii?Q?b0bU4eIO7ailaT7MwF6fjCMk9fQGYP2XbrpVDN8bjoqkOKGmawfc2AmjECod?= =?us-ascii?Q?I2LdtcB2qsvLHUlIU4mrxjvWAohNObXGrt0DU2CwZE7uiPaCmNIlpbVoe4vS?= =?us-ascii?Q?OZc6UHp1m7wDTJN3g29gVZ5Vejs607cZSVLWcgH3Pl5HzcOE0ttO/f9lOyxI?= =?us-ascii?Q?utMAbn4a3MDuwkkEElT6q7MY8fNCc2reEyEIXO7pQ64RR0rz0eRprw4fT01f?= =?us-ascii?Q?pqy0UkmyCphyRtCsYn522zlgqq3NgdMVciypk1Gw0ZOUr4dbj59cgeMq9Zmf?= =?us-ascii?Q?XqiWCzUJ8EwsLQxwfK+OTcXKKf2PELJa5onc/dTfHomiGCPK9agaWhzfJWQN?= =?us-ascii?Q?DXpq4ZfkUgkHqol6tBTntEHYMeVTqO55NLUhkPa64FPKQCNi3tb5fQ5yCRzY?= =?us-ascii?Q?kY3Ilwm5pwCaS/USAGFhY+6SanqV5ULHFHsEzqXjWAlr3FgGTwCQClz//UrU?= =?us-ascii?Q?1thhsr//+qxq7x+2/o9VdrYPJ0Y2FEtCkFXlR6yBLeaK+GKWSWAdiTxIkIi5?= =?us-ascii?Q?WUVG4o8JRzAdPd5tfUe3MAKeOlZjLKcrAqnQLekxzSJenPnoygki3js5iIli?= =?us-ascii?Q?KBRs514EMWcQyJsq+UcNAML79N72Gail85h3RH8d5tDNJXi7/tdeKjFEtKBU?= =?us-ascii?Q?oNGzXEdBwNkH+AnckhzqBFFQ8nbzMb6UxGJ+pCTe4HBKky5fQmtAukiWtl/w?= =?us-ascii?Q?mN1LduZDoQ=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc3e2d95-a38f-4a51-4f4c-08dec6ee2485 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:25.1911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FrxE3U82P20y9Dk+/x/SeyNY6FfyUrpEKLuqh/CaCIAXP+A5mP3jEQp3RUCyM7P6uAwBaun8IwslSoNTfjhUYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-d25034/1781095527-E3370CF5-5006A541/0/0 X-purgate-type: clean X-purgate-size: 11113 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095648508154100 Content-Type: text/plain; charset="utf-8" Handle system suspend/resume for GICv3 with an ITS present so LPIs keep working after firmware powers the GIC down. Save and restore the ITS CTLR, CBASER and BASER registers. On resume, re-establish the collection mapping only when the collection is held in the ITS itself. Memory-backed collections are restored through the restored GITS_BASER tables and must not be remapped unconditionally. Add list_for_each_entry_continue_reverse() in list.h for the ITS suspend error path that needs to roll back partially saved state. Based on Linux commit dba0bc7b76dc: "irqchip/gic-v3-its: Add ability to save/restore ITS state". Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in V10: - Replay MAPC on resume only for collections held in the ITS itself, as indicated by GITS_TYPER.HCC. Memory-backed collections are restored through GITS_BASER and are no longer remapped unconditionally. - Make the current Xen col_id =3D=3D cpu assumption explicit in the ITS resume path. - Use "unpredictable" instead of "undefined" in the CBASER/BASER restore comment. Changes in V9: - fix the ITS suspend/resume coding-style nits; - preserve the saved GITS_CTLR state while masking the read-only QUIESCENT bit. Changes in V8: - Reword the CBASER/CWRITER comment to match Xen and drop the stale Linux cmd_write reference. - Clarify the list_for_each_entry_continue_reverse() comment. - Factor out per-ITS helpers for collection setup and resume. - Restore each ITS and re-establish its collection mapping in the same loop, so a failed ITS resume is not followed by MAPC/SYNC on that un-restored instance. - panic in case when resume of an ITS failed - cleanup baser cache during suspend --- xen/arch/arm/gic-v3-its.c | 146 ++++++++++++++++++++++++-- xen/arch/arm/gic-v3.c | 11 +- xen/arch/arm/include/asm/gic_v3_its.h | 28 +++++ xen/include/xen/list.h | 14 +++ 4 files changed, 189 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c index 7560d46c6d..dd53209865 100644 --- a/xen/arch/arm/gic-v3-its.c +++ b/xen/arch/arm/gic-v3-its.c @@ -335,6 +335,22 @@ static int its_send_cmd_inv(struct host_its *its, return its_send_command(its, cmd); } =20 +static int gicv3_its_setup_collection_single(struct host_its *its, + unsigned int cpu) +{ + int ret; + + ret =3D its_send_cmd_mapc(its, cpu, cpu); + if ( ret ) + return ret; + + ret =3D its_send_cmd_sync(its, cpu); + if ( ret ) + return ret; + + return gicv3_its_wait_commands(its); +} + /* Set up the (1:1) collection mapping for the given host CPU. */ int gicv3_its_setup_collection(unsigned int cpu) { @@ -343,15 +359,7 @@ int gicv3_its_setup_collection(unsigned int cpu) =20 list_for_each_entry(its, &host_its_list, entry) { - ret =3D its_send_cmd_mapc(its, cpu, cpu); - if ( ret ) - return ret; - - ret =3D its_send_cmd_sync(its, cpu); - if ( ret ) - return ret; - - ret =3D gicv3_its_wait_commands(its); + ret =3D gicv3_its_setup_collection_single(its, cpu); if ( ret ) return ret; } @@ -1211,6 +1219,126 @@ int gicv3_its_init(void) return 0; } =20 +#ifdef CONFIG_SYSTEM_SUSPEND +int gicv3_its_suspend(void) +{ + struct host_its *its; + int ret; + + list_for_each_entry( its, &host_its_list, entry ) + { + unsigned int i; + void __iomem *base =3D its->its_base; + + /* + * By the time Xen reaches gic_suspend(), every domain is already = in + * SHUTDOWN_suspend, so ITS-targeting interrupt sources are expect= ed + * to have been quiesced by the owning OS before SYSTEM_SUSPEND. + */ + /* Preserve saved GITS_CTLR state, excluding read-only QUIESCENT. = */ + its->suspend_ctx.ctlr =3D readl_relaxed(base + GITS_CTLR) & + ~GITS_CTLR_QUIESCENT; + ret =3D gicv3_disable_its(its); + if ( ret ) + { + writel_relaxed(its->suspend_ctx.ctlr, base + GITS_CTLR); + goto err; + } + + its->suspend_ctx.cbaser =3D readq_relaxed(base + GITS_CBASER); + + for ( i =3D 0; i < GITS_BASER_NR_REGS; i++ ) + { + uint64_t baser =3D readq_relaxed(base + GITS_BASER0 + i * 8); + + its->suspend_ctx.baser[i] =3D 0; + + if ( !(baser & GITS_VALID_BIT) ) + continue; + + its->suspend_ctx.baser[i] =3D baser; + } + } + + return 0; + + err: + list_for_each_entry_continue_reverse( its, &host_its_list, entry ) + writel_relaxed(its->suspend_ctx.ctlr, its->its_base + GITS_CTLR); + + return ret; +} + +static int gicv3_its_resume_single(struct host_its *its, unsigned int cpu) +{ + void __iomem *base =3D its->its_base; + unsigned int i; + int ret; + uint64_t typer; + unsigned int col_id =3D cpu; /* Xen currently uses col_id =3D=3D cpu. = */ + + /* + * Make sure that the ITS is disabled. If it fails to quiesce, + * don't restore it since writing to CBASER or BASER + * registers is unpredictable according to the GIC v3 ITS + * Specification. + */ + WARN_ON(readl_relaxed(base + GITS_CTLR) & GITS_CTLR_ENABLE); + ret =3D gicv3_disable_its(its); + if ( ret ) + return ret; + + writeq_relaxed(its->suspend_ctx.cbaser, base + GITS_CBASER); + + /* + * Writing CBASER resets CREADR to 0, so reset CWRITER to + * keep the command queue pointers aligned. + */ + writeq_relaxed(0, base + GITS_CWRITER); + + /* Restore GITS_BASER from the value cache. */ + for ( i =3D 0; i < GITS_BASER_NR_REGS; i++ ) + { + uint64_t baser =3D its->suspend_ctx.baser[i]; + + if ( !(baser & GITS_VALID_BIT) ) + continue; + + writeq_relaxed(baser, base + GITS_BASER0 + i * 8); + } + + writel_relaxed(its->suspend_ctx.ctlr, base + GITS_CTLR); + + typer =3D readq_relaxed(base + GITS_TYPER); + + /* + * Only collections with IDs below HCC are held in the ITS itself + * and lose their state across an ITS reset/power loss. Memory-backed + * collections are restored by restoring GITS_BASER and must not be + * remapped here. + */ + if ( col_id < GITS_TYPER_HCC(typer) ) + return gicv3_its_setup_collection_single(its, cpu); + + return 0; +} + +void gicv3_its_resume(void) +{ + struct host_its *its; + unsigned int cpu =3D smp_processor_id(); + int ret; + + list_for_each_entry( its, &host_its_list, entry ) + { + ret =3D gicv3_its_resume_single(its, cpu); + if ( ret ) + panic("GICv3: ITS@%"PRIpaddr": failed to restore during resume= : %d\n", + its->addr, ret); + } +} + +#endif /* CONFIG_SYSTEM_SUSPEND */ =20 /* * Local variables: diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index be223dd915..05e42cdd55 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -2189,10 +2189,14 @@ static int gicv3_suspend(void) if ( ret ) goto out_enable_iface; =20 - ret =3D gicv3_disable_redist(); + ret =3D gicv3_its_suspend(); if ( ret ) goto out_enable_iface; =20 + ret =3D gicv3_disable_redist(); + if ( ret ) + goto out_its_resume; + /* Save GICR configuration */ gicv3_redist_wait_for_rwp(); =20 @@ -2232,6 +2236,9 @@ static int gicv3_suspend(void) =20 return 0; =20 + out_its_resume: + gicv3_its_resume(); + out_enable_iface: if ( gicv3_enable_redist() ) panic("GICv3: Failed to re-enable redistributor after suspend abor= t\n"); @@ -2358,6 +2365,8 @@ static void gicv3_resume(void) =20 gicv3_redist_wait_for_rwp(); =20 + gicv3_its_resume(); + WRITE_SYSREG(gicv3_ctx.cpu.sre_el2, ICC_SRE_EL2); isb(); =20 diff --git a/xen/arch/arm/include/asm/gic_v3_its.h b/xen/arch/arm/include/a= sm/gic_v3_its.h index fc5a84892c..0f8cb16e41 100644 --- a/xen/arch/arm/include/asm/gic_v3_its.h +++ b/xen/arch/arm/include/asm/gic_v3_its.h @@ -43,6 +43,11 @@ #define GITS_CTLR_QUIESCENT BIT(31, UL) #define GITS_CTLR_ENABLE BIT(0, UL) =20 +#define GITS_TYPER_HCC_SHIFT 24 +#define GITS_TYPER_HCC_MASK 0xffUL +#define GITS_TYPER_HCC(r) (((r) >> GITS_TYPER_HCC_SHIFT) & \ + GITS_TYPER_HCC_MASK) + #define GITS_TYPER_PTA BIT(19, UL) #define GITS_TYPER_DEVIDS_SHIFT 13 #define GITS_TYPER_DEVIDS_MASK (0x1fUL << GITS_TYPER_DEVIDS_SHIFT) @@ -129,6 +134,13 @@ struct host_its { spinlock_t cmd_lock; void *cmd_buf; unsigned int flags; +#ifdef CONFIG_SYSTEM_SUSPEND + struct suspend_ctx { + uint32_t ctlr; + uint64_t cbaser; + uint64_t baser[GITS_BASER_NR_REGS]; + } suspend_ctx; +#endif }; =20 /* Map a collection for this host CPU to each host ITS. */ @@ -204,6 +216,11 @@ uint64_t gicv3_its_get_cacheability(void); uint64_t gicv3_its_get_shareability(void); unsigned int gicv3_its_get_memflags(void); =20 +#ifdef CONFIG_SYSTEM_SUSPEND +int gicv3_its_suspend(void); +void gicv3_its_resume(void); +#endif + #else =20 #ifdef CONFIG_ACPI @@ -271,6 +288,17 @@ static inline int gicv3_its_make_hwdom_dt_nodes(const = struct domain *d, return 0; } =20 +#ifdef CONFIG_SYSTEM_SUSPEND +static inline int gicv3_its_suspend(void) +{ + return 0; +} + +static inline void gicv3_its_resume(void) +{ +} +#endif + #endif /* CONFIG_HAS_ITS */ =20 #endif diff --git a/xen/include/xen/list.h b/xen/include/xen/list.h index 98d8482dab..2aab274157 100644 --- a/xen/include/xen/list.h +++ b/xen/include/xen/list.h @@ -535,6 +535,20 @@ static inline void list_splice_init(struct list_head *= list, &(pos)->member !=3D (head); = \ (pos) =3D list_entry((pos)->member.next, typeof(*(pos)), member)) =20 +/** + * list_for_each_entry_continue_reverse - iterate backwards from the given= point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type backwards, starting from the element pr= evious + * to the current one in list order. + */ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for ((pos) =3D list_entry((pos)->member.prev, typeof(*(pos)), member);= \ + &(pos)->member !=3D (head); = \ + (pos) =3D list_entry((pos)->member.prev, typeof(*(pos)), member)) + /** * list_for_each_entry_from - iterate over list of given type from the * current point --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095656; cv=pass; d=zohomail.com; s=zohoarc; b=b0VMMcmBROCDM51PXEWQQvcVWCz3ybNGripgOVTudgM+AC9NnW1DXffheTLdn4sx0kIortU+PtfEoHV7VO+EaIQ4lih+XS2CWDrHBBjCV9wPQLxNJciEsszCzond7/fk97N5/Rg0E11vUyAtKy46mDQkXTbPZItY1gd8n7YWu7s= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095656; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RRVpxeM0gaRhUjO9d6z4tc/MJuoIRCJQUNdQDfFlEeE=; b=YyxVkWvRGcxcvhl9kepjrEFebXRNRnhppPu/PpdJkZCj3fA5Apf4ZoTO2KRJHGf8tqFlDSgTLmEdHK6O1KCaLoN+HPs0nQUIORrLb7Ydhu138CGbweWyoaPv3f5nBM4h13N9q4pwnwo/ePe7D0rbIZpdfebwpUeYmj0OYRn9nho= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095656004967.609891460078; Wed, 10 Jun 2026 05:47:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334266.1597374 (Exim 4.92) (envelope-from ) id 1wXIKo-0001rx-E4; Wed, 10 Jun 2026 12:47:06 +0000 Received: by outflank-mailman (output) from mailman id 1334266.1597374; Wed, 10 Jun 2026 12:47:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKo-0001pM-1p; Wed, 10 Jun 2026 12:47:06 +0000 Received: by outflank-mailman (input) for mailman id 1334266; Wed, 10 Jun 2026 12:45:33 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJJ-0001Cs-1Y for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:33 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJI-00H9hG-EE for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:32 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c60-5cb7-0a2a0a5109dd-0a2a4508dcb8-20 for ; Wed, 10 Jun 2026 14:45:32 +0200 Received: from [52.101.65.132] (helo=DU2PR03CU002.outbound.protection.outlook.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c6c-63b5-0a2a45080019-3465418425f0-3 for ; Wed, 10 Jun 2026 14:45:32 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:27 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:27 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LDBR4EgiHWDfctDyQOFveoNwrGy3CE8i7ESuRVWF8++TtRjyAw8ymU8kq74AO8//3ErQpBu1ldjcTc74xz/eQgmYEbbNZFCapJbiptAzOrwBC/c41Ur7O1ZC8c/T/fBTtNQMMCw2+jLPRkxE2gOAUVw9G6iDBgir0pZP2MQJsKznLsR54WB3iU+8UZKdX4caWQEplHSVHwSyjtzkXsELRCCAaGBfmY0FrSlmwrEitD3oMKD774QTjHWShYFTEvFnmMnA/BruLoF0OenJxWF4xd+BPY4lay0HKa3hJc9Vl0g1DUa880ZUyjrk4rEysvoveun8I2jiy0V9d/X0subAMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RRVpxeM0gaRhUjO9d6z4tc/MJuoIRCJQUNdQDfFlEeE=; b=F15kTgcSYiPMEC+vHRL41Dq8itkZ9fBRXWuFmMbQtxQf87I7tFsZB43QFxBPNxgCD4CL5NkKKkJPyhK4PBDkJb2zGSz2VWD0MEAjcYvmKDdx5+QK0ulJfaZgoguGpALyCcYIbPvsWVI6LAUes5OVNna4oKUgQRBRuV4FvcTi1NpNG+Waj3fDk0CwMIOcihTkwLfX5NhvCxluZoMzUjkRqKAZQfuTNVqawp+pk5RWIjJPnAJhER2YdyRax5jUtYDshOhCDYLgR4Mgz4PE15torZ+UoUA2+J1pRWyTGAbINpShCaa4RnKJxj17zTtr/giFpzsRbClyQnz+P/64CHt+tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RRVpxeM0gaRhUjO9d6z4tc/MJuoIRCJQUNdQDfFlEeE=; b=H+8w52V6eKOybGENTInrgbg97nlNH2OWQbHacydgKopkvWP2fT0t/tJ8HVKA1N6+/iVNv1FfqTajabgs5SQqEcJbzM6lMuoJj+5zE3qm1OFwBIKWXqOvjscawWtBo0QcvWpVx1dM/x0W+Jb5hIc6xPu21JQ28X9KCWgouZzRqCW0M4DI6GjrykZgACIBcTsuOg3lZUJZmmnBkolKHA5UnduCqEzz+S8wtiR1EvgM7lhgYXRHj+4RpikNVe2SQrIpfTSmBZwzItVTXW9O/UGcUfGa62LN4esPJLTDy5aUY6gSeFSByZFuPqBaix/yQjK5gH4BH9S9n1ulLF5HxOAIVw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Volodymyr Babchuk , Bertrand Marquis , Jens Wiklander , Stefano Stabellini , Julien Grall , Michal Orzel , Luca Fancellu Subject: [PATCH v11 06/13] xen/arm: tee: keep init_tee_secondary() for hotplug and resume Date: Wed, 10 Jun 2026 15:44:26 +0300 Message-ID: <839baea8d07b4de595296c274cc0a5a4867f4e5b.1781084290.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: d3c62d1c-a63a-4cf0-a84c-08dec6ee2604 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: E23G6cjbq1oAZKJ0MJQa8O1b2LlIA1uoHyd71vnM4ZqRfy0NXyD79t7668P8mgO/DA2n1TUgk2p9lXw/nYrSAsYnZ7nZZgwP5M3ioJTHSjF7XCOuYg1Z3pjJ+kF8IKPFuPAj2cd2RDRishb+tr8DchMDgOENxeS3SuwJ9fUJyniuBue5T3DThCSfXK83Ge8/ZVrOitfU+8qy9Gfxr6BVolxRX97X6RLKZlDtSibV/DG5qJnISw9gQS5s6WaP92pYLF21N/XPFTu2KVqj2PbpN9pJ0HfeTqWeMy59lum1ZWZecOhPCmUb+8v8W0TDtqji8/mkiZsdnrVXDXrYoe/Uzyknpmv4+xOESTka+hItDIVKeEXl5q0SF651iK0zG4qqBAGKK5OPoaveJ6/5YVwpCM2JdE6OY6nHxb+dZXpY8SZWXduyrmPHaxgVBM+JoklJ9bW3hiFdE+53+XVl3oQWCdBhpAP0MIQByhmnHoRyoGJouzyjPPMUCKY+k5rOdgaCeyKbmPiF5kyepFPvNtbJ4Ax+BIf3JXJgBcMJDHD4YREJ6xXuBxCAi2XCqaSaUNQ65WcrCLXnl+YZ9T15RRJ/KSCU167fJyyqx9gqKwLczv6JBVrOuXye/jvrPooL7pmlKqFsxFVyqk2A0ipmS1rR7FerOwjZeA3HZtlLlnlmINX7ZH2I9PmHyTDJsOJh/99i X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?x8D90J2UWMsVuGFgnW/t9ATE1N3GyB/zWFkv/MFLFVki5/Q+CV68AVjgcTlw?= =?us-ascii?Q?eP7ayugwJJvLQfm+2XkxOw5+P4QcSaTtVR9Bq4BasDhc/Lr5Yg13PJ3Q2ufn?= =?us-ascii?Q?wKY0eGaStOU79FpN3wihaUFjO7PPG2GbbcbsVvmxhhrsUc0HbzxsOTqxDmyN?= =?us-ascii?Q?iL0AlgUgaIycz+IVlclct3s7n09+SFSwHsL481WrjI76/ZoIIDFsVJmEwX1D?= =?us-ascii?Q?cSdd06nAdeg1FQXcUHAQKgXf5sOEnmYiL9fJ9rHdAzCQPnP5NfBR2tMs6lQN?= =?us-ascii?Q?J52kE1qIAUkDP3BN0x9kjW3dvRFJmfhzJSqdl1qBg0KxwfWgQawKYRxn7TRz?= =?us-ascii?Q?VSiJuVibffh1+dUUiCO9DI9JOgns5UY8WaawhCXuPZBAdbCCB4aTmaj/Xjvj?= =?us-ascii?Q?CoAplESNz+hP1+tI8YRNqCkuuQepUheOB/k8sVc8JUiDDWDSA7PUegDjp2c3?= =?us-ascii?Q?rJHdoPGTd0L+oayvb4y7mB5eo6L0JW5bKF8MFkSYd8RstjHubjTrIKDjulOW?= =?us-ascii?Q?E0NVJd1bCwCvt2uWfEQO8lmWhkGeqPVhHo5upcwW28nk+bG98mmOf2GuYJQP?= =?us-ascii?Q?IAIJ0WxAp8MdITPmPU2v0FJKA7UdZyg097lOjdrPMmVhN1hJECRc8pv0yLYD?= =?us-ascii?Q?1LRMhbpxAJAr1Ewy94ml2SMCqYpFvso1DmphPgzKdZMXifEw7A7OHiWnEC58?= =?us-ascii?Q?twXxCjNFuLEpUfcdK5uV+TQ91aWmDInuGd39UAAHj8cNer66j4tiJ7rIujAk?= =?us-ascii?Q?KM6VNE0TpEIsvU1XDS485qdTCLJ4/JFfcRNdlXZtsg7mOrI7IZItfzK0ZNVA?= =?us-ascii?Q?Fb1KD9MkrtmKuhH5+eabSHoCsqxYLCE2Yp+A03JYDTqKjbu46XfxHsJGZqES?= =?us-ascii?Q?R2Vd+V4BaI004j88HMARk7jPBvgQLoDrB2qJ7MT1Im8XUabfG1C5arEOGrxa?= =?us-ascii?Q?2Mi9ivr3UUOvnX3x1wHjbza4osMo7uZos6KqNj3u/IsvlwAI+3oNoN3ab+MV?= =?us-ascii?Q?SqcRYUk6l2aZha36FsCZhUswEZxxAUcUNvke+z4d+SSHP2rueCgDnuBNrW5b?= =?us-ascii?Q?fNCeaD3O9Xg4Vz/g+dCMVcOqghsC5mLm5ePFta6yxL8J9yA1QEPqLc+KCkTp?= =?us-ascii?Q?mnN8lwQDMilotE8RpZbmOFRMYSEOVplwoncA9Tw6YoE/5RTbmTSOsE8eHucZ?= =?us-ascii?Q?kP9U7LGKJw6K0EXrLGmL87X1Nb19eJVviEB0/mWH0bQVMke8w67MRTswTdFL?= =?us-ascii?Q?dLQilSGQuODTwrBl40ZcNrYwvzPp8cn8rlZo67SUy/l5TtChIxTg6VCkKTdz?= =?us-ascii?Q?wL58A0NmJFrGMnaf1nUxiBW2lYOaVV4e20DTIhcJLENUusrn92o42aXjevgM?= =?us-ascii?Q?zInAJOjfHwip7rWTpTMgfunSX9fadjMhR5QS0tIEQO0rtPBmPLMsVJo6LI9L?= =?us-ascii?Q?QlnH+X3wvIVi0Jv66nYCftBuxVZZWYf5Aam1S/nysbMtQ97GrFKnGUluXgQX?= =?us-ascii?Q?2Jkk/Jdt4GYHXgN+KNrPDEpSFVkxOJNG25UfUMdfE9uPOxug2fltv/MF8nTd?= =?us-ascii?Q?uweS7YwhKHcFCV0p6mUIpMPq4O7DgcVDL0MaWi+KMuq6VcYlQYS6BVdrNhQi?= =?us-ascii?Q?M5gYJ6bCQUYPibTxTknHdqmgJxj2b62mC3RLaIuTV1KpbYdrUrYkmHVexy98?= =?us-ascii?Q?qHeIuyzjo+rg5Rsr6XzW8dMNN+A2tFPURoTEi55WkW96OVZHmJ+kMa7RzasW?= =?us-ascii?Q?73JKOqtMUQ=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3c62d1c-a63a-4cf0-a84c-08dec6ee2604 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:27.7725 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ckLFgBP/SdiGUKkGfCt9UQsdciqEBk4CqGpfLhClOL8W+U/S7MsYwDPm2DHQx8pmFiYzLy2zab7ulStFnORxDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-c1860d/1781095532-C5F80DB1-4340F1EB/0/0 X-purgate-type: clean X-purgate-size: 1017 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095658393154100 Content-Type: text/plain; charset="utf-8" init_tee_secondary() was marked __init and freed after boot. Calling it from the CPU hotplug/resume path then executed discarded code, which could crash Xen. Drop __init so the TEE mediator secondary init can run safely on hotplugged and resumed CPUs. Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu Reviewed-by: Bertrand Marquis Reviewed-by: Volodymyr Babchuk --- xen/arch/arm/tee/tee.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/arm/tee/tee.c b/xen/arch/arm/tee/tee.c index 8501443c8e..00e561fc78 100644 --- a/xen/arch/arm/tee/tee.c +++ b/xen/arch/arm/tee/tee.c @@ -128,7 +128,7 @@ static int __init tee_init(void) =20 presmp_initcall(tee_init); =20 -void __init init_tee_secondary(void) +void init_tee_secondary(void) { if ( cur_mediator && cur_mediator->ops->init_secondary ) cur_mediator->ops->init_secondary(); --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095649; cv=pass; d=zohomail.com; s=zohoarc; b=ZsySPCVPkeJLKyOsoFw4IzK30BCVDCyG6lmC4rBwtqhjAjiWTx/oKSFRnJ32Xq6roMIWbZ0EBJ7DVv565LjoJ5a7DOfFCe+DEu+VW/nk0v/My1yNTPahWwSNAc/EFPej1MTjoYUXKpP4ATcQQ2eYeGKeS3GuxAltmplu1Oug7Gg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095649; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QnPckwdgpBUr+17cYI0AaPCAdJVEhHccUrVHQZ13anc=; b=GHvThKmuD/uYjaHVlFEwILy7wTw/ZUk9EyEznI0hkCFIb7DO5TJ15nTKeGJBTdGwGAPWJnouUSx1hdfUUhuSXMVymY8TDwEuHsofjM2HJ9SFfNOuZwiUE4zXScohFX5LYC2/nesbIj4bVq1MEY2229H64DzAay3WfWE3pdF0ukA= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 178109564925271.07341758673408; Wed, 10 Jun 2026 05:47:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334267.1597382 (Exim 4.92) (envelope-from ) id 1wXIKo-00021h-TR; Wed, 10 Jun 2026 12:47:06 +0000 Received: by outflank-mailman (output) from mailman id 1334267.1597382; Wed, 10 Jun 2026 12:47:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKo-0001zh-HZ; Wed, 10 Jun 2026 12:47:06 +0000 Received: by outflank-mailman (input) for mailman id 1334267; Wed, 10 Jun 2026 12:45:33 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJJ-0001Cy-NN for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:33 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJJ-00H9hG-3a for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:33 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c67-5cb7-0a2a0a5109dd-0a2a4504ad8a-28 for ; Wed, 10 Jun 2026 14:45:33 +0200 Received: from [52.101.69.118] (helo=AM0PR83CU005.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c6c-1dec-0a2a45040019-34654576fec7-3 for ; Wed, 10 Jun 2026 14:45:33 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:30 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:29 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NxQer9Uknijvh6HcxISJL7OOQ0b6FuQ67/MBVCJIip00SDa2vEHMGodboWBIQbg/COluM8RkR1QbOBoWtZc7+fjQAeqCwBwwyQCUy6UyuAbfJilToCCOnsYZe2iHvO3/FrQqSPcYMJyihAAnEw5LjcwS/HaswKLWJdzHJCQ+p7/664T2wh5HQQTYJVymz8avcAFXUvgciagLeAH74a5CzxwW4XvP4uirJR3GJMw01QDSzHOKmlSgW6nAJS5KzpCWhGWELSXF/IuxtEctsD8CMj+WlEXFIMo+MiFbPKY33JwJg+u8SynPxv9AtWPKHu6PiPe0NIAiMXUiVNGlxBPPNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QnPckwdgpBUr+17cYI0AaPCAdJVEhHccUrVHQZ13anc=; b=SKEttrGiRjNUFrHX92OMsYAitxJUi/94sZPIJ0XI4QknaKw22C9BTmEiNZadVpL864e0UOo1FmpOOLHvNP5aSDZJ6oWxvMHkXlUShZu+G+P1H4OKnlTtThCqazAKYR5b5pGKmoSOC7eJPBvz2QQD4i0lYuP9NYI41+gPAPwwe57gx3S/jba/9KZhggl06DVe9ZWI+/mD4c4QQEVXhmK3V35vNbR31IKVblBY901zrwZ9GM8QGkX3BJgztHPzqMpYTmwzVOjbFm8GKCdQN7kwwui8vjvFv3gqY1spRFcmwcnMTrxBQ1WVmwxkVkcrEvDK5XGe8p2Kuy2qVy/X0N1aeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QnPckwdgpBUr+17cYI0AaPCAdJVEhHccUrVHQZ13anc=; b=jSEAsYmMTeaqFQP6JTCcCKsITRurGOEGKpxaHsOzoBWFHqf81oQbeYA/dktRGUKisHHuTB5XSwCipxKKZkinWqbU5YehwYLahtF23AHU3eGErsDmXoqKDgDio7Xgyf+cpzh6TVuKmPQ5+FR08VqlpYyYrF7yLnk6MZtcpvV7CBg/81abFn+oJnocccA4Fnmiecwr7PpOHgcL3+ColnOaqSqF9zwlIbsScOJvJYOwwtZA+TCITvQzvryNfl8gEjU/X8fwLE7M10VSOYLyBdRakFjkHxNPtbvCuH7QhIp9aRSGR+CEbx8E2X880w8bpm7BT+KzLpHW1KRvVLICvkBe+g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Volodymyr Babchuk , Bertrand Marquis , Jens Wiklander , Stefano Stabellini , Julien Grall , Michal Orzel , Luca Fancellu Subject: [PATCH v11 07/13] xen/arm: ffa: fix notification SRI across CPU hotplug/suspend Date: Wed, 10 Jun 2026 15:44:27 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 19837be2-0888-44be-7fff-08dec6ee2733 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: F3c2389LQyrlBaOy0bblq/YWqdTtTp/n/Wh8B/hxE7aDRPhg1OQyvnkRyBG69eFDjJ5xvZTrf3lNGNDzxto3qyZh704TVWsPbFnc+/QX071VbL1+vQYkXTPzGp4FoyZkcXtnxlhks305gBuCYvcU5qq24GSi33iIoy7RCoJFJuFdg6va7D7evVFk7kslOjARCgpyuDTMedP7GbIQo91v48QItY2l1fJPbHV2FSna38SLC7EBAYzAz+XPxvnkPRLlXe7UjQe4IHBWzLtExhFFtoz5P+OavUZPDI6FaWcdV6b/hvbYLs5INEaFSsoMdZUWPA8GVh0rgzKBWODbksJoO+S+1WCtrG78bF6lruHdpkAvfiMkLydSzYPqhEVoEvBrM97IdcTasTmiIQLAfaD490d8o5e+AAaF6V/VWVU5t0Z/QuOkJy+wCdanCEByFSMwbqpVejAAGy40y5OA4uyIaO4EsVDywd8VWF2akTAo/haHJWRHw3EuZnVbNhqOyDZ4/q6jqgKRVY+BLSjvS3Ohc5DuYPgZGLCa6piIWBFc+xNpUNgbal1NZRXQEUpLfry4m7iwDQEYRU0I5CzgSymiswjn36zbF35CWZ76knha+R4K3oZd64ebrfgmDzEBzRdK62L0kcFA64oneZLU5IYH60aMH93t0JXElpBtUJMRM9IDj6v0Kv31+WHTdcHJyDvJ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?qq4SH96ykzfGTIbO3hQQY8QHBLz98ep31Vfdtpd8GKtxHShv3UXYYQnoBAZt?= =?us-ascii?Q?xudISUqK93oxrtDfX9zmgNjsnh1YiUaxWEHWHXrg4LCoRnac1Gus+3os/k1s?= =?us-ascii?Q?kBtvYmgeipTWMrdKtUdsw4EEByU8a1FWmEEoE0Fl7KI8ZSgXUUP9f6UfE2hK?= =?us-ascii?Q?EUvGqeKtc2SijvR5V1R1t6LQuw/BDIXe6M1bwiWKZ7g0AAnAZ/TAI7mb8dt5?= =?us-ascii?Q?Dn6ew2n+PR46FMsE92pm8hbqHGQP5DuyeuQMtsB8aOW+7Y27bsq9S/9D33pd?= =?us-ascii?Q?2OiPyhLhh5Dh3Wzk+N5ii7xxWgM/noOEePn1OVlk8AdFs3sDUNc9cwGOgYeH?= =?us-ascii?Q?7OE9NHqSZrAICuHQASas5i21uWXGTsu8JcuKddGRwsdehoR7e6qz1znRPOOI?= =?us-ascii?Q?u2AB4gHF9noZpnmJJTFMfcasQ+IffvbcsEZR1B1Q6pfLM9ARmMauK+gGvQED?= =?us-ascii?Q?+wBF/Rldr3tD5S/8dk+WKGeRRyWBz0A6+98I3QV4uDaR3BBB+pScvqHXfkZ1?= =?us-ascii?Q?SWESYgJ2Bd1brpB/V+odfJ6clv2+O9LNcD+PqXVXd6pSPzxnBkW7RjHz50TY?= =?us-ascii?Q?NkVsMwJtv5iNmmBhQnxGe3JS9ZYU5RZjEJvRcNdUcFcG+3iN+Ao0HNTj7HeV?= =?us-ascii?Q?2PJbkZ2C/4x2ff2Z9U8VLelFQtXqOqbM3r4QSWdxWw6LoXJzzH+nik+MW32Q?= =?us-ascii?Q?aZQCHZVLBEEwlizKVFWbpEqAZeC3m8kD6+OBjVXmPiCZFXEFrIK7AKSkhwBC?= =?us-ascii?Q?/sfYyZQnOoiOXdeNl/IpomH1rmeqTGhdYRjs0DNTqKegOShehnsah8RpyLoq?= =?us-ascii?Q?2DgCWofhiYlqx7/b4aqAVTCSmtDRpMSRSrwmWe/UdtxnaJjP55CYT3wBicRP?= =?us-ascii?Q?nwGrcjpjejq2XRTCbr/P4ZrufjqlVbz0H8t5eAK5F1hmTq5X9Qj+3AN7UDGP?= =?us-ascii?Q?7rthE7bpeC/6mTz3rLVuxEA+aCbzHfcLA4/l1X1F5Jp/CsoNl2EjLx5v41Or?= =?us-ascii?Q?twmX5eec8QpDXYDoPkmr1H5G4oV4UOgPbQ7naoFSdpEeSaBi4SFNufzqKNkx?= =?us-ascii?Q?5ZxzJRgsnpkv7dAyGyJIar8ki0EVUXF8niuSq7yt/euvURyNO0PA4yY9fso0?= =?us-ascii?Q?KnNnq9e0YVxYH0C8fXnMsoiLBzjQE7JOeoXVJxze+lm+FxcJp6C7XfqqZp+w?= =?us-ascii?Q?sucOJfWSQSOhITSZ8Cla5grSo5bsVW4k2iosdrmaha19M5XdJv4Cd3VNpXET?= =?us-ascii?Q?ja5MmotDhMoNcm124LuKAuB2YHbcx+x+VFgIOZ/U/ZaHtleQH6spU2XgygQ+?= =?us-ascii?Q?LXcvKh2CiofCNlsquGlxb7/G5Qdneis9/lgmGHcn9Oi4h5Po8gHRkBdPVtkP?= =?us-ascii?Q?9e/SnLB+zCPGqRQtHL7nlv/a+KWbAaONlj8woSjnPcP+Qv7PuA7asEJSQwaq?= =?us-ascii?Q?ThivFGrZdtms9HCRPxNCQTwwwzSZ3pK0tbSBX0NOeK9qXttQi2OUJrE0oHEI?= =?us-ascii?Q?7xt0gNB2N/X0i2a4GWQE3Cs1VgaKpR+a+nte1Uksxalz+V+6uaFJW6mVRaC6?= =?us-ascii?Q?FFp0Le7uH5jqmWCoiBMFHxkRLIQHANcSDIydzPHsvtJjY9cDFhu+xjl61P7o?= =?us-ascii?Q?wbtDo6OuzqhkI02W3Mcs5CIiBaph6p4y4vZBFRRgEOwwiKkGof9Gd6pEB5Vo?= =?us-ascii?Q?U+YUeubz7WrtIJTZibPGGhaHlQxQ1omuy52wFvxWXzpu1GbtxK9KX3S/DqdD?= =?us-ascii?Q?kRdSgLX1aA=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19837be2-0888-44be-7fff-08dec6ee2733 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:29.6704 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cfXX71M3T5cFAkjR5wXf3mIx7TJcxftI0a5lZ4BbO/ilOT9ekQwX5bWPlFNIJr3ksF3UjZ18o9yY+xDnPbWBlQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-ebf023/1781095533-413773FF-9C015285/0/0 X-purgate-type: clean X-purgate-size: 3654 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095650537154100 Content-Type: text/plain; charset="utf-8" The FF-A notification SRI interrupt handler was not correctly tied to CPU hotplug and suspend/resume. As a result, CPUs going offline and back online could end up with stale or missing handlers, breaking delivery of FF-A notifications. Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa_notif.c | 63 ++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c index 186e726412..513c399594 100644 --- a/xen/arch/arm/tee/ffa_notif.c +++ b/xen/arch/arm/tee/ffa_notif.c @@ -360,10 +360,28 @@ static int32_t ffa_notification_bitmap_destroy(uint16= _t vm_id) return ffa_simple_call(FFA_NOTIFICATION_BITMAP_DESTROY, vm_id, 0, 0, 0= ); } =20 -void ffa_notif_init_interrupt(void) +static DEFINE_PER_CPU_READ_MOSTLY(struct irqaction, sri_irq); + +static int request_sri_irq(void) { int ret; + struct irqaction *sri_action =3D &this_cpu(sri_irq); + + sri_action->name =3D "FF-A notif"; + sri_action->handler =3D notif_irq_handler; + sri_action->dev_id =3D NULL; + sri_action->free_on_release =3D 0; + + ret =3D setup_irq(notif_sri_irq, 0, sri_action); + if ( ret ) + printk(XENLOG_ERR "ffa: setup_irq irq %u failed: error %d\n", + notif_sri_irq, ret); =20 + return ret; +} + +void ffa_notif_init_interrupt(void) +{ if ( fw_notif_enabled && notif_sri_irq < NR_GIC_SGI ) { /* @@ -376,14 +394,36 @@ void ffa_notif_init_interrupt(void) * pending, while the SPMC in the secure world will not notice that * the interrupt was lost. */ - ret =3D request_irq(notif_sri_irq, 0, notif_irq_handler, "FF-A not= if", - NULL); - if ( ret ) - printk(XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n", - notif_sri_irq, ret); + request_sri_irq(); } } =20 +static void deinit_ffa_notif_interrupt(void) +{ + if ( fw_notif_enabled && notif_sri_irq < NR_GIC_SGI ) + release_irq(notif_sri_irq, NULL); +} + +static int cpu_ffa_notif_callback(struct notifier_block *nfb, + unsigned long action, + void *hcpu) +{ + switch ( action ) + { + case CPU_DYING: + deinit_ffa_notif_interrupt(); + break; + default: + break; + } + + return NOTIFY_DONE; +} + +static struct notifier_block cpu_ffa_notif_nfb =3D { + .notifier_call =3D cpu_ffa_notif_callback, +}; + void ffa_notif_init(void) { const struct arm_smccc_1_2_regs arg =3D { @@ -392,7 +432,6 @@ void ffa_notif_init(void) }; struct arm_smccc_1_2_regs resp; unsigned int irq; - int ret; =20 /* Only enable fw notification if all ABIs we need are supported */ if ( ffa_fw_supports_fid(FFA_NOTIFICATION_BITMAP_CREATE) && @@ -408,13 +447,11 @@ void ffa_notif_init(void) notif_sri_irq =3D irq; if ( irq >=3D NR_GIC_SGI ) irq_set_type(irq, IRQ_TYPE_EDGE_RISING); - ret =3D request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL); - if ( ret ) - { - printk(XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n", - irq, ret); + + if ( request_sri_irq() ) return; - } + + register_cpu_notifier(&cpu_ffa_notif_nfb); fw_notif_enabled =3D true; } } --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095659; cv=pass; d=zohomail.com; s=zohoarc; b=fAfR5ClCQlSpp0xeQb/c9UkVgsFeNks8reR0Jrxu7nHu7IOGF2fjoAFZ/PkWBlgnAZuKdowo4+g3Mf//ZMvmcLEq2LWfTeP1yrvcBBapk1OgtYa4SVmr8dRGdamhSL2Y562E9r3+nmjPCbqXBFT5nZcHWJJaPeoVcohVLkAWJMw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095659; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nQ4kNGerzyiusut8IWEJPjH9AN7FUvIvVDuMBpOnlU4=; b=FS4iEWMiiNcq8HMXh8Niz+DlJvb/lsi24a5GCe0mjTAfnn5Snwka+a0MpHXnzuKQ5tLLuVY58xQNwuwM2idGER5wx+RuhxEvl3J/GK29vQgMYP8+jMXuylBdegVpCkOSSqEpMjeuHrLaKznha4rOtrnNdhMZOnuziqvupsP9C4k= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095659758223.09106471943062; Wed, 10 Jun 2026 05:47:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334268.1597387 (Exim 4.92) (envelope-from ) id 1wXIKp-0002C4-70; Wed, 10 Jun 2026 12:47:07 +0000 Received: by outflank-mailman (output) from mailman id 1334268.1597387; Wed, 10 Jun 2026 12:47:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKo-0002AG-Vx; Wed, 10 Jun 2026 12:47:06 +0000 Received: by outflank-mailman (input) for mailman id 1334268; Wed, 10 Jun 2026 12:45:35 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJK-0001DU-VN for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:35 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJK-00H9hG-BU for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:34 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c67-5cb7-0a2a0a5109dd-0a2a4504ad8a-34 for ; Wed, 10 Jun 2026 14:45:34 +0200 Received: from [52.101.69.76] (helo=AM0PR83CU005.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c6e-1dec-0a2a45040019-3465454cb0ef-3 for ; Wed, 10 Jun 2026 14:45:34 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:32 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:32 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WQZEunZqsEASvaFPCdrXsuSBLqTLylVpmghm//4nXqy74ql/VYssIP+v+iXLteTDZAKyeYQoJLejCUMhLuIRX+UdCpcZ+/KLSzTCAHAYzICJ7uqwXa7m0Sy4Zwu2C5czbJNAFwVjbiCVFX1RV4E3SZGNM6hsJUMFE0oom8ACWNyjqXU5nI/t3H0VqJayNeqY13IAL9rlH41X5rtsKqDMWxbvio5DdDWmqDAeckfjbt/xtPnLFCcORzCuS3Eyd5f7ZBaDvAteOJv1dDZl/sbZK+lk/J/kVV00JYNDOwe9TvLGZzxbzfn9GYwpgwXKkffTZbB4OkJxyvfwT+HjlTjonQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nQ4kNGerzyiusut8IWEJPjH9AN7FUvIvVDuMBpOnlU4=; b=Xa7ux/i8rNQHIsKHgeLQINmZ8SdDJKmGPkQbv1KRUIjgUdcg7cxYgQymfbe2wlje0JWL12aa2ZyoIHuZ9ELck+F/wwrrhoypjhZc3m8Yu6LufT/vw6cauHQFTGYC4YDN/YmXBfQnLDRGB6h4Lk1emhKYfO7hrPNFOt8IghryY7+wPxVErGLRRrrsNzrj0Dc5O6IdlLvNLM8x8ay5qEGWU9pPz/XIjsHGtTlCRCSJjUi410zpaxNDyaPWKu7ijyG6SwWMmNSTR2v0dsP3T3ZH8eTKTQ4AfC2rPTvIy7dDMBaZVxBCkgi7wekY39+WtE2gtDG57pZxiYsUVZMHfWNIVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nQ4kNGerzyiusut8IWEJPjH9AN7FUvIvVDuMBpOnlU4=; b=quTNwmsuY1UqqmjG2gbzZXqT1DKrxIDl3jVn752Pmf4ucKBhCB3P+9HHLjld/oqfV1azXAjGrDJQIuDtLpv5ALVRmsc/33tWKb/vvouiHxb7OmOcWEr+ohGVifsu7mXFYJoRfpTHMplBCgb3pi8/Mb1dKa38U/KjQpI8yGQm9tIgyoWXojEAvLLxHosOuTBlC3AKsYnilfFbCOq/3i9G36UWOPZIGjYhH9qjfMWORyY7W/Q/Ly1mb2N2WzsmLXl1EYpHVJj+4muarxIbdjkV9ehQZUP7h0KZr/U0CuBSGEq2o6kymb2s8lqlGeqS6yknZEfG2W2vPiGJPqdlDgHRVQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Luca Fancellu Subject: [PATCH v11 08/13] iommu/ipmmu-vmsa: Implement suspend/resume callbacks Date: Wed, 10 Jun 2026 15:44:28 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: fd442826-6b7c-448a-a4fb-08dec6ee288a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|5023799004|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: ZYwVDvAgZZfnoUM4g76PTIgTaLoOMguf+SJArSTv84JGxYaaaAURxE+PVO/PUYy4KaSp/JtnOJ0msP1Kam+BpvDUrScj4ipj1DcAIh96wzdg9b8Hdd+aXqwX7z+eQ/t1AVvXISBbjo+7eq6n2UzEQZFAg3hhDcFic+p041siUc+cl0yBlWJREPypytOSeWGWWVgWLeiZrJViibz6cIS9KQt61GIPbQK6aQNMyuDoIn3fX00KxOjuvk7OdynJivjibIzy4INIErr85237GyNo/zj+FFwb4tImiOvw+u44FIb6LesNre91EhjksfQUy1CACA9wuc43DL6/ErBy6pkxZyQCchORuRTy8bgw+HLPhVdy7dWUiy+okvQ7cH/suNHPs4D03xi8hcH/nnmqi9C61n55JXDBRvTvq2+5/yD2e3+I8KawsLiFWF42W+5KQz5LMaLfNvD+dqZeYSwpxOJVcvjh9uVQrUz87cfmJHIHPrxp6TOt5BPBJGIEkzO5VTNFGUSGllH4jiGoLtF4U0M0nv87EOnk/qcIe1+7nE6d/DAiUlFFOmQQGl6E5qny+pEkO/Kxq+KjiuMUqcmnx6hibh6GejRqNzFgIwT9/zkilyI1aAYrufrxXLXCCTqlKC2PvL3LbWQ3tLuB17T8z9GSdT0fSahDBy+p0s5MZZrLVFsfEqBwlSeOM4dOg8JLc25x X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(5023799004)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Ij+YgkJf4oOGnpUZjvBNEmUsGZ1xkd6wnfAM89MFadwGi32grOVLPIXuVTz/?= =?us-ascii?Q?U8Vqo/rce2G31/u6QXIfOqZ7TKJ6xSERvP9VRiFH+MQlzhuNOnHtOke3XebS?= =?us-ascii?Q?xKfBOeRsg5bvbQOPnj0QDrtZaNqX4Go6qoD+gu9Ja0k1F2zc/QshLcgqWzz7?= =?us-ascii?Q?K29tfYbs5SxH1vgKFxyPWaBJCXugciOpVKp1/AeRiPkaKKeEo9YDuaY1jEuP?= =?us-ascii?Q?qtAWzJtN4ykk7gBSZBDcPcBdtlm1LEQOCX1OU9UhzTHwfBsqn14/ULGFOwEm?= =?us-ascii?Q?91V9YKU/FOyRxUEawK4hMMsW/ukuz/BAaNB3mtqpihBFnbyYGojAMvcSFPlp?= =?us-ascii?Q?v+Qdvx5YgD9KPfgAAK/Pd3ji/c6TgcyXhaeKnfn6Lrir7yQQNQ+LhnjuX1ZQ?= =?us-ascii?Q?7/c2BiEyD8PxzlgyvnKIw5hOQjuVOMflLuU3IIztwWYH2SANZmJ1JtTiCoAM?= =?us-ascii?Q?ivwHWrUjvL++MbzggN3FS2UUZHm7H2u8Mo5rV7kNNNyfLPYJfm6gSC/tZMVL?= =?us-ascii?Q?aRL+tqZeTzmi+Q2nw/x/70xpWcz+wKORBCzk9rAwtQqCTnOrkfU0Gr+nDGFd?= =?us-ascii?Q?8DaUdTw1by+wg5V2vjDQZaeP4xJm+0miuvGz46RxRs8fG8C13fUsRpujfu6C?= =?us-ascii?Q?RhBtZZPhlcCk8WXlpxyutw9yqdM4GaTopYrxyvBAv6CUoYL/q58vB2BDg+sQ?= =?us-ascii?Q?0nnxrYS37tBKSZloApC3MLeY7hjvAXFONijCrYg/VOlWWjNIduLcOSojSxAu?= =?us-ascii?Q?N1+Z3UZpq6QFL2tmmwyz/Ra+yA7Dt13Lg7hNsMyIK/XL94P91J703MjraAy6?= =?us-ascii?Q?8oz8Qniyo5s4if+KkNQC9zVxDvAnG5GUOyriYNP8ZOIhrFsylvgH/uX2VoPT?= =?us-ascii?Q?V6LcfUgyO9wOISecPO2Ji8T1LIWF0tAiQyASCpPszwewLIeO7k+lbSiAOqmw?= =?us-ascii?Q?y0rpffusNmau+8SbfM9aAsvswkT9dnE9TfOlpJwuZDOVigOA/qPDV7h6vS/A?= =?us-ascii?Q?bjVctkdvq/T4wUULL5GO5PeecZfRSqB39PUVXjSlt6ZtS+x8UIEmlcuXQ499?= =?us-ascii?Q?g7Zw3iKMzpjrpfkuk163z3G6Iwyhk+2xPL3gwCFczI9ffjLFUuj6othoCBz/?= =?us-ascii?Q?2w+ALdxcYWSumuW1M1WFpCS8wlVJkVlKfxsIcfPY7RvV/gkifuHzbg42v6+p?= =?us-ascii?Q?aWlBBO7AjKt+l4FrCp+k479tZZSwRd4ZoyWRXOauyBEbforLRkfsQRDKU0Og?= =?us-ascii?Q?KaorFtSMWwPLZzTFbGLPaWab0T8DYAz//NaTwd9MGIK9qBI95ea32+U+xms/?= =?us-ascii?Q?wiH77+tOcbK296F7VKJrUaKCq8/K6V2CRRGLS7AxvYhh6J+kINBBjIkf0zjZ?= =?us-ascii?Q?MVPHqJcrnAPPbgq/nRzLP9bt8OshluLGDPAgxOSDNgdDuuuOe3nfMoWTuhS9?= =?us-ascii?Q?yHhuMNJRQOmMKvmg05CJY9HeoPpEbHyxBn1J0V9J+6Fi/H3fc7ytadAR/YQ/?= =?us-ascii?Q?TBXp+eXlc0pNDYmJw9xYu39ZA01lXC1oTwmQB6C7I/ATaKT2sulBPyXiC9ql?= =?us-ascii?Q?xf/+v4f/DXGJlv4yjjywnr/w9ioSZup2v1t31jSuMDPCFnDhkqYdD8QzUO7D?= =?us-ascii?Q?pYwqxNwm0KyVRC5v6FDwAG+W8PzoSj7EV7XE3Ofsx1DqJ2kCCl7ODhDJvBql?= =?us-ascii?Q?SwOfl2aeW+E3IUwVUgtkuE9THhI/P0w9jnMcT16n0WGnVR7nUFZqAncOOHAh?= =?us-ascii?Q?TYEJYoA0vA=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd442826-6b7c-448a-a4fb-08dec6ee288a X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:31.9088 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7HI80ajRachY0b2IJ6shS5rbW45IiSinAaxVg1dXxub8GdHMleoYKkDb28RC2LfN8oZqwHsUDiEs5h/9dnWrDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-ebf023/1781095534-291763FF-8D6A7073/0/0 X-purgate-type: clean X-purgate-size: 14456 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095661483158500 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko Store and restore active context and micro-TLB registers. On resume, restore Root IPMMU context state before restoring Cache IPMMU micro-TLB state. Cache IPMMUs select Root contexts through their micro-TLB configuration, so restoring Cache micro-TLBs before the Root context registers are restored can expose stale or uninitialized context state. Tested on R-Car H3 Starter Kit. Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in V10: - Iterate over registered IPMMUs in reverse order during resume so Root IPM= MU context state is restored before Cache IPMMU micro-TLB state. Changes in V9: - set dt_device_set_protected() only after ipmmu_alloc_ctx_suspend() succeeds, so DT devices do not remain protected on allocation failure. Changes in V7: - moved suspend context allocation before pci stuff --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 323 +++++++++++++++++++++-- 1 file changed, 308 insertions(+), 15 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthr= ough/arm/ipmmu-vmsa.c index fa9ab9cb13..2e54fa63d6 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -71,6 +71,8 @@ }) #endif =20 +#define dev_dbg(dev, fmt, ...) \ + dev_print(dev, XENLOG_DEBUG, fmt, ## __VA_ARGS__) #define dev_info(dev, fmt, ...) \ dev_print(dev, XENLOG_INFO, fmt, ## __VA_ARGS__) #define dev_warn(dev, fmt, ...) \ @@ -130,6 +132,24 @@ struct ipmmu_features { unsigned int imuctr_ttsel_mask; }; =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +struct ipmmu_reg_ctx { + unsigned int imttlbr0; + unsigned int imttubr0; + unsigned int imttbcr; + unsigned int imctr; +}; + +struct ipmmu_vmsa_backup { + struct device *dev; + unsigned int *utlbs_val; + unsigned int *asids_val; + struct list_head list; +}; + +#endif + /* Root/Cache IPMMU device's information */ struct ipmmu_vmsa_device { struct device *dev; @@ -142,6 +162,9 @@ struct ipmmu_vmsa_device { struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; unsigned int utlb_refcount[IPMMU_UTLB_MAX]; const struct ipmmu_features *features; +#ifdef CONFIG_SYSTEM_SUSPEND + struct ipmmu_reg_ctx *reg_backup[IPMMU_CTX_MAX]; +#endif }; =20 /* @@ -547,6 +570,249 @@ static void ipmmu_domain_free_context(struct ipmmu_vm= sa_device *mmu, spin_unlock_irqrestore(&mmu->lock, flags); } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +static DEFINE_SPINLOCK(ipmmu_devices_backup_lock); +static LIST_HEAD(ipmmu_devices_backup); + +static struct ipmmu_reg_ctx root_pgtable[IPMMU_CTX_MAX]; + +static uint32_t ipmmu_imuasid_read(struct ipmmu_vmsa_device *mmu, + unsigned int utlb) +{ + return ipmmu_read(mmu, ipmmu_utlb_reg(mmu, IMUASID(utlb))); +} + +static void ipmmu_utlbs_backup(struct ipmmu_vmsa_device *mmu) +{ + struct ipmmu_vmsa_backup *backup_data; + + dev_dbg(mmu->dev, "Handle micro-TLBs backup\n"); + + spin_lock(&ipmmu_devices_backup_lock); + + list_for_each_entry( backup_data, &ipmmu_devices_backup, list ) + { + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(backup_data->= dev); + unsigned int i; + + if ( to_ipmmu(backup_data->dev) !=3D mmu ) + continue; + + for ( i =3D 0; i < fwspec->num_ids; i++ ) + { + unsigned int utlb =3D fwspec->ids[i]; + + backup_data->asids_val[i] =3D ipmmu_imuasid_read(mmu, utlb); + backup_data->utlbs_val[i] =3D ipmmu_imuctr_read(mmu, utlb); + } + } + + spin_unlock(&ipmmu_devices_backup_lock); +} + +static void ipmmu_utlbs_restore(struct ipmmu_vmsa_device *mmu) +{ + struct ipmmu_vmsa_backup *backup_data; + + dev_dbg(mmu->dev, "Handle micro-TLBs restore\n"); + + spin_lock(&ipmmu_devices_backup_lock); + + list_for_each_entry( backup_data, &ipmmu_devices_backup, list ) + { + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(backup_data->= dev); + unsigned int i; + + if ( to_ipmmu(backup_data->dev) !=3D mmu ) + continue; + + for ( i =3D 0; i < fwspec->num_ids; i++ ) + { + unsigned int utlb =3D fwspec->ids[i]; + + ipmmu_imuasid_write(mmu, utlb, backup_data->asids_val[i]); + ipmmu_imuctr_write(mmu, utlb, backup_data->utlbs_val[i]); + } + } + + spin_unlock(&ipmmu_devices_backup_lock); +} + +static void ipmmu_domain_backup_context(struct ipmmu_vmsa_domain *domain) +{ + struct ipmmu_vmsa_device *mmu =3D domain->mmu->root; + struct ipmmu_reg_ctx *regs =3D mmu->reg_backup[domain->context_id]; + + dev_dbg(mmu->dev, "Handle domain context %u backup\n", domain->context= _id); + + regs->imttlbr0 =3D ipmmu_ctx_read_root(domain, IMTTLBR0); + regs->imttubr0 =3D ipmmu_ctx_read_root(domain, IMTTUBR0); + regs->imttbcr =3D ipmmu_ctx_read_root(domain, IMTTBCR); + regs->imctr =3D ipmmu_ctx_read_root(domain, IMCTR); +} + +static void ipmmu_domain_restore_context(struct ipmmu_vmsa_domain *domain) +{ + struct ipmmu_vmsa_device *mmu =3D domain->mmu->root; + struct ipmmu_reg_ctx *regs =3D mmu->reg_backup[domain->context_id]; + + dev_dbg(mmu->dev, "Handle domain context %u restore\n", domain->contex= t_id); + + ipmmu_ctx_write_root(domain, IMTTLBR0, regs->imttlbr0); + ipmmu_ctx_write_root(domain, IMTTUBR0, regs->imttubr0); + ipmmu_ctx_write_root(domain, IMTTBCR, regs->imttbcr); + ipmmu_ctx_write_all(domain, IMCTR, regs->imctr | IMCTR_FLUSH); +} + +/* + * Xen: Unlike Linux implementation, Xen uses a single driver instance + * for handling all IPMMUs. There is no framework for ipmmu_suspend/resume + * callbacks to be invoked for each IPMMU device. So, we need to iterate + * through all registered IPMMUs performing required actions. + * + * Also take care of restoring special settings, such as translation + * table format, etc. + */ +static int __must_check ipmmu_suspend(void) +{ + struct ipmmu_vmsa_device *mmu; + + if ( !iommu_enabled ) + return 0; + + printk(XENLOG_DEBUG "ipmmu: Suspending...\n"); + + spin_lock(&ipmmu_devices_lock); + + list_for_each_entry( mmu, &ipmmu_devices, list ) + { + if ( ipmmu_is_root(mmu) ) + { + unsigned int i; + + for ( i =3D 0; i < mmu->num_ctx; i++ ) + { + if ( !mmu->domains[i] ) + continue; + ipmmu_domain_backup_context(mmu->domains[i]); + } + } + else + ipmmu_utlbs_backup(mmu); + } + + spin_unlock(&ipmmu_devices_lock); + + return 0; +} + +static void ipmmu_resume(void) +{ + struct ipmmu_vmsa_device *mmu; + + if ( !iommu_enabled ) + return; + + printk(XENLOG_DEBUG "ipmmu: Resuming...\n"); + + spin_lock(&ipmmu_devices_lock); + + /* + * IPMMUs are registered with list_add(), with Root IPMMU probed first. + * Walk backwards to restore Root contexts before Cache micro-TLBs. + */ + list_for_each_entry_reverse( mmu, &ipmmu_devices, list ) + { + uint32_t reg; + + /* Do not use security group function */ + reg =3D IMSCTLR + mmu->features->control_offset_base; + ipmmu_write(mmu, reg, ipmmu_read(mmu, reg) & ~IMSCTLR_USE_SECGRP); + + if ( ipmmu_is_root(mmu) ) + { + unsigned int i; + + /* Use stage 2 translation table format */ + reg =3D IMSAUXCTLR + mmu->features->control_offset_base; + ipmmu_write(mmu, reg, ipmmu_read(mmu, reg) | IMSAUXCTLR_S2PTE); + + for ( i =3D 0; i < mmu->num_ctx; i++ ) + { + if ( !mmu->domains[i] ) + continue; + ipmmu_domain_restore_context(mmu->domains[i]); + } + } + else + ipmmu_utlbs_restore(mmu); + } + + spin_unlock(&ipmmu_devices_lock); +} + +static int ipmmu_alloc_ctx_suspend(struct device *dev) +{ + struct ipmmu_vmsa_backup *backup_data; + unsigned int *utlbs_val, *asids_val; + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + + utlbs_val =3D xzalloc_array(unsigned int, fwspec->num_ids); + if ( !utlbs_val ) + return -ENOMEM; + + asids_val =3D xzalloc_array(unsigned int, fwspec->num_ids); + if ( !asids_val ) + { + xfree(utlbs_val); + return -ENOMEM; + } + + backup_data =3D xzalloc(struct ipmmu_vmsa_backup); + if ( !backup_data ) + { + xfree(utlbs_val); + xfree(asids_val); + return -ENOMEM; + } + + backup_data->dev =3D dev; + backup_data->utlbs_val =3D utlbs_val; + backup_data->asids_val =3D asids_val; + + spin_lock(&ipmmu_devices_backup_lock); + list_add(&backup_data->list, &ipmmu_devices_backup); + spin_unlock(&ipmmu_devices_backup_lock); + + return 0; +} + +#ifdef CONFIG_HAS_PCI +static void ipmmu_free_ctx_suspend(struct device *dev) +{ + struct ipmmu_vmsa_backup *backup_data, *tmp; + + spin_lock(&ipmmu_devices_backup_lock); + + list_for_each_entry_safe( backup_data, tmp, &ipmmu_devices_backup, lis= t ) + { + if ( backup_data->dev =3D=3D dev ) + { + list_del(&backup_data->list); + xfree(backup_data->utlbs_val); + xfree(backup_data->asids_val); + xfree(backup_data); + break; + } + } + + spin_unlock(&ipmmu_devices_backup_lock); +} +#endif /* CONFIG_HAS_PCI */ + +#endif /* CONFIG_SYSTEM_SUSPEND */ + static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) { uint64_t ttbr; @@ -559,6 +825,9 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_= domain *domain) return ret; =20 domain->context_id =3D ret; +#ifdef CONFIG_SYSTEM_SUSPEND + domain->mmu->root->reg_backup[ret] =3D &root_pgtable[ret]; +#endif =20 /* * TTBR0 @@ -615,6 +884,9 @@ static void ipmmu_domain_destroy_context(struct ipmmu_v= msa_domain *domain) ipmmu_ctx_write_root(domain, IMCTR, IMCTR_FLUSH); ipmmu_tlb_sync(domain); =20 +#ifdef CONFIG_SYSTEM_SUSPEND + domain->mmu->root->reg_backup[domain->context_id] =3D NULL; +#endif ipmmu_domain_free_context(domain->mmu->root, domain->context_id); } =20 @@ -1338,10 +1610,11 @@ static int ipmmu_add_device(u8 devfn, struct device= *dev) struct iommu_fwspec *fwspec; =20 #ifdef CONFIG_HAS_PCI + int ret; + if ( dev_is_pci(dev) ) { struct pci_dev *pdev =3D dev_to_pci(dev); - int ret; =20 if ( devfn !=3D pdev->devfn ) return 0; @@ -1358,17 +1631,24 @@ static int ipmmu_add_device(u8 devfn, struct device= *dev) if ( !to_ipmmu(dev) ) return -ENODEV; =20 - if ( !dev_is_pci(dev) ) + if ( !dev_is_pci(dev) && dt_device_is_protected(dev_to_dt(dev)) ) { - if ( dt_device_is_protected(dev_to_dt(dev)) ) - { - dev_err(dev, "Already added to IPMMU\n"); - return -EEXIST; - } + dev_err(dev, "Already added to IPMMU\n"); + return -EEXIST; + } =20 - /* Let Xen know that the master device is protected by an IOMMU. */ - dt_device_set_protected(dev_to_dt(dev)); +#ifdef CONFIG_SYSTEM_SUSPEND + if ( ipmmu_alloc_ctx_suspend(dev) ) + { + dev_err(dev, "Failed to allocate context for suspend\n"); + return -ENOMEM; } +#endif + + /* Let Xen know that the master device is protected by an IOMMU. */ + if ( !dev_is_pci(dev) ) + dt_device_set_protected(dev_to_dt(dev)); + #ifdef CONFIG_HAS_PCI if ( dev_is_pci(dev) ) { @@ -1377,26 +1657,28 @@ static int ipmmu_add_device(u8 devfn, struct device= *dev) struct pci_host_bridge *bridge; struct iommu_fwspec *fwspec_bridge; unsigned int utlb_osid0 =3D 0; - int ret; =20 bridge =3D pci_find_host_bridge(pdev->seg, pdev->bus); if ( !bridge ) { dev_err(dev, "Failed to find host bridge\n"); - return -ENODEV; + ret =3D -ENODEV; + goto free_suspend_ctx; } =20 fwspec_bridge =3D dev_iommu_fwspec_get(dt_to_dev(bridge->dt_node)); if ( fwspec_bridge->num_ids < 1 ) { dev_err(dev, "Failed to find host bridge uTLB\n"); - return -ENXIO; + ret =3D -ENXIO; + goto free_suspend_ctx; } =20 if ( fwspec->num_ids < 1 ) { dev_err(dev, "Failed to find uTLB"); - return -ENXIO; + ret =3D -ENXIO; + goto free_suspend_ctx; } =20 rcar4_pcie_osid_regs_init(bridge); @@ -1405,7 +1687,7 @@ static int ipmmu_add_device(u8 devfn, struct device *= dev) if ( ret < 0 ) { dev_err(dev, "No unused OSID regs\n"); - return ret; + goto free_suspend_ctx; } reg_id =3D ret; =20 @@ -1420,7 +1702,7 @@ static int ipmmu_add_device(u8 devfn, struct device *= dev) { rcar4_pcie_osid_bdf_clear(bridge, reg_id); rcar4_pcie_osid_reg_free(bridge, reg_id); - return ret; + goto free_suspend_ctx; } } #endif @@ -1429,6 +1711,13 @@ static int ipmmu_add_device(u8 devfn, struct device = *dev) dev_name(fwspec->iommu_dev), fwspec->num_ids); =20 return 0; +#ifdef CONFIG_HAS_PCI + free_suspend_ctx: +#ifdef CONFIG_SYSTEM_SUSPEND + ipmmu_free_ctx_suspend(dev); +#endif + return ret; +#endif } =20 static int ipmmu_iommu_domain_init(struct domain *d) @@ -1490,6 +1779,10 @@ static const struct iommu_ops ipmmu_iommu_ops =3D .unmap_page =3D arm_iommu_unmap_page, .dt_xlate =3D ipmmu_dt_xlate, .add_device =3D ipmmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend =3D ipmmu_suspend, + .resume =3D ipmmu_resume, +#endif }; =20 static __init int ipmmu_init(struct dt_device_node *node, const void *data) --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095653; cv=pass; d=zohomail.com; s=zohoarc; b=GRMXbI2cDUgKWmZ1ebJUvf9spXOTH+16Haa+csGQfhbpm2/I+bUyKCRhlmu7IXvegwuXaNZK288s7O7Q6PhcUDYYSDMx9ZOa+7egfs8sj+3AmPDdIx5kuT4diGEFt2+XuvKYUXlyGZiluxkZpS4em5to30m5QkhMLn3U7RhwZYo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095653; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zuU9qIia0v/KlFmfmQr2PfYUlwI141FZNiLujMqRB9A=; b=RlHWCrGDMDPsbKjJpghwBm/QOwFWzhsYUk3J5r13Xs57jVESAKJZRpSDeqafg7d9qWD359QU8w2f95A6MS1nj400keIaRgg2zgsvnb0N52ksXaJh+XHgk4yl9OaO9hDh3Jn0hWzAgaTm1riSunHtPMMRAsKC1WkppVxv7q8IuE4= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095653481806.7612517216621; Wed, 10 Jun 2026 05:47:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334272.1597394 (Exim 4.92) (envelope-from ) id 1wXIKp-0002Ht-JI; Wed, 10 Jun 2026 12:47:07 +0000 Received: by outflank-mailman (output) from mailman id 1334272.1597394; Wed, 10 Jun 2026 12:47:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKp-0002G6-Ai; Wed, 10 Jun 2026 12:47:07 +0000 Received: by outflank-mailman (input) for mailman id 1334272; Wed, 10 Jun 2026 12:45:39 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJO-0001F1-Qs for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:39 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJO-00H9hG-74 for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:38 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c67-5cb7-0a2a0a5109dd-0a2a4504ad8a-44 for ; Wed, 10 Jun 2026 14:45:38 +0200 Received: from [52.101.65.103] (helo=DU2PR03CU002.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c71-1dec-0a2a45040019-3465416798a7-3 for ; Wed, 10 Jun 2026 14:45:38 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:35 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:35 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ls2akCtxHCrDXkkdEcXzSXzUiy3QotfjYADyI2WbWxiRGwpxrHNirdp65VnAtDgxwNmId3QJHeoldhsGI/tcPqo3Lo5pdEYa29UR5deD/4KLEXV2L0s5wNFf4qfxiDBLmmq3mLxiM7pnsdC5c2tKKZ3IOdoytpEnOq/pj0PIAsM0YQa8gctPlQNoUyEU/9VuSfV38ss5D0Y6MMHUYD8HXScWq2qNwe0CxCdbU6EC1j2gGWvPsDRCVGFOFsackI37Hi22Jld1J38LtplZfcD+6qyuSkyA2pCeuX9Fam4Cy3jB/fquPeJHD6KwwomHmNdfWS0Qz3eVxLBMVQMyndl9qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zuU9qIia0v/KlFmfmQr2PfYUlwI141FZNiLujMqRB9A=; b=j2q2dlLPoVvdjM2FkVP4QzSWmC5xI8M83BFLfrsSoKqmFgg7ycts/YQOS26R3wn96dRSb6KWeGefI9tTI+Na3RyXLTaV3yI0n4qFlzxPeEQS3wI77pGVCQJJbjkXOTiDCatwNByAjIbThnzdOAmgWl6P1w0Ln7SPnX3hazJScM7u63YRLRZCmPRP4MZdlYfvX2pkUvb8amYtvncTd19T6qirpwDtKmy0Leqhdnjad0BX+A8P3fLJ9mb5DbxBnw5SRE0a3fNprR3jF0Bn612fJXvW+KlYtGt+EGM/oMNMgrU/f6uuAK6JrLtC6Fqdc1BYuNMdOS9R6l8U0rIiUo7Lxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zuU9qIia0v/KlFmfmQr2PfYUlwI141FZNiLujMqRB9A=; b=hk6GtzdKDrgsx55KMiSCjFB2jCF2jG6Qp7ubXzpw1xRyNSXYZuBASGcsVrD5leMnqws4Uxhty0U0rFMFkRfEIClvHExi4NsJO9rUCmREqWja2S6eFeoSDx2D0OycK6OD3X3+j86gs6a5qj0KpC2GPXmIpKLBQoICPj1MqHstOFMvY/7z0To+Mds8yqYPAx1DjIlgsQFxiTYmmHP40XZWF006/fQ4yX2OtuXGibLYKgyVFunrjyvGHPHXYHf/yUVxQxQnIhadlgGVQPNvbQ42d7OOznN/UO9KRBynjtnF3Z3cY2OPTjkcFrAGiIXjXsF63JX+40ZqFyLMQmhA/0TffA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Bertrand Marquis , Rahul Singh , Stefano Stabellini , Julien Grall , Michal Orzel , Volodymyr Babchuk , Pranjal Shrivastava , Luca Fancellu Subject: [PATCH v11 09/13] xen/arm: smmu-v3: add suspend/resume handlers Date: Wed, 10 Jun 2026 15:44:29 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 19d77b4b-6690-49e2-b0d0-08dec6ee2ab8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|3023799007|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: +4EWl3k3PQKfOBHPNt4O8R6W+YG/djPMZ1AEsd5fRXELZC1s9c7wi7QMl8ML7/KUZrSFE7fN0oOWmq3gI6Tr+BBHCjInuIxkvYmnF6tP0JLuFI2+QmYehaF+6xqWRoDVT6QDSYNX5L+Sw5BslpyHuvrQkWx0rJNTQWy1iipqcYWyEyY2KQzwmJvRugrFdWYDjmOxmAGfgNi+8OzA8LBmkuWmAKk/V1Ih6znUebe5QJ8ntXBZmG8S7U8mxNiQaoVYhxQATrV8Y/2dm7kKdFW+Rtxz1UpmFPLbDcSBHjXCbe/q0m3/0QoGxA1WMrRUv8Wcj75rWW+6Kj0p6JcYQ03WorxeCPJ3VD7gQdhfXKcO0HwoUYN1Tot+m/ivtBnmaB56yQyjJDKSEgbyi5DtlTaJktddeYtU1legYUt96xOv5Our8bVGNA6HqCeG3mLoRHllpGLmSrRXlcpHTgxruIw7VswIhA7A9SlyaWAQOFaJ8eY7kPcm+GTgUSVcpMUMLEajy/ajoNhYl6YPSEmor1i3FYBgmVg5I4DAQ1lB22VuNuqDjcmdmLzukEd5trPMjDRumnn3NMaXvBHjsH34qSYol1TvGwey6QcJLAO1xNnDy6E952Rivl/0dSl1l5sBJmer6bcZQHcJQmzH7N1JJqsoqcectqqwJi/+5WRtGJTfXt/bCwYgSUQ9n+0kJJqAIS1t+dxJHAmkJZHVwe7OpkFyQg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(3023799007)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yw4m8nky4dwxiApT6yp3pgf67x+QJVmywGl5B5Y1tKDy/Nymf2iyeCZnep9A?= =?us-ascii?Q?2MEoJCtcwelfizu29SzUe5VZu9FpCxhLB/rnPG1OEYpPnRUUqRe22vSp60O3?= =?us-ascii?Q?6kqksZi4FbkkZZAs3sdRI+KqHruvcsmLhMmd9ig1///ivnAUEg6XbBM3La/r?= =?us-ascii?Q?C4L3FKMr4/ny3chZl6nAnTNQ1lyNs1pwZ+4cntFFcf99nJY+Oqjw/Erw/Rd0?= =?us-ascii?Q?pmcVjDB37/GTPJ6wzbpYYQhUP2OpL3cTcaTMqlx9TNqI2obd8CGFyIEMHn9O?= =?us-ascii?Q?Z8/0xubGK1v7SddO1Od06yTL4lU8hTNgiJP7pVghP/1GjH15IoSae+4Wb2Xb?= =?us-ascii?Q?UPqOBBt4SzblX3PUYo/RI/351fWpxz/AIstjsIl/D1jZMlADLVMhzYplWZnE?= =?us-ascii?Q?dWS83Z8byez5N0exRlCkJfM/FihZ7Noqd8mQ0skIbnFIRGj7TlfTREJsmmv7?= =?us-ascii?Q?NfjJb/vzcuFBpUL8SPsy0Y4N0pzVPw4Qz6uG2f7R/ainihanRdDoa9DVxXdk?= =?us-ascii?Q?ivH9TUwVGBFSFejTsIFXpqAwxkV+1bFtfEcIilfVSS5X+6C3bH+vgPA34Bw5?= =?us-ascii?Q?rsrxFu3+/HDmWjmnnKi/U/EzLYI9xDPoTxFsX8OCAJOcpaRrPPHnJs4VK3B9?= =?us-ascii?Q?UA0a5jLxKhXLg8O/UN71mxPXRMQFZwrVcFB844QnZhY+SKHbRGLSsF56qKk9?= =?us-ascii?Q?oEr+ieQ6LF4BiU5QAcWS7VhehTvYdHKi7LxxBe9GM3J0fuIEBksdCwzfwxr9?= =?us-ascii?Q?L7KSPIujuSrUXGc50umUU+dG+LDRHq25cvmd3kJMF1ZxBZdP7q0OOQcAke2A?= =?us-ascii?Q?pZsylLDbL/saFBaq7WGiN6hJDfS8GsQoBKgh22+eDp5z1orphVIe1Aksi1lG?= =?us-ascii?Q?9JgzHUiLDClvOtlgFTIgOh7QiOdooZye87AuueNgzcjE0NvbUWH8lBX5pXvD?= =?us-ascii?Q?cZWKVtZ2HjwDWM8qpa9QGZk59iGUsy3tpzN3/51fABDEFnG9BO3AJRWAnucX?= =?us-ascii?Q?mEtC1S4S7YnCZ1qalPNJM2EHoUrXBdYIOQIF3yu6R54BMb5X2300EvtKT8Sj?= =?us-ascii?Q?G9QaX4oMu0+HEG5qMUYL00FtS2wI5TYmL+Tghx/JUutFBvMVvPX9m+ipnQJd?= =?us-ascii?Q?eaG+rKQs2aS0nr/sLHjCyjyu8p81N8aWGzRSyNNWw0RGSjQd5HYriXf4k41Q?= =?us-ascii?Q?4XfbjpCuScdA3dRWcJFxVCtFXreMCBfTYkNzr37u/86JJs+/7MGRvFFPw5Qm?= =?us-ascii?Q?v6Lgt5N527bE7baGT9kB3S3Gh7E1hFIS9PKVV5DdGFQ6Feh6KaGjZixv1Xsr?= =?us-ascii?Q?UD9pDyc0XGy1UT3GBbaahgpsjWLK6nXAxi37EiQDmPsnVMBw91LwE8hOfCmc?= =?us-ascii?Q?ODlbcm3oDkVicQ6mwaaNZvQ4TS0WI0pFv40ytCkLTl632AMcJdMp9QQNKpyG?= =?us-ascii?Q?atI3SO31rc4Iy/0mXg980VatxXgZ+zWfKpc5aLmt8EkeQdnOzb+80C7ufSua?= =?us-ascii?Q?+8lCpoK91DPEb7PNypb7i7vH4Gm9ZViphf3tXyPKpreY7u2WUeAOYaj7Tb1O?= =?us-ascii?Q?otHRhPSK0O9BddGbc95l7j8i39+F2g3WuRWrTfnoZ47x6ZikvWCx7ssorX7l?= =?us-ascii?Q?7uMTUB4jPQEEABlRhypANWkzGA8u1valLSPbf+mw992GWlclmmXEb1nCHR9n?= =?us-ascii?Q?L6baLSKSqSeXkHXOZsJxXfX5IylCxjXaIUKIt9am6Hpvyk3MkHhRdavNNysH?= =?us-ascii?Q?+7+bOw7ekA=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19d77b4b-6690-49e2-b0d0-08dec6ee2ab8 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:35.5440 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PL+WuQP7PI6lnc+yZF731wuC9SBAOOXGidsdiNrZexWIESRPApwxfqdzOUzOGM5Ero7sWCj/Og3RLQJwqgzugg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-ebf023/1781095538-2A5603FF-12F23C5C/0/0 X-purgate-type: clean X-purgate-size: 11069 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095656546154100 Content-Type: text/plain; charset="utf-8" Add system suspend/resume callbacks for the Arm SMMUv3 driver. During suspend, configure GBPA to abort incoming transactions, disable the translation interface while keeping CMDQ enabled, issue CMD_SYNC to ensure all previously issued commands have completed, then disable the SMMU IRQs and SMMU. Resume uses arm_smmu_device_reset() to reprogram the SMMU and re-enable translation and interrupt generation. The IRQ setup split follows the approach from Pranjal Shrivastava's Linux arm-smmu-v3 runtime/system sleep series: IRQ handlers are requested once during probe, while reset/resume only restores SMMU hardware state and re-enables IRQ_CTRL. Only the pieces relevant to Xen's currently supported SMMUv3 path are ported here. Xen documents SMMUv3 MSI and PCI ATS as unsupported and not compiled/tested, so this patch does not restore SMMU MSI IRQ_CFGn registers nor reinitialize ATS/PRI endpoints. If those paths become usable, suspend/resume will need corresponding MSI restore and ATS/PRI quiesce/reinit steps. Link: https://lore.kernel.org/r/20260414194702.1229094-1-praan@google.com/ Based-on-patch-by: Pranjal Shrivastava Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in V11: - Keep arm_smmu_update_gbpa() and arm_smmu_device_reset() in init text when CONFIG_SYSTEM_SUSPEND is disabled. Changes in V10: - Disable SMMU interrupt generation during suspend before disabling the SMMU interface, matching the resume/reset path which re-enables IRQ_CTRL. Changes in V9: - Use CMD_SYNC in suspend instead of polling CMDQ_CONS, so the suspend path waits for command completion rather than only command consumption. - Document that arm_smmu_setup_irqs() is probe-only and that future Xen SMMUv3 MSI support will need to restore SMMU IRQ_CFGn registers on resume. - Restore the reference to Pranjal's Linux runtime/system sleep series and clarify that MSI/ATS/PRI resume handling is outside the supported Xen path. - Prefix the subject with xen/arm for consistency with the rest of the Arm suspend/resume series. Changes in V8: - Honor ARM_SMMU_FEAT_SEV when draining the CMDQ during suspend, matching the existing runtime CMD_SYNC path. - Fold the suspend rollback reset path into a helper and rename the error reporting to describe suspend rollback rather than resume. - Treat SMMU reset failure during resume as fatal instead of logging and continuing with a potentially unusable IOMMU. - cosmetic changes --- xen/drivers/passthrough/arm/smmu-v3.c | 194 +++++++++++++++++++++----- 1 file changed, 158 insertions(+), 36 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthroug= h/arm/smmu-v3.c index bf153227db..7f1d00fb81 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -94,6 +94,12 @@ =20 #include "smmu-v3.h" =20 +#ifdef CONFIG_SYSTEM_SUSPEND +#define __init_or_smmu_suspend +#else +#define __init_or_smmu_suspend __init +#endif + #define ARM_SMMU_VTCR_SH_IS 3 #define ARM_SMMU_VTCR_RGN_WBWA 1 #define ARM_SMMU_VTCR_TG0_4K 0 @@ -1814,8 +1820,8 @@ static int arm_smmu_write_reg_sync(struct arm_smmu_de= vice *smmu, u32 val, } =20 /* GBPA is "special" */ -static int __init arm_smmu_update_gbpa(struct arm_smmu_device *smmu, - u32 set, u32 clr) +static int __init_or_smmu_suspend +arm_smmu_update_gbpa(struct arm_smmu_device *smmu, u32 set, u32 clr) { int ret; u32 reg, __iomem *gbpa =3D smmu->base + ARM_SMMU_GBPA; @@ -1995,10 +2001,35 @@ err_free_evtq_irq: return ret; } =20 +static int arm_smmu_enable_irqs(struct arm_smmu_device *smmu) +{ + int ret; + u32 irqen_flags =3D IRQ_CTRL_EVTQ_IRQEN | IRQ_CTRL_GERROR_IRQEN; + + if ( smmu->features & ARM_SMMU_FEAT_PRI ) + irqen_flags |=3D IRQ_CTRL_PRIQ_IRQEN; + + /* Enable interrupt generation on the SMMU */ + ret =3D arm_smmu_write_reg_sync(smmu, irqen_flags, + ARM_SMMU_IRQ_CTRL, ARM_SMMU_IRQ_CTRLACK); + if ( ret ) + { + dev_warn(smmu->dev, "failed to enable irqs\n"); + return ret; + } + + return 0; +} + +/* + * Probe-time only: request host IRQs and, when available, program the SMM= U's + * MSI doorbells. Resume does not restore the SMMU *_IRQ_CFGn MSI register= s, + * so any host suspend support must treat the active MSI IRQ path as + * unsupported until that restore path exists. + */ static int __init arm_smmu_setup_irqs(struct arm_smmu_device *smmu) { int ret, irq; - u32 irqen_flags =3D IRQ_CTRL_EVTQ_IRQEN | IRQ_CTRL_GERROR_IRQEN; =20 /* Disable IRQs first */ ret =3D arm_smmu_write_reg_sync(smmu, 0, ARM_SMMU_IRQ_CTRL, @@ -2028,22 +2059,7 @@ static int __init arm_smmu_setup_irqs(struct arm_smm= u_device *smmu) } } =20 - if (smmu->features & ARM_SMMU_FEAT_PRI) - irqen_flags |=3D IRQ_CTRL_PRIQ_IRQEN; - - /* Enable interrupt generation on the SMMU */ - ret =3D arm_smmu_write_reg_sync(smmu, irqen_flags, - ARM_SMMU_IRQ_CTRL, ARM_SMMU_IRQ_CTRLACK); - if (ret) { - dev_warn(smmu->dev, "failed to enable irqs\n"); - goto err_free_irqs; - } - return 0; - -err_free_irqs: - arm_smmu_free_irqs(smmu); - return ret; } =20 static int arm_smmu_device_disable(struct arm_smmu_device *smmu) @@ -2057,7 +2073,8 @@ static int arm_smmu_device_disable(struct arm_smmu_de= vice *smmu) return ret; } =20 -static int __init arm_smmu_device_reset(struct arm_smmu_device *smmu) +static int __init_or_smmu_suspend +arm_smmu_device_reset(struct arm_smmu_device *smmu) { int ret; u32 reg, enables; @@ -2163,17 +2180,9 @@ static int __init arm_smmu_device_reset(struct arm_s= mmu_device *smmu) } } =20 - ret =3D arm_smmu_setup_irqs(smmu); - if (ret) { - dev_err(smmu->dev, "failed to setup irqs\n"); + ret =3D arm_smmu_enable_irqs(smmu); + if ( ret ) return ret; - } - - /* Initialize tasklets for threaded IRQs*/ - tasklet_init(&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); - tasklet_init(&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); - tasklet_init(&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, - smmu); =20 /* Enable the SMMU interface, or ensure bypass */ if (disable_bypass) { @@ -2181,20 +2190,16 @@ static int __init arm_smmu_device_reset(struct arm_= smmu_device *smmu) } else { ret =3D arm_smmu_update_gbpa(smmu, 0, GBPA_ABORT); if (ret) - goto err_free_irqs; + return ret; } ret =3D arm_smmu_write_reg_sync(smmu, enables, ARM_SMMU_CR0, ARM_SMMU_CR0ACK); if (ret) { dev_err(smmu->dev, "failed to enable SMMU interface\n"); - goto err_free_irqs; + return ret; } =20 return 0; - -err_free_irqs: - arm_smmu_free_irqs(smmu); - return ret; } =20 static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) @@ -2558,10 +2563,23 @@ static int __init arm_smmu_device_probe(struct plat= form_device *pdev) if (ret) goto out_free; =20 + ret =3D arm_smmu_setup_irqs(smmu); + if ( ret ) + { + dev_err(smmu->dev, "failed to setup irqs\n"); + goto out_free; + } + + /* Initialize tasklets for threaded IRQs*/ + tasklet_init(&smmu->evtq_irq_tasklet, arm_smmu_evtq_tasklet, smmu); + tasklet_init(&smmu->priq_irq_tasklet, arm_smmu_priq_tasklet, smmu); + tasklet_init(&smmu->combined_irq_tasklet, arm_smmu_combined_irq_tasklet, + smmu); + /* Reset the device */ ret =3D arm_smmu_device_reset(smmu); if (ret) - goto out_free; + goto out_free_irqs; =20 /* * Keep a list of all probed devices. This will be used to query @@ -2575,6 +2593,8 @@ static int __init arm_smmu_device_probe(struct platfo= rm_device *pdev) =20 return 0; =20 +out_free_irqs: + arm_smmu_free_irqs(smmu); =20 out_free: arm_smmu_free_structures(smmu); @@ -2855,6 +2875,104 @@ static void arm_smmu_iommu_xen_domain_teardown(stru= ct domain *d) xfree(xen_domain); } =20 +#ifdef CONFIG_SYSTEM_SUSPEND + +static void arm_smmu_reset_for_suspend_rollback(struct arm_smmu_device *sm= mu) +{ + int ret =3D arm_smmu_device_reset(smmu); + + if ( ret ) + dev_err(smmu->dev, "Failed to reset during suspend rollback: %d\n", + ret); +} + +static int arm_smmu_suspend(void) +{ + struct arm_smmu_device *smmu; + int ret =3D 0; + + list_for_each_entry(smmu, &arm_smmu_devices, devices) + { + /* Abort all transactions before disable to avoid spurious bypass */ + ret =3D arm_smmu_update_gbpa(smmu, GBPA_ABORT, 0); + if ( ret ) + goto fail; + + ret =3D arm_smmu_write_reg_sync(smmu, 0, ARM_SMMU_IRQ_CTRL, + ARM_SMMU_IRQ_CTRLACK); + if ( ret ) + { + dev_err(smmu->dev, "Timed-out while disabling SMMU irqs\n"); + goto fail; + } + + /* Disable the SMMU via CR0.EN and all queues except CMDQ */ + ret =3D arm_smmu_write_reg_sync(smmu, CR0_CMDQEN, ARM_SMMU_CR0, + ARM_SMMU_CR0ACK); + if ( ret ) + { + dev_err(smmu->dev, "Timed-out while disabling smmu\n"); + goto fail; + } + + /* + * At this point the translation interface is disabled and the + * SMMU won't access translation/config structures, even + * speculatively, as per the IHI0070 spec (section 6.3.9.6). + * CMDQ is still enabled so that a CMD_SYNC can complete any + * previously issued commands. + */ + + /* Ensure all previously issued commands have completed. */ + ret =3D arm_smmu_cmdq_issue_sync(smmu); + if ( ret ) + { + dev_err(smmu->dev, "Timed-out waiting for pending commands\n"); + goto fail; + } + + /* Disable everything */ + ret =3D arm_smmu_device_disable(smmu); + if ( ret ) + goto fail; + + dev_dbg(smmu->dev, "Suspended smmu\n"); + } + + return 0; + + fail: + /* Reset the device that failed as well as any already-suspended ones. */ + arm_smmu_reset_for_suspend_rollback(smmu); + + list_for_each_entry_continue_reverse(smmu, &arm_smmu_devices, devices) + arm_smmu_reset_for_suspend_rollback(smmu); + + return ret; +} + +static void arm_smmu_resume(void) +{ + int ret; + struct arm_smmu_device *smmu; + + list_for_each_entry(smmu, &arm_smmu_devices, devices) + { + dev_dbg(smmu->dev, "Resuming device\n"); + + /* + * The reset will re-initialize all the base addresses, queues, + * prod and cons maintained within struct arm_smmu_device as well as + * re-enable the interrupts. + */ + ret =3D arm_smmu_device_reset(smmu); + if ( ret ) + panic("SMMUv3: %s: Failed to reset during resume: %d\n", + dev_name(smmu->dev), ret); + } +} +#endif + static const struct iommu_ops arm_smmu_iommu_ops =3D { .page_sizes =3D PAGE_SIZE_4K, .init =3D arm_smmu_iommu_xen_domain_init, @@ -2867,6 +2985,10 @@ static const struct iommu_ops arm_smmu_iommu_ops =3D= { .unmap_page =3D arm_iommu_unmap_page, .dt_xlate =3D arm_smmu_dt_xlate, .add_device =3D arm_smmu_add_device, +#ifdef CONFIG_SYSTEM_SUSPEND + .suspend =3D arm_smmu_suspend, + .resume =3D arm_smmu_resume, +#endif }; =20 static __init int arm_smmu_dt_init(struct dt_device_node *dev, --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095658; cv=pass; d=zohomail.com; s=zohoarc; b=kSqkGVnhsuQYo0brJQKGoCwGFJG/OvwIIbcVOemuhGpFIB0gv8+jFZfGxN79lnuDGmEmx1QDxsfjLYYVcVek5zQn4avr57Qn122l56fyORdklNUUcznsGyuPHEKhTljYwpwb6oTR6eTBrB6O0If78dJcpCBMDh8d91H/fQ4IEC8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095658; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sHwpIqiqjUhBvqtSggh5esR4e9b+MV3aX2Xvrv+38P8=; b=D+LgmvI4hbqygsTBIgdJQqWVoIunZqHHZiTZpYqX8B2EYF5LcVwwIlJhU4IzEU20KweILtee8SSmEcdwhzJKpuprfMCpFHLd3U8BraS0iOCOcLeaRoD6MZqW1V6eDU2fMGHvYKMBUfDeK7RiHkG7i7IbPA/U3oMthvNdOzOarUk= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095658754298.3565791277674; Wed, 10 Jun 2026 05:47:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334274.1597405 (Exim 4.92) (envelope-from ) id 1wXIKq-0002R8-Ez; Wed, 10 Jun 2026 12:47:08 +0000 Received: by outflank-mailman (output) from mailman id 1334274.1597405; Wed, 10 Jun 2026 12:47:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKp-0002P3-OX; Wed, 10 Jun 2026 12:47:07 +0000 Received: by outflank-mailman (input) for mailman id 1334274; Wed, 10 Jun 2026 12:45:40 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJQ-0001FS-ND for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:40 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJQ-007roF-3w for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:40 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c63-e002-0a2a0a5209dd-0a2a4509d228-44 for ; Wed, 10 Jun 2026 14:45:40 +0200 Received: from [52.101.65.137] (helo=DU2PR03CU002.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c73-2497-0a2a45090019-34654189f24b-3 for ; Wed, 10 Jun 2026 14:45:40 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:37 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:37 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=o9P6F818+1NEmAqx4GX5Y2ORpz8/xaUVvSosTGfEf9gTZfN7CCxyKCLF3sQCBt8e1BsHE4MZYMS/KUdW0BwhqaZivo0kS5rSwFqqUTXTF33baqGx41O6xRupP1613rvVVHZ4atKf8uEaoxc+G9Ht217FMbBI3IW0lOW7mlQFjWrc6yRiPj3NgWof0HMSb1R0jLLOLAq85A+Ax3/Y26GJqC56gNkCNFEE2WEIicytWs5PWmzcOHwjuq1c8op+jDLdD0/K1eMO6Up4UuekT279LyJoWvoeoHlkR1vp5VCHBzs593XGBK6/3YkIYaIqAoAxjakJJDkqYK8A1iK+OE2rag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sHwpIqiqjUhBvqtSggh5esR4e9b+MV3aX2Xvrv+38P8=; b=O+J0cnjVjQznnSIVbSYQLHjJ/ODQFY/iORwKe7suhMd4MHbHsILx4BCKzekj9G/z5K156RMw6Xx9U/SYIF2/DOEniUi+0X6Z2OxjugqPbeTKWxPST5THUSjNFaDuljXC6uhc/CXc5HgzHSHIzkH02w0kV27pvNVXh6uUqsIDSAeNVpQQMmc92jIGrVqGaOyT+oJPpMHFnH9+SD+Uq3ao8SDpyr6DSQP/Fpgz/NIVr7sBsrDw5n6axuNN97m8+dZOIhrAUybaf1fd8MLZ1mf2ArIhX3+Qvfm4+k6qfmwHAQN3VVtF/26iRGlURX0yCca0iaMGQn1p680yh8eTmIwtrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sHwpIqiqjUhBvqtSggh5esR4e9b+MV3aX2Xvrv+38P8=; b=Jr+mejaHQoO7Qv+YpTWqXfr8wKOKEk024/kqamWbWkNQOdBlN2iL06EVRz3S1hYHww9kANBe/iVVREq1ZnbjyX/ezmqAqM4KlChV94ZEuKPtKJQaox9Dn8eMCIBFPSorK0d3JOavahsozHPav1gYIj1QbPlxeew9CfZ9ktk0T84Vz6/IiVKcObJqNEaGiK6JSm6kKpEiXKH4hWZnNa2ZszBdxMp5tgMc9QrZGoi8wWn1MJhhhu7vvImjl8EGBCwmvUZUhXy/8PY8ip2w0CbUIst8ys5gl9xUGrZZ4Fq485sfS0Fg0lad4YBEB1RbnWnJF/9JcIaAldCwNZ7vG4ynFg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Oleksandr Tyshchenko , Luca Fancellu Subject: [PATCH v11 10/13] xen/arm64: Save/restore CPU context across SYSTEM_SUSPEND Date: Wed, 10 Jun 2026 15:44:30 +0300 Message-ID: <0df881b529384afbfd6ac289d3d6a14e188f5c57.1781084290.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 3217c138-79ac-4843-bcb4-08dec6ee2bee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|5023799004|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: N2/RSBYwWc43KrAmv2WLRKd663OQIz1+Abbp2Fws4xhdQnB4qDtpw1Knnu18VRKaA8Mq0nirU2TXr9LRJ54j/krrLiGKxdE3Qy9Vo9S7Nr4kbFalrvl+xqPYVwMXTpf18h4tJpuyoWzgHtxPq4o0SsJrLPP7CEon34haAMX0Os2AjTT3aih8T9m8XAmS70GXXJS4Fph96KXVnsrliaejJurpOvpHiWWViWMlTOQGYFBe2iJTIo3BW4/t9YO2fKxfXcbYeSlF7aNJSIfnYYQHycbA8GPJsohyCDzVyDm0YgL+W8d6+7DgVvgxlHEEFqCF+/L84IWfsLuJCiLuFKjvovGkStSarTfvYfg0bATBtNmfjz4Z/1VR36TPBmu5QNUq4W6MIwDnVrllvH6U626wHujomWHOKREGhw642q4Sbfp92vfZHGeGvzDl3IBRMT6dTnUf4mblUXc7u99VtjJh8vzRy/btij0gwBhX5iOTI9phMV9C9DGv7sKcEphNh6XRqKZFi9kOS6zaChBLkHOokUUf8kTg2LPlxEe8BmWsQkj/exTHsgLUEKxLhc6ghOWTEzm5GyedNqt/PNUGTObxRLfx5erSYsANFjST/IOys3iEq52KJrarBpBvtq5Szs7dAJoTHJJxFb47YfUOauG/SSiqJd2I4VHeakn5ds5iUD6NtiYGKjbLKrzByC4swAKG X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(5023799004)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?JfWsuICEPiMSUj8N18SXYmEixbEmAWnAR8RXpxVfT86mk9Ov3SsRK1gWwftK?= =?us-ascii?Q?rEBHSAjAWO7RI9ssRMOb/RzJFw8hDyIxPKavqJzrTpYPNv63SI39fBn9Lrl8?= =?us-ascii?Q?dOlo0ELKu8qBuJkMqNquTuQ+VWp73dk8ZFzMSzBVpoScZS7bD743DOuGtte0?= =?us-ascii?Q?IIzi7Bic36/Hmbucd6kmAzLifCKjbiDLkdXcgJl/HjeSedEcU2MHwX4THUoH?= =?us-ascii?Q?aK0jScl3XKqb9rznUxKU38W+rso2sM0584w6w5WULNxSGKOddkCchzlkqsiy?= =?us-ascii?Q?crHKWlOMeXsI5MxLXw/682tKtB54v1S6Q8yhZKixW261WDDMjFVne/fUViBM?= =?us-ascii?Q?O3G5Xgmo8809kWW8Piw0RoFZOWhhimGdxL10Y2CFsFCRaf6yDyMcSPsh+/Up?= =?us-ascii?Q?++2+n4HiSUU0ClCaIRssWmTwR9rZSg6KBsg10ZdYxfn3j/HTnRrU/kgRnxZM?= =?us-ascii?Q?FFLxAZEQW0A9+sEefPfY7DHmUkBfUgboTkmTczj/lcUvnJsA8bJf/EnEMA63?= =?us-ascii?Q?EwP1e3GK4YdD7lBrTKINrFf/ZcO2xDJbysNtRfJZtzonGpl08CiPGFXz5IF8?= =?us-ascii?Q?AzsYnOz4Ad888+Mp6CximuT5xra/qlPuVChZoT+JDmG0NpIYCNPvArk+1h4V?= =?us-ascii?Q?l1vj9g736ETycZXyhf6GlS40txEG2JzLAZbHL8Bg4I9rAZ1O2drZeDXN3EWm?= =?us-ascii?Q?X5NlYvPuMgt4Bjjk0UL92nau5LIW07h1Dv7dFhW8QB6U2PPc1JquCGJ8gd2F?= =?us-ascii?Q?MKsiP1rQio+a2Cmp4OkdMu2pgDS+HX88MqU8H8Ly08WERw5Aji4WanvqIy/z?= =?us-ascii?Q?e2lRNlgj9lkTTeJcw5FQCWEVG7t0DsZw0pXXnZL/RPpWfWRl4SXJEBVYnx48?= =?us-ascii?Q?EKjIETUhAojEFNtzZQJGjemwBGzjgb0X13Nk8biBTvNQcvk4FjTm8FB9Yy7i?= =?us-ascii?Q?pMMPUDgmFly2UxEQhAAD2rGiJocVyNYvgiS37gSU7YzQjI5B2nREiTEuDXZQ?= =?us-ascii?Q?Ej76kKV2mB7HznIaYEWT5Hu8icGl4S3SSJgPMOB6rDPQTdKYr+9BEcjVetAZ?= =?us-ascii?Q?XVQ7KSHzW+hgQEM/oO9QcX6UCLijokEPgakVTWj5PHNIDDiag/lwMZOntdar?= =?us-ascii?Q?EmjI5iKgd2yq6BoU9SEn/kxfbck3vVXUPpem5FiQGwwjDTr57o9aL+RSm50M?= =?us-ascii?Q?SKUpakwXkTNT9jqGo4GTCKolFxHJaA90qnOiZAqNyEl1FMrYxi4rLFdfjvlg?= =?us-ascii?Q?mVzmu6M4aEsxTp0KsnvaUUMLa5kr7WGWxfVTjXEN0ub6myiGgquBpumaCcTB?= =?us-ascii?Q?6pWpqfI0o+ZMgdJYQ/vrz3oD8fszwMkVY2E+b2qEYv2k4cxs2C8Aeccui3jb?= =?us-ascii?Q?vKlG738DPerkushLTkuFiUdfXHCWQ9yRXuITISvWCMUzhz0s6KzmdVCKqglZ?= =?us-ascii?Q?dUIQZiv0hyXhso8Gu40w7kmlYJKPTqspQ1PrlOPLtazZWyLb7WM7dG/M69D2?= =?us-ascii?Q?jfED61qPL2PjB0bOv0SwbbQSCM5l1aEm22urD8+mJapjrdweyPS6VSk7+st/?= =?us-ascii?Q?DFbSGOpwbTVso5XpF2unHY2kG8jRDhxgJIE0Ie3tHkGoJEYScbpNrSvRqSxi?= =?us-ascii?Q?K4CoK/241C3uycTQpYrP/d1YEy1tWkXh2J9NAtHVy4OEangqSzw4syJPwhfE?= =?us-ascii?Q?pHeBZDidHoQwq8M9DTysStkFH92KGbCVvfKtlRAMY4dIFt9etN46yrrTWMpU?= =?us-ascii?Q?eLko7YP/qw=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3217c138-79ac-4843-bcb4-08dec6ee2bee X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:37.6398 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oFoy28qX0pFvFgTUHT+XqTBf9iqSgbxxCBhqYPPgr4kss01gn3EJWXwFX37DQpb7tHBIxLKX1VFt9C3l6/67QQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-bad1c0/1781095540-89174A53-26438CAD/0/0 X-purgate-type: clean X-purgate-size: 11487 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095659805158500 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic On wakeup from PSCI SYSTEM_SUSPEND, Xen re-enters EL2 with the MMU and data cache disabled. The resume path must first switch back to Xen's runtime page tables before it can access the saved CPU context using virtual addresses. Add an arm64 hyp_resume trampoline that reuses enable_secondary_cpu_mm() to enable the data cache and MMU, switch to init_ttbr, and resume in the runtime virtual mapping. The trampoline then restores the saved CPU general-purpose and system-control register context. prepare_resume_ctx() must be invoked just before the PSCI system suspend call is issued to the platform firmware. It saves the current CPU context and returns a non-zero value so that the caller enters the physical SYSTEM_SUSPEND call. On resume, hyp_resume restores the saved context, including the saved link register. Control therefore returns to the place where prepare_resume_ctx() was called. To avoid re-entering the suspend path, the restored path sees prepare_resume_ctx() return zero. The assembly save/restore code uses offsets generated by asm-offsets.c from struct resume_cpu_context, keeping the assembly memory accesses in sync with the C structure layout. Support for ARM32 is not implemented. Instead, compilation fails with a build-time error if suspend is enabled for ARM32. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykyta Poturai Signed-off-by: Mykola Kvach Reviewed-by: Oleksandr Tyshchenko Reviewed-by: Luca Fancellu --- Changes in v10: - Save and restore CNTHCTL_EL2 across SYSTEM_SUSPEND Changes in v9: - Drop the misleading prepare_resume_ctx() pointer argument and make both save/restore paths use the global resume_cpu_context. - Squash the arm64 resume trampoline into the context save/restore patch. - Document in code that hyp_resume relies on PSCI initial-state rules. - Use generic platform firmware wording instead of ATF-specific wording. - Rename the saved context type/storage to resume_cpu_context and rely on implicit zero-initialization for the file-scope object. - Use asm-offsets.c-generated RESUME_CTX_* offsets to keep the assembly save/restore code in sync with struct resume_cpu_context. Changes in v8: - Fix alignments in code. Changes in v7: - No functional changes, just moved commit. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/asm-offsets.c | 21 +++++ xen/arch/arm/arm64/head.S | 122 +++++++++++++++++++++++++++++ xen/arch/arm/include/asm/suspend.h | 27 +++++++ xen/arch/arm/suspend.c | 14 ++++ 5 files changed, 185 insertions(+) create mode 100644 xen/arch/arm/suspend.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 84c4062b30..e256b0b348 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -51,6 +51,7 @@ obj-y +=3D setup.o obj-y +=3D shutdown.o obj-y +=3D smp.o obj-y +=3D smpboot.o +obj-$(CONFIG_SYSTEM_SUSPEND) +=3D suspend.o obj-$(CONFIG_SYSCTL) +=3D sysctl.o obj-y +=3D time.o obj-y +=3D traps.o diff --git a/xen/arch/arm/arm64/asm-offsets.c b/xen/arch/arm/arm64/asm-offs= ets.c index 38a3894a3b..5d60406e9c 100644 --- a/xen/arch/arm/arm64/asm-offsets.c +++ b/xen/arch/arm/arm64/asm-offsets.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 #define DEFINE(_sym, _val) = \ asm volatile ( "\n.ascii\"=3D=3D>#define " #_sym " %0 /* " #_val " */<= =3D=3D\""\ @@ -57,6 +58,26 @@ void __dummy__(void) OFFSET(INITINFO_stack, struct init_info, stack); BLANK(); =20 +#ifdef CONFIG_SYSTEM_SUSPEND + OFFSET(RESUME_CTX_X19, struct resume_cpu_context, callee_regs[0]); + OFFSET(RESUME_CTX_X21, struct resume_cpu_context, callee_regs[2]); + OFFSET(RESUME_CTX_X23, struct resume_cpu_context, callee_regs[4]); + OFFSET(RESUME_CTX_X25, struct resume_cpu_context, callee_regs[6]); + OFFSET(RESUME_CTX_X27, struct resume_cpu_context, callee_regs[8]); + OFFSET(RESUME_CTX_X29, struct resume_cpu_context, callee_regs[10]); + OFFSET(RESUME_CTX_SP, struct resume_cpu_context, sp); + OFFSET(RESUME_CTX_VBAR_EL2, struct resume_cpu_context, vbar_el2); + OFFSET(RESUME_CTX_VTCR_EL2, struct resume_cpu_context, vtcr_el2); + OFFSET(RESUME_CTX_VTTBR_EL2, struct resume_cpu_context, vttbr_el2); + OFFSET(RESUME_CTX_TPIDR_EL2, struct resume_cpu_context, tpidr_el2); + OFFSET(RESUME_CTX_MDCR_EL2, struct resume_cpu_context, mdcr_el2); + OFFSET(RESUME_CTX_HSTR_EL2, struct resume_cpu_context, hstr_el2); + OFFSET(RESUME_CTX_CPTR_EL2, struct resume_cpu_context, cptr_el2); + OFFSET(RESUME_CTX_HCR_EL2, struct resume_cpu_context, hcr_el2); + OFFSET(RESUME_CTX_CNTHCTL_EL2, struct resume_cpu_context, cnthctl_el2); + BLANK(); +#endif + OFFSET(SMCCC_RES_a0, struct arm_smccc_res, a0); OFFSET(SMCCC_RES_a2, struct arm_smccc_res, a2); OFFSET(ARM_SMCCC_1_2_REGS_X0_OFFS, struct arm_smccc_1_2_regs, a0); diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 72c7b24498..962be716ae 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -561,6 +561,128 @@ END(efi_xen_start) =20 #endif /* CONFIG_ARM_EFI */ =20 +#ifdef CONFIG_SYSTEM_SUSPEND +/* + * int prepare_resume_ctx(void) + * + * CPU context saved here will be restored on resume in hyp_resume functio= n. + * prepare_resume_ctx shall return a non-zero value. Upon restoring context + * hyp_resume shall return value zero instead. From C code that invokes + * prepare_resume_ctx, the return value is interpreted to determine whether + * the context is saved (prepare_resume_ctx) or restored (hyp_resume). + */ +FUNC(prepare_resume_ctx) + ldr x0, =3Dresume_cpu_context + + /* Store callee-saved registers */ + stp x19, x20, [x0, #RESUME_CTX_X19] + stp x21, x22, [x0, #RESUME_CTX_X21] + stp x23, x24, [x0, #RESUME_CTX_X23] + stp x25, x26, [x0, #RESUME_CTX_X25] + stp x27, x28, [x0, #RESUME_CTX_X27] + stp x29, lr, [x0, #RESUME_CTX_X29] + + /* Store stack-pointer */ + mov x2, sp + str x2, [x0, #RESUME_CTX_SP] + + /* Store system control registers */ + mrs x2, VBAR_EL2 + str x2, [x0, #RESUME_CTX_VBAR_EL2] + mrs x2, VTCR_EL2 + str x2, [x0, #RESUME_CTX_VTCR_EL2] + mrs x2, VTTBR_EL2 + str x2, [x0, #RESUME_CTX_VTTBR_EL2] + mrs x2, TPIDR_EL2 + str x2, [x0, #RESUME_CTX_TPIDR_EL2] + mrs x2, MDCR_EL2 + str x2, [x0, #RESUME_CTX_MDCR_EL2] + mrs x2, HSTR_EL2 + str x2, [x0, #RESUME_CTX_HSTR_EL2] + mrs x2, CPTR_EL2 + str x2, [x0, #RESUME_CTX_CPTR_EL2] + mrs x2, HCR_EL2 + str x2, [x0, #RESUME_CTX_HCR_EL2] + mrs x2, CNTHCTL_EL2 + str x2, [x0, #RESUME_CTX_CNTHCTL_EL2] + + /* prepare_resume_ctx must return a non-zero value */ + mov x0, #1 + ret +END(prepare_resume_ctx) + +FUNC(hyp_resume) + /* + * PSCI states that SYSTEM_SUSPEND follows the CPU_SUSPEND initial + * state rules, so PSCI-compliant firmware must enter the return + * exception level with DAIF masked. + */ + + /* Initialize the UART if earlyprintk has been enabled. */ +#ifdef CONFIG_EARLY_PRINTK + bl init_uart +#endif + PRINT_ID("- Xen resuming -\r\n") + + bl check_cpu_mode + bl cpu_init + + ldr x0, =3Dstart + adr x20, start /* x20 :=3D paddr (start) */ + sub x20, x20, x0 /* x20 :=3D phys-offset */ + ldr lr, =3Dmmu_resumed + b enable_secondary_cpu_mm + +mmu_resumed: + /* Now we can access the saved context, so restore it here. */ + ldr x0, =3Dresume_cpu_context + + /* Restore callee-saved registers */ + ldp x19, x20, [x0, #RESUME_CTX_X19] + ldp x21, x22, [x0, #RESUME_CTX_X21] + ldp x23, x24, [x0, #RESUME_CTX_X23] + ldp x25, x26, [x0, #RESUME_CTX_X25] + ldp x27, x28, [x0, #RESUME_CTX_X27] + ldp x29, lr, [x0, #RESUME_CTX_X29] + + /* Restore stack pointer */ + ldr x2, [x0, #RESUME_CTX_SP] + mov sp, x2 + + /* Restore system control registers */ + ldr x2, [x0, #RESUME_CTX_VBAR_EL2] + msr VBAR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_VTCR_EL2] + msr VTCR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_VTTBR_EL2] + msr VTTBR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_TPIDR_EL2] + msr TPIDR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_MDCR_EL2] + msr MDCR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_HSTR_EL2] + msr HSTR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_CPTR_EL2] + msr CPTR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_HCR_EL2] + msr HCR_EL2, x2 + ldr x2, [x0, #RESUME_CTX_CNTHCTL_EL2] + msr CNTHCTL_EL2, x2 + isb + + /* + * Since context is restored return from this function will appear + * as return from prepare_resume_ctx. To distinguish a return from + * prepare_resume_ctx which is called upon finalizing the suspend, + * as opposed to return from this function which executes on resum= e, + * we need to return zero value here. + */ + mov x0, #0 + ret +END(hyp_resume) + +#endif /* CONFIG_SYSTEM_SUSPEND */ + /* * Local variables: * mode: ASM diff --git a/xen/arch/arm/include/asm/suspend.h b/xen/arch/arm/include/asm/= suspend.h index 31a98a1f1b..c848fc6340 100644 --- a/xen/arch/arm/include/asm/suspend.h +++ b/xen/arch/arm/include/asm/suspend.h @@ -3,6 +3,8 @@ #ifndef ARM_SUSPEND_H #define ARM_SUSPEND_H =20 +#include + struct domain; struct vcpu; struct vcpu_guest_context; @@ -14,6 +16,31 @@ struct resume_info { =20 void arch_domain_resume(struct domain *d); =20 +#ifdef CONFIG_SYSTEM_SUSPEND +#ifdef CONFIG_ARM_64 +struct resume_cpu_context { + register_t callee_regs[12]; + register_t sp; + register_t vbar_el2; + register_t vtcr_el2; + register_t vttbr_el2; + register_t tpidr_el2; + register_t mdcr_el2; + register_t hstr_el2; + register_t cptr_el2; + register_t hcr_el2; + register_t cnthctl_el2; +} __aligned(16); +#else +#error "Define resume_cpu_context structure for arm32" +#endif + +extern struct resume_cpu_context resume_cpu_context; + +int prepare_resume_ctx(void); +void hyp_resume(void); +#endif /* CONFIG_SYSTEM_SUSPEND */ + #endif /* ARM_SUSPEND_H */ =20 /* diff --git a/xen/arch/arm/suspend.c b/xen/arch/arm/suspend.c new file mode 100644 index 0000000000..6ea4a0f9cc --- /dev/null +++ b/xen/arch/arm/suspend.c @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +struct resume_cpu_context resume_cpu_context; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095651; cv=pass; d=zohomail.com; s=zohoarc; b=KbXA+JdywG6CUrdIvBFABCBaz4STZhPWTG1A8X11KbSaqgXGuMvaCJ45KrP8bxzk/m8eyuNsycNsCn8nc2Zous5LsNrWKM2SuWvSFOgjn8/VhfspW3jG1xIK1F6TvVTs1D6pN/oXG2SV5aZLds329YW7IdlgKZ8dKqWvdEE/txE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095651; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9Q1Fsw7I5VcRKOn6Vwcp1VtMdJtga40n5Ed4Emmc+5c=; b=WEuwb6jBHzM4lQNZ5jgKQD9H6kan61g/lEGuO6E3m70H3cxGGM6qOzFCK7Rvn3XR4cyZNN0qk1FjpinxfWR7xqcyM4Qaw51rjxHWWP/gBJFDtZSTC2aL9BTwjxJguc2xUVGs94CjXvvdGoyV2Htf9BfsauHbLxElnEfJRF6u4NM= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095651944217.48359766568603; Wed, 10 Jun 2026 05:47:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334276.1597411 (Exim 4.92) (envelope-from ) id 1wXIKr-0002e4-2t; Wed, 10 Jun 2026 12:47:09 +0000 Received: by outflank-mailman (output) from mailman id 1334276.1597411; Wed, 10 Jun 2026 12:47:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKq-0002az-Bq; Wed, 10 Jun 2026 12:47:08 +0000 Received: by outflank-mailman (input) for mailman id 1334276; Wed, 10 Jun 2026 12:45:43 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJT-0001G1-8Q for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:43 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJS-007roF-LC for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:42 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c75-e002-0a2a0a5209dd-0a2a4509edfa-2 for ; Wed, 10 Jun 2026 14:45:42 +0200 Received: from [52.101.72.83] (helo=AM0PR02CU008.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c76-2497-0a2a45090019-34654853ba2b-3 for ; Wed, 10 Jun 2026 14:45:42 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:40 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:40 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oYqAFxO9WriTpN6UHnaYCQ1s5lWXCvxhCdsuhpPZLJVtzLnLGRzBPISmyfCqPhecmjLlfL4hT6eixy6QttttPpyPHntFfz/FR3FfqpEVUzeY90QATM32j4n568uaHyerUlVlzYyCZLzMoc5W1wGeQkxg00NuwyacZK0VbGuOhie02LoqGg8OhVe2jfJjCXC6K5RY1w2kHkyhnW/+EEBDvw7yuMj+vWw72UUAkcsKVh0Uk/sc2dbHvUNi92IUT2HsALaonJ1sxf6qP6VA263IQvWJ7i97w/HgD3LBH0GS2IQ5vCxw7B4sYUbBm3NX6N9UlPTNnPIhloL2OJBsbMZcoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9Q1Fsw7I5VcRKOn6Vwcp1VtMdJtga40n5Ed4Emmc+5c=; b=MttiLgnubCorR63FeNIhlqHe/88i1rOWAc5EuqvtZgOQdKecPlpwRuQti2LmEjX5W4XJN/0YEmsDcy5/MXoDaqXEyGYtGM+6jojQkK9lQfN1QBsN/8+/KrWJE8smvXxjtLiXgfhKtIK2T2BWSUXH7oj895EUxezaz3QEDtYU7gLrnETLtPWtYFDGQKXZ+HbRklsTpujTWKqdCVq50c45Lditd9eozfBEPrTEHUkFQbWvTlwJiyUkot3+YamnGtwUvjQ0RhnkNjrPoUXnsO/qMr71XZB+ULb9VovZPffkE3TmmEmLFCPwItqme6X5GegejDiflQLk0/Cw/NQ0F56bog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9Q1Fsw7I5VcRKOn6Vwcp1VtMdJtga40n5Ed4Emmc+5c=; b=hChIU2nE4+B0KQz+25FU/YnMcmk3Uycb9acMFdERJdsWjWi+0k4QIyNrMZton4LH/4aCplO+QqvOvvFAENgEKP8dkQ6X3382ihAkQXb6FveS3zHsmlr6Ryp9UZVZd9fKXV22NYqSVwiXtc2RQ6SmvgR995fsF9eWypG8OS0pdf3MXztvzdCYUEsV8059tCekybruWf8zB/zSgbSPfgR89xidWBgaOJk10TfVU/m56pJAax9htojlkzD5EeDRncWR9JyQvp18I9KZ1vLhltuc2N+CKsSGpBg/yPGbd1dBWCgVAEZXXc5NXylaY63xC7eGKn/HONaCpUzXmD3ji8Io/Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Luca Fancellu Subject: [PATCH v11 11/13] xen/arm: Implement PSCI SYSTEM_SUSPEND call (host interface) Date: Wed, 10 Jun 2026 15:44:31 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c8e49bb-9f50-4e71-53b5-08dec6ee2dbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|56012099006|11063799006|5023799004|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: PyPGwlfat60c4X9V0EPlTKI5aaa3rq3dm1Zh8FUd3LeJhbLbPoxSzq4QwMDqbAYl9Y69k2WLPU98eShJZtYCaGsDZYQSXIRm7jUPP/bhzVRyN3ZrwlmBwtxSOr4S+ydI+SDxHhNA4z4uNApjipJYrkQSfgabbkgYuIG30fXINpyfLQT+CGLXEgBQU0kXgd+/sI8m8hjqF+CRFjzBUg54dsVkQkRdZqzMIBeSWDITVqSxr81BzQumbSlDEFyQPQNoPR+EibjT+VCphAllfj+9dZpal+r9zvHE+uVIB+kdY3QQmDpTdgaiop1/OzFKBwApJ18WeYv9d5+0FHo498+Ekr6wUGYECh86bIuSnS5CBnkCgrDehPla1AjgMb2ThiOq2KZ3H/UXZi9oOI6AI5Ld3SV5G+nSLnW4K3f4RDDpHipsmriD5wHP4RYQTeq4pplCMouiWz3YCLB+RCRBm/b/nw888DT+9VfbD7pyiHnMAIJaUoBG8p5bwztp8mZSGbUCm/3jdagoEnktiyu81BD48CJZAQpK1HtgDOb9LctrTThVaXUfwZFo+CnlvwWxdVptCMrtpUJHYHjxRZZbNBC40SeME4W/zXpeOrs3EKGCeHB4TNXj/j+N1RXxeFMHZ2L2RF1tBDdjTkZk2oFWtlHRw5pk5Xg/XjR1yl+54ikg7pt2RNRu1DZY5aPCbQ6LoiMS X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(56012099006)(11063799006)(5023799004)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?8Jk5hx+dR2gBkG7z+XeERo2Vu83vLXXfWCXVQPHpMiTuSyE0FnDexxpN1p6P?= =?us-ascii?Q?7JWSSiGUh7U0sTVnIumM10Fi4T9MA6tBJYCDI75DUJCDAOojpe3SeVuf3lOs?= =?us-ascii?Q?nFTyNJ5Wr4wzhz4D4dSfU8uUmCvz2ChhgzxBstfxeyOsUiIeMlUkGjcULw7a?= =?us-ascii?Q?DqDduat+FD9jWFUoIicicdA+R/835jkjsMlBi2DHec7S+HOA5q4t2FtXFZNi?= =?us-ascii?Q?DM3oAKaLfWTLfStF3RYYC8FW1paB1dqDF6u62iNDmtLvN4FOSE/nZDaNQwlo?= =?us-ascii?Q?xDd7yEw/OHJEVW3MbgUCYgLfFiGKMpFyL/wNpCvJNI9YKprd+/EqPzYAyVWH?= =?us-ascii?Q?6JmEKW6w6+vl+3yykfUSJLUZsWVuA62SSULCpDwwDpT0FtpWXJSmleHgODeu?= =?us-ascii?Q?WsrElT21j0AuanYkVsgYz74YGRhZ8kIfbJWn5xQP6H2sdUjqxr3SHft58i+I?= =?us-ascii?Q?Py10jSzkO4nYtin9rREouoXD58UsAwLEitI6lJw6txJRyPkESP/YwciuiSAw?= =?us-ascii?Q?+6mVlNdipo2Lpz+dnSGVRWT8A1KUK3sS8HgF1qaioe8trNBNVGA9lLpL+oBE?= =?us-ascii?Q?L7S0sxQ0EHMM/TnR9eUt/JAmCNs6eQurYy9m79q6pMCkTfq81t8jky2EdoAE?= =?us-ascii?Q?oxMlEzIbYSbRpdEKY5ivb6MZ5WGZqMulB7Q9f1cm5+3kgJQQHVYbzKor0Nu/?= =?us-ascii?Q?FW2tcPikBTr98APF4y1isk4suy5aXVvYLB5KXH+QUMhpt1Udp0F5lmDY5D7A?= =?us-ascii?Q?2SxTY2Vns/rwBQFDQ64FpTb7BYpJNJyDRmCWWv6n+5RTVnX91SPBgGFDnUDe?= =?us-ascii?Q?ROsI4i8v05AaQHx2eDrzXinpDP629CSO7TfarZYQZDLmETEhQuj4EoSWOY/6?= =?us-ascii?Q?dq2VquW/wWtB6JMk6D4bqGtJ8sOsk+bAdmunF7BZ+SFqmem2c6TGqTlQdVk+?= =?us-ascii?Q?BnUifUobQiMCeQ1doRrx3AppEeUcb20Y5WBz8K2Tgj6oJJuMmrZiZ1wcInHN?= =?us-ascii?Q?I7OcV8CjEw7T9wg2p/NG76MHV8WdHzyrVQZx85jFTp1Fiu31NGH79jAQM4wS?= =?us-ascii?Q?fMf2fEbXy/9Uy+VaJLOLajnk17QBc6XjOpLqH7zKJe1O+nr2cv3BXxkAPFXJ?= =?us-ascii?Q?ksZVyR/jaX2YW308sxnLS2Tj/33q4EktSzoyKGVTlmhrVBoOw4aDXbLNNo14?= =?us-ascii?Q?aoxT456K+RdqOxe6QZ5un8/Shl7XjUhhAnoQOI8OBpywyjw+Dj9fEeQ/CrKh?= =?us-ascii?Q?rg0LIR7zZMss1EPlyIehnGfvrwQWbtuazCTjnDaCGkquyGkvnYDO5O3jAu17?= =?us-ascii?Q?daz1+xezOHNjsRwOYKVQUzFM5ECr/1+RDfxZnFvUu4gIUWUV9hqfmQJ7fuuw?= =?us-ascii?Q?tDFQQaYdmn7KzKmBRDKIMIcShXW1NXLUvU2t3XjZrka0mKT85KeE05gLwEzj?= =?us-ascii?Q?7kK2wek/nWcrHix2LirI68Na0Bu2AROBzzEor8ZUPHTbVDXa4uipDbztXouY?= =?us-ascii?Q?SoDBuUI5Ij9T7C+apP2oMX6F6Y5KkuHSPgZmid9dq2OgrAOLzUhi3gjaFsSW?= =?us-ascii?Q?8GYhtGt6Z3xIzwmR7KqhxkGJEvfDw05VIFqHV+q3pyTOSJhuqZ1p6f6GGLNL?= =?us-ascii?Q?LY/MlJ08F709doO3Qar/MDzfIHYfOqtPVEYJJPysVaEoQb4Aov8HupQTQ8MW?= =?us-ascii?Q?R3SP4s+0FUlXxHnZIq7tA5GQQmCHD3i8G5dTzUV/mPOP83xVm/h5o4AfmEVf?= =?us-ascii?Q?9r2RiA+3hg=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c8e49bb-9f50-4e71-53b5-08dec6ee2dbb X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:40.6981 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: znTOm2RgPgTWjxTSkdsw12O7JlS7TxtwEQte/g8tqdczjs6qZ7PK9Qcu430PrExrbGAszofyWkbotg8B7JWCeA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-bad1c0/1781095542-8B193A53-6591A88C/0/0 X-purgate-type: clean X-purgate-size: 4081 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095653477158500 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic Invoke PSCI SYSTEM_SUSPEND to finalize Xen's suspend sequence on ARM64 platforms. Pass the Xen resume entry point (hyp_resume) to EL3 together with a zero context ID, matching Linux. This patch wires up only the host-side PSCI SYSTEM_SUSPEND invocation. The resume trampoline and context restore are provided by earlier patches in the series. Only enable this path when CONFIG_SYSTEM_SUSPEND is set and PSCI advertises SYSTEM_SUSPEND via PSCI_FEATURES. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykyta Poturai Signed-off-by: Mykola Kvach Reviewed-by: Luca Fancellu --- Changes in v9: - cache SYSTEM_SUSPEND support using PSCI_FEATURES and gate the host call on the cached capability - keep the cached SYSTEM_SUSPEND capability read-only after init - log whether firmware reports SYSTEM_SUSPEND support - pass an explicit zero context ID in the SYSTEM_SUSPEND call - drop the stale note claiming hyp_resume is still a stub --- xen/arch/arm/include/asm/psci.h | 1 + xen/arch/arm/psci.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/psci.h b/xen/arch/arm/include/asm/psc= i.h index 48a93e6b79..bb3c73496e 100644 --- a/xen/arch/arm/include/asm/psci.h +++ b/xen/arch/arm/include/asm/psci.h @@ -23,6 +23,7 @@ int call_psci_cpu_on(int cpu); void call_psci_cpu_off(void); void call_psci_system_off(void); void call_psci_system_reset(void); +int call_psci_system_suspend(void); =20 /* Range of allocated PSCI function numbers */ #define PSCI_FNUM_MIN_VALUE _AC(0,U) diff --git a/xen/arch/arm/psci.c b/xen/arch/arm/psci.c index b6860a7760..e05dae1133 100644 --- a/xen/arch/arm/psci.c +++ b/xen/arch/arm/psci.c @@ -17,23 +17,27 @@ #include #include #include +#include =20 /* * While a 64-bit OS can make calls with SMC32 calling conventions, for * some calls it is necessary to use SMC64 to pass or return 64-bit values. - * For such calls PSCI_0_2_FN_NATIVE(x) will choose the appropriate + * For such calls PSCI_*_FN_NATIVE(x) will choose the appropriate * (native-width) function ID. */ #ifdef CONFIG_ARM_64 #define PSCI_0_2_FN_NATIVE(name) PSCI_0_2_FN64_##name +#define PSCI_1_0_FN_NATIVE(name) PSCI_1_0_FN64_##name #else #define PSCI_0_2_FN_NATIVE(name) PSCI_0_2_FN32_##name +#define PSCI_1_0_FN_NATIVE(name) PSCI_1_0_FN32_##name #endif =20 uint32_t psci_ver; uint32_t smccc_ver; =20 static uint32_t psci_cpu_on_nr; +static bool __ro_after_init has_psci_system_suspend; =20 #define PSCI_RET(res) ((int32_t)(res).a0) =20 @@ -60,6 +64,25 @@ void call_psci_cpu_off(void) } } =20 +int call_psci_system_suspend(void) +{ +#ifdef CONFIG_SYSTEM_SUSPEND + struct arm_smccc_res res; + + if ( !has_psci_system_suspend ) + return PSCI_NOT_SUPPORTED; + + /* Context ID is unused for the Xen resume path. */ + arm_smccc_smc(PSCI_1_0_FN_NATIVE(SYSTEM_SUSPEND), __pa(hyp_resume), 0, + &res); + return PSCI_RET(res); +#else + dprintk(XENLOG_WARNING, + "SYSTEM_SUSPEND not supported (CONFIG_SYSTEM_SUSPEND disabled)= \n"); + return PSCI_NOT_SUPPORTED; +#endif +} + void call_psci_system_off(void) { if ( psci_ver > PSCI_VERSION(0, 1) ) @@ -223,9 +246,15 @@ int __init psci_init(void) =20 psci_init_smccc(); =20 + has_psci_system_suspend =3D + psci_features(PSCI_1_0_FN_NATIVE(SYSTEM_SUSPEND)) =3D=3D 0; + printk(XENLOG_INFO "Using PSCI v%u.%u\n", PSCI_VERSION_MAJOR(psci_ver), PSCI_VERSION_MINOR(psci_ver)); =20 + printk(XENLOG_DEBUG "PSCI SYSTEM_SUSPEND is %ssupported by firmware\n", + has_psci_system_suspend ? "" : "not "); + return 0; } =20 --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095659; cv=pass; d=zohomail.com; s=zohoarc; b=D0ShRRTsGHIUIAdSUWgLPFY1uBj1LIHiThwLwhfx0dUewVaXVteyiCB+itxV1X0aaNDXpa96uj167rOC5AoIILHM9f8OxxIIgmUS3uwMnSwN/N5R59J469nMbCxNZqam8F5Uv9r/wxqWMDMymRZ2I7L1mnaLWYb1LHJyLdMwgVY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095659; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tFuYFSOecUKDErsyX3reeE5XOMbs8qgQiXdEZieBcHY=; b=KorHyC6FlrMRKMKckOVvmXw5jd9s+N7HdMbIpWdU5D4OKqhyiYVSEYP3xDlWiW4/gqH/MoomTxmhj7YUVR0etRKWnDMJqXqXggFngRSThie/uEO9XMvDQ5wl0kCO0AyCtUGKv6UOsSwFGMNoL39MWO8v1WZ8ODgFKYRBfx+14cA= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1781095659266540.6594283547945; Wed, 10 Jun 2026 05:47:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334278.1597419 (Exim 4.92) (envelope-from ) id 1wXIKr-0002nv-L7; Wed, 10 Jun 2026 12:47:09 +0000 Received: by outflank-mailman (output) from mailman id 1334278.1597419; Wed, 10 Jun 2026 12:47:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKr-0002lR-0k; Wed, 10 Jun 2026 12:47:09 +0000 Received: by outflank-mailman (input) for mailman id 1334278; Wed, 10 Jun 2026 12:45:48 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJY-0001H0-0X for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:48 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJX-009EBh-DE for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:47 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c6f-bab6-0a2a0a5309dd-0a2a450cbe3a-48 for ; Wed, 10 Jun 2026 14:45:47 +0200 Received: from [52.101.69.83] (helo=AM0PR83CU005.outbound.protection.outlook.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c7b-62f1-0a2a450c0019-346545532a7e-3 for ; Wed, 10 Jun 2026 14:45:47 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:44 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:43 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sFENJWjp6vpe4JCg7uBY9k2rtKuOblzWkiatvKfjejCivJ7qPqUTDQQxk2X/JuZF2WhlX/YhxFK8WRxIRaS0QPsyyAiG+53Blw6Oq5Gty6O3KLu2FjdMAnPyWtRAlgT1a9QpcmwGGFtV/lH0V4nOudjflWj1FdSEQ30ckNc8hS7SJ5C6p4ZdGdaFyBwYBVLi4Uuo0dWZ5oxCXg4WmCyUy9qmzKfpdRAoT7Avtaqc4fh6jOWuiIqJi2OkePViPlhWmnhRToN+KYj+GVWfZg1u2PslEBrJyVa9ziclP76f0+3Lbu0cq/0RPKmdik87+OPEFR5IelClfwu/9sWWKiNqdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tFuYFSOecUKDErsyX3reeE5XOMbs8qgQiXdEZieBcHY=; b=blQROoOMJZ7uSE9krhXyjGBFMwJuHgm5mkdCtGRXLLQ4YLSrGfKReaW8Y3HV0dU5zUbB6SV0As3cwR2uuVk0RA5SJgl4UreNGa6fCHtAo3Frh1pLUXAwPRK8fLhe6MxInAMP4yEYD9/XWE+eKVwm+n9N1OXaRCSx/zJoyots7YPp8vdOpdxmvURqm+PB13uSvHcMP7Iroz/fjIE123fsJDKm8OMTNU5BJ+PafRn2KWtXvev52Sg6UYcSA+Gc7HZIXYUKghDi0PS5QoKtEyRHAzFjZac3y8C9U52dSnLgTgiYPD8GeX7Xve9Jqzsh/RO0adLoP31Gwrw7TNi39XdVnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tFuYFSOecUKDErsyX3reeE5XOMbs8qgQiXdEZieBcHY=; b=vf1bzzP3hn6FuGn4+11tNRiwiU2KvnOOOuA/DaOnK+4XdRvWbB/9MtjnNh9FwNry8jd7GTmYvMncT1vsla+FAkhAJ9DI3mOD9Q8bs0eT6q/070u7ES7RLiwB7b+tkvCqLxLnrGal9kkbE1rkidj2G61isfDAErzylULZC50tIK/FGBNzoSE7FCT5SarWemBf+cY6JNjWFI6EHhXei5ctzag47cGn/n9YFodyg4aewbIhA8P6Hbyeuj/8UEEOVS8oG5D7hdO4NicK4YzyrDY9FsQV2kgpfxIEJpm9fKZHH4xvoMq1RXWWEVHs/9TYulBLiS0wJvSQkBAjv9DztE01Jg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Rahul Singh , Oleksandr Tyshchenko Subject: [PATCH v11 12/13] xen/arm: Add vPSCI SYSTEM_SUSPEND policy Date: Wed, 10 Jun 2026 15:44:32 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 9dcc0362-d773-4f48-2cc7-08dec6ee2f2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|7416014|376014|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: TyMmcxTH3pgd1/LNPkFM2wW0B245+U+dPGBk47RHt833trsJoQt0XBmtq9DGfxpBHXPE0GwwVjRKoFdjkzSRdkawrvsZnp6YE0VfieRt6trSFpGpW7GH+Kymjzz67069GsU0nCEsXXeiiLpTs8uMtAYQD3SJ2lbEz3OCJYrY0wlO9LZPkiErvm34YTwS+ZEbdNYSTdhSOx0Psx3jnWcmN8VQOEGS86kVKdeIpzIlF78MH4q/ot5HI+6ooIhEydic3Dk/35Hm29/U1f3/vay85DLtBXCgtbytXQpcEOMEK0EwlqruYv1QDuvFmztBb9AtHXezNwVxxlLB3J/f4YqBEtDMYwcCxnq/nhNsTjCgSJZbTlZtkOWOnvspPlJEbdWNgLGhwcFF6EeQF0WlWPJ4kWV/Utf+1zQtkGU9JAfjZtUtCOdPVPTXZGYJmDYfeem/fv8H7Mx2vndcSnUQvZ3VtQqwXoo3/te5P0qNsjTxVGR8F1BSGMtjxK+taosXN6uFCqYbzNY8231gHU93GqCUu57bWGTKMD1ClAwK/2+DX+5qkMrFDtnNUG19c56WJtnYQHj/HAhAhHWjpPkV9PkKTTwiWXmVOgtf46mGPXyKdTROEC2cqJiy4PBU2O02CgitYe9Mjze0OBG/wvn7NSF0CmsDiav4rKHeAJSrK4qpkl4jZj1bSo2KX50GR+4sTQoo X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(7416014)(376014)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?5HTXcxKUqjp3vh2bOV6qGzGSDyq0LoSZTfQaL3OLG+xg6URedz6/MRdXWQIt?= =?us-ascii?Q?kR9FCxUmoir3wd8ac2OEyn6YJvmK3T+Z11wZ3K0dDI3lfkjL95wSftNkZC/c?= =?us-ascii?Q?JVK/gXCg49WZqT2np3HHVMIZ5IhqCN+xPql0hGTVPgpK90iKE5v/A8dcBVlG?= =?us-ascii?Q?AZTsQKezasQTPXTW8npen7PocQvTd5sy8Xv0Dsh699jAGku0orM2j79d7CJ7?= =?us-ascii?Q?v+1u+zVUqcBHjkknDUqWSSuLNIPshgk5SYf3EN8XoaEgK/1OwGzD0LbqJ+2r?= =?us-ascii?Q?G+95TLiDY5rP1rlorUdDjo1da3kWIIGNxXQJkx8peDWWDTLw2xH5bclVZ6ks?= =?us-ascii?Q?ShC8pO+ObSA9Fjdx6CWkecaac9VD3V2W2GOf/k3RLXQ6zppTFLPKSpTHun4w?= =?us-ascii?Q?//7O71XmYuOZMoR7bcQYo3L3Y9J/IBbPvbu3NK58/8yyTd0Dq7rnN745ytQ2?= =?us-ascii?Q?As/zA2+Edw6vbPSIQJQvmRnj+7UydB+f810uSZtwLtSfq+D6L5ju+pfsXATZ?= =?us-ascii?Q?JFdRt/m1Q2ec3ho+8Z4GIWh3X0wrZlTpcrAUHXTuuZdNgNLK50/BsqYWHW/A?= =?us-ascii?Q?k0wGQUIX4V4SdZflbRRtS5sJdfE41WVjC9HdJz38dtySgAyszZOIMMN11XVj?= =?us-ascii?Q?qA5MgiX3tVHWPhOp6oU6r1VWuLUFhm+LwSX5Imh7cEiP61fN+jC1a8olrmqB?= =?us-ascii?Q?kNEwx+ee1SE+N8au2zPs60Pc8tW8B5rAudZ3q733r/SONvG2FmPIeHOrenAb?= =?us-ascii?Q?18DLa3pAzsbOIFJ5rgVc/v4q1+pqCVcjUi7gPcwy+B4+5knKgQZyIdypE+Bb?= =?us-ascii?Q?H5iHmVuYrzB6ZYLLSqUtwroa+hn9C0QWTJdTXicDCcMCR6O4Chiib9qAhgSr?= =?us-ascii?Q?bqF+wOsdTeWqCNNfzxNmLLrtFbevrKhbxqSPT4OzQx76WR30jlDsWwz1Ka5u?= =?us-ascii?Q?/08aKFtX5JSvn3WYztXVL0wU/sPBqLKxp+VEWpKywFwJyp1RX8aYvZNqX+iF?= =?us-ascii?Q?p+Gf/b8DMWMRLe368Czugv0sZ5ENWFf+GI0Thv0uB52Z7KCZXc17iAiWK83O?= =?us-ascii?Q?GhefZ+B3Rxi2j8S1un4QZY+FTE4BGK03Laynpld8ux1eE7booMSYbKbNTAnb?= =?us-ascii?Q?IOFRoRr/Vhgl+uo1fKm0JJ2EIeRupZna22e0DHG3QbMznle4RGMoa8y6EmbR?= =?us-ascii?Q?VxhCCJi96LzbZ/7RMZw1V3/aQanYOPUL5k1H4IIERmUWpodazJsVnLJsC0zj?= =?us-ascii?Q?OswQ3NfoPPppHEnN6mLzblU6ePPnOHwQqxNraEipM4+9KgK7DrIaJVqf8Tn/?= =?us-ascii?Q?N6WMFCR8gpKb2HNtsoDTDQAwMvDvPYwUgSVHFniFiPTUMp4DY/poIeMSUzFH?= =?us-ascii?Q?9H6J64cWsIs8UT9OOianXXdT+p4AxLeeS9jsGOeuqOYQb2mTgyFocEFr4bCN?= =?us-ascii?Q?vxZpd3SQ3t2nUQPPZZfHnLGse2aRwX2Vfvp0HjvT29hFLHG9N+ILk8H9G23h?= =?us-ascii?Q?ltP+fiXu+U1JoUanTQKz3SuKxX0mb18ll5e1w2bjKDDudBWUQAsYV5rqDADD?= =?us-ascii?Q?iTefchPl18IkhAX35pHv+bsU6iZjT6nb0/UWDLlsy9WTYtfjh6gR+v2OUB7w?= =?us-ascii?Q?tCHgZDINwGNdbn7z4bOGFURuTzOyTaFe2Iww49R1mHwA/ydbd8PX4JtvuvGz?= =?us-ascii?Q?Rv+UT/wUBoCjf8Wg2EzqMwpBSeLFZfBjwZ1HZPViORGz0op6mYPpI2LytCVE?= =?us-ascii?Q?RV9w8zKWFQ=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9dcc0362-d773-4f48-2cc7-08dec6ee2f2f X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:43.2223 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZIjjPsG15CZbmm8eSRrGvim933OrgHzOuk1QBbaaoLlfitAc85+YOFSqPwfW2+U8W5qzWiEbwm6jEyWyidBRHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-d25034/1781095547-DB370CF5-FA17FB19/0/0 X-purgate-type: clean X-purgate-size: 18210 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095659809158500 Content-Type: text/plain; charset="utf-8" Introduce CONFIG_HAS_HWDOM_SYSTEM_SUSPEND as an architecture-selected capability for platforms where the hardware domain can be parked with SHUTDOWN_suspend without calling hwdom_shutdown(). Expose PSCI SYSTEM_SUSPEND as a vPSCI operation for all domains. For non-control domains, including the hardware domain when it is not acting as a control domain, the call is handled as a guest/domain suspend request and parks the domain in SHUTDOWN_suspend. Control domains need additional sequencing because their SYSTEM_SUSPEND request is used to coordinate host-wide suspend. A non-last awake control domain may be parked in SHUTDOWN_suspend without requiring the host suspend path to be available. The last awake control domain is treated as the point where the request becomes a host-suspend request, and it may only proceed when all non-control domains are already in SHUTDOWN_suspend and the host suspend path is available. Keep the control-domain sequencing and domain-readiness checks out of PSCI_FEATURES. They are per-attempt runtime conditions rather than stable PSCI function availability. Advertise SYSTEM_SUSPEND as implemented by vPSCI and report attempt-time policy failures as PSCI_DENIED. Select HAS_HWDOM_SYSTEM_SUSPEND independently from CONFIG_SYSTEM_SUSPEND so that SHUTDOWN_suspend from the hardware domain can be treated as a domain suspend state rather than as a hardware-domain initiated host shutdown. This does not by itself imply that host-wide suspend is available. Add host_system_suspend_allowed() to combine the host PSCI SYSTEM_SUSPEND capability with runtime blockers reported by Xen-owned subsystems. Add runtime blockers for registered serial, IOMMU, GIC and SMMUv3 MSI IRQ paths lacking suspend/resume support. These blockers are runtime based, so they only apply to drivers or paths that Xen actually uses on the platform. For SMMUv3, the blocker applies only when Xen actually uses the MSI IRQ path, since resume does not restore the SMMU *_IRQ_CFGn MSI registers yet. Add a struct domain forward declaration to xen/suspend.h so the generic header can expose arch_domain_resume() without requiring a full domain.h include. Signed-off-by: Mykola Kvach Reviewed-by: Oleksandr Tyshchenko --- Changes in V11: - Mark host_system_suspend_runtime_allowed as __ro_after_init. - Avoid printing the SMMUv3 MSI IRQ host suspend blocker more than once when multiple SMMUv3 instances use MSIs. - Wrap the Arm IOMMU host suspend blocker in CONFIG_SYSTEM_SUSPEND to make its policy-only use explicit. Changes in V10: - Return PSCI_DENIED rather than PSCI_NOT_SUPPORTED when the last awake control domain cannot proceed to host suspend, keeping PSCI_FEATURES stable once SYSTEM_SUSPEND is advertised. - Shorten SYSTEM_SUSPEND blocker messages and use %pd when logging the control domain. - Mark serial_suspend_available as __ro_after_init. - Mention the struct domain forward declaration added to xen/suspend.h. Changes in V9: - Select HAS_HWDOM_SYSTEM_SUSPEND independently from CONFIG_SYSTEM_SUSPEND so that hardware-domain SHUTDOWN_suspend support is not tied to host-wide system suspend availability. - Add runtime host suspend blockers for Xen-owned subsystems lacking suspend/resume support. - Keep vPSCI SYSTEM_SUSPEND advertised through PSCI_FEATURES and enforce control-domain sequencing in the call handler. --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/gic.c | 6 ++ xen/arch/arm/include/asm/psci.h | 3 + xen/arch/arm/include/asm/suspend.h | 10 ++- xen/arch/arm/psci.c | 7 ++ xen/arch/arm/suspend.c | 40 +++++++++ xen/arch/arm/vpsci.c | 114 +++++++++++++++++++++++--- xen/common/Kconfig | 3 + xen/common/domain.c | 7 +- xen/drivers/char/serial.c | 12 +++ xen/drivers/passthrough/arm/iommu.c | 6 ++ xen/drivers/passthrough/arm/smmu-v3.c | 9 ++ xen/include/xen/serial.h | 1 + xen/include/xen/suspend.h | 2 + 14 files changed, 208 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 5fa89fcb24..9acd342f09 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -19,6 +19,7 @@ config ARM select HAS_ALTERNATIVE if HAS_VMAP select HAS_DEVICE_TREE_DISCOVERY select HAS_DOM0LESS + select HAS_HWDOM_SYSTEM_SUSPEND if !MPU select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE select HAS_STACK_PROTECTOR select HAS_UBSAN diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 7727ffed5a..60488c95b4 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include =20 @@ -44,6 +45,11 @@ static void __init __maybe_unused build_assertions(void) void register_gic_ops(const struct gic_hw_operations *ops) { gic_hw_ops =3D ops; + +#ifdef CONFIG_SYSTEM_SUSPEND + if ( !ops->suspend || !ops->resume ) + host_system_suspend_disable("GIC driver lacks suspend support"); +#endif } =20 static void clear_cpu_lr_mask(void) diff --git a/xen/arch/arm/include/asm/psci.h b/xen/arch/arm/include/asm/psc= i.h index bb3c73496e..142fa1bfe5 100644 --- a/xen/arch/arm/include/asm/psci.h +++ b/xen/arch/arm/include/asm/psci.h @@ -24,6 +24,9 @@ void call_psci_cpu_off(void); void call_psci_system_off(void); void call_psci_system_reset(void); int call_psci_system_suspend(void); +#ifdef CONFIG_SYSTEM_SUSPEND +bool psci_system_suspend_allowed(void); +#endif =20 /* Range of allocated PSCI function numbers */ #define PSCI_FNUM_MIN_VALUE _AC(0,U) diff --git a/xen/arch/arm/include/asm/suspend.h b/xen/arch/arm/include/asm/= suspend.h index c848fc6340..50dc6e9fdf 100644 --- a/xen/arch/arm/include/asm/suspend.h +++ b/xen/arch/arm/include/asm/suspend.h @@ -39,7 +39,15 @@ extern struct resume_cpu_context resume_cpu_context; =20 int prepare_resume_ctx(void); void hyp_resume(void); -#endif /* CONFIG_SYSTEM_SUSPEND */ +bool host_system_suspend_allowed(void); +void host_system_suspend_disable(const char *reason); + +#else /* !CONFIG_SYSTEM_SUSPEND */ + +static inline bool host_system_suspend_allowed(void) { return false; } +static inline void host_system_suspend_disable(const char *reason) {} + +#endif =20 #endif /* ARM_SUSPEND_H */ =20 diff --git a/xen/arch/arm/psci.c b/xen/arch/arm/psci.c index e05dae1133..e9d78668fd 100644 --- a/xen/arch/arm/psci.c +++ b/xen/arch/arm/psci.c @@ -41,6 +41,13 @@ static bool __ro_after_init has_psci_system_suspend; =20 #define PSCI_RET(res) ((int32_t)(res).a0) =20 +#ifdef CONFIG_SYSTEM_SUSPEND +bool psci_system_suspend_allowed(void) +{ + return has_psci_system_suspend; +} +#endif + int call_psci_cpu_on(int cpu) { struct arm_smccc_res res; diff --git a/xen/arch/arm/suspend.c b/xen/arch/arm/suspend.c index 6ea4a0f9cc..c7c26bcf03 100644 --- a/xen/arch/arm/suspend.c +++ b/xen/arch/arm/suspend.c @@ -1,9 +1,49 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include =20 +#include +#include + struct resume_cpu_context resume_cpu_context; =20 +/* + * Non-PSCI infrastructure can make host suspend impossible even when the = PSCI + * SYSTEM_SUSPEND conduit is present, e.g. when a Xen-owned driver has no = valid + * suspend/resume path. + * + * This gate is checked only when the last awake control domain attempts to + * turn a guest SYSTEM_SUSPEND request into a host-suspend request. + */ +static bool __ro_after_init host_system_suspend_runtime_allowed =3D true; + +static bool host_serial_suspend_allowed(void) +{ + if ( serial_suspend_supported() ) + return true; + + printk_once(XENLOG_INFO + "Host SYSTEM_SUSPEND blocked: serial unsupported\n"); + + return false; +} + +bool host_system_suspend_allowed(void) +{ + return psci_system_suspend_allowed() && + host_serial_suspend_allowed() && + host_system_suspend_runtime_allowed; +} + +void host_system_suspend_disable(const char *reason) +{ + host_system_suspend_runtime_allowed =3D false; + + printk(XENLOG_INFO "Host SYSTEM_SUSPEND blocked: %s\n", + reason ? reason : "unsupported suspend/resume path"); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vpsci.c b/xen/arch/arm/vpsci.c index ac6af6118f..0bae42c1bd 100644 --- a/xen/arch/arm/vpsci.c +++ b/xen/arch/arm/vpsci.c @@ -5,6 +5,7 @@ =20 #include #include +#include #include #include #include @@ -219,6 +220,89 @@ static void do_psci_0_2_system_reset(void) domain_shutdown(d,SHUTDOWN_reboot); } =20 +/* + * Serialise SYSTEM_SUSPEND policy decisions with the domain suspend trans= ition, + * so multiple control domains cannot all observe each other as still awak= e. + */ +static DEFINE_SPINLOCK(vpsci_system_suspend_lock); + +static bool domain_in_suspend_state(struct domain *d) +{ + bool suspended; + + spin_lock(&d->shutdown_lock); + suspended =3D d->is_shut_down && d->shutdown_code =3D=3D SHUTDOWN_susp= end; + spin_unlock(&d->shutdown_lock); + + return suspended; +} + +static int32_t domain_psci_system_suspend_policy(struct domain *d) +{ + struct domain *other; + bool last_awake_control_domain =3D true; + bool awake_non_control_domain =3D false; + + /* Only control domains participate in sequencing policy. */ + if ( !is_control_domain(d) ) + return 0; + + rcu_read_lock(&domlist_read_lock); + + for_each_domain ( other ) + { + bool suspended; + + if ( other =3D=3D d ) + continue; + + suspended =3D domain_in_suspend_state(other); + if ( suspended ) + continue; + + if ( is_control_domain(other) ) + { + last_awake_control_domain =3D false; + break; + } + + awake_non_control_domain =3D true; + } + + rcu_read_unlock(&domlist_read_lock); + + /* + * Another control domain is still awake. This request is only the fir= st + * phase of the sequencing: park this control domain and leave the host + * running. Host-wide suspend gates must not block this intermediate s= tate. + */ + if ( !last_awake_control_domain ) + return 0; + + /* + * This is the last awake control domain. It must not be parked unless= the + * request can proceed as a host-suspend request; otherwise Xen would = lose + * the last domain that can coordinate the system suspend. + */ + if ( awake_non_control_domain ) + { + printk(XENLOG_DEBUG + "SYSTEM_SUSPEND denied for %pd: non-control domains awake\n= ", + d); + return PSCI_DENIED; + } + + /* + * Host-wide gates are relevant only for the last-control-domain case.= They + * must not block parking of a non-last control domain, but they must = deny + * the last control domain when host suspend is not currently availabl= e. + */ + if ( !host_system_suspend_allowed() ) + return PSCI_DENIED; + + return 0; +} + static int32_t do_psci_1_0_system_suspend(register_t epoint, register_t ci= d) { int32_t rc; @@ -232,10 +316,6 @@ static int32_t do_psci_1_0_system_suspend(register_t e= point, register_t cid) if ( is_64bit_domain(d) && is_thumb ) return PSCI_INVALID_ADDRESS; =20 - /* SYSTEM_SUSPEND is not supported for the hardware domain yet */ - if ( is_hardware_domain(d) ) - return PSCI_NOT_SUPPORTED; - /* Ensure that all CPUs other than the calling one are offline */ domain_lock(d); for_each_vcpu ( d, v ) @@ -252,16 +332,29 @@ static int32_t do_psci_1_0_system_suspend(register_t = epoint, register_t cid) if ( rc ) return PSCI_DENIED; =20 - rc =3D domain_shutdown(d, SHUTDOWN_suspend); + spin_lock(&vpsci_system_suspend_lock); + + rc =3D domain_psci_system_suspend_policy(d); + if ( !rc ) + { + rc =3D domain_shutdown(d, SHUTDOWN_suspend); + if ( rc ) + rc =3D PSCI_DENIED; + else + { + rctx->ctxt =3D ctxt; + rctx->wake_cpu =3D current; + } + } + + spin_unlock(&vpsci_system_suspend_lock); + if ( rc ) { free_vcpu_guest_context(ctxt); - return PSCI_DENIED; + return rc; } =20 - rctx->ctxt =3D ctxt; - rctx->wake_cpu =3D current; - gprintk(XENLOG_DEBUG, "SYSTEM_SUSPEND requested, epoint=3D%#"PRIregister", cid=3D%#"= PRIregister"\n", epoint, cid); @@ -287,10 +380,9 @@ static int32_t do_psci_1_0_features(uint32_t psci_func= _id) case PSCI_0_2_FN32_SYSTEM_RESET: case PSCI_1_0_FN32_PSCI_FEATURES: case ARM_SMCCC_VERSION_FID: - return 0; case PSCI_1_0_FN32_SYSTEM_SUSPEND: case PSCI_1_0_FN64_SYSTEM_SUSPEND: - return is_hardware_domain(current->domain) ? PSCI_NOT_SUPPORTED : = 0; + return 0; default: return PSCI_NOT_SUPPORTED; } diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 5ff71480ee..816a1a4ecb 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -140,6 +140,9 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY bool =20 +config HAS_HWDOM_SYSTEM_SUSPEND + bool + config HAS_IOPORTS bool =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 8f2bfcae28..a8750c3839 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1377,6 +1377,11 @@ void __domain_crash(struct domain *d) domain_shutdown(d, SHUTDOWN_crash); } =20 +static inline bool want_hwdom_shutdown(uint8_t reason) +{ + return !IS_ENABLED(CONFIG_HAS_HWDOM_SYSTEM_SUSPEND) || + reason !=3D SHUTDOWN_suspend; +} =20 int domain_shutdown(struct domain *d, u8 reason) { @@ -1393,7 +1398,7 @@ int domain_shutdown(struct domain *d, u8 reason) d->shutdown_code =3D reason; reason =3D d->shutdown_code; =20 - if ( is_hardware_domain(d) ) + if ( is_hardware_domain(d) && want_hwdom_shutdown(reason) ) hwdom_shutdown(reason); =20 if ( d->is_shutting_down ) diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index adb312d796..e5348b5445 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -497,6 +497,8 @@ const struct vuart_info *serial_vuart_info(int idx) =20 #ifdef CONFIG_SYSTEM_SUSPEND =20 +static bool __ro_after_init serial_suspend_available =3D true; + void serial_suspend(void) { int i; @@ -513,6 +515,11 @@ void serial_resume(void) com[i].driver->resume(&com[i]); } =20 +bool serial_suspend_supported(void) +{ + return serial_suspend_available; +} + #endif /* CONFIG_SYSTEM_SUSPEND */ =20 void __init serial_register_uart(int idx, struct uart_driver *driver, @@ -521,6 +528,11 @@ void __init serial_register_uart(int idx, struct uart_= driver *driver, /* Store UART-specific info. */ com[idx].driver =3D driver; com[idx].uart =3D uart; + +#ifdef CONFIG_SYSTEM_SUSPEND + if ( !driver->suspend || !driver->resume ) + serial_suspend_available =3D false; +#endif } =20 void __init serial_async_transmit(struct serial_port *port) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/= arm/iommu.c index 100545e23f..461e01703e 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include =20 @@ -46,6 +47,11 @@ void __init iommu_set_ops(const struct iommu_ops *ops) } =20 iommu_ops =3D ops; + +#ifdef CONFIG_SYSTEM_SUSPEND + if ( !ops->suspend || !ops->resume ) + host_system_suspend_disable("IOMMU driver lacks suspend support"); +#endif } =20 int __init iommu_hardware_setup(void) diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthroug= h/arm/smmu-v3.c index 7f1d00fb81..16947a12f2 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -91,6 +91,7 @@ #include #include #include +#include =20 #include "smmu-v3.h" =20 @@ -1866,6 +1867,7 @@ static void arm_smmu_write_msi_msg(struct msi_desc *d= esc, struct msi_msg *msg) =20 static void arm_smmu_setup_msis(struct arm_smmu_device *smmu) { + static bool __ro_after_init host_suspend_blocked_by_msi; struct msi_desc *desc; int ret, nvec =3D ARM_SMMU_MAX_MSIS; struct device *dev =3D smmu->dev; @@ -1910,6 +1912,13 @@ static void arm_smmu_setup_msis(struct arm_smmu_devi= ce *smmu) } } =20 + if ( !host_suspend_blocked_by_msi ) + { + host_suspend_blocked_by_msi =3D true; + host_system_suspend_disable( + "SMMUv3 MSI IRQ path is unsupported for host suspend"); + } + /* Add callback to free MSIs on teardown */ devm_add_action(dev, arm_smmu_free_msis, dev); } diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index 8e18445552..418b00ead0 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -137,6 +137,7 @@ const struct vuart_info* serial_vuart_info(int idx); /* Serial suspend/resume. */ void serial_suspend(void); void serial_resume(void); +bool serial_suspend_supported(void); #endif =20 /* diff --git a/xen/include/xen/suspend.h b/xen/include/xen/suspend.h index 6f94fd53b0..a941331035 100644 --- a/xen/include/xen/suspend.h +++ b/xen/include/xen/suspend.h @@ -6,6 +6,8 @@ #if __has_include() #include #else +struct domain; + static inline void arch_domain_resume(struct domain *d) {} #endif =20 --=20 2.43.0 From nobody Sat Jun 13 07:34:17 2026 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1781095655; cv=pass; d=zohomail.com; s=zohoarc; b=UBgcBTPnZ2SQB6NYEJd65v8A8F0yG7dvuYmXGy3blMaAaj7cWHIoGdoqGFa44qbkJSmvlSeDJOr7JUO2uR4TXyGcG7WXN5/tWRNJmIWqo1s3oFyf4DRdS7xrFI+0W9RgKYP4eugCUeKw5o8HvDB4rlA8C0Ichke16wmjfqDzB7k= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781095655; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CmvxC/INp19b+i88n0k6NHOjs/Hn3KkLy2VeOHRcLXY=; b=eoe9RZsvqAzCRgLWDpAKrrF4a3w3nhm0XEw0D7bS7K4wIUQ+r8RjpjAuWVHua89YVEsWsz1mb5tfxiiGCncFK8vydbXffPXc5Va23RNBMLtKBwr3eycAGex8LPl4ilOzMYRKHmubXQsr1Pl5MoYDHs0guRT1cIq/itmFBCd065A= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 178109565525730.49328829797173; Wed, 10 Jun 2026 05:47:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1334279.1597425 (Exim 4.92) (envelope-from ) id 1wXIKs-00030E-6n; Wed, 10 Jun 2026 12:47:10 +0000 Received: by outflank-mailman (output) from mailman id 1334279.1597425; Wed, 10 Jun 2026 12:47:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIKr-0002vo-Nh; Wed, 10 Jun 2026 12:47:09 +0000 Received: by outflank-mailman (input) for mailman id 1334279; Wed, 10 Jun 2026 12:45:48 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wXIJY-0001H1-5c for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 12:45:48 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wXIJX-00HZzX-Ik for xen-devel@lists.xenproject.org; Wed, 10 Jun 2026 14:45:47 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a295c7b-2eae-0a2a0a5409dd-0a2a450cccde-0 for ; Wed, 10 Jun 2026 14:45:47 +0200 Received: from [52.101.69.83] (helo=AM0PR83CU005.outbound.protection.outlook.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a295c7b-62f1-0a2a450c0019-346545532a7e-4 for ; Wed, 10 Jun 2026 14:45:47 +0200 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) by AM9PR03MB7558.eurprd03.prod.outlook.com (2603:10a6:20b:415::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 12:45:45 +0000 Received: from AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7]) by AS8PR03MB9746.eurprd03.prod.outlook.com ([fe80::cf11:309:1384:58f7%4]) with mapi id 15.21.0113.011; Wed, 10 Jun 2026 12:45:45 +0000 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AEWDXlosCvNifLpDxluL+1iiRhpjrp+h3Fy1Xa/J0DaftDyx0aw13w26R4Jr2KC/ZyTuO4qnqnRv7zJngAV6/eE6DJ6sulBvnIk1TLbhs2eB9oIU7m00LecidFh7ZEthgaoX9qiFyDi8aP35dd4KjmxPEXgwqhkuwfhXhVDRaUWNcgVAF02MG2rWLYd1nfcaMX7qOdoJNhdGnVdOL83fBThbn8gnmxcZMKp68BWWONvYAlCJIveGtzp+j8ZWOFmJei61HzoGQxs6C9thrl11RMsQKq+fihpUVCWy68kAnMihL5a2Afkgj6uuVJsH5PiC/tc5w8iKkRCRDN+5R8KL3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CmvxC/INp19b+i88n0k6NHOjs/Hn3KkLy2VeOHRcLXY=; b=AZkFmpalzgjJIvUj2MX9OERXpgqq56HTiG31jWED4pFpM5fUxYxnSOgvecDSz7nm+vo1R+6HVtz0eju5HS3exuLQ+YZBc/aRQt3GYgQnTSyhVe0MwxLOIJtZsz6uFnpvzASmdBRbXjp3HVk9KBSvA4/lUtcG2DQCGXk2eI4JsjlWuOirAcC+Q7uGe+XGXUjShgI9yBaPcT2mgvvGa0JsXzu8NeIvG5teHxcd4lWIF7fvtUhZIbxFJva9gs4hLpo1HwuW6AdxUd+bNxk4v6UzBEbEiCYOTJVMWld0WO0l5p99fl4y2XIx5OPHodclgE6WIcr9ITyztnj2Sf/aqy5fCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CmvxC/INp19b+i88n0k6NHOjs/Hn3KkLy2VeOHRcLXY=; b=iqGiAEbukuy8V+6CEBUNXqWkOSxscfZMPkNHwRkUJnYfgcDY8o09JHijQXtfHdUwH3bbqKw/p9Fchsyztbh7sBqb6X9WUFs647/0mNmghHMrNaBpbKcCnb5G1Lcl4vHUv+glELwiqPBEIEw733DhXbDosTqnMza1rL6hH7tsL2xHWcS2r/U7s65GwfxCgOOeW/Vt1aVGBUoAr6tFkYffCFpu7kWTFWWnh7gUB9cBvA8/1wkNYK5qh2bL2+4YRHSGzZ7NB7RCUCdONWpLIZ1c0DYO/npjyX6aGO347HXdbtBMUHdgCXBfZeS7Z30ukxRg/fgRvuXaM5BCsH7AuuRSSA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mykola Kvach , Mykola Kvach , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v11 13/13] xen/arm: Add host system suspend backend Date: Wed, 10 Jun 2026 15:44:33 +0300 Message-ID: <8396f8bfd4a17a6aa38a824f317fb20000ebd940.1781084290.git.mykola_kvach@epam.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::19) To AS8PR03MB9746.eurprd03.prod.outlook.com (2603:10a6:20b:61d::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB9746:EE_|AM9PR03MB7558:EE_ X-MS-Office365-Filtering-Correlation-Id: 2840ef83-8f1b-4b58-2081-08dec6ee309f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|3023799007|56012099006|11063799006|5023799004|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: ep29k07wTH7rppEfb81arMHWUoXmqelkfYXEcVOkiR+B5bePO104+4oSyt74sSlAPFoH9DE0DXqYb4G+by7sXRwr3J5Cx2/obk0YghajVYuwtLC/RtUNgvBSvw/Rx+UdfB1XVz5f1bVFTRb2rpT0uows94BI5ZISqPUlh4B8goujSPlZNHk4AZDtzyofcWy06Mca7umX8kRmJjpAc/BM7odO39TMPqM65obsdtt44An2QkoSbG2JopT3gkj0FZS8wt+mukLz3CBxTz6PfzNZBQ6QKGh4hQtfp3c4EXdhobsjAiQVFhRbd271Ea37HbDsKVgtauIMXhHKhtqVmsQIJuye48uFxCJAUzoTpexlq/NNGVkT7RfF+gU/dgkGL4wfwWLA83jblWwTnDylUR/YVcjekhFn/PYjz156k6Gf9nlcGNxLQ332eV8ElYiX56OzXIrh/Q28jyVNeOaYnmCoyi6FCETUGIOU0J8KR95s1K1kdwL+1LoRxoicr7bFmbLd1DbrY8puAdkfxjE3YYxZxjgwvi9B9HOA1DJr0Cm6Sg0alzcaVoC0rhhiOJ+WfKjh8Utr+ahjShrm5C1cP4svraXcrLYoqwHdBemHLUSO3VSHKrV915MddsTtJllXcWwzj55tzat6NvisWY4zZZehTsOaqSpAtXWXkmIY1RQBwmKJKGqrrgF3QaZvAt0SGQic X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9746.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(3023799007)(56012099006)(11063799006)(5023799004)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?miKEKD1rjW5wzjl+GnUu1jp3HZk8J6rjeMyIbyydxOn6aNabjovZwHsC77oz?= =?us-ascii?Q?fIVMlG/mNWYQKfg7Lrrn7y6AFSE2BhKHDTV2PvLiMrp9IStBRXq/ZpcyRYcU?= =?us-ascii?Q?pu9QjiLItA1TDFpnKKLAD07qOm/e6D/JCdAPDxudHimLsKqH8qUVza8QBKDH?= =?us-ascii?Q?9jf4Gx8wHwWxnm8el3UKdv7Mfuw3Fgfr4nJqXdq4VItV3gcx8nvYDBvmp9/s?= =?us-ascii?Q?2CgCqT296AEHoCXx6ZOyPFIiy2ksdqOSQ88um0wDlBYfNMnLSvZpVM9asaO1?= =?us-ascii?Q?RKCIAXNQLkrVkWK+KAFTD+KWDl+LOfSc2cDoonf8205r3STDv9l9bjs0PShH?= =?us-ascii?Q?Be/ES4WWBYfClhd0N0aQPbCUleQxkPwgEs+4sQpgyx2FkomIIbcHsOO1XyYw?= =?us-ascii?Q?n2YWbMSqua2iwkg4bhcbbei228ifPPs79HorFVl9Fqs8HMj+aaztdVAD1heE?= =?us-ascii?Q?ILVwvuZ4/rPTEXKEhqYQkZLXWegMsgfCDaFjLfxN6w0H+p1RN5fSNTLg6gXf?= =?us-ascii?Q?G6+ljeNiQv5MzO5Sn1kCrA06B0qej9jZkdkP7JBKQRvlkAC/Q202d6UjBGQj?= =?us-ascii?Q?yRP3LcpFUx4okttBLP6c1oLLnQz4MMg8p5ewenXn3DXDsx9wWH///PskRvh0?= =?us-ascii?Q?hAkSqbOBQvDRTsMkNGPvtTGNDl8TkUKLaZkKFHS9eRyxnOqD54HP1uYa9WRV?= =?us-ascii?Q?ngxjnZHBHDCronJqEYdO8KJeZtfdeMsVta+eoCaOW6QEWYHLDLSdQtnZpQMd?= =?us-ascii?Q?GjmA1+ss/JJFLuXk2wgiJ3mJI3b/Um5NF1wRWAH8aRfKoU9sPmNRdKmekcDd?= =?us-ascii?Q?Nd/hL38LqozuXmizca2OAuiHwlQZ9pfrKqEA8j3XWjL76sDRFcek5q03gjwO?= =?us-ascii?Q?pXEsjIyMleDQ/9HRjuv+oisH3J+ZD2BCA16IzlxSJcaifuNXriP5xfISaQ+d?= =?us-ascii?Q?27wZZdpah8dLhZecXF3K4TKlQsNvTVqV4wzfkGkTW5D2hHuEl80mT6idBqBw?= =?us-ascii?Q?nO4ZabXP8HxyNan5e7HHONCjy3PrGWY9H6PVkSYthFOJt7d8DigW62oj8B4X?= =?us-ascii?Q?GdM4eKAYwOjQbE5WwBjNu0fEcLKIpcifXIUVd1lnJbg7fKGE1yCLkJCKUtfi?= =?us-ascii?Q?gcbXNme2baJHvXZ/PWaxNElzglFOQu50v2ynO+nVuCXR0c4R3nOIuHAVZAO3?= =?us-ascii?Q?cFaZJnffn9RBEF9H2kzlYg+6RVKU4A8JmbuN0RCWDBDtMHZtzwHSv5ggd3BZ?= =?us-ascii?Q?V9u0RIDdfwe2KTVXcO+injofSvl26PXMIFjPWvGvwxlGc2UClpYCeYUTpuGe?= =?us-ascii?Q?hz32iIsHQfRMPgFVWr1IxYKqXc9Ow850/D9CHIDNbHcLEo/YOwxXfVeXneun?= =?us-ascii?Q?ciCBWidUqodLxAwcLBYk0uxFmkVvNQ/eXf++86gVsbku2nDFguWNDuJgOM2D?= =?us-ascii?Q?N8KNrI6ttGBTiEdJ9+G5XpdefbRIdcjki8sVFjNd2qokKU5+/EuBnj+mVgTp?= =?us-ascii?Q?Nd8aK0eCjvOogX1y6riOeXU2vDwy9GRzNrpqnvv/u+Aw/B8joEQdbImg0oW8?= =?us-ascii?Q?/r2jN78mDi48GQW06JCA4Ucwe76/hzS2NMOgsqlGhzbFvI0Snmu2kco7q4g3?= =?us-ascii?Q?myQ3xNyDABThBYwJgSi4Zni9jxiAW1tOIAPBdgjc3femmG6sT2GovePXYSNN?= =?us-ascii?Q?+z7HiuYwVkR9pJ/nzVs7YTLEgEKU7c86bJvy9EH+h4fd6X/xN8We2586g5Ag?= =?us-ascii?Q?ZaxPNZ36qQ=3D=3D?= X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2840ef83-8f1b-4b58-2081-08dec6ee309f X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9746.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 12:45:45.5027 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r7vgIt8HtYEtHGDWnDy9PYbxmNPUMa563oD4erczjubjXJbA2wvIp5FC4rmN4lhBQpoU4+ruu0rp/haPqIDcBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7558 X-purgate-ID: tlsNG-d25034/1781095547-DA169CF5-0DD9C169/0/0 X-purgate-type: clean X-purgate-size: 13927 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1781095656696154100 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic Add the Xen-wide suspend/resume backend used after a control-domain vPSCI SYSTEM_SUSPEND request has been accepted. The vPSCI policy, runtime driver blockers and control-domain sequencing checks are handled by the preceding commit; this change adds the code that actually drives the host suspend attempt. The backend runs from a tasklet scheduled on pCPU0, because non-boot CPUs are disabled during suspend. It freezes domains, disables the scheduler and then disables non-boot CPUs. Host-side suspend participants are handled in phases. IOMMU and console state are suspended first. Local IRQs are then disabled before suspending timer and GIC state. On resume or failure, the completed suspend phases are unwound in reverse: GIC and timer state are restored while IRQs are still disabled, local IRQs are restored, and then console and IOMMU state are restored. On boot, init_ttbr is normally initialized during secondary CPU hotplug. On uniprocessor systems this can leave init_ttbr uninitialized, so set it from the boot CPU before entering suspend. Note: the code is behind CONFIG_HAS_SYSTEM_SUSPEND, which is currently only selected when UNSUPPORTED is set and MPU is not set. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykyta Poturai Signed-off-by: Mykola Kvach --- Changes in V10: - Re-apply boot CPU local errata/workaround handling after SYSTEM_SUSPEND, before resuming the rest of the host suspend path. - Move set_init_ttbr() declaration to asm/mmu/mm.h, since it is MMU-specific. Changes in V9: - Split vPSCI availability policy, runtime host-suspend blockers and the domain-readiness precheck into the preceding commit. - Trigger the host suspend backend from the control-domain SYSTEM_SUSPEND path. - Reorder the host suspend/resume phases so the timer is suspended with local IRQs disabled and local IRQs are restored after the GIC and timer resume paths, before the console and IOMMU resume paths. - Move HAS_HWDOM_SYSTEM_SUSPEND and related logic to policy patch. Changes in V8: - Add a pre-suspend check in system_suspend() after scheduler_disable() to require all domains to be in the shut down state with SHUTDOWN_suspend before proceeding with the global suspend flow. - Drop the common-level depends on !ARM_64 || !SYSTEM_SUSPEND from CONFIG_HAS_HWDOM_SHUTDOWN_ON_SUSPEND and model the ARM64 suspend case with an arch-selected capability instead. - Rename CONFIG_HAS_HWDOM_SHUTDOWN_ON_SUSPEND to CONFIG_HAS_HWDOM_SYSTEM_SUSPEND. - Rename need_hwdom_shutdown() to want_hwdom_shutdown(). Changes in V7: - Control domain is responsible for host suspend. - Add an empty inline host_system_suspend() function when SYSTEM_SUSPEND config is disabled. - Use IS_ENABLED() for config checking instead of #ifdef. - Replace #ifdef checks in domain_shutdown() with IS_ENABLED() to simplify control flow. - Factor hardware domain shutdown condition into a helper (need_hwdom_shutdown()) to avoid preprocessor directives inside the function. - Squash with iommu suspend/resume commit. --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/cpuerrata.c | 7 +- xen/arch/arm/include/asm/cpuerrata.h | 1 + xen/arch/arm/include/asm/mmu/mm.h | 2 + xen/arch/arm/include/asm/suspend.h | 2 + xen/arch/arm/mmu/smpboot.c | 2 +- xen/arch/arm/suspend.c | 156 +++++++++++++++++++++++++++ xen/arch/arm/vpsci.c | 10 +- 8 files changed, 177 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 9acd342f09..09ae8e1aac 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -9,6 +9,7 @@ config ARM_64 select 64BIT select HAS_DOMAIN_TYPE select HAS_FAST_MULTIPLY + select HAS_SYSTEM_SUSPEND if !MPU && UNSUPPORTED select HAS_VPCI_GUEST_SUPPORT if PCI_PASSTHROUGH =20 config ARM diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c index 3a32183618..e6499aaab3 100644 --- a/xen/arch/arm/cpuerrata.c +++ b/xen/arch/arm/cpuerrata.c @@ -782,6 +782,11 @@ void check_local_cpu_errata(void) update_cpu_capabilities(arm_errata, "enabled workaround for"); } =20 +int enable_local_cpu_errata_workarounds(void) +{ + return enable_nonboot_cpu_caps(arm_errata); +} + void __init enable_errata_workarounds(void) { enable_cpu_capabilities(arm_errata); @@ -818,7 +823,7 @@ static int cpu_errata_callback(struct notifier_block *n= fb, * fixed to expect an error at CPU_STARTING phase. */ ASSERT(system_state !=3D SYS_STATE_boot); - rc =3D enable_nonboot_cpu_caps(arm_errata); + rc =3D enable_local_cpu_errata_workarounds(); break; default: break; diff --git a/xen/arch/arm/include/asm/cpuerrata.h b/xen/arch/arm/include/as= m/cpuerrata.h index 1799a16d7e..b93521326f 100644 --- a/xen/arch/arm/include/asm/cpuerrata.h +++ b/xen/arch/arm/include/asm/cpuerrata.h @@ -5,6 +5,7 @@ #include =20 void check_local_cpu_errata(void); +int enable_local_cpu_errata_workarounds(void); void enable_errata_workarounds(void); =20 #define CHECK_WORKAROUND_HELPER(erratum, feature, arch) \ diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/m= mu/mm.h index 7f4d59137d..ee73a77777 100644 --- a/xen/arch/arm/include/asm/mmu/mm.h +++ b/xen/arch/arm/include/asm/mmu/mm.h @@ -110,6 +110,8 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr, extern void switch_ttbr(uint64_t ttbr); extern void relocate_and_switch_ttbr(uint64_t ttbr); =20 +void set_init_ttbr(lpae_t *root); + #endif /* __ARM_MMU_MM_H__ */ =20 /* diff --git a/xen/arch/arm/include/asm/suspend.h b/xen/arch/arm/include/asm/= suspend.h index 50dc6e9fdf..889a6509d9 100644 --- a/xen/arch/arm/include/asm/suspend.h +++ b/xen/arch/arm/include/asm/suspend.h @@ -41,11 +41,13 @@ int prepare_resume_ctx(void); void hyp_resume(void); bool host_system_suspend_allowed(void); void host_system_suspend_disable(const char *reason); +void host_system_suspend(struct domain *d); =20 #else /* !CONFIG_SYSTEM_SUSPEND */ =20 static inline bool host_system_suspend_allowed(void) { return false; } static inline void host_system_suspend_disable(const char *reason) {} +static inline void host_system_suspend(struct domain *d) {} =20 #endif =20 diff --git a/xen/arch/arm/mmu/smpboot.c b/xen/arch/arm/mmu/smpboot.c index 37e91d72b7..ff508ecf40 100644 --- a/xen/arch/arm/mmu/smpboot.c +++ b/xen/arch/arm/mmu/smpboot.c @@ -72,7 +72,7 @@ static void clear_boot_pagetables(void) clear_table(boot_third); } =20 -static void set_init_ttbr(lpae_t *root) +void set_init_ttbr(lpae_t *root) { /* * init_ttbr is part of the identity mapping which is read-only. So diff --git a/xen/arch/arm/suspend.c b/xen/arch/arm/suspend.c index c7c26bcf03..3fe2ffa4fb 100644 --- a/xen/arch/arm/suspend.c +++ b/xen/arch/arm/suspend.c @@ -1,10 +1,18 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include +#include +#include #include #include =20 +#include +#include +#include #include +#include #include +#include =20 struct resume_cpu_context resume_cpu_context; =20 @@ -44,6 +52,154 @@ void host_system_suspend_disable(const char *reason) reason ? reason : "unsupported suspend/resume path"); } =20 +/* Xen suspend. data identifies the domain that initiated suspend. */ +static void system_suspend(void *data) +{ + int status; + unsigned long flags; + struct domain *d =3D (struct domain *)data; + + BUG_ON(system_state !=3D SYS_STATE_active); + + system_state =3D SYS_STATE_suspend; + + printk("Xen suspending...\n"); + + freeze_domains(); + scheduler_disable(); + + /* + * Non-boot CPUs have to be disabled on suspend and enabled on resume + * (hotplug-based mechanism). Disabling non-boot CPUs will lead to PSCI + * CPU_OFF to be called by each non-boot CPU. Depending on the underly= ing + * platform capabilities, this may lead to the physical powering down = of + * CPUs. + */ + status =3D disable_nonboot_cpus(); + if ( status ) + { + system_state =3D SYS_STATE_resume; + goto resume_nonboot_cpus; + } + + console_start_sync(); + status =3D iommu_suspend(); + if ( status ) + { + system_state =3D SYS_STATE_resume; + goto resume_end_sync; + } + + status =3D console_suspend(); + if ( status ) + { + dprintk(XENLOG_ERR, "Failed to suspend the console, err=3D%d\n", s= tatus); + system_state =3D SYS_STATE_resume; + goto resume_iommu; + } + + local_irq_save(flags); + + time_suspend(); + + status =3D gic_suspend(); + if ( status ) + { + system_state =3D SYS_STATE_resume; + goto resume_time; + } + + set_init_ttbr(xen_pgtable); + + /* + * Enable identity mapping before entering suspend to simplify + * the resume path + */ + update_boot_mapping(true); + + if ( prepare_resume_ctx() ) + { + status =3D call_psci_system_suspend(); + /* + * If suspend is finalized properly by above system suspend PSCI c= all, + * the code below in this 'if' branch will never execute. Execution + * will continue from hyp_resume which is the hypervisor's resume = point. + * In hyp_resume CPU context will be restored and since link-regis= ter is + * restored as well, it will appear to return from prepare_resume_= ctx. + * The difference in returning from prepare_resume_ctx on system s= uspend + * versus resume is in function's return value: on suspend, the re= turn + * value is a non-zero value, on resume it is zero. That is why the + * control flow will not re-enter this 'if' branch on resume. + */ + if ( status ) + dprintk(XENLOG_WARNING, "PSCI system suspend failed, err=3D%d\= n", + status); + + system_state =3D SYS_STATE_resume; + } + else + { + system_state =3D SYS_STATE_resume; + + /* + * CPU0 resumes directly from hyp_resume(), bypassing the CPU hotp= lug + * path that re-checks and re-enables errata workarounds for secon= dary + * CPUs. + */ + check_local_cpu_errata(); + check_local_cpu_features(); + BUG_ON(enable_local_cpu_errata_workarounds()); + } + + update_boot_mapping(false); + + gic_resume(); + + resume_time: + time_resume(); + + local_irq_restore(flags); + + console_resume(); + + resume_iommu: + iommu_resume(); + + resume_end_sync: + console_end_sync(); + + resume_nonboot_cpus: + /* + * The rcu_barrier() has to be added to ensure that the per cpu area is + * freed before a non-boot CPU tries to initialize it (_free_percpu_ar= ea() + * has to be called before the init_percpu_area()). This scenario occu= rs + * when non-boot CPUs are hot-unplugged on suspend and hotplugged on r= esume. + */ + rcu_barrier(); + enable_nonboot_cpus(); + + scheduler_enable(); + thaw_domains(); + + system_state =3D SYS_STATE_active; + + printk("Resume (status %d)\n", status); + + domain_resume(d); +} + +static DECLARE_TASKLET(system_suspend_tasklet, system_suspend, NULL); + +void host_system_suspend(struct domain *d) +{ + system_suspend_tasklet.data =3D (void *)d; + /* + * The suspend procedure has to be finalized by the pCPU#0 (non-boot p= CPUs + * will be disabled during the suspend). + */ + tasklet_schedule_on_cpu(&system_suspend_tasklet, 0); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vpsci.c b/xen/arch/arm/vpsci.c index 0bae42c1bd..6e332d6a12 100644 --- a/xen/arch/arm/vpsci.c +++ b/xen/arch/arm/vpsci.c @@ -237,7 +237,8 @@ static bool domain_in_suspend_state(struct domain *d) return suspended; } =20 -static int32_t domain_psci_system_suspend_policy(struct domain *d) +static int32_t domain_psci_system_suspend_policy(struct domain *d, + bool *host_suspend) { struct domain *other; bool last_awake_control_domain =3D true; @@ -300,6 +301,7 @@ static int32_t domain_psci_system_suspend_policy(struct= domain *d) if ( !host_system_suspend_allowed() ) return PSCI_DENIED; =20 + *host_suspend =3D true; return 0; } =20 @@ -310,6 +312,7 @@ static int32_t do_psci_1_0_system_suspend(register_t ep= oint, register_t cid) struct vcpu *v; struct domain *d =3D current->domain; bool is_thumb =3D epoint & 1; + bool host_suspend =3D false; struct resume_info *rctx =3D &d->arch.resume_ctx; =20 /* THUMB set is not allowed with 64-bit domain */ @@ -334,7 +337,7 @@ static int32_t do_psci_1_0_system_suspend(register_t ep= oint, register_t cid) =20 spin_lock(&vpsci_system_suspend_lock); =20 - rc =3D domain_psci_system_suspend_policy(d); + rc =3D domain_psci_system_suspend_policy(d, &host_suspend); if ( !rc ) { rc =3D domain_shutdown(d, SHUTDOWN_suspend); @@ -359,6 +362,9 @@ static int32_t do_psci_1_0_system_suspend(register_t ep= oint, register_t cid) "SYSTEM_SUSPEND requested, epoint=3D%#"PRIregister", cid=3D%#"= PRIregister"\n", epoint, cid); =20 + if ( host_suspend ) + host_system_suspend(d); + return rc; } =20 --=20 2.43.0