From patchwork Mon Oct 1 19:44:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="z+cojfku"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCXM2sn6z9s3l for ; Tue, 2 Oct 2018 05:49:07 +1000 (AEST) Received: from localhost ([::1]:40346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g74Bl-0005lG-0v for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:49:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747b-0005G3-UV for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747Y-00056r-Le for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from mail-cys01nam02on0049.outbound.protection.outlook.com ([104.47.37.49]:27474 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747Y-000562-CI for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:44 -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:X-MS-Exchange-SenderADCheck; bh=gzXZynEfCcFIXtSokYuavKsqkYY61mCI+0SpExWdrIo=; b=z+cojfku1mFtQnaOCb0+zyJH3s0xyHncvactSwyfzcD2t9CJ4JxtTVA1J5e1cAiG59No8Z3eyLvjbfHnembmfeWP2nDv2le0m583W18XpaFam/yoj7wNZNWD585KkZ3VbYMmQu9qkdhzJoIp80WPNDWsYDYXFcP93Ufnwop08vY= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2601.namprd12.prod.outlook.com (20.176.116.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:27 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:27 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 1/9] x86_iommu: move the kernel-irqchip check in common code Thread-Index: AQHUWb8p6EmzxJfs5kuQCZxFETXr+g== Date: Mon, 1 Oct 2018 19:44:27 +0000 Message-ID: <1538423049-29524-2-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2601; 20:OUXoxWwCfU7fpin0j3bK7ZfzQ31+4+xMkQiFqgaaNE3rbRmRcRu+Gj3/rVmoMsHyt9yRipWy71Av5+8Lv8sLEOdeRsBO0BPCGHnCtcfqywWlrbDHTdU+x26aQjMC8tSSmHGoo3qAn+t1dl7Jn1JkFVd7pZ5CETZ1GHfrDZkGCJbo1rX5ZNhmDe2mxrde3ZUf2D7F8TuekgIi55qZOy8tlya2US7PSFalGzvLqZ9zAMw2sHySyl1fHEyib4EODCbe x-ms-office365-filtering-correlation-id: d94dd77a-ddf4-438c-16c4-08d627d64c11 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2601; x-ms-traffictypediagnostic: DM6PR12MB2601: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823302061)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2601; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2601; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(376002)(346002)(396003)(189003)(199004)(8936002)(52116002)(14454004)(26005)(3846002)(36756003)(71190400001)(39060400002)(99286004)(4326008)(71200400001)(6116002)(25786009)(186003)(6436002)(102836004)(486006)(6506007)(6486002)(446003)(11346002)(2616005)(316002)(476003)(105586002)(97736004)(2351001)(106356001)(386003)(76176011)(6916009)(2501003)(68736007)(54906003)(5250100002)(5660300001)(478600001)(66066001)(6512007)(2906002)(53936002)(7736002)(8676002)(305945005)(81156014)(5640700003)(81166006)(2900100001)(256004)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2601; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: SVZ3pxR9vbkbF74d9fIjSmFMsoISBY4qPv/wNPTnLPBKpxO803bKrCJObL+hu3yrNsgEE2DD5pm9THZhIEUuE2gqDm3YPdERoD7XOQYoDbbiMsMWtRpTyhjy+qHxZiOkET7mTTR9H4pL01lOJxHcuKX2LYPPybV2nR7KtaMOPNvhHZ8LEzepXUcBEbG42HHZeFLNks657jN8XpqRMhsIzFeLUWSzIUkkhZpcvSzXJldEbtZclZcrpKHRT6XLpILU3XyEU5eqTBrLUOyHOfYJ4M74AnoO82U15UaSEsPLqaDC7hvvYgt/pP/Xx2u0SYH525sF0qh6ndhaYIfqBJZohMuo+r+nmCs8tnIzHyRb3+c= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d94dd77a-ddf4-438c-16c4-08d627d64c11 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:27.6760 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2601 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.49 Subject: [Qemu-devel] [PATCH v5 1/9] x86_iommu: move the kernel-irqchip check in common code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Interrupt remapping needs kernel-irqchip={off|split} on both Intel and AMD platforms. Move the check in common place. Signed-off-by: Brijesh Singh Reviewed-by: Peter Xu Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit --- hw/i386/intel_iommu.c | 7 ------- hw/i386/x86-iommu.c | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3dfada1..84dbc20 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3248,13 +3248,6 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) { X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s); - /* Currently Intel IOMMU IR only support "kernel-irqchip={off|split}" */ - if (x86_iommu->intr_supported && kvm_irqchip_in_kernel() && - !kvm_irqchip_is_split()) { - error_setg(errp, "Intel Interrupt Remapping cannot work with " - "kernel-irqchip=on, please use 'split|off'."); - return false; - } if (s->intr_eim == ON_OFF_AUTO_ON && !x86_iommu->intr_supported) { error_setg(errp, "eim=on cannot be selected without intremap=on"); return false; diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c index 8a01a2d..7440cb8 100644 --- a/hw/i386/x86-iommu.c +++ b/hw/i386/x86-iommu.c @@ -25,6 +25,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "trace.h" +#include "sysemu/kvm.h" void x86_iommu_iec_register_notifier(X86IOMMUState *iommu, iec_notify_fn fn, void *data) @@ -94,6 +95,14 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp) return; } + /* Both Intel and AMD IOMMU IR only support "kernel-irqchip={off|split}" */ + if (x86_iommu->intr_supported && kvm_irqchip_in_kernel() && + !kvm_irqchip_is_split()) { + error_setg(errp, "Interrupt Remapping cannot work with " + "kernel-irqchip=on, please use 'split|off'."); + return; + } + if (x86_class->realize) { x86_class->realize(dev, errp); } From patchwork Mon Oct 1 19:44:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="cUt3LOMK"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCby4pbQz9s3l for ; Tue, 2 Oct 2018 05:52:14 +1000 (AEST) Received: from localhost ([::1]:40369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g74Em-0007uW-BF for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:52:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747b-0005G4-UY for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747Z-000578-3V for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from mail-cys01nam02on0049.outbound.protection.outlook.com ([104.47.37.49]:27474 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747Y-000562-RK for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:45 -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:X-MS-Exchange-SenderADCheck; bh=9EVwImUvHED04dy3o6nuiUHcvGeESbuKGITO7vjXpX0=; b=cUt3LOMKlH2N6VofcIbzBY2b/iAY7GcdqC8F2BQTgg+RiaMD14RYomn42kwh9UPNtkv+S9xG3pGiBRnWDSj6uPTLM7GqrC8B7GwaOOQFRuwn9HbJLkYylsSU+wkWe9ekP9jbYmtYNSqq2c9QHswzQSfz7zt4/RiphE30rkNYq2U= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2601.namprd12.prod.outlook.com (20.176.116.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:30 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:30 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 2/9] x86_iommu: move vtd_generate_msi_message in common file Thread-Index: AQHUWb8rZ4vdIZr/lEyz1U00FR++yg== Date: Mon, 1 Oct 2018 19:44:29 +0000 Message-ID: <1538423049-29524-3-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2601; 20:YIy33XxS6NvG8bGVyCbEERqXWV19zVnrPiDrZcLLR9hB0xO5IigayV0CRySbrhHefn3pvFfwEhP5dqdfZW7uPc8/1VDhJf1sPnQtGf1hV+qjhtUVE6GBgf39866vmRBijgEIDVXF3C/5jRZLOi3wRkFvuxcYhtZmKvXMxpPobYx9bwMLZ0E0nyUk5u21v2FnzRptrC1LcjoJ8lWNBYp3wW4MT0M9L7R7GIwsi/EkceQpmIJs5Jn4aBE34hSChQ4s x-ms-office365-filtering-correlation-id: 631413c8-0c69-4b74-ce7f-08d627d64d68 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2601; x-ms-traffictypediagnostic: DM6PR12MB2601: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823302061)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2601; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2601; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(376002)(346002)(396003)(189003)(199004)(8936002)(52116002)(14454004)(26005)(3846002)(36756003)(71190400001)(39060400002)(99286004)(4326008)(71200400001)(6116002)(25786009)(186003)(6436002)(102836004)(486006)(6506007)(6486002)(446003)(11346002)(2616005)(316002)(476003)(105586002)(97736004)(2351001)(106356001)(386003)(76176011)(6916009)(2501003)(68736007)(54906003)(5250100002)(5660300001)(478600001)(66066001)(6512007)(2906002)(53936002)(7736002)(8676002)(305945005)(81156014)(5640700003)(81166006)(2900100001)(256004)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2601; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: LywMBGKfugABY0DLlU3T5UgrleNVjSiFmdIfdEcUkpjo4kUcdQeM1W7Q9rEftFnOJWwEl2Q/5+97gVI15WEeI7Cip+HGtY69g/pvMlpsEFeJFKDZFvxxTfZ0lJK7SutXtbbwm+C/kbJWRD9JfsQaoOicKWYrP/Mlf0PBwhNfi9ne1BsTbJIOBUUBpM15snQC+mhIoa1chX805ksMESCK1l+5cICWqOaTTrmPWKHynOncLOJxRh3TAQDJnoydhyw3981QaIv2KQQC6XDuFBUWHSHWafkVtoRQ06MOZzuuB69mmbOVczeY3r/Aegre+Rygs0kHwIgylEDGUvfDiqfLcw5YSa+78JnM/0U+n543CW0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 631413c8-0c69-4b74-ce7f-08d627d64d68 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:30.0316 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2601 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.49 Subject: [Qemu-devel] [PATCH v5 2/9] x86_iommu: move vtd_generate_msi_message in common file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The vtd_generate_msi_message() in intel-iommu is used to construct a MSI Message from IRQ. A similar function will be needed when we add interrupt remapping support in amd-iommu. Moving the function in common file to avoid the code duplication. Rename it to x86_iommu_irq_to_msi_message(). There is no logic changes in the code flow. Signed-off-by: Brijesh Singh Suggested-by: Peter Xu Reviewed-by: Eduardo Habkost Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit --- hw/i386/intel_iommu.c | 32 +++------------------ hw/i386/x86-iommu.c | 24 ++++++++++++++++ include/hw/i386/intel_iommu.h | 59 -------------------------------------- include/hw/i386/x86-iommu.h | 66 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 87 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 84dbc20..014418b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2701,7 +2701,7 @@ static int vtd_irte_get(IntelIOMMUState *iommu, uint16_t index, /* Fetch IRQ information of specific IR index */ static int vtd_remap_irq_get(IntelIOMMUState *iommu, uint16_t index, - VTDIrq *irq, uint16_t sid) + X86IOMMUIrq *irq, uint16_t sid) { VTD_IR_TableEntry irte = {}; int ret = 0; @@ -2730,30 +2730,6 @@ static int vtd_remap_irq_get(IntelIOMMUState *iommu, uint16_t index, return 0; } -/* Generate one MSI message from VTDIrq info */ -static void vtd_generate_msi_message(VTDIrq *irq, MSIMessage *msg_out) -{ - VTD_MSIMessage msg = {}; - - /* Generate address bits */ - msg.dest_mode = irq->dest_mode; - msg.redir_hint = irq->redir_hint; - msg.dest = irq->dest; - msg.__addr_hi = irq->dest & 0xffffff00; - msg.__addr_head = cpu_to_le32(0xfee); - /* Keep this from original MSI address bits */ - msg.__not_used = irq->msi_addr_last_bits; - - /* Generate data bits */ - msg.vector = irq->vector; - msg.delivery_mode = irq->delivery_mode; - msg.level = 1; - msg.trigger_mode = irq->trigger_mode; - - msg_out->address = msg.msi_addr; - msg_out->data = msg.msi_data; -} - /* Interrupt remapping for MSI/MSI-X entry */ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, MSIMessage *origin, @@ -2763,7 +2739,7 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, int ret = 0; VTD_IR_MSIAddress addr; uint16_t index; - VTDIrq irq = {}; + X86IOMMUIrq irq = {}; assert(origin && translated); @@ -2842,8 +2818,8 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, */ irq.msi_addr_last_bits = addr.addr.__not_care; - /* Translate VTDIrq to MSI message */ - vtd_generate_msi_message(&irq, translated); + /* Translate X86IOMMUIrq to MSI message */ + x86_iommu_irq_to_msi_message(&irq, translated); out: trace_vtd_ir_remap_msi(origin->address, origin->data, diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c index 7440cb8..abc3c03 100644 --- a/hw/i386/x86-iommu.c +++ b/hw/i386/x86-iommu.c @@ -53,6 +53,30 @@ void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global, } } +/* Generate one MSI message from VTDIrq info */ +void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out) +{ + X86IOMMU_MSIMessage msg = {}; + + /* Generate address bits */ + msg.dest_mode = irq->dest_mode; + msg.redir_hint = irq->redir_hint; + msg.dest = irq->dest; + msg.__addr_hi = irq->dest & 0xffffff00; + msg.__addr_head = cpu_to_le32(0xfee); + /* Keep this from original MSI address bits */ + msg.__not_used = irq->msi_addr_last_bits; + + /* Generate data bits */ + msg.vector = irq->vector; + msg.delivery_mode = irq->delivery_mode; + msg.level = 1; + msg.trigger_mode = irq->trigger_mode; + + msg_out->address = msg.msi_addr; + msg_out->data = msg.msi_data; +} + /* Default X86 IOMMU device */ static X86IOMMUState *x86_iommu_default = NULL; diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index fbfedcb..ed4e758 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -66,8 +66,6 @@ typedef struct VTDIOTLBEntry VTDIOTLBEntry; typedef struct VTDBus VTDBus; typedef union VTD_IR_TableEntry VTD_IR_TableEntry; typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress; -typedef struct VTDIrq VTDIrq; -typedef struct VTD_MSIMessage VTD_MSIMessage; /* Context-Entry */ struct VTDContextEntry { @@ -197,63 +195,6 @@ union VTD_IR_MSIAddress { uint32_t data; }; -/* Generic IRQ entry information */ -struct VTDIrq { - /* Used by both IOAPIC/MSI interrupt remapping */ - uint8_t trigger_mode; - uint8_t vector; - uint8_t delivery_mode; - uint32_t dest; - uint8_t dest_mode; - - /* only used by MSI interrupt remapping */ - uint8_t redir_hint; - uint8_t msi_addr_last_bits; -}; - -struct VTD_MSIMessage { - union { - struct { -#ifdef HOST_WORDS_BIGENDIAN - uint32_t __addr_head:12; /* 0xfee */ - uint32_t dest:8; - uint32_t __reserved:8; - uint32_t redir_hint:1; - uint32_t dest_mode:1; - uint32_t __not_used:2; -#else - uint32_t __not_used:2; - uint32_t dest_mode:1; - uint32_t redir_hint:1; - uint32_t __reserved:8; - uint32_t dest:8; - uint32_t __addr_head:12; /* 0xfee */ -#endif - uint32_t __addr_hi; - } QEMU_PACKED; - uint64_t msi_addr; - }; - union { - struct { -#ifdef HOST_WORDS_BIGENDIAN - uint16_t trigger_mode:1; - uint16_t level:1; - uint16_t __resved:3; - uint16_t delivery_mode:3; - uint16_t vector:8; -#else - uint16_t vector:8; - uint16_t delivery_mode:3; - uint16_t __resved:3; - uint16_t level:1; - uint16_t trigger_mode:1; -#endif - uint16_t __resved1; - } QEMU_PACKED; - uint32_t msi_data; - }; -}; - /* When IR is enabled, all MSI/MSI-X data bits should be zero */ #define VTD_IR_MSI_DATA (0) diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h index 7c71fc7..2b22a57 100644 --- a/include/hw/i386/x86-iommu.h +++ b/include/hw/i386/x86-iommu.h @@ -22,6 +22,7 @@ #include "hw/sysbus.h" #include "hw/pci/pci.h" +#include "hw/pci/msi.h" #define TYPE_X86_IOMMU_DEVICE ("x86-iommu") #define X86_IOMMU_DEVICE(obj) \ @@ -35,6 +36,8 @@ typedef struct X86IOMMUState X86IOMMUState; typedef struct X86IOMMUClass X86IOMMUClass; +typedef struct X86IOMMUIrq X86IOMMUIrq; +typedef struct X86IOMMU_MSIMessage X86IOMMU_MSIMessage; typedef enum IommuType { TYPE_INTEL, @@ -78,6 +81,63 @@ struct X86IOMMUState { QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ }; +/* Generic IRQ entry information when interrupt remapping is enabled */ +struct X86IOMMUIrq { + /* Used by both IOAPIC/MSI interrupt remapping */ + uint8_t trigger_mode; + uint8_t vector; + uint8_t delivery_mode; + uint32_t dest; + uint8_t dest_mode; + + /* only used by MSI interrupt remapping */ + uint8_t redir_hint; + uint8_t msi_addr_last_bits; +}; + +struct X86IOMMU_MSIMessage { + union { + struct { +#ifdef HOST_WORDS_BIGENDIAN + uint32_t __addr_head:12; /* 0xfee */ + uint32_t dest:8; + uint32_t __reserved:8; + uint32_t redir_hint:1; + uint32_t dest_mode:1; + uint32_t __not_used:2; +#else + uint32_t __not_used:2; + uint32_t dest_mode:1; + uint32_t redir_hint:1; + uint32_t __reserved:8; + uint32_t dest:8; + uint32_t __addr_head:12; /* 0xfee */ +#endif + uint32_t __addr_hi; + } QEMU_PACKED; + uint64_t msi_addr; + }; + union { + struct { +#ifdef HOST_WORDS_BIGENDIAN + uint16_t trigger_mode:1; + uint16_t level:1; + uint16_t __resved:3; + uint16_t delivery_mode:3; + uint16_t vector:8; +#else + uint16_t vector:8; + uint16_t delivery_mode:3; + uint16_t __resved:3; + uint16_t level:1; + uint16_t trigger_mode:1; +#endif + uint16_t __resved1; + } QEMU_PACKED; + uint32_t msi_data; + }; +}; + /** * x86_iommu_get_default - get default IOMMU device * @return: pointer to default IOMMU device @@ -110,4 +170,10 @@ void x86_iommu_iec_register_notifier(X86IOMMUState *iommu, void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global, uint32_t index, uint32_t mask); +/** + * x86_iommu_irq_to_msi_message - Populate one MSIMessage from X86IOMMUIrq + * @X86IOMMUIrq: The IRQ information + * @out: Output MSI message + */ +void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *out); #endif From patchwork Mon Oct 1 19:44:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="Ial1O2Lu"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCSR4d7jz9s3l for ; Tue, 2 Oct 2018 05:45:43 +1000 (AEST) Received: from localhost ([::1]:40331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g748T-0005K1-1Y for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:45:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747b-0005G5-UX for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747Z-00057O-GE for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from mail-cys01nam02on0049.outbound.protection.outlook.com ([104.47.37.49]:27474 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747Z-000562-8p for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:45 -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:X-MS-Exchange-SenderADCheck; bh=AfcflibeFXpvuu0Ih8fmNk93S/D+M/KAuwlRsoBcnwc=; b=Ial1O2Lu/pSW7kbunneUBYqNi+IYyvcSDBs9bLwidj0Rz59lFBkJLdiVgWzVNXRXVM7OwoU8/j322JEQ4V6Eh4Ayx1lpbmwEL/7sClXxvg+Uqvq8SVbRvpAKSCTDEOMcvYLOhTSXFJMyHbhuQ7P5C6pNscxTrlmV/A3wb3lQs60= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2601.namprd12.prod.outlook.com (20.176.116.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:32 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:32 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 3/9] x86_iommu/amd: remove V=1 check from amdvi_validate_dte() Thread-Index: AQHUWb8sdRsth/BxOEiyPgtWnLrtnQ== Date: Mon, 1 Oct 2018 19:44:32 +0000 Message-ID: <1538423049-29524-4-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2601; 20:WTL88hrMQRk1TdmAzs9XlE13NWh7Tno+M7bGIWRUjw1L6E4a0XtrL+AbkaHwh9VsY3UWf9bf47PwztAfLLDTKSgN8+TNBr1paR/08K211xXRvi77rtz3ahQUMFuW1xML4jXGyB9Ug2o6oTohrptSKzbVzlX++dPxDut0MBk5gpm9ZGheU28XTAsDH4Q3VzeiCbht5tA2DmOIGHj/qZKJdXn74QjosVuW7hm3mOfwMhHs+/BIaBgoAhCdHd7AkEKt x-ms-office365-filtering-correlation-id: 33bec7bc-9048-4681-c9b8-08d627d64eda x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2601; x-ms-traffictypediagnostic: DM6PR12MB2601: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(163750095850)(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823302061)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2601; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2601; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(376002)(346002)(396003)(189003)(199004)(8936002)(52116002)(14454004)(26005)(3846002)(36756003)(71190400001)(39060400002)(99286004)(4326008)(71200400001)(6116002)(25786009)(186003)(6436002)(102836004)(486006)(6506007)(6486002)(446003)(11346002)(2616005)(316002)(476003)(105586002)(97736004)(2351001)(106356001)(386003)(76176011)(6916009)(2501003)(68736007)(54906003)(5250100002)(5660300001)(478600001)(66066001)(6512007)(2906002)(53936002)(7736002)(8676002)(305945005)(81156014)(5640700003)(81166006)(2900100001)(256004)(86362001)(14444005); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2601; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: nMctdWmA3l87oQg0pGJ8KH9Ns+lKQ2Uw7kaaWWlz3Dyosu5Wd5cbIpfZEFIPHwFtisL9VjICu0HXcCdnIeaPzwtHgizTbBXEOVu3hH9vM4wiqdn+ids1Jw88JaHNmdMGVCOH1qR+jIqKaelZoYI8Yte00W9kZIDZ+JdDBUxYL2sttjMQMgeux7F7GulM47JsMagZ62cA4hnxNmowBN0XmDFTh8c8m90JtFvT7KxgMD2/x+uUdUESY16AJrqIcmdXyU4bpH4u31rVx7LhEOxRhTsSQLI1Qd+jhi4OMF+QfdAE1yzaOCS6OHZFbTgrFi/I3SgbE1dv3a2plmKESmVh4KcV96rWlPzxhVomJxjy+3c= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33bec7bc-9048-4681-c9b8-08d627d64eda X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:32.3422 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2601 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.49 Subject: [Qemu-devel] [PATCH v5 3/9] x86_iommu/amd: remove V=1 check from amdvi_validate_dte() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently, the amdvi_validate_dte() assumes that a valid DTE will always have V=1. This is not true. The V=1 means that bit[127:1] are valid. A valid DTE can have IV=1 and V=0 (i.e address translation disabled and interrupt remapping enabled) Remove the V=1 check from amdvi_validate_dte(), make the caller responsible to check for V or IV bits. This also fixes a bug in existing code that when error is detected during the translation we'll fail the translation instead of assuming a passthrough mode. Signed-off-by: Brijesh Singh Reviewed-by: Peter Xu Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit --- hw/i386/amd_iommu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 1fd669f..7206bb0 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -807,7 +807,7 @@ static inline uint64_t amdvi_get_perms(uint64_t entry) AMDVI_DEV_PERM_SHIFT; } -/* a valid entry should have V = 1 and reserved bits honoured */ +/* validate that reserved bits are honoured */ static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid, uint64_t *dte) { @@ -820,7 +820,7 @@ static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid, return false; } - return dte[0] & AMDVI_DEV_VALID; + return true; } /* get a device table entry given the devid */ @@ -966,8 +966,12 @@ static void amdvi_do_translate(AMDVIAddressSpace *as, hwaddr addr, return; } - /* devices with V = 0 are not translated */ if (!amdvi_get_dte(s, devid, entry)) { + return; + } + + /* devices with V = 0 are not translated */ + if (!(entry[0] & AMDVI_DEV_VALID)) { goto out; } From patchwork Mon Oct 1 19:44:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="LUGehk0g"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCSP38fzz9s7T for ; Tue, 2 Oct 2018 05:45:41 +1000 (AEST) Received: from localhost ([::1]:40329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g748Q-0005Hc-Vp for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:45:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747a-0005FO-Sp for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747X-00056M-Lx for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:46 -0400 Received: from mail-co1nam03on0614.outbound.protection.outlook.com ([2a01:111:f400:fe48::614]:8231 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747W-00054U-Gf for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:42 -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:X-MS-Exchange-SenderADCheck; bh=x7BXA+uNftaMJ+NSLwmMLJdoEhJOrVldQrHWi7yBQQU=; b=LUGehk0gl2h1UZqmvSvftYOb9KYo/NTqtEJJ5tk0aiHEwGhnobYdwX5c+R2du67AB7G3wpEFpl576r3QTuhBRxQlGKbx8th43i/GwdtIpAEGgDBS+C8FQz4Tittjn9ANektw/QYrfIVtfZi7fCQW9PC3i9xrQblc4brtZXgWlwA= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2698.namprd12.prod.outlook.com (20.176.116.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:34 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:34 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 4/9] x86_iommu/amd: make the address space naming consistent with intel-iommu Thread-Index: AQHUWb8tM4UJDrNJPU+zrJHX6G/UHA== Date: Mon, 1 Oct 2018 19:44:34 +0000 Message-ID: <1538423049-29524-5-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2698; 20:igQAzihe/MkbIgCloUaCidgMhxSW15qAdcapnTixW6AyrIgj3LQtt0ozqturnQl+6ViftLZB1H2AW9npSegf+Y+FBj6YZj2nRkpNdx/YlUQW4UySc/1KOlU85SDOcU+1m3tzoBDNeT/Ik0axkt3VfzjlaVn0+T2oeJcJ9CoW3lNbbtuaa+lGBpcWNLbLn1ia1i/fcN5ErzAecEV8xyMmk6xSkgIBrLH0hX3efO7iw5yYS44vW2g9ftXq6mu14h6Q x-ms-office365-filtering-correlation-id: a5994939-cc27-457c-b1b9-08d627d65023 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2698; x-ms-traffictypediagnostic: DM6PR12MB2698: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(10201501046)(3231355)(944501410)(52105095)(3002001)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2698; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2698; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(376002)(366004)(396003)(199004)(189003)(2501003)(105586002)(5250100002)(305945005)(7736002)(106356001)(486006)(68736007)(39060400002)(446003)(6116002)(11346002)(3846002)(97736004)(6486002)(2616005)(6916009)(2351001)(476003)(81156014)(81166006)(2906002)(8676002)(5660300001)(8936002)(256004)(14444005)(186003)(36756003)(26005)(66066001)(6506007)(54906003)(4326008)(86362001)(102836004)(25786009)(76176011)(386003)(5640700003)(6512007)(52116002)(14454004)(53936002)(99286004)(71190400001)(71200400001)(478600001)(2900100001)(6436002)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2698; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: c8g0qu17NBRDU5Jizr3sPIgn9ESukvyHp+aVS3jBpfURJXORKTmzt0/puQjGlKRryNUOxta94iaOkQh0ZL2bNFwgOVa7/Qmu2oYe3gWDfPfpsmQsWE40hx00QB5T8y9D4Fr2HxYNICcFsB0+Mic9VLNH/Nk3nLEs1tJBikeiGpq2agerAXSenfO6AR7+fI4yB0Iik/SbPUwBYwku7n3qkf2gIdsWlNTBbrW5aIAs6Sr6IAMkHyKc4XVlzKggMHjqWdICM5uLragpsPNKpUUlXmS+K1BMBmkCdQp4vdkKJRYnYAMnX0csRTPSS+wi7e3c3/o5z0zxKqVGD6GlM3bOwpRZHK+IDkFnQKMdCjBfs/U= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5994939-cc27-457c-b1b9-08d627d65023 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:34.4357 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2698 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe48::614 Subject: [Qemu-devel] [PATCH v5 4/9] x86_iommu/amd: make the address space naming consistent with intel-iommu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" To be consistent with intel-iommu: - rename the address space to use '_' instead of '-' - update the memory region relationships Signed-off-by: Brijesh Singh Reviewed-by: Peter Xu Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit --- hw/i386/amd_iommu.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 7206bb0..4bec1c6 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -55,6 +55,7 @@ struct AMDVIAddressSpace { uint8_t bus_num; /* bus number */ uint8_t devfn; /* device function */ AMDVIState *iommu_state; /* AMDVI - one per machine */ + MemoryRegion root; /* AMDVI Root memory map region */ IOMMUMemoryRegion iommu; /* Device's address translation region */ MemoryRegion iommu_ir; /* Device's interrupt remapping region */ AddressSpace as; /* device's corresponding address space */ @@ -1032,8 +1033,9 @@ static IOMMUTLBEntry amdvi_translate(IOMMUMemoryRegion *iommu, hwaddr addr, static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) { + char name[128]; AMDVIState *s = opaque; - AMDVIAddressSpace **iommu_as; + AMDVIAddressSpace **iommu_as, *amdvi_dev_as; int bus_num = pci_bus_num(bus); iommu_as = s->address_spaces[bus_num]; @@ -1046,19 +1048,37 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) /* set up AMD-Vi region */ if (!iommu_as[devfn]) { + snprintf(name, sizeof(name), "amd_iommu_devfn_%d", devfn); + iommu_as[devfn] = g_malloc0(sizeof(AMDVIAddressSpace)); iommu_as[devfn]->bus_num = (uint8_t)bus_num; iommu_as[devfn]->devfn = (uint8_t)devfn; iommu_as[devfn]->iommu_state = s; - memory_region_init_iommu(&iommu_as[devfn]->iommu, - sizeof(iommu_as[devfn]->iommu), + amdvi_dev_as = iommu_as[devfn]; + + /* + * Memory region relationships looks like (Address range shows + * only lower 32 bits to make it short in length...): + * + * |-----------------+-------------------+----------| + * | Name | Address range | Priority | + * |-----------------+-------------------+----------+ + * | amdvi_root | 00000000-ffffffff | 0 | + * | amdvi_iommu | 00000000-ffffffff | 1 | + * |-----------------+-------------------+----------| + */ + memory_region_init_iommu(&amdvi_dev_as->iommu, + sizeof(amdvi_dev_as->iommu), TYPE_AMD_IOMMU_MEMORY_REGION, OBJECT(s), - "amd-iommu", UINT64_MAX); - address_space_init(&iommu_as[devfn]->as, - MEMORY_REGION(&iommu_as[devfn]->iommu), - "amd-iommu"); + "amd_iommu", UINT64_MAX); + memory_region_init(&amdvi_dev_as->root, OBJECT(s), + "amdvi_root", UINT64_MAX); + address_space_init(&amdvi_dev_as->as, &amdvi_dev_as->root, name); + memory_region_add_subregion_overlap(&amdvi_dev_as->root, 0, + MEMORY_REGION(&amdvi_dev_as->iommu), + 1); } return &iommu_as[devfn]->as; } From patchwork Mon Oct 1 19:44:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="wVIKhuMR"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCSP0pxBz9s55 for ; Tue, 2 Oct 2018 05:45:41 +1000 (AEST) Received: from localhost ([::1]:40330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g748Q-0005Hn-K4 for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:45:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747b-0005Fh-Ct for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747Z-00057f-UE for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from mail-by2nam05on061d.outbound.protection.outlook.com ([2a01:111:f400:fe52::61d]:56961 helo=NAM05-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747Z-00056Z-JQ for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:45 -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:X-MS-Exchange-SenderADCheck; bh=KMH3yLSLR6nJcUKphxkg6CONC5UwbX4Xle4k3XYb2fc=; b=wVIKhuMRKjzsbhmBsut7D2GDA1DsRyzGB0t08xhjWESw4uH6idOnTe2qghXFhndZJkfhh8T+E4lv/Ec9V59Ytr98uCuOaYecyfRfNGgoODlTqocHQ+0Cw1d/DJY2P+d8haQTHU1jClctpjtaVuBRyZuGdjAYfHvsEzi9/WN+A/Q= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2601.namprd12.prod.outlook.com (20.176.116.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:37 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:37 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 5/9] x86_iommu/amd: Prepare for interrupt remap support Thread-Index: AQHUWb8vpwcM/CZAyEeUsfFtma+MuA== Date: Mon, 1 Oct 2018 19:44:37 +0000 Message-ID: <1538423049-29524-6-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2601; 20:o/bzEfO/08ipIHApuR+GCx2cslsvxiCyWJiTsoL805Y/SP3ppYug2x19eZVm+TBJlDo2mP7qIXOo8jIrxsdWOG2bhPJJNn7epGjEQU/Jiv+RZb2GGzq9HEzQZ7fE3fAklHCy6JCeojNqJoRldX33FIfE9OmImcYHAJGKviJIZVt4srXcbt+gzt5HMRJ/NO+rZNxj67KAChqke/zDE8oS7XyQ4dx+m0c9wr7lbstud46/wxowlHp43RP/q9Jfn2Hw x-ms-office365-filtering-correlation-id: c2f1478c-28a7-4759-7ef6-08d627d651ad x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2601; x-ms-traffictypediagnostic: DM6PR12MB2601: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823302061)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2601; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2601; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(376002)(346002)(396003)(189003)(199004)(8936002)(52116002)(14454004)(26005)(3846002)(36756003)(71190400001)(39060400002)(99286004)(4326008)(71200400001)(6116002)(25786009)(186003)(6436002)(102836004)(486006)(6506007)(6486002)(446003)(11346002)(2616005)(316002)(476003)(105586002)(97736004)(2351001)(106356001)(386003)(76176011)(6916009)(2501003)(68736007)(54906003)(5250100002)(5660300001)(478600001)(66066001)(6512007)(2906002)(53936002)(7736002)(8676002)(305945005)(81156014)(5640700003)(81166006)(2900100001)(256004)(86362001)(14444005); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2601; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: nyx48jPoKoJmpgOUldV4WQBq4eCkSCi7zhZpGBLazYuWNGbgsN6Yt6oUQ4ZuCiU2/KH0Ah8ay09Kl9eWZvhRU3okZUobZsCpKofGNqao+0YyHd4Uqg4GMo9164cl4wZYuwY3A0gdyVK2ZvuNtLZAL2/SNT4cruN8XedRxuWut59QPRk6bYeEc0Acwnsb3g9tAsTcszOj6uVSs4nziDN5od6jZxk9Bv4lu7Ngk5SfkPDHLVZ0cCmzj8DNqeJeyi12AW59bVG8089wXVmkPqOhONa1JA7RS3Qo35HBIk1+IZMJrktsA1u7MwcrVcuUef+HoH/mYWa/2+lRjTB3NoxkjNktsoTUKl8BWi9bKzO5AP4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2f1478c-28a7-4759-7ef6-08d627d651ad X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:37.0656 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2601 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe52::61d Subject: [Qemu-devel] [PATCH v5 5/9] x86_iommu/amd: Prepare for interrupt remap support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Register the interrupt remapping callback and read/write ops for the amd-iommu-ir memory region. amd-iommu-ir is set to higher priority to ensure that this region won't be masked out by other memory regions. Signed-off-by: Brijesh Singh Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit Reviewed-by: Peter Xu --- hw/i386/amd_iommu.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 14 ++++++- hw/i386/trace-events | 5 +++ 3 files changed, 123 insertions(+), 2 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 4bec1c6..9118a75 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -26,6 +26,7 @@ #include "amd_iommu.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "hw/i386/apic_internal.h" #include "trace.h" /* used AMD-Vi MMIO registers */ @@ -1031,6 +1032,99 @@ static IOMMUTLBEntry amdvi_translate(IOMMUMemoryRegion *iommu, hwaddr addr, return ret; } +/* Interrupt remapping for MSI/MSI-X entry */ +static int amdvi_int_remap_msi(AMDVIState *iommu, + MSIMessage *origin, + MSIMessage *translated, + uint16_t sid) +{ + assert(origin && translated); + + trace_amdvi_ir_remap_msi_req(origin->address, origin->data, sid); + + if (!iommu || !X86_IOMMU_DEVICE(iommu)->intr_supported) { + memcpy(translated, origin, sizeof(*origin)); + goto out; + } + + if (origin->address & AMDVI_MSI_ADDR_HI_MASK) { + trace_amdvi_err("MSI address high 32 bits non-zero when " + "Interrupt Remapping enabled."); + return -AMDVI_IR_ERR; + } + + if ((origin->address & AMDVI_MSI_ADDR_LO_MASK) != APIC_DEFAULT_ADDRESS) { + trace_amdvi_err("MSI is not from IOAPIC."); + return -AMDVI_IR_ERR; + } + +out: + trace_amdvi_ir_remap_msi(origin->address, origin->data, + translated->address, translated->data); + return 0; +} + +static int amdvi_int_remap(X86IOMMUState *iommu, + MSIMessage *origin, + MSIMessage *translated, + uint16_t sid) +{ + return amdvi_int_remap_msi(AMD_IOMMU_DEVICE(iommu), origin, + translated, sid); +} + +static MemTxResult amdvi_mem_ir_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + int ret; + MSIMessage from = { 0, 0 }, to = { 0, 0 }; + uint16_t sid = AMDVI_IOAPIC_SB_DEVID; + + from.address = (uint64_t) addr + AMDVI_INT_ADDR_FIRST; + from.data = (uint32_t) value; + + trace_amdvi_mem_ir_write_req(addr, value, size); + + if (!attrs.unspecified) { + /* We have explicit Source ID */ + sid = attrs.requester_id; + } + + ret = amdvi_int_remap_msi(opaque, &from, &to, sid); + if (ret < 0) { + /* TODO: log the event using IOMMU log event interface */ + error_report_once("failed to remap interrupt from devid 0x%x", sid); + return MEMTX_ERROR; + } + + apic_get_class()->send_msi(&to); + + trace_amdvi_mem_ir_write(to.address, to.data); + return MEMTX_OK; +} + +static MemTxResult amdvi_mem_ir_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + return MEMTX_OK; +} + +static const MemoryRegionOps amdvi_ir_ops = { + .read_with_attrs = amdvi_mem_ir_read, + .write_with_attrs = amdvi_mem_ir_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + } +}; + static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) { char name[128]; @@ -1066,6 +1160,7 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) * |-----------------+-------------------+----------+ * | amdvi_root | 00000000-ffffffff | 0 | * | amdvi_iommu | 00000000-ffffffff | 1 | + * | amdvi_iommu_ir | fee00000-feefffff | 64 | * |-----------------+-------------------+----------| */ memory_region_init_iommu(&amdvi_dev_as->iommu, @@ -1076,6 +1171,13 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) memory_region_init(&amdvi_dev_as->root, OBJECT(s), "amdvi_root", UINT64_MAX); address_space_init(&amdvi_dev_as->as, &amdvi_dev_as->root, name); + memory_region_init_io(&amdvi_dev_as->iommu_ir, OBJECT(s), + &amdvi_ir_ops, s, "amd_iommu_ir", + AMDVI_INT_ADDR_SIZE); + memory_region_add_subregion_overlap(&amdvi_dev_as->root, + AMDVI_INT_ADDR_FIRST, + &amdvi_dev_as->iommu_ir, + 64); memory_region_add_subregion_overlap(&amdvi_dev_as->root, 0, MEMORY_REGION(&amdvi_dev_as->iommu), 1); @@ -1196,6 +1298,9 @@ static void amdvi_realize(DeviceState *dev, Error **err) return; } + /* Pseudo address space under root PCI bus. */ + pcms->ioapic_as = amdvi_host_dma_iommu(bus, s, AMDVI_IOAPIC_SB_DEVID); + /* set up MMIO */ memory_region_init_io(&s->mmio, OBJECT(s), &mmio_mem_ops, s, "amdvi-mmio", AMDVI_MMIO_SIZE); @@ -1229,6 +1334,7 @@ static void amdvi_class_init(ObjectClass *klass, void* data) dc->vmsd = &vmstate_amdvi; dc->hotpluggable = false; dc_class->realize = amdvi_realize; + dc_class->int_remap = amdvi_int_remap; /* Supported by the pc-q35-* machine types */ dc->user_creatable = true; } diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 8740305..4e7cc27 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -206,8 +206,18 @@ #define AMDVI_COMMAND_SIZE 16 -#define AMDVI_INT_ADDR_FIRST 0xfee00000 -#define AMDVI_INT_ADDR_LAST 0xfeefffff +#define AMDVI_INT_ADDR_FIRST 0xfee00000 +#define AMDVI_INT_ADDR_LAST 0xfeefffff +#define AMDVI_INT_ADDR_SIZE (AMDVI_INT_ADDR_LAST - AMDVI_INT_ADDR_FIRST + 1) +#define AMDVI_MSI_ADDR_HI_MASK (0xffffffff00000000ULL) +#define AMDVI_MSI_ADDR_LO_MASK (0x00000000ffffffffULL) + +/* SB IOAPIC is always on this device in AMD systems */ +#define AMDVI_IOAPIC_SB_DEVID PCI_BUILD_BDF(0, PCI_DEVFN(0x14, 0)) + +/* Interrupt remapping errors */ +#define AMDVI_IR_ERR 0x1 + #define TYPE_AMD_IOMMU_DEVICE "amd-iommu" #define AMD_IOMMU_DEVICE(obj)\ diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 9e6fc4d..41d533c 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -101,6 +101,11 @@ amdvi_mode_invalid(uint8_t level, uint64_t addr)"error: translation level 0x%"PR amdvi_page_fault(uint64_t addr) "error: page fault accessing guest physical address 0x%"PRIx64 amdvi_iotlb_hit(uint8_t bus, uint8_t slot, uint8_t func, uint64_t addr, uint64_t txaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64" hpa 0x%"PRIx64 amdvi_translation_result(uint8_t bus, uint8_t slot, uint8_t func, uint64_t addr, uint64_t txaddr) "devid: %02x:%02x.%x gpa 0x%"PRIx64" hpa 0x%"PRIx64 +amdvi_mem_ir_write_req(uint64_t addr, uint64_t val, uint32_t size) "addr 0x%"PRIx64" data 0x%"PRIx64" size 0x%"PRIx32 +amdvi_mem_ir_write(uint64_t addr, uint64_t val) "addr 0x%"PRIx64" data 0x%"PRIx64 +amdvi_ir_remap_msi_req(uint64_t addr, uint64_t data, uint8_t devid) "addr 0x%"PRIx64" data 0x%"PRIx64" devid 0x%"PRIx8 +amdvi_ir_remap_msi(uint64_t addr, uint64_t data, uint64_t addr2, uint64_t data2) "(addr 0x%"PRIx64", data 0x%"PRIx64") -> (addr 0x%"PRIx64", data 0x%"PRIx64")" +amdvi_err(const char *str) "%s" # hw/i386/vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p" From patchwork Mon Oct 1 19:44:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="3mISWcTz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCXR0ZBMz9s3l for ; Tue, 2 Oct 2018 05:49:11 +1000 (AEST) Received: from localhost ([::1]:40348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g74Bo-0005nj-Kz for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:49:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747b-0005G0-Sx for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747Z-00057Z-TR for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from mail-cys01nam02on0049.outbound.protection.outlook.com ([104.47.37.49]:27474 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747Z-000562-Ke for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:45 -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:X-MS-Exchange-SenderADCheck; bh=wPVMJa51a6AUh6Z6cDbjHLUORlpXW4E7K0zNHxVcGgY=; b=3mISWcTzN9rKFWw8o0VxiUtE67/QibNzSMHJosDgLO/LAjWHkQKnq67qQZWdSmDST6A7uYVaICJzmpVoUEwO1l52kf11U9iBlUdSnuOns3fAuhqdSIVag5naTeN0vWKj2Y8nwkUuQjTnyGjCo8fpDZueJzMcp5snsVkjfRufXOo= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2601.namprd12.prod.outlook.com (20.176.116.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:39 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:39 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 6/9] x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled Thread-Index: AQHUWb8wFUsHQ0/XFEqy9oZeGhkiPw== Date: Mon, 1 Oct 2018 19:44:39 +0000 Message-ID: <1538423049-29524-7-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2601; 20:8sAe6iBBiuF5jhZLXLEI8bnORWVXRYe52o5QCb+ophsKvDq5Pe9wIG0xk4iGj3VqGkjiXT4DM6uoMLsINutStXgjS4nRnb/EZ1w3zs37hsaOIE1lTRbV8YEbwWcaQOOa5hMZZs90/8dqBEkUf4TRxM3uko5e7Op5kFy3zB6WGIl9mYyHI36EbYK6Z9rNYgciH0iwbmRtVBoT+2kh9Bm4ut0mWVAtt04Tn0EBdvM/6In+6glWVNImvRjIPvMy1tLH x-ms-office365-filtering-correlation-id: b7c188ad-8af6-4bbf-f334-08d627d652ea x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2601; x-ms-traffictypediagnostic: DM6PR12MB2601: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823302061)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2601; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2601; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(376002)(346002)(396003)(189003)(199004)(8936002)(52116002)(14454004)(26005)(3846002)(36756003)(71190400001)(39060400002)(99286004)(4326008)(71200400001)(6116002)(25786009)(186003)(6436002)(102836004)(486006)(6506007)(6486002)(446003)(11346002)(2616005)(316002)(476003)(105586002)(97736004)(2351001)(106356001)(386003)(76176011)(6916009)(2501003)(68736007)(54906003)(5250100002)(5660300001)(966005)(478600001)(66066001)(6306002)(6512007)(2906002)(53936002)(7736002)(8676002)(305945005)(81156014)(5640700003)(81166006)(2900100001)(256004)(86362001)(14444005); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2601; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: t2DAC26ktjgkSZZ4dBep79I1i0pHlUw1puzmscwkKwl3d8BEYNy2n3/pge74Uxg4MlGVhLvSXFwmq2KtjFKqA4vPBnerkTNQLWkpGuUd6FUk3K/unpAv4JH8g+S8H7MoITExNc1CAcPmwfQVpnch4obJkYA62D7ronniQOV3fK/p8wPjRRg05PJ10BOOvYSta87sAmyjsaZV8NcESASy/7h3t2yCz1q0NGWbe9GAOwGVp1AKHGQDAyzcvYUaJ2oekQE1fYwC0VhtajX1/k1XewaHptmo51sgZabeND4k3fqhWoPR6FOR1P5Qb4B2pEMXDn8+6sC2hAD9Sl1dHGgJioedq4pfkG+VGEZ/zDslDX4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7c188ad-8af6-4bbf-f334-08d627d652ea X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:39.2411 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2601 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.49 Subject: [Qemu-devel] [PATCH v5 6/9] x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Emulate the interrupt remapping support when guest virtual APIC is not enabled. For more info Refer: AMD IOMMU spec Rev 3.0 - section 2.2.5.1 When VAPIC is not enabled, it uses interrupt remapping as defined in Table 20 and Figure 15 from IOMMU spec. Signed-off-by: Brijesh Singh Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit Reviewed-by: Peter Xu --- hw/i386/amd_iommu.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++- hw/i386/amd_iommu.h | 46 +++++++++++- hw/i386/trace-events | 7 ++ 3 files changed, 250 insertions(+), 2 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 9118a75..8e2f13c 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -28,6 +28,7 @@ #include "qemu/error-report.h" #include "hw/i386/apic_internal.h" #include "trace.h" +#include "hw/i386/apic-msidef.h" /* used AMD-Vi MMIO registers */ const char *amdvi_mmio_low[] = { @@ -1032,21 +1033,146 @@ static IOMMUTLBEntry amdvi_translate(IOMMUMemoryRegion *iommu, hwaddr addr, return ret; } +static int amdvi_get_irte(AMDVIState *s, MSIMessage *origin, uint64_t *dte, + union irte *irte, uint16_t devid) +{ + uint64_t irte_root, offset; + + irte_root = dte[2] & AMDVI_IR_PHYS_ADDR_MASK; + offset = (origin->data & AMDVI_IRTE_OFFSET) << 2; + + trace_amdvi_ir_irte(irte_root, offset); + + if (dma_memory_read(&address_space_memory, irte_root + offset, + irte, sizeof(*irte))) { + trace_amdvi_ir_err("failed to get irte"); + return -AMDVI_IR_GET_IRTE; + } + + trace_amdvi_ir_irte_val(irte->val); + + return 0; +} + +static int amdvi_int_remap_legacy(AMDVIState *iommu, + MSIMessage *origin, + MSIMessage *translated, + uint64_t *dte, + X86IOMMUIrq *irq, + uint16_t sid) +{ + int ret; + union irte irte; + + /* get interrupt remapping table */ + ret = amdvi_get_irte(iommu, origin, dte, &irte, sid); + if (ret < 0) { + return ret; + } + + if (!irte.fields.valid) { + trace_amdvi_ir_target_abort("RemapEn is disabled"); + return -AMDVI_IR_TARGET_ABORT; + } + + if (irte.fields.guest_mode) { + error_report_once("guest mode is not zero"); + return -AMDVI_IR_ERR; + } + + if (irte.fields.int_type > AMDVI_IOAPIC_INT_TYPE_ARBITRATED) { + error_report_once("reserved int_type"); + return -AMDVI_IR_ERR; + } + + irq->delivery_mode = irte.fields.int_type; + irq->vector = irte.fields.vector; + irq->dest_mode = irte.fields.dm; + irq->redir_hint = irte.fields.rq_eoi; + irq->dest = irte.fields.destination; + + return 0; +} + +static int __amdvi_int_remap_msi(AMDVIState *iommu, + MSIMessage *origin, + MSIMessage *translated, + uint64_t *dte, + X86IOMMUIrq *irq, + uint16_t sid) +{ + uint8_t int_ctl; + + int_ctl = (dte[2] >> AMDVI_IR_INTCTL_SHIFT) & 3; + trace_amdvi_ir_intctl(int_ctl); + + switch (int_ctl) { + case AMDVI_IR_INTCTL_PASS: + memcpy(translated, origin, sizeof(*origin)); + return 0; + case AMDVI_IR_INTCTL_REMAP: + break; + case AMDVI_IR_INTCTL_ABORT: + trace_amdvi_ir_target_abort("int_ctl abort"); + return -AMDVI_IR_TARGET_ABORT; + default: + trace_amdvi_ir_err("int_ctl reserved"); + return -AMDVI_IR_ERR; + } + + return amdvi_int_remap_legacy(iommu, origin, translated, dte, irq, sid); +} + /* Interrupt remapping for MSI/MSI-X entry */ static int amdvi_int_remap_msi(AMDVIState *iommu, MSIMessage *origin, MSIMessage *translated, uint16_t sid) { + int ret = 0; + uint64_t pass = 0; + uint64_t dte[4] = { 0 }; + X86IOMMUIrq irq = { 0 }; + uint8_t dest_mode, delivery_mode; + assert(origin && translated); + /* + * When IOMMU is enabled, interrupt remap request will come either from + * IO-APIC or PCI device. If interrupt is from PCI device then it will + * have a valid requester id but if the interrupt is from IO-APIC + * then requester id will be invalid. + */ + if (sid == X86_IOMMU_SID_INVALID) { + sid = AMDVI_IOAPIC_SB_DEVID; + } + trace_amdvi_ir_remap_msi_req(origin->address, origin->data, sid); - if (!iommu || !X86_IOMMU_DEVICE(iommu)->intr_supported) { + /* check if device table entry is set before we go further. */ + if (!iommu || !iommu->devtab_len) { memcpy(translated, origin, sizeof(*origin)); goto out; } + if (!amdvi_get_dte(iommu, sid, dte)) { + return -AMDVI_IR_ERR; + } + + /* Check if IR is enabled in DTE */ + if (!(dte[2] & AMDVI_IR_REMAP_ENABLE)) { + memcpy(translated, origin, sizeof(*origin)); + goto out; + } + + /* validate that we are configure with intremap=on */ + if (!X86_IOMMU_DEVICE(iommu)->intr_supported) { + trace_amdvi_err("Interrupt remapping is enabled in the guest but " + "not in the host. Use intremap=on to enable interrupt " + "remapping in amd-iommu."); + return -AMDVI_IR_ERR; + } + if (origin->address & AMDVI_MSI_ADDR_HI_MASK) { trace_amdvi_err("MSI address high 32 bits non-zero when " "Interrupt Remapping enabled."); @@ -1058,10 +1184,81 @@ static int amdvi_int_remap_msi(AMDVIState *iommu, return -AMDVI_IR_ERR; } + /* + * The MSI data register [10:8] are used to get the upstream interrupt type. + * + * See MSI/MSI-X format: + * https://pdfs.semanticscholar.org/presentation/9420/c279e942eca568157711ef5c92b800c40a79.pdf + * (page 5) + */ + delivery_mode = (origin->data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 7; + + switch (delivery_mode) { + case AMDVI_IOAPIC_INT_TYPE_FIXED: + case AMDVI_IOAPIC_INT_TYPE_ARBITRATED: + trace_amdvi_ir_delivery_mode("fixed/arbitrated"); + ret = __amdvi_int_remap_msi(iommu, origin, translated, dte, &irq, sid); + if (ret < 0) { + goto remap_fail; + } else { + /* Translate IRQ to MSI messages */ + x86_iommu_irq_to_msi_message(&irq, translated); + goto out; + } + break; + case AMDVI_IOAPIC_INT_TYPE_SMI: + error_report("SMI is not supported!"); + ret = -AMDVI_IR_ERR; + break; + case AMDVI_IOAPIC_INT_TYPE_NMI: + pass = dte[3] & AMDVI_DEV_NMI_PASS_MASK; + trace_amdvi_ir_delivery_mode("nmi"); + break; + case AMDVI_IOAPIC_INT_TYPE_INIT: + pass = dte[3] & AMDVI_DEV_INT_PASS_MASK; + trace_amdvi_ir_delivery_mode("init"); + break; + case AMDVI_IOAPIC_INT_TYPE_EINT: + pass = dte[3] & AMDVI_DEV_EINT_PASS_MASK; + trace_amdvi_ir_delivery_mode("eint"); + break; + default: + trace_amdvi_ir_delivery_mode("unsupported delivery_mode"); + ret = -AMDVI_IR_ERR; + break; + } + + if (ret < 0) { + goto remap_fail; + } + + /* + * The MSI address register bit[2] is used to get the destination + * mode. The dest_mode 1 is valid for fixed and arbitrated interrupts + * only. + */ + dest_mode = (origin->address >> MSI_ADDR_DEST_MODE_SHIFT) & 1; + if (dest_mode) { + trace_amdvi_ir_err("invalid dest_mode"); + ret = -AMDVI_IR_ERR; + goto remap_fail; + } + + if (pass) { + memcpy(translated, origin, sizeof(*origin)); + } else { + trace_amdvi_ir_err("passthrough is not enabled"); + ret = -AMDVI_IR_ERR; + goto remap_fail; + } + out: trace_amdvi_ir_remap_msi(origin->address, origin->data, translated->address, translated->data); return 0; + +remap_fail: + return ret; } static int amdvi_int_remap(X86IOMMUState *iommu, diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 4e7cc27..f73be48 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -217,7 +217,51 @@ /* Interrupt remapping errors */ #define AMDVI_IR_ERR 0x1 - +#define AMDVI_IR_GET_IRTE 0x2 +#define AMDVI_IR_TARGET_ABORT 0x3 + +/* Interrupt remapping */ +#define AMDVI_IR_REMAP_ENABLE 1ULL +#define AMDVI_IR_INTCTL_SHIFT 60 +#define AMDVI_IR_INTCTL_ABORT 0 +#define AMDVI_IR_INTCTL_PASS 1 +#define AMDVI_IR_INTCTL_REMAP 2 + +#define AMDVI_IR_PHYS_ADDR_MASK (((1ULL << 45) - 1) << 6) + +/* MSI data 10:0 bits (section 2.2.5.1 Fig 14) */ +#define AMDVI_IRTE_OFFSET 0x7ff + +/* Delivery mode of MSI data (same as IOAPIC deilver mode encoding) */ +#define AMDVI_IOAPIC_INT_TYPE_FIXED 0x0 +#define AMDVI_IOAPIC_INT_TYPE_ARBITRATED 0x1 +#define AMDVI_IOAPIC_INT_TYPE_SMI 0x2 +#define AMDVI_IOAPIC_INT_TYPE_NMI 0x4 +#define AMDVI_IOAPIC_INT_TYPE_INIT 0x5 +#define AMDVI_IOAPIC_INT_TYPE_EINT 0x7 + +/* Pass through interrupt */ +#define AMDVI_DEV_INT_PASS_MASK (1UL << 56) +#define AMDVI_DEV_EINT_PASS_MASK (1UL << 57) +#define AMDVI_DEV_NMI_PASS_MASK (1UL << 58) +#define AMDVI_DEV_LINT0_PASS_MASK (1UL << 62) +#define AMDVI_DEV_LINT1_PASS_MASK (1UL << 63) + +/* Interrupt remapping table fields (Guest VAPIC not enabled) */ +union irte { + uint32_t val; + struct { + uint32_t valid:1, + no_fault:1, + int_type:3, + rq_eoi:1, + dm:1, + guest_mode:1, + destination:8, + vector:8, + rsvd:8; + } fields; +}; #define TYPE_AMD_IOMMU_DEVICE "amd-iommu" #define AMD_IOMMU_DEVICE(obj)\ diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 41d533c..98150c9 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -106,6 +106,13 @@ amdvi_mem_ir_write(uint64_t addr, uint64_t val) "addr 0x%"PRIx64" data 0x%"PRIx6 amdvi_ir_remap_msi_req(uint64_t addr, uint64_t data, uint8_t devid) "addr 0x%"PRIx64" data 0x%"PRIx64" devid 0x%"PRIx8 amdvi_ir_remap_msi(uint64_t addr, uint64_t data, uint64_t addr2, uint64_t data2) "(addr 0x%"PRIx64", data 0x%"PRIx64") -> (addr 0x%"PRIx64", data 0x%"PRIx64")" amdvi_err(const char *str) "%s" +amdvi_ir_irte(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" offset 0x%"PRIx64 +amdvi_ir_irte_val(uint32_t data) "data 0x%"PRIx32 +amdvi_ir_err(const char *str) "%s" +amdvi_ir_intctl(uint8_t val) "int_ctl 0x%"PRIx8 +amdvi_ir_target_abort(const char *str) "%s" +amdvi_ir_delivery_mode(const char *str) "%s" +amdvi_ir_generate_msi_message(uint8_t vector, uint8_t delivery_mode, uint8_t dest_mode, uint8_t dest, uint8_t rh) "vector %d delivery-mode %d dest-mode %d dest-id %d rh %d" # hw/i386/vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p" From patchwork Mon Oct 1 19:44:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="M5BOIZJ/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCXN4dfdz9s55 for ; Tue, 2 Oct 2018 05:49:08 +1000 (AEST) Received: from localhost ([::1]:40345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g74Bm-0005l8-9s for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:49:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747a-0005FN-Sg for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747Y-00056y-VZ for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:46 -0400 Received: from mail-co1nam03on0614.outbound.protection.outlook.com ([2a01:111:f400:fe48::614]:8231 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747Y-00054U-O2 for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:44 -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:X-MS-Exchange-SenderADCheck; bh=Zw4JDCPaSnJTDs7z7xULj14nkL13bhGmbBxQoezBQ5c=; b=M5BOIZJ/V10XQUsPVETq6XAz9JuGL6wdVyU5jcgWzlQpHlHUYSWbb0PvDaE8XFPQ2GbnVg9CM3Zswp9pGu0YC7g6AKPGOrLvnP7TGaVatrhfH6pRsMrn2GB7w+3L2VAy+zSu0fhjtJx3D7qNvYF4w22G+yMVlAcxTTnauoQ1dg0= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2698.namprd12.prod.outlook.com (20.176.116.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Mon, 1 Oct 2018 19:44:42 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:42 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 7/9] i386: acpi: add IVHD device entry for IOAPIC Thread-Index: AQHUWb8ylx5+dbVT9EyGXspv53gy2g== Date: Mon, 1 Oct 2018 19:44:41 +0000 Message-ID: <1538423049-29524-8-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2698; 20:lVIRZUBgbl3y4chYcvvK1yNiFAeGZ0mckynnaDrNOD1rBhumRg/K5rK4wXEZvvR9LiFcnvR0ODhbV0cDtWjYyz/7/CUkQn8rk30eFZ7I7i3b3NtzbFVbXhwcxzRoQBjWBTJSKTqRJYXKy+i8gcmpBScdPu5y5MO1ZY6DO9ADZ6qRq2YZf9khKY/TJy3HggG280eoo5gZTNPv5am325nUtKHrc9+maIsZ1m7j+n8C1j9vovmLr8lYY7QKFp1ToMJk x-ms-office365-filtering-correlation-id: 34a1c95f-6746-4e8b-9d46-08d627d654a5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2698; x-ms-traffictypediagnostic: DM6PR12MB2698: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(10201501046)(3231355)(944501410)(4982022)(52105095)(3002001)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DM6PR12MB2698; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2698; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(376002)(366004)(396003)(199004)(189003)(2501003)(105586002)(5250100002)(305945005)(7736002)(106356001)(486006)(68736007)(39060400002)(446003)(6116002)(11346002)(3846002)(97736004)(6486002)(2616005)(6916009)(2351001)(476003)(81156014)(81166006)(2906002)(8676002)(5660300001)(8936002)(256004)(14444005)(186003)(36756003)(26005)(66066001)(6506007)(54906003)(4326008)(86362001)(102836004)(25786009)(76176011)(386003)(6306002)(5640700003)(6512007)(52116002)(14454004)(53936002)(99286004)(71190400001)(71200400001)(966005)(478600001)(2900100001)(6436002)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2698; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: /c4t9eSFD8pHCvyxDD8WEeLldZETJuDQo/+ys5QKFAeZpQi2yFKmNQCSbt6h604tnkWBQCExilZh8cp7HgYW2Wrw8RKh1p1FMyEm7CvARIb/1nE1gvXUjkVnXZhw+iobjtRIR+QoNh+AWH1IyMPmw17M+tPvu5DY05G9oq0+ubcHGkt4Cr3doHTlczMN9MPKvEUvJfoUJs5IrE6Ga5h8e3Jwop0WQhY8U88sZxM56fnYjVFKs5z8NlwZ07YhfEsuIuSXny+MNTeS9RO5EI6xjJWIli926rVdjFDKM81LO/YQ6keiTPgXa3XvAxmqlNe8d+ZCbEm/hR3OTAS/ysB1n+LGuGgeAMNBsXPmGOqWUj0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34a1c95f-6746-4e8b-9d46-08d627d654a5 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:41.9840 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2698 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe48::614 Subject: [Qemu-devel] [PATCH v5 7/9] i386: acpi: add IVHD device entry for IOAPIC X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When interrupt remapping is enabled, add a special IVHD device (type IOAPIC). Signed-off-by: Brijesh Singh Acked-by: Peter Xu Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit --- hw/i386/acpi-build.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 1599caa..1ef396d 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2467,9 +2467,12 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker) * IVRS table as specified in AMD IOMMU Specification v2.62, Section 5.2 * accessible here http://support.amd.com/TechDocs/48882_IOMMU.pdf */ +#define IOAPIC_SB_DEVID (uint64_t)PCI_BUILD_BDF(0, PCI_DEVFN(0x14, 0)) + static void build_amd_iommu(GArray *table_data, BIOSLinker *linker) { + int ivhd_table_len = 28; int iommu_start = table_data->len; AMDVIState *s = AMD_IOMMU_DEVICE(x86_iommu_get_default()); @@ -2491,8 +2494,16 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker) (1UL << 6) | /* PrefSup */ (1UL << 7), /* PPRSup */ 1); + + /* + * When interrupt remapping is supported, we add a special IVHD device + * for type IO-APIC. + */ + if (x86_iommu_get_default()->intr_supported) { + ivhd_table_len += 8; + } /* IVHD length */ - build_append_int_noprefix(table_data, 28, 2); + build_append_int_noprefix(table_data, ivhd_table_len, 2); /* DeviceID */ build_append_int_noprefix(table_data, s->devid, 2); /* Capability offset */ @@ -2516,6 +2527,21 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker) */ build_append_int_noprefix(table_data, 0x0000001, 4); + /* + * Add a special IVHD device type. + * Refer to spec - Table 95: IVHD device entry type codes + * + * Linux IOMMU driver checks for the special IVHD device (type IO-APIC). + * See Linux kernel commit 'c2ff5cf5294bcbd7fa50f7d860e90a66db7e5059' + */ + if (x86_iommu_get_default()->intr_supported) { + build_append_int_noprefix(table_data, + (0x1ull << 56) | /* type IOAPIC */ + (IOAPIC_SB_DEVID << 40) | /* IOAPIC devid */ + 0x48, /* special device */ + 8); + } + build_header(linker, table_data, (void *)(table_data->data + iommu_start), "IVRS", table_data->len - iommu_start, 1, NULL, NULL); } From patchwork Mon Oct 1 19:44:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 977444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="IxhZIPZO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PCc42VmVz9s3l for ; Tue, 2 Oct 2018 05:52:20 +1000 (AEST) Received: from localhost ([::1]:40372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g74Es-0007yT-1A for incoming@patchwork.ozlabs.org; Mon, 01 Oct 2018 15:52:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g747e-0005IA-Aj for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g747d-00059B-Hy for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:50 -0400 Received: from mail-co1nam03on0606.outbound.protection.outlook.com ([2a01:111:f400:fe48::606]:10238 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g747d-00058x-7L for qemu-devel@nongnu.org; Mon, 01 Oct 2018 15:44:49 -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:X-MS-Exchange-SenderADCheck; bh=9LJXJISJk3xwxHpNWq+bIonRni5UJzC0t1RM7Sc15pc=; b=IxhZIPZO2wW2TBY203o0hMrec5uZzPrmoOHK9n1ZzW9mA0xnzky1VyZ3tPU2Qk2/2Ta1DUq63jRUbsYRlCJ10jiGeyF5ZohaC7r8HWb7okoJQf9sql1rxcyfBTuYGxi75J/A7fOnCm0t2RRnkpNZZHmgQ8xiMKq8AnqBb3BXVV0= Received: from DM6PR12MB2682.namprd12.prod.outlook.com (20.176.116.31) by DM6PR12MB2649.namprd12.prod.outlook.com (20.176.116.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.22; Mon, 1 Oct 2018 19:44:45 +0000 Received: from DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8]) by DM6PR12MB2682.namprd12.prod.outlook.com ([fe80::7c34:f2e8:a8a9:cab8%3]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 19:44:45 +0000 From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 9/9] x86_iommu/amd: Enable Guest virtual APIC support Thread-Index: AQHUWb80ekuNPozivEu45sTQ5aeRXQ== Date: Mon, 1 Oct 2018 19:44:45 +0000 Message-ID: <1538423049-29524-10-git-send-email-brijesh.singh@amd.com> References: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> In-Reply-To: <1538423049-29524-1-git-send-email-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To DM6PR12MB2682.namprd12.prod.outlook.com (2603:10b6:5:4a::31) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR12MB2649; 20:U3kTwMdx5tbzaNynwOAmftYYLTPvfMZq2woce5Agh3IuGPaENL7vbU1CXRcBBiZzkC5E1KlJFMVt1F/CIWKDbjkumaeB625JtmiFVeApgYD5PXUzPCJXgfcEQFOWxQQ6x27jkGy80O0Z0WwfpEJzrPi5kAjWdmNqVL++bCXFkUBJK4+zIL0YUM8JwWlakaH4WAwdBO9XPnin+a2glMYWawCg1YvNLtjXgt31VRGfAO05uv02EqKgnGfMPPwAe86F x-ms-office365-filtering-correlation-id: d8f2058e-f0fb-44b7-5b6f-08d627d656d0 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DM6PR12MB2649; x-ms-traffictypediagnostic: DM6PR12MB2649: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(211171220733660)(767451399110)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(93006095)(93001095)(3002001)(10201501046)(3231355)(944501410)(52105095)(6055026)(149066)(150057)(6041310)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(201708071742011)(7699051); SRVR:DM6PR12MB2649; BCL:0; PCL:0; RULEID:; SRVR:DM6PR12MB2649; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(366004)(396003)(136003)(376002)(346002)(189003)(199004)(5250100002)(6486002)(54906003)(14454004)(3846002)(53936002)(386003)(6506007)(6116002)(105586002)(7736002)(11346002)(478600001)(106356001)(6436002)(2351001)(25786009)(5640700003)(486006)(66066001)(305945005)(6512007)(476003)(2616005)(52116002)(26005)(6916009)(2906002)(97736004)(39060400002)(2900100001)(446003)(186003)(76176011)(102836004)(2501003)(5660300001)(71200400001)(71190400001)(86362001)(68736007)(8676002)(36756003)(8936002)(99286004)(256004)(81166006)(81156014)(4326008)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR12MB2649; H:DM6PR12MB2682.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Oo7lIaW7uPw1QdePQdI+MJ8xfy37RjKuaTywvuWhBHGDHH9ym2inl/driFsa+O4gBZY6/zBqzjFVHGUAgWc9IUW+BCSmo/JeL1JvehvjIunG3xX5nk42gAdmf8V1+ok6k1B2r8ww5ef/UrDcJfQSDx7P1UOqVT0kvD1mFOGvqLw/7IyMg1+t5QA6+VIWmdQE6UqQ6VM9Qaf6PAyXscSlbLnNLZ++B0//jze3IeMSBGkI+1YTWSjITFRsMk7H3C5vx9PE3UU3t3N/1gadA8hi8O5wMCSWlmG/2rdCKtmKbmNv5jI9WJVt6dAc8O32+X6TvUtk4g+FECx2xco7fYs8Z1dXzMlpTqxiF+XPTwIy7KA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8f2058e-f0fb-44b7-5b6f-08d627d656d0 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 19:44:45.6957 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2649 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe48::606 Subject: [Qemu-devel] [PATCH v5 9/9] x86_iommu/amd: Enable Guest virtual APIC support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lendacky, Thomas" , "Singh, Brijesh" , Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , "Suthikulpanit, Suravee" , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Now that amd-iommu support interrupt remapping, enable the GASup in IVRS table and GASup in extended feature register to indicate that IOMMU support guest virtual APIC mode. GASup provides option to guest OS to make use of 128-bit IRTE. Note that the GAMSup is set to zero to indicate that amd-iommu does not support guest virtual APIC mode (aka AVIC) which would be used for the nested VMs. See Table 21 from IOMMU spec for interrupt virtualization controls Signed-off-by: Brijesh Singh Reviewed-by: Peter Xu Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit --- hw/i386/acpi-build.c | 3 ++- hw/i386/amd_iommu.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 1ef396d..236a20e 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2518,7 +2518,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker) build_append_int_noprefix(table_data, (48UL << 30) | /* HATS */ (48UL << 28) | /* GATS */ - (1UL << 2), /* GTSup */ + (1UL << 2) | /* GTSup */ + (1UL << 6), /* GASup */ 4); /* * Type 1 device entry reporting all devices diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 8061e9c..687fcd8 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -176,7 +176,7 @@ /* extended feature support */ #define AMDVI_EXT_FEATURES (AMDVI_FEATURE_PREFETCH | AMDVI_FEATURE_PPR | \ AMDVI_FEATURE_IA | AMDVI_FEATURE_GT | AMDVI_FEATURE_HE | \ - AMDVI_GATS_MODE | AMDVI_HATS_MODE) + AMDVI_GATS_MODE | AMDVI_HATS_MODE | AMDVI_FEATURE_GA) /* capabilities header */ #define AMDVI_CAPAB_FEATURES (AMDVI_CAPAB_FLAT_EXT | \