Skip to content

Commit

Permalink
Add flag to change caching attribute when pinning
Browse files Browse the repository at this point in the history
* This only works on X86.
* This is for experimental purposes only.
  • Loading branch information
joelsmithTT committed Jan 29, 2025
1 parent e8e660e commit 154ab2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ struct tenstorrent_reset_device {

// tenstorrent_pin_pages_in.flags
#define TENSTORRENT_PIN_PAGES_CONTIGUOUS 1 // app attests that the pages are physically contiguous
#define TENSTORRENT_PIN_PAGES_WC 2
#define TENSTORRENT_PIN_PAGES_UC 4

struct tenstorrent_pin_pages_in {
__u32 output_size_bytes;
Expand Down
22 changes: 20 additions & 2 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <linux/file.h>
#include <linux/vmalloc.h>

#if CONFIG_X86
#include <asm/set_memory.h>
#endif

#include "chardev_private.h"
#include "device.h"
#include "memory.h"
Expand Down Expand Up @@ -397,8 +401,8 @@ long ioctl_pin_pages(struct chardev_private *priv,
if (!is_pin_pages_size_safe(in.size))
return -EINVAL;

if (in.flags != 0 && in.flags != TENSTORRENT_PIN_PAGES_CONTIGUOUS)
return -EINVAL;
// if (in.flags != 0 && in.flags != TENSTORRENT_PIN_PAGES_CONTIGUOUS)
// return -EINVAL;

pinning = kmalloc(sizeof(*pinning), GFP_KERNEL);
if (!pinning)
Expand Down Expand Up @@ -490,6 +494,20 @@ long ioctl_pin_pages(struct chardev_private *priv,
pinning->virtual_address = in.virtual_address;

list_add(&pinning->list, &priv->pinnings);

#if CONFIG_X86
set_pages_array_wb(pages, nr_pages);
if (in.flags & TENSTORRENT_PIN_PAGES_WC) {
int r = set_pages_array_wc(pages, nr_pages);
if (r != 0)
pr_warn("set_pages_array_wc failed: %d (%lu pages)\n", r, nr_pages);
} else if (in.flags & TENSTORRENT_PIN_PAGES_UC) {
int r = set_pages_array_uc(pages, nr_pages);
if (r != 0)
pr_warn("set_pages_array_uc failed: %d (%lu pages)\n", r, nr_pages);
}
#endif

mutex_unlock(&priv->mutex);

if (clear_user(&arg->out, in.output_size_bytes) != 0)
Expand Down

0 comments on commit 154ab2b

Please sign in to comment.