Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5469267rwl; Tue, 11 Apr 2023 06:04:02 -0700 (PDT) X-Google-Smtp-Source: AKy350b3o2UvV5Oau04MK+zvJV+Ei2MDDkK1YUs/4ZPlaKb9rfLEKHoSU7FWWVJHaTCEQTjACJZL X-Received: by 2002:a17:906:8489:b0:94a:44ce:fdde with SMTP id m9-20020a170906848900b0094a44cefddemr11526693ejx.42.1681218242444; Tue, 11 Apr 2023 06:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681218242; cv=none; d=google.com; s=arc-20160816; b=1BZF4j09z6yHPFGwtp01IOMcxk1uINbzY9iNt86BM2u6CXEyH9DS4FBFMR9rQnFEWE n4XzOnuLqUtQvy8VC5JC03eWOeHzc1hfCDc3Lz1l+rp//0phbqYBUUM2sTmKupPz0AP1 V1InC+E0TI79fjCaSLqrMjzeyvmNQOnuNgOr+xUnaZKZGXsXMktk3o7qF9rLWOwe2tPX FDmv3lmH/LR5CH5/vvmvdBOyvZdxeA3Brv3CoyZBUP0ph5rVBIC/zT+OmfNX7NfLF04Q vtJ/PVFb8WJtOe8xjkt2R013dUMNM2mlL8j27RKYCzoUxKeojwhs9Gf+dmxYqS78FLIJ 7UWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Uro36Q9BxlPEIVH/KwpgPssMY18occbtTX2ic8QxRG4=; b=Rxj7WcDElRZu8BOU8YTib9NfgzlccwUQ82Dc9E4U/xa28iNEkhwjOckbCF9c4Wntsz RpZUb4zal+PMfM0bPfcSpNcOfJO4cYGX5BVGRGoMB1SY4xccLF0PO90UB+TwUUbR0YuX F4gFsbCqlaOM0/DutN3aqAx2CjLRtMYLpFZs78Bp+Ng88TdLD0FlOlVbscEuCkZ55DF0 fhb4MVXT+WOYiVv5sahctV7CfcI8wPTWoHnO/4ZdeDSPsXGIHKN9awG8tdYgaIF8H2dr iae2xesNzjcdAZ1QRuNNElL41akihzqc+UUN/qtGgBqxtv3xlOoZFgGOWPX6WvGR+ItX /2kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dectris.com header.s=google header.b=UutsbkIu; 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=NONE dis=NONE) header.from=dectris.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a1709065dd200b00947bf51f947si4247761ejv.276.2023.04.11.06.03.36; Tue, 11 Apr 2023 06:04:02 -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=@dectris.com header.s=google header.b=UutsbkIu; 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=NONE dis=NONE) header.from=dectris.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbjDKNB5 (ORCPT + 99 others); Tue, 11 Apr 2023 09:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbjDKNBh (ORCPT ); Tue, 11 Apr 2023 09:01:37 -0400 Received: from mail-ed1-x564.google.com (mail-ed1-x564.google.com [IPv6:2a00:1450:4864:20::564]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64BF24C07 for ; Tue, 11 Apr 2023 06:01:09 -0700 (PDT) Received: by mail-ed1-x564.google.com with SMTP id 4fb4d7f45d1cf-50489b16e6aso1871880a12.1 for ; Tue, 11 Apr 2023 06:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dectris.com; s=google; t=1681218042; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Uro36Q9BxlPEIVH/KwpgPssMY18occbtTX2ic8QxRG4=; b=UutsbkIucpDckiULFPkgVrSIzAcICeJRe1UxOAL+rkNvLGByoI71hUK4yIN4MIcafb QHnKPy8ug7tUQU28mnS0fHazLKG9js/2nB7nt1grd0Qrzt+rzoMOxpB4yMX6GfPgv5ve KRM/6UCRGmx5hmw1WsoboL7v/2OU/FXHNK0I8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681218042; 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=Uro36Q9BxlPEIVH/KwpgPssMY18occbtTX2ic8QxRG4=; b=J/ijmaW0q6WprbJ+OoDy8WEiP9YEjLuFyvv12CO1yN3I0gR9+IgEua6kfnMB6kO3iW nNFxkitCKutEgch7v9FfGOnzKkGxObxqbuc4uHKGZ8tM679M7rGTJZiTHuoL7kGMmg9P 1ZIezX3CkSJq4tpIOEHg2ajFXPphzUPHXG5y3coQA7XAeYrkFAtwgHU+KZiGYIR43mMI G/Gk05Urodim9OEp1bdm8ftEI/0jx5fXWMHpqgD23/vtKacrRcq5C3uAjd8TU1xy7CyE xiglhyZ5l+CMrRiuOOuWQ2id+FtIsf5fBOFm8n/fh5ewTrlSQPLHOHp5EPyqj9D6rk/l qORw== X-Gm-Message-State: AAQBX9ebbM5crSkFLGHqQX1tWXlIpcWbRYJBCxIbfDcs2Wv2a60iWvEW ewij757Gszm8d1z6eOJ58401NDqk1bALSC1i1XrlQXww0DDx X-Received: by 2002:aa7:d3da:0:b0:504:b324:9eb6 with SMTP id o26-20020aa7d3da000000b00504b3249eb6mr4004684edr.29.1681218042329; Tue, 11 Apr 2023 06:00:42 -0700 (PDT) Received: from fedora.dectris.local (dect-ch-bad-pfw.cyberlink.ch. [62.12.151.50]) by smtp-relay.gmail.com with ESMTPS id xa10-20020a170906fd8a00b0094c9be3f56esm2457608ejb.166.2023.04.11.06.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 06:00:42 -0700 (PDT) X-Relaying-Domain: dectris.com From: Kal Conley To: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: Kal Conley , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2] xsk: Elide base_addr comparison in xp_unaligned_validate_desc Date: Tue, 11 Apr 2023 15:00:25 +0200 Message-Id: <20230411130025.19704-1-kal.conley@dectris.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Remove redundant (base_addr >= pool->addrs_cnt) comparison from the conditional. In particular, addr is computed as: addr = base_addr + offset where base_addr and offset are stored as 48-bit and 16-bit unsigned integers, respectively. The above sum cannot overflow u64 since base_addr has a maximum value of 0x0000ffffffffffff and offset has a maximum value of 0xffff (implying a maximum sum of 0x000100000000fffe). Since overflow is impossible, it follows that addr >= base_addr. Now if (base_addr >= pool->addrs_cnt), then clearly: addr >= base_addr >= pool->addrs_cnt Thus, (base_addr >= pool->addrs_cnt) implies (addr >= pool->addrs_cnt). Subsequently, the former comparison is unnecessary in the conditional since for any boolean expressions A and B, (A || B) && (A -> B) is equivalent to B. Signed-off-by: Kal Conley --- net/xdp/xsk_queue.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index 66c6f57c9c44..dea4f378327d 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -153,16 +153,12 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) { - u64 addr, base_addr; - - base_addr = xp_unaligned_extract_addr(desc->addr); - addr = xp_unaligned_add_offset_to_addr(desc->addr); + u64 addr = xp_unaligned_add_offset_to_addr(desc->addr); if (desc->len > pool->chunk_size) return false; - if (base_addr >= pool->addrs_cnt || addr >= pool->addrs_cnt || - addr + desc->len > pool->addrs_cnt || + if (addr >= pool->addrs_cnt || addr + desc->len > pool->addrs_cnt || xp_desc_crosses_non_contig_pg(pool, addr, desc->len)) return false; -- 2.39.2