From patchwork Fri Apr 8 12:49:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 65399 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp49497lbl; Fri, 8 Apr 2016 05:50:46 -0700 (PDT) X-Received: by 10.98.15.135 with SMTP id 7mr12439592pfp.142.1460119838959; Fri, 08 Apr 2016 05:50:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 81si741542pfq.221.2016.04.08.05.50.38; Fri, 08 Apr 2016 05:50:38 -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 S932853AbcDHMuZ (ORCPT + 29 others); Fri, 8 Apr 2016 08:50:25 -0400 Received: from mail-bn1on0061.outbound.protection.outlook.com ([157.56.110.61]:21856 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932775AbcDHMuT (ORCPT ); Fri, 8 Apr 2016 08:50:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VOHXtQRgcmzzP8vRM5camPCQ7ris2RF//7RCY6BDAAw=; b=YzxS1krq/10dA6HMY/Dpe0yxzPy6JTNCKS8mlK2aFol03BUCtcJP5wN+OP2j7utiv8vaB3n7PB35nPszP6DLCYOFrUuxzgxLD2c7H892/fDa+ObiQuHcme5GVqGNwRH1tOHRyzVfoQgUzw/YBSyxXai+Iw0tdTIv6UYx1AKNr7s= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) with Microsoft SMTP Server (TLS) id 15.1.453.26; Fri, 8 Apr 2016 12:50:11 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit Subject: [PART2 RFC v1 5/9] iommu/amd: Introduce amd_iommu_update_ga() Date: Fri, 8 Apr 2016 07:49:26 -0500 Message-ID: <1460119770-2896-6-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460119770-2896-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1460119770-2896-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: HKNPR06CA0022.apcprd06.prod.outlook.com (10.141.16.12) To SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) X-MS-Office365-Filtering-Correlation-Id: 274c4a5b-1d57-4de2-e3eb-08d35fac54a3 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 2:E8Vdy176Nruy5Qo1/PgBGmqVkFU3j4jd8vgNv91j/hreskVyKjvR3XKgioxHDMxlqmiH5BXMlQ17Te9BaKEBtsTU+bh7fkCAU83SUB0B1xXBpZS7G9gPq4lygluO28IU90GdaZl0vsUVH+6O8MPmMsXR/mwXzl0KTn2lI2oJy9mA0q6TPkcK7P/cRt+CuWe5; 3:p0V64tvRPQ6/wqES5WLh7Zthtl4WaAh5zKcpqYBgRSdOP5ETm3xz2VUAxF8zuXVvbEatSWWP6iR53UElUAVfpNuhM/VsvlHnYp34/fs/NnmTKaCO/bjJwUl9VSPgVoHk X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID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TgacIyjPYrby2SHDemKfTSPqR9xDVkDozL2afLaHf4dLZaOX8X7hnHMsl5oqiBJFp7C3D+0hGu6F1qIcNs7vIbpUu1EYXkyjHpJV4iGQjT9GpyMWYyIxBuMtj5e8iv6MhnJf+loMLWapDTYGKnRcoEzCJGwJ88qCIIghGJYl0d8kzlEGXd+58lfpe/8H9zjfVCIBzzmYmvuWnXvxdJCGyX6iRSnxG4th8FX8+JmeN6r0; 4:evQf+98Phm3hNSH7I103tOg4JRHmAVZAAQw79ZKPPsj7+byNbro/vvmjY+G/UP+lTFLmnQJJgzQIKPP44CWVOhugAfsFmCAQhb86OlcpPUV03n/EIpolsx9ScH2V/ojbnwVRU4U0ufv4JOQLlajRG3zVjIJbpDS5pafESO2fjfPx1RnTfpfYfNZjLUIaB0QxJgiidPTlKFS7+WGId3aWQLjIdVWfiTZ3SWWhTOqjW+rw09gQ9zs435pyOHfPCrYsQwJITme2p8Er/8Cfkrli4Rm+0ZGXT/LBjahhqbFTKfadKY+UssdqBGhgyxid85fL80OuE4Ftjv3mykW1xV+DcrbJV851ZpTyGAFvG+U1JZ/i5xbKZ+4wr4eL9/ftOCKD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:SN1PR12MB0446; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0446; X-Forefront-PRVS: 0906E83A25 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(50466002)(48376002)(77096005)(47776003)(66066001)(229853001)(36756003)(86362001)(1096002)(42186005)(19580405001)(19580395003)(92566002)(6116002)(3846002)(586003)(5004730100002)(50986999)(76176999)(4326007)(189998001)(5003940100001)(2950100001)(2201001)(2906002)(5008740100001)(5001770100001)(81166005)(50226001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0446; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 23:8Y2X7TlCco3b8oBdwIxJqUh967qybgKPOxhduQLze1WRrx8OZG/xiu2p2W287jNNLPYZGoXqEwszs1G5NC1tX2RMLeRWuG+S9jVAL3Fz4oJXg7VI57Ghd8PQpyB2vqgtjCOgJjtDPDoDGrCnvH79HQjTFKGcFltVSTBEtAMD7XOKV89RD1rakVjIw+cX0v3n59aqAvHRkNPmpghTPPwz1rXbJz5+aIs4VzkqX2nDitt25vigRQpATOzrX/hiqKObkYX7kgZmjMtcFV3Mt/G0aDd3SvGuPhOa5CkbjkIv4cAuZlyZPt0KIEbWW1AJfgqVXceCqKeTDOyVybKKQhVh1eD4iaZjPmBYf76lSwtSGpa2OM+H6ELUm3oQV+gtzHiqVuwmWorD3h7RGx/hhsM0K6jbLNNl6hn4bNgkQ1CQRfe6eoFgUb9I7zpFqdmFjG/RglnXMFj90WjNyStI3B0V11AllXcc9MSdPZSTysXP1jiOQae3b6l/9GK5o2FrwCjA39tZpfpDAgzLEI7eVTTKVDP5L6ud8GBz9HYeaBuuLXf/aqbs6/E6VSpcGihGySd+c9rBoNCwnFXPG6ngbSC4eEKITsydByGPDIx+rGHskFxJPF6sHAOSwtEX8JS90ddUdABIb0MdozyLeaSnk9DrGrVKe4N7pI0Pbd4L3md6+yq8UtoJOBSp92i6zqYP4xlzlH2QgTSol9fShAg7H2lO80L33nN0HRwnoNfdQby35gNZDOm+DqC9LmIVeaCEEzdxVsRD+zsSABIOw/GGoVkT+WR0f7PBE4E6h4tY8Wd+CBLiN3aKBoALND4QQggNNseig74nWlq0ogwJjYrXnjmoXEpFIPJ9m+YXZqBf9NhIKc59J/Cqh18qiXE84li3pJI+uHG31KT+nVxm0dzZ3poa0w== X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 5:m5PR5EQEF8DQIvZEsFUJaso++pHBQk5K+sCPSK+nBpIVhoaUc5+zK1qSP6fHjznexBpjLc+roVk46sfx1MIk8KJtC38vr7QFRyn8t5Bu1i3IDWMhFQJydd56mQl7WKGgPe1AUox/n+zFSwsWWME9fA==; 24:uxg6SHfp3MlzeAJPCOxGCEUGjKzhJj3DWov6Gga4Tq5oper6UtWwR/RfYGxIJmGlPlVyca2/UE5DYxVBgH8PHnLov1qs14hUSX1reSHaLLw=; 20:y+UtcN5EJNTHvm+9wVf6lDzDLWaeLV/MuPkIu7v+EsEgogxyUjPi17MJyev3n47kG5Ow7BOmydT+Rari3c+WK1H3z5YwQ04sJmskP48/DGxhH36muRfsXuh01goatxgv0izCDv3Txtj2b22LqK2p6SvJCf1sCfbnRIOAeKpIQvuZbTGl7iMMsg6ZHYpCqqSKXBhtaJYuSTCl17wS1Qov15hmhh74Yaa8DhbrEdqIa7s8RXjEDJ7ikm8jl3CPBQPC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2016 12:50:11.4036 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0446 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 interface, amd_iommu_update_ga(), which allows KVM (SVM) to update existing posted interrupt IOMMU IRTE when load/unload vcpu. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/amd-iommu.h | 8 ++++++ 2 files changed, 78 insertions(+) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 8cdde339..1d17597 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -4330,4 +4330,74 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu) return 0; } + +static int +set_irte_ga(struct amd_iommu *iommu, unsigned int devid, + u64 base, int cpu, bool is_run) +{ + struct irq_remap_table *irt = get_irq_table(devid, false); + unsigned long flags; + int index; + + if (!irt) + return -ENODEV; + + spin_lock_irqsave(&irt->lock, flags); + + for (index = irt->min_index; index < MAX_IRQS_PER_TABLE; ++index) { + struct irte_ga *irte = amd_iommu_get_irte(irt, index); + + if (!irte->lo.fields_vapic.guest_mode) + continue; + + irte->hi.fields.ga_root_ptr = (base >> 12); + irte->lo.fields_vapic.destination = cpu; + irte->lo.fields_vapic.is_run = is_run; + barrier(); + } + + spin_unlock_irqrestore(&irt->lock, flags); + + iommu_flush_irt(iommu, devid); + iommu_completion_wait(iommu); + + return 0; +} + +int amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 ga_tag, + u64 base, bool is_run) +{ + unsigned long flags; + struct amd_iommu *iommu; + + if (amd_iommu_guest_ir < AMD_IOMMU_GUEST_IR_GA) + return 0; + + for_each_iommu(iommu) { + struct amd_ir_data *ir_data; + + spin_lock_irqsave(&iommu->ga_hash_lock, flags); + + hash_for_each_possible(iommu->ga_hash, ir_data, hnode, + AMD_IOMMU_GATAG(ga_tag, vcpu_id)) { + struct iommu_dev_data *dev_data; + + if (!ir_data) + break; + + dev_data = search_dev_data(ir_data->irq_2_irte.devid); + + if (!dev_data || !dev_data->guest_mode) + continue; + + set_irte_ga(iommu, ir_data->irq_2_irte.devid, + base, cpu, is_run); + } + + spin_unlock_irqrestore(&iommu->ga_hash_lock, flags); + } + + return 0; +} +EXPORT_SYMBOL(amd_iommu_update_ga); #endif diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index 36648fe..e52cee5 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -173,6 +173,9 @@ extern int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev, extern int amd_iommu_register_ga_log_notifier(int (*notifier)(int, int, int)); +extern int +amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 ga_tag, u64 base, bool is_run); + #else static inline int amd_iommu_detect(void) { return -ENODEV; } @@ -183,6 +186,11 @@ amd_iommu_register_ga_log_notifier(int (*notifier)(int, int, int)) return 0; } +static inline int +amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 ga_tag, u64 base, bool is_run) +{ + return 0; +} #endif #endif /* _ASM_X86_AMD_IOMMU_H */