From patchwork Wed Nov 15 14:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1864378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=cRGemSX5; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=ZNTnIhwt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SVmb64mXRz1yRG for ; Thu, 16 Nov 2023 02:01:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xN//lq8RDQ2sLQblI/P4Ble9ZeoevxfOIMor8tuM70s=; b=cRGemSX5lI3/Jj o8Zl7jVOuDCPo1caj6VNTLk4UI7AvQbdA2Mx2NCTbmmlubDMai8ZTdgcCzlZybJSLT6DgZAu3ej8e iHlMN6lxIn1N0Lux11Bf9HDG7RJFPBScSUIDj9/sUiOkfWdBcjblXsyORdV8MTPuT/6f/msrGGFId +d3Klg7HVul3ZjYQoLzuhUefao0M+hyrrAvRXEQ/Pb477g/LEElJiHkIcqqOhh/A5G6WhmmamdWRM wBwW8kB6y6bpL8IVHIfBfrw6D7H3UAHTvMMk0KYn7xWSN3cF24bmGHNvbHgFWCwuWijhQYrMcHn6R eUmbtZIedFvgpr2GgSgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3HOO-0016mu-0I; Wed, 15 Nov 2023 15:01:24 +0000 Received: from m126.mail.126.com ([220.181.12.37]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3HOK-0016lz-3A for opensbi@lists.infradead.org; Wed, 15 Nov 2023 15:01:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=eICZA VEGifeO87zyIv2YuCpCweI9e4uksU3ijqVVPIU=; b=ZNTnIhwt6gl5lLcKkM2jx OPq72CUaFcmCZU+HJ6eT0vMPxeDbAWIEsZttxkgA+asiRrh/dj5KY1k74rGuWHuW MY16eaEnkGfuubCBnY/bc7fDYc6VFePGuMaWYF8jc7z9wsm1w8yXiQTdnpcWnLqq 4mptWJfaGhJH5ActTiLAu8= Received: from T490.lan (unknown [112.83.183.252]) by zwqz-smtp-mta-g3-0 (Coremail) with SMTP id _____wCn6zTV3FRlI3f0Cg--.19734S3; Wed, 15 Nov 2023 22:59:34 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , jrtc27@jrtc27.com Subject: [PATCH v2 1/2] lib: sbi: Fix __atomic_op_bit_ord and comments Date: Wed, 15 Nov 2023 22:59:21 +0800 Message-ID: <20231115145929.488427-2-wxjstz@126.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231115145929.488427-1-wxjstz@126.com> References: <20231115145929.488427-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCn6zTV3FRlI3f0Cg--.19734S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7AFy3Jw45uF47Jr4UGr17Wrg_yoW8tr15pr 4av3WDKws0qa47C3srA3y8G3WrCa1vv345Gwsrur98Zw129a1rGF48Kw15Aa15CF48Xr1f ZrW7JrW5C34jqrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zig_-QUUUUU= X-Originating-IP: [112.83.183.252] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcw4pOmSQAZGh6QACsA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_070121_384531_4A4D8053 X-CRM114-Status: UNSURE ( 9.60 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The original code returns the value of the word before modification. When modifying the upper 32 bits under RV64, the value returned via int return will have no meaning. Corrected to return the value [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [220.181.12.37 listed in wl.mailspike.net] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The original code returns the value of the word before modification. When modifying the upper 32 bits under RV64, the value returned via int return will have no meaning. Corrected to return the value of the bit. And modify the function description. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- include/sbi/riscv_atomic.h | 8 ++++---- lib/sbi/riscv_atomic.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/sbi/riscv_atomic.h b/include/sbi/riscv_atomic.h index 3972e0b..c5aa05e 100644 --- a/include/sbi/riscv_atomic.h +++ b/include/sbi/riscv_atomic.h @@ -39,14 +39,14 @@ unsigned int atomic_raw_xchg_uint(volatile unsigned int *ptr, unsigned long atomic_raw_xchg_ulong(volatile unsigned long *ptr, unsigned long newval); /** - * Set a bit in an atomic variable and return the new value. + * Set a bit in an atomic variable and return the value of bit before modify. * @nr : Bit to set. * @atom: atomic variable to modify */ int atomic_set_bit(int nr, atomic_t *atom); /** - * Clear a bit in an atomic variable and return the new value. + * Clear a bit in an atomic variable and return the value of bit before modify. * @nr : Bit to set. * @atom: atomic variable to modify */ @@ -54,14 +54,14 @@ int atomic_set_bit(int nr, atomic_t *atom); int atomic_clear_bit(int nr, atomic_t *atom); /** - * Set a bit in any address and return the new value . + * Set a bit in any address and return the value of bit before modify. * @nr : Bit to set. * @addr: Address to modify */ int atomic_raw_set_bit(int nr, volatile unsigned long *addr); /** - * Clear a bit in any address and return the new value . + * Clear a bit in any address and return the value of bit before modify. * @nr : Bit to set. * @addr: Address to modify */ diff --git a/lib/sbi/riscv_atomic.c b/lib/sbi/riscv_atomic.c index 528686f..477f709 100644 --- a/lib/sbi/riscv_atomic.c +++ b/lib/sbi/riscv_atomic.c @@ -222,7 +222,7 @@ unsigned long atomic_raw_xchg_ulong(volatile unsigned long *ptr, : "=r"(__res), "+A"(addr[BIT_WORD(nr)]) \ : "r"(mod(__mask)) \ : "memory"); \ - __res; \ + __res & mask ? 1 : 0; \ }) #define __atomic_op_bit(op, mod, nr, addr) \ From patchwork Wed Nov 15 14:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1864375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=TaEmD6rL; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=Zv57UEO2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SVmZD5md5z1yRM for ; Thu, 16 Nov 2023 02:00:52 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8HPnld7GY6kspmnS/NDl/j9BzyM9Fh4nO2rHR2O1R54=; b=TaEmD6rLT54RA/ Y1GRbBwnRbH2/jdWLkDqQ08xunHkLtnvOozEepQzTnxAM/a8tpeNzdA8rybrvc0vRpP+1pKd8OMjB ZUAk7E6NlqJFaK7g0P/wgiXk4eO5v6N2AUQYfAV/eZJndVLTv6WK1dyQiN7iwNnC1oXHXiUV8jhFu feraKLGwXhOV8l5b2JRO8RLPicFwfZWymU7V8u9r8Ztb3sNUPvIzDI/oP52xrigwQxGbYGZEXu/uc HG8xe3fv1iW9OeOWlkiQv8GEu14vxx45RjQpU1SdgE3ceTYdgRcnUuQlM00GPDfJp6Wn/+cK3tk8w sNDsQNkpnvC9e1/VyeeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3HNf-0016dp-0b; Wed, 15 Nov 2023 15:00:39 +0000 Received: from m126.mail.126.com ([220.181.12.28]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3HNa-0016cS-2m for opensbi@lists.infradead.org; Wed, 15 Nov 2023 15:00:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=psqoj 1Y5IxTEsNwa3PrENoBYfIjOSK9T8HR9irIDPlo=; b=Zv57UEO2KIREgSE0wtsNY MyUVqR7Vn2FIoYdomx4TuhJXeYm0M2YL3DDUrE/AxBoiu/Wpw0OQahJctPAQGzp6 feZvatKPm5g63TaJDHhX0RE5CSZE97vTNIqxMk7KqKDeIG49OOlEte4tQHk2FlgV KOjyDJL+FqLCwEd4dYBvEQ= Received: from T490.lan (unknown [112.83.183.252]) by zwqz-smtp-mta-g3-0 (Coremail) with SMTP id _____wCn6zTV3FRlI3f0Cg--.19734S4; Wed, 15 Nov 2023 22:59:34 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , jrtc27@jrtc27.com Subject: [PATCH v2 2/2] lib: sbi: Replace __atomic_op_bit_ord with __atomic intrinsics Date: Wed, 15 Nov 2023 22:59:22 +0800 Message-ID: <20231115145929.488427-3-wxjstz@126.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231115145929.488427-1-wxjstz@126.com> References: <20231115145929.488427-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCn6zTV3FRlI3f0Cg--.19734S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF4rXrWUuFWUJw4DJry7KFg_yoW8CFy3pr 4fWwnrtr4Fqr13G3s7GrW5X3Z8Gan0y3srJrW2gryv93ZI9Fs3WF1F9w15JrW5Ca4xZ34f ArWUGrZ8u34DXa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR4xRDUUUUU= X-Originating-IP: [112.83.183.252] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcw4pOmSQAZGh6QABsD X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_070035_684334_1BAD9FEF X-CRM114-Status: UNSURE ( 5.93 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Simplify atomic-related bit operations through __atomic intrinsics. Signed-off-by: Xiang W --- lib/sbi/riscv_atomic.c | 40 ++++++++++++ 1 file changed, 12 insertions(+), 28 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Simplify atomic-related bit operations through __atomic intrinsics. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- lib/sbi/riscv_atomic.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/lib/sbi/riscv_atomic.c b/lib/sbi/riscv_atomic.c index 477f709..1c852a1 100644 --- a/lib/sbi/riscv_atomic.c +++ b/lib/sbi/riscv_atomic.c @@ -206,40 +206,24 @@ unsigned long atomic_raw_xchg_ulong(volatile unsigned long *ptr, #endif } -#if (__SIZEOF_POINTER__ == 8) -#define __AMO(op) "amo" #op ".d" -#elif (__SIZEOF_POINTER__ == 4) -#define __AMO(op) "amo" #op ".w" -#else -#error "Unexpected __SIZEOF_POINTER__" -#endif - -#define __atomic_op_bit_ord(op, mod, nr, addr, ord) \ - ({ \ - unsigned long __res, __mask; \ - __mask = BIT_MASK(nr); \ - __asm__ __volatile__(__AMO(op) #ord " %0, %2, %1" \ - : "=r"(__res), "+A"(addr[BIT_WORD(nr)]) \ - : "r"(mod(__mask)) \ - : "memory"); \ - __res & mask ? 1 : 0; \ - }) - -#define __atomic_op_bit(op, mod, nr, addr) \ - __atomic_op_bit_ord(op, mod, nr, addr, .aqrl) - -/* Bitmask modifiers */ -#define __NOP(x) (x) -#define __NOT(x) (~(x)) - inline int atomic_raw_set_bit(int nr, volatile unsigned long *addr) { - return __atomic_op_bit(or, __NOP, nr, addr); + volatile unsigned long *ptr; + unsigned long res, mask; + mask = BIT_MASK(nr); + ptr = &addr[BIT_WORD(nr)]; + res = __atomic_fetch_or(ptr, mask, __ATOMIC_ACQ_REL); + return res & mask ? 1 : 0; } inline int atomic_raw_clear_bit(int nr, volatile unsigned long *addr) { - return __atomic_op_bit(and, __NOT, nr, addr); + volatile unsigned long *ptr; + unsigned long res, mask; + mask = BIT_MASK(nr); + ptr = &addr[BIT_WORD(nr)]; + res = __atomic_fetch_and(ptr, ~mask, __ATOMIC_ACQ_REL); + return res & mask ? 1 : 0; } inline int atomic_set_bit(int nr, atomic_t *atom)