← Documents Documentation/arch/powerpc/vas-api.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Virtual Accelerator Switchboard (VAS) userspace API

POWER9 VAS를 통해 userspace가 NX-GZIP window를 열고 CRB를 직접 제출하는 API입니다.

Source pathDocumentation/arch/powerpc/vas-api.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

vas-api.rst:1-305

Application은 nx-gzip device를 열고 `VAS_TX_WIN_OPEN`으로 send window를 만든 뒤 `mmap()`으로 얻은 paste address에 CRB를 COPY/PASTE합니다. Translation fault는 valid CSB이면 retry 정보로, invalid CSB이면 SIGSEGV로 전달됩니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2 .. _VAS-API:
3
4 ===================================================
5 Virtual Accelerator Switchboard (VAS) userspace API
6 ===================================================
7
8 Introduction
9 ============
10
11 Power9 processor introduced Virtual Accelerator Switchboard (VAS) which
12 allows both userspace and kernel communicate to co-processor
13 (hardware accelerator) referred to as the Nest Accelerator (NX). The NX
14 unit comprises of one or more hardware engines or co-processor types
15 such as 842 compression, GZIP compression and encryption. On power9,
16 userspace applications will have access to only GZIP Compression engine
17 which supports ZLIB and GZIP compression algorithms in the hardware.
18
19 To communicate with NX, kernel has to establish a channel or window and
20 then requests can be submitted directly without kernel involvement.
21 Requests to the GZIP engine must be formatted as a co-processor Request
22 Block (CRB) and these CRBs must be submitted to the NX using COPY/PASTE
23 instructions to paste the CRB to hardware address that is associated with
24 the engine's request queue.
25
26 The GZIP engine provides two priority levels of requests: Normal and
27 High. Only Normal requests are supported from userspace right now.
28
29 This document explains userspace API that is used to interact with
30 kernel to setup channel / window which can be used to send compression
31 requests directly to NX accelerator.
32
33
34 Overview
35 ========
36
37 Application access to the GZIP engine is provided through
38 /dev/crypto/nx-gzip device node implemented by the VAS/NX device driver.
39 An application must open the /dev/crypto/nx-gzip device to obtain a file
40 descriptor (fd). Then should issue VAS_TX_WIN_OPEN ioctl with this fd to
41 establish connection to the engine. It means send window is opened on GZIP
42 engine for this process. Once a connection is established, the application
43 should use the mmap() system call to map the hardware address of engine's
44 request queue into the application's virtual address space.
45
46 The application can then submit one or more requests to the engine by
47 using copy/paste instructions and pasting the CRBs to the virtual address
48 (aka paste_address) returned by mmap(). User space can close the
49 established connection or send window by closing the file descriptor
50 (close(fd)) or upon the process exit.
51
52 Note that applications can send several requests with the same window or
53 can establish multiple windows, but one window for each file descriptor.
54
55 Following sections provide additional details and references about the
56 individual steps.
57
58 NX-GZIP Device Node
59 ===================
60
61 There is one /dev/crypto/nx-gzip node in the system and it provides
62 access to all GZIP engines in the system. The only valid operations on
63 /dev/crypto/nx-gzip are:
64
65 * open() the device for read and write.
66 * issue VAS_TX_WIN_OPEN ioctl
67 * mmap() the engine's request queue into application's virtual
68 address space (i.e. get a paste_address for the co-processor
69 engine).
70 * close the device node.
71
72 Other file operations on this device node are undefined.
73
74 Note that the copy and paste operations go directly to the hardware and
75 do not go through this device. Refer COPY/PASTE document for more
76 details.
77
78 Although a system may have several instances of the NX co-processor
79 engines (typically, one per P9 chip) there is just one
80 /dev/crypto/nx-gzip device node in the system. When the nx-gzip device
81 node is opened, Kernel opens send window on a suitable instance of NX
82 accelerator. It finds CPU on which the user process is executing and
83 determine the NX instance for the corresponding chip on which this CPU
84 belongs.
85
86 Applications may chose a specific instance of the NX co-processor using
87 the vas_id field in the VAS_TX_WIN_OPEN ioctl as detailed below.
88
89 A userspace library libnxz is available here but still in development:
90
91 https://github.com/abalib/power-gzip
92
93 Applications that use inflate / deflate calls can link with libnxz
94 instead of libz and use NX GZIP compression without any modification.
95
96 Open /dev/crypto/nx-gzip
97 ========================
98
99 The nx-gzip device should be opened for read and write. No special
100 privileges are needed to open the device. Each window corresponds to one
101 file descriptor. So if the userspace process needs multiple windows,
102 several open calls have to be issued.
103
104 See open(2) system call man pages for other details such as return values,
105 error codes and restrictions.
106
107 VAS_TX_WIN_OPEN ioctl
108 =====================
109
110 Applications should use the VAS_TX_WIN_OPEN ioctl as follows to establish
111 a connection with NX co-processor engine:
112
113 ::
114
115 struct vas_tx_win_open_attr {
116 __u32 version;
117 __s16 vas_id; /* specific instance of vas or -1
118 for default */
119 __u16 reserved1;
120 __u64 flags; /* For future use */
121 __u64 reserved2[6];
122 };
123
124 version:
125 The version field must be currently set to 1.
126 vas_id:
127 If '-1' is passed, kernel will make a best-effort attempt
128 to assign an optimal instance of NX for the process. To
129 select the specific VAS instance, refer
130 "Discovery of available VAS engines" section below.
131
132 flags, reserved1 and reserved2[6] fields are for future extension
133 and must be set to 0.
134
135 The attributes attr for the VAS_TX_WIN_OPEN ioctl are defined as
136 follows::
137
138 #define VAS_MAGIC 'v'
139 #define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 1,
140 struct vas_tx_win_open_attr)
141
142 struct vas_tx_win_open_attr attr;
143 rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr);
144
145 The VAS_TX_WIN_OPEN ioctl returns 0 on success. On errors, it
146 returns -1 and sets the errno variable to indicate the error.
147
148 Error conditions:
149
150 ====== ================================================
151 EINVAL fd does not refer to a valid VAS device.
152 EINVAL Invalid vas ID
153 EINVAL version is not set with proper value
154 EEXIST Window is already opened for the given fd
155 ENOMEM Memory is not available to allocate window
156 ENOSPC System has too many active windows (connections)
157 opened
158 EINVAL reserved fields are not set to 0.
159 ====== ================================================
160
161 See the ioctl(2) man page for more details, error codes and
162 restrictions.
163
164 mmap() NX-GZIP device
165 =====================
166
167 The mmap() system call for a NX-GZIP device fd returns a paste_address
168 that the application can use to copy/paste its CRB to the hardware engines.
169
170 ::
171
172 paste_addr = mmap(addr, size, prot, flags, fd, offset);
173
174 Only restrictions on mmap for a NX-GZIP device fd are:
175
176 * size should be PAGE_SIZE
177 * offset parameter should be 0ULL
178
179 Refer to mmap(2) man page for additional details/restrictions.
180 In addition to the error conditions listed on the mmap(2) man
181 page, can also fail with one of the following error codes:
182
183 ====== =============================================
184 EINVAL fd is not associated with an open window
185 (i.e mmap() does not follow a successful call
186 to the VAS_TX_WIN_OPEN ioctl).
187 EINVAL offset field is not 0ULL.
188 ====== =============================================
189
190 Discovery of available VAS engines
191 ==================================
192
193 Each available VAS instance in the system will have a device tree node
194 like /proc/device-tree/vas@* or /proc/device-tree/xscom@*/vas@*.
195 Determine the chip or VAS instance and use the corresponding ibm,vas-id
196 property value in this node to select specific VAS instance.
197
198 Copy/Paste operations
199 =====================
200
201 Applications should use the copy and paste instructions to send CRB to NX.
202 Refer section 4.4 in PowerISA for Copy/Paste instructions:
203 https://openpowerfoundation.org/?resource_lib=power-isa-version-3-0
204
205 CRB Specification and use NX
206 ============================
207
208 Applications should format requests to the co-processor using the
209 co-processor Request Block (CRBs). Refer NX-GZIP user's manual for the format
210 of CRB and use NX from userspace such as sending requests and checking
211 request status.
212
213 NX Fault handling
214 =================
215
216 Applications send requests to NX and wait for the status by polling on
217 co-processor Status Block (CSB) flags. NX updates status in CSB after each
218 request is processed. Refer NX-GZIP user's manual for the format of CSB and
219 status flags.
220
221 In case if NX encounters translation error (called NX page fault) on CSB
222 address or any request buffer, raises an interrupt on the CPU to handle the
223 fault. Page fault can happen if an application passes invalid addresses or
224 request buffers are not in memory. The operating system handles the fault by
225 updating CSB with the following data::
226
227 csb.flags = CSB_V;
228 csb.cc = CSB_CC_FAULT_ADDRESS;
229 csb.ce = CSB_CE_TERMINATION;
230 csb.address = fault_address;
231
232 When an application receives translation error, it can touch or access
233 the page that has a fault address so that this page will be in memory. Then
234 the application can resend this request to NX.
235
236 If the OS can not update CSB due to invalid CSB address, sends SEGV signal
237 to the process who opened the send window on which the original request was
238 issued. This signal returns with the following siginfo struct::
239
240 siginfo.si_signo = SIGSEGV;
241 siginfo.si_errno = EFAULT;
242 siginfo.si_code = SEGV_MAPERR;
243 siginfo.si_addr = CSB address;
244
245 In the case of multi-thread applications, NX send windows can be shared
246 across all threads. For example, a child thread can open a send window,
247 but other threads can send requests to NX using this window. These
248 requests will be successful even in the case of OS handling faults as long
249 as CSB address is valid. If the NX request contains an invalid CSB address,
250 the signal will be sent to the child thread that opened the window. But if
251 the thread is exited without closing the window and the request is issued
252 using this window. the signal will be issued to the thread group leader
253 (tgid). It is up to the application whether to ignore or handle these
254 signals.
255
256 NX-GZIP User's Manual:
257 https://github.com/libnxz/power-gzip/blob/master/doc/power_nx_gzip_um.pdf
258
259 Simple example
260 ==============
261
262 ::
263
264 int use_nx_gzip()
265 {
266 int rc, fd;
267 void *addr;
268 struct vas_setup_attr txattr;
269
270 fd = open("/dev/crypto/nx-gzip", O_RDWR);
271 if (fd < 0) {
272 fprintf(stderr, "open nx-gzip failed\n");
273 return -1;
274 }
275 memset(&txattr, 0, sizeof(txattr));
276 txattr.version = 1;
277 txattr.vas_id = -1
278 rc = ioctl(fd, VAS_TX_WIN_OPEN,
279 (unsigned long)&txattr);
280 if (rc < 0) {
281 fprintf(stderr, "ioctl() n %d, error %d\n",
282 rc, errno);
283 return rc;
284 }
285 addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE,
286 MAP_SHARED, fd, 0ULL);
287 if (addr == MAP_FAILED) {
288 fprintf(stderr, "mmap() failed, errno %d\n",
289 errno);
290 return -errno;
291 }
292 do {
293 //Format CRB request with compression or
294 //uncompression
295 // Refer tests for vas_copy/vas_paste
296 vas_copy((&crb, 0, 1);
297 vas_paste(addr, 0, 1);
298 // Poll on csb.flags with timeout
299 // csb address is listed in CRB
300 } while (true)
301 close(fd) or window can be closed upon process exit
302 }
303
304 Refer https://github.com/libnxz/power-gzip for tests or more
305 use cases.
306

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Virtual Accelerator Switchboard userspace API

