Re: [PATCH v3 5/5] iommu/amd - Add a debugfs entry to specify a IOMMU device table entry

2018-03-17 Thread kbuild test robot
Hi Gary,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc4]
[also build test WARNING on next-20180316]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Gary-R-Hook/Add-debugfs-info-for-the-AMD-IOMMU/20180317-232302
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/iommu/amd_iommu_debugfs.c: In function 
'amd_iommu_debugfs_devid_write':
>> drivers/iommu/amd_iommu_debugfs.c:145:3: warning: ignoring return value of 
>> 'kstrtoint', declared with attribute warn_unused_result [-Wunused-result]
  kstrtoint(obuf, 0, &amd_iommu_devid);
  ^~~~

vim +/kstrtoint +145 drivers/iommu/amd_iommu_debugfs.c

   123  
   124  static ssize_t amd_iommu_debugfs_devid_write(struct file *filp,
   125  const char __user *ubuf,
   126  size_t count, loff_t *offp)
   127  {
   128  unsigned int pci_id, pci_slot, pci_func;
   129  unsigned int obuflen = 80;
   130  ssize_t ret;
   131  char *obuf;
   132  
   133  obuf = kmalloc(OBUFLEN, GFP_KERNEL);
   134  if (!obuf)
   135  return -ENOMEM;
   136  
   137  ret = simple_write_to_buffer(obuf, OBUFLEN, offp, ubuf, count);
   138  
   139  if (strnchr(obuf, OBUFLEN, ':')) {
   140  int n;
   141  n = sscanf(obuf, "%x:%x.%x", &pci_id, &pci_slot, 
&pci_func);
   142  if (n == 3)
   143  amd_iommu_devid = PCI_DEVID(pci_id, 
PCI_DEVFN(pci_slot, pci_func));
   144  } else {
 > 145  kstrtoint(obuf, 0, &amd_iommu_devid);
   146  }
   147  
   148  kfree(obuf);
   149  
   150  return ret;
   151  }
   152  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH v3 5/5] iommu/amd - Add a debugfs entry to specify a IOMMU device table entry

2018-03-14 Thread Gary R Hook
Initially (at boot) the device table values dumped are all of the
active devices.  Add a devid debugfs file to allow the user to select a
single device table entry to dump (active or not). Let any devid value
greater than the maximum allowable PCI ID (0x) restore the
behavior to that effective at boot.

Signed-off-by: Gary R Hook 
---
 drivers/iommu/amd_iommu_debugfs.c |  121 -
 1 file changed, 106 insertions(+), 15 deletions(-)

diff --git a/drivers/iommu/amd_iommu_debugfs.c 
b/drivers/iommu/amd_iommu_debugfs.c
index 1d941c5329be..47bf718f6178 100644
--- a/drivers/iommu/amd_iommu_debugfs.c
+++ b/drivers/iommu/amd_iommu_debugfs.c
@@ -42,6 +42,7 @@ static DEFINE_MUTEX(iommu_debugfs_lock);
 #defineMAX_NAME_LEN20
 
 static unsigned int amd_iommu_verbose = 0;
+static unsigned int amd_iommu_devid = ~0;
 
 static unsigned int amd_iommu_count_valid_dtes(int start, int end)
 {
@@ -92,14 +93,84 @@ static const struct file_operations 
amd_iommu_debugfs_dtecount_ops = {
.write = NULL,
 };
 
+static ssize_t amd_iommu_debugfs_devid_read(struct file *filp,
+   char __user *ubuf,
+   size_t count, loff_t *offp)
+{
+   unsigned int obuflen = 64;
+   unsigned int oboff = 0;
+   ssize_t ret;
+   char *obuf;
+
+   obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+   if (!obuf)
+   return -ENOMEM;
+
+   if (amd_iommu_verbose)
+   oboff += OSCNPRINTF("%02x:%02x:%x (%u / %04x)\n",
+   PCI_BUS_NUM(amd_iommu_devid),
+   PCI_SLOT(amd_iommu_devid),
+   PCI_FUNC(amd_iommu_devid),
+   amd_iommu_devid, amd_iommu_devid);
+   else
+   oboff += OSCNPRINTF("%u\n", amd_iommu_devid);
+
+   ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+   kfree(obuf);
+
+   return ret;
+}
+
+static ssize_t amd_iommu_debugfs_devid_write(struct file *filp,
+   const char __user *ubuf,
+   size_t count, loff_t *offp)
+{
+   unsigned int pci_id, pci_slot, pci_func;
+   unsigned int obuflen = 80;
+   ssize_t ret;
+   char *obuf;
+
+   obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+   if (!obuf)
+   return -ENOMEM;
+
+   ret = simple_write_to_buffer(obuf, OBUFLEN, offp, ubuf, count);
+
+   if (strnchr(obuf, OBUFLEN, ':')) {
+   int n;
+   n = sscanf(obuf, "%x:%x.%x", &pci_id, &pci_slot, &pci_func);
+   if (n == 3)
+   amd_iommu_devid = PCI_DEVID(pci_id, PCI_DEVFN(pci_slot, 
pci_func));
+   } else {
+   kstrtoint(obuf, 0, &amd_iommu_devid);
+   }
+
+   kfree(obuf);
+
+   return ret;
+}
+
+static const struct file_operations amd_iommu_debugfs_devid_ops = {
+   .owner = THIS_MODULE,
+   .open = simple_open,
+   .read = amd_iommu_debugfs_devid_read,
+   .write = amd_iommu_debugfs_devid_write,
+};
+
 #defineMAX_PCI_ID  0x
 
-#definePRINTDTE(i) OSCNPRINTF("%02x:%02x:%x - %016llx %016llx 
%016llx %016llx\n", \
-  PCI_BUS_NUM(i), PCI_SLOT(i), PCI_FUNC(i), \
-  amd_iommu_dev_table[i].data[0], \
-  amd_iommu_dev_table[i].data[1], \
-  amd_iommu_dev_table[i].data[2], \
-  amd_iommu_dev_table[i].data[3]);
+static inline int amd_iommu_debugfs_printdte(int i, char *obuf, unsigned int 
obuflen, unsigned int oboff)
+{
+   int rc;
+
+   rc = OSCNPRINTF("%02x:%02x:%x - %016llx %016llx %016llx %016llx\n",
+   PCI_BUS_NUM(i), PCI_SLOT(i), PCI_FUNC(i),
+   amd_iommu_dev_table[i].data[0],
+   amd_iommu_dev_table[i].data[1],
+   amd_iommu_dev_table[i].data[2],
+   amd_iommu_dev_table[i].data[3]);
+   return rc;
+}
 
 static ssize_t amd_iommu_debugfs_dte_read(struct file *filp,
  char __user *ubuf,
@@ -113,19 +184,28 @@ static ssize_t amd_iommu_debugfs_dte_read(struct file 
*filp,
char *obuf;
 
/* Count the number of valid entries in the device table */
-   istart = 0;
-   iend = MAX_PCI_ID;
-   n = amd_iommu_count_valid_dtes(istart, iend);
+   if (amd_iommu_devid > MAX_PCI_ID) {
+   istart = 0;
+   iend = MAX_PCI_ID;
+   n = amd_iommu_count_valid_dtes(istart, iend);
+   } else {
+   n = 1;
+   }
obuflen = n * 80;
 
obuf = kmalloc(OBUFLEN, GFP_KERNEL);
if (!obuf)
return -ENOMEM;
 
-   for (i = istart ; i <= iend ; i++)
-   if ((amd_iommu_dev_table[i].data