accel/amdxdna: Fix clflush buffer size
Lizhi Hou
maintainerPATCH 1/1 accel/amdxdna: Fix clflush buffer size
The firmware is told the buffer is req.buf_size bytes. It may read/write the entire region. If the CPU only flushes a subset, the remaining cache lines could contain stale data, causing the device to see garbage.
--- drivers/accel/amdxdna/aie2_message.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/accel/amdxdna/aie2_message.c +3 -3
@@ -390,7 +390,7 @@ int aie2_query_status(struct amdxdna_dev_hdl *ndev, char __user *buf, req.num_cols =hweight32 (aie_bitmap); req.aie_bitmap = aie_bitmap; -drm_clflush_virt_range (buff_addr, size);/* device can access */ +drm_clflush_virt_range (buff_addr, req.dump_buff_size);/* device can access */ ret =aie_send_mgmt_msg_wait (&ndev->aie, &msg);if (ret) {XDNA_ERR (xdna,"Error during NPU query, status %d" , ret);
@@ -442,7 +442,7 @@ int aie2_query_telemetry(struct amdxdna_dev_hdl *ndev, req.buf_size = buf_sz; req.type = header->type; -drm_clflush_virt_range (addr, size);/* device can access */ +drm_clflush_virt_range (addr, req.buf_size);/* device can access */ ret =aie_send_mgmt_msg_wait (&ndev->aie, &msg);if (ret) {XDNA_ERR (xdna,"Query telemetry failed, status %d" , ret);
@@ -1186,7 +1186,7 @@ int aie2_query_app_health(struct amdxdna_dev_hdl *ndev, u32 context_id, req.context_id = context_id; req.buf_size = buf_size; -drm_clflush_virt_range (buf,sizeof (*report)); +drm_clflush_virt_range (buf, req.buf_size); ret =aie_send_mgmt_msg_wait (&ndev->aie, &msg);if (ret) {XDNA_ERR (xdna,"Get app health failed, ret %d status 0x%x" , ret, resp.status);
Signature · 1 line
2.34.1
Quoted 6 lines · Lizhi Hou
The firmware is told the buffer is req.buf_size bytes. It may read/write the entire region. If the CPU only flushes a subset, the remaining cache lines could contain stale data, causing the device to see garbage.
Fixes 6e87001fe19f ("accel/amdxdna: Adjust size for copy_to_user()")Signed-off-by Lizhi Hou <[email protected]>
Quoted 35 lines
--- drivers/accel/amdxdna/aie2_message.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/accel/amdxdna/aie2_message.c +3
-3@@ -390,7 +390,7 @@ int aie2_query_status(struct amdxdna_dev_hdl *ndev, char __user *buf, req.num_cols =hweight32 (aie_bitmap); req.aie_bitmap = aie_bitmap; -drm_clflush_virt_range (buff_addr, size);/* device can access */ +drm_clflush_virt_range (buff_addr, req.dump_buff_size);/* device can access */ ret =aie_send_mgmt_msg_wait (&ndev->aie, &msg);if (ret) {XDNA_ERR (xdna,"Error during NPU query, status %d" , ret);@@ -442,7 +442,7 @@ int aie2_query_telemetry(struct amdxdna_dev_hdl *ndev, req.buf_size = buf_sz; req.type = header->type; -drm_clflush_virt_range (addr, size);/* device can access */ +drm_clflush_virt_range (addr, req.buf_size);/* device can access */ ret =aie_send_mgmt_msg_wait (&ndev->aie, &msg);if (ret) {XDNA_ERR (xdna,"Query telemetry failed, status %d" , ret);@@ -1186,7 +1186,7 @@ int aie2_query_app_health(struct amdxdna_dev_hdl *ndev, u32 context_id, req.context_id = context_id; req.buf_size = buf_size; -drm_clflush_virt_range (buf,sizeof (*report)); +drm_clflush_virt_range (buf, req.buf_size); ret =aie_send_mgmt_msg_wait (&ndev->aie, &msg);if (ret) {XDNA_ERR (xdna,"Get app health failed, ret %d status 0x%x" , ret, resp.status);
Applied to drm-misc-next
Quoted 47 lines · Mario Limonciello
Quoted 6 lines · Lizhi Hou
The firmware is told the buffer is req.buf_size bytes. It may read/write the entire region. If the CPU only flushes a subset, the remaining cache lines could contain stale data, causing the device to see garbage.
Fixes 6e87001fe19f ("accel/amdxdna: Adjust size for copy_to_user()")Signed-off-by Lizhi Hou <[email protected]>Reviewed-by Mario Limonciello (AMD) <[email protected]>Quoted 36 lines
---
drivers/accel/amdxdna/aie2_message.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/accel/amdxdna/aie2_message.c +0
-0@@ -390,7 +390,7 @@ int aie2_query_status(struct amdxdna_dev_hdl *ndev, char__user *buf, req.num_cols = hweight32(aie_bitmap); req.aie_bitmap = aie_bitmap;-
drm_clflush_virt_range(buff_addr, size); /* device can access */ +drm_clflush_virt_range(buff_addr, req.dump_buff_size); /* device can access */
ret =aie_send_mgmt_msg_wait(&ndev->aie, &msg);
if (ret) {
XDNA_ERR(xdna, "Error during NPU query, status %d", ret);drivers/accel/amdxdna/aie2_message.c +0
-0@@ -442,7 +442,7 @@ int aie2_query_telemetry(struct amdxdna_dev_hdl *ndev, req.buf_size = buf_sz; req.type = header->type;-
drm_clflush_virt_range(addr, size); /* device can access */ +drm_clflush_virt_range(addr, req.buf_size); /* device can access */ ret =aie_send_mgmt_msg_wait(&ndev->aie, &msg);
if (ret) {
XDNA_ERR(xdna, "Query telemetry failed, status %d", ret);drivers/accel/amdxdna/aie2_message.c +1
-0@@ -1186,7 +1186,7 @@ int aie2_query_app_health(struct amdxdna_dev_hdl *ndev, u32 context_id, req.context_id = context_id; req.buf_size = buf_size; - drm_clflush_virt_range(buf, sizeof(*report)); + drm_clflush_virt_range(buf, req.buf_size); ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg); if (ret) {
XDNA_ERR(xdna, "Get app health failed, ret %d status 0x%x", ret, resp.status);