From nobody Mon Sep 28 14:46:46 2026 Received: from mail-yx1-f46.google.com (mail-yx1-f46.google.com [74.125.224.46]) (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 757753148A7 for ; Fri, 21 Aug 2026 02:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787280643; cv=none; b=YPcyaQpVyXztwCHx6jWMPwur4+hBAJO+wPLkb5oEqZwkSt6acyH9lZgIWs+Jv+66ZxgNi8oSBtklJK66g3jXG51Suqmct9VsGFkVJnKYkxSMzD4a9eyFCG+2iPwOqgI8KbXlBdlD4tombifeoZK0KbfMs9GV63UQCdl0FsbmHUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787280643; c=relaxed/simple; bh=BYrml0pMXKQLTy35R2yD094JYC3Ix+mC4M+c8TqmOhQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XHCsuJXeHcrdAphSUXm7xvshv5aJ0kJjdrXsdu3TDK0LQPYDW7eNXzKPq5BqOHK3APq5ATj3+pk5m2+Kdcn6psC635mjhj9CIXHulTBONo34YoCnh+EAv6fmHfQ/RWDtAPMNbbtQZYAjwlo2ojdFCJLbK3DV6DNlk5hrZSjtqm4= 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=nbxuDefy; arc=none smtp.client-ip=74.125.224.46 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="nbxuDefy" Received: by mail-yx1-f46.google.com with SMTP id 956f58d0204a3-66c83e34212so680125d50.0 for ; Thu, 20 Aug 2026 19:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787280641; x=1787885441; 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=bLHl1jCdXwSsUFajCWQ0rWHHmvya92XtyYS+pQ7tQVA=; b=nbxuDefy2rZdc4Im0sTdTOTjO0Kap96dfCNctQWBkgXx4iICCfhPorUOFmSXU/of+V +y2yYP6q87WzHWsOw0KMZ6a1FKYGN5U9rhd5FkXzTOu1Q9cyq2vTrtmV3y+TAavROpgK 2TJW3/XjobtkV6wiO04c8veiHVxltoG26cKXhITPzPoncmMMjD3EH6NM1ajowz/9Me02 p57mfdnJkXSK8hGb/XFrVzzSeoLjh7Q0vNJe6aez+eYuGwa1GDFV93RP/nIoNutVhqpG faOXmTSvPktpHfJqKdVFbMUBOuqkQNx4BENmjnr+caxTCKyRaPcrJsaTa7Mq8dKACoWp v2IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787280641; x=1787885441; 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=bLHl1jCdXwSsUFajCWQ0rWHHmvya92XtyYS+pQ7tQVA=; b=M1Tp+nDmit45R/7drgJ4OhvUY61Pk6jf9wUnqDSSFkCu9WN89iIQ9rJhIh3Y1oJrFE JS5sQSZZH8xEXiaIvMHQqH76jUbbDItbFdJI4CT5ATdnV7iDlzmh+aAyc07Us3JPbjMu TC4yuyWsuBPcRgVTYx/iJjEkGVHccNCFzl2WMWrt0UP/un1MwYHBlbrTIYy1tHkj2XPS so+eboRb3Yehibs7pnfVzdWn9to/oqMiSRMnNZ0zTOd+ef5FKFE0gE6tHg/BWl47OCmP E8o04hrste98rjF0UNFcUdPDy0j/jRCTY5tDeUcYpeTo06PwuSmlsId2BHn38pZIU+nZ n3QA== X-Forwarded-Encrypted: i=1; AHgh+RrK8p8rxcKHm0gMC3nYa0g3yH9B9IFkOZb2215gIf6GrS9tQnXa1NdjTl7FauUwoVX4+u1JhDe20TVHuEQ=@vger.kernel.org X-Gm-Message-State: AFuF++luii+aNCJDLi4tAYwvgpG3GdYHACYsrTtLz25MvXF/1/BPoZST kevoc9jt5NZE5oJ+ZwOh8v2ZIohBWs4mwGm1IUcQZ4t7QNUfzEFhVZzA X-Gm-Gg: AR+sD135jVe1CJuGbhpOGSvps88nVfSjJXQjaWu8w9gDG6CCIMpIR+GZ2HLRGuEW+gi DaDyp6RMRIXcVTi66fjGITfmwRIXknUteIreqKBbLTchqhYfu6WVYRLGoYsv65t0gpKfaL0wElO Mq8Ptqn6qyoTU3aZjjb4h1SM4eV11HvB54FTpObFZ0M0uROMpXhI8ejG2HOOhheE+yMhWt92MOB 8x9asR26JZqsEcZiTeF25cTU6rRLchXh54+O3ALPTKDkeiMj9A6AIWifLq1d9O5V1vcexusdFzy RlMlvFmlXUqa3VGqRZ5cG6GeccKKt4aDT8WB3+J0q4+ALODRI7J8SVaSSRXW2Zt8kmAz+Lr3jlu CZlQarQzDNUh/yd8xLLB2l4VySvrSo7y1hjeMRRKZlrm6h9EzhHzwoYVlax1vHREtqrh18x4hRg +LtK9dUMIF/f4K9XNin3usAJMigf6vNteqmma+FX/HAnWZjIuHd/yUlKFuMQ== X-Received: by 2002:a05:690e:191e:b0:66c:d803:b45 with SMTP id 956f58d0204a3-66ce4ade1a5mr1490926d50.25.1787280641489; Thu, 20 Aug 2026 19:50:41 -0700 (PDT) Received: from Turin ([187.15.143.241]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66ccb144956sm3682195d50.13.2026.08.20.19.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 19:50:41 -0700 (PDT) From: Nicholas Dudar To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, johan.almbladh@anyfinetworks.com, paulburton@kernel.org, tsbogend@alpha.franken.de Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, bpf@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 1/2] bpf, mips: Factor narrow loads out of emit_ldx() Date: Thu, 20 Aug 2026 22:46:39 -0400 Message-ID: <20260821024640.1601299-2-main.kalliope@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260821024640.1601299-1-main.kalliope@gmail.com> References: <20260821024640.1601299-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" Factor the byte, half-word, and word load selection out of emit_ldx() in both MIPS JIT backends. The existing unsigned LDX paths remain the only callers and retain the same native instructions, upper-half handling, and clobber accounting. The double-word paths remain unchanged. This gives narrow loads one width dispatcher that can be extended without duplicating the BPF size switch. No functional change intended. Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Nicholas Dudar --- arch/mips/net/bpf_jit_comp32.c | 28 ++++++++++++++++++++-------- arch/mips/net/bpf_jit_comp64.c | 18 ++++++++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c index b3f6b92ac34ed..48a3c834453f2 100644 --- a/arch/mips/net/bpf_jit_comp32.c +++ b/arch/mips/net/bpf_jit_comp32.c @@ -707,24 +707,36 @@ static void emit_trunc_r64(struct jit_context *ctx, c= onst u8 dst[], u32 width) } } =20 -/* Load operation: dst =3D *(size*)(src + off) */ -static void emit_ldx(struct jit_context *ctx, - const u8 dst[], u8 src, s16 off, u8 size) +/* Narrow load operation: dst =3D *(size *)(src + off) */ +static void emit_ldx_narrow(struct jit_context *ctx, + u8 dst, u8 src, s16 off, u8 size) { switch (size) { /* Load a byte */ case BPF_B: - emit(ctx, lbu, lo(dst), off, src); - emit(ctx, move, hi(dst), MIPS_R_ZERO); + emit(ctx, lbu, dst, off, src); break; /* Load a half word */ case BPF_H: - emit(ctx, lhu, lo(dst), off, src); - emit(ctx, move, hi(dst), MIPS_R_ZERO); + emit(ctx, lhu, dst, off, src); break; /* Load a word */ case BPF_W: - emit(ctx, lw, lo(dst), off, src); + emit(ctx, lw, dst, off, src); + break; + } +} + +/* Load operation: dst =3D *(size *)(src + off) */ +static void emit_ldx(struct jit_context *ctx, + const u8 dst[], u8 src, s16 off, u8 size) +{ + switch (size) { + /* Load a byte, half word or word */ + case BPF_B: + case BPF_H: + case BPF_W: + emit_ldx_narrow(ctx, lo(dst), src, off, size); emit(ctx, move, hi(dst), MIPS_R_ZERO); break; /* Load a double word */ diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index ee99f46828c86..22fb58f970223 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -398,8 +398,9 @@ static void emit_trunc_r64(struct jit_context *ctx, u8 = dst, u32 width) clobber_reg(ctx, dst); } =20 -/* Load operation: dst =3D *(size*)(src + off) */ -static void emit_ldx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8 = size) +/* Narrow load operation: dst =3D *(size *)(src + off) */ +static void emit_ldx_narrow(struct jit_context *ctx, + u8 dst, u8 src, s16 off, u8 size) { switch (size) { /* Load a byte */ @@ -414,6 +415,19 @@ static void emit_ldx(struct jit_context *ctx, u8 dst, = u8 src, s16 off, u8 size) case BPF_W: emit(ctx, lwu, dst, off, src); break; + } +} + +/* Load operation: dst =3D *(size *)(src + off) */ +static void emit_ldx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8 = size) +{ + switch (size) { + /* Load a byte, half word or word */ + case BPF_B: + case BPF_H: + case BPF_W: + emit_ldx_narrow(ctx, dst, src, off, size); + break; /* Load a double word */ case BPF_DW: emit(ctx, ld, dst, off, src); From nobody Mon Sep 28 14:46:46 2026 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 4887C312825 for ; Fri, 21 Aug 2026 02:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787280647; cv=none; b=pt0tXKJKnUWtalbYxCKe9MMGe40aNeYBnRuMiHnLtNoQtUEJ8Yas3yu0jwObcpwxBJq2E6OgHT/zSWx6+tGXYGV93E5had9YvtjmPQ74R4UzvpOw35ILZy+kgfOqGpbS3PikOX6QhO+vibSDwywsQurBe8WX/ib7CVwEdP3ftPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787280647; c=relaxed/simple; bh=biSlZdKoW2TIp1N9Eur8irrRElc5mHmfC7w36+KN9dc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9IJ4nFOmVNffH6K9cjxzOZjbjZ5jQ1SvskI06nYXKhntL2wSamQ8OGQY1JIc36HiobP1bLU4xY2zSQaEJ0t1EcBxh0GRktEk6xQHRSPb93UCDi16hVwdU/Sz5IVz3npiPeWTIbKH+rDJSmt4qvSDGFMOX275mAJtRft2QQ47V0= 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=gd3gRaH1; arc=none smtp.client-ip=209.85.128.177 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="gd3gRaH1" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-81ee6b2da98so8459897b3.3 for ; Thu, 20 Aug 2026 19:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787280645; x=1787885445; 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=0wOKIjhcTdiEA7KXOwvh33miMuBlXwjUoaWhMM4geyg=; b=gd3gRaH17qTAfafW/wpEB91wz+BQSr535LEqza+5A+AvwmnpHZU/bz8ciZek+SekER oA0YBB2YKL09rUtwlUxqIItXSUG6RtxKz8r6LJPLzu8KRrBsxp15bGnq/sCxEG6BAnR0 xMjHTtXZQiv/bZkK3JIDwNllm++mhTck5x5uQ3TQdxdW2duzbacI88vRhp6OmorW5nfb cLhtpebeAlIBQoGWUEkOO+wf/6fy63+poth/sTwskkmc4Gm6wJgNrT3dlThW2ZJ8+LaV /qWc8qc6zASCtiFDJvqUpOHJQdB6G+qnC5HxNTg0LAroNuwXFmR59mcj6KHLrdyliQ0v NZLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787280645; x=1787885445; 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=0wOKIjhcTdiEA7KXOwvh33miMuBlXwjUoaWhMM4geyg=; b=nfqPPVGn71WFutMC5gVse0vhPNGOJ+yJlz73Q/DNXjYpfi9cdwdWnMgFwz/qSXZOYP LSS7iF5+CpEtgaBQuX7HMnhhUzWZOYLtIBmLi0nyq6Qr3Fuc69E8yMkLUda9IuCSW1u+ x2e7Jrx/MN4PPwezHpOKaPHf60m+zAtUMHcIJQX1KDDBFhM257m8pkZwUMmzLP0i/3qH Aqw9aZUU2H63prsgH863dyDtsz3ivHdM65pmYXM1O6zAV1b/Pj1Ts14FBXhpoBqjw+eJ 6RIyTf6WE5zea4E8BymNkkJZmSbxnfrb9s68zwLHP7C0apDiGzCXhc9HIO9l7DBlA7t6 cQfw== X-Forwarded-Encrypted: i=1; AHgh+RrZ679iqSsNzJqNUwn6qv7O6FN8tyKuu0ID5dxFlYefff8BY7QX3t4JoLTNMfz7YRRRA5UVDF49+rNUP6Y=@vger.kernel.org X-Gm-Message-State: AFuF++l2RX2O6io7Wg6vassgVVfmNGfIG5cr6prMxSbGwyyF3gp6Rk6e Wui8ZTNqOi8/FO/NoDrrOajj83MFFAItO0gAgwy3fVKWpAaDWi9eEG53 X-Gm-Gg: AR+sD116xliJQuxEvUh20cac6unqfei1KrARTygMalrAfceyf53fAsapajYZiJ+NIo3 AVXjdHt/kSs+2Vnmy3dN46J0IUoMDcUZy0/Ip7yueJilEdlBzkdQxa0RoVTTi/k7LdgizKmMmt0 +blXalIHy3TNUe9FojMB4wFUUgU43xlJcTXej5zTfJh2L6e6M4YdRSPpayrOBqNwGoc+T881MOM f+3m53ZqPQYbN5R/N2H7hTf9y6OLmN01GK1B22VopTKS+UA/Li/Yq8/werItg7l7KQ7nq9+7X06 M0MhRKpktOOeMraBaXqH+WP2DuaoeNXlGSDO76GAVtN4LvUvBI79MdJpik/Ka4D4/2fZX4GtHMV S7Iif9gO8KzTk+koKs3+KRrxOZa2+RUYDpVhiIoovrj/InO3zl8OvQCwT99UtxAORAs6k43VOWj g/zyrK4cfncXF6tq2xlKwD99KV2Y1xD97UtTuDi62gcAbLinJuOQLVsbgO5Q== X-Received: by 2002:a05:690e:12cf:b0:668:24a9:a7a2 with SMTP id 956f58d0204a3-66ce4a69ff5mr1394095d50.21.1787280645276; Thu, 20 Aug 2026 19:50:45 -0700 (PDT) Received: from Turin ([187.15.143.241]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66ccb144956sm3682195d50.13.2026.08.20.19.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 19:50:44 -0700 (PDT) From: Nicholas Dudar To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, johan.almbladh@anyfinetworks.com, paulburton@kernel.org, tsbogend@alpha.franken.de Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, bpf@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 2/2] bpf, mips: Add BPF_MEMSX support to the JITs Date: Thu, 20 Aug 2026 22:46:40 -0400 Message-ID: <20260821024640.1601299-3-main.kalliope@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260821024640.1601299-1-main.kalliope@gmail.com> References: <20260821024640.1601299-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" BPF_LDX with BPF_MEMSX loads a signed byte, half-word, or word and sign-extends it through the full 64-bit destination. Both MIPS JITs predate this mode and reject all three verifier-valid encodings when JIT execution is required. Teach the narrow-load helpers to select signed native loads. MIPS64 gets the full result from lb, lh, or lw. MIPS32 loads the low half, observes the MIPS I load-delay rule, and propagates bit 31 into the high half. Keep BPF_MEMSX with BPF_DW unsupported, and leave ordinary loads on their existing unsigned helper path. The existing BPF_LDX_MEMSX byte, half-word, and word test_bpf cases cover the verifier-valid widths. Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Nicholas Dudar --- arch/mips/net/bpf_jit_comp32.c | 31 +++++++++++++++++++++++++++---- arch/mips/net/bpf_jit_comp64.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c index 48a3c834453f2..3de7aac72fb83 100644 --- a/arch/mips/net/bpf_jit_comp32.c +++ b/arch/mips/net/bpf_jit_comp32.c @@ -709,16 +709,23 @@ static void emit_trunc_r64(struct jit_context *ctx, c= onst u8 dst[], u32 width) =20 /* Narrow load operation: dst =3D *(size *)(src + off) */ static void emit_ldx_narrow(struct jit_context *ctx, - u8 dst, u8 src, s16 off, u8 size) + u8 dst, u8 src, s16 off, u8 size, + bool sign_extend) { switch (size) { /* Load a byte */ case BPF_B: - emit(ctx, lbu, dst, off, src); + if (sign_extend) + emit(ctx, lb, dst, off, src); + else + emit(ctx, lbu, dst, off, src); break; /* Load a half word */ case BPF_H: - emit(ctx, lhu, dst, off, src); + if (sign_extend) + emit(ctx, lh, dst, off, src); + else + emit(ctx, lhu, dst, off, src); break; /* Load a word */ case BPF_W: @@ -736,7 +743,7 @@ static void emit_ldx(struct jit_context *ctx, case BPF_B: case BPF_H: case BPF_W: - emit_ldx_narrow(ctx, lo(dst), src, off, size); + emit_ldx_narrow(ctx, lo(dst), src, off, size, false); emit(ctx, move, hi(dst), MIPS_R_ZERO); break; /* Load a double word */ @@ -754,6 +761,16 @@ static void emit_ldx(struct jit_context *ctx, clobber_reg64(ctx, dst); } =20 +/* Load operation with sign extension: dst =3D *(signed size *)(src + off)= */ +static void emit_ldsx(struct jit_context *ctx, + const u8 dst[], u8 src, s16 off, u8 size) +{ + emit_ldx_narrow(ctx, lo(dst), src, off, size, true); + emit_load_delay(ctx); + emit(ctx, sra, hi(dst), lo(dst), 31); + clobber_reg64(ctx, dst); +} + /* Store operation: *(size *)(dst + off) =3D src */ static void emit_stx(struct jit_context *ctx, const u8 dst, const u8 src[], s16 off, u8 size) @@ -1725,6 +1742,12 @@ int build_insn(const struct bpf_insn *insn, struct j= it_context *ctx) case BPF_LDX | BPF_MEM | BPF_DW: emit_ldx(ctx, dst, lo(src), off, BPF_SIZE(code)); break; + /* LDSX: dst =3D *(signed size *)(src + off) */ + case BPF_LDX | BPF_MEMSX | BPF_W: + case BPF_LDX | BPF_MEMSX | BPF_H: + case BPF_LDX | BPF_MEMSX | BPF_B: + emit_ldsx(ctx, dst, lo(src), off, BPF_SIZE(code)); + break; /* ST: *(size *)(dst + off) =3D imm */ case BPF_ST | BPF_MEM | BPF_W: case BPF_ST | BPF_MEM | BPF_H: diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index 22fb58f970223..14ef3f475c1c1 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -400,20 +400,30 @@ static void emit_trunc_r64(struct jit_context *ctx, u= 8 dst, u32 width) =20 /* Narrow load operation: dst =3D *(size *)(src + off) */ static void emit_ldx_narrow(struct jit_context *ctx, - u8 dst, u8 src, s16 off, u8 size) + u8 dst, u8 src, s16 off, u8 size, + bool sign_extend) { switch (size) { /* Load a byte */ case BPF_B: - emit(ctx, lbu, dst, off, src); + if (sign_extend) + emit(ctx, lb, dst, off, src); + else + emit(ctx, lbu, dst, off, src); break; /* Load a half word */ case BPF_H: - emit(ctx, lhu, dst, off, src); + if (sign_extend) + emit(ctx, lh, dst, off, src); + else + emit(ctx, lhu, dst, off, src); break; /* Load a word */ case BPF_W: - emit(ctx, lwu, dst, off, src); + if (sign_extend) + emit(ctx, lw, dst, off, src); + else + emit(ctx, lwu, dst, off, src); break; } } @@ -426,7 +436,7 @@ static void emit_ldx(struct jit_context *ctx, u8 dst, u= 8 src, s16 off, u8 size) case BPF_B: case BPF_H: case BPF_W: - emit_ldx_narrow(ctx, dst, src, off, size); + emit_ldx_narrow(ctx, dst, src, off, size, false); break; /* Load a double word */ case BPF_DW: @@ -436,6 +446,13 @@ static void emit_ldx(struct jit_context *ctx, u8 dst, = u8 src, s16 off, u8 size) clobber_reg(ctx, dst); } =20 +/* Load operation with sign extension: dst =3D *(signed size *)(src + off)= */ +static void emit_ldsx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8= size) +{ + emit_ldx_narrow(ctx, dst, src, off, size, true); + clobber_reg(ctx, dst); +} + /* Store operation: *(size *)(dst + off) =3D src */ static void emit_stx(struct jit_context *ctx, u8 dst, u8 src, s16 off, u8 = size) { @@ -908,6 +925,12 @@ int build_insn(const struct bpf_insn *insn, struct jit= _context *ctx) case BPF_LDX | BPF_MEM | BPF_DW: emit_ldx(ctx, dst, src, off, BPF_SIZE(code)); break; + /* LDSX: dst =3D *(signed size *)(src + off) */ + case BPF_LDX | BPF_MEMSX | BPF_W: + case BPF_LDX | BPF_MEMSX | BPF_H: + case BPF_LDX | BPF_MEMSX | BPF_B: + emit_ldsx(ctx, dst, src, off, BPF_SIZE(code)); + break; /* ST: *(size *)(dst + off) =3D imm */ case BPF_ST | BPF_MEM | BPF_W: case BPF_ST | BPF_MEM | BPF_H: