smatch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan McDonald <danmcd@joyent.com>
To: smatch@vger.kernel.org
Cc: Dan McDonald <danmcd@joyent.com>
Subject: Intel i40e code finds smatch bug
Date: Tue, 19 Jan 2021 12:22:50 -0500	[thread overview]
Message-ID: <38E556EE-C173-4935-80DF-51DC4FE8C90E@joyent.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

We in illumos are in the midst of updating our i40e code from Intel upstream. We found a bug in smatch while building it. It's documented here in:

	https://www.illumos.org/issues/13457

A colleague recommended I include a toy program, try the smatch `master` branch on a Linux distro, and submit the toy to this list.  Its source is attached, ready to compile (without incident) and smatch (with one incident, but not two).  You'll see two cases of potential failure, but only one (the one Intel source uses to confirm proper compilation) breaks smatch.  Look for the KEBE comments.

Once this bug gets fixed, I suspect we'll also be updating our branch of smatch as well.  :)

Thanks,
Dan


[-- Attachment #2: pack.c --]
[-- Type: application/octet-stream, Size: 1646 bytes --]

#include <sys/types.h>
#include <inttypes.h>
#include <stdio.h>

#define u8 uint8_t
#define __le16 uint16_t
#define __le32 uint32_t

#pragma pack(1)
/* Run PHY Activity (0x0626) */
struct i40e_aqc_run_phy_activity {
        u8      cmd_flags;
        __le16  activity_id;
#define I40E_AQ_RUN_PHY_ACT_ID_USR_DFND                 0x10
        u8      reserved;
        union {
                struct {
                        __le32  dnl_opcode;
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT_DUR 0x801a
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT     0x801b
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_DUR      0x1801b
                        __le32  data;
                        u8      reserved2[4];
                } cmd;
                struct {
                        __le32  cmd_status;
#define I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC               0x4
#define I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK               0xFFFF
                        __le32  data0;
                        __le32  data1;
                } resp;
   } params;
};
#pragma pack()

#define I40E_CHECK_STRUCT_LEN(n, X) enum i40e_static_assert_enum_##X \
        { i40e_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }

/* XXX KEBE SAYS this one fails! */
I40E_CHECK_STRUCT_LEN(16, i40e_aqc_run_phy_activity);

int
main(void)
{
	struct i40e_aqc_run_phy_activity foo;

	printf("foo == 0x%p, foo.activity_id = 0x%p, size == %d, tripval = %d\n",
	    &foo, &foo.activity_id, sizeof (struct i40e_aqc_run_phy_activity),
	    /* XXX KEBE SAYS but this one doesn't. */
	    16 / ((sizeof (struct i40e_aqc_run_phy_activity) == 16) ? 1 : 0) );
	return (0);
}

             reply	other threads:[~2021-01-19 17:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-19 17:22 Dan McDonald [this message]
2021-01-19 18:55 ` Intel i40e code finds smatch bug Dan Carpenter
2021-01-19 19:12   ` Dan McDonald
2021-01-19 20:51   ` Dan McDonald
2021-01-19 21:42     ` Luc Van Oostenryck
2021-01-19 21:49       ` Dan McDonald
2021-01-21  8:49       ` Dan Carpenter
2021-01-25 15:10         ` Dan Carpenter
2021-01-25 16:33           ` Luc Van Oostenryck
2021-01-25 16:41           ` Dan McDonald

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38E556EE-C173-4935-80DF-51DC4FE8C90E@joyent.com \
    --to=danmcd@joyent.com \
    --cc=smatch@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).