patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Kevin Traynor <ktraynor@redhat.com>
To: Robin Jarry <robin.jarry@6wind.com>
Cc: Olivier Matz <olivier.matz@6wind.com>, dpdk stable <stable@dpdk.org>
Subject: [dpdk-stable] patch 'usertools: fix pmdinfo with python 3 and pyelftools>=0.24' has been queued to LTS release 18.11.6
Date: Tue, 10 Dec 2019 14:59:19 +0000	[thread overview]
Message-ID: <20191210145937.32755-45-ktraynor@redhat.com> (raw)
In-Reply-To: <20191210145937.32755-1-ktraynor@redhat.com>

Hi,

FYI, your patch has been queued to LTS release 18.11.6

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/16/19. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable-queue

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable-queue/commit/ce007065793c0918e01c76618d0d9cedfb533145

Thanks.

Kevin.

---
From ce007065793c0918e01c76618d0d9cedfb533145 Mon Sep 17 00:00:00 2001
From: Robin Jarry <robin.jarry@6wind.com>
Date: Tue, 15 Oct 2019 14:39:17 +0200
Subject: [PATCH] usertools: fix pmdinfo with python 3 and pyelftools>=0.24

[ upstream commit 4da069194ef4578aac7ae10cf05abd992c61723c ]

Running dpdk-pmdinfo.py on Ubuntu 18.04 (bionic) with python 3 and
pyelftools installed produces no output but no error is reported
neither:

  ~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
  ~$ echo $?
  0

While with python 2, it works:

  ~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
  {"pci_ids": [], "name": "dpio"}
  {"pci_ids": [], "name": "dpbp"}
  {"pci_ids": [], "name": "dpaa2_qdma"}
  .....

