From patchwork Mon Dec 19 15:35:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13076734 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 A3D91C4332F for ; Mon, 19 Dec 2022 15:43:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C2618E0008; Mon, 19 Dec 2022 10:43:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F6688E0007; Mon, 19 Dec 2022 10:43:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED6C88E0007; Mon, 19 Dec 2022 10:43:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CF5BB8E0003 for ; Mon, 19 Dec 2022 10:43:44 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id ABAEB1607FA for ; Mon, 19 Dec 2022 15:43:44 +0000 (UTC) X-FDA: 80259475968.06.BCD0375 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 2FBF3140003 for ; Mon, 19 Dec 2022 15:43:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hikgFxO9; spf=none (imf23.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) 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=1671464623; 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=TPf252rpqr9tSwRpNAavICICeFc5ydD0TdU6p9uBQtA=; b=nxT/xZQetEOequj4kAhBj0+UMtxwQJuS2/6Autl4x6VvQ6uafbvnSxE1OiMkcjJiv67+0B Sf6f/IbZXB9BoxriqzoyQFoKrDzX5JPgV+a21i70e9UwCDl3wpHbZerMNEsIFDaF7I4hpl afPNIfwWMLMxQ1GcgJxeCuW4GMMrThk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hikgFxO9; spf=none (imf23.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671464623; a=rsa-sha256; cv=none; b=ic79U7RcHEfxYbDAGPyb0c6eRJW4s9Gyst2NrqH18hn0lb5eVeta9FdXoDF0OPXrfj2Adg 3iYuQhkbW36rswFgCZuknB9us2NK73lHk3Ob5PYPnfAAIdzJoufS38+csgNGFUn2v+A8qG E602OFY+Fg+/Ica9YOx0PId3mACKzVo= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=TPf252rpqr9tSwRpNAavICICeFc5ydD0TdU6p9uBQtA=; b=hikgFxO9sKFM24xM6AvNTdx5rx 4bK/y8q/B0VCEnW01d/jdOIOOgxIQq4NAI6Euj1jUMXfyP+rrDOK4e4zF1MxY9SDmw3712EXyfs0e zZyVyHpAFwBjGr/vHvoeSRNRrKno451ZKvcGDinbA8BYM5e9DbPj/bZgs6iT29aBwXdpHXM81ydbA BuU2h9UTrqr7sYcUkI12tkRLSEh3whv/yts2oyMWWf/AtwiO7CtycmUfUgvK9Yfqfb/hCNyOAszam f/zQg3GR+4JQj5VUE26N5UTKvtWgZjr6FBo4UI3eE2tZNipWqM42J/lcxj2ocKWrQLjmoRPH/MazT iU0/RFQw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7IIT-000qwq-PH; Mon, 19 Dec 2022 15:43:21 +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 0DCAD3031AE; Mon, 19 Dec 2022 16:43:10 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 96CCA20B0F89E; Mon, 19 Dec 2022 16:43:06 +0100 (CET) Message-ID: <20221219154119.419176389@infradead.org> User-Agent: quilt/0.66 Date: Mon, 19 Dec 2022 16:35:34 +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, Herbert Xu , davem@davemloft.net, 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 , 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, linux-crypto@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org Subject: [RFC][PATCH 09/12] x86,amd_iommu: Replace cmpxchg_double() References: <20221219153525.632521981@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2FBF3140003 X-Stat-Signature: 65d9d1byqzc9j4sod6x1nzm7zai9mcpb X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1671464622-251343 X-HE-Meta: U2FsdGVkX18pgPeDt3F+PGqyPnUCQxywniNa2w9uceKTGW8C7YIl2FjrosTFUIqkOLtgI4n8YJ5pj4q3cEfraL/aNU1trAqUgOmL5L5zbFbeNBKtuaovm1FGsp0mz9BinwDsAqKB13UTm4UAtI9jyUfY1PmVHG1w3Re08A6cQCihObCck3ZisLAYkPsMJ+eEcQXu+OcdsE6/aGLOpVeIoIzkawmZmND+GjgtFLC1q04L0fn5LNWK7IFSlbJNcue6q5YjZT0f1UD863zrnimT5nO2LNiKip+aYLtyS8Ix9hpSVg+Hrbu7ahupbjdqy7T2ju/ICsgZkkTUHCwj0NNi4e3deQSn34CIjqCL12eLfePrF1FqItPW4sDzMrZXHxpR389KQT3CSkU5O487r/89K+SP8qDIHq6p/d4g08Js5aFUSiZTZD4wxGpaNlCpC4EVCdPdErdzeF0ZXPvFuRo4Te2ouEt24wOgxqS7BWlv5TESXWxGHABcl0F5u8kbXoXNP3acCva6qSijOAmeP7zZIiwFARNgV/IrSICurS+KgYr+YfvT+38kvHzc4wLTmIcvFkbZZExQBp3JieNHjfZtw2SmkYCsCkMsMQ+EESwhFdP2FecRFo9QqtHTV2BMLrrZkOAzSrNAXMrLTDB+P2AYCLuQd8AFg0AhuWacXLxhN/ndC/PsfqgmNogW2uMeErNLQO2XH2h2EbjaUQstyPZy+HseX7s7g7mHocSyd8alztbjfg6uIikjSYRGYZ58tpzWgW3aJDildTKv8Qbsg4PSp1Uq0PLQa+6IRO+PyVBEC7p/OMBkFdzN1rnZ+qsB5HrX5JMQUergmEN3cGgmK9tvTDrBniqLQ7twqjl9v76bUvoFMW6uiky6UFYhIrD4PuosyWQ9CeFnaxTW6FRmlwFAf2bzOiqEZ+Mml0XSh/DXnz+bScPS7kp+pte3qAtormEnaBaDZ6/v5+5hvFBRFq7 bCwlKSCl 9GNE9d14Z/nLrYD9cmn4rNswLyyAIOf5QiaFIgr/TtbBMk2E= 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) --- 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;