From patchwork Tue Sep 12 22:46:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382285 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 C4AFCEE49B7 for ; Tue, 12 Sep 2023 22:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V4pUKDIV/4aAYBVnJDAJ/C2Ausywh117fmKs30cYIe0=; b=ZDqcvR2P7IDT0k +vKjca7B2ccHHDPCUROw1UXAU7GGswM8HaKIjbFuLNom1T4Om8vgZdM8b4BEQQeJqLf++tY9c+tic PyKzkNvDMyI8RaTqxL5xzKXWTfD38sy3a07h7bbzW9+6rchj1+JaWe2WBjmV1ZefgSjRKmgEbTc+B p0tscceO8GRZ65+pkO5uooOk+KEGYsO50QBIdjhKLnU2JG6fTHAYXt9jLog1IThc9mwmp5CeWdveg Dp8M/rIfv29OfV5+xw6l1EQkkRfb35So4n7zuMcrPSCOWmW3KLoneCtK012dW/j8z8dcawNqTmk/L WhR/2ZoXz9cWeptBUX/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9w-004DGF-1B; Tue, 12 Sep 2023 22:47:04 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9s-004DDG-27; Tue, 12 Sep 2023 22:47:01 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-403012f27e1so42464985e9.1; Tue, 12 Sep 2023 15:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558817; x=1695163617; 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=Vapbmpx4kHHnDeZPSymjWm+kxhmkjrMGYPDoYN863/0=; b=e7E+VJrw5xJ9kMqZEXLyobYtLnCIhJiXHchoMAG9s0rAJGPpEMsDngAqBy6RE8qJpy zp3pZ0YRWte8Q+G7VS253/r6ngLRk/9EQ/3y2e/Uguq4kQ4p2eEXYp7YZOhOSLwjzF9H 5cdGkU2FXm+WeeKwRgAjE5N1SxBgaQ58KG5T3ZF+geBb+PX7TzRfn73DJK4RBFZUVU+l chZee94a44vi4d9YaRsO6PuVk3eXVRD7ucxIsUockv5b5OCadtblM0TxUcpgi7w5fw4j BXjWRHxRYrcS3sxzg2k17gKPwg5iKcXGxMVN2TmiVrvrCDVg9XB/d9I1AqBEOu0EFrku hNsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558817; x=1695163617; 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=Vapbmpx4kHHnDeZPSymjWm+kxhmkjrMGYPDoYN863/0=; b=JBV8kWftXGQVo3S53bXgmu8+tt9d9Y6nSlkIUqG7MOMMBwOFVe0RzznL+rXxcsc0CY O9ETbBkSnCaW7VtpNSPB35UQ3q/oip4Kt5dfmrUYfFFUxmvx5Tw/3Ylv+xke91cyRYE9 s5fVg/h44Fj0hEfawafwd5Mw65jyouGD6bLGXELZQs6Y4VKRUORWpESpT3ro7vBVABcK isj8JKd8MYADRMtoP29rr9VH2aouTUJIDewU5SN3UM4Pfe6MtWahjUt9Izz3Pf9MwM3S hotn3N9my81PLhonSGFtxkHldOsPABTUoVCflyVtdQobUwUfaHFpjpKMHgEo8wcvHYHa 6ceg== X-Gm-Message-State: AOJu0Yz7hHyOv499j/qgcxmNqKNAqEGl1T5Wp8QllftN8Wlh/5CitLdJ 79+sAfiI2oOhGSzmFaBKDAU= X-Google-Smtp-Source: AGHT+IGYaSde42//e2zWhzE0pBMJ3eH7x1xRhsn/tGbjooCPwkOeTE3BOytCJBgEeqN+vRwsYu0ZSg== X-Received: by 2002:adf:f302:0:b0:317:ddd3:1aed with SMTP id i2-20020adff302000000b00317ddd31aedmr616529wro.68.1694558817139; Tue, 12 Sep 2023 15:46:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:46:56 -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 1/6] bpf, riscv32: Always zero extend for LDX with B/W/H Date: Tue, 12 Sep 2023 22:46:49 +0000 Message-Id: <20230912224654.6556-2-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912224654.6556-1-puranjay12@gmail.com> References: <20230912224654.6556-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_154700_712511_A1F0E348 X-CRM114-Status: GOOD ( 11.77 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The JITs should not depend on the verifier for zero extending the upper 32 bits of the destination register when loading a byte, half-word, or word. A following patch will make the verifier stop patching zext instructions after LDX. Signed-off-by: Puranjay Mohan --- arch/riscv/net/bpf_jit_comp32.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp32.c b/arch/riscv/net/bpf_jit_comp32.c index 529a83b85c1c..8f8255519ba1 100644 --- a/arch/riscv/net/bpf_jit_comp32.c +++ b/arch/riscv/net/bpf_jit_comp32.c @@ -847,18 +847,15 @@ static int emit_load_r64(const s8 *dst, const s8 *src, s16 off, switch (size) { case BPF_B: emit(rv_lbu(lo(rd), 0, RV_REG_T0), ctx); - if (!ctx->prog->aux->verifier_zext) - emit(rv_addi(hi(rd), RV_REG_ZERO, 0), ctx); + emit(rv_addi(hi(rd), RV_REG_ZERO, 0), ctx); break; case BPF_H: emit(rv_lhu(lo(rd), 0, RV_REG_T0), ctx); - if (!ctx->prog->aux->verifier_zext) - emit(rv_addi(hi(rd), RV_REG_ZERO, 0), ctx); + emit(rv_addi(hi(rd), RV_REG_ZERO, 0), ctx); break; case BPF_W: emit(rv_lw(lo(rd), 0, RV_REG_T0), ctx); - if (!ctx->prog->aux->verifier_zext) - emit(rv_addi(hi(rd), RV_REG_ZERO, 0), ctx); + emit(rv_addi(hi(rd), RV_REG_ZERO, 0), ctx); break; case BPF_DW: emit(rv_lw(lo(rd), 0, RV_REG_T0), ctx); From patchwork Tue Sep 12 22:46:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382283 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 A57B4EE49A4 for ; Tue, 12 Sep 2023 22:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PJ+HvIqGkOkzwgbMsXeWKgAxySntQ8rhUlJtWAcEYPE=; b=N9aJPGzj5eF3Ha 9FQPJLICit2ABAainlvAF8FmxPu5sROt2SZSX7NnM12gV/UpeYQRLDS2uF8IGwxAxGeiaSIl1SVmJ z2QzJtW2OEP77JjWFVWOV7rmKMKvPBh4DIKtTBBOP0Y40REOrvcCWGo8+XyLh71zHmH9bBXTrBreY xlV2+6jDp+rt1IwwHEurLq6A+YG4I4PuwbEUXDkmKof7kTTU3hLiFCaqmjVACjxLkUM/1JfqpNUbc 7VrJH4m9i6mbXpxqFNnddImeznPJNCYVbbQoe48W9k7BYT3s9BZmF30JeNcK1pI38LnnbBgXREI9t FYVPMIR9I1RAVfb1PmEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9z-004DIA-1x; Tue, 12 Sep 2023 22:47:07 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9s-004DDK-2w; Tue, 12 Sep 2023 22:47:03 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-401d6f6b2e0so1846915e9.1; Tue, 12 Sep 2023 15:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558818; x=1695163618; 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=sT29HscYryKGVaLS4ITmGogx99J9Puoxilk7JdApwLE=; b=BiSDXMHajtxHfd83maBOxXA6EzN776zuBcm3ahY6bGSsQnpZIj+ytcwrW/uksaZ5Bh p3Rs9HKPHTEGjr1pE+CueEblgd69BR6URwXMuBotVyKkbdkQXnteEiS1klqKt0+6k03M S3sGv+oVARVNuLrVpMzXizgpGscRwtza3pt7yyMYJDyY2DeZ2A3u5cQGOKExCsltHaD/ Clij1weqUZYUhXPZZY1/ZqxJD5lJvQ9G+uOtWEyM2CgNaLhbIQz+rD87YL7QIBLdMpul jq3isknsYc7aOHRlQUPHniCOc0RKfzNzrPJvzP914om3GPjPHBkPFiiSOxvswU0PilRe Ayfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558818; x=1695163618; 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=sT29HscYryKGVaLS4ITmGogx99J9Puoxilk7JdApwLE=; b=LZDYWYaIdco0NurjcxeO69wF4spl+0UyK6gP80DqzNeu6jZSbKfdJtxCEt84HWSoO+ rMJSLACut2wJB5pFzlamm7U1Ca9HqSlyOotnhUQu8rnWvzsSinwAxbi/SUf4PD2w3UeH ZzBlitvwDKrM3P11Ench9EeP2zsOtB1bfde9ogTpmdpmCl1SEf4mxYLnW/dEbb0+cPIJ UzvCChnPChddMv43vqozvTkcodZ/o9OhXt5Yv4NeHDAshalWnKl6swMH7DBbLM6RmJU8 cm+yr3Qj2Pau9z60ZiIrWnC9I2+fh1pKfRcoxS4tuUVMfLainlQGDINlMK7e40xx5veK AFtQ== X-Gm-Message-State: AOJu0YxUPKp8Uwt3s1GgOiglL7ydy9VONXc8yZhfzEnm+JI7kWF/8SM9 eZ/r5dffsXZ24i/CRYkEqIk= X-Google-Smtp-Source: AGHT+IGmXcseiJIR5TJ93E0zDMbc0daNf/KmJUUYoyIE/Gf3HMcwKKCMLML9MVROQedqC+pALyVq0A== X-Received: by 2002:adf:dc85:0:b0:319:5234:5c92 with SMTP id r5-20020adfdc85000000b0031952345c92mr596882wrj.35.1694558818289; Tue, 12 Sep 2023 15:46:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:46:58 -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 2/6] bpf, x86-32: Always zero extend for LDX with B/W/H Date: Tue, 12 Sep 2023 22:46:50 +0000 Message-Id: <20230912224654.6556-3-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912224654.6556-1-puranjay12@gmail.com> References: <20230912224654.6556-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_154700_945760_AF7B69CE X-CRM114-Status: GOOD ( 11.33 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The JITs should not depend on the verifier for zero extending the upper 32 bits of the destination register when loading a byte, half-word, or word. A following patch will make the verifier stop patching zext instructions after LDX. Signed-off-by: Puranjay Mohan --- arch/x86/net/bpf_jit_comp32.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c index 429a89c5468b..aef9183ff107 100644 --- a/arch/x86/net/bpf_jit_comp32.c +++ b/arch/x86/net/bpf_jit_comp32.c @@ -2050,8 +2050,6 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, case BPF_B: case BPF_H: case BPF_W: - if (bpf_prog->aux->verifier_zext) - break; if (dstk) { EMIT3(0xC7, add_1reg(0x40, IA32_EBP), STACK_VAR(dst_hi)); From patchwork Tue Sep 12 22:46:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382286 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 17E7CEE3F39 for ; Tue, 12 Sep 2023 22:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sYP6gMexYOeZfmS54QuXEWKD2DhwUCOlEjfjFsdmchA=; b=IMD83UXG0eZIhu L+ot+f4lqt/GVey9uOZV7b2+8d0eu26Q8SJza5AeTpFECSXFMicBWuATVEPFOik2xy8Ans1zfa1yl 2hPuKbEP8fHHfmEg97uq38IkPpq5b3W8H5qMTlh6ScnVWK6OujtiViBrCVWv3mQBhBVy8QAA9baBM ju2TWb4+XgBw3+4gjcECgKNtf82H+d7GTzr31/sbRD6pRi4/ydEQ/sbp/kWk1Wyb9GJ/PMAYXLbBs aJfut5Ikz0TQVq45MfxN/QFEZdWtsWTXaCW5Fe9cWaROKaINAm7wxn0lt82vKAWOI91f5L6isRO04 h/Ln0CumY8Cz5MMPWpew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgCA0-004DIf-2W; Tue, 12 Sep 2023 22:47:08 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9u-004DDL-07; Tue, 12 Sep 2023 22:47:03 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-31aec0a1a8bso205527f8f.0; Tue, 12 Sep 2023 15:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558819; x=1695163619; 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=Oda7cl9iVFTkbJ1PzPqgjhpi/bhkWFnkRBdUJ5tFX88=; b=jvlmWVLduXvlhjSI72Ozs0XgjOTvZvGVBbn3D0Cr+SrWk1Aqdrav9nSwlRv+sMwypx cnSRwR6VCcAV0EK4XjnJXnF6pLSFwv6QaglcYVaYxVjh/k2WCYGM0gmneXXKPzWQ4rew hKzs2gX4E+4MDjqMyzqlYkqGktIbq6mVOFcA+lorLT4M6QPmD8pV8aQOW0B03OQF5uRk 5+TldeFGFDv87HbNc3a1JHSa2k8y6RSfJB0pxeWjhGViZxhe27oXyRO0G96jc6yC93LE ggGB8gibW2dnRb1v27l0u3nALprgNI+2s97lQw6OdLCskHPms/qcBc29UmGHYOqKGsan E9RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558819; x=1695163619; 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=Oda7cl9iVFTkbJ1PzPqgjhpi/bhkWFnkRBdUJ5tFX88=; b=KqD2epvx8yIRDx1uDZHjQD1keDbpgMAU7FhXVZltE1Jfs9ZU0w32txFYdCy388voBB mtkmM624/A2AppiQ9GYTILz/t2d46O9AL7VUypvmSiyVh1s33XHAoZQ9pKj3HTtIWPZh nrHmhCVeuPezj84p+chtselTaz80CA9JMvXH4XBxPhSurLngn9B+cP/xOiq+4vhHJVnC 88NYgM4M9FTkG8G+dT3p/GEurMic1rVgbSt1iTfTCnf3lPTOI+zlYtmheQ1/RkPqFIz6 yRWfLpOmtX5RYdoTUuz7rqUJq17/t3BFsbxNDnaXpLwHnr/EMzFhm9TJ/HhsbPH1ogZH Uq8w== X-Gm-Message-State: AOJu0YzU+s627FcqYS+/cVmlru3ZB7k1l4YzUKZ/Dl6Rf8t73+sG4wgN Vp8dGpO09vsrJtQdrbd2OTA= X-Google-Smtp-Source: AGHT+IHcd9xLp1ws84Is5QLcU4SiUEHRnEtZ9HHHFgMinXaJVjwni/sneatzZERdYAHhMylr9POa6g== X-Received: by 2002:a5d:484a:0:b0:31a:cca0:2f3a with SMTP id n10-20020a5d484a000000b0031acca02f3amr3150339wrs.0.1694558819326; Tue, 12 Sep 2023 15:46:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:46:59 -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 3/6] bpf, parisc32: Always zero extend for LDX with B/W/H Date: Tue, 12 Sep 2023 22:46:51 +0000 Message-Id: <20230912224654.6556-4-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912224654.6556-1-puranjay12@gmail.com> References: <20230912224654.6556-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_154702_081050_1EFFE294 X-CRM114-Status: GOOD ( 11.67 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The JITs should not depend on the verifier for zero extending the upper 32 bits of the destination register when loading a byte, half-word, or word. A following patch will make the verifier stop patching zext instructions after LDX. Signed-off-by: Puranjay Mohan --- arch/parisc/net/bpf_jit_comp32.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/parisc/net/bpf_jit_comp32.c b/arch/parisc/net/bpf_jit_comp32.c index 5ff0cf925fe9..cc3972d6c971 100644 --- a/arch/parisc/net/bpf_jit_comp32.c +++ b/arch/parisc/net/bpf_jit_comp32.c @@ -1026,18 +1026,15 @@ static int emit_load_r64(const s8 *dst, const s8 *src, s16 off, switch (size) { case BPF_B: emit(hppa_ldb(off + 0, srcreg, lo(rd)), ctx); - if (!ctx->prog->aux->verifier_zext) - emit_hppa_copy(HPPA_REG_ZERO, hi(rd), ctx); + emit_hppa_copy(HPPA_REG_ZERO, hi(rd), ctx); break; case BPF_H: emit(hppa_ldh(off + 0, srcreg, lo(rd)), ctx); - if (!ctx->prog->aux->verifier_zext) - emit_hppa_copy(HPPA_REG_ZERO, hi(rd), ctx); + emit_hppa_copy(HPPA_REG_ZERO, hi(rd), ctx); break; case BPF_W: emit(hppa_ldw(off + 0, srcreg, lo(rd)), ctx); - if (!ctx->prog->aux->verifier_zext) - emit_hppa_copy(HPPA_REG_ZERO, hi(rd), ctx); + emit_hppa_copy(HPPA_REG_ZERO, hi(rd), ctx); break; case BPF_DW: emit(hppa_ldw(off + 0, srcreg, hi(rd)), ctx); From patchwork Tue Sep 12 22:46:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382280 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 81887EE3F39 for ; Tue, 12 Sep 2023 22:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pxg9xwxNZk1/N5HbBzRyjz6NPFcaCQ1Z/t3H+5rAKnw=; b=Jq0IQhr9vbqV5w QW3/fALtrBVlhytT8ty306wZSjThEELDDKdei0xcpR3+HCfPwYD9fYwfi5az9nH1GLph1jSNHCx5l J63dBqTd31L89xXy+7vdlKSNiGfAJRNlee2Rsa1+iVIIM4ymGQNkD1gf0Pi4cgBBFOX/fZj75eVBk 2WbL7qWvq92k5jtl1zciBTEFxxBs1mtDktBwjidVYATn/7AcMP/9ipAcg4XSJF+sjECPlXg4l/xKD fQQn4vavrzlxAMCrJiikc5cQymhS+uY2K94SdeLTvu980GPNqqA9zrOmBMRzcEqYkT/ElzsHVH0In 8aYm1MixulPv2d+Sz23w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgCA1-004DJ7-2k; Tue, 12 Sep 2023 22:47:09 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9u-004DEE-2s; Tue, 12 Sep 2023 22:47:04 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31aeef88a55so5761582f8f.2; Tue, 12 Sep 2023 15:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558820; x=1695163620; 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=qhUNqTKNJ5t40WxcJkQJJc6NwQozn+LNI3JL0/ULous=; b=OzrJS7uruqa48TL1qlc8nBDnkD+UHN6XYFr+w+LmQDn8m9dDoG3/8+GjVk//aud2qV zBvTns7ykKTbRejviWw1raHmw8Cl0YoHwqUaj+RDMYNr/b11xQ5OhIWubHVMh0oZ7DWP ABASUHfEfmhIY7C2nEsD/Us88TYh9XGp2cIM7gXbU2vEAy857fWN8C+JmVdyCV8GdNGB xijsJe8KsUedOXtbs3d/p/oAGJgOwTiWWPymT7j2FigLfdgffMg/ak4uvvNBgAGajXd3 4kg1F0FVVCvq8FDONkEVuCAQQw0q+zxc1E1jZSahDO18fMt88VChCOBj+vvq57hVOUJf I1Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558820; x=1695163620; 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=qhUNqTKNJ5t40WxcJkQJJc6NwQozn+LNI3JL0/ULous=; b=FBxX/R637PMeg05bt4rAxTI2fRtWX4DrBC2IXCStJJ9p1rJBPlhzzimlT+hNYc7FUB kxT5qN1poZhLgo2niM3mTMaYAlTQ1ndIeITPX3o5rhx7Q5TKZy89ihyv9nSoE29PTEi9 E/AI7VIoPfIy0lhywz5s5vVaj8IH38LSoXx1lbnH4nbHpZ5XdSh0i4/viHmKt6xz+sTi 32T5tJPi25woqDNN5cnnG+/BAx8fynTRqnoxKX1NtErD/rG5py/ZWTjI/9/ovl0lCxSL llv9VV9ArHXFXjxDZExPc85af67UiZ6VNcRfTP94nDs/deGekhEXE2ndW/N3aXLp134h HmQw== X-Gm-Message-State: AOJu0YwLmD7QMOi8Da48fEgbz2ol1tOL1n6j35tc9GlpK6wCyRHvjS30 43WCQkKwi6PRPf3gQ3e8m7s= X-Google-Smtp-Source: AGHT+IFgAH0fOtyaF0ehV56I8y/PX0drowIs04cM59dILrqCnUI/euGHNvJaohPj3FXuSexhWOZw7g== X-Received: by 2002:a5d:628c:0:b0:319:7a9f:c63 with SMTP id k12-20020a5d628c000000b003197a9f0c63mr718103wru.50.1694558820430; Tue, 12 Sep 2023 15:47:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:47:00 -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 4/6] bpf, powerpc32: Always zero extend for LDX Date: Tue, 12 Sep 2023 22:46:52 +0000 Message-Id: <20230912224654.6556-5-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912224654.6556-1-puranjay12@gmail.com> References: <20230912224654.6556-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_154702_927830_E917184F X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The JITs should not depend on the verifier for zero extending the upper 32 bits of the destination register when loading a byte, half-word, or word. A following patch will make the verifier stop patching zext instructions after LDX. Signed-off-by: Puranjay Mohan --- arch/powerpc/net/bpf_jit_comp32.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index 7f91ea064c08..0a952a2cfaac 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -936,14 +936,13 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) * 4); EMIT(PPC_RAW_LI(dst_reg, 0)); /* - * For BPF_DW case, "li reg_h,0" would be needed when - * !fp->aux->verifier_zext. Emit NOP otherwise. + * For BPF_DW case, "li reg_h,0" would be needed emit NOP otherwise. * * Note that "li reg_h,0" is emitted for BPF_B/H/W case, * if necessary. So, jump there insted of emitting an * additional "li reg_h,0" instruction. */ - if (size == BPF_DW && !fp->aux->verifier_zext) + if (size == BPF_DW) EMIT(PPC_RAW_LI(dst_reg_h, 0)); else EMIT(PPC_RAW_NOP()); @@ -974,7 +973,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * break; } - if (size != BPF_DW && !fp->aux->verifier_zext) + if (size != BPF_DW) EMIT(PPC_RAW_LI(dst_reg_h, 0)); if (BPF_MODE(code) == BPF_PROBE_MEM) { @@ -982,20 +981,12 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * int jmp_off = 4; /* - * In case of BPF_DW, two lwz instructions are emitted, one - * for higher 32-bit and another for lower 32-bit. So, set - * ex->insn to the first of the two and jump over both - * instructions in fixup. - * - * Similarly, with !verifier_zext, two instructions are - * emitted for BPF_B/H/W case. So, set ex->insn to the - * instruction that could fault and skip over both - * instructions. + * Two instructions are emitted for LDX. + * So, set ex->insn to the instruction that could fault and skip + * over both instructions. */ - if (size == BPF_DW || !fp->aux->verifier_zext) { - insn_idx -= 1; - jmp_off += 4; - } + insn_idx -= 1; + jmp_off += 4; ret = bpf_add_extable_entry(fp, image, pass, ctx, insn_idx, jmp_off, dst_reg); From patchwork Tue Sep 12 22:46:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382284 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 6D29AEE801F for ; Tue, 12 Sep 2023 22:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hvEqVGfZbkVaTNyGFjV/K9N3k1wYCcI6dO8LMkR44iY=; b=pkqjmj9C69B9Ye 89fFJqBZKWetGV2Pjx4CgmLAVmomnkl4s4Ry96oG4EvisSIQ9qhA/aFsFkTNaOjxHNmle3mTzKQ5P Dc6nWSvzdUBxCk5QqVsJbM/V5BoD5YyNYCRd4+48d1QppLiIRc+ALsEph86kO4gkbEf7u9SN57UR4 18JhRL1Vp+tJKPoGRek1c8Wro98V00qREve6Aa9gXB5OhoonUDG65JQUAfrlLRIulRcF2p3Q6/Ypm TCRlBepWvS1luoK7/qBUV+rLZm6lqF/Rt9PbmhBEofz5CXX3HXPg+prB8LvKaOpqEzNE/bOE+mjDd WWNGO0EXyBMRz2I/mR3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgCA3-004DKs-0c; Tue, 12 Sep 2023 22:47:11 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9v-004DET-1O; Tue, 12 Sep 2023 22:47:04 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-401da71b7faso72322055e9.2; Tue, 12 Sep 2023 15:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558821; x=1695163621; 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=9kqE25xddEGWdkAd5IJWaOPr3bcznXZB6DbOZ/MzuKY=; b=RRxzcUoGSEc9HhmTAzx4TIGy4IsMb45Qkd1kf/JlGPDR01cc34K52Cdjhsop4r6oCt VIKX4ueFdaQMzN+HcV4dhAj0Fb9P657gjexW1QsHPSd661mj1gUcsOEUbLSuh0Fq4FEx 9dKAYrYi5j1Oq+yVwrxSYUx/TvQ4FPy3ty1ac4YOVVrUYI5LGIcolT40vilz7U0ZAfcy yyL7oSRRrzHefzj5xztRh6ww47+IzvN5TlilxeyJQAgDKiNkIZ8/GO8nJYJH0QpPnCsZ E3LhcBUct3NJbz549OjoNW7mqEDLsZWMzY0y1yvjHlhIfzZBVUP1j35KhoHqOsI7eEYm eofQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558821; x=1695163621; 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=9kqE25xddEGWdkAd5IJWaOPr3bcznXZB6DbOZ/MzuKY=; b=WIwlg0zZm/kbgUR1kFQzv0BjpP2dJOmKxWIgtxDOs08uwM/LhGqKZCFfoNd0/1cypZ zIRbKeXfiXcphsl2FGwYfKzjx4mRjvR4szAuz10KB9dUdeUEdeljsAIBqT8h+3Y40pns cDv9Ce8PXHKMnEgZkmDnVezhnblvAJoM+v/QLpkP2L7uYvAokhfBjCF2kPlnOpO3aLzA UfZDiH36JmRUtYh/mpeDjNXqHff/ubrEF9Zz87Axe6523TGkoDnE27IBtU+KaE//pKYc aLVCf6RnDyYVdpktUg0j9CHLUUsODn1O0hQACT07u5cxUn07GHE6381pXzcWNlCLMWQh BIWQ== X-Gm-Message-State: AOJu0YzWNbZX/HJC9RuF0gj4zFlc8iK0+BlaSZd6jxd086pk7MP92yyd KC1K6E13u7W0UBoo6o92ux5uejXgF50wbW3PjMKYLg== X-Google-Smtp-Source: AGHT+IFtRPmqCA45qZeOfe4gap2/v8LgzERhETar42HTdZcTU3NFDWNWl1Q7ouaYhNuNBRQewOmqOA== X-Received: by 2002:a7b:cbcc:0:b0:3fe:db1b:8c39 with SMTP id n12-20020a7bcbcc000000b003fedb1b8c39mr604002wmi.41.1694558821453; Tue, 12 Sep 2023 15:47:01 -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.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:47:01 -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 5/6] bpf, arm32: Always zero extend for LDX with B/H/W Date: Tue, 12 Sep 2023 22:46:53 +0000 Message-Id: <20230912224654.6556-6-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912224654.6556-1-puranjay12@gmail.com> References: <20230912224654.6556-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_154703_484068_EEA56061 X-CRM114-Status: GOOD ( 11.91 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The JITs should not depend on the verifier for zero extending the upper 32 bits of the destination register when loading a byte, half-word, or word. A following patch will make the verifier stop patching zext instructions after LDX. Signed-off-by: Puranjay Mohan --- arch/arm/net/bpf_jit_32.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c index 6a1c9fca5260..757a99febba5 100644 --- a/arch/arm/net/bpf_jit_32.c +++ b/arch/arm/net/bpf_jit_32.c @@ -1081,20 +1081,17 @@ static inline void emit_ldx_r(const s8 dst[], const s8 src, case BPF_B: /* Load a Byte */ emit(ARM_LDRB_I(rd[1], rm, off), ctx); - if (!ctx->prog->aux->verifier_zext) - emit_a32_mov_i(rd[0], 0, ctx); + emit_a32_mov_i(rd[0], 0, ctx); break; case BPF_H: /* Load a HalfWord */ emit(ARM_LDRH_I(rd[1], rm, off), ctx); - if (!ctx->prog->aux->verifier_zext) - emit_a32_mov_i(rd[0], 0, ctx); + emit_a32_mov_i(rd[0], 0, ctx); break; case BPF_W: /* Load a Word */ emit(ARM_LDR_I(rd[1], rm, off), ctx); - if (!ctx->prog->aux->verifier_zext) - emit_a32_mov_i(rd[0], 0, ctx); + emit_a32_mov_i(rd[0], 0, ctx); break; case BPF_DW: /* Load a Double Word */ From patchwork Tue Sep 12 22:46:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13382281 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 D4109EE57DF for ; Tue, 12 Sep 2023 22:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xVwF8t9HUYg+R+/AjX0EC5MVEo1mhY1RPaaxMSMnHNo=; b=bwcsZsFvDxk9Qa Yy45iGTThJTtE3dfZt8r1XSjw0O79tCzYXpHkdBwIq2f1N5/TPWLbr5ea4llUEJgM2q/PRv6RoUzh xagEivj4i6g5JFEZJUde+pbA5MVGmxNWQIWotgeFjIN2mRAaM0kLGCFXOlnaMJ42dubYQsQWAbD1N q6tsxpvD4aGLISW6xg8IPxoaI3UeOZfFT2WUDAH7ms44Ms4eMun/nQO7r8X8YqZOkXodu6pWhU/pt b3mMUBoHV3SzPcGwckAm2GWuSBKSTDvN8qOp/o2rtJfzW05nrH54iLtTFQr4Zi6Z4LSoGVA84A+f8 +kvTBvVoYZSZ42hrAIrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgCA4-004DLz-1U; Tue, 12 Sep 2023 22:47:12 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgC9w-004DFG-1L; Tue, 12 Sep 2023 22:47:05 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31c7912416bso6595019f8f.1; Tue, 12 Sep 2023 15:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694558822; x=1695163622; 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=GxeItlNv04+BjzshAn31wAsB9adLvt962s1bQaHQhqk=; b=FCXl2Q9dE+us5/A+btBzzZXOMUkxuB8YCqDuaDSQu+npSqI0+lBEkPbCeH/DuYCvtF TSorx3hF3CDclrkIBvOp5EsoW+PWWT25xd6plgHQ7Wnmz4XBMOTgPBzDkwWjxZVX3sGG qLnDeKoI4FYiuqoTS0hSaXLFtjMeFFzTdvXSUr6c6pGNwlHqjLPpa4e9g19cKdCEywmv ZFZUckLH+eG+Odcu441dN5eQzS3RhQJoGWxihluFrfnzqaU3FvmhioTr43g7WtvNrmHH ab/d6ljYLBezKTwkGYoLll9/rlpRJr1pxdVr+XhFJciKrlZka1fIAOKZsl8osmcE3R77 N7cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694558822; x=1695163622; 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=GxeItlNv04+BjzshAn31wAsB9adLvt962s1bQaHQhqk=; b=Rb0HvObDO52hefWj/IESnKM64xIRmPY8MLUf/xNtVUhIIAzBhFSc0zhxakcNwM5gbZ ik3wxvrKSmBXo78gjckRDWDRVSTnYFN1L7bA4U8P3tYEWc8E7ApUMfm5TlNuGP7lHrL1 EmVbRiJ2r+59sHRG1Kdn8DjsTUAI9jt+lOabTsKfZSltVyO1fflvY/zSoCaSeL0cgFj5 MZKoRrYBZFb6tW5RKyhv6ZgoPy1UZVT8M18Jr37u+optt6PFGNPobj6R7WUrUQUywAxe e8NjQ/bRfYEPUTp8ksYioZM2oTxj7xWtuqKZuEmtO9aCDX/VU87Bi0/HlnCt+jtAnMDd qZtA== X-Gm-Message-State: AOJu0Yw0AERVkboyLu/zQg8L7Vn3wb90xA8NhDXH2yKU3nZw+xDlfiX0 1UwPiDlmS25xf1K6ro4YZg8= X-Google-Smtp-Source: AGHT+IGIRL1pLS66Q0kL+tNt95f9G7dGNYYYAmglWQ49OAUKZ2P+a9yQAWCML5eZu0IFvzTnTl7LPw== X-Received: by 2002:a5d:45d0:0:b0:31f:9838:dfc4 with SMTP id b16-20020a5d45d0000000b0031f9838dfc4mr646970wrs.33.1694558822455; Tue, 12 Sep 2023 15:47:02 -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.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:47:02 -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 6/6] bpf, verifier: always mark destination of LDX as 64-bit Date: Tue, 12 Sep 2023 22:46:54 +0000 Message-Id: <20230912224654.6556-7-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912224654.6556-1-puranjay12@gmail.com> References: <20230912224654.6556-1-puranjay12@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_154704_463017_D9BEA268 X-CRM114-Status: GOOD ( 10.81 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org All 64-bit JITs utilize a single instruction to load + zero-extend a byte, word, or a half-word. The optimisation of emitting zext for LDX is not useful for most of the JITs. All the JITs that relied on the verifier for zero extension of LDX desitination registers have been modified to always zero extend the destination. Now the verifier can safely mark LDX destination as 64-bit and stop emitting zero-extension instructions for it. Signed-off-by: Puranjay Mohan --- kernel/bpf/verifier.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index dbba2b806017..02a1ac1a1327 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3028,9 +3028,7 @@ static bool is_reg64(struct bpf_verifier_env *env, struct bpf_insn *insn, return false; if (class == BPF_LDX) { - if (t != SRC_OP) - return BPF_SIZE(code) == BPF_DW; - /* LDX source must be ptr. */ + /* LDX source must be a ptr. and LDX destination is always zero-extended. */ return true; }