From patchwork Wed Jul 13 13:20:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 71955 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1146261qga; Wed, 13 Jul 2016 11:37:29 -0700 (PDT) X-Received: by 10.66.8.37 with SMTP id o5mr16107623paa.100.1468435049380; Wed, 13 Jul 2016 11:37:29 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id va9si5105216pac.186.2016.07.13.11.37.21; Wed, 13 Jul 2016 11:37:29 -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 S1752897AbcGMR4m (ORCPT + 30 others); Wed, 13 Jul 2016 13:56:42 -0400 Received: from mail-by2nam01on0044.outbound.protection.outlook.com ([104.47.34.44]:34996 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752820AbcGMR4Z (ORCPT ); Wed, 13 Jul 2016 13:56:25 -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=6fl5Cs7yvIaFsLHUvZ0nqgxXblEFbdQ8+i92+eiuzoQ=; b=FaBI6bu9yo2x8GSIVTELNwZdT6VI+hrkcTQw4G1FhBCMbU23t+nkxUIZXXBvEYyi7KbT5bTrzeOHX0GHjVyTUdPq2w8/d5Fslr+tanBeFCxtgcArQLNhjEQvkl+OvXicey+4J64d/2hn9Tg52S9hUyzipvIY6PdDgm38LY4HxmA= 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:36 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART2 PATCH v4 09/11] iommu/amd: Enable vAPIC interrupt remapping mode by default Date: Wed, 13 Jul 2016 08:20:30 -0500 Message-ID: <1468416032-7692-10-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: b4814c17-b4c7-45ad-5de2-08d3ab20a24c X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:0slwSzfYeyvx95dv1tOCf2A/2mSEW+n5IgGOre4X0sQpDsbhyDvvIDQXc/kx1jWW4uAA5sfKfdySh3ykiZz0uY+lsqTkb22tovuIDYggIW/yM96oNWXa+0gcODRNSORI+6JN3PpvyjTN9PrOkRfe3+VPS/Ou1KJkauKaD4T3Oz7Bh19qRDsZ4iWNkUPDSFA8; 3:menO9nqdIeisK8L4ByFyAXgWdRnnSn38nL6i2prodOiwAUBum3S0Jwyg0SiEjdHNduMkFoTFzEeI1Vn7XCV2tO1AqfuxB2bZ5lY+zss8Vy+tnTh1zIk/b1u54xh676AL; 25:U+hsBLiJdQac59v71ea0DDa2uPajO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cZ9myVpjq8w6rmSxAQzBzbQRdcz5VVdtamm7w2FoVflRIrU3REHJuvWNuuBFBny3RseCa0lWa4hb2v9hYxEO55ZDBmTpXJBYTut052w5GjnKWshpe07wLUtSyQIyPSj+ZyjTmgB4SzSUrO; 4:CCa7dVCfMNXTk6Srzep/OH8XixpvP21qyGB3LB0Gf8VnVVD+bJvk7ELzemtF8pihqDYime2kJgu6rqtjS2tMSHs+o9u/69ILHQ4DPYnV4gt9o3YjChru9NuqHYr5KvbQP0xA65e8Kdy7gzuuwYxhsu5H6I/19kVm4cNrZbKQmWxxAzX1GpkqZ455RgeseFagCayhG+jUxsMGnFmrFkJ1NnRJbywhVHQHDZO+LfwOXM5U5/rgDjX01pPCewSmS5ezCsoZMtDbkq87vNhuVczJjQ2ateR45KL4l5Restj7jAdMbbuxbwF+OKlJFeHAu7dK9YRROGv/Q4Bayn3+qmVsGXWP+2rNHXjTtelcSdNPHRt6h7lZpI8xassAOIXBlKS1VrwaDtzHXhK5wM9l4wTGhiDt5Uc4F7YuTY/qZEth/QY= 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)(5890100001)(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:Eve2xdmHu0P5hxcvLE8XtkypApfQNlLJ3jAE6Tcm9?= =?us-ascii?Q?LnqyyuiLTCdQpzVHaWBK/kU2l7miIiU5BVFqmyVcAvUda9pJVMLlFirFB8tm?= =?us-ascii?Q?3Tjt70So5G1AEohWWBns6+iHsLjMzWi2dY/bIrBF559XFzvHd10YKtu3qXxY?= =?us-ascii?Q?D7+tcJSFPhFjuiuXI5bQs4iAYyyO7cSWmi0k/l0nJs30Pue/2kws1ANy5gbD?= =?us-ascii?Q?hF2GG+z+26guN0fF/z3piTHd/b8w10Vhf9ssoK0SXzMWs5d1KXvNVDG8fA9z?= =?us-ascii?Q?VH6OGX2kd5VkB63ZEzp5UjF2JTuIzvlYcMwqrjnjV6meuM/y4xs3s3RNpeKc?= =?us-ascii?Q?VaKMOp2XnotSIxnd17YfVWa0t58Tqa5DXGfn4SeAxi1o7ru1wzqW82HMF8Oe?= =?us-ascii?Q?2TmYCXVNTXPHi4PqBS56Jwuj/9aRGwUbxkpTC/W5XveAhp3LZnZ9h5G9wn4s?= =?us-ascii?Q?zQAPwPAtw9tnWbrTtbYMj0YkNWvdKk5QxU+AlzlMgZdC7WQqGMfybCt9L1Q0?= =?us-ascii?Q?Gjx8kUo22oL1OF8YhnsHdSP6zzRSAl+tNAye/11wEXlv1D3z6LVXn6gwsusy?= =?us-ascii?Q?iKlWYF+FaEmIJiHKNfS4nX6pKi+jGt5LKKuyvfQ2haQZrivx+O80cAWWezi3?= =?us-ascii?Q?aB7J/0YDtU6mCJqA6KCECPagrAesmrZaYpjVLVf/l/OlpRcTTm2SJU88lK2Y?= =?us-ascii?Q?Bm1tr26BCjfcVSjnY68denkTgyRZQWmI0SsjA7K0fePgexjQXF4kSrXW2xdC?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ya1ftmbT0j5ASTJC2QZ1ircV6f58ovBy2Jb98o=; 7:4fKCGl/hEOQQ5q2nx7ylR7wGVc7GiSdKvH9sS9/ASaDZUErILzVmLZeY0Chs1Z4dSiq2GBMZ0MN6swG19WeJA+J0dZH06s61MGIG0RpruILJG/yYr8WYEVfKNJnEcvu5YfQ/rWEouYL2kfQApi8gwdHftDrnGcR7z7uPXkQrmPyTQWGLc9D3Q2RiGIRSAOIaECE1MAl8uNeJecrcEonisixifpiZLfkEzZrdIlTgQD+DShX0bfdNFBzUemfUdevt SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 20:yKxlxPbwI6IEfniS4dr3ysENWfasmL8g0Dd0fIY+OdDMBZSLY1jLdmbomPMLXz51OUp8ggwVRSQgkXUW7jiDXYm0kMG6hUyWDjjxEhE/4oXF/+L73xCKfC52JnyNwmEiPYfYK0RLaT82yLYW8jouctYP7Ks+6cH1mWd2UJwIsC2ayGE5m375qPZ/MDFM/FbaAkB4rWdz4bQp9ztfsBrzeiqqCLXGGVHVXcKngfx80D81D8tD4Hn7Y6X3gVrg/RzI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2016 13:21:36.2119 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0445 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit 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 1b81af8..dc98825 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 */ + u32 use_vapic; /* Enable device to use vapic mode */ }; /* @@ -3218,6 +3219,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); } @@ -3243,6 +3250,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; @@ -3993,7 +4009,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; @@ -4007,13 +4023,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; @@ -4067,11 +4084,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) @@ -4214,7 +4234,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: @@ -4415,6 +4435,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; /* Note: * SVM tries to set up for VAPIC mode, but we are in diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 6fab883..83f5e7d 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; @@ -2014,6 +2014,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) @@ -2039,6 +2044,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 52160c8..a3d9dee 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -827,7 +827,7 @@ struct irq_2_irte { }; 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);