From patchwork Thu Jul 27 07:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13329089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBBA7C001E0 for ; Thu, 27 Jul 2023 07:38:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.570805.892969 (Exim 4.92) (envelope-from ) id 1qOvZg-0000Qz-3R; Thu, 27 Jul 2023 07:38:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 570805.892969; Thu, 27 Jul 2023 07:38:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOvZg-0000Qs-0H; Thu, 27 Jul 2023 07:38:16 +0000 Received: by outflank-mailman (input) for mailman id 570805; Thu, 27 Jul 2023 07:38:14 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOvZe-0000FZ-9d for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 07:38:14 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20627.outbound.protection.outlook.com [2a01:111:f400:7e1b::627]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a26532c-2c50-11ee-8613-37d641c3527e; Thu, 27 Jul 2023 09:38:12 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DBBPR04MB8026.eurprd04.prod.outlook.com (2603:10a6:10:1ed::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 07:38:09 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e%5]) with mapi id 15.20.6631.026; Thu, 27 Jul 2023 07:38:09 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8a26532c-2c50-11ee-8613-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dpLkLxMeWipIXfdCY25mI1kARJQhsvnEy2Q3VqRrpnYjlndNkp6MPIzuQQ/wQtKT9fh/P8cldfvRmZ6WcpunK5Q/pE0BGAisJYv2ARPa2KazTwgRLq2BuKYOI6oxVIR/mXoOgHuJQFMuFx+6LVgRblOpkWvoVI/LYs79Xvy4FwZmSrLT0eS3CgGWitOYEwetGoj0XJmBCog83v9IEMUVUVLfgRMDDai5t2JhZiAu2DeT0yY4Y84OktXQUMFtJ7rcNS+DYBf7bGnWiYvxiI2xZWSshPq2SxrzxjFrT+5d8W3UqjagiADmuh+4duXq9U2MBxxJpj1u3tmgH7eE+Jz1Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=taHtIzeBIdPQZ8hfsCK1k6WHI3O8TZ4BTx1jK1HZDlM=; b=CL1Pm90bMihvxK3goMiwpNxApJdm3mPBengCooGA43ZkMx9XUwKx/Pay+B31c9IPOpB6uYxCBLuMvFsjhl1anWbmKm+OJx26+Am3r+OTg4WQZvEDUPrJw62WdyRFvHlHLB7yj684vrOmaLPlSaAZx1GBjzdOt3LMbdUUQxVHUluiPHQwevBosuuqffL/IBQVc1J3tkZwyynf/F+nhGjgZXzcbEsSQrapmENB2MfRJtUQFAzXx1FeVUmOQ6pBZ0aJBGgScqAsVB6dHVvKIMl76rhrV51E8MHx75ZpphiCUl1ITJHMMHSO5jMh2am5jLi1Ba4aFeWzLJNjp0wSIN6QYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=taHtIzeBIdPQZ8hfsCK1k6WHI3O8TZ4BTx1jK1HZDlM=; b=nPYKliH+B/aR+3Iq+2lMIu+iHa3iWDBQKHrkEEmwi2L1+1YWSGtuA9arV45lVHbhXtTWxydGaRbmrFRkpfBPXSgdPMQsGFxWDC3ZIQCktWPQuZk6hbv9Xi4w8KzISThDQnNn75vAPvhDzaDpflRCRbICDGXSYKzXv7S269aJC9wRk639OGbPy9GA8yW2ULG/4w/5wBK6e5tHqZk3M5+riFcxeU3sNKDQ7aFJ4FxjNF67LVSRv7vge05keJ/7sGcF4Qlt0BpK9wanJsQy9mtnGMLZGnMInfrikaDCR2+tFdAB5H39PZTD6QnrW3FoFn9Hy7+20aXJD0YcmNnvaDvLFw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 27 Jul 2023 09:38:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: [PATCH v3 1/3] restrict concept of pIRQ to x86 Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Bertrand Marquis , Volodymyr Babchuk References: <7cb0d24e-2bda-dcda-4874-2c01ba179947@suse.com> In-Reply-To: <7cb0d24e-2bda-dcda-4874-2c01ba179947@suse.com> X-ClientProxiedBy: FR2P281CA0144.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:98::18) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DBBPR04MB8026:EE_ X-MS-Office365-Filtering-Correlation-Id: 76c16a22-ddc8-483e-4177-08db8e746cce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6pslMkiDn1JtJT0lHkUYCjfK0yjDPRJE4YZPiKIzv8z/hy/rAiaJWiA9KylgHEbImyNQyHlVkCO7DFRVmV+n7RoOgy5+cybxHOsdjpyKQpnn5WCYrvTf7WCxGMz//R0nxeVJhmx5LFSi9JfxUUXgtC15rbROjlP+P0/7laDYtrnxa/ubrb8S2MztjFAWJ4Sjp5kGsIAQii2o6AsANTDLHnDyPrO7HZAAYUkTSZFAWbhZpvKcTSSnFOdlDch+WzDHGwIpIyVMiXOiEbbgI2w4XnhmCbD+nC6mmeNv41yqvUUqg9ALRAIMvSNtomE1Jh9lxNmQyQNgBY7qzZVeQ5o/+5V++nMg+RjqfXyvHKF90B4eTj5gP0TqtMImZmGmT0PQAATPiIq7GTrBFFVygUMLFxGA69Ukol1aQk4mHNI00fak1YSeFGu52P0LjPPSOI3f+vwKNV/9xD5pJoYK8fCaiv4r3lfQKadkhGmDVhVRPT1cYMsxJ8mFY4/u22DAPfNl6OMxhxgmblNAdE15znMvXrR7egnCdhqFiHNcJ5nBk/16rB8ki8CKj/Et2H+L6MK04jBaJfAsbDFf01g+CE+53aKLoIDiEkns/eEI1GvSg7Ha01uIyusbwSBk1TqgIuU+hCNoSVIj3DUDvuKfm6A3PQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(396003)(39860400002)(136003)(366004)(376002)(451199021)(6486002)(478600001)(83380400001)(6506007)(26005)(6512007)(6916009)(4326008)(54906003)(66556008)(66476007)(66946007)(186003)(2616005)(38100700002)(31686004)(8936002)(8676002)(5660300002)(2906002)(316002)(41300700001)(86362001)(31696002)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?p12+ZWmNp5gn3Tre9xglk59h+Wfm?= =?utf-8?q?bONXhWWY6v/A1zu73kUSBCgZXxkwvXVNZOyLXTM7dd9V14F8K9ImEoh2GKNJLpbVT?= =?utf-8?q?cuAqZ6+WoiFzqaOuvRVAWnp4VzQKXJkG3Wyq3h4bLFedbhP6NFbmEiggqacynJXKr?= =?utf-8?q?hTWKofymuf7+VCJ4pleRKGGwCg10suiPWT6utC0YvzF5vRon9pvFZ1kq073LKkMPJ?= =?utf-8?q?j8bPywf0vYk2b2oVInFBSuiXPuhREX8iwyBKN1X7FFVBgOtnrAlGqpX3NHyewtDs2?= =?utf-8?q?q4GyVuX24FEH36brL4LEyQSWN+5QJAwMEQlYg4ZjWCq4NFc6XqLTXhu2OUEZvyBdb?= =?utf-8?q?tLOJ21uUgSvejsTBaFIXRvGLfDfD0xdPbDCAVLVP/fWPd9t3t+hyvUSZMhX/WRn+/?= =?utf-8?q?tn0OT2/UKo7GNBPX3hbq77e1Guluhnqq+8rGqers7pfUq3mCn/AOwbDatZhEGqpyo?= =?utf-8?q?SNmaFuk6k2h3kOu6y1j5/mu0zKZxfgEQ+tDG69JldV1f3fkFqcCdilXCYdOA7QN7v?= =?utf-8?q?O2zaMwmHG78xgxE5A3ads2vXvR/ImxJ85T89mIdnmNO5+jqYDpZUBbFG0BoBAeZHu?= =?utf-8?q?mZl0U1/YLrxMVYhW33uKK9cXZmqaHuKmhcKM0OLM8pfB7RWtnADZReL+F7IkdFyo2?= =?utf-8?q?esypgT/8aamzKQVFjIxmPAmsxEe0u6Ip91jjQ6ITsC7wnHYetbxv32rNyeFWZQnRZ?= =?utf-8?q?xuI/VPlIdRkik5iFO5X9LAWkJ7lxtZ2ensVO2uJ9sxzkO5QTzMcll1BrMGS7JMPu0?= =?utf-8?q?SvT9ZLBmJQuMPDyGoDRNdqEGLBmKid0Z4iqeAj0oRW1MoXaJ3gSsvTd8oTZ+HFI8n?= =?utf-8?q?QBRmmaMewjjaR9jP2ly93ql9/dVHAkL44bi6sP3VsZAkn9zXT6etKaWV/Z8cZs3kP?= =?utf-8?q?660aK1Zbu89R95yvO1JpkSP5CpuYaEwOvWi5dHPesS5d2e0CXdhEDvZK2ADTBEUuz?= =?utf-8?q?o4gVzMjISdSEZZC732OZF47JLj48puZQLR5Cs7BsBnXuIizSA8P43ePhPzzQKokow?= =?utf-8?q?tSBCy4L7qfDxKujsisHqdaYVy7Q1Z90u7vSwMaNMVwNZqfMDSGBMOYQqu83a3SufZ?= =?utf-8?q?NIuyXJ3CZRRJqs4/LpxrSlq32y38WDoFUnsVmzrbBgSEMq1sNPb+nuqHn5W0j3HfC?= =?utf-8?q?LI7wAq8+jQgYVz+lCW2wKA2FNGlj6HKTjd/gBop1iy39tZYKk0s0m0jbJDlyxAcBo?= =?utf-8?q?mkxkm8phwly6dB3dzfA3bymRJcPBiHT/BVs1rbO3p+lW9ZAxKCJEO8CgIbKSOyaCn?= =?utf-8?q?ChcObv2vvuBoQ+oHCvrFkMHCm7wo3CchMQrxKRwek41szGkT0pgil+hVAGeb0QEgN?= =?utf-8?q?54PEaLWmDsYs7kHqTkbG30kuT7sO7bnz238D7+fBFHsc2bVB2bjZqw+k3X1J7GcOH?= =?utf-8?q?qWA/aJNcFywSfqR5EZn8S1G3wm0Lw4oqKSA45LJ01cxQV1GcPHkmRlJYx0S+GpY4I?= =?utf-8?q?8lWBbDctXwcixyVsVeK4p5XSHBzbO3Y3fu7C1fgSylqBPz+4pLiCxVbxbqrPWDWep?= =?utf-8?q?OfDgjEWxQtrr?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76c16a22-ddc8-483e-4177-08db8e746cce X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 07:38:09.7606 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EpjO4hO3cF0JxkUdOJEXxijokyqF4+mTgfJ+kVK8nfetsHO3bHHLAz8hC3UiUIG+IK51ObhzgLsjRenBEC3ocQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8026 ... by way of a new arch-selectable Kconfig control. Note that some smaller pieces of code are left without #ifdef, to keep things better readable. Hence items like ECS_PIRQ, nr_static_irqs, or domain_pirq_to_irq() remain uniformly. As to XEN_DOMCTL_irq_permission - this, despite having a uniformly available wrapper in libxc, is unused on Arm: libxl bypasses those calls, and the Python and OCamL bindings have no users at all. Signed-off-by: Jan Beulich Acked-by: Julien Grall --- v3: Move #ifdef in xen/common/domctl.c around the entire sub-op. Re-base. v2: New. --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1136,7 +1136,7 @@ introduced with the Nehalem architecture intended as an emergency option for people who first chose fast, then change their minds to secure, and wish not to reboot.** -### extra_guest_irqs +### extra_guest_irqs (x86) > `= [][,]` > Default: `32,` --- a/xen/arch/arm/include/asm/irq.h +++ b/xen/arch/arm/include/asm/irq.h @@ -52,7 +52,6 @@ struct arch_irq_desc { extern const unsigned int nr_irqs; #define nr_static_irqs NR_IRQS -#define arch_hwdom_irqs(domid) NR_IRQS struct irq_desc; struct irqaction; --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -25,6 +25,7 @@ config X86 select HAS_PCI select HAS_PCI_MSI select HAS_PDX + select HAS_PIRQ select HAS_SCHED_GRANULARITY select HAS_UBSAN select HAS_VPCI if HVM --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -56,6 +56,9 @@ config HAS_KEXEC config HAS_PDX bool +config HAS_PIRQ + bool + config HAS_PMAP bool --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -350,6 +350,8 @@ static int late_hwdom_init(struct domain #endif } +#ifdef CONFIG_HAS_PIRQ + static unsigned int __read_mostly extra_hwdom_irqs; static unsigned int __read_mostly extra_domU_irqs = 32; @@ -364,6 +366,8 @@ static int __init cf_check parse_extra_g } custom_param("extra_guest_irqs", parse_extra_guest_irqs); +#endif /* CONFIG_HAS_PIRQ */ + static int __init cf_check parse_dom0_param(const char *s) { const char *ss; @@ -682,6 +686,7 @@ struct domain *domain_create(domid_t dom if ( is_system_domain(d) && !is_idle_domain(d) ) return d; +#ifdef CONFIG_HAS_PIRQ if ( !is_idle_domain(d) ) { if ( !is_hardware_domain(d) ) @@ -693,6 +698,7 @@ struct domain *domain_create(domid_t dom radix_tree_init(&d->pirq_tree); } +#endif if ( (err = arch_domain_create(d, config, flags)) != 0 ) goto fail; @@ -784,7 +790,9 @@ struct domain *domain_create(domid_t dom { evtchn_destroy(d); evtchn_destroy_final(d); +#ifdef CONFIG_HAS_PIRQ radix_tree_destroy(&d->pirq_tree, free_pirq_struct); +#endif } if ( init_status & INIT_watchdog ) watchdog_domain_destroy(d); @@ -1180,7 +1188,9 @@ static void cf_check complete_domain_des evtchn_destroy_final(d); +#ifdef CONFIG_HAS_PIRQ radix_tree_destroy(&d->pirq_tree, free_pirq_struct); +#endif xfree(d->vcpu); @@ -1893,6 +1903,8 @@ long do_vm_assist(unsigned int cmd, unsi } #endif +#ifdef CONFIG_HAS_PIRQ + struct pirq *pirq_get_info(struct domain *d, int pirq) { struct pirq *info = pirq_info(d, pirq); @@ -1922,6 +1934,8 @@ void cf_check free_pirq_struct(void *ptr call_rcu(&pirq->rcu_head, _free_pirq_struct); } +#endif /* CONFIG_HAS_PIRQ */ + struct migrate_info { long (*func)(void *data); void *data; --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -648,6 +648,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe } break; +#ifdef CONFIG_HAS_PIRQ case XEN_DOMCTL_irq_permission: { unsigned int pirq = op->u.irq_permission.pirq, irq; @@ -667,6 +668,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe ret = irq_deny_access(d, irq); break; } +#endif case XEN_DOMCTL_iomem_permission: { --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -567,6 +567,7 @@ static int evtchn_bind_ipi(evtchn_bind_i return rc; } +#ifdef CONFIG_HAS_PIRQ static void link_pirq_port(int port, struct evtchn *chn, struct vcpu *v) { @@ -592,9 +593,11 @@ static void unlink_pirq_port(struct evtc chn->u.pirq.prev_port; } +#endif /* CONFIG_HAS_PIRQ */ static int evtchn_bind_pirq(evtchn_bind_pirq_t *bind) { +#ifdef CONFIG_HAS_PIRQ struct evtchn *chn; struct domain *d = current->domain; struct vcpu *v = d->vcpu[0]; @@ -664,6 +667,9 @@ static int evtchn_bind_pirq(evtchn_bind_ write_unlock(&d->event_lock); return rc; +#else /* !CONFIG_HAS_PIRQ */ + return -EOPNOTSUPP; +#endif } @@ -696,6 +702,7 @@ int evtchn_close(struct domain *d1, int case ECS_UNBOUND: break; +#ifdef CONFIG_HAS_PIRQ case ECS_PIRQ: { struct pirq *pirq = pirq_info(d1, chn1->u.pirq.irq); @@ -705,14 +712,13 @@ int evtchn_close(struct domain *d1, int pirq_guest_unbind(d1, pirq); pirq->evtchn = 0; pirq_cleanup_check(pirq, d1); -#ifdef CONFIG_X86 if ( is_hvm_domain(d1) && domain_pirq_to_irq(d1, pirq->pirq) > 0 ) unmap_domain_pirq_emuirq(d1, pirq->pirq); -#endif } unlink_pirq_port(chn1, d1->vcpu[chn1->notify_vcpu_id]); break; } +#endif case ECS_VIRQ: { struct vcpu *v; @@ -1122,6 +1128,8 @@ int evtchn_bind_vcpu(evtchn_port_t port, case ECS_INTERDOMAIN: chn->notify_vcpu_id = v->vcpu_id; break; + +#ifdef CONFIG_HAS_PIRQ case ECS_PIRQ: if ( chn->notify_vcpu_id == v->vcpu_id ) break; @@ -1131,6 +1139,8 @@ int evtchn_bind_vcpu(evtchn_port_t port, cpumask_of(v->processor)); link_pirq_port(port, chn, v); break; +#endif + default: rc = -EINVAL; break; --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -438,12 +438,14 @@ struct domain struct grant_table *grant_table; +#ifdef CONFIG_HAS_PIRQ /* * Interrupt to event-channel mappings and other per-guest-pirq data. * Protected by the domain's event-channel spinlock. */ struct radix_tree_root pirq_tree; unsigned int nr_pirqs; +#endif unsigned int options; /* copy of createdomain flags */ From patchwork Thu Jul 27 07:38:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13329090 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 996C1C001DC for ; Thu, 27 Jul 2023 07:38:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.570806.892979 (Exim 4.92) (envelope-from ) id 1qOvZz-0000rr-BU; Thu, 27 Jul 2023 07:38:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 570806.892979; Thu, 27 Jul 2023 07:38:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOvZz-0000ra-7B; Thu, 27 Jul 2023 07:38:35 +0000 Received: by outflank-mailman (input) for mailman id 570806; Thu, 27 Jul 2023 07:38:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOvZx-0000oV-Il for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 07:38:33 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20627.outbound.protection.outlook.com [2a01:111:f400:7e1b::627]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9636c91a-2c50-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 09:38:32 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DBBPR04MB8026.eurprd04.prod.outlook.com (2603:10a6:10:1ed::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 07:38:31 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e%5]) with mapi id 15.20.6631.026; Thu, 27 Jul 2023 07:38:31 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9636c91a-2c50-11ee-b247-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S36Ixr4Z+Ln7tN/dSjpT2baYv+w+4WIJiQR4Y7v84Fm+jtYj2MFZjWvXX9jfOYlzeb3//uzQVAU9LPIVp5Y0KMOmFavrmOw2MXoNZrSXTonHXQ7MAbCbFLkP8VsfDVHV9Vo0cKC4TJYM6snAho+ZqwvE7jxptQ1ZyIpDiboUpLvB2WSzEwTlhvA6q5JkrWAHv90IUL++jVckFvUIvgKBHvuoItsuF4V89wPg9Pvu7UJSCwM16rlQ4jILKfUr31WP9HfhWoAYtLlAq9QJOoBQqibggntGDOo4SXRJ0dCPU9LgT/a5/BnuZ0mRfl/AYlNiKtnFKwxQkhk1BdUBiIZBYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=42G1q1cbtqLAMoOILaHON+bdi1vm2gokigDbkHTcLas=; b=im54/SKoplx/5mwC6VfvATT4eOkoJI7tyUjARqxjVN5ipGGcNV7SU+Dd/F61wI29u2vLS/cmzjv6E6ePCZKhD3UeT61rrCdr8omA9YMCHdhGvRBdxDhCYVWEYREY3zqNNrSKEtNS+w3vbAyGOwk7KI6f+eXt15leHVQ7j616GCcNwDyYSqjLSDJwYxzeCEOVXoV7pl8bvO+1MldyQpRkl8w65N6G9/jodYJc6lBD0o5Tx7nH3a8s8T9mTZvd4sbWTih2BcnfvnWFZ113V/05pM5baLH2pxekg4fymNa8f236e9Zj1NehNvyXRybWeuvjAspx/dIM3FvU3RaW88erIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=42G1q1cbtqLAMoOILaHON+bdi1vm2gokigDbkHTcLas=; b=C0f1ociMyS9vc9x+0AzwYlBDRBJ2/UxqacI/na6zD+u+AdonkZvChNia62dtt/tz4YlDTSVK+0VeH7AHSdoCUU27RfR0WiRVLvv/MHXJLheKlYh3lgemwBXVKSPXGlAbElpXgRvSYpvD222Jh7BlHM7v0kPCm2zhmHboZu+p4ima15joL+SvgPwYl79uPTfkUTSj8scy6J16rKFoU2v3fXZSQD1Syf0E9PIbedDnhhYoglz8mvXlMKqdx68eZXoLOx2v6t7bfGyiyH4TZVUQU59xGdjB5vDiOBLtst9/Ev5vvtDJIh7Qs1BtNUKfv/nZIKcpdDLPJx8CfHLNVjN0Wg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <5641f8eb-5736-8ccc-122b-b3b47c1bac28@suse.com> Date: Thu, 27 Jul 2023 09:38:29 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: [PATCH v3 2/3] pirq_cleanup_check() leaks Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <7cb0d24e-2bda-dcda-4874-2c01ba179947@suse.com> In-Reply-To: <7cb0d24e-2bda-dcda-4874-2c01ba179947@suse.com> X-ClientProxiedBy: FR0P281CA0245.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:af::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DBBPR04MB8026:EE_ X-MS-Office365-Filtering-Correlation-Id: d0e47f9d-840e-464a-5cba-08db8e747992 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SQg/baH/L+3HTi5t7EeuF7Jhyc36KxHdDA/186cQTCKdqBaQBR3kCTRqmRPvkVptJPolJL1kbmkVqYYh8GnB4SEI/zmLASS4+c9P0ebAKY3+hho5p/NBEczDvJbofFnkcs0+hk8n1Q29UsRNvTnT3Ewk9LoHl6OGbIXuwj2DxBqLrFaC/cciePAI/8tQshKOpThh5CVZuShAyCFocY2jiCmCtx4KOejW1mPs5X2ugqiPGRtt3xosfHJWmlJFYVj4TWw1Hhmi/Zn1tMuG317a9omN/zATFCbLygIeluSyd0Us5T/we8vh2uE9+keft3L3Zj/HjlJOAWwmq0hw6xLn5hLGchSoOBBUy53nKJNl8FCrwvEDCPDXXSkR32aonyAKH03J8n8YBbZOFcAQFJFPdd6nemJvv5rQKTAvIj/kaFQ7rMnCy72yh5TT5Pipd1gyKqoX9MDxok9wirtrNGMl0PnVPl/2+LRoL9Ii3VtS+KswnwXM9273upk5UxtemDCu5Me0pp3qxDmtG4QTUD00AgZpESeSNPYyp3lpL9emORIr50h5AxxE1VaAlnyPtwsgFiJbk6eKQeFp5xWFZJW53wsFVZT+O3LtLv5Zuab2jJM9vqR5qxOD5ej9TARvV6dGt4s4MREPYYRnIAJ+5ZH/UA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(396003)(39860400002)(136003)(366004)(376002)(451199021)(6486002)(478600001)(83380400001)(6506007)(26005)(6512007)(6916009)(4326008)(54906003)(66556008)(66476007)(66946007)(186003)(2616005)(38100700002)(31686004)(8936002)(8676002)(5660300002)(2906002)(316002)(41300700001)(86362001)(31696002)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?EPaCki54CgDVES2fcrJdYHSleuof?= =?utf-8?q?8sl/tfa6NVnZcMhn1LylLAlDiObWywuz9melaop2CJ7MEHWwgrO6cEJThNXY88Vxb?= =?utf-8?q?VA5h2tDe3FpfjppxBxTWAXFa7yFoCdzEK137zZ2CydD3wzYrsgAAB08kK+6yT7B+5?= =?utf-8?q?JIPmi3Iif/wolwWEBQH9f19titPF4Q+N4Qm9w6t9jNL+X5Itac1w/pa9esWWZu9hi?= =?utf-8?q?1yu18DaZWVQGN/XPVIGNJi862SzgaFDnsqxeUBOtScCy/AlG0bMeOVb8Q4ttb/XSS?= =?utf-8?q?NmtgYLN28zYrXtpK/3gpkm1g8oFcEtcPSpajxwbZo+PfavIwC9kM7at6jL28efuS0?= =?utf-8?q?/n2wf4wdNAA+TG36Q5UjiKc+cuVvll6u52YziaGU80YyZMRvZ04FG5ZOvq302X0CU?= =?utf-8?q?ag8cXFJRW2enc7QCo172NSRB7vOXesgsjqxWaC8tpDAlWBVSHzPWre054pMi3Ix2Y?= =?utf-8?q?JHPBHLMP0ToEuHN8VS/NxrEyUYvVWj9Yh6o4E2kJN/Gn/hsZa1RJ7yvVQO1gyRqoj?= =?utf-8?q?SB58KmRwgflUseLqJ1lGiyF5cROHY59eDGYj1Ie5MJasGOsQAYmf+GcswiXapEknV?= =?utf-8?q?m9T5VUBV0a0oFDDpAoQxbU6kcOCmlcRdW0X9ypCDwce6asyrP1G2zWFj0jCwX2jtQ?= =?utf-8?q?3rOANEM3TK18MUKf0kclnfZPdk7zb16dqW+99G6bdXxHkXZFFmFTmW0tr2OzVDahQ?= =?utf-8?q?HoWnUn26mU9cNfpG4vmnkGimfmM6KxUFcixMh1ny/tCDbXkAew5jBXV5j7+IQrWP+?= =?utf-8?q?ohuEGFeLZcpLINbS2gzA3x5Ac9587WcesiqFAgRflSdWN6Z2iQLuEaYVp5Clhgkcy?= =?utf-8?q?gpB3MkTv9hW//ITGaadZ8uITrOtSK/0BY9w2KalNA/e3gn4Rxi/g6+Tms8DOgaLZk?= =?utf-8?q?IEkXrprWVeLFW7+zgKAZcPYOsEZVa0WeVsOtOtxavRXFhtK5sjrvJj8F/Iy9Ju+fI?= =?utf-8?q?o+9gNdhe8UWth2guGY/mVGct86En6pagChe+huuoabIIHL9sXq4GAKybqLoP6Sujz?= =?utf-8?q?EOxMODuSPRK+6A71U8Bqw0Kj0O9+6KlYcNCqjboqzYcMCyqgRXIvTArT4TvyxnA+G?= =?utf-8?q?5ni13ImPB3DUHFbcCZFDU+XGDKbOSnqq2Z2hjdJQcrQLP2jwMtmkjeruUCMeJr0cH?= =?utf-8?q?3yhqft/TUIS9wY3l6Lf9R/3oZq8SXA8uPRHLM1roF91Xbhp1ZfKhk2p7a3Rtle8C/?= =?utf-8?q?TAh/AVYP3FSyqOVaaPU+bXJvkSkDAOHJIIWo219ZN1EhOMlcUlHJk0qSC0G+DKzx2?= =?utf-8?q?6nUu8da33bTUn1JWU+Mfgwfxw5mWFHDGKq9xY0OSDUpz3gXKZUF5UHYF8Sad0XGgC?= =?utf-8?q?4H/h+K8YUQAeihFjuNuB2Ev/prJaFfY5/vot6y6DnAo2Vm5rEHB6UYfc9H6oDlhlA?= =?utf-8?q?5fn9jUsxAn0bctWn/y63uFwKgQeX/bJNkVSyUHaYNsMT4NW4PpoxUZlWGdpxN76JN?= =?utf-8?q?5MWk9hodGiPYT6zhG1nH5G4BMI5t4zYhWaBnXmB9pGL72RWTEs18g2FLT96rF7IwM?= =?utf-8?q?L60nqmP49Nua?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0e47f9d-840e-464a-5cba-08db8e747992 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 07:38:31.1934 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: swjeH4W5T0YnuLfNMSpgIRAZZEoeAnVaSz4EnZ2iiuAz2brzEmkuQnZvDJCIVMWWVXrRcfdhquAaPDKU6TIz+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8026 Its original introduction had two issues: For one the "common" part of the checks (carried out in the macro) was inverted. And then after removal from the radix tree the structure wasn't scheduled for freeing. (All structures still left in the radix tree would be freed upon domain destruction, though.) For the freeing to be safe even if it didn't use RCU (i.e. to avoid use- after-free), re-arrange checks/operations in evtchn_close(), such that the pointer wouldn't be used anymore after calling pirq_cleanup_check() (noting that unmap_domain_pirq_emuirq() itself calls the function in the success case). Fixes: c24536b636f2 ("replace d->nr_pirqs sized arrays with radix tree") Fixes: 79858fee307c ("xen: fix hvm_domain_use_pirq's behavior") Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- This is fallout from me looking into whether the function and macro of the same name could be suitably split, to please Misra rule 5.5. The idea was apparently that the check done in the macro is the "common" part, and the actual function would be per-architecture. Pretty clearly this, if need be, could also be achieved by naming the actual function e.g. arch_pirq_cleanup_check(). Despite my testing of this (to a certain degree), I'm wary of the change, since the code has been the way it was for about 12 years. It feels like I'm overlooking something crucial ... The wrong check is also what explains why Arm got away without implementing the function (prior to "restrict concept of pIRQ to x86"): The compiler simply eliminated the two calls from event_channel.c. --- v3: New. --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -1349,6 +1349,7 @@ void (pirq_cleanup_check)(struct pirq *p if ( radix_tree_delete(&d->pirq_tree, pirq->pirq) != pirq ) BUG(); + free_pirq_struct(pirq); } /* Flush all ready EOIs from the top of this CPU's pending-EOI stack. */ --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -711,9 +711,10 @@ int evtchn_close(struct domain *d1, int if ( !is_hvm_domain(d1) ) pirq_guest_unbind(d1, pirq); pirq->evtchn = 0; - pirq_cleanup_check(pirq, d1); - if ( is_hvm_domain(d1) && domain_pirq_to_irq(d1, pirq->pirq) > 0 ) - unmap_domain_pirq_emuirq(d1, pirq->pirq); + if ( !is_hvm_domain(d1) || + domain_pirq_to_irq(d1, pirq->pirq) <= 0 || + unmap_domain_pirq_emuirq(d1, pirq->pirq) < 0 ) + pirq_cleanup_check(pirq, d1); } unlink_pirq_port(chn1, d1->vcpu[chn1->notify_vcpu_id]); break; --- a/xen/include/xen/irq.h +++ b/xen/include/xen/irq.h @@ -158,7 +158,7 @@ extern struct pirq *pirq_get_info(struct void pirq_cleanup_check(struct pirq *, struct domain *); #define pirq_cleanup_check(pirq, d) \ - ((pirq)->evtchn ? pirq_cleanup_check(pirq, d) : (void)0) + (!(pirq)->evtchn ? pirq_cleanup_check(pirq, d) : (void)0) extern void pirq_guest_eoi(struct pirq *); extern void desc_guest_eoi(struct irq_desc *, struct pirq *); From patchwork Thu Jul 27 07:38:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13329091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB609C001DC for ; Thu, 27 Jul 2023 07:39:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.570809.892989 (Exim 4.92) (envelope-from ) id 1qOvaP-0001Ts-Im; Thu, 27 Jul 2023 07:39:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 570809.892989; Thu, 27 Jul 2023 07:39:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOvaP-0001Tl-G0; Thu, 27 Jul 2023 07:39:01 +0000 Received: by outflank-mailman (input) for mailman id 570809; Thu, 27 Jul 2023 07:39:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOvaO-0000oV-BL for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 07:39:00 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2061e.outbound.protection.outlook.com [2a01:111:f400:7e1b::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a65a739e-2c50-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 09:38:59 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DBBPR04MB8026.eurprd04.prod.outlook.com (2603:10a6:10:1ed::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 07:38:58 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e%5]) with mapi id 15.20.6631.026; Thu, 27 Jul 2023 07:38:58 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a65a739e-2c50-11ee-b247-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hwjPV5rzFikFiImdAsVzsAfrUIrIiieX6RTXK2Z7CmM2zNU+5wc/7sZ4kOrKx0QrtCDNLH1Fo+Da+4Rh517guPk3vi8CXgVzdnQq82dVfve96vF1oyABseynDVOmJ8IaWBq0TzDpWgURENshRpjKy6vfoIUWDT5Nd8q5G7oY+m9vdVGx5dVQnxf2j1kMvhhRsyma2KuAztn8xPlA42rcb2hTqBVc4WkaDG1UgNK/6d0U8uNrcfyROJ0kgHpfddgv+nAKpxg5x9VpjRqdgSkRePjxXDo5Ixf0W+bs/h0hJFgcJqoOOv68M1hn3+J5VqQE3Hd4Ef5w3gXj5tSjMSQuRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=LcI5ZJzazpf4rWCLgNaHF2wR1tw4mKVTroN0tDPQMsM=; b=U5dZHRlscsMqLLIRSNZWHgpMpz4xrpal9KLc28xPSJ2VffYoO/G+O6BlPmVhj5/kZJ7GB+RkQElm2QX3L/C6lJiyDa/4oZe1oZZX8zyq+7wFFBp2tfUOvEeXCxAdjc9K37wwgh0u6maWVx2N+qSTnDfIwkTdG9AGosKCYKnjoTXmclxKLArIJ5pUq6u7BvvqVFMOBtCYKCRqLBbyaE/nqCEsTKYVdAAP9Apqjsiefx5qD9+SAZgzrKpxd0n7tUNrQjCgy10x5co69BJw/z/md2/2j9F303DGLPhWY8PkCrjao8cYhn85dp1pR91oHO9GSVw8QcmIZbM8rZZuM1DPpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LcI5ZJzazpf4rWCLgNaHF2wR1tw4mKVTroN0tDPQMsM=; b=Aj9Yno/MvACaO1g0NEFklF3LLItAvZSh8FpqY0/jNUCt8ihsDAQ/zB98M00X7RUqxZBFbBEJ+/DNR8qlGdHFXYMXDR0NJ4Abnox9kSIbCOh+a/VkY1HZ5tAsUsVUvl6tuXfR72k39MENP9YsTvDGvVmZpB1zvKRkPgHat3ULliIn7hBigVPcM7QiNIdYfh6u2cQqOOxnWFbCvQk7wtOyjlvN9t4mWI2+mISkvid+L4LHyAX/YGnprkaLasShl7CYPEe/uiNBL02z5OIM4ePeHNouVD5MZey72b5gRoeqNk6DyWwDAHbGAO4ruOTm9gSoCm8MoIi9ITBS2LHdXqy6Xw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <3c3a1d0c-06f2-a392-b2f9-381bed5c5e7b@suse.com> Date: Thu, 27 Jul 2023 09:38:55 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: [PATCH v3 3/3] cmdline: document and enforce "extra_guest_irqs" upper bounds Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <7cb0d24e-2bda-dcda-4874-2c01ba179947@suse.com> In-Reply-To: <7cb0d24e-2bda-dcda-4874-2c01ba179947@suse.com> X-ClientProxiedBy: FR0P281CA0226.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b2::19) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DBBPR04MB8026:EE_ X-MS-Office365-Filtering-Correlation-Id: e357e203-fb80-4bb8-3ddd-08db8e74898f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tddKRQH9BPT2hKmHa75uwHZdQw5ByTpVpyxtjSi84jDQ4cdb/omKBMBfPNy7oX5CnZNzJc7khVtJHd+fm7HgODXfgvb8YScdBEBkIkdzbJuUQPcSal4s2WPsCh9srUuu6UlC6pGicK6/MnUZFoyJ9b2b/KcLxgUImikSMpp5hjaluCR7UVkoHKndNCevo0kPL3ocaWoAzofTlDVyyKANnzYCFqoEgUrG5sq4fCFRlNutVY1gLpY3mOHl9U7oASbtkM3oWVqlbI95D++eY0yozC2lTCZ4HVFFKIJRhotH/XMIZNKdH33M5cRjw6hDWCAptDjTPCIMxq1UVHjb06ztyeDZpeyeM2if1T1X0iIkFH3HJ9E2SdBgqi9OIGdTHRQadNdOTyOLhbPIn/kkJaJkBmo4cLqlwLznkgWaiEIw6AwP0sTFKTj+c914TQ809TkDRaUSlVwlADDb+eFQaNSfb9tmVEb2Qa96UR8UV3ccd+GtU111xy71Dx0b/3NzEQ6jWutTHs6aWN21hC5O6XqqhHDFxQpUP7wRbI58Wbvk4xeloeCMP4E56J+8pziogGCxkIn2gttMrKjndTtvr1gGvGIdhAbvAk00YgZKYjEGSGAIbby2U77uKYm64HI9ezN4oShUeKUDXA6+z+pFxHh8Xw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(396003)(39860400002)(136003)(366004)(376002)(451199021)(6666004)(6486002)(478600001)(83380400001)(6506007)(26005)(6512007)(6916009)(4326008)(54906003)(66556008)(66476007)(66946007)(186003)(2616005)(38100700002)(31686004)(8936002)(8676002)(5660300002)(2906002)(316002)(41300700001)(86362001)(31696002)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cdzm2DWhxSFa10canLO+BoAnerMU?= =?utf-8?q?VaBVGxgmQuZJLUK2w0COV/Gy2t9a85n+ElJ/AFX0I37PJgNgBOqDMUJgn5tX8LT6c?= =?utf-8?q?DJOlHQwANKa10I7JMMgwuSQib142JOz75R1YPuq/OS4dQMUaicC+5BWSniBw9VQ/f?= =?utf-8?q?a4CrvYq+ZN2YA0K2Q3iQ2ayB1aHZpByIEiWvUvtikOL+NVJhUyjPdbsPEPHpVK85V?= =?utf-8?q?QdghfsHSs623umzhME+Cp/NeVeMTfKNu+MMkT6xXrZuLVPRaXwyAwfNZQ84jJMScx?= =?utf-8?q?fSgYFR905xvE4XdrU/TVmJ8IDkggROsOia6FHXQXObmZU0CdBzGk1hb1gxjltbvy2?= =?utf-8?q?n0YpiuJagCBQgGq2IA9MiraXw1+OUjETsMupQXhNYIniy3A+0xOV5KEQ5HSEN4Uqw?= =?utf-8?q?GrltMU11Eiwr6RHX/3CVMArjhFWMOdrHQZ6W7NiJfsTswSI6KvLZXNfE2gkjlkY1w?= =?utf-8?q?FddsJipJyDN8MoHn4kq+02DX0cAO1OQ/yf3uxi9QOfAEsPvh2PjrINblXVniyjZSB?= =?utf-8?q?E/tn/prXNEb6E8KxS+u6ggQ4NPAW+i5ScVl0CaRKjkO5m4ysbszXbQmUHxrj5vVQG?= =?utf-8?q?sRxcqvMS3/bP/aNggYUxxKFzcSh6s+OmwYC4pJlYAdzgYbaamM/V8QjbjO11810xP?= =?utf-8?q?LQRqWrPs9WSD6fkF36mF4C7yo9KWcXqavDDM8CBbMOYkDsAyKUYnrV8MNiEB1IdAy?= =?utf-8?q?zdV/KgU4t4DvO6XDCDyx/8NjjMr8nxMoAN/T9cEUdktc8tE5R1jNpDGB1eTMoN3Q2?= =?utf-8?q?5NOP2xG6l7TQaZAvYFV78TsR5UcUfojoqhOaFZKMLPJF1W8votvehnXInuKS951qm?= =?utf-8?q?losxIZG2kAmmTv83rxlWzGNitpFeF61As57ZOhftrgIWCKb8lIAWge1/UHdl5WTmY?= =?utf-8?q?xG9c/wpCnHkvVvoj0PwgW+7dy/0WL5/v7FZfTn/zh4xZlcati/JcMtAoUCiU0pSw/?= =?utf-8?q?bqPYCHpFowWkNMmaiNTd7gSnuKz3q4mWLafusimHV1miKyfKUbw2YwJwdIVSMAMt3?= =?utf-8?q?rDtBou5X1JfvaphaAv/ZhMNU8ugwPrgZyeXQ5dnTtlcVvXaN4jTjNFvdQTNvCuAwa?= =?utf-8?q?UbhDT+LKe+JWQvTk3DaUIwwVFj9pHJB/QwvLEii9njNbB7mfGJ0CMAYqG31NkCXYo?= =?utf-8?q?tlocCWh0avoxkZ0zx55cpRD98iUqS3scyb90dXBhVTLFw6G9/HNKLrn67EUTWrVcV?= =?utf-8?q?Z5Rn7PEBXp8JglthcU+5xxQ5zlnmk7mevNL46Sa/lkNdCq0D6mw2tFYmx0QUWI/BV?= =?utf-8?q?RdGwwKZRWpW+EbGZjH8/AvLHJlXAr/cykoIMO3LpDx1MezeHQ2H93vhUq1gbe/EtJ?= =?utf-8?q?LacESC8vY0kyG+Au3g/pRp0c41jcDOBHJCpq+chSbcWxdoAgnh9BfUYklCWPsZoLh?= =?utf-8?q?O6vK07nI0rCPIKYzg4U2RllCilX1GmsY1V/PKERTf9pgKqP+7DcP/Sv61emJb9+L4?= =?utf-8?q?9stHorgeCC9sAL6J4Ebj3Xh0jHO8ctEOk8t+t7HidMTNR0uoaT60XHAbYzBZx/lf5?= =?utf-8?q?jFfm9n2GeXGm?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e357e203-fb80-4bb8-3ddd-08db8e74898f X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 07:38:58.7502 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u0zbVvRQOV3DmCAIw7+qnOc+Eovgqu1z68HmgyMm5pw31KL68/KIYfQVeA9YiWE72HUc9lO2PjNoe++uMfv1KQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8026 PHYSDEVOP_pirq_eoi_gmfn_v accepting just a single GFN implies that no more than 32k pIRQ-s can be used by a domain on x86. Document this upper bound. To also enforce the limit, (ab)use both arch_hwdom_irqs() (changing its parameter type) and setup_system_domains(). This is primarily to avoid exposing the two static variables or introducing yet further arch hooks. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- Instead of passing dom_xen into arch_hwdom_irqs(), NULL could also be used. That would make the connection to setup_system_domains() yet more weak, though. Passing the domain pointer instead of the domain ID would also allow to return a possibly different value if sensible for PVH Dom0 (which presently has no access to PHYSDEVOP_pirq_eoi_gmfn_v in the first place). --- v2: Also enforce these bounds. Adjust doc to constrain the bound to x86 only. Re-base over new earlier patch. --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1146,7 +1146,8 @@ common for all domUs, while the optional is for dom0. Changing the setting for domU has no impact on dom0 and vice versa. For example to change dom0 without changing domU, use `extra_guest_irqs=,512`. The default value for Dom0 and an eventual separate -hardware domain is architecture dependent. +hardware domain is architecture dependent. The upper limit for both values on +x86 is such that the resulting total number of IRQs can't be higher than 32768. Note that specifying zero as domU value means zero, while for dom0 it means to use the default. --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -2663,18 +2663,21 @@ void __init ioapic_init(void) nr_irqs_gsi, nr_irqs - nr_irqs_gsi); } -unsigned int arch_hwdom_irqs(domid_t domid) +unsigned int arch_hwdom_irqs(const struct domain *d) { unsigned int n = fls(num_present_cpus()); - if ( !domid ) + if ( is_system_domain(d) ) + return PAGE_SIZE * BITS_PER_BYTE; + + if ( !d->domain_id ) n = min(n, dom0_max_vcpus()); n = min(nr_irqs_gsi + n * NR_DYNAMIC_VECTORS, nr_irqs); /* Bounded by the domain pirq eoi bitmap gfn. */ n = min_t(unsigned int, n, PAGE_SIZE * BITS_PER_BYTE); - printk("Dom%d has maximum %u PIRQs\n", domid, n); + printk("%pd has maximum %u PIRQs\n", d, n); return n; } --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -693,7 +693,7 @@ struct domain *domain_create(domid_t dom d->nr_pirqs = nr_static_irqs + extra_domU_irqs; else d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs - : arch_hwdom_irqs(domid); + : arch_hwdom_irqs(d); d->nr_pirqs = min(d->nr_pirqs, nr_irqs); radix_tree_init(&d->pirq_tree); @@ -819,6 +819,24 @@ void __init setup_system_domains(void) if ( IS_ERR(dom_xen) ) panic("Failed to create d[XEN]: %ld\n", PTR_ERR(dom_xen)); +#ifdef CONFIG_HAS_PIRQ + /* Bound-check values passed via "extra_guest_irqs=". */ + { + unsigned int n = max(arch_hwdom_irqs(dom_xen), nr_static_irqs); + + if ( extra_hwdom_irqs > n - nr_static_irqs ) + { + extra_hwdom_irqs = n - nr_static_irqs; + printk(XENLOG_WARNING "hwdom IRQs bounded to %u\n", n); + } + if ( extra_domU_irqs > max(32U, n - nr_static_irqs) ) + { + extra_domU_irqs = n - nr_static_irqs; + printk(XENLOG_WARNING "domU IRQs bounded to %u\n", n); + } + } +#endif + /* * Initialise our DOMID_IO domain. * This domain owns I/O pages that are within the range of the page_info --- a/xen/include/xen/irq.h +++ b/xen/include/xen/irq.h @@ -173,8 +173,9 @@ extern irq_desc_t *pirq_spin_lock_irq_de unsigned int set_desc_affinity(struct irq_desc *, const cpumask_t *); +/* When passed a system domain, this returns the maximum permissible value. */ #ifndef arch_hwdom_irqs -unsigned int arch_hwdom_irqs(domid_t); +unsigned int arch_hwdom_irqs(const struct domain *); #endif #ifndef arch_evtchn_bind_pirq