1993-06-12 14:49:13 +00:00
|
|
|
.\" Copyright (c) 1991 The Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
2014-03-14 03:07:51 +00:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1993-06-12 14:49:13 +00:00
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)mem.4 5.3 (Berkeley) 5/2/91
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1993-06-12 14:49:13 +00:00
|
|
|
.\"
|
2020-09-02 18:12:47 +00:00
|
|
|
.Dd August 25, 2020
|
1999-11-15 23:14:32 +00:00
|
|
|
.Dt MEM 4
|
1993-06-12 14:49:13 +00:00
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm mem ,
|
|
|
|
.Nm kmem
|
|
|
|
.Nd memory files
|
2004-10-03 13:14:20 +00:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Cd "device mem"
|
1993-06-12 14:49:13 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The special file
|
2003-06-28 23:53:39 +00:00
|
|
|
.Pa /dev/mem
|
1993-06-12 14:49:13 +00:00
|
|
|
is an interface to the physical memory of the computer.
|
|
|
|
Byte offsets in this file are interpreted as physical memory addresses.
|
|
|
|
Reading and writing this file is equivalent to reading and writing
|
|
|
|
memory itself.
|
|
|
|
Only offsets within the bounds of
|
2003-06-28 23:53:39 +00:00
|
|
|
.Pa /dev/mem
|
1993-06-12 14:49:13 +00:00
|
|
|
are allowed.
|
|
|
|
.Pp
|
|
|
|
Kernel virtual memory is accessed through the interface
|
2003-06-28 23:53:39 +00:00
|
|
|
.Pa /dev/kmem
|
1993-06-12 14:49:13 +00:00
|
|
|
in the same manner as
|
2003-06-28 23:53:39 +00:00
|
|
|
.Pa /dev/mem .
|
1993-06-12 14:49:13 +00:00
|
|
|
Only kernel virtual addresses that are currently mapped to memory are allowed.
|
|
|
|
.Pp
|
2020-09-02 18:12:47 +00:00
|
|
|
On ISA the I/O memory space begins at physical address 0x000a0000
|
1993-06-12 14:49:13 +00:00
|
|
|
and runs to 0x00100000.
|
|
|
|
The
|
|
|
|
per-process data
|
|
|
|
size
|
|
|
|
for the current process
|
|
|
|
is
|
|
|
|
.Dv UPAGES
|
|
|
|
long, and ends at virtual
|
1994-08-23 09:34:10 +00:00
|
|
|
address 0xf0000000.
|
1999-04-07 04:03:51 +00:00
|
|
|
.Sh IOCTL INTERFACE
|
2020-09-02 18:12:47 +00:00
|
|
|
The
|
|
|
|
.Dv MEM_EXTRACT_PADDR
|
|
|
|
ioctl can be used to look up the physical address and NUMA domain of a given
|
|
|
|
virtual address in the calling process' address space.
|
|
|
|
The request is described by
|
|
|
|
.Bd -literal
|
|
|
|
struct mem_extract {
|
|
|
|
uint64_t me_vaddr; /* input */
|
|
|
|
uint64_t me_paddr; /* output */
|
|
|
|
int me_domain; /* output */
|
|
|
|
int me_state; /* output */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The ioctl returns an error if the address is not valid.
|
|
|
|
The information returned by
|
|
|
|
.Dv MEM_EXTRACT_PADDR
|
|
|
|
may be out of date by the time that the ioctl call returns.
|
|
|
|
Specifically, concurrent system calls, page faults, or system page reclamation
|
|
|
|
activity may have unmapped the virtual page or replaced the backing physical
|
|
|
|
page before the ioctl call returns.
|
|
|
|
Wired pages, e.g., those locked by
|
|
|
|
.Xr mlock 2 ,
|
|
|
|
will not be reclaimed by the system.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa me_state
|
|
|
|
field provides information about the state of the virtual page:
|
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Dv ME_STATE_INVALID
|
|
|
|
The virtual address is invalid.
|
|
|
|
.It Dv ME_STATE_VALID
|
|
|
|
The virtual address is valid but is not mapped at the time of the ioctl call.
|
|
|
|
.It Dv ME_STATE_MAPPED
|
|
|
|
The virtual address corresponds to a physical page mapping, and the
|
|
|
|
.Fa me_paddr
|
|
|
|
and
|
|
|
|
.Fa me_domain
|
|
|
|
fields are valid.
|
|
|
|
.Pp
|
1999-04-07 04:03:51 +00:00
|
|
|
Several architectures allow attributes to be associated with ranges of physical
|
2003-06-28 23:53:39 +00:00
|
|
|
memory.
|
|
|
|
These attributes can be manipulated via
|
1999-04-07 04:03:51 +00:00
|
|
|
.Fn ioctl
|
|
|
|
calls performed on
|
2003-06-28 23:53:39 +00:00
|
|
|
.Pa /dev/mem .
|
1999-04-07 04:03:51 +00:00
|
|
|
Declarations and data types are to be found in
|
2003-09-08 19:57:22 +00:00
|
|
|
.In sys/memrange.h .
|
1999-04-07 04:03:51 +00:00
|
|
|
.Pp
|
|
|
|
The specific attributes, and number of programmable ranges may vary between
|
2003-06-28 23:53:39 +00:00
|
|
|
architectures.
|
|
|
|
The full set of supported attributes is:
|
2001-02-01 16:38:02 +00:00
|
|
|
.Bl -tag -width indent
|
2003-06-28 23:53:39 +00:00
|
|
|
.It Dv MDF_UNCACHEABLE
|
1999-04-07 04:03:51 +00:00
|
|
|
The region is not cached.
|
2003-06-28 23:53:39 +00:00
|
|
|
.It Dv MDF_WRITECOMBINE
|
1999-04-07 04:03:51 +00:00
|
|
|
Writes to the region may be combined or performed out of order.
|
2003-06-28 23:53:39 +00:00
|
|
|
.It Dv MDF_WRITETHROUGH
|
1999-04-07 04:03:51 +00:00
|
|
|
Writes to the region are committed synchronously.
|
2003-06-28 23:53:39 +00:00
|
|
|
.It Dv MDF_WRITEBACK
|
1999-04-07 04:03:51 +00:00
|
|
|
Writes to the region are committed asynchronously.
|
2003-06-28 23:53:39 +00:00
|
|
|
.It Dv MDF_WRITEPROTECT
|
1999-04-07 04:03:51 +00:00
|
|
|
The region cannot be written to.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Memory ranges are described by
|
2020-09-02 18:12:47 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct mem_range_desc {
|
|
|
|
uint64_t mr_base; /* physical base address */
|
|
|
|
uint64_t mr_len; /* physical length of region */
|
|
|
|
int mr_flags; /* attributes of region */
|
|
|
|
char mr_owner[8];
|
|
|
|
};
|
1999-04-07 04:03:51 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
In addition to the region attributes listed above, the following flags
|
|
|
|
may also be set in the
|
|
|
|
.Fa mr_flags
|
|
|
|
field:
|
2001-02-01 16:38:02 +00:00
|
|
|
.Bl -tag -width indent
|
1999-04-07 04:03:51 +00:00
|
|
|
.It MDF_FIXBASE
|
|
|
|
The region's base address cannot be changed.
|
|
|
|
.It MDF_FIXLEN
|
|
|
|
The region's length cannot be changed.
|
|
|
|
.It MDF_FIRMWARE
|
2002-01-21 12:09:13 +00:00
|
|
|
The region is believed to have been established by the system firmware.
|
1999-04-07 04:03:51 +00:00
|
|
|
.It MDF_ACTIVE
|
|
|
|
The region is currently active.
|
|
|
|
.It MDF_BOGUS
|
|
|
|
We believe the region to be invalid or otherwise erroneous.
|
|
|
|
.It MDF_FIXACTIVE
|
|
|
|
The region cannot be disabled.
|
|
|
|
.It MDF_BUSY
|
2001-07-14 19:41:16 +00:00
|
|
|
The region is currently owned by another process and may not be
|
1999-04-07 04:03:51 +00:00
|
|
|
altered.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Operations are performed using
|
2020-09-02 18:12:47 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct mem_range_op {
|
|
|
|
struct mem_range_desc *mo_desc;
|
|
|
|
int mo_arg[2];
|
|
|
|
};
|
1999-04-07 04:03:51 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The
|
2003-06-28 23:53:39 +00:00
|
|
|
.Dv MEMRANGE_GET
|
2000-03-01 14:50:24 +00:00
|
|
|
ioctl is used to retrieve current memory range attributes.
|
|
|
|
If
|
2003-06-28 23:53:39 +00:00
|
|
|
.Va mo_arg[0]
|
1999-04-07 04:03:51 +00:00
|
|
|
is set to 0, it will be updated with the total number of memory range
|
2003-06-28 23:53:39 +00:00
|
|
|
descriptors.
|
|
|
|
If greater than 0, the array at
|
|
|
|
.Va mo_desc
|
1999-04-07 04:03:51 +00:00
|
|
|
will be filled with a corresponding number of descriptor structures,
|
|
|
|
or the maximum, whichever is less.
|
|
|
|
.Pp
|
2001-07-14 19:41:16 +00:00
|
|
|
The
|
2003-06-28 23:53:39 +00:00
|
|
|
.Dv MEMRANGE_SET
|
2004-07-03 18:29:24 +00:00
|
|
|
ioctl is used to add, alter and remove memory range attributes.
|
|
|
|
A range
|
2003-06-28 23:53:39 +00:00
|
|
|
with the
|
|
|
|
.Dv MDF_FIXACTIVE
|
|
|
|
flag may not be removed; a range with the
|
|
|
|
.Dv MDF_BUSY
|
1999-04-07 04:03:51 +00:00
|
|
|
flag may not be removed or updated.
|
|
|
|
.Pp
|
2003-06-28 23:53:39 +00:00
|
|
|
.Va mo_arg[0]
|
|
|
|
should be set to
|
|
|
|
.Dv MEMRANGE_SET_UPDATE
|
|
|
|
to update an existing or establish a new range, or to
|
|
|
|
.Dv MEMRANGE_SET_REMOVE
|
|
|
|
to remove a range.
|
2020-09-22 21:13:26 +00:00
|
|
|
.El
|
1999-04-07 04:03:51 +00:00
|
|
|
.Sh RETURN VALUES
|
2000-11-22 16:11:48 +00:00
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EOPNOTSUPP
|
1999-04-07 04:03:51 +00:00
|
|
|
Memory range operations are not supported on this architecture.
|
2000-11-22 16:11:48 +00:00
|
|
|
.It Bq Er ENXIO
|
2020-09-02 18:12:47 +00:00
|
|
|
No memory range descriptors are available (e.g., firmware has not enabled
|
1999-04-07 04:03:51 +00:00
|
|
|
any).
|
2000-11-22 16:11:48 +00:00
|
|
|
.It Bq Er EINVAL
|
1999-04-07 04:03:51 +00:00
|
|
|
The memory range supplied as an argument is invalid or overlaps another
|
|
|
|
range in a fashion not supported by this architecture.
|
2000-11-22 16:11:48 +00:00
|
|
|
.It Bq Er EBUSY
|
1999-04-07 04:03:51 +00:00
|
|
|
An attempt to remove or update a range failed because the range is busy.
|
2000-11-22 16:11:48 +00:00
|
|
|
.It Bq Er ENOSPC
|
1999-04-07 04:03:51 +00:00
|
|
|
An attempt to create a new range failed due to a shortage of hardware
|
2020-09-02 18:12:47 +00:00
|
|
|
resources (e.g., descriptor slots).
|
2000-11-22 16:11:48 +00:00
|
|
|
.It Bq Er ENOENT
|
1999-04-07 04:03:51 +00:00
|
|
|
An attempt to remove a range failed because no range matches the descriptor
|
2002-01-21 12:09:13 +00:00
|
|
|
base/length supplied.
|
2000-11-22 16:11:48 +00:00
|
|
|
.It Bq Er EPERM
|
1999-04-07 04:03:51 +00:00
|
|
|
An attempt to remove a range failed because the range is permanently
|
|
|
|
enabled.
|
|
|
|
.El
|
1993-06-12 14:49:13 +00:00
|
|
|
.Sh FILES
|
2001-02-01 16:38:02 +00:00
|
|
|
.Bl -tag -width /dev/kmem -compact
|
1993-06-12 14:49:13 +00:00
|
|
|
.It Pa /dev/mem
|
|
|
|
.It Pa /dev/kmem
|
|
|
|
.El
|
1999-04-07 04:03:51 +00:00
|
|
|
.Sh SEE ALSO
|
2005-01-12 10:14:43 +00:00
|
|
|
.Xr kvm 3 ,
|
1999-04-07 04:03:51 +00:00
|
|
|
.Xr memcontrol 8
|
1993-06-12 14:49:13 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
2003-06-28 23:53:39 +00:00
|
|
|
.Nm mem
|
|
|
|
and
|
1993-06-12 14:49:13 +00:00
|
|
|
.Nm kmem
|
|
|
|
files appeared in
|
|
|
|
.At v6 .
|
1999-04-07 04:03:51 +00:00
|
|
|
The ioctl interface for memory range attributes was added in
|
|
|
|
.Fx 3.2 .
|
2005-01-21 08:36:40 +00:00
|
|
|
.Sh BUGS
|
|
|
|
Busy range attributes are not yet managed correctly.
|
|
|
|
.Pp
|
|
|
|
This device is required for all users of
|
|
|
|
.Xr kvm 3
|
|
|
|
to operate.
|