From patchwork Wed Dec 18 06:20:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13913070 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 76602E77183 for ; Wed, 18 Dec 2024 06:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lvYxXwvEnjyqSBQUdMwEVvz9hfO5O8pSiGSR6Ept2V0=; b=yzMZMKeKUvAc/hkVim1vaUlRnJ adDL3vVy0+epVbmTFNJHUanzwzu8EMWsblCTd5edlp0YYTQEa4KQ9s9wzsn7yhuK8fR8hg4KZNcNP ylXpfDcfyZ4u6v2K3+vNKAFmALB4cBfH3GW8+G1YC4FXxAB0MXyGvTXPi1OXvhG5VWLDMBmnEw9NS WsgAmXB8nzikuhW1DIDeXIfy0ajiYKfUJspKuHTyduOi080M9uRwF+4cwiYreQW7zRD47p7OUnDXr tTHOVVLkGcFGspDfd7AiraifeOJCceZF1K478MfeWIFOXZSfFJBkcsSPv3+OAXjnr7q2GU5rLckKh rAssePbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNnSp-0000000FhiX-1KDc; Wed, 18 Dec 2024 06:23:19 +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 1tNnQj-0000000Fh9r-3P9V; Wed, 18 Dec 2024 06:21:10 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-725f2f79ed9so4884264b3a.2; Tue, 17 Dec 2024 22:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734502869; x=1735107669; 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=kcqFkAn6kvYMWwP2I5Kr+NG5AcbO3wq3HoyP9++fEkg/1/mSqPLT3iC65BZmjlXZR4 /XxID359Ss7DQ5eOykl1K3g8TTCW3XgQ6Bb6VP8JlP2TJ+rgq+pjkHqo47xYPLTUT3D7 wJqa94BAm+lq+Xoo9gy+B7QoxervxvRYmz8hQStzIXRKZng6DcGJXlHCCUlQ7hNvEaNM FPqBSKPdvL4cTgO0S4+tS0BK9LUfK/bptmV8uKd4mtFm6YJ8T8f1y1rb0dCdiMoMdZrn b9+B1H1BytZONH/aQxfUgBzMH4MEloYvHjuvKbDeoPUnhpP9xgVtlEiRVTeLBo/tmzFB 4mkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734502869; x=1735107669; 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=ZrmfNuYYlb8zSpfALjsv6PI2NNgDiyajLP47EVEb1NUiGN9SvQQRUdAi6fPxks52LP A3IUCgHc24293ojPudR05UOw0pTmYECF0s7Ug0iGn5JCoueb48vTGJP0VlC/bQaZGVtU nCSn2609Dyrq9RXSQUFweN3GKYFBmnkqjDtDD2vEDYgyH+4RWJm4Ds8rGIxZLmySIz/C VXhXFsNKBK43Hf4jfgalKWFX4nabnlpaETYycq8pbvLVmQC/r47qS6GB0CGFVwyX4tEI oMGB8i2tcq46nRYPBOt2u0MQ79vV2A2rPKXf5b9t16f1pM1pVdkmPjBmX0GIE1YR4RX1 U7Gw== X-Forwarded-Encrypted: i=1; AJvYcCULLva9CY1PaKQJSUKLdmgNWjaU+dnygUI86J9pWh1yR/HETU1MY/mdJr2ZQB7VcWuefKV6zv7XaYdsWOc=@lists.infradead.org, AJvYcCWCbG34aLHL0b5VH5TIIh+2kfDv8pEXXSH0mWSW2snZcMkwG+zgyJ9uu9NCcjpIvVVQPbsSdZ1M1m+QgAatbPKc@lists.infradead.org X-Gm-Message-State: AOJu0Yx+CIi8BPLKtV4JeDmrNPa4BCxqDOUqcup8L14Ce6HHds252Cki RC9tkLXakqViyUzxLRM4PbYZLYzcAF+K0eHzKv5tbsDEX4kI7Q2f X-Gm-Gg: ASbGncsz3HLBwjwDHf422ByUavXz4epb4FpA2TlufjAGuIRfyM7rGdRAurq68xPFo2E VFL4pIduoN5CxSAr6z+hIpy4k/ACcTx2fXJvVD/xKfly8yE2xUJuKKLKJuwcCNsDvAlK4Un7cnW EUgm0R9piYO3vuzFNBCgpIlI55XEqEyEr9igDCrXOtA3PH+Ees7R8r8zYUzlMrgNMJNVM/loHmN 1j+SBw6wzVXVjoykznWbMaMNjpcchNwwV8LzxFebqWN37Mqfz+jTzQFwnLGJjILOrGcVjiNXkk1 Z7rs9CG1kXQ8Gc8rvw== X-Google-Smtp-Source: AGHT+IH3lAAsImJoXUaublLviIawcjfOTs7NtBTxEZSyuiwkLzPj5BCveefFa5Kl5C1+gqt2KTHhiQ== X-Received: by 2002:a05:6a00:130e:b0:725:f4c6:6b71 with SMTP id d2e1a72fcca58-72a8d2a0d11mr3266430b3a.20.1734502868748; Tue, 17 Dec 2024 22:21:08 -0800 (PST) Received: from snail23.. (p7659208-ipoefx.ipoe.ocn.ne.jp. [221.188.16.207]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72918ad5bc5sm7987806b3a.69.2024.12.17.22.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 22:21:08 -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 v2 1/5] x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Wed, 18 Dec 2024 15:20:05 +0900 Message-ID: <20241218062009.2402650-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241218062009.2402650-1-fujita.tomonori@gmail.com> References: <20241218062009.2402650-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-20241217_222109_851005_03A1A60E X-CRM114-Status: UNSURE ( 8.65 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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 Acked-by: Peter Zijlstra (Intel) --- 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 Wed Dec 18 06:20:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13913074 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 A5167E77183 for ; Wed, 18 Dec 2024 06:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uE1ozcM0HS04q9lZpGc37IxiI38s9WgqP3M8QOeasQ4=; b=2ct2//tpoZyiMMCIm9LT9nmXOJ Rl/FATMGv/9B5nPOE8dRjm+I1c4dWHsoixjh23/BFuHsKdwR8I7Y/hB3FfW3c97Rr8LHkKCRHeXzU 1ahMB/lSG0ERIPjZ10JQ+q4SPY9bsrfjUvRKdV2GE0QmaEE1Oc9n77onWSpcz8PNwNCmnXLO469AL 6vpuK5jpLKDCqQYnozw0UnpNth70mm3G7oH8oY1v/SqAvwmSBD7EMcFtJlraDB8oq5WmSzYTiw3pE 7NGwLfiRkzSrQRFp01VxeSDB7l4Y9QozXmndG9SZjqnZ5KgGzPCUbAsOsJnQHKL+xgdVvvcnL76I2 8FyZ7rXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNnTv-0000000Fhwq-2QTY; Wed, 18 Dec 2024 06:24:27 +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 1tNnQp-0000000FhBU-3g7N; Wed, 18 Dec 2024 06:21:16 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-728ec840a8aso6499976b3a.0; Tue, 17 Dec 2024 22:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734502875; x=1735107675; 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=PBWWhQyF8xqhkITS3nsldrtXPPRGnQqw65RvykwSTLjb/o8Umvysa9ztAcuZ2suLQS Z9AgjN+tfWDtTKY+egGavkNvOw56tdgeXGjUEIWrjrE9dxfY5rzLLe/g56QPbcqB0mFo dMrMeUqHI3GB6qTR4WDnVcUv6iSNw1fsh8Ee+MYPtVPL83AZ+F79cDC9OT9C5CBLD+m+ zMxt/XIRhpzcm381s4AKCKx2au8yUuCe1ppWXvxCgaEPH9cvqrxX0uAEcxlh2VXNGgG6 w/xh7kf+9GHlnX+QH8YKG7l5McG+91Nyyr+/LlAJ1WnuFPq91nLvvD4J5k98B/+1UEUa m/kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734502875; x=1735107675; 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=lLQ13vVqHW8GNj6SVR751cgvDQgUX10P1ecVAFfF4BhdtWfvwQFFEn0saW+oUtKRAJ jxSnV7pzYLWeRWhN5J7cDz2K89Mx4bYXXheb6aOWvafVEYhqNARUABM6ipSjoi24/nDq EfS/yJ+xyJFrNPivdorbEJjX64Fiwx566A17iKWibYl+b8j2H6WRmQxCD8BaYbMCaGn5 tVdRoUaZsiyZXe0xrNjU6lCkG/rsKa/w5DLIjM8i2JcAs0QBfzIIPAlxknh5Tv32kP0I aHFVxMxfBvKSTqeH+uK++rPL1ir7c5KsXOD2Aus1+4NoUqhF7bcKVYJVK/6eC4Un08vn ifdA== X-Forwarded-Encrypted: i=1; AJvYcCVwWG9vRK5O/yoeiWRY2IPe2Tg5lIr0zBAoCEYfmwOlertixdozrLCve80Mwm11uzo+6ePzxXQq319fUTA=@lists.infradead.org, AJvYcCWDFFyeyrqHR4vEzkf430r3dyGB8dDtdMcOaur7Ofayicvvo+/InEGsTJYwZgoOJ/9h6ku99M57yc504vOwg+d6@lists.infradead.org X-Gm-Message-State: AOJu0YxMwX3bPTKWzWou56wRJygLneBKNrfiUVJdbej4XkL+frZGbXI5 pAPSJ0GssM8gS6Jg2h9ZI8wX//6ysRUSzxE3+MPBKHYPMfPj3RnL X-Gm-Gg: ASbGncuCR1a52ER4XODKnV/8MHevPk4nTD/pw2rIsnFHnY67uOCjMPvMYYx1VS84ina T3O9Q4FY/4tutbngIjFuNAImNxhuS/Eu540gfXd3xHwCKU8f4jSwnkbB/Mw1bUkd+w+MWjC7fS+ wNgOZbFci5QmucjKU0Ka1J80IiOJHT3Ge43BstuqDDLO3hej9F90ywLMXUkQdSaq43XrkxL4OhE rRlX08Jx+yNJgsAmcEZtYdLEMokL3uo95UvOA6wZTTWz4gk8wV8SFCHcRylekSPW0oCDnBvDz16 NItXG2H60gc+1KoHpQ== X-Google-Smtp-Source: AGHT+IE8Ef54dNMtI5iw0XGR0f6dNrZGSBFn2rHI6W1DYE3F710PsI3NNNPfVvjoBn7Wi42XdgnDdw== X-Received: by 2002:a05:6a21:3382:b0:1e1:d22d:bc01 with SMTP id adf61e73a8af0-1e5b48831e7mr2645443637.30.1734502874926; Tue, 17 Dec 2024 22:21:14 -0800 (PST) Received: from snail23.. (p7659208-ipoefx.ipoe.ocn.ne.jp. [221.188.16.207]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72918ad5bc5sm7987806b3a.69.2024.12.17.22.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 22:21:14 -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 v2 2/5] riscv/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Wed, 18 Dec 2024 15:20:06 +0900 Message-ID: <20241218062009.2402650-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241218062009.2402650-1-fujita.tomonori@gmail.com> References: <20241218062009.2402650-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-20241217_222115_911688_5025B8D1 X-CRM114-Status: UNSURE ( 9.13 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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 Wed Dec 18 06:20:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13913075 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 66038E77183 for ; Wed, 18 Dec 2024 06:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GaW3Ni06SPvaTbLHs0pbUeHaTTwDPxQuBfccVmzf3vY=; b=T+AT++KXXJ/2AZdKhWPqX/R3aJ 5FeArrMNpPj0spITZthOfSei/hla8F8zsops8RP+fyMTWUrnm68m5Cu90pJbANLxPvjzkkmPSZgaK 4Xy8GbmdUSVi7G5y4Oi+r9dt7DllNzPV4pxzKwNJODFv/Z+l32RgzqkGR3es7Px1+sv9NW5BlRHEm 32P/xIiFhb6/en0e7DrvjrGXhfQe2kd63Lt001AQEpxLTZjmF+YJsBF9jPIF9lLS3vC75syTPfTHe uxaRval88ptsMPkTOmDuKbCvbs+4Lg3PwUCwgKLhMOrzxTzmaPQywUTpk5+/pT14QhTH6OeMndA+D G6+7mL3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNnUz-0000000Fi9V-2mwB; Wed, 18 Dec 2024 06:25:33 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNnQw-0000000FhDf-0ILK; Wed, 18 Dec 2024 06:21:23 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7273967f2f0so6592455b3a.1; Tue, 17 Dec 2024 22:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734502881; x=1735107681; 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=Mn4spuaKel42voPRpa/pSK0zM89c7M4aSN460fTNzrMHxQkoDR7EoNPZcoEHxeiraZ Izic/GeYUplLdRj5pv/6fiOf5az4STY0nm1DwzXfBlOaLE6vusFVAISXd2g265qPeJlb /suhVSyN6iVYJV7frDYz4GZUV+niC9PPlgVC0HlmSJXgGdBvCob8JJ5B8+GxaSqJ00dE NkoJdx5N8+eLGPcyRsvBFIKC0orbhHmKeKUK3ghw8cbszfNSytPdG7kDZmuProIOZOyO H4xsKzrwO3ih4l97nyKDMqntIAitCqI5WStguvHImVaIyj7ZEHH92AV08m3fghbAQynt Wpkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734502881; x=1735107681; 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=csyrNRMxJpl/wPyKCC0cA0wM4a45+qSMq8y00oyxHqeZZx9cL1rs8c9D4PImaPku/E k7UDzSG4MXI/kBsg4MNqpuMyrHn9LRHpFOM+ilSb7pSSu9TobS8uYcdo1y7zw9qkxAyU c0G3P2iy4y5BCWzikG2/NCUAkpwCbeN5vU+Ay7VpLT9L1z8Fi50vgn59JVt3+IYv8EtU j+nD+Q3zFvcahLU0AXkNMkrjJbzlH/kLYrZUpupoVzsohRh6TEwuYkiWokQzhLxOlsfL 3oEwrV7wOCqmhelenewZ0ngfcQopVgH9G8/ILUPLDIaMa2LMVwiIsVnGwHdiFXQJxfS5 spPQ== X-Forwarded-Encrypted: i=1; AJvYcCV442jDLluogq7A7VkYHAQwNH1vR3/relJxLzbKGlw8T3CCHZNcH8zIMq4gqkaY1DKCkgo6epn+UDG3zNJMy6rV@lists.infradead.org, AJvYcCVK67VE+cHQ3MmPYABga8cw52oF17gKln6fRZb72QUA9aA/CRVYqIy03YQdrVhYbvgTD5UAZVVTEU4zwho=@lists.infradead.org X-Gm-Message-State: AOJu0YxbYUfZWQZXPVF9El7VP2xNoqlzUQ/LDzwHzkVQLbY9cV5/uRpS O3WsJCUzwtGWKFp25phDEL7PA8fh4r1Tg46PluiJyOO45nrYpF35 X-Gm-Gg: ASbGncut6+1kWxBlrcBPyO8G4sG+VJLgjPVxGGKSppRMlyWHwy+MZ68bE/phg2dPXXY WpR+2pAeGSa9YLDMECyecOx7auJ1P/YQk1JSDV50I1Kg6yOdFszVqdawX+OsVFTcxcRxEaxqses +PMnpVs+70J1+Rr/Pmg92fAC+g96eJvQcMLuR7E9rKCNVd30gXOaOu4JU7+IEJOJnvjqEiQw/IS kL+S5M+tdree+BlZOWS6o+XbhCo2aMehxu4EKB/dv5Mnwa1ioSzpTbbhDTygGRzqui0fHBhX4wt 82qDEWfVsMImsEJftQ== X-Google-Smtp-Source: AGHT+IEuE5RibS/0PE8QGo2Gm9cyN9hV9VQKXrPoGrTJF/gtHBVwLDycc3gJhMqxVgMQzkxuMYzzBg== X-Received: by 2002:a05:6a00:21c6:b0:71e:13ac:d835 with SMTP id d2e1a72fcca58-72a8d26988emr2575186b3a.11.1734502881056; Tue, 17 Dec 2024 22:21:21 -0800 (PST) Received: from snail23.. (p7659208-ipoefx.ipoe.ocn.ne.jp. [221.188.16.207]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72918ad5bc5sm7987806b3a.69.2024.12.17.22.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 22:21:20 -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 v2 3/5] arm64/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Wed, 18 Dec 2024 15:20:07 +0900 Message-ID: <20241218062009.2402650-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241218062009.2402650-1-fujita.tomonori@gmail.com> References: <20241218062009.2402650-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-20241217_222122_127858_405D49A2 X-CRM114-Status: UNSURE ( 9.90 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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 Wed Dec 18 06:20:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13913076 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 28B7BE77187 for ; Wed, 18 Dec 2024 06:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bV4HRBWZxkX47QY6JDDMA6tt+8zgh76SAzdokkmEw1Y=; b=MJBYVvGEyeKvPUpapMKOtIQC2g E8qg8X69w9YKB8N7VZVwWFdUOcSuGq3aB8GlHF0/Cvp78zOLGvJjzIq/k3dPf+rFjoltaMESekTnx nZ5GKq+91flKTSsd4WQO+/n53ettHD5bjbZ+L/VLEWvFA44zXkQ7rOJ+zv5QKlw6ApME+G1xK7ecH FqVBGosXOB8NUp5E/DTj16M4MOJ/7n05Kx1CBFxeRcvAQjq7ewkb1U4rDiSqUEuA6ZU2NTYy3zAOQ 34rwJlivYnQBXuRiJeCKrs5CJBUbTIxnCaWxF8QOIeKkEs3zfT/O21iKEb8AJ2r9L2/cn357hjDxj Lg1Us9Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNnW5-0000000FiYq-3upp; Wed, 18 Dec 2024 06:26:41 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNnR2-0000000FhGN-0key; Wed, 18 Dec 2024 06:21:29 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7265c18d79bso6513485b3a.3; Tue, 17 Dec 2024 22:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734502887; x=1735107687; 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=bV4HRBWZxkX47QY6JDDMA6tt+8zgh76SAzdokkmEw1Y=; b=L25PHI3yAhEnD1pla33E3d0VGKEjcblAjmSbJYZIS7j7AuxVk9MI9HA7QqL4oRZJsf eYF/FoWTOvd4vrQNWNhAjcEkryDIay2QFqXJMZ5NvTkyqfg7cwVMu6clPGzYTjidJcqV onEWzl8xlkw6vWm5UFCMsxkfs990pqwWAc6t9Kgtj620TicQJhCTLeclpX9M7PDrxl58 W2U7V0VvEm+bgMMHhcZ7dPJLOm+WrdpNeSel8kPpNkIcBKHZzeHlXJ9WyNi5hWIPEurh AedrAxo/ROPqZS4xB1W3Yuf5lsbMIvrkrGc0MSrljA40c1yDY8D7Ginf0GTSY86F3Lpz Iugw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734502887; x=1735107687; 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=bV4HRBWZxkX47QY6JDDMA6tt+8zgh76SAzdokkmEw1Y=; b=M1NJCW6QfMBlIyjEoYiR1Y6dqv3UKE5Yw74PWlp50bTsVAxwchQc8ISSr73mKDcPSU KYrKqG9XC4+rLzNpXSBhpibxjzSUpRQw5x8vQHi8S+vq3Mvmnf7TicSrHGcoqkWbFTyM 2KVJmVHrUcsK9vv/GWafvb8odrotjHHCnQrf5/wBgvTKwdRyHrrJMU+8LIA9eGf+qmv2 kWQB8bIfFC6wdmve9f43jlq/d0qdFcKCKYYJtpxY3UC2Wz9OoulidXY8ArRVxzlNT9pU +oE9NW9NqmJsiLf76BI/HNVgFxUH3Rl1pIhlM/sijkoy2VEQJb0tbo67deFqthLKEjti roLg== X-Forwarded-Encrypted: i=1; AJvYcCVRhsMGFDo6niHaxUo0M09y9jlF5O+S66JYkYulmUfSSJhApahuGaDC3cDI0aFhB+qYX686olMTpg3mliQ=@lists.infradead.org, AJvYcCWP4qt8ahMhYHEPflWMqGIqe8MCEAjXZILFfXBOkYR2+be8hqxyIcCiD+/HP6HUf+apPO+aw3CxqaylAUB8vYzn@lists.infradead.org X-Gm-Message-State: AOJu0YwOWgUNdVs1QvO7VfVxLeufZV8Gmregp35txIMwVGXhL8bZrpNA /3jtNgjhKSMhuUCqQBJX5K5x8K21ZJpo5AbH4pS6h15Q1IIvt9XB X-Gm-Gg: ASbGnctdj0D6e4sMPB/+ZPRkH2ZZCVbY4C2O8gm/1z7uFh+v7oS5mD2tZp8nmPd6+lB 6J/nP8LKafe2fXb5JbB4XUitC0PC9nr6Q3b4USy/EmqgbZJ+N8fekgxrx1Os+CYWa8MJVdeZC9i L4g772isQfnyPdFn44PXO/qzhrcpm+8Ua+mIo9SLupxl5ZwQrMUjzOj7UMbE8igUFAa3Ii9abJH 9fRlbBOivmtcG+nfZdhwBjJYiofsb+LwSLMHWdyXjx+1QBbLLKH2u56BG/sfwbeJuFZ7IP75/bW LnJh62y8q4U31C2isQ== X-Google-Smtp-Source: AGHT+IFlF8vY4Xu+YyeQGqBnLgvAT6KCSD+NGgBHnqg25UXCR6Ho2esifXRrWSvDZ1rmidOkpqKkqw== X-Received: by 2002:a05:6a00:2c87:b0:729:597:4fb2 with SMTP id d2e1a72fcca58-72a8cd37353mr3156867b3a.0.1734502887210; Tue, 17 Dec 2024 22:21:27 -0800 (PST) Received: from snail23.. (p7659208-ipoefx.ipoe.ocn.ne.jp. [221.188.16.207]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72918ad5bc5sm7987806b3a.69.2024.12.17.22.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 22:21:26 -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 v2 4/5] loongarch/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust Date: Wed, 18 Dec 2024 15:20:08 +0900 Message-ID: <20241218062009.2402650-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241218062009.2402650-1-fujita.tomonori@gmail.com> References: <20241218062009.2402650-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-20241217_222128_208787_E90D7425 X-CRM114-Status: UNSURE ( 9.56 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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..5cac2d3efd75 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 Wed Dec 18 06:20:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13913077 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 273FDE77183 for ; Wed, 18 Dec 2024 06:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iwlBx0jrzaKTcJ0dbZncCuW6nwSfqkNTYDsslGfubt4=; b=MiX8yR9/mIedfxJNUWNWWNYWjI oIAlvmXunpietPp8CdZr4qWNUTINVAZB+0uahXRhB4Qh0hkvB4xajA0jA448eCmimbfxRDVkjceAY LIrEr28Wat4YaAYNukIhNWX5e1WGIHW8KLOOCceTo+f+YvBH1HS3+jvrWk+EBAK76AtBjKEHTWszS rI/lE242a2uDMRDSiuzr6x4D3Cnc5nB8T1YZRhitxKN4cnR13TPQ1Yqj8m+fE73sRlSJdwam10V1R D6NDTBl3XBsavTTcD8J9jBM2jncuuTkpBmRTyIv+Kua0wuQdBAA+moBTPd6CjXMx8CGn+5Ub30tKp AMUQOBvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNnXA-0000000Fivx-0mwZ; Wed, 18 Dec 2024 06:27:48 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNnR8-0000000FhHz-0CAg; Wed, 18 Dec 2024 06:21:35 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-725abf74334so5365112b3a.3; Tue, 17 Dec 2024 22:21:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734502893; x=1735107693; 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=iwlBx0jrzaKTcJ0dbZncCuW6nwSfqkNTYDsslGfubt4=; b=LaLAjpaE+ejg6IxH+tXbVyBx/KxN51IhZ5fOkhESn80tFesFrevEfoynZd00W4RI/i VMK8ShvQXCQdp0b7ny2Bft89QdBLkyIH8NFgkhIl6DL/jagdD+bVIXCCR1spFKKHYiuF mlok/yu/LBO6kGuJobzkjeVHzNa/4L2P0Sb9uMSw7e/W8Zy5JIA9T3SJyeM01cAUUdNY 6QcFL/FolFISM7oYM+u/bTvItw4TmJjqgvw8rIRHksEBblcCV0dJicbct/u6TqRvu2YR sZXBDVSvp2RAnmaMbp8MeqJQBA98VHguoNUqNRfU2E+/YcWZe1SinRbU0RRh7TAW9zWr flRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734502893; x=1735107693; 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=iwlBx0jrzaKTcJ0dbZncCuW6nwSfqkNTYDsslGfubt4=; b=EJFeaHofjxj4bOTOjTU376mKL/5KbG/y2nH875uSRVH4JKzlk9fcYa3LKddtescKVC 6TiH5z+aa9Ut9rEHTs5WBWBIeveBd1o2+MX1NETYGhCk2X+LVrC+JZIjSZIIiU+V29e6 uuZSZH7rteMozt/IbPbcZC4+W/nua5KBF2F/CZ1di2QLAa0VEkbMvq7ntBj1EtcEjY08 ccRdQWX9rNcZWITm1WaKy9rhWV8tFyEbEOYXTqaZb9bMqG82lK5MlW2AR26aBYzdY3Kl x/iEx4thBI07SCHVtZooCJUIdXAHlPEWcxVGhWPbvGQkQq0G23nunSlfEMMDLWAJ1Goq ZSuA== X-Forwarded-Encrypted: i=1; AJvYcCXJx5jzWf9bptS95UrsWmorT/aMPHnbgWzoGXV5k17uvTLIyW35W9UWp4khGoz81c83T4tYNODul0JAR+U=@lists.infradead.org, AJvYcCXQOnaAgdxcRj1/QV+Bn3Lzw7ZntZuTcMCRoSWtWCk4/5Jlpq2Dxu0F5FnyZrowmqNHzwM0KK0ev1e+9ONW2pos@lists.infradead.org X-Gm-Message-State: AOJu0Yxlk+pM62IegYMMbJtD9VCqRYZm7Br9ne4Y1dZoYI9t69NQxiY9 i8un8SsJOr396aPOos2F6aHoEUpV3UpVh5S5PqlyIU1ExPJl4uKj X-Gm-Gg: ASbGncuyN/gBX6L1xuk5olRzYhcsXvefUKXyT9mEcdxfBvwEcjFTCHppyqFcWjl9tzY iY4qs6i5HMLYi6Os9T8c4vVX0sZ96WZqgjRjmJCwDj0gFEYeyMb0zP3b1rz4/KIIC+5L1yqfNGb 3bFW9CDY2CT+lluNm7b/QylrFGX7T3UpuAGsXdBA7KarwfoqzMuQ/cPqYbtNdA0pweu2CZXFuVj cMJ+RYkvq8Wnk+Ec9ovxp6Ejv5fWuLyoz9L5bVhqSXTJ/dN72jNpa8RzmhgrE1N2+/DRlE3JBBF iAsj8GgHxSFIwpDRzQ== X-Google-Smtp-Source: AGHT+IHQ4m+HWcjLQvuT9XztCDOhnw/Ackcq84+U+25p09X+uuYbWpONGNOHBq0tC1LQs8iHELt5MQ== X-Received: by 2002:a05:6a00:44cb:b0:726:41e:b314 with SMTP id d2e1a72fcca58-72a8d2c3f2cmr2786241b3a.19.1734502893327; Tue, 17 Dec 2024 22:21:33 -0800 (PST) Received: from snail23.. (p7659208-ipoefx.ipoe.ocn.ne.jp. [221.188.16.207]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72918ad5bc5sm7987806b3a.69.2024.12.17.22.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 22:21:33 -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 v2 5/5] rust: Add warn_on and warn_on_once Date: Wed, 18 Dec 2024 15:20:09 +0900 Message-ID: <20241218062009.2402650-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241218062009.2402650-1-fujita.tomonori@gmail.com> References: <20241218062009.2402650-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-20241217_222134_090273_447F1D1F X-CRM114-Status: GOOD ( 18.54 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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 | 100 ++++++++++++++++++ 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, 125 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 a40a3936126d..633b2c28605c 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 @@ -449,5 +452,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..7ffd9cb1ad75 --- /dev/null +++ b/rust/kernel/bug.rs @@ -0,0 +1,100 @@ +// 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)))] +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!( + "/* {size} */", + ".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!( + "/* {size} */", + 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, 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;