From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 30A3F5A0271 for ; Mon, 4 Mar 2024 18:05:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709571904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BFBrLDF/Gfy35vlg/uiTdyp8QOX29T9+nxDBdMwIvgc=; b=AJoqZluVi5V5YNKD7VqSN/ZKVvCP59kOxjfVZHA20bIMG1aiSyDDptcv8rCoeYAsyepD5S F5Kx20bbON80Gl4McK9w+Nj/UWUCmX+/GjLZNIzRI182kz0vfo1Ng6MgbNobgFr0aoMl2+ oG3HvDYuZ8evOjdK5DPtFCYhbfWvQEM= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-577-PIoDE98FOKO5NqL8M0a0ew-1; Mon, 04 Mar 2024 12:05:03 -0500 X-MC-Unique: PIoDE98FOKO5NqL8M0a0ew-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-51325a4d003so5190801e87.3 for ; Mon, 04 Mar 2024 09:05:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709571901; x=1710176701; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=BFBrLDF/Gfy35vlg/uiTdyp8QOX29T9+nxDBdMwIvgc=; b=cl+jwVqAPHwT3tVnuaG8YbrrdlvJAU6ZoSzbkxIW6Avy2wq0HYUc5UCYU6NOPaOe28 Py37fJNUwMS6bSRlHiSz9/MHhThG0z01CE6ZQV0aSbvIpJ54MhvvxkTDb7uudpG6cTNc baOs6lWZ2kZ51Y5YPgp1sPl41C2X368n7ff7/EysWf1VSASNPVXB8bfgoEGj7Y4UvOqd M3hBrIDsc8yB+hgBPv1UvCmv7pbOON6LPnrJGv/TR+mX3/hdva8i3DjVSR/CVMO6GWmD hG0YALM0f5JvZCFIuu6RBxMbChAtO5h45c9Qiu2HJcym2xJL5zsEd6321uSchT+XnuPU cmPQ== X-Gm-Message-State: AOJu0YzHyvK7WzAqyf3/Mg12vpD1/CGMm5CJ4Hl2NXux19ZY3QJmneVS kdxAg4LxwkdcCoApHFdRlJ310CLM+DLgYh4q1ZC4YYeDKNB8QPd7DOL6uCWS5WeTtffEAhV+ghn XwoPJtRdZ8ksP8au0PLJCQJlzOG82CwlIaB31U2XQ8mFNa7ggzg== X-Received: by 2002:ac2:5106:0:b0:513:1816:bbfc with SMTP id q6-20020ac25106000000b005131816bbfcmr5743924lfb.27.1709571901668; Mon, 04 Mar 2024 09:05:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmSn6YgzcrkxeIELVjLVP0Y6qw3roWD2wjFXS7U3WrVTXAn9eTXIFecTv6SKZHipCaWKDl6A== X-Received: by 2002:ac2:5106:0:b0:513:1816:bbfc with SMTP id q6-20020ac25106000000b005131816bbfcmr5743908lfb.27.1709571901275; Mon, 04 Mar 2024 09:05:01 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id zh14-20020a170906880e00b00a456573f9c5sm970667ejb.0.2024.03.04.09.04.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2024 09:04:59 -0800 (PST) Date: Mon, 4 Mar 2024 18:04:14 +0100 From: Stefano Brivio To: David Gibson , Laurent Vivier Subject: Re: [PATCH v3 6/9] checksum: use csum_ip4_header() in udp.c and tcp.c Message-ID: <20240304180400.56142a55@elisabeth> In-Reply-To: References: <20240217150725.661467-1-lvivier@redhat.com> <20240217150725.661467-7-lvivier@redhat.com> <20240229172406.6a8331f1@elisabeth> <20240301085845.0da98048@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YNSQ3Y6Q46GZDTMZXBSCON3YSQMNEQTG X-Message-ID-Hash: YNSQ3Y6Q46GZDTMZXBSCON3YSQMNEQTG X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 1 Mar 2024 23:23:41 +1100 David Gibson wrote: > On Fri, Mar 01, 2024 at 08:58:45AM +0100, Stefano Brivio wrote: > > On Fri, 1 Mar 2024 10:10:52 +1100 > > David Gibson wrote: > > > > > On Thu, Feb 29, 2024 at 05:24:06PM +0100, Stefano Brivio wrote: > > > > On Sat, 17 Feb 2024 16:07:22 +0100 > > > > Laurent Vivier wrote: > > > > > > > > > +uint16_t csum_ip4_header(uint16_t tot_len, uint8_t protocol, > > > > > + uint32_t saddr, uint32_t daddr) > > > > > { > > > > > - ip4h->check = 0; > > > > > - ip4h->check = csum(ip4h, (size_t)ip4h->ihl * 4, 0); > > > > > + uint32_t sum = L2_BUF_IP4_PSUM(protocol); > > > > > > > > Now that we use this macro, Coverity Scan realises that it's broken: > > > > > > > > #define L2_BUF_IP4_PSUM(proto) ((uint32_t)htons_constant(0x4500) + \ > > > > (uint32_t)htons_constant(0xff00 | (proto))) > > > > > > > > ...but proto is eight (lower) bits, so this actually ignores 'proto'. > > > > > > Uh... how so? > > > > Oops, sorry, it's not broken, and this is a false positive due to the > > fact that __bswap_constant_16() (which htons_constant() resolves to, on > > little-endian) is defined, for example in glibc, as: > > > > #define __bswap_constant_16(x) \ > > ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) > > > > and in this case the first term of the | resolves to a constant value, > > 0xff, because 0xffxx >> 8 is 0xff for any value of xx. > > Right. This really seems overzealous of coverity: it seems like any > occasion where the compiler would constant fold could result in a > similar warning. > > > I couldn't think of a "solution", yet. > > Making it an inline function rather than a macro might be enough to > convince Coverity. Otherwise we could just mark it as a false > positive in the Coverity web interface. The inline function didn't help per se, but while trying it out (with a number of variations on it) I realised that, Coverity being overzealous or not... 'proto' isn't a constant, so we shouldn't use __bswap_constant_16(), unless we want to define three constants for the Layer-4 protocols we support. Switched to htons() as it obviously ought to be, problem solved. I'll post this as follow-up patch to Laurent's series. -- Stefano