From patchwork Tue Sep 12 22:46:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382266 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F37EE3F3F for ; Tue, 12 Sep 2023 22:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbjILWrC (ORCPT ); Tue, 12 Sep 2023 18:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237790AbjILWrB (ORCPT ); Tue, 12 Sep 2023 18:47:01 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B77D710EF; Tue, 12 Sep 2023 15:46:57 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-401187f8071so2136825e9.0; Tue, 12 Sep 2023 15:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558816; x=1695163616; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5maphRaiJtxCw6vGqmBPcygT14ffJWcXjb1lb6GupVY=; b=bHBFpxYObCOAeTwyTuOAKTUJ/BJov0F1mEVMfUw3Lgicx5DLBY6N2hBJp/RVoWoY4t 4/W4yGQKj38C1e9OyIyPD+aXYOqY7Npi+EOIbN4eEAlbcftfKatpymhSrrbd5nWU2pGY QgHx9t/FVU2jZv+hr4YO0oN4GjNvGoq2+i1S2NkXfd2q56BShrnn2hM80PziugCiyiCz oP7dxauNEDgjuviAJdrd2FCUI8x7yGzBMdyt3XC7zJHXcMbAr9tgfqli8dFOzNCetX60 rXoai5tFj6TDQDdgCecEQ2oJ8UIPmvQ3yXfwmhe/jt1u69qOe8a2pP21AJtg3H+NpHaK hTCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558816; x=1695163616; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5maphRaiJtxCw6vGqmBPcygT14ffJWcXjb1lb6GupVY=; b=iLxw3WWGdZE0ITAtrNDjzYWrpkg5XUD2iBAbqcjTlsr12WUkEj8+61h5W6o2odw/ST 2asDP3P2eQpc+49c9zZIvKKISqzXbjOQITckqks3h5CuMtYN+q+bGj2tRcEE5V42YQeT u1WhUmNN+W1WuSZzZ7LhodWfYvlyQGceVgWtKMs0ETd/DpSkXWOzCHean6V/AJ5VNhf0 +qn6hR2mjbh127WNUL673yoc+vEB2oOWcqLoCw63p7LOvaH/vEUMhHK0DuzjVXo3zWLJ fcaBFaM9qPtIgJlsgDHbBGKOsJLgIhBGIfJ5Hzspd3fyK9dsCQUbSESvsqucssvNiJ2Z cfvg== X-Gm-Message-State: AOJu0Yz0iy8Pki1PFPKBR/WeplojuRFGjJ7tEjXh9SVzYfs8JXWvoHyg sf0zL/WpRkT6pXkMNMOC4a/FF8SAKK5Dmkah6mXpIw== X-Google-Smtp-Source: AGHT+IFYGntNSfOXewM/tS8LvcLOqQgmS8ZJLgFgXfGLUpzIXraOzxew/iXIiOfAYDr2U/xwgoNtcg== X-Received: by 2002:a05:600c:21cc:b0:401:c8b9:4b86 with SMTP id x12-20020a05600c21cc00b00401c8b94b86mr734598wmj.9.1694558815736; Tue, 12 Sep 2023 15:46:55 -0700 (PDT) Received: from ip-172-31-30-46.eu-west-1.compute.internal (ec2-34-242-166-189.eu-west-1.compute.amazonaws.com. [34.242.166.189]) by smtp.gmail.com with ESMTPSA id e15-20020a5d594f000000b00317df42e91dsm13921794wri.4.2023.09.12.15.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:46:55 -0700 (PDT) From: Puranjay Mohan To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shubham Bansal , Russell King , "James E.J. Bottomley" , Helge Deller , "Naveen N. Rao" , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Luke Nelson , Xi Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Wang YanQing , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, netdev@vger.kernel.org Cc: puranjay12@gmail.com Subject: [PATCH bpf-next 0/6] bpf: verifier: stop emitting zext for LDX Date: Tue, 12 Sep 2023 22:46:48 +0000 Message-Id: <20230912224654.6556-1-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org All 64-bit architectures that support the BPF JIT do LDX + zero extension with a single CPU instruction. Some 64-bit architectures like riscv64, s390, mips64, etc. have bpf_jit_needs_zext() -> true. This means although these architectures do LDX + zero extension with a single CPU instruction, the verifier emits extra zero extension instructions after LDX | B/H/W. After a discussion about this in [1], it was decided that the verifier should not emit zext instructions for LDX and all JITs that can't do a LDX + zero extension with a single instruction should emit two instructions by default for LDX. All 32 bit JITs checked for ctx->prog->aux->verifier_zext and did not do explicit zero extension after LDX if this is set by the verifier. This patch series changes all applicable 32-bit JITs to always do a zero extension after LDX without checking ctx->prog->aux->verifier_zext. The last patch modifies the verifier to always mark the destination of LDX as 64 bit which in turn stops the verifier from emitting zext after LDX. These changes have not been tested because I don't have the hardware to do so, I would request the JIT maintainers to help me test this. Especially, the powerpc32 JTI where amount of code change is more. [1] https://lore.kernel.org/all/CANk7y0j2f-gPgZwd+YfTL71-6wfvky+f=kBC_ccqsS0EHAysyA@mail.gmail.com/ Puranjay Mohan (6): bpf, riscv32: Always zero extend for LDX with B/W/H bpf, x86-32: Always zero extend for LDX with B/W/H bpf, parisc32: Always zero extend for LDX with B/W/H bpf, powerpc32: Always zero extend for LDX bpf, arm32: Always zero extend for LDX with B/H/W bpf, verifier: always mark destination of LDX as 64-bit arch/arm/net/bpf_jit_32.c | 9 +++------ arch/parisc/net/bpf_jit_comp32.c | 9 +++------ arch/powerpc/net/bpf_jit_comp32.c | 25 ++++++++----------------- arch/riscv/net/bpf_jit_comp32.c | 9 +++------ arch/x86/net/bpf_jit_comp32.c | 2 -- kernel/bpf/verifier.c | 4 +--- 6 files changed, 18 insertions(+), 40 deletions(-)