1-7

이 문서는 POWER9 Virtual Accelerator Switchboard(VAS)를 통해 userspace가 NX GZIP hardware accelerator에 직접 request를 보내는 API를 설명합니다.

VAS와 NX 소개

8-33

POWER9의 VAS는 userspace와 kernel이 Nest Accelerator(NX) co-processor와 통신하도록 합니다. NX에는 842 compression, GZIP compression, encryption 같은 하나 이상의 hardware engine이 있습니다.

POWER9 userspace application은 현재 ZLIB 및 GZIP algorithm을 hardware로 처리하는 GZIP Compression engine만 사용할 수 있습니다.

Kernel은 NX와의 channel 또는 window를 먼저 설정합니다. 이후 request는 kernel 개입 없이 직접 제출할 수 있습니다. GZIP request는 co-processor Request Block(CRB) 형식이어야 하며 `COPY`/`PASTE` instruction으로 engine request queue에 대응하는 hardware address에 paste합니다.

GZIP engine은 Normal과 High 두 priority를 제공하지만 현재 userspace에서는 Normal request만 지원합니다.

이 API는 compression request를 NX accelerator에 직접 보낼 channel/window를 kernel과 설정하는 절차를 정의합니다.

Userspace 연결 lifecycle

34-57

Application은 VAS/NX driver가 제공하는 `/dev/crypto/nx-gzip`을 open해 file descriptor를 얻고, 그 fd로 `VAS_TX_WIN_OPEN` ioctl을 실행하여 process용 GZIP send window를 엽니다.

