share virtual address...huawei technologies co., ltd. share virtual address yisheng xie/...

17
HUAWEI TECHNOLOGIES CO., LTD. www.huawei.com Share Virtual Address Yisheng Xie/ [email protected] Bob Liu / [email protected]

Upload: others

Post on 20-Jan-2021

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

HUAWEI TECHNOLOGIES CO., LTD.

www.huawei.com

Share Virtual Address

Yisheng Xie/ [email protected]

Bob Liu / [email protected]

Page 2: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 2

Agenda

What is SVA?

Why SVA ?

How SVA works?

Our works

Upstream status

Page 3: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 3

What is SVA?(cont.)

SVA (Share Virtual Address) means device use the same virtual address with

CPU which get the same thing. But they may have different achievement in HW

and SW.

DMAR (IOMMU, SMMU) or MMU

Use the same page table or not

Same physical address or not

Support zero copy or not

Support IO-Page Fault or not

Page 4: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 4

What is SVA?

Intel - SVM (Share Virtual Memory) :

CPU access DDR through MMU

Device access DDR through IOMMU

MMU share the same page table with IOMMU

(used by AMD’s Secure Virtual Machine in Linux)

PASID

ATC

Device

VA

CPU

VA

MMUIOMMU

(Vt-d)

PageTable

ATS

DDR PCIe

B

U

S

Page 5: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 5

What is SVA?(cont.)

Nvidia – UVA(Unify Virtual address): GPU has its own MMU

CPU can only access DDR while GPU can only access HBM

GPU MMU mirror the Page Table of CPU

When GPU access a VA not populated in HBM it will copy the data from DDR ,

and vice versa.

GPU

VA

X86 CPU

VA

MMU GPU-MMU

PageTable

DDR HBMPCIe

B

U

S

B

U

S PageTable

Copy

HBM

Page 6: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 6

What is SVA?(cont.)

PASID

ATC

Device

VA1 VA2

CPU

VA2VA1

MMU SMMU

PageTable

ATS

DDR DDRcache coherent bus

B

U

S

ARM – SVA(share virtual address space) :

Use SMMU instead of IOMMU

Device may also has DDR memory

With the help of CCIX, both CPU and Device can access

DDR and HBM in Cache Coherent way

(Device memory management is another story)

Page 7: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 7

Why SVA?

Simplify user program

Share objects is hard to achieve for complex data-set

(list, tree, ...)

Zero-copy is easier to achieve (device can access DDR

with cc)

CPUGPU/FPGA/

ASIC/Accel

erator

Sw

Thread

CPUGPU/FPGA/

ASIC/Accel

erator

Dev

Thread

Sw

Thread

Dev

Thread

0x00000000 --------------------------------- 0xFFFFFFFF

datanext0x0002

0x0001

datanext0x0003

0x0002

datanext0x1001

0x1000

datanextNULL

0x1001

0x00000000 --------------------------------- 0xFFFFFFFF

datanext0xE002

0xE001

datanext0xE003

0xE002

datanext0xF001

0xF000

datanextNULL

0xF001

0x00000000 --------------------------------- 0xFFFFFFFF

datanext0x0002

0x0001

datanext0x0003

0x0002

datanext0x1001

0x1000

datanextNULL

0x1001

Page 8: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 8

Why SVA? (cont.)

1. Malloc() buffer, syscall or ioctl to kernel 2. Kmalloc() buffer request device initial dma3. Device DMAs to/from kernel buffer4. Kernel copies to user buffer Device DMA to user buffer(pin….)

Process address space

User Buffer

DeviceKernel

Kernel

Buffer

1. Malloc() buffer, syscall or ioctl to kernel 2. Request device to initiate DMA3. Device DMA access process address directly. It

trigger interrupt to CPU when access non-populated Virtual Address.

Device side on-demand paging(based on IO page fault)

Pros:

No need to pin memory – decrease pin memory overhead

Allow memory overcommit – usefully for low-end production

Cons:

Performance overhead of page fault for high speed device

Process address space

User Buffer

KernelKernel

Buffer

Device

1

2

3

4

2

1

3

Page 9: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 9

arm_smmu_cd

- pasid

- miar

- tcr

- asid

- ttbr

How SVA works?

ARM/SMMUv3: Bind a mm to device to share page table

arm_smmu_mm: address space abstraction in smmu

arm_smmu_cd: smmu context descriptor instant

When task is bound to device, its values are got from task

PageTable

STE

StreamID

SMMU_(S)_STRTAB_BASE

ConfigureASID

MIARTTB

SubstreamID/PASID

Context Descriptor (CD)

Context Descriptor Table

Stream Table

write to

write to

write to

write to

Device

bind SMMU

MMU

MIAR

TCR

ASID

TTBR

MMU configure registers

write to

write to

write to

write to

arm_smmu_mm

- *cd

Page 10: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 10

How SVA works ? (cont.)

ARM/IO Pagefault: PRI Queue vs Event Queue

PCI devices use PRI Queue/PASID

Platform devices use Event Queue/SSID (Stall-mode )

