Skip to contentSkip to conversation

amdkfd: fix error printing in kfd_ioctl()

PATCH Superseded Oded Gabbay 4 participants 10 messages Dec 14, 2014 – Dec 29, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 amdkfd: fix error printing in kfd_ioctl()

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
index 7d4974b..69c5fe7 100644
@@ -571,7 +571,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 		break;
 	}
 
-	if (err < 0)
+	if ((err < 0) && (err != -EAGAIN))
 		dev_err(kfd_device,
 			"ioctl error %ld for ioctl cmd 0x%x (#%d)\n",
 			err, cmd, _IOC_NR(cmd));
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/4 amdkfd: Add number of watch points to topology

From: Alexey Skidanov <[email protected]>

This patch adds the number of watch points to the node capabilities in the topology module

---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c   |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h     |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 13 +++++++++++++
 3 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +1 -0
index 43884eb..436c31c 100644
@@ -32,6 +32,7 @@
 static const struct kfd_device_info kaveri_device_info = {
 	.max_pasid_bits = 16,
 	.ih_ring_entry_size = 4 * sizeof(uint32_t),
+	.num_of_watch_points = 4,
 	.mqd_size_aligned = MQD_SIZE_ALIGNED
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
index f9fb81e..ba2bba8 100644
@@ -107,6 +107,7 @@ enum cache_policy {
 struct kfd_device_info {
 	unsigned int max_pasid_bits;
 	size_t ih_ring_entry_size;
+	uint8_t num_of_watch_points;
 	uint16_t mqd_size_aligned;
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +13 -0
index b11792d..da34e1f 100644
@@ -27,6 +27,7 @@
 #include <linux/acpi.h>
 #include <linux/hash.h>
 #include <linux/cpufreq.h>
+#include <linux/log2.h>
 
 #include "kfd_priv.h"
 #include "kfd_crat.h"
@@ -634,6 +635,7 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
 	struct kfd_topology_device *dev;
 	char public_name[KFD_TOPOLOGY_PUBLIC_NAME_SIZE];
 	uint32_t i;
+	uint32_t log_max_watch_addr;
 
 	/* Making sure that the buffer is an empty string */
 	buffer[0] = 0;
@@ -708,6 +710,17 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
 				dev->node_props.location_id);
 
 		if (dev->gpu) {
+			log_max_watch_addr =
+				__ilog2_u32(dev->gpu->device_info->num_of_watch_points);
+
+			if (log_max_watch_addr) {
+				dev->node_props.capability |=
+						HSA_CAP_WATCH_POINTS_SUPPORTED;
+				dev->node_props.capability |=
+					(log_max_watch_addr << HSA_CAP_WATCH_POINTS_TOTALBITS_SHIFT) &
+					HSA_CAP_WATCH_POINTS_TOTALBITS_MASK;
+			}
+
 			sysfs_show_32bit_prop(buffer, "max_engine_clk_fcompute",
 					kfd2kgd->get_max_engine_clock_in_mhz(
 						dev->gpu->kgd));
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 3/4 amdkfd: Remove duplicate include

In reply to Oded Gabbay
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
index 69c5fe7..4083dbc 100644
@@ -31,7 +31,6 @@
 #include <uapi/linux/kfd_ioctl.h>
 #include <linux/time.h>
 #include <linux/mm.h>
-#include <linux/uaccess.h>
 #include <uapi/asm-generic/mman-common.h>
 #include <asm/processor.h>
 #include "kfd_priv.h"
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH 4/4 amdkfd: Process-device data creation and lookup split

In reply to Oded Gabbay

From: Alexey Skidanov <[email protected]>

This patch splits the current kfd_get_process_device_data() to two functions, one that specifically creates a pdd and another one which just do lookup.

This is done to enhance the readability and maintainability of the code.

---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  |  1 -
 drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c          |  4 ---
 drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c       | 13 ++++---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  5 +--
 drivers/gpu/drm/amd/amdkfd/kfd_process.c           | 40 +++++++++++++---------
 .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 14 +++++---
 6 files changed, 46 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -1
index f44d673..7b6df51 100644
@@ -75,7 +75,6 @@ get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
 	nybble = (pdd->lds_base >> 60) & 0x0E;
 
 	return nybble;
-
 }
 
 static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +0 -4
index b5791a5..1a9b355 100644
@@ -137,10 +137,6 @@ int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma)
 	if (dev == NULL)
 		return -EINVAL;
 
-	/* Find if pdd exists for combination of process and gpu id */
-	if (!kfd_get_process_device_data(dev, process, 0))
-		return -EINVAL;
-
 	/* Calculate physical address of doorbell */
 	address = kfd_get_process_doorbells(dev, process);
 
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c +9 -4
index e64aa99..5c91029 100644
@@ -303,10 +303,11 @@ int kfd_init_apertures(struct kfd_process *process)
 	while ((dev = kfd_topology_enum_kfd_devices(id)) != NULL &&
 		id < NUM_OF_SUPPORTED_GPUS) {
 
-		pdd = kfd_get_process_device_data(dev, process, 1);
-		if (!pdd)
-			return -1;
-
+		pdd = kfd_create_process_device_data(dev, process);
+		if (pdd == NULL) {
+			pr_err("Failed to create process device data\n");
+			goto err;
+		}
 		/*
 		 * For 64 bit process aperture will be statically reserved in
 		 * the x86_64 non canonical process address space
@@ -349,6 +350,10 @@ int kfd_init_apertures(struct kfd_process *process)
 	}
 
 	return 0;
+
+err:
+	mutex_unlock(&process->mutex);
+	return -1;
 }
 
 
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -2
index ba2bba8..a2e053c 100644
@@ -473,8 +473,9 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
 							struct kfd_process *p);
 void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid);
 struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
-							struct kfd_process *p,
-							int create_pdd);
+							struct kfd_process *p);
+struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
+							struct kfd_process *p);
 
 /* Process device data iterator */
 struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +24 -16
index 3c76ef0..a369c14 100644
@@ -311,24 +311,29 @@ err_alloc_process:
 }
 
 struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
-							struct kfd_process *p,
-							int create_pdd)
+							struct kfd_process *p)
 {
 	struct kfd_process_device *pdd = NULL;
 
 	list_for_each_entry(pdd, &p->per_device_data, per_device_list)
 		if (pdd->dev == dev)
-			return pdd;
-
-	if (create_pdd) {
-		pdd = kzalloc(sizeof(*pdd), GFP_KERNEL);
-		if (pdd != NULL) {
-			pdd->dev = dev;
-			INIT_LIST_HEAD(&pdd->qpd.queues_list);
-			INIT_LIST_HEAD(&pdd->qpd.priv_queue_list);
-			pdd->qpd.dqm = dev->dqm;
-			list_add(&pdd->per_device_list, &p->per_device_data);
-		}
+			break;
+
+	return pdd;
+}
+
+struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
+							struct kfd_process *p)
+{
+	struct kfd_process_device *pdd = NULL;
+
+	pdd = kzalloc(sizeof(*pdd), GFP_KERNEL);
+	if (pdd != NULL) {
+		pdd->dev = dev;
+		INIT_LIST_HEAD(&pdd->qpd.queues_list);
+		INIT_LIST_HEAD(&pdd->qpd.priv_queue_list);
+		pdd->qpd.dqm = dev->dqm;
+		list_add(&pdd->per_device_list, &p->per_device_data);
 	}
 
 	return pdd;
@@ -344,11 +349,14 @@ struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
 struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
 							struct kfd_process *p)
 {
-	struct kfd_process_device *pdd = kfd_get_process_device_data(dev, p, 1);
+	struct kfd_process_device *pdd;
 	int err;
 
-	if (pdd == NULL)
+	pdd = kfd_get_process_device_data(dev, p);
+	if (!pdd) {
+		pr_err("Process device data doesn't exist\n");
 		return ERR_PTR(-ENOMEM);
+	}
 
 	if (pdd->bound)
 		return pdd;
@@ -384,7 +392,7 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid)
 
 	pqm_uninit(&p->pqm);
 