연결 뒤 `mmap()`으로 engine request queue의 hardware address를 application virtual address space에 mapping합니다. 반환된 `paste_address`에 CRB를 copy/paste하여 여러 request를 보냅니다.

`close(fd)` 또는 process exit로 window를 닫습니다. 같은 window로 여러 request를 보낼 수 있고 여러 window도 만들 수 있지만 file descriptor 하나에는 window 하나만 대응합니다.

NX-GZIP userspace lifecycle
`open(/dev/crypto/nx-gzip)``VAS_TX_WIN_OPEN``mmap()``paste_address``COPY`/`PASTE` CRB`close(fd)`

Device open부터 direct COPY/PASTE request와 window close까지의 순서입니다.

NX-GZIP device node

58-95

System에는 `/dev/crypto/nx-gzip` node가 하나만 있으며 모든 GZIP engine에 접근합니다. Valid operation은 다음뿐이고 다른 file operation은 undefined입니다.

Operation역할
`open()`Device를 read/write로 열어 window별 file descriptor 생성
`VAS_TX_WIN_OPEN`NX GZIP send window 연결
`mmap()`Engine request queue의 `paste_address` mapping
`close()`Send window와 device descriptor 종료

COPY/PASTE는 device node를 거치지 않고 hardware로 직접 갑니다. 세부 instruction은 COPY/PASTE 문서를 따라야 합니다.

