From patchwork Thu Jun 1 10:14:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 101871 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp203424vqr; Thu, 1 Jun 2023 03:35:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zvxK2I5C39S+YkYEN5aAb8qNrgVMCogzUr96A8apWzw3Sa+1DU9Jwy2auDj7qlDU6yaoV X-Received: by 2002:a92:d08a:0:b0:33b:94d:b60b with SMTP id h10-20020a92d08a000000b0033b094db60bmr5762424ilh.14.1685615745059; Thu, 01 Jun 2023 03:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685615745; cv=none; d=google.com; s=arc-20160816; b=irP8bSEhPv8sDiyWw2j9jkxpI3VKHESvgFuB8ZSmp2DcjKJgdXnVUlUwiTXD5d6PDn lonAIOfoYTcphZ5HxYXy+PJdg6PHHvPpxMTnPU2Hd1ZbGDblAKLj/37x9EfdTrIidyZj hLP21EUgFEAmluhDKPrPqadRm0LEQ6OCJj5H1Ietg1qSNVRtln0ai0ucYMTzOyZ7lKEK eLpyY04UdDSDtfGfW8kiy45MZBfxz3o9shv1mpDqtdGj/hRONGnBzJUjypYZ04bbgBT7 zKqncqZ2nv1u3us7M4ZPGKmy0g3RRzFEnFWCQgjlDI8SvqUxZo1rjZQpbPAvYOJwBJll 33Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=G1trJdY7ybtDfb34YzOEZVtQJ+4O7zYES3kMJ7sRdCU=; b=wXVqIG1Z2AV70ns+295cx7uUCd3VGvG2Dva2t+XwOk1yt/aYE2ZNV0QVCNKCp7MYZy XO/UrHcy61LBI8VY7DIVksGADNDZQ1wmvxp0yDxXeS6ThBhRA/hI/2HKdxqG4iwde1QN OB7p7lVOrv3sSGUfCv+06NLRY0ydDW5XXnCP/Bm5HFFxZQUbVge/nUvf2/mpZSfHYG7f KmP5wBp7UIcYn+ovOkj4qJr5Eaqw6HA7z497TlrffkvybUJrkdQ/AH+f1o2cX5dPORdC H7FY7NrZ/aJswWBKHPH2lIZ3+bZ2WTpMAlXpvsKT8OLX6FDKlrjHFjr+zDKL5yWzGxSL Zpbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pytfcabS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g64-20020a636b43000000b00528d1d9c7b3si2663016pgc.732.2023.06.01.03.35.30; Thu, 01 Jun 2023 03:35:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pytfcabS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233034AbjFAKSl (ORCPT + 99 others); Thu, 1 Jun 2023 06:18:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232499AbjFAKSG (ORCPT ); Thu, 1 Jun 2023 06:18:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF58A1FDB; Thu, 1 Jun 2023 03:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=G1trJdY7ybtDfb34YzOEZVtQJ+4O7zYES3kMJ7sRdCU=; b=pytfcabSQbAioNogqcJyIjWxkb I3OIRz0nPyGAHQCouHiezAZ3WYDnbr+0H5ASElPr4+OfQuPcqSEVXUzQNdmNT0vDCq0lYth70hxc+ nIxwWeL5rSBkZoelbLSxxySFndCPqg76D3wq86BEGZ1gkD10CrGs9NABCiAJPJkEv81csRGvvoVja EaBwzktB36vi1XtuFtdCEjY2KE+yJjTGMIB4mjx3jEx3iBh0aM1LDhfieu9IZABiemcJgKbkPFNuq /6ksBvE3iaE68Sn2CQ4733UmzPnTQKsAKE8EvFRBt0Ej6Ani+wvx452hsmvy64dZ4tGLH+6z41/Rs 43i6i9qw==; 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 1q4fJv-008GIu-Pp; Thu, 01 Jun 2023 10:14:15 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 66A3C3002F0; Thu, 1 Jun 2023 12:14:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 374AA21484A8B; Thu, 1 Jun 2023 12:14:09 +0200 (CEST) Date: Thu, 1 Jun 2023 12:14:09 +0200 From: Peter Zijlstra To: Arnd Bergmann Cc: Linus Torvalds , Jonathan Corbet , Will Deacon , Boqun Feng , Mark Rutland , Catalin Marinas , dennis@kernel.org, Tejun Heo , Christoph Lameter , Heiko Carstens , gor@linux.ibm.com, Alexander Gordeev , borntraeger@linux.ibm.com, Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Joerg Roedel , suravee.suthikulpanit@amd.com, Robin Murphy , David Woodhouse , Baolu Lu , Herbert Xu , "David S . Miller" , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <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 , linux-crypto@vger.kernel.org, Stephen Rothwell , Michael Ellerman , "James E . J . Bottomley" , Helge Deller , linux-parisc@vger.kernel.org Subject: [PATCH v2 07/12] parisc/percpu: Work around the lack of __SIZEOF_INT128__ Message-ID: <20230601101409.GS4253@hirez.programming.kicks-ass.net> References: <20230531130833.635651916@infradead.org> <20230531132323.722039569@infradead.org> <70a69deb-7ad4-45b2-8e13-34955594a7ce@app.fastmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <70a69deb-7ad4-45b2-8e13-34955594a7ce@app.fastmail.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767496215858195286?= X-GMAIL-MSGID: =?utf-8?q?1767496215858195286?= On Wed, May 31, 2023 at 04:21:22PM +0200, Arnd Bergmann wrote: > It would be nice to have the hack more localized to parisc > and guarded with a CONFIG_GCC_VERSION check so we can kill > it off in the future, once we drop either gcc-10 or parisc > support. I vote for dropping parisc -- it's the only 64bit arch that doesn't have sane atomics. Anyway, the below seems to work -- build tested with GCC-10.1 Signed-off-by: Peter Zijlstra (Intel) Tested-by: Mark Rutland Acked-by: Helge Deller --- Subject: parisc/percpu: Work around the lack of __SIZEOF_INT128__ From: Peter Zijlstra Date: Tue May 30 22:27:40 CEST 2023 HPPA64 is unique in not providing __SIZEOF_INT128__ across all supported compilers, specifically it only started doing this with GCC-11. Since the per-cpu ops are universally availably, and this_cpu_{,try_}cmpxchg128() is expected to be available on all 64bit architectures a wee bodge is in order. Sadly, while C reverts to memcpy() for assignment of POD types, it does not revert to memcmp() for for equality. Therefore frob that manually. Signed-off-by: Peter Zijlstra (Intel) --- arch/parisc/include/asm/percpu.h | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) --- /dev/null +++ b/arch/parisc/include/asm/percpu.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_PARISC_PERCPU_H +#define _ASM_PARISC_PERCPU_H + +#include + +#if defined(CONFIG_64BIT) && CONFIG_GCC_VERSION < 1100000 + +/* + * GCC prior to 11 does not provide __SIZEOF_INT128__ on HPPA64 + * as such we need to provide an alternative implementation of + * {raw,this}_cpu_{,try_}cmpxchg128(). + * + * This obviously doesn't function as u128 should, but for the purpose + * of per-cpu cmpxchg128 it might just do. + */ +typedef struct { + u64 a, b; +} u128 __attribute__((aligned(16))); + +#define raw_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval) \ +({ \ + typeof(pcp) *__p = raw_cpu_ptr(&(pcp)); \ + typeof(pcp) __val = *__p, __old = *(ovalp); \ + bool __ret; \ + if (!__builtin_memcmp(&__val, &__old, sizeof(pcp))) { \ + *__p = nval; \ + __ret = true; \ + } else { \ + *(ovalp) = __val; \ + __ret = false; \ + } \ + __ret; \ +}) + +#define raw_cpu_generic_cmpxchg_memcmp(pcp, oval, nval) \ +({ \ + typeof(pcp) __old = (oval); \ + raw_cpu_generic_try_cmpxchg_memcpy(pcp, &__old, nval); \ + __old; \ +}) + +#define raw_cpu_cmpxchg128(pcp, oval, nval) \ + raw_cpu_generic_cmpxchg_memcmp(pcp, oval, nval) +#define raw_cpu_try_cmpxchg128(pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval) + +#define this_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval) \ +({ \ + bool __ret; \ + unsigned long __flags; \ + raw_local_irq_save(__flags); \ + __ret = raw_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval); \ + raw_local_irq_restore(__flags); \ + __ret; \ +}) + +#define this_cpu_generic_cmpxchg_memcmp(pcp, oval, nval) \ +({ \ + typeof(pcp) __ret; \ + unsigned long __flags; \ + raw_local_irq_save(__flags); \ + __ret = raw_cpu_generic_cmpxchg_memcmp(pcp, oval, nval); \ + raw_local_irq_restore(__flags); \ + __ret; \ +}) + +#define this_cpu_cmpxchg128(pcp, oval, nval) \ + this_cpu_generic_cmpxchg_memcmp(pcp, oval, nval) +#define this_cpu_try_cmpxchg128(pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval) + +#endif /* !__SIZEOF_INT128__ */ + +#include + +#endif /* _ASM_PARISC_PERCPU_H */