From patchwork Thu Aug 18 19:42:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 74196 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp70751qga; Thu, 18 Aug 2016 18:19:55 -0700 (PDT) X-Received: by 10.66.57.7 with SMTP id e7mr8935984paq.101.1471569595510; Thu, 18 Aug 2016 18:19:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sl8si5203377pab.264.2016.08.18.18.19.54; Thu, 18 Aug 2016 18:19:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755198AbcHSBTj (ORCPT + 27 others); Thu, 18 Aug 2016 21:19:39 -0400 Received: from mail-sn1nam01on0058.outbound.protection.outlook.com ([104.47.32.58]:6892 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754140AbcHSBTg (ORCPT ); Thu, 18 Aug 2016 21:19:36 -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=Q4ALgmW3eUfJM6MgjTLEBKa1m65mjSCzUHOk5XyAeqU=; b=WrzVAccdIXk/Rx/Xlab4YoOaWM5wizZkr9xSvoRGvj6tcN5qihkG8XtUgM0zcFtTTOJpuy+YO5eb5GET0UJwelQb4jecUbiAzdMcQ3SSWwRanteRty1aquh1bqw/UcJ4fmIMZaObzwVQ+hC8zTaCM+4I8n+NnRBXmK3/UVIkLQY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 18 Aug 2016 19:43:52 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v6 09/12] iommu/amd: Enable vAPIC interrupt remapping mode by default Date: Thu, 18 Aug 2016 14:42:41 -0500 Message-ID: <1471549364-6672-10-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471549364-6672-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1471549364-6672-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: KL1PR0201CA0016.apcprd02.prod.outlook.com (10.167.53.154) To MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) X-MS-Office365-Filtering-Correlation-Id: 1ccdff9f-50e2-44ff-b080-08d3c79ffd04 X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 2:Mi/Yer+4knVo3XOc3oCJ5XiGrrknfpEncJE/3hE5s+LXe/z1yAV7fGwdyfMftW6oUAzltx6aAPTcqLvBDaOcs69MIewoYN8rEfilXGci9HMI9j4xBzzLTzNwFtekTnUOUo6JZpmNSRBdiAlor2CBxlV//nyyRLpNxOLAmaYnbQW9IvGFA5/HXz81FQv1Fu3V; 3:tiwcponmczAVVMOODjbIvxkP5QdEKiJJNByV+bcefvp1pevvX4E4niyFqj9PUtSmutN0l0AUrwqQ1uco0qVrGh8CgrdOj6tDEMlHdyGn27ZSIiBFHifcs7lOerZ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JsXWMG6PHXcAKANxiKW3F9RoOLaGMJPYbRPFgLpve6CdRfHqcZpTp4cVE1Zlhy3+tOStNbKPf1gCN9t6jdKj4wj2EhGsBtWwDxdf2xc+KKFuR6tVQ0Qz6E3+vaBmqCfpbJ2TzOZ9bcADYAznZ+5XiVtAz6jmXo4irllBO2PBLfq4LVcUGm7RQtarrL8HrWKSqAnF X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:MWHPR12MB1453; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1453; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 4:Hpy2VjV33NEhNr6P46JHPwvqEyeJ2t9dsEzdTgdI9o82ZwcriCwHrAq50A6qJtPLWh2q4jKXosWvwunZeMsc7ukeekTMuSnZOtH6sxjEWacNi/Xx/MknDVwvo4YZGT7Whdx0KHhrXIMMhs/wyMm6sVExaj5W6b3muMln6yzZg3XY5xvxYIM23oy9Uj/Q+8WhoMUWjdW+gH7gnkhGi09zWwLG9f7mY+0SWsq5PNOLBBuwUih87aje8I6nmjHvCzmJZUmlDx5damZsOlpDioX/kdKUHN+ckON7ZsY3hThSa0jfTUAToqXgFIfNMzqKSOOonA5u9pJ+iKJFrzWEx/bkgX7ibZn6S6THT0y+TDgHNkFBqFz5iu8f6aV0jgV4l4VHcDFyLSHx7T1JmNYw08f26mRpM9lFrpZEIHpAO/9LwvfC5ULTuSuWRthmPGyo9Rsq X-Forefront-PRVS: 0038DE95A2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(189002)(199003)(86362001)(42186005)(50226002)(19580395003)(586003)(68736007)(92566002)(3846002)(6116002)(575784001)(189998001)(105586002)(8676002)(81156014)(81166006)(5003940100001)(47776003)(5001770100001)(2950100001)(97736004)(48376002)(77096005)(50986999)(50466002)(106356001)(36756003)(2201001)(305945005)(19580405001)(76176999)(7846002)(7736002)(4326007)(5890100001)(2906002)(66066001)(229853001)(101416001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1453; 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; MWHPR12MB1453; 23:h+wDFyIdwUjUvyx671s0zULWK2V1CZNCsAFyFHlzH?= =?us-ascii?Q?DKVQZYCjSw50ieZOmxTmD0iuQ3xVyxoMUI+eLl9O+rJFnclxyB+juUBEfDHj?= =?us-ascii?Q?D5P1IxhvaPX+BNl2qpl6yQ0htDIKdZJ9CJZ6gwYut0ckg7SBXtCwSkysugLi?= =?us-ascii?Q?Kayudhvmt7gxa7yTIwTKv7+abrM6oOxvLA+FHXIZLprukQckSzDfq9V+JTwc?= =?us-ascii?Q?Ddtpv/pIJnk1kDBox1KCxLUhPhCVKhXyAJ7qHF6F+NINRiHZJOonlMZ26IOy?= =?us-ascii?Q?Ddz5hjpFP6plUpCCbnTNsHpQ/IABaPYDo/vxjInj9ckK2FNmepHkPD7rO10R?= =?us-ascii?Q?AuPnLvCCcYTxttHT26KKc1bToecfwOqxzjdGHusGjdfDZrB21OTFy5s1gHiq?= =?us-ascii?Q?0/3o//Pv18xjlphC+dvnfYyy+J5kBk2GrmqIAR7ontSvbv1vVG8XU40CmRV2?= =?us-ascii?Q?e84hP0H0NpE1mcHM3bhvViFf3bvib8SM7yeoxDhxbmqmoW9vutG7mSVZOSWI?= =?us-ascii?Q?m5D6LXy4CpVPo79cGgmuYMUsnJmtA1bZtlv0CG18Ln4a7vHvoNYP4kRg+Xbn?= =?us-ascii?Q?ebT7JbJLy8fQD+oOffkjP9hAxy1+u+/2ubdgQYMKRNKBcPUgFp2rXR2RWkw3?= =?us-ascii?Q?SnQsAG1Nz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sZAfIek/b4mdwmzSq5J2Gqx2rygDF9YqvyUA1BuFHwZewLrZr45k/dMqA==; 24:CcNxuWG5vUahJ3V5muwujzMRpMlFwGe1eK3//hhogOshGpJVt4G06AjaFEffWm1QmEcQ4jEQA9KxN4dM5Q63oFzcQ0lRNMMdgyPHCQ7f+Jg=; 7:hrIA9fFZAbBWHa8RcYBUC4KTQaSeiv2j14ejivQyuoNWhMEx0m1QrGT2P7jW/bysHjCD4tCtA6pGIu1J5g+3U+kNEZyoSC9PxyFS0eYjTMrp2VXcK6KaNWzmdM+HkSb1uoUmGxQ4vqT/eHGARfQVBugf7S1WFgbnVCFmmnLpXv8JbyENhYbQ/9nO/wHG+XHRA/agbAidFxbakIw1vEBs/uIjXlbD0gP+g0nRsJ5sy8/KblDfyz1viciqzvd0xTzX SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 20:++JcqoOq4wmSSgTD8MraEsyXT1IWSvHHoIUDcYpnaWfrE2sfIRExk0nNflN3uDOWHgL0KnuSfo5jotrbjJbBCb9K5kqBsEP/eMSlb9jSDpC5FdcOpQAQFkCbwZaaD5/AgohFKR4M9iv4fbGsxET/OKSB3NFRrEZCoD2JMTTncxw4YREAylRqBxtmxNsdLg3RdZV/hxapfbXtRqzUFw4KgyFx9LP2rgO5kAIxuXgKCx6PXAz5/amNuBhCyMBqk/DY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2016 19:43:52.3301 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1453 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce struct iommu_dev_data.use_vapic flag, which IOMMU driver uses to determine if it should enable vAPIC support, by setting the ga_mode bit in the device's interrupt remapping table entry. Currently, it is enabled for all pass-through device if vAPIC mode is enabled. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu.c | 44 +++++++++++++++++++++++++++++++++-------- drivers/iommu/amd_iommu_init.c | 12 ++++++++++- drivers/iommu/amd_iommu_types.h | 2 +- 3 files changed, 48 insertions(+), 10 deletions(-) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 65cdfcd..9cfac8b 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -105,6 +105,7 @@ struct iommu_dev_data { bool pri_tlp; /* PASID TLB required for PPR completions */ u32 errata; /* Bitmap for errata to apply */ + bool use_vapic; /* Enable device to use vapic mode */ }; /* @@ -3211,6 +3212,12 @@ static void amd_iommu_detach_device(struct iommu_domain *dom, if (!iommu) return; +#ifdef CONFIG_IRQ_REMAP + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && + (dom->type == IOMMU_DOMAIN_UNMANAGED)) + dev_data->use_vapic = 0; +#endif + iommu_completion_wait(iommu); } @@ -3236,6 +3243,15 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, ret = attach_device(dev, domain); +#ifdef CONFIG_IRQ_REMAP + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) { + if (dom->type == IOMMU_DOMAIN_UNMANAGED) + dev_data->use_vapic = 1; + else + dev_data->use_vapic = 0; + } +#endif + iommu_completion_wait(iommu); return ret; @@ -3986,7 +4002,7 @@ static void free_irte(u16 devid, int index) static void irte_prepare(void *entry, u32 delivery_mode, u32 dest_mode, - u8 vector, u32 dest_apicid) + u8 vector, u32 dest_apicid, int devid) { union irte *irte = (union irte *) entry; @@ -4000,13 +4016,14 @@ static void irte_prepare(void *entry, static void irte_ga_prepare(void *entry, u32 delivery_mode, u32 dest_mode, - u8 vector, u32 dest_apicid) + u8 vector, u32 dest_apicid, int devid) { struct irte_ga *irte = (struct irte_ga *) entry; + struct iommu_dev_data *dev_data = search_dev_data(devid); irte->lo.val = 0; irte->hi.val = 0; - irte->lo.fields_remap.guest_mode = 0; + irte->lo.fields_remap.guest_mode = dev_data ? dev_data->use_vapic : 0; irte->lo.fields_remap.int_type = delivery_mode; irte->lo.fields_remap.dm = dest_mode; irte->hi.fields.vector = vector; @@ -4060,11 +4077,14 @@ static void irte_ga_set_affinity(void *entry, u16 devid, u16 index, u8 vector, u32 dest_apicid) { struct irte_ga *irte = (struct irte_ga *) entry; + struct iommu_dev_data *dev_data = search_dev_data(devid); - 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, NULL); + if (!dev_data || !dev_data->use_vapic) { + 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, NULL); + } } #define IRTE_ALLOCATED (~1U) @@ -4207,7 +4227,7 @@ static void irq_remapping_prepare_irte(struct amd_ir_data *data, data->irq_2_irte.index = index + sub_handle; iommu->irte_ops->prepare(data->entry, apic->irq_delivery_mode, apic->irq_dest_mode, irq_cfg->vector, - irq_cfg->dest_apicid); + irq_cfg->dest_apicid, devid); switch (info->type) { case X86_IRQ_ALLOC_TYPE_IOAPIC: @@ -4407,6 +4427,14 @@ static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *vcpu_info) 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; + struct iommu_dev_data *dev_data = search_dev_data(irte_info->devid); + + /* Note: + * This device has never been set up for guest mode. + * we should not modify the IRTE + */ + if (!dev_data || !dev_data->use_vapic) + return 0; pi_data->ir_data = ir_data; diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 156ab4b..cd17136 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -146,7 +146,7 @@ struct ivmd_header { bool amd_iommu_dump; bool amd_iommu_irq_remap __read_mostly; -int amd_iommu_guest_ir; +int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC; static bool amd_iommu_detected; static bool __initdata amd_iommu_disabled; @@ -2019,6 +2019,11 @@ static void early_enable_iommus(void) iommu_enable(iommu); iommu_flush_all_caches(iommu); } + +#ifdef CONFIG_IRQ_REMAP + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) + amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP); +#endif } static void enable_iommus_v2(void) @@ -2044,6 +2049,11 @@ static void disable_iommus(void) for_each_iommu(iommu) iommu_disable(iommu); + +#ifdef CONFIG_IRQ_REMAP + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) + amd_iommu_irq_ops.capability &= ~(1 << IRQ_POSTING_CAP); +#endif } /* diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 71d1d0e..596e43f 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -803,7 +803,7 @@ struct irte_ga { }; struct amd_irte_ops { - void (*prepare)(void *, u32, u32, u8, u32); + void (*prepare)(void *, u32, u32, u8, u32, int); void (*activate)(void *, u16, u16); void (*deactivate)(void *, u16, u16); void (*set_affinity)(void *, u16, u16, u8, u32);