On Ubuntu 18.04, pyelftools is version 0.24. The change log of
pyelftools v0.24 says:

 - Symbol/section names are strings internally now, not bytestrings
   (this may affect API usage in Python 3) (#76).

We cannot guess which version of pyelftools is actually being used. The
elftools.__version__ symbol is not consistent with each distro's package
version. For example, on Ubuntu 16.04 (xenial), the .deb package version
is '0.23-2' but elftools.__version__ contains '0.25'. This is certainly
due to partial backports.

To have a more consistent behaviour of this script across all versions
of python, add the unicode_literals future import so that literal
strings are now always "unicode".

Add 2 utility functions to force a string into bytes or bytes into an
unicode string.

Force pyelftools return values to unicode strings (will do nothing with
recent version of pyelftools).

If elffile.get_section_by_name returns None with a unicode section name,
try with the same one encoded as bytes.

Also, replace all open() calls by io.open() which behaves like the
builtin open in python 3. The only non-binary opened file is
/usr/share/hwdata/pci.ids which is UTF-8 encoded text. Explicitly
specify that encoding.

Link: https://github.com/eliben/pyelftools/blob/v0.24/CHANGES#L7
Link: https://github.com/eliben/pyelftools/commit/108eaea9e75a8b5a

Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")

Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
---
 usertools/dpdk-pmdinfo.py | 65 +++++++++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 19 deletions(-)

diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
index 03623d5b8..069a3bf12 100755
--- a/usertools/dpdk-pmdinfo.py
+++ b/usertools/dpdk-pmdinfo.py
@@ -9,5 +9,7 @@
 # -------------------------------------------------------------------------
 from __future__ import print_function
+from __future__ import unicode_literals
 import json
+import io
 import os
 import platform
@@ -15,5 +17,5 @@ import string
 import sys
 from elftools.common.exceptions import ELFError
-from elftools.common.py3compat import (byte2int, bytes2str, str2bytes)
+from elftools.common.py3compat import byte2int
 from elftools.elf.elffile import ELFFile
 from optparse import OptionParser
@@ -214,5 +216,6 @@ class PCIIds:
         Reads the local file
         """
-        self.contents = open(filename).readlines()
+        with io.open(filename, 'r', encoding='utf-8') as f:
+            self.contents = f.readlines()
         self.date = self.findDate(self.contents)
 
@@ -268,5 +271,11 @@ class ReadElf(object):
         except ValueError:
             # Not a number. Must be a name then
-            return self.elffile.get_section_by_name(str2bytes(spec))
+            section = self.elffile.get_section_by_name(force_unicode(spec))
+            if section is None:
+                # No match with a unicode name.
+                # Some versions of pyelftools (<= 0.23) store internal strings
+                # as bytes. Try again with the name encoded as bytes.
+                section = self.elffile.get_section_by_name(force_bytes(spec))
+            return section
 
     def pretty_print_pmdinfo(self, pmdinfo):
@@ -340,5 +349,6 @@ class ReadElf(object):
                 endptr += 1
 
-            mystring = bytes2str(data[dataptr:endptr])
+            # pyelftools may return byte-strings, force decode them
+            mystring = force_unicode(data[dataptr:endptr])
             rc = mystring.find("PMD_INFO_STRING")
             if (rc != -1):
@@ -349,7 +359,8 @@ class ReadElf(object):
     def find_librte_eal(self, section):
         for tag in section.iter_tags():
-            if tag.entry.d_tag == 'DT_NEEDED':
-                if "librte_eal" in tag.needed:
-                    return tag.needed
+            # pyelftools may return byte-strings, force decode them
+            if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
+                if "librte_eal" in force_unicode(tag.needed):
+                    return force_unicode(tag.needed)
         return None
 
@@ -374,5 +385,5 @@ class ReadElf(object):
                 if raw_output is False:
                     print("Scanning for autoload path in %s" % library)
-                scanfile = open(library, 'rb')
+                scanfile = io.open(library, 'rb')
                 scanelf = ReadElf(scanfile, sys.stdout)
         except AttributeError:
@@ -404,5 +415,6 @@ class ReadElf(object):
                 endptr += 1
 
-            mystring = bytes2str(data[dataptr:endptr])
+            # pyelftools may return byte-strings, force decode them
+            mystring = force_unicode(data[dataptr:endptr])
             rc = mystring.find("DPDK_PLUGIN_PATH")
             if (rc != -1):
@@ -417,6 +429,7 @@ class ReadElf(object):
     def get_dt_runpath(self, dynsec):
         for tag in dynsec.iter_tags():
-            if tag.entry.d_tag == 'DT_RUNPATH':
-                return tag.runpath
+            # pyelftools may return byte-strings, force decode them
+            if force_unicode(tag.entry.d_tag) == 'DT_RUNPATH':
+                return force_unicode(tag.runpath)
         return ""
 
@@ -439,8 +452,8 @@ class ReadElf(object):
 
         for tag in dynsec.iter_tags():
-            if tag.entry.d_tag == 'DT_NEEDED':
-                rc = tag.needed.find(b"librte_pmd")
-                if (rc != -1):
-                    library = search_file(tag.needed,
+            # pyelftools may return byte-strings, force decode them
+            if force_unicode(tag.entry.d_tag) == 'DT_NEEDED':
+                if 'librte_pmd' in force_unicode(tag.needed):
+                    library = search_file(force_unicode(tag.needed),
                                           runpath + ":" + ldlibpath +
                                           ":/usr/lib64:/lib64:/usr/lib:/lib")
@@ -448,5 +461,5 @@ class ReadElf(object):
                         if raw_output is False:
                             print("Scanning %s for pmd information" % library)
-                        with open(library, 'rb') as file:
+                        with io.open(library, 'rb') as file:
                             try:
                                 libelf = ReadElf(file, sys.stdout)
@@ -459,4 +472,18 @@ class ReadElf(object):
 
 
+# compat: remove force_unicode & force_bytes when pyelftools<=0.23 support is
+# dropped.
+def force_unicode(s):
+    if hasattr(s, 'decode') and callable(s.decode):
+        s = s.decode('latin-1')  # same encoding used in pyelftools py3compat
+    return s
+
+
+def force_bytes(s):
+    if hasattr(s, 'encode') and callable(s.encode):
+        s = s.encode('latin-1')  # same encoding used in pyelftools py3compat
+    return s
+
+
 def scan_autoload_path(autoload_path):
     global raw_output
@@ -477,5 +504,5 @@ def scan_autoload_path(autoload_path):
         if os.path.isfile(dpath):
             try:
-                file = open(dpath, 'rb')
+                file = io.open(dpath, 'rb')
                 readelf = ReadElf(file, sys.stdout)
             except ELFError:
@@ -504,5 +531,5 @@ def scan_for_autoload_pmds(dpdk_path):
         return
 
-    file = open(dpdk_path, 'rb')
+    file = io.open(dpdk_path, 'rb')
     try:
         readelf = ReadElf(file, sys.stdout)
@@ -596,5 +623,5 @@ def main(stream=None):
         sys.exit(1)
 
-    with open(myelffile, 'rb') as file:
+    with io.open(myelffile, 'rb') as file:
         try:
             readelf = ReadElf(file, sys.stdout)
-- 
2.21.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2019-12-10 14:49:42.092757126 +0000
+++ 0045-usertools-fix-pmdinfo-with-python-3-and-pyelftools-0.patch	2019-12-10 14:49:39.077457301 +0000
@@ -1 +1 @@
-From 4da069194ef4578aac7ae10cf05abd992c61723c Mon Sep 17 00:00:00 2001
+From ce007065793c0918e01c76618d0d9cedfb533145 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 4da069194ef4578aac7ae10cf05abd992c61723c ]
+
@@ -56 +57,0 @@
-Cc: stable@dpdk.org


  parent reply	other threads:[~2019-12-10 15:01 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 14:58 [dpdk-stable] patch 'app/testpmd: fix CRC strip command' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/i40e: fix integer overflow' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'vhost: translate incoming log address to GPA' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'vhost: fix virtqueue not accessible' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'vhost: prevent zero copy mode if IOMMU is on' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/i40e: fix address of first segment' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/ixgbe: " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'doc: fix a common typo in NIC guides' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'app/testpmd: fix help for loop topology option' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/mlx4: remove dependency on libmnl in meson' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/axgbe: fix double unlock' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/af_packet: improve Tx statistics accuracy' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/enetc: fix BD ring alignment' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'bus/fslmc: fix global variable multiple definitions' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/igb: " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'crypto/null: " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'crypto/virtio: " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'compress/octeontx: " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'test: " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'reciprocal: fix off-by-one with 32-bit divisor' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'vfio: fix truncated BAR offset for 32-bit' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'ethdev: fix include of ethernet header file' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/bnxt: fix mbuf free when clearing Tx queue' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/i40e: fix exception with multi-driver' " Kevin Traynor
2019-12-10 14:58 ` [dpdk-stable] patch 'net/ixgbe: fix zeroing of RSS config' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/e1000: " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/virtio: reject deferred Rx start' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/virtio: reject deferred Tx " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/virtio: reject unsupported Rx multi-queue modes' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/virtio: reject unsupported Tx " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'vhost: fix IPv4 checksum' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/mlx: fix debug build with icc' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'app/testpmd: fix Tx checksum when TSO enabled' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bnxt: fix ping with MTU change' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bnxt: fix setting max RSS contexts' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bnxt: fix writing MTU to FW' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bnxt: expose some missing counters in port stats' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bonding: use non deprecated PCI API' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'vhost: fix build on RHEL 7.6 for Power' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'app/procinfo: use strlcpy for copying string' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'examples/vm_power: fix type of cmdline token in cli' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'examples/l3fwd-power: fix Rx interrupt disabling' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'power: fix socket indicator value' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'examples/vm_power: fix build without i40e' " Kevin Traynor
2019-12-10 14:59 ` Kevin Traynor [this message]
2019-12-10 14:59 ` [dpdk-stable] patch 'usertools: fix telemetry client with python 3' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'doc: fix description of links to EAL options pages' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'common/dpaax: fallback to check separate memory node for VM' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'doc: fix description of versioning macros' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'eventdev: fix possible use of uninitialized var' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'common/cpt: fix possible null dereference' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'compress/octeontx: remove commented out code' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'event/opdl: " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bnxt: " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'mk: fix build on arm64' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'crypto/dpaa2_sec: fix length retrieved from hardware' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'examples/ipsec-secgw: fix GCM IV length' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'examples/ipsec-secgw: fix SHA256-HMAC digest " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'crypto/openssl: use local copy for session contexts' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/fm10k: fix mbuf free in vector Rx' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/igb: fix PHY status if PHY reset is not blocked' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'net/bonding: fix port ID check' " Kevin Traynor
2019-12-10 14:59 ` [dpdk-stable] patch 'port: fix pcap support with meson' " Kevin Traynor

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=20191210145937.32755-45-ktraynor@redhat.com \
    --to=ktraynor@redhat.com \
    --cc=olivier.matz@6wind.com \
    --cc=robin.jarry@6wind.com \
    --cc=stable@dpdk.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 NNTP newsgroup(s).