From patchwork Tue Jul 16 16:40:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11046481 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 207D4746 for ; Tue, 16 Jul 2019 16:42:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E2D32860A for ; Tue, 16 Jul 2019 16:42:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0236728610; Tue, 16 Jul 2019 16:42:53 +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 836002860A for ; Tue, 16 Jul 2019 16:42:53 +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 1hnQVz-0003gA-Vm; Tue, 16 Jul 2019 16:41:19 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnQVy-0003fe-Jy for xen-devel@lists.xenproject.org; Tue, 16 Jul 2019 16:41:18 +0000 X-Inumbo-ID: 88071640-a7e8-11e9-8980-bc764e045a96 Received: from m9a0003g.houston.softwaregrp.com (unknown [15.124.64.68]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 88071640-a7e8-11e9-8980-bc764e045a96; Tue, 16 Jul 2019 16:41:17 +0000 (UTC) Received: FROM m9a0003g.houston.softwaregrp.com (15.121.0.190) BY m9a0003g.houston.softwaregrp.com WITH ESMTP; Tue, 16 Jul 2019 16:41:16 +0000 Received: from M9W0067.microfocus.com (2002:f79:be::f79:be) by M9W0067.microfocus.com (2002:f79:be::f79:be) 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:41:00 +0000 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (15.124.72.13) by M9W0067.microfocus.com (15.121.0.190) 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:41:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nlnSBen0K4moKmNz4ej4gWr33vQPsDIYWDGefFzPghyrrcVhTfZ9hCZ5xaCk+LFidCpzcxhujpMMe4nQ2w9eLxq8z3EDRVXRc2u9sbtEkTbPUvfVfQn91bWzL5t0XLfmNCpc4OXNUqu94SNfxaEsuuwzm4OwrLtGFJifBgmbQWvnRDvA4sLA9miNh9Arbd2m9BLexGNUXYfa2QuLsBdFRXiAhg00R8Qax1dHMGOBtxHyVmOXQNSWIbSlwLAap2qbEjH6s+ztBmTrHl7afq5+MSskGEkwYb1cdHKE0K86Pzrtrr6io2jqaZcqOQT2ZtbxxQ6IJE/TdcG/7Ts4UTFRzg== 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=pa4iProVUTIMZDm9RNd8EedGMivZSaJ2SgRN3Q/rP0g=; b=dQrtD0UHcok05WHlGCeBUoNYFc30cdllZM4ShsPVJp4gdYoW47WwsyeattW0ABD9BEN5NraZDO4U6fNLLKqOtgPCCE/xnWZATcjgajV0conbMIBLSXw516GMOIpUQJ/8mQkvGZu8xIpexNOcEoxJVUdOfAVPV583LUd+HyiCpnMSUmuCs8EAlPFx9asJ5LIBhMM56LOCBoz6QdX2AN7Gihd43yom9GyKjQU7SLNQv3WuvTZhcT3oBW/ytN8v/CCtGikLkvmujqPN1zanqvl5HtVvvAdQmsaEgyxL9tLKsBLIVZ6J6Pe1ib+qYd/5CnWyNEpevA733Zg/y4kc/X/Mbg== 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:40:58 +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:40:58 +0000 From: Jan Beulich To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH RFC v3 13/14] AMD/IOMMU: correct IRTE updating Thread-Index: AQHVO/U+AyGNFXRfrkOVPYzWeacU2A== Date: Tue, 16 Jul 2019 16:40:58 +0000 Message-ID: <9461810d-9538-ef84-005f-0398673577db@suse.com> 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: DB6PR0301CA0013.eurprd03.prod.outlook.com (2603:10a6:4:3e::23) 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: 77c115ff-d90a-4d21-f1e8-08d70a0c6169 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:5516; 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); 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: Z7Cjsah7ihoYkw10R7XDndpAdl1OLrLoFsKY9/2kO3LhRGMDEaX+x0WTKCVFR2XQdqMBvB7fjomQ7YMckXtswB3VHJK5zMWCPrNojJBp37MB1+5ru+0xWVayVovnbcN3wwVELnxRr1DKA1LCZE6Hl0citC2UrkdJ0wOmSGkvKcYlRWSjn2vHuSrAVnwyyk6e13ocOKqmu31x5llHhv4G4OFGjrzrvWNJuBlD2UmcUsNeC8YpvBujd2U4IPgBggrPv1tPv5I9Eb+XiZIf+8vdkQPFoB4ooTLNok43W48fT45focsrwFoE1nIaR6orwSqiIi4zjhlPTjIPF0Spfgh0DODO/cRdzjf6mrW0TGlXKxF1tfPjSr/7Rd3uoFLAdPfPckZouWNlfFu/7yleHlGPulep+Hkd/d5pCeVtxNomHw8= Content-ID: <824B74143555CA489C3963A1AF7A3429@namprd18.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 77c115ff-d90a-4d21-f1e8-08d70a0c6169 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jul 2019 16:40:58.7782 (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 RFC v3 13/14] AMD/IOMMU: correct IRTE updating 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 Flushing didn't get done along the lines of what the specification says. Mark entries to be updated as not remapped (which will result in interrupt requests to get target aborted, but the interrupts should be masked anyway at that point in time), issue the flush, and only then write the new entry. In update_intremap_entry_from_msi_msg() also fold the duplicate initial lock determination and acquire into just a single instance. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- RFC: Putting the flush invocations in loops isn't overly nice, but I don't think this can really be abused, since callers up the stack hold further locks. Nevertheless I'd like to ask for better suggestions. --- v3: Remove stale parts of description. Re-base. v2: Parts morphed into earlier patch. --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -207,9 +207,7 @@ static void update_intremap_entry(const .vector = vector, }; - ACCESS_ONCE(entry.ptr128->raw[0]) = 0; - /* Low half, in particular RemapEn, needs to be cleared first. */ - barrier(); + ASSERT(!entry.ptr128->full.remap_en); entry.ptr128->raw[1] = container_of(&full, union irte128, full)->raw[1]; /* High half needs to be set before low one (containing RemapEn). */ @@ -288,6 +286,20 @@ static int update_intremap_entry_from_io } entry = get_intremap_entry(iommu, req_id, offset); + + /* The RemapEn fields match for all formats. */ + while ( iommu->enabled && entry.ptr32->basic.remap_en ) + { + entry.ptr32->basic.remap_en = false; + spin_unlock(lock); + + spin_lock(&iommu->lock); + amd_iommu_flush_intremap(iommu, req_id); + spin_unlock(&iommu->lock); + + spin_lock(lock); + } + if ( fresh ) /* nothing */; else if ( !lo_update ) @@ -317,13 +329,6 @@ static int update_intremap_entry_from_io spin_unlock_irqrestore(lock, flags); - if ( iommu->enabled && !fresh ) - { - spin_lock_irqsave(&iommu->lock, flags); - amd_iommu_flush_intremap(iommu, req_id); - spin_unlock_irqrestore(&iommu->lock, flags); - } - set_rte_index(rte, offset); return 0; @@ -579,19 +584,27 @@ static int update_intremap_entry_from_ms req_id = get_dma_requestor_id(iommu->seg, bdf); alias_id = get_intremap_requestor_id(iommu->seg, bdf); + lock = get_intremap_lock(iommu->seg, req_id); + spin_lock_irqsave(lock, flags); + if ( msg == NULL ) { - lock = get_intremap_lock(iommu->seg, req_id); - spin_lock_irqsave(lock, flags); for ( i = 0; i < nr; ++i ) free_intremap_entry(iommu, req_id, *remap_index + i); spin_unlock_irqrestore(lock, flags); - goto done; - } - lock = get_intremap_lock(iommu->seg, req_id); + if ( iommu->enabled ) + { + spin_lock_irqsave(&iommu->lock, flags); + amd_iommu_flush_intremap(iommu, req_id); + if ( alias_id != req_id ) + amd_iommu_flush_intremap(iommu, alias_id); + spin_unlock_irqrestore(&iommu->lock, flags); + } + + return 0; + } - spin_lock_irqsave(lock, flags); dest_mode = (msg->address_lo >> MSI_ADDR_DESTMODE_SHIFT) & 0x1; delivery_mode = (msg->data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x1; vector = (msg->data >> MSI_DATA_VECTOR_SHIFT) & MSI_DATA_VECTOR_MASK; @@ -615,6 +628,22 @@ static int update_intremap_entry_from_ms } entry = get_intremap_entry(iommu, req_id, offset); + + /* The RemapEn fields match for all formats. */ + while ( iommu->enabled && entry.ptr32->basic.remap_en ) + { + entry.ptr32->basic.remap_en = false; + spin_unlock(lock); + + spin_lock(&iommu->lock); + amd_iommu_flush_intremap(iommu, req_id); + if ( alias_id != req_id ) + amd_iommu_flush_intremap(iommu, alias_id); + spin_unlock(&iommu->lock); + + spin_lock(lock); + } + update_intremap_entry(iommu, entry, vector, delivery_mode, dest_mode, dest); spin_unlock_irqrestore(lock, flags); @@ -634,16 +663,6 @@ static int update_intremap_entry_from_ms get_ivrs_mappings(iommu->seg)[alias_id].intremap_table); } -done: - if ( iommu->enabled ) - { - spin_lock_irqsave(&iommu->lock, flags); - amd_iommu_flush_intremap(iommu, req_id); - if ( alias_id != req_id ) - amd_iommu_flush_intremap(iommu, alias_id); - spin_unlock_irqrestore(&iommu->lock, flags); - } - return 0; }