From patchwork Wed Jul 13 13:20:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 9228347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 808C6608A1 for ; Wed, 13 Jul 2016 18:03:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 766492807E for ; Wed, 13 Jul 2016 18:03:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A64A2807B; Wed, 13 Jul 2016 18:03:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3167D27F8E for ; Wed, 13 Jul 2016 18:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932074AbcGMSAf (ORCPT ); Wed, 13 Jul 2016 14:00:35 -0400 Received: from mail-by2nam01on0085.outbound.protection.outlook.com ([104.47.34.85]:14264 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751367AbcGMSAc (ORCPT ); Wed, 13 Jul 2016 14:00:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QiRru1hggv1EzAPvAxur7MoqQyAiUFvFwSEtMTS1MGs=; b=4mkCtpRCfpbRi1qV+nhR97aN6ljIQEDKWyyLjltNIood++IpvL4x4Clbsx/kS2+oot+X0p8Ce6bvcgAe83jJzrQICn/A8Q6xmUpoc93MuOOoFodNf1YzolTuhLkPy8m1sGb7yGmqUsqZvZafELwcNrMo0RK77F8vooQCcV+xErI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) with Microsoft SMTP Server (TLS) id 15.1.534.14; Wed, 13 Jul 2016 13:21:33 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v4 08/11] iommu/amd: Implements irq_set_vcpu_affinity() hook to setup vapic mode for pass-through devices Date: Wed, 13 Jul 2016 08:20:29 -0500 Message-ID: <1468416032-7692-9-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468416032-7692-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1468416032-7692-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: SIXPR04CA0024.apcprd04.prod.outlook.com (10.162.171.14) To SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) X-MS-Office365-Filtering-Correlation-Id: 20ac9c6f-9f10-4445-8b60-08d3ab209d69 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:OJueceSZcxcCkKlQaYeNXfBCVt8aLmR/wlzcS1l382nPAqrvjNrDFMov3H0z9vXb7y89yZcwZ+cZDwezIKY6MfWvynB2gttHcu+VanxP9q03QcUUfI6FKXSmSFPLvusBRxJdotaUH71rc0g0eJAbPgV+Jna+RZxoLOrb7dxqhLHKuTOHVZhhaRDz0GccIGBM; 3:EkcBtozRYH7wqnIw4jYfBislkeq6Da7CgfAXp5Om3VHhjG11XoAr50FYqoJ1LzM/3wGrxryK9l/jIABBIj3AittE7YsTgFOHkyX3HyGTDIIkxg/5mBx9vefcFzWe42EV; 25:0FktEi12eu+L+vEv6ZVXrxUoewXYpZhn+/gXCFMWjygw99rOO84c9V1D0hbG0RkoeE341jfe+gsODvNet6GMZSumMf3rXdCC0NA8rhgZBELUTuhJpwq5R5IY/2d2fH84Fk7n3zun+pQEnAL9ZPL4iPW280b9Z46G59PC5MfEtlkPsob+6XeXm/arF70sxaJ9TS0LIE0n61lWJbczQCGvpzFW10dxDhSUrOVD9KL8LdPCKetvJRHeYMH7VGuNrpVeZMPrI6yJgBqyK+i/XMSQxYUUU+gyv3JcElPiZjSzbaAV5ZWrtHAndRIlCbd3NxdlcHASYnwXptYR8YR54xieLx7gRNgr4tm8eQv/MQmISQXTpszS/VyTkiT+RfOl+oiyuM10RMVPOKzla8IemC6EgNbO0AYDbUTEW1LkBvss/pY=; 31:pyojVeuP7Gc60fVkDG2UaWCltsfj2RS/RWIbZFRG9ccieON2B2UYrf6kD2KDykIjCfi2ilftLjsN765uWciTp6L2jYSfmEtyw+7YC0zOuKiDqHAmMrgEux1lMu9i/NgfPkkEtUGd6trI/8JRL504vu3b09pFRu/bgaUPoP1VpERe7FSMnZm dyIrigsPLY8nlnhJ/s1pP/Kw8euyzkxg2Wg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0445; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 20:U2GbMcP9TUyFQgelg9TGYDALL8Ii9HGmtWzRRBc0SkKP54pwYphRwbqRHIMkuv6Y619iYj010v10peHCieAyFB/IuiYefCO7zXApsUS79GrmV0tgjTdJzE5sh6RcbcMIJa8XkJ6Hbgc4OY4EhUvGyU8zAuptiArkW0Qu3e4WaRfPYaDjvcCmmOGlMx2I8nQv5kNwYufF1z3BJ+P00N4t7TGjywOTxw9r9nldXOrWb/KHSj9M1fCoDlm7E1YFtPVQ8Zk51ZYsNcDTynbo3TXeaFitWUNVkWe5Dm9dpv1MHfWHAA6r06mRrZqe5i383+IqF/Zsjl5biialBlPd9ERoa80KLggcr/k+PoMhqF5w7uZXzdjqX9yr77eXx9Nx7hEeToNoWRuCTQcFgIQjgIfo2pWVJN0oEvKE3VgkMx7y7uRazJ3pHu0VzmLVsh4WsJDoaDd65DJEDEx+epLmM/W+oXB4nYKIvuqkfRzo06HEymcX3rp725cfFBFZMdhZDaVn; 4:DeYwoee+79mRbTYPyts7Q9HUEEqxIP7fZ+DPywRHUQkohCBLliW7WsmdovNkqiLI6HS7tUbLDBhy7xPHCD5htpCjuN9/oHUh1YXlD1FNRCqX3nG7GmCsDYADUHmCIBQAUDEr7Hc/vsZz0rhKPlfGWSEmqGhfwPuqY63qkUoLqxQSzMhf4w8pHjCvkUAB7MSAxIcwxir/eLj+TIJWHc+jKqTbTftgAxpzm1K+2bUYatDOdV8ssRXxXfqvXYyx1QeeehKLpTCr6VwHAqvu+WnGFL4hFofa8385T8p7qK6cqHvMwBw61cF+pYr5UPp+KTKxhFM2CLcTJvNcyrb2YhYj7RfJswRlDm79hM/cTEqBJOdZNGVdp+49E7pLbP22JhFbM49KCleKmBedG7fxtCM3bDonCvFQ9omto1nTCP szJr4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Forefront-PRVS: 000227DA0C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(189002)(199003)(229853001)(101416001)(77096005)(8676002)(6116002)(2950100001)(42186005)(586003)(81156014)(81166006)(2201001)(3846002)(50986999)(4326007)(76176999)(50466002)(36756003)(5003940100001)(68736007)(105586002)(305945005)(47776003)(66066001)(86362001)(7846002)(50226002)(2906002)(48376002)(92566002)(106356001)(19580405001)(7736002)(33646002)(97736004)(189998001)(5001770100001)(19580395003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0445; 23:ky2gdEswjw5zxOCJVFfZIxKOOyuRrCNleLIS5C2H4?= =?us-ascii?Q?AeB37aanJxdLAR5scqV31n6JCNaFeF8GuDoMrSY5ufCwaixGgx0Le4TuR3KC?= =?us-ascii?Q?fcSc7BbtjucAGHu4j05VotQ3GqFOehimMh3JTYjpyJ3CTOc6CG7qt4704Sb3?= =?us-ascii?Q?njjqFMrQ/KXcDFmeZjm04ONqnZ2yFuBLjIUuzD55gAMzfiMkxpR67cc5Mt8+?= =?us-ascii?Q?rwGBzOvP+/5i1+ik3m4lTPmuzkahToYVjR4ebCEPj2kUPNOPWiaTzcURqCXn?= =?us-ascii?Q?ykQUrhHmk2Skukuc3UB/w25e42/z8XuZE04ZYOZINerDpzUdqviqC3zoHA9v?= =?us-ascii?Q?7c6k9+b6CMLpmC/iNXWylksvDLnvbOM4xe2uZBHgUzISqmJqwKQgOHaEC4Hg?= =?us-ascii?Q?BuLZpm7Yaq67hSMQMNxV8/RKDpYiaMWJGtLBTYR+P+A5XDQ/PL59Ppasqz75?= =?us-ascii?Q?BxUdyohQ5kmKzAuH4QQLqycdCch97DnvONPwAD+F6r1P0TyPCkLO5QeW0sJg?= =?us-ascii?Q?RhT/kbEe3GTxl/mAa74djST8j2tCZFMXshAtsOl1GULTFN0hPP/VFsTqUfuZ?= =?us-ascii?Q?KDRh6ZER042Ke1AoJzxNCg10bWg9hwVNRm+JAHfKJRXziOlI4klT6krbl80V?= =?us-ascii?Q?x9iBd80lQi0Cxm9blQ8uaEeHDdhg6uNYWurB+I+vntr2+st81/HFVmETde0U?= =?us-ascii?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HL8qak7biR7hSp7QdQfZ16UXx/gSDtWfeak2i7t8MZ1HwUL4Xh1buBC/jh+OSAChW9tI=; 7:8LR9BWa3QCVDr5qM3muZclBDkvJJ/zn+4uh9n6ZD+DJqAkn8bQ3AN+F06rpPHW6zGEoFRAWhD+j/rD4TcDZKIruR9yZTw7mNJ4i6M2aGW8gnG+AEdB2IMMK7wvkjiSCQ6aReHh8+3ZjdJzdomSetpoD2Ld1DyZEe4K/Vyu8XzMTY18aU3Rv0yio1U8eu52osyaSh44USvLBzOEqw3+sif1fBkJMXGSb3A/iOLgx5uxITK7/CU18kO/T1V/FPnYmY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 20:DWCzJrHbYc5uiM/g7928H+DlPmC93Z17YgWjLcm/tLGWx1yhrp9jvrkin8UyDSMv1ff94DvS3bWNxVEClioJbLIjLUqKSA73MBDXq6vN8tG+wXTDdfL1m7G0wgUeky6zsTjZyIIJ10MIQlgn29HsPk3q3ScnXj6A3QGqQoKLPbmKXXapvFVPoTsbhNAgTJBtz27ItHnbslOTyYwqMQoLPqhqnTgDGkihu8XbRQtCnfJYWjpp8WZ0gEUHk+Ei069e X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2016 13:21:33.2422 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0445 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Suravee Suthikulpanit This patch implements irq_set_vcpu_affinity() function to set up interrupt remapping table entry with vapic mode for pass-through devices. In case requirements for vapic mode are not met, it falls back to set up the IRTE in legacy mode. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu.c | 68 ++++++++++++++++++++++++++++++++++++++++++++--- include/linux/amd-iommu.h | 6 +++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 4a337dc..1b81af8 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3907,7 +3907,8 @@ out: return index; } -static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte) +static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte, + struct amd_ir_data *data) { struct irq_remap_table *table; struct amd_iommu *iommu; @@ -3933,6 +3934,8 @@ static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte) entry->hi.fields.ga_root_ptr = tmp.hi.fields.ga_root_ptr; entry->lo.val = irte->lo.val; entry->lo.fields_remap.valid = 1; + if (data) + data->ref = entry; spin_unlock_irqrestore(&table->lock, flags); @@ -4031,7 +4034,7 @@ static void irte_ga_activate(void *entry, u16 devid, u16 index) struct irte_ga *irte = (struct irte_ga *) entry; irte->lo.fields_remap.valid = 1; - modify_irte_ga(devid, index, irte); + modify_irte_ga(devid, index, irte, NULL); } static void irte_deactivate(void *entry, u16 devid, u16 index) @@ -4047,7 +4050,7 @@ static void irte_ga_deactivate(void *entry, u16 devid, u16 index) struct irte_ga *irte = (struct irte_ga *) entry; irte->lo.fields_remap.valid = 0; - modify_irte_ga(devid, index, irte); + modify_irte_ga(devid, index, irte, NULL); } static void irte_set_affinity(void *entry, u16 devid, u16 index, @@ -4068,7 +4071,7 @@ static void irte_ga_set_affinity(void *entry, u16 devid, u16 index, irte->hi.fields.vector = vector; irte->lo.fields_remap.destination = dest_apicid; irte->lo.fields_remap.guest_mode = 0; - modify_irte_ga(devid, index, irte); + modify_irte_ga(devid, index, irte, NULL); } #define IRTE_ALLOCATED (~1U) @@ -4403,6 +4406,62 @@ static struct irq_domain_ops amd_ir_domain_ops = { .deactivate = irq_remapping_deactivate, }; +static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *vcpu_info) +{ + unsigned long flags; + struct amd_iommu *iommu; + struct amd_iommu_pi_data *pi_data = vcpu_info; + struct vcpu_data *vcpu_pi_info = pi_data->vcpu_data; + struct amd_ir_data *ir_data = data->chip_data; + struct irte_ga *irte = (struct irte_ga *) ir_data->entry; + struct irq_2_irte *irte_info = &ir_data->irq_2_irte; + + /* Note: + * SVM tries to set up for VAPIC mode, but we are in + * legacy mode. So, we force legacy mode instead. + */ + if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) { + pr_debug("AMD-Vi: %s: Fall back to using intr legacy remap\n", + __func__); + vcpu_pi_info = NULL; + } + + iommu = amd_iommu_rlookup_table[irte_info->devid]; + if (iommu == NULL) + return -EINVAL; + + spin_lock_irqsave(&iommu->gatag_ir_hash_lock, flags); + + if (vcpu_pi_info) { + /* Setting */ + irte->hi.fields.vector = vcpu_pi_info->vector; + irte->lo.fields_vapic.guest_mode = 1; + irte->lo.fields_vapic.ga_tag = + AMD_IOMMU_GATAG(pi_data->vm_id, pi_data->vcpu_id); + + if (!hash_hashed(&ir_data->hnode)) + hash_add(iommu->gatag_ir_hash, &ir_data->hnode, + (u16)(irte->lo.fields_vapic.ga_tag)); + } else { + /* Un-Setting */ + struct irq_cfg *cfg = irqd_cfg(data); + + irte->hi.val = 0; + irte->lo.val = 0; + irte->hi.fields.vector = cfg->vector; + irte->lo.fields_remap.guest_mode = 0; + irte->lo.fields_remap.destination = cfg->dest_apicid; + irte->lo.fields_remap.int_type = apic->irq_delivery_mode; + irte->lo.fields_remap.dm = apic->irq_dest_mode; + + hash_del(&ir_data->hnode); + } + + spin_unlock_irqrestore(&iommu->gatag_ir_hash_lock, flags); + + return modify_irte_ga(irte_info->devid, irte_info->index, irte, ir_data); +} + static int amd_ir_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force) { @@ -4447,6 +4506,7 @@ static void ir_compose_msi_msg(struct irq_data *irq_data, struct msi_msg *msg) static struct irq_chip amd_ir_chip = { .irq_ack = ir_ack_apic_edge, .irq_set_affinity = amd_ir_set_affinity, + .irq_set_vcpu_affinity = amd_ir_set_vcpu_affinity, .irq_compose_msi_msg = ir_compose_msi_msg, }; diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index a6fc022..0928c26 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -22,6 +22,12 @@ #include +struct amd_iommu_pi_data { + u32 vcpu_id; + u32 vm_id; + struct vcpu_data *vcpu_data; +}; + #ifdef CONFIG_AMD_IOMMU struct task_struct;