P9 chip마다 NX instance가 있을 수 있지만 node는 하나입니다. Device open 시 kernel은 user process가 실행 중인 CPU와 그 CPU가 속한 chip을 확인해 적합한 NX instance에 send window를 엽니다. Application은 `VAS_TX_WIN_OPEN`의 `vas_id`로 특정 instance를 선택할 수도 있습니다.

개발 중인 `libnxz` userspace library를 사용하면 `inflate`/`deflate` application이 `libz` 대신 link하여 source 수정 없이 NX GZIP compression을 사용할 수 있습니다.

Single device node와 NX instance 선택
`/dev/crypto/nx-gzip`Current CPU/chipOptimal NX instanceSend window
Explicit `vas_id`Specific VAS/NX instance

하나의 device node가 process CPU의 chip 또는 명시한 vas_id에 따라 NX instance를 선택합니다.

Device open

96-106

NX-GZIP device는 read/write로 open하며 특별한 privilege가 필요하지 않습니다. Window 하나가 fd 하나에 대응하므로 여러 window가 필요하면 여러 번 open해야 합니다.

Return value, error code와 restriction의 일반 사항은 `open(2)` man page를 따릅니다.

VAS_TX_WIN_OPEN ioctl

107-163

NX co-processor engine과 connection을 만들기 위해 다음 attribute structure와 ioctl을 사용합니다.

struct vas_tx_win_open_attr {
        __u32   version;
        __s16   vas_id; /* specific instance of vas or -1
                                for default */
        __u16   reserved1;
        __u64   flags;        /* For future use */
        __u64   reserved2[6];
};
Field규칙
`version`현재 반드시 `1`
`vas_id``-1`이면 kernel이 optimal NX instance를 best-effort 선택
`reserved1`Future extension용, `0`
`flags`Future use, `0`
`reserved2[6]`Future extension용, 모두 `0`

`vas_id=-1`이면 kernel이 process에 optimal한 NX instance를 best-effort로 배정합니다. 특정 VAS 선택에는 아래 discovery 절차의 `ibm,vas-id` 값을 사용합니다.

#define VAS_MAGIC 'v'
#define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 1,
                                struct vas_tx_win_open_attr)

struct vas_tx_win_open_attr attr;
rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr);

`VAS_TX_WIN_OPEN`은 성공 시 0, 실패 시 -1을 반환하고 `errno`를 설정합니다.

errno조건
`EINVAL``fd`가 valid VAS device가 아님
`EINVAL`Invalid VAS ID
`EINVAL``version` 값이 올바르지 않음
`EEXIST`해당 `fd`에 window가 이미 열림
`ENOMEM`Window 할당 memory 부족
`ENOSPC`System active window 수가 너무 많음
`EINVAL`Reserved field가 0이 아님

추가 ioctl 제약은 `ioctl(2)` man page를 따릅니다.

NX-GZIP mmap

164-189

NX-GZIP fd의 `mmap()`은 CRB를 hardware engine에 copy/paste할 `paste_address`를 반환합니다.

paste_addr = mmap(addr, size, prot, flags, fd, offset);
ParameterRestriction
`size``PAGE_SIZE`
`offset``0ULL`

일반 `mmap(2)` error 외에 다음 NX-GZIP-specific `EINVAL` 조건이 있습니다.

errno조건
`EINVAL``fd`가 open window와 연결되지 않음
`EINVAL``offset`이 `0ULL`이 아님

