From: Philip Yang <Philip.Yang@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Philip Yang <Philip.Yang@amd.com>, felix.kuehling@amd.com
Subject: [PATCH v3 2/8] drm/amdkfd: Correct SMI event read size
Date: Tue, 15 Feb 2022 16:22:41 -0500 [thread overview]
Message-ID: <20220215212247.16228-3-Philip.Yang@amd.com> (raw)
In-Reply-To: <20220215212247.16228-1-Philip.Yang@amd.com>
sizeof(buf) is 8 bytes because it is defined as unsigned char *buf,
each SMI event read only copy max 8 bytes to user buffer. Correct this
by using the buf allocate size.
Use KFD_SMI_EVENT_MSG_SIZE to define msg size, the same size will be
used in user space to alloc the msg receive buffer.
Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
index f9eafc796e70..ce78bbd360da 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
@@ -82,7 +82,8 @@ static ssize_t kfd_smi_ev_read(struct file *filep, char __user *user,
struct kfd_smi_client *client = filep->private_data;
unsigned char *buf;
- buf = kmalloc_array(MAX_KFIFO_SIZE, sizeof(*buf), GFP_KERNEL);
+ size = min_t(size_t, size, MAX_KFIFO_SIZE);
+ buf = kmalloc(size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
@@ -96,7 +97,7 @@ static ssize_t kfd_smi_ev_read(struct file *filep, char __user *user,
ret = -EAGAIN;
goto ret_err;
}
- to_copy = min3(size, sizeof(buf), to_copy);
+ to_copy = min(size, to_copy);
ret = kfifo_out(&client->fifo, buf, to_copy);
spin_unlock(&client->lock);
if (ret <= 0) {
@@ -183,7 +184,7 @@ void kfd_smi_event_update_gpu_reset(struct kfd_dev *dev, bool post_reset)
* 1 byte event + 1 byte space + 8 bytes seq num +
* 1 byte \n + 1 byte \0 = 12
*/
- char fifo_in[12];
+ char fifo_in[KFD_SMI_EVENT_MSG_SIZE];
int len;
unsigned int event;
@@ -215,7 +216,7 @@ void kfd_smi_event_update_thermal_throttling(struct kfd_dev *dev,
* 1 byte : + 16 byte thermal_interupt_counter + 1 byte \n +
* 1 byte \0 = 37
*/
- char fifo_in[37];
+ char fifo_in[KFD_SMI_EVENT_MSG_SIZE];
int len;
if (list_empty(&dev->smi_clients))
@@ -235,7 +236,7 @@ void kfd_smi_event_update_vmfault(struct kfd_dev *dev, uint16_t pasid)
/* 1 byte event + 1 byte space + 25 bytes msg + 1 byte \n +
* 1 byte \0 = 29
*/
- char fifo_in[29];
+ char fifo_in[KFD_SMI_EVENT_MSG_SIZE];
int len;
if (list_empty(&dev->smi_clients))
--
2.17.1
next prev parent reply other threads:[~2022-02-15 21:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-15 21:22 [PATCH v3 0/8] HMM profiler interface Philip Yang
2022-02-15 21:22 ` [PATCH v3 1/8] drm/amdkfd: Add KFD SMI event IDs and triggers Philip Yang
2022-02-15 21:22 ` Philip Yang [this message]
2022-02-15 21:22 ` [PATCH v3 3/8] drm/amdkfd: Enable per process SMI event Philip Yang
2022-02-15 21:22 ` [PATCH v3 4/8] drm/amdkfd: Add GPU recoverable fault " Philip Yang
2022-02-15 21:22 ` [PATCH v3 5/8] drm/amdkfd: Add migration " Philip Yang
2022-02-15 21:22 ` [PATCH v3 6/8] drm/amdkfd: Add user queue eviction restore " Philip Yang
2022-02-15 21:22 ` [PATCH v3 7/8] drm/amdkfd: Add unmap from GPU " Philip Yang
2022-02-15 21:22 ` [PATCH v3 8/8] drm/amdkfd: Bump KFD API version for SMI profiling event Philip Yang
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=20220215212247.16228-3-Philip.Yang@amd.com \
--to=philip.yang@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=felix.kuehling@amd.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