Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5134502rwb; Tue, 8 Aug 2023 22:03:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV8s2rZc2jLZdF4ZS5RFbVKx5JJogpJvWm6cAzcGrmMNBOKva88HqXlhFQLCUHAfneDnHM X-Received: by 2002:a05:6402:658:b0:523:2df6:395e with SMTP id u24-20020a056402065800b005232df6395emr1175421edx.31.1691557419020; Tue, 08 Aug 2023 22:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691557419; cv=none; d=google.com; s=arc-20160816; b=BipdDb+KgNMG8fLXWcB0A9jWVD15tfuXxD8ZW2qJIBUNEw4oXwgu+nKHHomu73g9/7 TB/RIJ8yEbxOXDqmpGu6jR06Sr70wPs8BQEZmKGMl+ZwQiuO8NM95RUrpQI4GHa3H+3X ZcmWzU3azLtCkAJx13DoSgJfPOE+GPKGXisef1tTVuSYVZZzN7Hyi74IzE6EUtCkDA0T QGXbRgcJoLPkHWqiPRudcrX389UFn7h2pEc9tVrtOVn1FKRK/EgyLfTm4Fk/Xg22857p CFu/geL1TAwoUUOLypbgAgoJs7wrfLfPW64+xg4eEbp/TEKqm3ROgMv/63fFl0bu9R34 3xGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rTa9TiH+Nbxa2120Ikd+iVzWMSduN4Wn5JO47t6FkLU=; fh=RC6bsfN8bPPp/iDUCpnJMEtdiqa5XC4G6XtB4MmAVnA=; b=tExsm712iuNE6lXmUrntp+qGc00ztU3IJZg13HnM+4Jwuv1wviC3i6u2Cvcsj9Mgl9 kxlqr7ngr2pkWWmP6x1PWPqKEZpQtnW0KlqrsNaw2KgbHbeY/ydpkOeP55gFEEA2ltk8 dj/IPB3RKfYBHjllD6Oa8nDwJt9G74dzvYYpfdNiFBPSNr2dSuXf4oBm5Y2zC/gVdUjJ seWwRZGysN3jsijhg41wHwTHElKC98TU6hH4NVq79FEwNuH6UlKc5g+NssTWSVCxE9Ir GVJn4mAZaT+xCKMyBNXjWUT5TN2tAapR6e6s7dRTO6A6a+hqYD4/gmHrYxjLQC0gZ+ZM Xd3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QxU9vY3Y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jt26-20020a170906ca1a00b00992a9b22b7fsi7061556ejb.668.2023.08.08.22.03.14; Tue, 08 Aug 2023 22:03:38 -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=@redhat.com header.s=mimecast20190719 header.b=QxU9vY3Y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbjHICOh (ORCPT + 99 others); Tue, 8 Aug 2023 22:14:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjHICOg (ORCPT ); Tue, 8 Aug 2023 22:14:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E75C71BCE for ; Tue, 8 Aug 2023 19:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691547235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=rTa9TiH+Nbxa2120Ikd+iVzWMSduN4Wn5JO47t6FkLU=; b=QxU9vY3YCrbvtFW5O2Iq+gUkiyUv1O19LvS+kAtsUWwJOMCj6iXIKDv3AhbBxVsjPZ/8+M zNuEKomhbGVZSUZRutItkTdorcQTacXI7ERpNVPewYH+Lo+7SgTfCj70AuFuRPzVqEVB7u i1HT3uCkV0cQoEsmeW0TLxSa2pJscK4= Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-178-_7mIaaktPMWItDvMJeR5YQ-1; Tue, 08 Aug 2023 22:13:53 -0400 X-MC-Unique: _7mIaaktPMWItDvMJeR5YQ-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-1b728bfb372so10757970fac.2 for ; Tue, 08 Aug 2023 19:13:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691547233; x=1692152033; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rTa9TiH+Nbxa2120Ikd+iVzWMSduN4Wn5JO47t6FkLU=; b=T9M5rS8Myu53yxQ6er6Xx8CAftPunnUAgqiICL4GAKO4D/g0dBuEc5FJwhDrtUag0y mvKZuwvZ7rf7hPJUDwMqiSyWxw4fqOLi1syIc4DiYuIp9lyDzwFaOnXlh12rHzumz7QP KCOHBVW/65XD5yoCnDLe4tbisEHuejwNKivWihOY32xTJFxRT9hW70GksT6aWO5uEzaK 7walY2gRcGG3RrnFsOHF1bHLEw3ralVikNS22c8EMfhtEdk8n9J/cVKraFhJ+EFF/ffq VTjVIluvKuzBk42+qdsNhOAlneCc8wPXSzyxyXu43AdknoqmOCkuycF2J1Vt/gSULvOw 1p/Q== X-Gm-Message-State: AOJu0YzrEFQres7iMHm+VCLQwHj8zz+GnZydkMSqWxMWy++Zgr9uknBW fqtcNfb3nnEZ9H/2N8XlJgl6GtbUTaDLKKtund5ti4EihvPdZtrTKmTdvWkP3V09xHg3XaUuLya 9zP82thUyo/CDAj0tj/OX6TPV X-Received: by 2002:a05:6870:7021:b0:1c0:937:455d with SMTP id u33-20020a056870702100b001c00937455dmr1416398oae.47.1691547232928; Tue, 08 Aug 2023 19:13:52 -0700 (PDT) X-Received: by 2002:a05:6870:7021:b0:1c0:937:455d with SMTP id u33-20020a056870702100b001c00937455dmr1416382oae.47.1691547232692; Tue, 08 Aug 2023 19:13:52 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7ec:e667:6b7d:ed55:c363:a088]) by smtp.gmail.com with ESMTPSA id v10-20020a4a8c4a000000b0054fba751207sm6475518ooj.47.2023.08.08.19.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 19:13:52 -0700 (PDT) From: Leonardo Bras To: Will Deacon , Peter Zijlstra , Boqun Feng , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Leonardo Bras , Andrea Parri , Ingo Molnar , Geert Uytterhoeven , Andrzej Hajda , Palmer Dabbelt , Guo Ren Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [RFC PATCH v4 0/5] Rework & improve riscv cmpxchg.h and atomic.h Date: Tue, 8 Aug 2023 23:13:05 -0300 Message-ID: <20230809021311.1390578-2-leobras@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 While studying riscv's cmpxchg.h file, I got really interested in understanding how RISCV asm implemented the different versions of {cmp,}xchg. When I understood the pattern, it made sense for me to remove the duplications and create macros to make it easier to understand what exactly changes between the versions: Instruction sufixes & barriers. Also, did the same kind of work on atomic.c. After that, I noted both cmpxchg and xchg only accept variables of size 4 and 8, compared to x86 and arm64 which do 1,2,4,8. Now that deduplication is done, it is quite direct to implement them for variable sizes 1 and 2, so I did it. Then Guo Ren already presented me some possible users :) I did compare the generated asm on a test.c that contained usage for every changed function, and could not detect any change on patches 1 + 2 + 3 compared with upstream. Pathes 4 & 5 were compiled-tested, merged with guoren/qspinlock_v11 and booted just fine with qemu -machine virt -append "qspinlock". Thanks! Leo Changes since squashed cmpxchg RFCv3: - Fixed bug on cmpxchg macro for var size 1 & 2: now working - Macros for var size 1 & 2's lr.w and sc.w now are guaranteed to receive input of a 32-bit aligned address - Renamed internal macros from _mask to _masked for patches 4 & 5 - __rc variable on macros for var size 1 & 2 changed from register to ulong https://lore.kernel.org/all/20230804084900.1135660-2-leobras@redhat.com/ Changes since squashed cmpxchg RFCv2: - Removed rc parameter from the new macro: it can be internal to the macro - 2 new patches: cmpxchg size 1 and 2, xchg size 1 and 2 https://lore.kernel.org/all/20230803051401.710236-2-leobras@redhat.com/ Changes since squashed cmpxchg RFCv1: - Unified with atomic.c patchset - Rebased on top of torvalds/master (thanks Andrea Parri!) - Removed helper macros that were not being used elsewhere in the kernel. https://lore.kernel.org/all/20230419062505.257231-1-leobras@redhat.com/ https://lore.kernel.org/all/20230406082018.70367-1-leobras@redhat.com/ Changes since (cmpxchg) RFCv3: - Squashed the 6 original patches in 2: one for cmpxchg and one for xchg https://lore.kernel.org/all/20230404163741.2762165-1-leobras@redhat.com/ Changes since (cmpxchg) RFCv2: - Fixed macros that depend on having a local variable with a magic name - Previous cast to (long) is now only applied on 4-bytes cmpxchg https://lore.kernel.org/all/20230321074249.2221674-1-leobras@redhat.com/ Changes since (cmpxchg) RFCv1: - Fixed patch 4/6 suffix from 'w.aqrl' to '.w.aqrl', to avoid build error https://lore.kernel.org/all/20230318080059.1109286-1-leobras@redhat.com/ Leonardo Bras (5): riscv/cmpxchg: Deduplicate xchg() asm functions riscv/cmpxchg: Deduplicate cmpxchg() asm and macros riscv/atomic.h : Deduplicate arch_atomic.* riscv/cmpxchg: Implement cmpxchg for variables of size 1 and 2 riscv/cmpxchg: Implement xchg for variables of size 1 and 2 arch/riscv/include/asm/atomic.h | 164 ++++++------- arch/riscv/include/asm/cmpxchg.h | 394 ++++++++++--------------------- 2 files changed, 195 insertions(+), 363 deletions(-) -- 2.41.0