Page 11: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 11

- *pgtbl_ops

arm_smmu_cd

- pasid

- miar

- tcr

- asid

- ttb

arm_smmu_mm

- *cd

Our Works SVA in private mode

The main works add SVA support for device which do not support fault, for our device

do not support IO page fault(pri)

Device driver need pin the memory used by device

No fault mode: device use the same page table with process.

Private mode: device use a different page table which named io-pageable.

PageTable

STE

StreamID

SMMU_(S)_STRTAB_BASE

ConfigureASID

MIARTTB

SubstreamID/PASID

Context Descriptor (CD)

Context Descriptor Table

Stream Table

write to

write to

write to

write to

Device

bind - private SMMU

MMU

MIAR

TCR

ASID

TTB

MMU configure registers

PageTableVA

DDR

VA

CPU

mmap sva_mapPA

allocate

Page 12: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 12

User Space Kernel Space

USER libwrapdrive MM VFIOIOMMU/

SMMU

malloc/mmap

Prepare date

1. Get the io-pagetable by PASID2. map Vaddr to PA at io- pagetable

Our Works (cont.)

wd_request_queue()ioctl(fd, VFIO_BIND_MM, <pid>)

driver

iommu_sva_bind(mm, device)

alloc pgtlbops and use it to alloc io pgtable

PASID

drv_set_pasid(fd, PASID)

set the PASID to device register

Vaddr

wd_mem_share(Vaddr)

⑤wd_send(Vaddr) drv_send(Vaddr)

⑥wd_recv(Vaddr)

...

page fault:alloc PA and map Vaddr to PA

ioctl(fd, VFIO_IOMMU_MAP_DMA,<Vaddr, PASID>)

Pin memoy and get the PA

sva_map( PASID, Vaddr, PA)

Trigger device start dma

Wait dma over and return data

SVA for WrapDrive

PASID is used for multi-queue under multi-process.

http://connect.linaro.org/resource/sfo17/sfo17-317/

Page 13: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 13

Our Works (cont.)

A SVA implement case:

M-COREs and Super COREs in on-chip device

S-COREs use SMMUv3 whichs works in stall mode

M-COREs use MMU instead

PASID

Accelerator

CPU

VAVA VA

Task

schedulerMMU SMMUv3

PageTable

DDR

MMU

M-CORE S-CORE

tcr, ttb, asid

Page 14: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 14

User Space Kernel Space Hardware/ Accelerator

USER MM SVA DriverIOMMU/SMMU

Driver

Task

SchedulerS-CORE M-CORE

malloc/mmap

Vaddr

Prepare date

page fault:alloc PA and map Vaddr to PA

ioctrl(fd, <pid>, TASK_BIND….)

1. Get task’s mm from pid2. Alloc sva_mm to tack the mm3. Get ASID from task’s mm4. Get pgd(TTB) from task’s mm5. Get TCR from system reg

PASID; (ASID, TTB, TCR)

iommu_sva_bind(mm, device)

PASID

ioctrl (fd, OFFLOAD_TASK, <Vaddr, PASID, ASID,TTB, TCR>)

④case 1: dispatch to Super COREwith Vaddr, PASID

1. get mm from PASID2. handle_mm_fault(mm, Vaddr)

IO page fault from Super CORE:Vaddr, PASID

case 2: dispatch to Normal COREwith Vaddr, ASID, TTB, TCR

IO page fault from Normal CORE:Vaddr, ASID

1. Get mm ASID2. handle_mm_fault(mm, Vaddr)

free/munmap (Vaddr)⑤

Our Works (cont.)

reply ok

reply ok

Page 15: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 15

Upstream status

SVA for SMMUv3

RFC1: [RFC PATCH 00/30] Add PCIe SVM support to ARM SMMUv3

Only works for PCIE pri

RFC2: [RFCv2 PATCH 00/36] Process management for IOMMU + SVM

for SMMUv3

Add support of stall mode for platform device

V1/V2: [PATCH v2 00/40] Shared Virtual Addressing for the

IOMMU

Only support devices which have IO-Page Fault ability.

Our works is in upstream plan, which will be coming soon...

Page 16: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

Thank you

Page 17: Share Virtual Address...HUAWEI TECHNOLOGIES CO., LTD. Share Virtual Address Yisheng Xie/ xieyisheng1@hauwei.com Bob Liu / liubo95@Huawei.com page 3 What is SVA?(cont.) SVA (Share Virtual

page 17

Huawei OS Kernel Lab

Huawei Operating System R&D Department- OS Kernel Lab Linux Kernel (ARM/x86/ heterogeneous platforms) R&D and Innovation R&D on a Next-generation OS kernel with Low Latency, High Security, Strong Reliability,

Intelligence, etc.

Job Vacancy Next-generation Operating System Researcher and Senior Engineer

Formal Verification Researcher and Senior Engineer

Linux Kernel Architect and Senior Engineer

Locations

Hangzhou, Beijing, Shanghai

Contact us

Tel: Mr. Wang/18658102676

Email:[email protected]