Commit 66542c3b authored by Omer Shpigelman's avatar Omer Shpigelman Committed by Oded Gabbay
Browse files

habanalabs: add MMU shadow mapping



This patch adds shadow mapping to the MMU module. The shadow mapping
allows traversing the page table in host memory rather reading each PTE
from the device memory.
It brings better performance and avoids reading from invalid device
address upon PCI errors.
Only at the end of map/unmap flow, writings to the device are performed in
order to sync the H/W page tables with the shadow ones.

Signed-off-by: default avatarOmer Shpigelman <oshpigelman@habana.ai>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent d75bcf3e
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -51,8 +51,9 @@

/**
 * struct pgt_info - MMU hop page info.
 * @node: hash linked-list node for the pgts hash of pgts.
 * @addr: physical address of the pgt.
 * @node: hash linked-list node for the pgts shadow hash of pgts.
 * @phys_addr: physical address of the pgt.
 * @shadow_addr: shadow hop in the host.
 * @ctx: pointer to the owner ctx.
 * @num_of_ptes: indicates how many ptes are used in the pgt.
 *
@@ -63,7 +64,8 @@
 */
struct pgt_info {
	struct hlist_node	node;
	u64 addr;
	u64			phys_addr;
	u64			shadow_addr;
	struct hl_ctx		*ctx;
	int			num_of_ptes;
};
@@ -595,7 +597,8 @@ struct hl_va_range {
 * struct hl_ctx - user/kernel context.
 * @mem_hash: holds mapping from virtual address to virtual memory area
 *		descriptor (hl_vm_phys_pg_list or hl_userptr).
 * @mmu_hash: holds a mapping from virtual address to pgt_info structure.
 * @mmu_phys_hash: holds a mapping from physical address to pgt_info structure.
 * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.
 * @hpriv: pointer to the private (KMD) data of the process (fd).
 * @hdev: pointer to the device structure.
 * @refcount: reference counter for the context. Context is released only when
@@ -624,7 +627,8 @@ struct hl_va_range {
 */
struct hl_ctx {
	DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
	DECLARE_HASHTABLE(mmu_hash, MMU_HASH_TABLE_BITS);
	DECLARE_HASHTABLE(mmu_phys_hash, MMU_HASH_TABLE_BITS);
	DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
	struct hl_fpriv		*hpriv;
	struct hl_device	*hdev;
	struct kref		refcount;
@@ -1066,7 +1070,8 @@ struct hl_device_reset_work {
 * @asic_specific: ASIC specific information to use only from ASIC files.
 * @mmu_pgt_pool: pool of available MMU hops.
 * @vm: virtual memory manager for MMU.
 * @mmu_cache_lock: protects MMU cache invalidation as it can serve one context
 * @mmu_cache_lock: protects MMU cache invalidation as it can serve one context.
 * @mmu_shadow_hop0: shadow mapping of the MMU hop 0 zone.
 * @hwmon_dev: H/W monitor device.
 * @pm_mng_profile: current power management profile.
 * @hl_chip_info: ASIC's sensors information.
@@ -1136,6 +1141,7 @@ struct hl_device {
	struct gen_pool			*mmu_pgt_pool;
	struct hl_vm			vm;
	struct mutex			mmu_cache_lock;
	void				*mmu_shadow_hop0;
	struct device			*hwmon_dev;
	enum hl_pm_mng_profile		pm_mng_profile;
	struct hwmon_chip_info		*hl_chip_info;
+8 −8
Original line number Diff line number Diff line
@@ -14,16 +14,16 @@
#define PAGE_SIZE_4KB			(_AC(1, UL) << PAGE_SHIFT_4KB)
#define PAGE_MASK_2MB			(~(PAGE_SIZE_2MB - 1))

#define PAGE_PRESENT_MASK		0x0000000000001
#define SWAP_OUT_MASK			0x0000000000004
#define LAST_MASK			0x0000000000800
#define PHYS_ADDR_MASK			0x3FFFFFFFFF000ull
#define PAGE_PRESENT_MASK		0x0000000000001ull
#define SWAP_OUT_MASK			0x0000000000004ull
#define LAST_MASK			0x0000000000800ull
#define PHYS_ADDR_MASK			0xFFFFFFFFFFFFF000ull
#define HOP0_MASK			0x3000000000000ull
#define HOP1_MASK			0x0FF8000000000ull
#define HOP2_MASK			0x0007FC0000000ull
#define HOP3_MASK			0x000003FE00000
#define HOP4_MASK			0x00000001FF000
#define OFFSET_MASK			0x0000000000FFF
#define HOP3_MASK			0x000003FE00000ull
#define HOP4_MASK			0x00000001FF000ull
#define OFFSET_MASK			0x0000000000FFFull

#define HOP0_SHIFT			48
#define HOP1_SHIFT			39
@@ -32,7 +32,7 @@
#define HOP4_SHIFT			12

#define PTE_PHYS_ADDR_SHIFT		12
#define PTE_PHYS_ADDR_MASK		~0xFFF
#define PTE_PHYS_ADDR_MASK		~OFFSET_MASK

#define HL_PTE_SIZE			sizeof(u64)
#define HOP_TABLE_SIZE			PAGE_SIZE_4KB
+333 −267

File changed.

Preview size limit exceeded, changes collapsed.