From patchwork Tue Jul 16 16:37:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11046471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D885746 for ; Tue, 16 Jul 2019 16:41:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0BDC2860A for ; Tue, 16 Jul 2019 16:41:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4DA628610; Tue, 16 Jul 2019 16:41:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5CF912860A for ; Tue, 16 Jul 2019 16:41:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnQUn-0003BX-I7; Tue, 16 Jul 2019 16:40:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnQUm-0002xq-1g for xen-devel@lists.xenproject.org; Tue, 16 Jul 2019 16:40:04 +0000 X-Inumbo-ID: 5a283b1c-a7e8-11e9-a042-cf304ed0ffc3 Received: from m4a0041g.houston.softwaregrp.com (unknown [15.124.2.87]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5a283b1c-a7e8-11e9-a042-cf304ed0ffc3; Tue, 16 Jul 2019 16:40:00 +0000 (UTC) Received: FROM m4a0041g.houston.softwaregrp.com (15.120.17.146) BY m4a0041g.houston.softwaregrp.com WITH ESMTP; Tue, 16 Jul 2019 16:39:59 +0000 Received: from M4W0335.microfocus.com (2002:f78:1193::f78:1193) by M4W0334.microfocus.com (2002:f78:1192::f78:1192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Tue, 16 Jul 2019 16:37:52 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (15.124.8.12) by M4W0335.microfocus.com (15.120.17.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Tue, 16 Jul 2019 16:37:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WrCpBH91lv+oukmhUXTGXMMr/D22A36kJbjkqMyoLgSsDLi4W1NeIuTFYnP88VYFkenmByQy6VCXLmixCyaMKe8HkocgFEBypDeN2KAx3iUZx7lmXAkfyqC14HKEbsm9fvb4SC5YrEkt/+XPwulZFZr4P9rHY5+Qe99gZ6nxp9LFKLVmPwysF1uSOsCDvoji5J1R/6qOtpEzZ1g4IDOj0KbI+HLvkqkTPZP1SbfJsQlHxhvm4tIpmXfIXbVrlVoZ+NGoEXqHr8U8hUVAqxKq9AiKrSH+80IzsTbVDQ/EnStGdRb7JEgM0IiUxOUEQGEyXz/5VFgRLitH8GR3Oc0qxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pbmVG+xtC/ndA7O3oJS9moz976STYe8Tu1Ukyrkn5Io=; b=m7WLTDx1OqelvvVXvvleOfLYiQcuWgtWoAQzdiJrmk0QJgxA2A5oOaue2qYMbO4XPEuF2qXArPN5HVnJP84jWpdFr8q7afOuZfjJcu8J8cn+mE1wudfErktgTSKRnQjDCHWvOsVMkJqYj7sGAiySAeXlP8rQ7JWzEFnAtLuo2rac6u3sEa1sDlTqD04+m/0u6RTCQYwUNhSRL82ENBu8PY0bHHNH+1rEqi7Aoynx/9apP2egMuPz8J5iiuKnK2CCJhLoYfQnwILMIJmRDy3GbquC3vHHdx3IgvR8Mepxhq6rCjcSWNPj08P8xGHp7EN7ydr6A1/1t+iRegxiaiC65g== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none Received: from DM6PR18MB3401.namprd18.prod.outlook.com (10.255.174.218) by DM6PR18MB3164.namprd18.prod.outlook.com (10.255.172.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.14; Tue, 16 Jul 2019 16:37:52 +0000 Received: from DM6PR18MB3401.namprd18.prod.outlook.com ([fe80::1fe:35f6:faf3:78c7]) by DM6PR18MB3401.namprd18.prod.outlook.com ([fe80::1fe:35f6:faf3:78c7%7]) with mapi id 15.20.2073.012; Tue, 16 Jul 2019 16:37:52 +0000 From: Jan Beulich To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3 07/14] AMD/IOMMU: pass IOMMU to {get,free,update}_intremap_entry() Thread-Index: AQHVO/TPRJnsmnG7IEW/OeCiigfJ2A== Date: Tue, 16 Jul 2019 16:37:51 +0000 Message-ID: References: <6272c301-a905-38cf-dd1a-645f3d703241@suse.com> In-Reply-To: <6272c301-a905-38cf-dd1a-645f3d703241@suse.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: DB6PR07CA0053.eurprd07.prod.outlook.com (2603:10a6:6:2a::15) To DM6PR18MB3401.namprd18.prod.outlook.com (2603:10b6:5:1cc::26) authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@suse.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [87.234.252.170] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e3ca135e-fd3b-46bd-eabf-08d70a0bf214 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:DM6PR18MB3164; x-ms-traffictypediagnostic: DM6PR18MB3164: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3383; x-forefront-prvs: 0100732B76 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(346002)(39860400002)(136003)(376002)(396003)(366004)(199004)(189003)(31696002)(14444005)(256004)(6512007)(36756003)(86362001)(53936002)(8676002)(6436002)(486006)(6486002)(66556008)(66946007)(66476007)(64756008)(5640700003)(66446008)(6506007)(66066001)(2906002)(446003)(6916009)(31686004)(2616005)(476003)(81156014)(386003)(11346002)(81166006)(3846002)(2351001)(71190400001)(80792005)(2501003)(186003)(4326008)(26005)(8936002)(52116002)(305945005)(25786009)(68736007)(54906003)(14454004)(316002)(478600001)(7736002)(102836004)(99286004)(76176011)(71200400001)(5660300002)(6116002)(15650500001)(142933001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR18MB3164; H:DM6PR18MB3401.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: suse.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: PSdByxmysgb0cYtT3J+sDNSuiEd3lJJipMm1ys2CLY5sq8lqniOR6kYItOQzvHSgMaFlSX6+X1iT/vCUaauQXWrAZb8Dskd2TYiFpAcFmVRx4zAwrTr8RkjikHntlMzSdl352SxSk8L/azQcA7ofrgcPrtey/8BVQrGLkM8XirPv13aLeHVolCGNKcwjb2CdJM28S+EzN3U+IqQGvFvPpTyDanylueZuy9vykPGW6qXEiPm60OhotJB0RjHaz2vieSjAS9Af24mmmycQoCTNaMKGnni8tx5JhITgxymCZ0IY7hgy4baUw8/Qx4SzoB9th3RR/ZdInK/1yKmhYCgI+zd2zmd4dHXQoMRSza398IQmte/kk0TtTcWEiU8ZYS77n58HjgGkud8RoL/Eg2H9jBN1fVLMLNAYSDk96z4+i18= Content-ID: <2CA212B55FC9B648A8B7145F8C4EF13F@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e3ca135e-fd3b-46bd-eabf-08d70a0bf214 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jul 2019 16:37:51.9439 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JBeulich@suse.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR18MB3164 X-OriginatorOrg: suse.com Subject: [Xen-devel] [PATCH v3 07/14] AMD/IOMMU: pass IOMMU to {get, free, update}_intremap_entry() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Brian Woods , Suravee Suthikulpanit Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The functions will want to know IOMMU properties (specifically the IRTE size) subsequently. Rather than introducing a second error path bogusly returning -E... from amd_iommu_read_ioapic_from_ire(), also change the existing one to follow VT-d in returning the raw (untranslated) IO-APIC RTE. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper Acked-by: Brian Woods --- v3: New. --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -123,11 +123,11 @@ static unsigned int alloc_intremap_entry return slot; } -static union irte_ptr get_intremap_entry(unsigned int seg, unsigned int bdf, - unsigned int index) +static union irte_ptr get_intremap_entry(const struct amd_iommu *iommu, + unsigned int bdf, unsigned int index) { union irte_ptr table = { - .ptr = get_ivrs_mappings(seg)[bdf].intremap_table + .ptr = get_ivrs_mappings(iommu->seg)[bdf].intremap_table }; ASSERT(table.ptr && (index < INTREMAP_ENTRIES)); @@ -137,18 +137,19 @@ static union irte_ptr get_intremap_entry return table; } -static void free_intremap_entry(unsigned int seg, unsigned int bdf, - unsigned int index) +static void free_intremap_entry(const struct amd_iommu *iommu, + unsigned int bdf, unsigned int index) { - union irte_ptr entry = get_intremap_entry(seg, bdf, index); + union irte_ptr entry = get_intremap_entry(iommu, bdf, index); ACCESS_ONCE(entry.ptr32->raw[0]) = 0; - __clear_bit(index, get_ivrs_mappings(seg)[bdf].intremap_inuse); + __clear_bit(index, get_ivrs_mappings(iommu->seg)[bdf].intremap_inuse); } -static void update_intremap_entry(union irte_ptr entry, unsigned int vector, - unsigned int int_type, +static void update_intremap_entry(const struct amd_iommu *iommu, + union irte_ptr entry, + unsigned int vector, unsigned int int_type, unsigned int dest_mode, unsigned int dest) { struct irte_basic basic = { @@ -212,7 +213,7 @@ static int update_intremap_entry_from_io lo_update = 1; } - entry = get_intremap_entry(iommu->seg, req_id, offset); + entry = get_intremap_entry(iommu, req_id, offset); if ( !lo_update ) { /* @@ -223,7 +224,7 @@ static int update_intremap_entry_from_io vector = entry.ptr32->basic.vector; delivery_mode = entry.ptr32->basic.int_type; } - update_intremap_entry(entry, vector, delivery_mode, dest_mode, dest); + update_intremap_entry(iommu, entry, vector, delivery_mode, dest_mode, dest); spin_unlock_irqrestore(lock, flags); @@ -288,8 +289,8 @@ int __init amd_iommu_setup_ioapic_remapp spin_lock_irqsave(lock, flags); offset = alloc_intremap_entry(seg, req_id, 1); BUG_ON(offset >= INTREMAP_ENTRIES); - entry = get_intremap_entry(iommu->seg, req_id, offset); - update_intremap_entry(entry, vector, + entry = get_intremap_entry(iommu, req_id, offset); + update_intremap_entry(iommu, entry, vector, delivery_mode, dest_mode, dest); spin_unlock_irqrestore(lock, flags); @@ -413,7 +414,7 @@ unsigned int amd_iommu_read_ioapic_from_ idx = ioapic_id_to_index(IO_APIC_ID(apic)); if ( idx == MAX_IO_APICS ) - return -EINVAL; + return val; offset = ioapic_sbdf[idx].pin_2_idx[pin]; @@ -422,9 +423,13 @@ unsigned int amd_iommu_read_ioapic_from_ u16 bdf = ioapic_sbdf[idx].bdf; u16 seg = ioapic_sbdf[idx].seg; u16 req_id = get_intremap_requestor_id(seg, bdf); - union irte_ptr entry = get_intremap_entry(seg, req_id, offset); + const struct amd_iommu *iommu = find_iommu_for_device(seg, bdf); + union irte_ptr entry; + if ( !iommu ) + return val; ASSERT(offset == (val & (INTREMAP_ENTRIES - 1))); + entry = get_intremap_entry(iommu, req_id, offset); val &= ~(INTREMAP_ENTRIES - 1); val |= MASK_INSR(entry.ptr32->basic.int_type, IO_APIC_REDIR_DELIV_MODE_MASK); @@ -454,7 +459,7 @@ static int update_intremap_entry_from_ms lock = get_intremap_lock(iommu->seg, req_id); spin_lock_irqsave(lock, flags); for ( i = 0; i < nr; ++i ) - free_intremap_entry(iommu->seg, req_id, *remap_index + i); + free_intremap_entry(iommu, req_id, *remap_index + i); spin_unlock_irqrestore(lock, flags); goto done; } @@ -479,8 +484,8 @@ static int update_intremap_entry_from_ms *remap_index = offset; } - entry = get_intremap_entry(iommu->seg, req_id, offset); - update_intremap_entry(entry, vector, delivery_mode, dest_mode, dest); + entry = get_intremap_entry(iommu, req_id, offset); + update_intremap_entry(iommu, entry, vector, delivery_mode, dest_mode, dest); spin_unlock_irqrestore(lock, flags); *data = (msg->data & ~(INTREMAP_ENTRIES - 1)) | offset; @@ -594,12 +599,13 @@ void amd_iommu_read_msi_from_ire( const struct pci_dev *pdev = msi_desc->dev; u16 bdf = pdev ? PCI_BDF2(pdev->bus, pdev->devfn) : hpet_sbdf.bdf; u16 seg = pdev ? pdev->seg : hpet_sbdf.seg; + const struct amd_iommu *iommu = _find_iommu_for_device(seg, bdf); union irte_ptr entry; - if ( IS_ERR_OR_NULL(_find_iommu_for_device(seg, bdf)) ) + if ( IS_ERR_OR_NULL(iommu) ) return; - entry = get_intremap_entry(seg, get_dma_requestor_id(seg, bdf), offset); + entry = get_intremap_entry(iommu, get_dma_requestor_id(seg, bdf), offset); if ( msi_desc->msi_attrib.type == PCI_CAP_ID_MSI ) {