사용 가능한 VAS engine discovery

190-197

각 VAS instance에는 `/proc/device-tree/vas@*` 또는 `/proc/device-tree/xscom@*/vas@*` 형태의 device-tree node가 있습니다. Chip/VAS instance를 찾고 node의 `ibm,vas-id` property를 `vas_id`에 사용합니다.

COPY/PASTE operation

198-204

Application은 COPY와 PASTE instruction으로 CRB를 NX에 보냅니다. 자세한 instruction은 PowerISA section 4.4를 참고합니다.

CRB specification

205-212

Co-processor request는 CRB 형식으로 작성해야 합니다. CRB format, userspace request 제출과 status 확인은 NX-GZIP user's manual을 따릅니다.

NX fault handling

213-258

Application은 NX request를 보내고 co-processor Status Block(CSB) flag를 polling합니다. NX는 request 처리 뒤 CSB status를 update합니다.

CSB address나 request buffer에서 translation error, 즉 NX page fault가 발생하면 NX가 CPU interrupt를 올립니다. Invalid address를 전달했거나 request buffer가 memory에 없을 때 발생할 수 있습니다.

OS가 CSB에 기록하는 fault data는 다음과 같습니다.

csb.flags = CSB_V;
csb.cc = CSB_CC_FAULT_ADDRESS;
csb.ce = CSB_CE_TERMINATION;
csb.address = fault_address;

Application이 translation error를 받으면 fault address page를 touch하여 memory에 올린 뒤 request를 NX에 다시 제출할 수 있습니다.

Invalid CSB address 때문에 OS가 CSB를 update할 수 없으면 send window를 연 process에 `SIGSEGV`를 보냅니다.

siginfo.si_signo = SIGSEGV;
siginfo.si_errno = EFAULT;
siginfo.si_code = SEGV_MAPERR;
siginfo.si_addr = CSB address;
상태OS 처리
CSB address validOS가 CSB에 `CSB_CC_FAULT_ADDRESS`, `CSB_CE_TERMINATION`, fault address 기록
CSB address invalidWindow를 연 thread 또는 그 thread가 종료된 경우 thread-group leader에 `SIGSEGV`

Multithread application에서는 NX send window를 모든 thread가 share할 수 있습니다. CSB address가 valid하면 다른 thread의 request도 OS fault handling과 함께 성공합니다.

Invalid CSB request의 signal은 window를 연 child thread로 갑니다. 그 thread가 window를 닫지 않고 exit한 뒤 request가 발행되면 thread-group leader(`tgid`)에게 signal을 보냅니다. Signal을 무시하거나 처리할지는 application 책임입니다.

NX page-fault recovery
NX translation errorCSB validOS writes fault statusPage touchResubmit CRB
NX translation errorCSB invalid`SIGSEGV`Window owner or TGID

CSB validity에 따라 retry 가능한 status update 또는 SIGSEGV delivery로 나뉩니다.

Simple example

259-305

다음 원문 예제는 device open, attribute 초기화, ioctl, mmap, CRB copy/paste, CSB polling과 close의 전체 흐름을 보여 줍니다.

int use_nx_gzip()
{
        int rc, fd;
        void *addr;
        struct vas_setup_attr txattr;

        fd = open("/dev/crypto/nx-gzip", O_RDWR);
        if (fd < 0) {
                fprintf(stderr, "open nx-gzip failed\n");
                return -1;
        }
        memset(&txattr, 0, sizeof(txattr));
        txattr.version = 1;
        txattr.vas_id = -1
        rc = ioctl(fd, VAS_TX_WIN_OPEN,
                        (unsigned long)&txattr);
        if (rc < 0) {
                fprintf(stderr, "ioctl() n %d, error %d\n",
                                rc, errno);
                return rc;
        }
        addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE,
                        MAP_SHARED, fd, 0ULL);
        if (addr == MAP_FAILED) {
                fprintf(stderr, "mmap() failed, errno %d\n",
                                errno);
                return -errno;
        }
        do {
                //Format CRB request with compression or
                //uncompression
                // Refer tests for vas_copy/vas_paste
                vas_copy((&crb, 0, 1);
                vas_paste(addr, 0, 1);
                // Poll on csb.flags with timeout
                // csb address is listed in CRB
        } while (true)
        close(fd) or window can be closed upon process exit
}

예제의 type name, 괄호와 세미콜론 표기는 원문 그대로 보존했습니다. 실제 build에는 현재 UAPI header와 library helper prototype에 맞춘 수정이 필요할 수 있습니다.