public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: John Moon <quic_johmoo@quicinc.com>
To: <libabigail@sourceware.org>, <dodji@seketeli.org>
Cc: Trilok Soni <quic_tsoni@quicinc.com>,
	Satya Durga Srinivasu Prabhala <quic_satyap@quicinc.com>
Subject: abidiff improvements for kernel UAPI checker
Date: Mon, 10 Apr 2023 17:45:48 -0700	[thread overview]
Message-ID: <5363161d-8167-284e-e35d-9a8ef20adea9@quicinc.com> (raw)

Hi all,

As you may be aware from the Linux kernel mailing list threads I've been 
CC'ing you on, we're in the process of upstreaming a shell script that 
uses abidiff to compare Linux kernel userspace APIs between revisions. 
Linux UAPIs are supposed to be stable forever, so we're trying to detect 
when a patch breaks a UAPI.

If you haven't been following, the latest thread is here: 
https://lore.kernel.org/lkml/20230407203456.27141-1-quic_johmoo@quicinc.com/

At a high level, we're taking the header file before/after the patch, 
building it in a dummy C file, then taking advantage of abidiff's 
"--non-reachable-types" argument to compare all the symbols.

This method works great! However, there are a couple of classes of ABI 
differences that are detected but don't qualify as UAPI-breaking.

By far the most common class of differences occur with enum expansions.

For example, this change triggers finding: 
https://github.com/torvalds/linux/commit/622f1b2fae2eea28a80b04f130e3bb54227699f8#diff-a7f82b68b3459e13934c123bda4c3a9be20eadebe938a376e39a395e5ffa825a 


Specifically this change to include/uapi/linux/dbcnl.h:
diff --git a/include/uapi/linux/dcbnl.h b/include/uapi/linux/dcbnl.h
index 99047223ab26..7e15214aa5dd 100644
--- a/include/uapi/linux/dcbnl.h
+++ b/include/uapi/linux/dcbnl.h
@@ -411,6 +411,7 @@ enum dcbnl_attrs {
   * @DCB_ATTR_IEEE_PEER_PFC: peer PFC configuration - get only
   * @DCB_ATTR_IEEE_PEER_APP: peer APP tlv - get only
   * @DCB_ATTR_DCB_APP_TRUST_TABLE: selector trust table
+ * @DCB_ATTR_DCB_REWR_TABLE: rewrite configuration
   */
  enum ieee_attrs {
         DCB_ATTR_IEEE_UNSPEC,
@@ -425,6 +426,7 @@ enum ieee_attrs {
         DCB_ATTR_IEEE_QCN_STATS,
         DCB_ATTR_DCB_BUFFER,
         DCB_ATTR_DCB_APP_TRUST_TABLE,
+       DCB_ATTR_DCB_REWR_TABLE,
         __DCB_ATTR_IEEE_MAX
  };


abidiff correctly reports there's an ABI difference:

     [C] 'enum ieee_attrs' changed:
       type size hasn't changed
       1 enumerator insertion:
         'ieee_attrs::DCB_ATTR_DCB_REWR_TABLE' value '12'
       1 enumerator change:
         'ieee_attrs::__DCB_ATTR_IEEE_MAX' from value '12' to '13' at 
dcbnl.h:416:1

It's quite common in the kernel to have the last variant in your enum be 
*_MAX, then define the max value of the enum based on that variant.

However, just adding a variant to this enum doesn't break userspace 
(unless you have a program that does something silly like this):

if (DCB_ATTR_IEEE_MAX > 12) {
     // crash the program
}

Assuming that programs will use the MAX value in a reasonable way, we 
can consider this change safe for userspace backwards-compatibility if 
it meets the following criteria:

   1. No variants are removed/renamed
   2. No variants have a changed value (unless it's the last one)

Technically, we could parse the stdout of abidiff to see if these 
conditions are met, but that'd be quite complicated and fragile. It 
seems a better choice to detect them when the data structures are available.

Do you have any ideas on how these condition could be detected from 
abidiff? We could spend some time to implement the logic, but I'm not 
sure if this kind of specific use case is within the scope of your project.

If so, could something be added like "--ignore-enum-expansion" (or some 
other flag)?

There are other similar "false positives" discussed in the LKML thread, 
but this first one is the largest and probably the easiest to detect 
algorithmically, so I figure it's a good starting point.

Thank you in advance for any help!

- John Moon

             reply	other threads:[~2023-04-11  0:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11  0:45 John Moon [this message]
2023-04-16 18:33 ` Trilok Soni
2023-04-21 18:21 ` Dodji Seketeli
2023-04-21 20:03   ` Dodji Seketeli
2023-04-24 18:39     ` John Moon
2023-05-10 14:21       ` Dodji Seketeli
2023-05-23 19:59         ` John Moon
2023-07-05 16:52           ` John Moon
2023-10-05 13:44             ` Support suppressing data members inserted right before flexible array members (was Re: abidiff improvements for kernel UAPI checker) Dodji Seketeli
2023-07-10 10:55           ` abidiff improvements for kernel UAPI checker Dodji Seketeli
2023-09-22 11:39       ` Dodji Seketeli
2023-09-22 11:51         ` Dodji Seketeli
2023-09-22 18:28           ` John Moon
2023-09-22 20:02             ` John Moon
2023-09-26  8:38             ` Dodji Seketeli
2023-09-27 17:37               ` John Moon
2023-09-29  9:52                 ` Dodji Seketeli

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=5363161d-8167-284e-e35d-9a8ef20adea9@quicinc.com \
    --to=quic_johmoo@quicinc.com \
    --cc=dodji@seketeli.org \
    --cc=libabigail@sourceware.org \
    --cc=quic_satyap@quicinc.com \
    --cc=quic_tsoni@quicinc.com \
    /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).