From patchwork Mon Jun 13 22:06:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 9174505 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 956C26075D for ; Mon, 13 Jun 2016 22:25:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86B07265F9 for ; Mon, 13 Jun 2016 22:25:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B73627C0C; Mon, 13 Jun 2016 22:25:04 +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 D4F8E265F9 for ; Mon, 13 Jun 2016 22:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422726AbcFMWWO (ORCPT ); Mon, 13 Jun 2016 18:22:14 -0400 Received: from mail-bn1on0062.outbound.protection.outlook.com ([157.56.110.62]:8544 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1161258AbcFMWWM (ORCPT ); Mon, 13 Jun 2016 18:22:12 -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=y9IzU0N2n6RYhDloiQW4Kcc5s8tFc7PM+YB4zc1oCXg=; b=hs+VWr1TJYHumgqJA7gdbFTLrqsztUmuCbvX2hw6si51LWFIMZ3SqQrcEbdLw1VrCoMBXBDWf1JbIpFSIRwAtlKug44XswChTEmx2jAEBxlfDeV4jhp75HPiSOzHaLAZn2LLMA6Z7YqVnnsz1jz7g1Z6AvacKbUUnR1kC69SSj8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) with Microsoft SMTP Server (TLS) id 15.1.517.8; Mon, 13 Jun 2016 22:07:05 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 RFC v2 07/10] iommu/amd: Enable vAPIC interrupt remapping mode by default Date: Mon, 13 Jun 2016 17:06:47 -0500 Message-ID: <1465855611-10092-8-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465855611-10092-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1465855611-10092-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR0701CA0005.namprd07.prod.outlook.com (10.162.96.15) To BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) X-MS-Office365-Filtering-Correlation-Id: 00eb48d8-90d0-44dd-2443-08d393d70ee1 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 2:14tlZyikc5ddUcmrLNNhGVz2WYTPrHCOiXtQmYe6wm10A2kmq1K3s1h5UkbkACCs43FIcdFVgNrIV2Nd+9AVgVXEruipNU5SQ4joUIvwgNNP3Lw3/5Bu/1tMnKT3rukKUR+KD48naVSwPcdARj6EWFfg26lBIG1lEYuTRbT0Z/6aQzk31DIMk7WMRcWREePx; 3:W7MSK6X0LwvRP1o7uIC01Vd/649CE8RSgdwimHrdbr6R/qG3UiBOU33SjhN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XY/iLpHLshTVfMi+9jxM; 4:Q4yJCjJ+tdJoUMrznP9y3ymUDIw4wN8C1cUE7WS4ETA7OddKvsTimTOJ9LeQbFfXN+0a3tojDlcu0nh8vreDxfA5T2cE4ZpC2K0EGaZQWTz/M3RmJ3ewKOkHU4eVSekByLaCTD2LHXcW06fNiYE8cREIxWx+6hHSu9uKqnBzz9DueYUHrx+ZGnNUTuRoXkXvpaWgl9UWTTS7mpw/Gspoa0SGZBaOyGFlfjj0pqZoTBFfMcghWGOwZwQiz4+aQjKLvsDuRBudPsUMnsmrd2TtCimaer7cfxEGUxOgNHZOxZlz+9KLHIaF0JNia6kCdRXe2TwaQr71EXwLM/UnsGsm1rA9UcKiwZjeupAeqe8QTTDowJxXDtKOFCZlaej4sTMTdiIwF5iv75DDXmn7duT8N8IzREZRXWT8wTDXJC qL3LP2hflpb0YJSpe2sBinh9JY 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)(3002001)(10201501046)(6055026); SRVR:BLUPR12MB0434; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0434; X-Forefront-PRVS: 0972DEC1D9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(53416004)(50226002)(5890100001)(5008740100001)(50466002)(36756003)(19580405001)(19580395003)(106356001)(189998001)(68736007)(105586002)(42186005)(2906002)(586003)(5001770100001)(101416001)(50986999)(4326007)(8676002)(81156014)(2950100001)(3846002)(6116002)(76176999)(77096005)(81166006)(97736004)(5003940100001)(5004730100002)(47776003)(86362001)(48376002)(92566002)(229853001)(33646002)(2201001)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0434; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR12MB0434; 23:ofM/jSfcG7D0/x2Sy4Ed0zfKkh4RcKjuGb0hdoYyJ?= =?us-ascii?Q?qz1nOhNrQ1fydLj4UT9ZFN4S8z4JfplFH14292wxqgmN69DjM4NQGjYmrFp3?= =?us-ascii?Q?MT602zW03hDkKWbCX+xyFckqNsQpInA4JdWLgvB4tTd5peqKbzZlRDqkrqRp?= =?us-ascii?Q?c1rySaa51nPkqp1kidhDUg/mqqQUUIcaytW1wZLWz41tnAd+Ng45NU4ccb3q?= =?us-ascii?Q?rLqB/bsc6LKZk5wFJTgyhTTcPbgpGMwsepu0qJ90gfT0Oi0+QqEr5QfduY+T?= =?us-ascii?Q?hYbvzegF+/R29UGeIvVvH9S6RQBJ+iHBwI7lePq+XvJyliV+XqdDQxBUoyyl?= =?us-ascii?Q?IAyGtBZ7KFMbrpDpxcO27G8vzCHiqWDkTFfFZzH+nG3sQlc7Cnjl+/G2398x?= =?us-ascii?Q?8mPFNbjXAS1BTmWNwE4aZ3CJ4edUnKex1l6WAvmOs2xiitnFDnUgV/1Rnnqf?= =?us-ascii?Q?ly2WiT5+IPNAyFTMngymPvnC2CrHuDsC5+lm5nVA5UbCRX2G7mlIyXVkjv2+?= =?us-ascii?Q?jFsnshmd03MOHqKKZXUdXMHHqNc1HqXyj8sPaki8ER0BDZ1lzqCanPPWieaP?= =?us-ascii?Q?wFl1rxkljnG9CHPrCGI14VX4nlh5ePwvV1L6xCfi+R87ShHNsSQCSUxDzxau?= =?us-ascii?Q?Sixk1TKP8qiPJGEIrpqs3kgeX7N4nyO77i3LuOkkXedDXYvPIrvuU1NTBZkL?= =?us-ascii?Q?fYctb756hFpZdB+rr3k/5OvJQeyWohxCsUg4Zgvx4GxmQVPvWQp5Q0BUiOp5?= =?us-ascii?Q?0R0LsXAG715FcC6AdpXlExsLHWj2enhe8cFSIk/n4mE6lsLmFK424SGp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gKq2Q4dov/+60Uk4BBxt2xMwoqriuyEjrz8tft7UC+5GSnDttpgXfMCOu4O1Ih8yQpmquTTsbFFAo+aOyyvwCASF1IDp7itKYIBzRNgKpxxBOpcZ0iDBm3dRO4mhwWQ1hvHjh8+ok3ywva5B8FWcXZ1aIOKmNNVaQrw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:Ltty3Xk+zAbso2BGUvMZgRaZrIfyCVlqM1+GmvPi1aL/+Lv4Nqu903a63SNsg9dd1PUXaO2pLdXyje2YKQFRIZY+NwU+gPAZVU36t9kkSDgMfK63K/J73XpB7Y5aFcaX14vgiRgGt9JequzDmonVxuK0XY09r8kTaLh+eXVUZuoM0quqAYSzEJoV55o/cKeXx1/AVx/yVCqtgX+6DJ1WimTTh98ZZwXu+U0gJ2n19o2+XL1V+lfma9zDRgvupZU5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2016 22:07:05.9071 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0434 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 18 ++++++++++++++++-- drivers/iommu/amd_iommu_init.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 7176c94..1c6693b 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 */ }; /* @@ -3232,6 +3233,10 @@ static void amd_iommu_detach_device(struct iommu_domain *dom, if (!iommu) return; + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && + (dom->type == IOMMU_DOMAIN_UNMANAGED)) + dev_data->use_vapic = 0; + iommu_completion_wait(iommu); } @@ -3257,6 +3262,13 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, ret = attach_device(dev, domain); + 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; + } + iommu_completion_wait(iommu); return ret; @@ -4161,7 +4173,8 @@ static void irq_remapping_prepare_irte(struct amd_ir_data *data, 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 = apic->irq_delivery_mode; irte->lo.fields_remap.dm = apic->irq_dest_mode; irte->hi.fields.vector = irq_cfg->vector; @@ -4405,6 +4418,7 @@ static int amd_ir_set_affinity(struct irq_data *data, struct irq_2_irte *irte_info = &ir_data->irq_2_irte; struct irq_cfg *cfg = irqd_cfg(data); struct irq_data *parent = data->parent_data; + struct iommu_dev_data *dev_data = search_dev_data(irte_info->devid); int ret; ret = parent->chip->irq_set_affinity(parent, mask, force); @@ -4420,7 +4434,7 @@ static int amd_ir_set_affinity(struct irq_data *data, ir_data->irte_entry.fields.destination = cfg->dest_apicid; modify_irte(irte_info->devid, irte_info->index, ir_data->irte_entry); - } else { + } else if (!dev_data || !dev_data->use_vapic) { struct irte_ga *entry = &ir_data->irte_ga_entry; entry->hi.fields.vector = cfg->vector; diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 60b0394..5f7b6be 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;