From patchwork Wed Mar 31 10:32:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6AECC433C1 for ; Wed, 31 Mar 2021 10:36:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2BDF461582 for ; Wed, 31 Mar 2021 10:36:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BDF461582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103841.198067 (Exim 4.92) (envelope-from ) id 1lRYCu-0004vo-8D; Wed, 31 Mar 2021 10:36:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103841.198067; Wed, 31 Mar 2021 10:36: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 1lRYCu-0004ve-3y; Wed, 31 Mar 2021 10:36:16 +0000 Received: by outflank-mailman (input) for mailman id 103841; Wed, 31 Mar 2021 10:36:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCs-0004un-Gm for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:14 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 708e5ba8-4afb-4791-94a4-f598a6585d17; Wed, 31 Mar 2021 10:36:13 +0000 (UTC) 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: 708e5ba8-4afb-4791-94a4-f598a6585d17 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186972; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=BZyxwqwyKCBvk+CFEEPMfCfivieAaaU9nS1MxnsMyOk=; b=anUu9mHhbDqO7K2cjT5JUqp7AMREM17mju5grLFBe+qMiuELHJI4JjM/ YlLGo+Kayp+3uExbeVjSuhXLV+2uOdfPjyCxYVPDIpXsYCQ5vAt6XZm/0 4zZs8RkmbQFJbo60xO2exgi0eifEOLBxWFmMrcJxubAs2JEm33OkRp9xd I=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 7sweMx5zWJWaAZNnY8I3TtLQCrhCvt5dyYhSWNsHIcX7mNhRYJVlxKxRgWU3iQD6bGTKdMw74D 7Y2rt241g3zBMKcr45pqAnzpmYPbZO/rN77CWnLE3dXrV2eo6knASSLCNHgfeJNILDYLhKban7 0B3p54OROfNl6fSKuQ89IJnwQLZvJ9BIRckSmJ+iIiM256oMZBRFDDPgEdQI3rfq1l7Stbomas ffpeuIlarle2akh6b2GihexNZ0ybHLjmaj0DfIsBLRIrQYr9wnYo4mD1ySey5FvXIRm4PhXZIa bII= X-SBRS: 5.2 X-MesageID: 40415665 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:EBtb1K3DTN0tXw2AbsaiQAqjBTd3eYIsi2QD101hICF9Wvez0+ izgfUW0gL1gj4NWHcm3euNIrWEXGm0z/FIyKErF/OHUBP9sGWlaLtj44zr3iH6F0TFmtJ1/Z xLN5JzANiYNzVHpO7n/Qi1FMshytGb8KauwdzT1WtpUBsCUcBdxi1SYzzrdnFebg9AGJY/Cd 6g/cJBvTWtYjA6ac68C3kDUYH41qH2vbjhZgMLAANi1RmWgVqTmcPHOjW7/jNbaTNAxr8+7X PI+jaW2oyPu+y2oyWssVP7wI9RnLLau7l+LeyKzvMYMzD9zjuvDb4RIIGqmBAQjKWR5E0xkN /Kyi1QT/hbz3/KZGm6rV/M9mDboU8TwkTvw1OZnnfvyPaRLFlRa7sj9PBkWyDU5EY6sNZ33L gj5RPii7NtAQ7dhyO43tDUVnhR5zuJiEA/mu0ehWE3a/p4VJZtq+UkjSZoOaZFNif75Ic7Kf JpHcHR6d1HGGnqEUzxjy1BxsehUW80GQrDak8eutaN2zwTp3xhyVAErfZv0ksoxdYYcd1p9u 7EOqNnmPVnSdIXV7t0AKMkTdGsAmLAbBrQOAupUBvaPZBCH0iIh4/84b0z6u3vUocP1oEOlJ PIV04dnXIuemr1YPf+nKFjw1ToeiGQTD7twsZR69xSobvnXofmNiWFVRQHj9agmfMCGcfWMs zDea5+MrvGFy/DCIxJ1wrxV915Mn8FSvAYvd49RhagucTOBor2tvHKUfraKbb3eAxUGF/XMz 8mZnzeNc9A5kekVjvTmx7KQU7gfUT54NZRHcHhjq0u4blIErcJnhkeiFy/6M3OAyZFqLYKcE x3J66itqu6oGKx7FvZ9mkBAGsYMm9lpJHbF19arw4DNE35NZwZvc+ERGxU1HybYjhyUt3RCw wag1hs46q4I9ixyEkZepyaG1Pfq0FWiGOBTp8alKHGz9ziYIkEApEvX7E0Mx7KGRxzkQNDs3 xCdwcAe0/aGlrV+OaYpa1RINuaW8h3gQ+tL8IRg2nYr1+gqcYmQWZeYySjSveNgQElRyNdg3 p496N3usvGpR+fbU8ExMgoOlxFb2qaRJZLFh6Maolvlrf3Qw1oVmuRiTuGixY8R3ry+ywp9x /cBBzRXcuOLktWu3he3Kqvyl9ye2mHV29ba3xxs+RGZC/7k0c29dXOSru40mOXZFdH//oUNy vdZyAOZil0wcqs6RKTkDGeNHkvy5k0JNbBBLA7f7y74ALqFKS40YU9W9NE9pdsM97j9tIRWe WEYgmPMXfWDfgq1wH9nAdSBABE7F0f1dXm1x3u4DLmgDoRAf/OLE9nQL9eCdeG9GTgT+uJ1p I8rd9dh5rFDkzBLvq9jYfQZHp/DzmWh0icZeQhs4pVsqI/r6EbJeiSbRL4kFV8mCwjJ8L1nn 4ESKt14Lr9KpZiFvZiDh5xzx4MrpCzN0MlvQz9P/8mcXwsh3HdOcmV47Cgk8tZPmSx4C/5OV yS6ERmjo/4dhrG8b4REKQrJ2tKLGA69XR55euHHregQjmCRqVm/FCgNGW6f6IYYK+ZGa8Iph I/x92TheeYe27Z3w/X1AELb55mwiKCQcmoBhiLFvMN29umOU6Uiq/v2fWNtl7MOHKGQnVdo5 ZEe0wWZtlCjTdnrLRf6FnMdoXH5mQ/k1Vf5jl7kEXKwYbO2haDIX17 X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40415665" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nt3GhNGopzsE2YzTerzZrxwAENTHZOA2BtwDyIC13GHI8g6UneOeJXM83D/uLGATlRC0wJqHXDZWeQIWIL1fLLngqTxWGhephZNQWrcMpdLehv7NDFd+Si4kQJKuAGjN9oS1XRxULMM/nWTnt6eZ7Bgviyxpbk4rq/L8P6+5N9bNWtLpkOvoB3QFwZSoOlfF4K8CcYg6dkOAvsHsFOctDhUMakiHcjV/JYBoMO1goxCuWQl2xP1U5T1A4BhoJMrbzBuvU6lweKXy11m3I++X7s+Kb/bP7eCr4O/twSg2lyDGUQhrX4BJfQm4U3w8sQcKdg9H6wNubDRn0jQ++RBi4Q== 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-SenderADCheck; bh=YbLS6BH8MbuCXwxN5xjKUX6UwKmNt7gnMdLP8UFuW2Y=; b=G8Tgtvm72k9EzMB5hH2xb/QvQqmjaG40JxAoQtpeyq6vOjELydrqhjF07xLDLUlVkUWkTJ5uz9UNwhI6FQMGsLGj1x9JDWf6J9n2K/KSFFBZ1CVHfguM450CqmNnxasGh0RtaVwYdswZ88et0g10+D1FnELdPvjZyG3JG+SYMkeCq30vR8slfU+1eTzLrQ6rfudVNQmPy1XjBQ0/LL1trftJrFhcx/PfcQdekz+Tj3ag9xyTYPvp528s0LFeykB0N4OF3ncJNYihDaOipzuP3tzk5NhYR/g5upBO3Od1Jz/y1dmafC/moqyXu/3QYu4GM2a9x5zI9vwLSgnIZJP9yg== 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=YbLS6BH8MbuCXwxN5xjKUX6UwKmNt7gnMdLP8UFuW2Y=; b=KEKsVdkyKlVa/Q+s8RzEVvve8vqeAKcPkP8yiGIFTFT6VswAkiX2God7WCHd5S2kQOsBZJrhEnjYNP3+wsctiihkIArWAPRjFel1a9/r4JJ6jwxPOYgQbWY+PVNyu0IjbFcycghLhCa8sW6picM5IGik1ALDVqGYSc7Yi9OheJ8= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 05/11] x86/vioapic: switch to use the EOI callback mechanism Date: Wed, 31 Mar 2021 12:32:57 +0200 Message-ID: <20210331103303.79705-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0163.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::26) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a8063ccd-c7ae-4def-a92f-08d8f430c94c X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /FFoXPnFQtGk3HaQwqeNi3TMIhhfxrj3infJ+2yDmaEOrXF+plMov929zYxyWtUU423JsZL8YDUbjMtLrttS1ikOYJUSQX9CufkYu1wfD482gIdOxm+k9sGZswZ6dClfl6+Cdy78GLyLEivg3vbhSwgUd2wt4RLuMyBwxnRVuvpc1ZGDWscWrqEjyzEsuoBdBqGJbbm1tiHEJi/rXPJ6F6s2SW3IaAqAD4dvwr4LCPLqjfXrkcAlM2ez70AZubdumVqGF9AGj7CSuPyDPRovTV4hn87Dg1hrzXj/xVHQ7j/17HPyYh1kPu6tD8GtpaaCUPmTas22LqGh80NamRVxCD3l6yKqHnPSoU9xbUCyDpY7ug8TGpUiTlStIAQsATXCC0VGIBTh2cwmkhmVi9ulMOxJR/uSkIUfV/HZZ6glbqq37A2ym5iUhuaniMsnMAsAza/mGABs873wJCnAbn2xaAPqfLNshRNUQn6Tu3E60RkmNFoYwGS/i0VxboH/B1lVXbi9+nQKx8xL2VYxv/yFIGUdZJb9zTzwRCvsiakYmfKb27LYx5esXShzRIqZ4CJQSw2UUZqRU5lg3hCnQYMnd/46RCGivqS+0enOkO5Mq+pC0tVtts5uMQaVYVS3WsFWqiEu66jHoMRE5p0dIKsm4dl5qq4sqwno8NEsOFz4yx6YH5a7kGc60TQpjY9hPIeH 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:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?DZGvpClnu02zLEkJP7u9mmmCx1QuNj?= =?utf-8?q?QlYdWQ0LU9WYXDxxsBUlD1rgMzJTQxv9t0UYa8Yzyuv4NH6kxjc6aZ3mFc9DOB3nW?= =?utf-8?q?V+FqViO5xtSjzIpaFrxuJ7Wiuwvp3vNivG39n0evD97iW/eJ7sMdO4DvKj9fRa6Hl?= =?utf-8?q?ZvOrOteR5wbyys6XfVFdfaZ+ljQvdJEoC9NSOPWIlI1ICHZH4JYHV3Ir88GFsGQUY?= =?utf-8?q?Fsyxg4L5dItzhenLfPt0IpB5Os76Mw6QokYIoqkviw485FOW5SXkEaYgQ9ppLaSUu?= =?utf-8?q?BGCWiBmZLFRXcnVQ8xb30bcCUt//t8lTCzcI8+tTyBBO9V2l256T4MF6/VpEb4jN+?= =?utf-8?q?QpqAbTaXvFpKyYFqgGCOHPaXColDBf7Yg4327sVjZBcarsjBBLxiuG0Jw3uRF106a?= =?utf-8?q?4GYxboqRFlJtiFc45cwgqmaLCF+Qk1D1Yh7tTr+6DbTXT4ug8rVvFPF23ih7A488k?= =?utf-8?q?wkMco910So+tRDjlB4CvPLcIcSsUdotT9yFP7u4AusfCp/xG4CLW8LXA2wkDL7PS9?= =?utf-8?q?S6aqIEKDEQ5V3t4vn3R6ZtvfimGOm77Q9o4MePsPRjLyQd74jL99tDb/yJwIniPZS?= =?utf-8?q?BkW7r160S5Ida/qgT5bYRKWvPEYcV8CCz7DLGkUFvFeQs8Hnzxxb2UqMD9zLDkugG?= =?utf-8?q?Wlomnk6sMBm/ToDxGsHtWTupfiEiKDiaoVwz535e+hbSSR4rjeuEcd2TUNQ93E33i?= =?utf-8?q?CSOGBhf2SbFyHGxJusOmGsbAYM2dG5fn5iVCojYThGwvMSfC39BVfgkn8Q/cE+gKr?= =?utf-8?q?izXlfiW9rj6nfpbGRrazvEDBFFhWiFj8qD4EhtNQpjvVexvs2UzPC2mEpl/qgT90Y?= =?utf-8?q?SsLWEucSJrLqW0ejn1RUzOdQ3645+m/N6x7gXw91zK7SZ6m9/Eu68l+afwUfqZtew?= =?utf-8?q?CcASLQlpHdFspz8hEU2GUHIqCUSKN2OY6oIhvQWIg1H9kkuB5i/kEMceh+7b86so7?= =?utf-8?q?OGwCLCy0y/uKMaSiE5kJdykUOjfKGeR6Hr558vop2CwiYJWOytVJOiCf0PM+j0QMh?= =?utf-8?q?dPcKPeRWjmjNioq1bc1rgxH+Ry4J+5c1/C84yySWl2GWzlWhMpEqQUqSDThvEREbH?= =?utf-8?q?mNznvbGsRXSX86xC5ZQ6Qh3IK89Db8P+R+LI7+qBqmunXDrDGAVDAUarc505ji6V8?= =?utf-8?q?21IR2eut6nO/8HCTaRLwxZk6zkf7D3+AvF0jHDAaCgzEBCXyp/jo01Uq+fQf1Q36j?= =?utf-8?q?V/lwDYeR/TP02/FOLVmomnqqzDLY+Uwh8iEmJKYMfBrFuB/atB95mQZWMzdx+OtJ9?= =?utf-8?q?SQEyWerXsdy3rZ?= X-MS-Exchange-CrossTenant-Network-Message-Id: a8063ccd-c7ae-4def-a92f-08d8f430c94c X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:04.6593 (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: bWaxEIV5pDDpgahkbuy9zCxae3GNfBE9cDuQjcyBJeNdzTb9Nx53g8mynf5xb8FaYUIvreKXi3l80ZddvRAKPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Switch the emulated IO-APIC code to use the local APIC EOI callback mechanism. This allows to remove the last hardcoded callback from vlapic_handle_EOI. Removing the hardcoded vIO-APIC callback also allows to getting rid of setting the EOI exit bitmap based on the triggering mode, as now all users that require an EOI action use the newly introduced callback mechanism. Move and rename the vioapic_update_EOI now that it can be made static. Signed-off-by: Roger Pau Monné --- Changes since v2: - Explicitly convert the last alternative_vcall parameter to a boolean in vlapic_set_irq_callback. Changes since v1: - Remove the triggering check in the update_eoi_exit_bitmap call. - Register the vlapic callbacks when loading the vIO-APIC state. - Reduce scope of ent. --- xen/arch/x86/hvm/vioapic.c | 131 ++++++++++++++++++++++++------------- xen/arch/x86/hvm/vlapic.c | 11 ++-- 2 files changed, 92 insertions(+), 50 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index dcc2de76489..d29b6bfdb7d 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -394,6 +394,50 @@ static const struct hvm_mmio_ops vioapic_mmio_ops = { .write = vioapic_write }; +static void eoi_callback(unsigned int vector, void *data) +{ + struct domain *d = current->domain; + struct hvm_irq *hvm_irq = hvm_domain_irq(d); + unsigned int i; + + ASSERT(has_vioapic(d)); + + spin_lock(&d->arch.hvm.irq_lock); + + for ( i = 0; i < d->arch.hvm.nr_vioapics; i++ ) + { + struct hvm_vioapic *vioapic = domain_vioapic(d, i); + unsigned int pin; + + for ( pin = 0; pin < vioapic->nr_pins; pin++ ) + { + union vioapic_redir_entry *ent = &vioapic->redirtbl[pin]; + + if ( ent->fields.vector != vector ) + continue; + + ent->fields.remote_irr = 0; + + if ( is_iommu_enabled(d) ) + { + spin_unlock(&d->arch.hvm.irq_lock); + hvm_dpci_eoi(vioapic->base_gsi + pin); + spin_lock(&d->arch.hvm.irq_lock); + } + + if ( (ent->fields.trig_mode == VIOAPIC_LEVEL_TRIG) && + !ent->fields.mask && !ent->fields.remote_irr && + hvm_irq->gsi_assert_count[vioapic->base_gsi + pin] ) + { + ent->fields.remote_irr = 1; + vioapic_deliver(vioapic, pin); + } + } + } + + spin_unlock(&d->arch.hvm.irq_lock); +} + static void ioapic_inj_irq( struct hvm_vioapic *vioapic, struct vlapic *target, @@ -407,7 +451,8 @@ static void ioapic_inj_irq( ASSERT((delivery_mode == dest_Fixed) || (delivery_mode == dest_LowestPrio)); - vlapic_set_irq(target, vector, trig_mode); + vlapic_set_irq_callback(target, vector, trig_mode, + trig_mode ? eoi_callback : NULL, NULL); } static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) @@ -514,50 +559,6 @@ void vioapic_irq_positive_edge(struct domain *d, unsigned int irq) } } -void vioapic_update_EOI(unsigned int vector) -{ - struct domain *d = current->domain; - struct hvm_irq *hvm_irq = hvm_domain_irq(d); - union vioapic_redir_entry *ent; - unsigned int i; - - ASSERT(has_vioapic(d)); - - spin_lock(&d->arch.hvm.irq_lock); - - for ( i = 0; i < d->arch.hvm.nr_vioapics; i++ ) - { - struct hvm_vioapic *vioapic = domain_vioapic(d, i); - unsigned int pin; - - for ( pin = 0; pin < vioapic->nr_pins; pin++ ) - { - ent = &vioapic->redirtbl[pin]; - if ( ent->fields.vector != vector ) - continue; - - ent->fields.remote_irr = 0; - - if ( is_iommu_enabled(d) ) - { - spin_unlock(&d->arch.hvm.irq_lock); - hvm_dpci_eoi(vioapic->base_gsi + pin); - spin_lock(&d->arch.hvm.irq_lock); - } - - if ( (ent->fields.trig_mode == VIOAPIC_LEVEL_TRIG) && - !ent->fields.mask && !ent->fields.remote_irr && - hvm_irq->gsi_assert_count[vioapic->base_gsi + pin] ) - { - ent->fields.remote_irr = 1; - vioapic_deliver(vioapic, pin); - } - } - } - - spin_unlock(&d->arch.hvm.irq_lock); -} - int vioapic_get_mask(const struct domain *d, unsigned int gsi) { unsigned int pin = 0; /* See gsi_vioapic */ @@ -611,6 +612,8 @@ static int ioapic_save(struct vcpu *v, hvm_domain_context_t *h) static int ioapic_load(struct domain *d, hvm_domain_context_t *h) { struct hvm_vioapic *s; + unsigned int i; + int rc; if ( !has_vioapic(d) ) return -ENODEV; @@ -621,7 +624,43 @@ static int ioapic_load(struct domain *d, hvm_domain_context_t *h) d->arch.hvm.nr_vioapics != 1 ) return -EOPNOTSUPP; - return hvm_load_entry(IOAPIC, h, &s->domU); + rc = hvm_load_entry(IOAPIC, h, &s->domU); + if ( rc ) + return rc; + + for ( i = 0; i < ARRAY_SIZE(s->domU.redirtbl); i++ ) + { + const union vioapic_redir_entry *ent = &s->domU.redirtbl[i]; + unsigned int vector = ent->fields.vector; + unsigned int delivery_mode = ent->fields.delivery_mode; + struct vcpu *v; + + /* + * Add a callback for each possible vector injected by a redirection + * entry. + */ + if ( vector < 16 || !ent->fields.remote_irr || + (delivery_mode != dest_LowestPrio && delivery_mode != dest_Fixed) ) + continue; + + for_each_vcpu ( d, v ) + { + struct vlapic *vlapic = vcpu_vlapic(v); + + /* + * NB: if the vlapic registers were restored before the vio-apic + * ones we could test whether the vector is set in the vlapic IRR + * or ISR registers before unconditionally setting the callback. + * This is harmless as eoi_callback is capable of dealing with + * spurious callbacks. + */ + if ( vlapic_match_dest(vlapic, NULL, 0, ent->fields.dest_id, + ent->fields.dest_mode) ) + vlapic_set_callback(vlapic, vector, eoi_callback, NULL); + } + } + + return 0; } HVM_REGISTER_SAVE_RESTORE(IOAPIC, ioapic_save, ioapic_load, 1, HVMSR_PER_DOM); diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 10b216345a7..63fa3780767 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -192,7 +192,13 @@ void vlapic_set_irq_callback(struct vlapic *vlapic, uint8_t vec, uint8_t trig, if ( hvm_funcs.update_eoi_exit_bitmap ) alternative_vcall(hvm_funcs.update_eoi_exit_bitmap, target, vec, - trig || callback); + /* + * NB: need to explicitly convert to boolean to avoid + * truncation wrongly result in false begin reported + * for example when the pointer sits on a page + * boundary. + */ + !!callback); if ( hvm_funcs.deliver_posted_intr ) alternative_vcall(hvm_funcs.deliver_posted_intr, target, vec); @@ -496,9 +502,6 @@ void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) unsigned long flags; unsigned int index = vector - 16; - if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]) ) - vioapic_update_EOI(vector); - spin_lock_irqsave(&vlapic->callback_lock, flags); callback = vlapic->callbacks[index].callback; vlapic->callbacks[index].callback = NULL;