From patchwork Tue Dec 10 00:17:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13900561 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DF20E7717D for ; Tue, 10 Dec 2024 00:25:08 +0000 (UTC) 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=CDRfESRLlZ1tzXdnyPTQyVkk6Ks3cNPYKO1yY889j1Y=; b=aNLknaSpPY9cMj PKfUfQsSmY4FJ26IKKAxaZBgO0fR9dLlfo79/EaCq++InwtPMAa2c95UB2Q4Ml8muEJWmJaVj9TeU w1z3eOLHPttG7pIs8Y7ztCwEB+UBdZJVsikhFKiOQbo/qMSoava/SeDiHZCxBVRRinqfvAlAdgHVc EpS7a2rmp4ifS/oVBJYIIxXGyShb+a/iGIDX1xn89Ra/q52dJsJ4wMCabQMdqDxyTSfvV1sVNTp+h VIu182AY/Vayc3kba1ry43oIEttnQwm4ERG54W3siJXLVbHPNo2SdRAlPF+ciWo5nogSAsMGKCgl3 ayWpjAK9mXhsCZPSpVdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKo3i-00000009hOm-2SaW; Tue, 10 Dec 2024 00:25:02 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnyA-00000009gNB-1Dud; Tue, 10 Dec 2024 00:19:19 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-725ec1fa493so1246130b3a.1; Mon, 09 Dec 2024 16:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733789957; x=1734394757; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lvYxXwvEnjyqSBQUdMwEVvz9hfO5O8pSiGSR6Ept2V0=; b=DOxK1P2k9V21Q2cNm3mqZxUv2ZRijAQZqiofCsllSpCQzIoRb04of4IuqYbKS3sf7q loHk74J/z5HrcqEOPfZJjI3D8gNyW29/R+C4hzI02tvMF4J3Zk8cmdDur6TtgbeQ4WCP RqRTJJm6gE08SV/fdu5F1Pe0weom/d6v0Bt7cxBtSR5LWg5W2VsZ5PLtUyNc0Q0y01ef fyXq745hzWi57c2K4JQmrz6I3KX+l4uQ9mk3bbBaez+L0gqqgy6mKjHknVToDExJWNsk 6Hk5IhzBvyFioqVVTdRnsEXEaXVgtxEC31TQaup/loEmNLoPB4jJT/6Xbe75WORI7rAG DKsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789957; x=1734394757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lvYxXwvEnjyqSBQUdMwEVvz9hfO5O8pSiGSR6Ept2V0=; b=w4zynU/7Cy9R8H8jUZAWjFy5aCz4Fb1r7cpGTY1bAEuee9wWgO5WzNcihmF3OM1eao xQs/XFSUBMyKU5QSeUnGKIM6vlCVW3iOM4bzKa2gwTmSJEM662jKiPkXq9ox9M1QJ5er IPd4CcqSULLQyPQqFZpTofoNDgLWkGyNQNOEj7v2wDNTioUmuf5uaWt0bqTuyn88jeKX 4YwMxrKuQl3p3s2zbNHHRVNR50ohqypYpdzydMx8DrTAE4yl8NAT8NhPNTA4eiIHFLCw uvRxei6VME4FTOOpu3gpFyeMtc6pFSBySZUr4R/afl9TUgjguerI3AEH3QjVXf+QiBjV N6Xg== X-Forwarded-Encrypted: i=1; AJvYcCW6umXAlvp0alSK3LglveTt67O18m0f3XFdOLsLTsLpsypN0EUgPoChje7NdHroHn2ywiH4uWUtd8hjDfw=@lists.infradead.org, AJvYcCXlcSgeMw1FqgjbUvQZsy6EgjHpeoFNAuEQUQCiO7E6db4puX+sLMKJEGUOaqACcXWbUfVeyWdXrfMOlOvpPe1s@lists.infradead.org X-Gm-Message-State: AOJu0Yw00Vov2IoldB4jiaZHZK6ScdVV7oTRKqqfKGQSzErnWexFn4x4 EYHrmFJPjxcNPpAxrLhFoyD8RZxmfZBAomC39pYkLxQANbhASaag X-Gm-Gg: ASbGncujK5vd84Ibg/yIKpzAfF6kyfz4YwmZmI1lU2iSm0RBzv7RyTEoZ2db/hB4Q9a PIeM9k6mPmmOmSWVEyE7j4YocNWjMoyTluh7KCNd/bewslyoaCuCG9aNoPPsDFhQpIjnUuVmZCG dBEprKlxbiRtOVXUwQJArDK0A0F3IUbrDi2l/fe0IwZ/sh7AggrwIk7ONkbYVnLqG/qC0BgAZY2 /roMirC1zZVncUHZSfB6+VWEfRZvW5MaaI30d5n4UKaZOJjwbK9j/4Jykh8Yvry1GCZq39g45aI zzkk7pNlKq295XPKxtF/I+ntzjaw X-Google-Smtp-Source: AGHT+IGXDLB74qKfVuatRG8d4NT0q2/7WE7V1EKSlo1ahbfyprBuniJ//vSx8P3YzstgSPlCq25zXA== X-Received: by 2002:a05:6a00:1815:b0:725:e015:9090 with SMTP id d2e1a72fcca58-7273c90ae9bmr3318953b3a.9.1733789957264; Mon, 09 Dec 2024 16:19:17 -0800 (PST) Received: from mew.. (p4007189-ipxg22601hodogaya.kanagawa.ocn.ne.jp. [180.53.81.189]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725f1fba027sm2005005b3a.3.2024.12.09.16.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:19:17 -0800 (PST) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: x86@kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, peterz@infradead.org, hpa@zytor.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, tangyouling@loongson.cn, hejinyang@loongson.cn, yangtiezhu@loongson.cn, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu Subject: [PATCH v1 1/5] x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Tue, 10 Dec 2024 09:17:57 +0900 Message-ID: <20241210001802.228725-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210001802.228725-1-fujita.tomonori@gmail.com> References: <20241210001802.228725-1-fujita.tomonori@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_161918_330779_8DD6AE77 X-CRM114-Status: UNSURE ( 7.92 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add new ARCH_WARN_ASM macro for BUG/WARN assembly code sharing with Rust to avoid the duplication. No functional changes. Signed-off-by: FUJITA Tomonori --- arch/x86/include/asm/bug.h | 51 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 806649c7f23d..71df68e2a731 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -28,45 +28,42 @@ #ifdef CONFIG_GENERIC_BUG #ifdef CONFIG_X86_32 -# define __BUG_REL(val) ".long " __stringify(val) +# define __BUG_REL(val) ".long " val #else -# define __BUG_REL(val) ".long " __stringify(val) " - ." +# define __BUG_REL(val) ".long " val " - ." #endif #ifdef CONFIG_DEBUG_BUGVERBOSE +#define __BUG_ENTRY(file, line, flags) \ + "2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ + "\t" __BUG_REL(file) "\t# bug_entry::file\n" \ + "\t.word " line "\t# bug_entry::line\n" \ + "\t.word " flags "\t# bug_entry::flags\n" +#else +#define __BUG_ENTRY(file, ine, flags) \ + "2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ + "\t.word " flags "\t# bug_entry::flags\n" +#endif + +#define _BUG_FLAGS_ASM(ins, file, line, flags, size, extra) \ + "1:\t" ins "\n" \ + ".pushsection __bug_table,\"aw\"\n" \ + __BUG_ENTRY(file, line, flags) \ + "\t.org 2b + " size "\n" \ + ".popsection\n" \ + extra #define _BUG_FLAGS(ins, flags, extra) \ do { \ - asm_inline volatile("1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ - "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ - ".popsection\n" \ - extra \ + asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c0", \ + "%c1", "%c2", "%c3", extra) \ : : "i" (__FILE__), "i" (__LINE__), \ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0) -#else /* !CONFIG_DEBUG_BUGVERBOSE */ - -#define _BUG_FLAGS(ins, flags, extra) \ -do { \ - asm_inline volatile("1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ - "\t.word %c0" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c1\n" \ - ".popsection\n" \ - extra \ - : : "i" (flags), \ - "i" (sizeof(struct bug_entry))); \ -} while (0) - -#endif /* CONFIG_DEBUG_BUGVERBOSE */ +#define ARCH_WARN_ASM(file, line, flags, size) \ + _BUG_FLAGS_ASM(ASM_UD2, file, line, flags, size, "") #else From patchwork Tue Dec 10 00:17:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13900562 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C81EDE7717D for ; Tue, 10 Dec 2024 00:26:09 +0000 (UTC) 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=VpdnS5S0xvM77Gkl3m5K8gXXIm/bMfyMlurN0zMeH5U=; b=eO5oHe2IrIMXKV k8mUvUXF/nQoOKBbgvDBJrgPw37sTNy105sqvlRf8pGW12/pHJ7PIq4sjpxRZQ6iWOLeexY6FrzDh RZD20eFeuTzqaMCnoifyPvTlRngOl3nnHW4pHSO28/fQW4tJSdZzgKQ5vQTqKTJPmnDywS8uzlX/k 5P6ypfUEaOHQXlXkS9bJPIH1IHe4w5AzdPouobVOhhP2TKypVAhW+04qn5L7+3ps8seJFcRWJIJpo kJfPg2JVPV7qXYxcFUcHzY25Tsihx1DrwZWucOWfppaSEFrmDdbyTkiFwsapsdeIfPuzzniBP6Iwc nvqQCAjkkyjdbj6tPlKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKo4j-00000009haZ-3HDY; Tue, 10 Dec 2024 00:26:05 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnyH-00000009gPF-2MXX; Tue, 10 Dec 2024 00:19:26 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-725f4025e25so1077525b3a.1; Mon, 09 Dec 2024 16:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733789964; x=1734394764; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uE1ozcM0HS04q9lZpGc37IxiI38s9WgqP3M8QOeasQ4=; b=Y/uhKCRmidgHT3KU+TNsY4oYAd4HLRaD7+YgZcHvGMIXCwPNcAt3nTAOx27wqbmg4V /04BgtI2xFSNx9UBdDs94BeD/fv2tnAygLVaOR07ig/64VVltdYlWxzJoXai4VbRkpae 5lx3KNIntuZ8ZBgjsQ41I5SfEYNVfhHampZHJqLuDW6A000FRWMYfpYRRU4zBQKTEWtI KyfJLF+o09SuS6CvWBZVNHImJdauuZobxSoRjatoqchKAl7qXuVNuAWEb+f3dW84MHx+ dPYpfF3MQJChb2T6mG+PdurGU14FM6OyVimcYxDO7am7HuDEYsSdq1pEqYMCsB04uPKR zMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789964; x=1734394764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uE1ozcM0HS04q9lZpGc37IxiI38s9WgqP3M8QOeasQ4=; b=On89pF8Ev/zmbld9Gjf0QLoP9fWbSPuM5vIgSccjt3HoRY+gscgbtdPxaOtNXtPnxu UFI7XIwqvUq2dznuDA+/PatguWSd4AqnZGx2yZT6R3YlRFtSAqb8AsCI02G7q6/zqbKS A9i62zAtI1yQuXH+2VHzquscyNt9rble2n3989J0tJIOCrJQ56JjtUqe2q/YCZi7OsFy l4R8n0EcvFWy6/CCh/9T3SU1bLfpKh7h+DFv4uUbdo2xAuXSC8OzuNV6LnSLY0kXIMjo kKem5frOTNXFdFpgEvDRK2KSVKuudAqJG7/Xx/8KyeSEAlc9X8wP7634Mu7vNzX/iU1t 8mRA== X-Forwarded-Encrypted: i=1; AJvYcCV3P8M3mTxI1cmdQQmOHOLW7ylGQTEm+cr26YGKUnRwcSwJZs/ccEYLV7n+X/rlELpGiDi7r2CV4EQOh4/no97n@lists.infradead.org, AJvYcCW+JGnDAaBNvUonqFQrwF9GQkAVegg2tLb1Wgw7pGoNP3vMn0tB7KiwWmlAwCxM3jrWDe8imN+5wKdpYRs=@lists.infradead.org X-Gm-Message-State: AOJu0YzNERsZdMocp2LYXMeGHUB3ZJ5Fql0jRJlRhSF3vGbO57+hnjn6 yEtikqd+SGQSM86iv+mRunabzqJcJ/oUytXymiD7XGj9UhOVc7cx X-Gm-Gg: ASbGncv82TvZ9h3XdDyIoh9WWZpZgtVbV9IKpc+KhsCEI0PT/IFafPCNBexqZXyaTDi Hd+PJf2ijnwfljbaav0fK4vKejqWJo9HkEE7tg3jWAu6pbkaxPJy6BE7dPj1juW2CNAIxt8GZwZ r406pQqK94+H+WeRXFpYu662xFEO+8BFQHrl2kh117Br0P1614FAH5w/Lotuu3FHo7hDVo9mz0q LhoCIlJnSTVW67U9SQY3XOnwqE0VeU235sGJMWyzNCEOVxbaKcR3ur0ZFaS++QDwthue+SIojKT itF9CMbdWZpllY2RB8BNWFiVbF8X X-Google-Smtp-Source: AGHT+IE0sO05jto/zLfmn6/T151S8aCpOvFIvTm7U8rW5Jtk2M587AQu6vur1sMtmKA/fHe5aWFjDA== X-Received: by 2002:a05:6a00:3e1b:b0:727:3935:dc83 with SMTP id d2e1a72fcca58-7273935f820mr4927070b3a.10.1733789963629; Mon, 09 Dec 2024 16:19:23 -0800 (PST) Received: from mew.. (p4007189-ipxg22601hodogaya.kanagawa.ocn.ne.jp. [180.53.81.189]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725f1fba027sm2005005b3a.3.2024.12.09.16.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:19:23 -0800 (PST) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: x86@kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, peterz@infradead.org, hpa@zytor.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, tangyouling@loongson.cn, hejinyang@loongson.cn, yangtiezhu@loongson.cn, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu Subject: [PATCH v1 2/5] riscv/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Tue, 10 Dec 2024 09:17:58 +0900 Message-ID: <20241210001802.228725-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210001802.228725-1-fujita.tomonori@gmail.com> References: <20241210001802.228725-1-fujita.tomonori@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_161925_603479_8F796A02 X-CRM114-Status: UNSURE ( 8.49 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add new ARCH_WARN_ASM macro for BUG/WARN assembly code sharing with Rust to avoid the duplication. No functional changes. Signed-off-by: FUJITA Tomonori --- arch/riscv/include/asm/bug.h | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h index 1aaea81fb141..ee6b9b787e46 100644 --- a/arch/riscv/include/asm/bug.h +++ b/arch/riscv/include/asm/bug.h @@ -31,40 +31,45 @@ typedef u32 bug_insn_t; #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS #define __BUG_ENTRY_ADDR RISCV_INT " 1b - ." -#define __BUG_ENTRY_FILE RISCV_INT " %0 - ." +#define __BUG_ENTRY_FILE(file) RISCV_INT " " file " - ." #else #define __BUG_ENTRY_ADDR RISCV_PTR " 1b" -#define __BUG_ENTRY_FILE RISCV_PTR " %0" +#define __BUG_ENTRY_FILE(file) RISCV_PTR " " file #endif #ifdef CONFIG_DEBUG_BUGVERBOSE -#define __BUG_ENTRY \ +#define __BUG_ENTRY(file, line, flags) \ __BUG_ENTRY_ADDR "\n\t" \ - __BUG_ENTRY_FILE "\n\t" \ - RISCV_SHORT " %1\n\t" \ - RISCV_SHORT " %2" + __BUG_ENTRY_FILE(file) "\n\t" \ + RISCV_SHORT " " line "\n\t" \ + RISCV_SHORT " " flags #else -#define __BUG_ENTRY \ - __BUG_ENTRY_ADDR "\n\t" \ - RISCV_SHORT " %2" +#define __BUG_ENTRY(file, line, flags) \ + __BUG_ENTRY_ADDR "\n\t" \ + RISCV_SHORT " " flags #endif #ifdef CONFIG_GENERIC_BUG -#define __BUG_FLAGS(flags) \ -do { \ - __asm__ __volatile__ ( \ + +#define ARCH_WARN_ASM(file, line, flags, size) \ "1:\n\t" \ "ebreak\n" \ ".pushsection __bug_table,\"aw\"\n\t" \ "2:\n\t" \ - __BUG_ENTRY "\n\t" \ - ".org 2b + %3\n\t" \ - ".popsection" \ + __BUG_ENTRY(file, line, flags) "\n\t" \ + ".org 2b + " size "\n\t" \ + ".popsection\n" \ + +#define __BUG_FLAGS(flags) \ +do { \ + __asm__ __volatile__ ( \ + ARCH_WARN_ASM("%0", "%1", "%2", "%3") \ : \ : "i" (__FILE__), "i" (__LINE__), \ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0) + #else /* CONFIG_GENERIC_BUG */ #define __BUG_FLAGS(flags) do { \ __asm__ __volatile__ ("ebreak\n"); \ From patchwork Tue Dec 10 00:17:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13900563 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35A7AE77180 for ; Tue, 10 Dec 2024 00:27:14 +0000 (UTC) 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=SL/6lYNQZqqJnQije09x2jef0lSDWiyfi4XEIz0LQu0=; b=RZXEG7MT5JOs/q nMLWBc64gy4yZmN2y+WauS5klUYHCStTDfIDvd7tk65AiJgc+FeVm92u4k06Nxe7hfJUYNoACj+Gm iS8a5TyV40NnU8hGZt0xDZS+L2Qj1oMD6ry73goxLiV7S4FW+lz0bLYRhU57tkwVYkdqUCVp3vTz9 J1lW0IuxxOu24HZ25+iQyU/bimMtaxcaj1TvX0CHhIjxIImEaVoZxYcpzX31qm43P2mUs/7NmUnzw 53FE6zyQJz0xXxPDcHs2AlTLnHdVd1ab6F6BBKz1ZmTFSCOzrxxjvMRZxN+nCMZkntNpgyxCFW/Ij za3swU6Kbb+XrP3b7THQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKo5k-00000009hpU-45RQ; Tue, 10 Dec 2024 00:27:08 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnyM-00000009gRA-3Gh5; Tue, 10 Dec 2024 00:19:31 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-725c0dd1fbcso3605381b3a.0; Mon, 09 Dec 2024 16:19:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733789970; x=1734394770; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GaW3Ni06SPvaTbLHs0pbUeHaTTwDPxQuBfccVmzf3vY=; b=jsYXOWig0e8YLAH9oEpJt0FuPXueg7NqavFk4HCZJaUH9NxSfUUraKEf3HLBr6cy7y 0KyZRzR6UoWfWi+5ZQ66Y+w6tMcUOKdPZTtIHsoRYKslzAhveIVfGceJCnY/5POIQWmJ NF1WRRY/fBw6dk46dmwqI7u3ZUXbWmb0zO4AxYL6GjJyZ0N1RLMSfMJRuZ09kkGzsxPQ 1n7emsfthIEcEftxaRDCFngomrCdO+1ctrwJQqvO6dsrvgwr2aXGd57bj7pN8dJAl7Hf cdKekmwYBX52+KTcwI9ekR9ZbEGyFkaG9WGlEnm3Yk1DyVAAVkOkpzHhYEo+luK8yLKm qkJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789970; x=1734394770; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GaW3Ni06SPvaTbLHs0pbUeHaTTwDPxQuBfccVmzf3vY=; b=u1idRwqdP8g1WJdACFD6fdBH1/0As7yS5VhWtZUgAPldYLkKhhU8MRY5ushDBQt8Qh qjrRbi8sXDrETkzLxWBXUgrdBDJEBBlVC1+OCDqYzFHarZRBu2jxInlXD0qGosuoywvc Nlm1x46shxRqasfavFbsfdC0Z41VtDKSVF+wd5LffNdT2vljTSj3tdyQMeiZwSBijJ8R 8EYAWWBfNUvMJ3AHJPFdj+G5NBfmOKWMGe6iTxvimUSW24udLb56BpxhWyIoL3z/1L+P v6bs+IxMRdQQBcsMFwjBYMeq2rEFyFws2+tAqPWoAfhlYSX4LQfrrYAjYDr0Bm01C5Kw 4pHg== X-Forwarded-Encrypted: i=1; AJvYcCUyBvuKt1/eD06nDB7uDAMPavBHV8XhmOKtjqoNcvPol2b4g5TPKkK0+zcABZEvigQfQi0VduVM5bGwJoI=@lists.infradead.org, AJvYcCX1sjPzTy62KV9QjUQeXsal+KFmfoUJm2B1T0YbKsC3zN6+SRyDq3RdW79+zA7Tpviz70SB30IOMWDSAuvAWwqM@lists.infradead.org X-Gm-Message-State: AOJu0YyQEKaLeoUX+pBMPzKaWkPX2hVJI9cfN3aOuAK3QTKF4W/psAXT ZYlkfAajmYiIFpQ/0LGNvMU9BXNOFw4augJO/OJBHosNfMSWN8fV X-Gm-Gg: ASbGnctUFm8d4yjI6YSdvgoJuH+Z8A2wxAZ+TowPSWYqSVd0HX/xTERJVEGSF/h4pJi jUCVHhmYC6Um2uvNT+h79eUQm8ykPcgy9ETQKPDd36YQ5TaMvLXiyamSnhwyh+ozrOrAKo94J/E xVqVvrXwSPBcigo0sLlD/uyctydR7NeKq3J5KOvxS5SwRZEvCF+2tTmRufgpsP4v0tj1zYDGdXL t9kBS8aiHPOiOBM6/7ahkDiEQP7d7j3E7sdTVmaMIUi2yCf7HFNJj6ViTU9X5w0RD0nhQ6l6CDe 0/MLvQZow4T8tG9V4fRGr9O/3zqq X-Google-Smtp-Source: AGHT+IEHFQLb+CnaKIfB/aQiVn4EtFWGkBf9ZZUksgIXRkbcaqD+tHXdDTDwGlizNlrZosk3pbCxTw== X-Received: by 2002:a05:6a00:1d8b:b0:725:dab9:f732 with SMTP id d2e1a72fcca58-725dab9f7f2mr11873956b3a.22.1733789970068; Mon, 09 Dec 2024 16:19:30 -0800 (PST) Received: from mew.. (p4007189-ipxg22601hodogaya.kanagawa.ocn.ne.jp. [180.53.81.189]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725f1fba027sm2005005b3a.3.2024.12.09.16.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:19:29 -0800 (PST) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: x86@kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, peterz@infradead.org, hpa@zytor.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, tangyouling@loongson.cn, hejinyang@loongson.cn, yangtiezhu@loongson.cn, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu Subject: [PATCH v1 3/5] arm64/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Tue, 10 Dec 2024 09:17:59 +0900 Message-ID: <20241210001802.228725-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210001802.228725-1-fujita.tomonori@gmail.com> References: <20241210001802.228725-1-fujita.tomonori@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_161930_814170_6C56BE74 X-CRM114-Status: UNSURE ( 9.17 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add new ARCH_WARN_ASM macro for BUG/WARN assembly code sharing with Rust to avoid the duplication. No functional changes. Signed-off-by: FUJITA Tomonori --- arch/arm64/include/asm/asm-bug.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/asm-bug.h b/arch/arm64/include/asm/asm-bug.h index 6e73809f6492..822e9d51d3e9 100644 --- a/arch/arm64/include/asm/asm-bug.h +++ b/arch/arm64/include/asm/asm-bug.h @@ -21,16 +21,21 @@ #endif #ifdef CONFIG_GENERIC_BUG - -#define __BUG_ENTRY(flags) \ +#define __BUG_ENTRY_START \ .pushsection __bug_table,"aw"; \ .align 2; \ 14470: .long 14471f - .; \ -_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ - .short flags; \ + +#define __BUG_ENTRY_END \ .align 2; \ .popsection; \ 14471: + +#define __BUG_ENTRY(flags) \ + __BUG_ENTRY_START \ +_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ + .short flags; \ + __BUG_ENTRY_END #else #define __BUG_ENTRY(flags) #endif @@ -41,4 +46,22 @@ _BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ #define ASM_BUG() ASM_BUG_FLAGS(0) +#ifdef CONFIG_DEBUG_BUGVERBOSE +#define __BUG_LOCATION_STRING(file, line) \ + ".long " file "- .;" \ + ".short " line ";" +#else +#define __BUG_LOCATION_STRING(file, line) +#endif + +#define __BUG_ENTRY_STRING(file, line, flags) \ + __stringify(__BUG_ENTRY_START) \ + __BUG_LOCATION_STRING(file, line) \ + ".short " flags ";" \ + __stringify(__BUG_ENTRY_END) + +#define ARCH_WARN_ASM(file, line, flags, size) \ + __BUG_ENTRY_STRING(file, line, flags) \ + __stringify(brk BUG_BRK_IMM) + #endif /* __ASM_ASM_BUG_H */ From patchwork Tue Dec 10 00:18:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13900564 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFBE4E7717D for ; Tue, 10 Dec 2024 00:28:16 +0000 (UTC) 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=h6XPZ7wkSL2pjtA4a9pFwBv2vqqztMsay8KrS+3x5yc=; b=ubIveLBSJpxWfB H+Mntfnxvd6p7jV7mUj2W4i9HgXq9go2knCLm6aj3hPFwyzpozo3kT8/XdMjy/Lc3KgEeYSSWHoWX efVYH/rjFijFP7dBk1rIFdNjiB+/2+Y1RkuBNyroPqOjtx0IlUuN6ua01QlXpvljvcismpVj+zHsq HDlFWgtLfkI0kUIS428GWuam5mS1VJIyxzbttd3QtDty9cD3udBGlWntHEpcHlP2b6H1M2GP02Tqy vePXkQ+L+JwJFNs7zJZGWH36g5c5NHD6WLsfgsIgsJ+ID/+hkYqKbrUrwijixT8Zto/jckByGW6lO 6lNF9e4nCW2whpW/IE1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKo6m-00000009i2v-0aGH; Tue, 10 Dec 2024 00:28:12 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnyT-00000009gT5-2EH2; Tue, 10 Dec 2024 00:19:38 +0000 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7fbc65f6c72so4869377a12.1; Mon, 09 Dec 2024 16:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733789976; x=1734394776; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Og2RZIwk2Fmm4a1enxRaJzgczmbvkc80VyX2Z+HeAaA=; b=T9Z9VIDVqGG6IS0jMS6nFDIJL/1xVlRyI3WzHgoBNQswZbuXnF9LI3FZCY0jfr2nFt DF8kpoQKgCsYJ4ShxjYAV0hXQVqZDwXQhQE7h/yXB3a6Aq6U4i5XU9q/BhLzOksqi5HK rs52gdFsgsw7wvOhfKKu7MFLYk53BlN9gbKsIF88bbwoSmQ/1vTjJP0sdkdpt6YLzCYq F/QmxGwDXIEptLoBhl8ClhifKQRCE/ztgOMjM+L5Gi2+0ynYpsoqtzeA7zJR0vKcQKqD 2SzQPd3O/awDB68man9+AHu/xUl2ZMT21PV6M41q5XGJUjwnrPw8wt+GBY9wVub73aZk Lupg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789976; x=1734394776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Og2RZIwk2Fmm4a1enxRaJzgczmbvkc80VyX2Z+HeAaA=; b=bZ453vrnW3ujPyuuE7f6srULuQcmnETi7ny2InhjECAFXzIa9nWOQ5QAM4x7DmEEr6 02MxoBWT3uS5MMLWXdNfzOLe1HDTLpxeiL6vJ4iuQJypkIKqlCXRXhzMBde+h9MKgQIt eLXObS+YIBv1qRpC0UuKHFeOR5Gnt7aJSvD4UdBTZzrxlbmxF3/CBPXWbQbBnz0svjgn 9P1ozKGbea7gABRuRJzq2Y764dOfnFFWg5s5gi0HDNZnYA8am2AHHueAnupplH2q3w5l FGnL15ywoRm4qH9nldCeR9Da0sR62mUGdIdLDlZfNOo4O1LywaifOiKqCGA7RKGWJxep Nr2A== X-Forwarded-Encrypted: i=1; AJvYcCUMzxSUkhHexs4vO27Y6RHxHROAvwZ4WzKUWbNRBWMn1H7fSdO0QtxTVlPUIycG7qbCjV2oFyQPRVzlgeY=@lists.infradead.org, AJvYcCVVx7kbjDJ/+jmyJjPnpOkY6KXyGtECxxiNUoNbb6oAhi0Q6yX38jPw0k0Zp1VfOeDLaDrtog3wIXqQu8mfMt3b@lists.infradead.org X-Gm-Message-State: AOJu0YwIHVzaA/dRZ2A1iuaE1E8HVfRdvKUpbiI3PYGSRWlOEAbXunrH yGMus1W5LSlbKS3989gV02QSyGR2S8vexfBB3csIiBWIyuBPCJT5 X-Gm-Gg: ASbGncu5r15OnHr0NaQ2/CAzhPgsh9fszuYNgxjxpHN3A+6RQhQeXHiWjeY8JBsBHpw vTPlYU2xq88rd/wqSTc3WqSIW/Y1p7fEx2dHFasccAtXBaWpJIEs/5NoyA/z2kD10gr2QV2rIeO /MTaKIWWa8qDR2nu/5eBl6AflL2H5/kheaQHNF7/vjvujsx45gEtTvR43rydJLzu4PV3S+PB6ul hEDBi9dFDg/GG+UmYdP8txAG3UXhflOEMGH4EmVzKgjvJ6w9ezClIFPA7TY4YCYvfthHW+sQaud PbADDSugoxUC4f4ooLbnrAzhf0c2 X-Google-Smtp-Source: AGHT+IFzrftQzGze1g0ifR+gfHYjdPe8pRM5le+6CFZEL33/9GPgGvUcXSJX0JYy+N5Of4n1uRZr/g== X-Received: by 2002:a05:6a21:8cc7:b0:1d9:c78f:4207 with SMTP id adf61e73a8af0-1e1870bb625mr22034147637.11.1733789976324; Mon, 09 Dec 2024 16:19:36 -0800 (PST) Received: from mew.. (p4007189-ipxg22601hodogaya.kanagawa.ocn.ne.jp. [180.53.81.189]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725f1fba027sm2005005b3a.3.2024.12.09.16.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:19:36 -0800 (PST) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: x86@kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, peterz@infradead.org, hpa@zytor.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, tangyouling@loongson.cn, hejinyang@loongson.cn, yangtiezhu@loongson.cn, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu Subject: [PATCH v1 4/5] loongarch/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Tue, 10 Dec 2024 09:18:00 +0900 Message-ID: <20241210001802.228725-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210001802.228725-1-fujita.tomonori@gmail.com> References: <20241210001802.228725-1-fujita.tomonori@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_161937_561740_DB3BAF9E X-CRM114-Status: UNSURE ( 8.83 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add new ARCH_WARN_ASM macro for BUG/WARN assembly code sharing with Rust to avoid the duplication. No functional changes. Signed-off-by: FUJITA Tomonori --- arch/loongarch/include/asm/bug.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/include/asm/bug.h b/arch/loongarch/include/asm/bug.h index 08388876ade4..2343c4226595 100644 --- a/arch/loongarch/include/asm/bug.h +++ b/arch/loongarch/include/asm/bug.h @@ -21,14 +21,21 @@ #ifndef CONFIG_GENERIC_BUG #define __BUG_ENTRY(flags) #else -#define __BUG_ENTRY(flags) \ + +#define __BUG_ENTRY_START \ .pushsection __bug_table, "aw"; \ .align 2; \ 10000: .long 10001f - .; \ - _BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ - .short flags; \ + +#define __BUG_ENTRY_END \ .popsection; \ 10001: + +#define __BUG_ENTRY(flags) \ + __BUG_ENTRY_START \ + _BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ + .short flags; \ + __BUG_ENTRY_END #endif #define ASM_BUG_FLAGS(flags) \ @@ -55,6 +62,24 @@ do { \ unreachable(); \ } while (0) +#ifdef CONFIG_DEBUG_BUGVERBOSE +#define __BUG_LOCATION_STRING(file, line) \ + ".long " file "- .;" \ + ".short " line ";" +#else +#define __BUG_LOCATION_STRING(_file, _line) +#endif + +#define __BUG_ENTRY_STRING(file, line, flags) \ + __stringify(__BUG_ENTRY_START) \ + __BUG_LOCATION_STRING(file, line) \ + ".short " flags ";" \ + __stringify(__BUG_ENTRY_END) + +#define ARCH_WARN_ASM(file, line, flags, size) \ + __BUG_ENTRY_STRING(file, line, flags) \ + __stringify(break BRK_BUG) ";" + #define HAVE_ARCH_BUG #include From patchwork Tue Dec 10 00:18:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13900567 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FB03E7717D for ; Tue, 10 Dec 2024 00:29:20 +0000 (UTC) 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=tda+xBPiY5GoTnuIJ29LWt3qnPdse484nT6YGxFUgzQ=; b=A23eFZtP4cBxw+ 3rjEzfV7PlU9CJVTDRT29OyPquLlDBYsVdwgLOTdZ7LUdXFKmVRRP7svw6708wlg7u60yg/ebnaLF rpp2tGV/C3Q59TJ7z+a0xli5Gh4WZJW3e7/u+9+LYHqoFwplDCA/i4UGvvgqHrhLwaPrLtnLerA76 n07roYBsJeas37awPB3kf8L0+GxOmBp/62ZvV6owDuAKGX95y17kFU/FM96zeHa0LVWgK1CgZcARv /keTn5qPdFsB+ABj36SgYAGzTobOlibYZ1AHtiZZzgFpyAzYP6k3HqMAlrMryLbuCFUNBh96Br3Wg IKC3d7D4+8EXTs4P/lBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKo7n-00000009iDS-1R4s; Tue, 10 Dec 2024 00:29:15 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnyZ-00000009gVl-10gW; Tue, 10 Dec 2024 00:19:44 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-725f4025e25so1077712b3a.1; Mon, 09 Dec 2024 16:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733789983; x=1734394783; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=StSb96QxP9/iNWSVkb/5jVIomgW7WStqt28dyYj6iuc=; b=gQLdugetxjNmDtp/e1/mrZpAGzpuWlgjaaHZ62uS4lswvZd6tB0vZQBNbAR8iu323p NALZhLS9bPMUrL9LLvdyvIDwud8oqlQ4dPr6TmgNssL1fYUBIYVgeNsftDWOhApb3b2H p/yiFiI9uetTMBUDjJPu8cuxvGWguGzawRsc7gO9WPP8jmLaJgrV2fCsRG2lVbyQF+73 aB2sYO3kZI233NP2QeWBr+h8s+T8PhkIl7HhjPAKVsvPrvvVIpCRNy79nK1qH4HZpUqT N6/7D5fX+33+bC04nmiNpDAmXbQZ4hVgJ2gVk+IvjqmwUoMLezumEIQPxHRFwVLyoYoq o0Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789983; x=1734394783; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=StSb96QxP9/iNWSVkb/5jVIomgW7WStqt28dyYj6iuc=; b=drsa2qAC0SbCgBMTp9ATMEfubyRe45SNbEY1Y1atxmRvoJJ9ORnNbrdQQTwQVwv1Gx 57rNfVQFOApurlWHAqXfTvVoyjYOpnO0P+b/b4qmQ/W62mBz0exI7CCAFvqAD1wnrzHH RiouzCs6VTOCJ9+ToWa95nZfO7S4L6qgdLoafsQqS+cgErMHXheHl6j3f3ocNCMd82wT +UNg3zf/f+wopq1xZGcZuPa46C+I3kD1ZlcmQUQy2IJUtbWgFIksCWhP7L8fBQtdEPm5 8+7DBYBDcUtE2H3X5zeoxd0VmnhqQhQHl+TxtNpTI/R5SmFY0KCA+1/+mxGof1N9FWEe G3rw== X-Forwarded-Encrypted: i=1; AJvYcCUY5bqZqmZ03zmQvJo9ETl4/BP7fyGnF8oalE/YMWTFh3l7JFkpN4cxbmfLPQBcXBlTQ5eaWRLsuy1EAWM=@lists.infradead.org, AJvYcCWL9UCZLzswNbs8WeYnR0AEd9zKqjvgL1l7NVprIKuytur/BGJoLPXyr673Xohw9bWeka70gEt7bZC49j5fI+U9@lists.infradead.org X-Gm-Message-State: AOJu0Yzwckd3xQLLfTF3gjyDwQxgpitu3mPx7qEtpMU5t+pj+9MASW1m rKMvDgBBHMvBFY7pWjVHXquqAUT/pGWiINexzOiCR2qmZgS1AC8P X-Gm-Gg: ASbGnct9Kp07Y4BhZIE8B+guI2pCOQSWP3Epjm74LlTFM8p2O0w1IvVhCbjb5qAYpiu G8EEGLgUzDrdDG0VKy5K8vd12Z0UvYVd4YER1Z97WIX4f2kYMmOZTICR3des7FKWmQ10Qu4SkJy wdF8DC04O2eJptDA3JHSzBT0Vniwz2GycGKqVuu7EpftGrmjvNqCViHf5BSFk9mbN0JpaGQLec8 8+VUxfS9Ykx/MfOzPWyv8voBwuEwXE1m95FBwApniecx6wgFzQcfHG4S22Q9NufQOeR4W3oVEcl t1HUoQUIxZGH8oKCwF1w9r/YNb8t X-Google-Smtp-Source: AGHT+IEAyDAPo8at1XMlk9fsI+urdhbvpydHDU/JmlA7KkIMjf5Ed0t5JYgg2Zppc8mo6aYL53N8NA== X-Received: by 2002:a05:6a00:2ea9:b0:725:b702:af with SMTP id d2e1a72fcca58-725b81b7b57mr24866139b3a.25.1733789982639; Mon, 09 Dec 2024 16:19:42 -0800 (PST) Received: from mew.. (p4007189-ipxg22601hodogaya.kanagawa.ocn.ne.jp. [180.53.81.189]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725f1fba027sm2005005b3a.3.2024.12.09.16.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:19:42 -0800 (PST) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: x86@kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, peterz@infradead.org, hpa@zytor.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, kernel@xen0n.name, tangyouling@loongson.cn, hejinyang@loongson.cn, yangtiezhu@loongson.cn, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu Subject: [PATCH v1 5/5] rust: Add warn_on and warn_on_once Date: Tue, 10 Dec 2024 09:18:01 +0900 Message-ID: <20241210001802.228725-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210001802.228725-1-fujita.tomonori@gmail.com> References: <20241210001802.228725-1-fujita.tomonori@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_161943_282258_84EBD51D X-CRM114-Status: GOOD ( 17.93 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add warn_on and warn_on_once macros. Wrapping the C's WARN_* and BUG_* macros doesn't work so this uses the assembly code exported by the C side via ARCH_WARN_ASM macro. Like the static branch code, this generates the assembly code for rust dynamically by using the C preprocessor. file()! macro doesn't work for the Rust inline assembly in the same way as __FILE__ for the C inline assembly. So the code to handle a file name is different from the C assembly code (similar to the arm64/loongarch assembly). ASM_REACHABLE definition works in the same way to get objtool's reachable asm code. The architectures which use objtool (x86 and loongarch) needs it. Signed-off-by: FUJITA Tomonori --- rust/Makefile | 8 ++ rust/kernel/.gitignore | 2 + rust/kernel/bug.rs | 131 ++++++++++++++++++ rust/kernel/generated_arch_reachable_asm.rs.S | 7 + rust/kernel/generated_arch_warn_asm.rs.S | 7 + rust/kernel/lib.rs | 1 + 6 files changed, 156 insertions(+) create mode 100644 rust/kernel/bug.rs create mode 100644 rust/kernel/generated_arch_reachable_asm.rs.S create mode 100644 rust/kernel/generated_arch_warn_asm.rs.S diff --git a/rust/Makefile b/rust/Makefile index 9da9042fd627..80c9c6b3e491 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -37,6 +37,9 @@ obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.o obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o always-$(subst y,$(CONFIG_RUST),$(CONFIG_JUMP_LABEL)) += kernel/generated_arch_static_branch_asm.rs +ifndef CONFIG_UML +always-$(subst y,$(CONFIG_RUST),$(CONFIG_BUG)) += kernel/generated_arch_warn_asm.rs kernel/generated_arch_reachable_asm.rs +endif # Avoids running `$(RUSTC)` for the sysroot when it may not be available. ifdef CONFIG_RUST @@ -436,5 +439,10 @@ $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o \ ifdef CONFIG_JUMP_LABEL $(obj)/kernel.o: $(obj)/kernel/generated_arch_static_branch_asm.rs endif +ifndef CONFIG_UML +ifdef CONFIG_BUG +$(obj)/kernel.o: $(obj)/kernel/generated_arch_warn_asm.rs $(obj)/kernel/generated_arch_reachable_asm.rs +endif +endif endif # CONFIG_RUST diff --git a/rust/kernel/.gitignore b/rust/kernel/.gitignore index 6ba39a178f30..f1d7f4225332 100644 --- a/rust/kernel/.gitignore +++ b/rust/kernel/.gitignore @@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 /generated_arch_static_branch_asm.rs +/generated_arch_warn_asm.rs +/generated_arch_reachable_asm.rs \ No newline at end of file diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs new file mode 100644 index 000000000000..8959a2e94971 --- /dev/null +++ b/rust/kernel/bug.rs @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2024 FUJITA Tomonori + +//! Support for BUG_* and WARN_* functionality. +//! +//! C header: [`include/asm-generic/bug.h`](srctree/include/asm-generic/bug.h) + +#[macro_export] +#[doc(hidden)] +#[cfg(all(CONFIG_BUG, not(CONFIG_UML)))] +#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))] +macro_rules! warn_flags { + ($flags:expr) => { + const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags; + // SAFETY: Just an FFI call. + #[cfg(CONFIG_DEBUG_BUGVERBOSE)] + unsafe { + $crate::asm!(concat!( + ".pushsection .rodata.str1.1, \"aMS\",@progbits, 1\n", + "111:\t .string ", "\"", file!(), "\"\n", + ".popsection\n", + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")), + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs"))); + line = const line!(), + flags = const FLAGS, + size = const ::core::mem::size_of::<$crate::bindings::bug_entry>(), + ); + } + // SAFETY: Just an FFI call. + #[cfg(not(CONFIG_DEBUG_BUGVERBOSE))] + unsafe { + $crate::asm!( + concat!( + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")), + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs"))); + flags = const FLAGS, + size = const ::core::mem::size_of::<$crate::bindings::bug_entry>(), + ); + } + } +} + +#[macro_export] +#[doc(hidden)] +#[cfg(all(CONFIG_BUG, not(CONFIG_UML)))] +#[cfg(any(target_arch = "aarch64", target_arch = "loongarch64"))] +macro_rules! warn_flags { + ($flags:expr) => { + const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags; + // SAFETY: Just an FFI call. + #[cfg(CONFIG_DEBUG_BUGVERBOSE)] + unsafe { + $crate::asm!(concat!( + ".pushsection .rodata.str1.1, \"aMS\",@progbits, 1\n", + "111:\t .string ", "\"", file!(), "\"\n", + ".popsection\n", + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")), + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs"))); + line = const line!(), + flags = const FLAGS, + ); + } + // SAFETY: Just an FFI call. + #[cfg(not(CONFIG_DEBUG_BUGVERBOSE))] + unsafe { + $crate::asm!(concat!( + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")), + include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs"))); + flags = const FLAGS, + ); + } + } +} + +#[macro_export] +#[doc(hidden)] +#[cfg(all(CONFIG_BUG, CONFIG_UML))] +macro_rules! warn_flags { + ($flags:expr) => { + // SAFETY: Just an FFI call. + unsafe { + $crate::bindings::warn_slowpath_fmt( + $crate::c_str!(::core::file!()).as_ptr() as *const ::core::ffi::c_char, + line!() as i32, + $flags as u32, + ::core::ptr::null() as *const ::core::ffi::c_char, + ); + } + }; +} + +#[macro_export] +#[doc(hidden)] +#[cfg(not(CONFIG_BUG))] +macro_rules! warn_flags { + ($flags:expr) => {}; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! bugflag_taint { + ($taint:expr) => { + $taint << 8 + }; +} + +/// Report a warning only once. +#[macro_export] +macro_rules! warn_on_once { + ($cond:expr) => { + if $cond { + $crate::warn_flags!( + $crate::bindings::BUGFLAG_ONCE + | $crate::bugflag_taint!($crate::bindings::TAINT_WARN) + ); + } + $cond + }; +} + +/// Report a warning. +#[macro_export] +macro_rules! warn_on { + ($cond:expr) => { + if $cond { + $crate::warn_flags!($crate::bugflag_taint!($crate::bindings::TAINT_WARN)); + } + $cond + }; +} diff --git a/rust/kernel/generated_arch_reachable_asm.rs.S b/rust/kernel/generated_arch_reachable_asm.rs.S new file mode 100644 index 000000000000..4e65525e4464 --- /dev/null +++ b/rust/kernel/generated_arch_reachable_asm.rs.S @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include + +// Cut here. + +::kernel::concat_literals!(ASM_REACHABLE) diff --git a/rust/kernel/generated_arch_warn_asm.rs.S b/rust/kernel/generated_arch_warn_asm.rs.S new file mode 100644 index 000000000000..8f239b431aa4 --- /dev/null +++ b/rust/kernel/generated_arch_warn_asm.rs.S @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include + +// Cut here. + +::kernel::concat_literals!(ARCH_WARN_ASM("111b", "{line}", "{flags}", "{size}")) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index e1065a7551a3..913f3a5b2a98 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -32,6 +32,7 @@ pub mod alloc; #[cfg(CONFIG_BLOCK)] pub mod block; +pub mod bug; mod build_assert; pub mod cred; pub mod device;