-	pdd = kfd_get_process_device_data(dev, p, 0);
+	pdd = kfd_get_process_device_data(dev, p);
 
 	/*
 	 * Just mark pdd as unbound, because we still need it to call
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +10 -4
index 4752678..d12f9d3 100644
@@ -167,8 +167,11 @@ int pqm_create_queue(struct process_queue_manager *pqm,
 	q = NULL;
 	kq = NULL;
 
-	pdd = kfd_get_process_device_data(dev, pqm->process, 1);
-	BUG_ON(!pdd);
+	pdd = kfd_get_process_device_data(dev, pqm->process);
+	if (!pdd) {
+		pr_err("Process device data doesn't exist\n");
+		return -1;
+	}
 
 	retval = find_available_queue_slot(pqm, qid);
 	if (retval != 0)
@@ -273,8 +276,11 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
 		dev = pqn->q->device;
 	BUG_ON(!dev);
 
-	pdd = kfd_get_process_device_data(dev, pqm->process, 1);
-	BUG_ON(!pdd);
+	pdd = kfd_get_process_device_data(dev, pqm->process);
+	if (!pdd) {
+		pr_err("Process device data doesn't exist\n");
+		return -1;
+	}
 
 	if (pqn->kq) {
 		/* destroy kernel queue (DIQ) */
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Oded Gabbay

Am 14.12.2014 um 14:35 schrieb Oded Gabbay:

Quoted 1 line

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

You most likely want to handle -ERESTARTSYS the same way.

