From patchwork Thu Apr 21 13:21:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 12821624 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 BBEDDC433FE for ; Thu, 21 Apr 2022 13:22:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.310183.526915 (Exim 4.92) (envelope-from ) id 1nhWlJ-0007vo-5C; Thu, 21 Apr 2022 13:22:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 310183.526915; Thu, 21 Apr 2022 13:22:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nhWlJ-0007vH-1H; Thu, 21 Apr 2022 13:22:21 +0000 Received: by outflank-mailman (input) for mailman id 310183; Thu, 21 Apr 2022 13:22:19 +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 1nhWlH-0005Gk-Dy for xen-devel@lists.xenproject.org; Thu, 21 Apr 2022 13:22:19 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0f2121c8-c176-11ec-8fc2-03012f2f19d4; Thu, 21 Apr 2022 15:22:16 +0200 (CEST) Received: from mail-dm6nam11lp2171.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.171]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 Apr 2022 09:22:15 -0400 Received: from DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) by DM6PR03MB3771.namprd03.prod.outlook.com (2603:10b6:5:4e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Thu, 21 Apr 2022 13:22:14 +0000 Received: from DS7PR03MB5608.namprd03.prod.outlook.com ([fe80::5df3:95ce:4dfd:134e]) by DS7PR03MB5608.namprd03.prod.outlook.com ([fe80::5df3:95ce:4dfd:134e%4]) with mapi id 15.20.5186.015; Thu, 21 Apr 2022 13:22:14 +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: 0f2121c8-c176-11ec-8fc2-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1650547337; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=t8julXlOoNYBqtFkpFb4nXUExQj90ge4lQC5Ly84gfg=; b=iXyEyQpdNrYDBFd5bP+PqsHVIvCoO3V2lWChOmOpZ8fAy3SdcBq7HUJk GmlVtWQE/LsVo1SUclYWnagLwXCtnzMCmDxeQ8+iU1ycGffgwuXl4WW9I e7FTiSGJrdYqNKLIePmKsLa7tA8Pl6vZYFeE7CcU5VqdZjQZ89x7+1Uvg E=; X-IronPort-RemoteIP: 104.47.57.171 X-IronPort-MID: 69007273 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:QYDs6qsTWUENs+y4/n18U5bdb+fnVCJfMUV32f8akzHdYApBsoF/q tZmKT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6mt jFpBkte+x19nPqZ2mw5SDg3gHxuQxen0PK+Bu9uz/OsMb5TDU1B45qnoRCaCbU7EImoZVVzL 9L93jxjesZMTrw2ADGo/TYXRBjkUS55VA4l/QIsnBZWYwCLJdMsI0k+l9PGptoJlO31GkeKp guMCjg3ocXTbvDBEqp/VWHgebcE0jbJy32DHTr4aeuonprdHMQ9Tps+CVQpAZEyHsHceg02w 31CNUXqFhwdL5nUUsEPpZmfSKWMB27ffueChPlHbzYfJt3SE7lmtrQ3Igfwt2MVdgh8KYS8a 6xIm+w81RCMX7TNQ== X-IronPort-AV: E=Sophos;i="5.90,278,1643691600"; d="scan'208";a="69007273" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lX2SthwrUQ/YIADe5wZ0yXXTWPCtgLF1RH2dAeo+TITMiwhQPE7y0Obm/vp5otIPpfVvrEnr7Fq2A/S3tHYav6f6s9j7kWkq2S/wTvhP1PSXvD5o2o1vbQW3TCrRux+Mol4i0d6IUhp7Nn+/3UAgvHEdpUmoX94xzFm1/EPIOqHMZwzIQ87sFaymIslg7CFo8PF8PqvuYKOp+0/zvhDFos7yDaY9KctbKMeJ8yisJLQ94rB25S4P8joGCN6ZLjjMP+vtJwgkv/kNnToI1qfe553GBcri6ILZmIN/Xj0nwTO14FvAZLvU8QrsaeSkQo6Jz5ZLJsqmTcyGfHotbo1T5w== 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=726ON294pXNt7c/3gsJ1Z+Ba/nN1vU6Da+G2qEPvwDg=; b=InHwxIemJPfVUmwg1QUudFLEgbO9AyoQoBY3PX21CtPT6J+KU9jvl+cYovnfIY4o8raD6Xwc0MRgma/+rJNPuzQrwwGBhDHPSilY8wbci+LN73/FUWGUimLaYdA5EDDjblBiHNbjA5N2SlRdRJI1r1jA1ayuqpN3ZCHfK8EuSvy0yIuORkZRbb6U+6P8mgJiN4gw1im2Q4gjMP0I0StEBQNCh3TXooi3r9q6vR+TMqliXaW51poqlmHuHL51tGBeTkfLX/pbbQJzJDP+KE6gBoEwBimAYFHcu/5Bozcz081wFMl8hGHF1dIAjrRtaNUInHdlK872LXGRfLm8ITxwSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=726ON294pXNt7c/3gsJ1Z+Ba/nN1vU6Da+G2qEPvwDg=; b=ep2ptWBSGhvmUNG5k//D2107BLtD80ac7BUM+4w97PyJfz3aW+QDL07vPJhqCvgGpZa4eyp1fURp4gd5VJkHi//jo7UTHP6kVUVDD0uMoY0NyUuW6aQPOxJKHHhRhO8val9F+zYpqcXhT/CKk+7ZSnngWlesaStgCIfmGRmoGao= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH RFC 6/6] x86/ioapic: mask entry while updating Date: Thu, 21 Apr 2022 15:21:14 +0200 Message-Id: <20220421132114.35118-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220421132114.35118-1-roger.pau@citrix.com> References: <20220421132114.35118-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0143.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::35) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3b82e05-6ed6-4f41-b84f-08da2399f2fc X-MS-TrafficTypeDiagnostic: DM6PR03MB3771:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hReYVgCXeBfLRRYWkepBFYpuFUQA0kEkR8OeIulKXfFr8KAxEeZDe84BDIa2xFck/FjPS2JcF6oGhJTvSDIqoILtZaTOeyMu4uW8l9TDCbOR7Vk+d4lyPlKyBN1utjWsSkktIj/LNxnxBKwbj83rTZ22qIrg2yr8OKTL1PNOOWensgvM5CmWP/+jnYKRtDt/YlMFEvuYbvsN2Gpn1LqZOV4o+FEV0v3+9T8sLbMqyXsqDWnfJKcKxC86A97ubZv/sre85ma40PKZNrW9bIgEajnBS1KMZ9OgiWAyS6EQs7ylGW7Vi3XfE5ZuDFFwH27aqPOV+iuz2mm2ITm71ryVZx5jRW3mFHhSv/470pY17TAO3+/0qjPca1bjI4yK5XbgQFZRVje8/lTbPNcYX0WRvyWwUbyXNRRy8+HqceAJy4NxP+BBf/1YG2R+CZX9NRIm6855MZR/yGAgGi8k9FzPinbOjPmqR/PKhyxaZ2FDeoQNCvLhG2y24JKXDxGIzvFj45qPihRlTIXLSRHQTvQfpb59zu5gBgPVqnNzKQUvA3KpaHR+8WFXREVYX5t8Pod26kz1PJJ6YCqUFuDuNaPMwoTz1Bkvq1gUlnCTaWyHaG+WQx1VDeit4o8ODSDNuxsZl7+2V4iQuURWEFroULXKRw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(82960400001)(316002)(186003)(2616005)(26005)(5660300002)(83380400001)(2906002)(6512007)(4326008)(8936002)(66556008)(6506007)(86362001)(66476007)(38100700002)(1076003)(8676002)(508600001)(54906003)(6486002)(66946007)(6916009)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?GxAQFKptwVGIuY+wWmwUjdDWStqT?= =?utf-8?q?jhuf6VwhZAXIzxXBP2bBBMecBVvBgZIA1pk5pwq0utpTRUgAkQgSMbY1rssnQLVei?= =?utf-8?q?3b9RJrsSNVHdA1Vw9PShVtfXz3C5bitBGLeoZQ8Fq+DfGaKglNFYNVah4mwsI+ehA?= =?utf-8?q?gOkO11UIgCooPFJtTW4N2tCYZuS0pn7eO3yy3SHvLQ5OJhulyj7plcnLxesYz0FWK?= =?utf-8?q?6rLQWuOmzcxMIYYiDBxeIUVL1KMkWlAvobT+z3I6QRdaJr6QyC8iJcYLhI1xyvDFo?= =?utf-8?q?k8G83sSipLY5JaS+AivhGCLHFt81VotikZXkSCV9xyThy5W4E9vsRw8xYobgD6dR0?= =?utf-8?q?Bp2ScpXn0TfzUF+1izrKfHM4KtWieKDtJYW88ePs3wOCq/hmIX1FD9GVcwpYsXMc3?= =?utf-8?q?/hEE4FvZunQ6hSJJw53CU7vn0xgm7Tqml+j0viKk1NcyXzJ1VCXLlA06h8UaJh6N8?= =?utf-8?q?lSw7JiH9e061hfoec681/HilqcLo3Q8YUZzXahfJb+ml6BzCUCSlXRqAc+NOTkIih?= =?utf-8?q?x6136osxH/qmTS6/XvOktZ1BQ7CA7BcC4rb9poKiKImIyRY50+nDHFuJBcoVpfpuW?= =?utf-8?q?0gDqCf8Q0VwpsyOmnkWAuRMbgW/ykyZUhOj4H8nsC4B/UwNibn196wD9logxP5G6w?= =?utf-8?q?dJCiMq3MGrRNhNx+j2NuYzaioAkzBDTZ6cZllfokEv9dxZns3XaTmR5e07DtAy7OY?= =?utf-8?q?qkLeRpTEs1yP0Rx90ztTaJnSzalzxK2aRIHAlKRhC2RyDQrj41JucLR/K4zv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Xm+?= =?utf-8?q?9yW3thGXHE9Wz0mMMRIkuDyG4+R1tbb8SwFXq1qKGap5XWuJLf5l8=3D?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3b82e05-6ed6-4f41-b84f-08da2399f2fc X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2022 13:22:14.2150 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zQ5bns9muO1JXf/NhXYQKgslld6veYOsM7kUW+GBE2FqKgDAsjBzyxt+hP523r7+JL8rqd9RCJxOVo87hOxvGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB3771 When writing an IO-APIC RTE entry make sure incoming interrupts never see a partially updated entry, by masking the pin while doing the update when necessary. Add some logic to attempt to limit the number of writes. With the masking now handled by __ioapic_write_entry itself when necessary, we can drop the setting of the disable hook for IO-APIC edge triggered interrupts. Signed-off-by: Roger Pau Monné --- Note this includes a revert of the first patch in the series. --- xen/arch/x86/io_apic.c | 45 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index f61e56f3d1..1860af7353 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -267,12 +267,47 @@ void __ioapic_write_entry( unsigned int apic, unsigned int pin, bool raw, struct IO_APIC_route_entry e) { - union entry_union eu = { .entry = e }; - if ( raw || !iommu_intremap ) { - __io_apic_write(apic, 0x11 + 2 * pin, eu.w2); - __io_apic_write(apic, 0x10 + 2 * pin, eu.w1); + union entry_union eu = { .entry = e }; + union entry_union curr = { + .entry = __ioapic_read_entry(apic, pin, true), + }; + bool masked = true; + + if ( curr.entry.mask ) + { + /* + * If pin is currently masked we can update the high part first + * without worrying about the RTE being in an inconsistent state. + */ + if ( curr.w2 != eu.w2 ) + __io_apic_write(apic, 0x11 + 2 * pin, eu.w2); + if ( curr.w1 != eu.w1 ) + __io_apic_write(apic, 0x10 + 2 * pin, eu.w1); + return; + } + + if ( curr.w1 != eu.w1 && curr.w2 != eu.w2 && !eu.entry.mask ) + { + /* + * If updating both halves mask the entry while updating so + * interrupts are not injected with an inconsistent RTE. + */ + eu.entry.mask = 1; + masked = false; + } + + if ( curr.w1 != eu.w1 ) + __io_apic_write(apic, 0x10 + 2 * pin, eu.w1); + if ( curr.w2 != eu.w2 ) + __io_apic_write(apic, 0x11 + 2 * pin, eu.w2); + + if ( !masked ) + { + eu.entry.mask = 0; + __io_apic_write(apic, 0x10 + 2 * pin, eu.w1); + } } else iommu_update_ire_from_apic(apic, pin, e.raw); @@ -1780,7 +1815,7 @@ static hw_irq_controller ioapic_edge_type = { .startup = startup_edge_ioapic_irq, .shutdown = irq_shutdown_none, .enable = unmask_IO_APIC_irq, - .disable = mask_IO_APIC_irq, + .disable = irq_disable_none, .ack = ack_edge_ioapic_irq, .set_affinity = set_ioapic_affinity_irq, };