From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2064.outbound.protection.outlook.com [40.107.220.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97FC32E7F3A; Wed, 13 Aug 2025 15:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.64 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755097423; cv=fail; b=RFWWMevkqXwDkN5gFSrS5h4I39trE+sal2iZXhFQ39dxGIefHvq35M4kevsSuqg5fntsV3RVLjllYB8JrrH24MwY2lHDMSiifXvRD62ZO1947zM/jz07Vxc+80JjRgwq+7pdCq50lX5uhb3qb86wIvVlGJ0w48lBz7PcMWkniV4= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755097423; c=relaxed/simple; bh=jNoRVs1nlAcR4stQl4l1uQYO3oyYGz71E22zeQ9fckU=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=FeNl5GpwMuy9KuVusJNE5kC0L6Rwt8nVSpjBmDhpc/w+y/ZJBDMwmkZY8mOdhTIRko4orEWp6DHmC3nBPGHBQjz04BCWCIt3MZ0v1iSJwwrznU1zMwCVUcuCp4ecOYyrmPySXBmzcMIi2BGoAG1KC3Umtc5xaMcsVcFhd4F5ynY= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=py+VIA2I; arc=fail smtp.client-ip=40.107.220.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="py+VIA2I" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qcPt3LjFUgL5sInauuz86Coww4uSJ64ZeGfmP7j/wGAXupyDxREFppM9z6QC0KUcpc4/HsBXvP9o8qJ9H9mNdDW3QwT4ljC6JzyJXzdmNq18wQKfK809zJ/OtOKGcBJB9rilp6LK4irym8/FobbDuEsG4mQM2pmOwH+2bsqKfAURkk08dsK64JFD7qnbj7wkYathBEpzg+N04GnS/VIEWWhzZ8THmiM1VdT2lTs3DGb9osHXk0xaiVGWNi7Ac9YGdoZPKoeTYsvyRcNLAJvadLSzf/CF0/xXLCQs9G8JfOKY08O2TfsOReKpYmsqBSDFlASuetugD+PtQoyWO6+yfA== 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=fbXIz+dpf07LB8Lps4BsCGr7J8+XyURVjsYYM66Yg1Y=; b=WayCJ5Vyv1Gc4z/M1yktRmM5RRMEQse2enL59vlTX0XP2VjPrNT0gAwVoYp1uYXd24/oyp9viVYg7uuBq330wBbv1pRglUcpIuhiOSaCaeDdxVZkzcIH18oebMafVyt96cLZNMC+aKmkx032lTCJSWm53zoN/wkbFABkRsI1NG0Aw6JZwUiEMxZIwU+J3+pJnIUl90NJFR9brEF34oeP1aWkHQzJ6JEQQw7K0sD74PH4dOctqWlpSmT3ncXDtYE94XcEBlz5YdgFQQ8Ob0ccBtE91bonxHQovZH35d544PQrI5/nHCB1dMshUUM0T39p9qYm0LW71bYl3sz9730TgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=fbXIz+dpf07LB8Lps4BsCGr7J8+XyURVjsYYM66Yg1Y=; b=py+VIA2ICXxTSJ8YMzZAZmBbBfUBJrgcotpgG2oxqyZrqbTJJ9GoqiBMcEFayUUG6Etalbchh8ViWxMdGy18CDYKRulRtsQhZKgi5uZrZebdRDtymvbHTUV1Ir/1DEcOds1o3so3nBNspm06gL92oHls255zW4TEnBmgZKoPtak= Received: from MN0P221CA0013.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:52a::18) by DM4PR12MB6663.namprd12.prod.outlook.com (2603:10b6:8:8f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9031.13; Wed, 13 Aug 2025 15:03:38 +0000 Received: from BL6PEPF00022574.namprd02.prod.outlook.com (2603:10b6:208:52a:cafe::c4) by MN0P221CA0013.outlook.office365.com (2603:10b6:208:52a::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9031.15 via Frontend Transport; Wed, 13 Aug 2025 15:03:38 +0000 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 (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 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF00022574.mail.protection.outlook.com (10.167.249.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.9031.11 via Frontend Transport; Wed, 13 Aug 2025 15:03:38 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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.39; Wed, 13 Aug 2025 10:03:34 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 13 Aug 2025 10:03:34 -0500 Received: from [172.23.255.54] (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 13 Aug 2025 10:03:32 -0500 Message-ID: Date: Wed, 13 Aug 2025 11:03:28 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] xen/events: Fix Global and Domain VIRQ tracking To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Chris Wright , "Jeremy Fitzhardinge" CC: , , References: <20250812190041.23276-1-jason.andryuk@amd.com> Content-Language: en-US From: Jason Andryuk In-Reply-To: <20250812190041.23276-1-jason.andryuk@amd.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: None (SATLEXMB05.amd.com: jason.andryuk@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00022574:EE_|DM4PR12MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: ba4759dc-dea8-49be-b56e-08ddda7a9579 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700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pV?= =?utf-8?B?bXpOWDVoRnRWalNSbzI2aU81T2NEQmdxd3RuSDBkWWNOcTR6Si9lbG9xdTB4?= =?utf-8?B?WXU3dU5jUi8zSDB3eVpkcHdGaDZzTjZMb2k1WXFrSmdTNXNlU2ZrcllpaWdL?= =?utf-8?B?REVZZVhYRnFFMVRzdlpFdlVPNlc1enQwcWJFbGZ3ZE0zd0Z1YTNkNnVnWEc2?= =?utf-8?B?b1d1U1hpWXZxcXF6RU5CWVZCRmN6WGZwR0RKMUVXTGJibHIzVFlhclV1cStC?= =?utf-8?B?amR0RVY5S1BwNWF4MU9hMU5nUTZkbmgxUFc3ZFdWQUVsM2hidHAzUTVtaVAx?= =?utf-8?Q?d+ru2D?= 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:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2025 15:03:38.4675 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba4759dc-dea8-49be-b56e-08ddda7a9579 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: BL6PEPF00022574.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6663 On 2025-08-12 15:00, Jason Andryuk wrote: > VIRQs come in 3 flavors, per-VPU, per-domain, and global. The existing > tracking of VIRQs is handled by per-cpu variables virq_to_irq. > > The issue is that bind_virq_to_irq() sets the per_cpu virq_to_irq at > registration time - typically CPU 0. Later, the interrupt can migrate, > and info->cpu is updated. When calling unbind_from_irq(), the per-cpu > virq_to_irq is cleared for a different cpu. If bind_virq_to_irq() is > called again with CPU 0, the stale irq is returned. > > Change the virq_to_irq tracking to use CPU 0 for per-domain and global > VIRQs. As there can be at most one of each, there is no need for > per-vcpu tracking. Also, per-domain and global VIRQs need to be > registered on CPU 0 and can later move, so this matches the expectation. > > Fixes: e46cdb66c8fc ("xen: event channels") > Cc: stable@vger.kernel.org > Signed-off-by: Jason Andryuk > --- > Fixes is the introduction of the virq_to_irq per-cpu array. > > This was found with the out-of-tree argo driver during suspend/resume. > On suspend, the per-domain VIRQ_ARGO is unbound. On resume, the driver > attempts to bind VIRQ_ARGO. The stale irq is returned, but the > WARN_ON(info == NULL || info->type != IRQT_VIRQ) in bind_virq_to_irq() > triggers for NULL info. The bind fails and execution continues with the > driver trying to clean up by unbinding. This eventually faults over the > NULL info. > --- > drivers/xen/events/events_base.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c > index 41309d38f78c..a27e4d7f061e 100644 > --- a/drivers/xen/events/events_base.c > +++ b/drivers/xen/events/events_base.c > @@ -159,7 +159,19 @@ static DEFINE_MUTEX(irq_mapping_update_lock); > > static LIST_HEAD(xen_irq_list_head); > > -/* IRQ <-> VIRQ mapping. */ > +static bool is_per_vcpu_virq(int virq) { > + switch (virq) { > + case VIRQ_TIMER: > + case VIRQ_DEBUG: > + case VIRQ_XENOPROF: > + case VIRQ_XENPMU: > + return true; > + default: > + return false; > + } > +} > + > +/* IRQ <-> VIRQ mapping. Global/Domain virqs are tracked in cpu 0. */ > static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1}; > > /* IRQ <-> IPI mapping */ > @@ -974,6 +986,9 @@ static void __unbind_from_irq(struct irq_info *info, unsigned int irq) > > switch (info->type) { > case IRQT_VIRQ: > + if (!is_per_vcpu_virq(virq_from_irq(info))) > + cpu = 0; > + > per_cpu(virq_to_irq, cpu)[virq_from_irq(info)] = -1; > break; > case IRQT_IPI: Thinking about it a little more, bind_virq_to_irq() should ensure cpu == 0 for per-domain and global VIRQs to ensure the property holds. Also virq_to_irq accesses should go through wrappers to ensure all accesses are handled consistently. I'll send a v2. Regards, Jason