Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796143999; b=uzGBeRiKXQy25A4ruIylcgy1rIohwbiFe8k3jXI07IKlb1Fjhkzq/Lr73dil5NOl2g7r uCQbXm6787Nc/mjmbI/4vLVRWIWC4R9tHZ6nIOQu1scl8OhIqby5oIOL8ISQK8ADvyxOU 4BVkbepFOsdwf0MaPdgii1GMecFAuIuGtnzF4HHtJJupkTgs3/hNPUFFzxml30ZCp5a4k f5mWtCGvg6Qk3v9vIJVSB1zVoa1FZIR8Meu3Px7sNqSooQxwUHcmtklDuBELN96uEy9+b hqGVnE+03X89e/Dl4uZc+FcX6bqQqx9yfqcc+w/+rPhc86gaEBtGdpTu24/DnKhg5Pw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143999; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=SacHS26F4wxER6qI4ojBTAAYYFLzdB/Bos5NQBqEPVo=; b=rzRUOtdt3noydlNuc5YQ6KypjsjciUha01d7/VFZZy8oMsHf+39xMINgbbX/ki8XX2tE VXhqNLKe8kyrxruccthPDhAvHR76kRSCyCj6JabaqqPHoHSrnJesOYhxM+RoJTOQ5jdJC e7UU12byevCXRGH2Bt8T6rX4XK9Q3830rV1T0cki77sg+XA4XRvmR2EPuAlJXtdnyAFfH sumwd3eezhKvYLjAh47lSZ41Bi8iqqWIUKm7fM6f4sxQub7SWvQy3EWiYUheqAYaT7ydn 3nfyC+jWVGVcu+2tZj1gg6Me56ftntM7VR4Dow+sF66tusFfy1QY7fOxD+hCXIOfBfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=lukasstockner.de; spf=pass smtp.mailfrom=lukasstockner.de; dkim=pass header.d=lukasstockner-de.20260707.gappssmtp.com header.i=@lukasstockner-de.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=aEcEof7b; arc=none smtp.remote-ip=209.85.221.46 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 061CC606A684 for ; Tue, 1 Dec 2026 16:53:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 061CC606A684 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lukasstockner.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lukasstockner.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lukasstockner-de.20260707.gappssmtp.com header.i=@lukasstockner-de.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=aEcEof7b Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4a32576da88so6994298f8f.3 for ; Tue, 01 Dec 2026 08:53:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lukasstockner-de.20260707.gappssmtp.com; s=20260707; t=1796143997; x=1796748797; 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=SacHS26F4wxER6qI4ojBTAAYYFLzdB/Bos5NQBqEPVo=; b=aEcEof7bJhwFe2SfemYU8xr/gyp+6I8jGh5UPLjAgVQV6fzz/3fiQ7aI1VU18CHDaP SSkcNOrDJXyz/DAG9yBULFeenwMfyCBpNgjrVyM5+qEq+eCu++8TO+LLu+LchykVjahB w5Ab3UYxjTjSOKig1FJLXekmojvI40EDzu9+H7evE+foMUyadW5h/zMM6Nt9tmL6nMaf tX+Uxir9toPDrjfoEJeau4sLchVkGRFAYIVuMGqG+hkzZl0I/Q9AVCO/jxZTxqSP3JRY GlKAo2XwZ4aa7OSyP0a/oolq22/Dzxz34qv8z8jOZH2/+OZCalvgQHRdKAW8TTmZYsvU bDcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796143997; x=1796748797; 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=SacHS26F4wxER6qI4ojBTAAYYFLzdB/Bos5NQBqEPVo=; b=vI5rn3oU+lGtkweTfnW3y+/LCNJwTaMimPnLPy5rRHhd3PJsrizl6i44QZ4Qm6Ru1r QKDoLd+cb90czkHmfeTII5M9h8jEhz79IW/h0ViwEOFEGU9LjSNoru4eTHfpe0Atvrct CDCrgsar8JHveM+Jtmnjc7wEJlec50Gh0PUW9bMutTOzYTcp3toV8IFYd28ZFg+RGVt4 LlFHb6dpEnsa7Ky2tDRMqueJQOq0r1fj4ONB/a1aFYpY8NC5JwcDxH88HhFnZ69kcWjM J3+TJ2Y973Nw/1PbnUQOF6/Y/zkVh8uXwq/tW5id+P7WEHikba6yLySyXkAVuVEqljq7 ibow== X-Forwarded-Encrypted: i=1; AL+hErHf3MggMmXVcKaHGoGiHIZgGjoH9JY6Q4OKk05VG/cyzr7M5t6pf5xuKtTDdQbcrAwzRD0=@vger.kernel.org X-Gm-Message-State: APuU4Z8i5Z9tgRbLNnRvSVghs+wAOW4Gg6NuNV3EaFLN879DGCPSgyJq EaPQVPKFO5Hus4fEH8SbGti6qd9di9dWrEhHsfNCt2v8IsUcx3bwK+cqEnFOlelAoPw= X-Gm-Gg: AZFdTZeUM5Twz1iiuSLpfIuU/sspVeWjYM0+wFa4NfcvYKCebmrf8pDuOtm0/avGWLI 12N+r3Nl6f/FZTsrnoGXYj+0kmr9TmoW4Epong9EGE4Na1drNwWcOGvNVDUNEVeDb08poSkD2Ab 3fACNfDp17NwQAOkdAe0mXgo02+2ZV/rXyc/bYWseWFRHfbSOHiBH65w0fGt2r13C5pK8XWJeUA Rf/EKNxCcSja6eDqpwcDTZrTdMIz1//86g/lMDHzuuW/pQYmmVt7rFmA2LEbTfj2u51Yi3yt9hC kHYWjExA86ej+sUuO/Z0tV5vqUmad1OMakXpTP+0br69bkU7FpzwdDrX1GSAhW8aNV7R0YdrdxP +5Bge6tG4JOFyCa3BZ3AR1/QiCYpPP157W3UiPPgjExN9TVKB5WoNd3sYQBldxtwqbpivRFiQLa Y251ATtsK2UZ+aHu53KmvtoGnQz3LMB3f3O+rsTIdp0fKJJ0CA6eYIato98Ztw74WQaksNrtjGm 2hLLS7r6ujFDqYJaRy3d0Z+HEsIEc8oJg8eYJSAtaHAPiTiaFj8vtL3SF9GYf738O9eTBW8bl5p caNcivf2fKo9MioX/GbVhH4CieE+6HCPhiUI25YmAi+FR23WU+XMpxTkActhiSoqI1Yf9NbaOk3 tTxKy3fnEHPplZ13k6qhI X-Received: by 2002:a05:6000:4809:b0:4aa:842f:5f78 with SMTP id ffacd0b85a97d-4abb759e947mr69958249f8f.46.1796143997434; Tue, 01 Dec 2026 08:53:17 -0800 (PST) Received: from lukas-laptop (p200300feff05c900f3466834a17f39d0.dip0.t-ipconnect.de. [2003:fe:ff05:c900:f346:6834:a17f:39d0]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab65cb42absm71207855f8f.1.2026.12.01.08.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 08:53:17 -0800 (PST) From: Lukas Stockner To: Hari Bathini , Christophe Leroy , Naveen N Rao , bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Madhavan Srinivasan , Michael Ellerman , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Lukas Stockner Subject: [PATCH v2 3/7] powerpc32/bpf: mark all argument registers seen in function calls Date: Tue, 1 Dec 2026 17:53:09 +0100 Message-ID: <20261201165313.413960-4-lukas@lukasstockner.de> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201165313.413960-1-lukas@lukasstockner.de> References: <20261201165313.413960-1-lukas@lukasstockner.de> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The JIT code tracks which registers are used and remaps based on that, but currently does not account for the fact that function calls implicitly use registers because the called function will treat them as arguments. Therefore, if a function merely passes through one of its arguments to another function call, it will incorrectly be considered unused and may be overwritten with another register's contents. In practice, this is unlikely to affect main programs as they only get one argument (the context, which they are very likely to touch somehow in addition to passing it on), so they'll have to touch other registers if they want to pass them as arguments. Subprograms, however, are much likelier to hit this. Similarly, tail calls pass R1 to the callee, so mark it used as well. Fixes: 51c66ad849a7 ("powerpc/bpf: Implement extended BPF on PPC32") Fixes: a8936569a07b ("powerpc/bpf: Always reallocate BPF_REG_5, BPF_REG_AX and TMP_REG when possible") Signed-off-by: Lukas Stockner --- arch/powerpc/net/bpf_jit_comp32.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 9f55dd4bdfd6..7414e350d2d4 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -339,7 +339,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code { const struct bpf_insn *insn = fp->insnsi; int flen = fp->len; - int i, ret; + int i, ret, max_arg; /* Start of epilogue code - will only be valid 2nd pass onwards */ u32 exit_addr = addrs[flen]; @@ -1183,6 +1183,18 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code if (ret < 0) return ret; + /* + * We don't know which arguments the called function will use, + * so if this is a subprogram, assume the worst case where it + * uses all of them. Regular programs only get one argument, + * so any others would have been explicitly set. + */ + max_arg = ctx->is_subprog ? BPF_REG_5 : BPF_REG_1; + for (int reg = BPF_REG_1; reg <= max_arg; ++reg) { + bpf_set_seen_register(ctx, bpf_to_ppc(reg) - 1); + bpf_set_seen_register(ctx, bpf_to_ppc(reg)); + } + if (bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_5))) { EMIT(PPC_RAW_STW(bpf_to_ppc(BPF_REG_5) - 1, _R1, 8)); EMIT(PPC_RAW_STW(bpf_to_ppc(BPF_REG_5), _R1, 12)); @@ -1412,6 +1424,9 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code * Tail call */ case BPF_JMP | BPF_TAIL_CALL: + bpf_set_seen_register(ctx, bpf_to_ppc(BPF_REG_1) - 1); + bpf_set_seen_register(ctx, bpf_to_ppc(BPF_REG_1)); + ctx->seen |= SEEN_TAILCALL; ret = bpf_jit_emit_tail_call(image, ctx, addrs[i + 1]); if (ret < 0) -- 2.56.0