From nobody Fri Nov 22 18:28:58 2024 Delivered-To: importer@patchew.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=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1716450090; cv=pass; d=zohomail.com; s=zohoarc; b=QPHHXtDHYFK9BY0b6SNhPDtQiH0M4NQ9LqNR3MvycpAVPWRsPw+/bt/Zj08MM7GQshqT+wAAyBTY+N3Kw2mc7pZyHa4lriO1IQWHO65d6t/i2GEQuYs9ylJ4ERA/0lpYLwYxGmzT8ctb9ZhQZ1/SSaTJ2ousvsgwNC+Alt1ZX2E= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716450090; 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=L8dKwKh5Agkr6/Sz2gAOhHiky/a7zfL5mmaZ+kO5RLw=; b=ES0P3xH8YBoEL1bCgcexjuoU0I3xEaBESv1v41LAT5iNXgLVSu3e6e9JbB3kIMSLS7UyHyNifehujce9vHG6FI3DjpjF5iHWkvnqMW1NBnPTrGyhJawzIg/HR3xY9g8PDVhxQ8yXjKvgy/rCDcrE1kIdSRGyugb6X+OuIlI8Ef8= 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=amd.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 1716450090833822.4436803766164; Thu, 23 May 2024 00:41:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.728101.1132930 (Exim 4.92) (envelope-from ) id 1sA34Y-0003hP-N9; Thu, 23 May 2024 07:41:10 +0000 Received: by outflank-mailman (output) from mailman id 728101.1132930; Thu, 23 May 2024 07:41: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 1sA34Y-0003gE-Gq; Thu, 23 May 2024 07:41:10 +0000 Received: by outflank-mailman (input) for mailman id 728101; Thu, 23 May 2024 07:41:09 +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 1sA34W-0003CF-VT for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:41:08 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2415::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cdf34002-18d7-11ef-b4bb-af5377834399; Thu, 23 May 2024 09:41:03 +0200 (CEST) Received: from CH0PR03CA0441.namprd03.prod.outlook.com (2603:10b6:610:10e::34) by LV3PR12MB9215.namprd12.prod.outlook.com (2603:10b6:408:1a0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.18; Thu, 23 May 2024 07:40:59 +0000 Received: from CH1PEPF0000AD77.namprd04.prod.outlook.com (2603:10b6:610:10e:cafe::99) by CH0PR03CA0441.outlook.office365.com (2603:10b6:610:10e::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.18 via Frontend Transport; Thu, 23 May 2024 07:40:59 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH1PEPF0000AD77.mail.protection.outlook.com (10.167.244.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:58 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 May 2024 02:40:57 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:55 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cdf34002-18d7-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RBUWCnqg9UeHYedJVl/R9pfYRSQPbqjaNn7+kPZ1VzeYDdGsRAp6XO47j2WTc9R8hM4UNNlWKMNw9MswuMqsmKEnjdMfgGqrE4wyf3xQ5L0TofVKYiwN/gtb9hkGr8TqbdvBzej0OAR6vc5DxmMLvGN0qg4FskHGYTkKxlhZ63v0cofGYvrswBoEhfCeZ8RopH0nWDa1LGDZsA/ec4cxH9Zj+CN4JI0T4+i/Q7sIZD1vJQ/3sudVXdI5ooolnAkTZcHZi2yu8B501MN90jnYqJ6+zAOnPs4lfH8osgQlkR2uMslfZYvy/hi8DC71mal6htn6GKUl6Sy27xa20e76Yw== 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=L8dKwKh5Agkr6/Sz2gAOhHiky/a7zfL5mmaZ+kO5RLw=; b=n1oH2n8ilKylm7HfqTfqeCDmNiQtZwqTCQcKFooiKb/aHe0ze2d4w91fG5jwTa5/Ewa6XB40tDtz+8hCSkuEIqIfOyufbswZ7vWKRIkSI+OmcaI2TH+9GepKfewK2djNlRVg1uBg0F0Q6uftP6/mJQ0cSDpICce7ZkXgFJziWxsChmFYBhpk8vTg2lrUJvskgp9invOzTcyybXEf4uopUDYYm4Gdm6N4BJYZEd+i9WI4mv89/JiCoCu5VuOfrZ8amP9G3upRy8TnMQmepNchdZiJcpL0wxXcbc8DHoa6v6l9VmJouTLy1ba52svo04rMRpS5NXJUTMhsSXsX5u8oXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L8dKwKh5Agkr6/Sz2gAOhHiky/a7zfL5mmaZ+kO5RLw=; b=qu60VsrHqx7x0QzeoqjN1uswiuS4Q1T48lpY2u313+IUphvS2ILN1y95o22X8mXIlwIIRO/lLjU03QmQ+WB7xdH93inSSXHU55FDY6au3ea7lxuRv1I7M4lnt34nX9KtrG1WnBE3q4ESb9ADol4AxaplKS1KRoggPbLZzYm8kmQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; 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; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , "Henry Wang" Subject: [PATCH v4 6/9] xen/arm/gic: Allow removing interrupt to running VMs Date: Thu, 23 May 2024 15:40:37 +0800 Message-ID: <20240523074040.1611264-7-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB03.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD77:EE_|LV3PR12MB9215:EE_ X-MS-Office365-Filtering-Correlation-Id: 26087eb1-bd6e-4dcb-36f2-08dc7afbb00a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?589QVo1rUR6jtYI+hepZXhQS/2JuFhESRrE1KFczuIeIYQSskO+IhDLWCaOl?= =?us-ascii?Q?UHGvySCx19xxCsbhFfvDxlEYvOmKeT8tUgDhd6i6eGKqvGTlfBDq5zP+wCyV?= =?us-ascii?Q?gsGJbAP+G9sH6anfv2ucG5DNXxVZbqvkomx/ClEJHK1XMj+6s9BZxydxLttU?= =?us-ascii?Q?5ejamBYAhW8iDb8Pdgvn3NtIK6YaSY/B0HxvWftP7f0CDPeUeJf7uMX5cnE+?= =?us-ascii?Q?MABpDff/pLQDcKV6kRJaTp3vw8/07bZ+uEZgO3NbCyj/MH8peeG6167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Ugy8oA/sCeZZOY6nDb4dIlipa+MqEUY6+j9RKnI+/ZZhiNV+PtC5ou5FZuvu?= =?us-ascii?Q?qMVYsFcWFnThJiHQMdu/yQjOFY/o1a5xYH5H3R8SphjTcPMGA0yh7jnB4ry9?= =?us-ascii?Q?W8P3JRGRfTY06Ca5swh4EeACv1QLdXY+G4llyZN2iBzyQV+jLZDmRkSqjkP+?= =?us-ascii?Q?3FQHLoxRyEecKZET/bsAAEXtd746LkaBI2a7eyW9Y71YsTtKrJPV8SPbQzI+?= =?us-ascii?Q?8P978YdRzxirDX2UX1v+FcpyI7C5?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376005)(1800799015)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:58.7826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26087eb1-bd6e-4dcb-36f2-08dc7afbb00a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD77.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9215 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1716450091217100003 Content-Type: text/plain; charset="utf-8" From: Vikram Garhwal Currently, removing physical interrupts are only allowed at the domain destroy time. For use cases such as dynamic device tree overlay removing, the removing of physical IRQ to running domains should be allowed. Move the above-mentioned domain dying check to vgic_connect_hw_irq(). Similarly as the routing interrupt to running domains, reject the operation if the IRQ is active or pending in the guest. Do it for both new and old vGIC implementations. Since now vgic_connect_hw_irq() may reject the invalid operation case, move the clear of _IRQ_INPROGRESS flag in gic_remove_irq_from_guest() to after the successful execution of vgic_connect_hw_irq(). Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Signed-off-by: Henry Wang --- v4: - Split the original patch, only do the removing IRQ stuff in this patch. - Move the clear of _IRQ_INPROGRESS flag in gic_remove_irq_from_guest() to after the successful execution of vgic_connect_hw_irq(). - Special case the d->is_dying check. --- xen/arch/arm/gic-vgic.c | 27 ++++++++++++++++++++++++--- xen/arch/arm/gic.c | 9 +-------- xen/arch/arm/vgic/vgic.c | 24 ++++++++++++++++++++---- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c index b99e287224..56b6a3d5b0 100644 --- a/xen/arch/arm/gic-vgic.c +++ b/xen/arch/arm/gic-vgic.c @@ -439,6 +439,14 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu = *v, unsigned int virq, =20 /* We are taking to rank lock to prevent parallel connections. */ vgic_lock_rank(v_target, rank, flags); + /* Return with error if the IRQ is being migrated. */ + if( test_bit(GIC_IRQ_GUEST_MIGRATING, &p->status) ) + { + vgic_unlock_rank(v_target, rank, flags); + return -EBUSY; + } + + spin_lock(&v_target->arch.vgic.lock); =20 if ( connect ) { @@ -456,12 +464,25 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu= *v, unsigned int virq, } else { - if ( desc && p->desc !=3D desc ) - ret =3D -EINVAL; + if ( d->is_dying ) + { + if ( desc && p->desc !=3D desc ) + ret =3D -EINVAL; + else + p->desc =3D NULL; + } else - p->desc =3D NULL; + { + if ( (desc && p->desc !=3D desc) || + test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) || + test_bit(GIC_IRQ_GUEST_ACTIVE, &p->status) ) + ret =3D -EINVAL; + else + p->desc =3D NULL; + } } =20 + spin_unlock(&v_target->arch.vgic.lock); vgic_unlock_rank(v_target, rank, flags); =20 return ret; diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index b3467a76ae..8633f14bdd 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -159,24 +159,17 @@ int gic_remove_irq_from_guest(struct domain *d, unsig= ned int virq, ASSERT(test_bit(_IRQ_GUEST, &desc->status)); ASSERT(!is_lpi(virq)); =20 - /* - * Removing an interrupt while the domain is running may have - * undesirable effect on the vGIC emulation. - */ - if ( !d->is_dying ) - return -EBUSY; - desc->handler->shutdown(desc); =20 /* EOI the IRQ if it has not been done by the guest */ if ( test_bit(_IRQ_INPROGRESS, &desc->status) ) gic_hw_ops->deactivate_irq(desc); - clear_bit(_IRQ_INPROGRESS, &desc->status); =20 ret =3D vgic_connect_hw_irq(d, NULL, virq, desc, false); if ( ret ) return ret; =20 + clear_bit(_IRQ_INPROGRESS, &desc->status); clear_bit(_IRQ_GUEST, &desc->status); desc->handler =3D &no_irq_type; =20 diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 048e12c562..0c324b58f7 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -890,14 +890,30 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu= *vcpu, } else /* remove a mapped IRQ */ { - if ( desc && irq->hwintid !=3D desc->irq ) + if ( d->is_dying ) { - ret =3D -EINVAL; + if ( desc && irq->hwintid !=3D desc->irq ) + { + ret =3D -EINVAL; + } + else + { + irq->hw =3D false; + irq->hwintid =3D 0; + } } else { - irq->hw =3D false; - irq->hwintid =3D 0; + if ( (desc && irq->hwintid !=3D desc->irq) || + irq->active || irq->pending_latch ) + { + ret =3D -EINVAL; + } + else + { + irq->hw =3D false; + irq->hwintid =3D 0; + } } } =20 --=20 2.34.1