Christian.

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index 7d4974b..69c5fe7 100644

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) · line 577

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
@@ -571,7 +571,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  		break;
  	}
 
-	if (err < 0)
+	if ((err < 0) && (err != -EAGAIN))
  		dev_err(kfd_device,
  			"ioctl error %ld for ioctl cmd 0x%x (#%d)\n",
  			err, cmd, _IOC_NR(cmd));

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 6 lines · Christian König

Am 14.12.2014 um 14:35 schrieb Oded Gabbay:

Quoted 1 line

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

You most likely want to handle -ERESTARTSYS the same way.

Christian.

Thanks, will fix and resend.

Oded

Quoted 7 lines
Quoted 7 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index 7d4974b..69c5fe7 100644

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static long kfd_ioctl(struct file *filep, unsigned int · line 577

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
@@ -571,7 +571,7 @@ static long kfd_ioctl(struct file *filep, unsigned int
 cmd, unsigned long arg)
          break;
      }
-    if (err < 0)
+    if ((err < 0) && (err != -EAGAIN))
          dev_err(kfd_device,
              "ioctl error %ld for ioctl cmd 0x%x (#%d)\n",
              err, cmd, _IOC_NR(cmd));

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
In reply to Christian König
Quoted 4 lines · Christian König

Am 14.12.2014 um 14:35 schrieb Oded Gabbay:

Quoted 1 line

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

You most likely want to handle -ERESTARTSYS the same way.

Please just reuse drmIoctl or at least copy it perfectly. We've had too many tears about ioctl restarting going badly wrong. Also make sure you never do a raw ioctl call anywhere for amdkfd. Adding Dave.

Thanks, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#7 lore raw
Quoted 9 lines · Daniel Vetter
Quoted 4 lines · Christian König

Am 14.12.2014 um 14:35 schrieb Oded Gabbay:

Quoted 1 line

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

You most likely want to handle -ERESTARTSYS the same way.

Please just reuse drmIoctl or at least copy it perfectly. We've had too many tears about ioctl restarting going badly wrong. Also make sure you never do a raw ioctl call anywhere for amdkfd. Adding Dave.

Also please don't make a user triggerable printk.

If the user can throw crap at the ioctl and get msgs in dmesg, then its annoying as hell.

Copy the drm.debug stuff and code as well, and for userspace, yes do what Daniel says and use drmIoctl wrapper or something like that, though Daniel I believe one of the main consumers on i915 insists on opencoding his ioctls.

Dave.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
Quoted 16 lines · Dave Airlie
Quoted 9 lines · Daniel Vetter
Quoted 4 lines · Christian König

Am 14.12.2014 um 14:35 schrieb Oded Gabbay:

Quoted 1 line

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

You most likely want to handle -ERESTARTSYS the same way.

Please just reuse drmIoctl or at least copy it perfectly. We've had too many tears about ioctl restarting going badly wrong. Also make sure you never do a raw ioctl call anywhere for amdkfd. Adding Dave.

Also please don't make a user triggerable printk.

If the user can throw crap at the ioctl and get msgs in dmesg, then its annoying as hell.

Quoted 7 lines

Copy the drm.debug stuff and code as well, and for userspace, yes do what Daniel says and use drmIoctl wrapper or something like that, though Daniel I believe one of the main consumers on i915 insists on opencoding his ioctls.

Dave.

Dave & Daniel,

Thanks for the guidance & comments.
I will take a look at drmioctl & drm.debug stuff and copy/reuse what's relevant.
After that, I'll resubmit this patch, and probably this will generate some more patches for me to submit for review.

Oded
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw
In reply to Dave Airlie
Quoted 16 lines · Dave Airlie
Quoted 9 lines · Daniel Vetter
Quoted 4 lines · Christian König

Am 14.12.2014 um 14:35 schrieb Oded Gabbay:

Quoted 1 line

When an ioctl function returns -EAGAIN, don't print error in kfd_ioctl()

You most likely want to handle -ERESTARTSYS the same way.

Please just reuse drmIoctl or at least copy it perfectly. We've had too many tears about ioctl restarting going badly wrong. Also make sure you never do a raw ioctl call anywhere for amdkfd. Adding Dave.

Also please don't make a user triggerable printk.

If the user can throw crap at the ioctl and get msgs in dmesg, then its annoying as hell.

Quoted 7 lines

Copy the drm.debug stuff and code as well, and for userspace, yes do what Daniel says and use drmIoctl wrapper or something like that, though Daniel I believe one of the main consumers on i915 insists on opencoding his ioctls.

Dave.

Hi Dave, Daniel

I just sent a patch-set that copies the drm_ioctl() handling to kfd_ioctl(), as you requested. All error prints have been converted to debug prints.
This is the first part and I'm now going to change the userspace as well.

Oded
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel