From patchwork Wed May 31 13:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13262408 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 E4ADDC77B73 for ; Wed, 31 May 2023 14:40:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C4578E0008; Wed, 31 May 2023 10:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 174458E0001; Wed, 31 May 2023 10:40:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0631F8E0008; Wed, 31 May 2023 10:40:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EAAA68E0001 for ; Wed, 31 May 2023 10:40:38 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BAD5CA0209 for ; Wed, 31 May 2023 14:40:38 +0000 (UTC) X-FDA: 80850811356.07.49E04C3 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf02.hostedemail.com (Postfix) with ESMTP id 4B0FA80019 for ; Wed, 31 May 2023 14:40:34 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=HwjGAHT5; spf=none (imf02.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=1685544036; 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=oEM9cKMOhay2aIvdrV8l4iv3Y85XNhmkKjhGaIIXx9s=; b=AnkV/b4loZNnZdAmivqnpWgTjXhfH0bXl0x8j4pXwaEt4/R1fmCR2Zg6kotH/TOznOBR9Q flEkSJDnHbwGvc3/NSJq/NYI4AuXwkIvIcOy5KH+iW1gc8h+Vq0u491Z0btH9TpESv4++4 +UoLYTmeKLs7x3xNQO4MYOumzxUk0vA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685544036; a=rsa-sha256; cv=none; b=5npkUBoVb/D7oZz5HXZfZUr3cO6Kf+cLllU8OAkeY3+Rs1++5ZAHemVz/JLvSzroKSNS2p MphuS12dO2dj52oWcI5XwsJdZyQ0++q4i+BHEKGr0/mTui+yn61PmUfKTwu6epFT7In53b 3aHjUSM/22w4mmUqCQiCDzTU8nIqnaM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=HwjGAHT5; spf=none (imf02.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none 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=oEM9cKMOhay2aIvdrV8l4iv3Y85XNhmkKjhGaIIXx9s=; b=HwjGAHT5MrE1xu4SBX93HkmX9u a2znWTmLZ07JD0sUzV+0IbVtXOD/6RBCRGFsNejvnCtTI/amSgZ5UZ4/YfCJGHaxijoudZ1oYAVKW uqofk9TNQ3evFFh/rxMp+rU18zbEUWrANyQO39RE82BwGYNqD3ZPhacASMa6BwWLixxGUTLxqd8Vi d1YqKT1tBIGCET2CoaFNyLZHd92jwsvnYwiD1nC7ltau7JQ4E8QzuEDIZNUQGqdqQXo+32DWDjxVT 5m52fmU5Y+Z3xNFs0Ud9NdY2ZSjk0KJZeTseHj/XGzXMWFdlSANtg+aZnACSKvKlZR9CBvnkLYmgn dJcqgM4g==; 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-00FTCd-1R; 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 55A463002A9; Wed, 31 May 2023 15:27:21 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 9E8FE243B8572; Wed, 31 May 2023 15:27:16 +0200 (CEST) Message-ID: <20230531132323.855976804@infradead.org> User-Agent: quilt/0.66 Date: Wed, 31 May 2023 15:08:42 +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 Subject: [PATCH 09/12] x86,intel_iommu: Replace cmpxchg_double() References: <20230531130833.635651916@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4B0FA80019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: embcrxy7p6tzkkiiysqkpbn7b5arhn6g X-HE-Tag: 1685544034-759011 X-HE-Meta: U2FsdGVkX19owkHCSkIlh52JtFD15LYVHcIgyZPDDOQ/Y0o5pcdBbjtFFG1HYGr5JcYJfkw1EkZlijZr7/f3qeb9EdYOT1FBSCS/oKHVKF4ItS3W92+gVBUvTLc3CkTOQckj7Ad3KB1HISobKZIgO0LqrBvEMHdqU4KIZyS+dSYRc/edue6N3T2i/Emxc5u3lzkObN8qvwxUzT9F+Ulhfig9qN5NqHDv3BYmvc+5gud7JAwsX1/oBk1au3fQw8nZdU8e9J9nLG0zFIi3v8nzKjVeTmyWprF8yhWetgrBuZTMy4GqcXN6NBKDJDCKqNI5YWDGrpo/gSN9+cYbkZNAbX3MTnEP8hbgBL/9o96IqHjb9P50F2fFRUDEYskUxmvJCd9I2J03qO7hBdOYb1QsoM1bO7A4UxLsHptfYJyMF0Pw3S489jYe/t17dt0e5PXHR/sVC3G0sMLa0mRsIywCM6kjrfD7vllno0H61opE3kSc55FkvtIc4puEH/ujUPYbQuXBQkascpt2To4PeN6kqjQZWYv6kAgYkni+szlNYe+c/dsy5W9RCvCA6QBC4ghfMC6mr2G8GPtE0HoHxtFGcv5651sW3W7Va5e5HffmVUt3PcmNZTQrH4RFtWw8YN36eW/jZQkI3TW/nZN/RpGNqAuLo+VKmwh6lQz8+lMu39bbAdqZ9f6+2hnASKTyKc3MNcT3GNEmTllw6agYD6S63z6ng6VnlfKrLOYA9YkBN+aFLr66dCIl1rquX1XGgU4hxHfXI+P9lBOnzGLvh8xyBUeUQ6/s4OTrTrqzgHoqGUBvfmpBpSG+lEIGnNOPOSF8yYEPTQ/AKETxPqo5PFhXTtiu69biktSpygG48mWWgAeWy5LEcdPRUd6QYzAalD9RYv1jcUYeCK2IumyrxmABNncvcPz/Xurzovk1CmF4DzrsEMuyyzP01uVTcLw10SuRHkhKdvBE/CsOYFq2crF he4TdOMn N6SQ5o+VX3LmchCd4ufx+hmpxBRvJcWm0VN8I6ttpNxNRxUQUQXMuR7fWjk/9az7MF4EAWRwRIZ70MdGDa7X/Qb07dA6EWQEM6XsdOkTAbtxj/I9mMyQbzblhbwztP/gliFoz47/uUmc1b3onjWl4oK3v3+y4kwfKy9aCqjW1kWj321xoYU1cGskiEBSZi/pS1ymUS/Id1jmMi1ScUGxn4fp3VQVeXZdflQlrCqE2ei15DVIuS9bK0NO6KzH8y99sAIn5pixt9+F414ShcD40wRx9+yaxv667yIcKzYbNLlp8eQOHrMcGQpnwPYZdusiN9LrH4jw2+/ZZimNIHAF/7RGoFSZCMj1HRMRl/zC2LSvrwslfG6owqOFAynYJbZseDR8LS/QHcOqk3OdOr1glbnWSlVZsaeO5A0ip 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 Reviewed-by: Arnd Bergmann --- 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 @@ -175,18 +175,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 @@ -202,67 +202,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 }; };