xmattach Kernel Service

Purpose

Attaches to a user buffer for cross-memory operations.

Syntax

#include <sys/types.h>
#include <sys/errno.h>
#include <sys/xmem.h>

int xmattach (addr, count, dp, segflag)
char * addr;
int count;
struct xmem * dp;
int segflag;

Parameters

Item Description
addr Specifies the address of the user buffer to be accessed in a cross-memory operation.
count Indicates the size of the user buffer to be accessed in a cross-memory operation.
dp Specifies a cross-memory descriptor. The dp->aspace_id variable must be set to a value of XMEM_INVAL.
segflag Specifies a segment flag. This flag is used to determine the address space of the memory that the cross-memory descriptor applies to, as well as for other purposes. The valid values for this flag can be found in the /usr/include/xmem.h file.

Description

The xmattach kernel service prepares the user buffer so that a device driver can access it without executing under the process that requested the I/O operation. A device top-half routine calls the xmattach kernel service. The xmattach kernel service allows a kernel process or device bottom-half routine to access the user buffer with the xmemin or xmemout kernel services. The device driver must use the xmdetach kernel service to inform the kernel when it has finished accessing the user buffer.

The kernel remembers which segments are attached for cross-memory operations. Resources associated with these segments cannot be freed until all cross-memory descriptors have been detached. "Cross Memory Kernel Services" in Memory Kernel Services in in AIX® Version 7.1 Kernel Extensions and Device Support Programming Concepts describes how the cross-memory kernel services use cross-memory descriptors.

Note: When the xmattach kernel service remaps user memory containing the cross-memory buffer, the effects are machine-dependent. Also, cross-memory descriptors are not inherited by a child process.

Storage-key protection can be enforced on memory regions described by a cross-memory descriptor. The enforcement is done during normal access checking performed by cross-memory services, such as the xmemdma kernel service. A kernel keyset can be contained in the cross-memory descriptor to limit memory accessibility. When a keyset is associated with a cross-memory descriptor, access to the memory region is limited by that keyset. A keyset is required because a cross-memory descriptor can describe a virtual memory region with multiple keys assigned to the pages it contains. Normally, a keyset describes the accessibility of the context that the attach was initiated for. For example, a cross-memory attached to user-space contains a description of the user-mode accessibility (keyset). Adding keysets to kernel cross-memory descriptors can also enhance system RAS, since they limit kernel access by the cross-memory descriptor. Typically it is limited to that of the xmattach caller or to specific key(s), to catch cases where a cross-memory descriptor is misused.

User-mode storage-keys are always associated with descriptors attached using USER_SPACE or USERI_SPACE segflag. These flags were always required to attach to the user address space, so no explicit update is required to enable storage-key protection on user memory attaches. Once attached, existing kernel services that require cross-memory descriptors enforce the user keyset saved at attach time when performing memory accesses or checking user accessibility.

For kernel memory, a keyset is not used to restrict regions attached with SYS_ADSPACE. Attaching a region with SYS_ADSPACE_ASSIGN_KEYSET associates the caller’s keyset with the cross-memory region.

Execution Environment

The xmattach kernel service can be called from the process environment only.

Return Values

Item Description
XMEM_SUCC Indicates a successful operation.
XMEM_FAIL Indicates one of the following errors:
  • The buffer size indicated by the count parameter is less than or equal to 0.
  • The cross-memory descriptor is in use (dp->aspace_id != XMEM_INVAL).
  • The area of memory indicated by the addr and count parameters is not defined.