From patchwork Thu Feb 2 14:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13126463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49B12C05027 for ; Thu, 2 Feb 2023 16:02:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C334A6B0071; Thu, 2 Feb 2023 11:02:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE3BA6B0073; Thu, 2 Feb 2023 11:02:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A849F6B0074; Thu, 2 Feb 2023 11:02:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 974A36B0071 for ; Thu, 2 Feb 2023 11:02:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5AACDC0F79 for ; Thu, 2 Feb 2023 16:02:46 +0000 (UTC) X-FDA: 80422819932.27.EE4D2B8 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf23.hostedemail.com (Postfix) with ESMTP id 7E7DE14001D for ; Thu, 2 Feb 2023 16:02:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=FGER7ivR; spf=none (imf23.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675353762; a=rsa-sha256; cv=none; b=IP7e0S8bFe8+Ckw9N970csTc3uXohQsngivC+a069EaH/Y+L8lt5hsnJvUtHn6xfuvFSoJ o8gR4O/PUzkvlo5yOz7NDIwWdlxRLBCBXRhfv2B8hxvpI7YSUGp0+Iqb2bXNaoxs5s44G5 Ic3yJdewSMYzW27h09z4Uao+pZt/Dd0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=FGER7ivR; spf=none (imf23.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675353762; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=ojAeZWZTS/q5DGsRDsr4pNfeq1PMMFo32HAk+mO3778=; b=VeiB/2obZPn75fM6bPanDN1Qjns6lNW2VVP/WDCBYtp+RYrIUgb7V+ORDn8He3gqeF7kjv CiNpe+AhsieZKGqzmtQHjxxKnioaW/1v9EnCRWoweTjNS286QEgwqRV4dBH6moJroiT0YL 2ZltlRZJH9JHCbg7CCcxupSyxXUNn+w= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=ojAeZWZTS/q5DGsRDsr4pNfeq1PMMFo32HAk+mO3778=; b=FGER7ivRI9nqOjWL8qnZWxwDNb 39pm5f8BWqpO7fYq6QibN6ZMQNOeNsT4Tg9w7Vo+6gECc8/1oeRV2ABFtChGZ49limW+d/1pIgGMI 6wZgZ5jkMGHagoUdy5N0VpZWWjsJ3arChLUNp8epccoypGY5Q5iFN52IwwNXOvdwaeXRq9dSRv67L jexzaT3xActH30W/+i3QbicxHZqQOv425gL5Sur5FXyTLpHPwvrtDjg8n9dBZqrcjfi6sgZ4wuAdR HndfRFQO3mBLVi9gwLq1o2+rRTAz/XzyLKaQsYHafQ62KU2RwBgaEtKPlqLleGgm1mDqKHiB31COp qIdnlelA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pNbVU-005CFv-21; Thu, 02 Feb 2023 15:28:12 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3AE643021D4; Thu, 2 Feb 2023 16:28:45 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 96E8D23F31FB6; Thu, 2 Feb 2023 16:28:40 +0100 (CET) Message-ID: <20230202152655.564329626@infradead.org> User-Agent: quilt/0.66 Date: Thu, 02 Feb 2023 15:50:36 +0100 From: Peter Zijlstra To: torvalds@linux-foundation.org Cc: corbet@lwn.net, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, mark.rutland@arm.com, catalin.marinas@arm.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, joro@8bytes.org, suravee.suthikulpanit@amd.com, robin.murphy@arm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, Arnd Bergmann , Herbert Xu , davem@davemloft.net, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, Andrew Morton , vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-crypto@vger.kernel.org, Vasant Hegde Subject: [PATCH v2 06/10] x86,amd_iommu: Replace cmpxchg_double() References: <20230202145030.223740842@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 7E7DE14001D X-Rspamd-Server: rspam01 X-Stat-Signature: ezkagao95kd3kg47je4gthtas8ag8cih X-HE-Tag: 1675353762-923385 X-HE-Meta: U2FsdGVkX19ISJB6mnjGhf8ggmbxMqobUDIvx01a9zhv3528jam8szoU3p2aYBaCfkjumb61LG8elQXCg53aDn7cy29dktAGpIudbAPUMVM8X958lK2mIeayac1MKr9uO58wWLCtpKSEO0XZo5170Xk9YJDnXgihqktREpBJEgxgY/OBaJ+XNEtKO4hqLl/j+3J1tpJDk2/cleucxUEtcyUzpFonr3Xh0Ia+Md6cxoAN/CL3b2LKy0AaD3ROAo0+87xbxuDXSdZCEhJGgyrfMFWVSf2RhukF39JYKC7ug5N+FBzmpnQLddDp3s0wZNzjp4IcrJwkBAE4nFvuI+BGOVUdWrlcU7U5kLeUnSoxBpsRrLxVkcbzuUgkcWpPtDDQrY+B4bGwPwb3Y/XI5gSE7DRwdo1HguRS5xnsSsqPdwQRcuNoMpfGsCJd1lfD8kYs2HlIsSL79FKoL12P5mM+7gNlJd/t/cU5PeOYS+FEgTrgD39/0E/Tnz/jjsTSv32oCl6THsoPBO8uOQ2X02VybY9t5Dc1OVRD61vEo1dSuBmAmvw4/kxnM5M0NUPJnwWkWUPbbkkZ537elbOqzMkFLDO/sGKpn9aUNo/epSZqrMhQY2ZCIcQZEeu6quCGexkD7WcFJl15zAIJ03YvLl6vpABHagSWpGIcZNttKkRO4P3NCuWU5Vv7fb7+eEQ69lApKtQ8cZbSETJMT+ihULCqfRzWxZtKKo2iPI83idTF5a8qh92g1MPD/v3B8i5jKtb+SPbYuPFue+TKfmfHg0kbJ3+QT0HFC0X76LrCHvh8bXkpLqYp3YK2RgblW4Fkg37ahaPgJnDprZ1U7OHRRGasHi3LTqnvQv4selQT7r0GnkDZe2J36xIw4zyGWHOT/Kk7ilMBefhluTciViXAKIT++p8hO8YgzIN2PEHa830eY3qiVaXEpC3EnFFHuQGMY+A6mbvRTXaf3a3LEkBWQPv yWfu34eA z/dP6gVNzmAquK/TCNDvJdfN62n/xt8FNmonM9+oq82e4yyQ2/QRiZUhV3kBOpHgOQdw9tWcVxnrB+FsbJcsVxUCGOCv5uvyuufjAhyyWdf0pgJorK8X7UAb0vt5hrTk/scuekf4PQKxtgQDWQYmuV30PkqVZ7/QslSIfrV5bm//j+qGkKyU3cEukqyR24RhwhZaQXTX1NddnRHKSi7mXS+9wl5KSDcZpCj/aTZQPef9a3JHUr7oJztGdirVMZNBBPDK/qwCTaqhIIr19pqhJkkg7iurlRvJzbR5Pfps0WwGVCsE3E55yhigHCmiV6BLKgdfhbm98OCqfqhBTZyR8g2vxO3sXAfUGKho5QYwnHLv23B9O904yE6IvCKf+j+6YtdM7w1ergnga+SlKOiTlMI3S+4mdSUFEnS50J0NWv4J0MzK2fvT+wBJgMg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Signed-off-by: Peter Zijlstra (Intel) Tested-by: Vasant Hegde --- drivers/iommu/amd/amd_iommu_types.h | 9 +++++++-- drivers/iommu/amd/iommu.c | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-) --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -979,8 +979,13 @@ union irte_ga_hi { }; struct irte_ga { - union irte_ga_lo lo; - union irte_ga_hi hi; + union { + struct { + union irte_ga_lo lo; + union irte_ga_hi hi; + }; + u128 irte; + }; }; struct irq_2_irte { --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2992,10 +2992,10 @@ static int alloc_irq_index(struct amd_io static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, struct irte_ga *irte, struct amd_ir_data *data) { - bool ret; struct irq_remap_table *table; - unsigned long flags; struct irte_ga *entry; + unsigned long flags; + u128 old; table = get_irq_table(iommu, devid); if (!table) @@ -3006,16 +3006,14 @@ static int modify_irte_ga(struct amd_iom entry = (struct irte_ga *)table->table; entry = &entry[index]; - ret = cmpxchg_double(&entry->lo.val, &entry->hi.val, - entry->lo.val, entry->hi.val, - irte->lo.val, irte->hi.val); /* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ - WARN_ON(!ret); + old = entry->irte; + WARN_ON(!try_cmpxchg128(&entry->irte, &old, irte->irte)); if (data) data->ref = entry;