From patchwork Tue Aug 23 18:52:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 74510 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2246228qga; Tue, 23 Aug 2016 11:55:19 -0700 (PDT) X-Received: by 10.98.101.1 with SMTP id z1mr55985928pfb.53.1471978519647; Tue, 23 Aug 2016 11:55:19 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si5095476pfk.163.2016.08.23.11.55.11; Tue, 23 Aug 2016 11:55:19 -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 S1754552AbcHWSyu (ORCPT + 27 others); Tue, 23 Aug 2016 14:54:50 -0400 Received: from mail-co1nam03on0073.outbound.protection.outlook.com ([104.47.40.73]:37280 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751187AbcHWSyV (ORCPT ); Tue, 23 Aug 2016 14:54:21 -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=zq8iY/CqaMHepAM757yDTSLtFAvvySYrqTR85hycwQ0=; b=GYpGbWMPAATYXZ4i4CNR+afRrr0yL6Uk9+NJIM15h94RQf1tfr6NtHzHUkeIMDFzdtHDIMn/YqPc8gobBpQMCZEAD/aOO0VzLqs4vXx6GWfcPZqRSzURK4XO9NQtowrpfRQjQC5zpFV8xX5F1XAsX3QAzar+kGp/UzGQEuJlsKI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by DM5PR12MB1452.namprd12.prod.outlook.com (10.172.38.141) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21; Tue, 23 Aug 2016 18:53:09 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 PATCH v7 01/12] iommu/amd: Detect and enable guest vAPIC support Date: Tue, 23 Aug 2016 13:52:32 -0500 Message-ID: <1471978363-13756-2-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471978363-13756-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1471978363-13756-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: KL1PR02CA0053.apcprd02.prod.outlook.com (10.167.54.21) To DM5PR12MB1452.namprd12.prod.outlook.com (10.172.38.141) X-MS-Office365-Filtering-Correlation-Id: 351140af-28f6-4ba3-8d8d-08d3cb86bb7a X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 2:7YDB07e324K4px1kAWGNnVpNpHuCVoIyL2zf3ZdYkxLQA+IoH3ywniucLWR4wx0sS7Zy0rOAYMZXp71m3bum9dluMG7rn8g79jnwrCBXjaAd8oFHXmzqcT7C+QMzN9Qj7zfTivVvNDSTIXBGs2l1MI0BhCQcmN6nvusEL9ZnWIzdjRZtYh+aAhthIh10mzqM; 3:Dp9O5Pk4wtOX48n4nnlHRff5gTAZivOCKDUk1vUCJXWN7r0XEG4Pimv18YZStRpo8+xhwJLOCnn7yvN2mEpjyfcH2A89ztb230f6SaKQSTsRCxK7QjT8tl6SKcDitkGx X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR12MB1452; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 25:WYVSOQY/iOZgoUrXZ/5Luk07h5gTes4wCBhSD3qdYMUaYCG2kAv3qirMHpOI6ubJm/l+SlyBtwhVFrnpnFzM7hH994JIvFHYHx9aCowIogTpXAdU3hu+dH42dylizpJL856xriEAhNArVgbxsRacvIzyv6dCPSt/0TN2S+gLBsiswCuJm0C9ExDoo2ct+88kxGtDtno7/iO/QqXrHMiG34P+b471nr9ZTmWDMLSH+MzxRiVzrmup6S0k26v1TKPEBkhUdSp7bWD5AbLNewb4q7ePQcDEIpQmb9tRBHL5yLGJaANCfd5dXiXDxPmAGJL5wWFgv5YH52iO+dzkazjwZzwps7MoNI0KewRGsjdsuiNRjge5a1PbP/vXC/knjyd0jIoFYnoA6z05TeoCAiZc+8GbunKWgMtWo1aDpGNyugxQZA1zcy2fHYYksb1CoC0aJpsZNnD57lZykqyUzYTdynP5UFvA3HFHEjbwajLWU11vDeCFp7EDWhqQWWKis7xzJzuMVZUeGi8gcvHHKMQKbLWpGr0CWmBqI8tJztyySUC+unSJtK/b42Bnmx4VgyANsgHT77r0s0WqA27lpuBfD2eaPD/uJJ3Z6/XKuvShqrmyapGKCfm1QeaeIlwPq5C+JtRGbdMP4w4Gr5OC3vmR1iErRa020AHFxsqLu4mzetq39ZShYTo/1P9jqUtEk81Y2aN4Ah/MMjDk7SufmP3WVinouQFTLc3Nk3kAYrUaGgFYwebBWsI6djxknk0M9GimgIn1nqlAS8+RJZfxm1YE9A== X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 31:9fW33clCcVMgfrnYhdlKBxoV5eZmnK3da6z8P2ASuUMkR+8pFBjtUiIhGMoYbKxLF0gJRxqWF0TeeJfAuWJWVMq1zuzbxY8YkObJgoC0TmjAbKnxAhT6TF848cbGqSWr3YG0xjxuR7l8b4X8QjdFkePBVsOq0kt10gzgsZYQH4y47Z6kdpffyADHEfqkPibuZyecsvFP4YKFy4Ct74E1w4pDnYjqeTkDlpm2ZmxVais=; 20:RF8HzpV8JR9PsSL4qFr6VhGq5QJjA+5aJRxzva81zLv5Q+d1uLqqK9tPSomqmM0apU4snYSeV1OCEGdhrIxBO7+CG9J1Wg3F7tjds1Y5MbxcsO7k7nZMQE70vRJLHjfnywfq9jChNmjwbe9Nbv9z1jktf7DiAjm+VfPhvDpcZ6DyUH/FWfx3Xacd53fBqzAlyKD8rLMP5gYiVmpqGZ6JBapmFEnsd/JImlR0Y9qIzDO+Fc42vJXhQ+XKI1wLQnbcvtaHJB3EbPGUqkRj6fjSB9NFe+8JbGQRCcRVbyS26rDeX4AH6foF3QPZLt0cl8l5amXzinA8eC4fN1GVXZQ/lvKJXiqwtBnV1KUIPlmWUJWlN0i4Bhy7wx2lwgiwn+iUi+xR0wPR6fTQjLP0Ol6YsEwPMtKM9B/rAEJaysox7tsOslhq8dkRP6sWRJ+DibDYVKSqClaYZ4tCDZd2TmEiIL6AqoPbr4EzoEOgS/avew5GIYE00terAxYza500B0Ct X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:DM5PR12MB1452; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1452; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1452; 4:b09ZI/FbiAkdL0RowBOug40G6vvAbExfEHeLO04bZPkDniSoG17A6ZQ7wTM+enjqHnWuCb7dECDLxw4Dum8OvCQyH+ZmXZfJgaocbhIzSMpC0YEwMebthi3UU5qEMy+n27TYv7rm8Yl5ronQojjay4XiXk5pQZdj1g+UFR2vyyOam1GBFF5ipC3zxAxZ/dCEAA7E3SkN0tKbXuJB2NTuVKiBqDv2/8CvFEm7IKJVYErIyk8DMgsihXBkidsOBPaomXhyzkDyfLzMQuIuCBCkmoiltUG6hPsLfNGlY+NphCrEFfS+uhTMc04t+BcWSP+s6c5p40PdIGUHtRD8ejDKjUEtf4OAPMX9QIciHaHP3rtOb0+d7F4ZX8H8bQtx0BjUWEW367RiCm+nE7rBSUDXTI6pvEBCj5BCvWx5IjyP0FfbtCwN7X5CHWDwjrLj5dc5OIMFsklKZPBPcbxu+bMixZvepw7w5tm3H+c9vR93O1w= X-Forefront-PRVS: 004395A01C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(42186005)(76176999)(101416001)(48376002)(50466002)(77096005)(5890100001)(5660300001)(575784001)(92566002)(105586002)(5003940100001)(36756003)(86362001)(106356001)(66066001)(50986999)(5001770100001)(19580395003)(19580405001)(50226002)(97736004)(189998001)(229853001)(3846002)(2950100001)(47776003)(8676002)(7736002)(6116002)(586003)(81156014)(68736007)(4326007)(2201001)(81166006)(305945005)(7846002)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1452; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; DM5PR12MB1452; 23:X1aGp/7HK5hulwav+zeVE80viKfEsAlI4vLh6TJ/t?= =?us-ascii?Q?4f1+RqoMSLp5kOv6+RDcDUVTP3KZQjNnFn/U4MnSURWnytS3lIywPAFSDcOh?= =?us-ascii?Q?tslOpPQiM6bNXLyjji76c8E3ZqWSovd2m2e62YMw/hCMQcu5dN76AijLrXo/?= =?us-ascii?Q?/iwHrRLWvUdhen8fnxRmtIilfDM/2cMAzgCmNjDb98N4rPRebRdIJKEHAOqN?= =?us-ascii?Q?Fs0bY3XI7e3GkYvjRNXzY/TpJHW5iPeIoe/vYpvq6ZNsIS0ZaxpuLeK0wesl?= =?us-ascii?Q?kWrWGt91bz741owdqY+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29PmSMVRk1LnCJnitl+FPykWRqSiqb8VPsTDXHaC3K3cv2qiOhRecjGF2vWLO1BcW78jD3J8WHXmRerro6YMX3mgVp0KrKOQYnDhIql/B9oeigGhr+g/R/F4tKq650EBsOj2pMee1xykB44IgcBFKh8mU3PlzSNlzHF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2016 18:53:09.1604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1452 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit This patch introduces a new IOMMU driver parameter, amd_iommu_guest_ir, which can be used to specify different interrupt remapping mode for passthrough devices to VM guest: * legacy: Legacy interrupt remapping (w/ 32-bit IRTE) * vapic : Guest vAPIC interrupt remapping (w/ GA mode 128-bit IRTE) Note that in vapic mode, it can also supports legacy interrupt remapping for non-passthrough devices with the 128-bit IRTE. Signed-off-by: Suravee Suthikulpanit --- Documentation/kernel-parameters.txt | 9 +++++ drivers/iommu/amd_iommu_init.c | 71 +++++++++++++++++++++++++++++++++---- drivers/iommu/amd_iommu_proto.h | 1 + drivers/iommu/amd_iommu_types.h | 24 +++++++++++++ 4 files changed, 99 insertions(+), 6 deletions(-) -- 1.9.1 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 17e33db..66c8f4b 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -460,6 +460,15 @@ bytes respectively. Such letter suffixes can also be entirely omitted. driver will print ACPI tables for AMD IOMMU during IOMMU initialization. + amd_iommu_intr= [HW,X86-64] + Specifies one of the following AMD IOMMU interrupt + remapping modes: + legacy - Use legacy interrupt remapping mode. + vapic - Use virtual APIC mode, which allows IOMMU + to inject interrupts directly into guest. + This mode requires kvm-amd.avic=1. + (Default when IOMMU HW support is present.) + amijoy.map= [HW,JOY] Amiga joystick support Map of devices attached to JOY0DAT and JOY1DAT Format: , diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 59741ea..c3afd86 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -145,6 +145,8 @@ struct ivmd_header { bool amd_iommu_dump; bool amd_iommu_irq_remap __read_mostly; +int amd_iommu_guest_ir; + static bool amd_iommu_detected; static bool __initdata amd_iommu_disabled; static int amd_iommu_target_ivhd_type; @@ -1258,6 +1260,8 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) iommu->mmio_phys_end = MMIO_REG_END_OFFSET; else iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET; + if (((h->efr_attr & (0x1 << IOMMU_FEAT_GASUP_SHIFT)) == 0)) + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY; break; case 0x11: case 0x40: @@ -1265,6 +1269,8 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) iommu->mmio_phys_end = MMIO_REG_END_OFFSET; else iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET; + if (((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0)) + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY; break; default: return -EINVAL; @@ -1488,6 +1494,14 @@ static int iommu_init_pci(struct amd_iommu *iommu) if (iommu_feature(iommu, FEATURE_PPR) && alloc_ppr_log(iommu)) return -ENOMEM; + /* Note: We have already checked GASup from IVRS table. + * Now, we need to make sure that GAMSup is set. + */ + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && + !iommu_feature(iommu, FEATURE_GAM_VAPIC)) + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; + + if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) amd_iommu_np_cache = true; @@ -1545,16 +1559,24 @@ static void print_iommu_info(void) dev_name(&iommu->dev->dev), iommu->cap_ptr); if (iommu->cap & (1 << IOMMU_CAP_EFR)) { - pr_info("AMD-Vi: Extended features: "); + pr_info("AMD-Vi: Extended features (%#llx):\n", + iommu->features); for (i = 0; i < ARRAY_SIZE(feat_str); ++i) { if (iommu_feature(iommu, (1ULL << i))) pr_cont(" %s", feat_str[i]); } + + if (iommu->features & FEATURE_GAM_VAPIC) + pr_cont(" GA_vAPIC"); + pr_cont("\n"); } } - if (irq_remapping_enabled) + if (irq_remapping_enabled) { pr_info("AMD-Vi: Interrupt remapping enabled\n"); + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) + pr_info("AMD-Vi: virtual APIC enabled\n"); + } } static int __init amd_iommu_init_pci(void) @@ -1862,6 +1884,22 @@ static void iommu_apply_resume_quirks(struct amd_iommu *iommu) iommu->stored_addr_lo | 1); } +static void iommu_enable_ga(struct amd_iommu *iommu) +{ +#ifdef CONFIG_IRQ_REMAP + switch (amd_iommu_guest_ir) { + case AMD_IOMMU_GUEST_IR_VAPIC: + iommu_feature_enable(iommu, CONTROL_GAM_EN); + /* Fall through */ + case AMD_IOMMU_GUEST_IR_LEGACY_GA: + iommu_feature_enable(iommu, CONTROL_GA_EN); + break; + default: + break; + } +#endif +} + /* * This function finally enables all IOMMUs found in the system after * they have been initialized @@ -1877,6 +1915,7 @@ static void early_enable_iommus(void) iommu_enable_command_buffer(iommu); iommu_enable_event_buffer(iommu); iommu_set_exclusion_range(iommu); + iommu_enable_ga(iommu); iommu_enable(iommu); iommu_flush_all_caches(iommu); } @@ -2059,7 +2098,7 @@ static int __init early_amd_iommu_init(void) struct acpi_table_header *ivrs_base; acpi_size ivrs_size; acpi_status status; - int i, ret = 0; + int i, remap_cache_sz, ret = 0; if (!amd_iommu_detected) return -ENODEV; @@ -2157,10 +2196,14 @@ static int __init early_amd_iommu_init(void) * remapping tables. */ ret = -ENOMEM; + if (!AMD_IOMMU_GUEST_IR_GA(amd_iommu_guest_ir)) + remap_cache_sz = MAX_IRQS_PER_TABLE * sizeof(u32); + else + remap_cache_sz = MAX_IRQS_PER_TABLE * (sizeof(u64) * 2); amd_iommu_irq_cache = kmem_cache_create("irq_remap_cache", - MAX_IRQS_PER_TABLE * sizeof(u32), - IRQ_TABLE_ALIGNMENT, - 0, NULL); + remap_cache_sz, + IRQ_TABLE_ALIGNMENT, + 0, NULL); if (!amd_iommu_irq_cache) goto out; @@ -2413,6 +2456,21 @@ static int __init parse_amd_iommu_dump(char *str) return 1; } +static int __init parse_amd_iommu_intr(char *str) +{ + for (; *str; ++str) { + if (strncmp(str, "legacy", 6) == 0) { + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY; + break; + } + if (strncmp(str, "vapic", 5) == 0) { + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC; + break; + } + } + return 1; +} + static int __init parse_amd_iommu_options(char *str) { for (; *str; ++str) { @@ -2521,6 +2579,7 @@ static int __init parse_ivrs_acpihid(char *str) __setup("amd_iommu_dump", parse_amd_iommu_dump); __setup("amd_iommu=", parse_amd_iommu_options); +__setup("amd_iommu_intr=", parse_amd_iommu_intr); __setup("ivrs_ioapic", parse_ivrs_ioapic); __setup("ivrs_hpet", parse_ivrs_hpet); __setup("ivrs_acpihid", parse_ivrs_acpihid); diff --git a/drivers/iommu/amd_iommu_proto.h b/drivers/iommu/amd_iommu_proto.h index 0bd9eb3..faa3b48 100644 --- a/drivers/iommu/amd_iommu_proto.h +++ b/drivers/iommu/amd_iommu_proto.h @@ -38,6 +38,7 @@ extern int amd_iommu_enable(void); extern void amd_iommu_disable(void); extern int amd_iommu_reenable(int); extern int amd_iommu_enable_faulting(void); +extern int amd_iommu_guest_ir; /* IOMMUv2 specific functions */ struct iommu_domain; diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 590956a..25f939b 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -92,6 +92,7 @@ #define FEATURE_GA (1ULL<<7) #define FEATURE_HE (1ULL<<8) #define FEATURE_PC (1ULL<<9) +#define FEATURE_GAM_VAPIC (1ULL<<21) #define FEATURE_PASID_SHIFT 32 #define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT) @@ -146,6 +147,8 @@ #define CONTROL_PPFINT_EN 0x0eULL #define CONTROL_PPR_EN 0x0fULL #define CONTROL_GT_EN 0x10ULL +#define CONTROL_GA_EN 0x11ULL +#define CONTROL_GAM_EN 0x19ULL #define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT) #define CTRL_INV_TO_NONE 0 @@ -329,6 +332,12 @@ #define IOMMU_CAP_NPCACHE 26 #define IOMMU_CAP_EFR 27 +/* IOMMU Feature Reporting Field (for IVHD type 10h */ +#define IOMMU_FEAT_GASUP_SHIFT 6 + +/* IOMMU Extended Feature Register (EFR) */ +#define IOMMU_EFR_GASUP_SHIFT 7 + #define MAX_DOMAIN_ID 65536 /* Protection domain flags */ @@ -682,4 +691,19 @@ static inline int get_hpet_devid(int id) return -EINVAL; } +enum amd_iommu_intr_mode_type { + AMD_IOMMU_GUEST_IR_LEGACY, + + /* This mode is not visible to users. It is used when + * we cannot fully enable vAPIC and fallback to only support + * legacy interrupt remapping via 128-bit IRTE. + */ + AMD_IOMMU_GUEST_IR_LEGACY_GA, + AMD_IOMMU_GUEST_IR_VAPIC, +}; + +#define AMD_IOMMU_GUEST_IR_GA(x) (x == AMD_IOMMU_GUEST_IR_VAPIC || \ + x == AMD_IOMMU_GUEST_IR_LEGACY_GA) + +#define AMD_IOMMU_GUEST_IR_VAPIC(x) (x == AMD_IOMMU_GUEST_IR_VAPIC) #endif /* _ASM_X86_AMD_IOMMU_TYPES_H */