From patchwork Mon May 15 07:57:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13240939 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 C2BD7C77B75 for ; Mon, 15 May 2023 08:07:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BC86280006; Mon, 15 May 2023 04:06:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6810A280008; 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 C4BF6280001; Mon, 15 May 2023 04:06:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6EE99280001 for ; Mon, 15 May 2023 04:06:55 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 40BB416130C for ; Mon, 15 May 2023 08:06:55 +0000 (UTC) X-FDA: 80791758390.06.7F935A0 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf05.hostedemail.com (Postfix) with ESMTP id 67386100011 for ; Mon, 15 May 2023 08:06:52 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=EaiXXa+J; spf=none (imf05.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=1684138012; a=rsa-sha256; cv=none; b=K0xTnVgWXnhKPHAlv+LYsWhNHqyT0NN+2MXkxNRzTqCtAxlLR0trf2kFI3Qhy9I9Mv6n9E dcg5LErjqgPh8e0I3g49/0d6Vc2NKynqqm7z8gV6XlXnnQLiWROwybff/Bm5APV70IPg65 i0FvExKVlimVpuHCPm45qLJS2RRTU8E= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=EaiXXa+J; spf=none (imf05.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=1684138012; 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=/ezz9F43epJmjX+2+q2EuT6G37yn9BJ4CMV+iiE+KIk=; b=qMs40ciD4VwylVrWgLk004OgvatfJJW94N6XqeSK3WHygwqF5Nb7mvxsNkRj3zoSSgGvjG zzOBKDGuoolrkktqlgmZF5VMs9C0L9Z4ZRTw/M62HlCcajugrAq10pgfnYO3PxPEX/QYln H8ZMkc1bh1bKGJbezpCs4Si4ObO6CBA= 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=/ezz9F43epJmjX+2+q2EuT6G37yn9BJ4CMV+iiE+KIk=; b=EaiXXa+JLNkopxcm154uvINSoT XXhhxSNYI9Dj8TJsMePYGsmPawAk4PgxqA24LoC8ToY8T+UvgX6Mt1Iok43XBxw17lZCw5OZdQ2tQ ZaaSSGuhzCCsuKXfTSd/sC/q9v1c7d0frobCxDxfEp+AjNlpv5Qz2smjLvBY1tflTjx41hwRaKkev GYei11HqZz4Lpne0uwvABdXqI3PMUjfJYYIBLxOseh77Y/9EJ3pflT5Yk/oyQZ6FSRQ1NCjm4r6UF NHWZLaCOz+6hbMv+Kar15kRPnKaI+ssxzGQ048NySZiovPqlPKgHK6tfNCL3XXal7p8b7Oo4dmUEi /ipC8uhw==; 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 1pyTDl-00BQN4-1M; 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 87106302FB8; Mon, 15 May 2023 10:06:15 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C75F2202FCEA7; Mon, 15 May 2023 10:06:10 +0200 (CEST) Message-ID: <20230515080554.382778664@infradead.org> User-Agent: quilt/0.66 Date: Mon, 15 May 2023 09:57:06 +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 Subject: [PATCH v3 07/11] x86,intel_iommu: Replace cmpxchg_double() References: <20230515075659.118447996@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 67386100011 X-Stat-Signature: euhynbq7pdz31a4emunemgsp3cbgffbp X-HE-Tag: 1684138012-394616 X-HE-Meta: U2FsdGVkX1+gCufDXUJlJldWph5T6J0++yjhFcihBmRgkLwxOlNtOa22jNq5rv4ozblfuuTSu+GpcfkqBdjARGptGrI6SSVV+8Z8ooUX9T2uMvhfoUM1DqBWk1Wz7f0AO80+O6Y0ymOUD+HvvqY9Lu15oAZPiOmFrlW5MK6FdKWnJGlT1B5/QKHVImncprbtGI62rWKly3V4lS/xGmb0cofgpLN9fhxb0z3KJ1ZRg7C5OACquX0SxxApxRjNYtYk/4+Ld3dGrnKOuUd0SUt0wc/ouW48TBZp0tdNbHP1nPpl/4GcHICaw1UlRDnWRF0sfEj7oLf6Yl/5S31gWMknAZl4v1GEGUZ3tcL0Vw0fdh+zhUI5RygyqbSIoYZy2o4tu2cLhPxULPc6ZnpmjqFh1ZzOtsMN1jGhoGhO2n1/6C9g+tmM18KZCBWKo7Ko3gQMYmOD2T5/PHa4A8EZPhmG2eiIq3xHkpTTqDpLES8Qeh+SZqCTPPGc4U0oSPb7/0MMI9m5gxpnEcDQl6/fBmqLxw7t6P4Zw5u8jzRtjFc3kAL1VOp2m3MePIroBQFIsGpklwoQH0zRHXPVpmnfBfnMeCcj57keluZrGakpw+PP810CqAl/9WOFoXTcxrD1GDwnP+BhvWYq+pW3KxaMTc4oAhJiMXMWg8c+te9UFrwc8apMmkS0mkb5p3DvfISwtiYaAYuUMWRbHvF8ZJwex+ZA/hji0NycIu7sOkaozJ91KTHrjfcW2vlXjfg5v2zPyqngB3aAXQHahVHfp2ttHkTie/vAsVBucBYGYyaGPBIDR7KBlWIYnYDXoOVFf/b10oLsu5OvovOVMbP0YqTIMLefUqjH1j+XRxfs08IL44QaGFg+Hr3l7dfpWXtngNZ2HtUykRNkDCHU2osQFFQQbM9rN4vt6LXrj/qopC2y3vIPcSPBXQa40+jh922CR3XQsn/Xk8DhjuqSI53EOK2nck+ 9HBN8fLF pONvUjBBx1qCb3MRAa5sOCuTM9VHwEAwpN5vbN/4AvbEfZ0D+Sy/mT8f7RRk5WnMp70lyq84t/RJEJzzfndu8CzZP5PMak3j/ZopiqIgkKZ42MjajSk5aXdFyKImgoJHw3qrB070hTYWNBFCGgpJCyVT2+319+bAI9P4aHLH1yNA+qzrS7xpNhkDPlyhzXWwPyqaGfjcyYmw2ymzJ+iQJTi6SAyS6SHNIDqwDey1HnR4FnBd6yfglQybNMg0WlHff+lutBxZFCw+mIBJ7WiVlBilk8YgvBqfllHGuiZhLnvPjU1pxZBkuieolgY8g3uQWIauSvj7n/AYJeQoSJuoIrEf4Ta/hRklm8tx/TqF5VUyGaVz+7REfDmVChiof2E2E9Hn3EE4Ih5DEZ8iMEtl5IIU2Qf80lhc6U2gk 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: Lu Baolu --- drivers/iommu/intel/irq_remapping.c | 8 -- include/linux/dmar.h | 125 +++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 65 deletions(-) --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -174,18 +174,14 @@ static int modify_irte(struct irq_2_iomm irte = &iommu->ir_table->base[index]; if ((irte->pst == 1) || (irte_modified->pst == 1)) { - bool ret; - - ret = cmpxchg_double(&irte->low, &irte->high, - irte->low, irte->high, - irte_modified->low, irte_modified->high); /* * 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); + u128 old = irte->irte; + WARN_ON(!try_cmpxchg128(&irte->irte, &old, irte_modified->irte)); } else { WRITE_ONCE(irte->low, irte_modified->low); WRITE_ONCE(irte->high, irte_modified->high); --- a/include/linux/dmar.h +++ b/include/linux/dmar.h @@ -201,67 +201,74 @@ static inline void detect_intel_iommu(vo struct irte { union { - /* Shared between remapped and posted mode*/ struct { - __u64 present : 1, /* 0 */ - fpd : 1, /* 1 */ - __res0 : 6, /* 2 - 6 */ - avail : 4, /* 8 - 11 */ - __res1 : 3, /* 12 - 14 */ - pst : 1, /* 15 */ - vector : 8, /* 16 - 23 */ - __res2 : 40; /* 24 - 63 */ + union { + /* Shared between remapped and posted mode*/ + struct { + __u64 present : 1, /* 0 */ + fpd : 1, /* 1 */ + __res0 : 6, /* 2 - 6 */ + avail : 4, /* 8 - 11 */ + __res1 : 3, /* 12 - 14 */ + pst : 1, /* 15 */ + vector : 8, /* 16 - 23 */ + __res2 : 40; /* 24 - 63 */ + }; + + /* Remapped mode */ + struct { + __u64 r_present : 1, /* 0 */ + r_fpd : 1, /* 1 */ + dst_mode : 1, /* 2 */ + redir_hint : 1, /* 3 */ + trigger_mode : 1, /* 4 */ + dlvry_mode : 3, /* 5 - 7 */ + r_avail : 4, /* 8 - 11 */ + r_res0 : 4, /* 12 - 15 */ + r_vector : 8, /* 16 - 23 */ + r_res1 : 8, /* 24 - 31 */ + dest_id : 32; /* 32 - 63 */ + }; + + /* Posted mode */ + struct { + __u64 p_present : 1, /* 0 */ + p_fpd : 1, /* 1 */ + p_res0 : 6, /* 2 - 7 */ + p_avail : 4, /* 8 - 11 */ + p_res1 : 2, /* 12 - 13 */ + p_urgent : 1, /* 14 */ + p_pst : 1, /* 15 */ + p_vector : 8, /* 16 - 23 */ + p_res2 : 14, /* 24 - 37 */ + pda_l : 26; /* 38 - 63 */ + }; + __u64 low; + }; + + union { + /* Shared between remapped and posted mode*/ + struct { + __u64 sid : 16, /* 64 - 79 */ + sq : 2, /* 80 - 81 */ + svt : 2, /* 82 - 83 */ + __res3 : 44; /* 84 - 127 */ + }; + + /* Posted mode*/ + struct { + __u64 p_sid : 16, /* 64 - 79 */ + p_sq : 2, /* 80 - 81 */ + p_svt : 2, /* 82 - 83 */ + p_res3 : 12, /* 84 - 95 */ + pda_h : 32; /* 96 - 127 */ + }; + __u64 high; + }; }; - - /* Remapped mode */ - struct { - __u64 r_present : 1, /* 0 */ - r_fpd : 1, /* 1 */ - dst_mode : 1, /* 2 */ - redir_hint : 1, /* 3 */ - trigger_mode : 1, /* 4 */ - dlvry_mode : 3, /* 5 - 7 */ - r_avail : 4, /* 8 - 11 */ - r_res0 : 4, /* 12 - 15 */ - r_vector : 8, /* 16 - 23 */ - r_res1 : 8, /* 24 - 31 */ - dest_id : 32; /* 32 - 63 */ - }; - - /* Posted mode */ - struct { - __u64 p_present : 1, /* 0 */ - p_fpd : 1, /* 1 */ - p_res0 : 6, /* 2 - 7 */ - p_avail : 4, /* 8 - 11 */ - p_res1 : 2, /* 12 - 13 */ - p_urgent : 1, /* 14 */ - p_pst : 1, /* 15 */ - p_vector : 8, /* 16 - 23 */ - p_res2 : 14, /* 24 - 37 */ - pda_l : 26; /* 38 - 63 */ - }; - __u64 low; - }; - - union { - /* Shared between remapped and posted mode*/ - struct { - __u64 sid : 16, /* 64 - 79 */ - sq : 2, /* 80 - 81 */ - svt : 2, /* 82 - 83 */ - __res3 : 44; /* 84 - 127 */ - }; - - /* Posted mode*/ - struct { - __u64 p_sid : 16, /* 64 - 79 */ - p_sq : 2, /* 80 - 81 */ - p_svt : 2, /* 82 - 83 */ - p_res3 : 12, /* 84 - 95 */ - pda_h : 32; /* 96 - 127 */ - }; - __u64 high; +#ifdef CONFIG_IRQ_REMAP + __u128 irte; +#endif }; };