Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2884893rwd; Fri, 19 May 2023 11:29:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BXKGobInzoYEFTvRz5lLLqi2M8xmZ9EOlIgOZaIO/Ooe/wqu1owrm46tIdxf/rvHLDp/W X-Received: by 2002:a05:6a00:8d1:b0:62d:8376:3712 with SMTP id s17-20020a056a0008d100b0062d83763712mr3947566pfu.28.1684520954767; Fri, 19 May 2023 11:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684520954; cv=none; d=google.com; s=arc-20160816; b=LeKcf3LjzOptGlFgJKoZ1vF97lYecwiFl3QCvuC256M3X7cOckRphqWlBKngEMxW8r g0enagehG2d7QN2Ftc1gGOVvKnf/iaSMg0xu1CFOaC20c/LYvOnn8u1z2Gs9mqxpz7Nf CREEIE99a2/EdKuvlpEiJmJFLWz49z2M3b+DEEfrPivRcg0gvzs55gJtQ+Ti/qfuE1NB Gd91kZ3KXbteGN/ZYD0EscVX6X3LpTFvXvAsDNiSILnYvoa4FxVq751y9ugl+1HTHqmp h99wlzEo0RCsW4aezUEScA6S1taRu6Ci98+LCkOp6M+37AwMC5zmn41ZElst09PcmfF5 znrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=khFg+a2ReqaiRTxpoq6SkxqkDB49wgafJiFpqI5YKbQ=; b=qwCFTm5LaWfZGgJXDdBr/KFjfvOwY09dYng35eOzeAxQ1QKiqVb72AZuP7bagkAt2m 621eYLspPT5lt9Ny7smRkToEwYf8TLb5+kMOsqnFQ688y+umXgQLQPRqLzT6WH2YktVN CFrPbOg3ATUD1OXFuboNeIhq31MBUpy2zscBKPLobhQpwegiPGVfTGeR/lQNNbI/FWsq t17HksddipZFMRyjVasF0bxueDngGcE7Ab+HVnv9P/+7Mhg9Dvnhm7Uj6FZuDRMhZjhW YQorqbtQWNjV8WCxMahlWy6fmU0qvlRDkZ6Z6LvMjTXa5s5Gxhpy5yugq/fmU2qtHf8g SslQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PeoHFGMq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h126-20020a636c84000000b0051bb433f5d3si8141pgc.862.2023.05.19.11.29.01; Fri, 19 May 2023 11:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PeoHFGMq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229641AbjESSDU (ORCPT + 99 others); Fri, 19 May 2023 14:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjESSDT (ORCPT ); Fri, 19 May 2023 14:03:19 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCD7F107; Fri, 19 May 2023 11:03:18 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4eff4ea8e39so3934914e87.1; Fri, 19 May 2023 11:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684519397; x=1687111397; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=khFg+a2ReqaiRTxpoq6SkxqkDB49wgafJiFpqI5YKbQ=; b=PeoHFGMqx/4ake57D2CCDDH+d94OtdA/5oF9fjO3V0hsfCJu32yUHrMCcZ4y4KwKwg oNkpMOoOmUw0Hun067YjyZM2WAgdP7+OTdw/U26KOuoUSv51KCJrYIoiGVaHJRP/NZwT bRNt6adNtfwgtoFZEjlk8VeOPJLo7EuGrnldrRSEJogdAvzzL+qWs1QCzdsmQT4qRIt6 PwIrE+1dqqDLwfj9UNRAFiKeGDO8DbuNGsqVSxaxEHpKJoG+Q02Cvjhhu0PfS30Rq/Gh OAa1QURm3yEGqA6SkZ6LdszMWgTrJce9oEj3bKMb+Cew4SPUWdgQ4w/Tt6cncRdC2bqs +jhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684519397; x=1687111397; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=khFg+a2ReqaiRTxpoq6SkxqkDB49wgafJiFpqI5YKbQ=; b=N6TSwTU6eK9SL9duksAEpm75Fi+7uvk/wx4PQ5GkRuh/wihpfu88SJhwgbFAomr9U8 i3GRH9XKmpt4Uhz7bcdd53rzC04b6YDU0YiFAmnz7rP9XDa7aFntXetWLrwmaiHLc3Qx HCMGmNlCiHGCwZqqoFA7+AUdEqyQ5tr8+fmR8HTanPP6nzLEFn002ZTYYs9R5xvnKZ5u lAnHgrmenqhGMqZWBZLl7K0xuGyG4k+0FVacQX1dqL+Bb3alcIxLfxirEEtOhppF4t64 J9VyonJ2mMTiRz/uVPHI6kHo+QJ2ksVIGfYwYhH6OTx4A82yTvWWu9gvQH2WcKtdmise 4QcA== X-Gm-Message-State: AC+VfDzLZZv4SEg79ee8Q5NCMy4D8uGx1A6Vun+p11QnItwd8092smql 9jUCKtH161p7T99oBeft2j5Ph1CcjYlnDAxrLFjkuEiL X-Received: by 2002:a05:6512:510:b0:4f3:8196:80c8 with SMTP id o16-20020a056512051000b004f3819680c8mr1047319lfb.1.1684519396705; Fri, 19 May 2023 11:03:16 -0700 (PDT) MIME-Version: 1.0 References: <20230518102528.1341-1-will@kernel.org> In-Reply-To: <20230518102528.1341-1-will@kernel.org> From: Alexei Starovoitov Date: Fri, 19 May 2023 11:03:05 -0700 Message-ID: Subject: Re: [PATCH v2] bpf: Fix mask generation for 32-bit narrow loads of 64-bit fields To: Will Deacon Cc: bpf , LKML , Network Development , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Krzesimir Nowak , Andrey Ignatov , Yonghong Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 18, 2023 at 3:25=E2=80=AFAM Will Deacon wrote= : > > A narrow load from a 64-bit context field results in a 64-bit load > followed potentially by a 64-bit right-shift and then a bitwise AND > operation to extract the relevant data. > > In the case of a 32-bit access, an immediate mask of 0xffffffff is used > to construct a 64-bit BPP_AND operation which then sign-extends the mask > value and effectively acts as a glorified no-op. For example: > > 0: 61 10 00 00 00 00 00 00 r0 =3D *(u32 *)(r1 + 0) > > results in the following code generation for a 64-bit field: > > ldr x7, [x7] // 64-bit load > mov x10, #0xffffffffffffffff > and x7, x7, x10 > > Fix the mask generation so that narrow loads always perform a 32-bit AND > operation: > > ldr x7, [x7] // 64-bit load > mov w10, #0xffffffff > and w7, w7, w10 > > Cc: Alexei Starovoitov > Cc: Daniel Borkmann > Cc: John Fastabend > Cc: Krzesimir Nowak > Cc: Andrey Ignatov > Acked-by: Yonghong Song > Fixes: 31fd85816dbe ("bpf: permits narrower load from bpf program context= fields") > Signed-off-by: Will Deacon Thanks for the fix! Applied to bpf tree.