From patchwork Mon May 15 07:57:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13240940 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 74C0EC77B7D for ; Mon, 15 May 2023 08:07:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEFB0280001; Mon, 15 May 2023 04:06:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7421280009; Mon, 15 May 2023 04:06:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B784280001; Mon, 15 May 2023 04:06:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 33D6A280006 for ; Mon, 15 May 2023 04:06:56 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 04147121394 for ; Mon, 15 May 2023 08:06:55 +0000 (UTC) X-FDA: 80791758432.22.B752D7D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 3B7F5A0004 for ; Mon, 15 May 2023 08:06:54 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="VA/C0Cmc"; spf=none (imf25.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=1684138014; 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=rgZ7hZWkHDtTpF84Xw00Ifyh/7yejqO/hjYHP4KrVyk=; b=DtvBGVw4DY7JsnZZeZGXkG2If7nLoMPm8HdeTm6Jgf/2YoMyHcncbx6PolOydXqcyrOInB n4cO7N/kofqruMWZ76bLe7JSt+haHXj6BFl+GxoRpBJ+pO5Ydc07vVIh9lsvlJPlyu1Lz3 4UNBjM8HnS7DmKfBdKc/hD5kmO5AneI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684138014; a=rsa-sha256; cv=none; b=3sntECuwFS1myfdE8/VBRCEErAHOx++IzVQzhYYIhu8OBUWkp4/6yGaZJiaw9Ne+erpcLz ito/Vckjzv3Mq1MIF13Fn48PYYjbfi/gkSfPOe3F1R53dxT51p+PPm3FOTOVH0waQ8SraQ eGnmd39OGmm9ojsSsMaNGzEY6rgXbQE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="VA/C0Cmc"; spf=none (imf25.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none 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=rgZ7hZWkHDtTpF84Xw00Ifyh/7yejqO/hjYHP4KrVyk=; b=VA/C0CmchcfXpbAczSsPgonOyt 2aUt/agGqPFIFpZ6l2I6Qg5nqdJuz9IoNMj9V/ozfrCxRR6fb5YEf1Ga0kiJRyftM4e6pWjqWSKkc dIb0BRa5UE1aFif3qoM2MZ9k3ki3NvKxYPbB/R6/S547Pj10WkYXT/Q4uPhD0UtHAZXSrtLCyzGlN kb1o1hAHxW8lgC6PteRUH9iYuSUB3Gmflm7Y6x74H7yhLbWGQ2MymwpDc7/LOZXgNN8aLC7xVvmQ7 r4CZEX4BQYELzBYNeKfUDIJMu3CGkBsiIghUyTmTjEZk9+BAmwahfI7LbKKQJ31UK8rF4TV1yz3Wq y8BpnERg==; 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 1pyTDl-003HUW-Ez; Mon, 15 May 2023 08:06:17 +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 872123033CC; Mon, 15 May 2023 10:06:15 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C2169202FCEA4; Mon, 15 May 2023 10:06:10 +0200 (CEST) Message-ID: <20230515080554.315901115@infradead.org> User-Agent: quilt/0.66 Date: Mon, 15 May 2023 09:57:05 +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, Vasant Hegde Subject: [PATCH v3 06/11] x86,amd_iommu: Replace cmpxchg_double() References: <20230515075659.118447996@infradead.org> MIME-Version: 1.0 X-Stat-Signature: xttj9tz4rd4o45fxk38c3ms3fqdxy6of X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3B7F5A0004 X-HE-Tag: 1684138013-59949 X-HE-Meta: U2FsdGVkX1+8UWwyQMP7ffmSjuA+qx45n/IX6cM9F0IvGqiMpsgeVMOQoJVxln5iBIpDMNUTFI8YKcBjhTAjT/OxMt4VEI3AMxHc9h9gtyHdEAPf1BB3LBIvOsAm5Nn3p/EVv0fii5Vuh0DoiwI0lHhw9PD7XTX5E45irLMR0wjhSxWspHju9lXMD3VHAHzI7laWlvoUASD7qkuA1BYnIrZ5Lnv8Ev/spr7iE5iOdJzqO+kfuvM8SrYrvzT8pV82fBd9f3/0y/rQguamCW2PBe/LYMva7HhYvJ/sqUiJ2JjeNKQ7YCfiAdFCyx0VdUHar+vsldqH7aUnDsH6T+FEE0kt730m91dU3EvofGu8DBLZiNxOzEFS2bnwZMlLL2ilfM4DL0wZzGkbaiPFieVUn97oPI2TGaZWO0R8WxdwUlNUyrEF9AJVT20hvttPfjW3t3G0r+N3vKLnvYVk2daRuaqtJigMOGgAJ8YWWzDcW/bYxXwA3DsgswJcp+v391U0JutW3h1U1Dz1MThvrtWZVi4NJVMK0AA2VmOLXET3Vy/WqwFnK8xGReFOJrl4zM318gSt70qCuNOY+t4U7MJY60Hlc9sDKOW/4d3XMgBmzult+hCUcTLiPrnyBT4MKowjlL0Gm1ncIkrvLjPosgiMmN/KH005N4J9YisKyJCr+IZsh9nSZk0nbCdQDjERid69C3s3fNgyc1d+gf010++/ss1REXIV50uTlnFPVBUcZ+2DP5sTYnVcPat48rJy4jX3j5oYJm7jb1PSFzVQJbO6bCbeSfLP2RPgiViYXp56tIb9njnF+Dm6ci+HIvcISlIR23QwvWwcrd9x1ZR1QmslzS1r/Xgj9MVVd0fZlNAteGPWbb9QkGb2uxM0YqM34s1T2D7Kj9+9SfLc97SZBNxExAqfsrptPGcO3y2TS8QO/mbNgJHU/nKadJFPCuxkXH0yLEyLEUdEhyqdNPdB7c7 SdwvVOVJ YcESTPXKK9jR40gmeq0bRGrxyZqVo1X2w7nAdeetJDnWlYhWaR3E7REwx+z3Wf+aagVSRPKjD935ZQ/+r/wQxx4rfXbPlW5PONzayba1LUlkU5AEb2DpZ1i6Eke6BtN5lwNirhZ7BA5HHTcdoN3pitJjBrImYm1Oe3J6MCIfZGwZNmGx216PM65PpedO3GPSOlsFnvOTDR87GnSu/yrMJVmQwlFSnVxcBC+8BB99X1CpeQwkgvVYf5NcD+yMRLC+bI0v4xkaAsAOVgpZQ3SXXCx0uCPYrzJMp7Whj0n8opqtxnGqnFVcTkbDxO0ogR8/61egZYSc9J7KNFJoEyuevcud0najBbYPF+nG6/F2Bt7BTfbXY1DJ9eOUDUnKn4TP3vihUvwhBKc8YVrrR6pE8nwImZFyW3Mvk2m91 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 @@ -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;