From patchwork Wed May 31 13:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13262296 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 19637C7EE43 for ; Wed, 31 May 2023 13:28:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C67B8E000E; Wed, 31 May 2023 09:28:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70FC78E0010; Wed, 31 May 2023 09:28:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B29E8E000F; Wed, 31 May 2023 09:28:04 -0400 (EDT) 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 07AE68E000E for ; Wed, 31 May 2023 09:28:04 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D38F080135 for ; Wed, 31 May 2023 13:28:03 +0000 (UTC) X-FDA: 80850628446.14.1062019 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf29.hostedemail.com (Postfix) with ESMTP id 9A97B120015 for ; Wed, 31 May 2023 13:28:00 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=UtVwkPrM; dmarc=none; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685539680; 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=EFRjNdGkKmPs8t8EQjORBoOhY59fsy+w5h28GAZsB6Q=; b=kwVfXoDZWLqLiJXeNS/eOlljbIT3XvdOEEKwZyaWB0e3uBiT0VcmjcoSmJhC8+BDHFjstt ddb75IIDNXMBAfXkm7xtBiPuHM0PwpxeIr6b5acR1SRWOgSHOQsIrbSJUBBQ50xKgl45kk yIKRj0vtiKSMTW0AVSBPMz502mH8hFk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=UtVwkPrM; dmarc=none; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685539680; a=rsa-sha256; cv=none; b=3Xs11Bx3y5LwOmSszPd91ioRkY48ViZv+lOLVrQAX8EOd8DF+bf4WIIkMNHwthJhr+cJKQ e6l117KvUJiCilvhUNKa6dDYT1iDYUj20+1JeidgmSl4xVQeMq2I91dEGjcK8as0vMHToj mEQQTJ0+l9We6sZx6o3td7ccC70OSHI= 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=EFRjNdGkKmPs8t8EQjORBoOhY59fsy+w5h28GAZsB6Q=; b=UtVwkPrM/XC85pGt7r9J/NNpRu UL+91AuyLHvjrvG49pQLde3FfNNUmo1htXYmBdQi6zGavV3SSWRcdYYRg2pT/RFAN1s0beaKp6uIt qmsCYWl48JdxSnUcl0TZnP/DxO6Las7rvju+4B6BHlugr3GN/O1xwkrFbvEm1TcgBc0nFb02d74Q+ FugUvUwlkjaq40KU1RNfTvbPliEJmyGnO7N9Y8FQ1QTQ6NKNxRxIvQbmh4ObO5y3tSWG6QFsZealY U6f5lhw6Luo8Kph7RKkJJmtoJB0hFyStxCRmgm2iCzUziTKBMxS0MFEMxeMLjZEeDlsmuqhPZCMlC fkpnhqUg==; 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 1q4LrG-00FTCc-1L; Wed, 31 May 2023 13:27:22 +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 55AC1300C4B; Wed, 31 May 2023 15:27:21 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 992BE243B8570; Wed, 31 May 2023 15:27:16 +0200 (CEST) Message-ID: <20230531132323.788955257@infradead.org> User-Agent: quilt/0.66 Date: Wed, 31 May 2023 15:08:41 +0200 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, sfr@canb.auug.org.au, mpe@ellerman.id.au, James.Bottomley@hansenpartnership.com, deller@gmx.de, linux-parisc@vger.kernel.org, Vasant Hegde Subject: [PATCH 08/12] x86,amd_iommu: Replace cmpxchg_double() References: <20230531130833.635651916@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9A97B120015 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: nsu14u69q7g3rkgfduwy4ydka5zkzyso X-HE-Tag: 1685539680-275955 X-HE-Meta: U2FsdGVkX19arbypiAUlxWJ2isLBaFfKKIu1S2NC0cBI8LF9dvbOr590VhLj2sYyU3oKIDesznXwqz5TSz7kfr2ymsC0sBsH8DMSOLOT2EaK3uA/GmxHTgqQBIeQazMr6d2X/EpLt7hCSK7Pe8ypugDg1MQ0ivBqgH8fIz1pDXWz3qkoTtoBEi23lVh6n7QenYJEVsqYv/rnd1xjcUfHPVM5Va9B7R7hvZZbsC9cIiusj/tRwNCOxcT5Uvl69PxaWSUEO3s31mGcIpATIHHtn7Zg4QtpoaFb3V2AwLTubB5aQJHs5CaXbFLYo9cP+SOy0wLO0xtaCoN6onTHMBjUZ3VbRSP3lTWORGKNeA7KaF8lCXsEIltuBwAoooOalLLA4x0LIfAl75tzA9IMaLj4jwi8q7eUMqLvLYqSUNf8HrmkwIWy5h/yU+PXKhEyhvSu9h9nMcbVtqA/8LjfNywQX1I8Fi3qqSHRQ0qKAkLAT27jPNw0hzqZu6grCRfbTZXoFhvmA/pLWB+hRiPfcf6X1SvM0DBRpWY2W/wnMRJBFoAgx9oOI8DrTwdH1UoLbYw5CfmBBdav93R/5rNU1VVQrUViuXtsxpCVFCQH9acP0/uBUbBoeDJuB0IklJyCpyQUbN6oH8RVrGZPJkN4XR0LWzTEmwH3smEIqwG+56VmlQpTLy2vE/cIRUj9bCHQGz2+qelEZAn8qC+IeL3gj6+uidw1ib/09qKrK3T9bo0BfrUXRVAseCTeaqgo1RMSKlyxZvQQ080eTIbAmgrd/dhcvJ/ObHHEk9oR5H8gEFRxVlGZXfHXDE93/aW3x8RbbOzvSDfJ2WoT2M1W9sUKJoO3ECgd8iPfl4Rqdke2blZUu3UI1ZDo4BkuKXqE5WwMEsbvEN0lrf9elaIxAjmlEJRK/shPqDPpLsY/rSxKb6rM2ejt9skG8792O4z8X6mwpnB6Eia26VMelNNR1y+ZRxo Rvndv07T OAEww18H4aKVBAL4FuScxM/IxW8FotQwG9f7sH1VjT/iCUbESmCxtdoOBywnWHgUXOn33x24cyZCV0TsLtgLWGvEQ1G3r78dvaet/ggeY4UP/pQKmYTkjYgBCg44gSzlH1giH76u3zdnqKwpJkjfWJHDDorui1HorPheJPuo/DALpombGyiLTc93t3eQQHfI0MiOqxGfJUG9m72ZXArQJ4bcEiAPf3EnD3a0lzp6bbf93NLeMLWuBnL7llX2dLQQ3YwsJrOvQF+cIZuvzWkaLie7/nm4BwLB52s8BaDNUsHL2ItBqV/UmzJLqjm9voAiO4gQTRD3yy75PFCKchMgVAbMI2eC477JjHBOCHAJ9h8lC19wJFqjULOfNserd7DokY3pD2oSEZh5B7reIMznHZ6RVZUKHlv7Vcoxx 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) Reviewed-by: Arnd Bergmann 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 @@ -986,8 +986,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 @@ -3003,10 +3003,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) @@ -3017,16 +3017,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;