From nobody Sat Jul 25 04:54:07 2026 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 028A134DCE0 for ; Fri, 17 Jul 2026 19:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784315180; cv=none; b=bPOuMHM8rr74GzUAI+VTig7q0nVu7fAIohq2casyE6eDs7/nPGRXNGFl6BHKL3uCk6bq9mHGFEcl1tijq0+Qt4ndXTpyGHlZ1JLVl+qPdcEl+F/FGF8UAlUup1pCXdRQQBppqA+9X1pc6dgQm1H4eqQXPTR7mRBJ9IIbb6AjpHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784315180; c=relaxed/simple; bh=8KfC1Q+hVlMgx18fEn+5U56IOcMygoLf8d8VPItiBVU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OsGeLVnT3ejxquDEPGyARAwbhAM1jvDXmx04HI7LYCpsW/qOXowBdCpV9uIvuUcKKmlVfyK/FabXoLJloOuVtpv/Bmb2vDUMxG4P7t7u3g47I+o1ScIWr2w+QzuWDGQ0wZH9kTR1DtPM9XqfhDW885bLJiqJLC7YSJ+iPmrIg4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XCbzFftE; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XCbzFftE" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-8f1e274ccb9so36508806d6.2 for ; Fri, 17 Jul 2026 12:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784315178; x=1784919978; darn=vger.kernel.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:content-type; bh=REAtAr9MF3gwMGff8xpP1gOdx32tZ9rS1fvQIY3YEN4=; b=XCbzFftEvZRpCsjwHq8kSdNz1+a+FyuP3HKcDnYgiBatkY38b30UixH+oT34jzR/0I jQ8FHu4L5xj4Y8rhH4rK8b4/rX58cPC4nehN/agdjWLCIi906ic3Wr4ob0meVuqs8BaQ ymyZXCB+2ojTzwS+Z+GIJe1AvHssC9E77Xrmqqr4C1Yz0ea/L/RjPcIvx4U5LLpXO71B Tfy9wZk59ri9jbLcRRHXJnIbT2tXR5AQIArmOghGxAXggB7O0qVSV8ASTSsnMhibnUHq chj4AaV8ISxqasBdd5E2iM/49N2dwlQEcR/mopW2/6R6N5XflLlTYQKIX8APNGilUAyM 5MGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784315178; x=1784919978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=REAtAr9MF3gwMGff8xpP1gOdx32tZ9rS1fvQIY3YEN4=; b=f2zO/94IKJo0Z39r6aLIITu/nxWRvK/DgbazuAHjuJCygX9PM1RFeE14HIso+QnTkl kMH+RpgWVmbfeqpA7We6ECBKH8y0vIBLuVl5YZ0OOFt2Z/hdQjUY98hybXZRDPbrU8YS 48/FLnYa5v3oDjWQXncPRoUS9QcmPdohYEdTfksRuM0DJGkmX1y1VpqjQFzlnjLt24Bd hESoqK8F77ZJ/vQvPVnYBx22QxV0LQyWV7PdzOO3YCR/vwe7ErECi9bSHKpAHknat4ut NAhxEPT7gOdbHV2btsFjAojkoklqTySFA/lJ6biypr7UykaLnQKI3QoCz2VkcSB5GkDg d6YQ== X-Forwarded-Encrypted: i=1; AHgh+Ro6ctOcMXbX/IJcH/ptCVvbCBSAlHzajiPYM9AKYqO0WcFLV2lTCN7+jUsskT1dFwAdQJESCAe1RwMwHV0=@vger.kernel.org X-Gm-Message-State: AOJu0YyFaMfQzxS+hTn920ZUCKTNNqq0QlxrWjLa9znOQXqj2tJZO57Y y6rqWmGUTM2aRpU0LwejI59aBUc+SKIQC2VQIuk8OuaK5zd5/YsCrQ7AYDRtclhb X-Gm-Gg: AfdE7cnA4TWpB90EKx3o24jttXZ/RHbSLAtIuG3M5dm0efC4KVSIaf9Sno0l89H3DhA JmKx3a+YCorBQryipompDPkkT5FRqv2lQyJ+jCJsyrWuvP7EKzx2OfpMhS0uIMBv8I9agmUBWvm 48kyhNmgF6etE2Uoq0DFry/GfLkMy+yjmZn4tXqiTHE3FMeVi3QEicHef7yNzI20ade9aOeMiVe 4Jcdtbg2fbscxpXKyRrLmClRoQiH7ykXf+ciSF+KWAVZmftWTsZxBgPlG5FUnVRkcFvzN5va8mW F0RTgQxggYI6Bl/nQwg9JTk8afVpQwY3secZE5XGPXWdlZ8/DaBv9SJYONak8Dqu7q62pltL4uf l/bWFSdrHFxHMMi4VK4cp0yh4eSgpAJaJBC/84oGh0OlaPdHfsPG9Kpa85YfEa2p6/NWUNqMXTi 45kqd6+FSCrWjnGJzSKAU= X-Received: by 2002:a05:6214:1305:b0:8ee:a2f3:af32 with SMTP id 6a1803df08f44-907784dd1a9mr49578396d6.38.1784315177508; Fri, 17 Jul 2026 12:06:17 -0700 (PDT) Received: from TurinLinux.. ([184.144.109.221]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9077871d06csm24035606d6.43.2026.07.17.12.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 12:06:13 -0700 (PDT) From: Nicholas Dudar To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, deller@gmx.de, James.Bottomley@HansenPartnership.com Cc: bpf@vger.kernel.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, visitorckw@gmail.com Subject: [PATCH bpf-next 1/2] bpf, parisc: Add support for BPF_SDIV and BPF_SMOD in the parisc64 JIT Date: Fri, 17 Jul 2026 15:05:43 -0400 Message-Id: <20260717190544.257306-2-main.kalliope@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260717190544.257306-1-main.kalliope@gmail.com> References: <20260717190544.257306-1-main.kalliope@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" emit_call_libgcc_ll() zero-extends the ALU32 operands and calls the unsigned hppa_div64()/hppa_div64_rem() helpers regardless of the BPF instruction's signedness, so the parisc64 JIT does not implement signed BPF_SDIV and BPF_SMOD (off =3D=3D 1). Signed ALU32 and ALU64 div/mod get an unsigned quotient and remainder rather than the verifier's and the interpreter's signed result for negative operands. Add hppa_sdiv64()/hppa_sdiv64_rem() wrapping div64_s64(), thread is_signed =3D (insn->off =3D=3D 1) through the div/mod emit sites, and on t= he signed path sign-extend the ALU32 operands (and the immediate divisor) instead of zero-extending them before calling the signed helpers. bpf_do_misc_fixups() rewrites the zero-divisor and INT_MIN/-1 cases out of the instruction stream before the JIT runs. Signed-off-by: Nicholas Dudar Assisted-by: Claude:claude-opus-4-8 --- arch/parisc/net/bpf_jit.h | 2 ++ arch/parisc/net/bpf_jit_comp64.c | 35 ++++++++++++++++++++++++-------- arch/parisc/net/bpf_jit_core.c | 14 +++++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/arch/parisc/net/bpf_jit.h b/arch/parisc/net/bpf_jit.h index 8b8896959f04..074115c93c90 100644 --- a/arch/parisc/net/bpf_jit.h +++ b/arch/parisc/net/bpf_jit.h @@ -467,6 +467,8 @@ static inline u32 hppa_t21_insn(u8 opcode, u8 r2, u8 r1= , u8 ext8, u8 t) =20 u64 hppa_div64(u64 div, u64 divisor); u64 hppa_div64_rem(u64 div, u64 divisor); +u64 hppa_sdiv64(u64 div, u64 divisor); +u64 hppa_sdiv64_rem(u64 div, u64 divisor); =20 /* Helper functions that emit HPPA instructions when possible. */ =20 diff --git a/arch/parisc/net/bpf_jit_comp64.c b/arch/parisc/net/bpf_jit_com= p64.c index 54b0d5e25e02..c326fa737ec8 100644 --- a/arch/parisc/net/bpf_jit_comp64.c +++ b/arch/parisc/net/bpf_jit_comp64.c @@ -502,14 +502,19 @@ static void emit_call(u64 addr, bool fixed, struct hp= pa_jit_context *ctx) emit_hppa_copy(HPPA_REG_RET0, regmap[BPF_REG_0], ctx); } =20 -static void emit_call_libgcc_ll(void *func, const s8 arg0, - const s8 arg1, u8 opcode, struct hppa_jit_context *ctx) +static void emit_call_libgcc_ll(void *func, const s8 arg0, const s8 arg1, + u8 opcode, bool is_signed, struct hppa_jit_context *ctx) { u64 func_addr; =20 if (BPF_CLASS(opcode) =3D=3D BPF_ALU) { - emit_hppa64_zext32(arg0, HPPA_REG_ARG0, ctx); - emit_hppa64_zext32(arg1, HPPA_REG_ARG1, ctx); + if (is_signed) { + emit_hppa64_sext32(arg0, HPPA_REG_ARG0, ctx); + emit_hppa64_sext32(arg1, HPPA_REG_ARG1, ctx); + } else { + emit_hppa64_zext32(arg0, HPPA_REG_ARG0, ctx); + emit_hppa64_zext32(arg1, HPPA_REG_ARG1, ctx); + } } else { emit_hppa_copy(arg0, HPPA_REG_ARG0, ctx); emit_hppa_copy(arg1, HPPA_REG_ARG1, ctx); @@ -600,6 +605,8 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, stru= ct hppa_jit_context *ctx, u8 rd =3D -1, rs =3D -1, code =3D insn->code; s16 off =3D insn->off; s32 imm =3D insn->imm; + bool is_signed; + void *func; =20 init_regs(&rd, &rs, insn, ctx); =20 @@ -656,29 +663,39 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, st= ruct hppa_jit_context *ctx, fallthrough; case BPF_ALU | BPF_MUL | BPF_X: case BPF_ALU64 | BPF_MUL | BPF_X: - emit_call_libgcc_ll(__muldi3, rd, rs, code, ctx); + emit_call_libgcc_ll(__muldi3, rd, rs, code, false, ctx); if (!is64 && !aux->verifier_zext) emit_zext_32(rd, ctx); break; case BPF_ALU | BPF_DIV | BPF_K: case BPF_ALU64 | BPF_DIV | BPF_K: - emit_imm(HPPA_REG_T1, is64 ? (s64)(s32)imm : (u32)imm, HPPA_REG_T2, ctx); + is_signed =3D (off =3D=3D 1); + emit_imm(HPPA_REG_T1, + is64 || is_signed ? (s64)(s32)imm : (u32)imm, + HPPA_REG_T2, ctx); rs =3D HPPA_REG_T1; fallthrough; case BPF_ALU | BPF_DIV | BPF_X: case BPF_ALU64 | BPF_DIV | BPF_X: - emit_call_libgcc_ll(&hppa_div64, rd, rs, code, ctx); + is_signed =3D (off =3D=3D 1); + func =3D is_signed ? &hppa_sdiv64 : &hppa_div64; + emit_call_libgcc_ll(func, rd, rs, code, is_signed, ctx); if (!is64 && !aux->verifier_zext) emit_zext_32(rd, ctx); break; case BPF_ALU | BPF_MOD | BPF_K: case BPF_ALU64 | BPF_MOD | BPF_K: - emit_imm(HPPA_REG_T1, is64 ? (s64)(s32)imm : (u32)imm, HPPA_REG_T2, ctx); + is_signed =3D (off =3D=3D 1); + emit_imm(HPPA_REG_T1, + is64 || is_signed ? (s64)(s32)imm : (u32)imm, + HPPA_REG_T2, ctx); rs =3D HPPA_REG_T1; fallthrough; case BPF_ALU | BPF_MOD | BPF_X: case BPF_ALU64 | BPF_MOD | BPF_X: - emit_call_libgcc_ll(&hppa_div64_rem, rd, rs, code, ctx); + is_signed =3D (off =3D=3D 1); + func =3D is_signed ? &hppa_sdiv64_rem : &hppa_div64_rem; + emit_call_libgcc_ll(func, rd, rs, code, is_signed, ctx); if (!is64 && !aux->verifier_zext) emit_zext_32(rd, ctx); break; diff --git a/arch/parisc/net/bpf_jit_core.c b/arch/parisc/net/bpf_jit_core.c index 172770132440..a2f93202a2ef 100644 --- a/arch/parisc/net/bpf_jit_core.c +++ b/arch/parisc/net/bpf_jit_core.c @@ -190,3 +190,17 @@ u64 hppa_div64_rem(u64 div, u64 divisor) div64_u64_rem(div, divisor, &rem); return rem; } + +u64 hppa_sdiv64(u64 div, u64 divisor) +{ + s64 sdiv =3D div64_s64((s64)div, (s64)divisor); + + return (u64)sdiv; +} + +u64 hppa_sdiv64_rem(u64 div, u64 divisor) +{ + s64 sdiv =3D div64_s64((s64)div, (s64)divisor); + + return (u64)((s64)div - sdiv * (s64)divisor); +} --=20 2.34.1 From nobody Sat Jul 25 04:54:07 2026 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97A7E35DA79 for ; Fri, 17 Jul 2026 19:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784315185; cv=none; b=OR+H7EQHoJpeZK6utbXxLXu7WPgXZLP7nmjP17KV4c6pVdavS890XqCmJidFixIIcC/CaRmJcR1H0mJEGq33zovZKre2khjwZI7O0pZu+AkGGijTO+WzTBXpUa8W0zDTO59EiZlmxdPeyN06MV1CixLU+hMc0jau8QCK6Z2ml50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784315185; c=relaxed/simple; bh=nWMgcy9zH/zCGg85IYNWf4KjnH9+fNVSaaVmgPl1xDM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lxbp8TymyGIdFAjGIg9hVAjrobRtdpUpH1LqufQ7EMTE3U3cr4+I47Oya+0UXfv7uZ0ku190dXAWWLkeQJef4fzxi/LRd9CFCPWza7B+gCqJGIooOpGpo+vbKABjzAhRcVRUmSLt5BQTnGtWwbu9x5Ogz3qLL57JQ3lNbMECFoU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gkE3hNG2; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gkE3hNG2" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-8e5be46f663so32731106d6.0 for ; Fri, 17 Jul 2026 12:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784315182; x=1784919982; darn=vger.kernel.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:content-type; bh=ErOSeJ2Za9/1ZgC4ztqnYtsxKhikz8KNOMoALAHDxVY=; b=gkE3hNG2ux1nHj9OT+vByI94BA/1KfE4Vmxdqq8u9Eg7ScUJ1MNG8owDvs/Ni2BxP6 XxvrqYSapwhErJb+afcpCGpyjPI0kEUYu8QsJ5JDbElAgQaLAHBS2kFdDwzgw0BtFOnT VP/bIiMJ8Viq4UUyZhGq7iEIRWj5h6v/JmQYLZUw6MMnnfHfUnkw9l7AeppjszGOfiUb A34kDASA9mz3FHPU1xVcjYBm3izAhB/utLYg5yGW10hGXhed/2lD9BSAwGM4Kw1ltawp cPMlsSkifgh+yV+fKi5Z1EnnjY96hyDBYGnVgNIpi4sukB7AYHkaAKWcoXp7Z6okvjbo LDsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784315182; x=1784919982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ErOSeJ2Za9/1ZgC4ztqnYtsxKhikz8KNOMoALAHDxVY=; b=ICIPCF9PFww0zSY1t/aruDAVqZP/Q2vGgnUrjFZyW5Z4Hu3/eYe/rUVVeeLs+YuLNZ wafcWDDwkfl5+nCRcTFrScKJ4OX94CwbEGHwWmCxTjYIAP0GYmxm8bxNbkyWW6wKbkGq CnvMS988w6+/+Vbe8oMglQOqO4PEHFZ7+WupubU/CBzlUa+wIgb24kOIJkUvUxQ0UCon Vhsgr7PVCTSXN5fKyQeZ8Q7cV4w2b4xCv/3GBS4zugsWqlXjLa3l6ts/Tor5rp3cAmse vcqTMZqIvYZMnH5LbzXjvd+Z8RLN4d+mEjUOImbW6pVOqEoCBLCs4OrME9RVBRPPBcAu 9IsA== X-Forwarded-Encrypted: i=1; AHgh+Roe1QLvSsj/jK71MKZzAypiOveG7YUYm42EaBZFsPmRNvYatnzyH8WPNHJ29jkDIC2Mee3k2mQZvuU19tc=@vger.kernel.org X-Gm-Message-State: AOJu0Yww+UAUbLEhv11jqkiqiPFEOH55UQNQ8j7b6hG2bgBv9UhhK0ib CnM8cVez+aLdRQL3mPwAfsDT/oWfNamAhqSjR/NyNUwDDQ6aKTaPy6zv X-Gm-Gg: AfdE7cnJ+zXlCBLc9bRtbxQL5BHVwY/LS+uOhmqBX0M7E7veD9GqsC/9Rs+w/BYQLv9 qPuzdEUmffq5F/7pSz/s6tV7Pnwi9oVfiQuTvWTQsNVQv4DStKi59bmNSU2Re8sqE7XpNZdk1/e 7HMkZNxPi/YVq1ZODLzWRfPguAtiyKLIF4HhdgXfFJF0aISVF9lnlTtfInYsy0r8HmEZtNrySkl oAaR9nXnzS7v0x7YRZV/pt27Ra9iSqruA2bORJhT+eblZ03y2XSSLHW2RpIn8gkHjN7kzcb50jT 3RxFUDa91X4hBmpcsYL5j/chUwsNK25ZJNKJFhjK3BBiSyL33v4UIhACQe/qiUw7PclPZ+k1csR fco9ZthVa7l62ItZb1Nge27+d5q3XcQDB4dNg8tZsBRL/jix3wUzacNYCzhbEgI6QYn1/Kl82XS wNTf/WNPb+ X-Received: by 2002:a05:6214:449e:b0:8fd:6de3:dd8b with SMTP id 6a1803df08f44-9077850ed21mr41084416d6.65.1784315182204; Fri, 17 Jul 2026 12:06:22 -0700 (PDT) Received: from TurinLinux.. ([184.144.109.221]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9077871d06csm24035606d6.43.2026.07.17.12.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 12:06:20 -0700 (PDT) From: Nicholas Dudar To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, deller@gmx.de, James.Bottomley@HansenPartnership.com Cc: bpf@vger.kernel.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, visitorckw@gmail.com Subject: [PATCH bpf-next 2/2] bpf, parisc: Add support for BPF_SDIV and BPF_SMOD in the parisc32 JIT Date: Fri, 17 Jul 2026 15:05:44 -0400 Message-Id: <20260717190544.257306-3-main.kalliope@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260717190544.257306-1-main.kalliope@gmail.com> References: <20260717190544.257306-1-main.kalliope@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" emit_alu_r32() and emit_alu_r64() call the unsigned millicode ($$divU/$$remU) and libgcc-style (hppa_div64()/hppa_div64_rem()) divide/remainder helpers for BPF_DIV and BPF_MOD regardless of the BPF instruction's signedness, so the parisc32 JIT does not implement signed BPF_SDIV and BPF_SMOD (off =3D=3D 1). Signed ALU32 and ALU64 div/mod get an unsigned quotient and remainder rather than the verifier's and the interpreter's signed result for negative operands. Thread is_signed =3D (insn->off =3D=3D 1) through emit_alu_r32()/ emit_alu_r64(), and on the signed path use the $$divI/$$remI signed millicode routines (32-bit) or the hppa_sdiv64()/hppa_sdiv64_rem() helpers added in patch 1 (64-bit) instead of their unsigned counterparts. $$divI and $$remI are extern-declared and exported next to $$divU/$$remU in arch/parisc/kernel/parisc_ksyms.c. bpf_do_misc_fixups() rewrites the zero-divisor and INT_MIN/-1 cases out of the instruction stream before the JIT runs. Signed-off-by: Nicholas Dudar Assisted-by: Claude:claude-opus-4-8 --- arch/parisc/net/bpf_jit_comp32.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/arch/parisc/net/bpf_jit_comp32.c b/arch/parisc/net/bpf_jit_com= p32.c index 5ff0cf925fe9..eea0a34a3bfe 100644 --- a/arch/parisc/net/bpf_jit_comp32.c +++ b/arch/parisc/net/bpf_jit_comp32.c @@ -321,6 +321,8 @@ static void bpf_put_reg32(const s8 *reg, const s8 *src, extern void $$mulI(void); extern void $$divU(void); extern void $$remU(void); +extern void $$divI(void); +extern void $$remI(void); =20 static void emit_call_millicode(void *func, const s8 arg0, const s8 arg1, u8 opcode, struct hppa_jit_context *ctx) @@ -562,12 +564,14 @@ static void emit_alu_i32(const s8 *dst, s32 imm, } =20 static void emit_alu_r64(const s8 *dst, const s8 *src, - struct hppa_jit_context *ctx, const u8 op) + struct hppa_jit_context *ctx, const u8 op, + bool is_signed) { const s8 *tmp1 =3D regmap[TMP_REG_1]; const s8 *tmp2 =3D regmap[TMP_REG_2]; const s8 *rd; const s8 *rs =3D bpf_get_reg64(src, tmp2, ctx); + void *func; =20 if (op =3D=3D BPF_MOV) rd =3D bpf_get_reg64_ref(dst, tmp1, false, ctx); @@ -604,10 +608,12 @@ static void emit_alu_r64(const s8 *dst, const s8 *src, emit_call_libgcc_ll(__muldi3, rd, rs, op, ctx); break; case BPF_DIV: - emit_call_libgcc_ll(&hppa_div64, rd, rs, op, ctx); + func =3D is_signed ? &hppa_sdiv64 : &hppa_div64; + emit_call_libgcc_ll(func, rd, rs, op, ctx); break; case BPF_MOD: - emit_call_libgcc_ll(&hppa_div64_rem, rd, rs, op, ctx); + func =3D is_signed ? &hppa_sdiv64_rem : &hppa_div64_rem; + emit_call_libgcc_ll(func, rd, rs, op, ctx); break; case BPF_LSH: emit_call_libgcc_ll(__ashldi3, rd, rs, op, ctx); @@ -630,7 +636,8 @@ static void emit_alu_r64(const s8 *dst, const s8 *src, } =20 static void emit_alu_r32(const s8 *dst, const s8 *src, - struct hppa_jit_context *ctx, const u8 op) + struct hppa_jit_context *ctx, const u8 op, + bool is_signed) { const s8 *tmp1 =3D regmap[TMP_REG_1]; const s8 *tmp2 =3D regmap[TMP_REG_2]; @@ -666,10 +673,12 @@ static void emit_alu_r32(const s8 *dst, const s8 *src, emit_call_millicode($$mulI, lo(rd), lo(rs), op, ctx); break; case BPF_DIV: - emit_call_millicode($$divU, lo(rd), lo(rs), op, ctx); + emit_call_millicode(is_signed ? $$divI : $$divU, + lo(rd), lo(rs), op, ctx); break; case BPF_MOD: - emit_call_millicode($$remU, lo(rd), lo(rs), op, ctx); + emit_call_millicode(is_signed ? $$remI : $$remU, + lo(rd), lo(rs), op, ctx); break; case BPF_LSH: emit(hppa_subi(0x1f, lo(rs), HPPA_REG_T0), ctx); @@ -1163,12 +1172,12 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, = struct hppa_jit_context *ctx, emit_imm32(tmp2, imm, ctx); src =3D tmp2; } - emit_alu_r64(dst, src, ctx, BPF_OP(code)); + emit_alu_r64(dst, src, ctx, BPF_OP(code), off =3D=3D 1); break; =20 /* dst =3D -dst */ case BPF_ALU64 | BPF_NEG: - emit_alu_r64(dst, tmp2, ctx, BPF_OP(code)); + emit_alu_r64(dst, tmp2, ctx, BPF_OP(code), false); break; =20 case BPF_ALU64 | BPF_MOV | BPF_K: @@ -1211,7 +1220,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, st= ruct hppa_jit_context *ctx, emit_imm32(tmp2, imm, ctx); src =3D tmp2; } - emit_alu_r32(dst, src, ctx, BPF_OP(code)); + emit_alu_r32(dst, src, ctx, BPF_OP(code), off =3D=3D 1); break; =20 /* dst =3D dst OP imm */ @@ -1236,7 +1245,7 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, st= ruct hppa_jit_context *ctx, * src is ignored---choose tmp2 as a dummy register since it * is not on the stack. */ - emit_alu_r32(dst, tmp2, ctx, BPF_OP(code)); + emit_alu_r32(dst, tmp2, ctx, BPF_OP(code), false); break; =20 /* dst =3D BSWAP##imm(dst) */ --=20 2.34.1