lib/iov_iter.c
Source file repositories/reference/linux-study-clean/lib/iov_iter.c
File Facts
- System
- Linux kernel
- Corpus path
lib/iov_iter.c- Extension
.c- Size
- 50984 bytes
- Lines
- 1946
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/bvec.hlinux/fault-inject-usercopy.hlinux/uio.hlinux/pagemap.hlinux/highmem.hlinux/slab.hlinux/vmalloc.hlinux/splice.hlinux/compat.hlinux/scatterlist.hlinux/instrumented.hlinux/iov_iter.h
Detected Declarations
function copy_to_user_iterfunction copy_to_user_iter_nofaultfunction copy_from_user_iterfunction memcpy_to_iterfunction memcpy_from_iterfunction infunction get_user_pagesfunction iov_iter_initfunction _copy_to_iterfunction copy_to_user_iter_mcfunction memcpy_to_iter_mcfunction _copy_to_iterfunction __copy_from_iterfunction _copy_from_iterfunction copy_from_user_iter_nocachefunction _copy_from_iter_nocachefunction copy_from_user_iter_flushcachefunction memcpy_from_iter_flushcachefunction dax_copy_from_iterfunction page_copy_sanefunction copy_page_to_iterfunction copy_page_to_iter_nofaultfunction copy_page_from_iterfunction zero_to_user_iterfunction zero_to_iterfunction iov_iter_zerofunction copy_folio_from_iter_atomicfunction iov_iter_bvec_advancefunction iov_iter_iovec_advancefunction iov_iter_folioq_advancefunction iov_iter_advancefunction iov_iter_folioq_revertfunction iov_iter_revertfunction iov_iter_single_seg_countfunction iov_iter_kvecfunction iov_iter_bvecfunction iov_iter_folio_queuefunction iov_iter_xarrayfunction iov_iter_discardfunction iov_iter_alignment_iovecfunction iov_iter_alignment_bvecfunction iov_iter_alignmentfunction iov_iter_gap_alignmentfunction want_pages_arrayfunction iter_folioq_get_pagesfunction iter_xarray_populate_pagesfunction iter_xarray_get_pagesfunction first_iovec_segment
Annotated Snippet
if (offset == PAGE_SIZE) {
page++;
offset = 0;
}
}
return res;
}
EXPORT_SYMBOL(copy_page_to_iter);
size_t copy_page_to_iter_nofault(struct page *page, unsigned offset, size_t bytes,
struct iov_iter *i)
{
size_t res = 0;
if (!page_copy_sane(page, offset, bytes))
return 0;
if (WARN_ON_ONCE(i->data_source))
return 0;
page += offset / PAGE_SIZE; // first subpage
offset %= PAGE_SIZE;
while (1) {
void *kaddr = kmap_local_page(page);
size_t n = min(bytes, (size_t)PAGE_SIZE - offset);
n = iterate_and_advance(i, n, kaddr + offset,
copy_to_user_iter_nofault,
memcpy_to_iter);
kunmap_local(kaddr);
res += n;
bytes -= n;
if (!bytes || !n)
break;
offset += n;
if (offset == PAGE_SIZE) {
page++;
offset = 0;
}
}
return res;
}
EXPORT_SYMBOL(copy_page_to_iter_nofault);
size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes,
struct iov_iter *i)
{
size_t res = 0;
if (!page_copy_sane(page, offset, bytes))
return 0;
page += offset / PAGE_SIZE; // first subpage
offset %= PAGE_SIZE;
while (1) {
void *kaddr = kmap_local_page(page);
size_t n = min(bytes, (size_t)PAGE_SIZE - offset);
n = _copy_from_iter(kaddr + offset, n, i);
kunmap_local(kaddr);
res += n;
bytes -= n;
if (!bytes || !n)
break;
offset += n;
if (offset == PAGE_SIZE) {
page++;
offset = 0;
}
}
return res;
}
EXPORT_SYMBOL(copy_page_from_iter);
static __always_inline
size_t zero_to_user_iter(void __user *iter_to, size_t progress,
size_t len, void *priv, void *priv2)
{
return clear_user(iter_to, len);
}
static __always_inline
size_t zero_to_iter(void *iter_to, size_t progress,
size_t len, void *priv, void *priv2)
{
memset(iter_to, 0, len);
return 0;
}
size_t iov_iter_zero(size_t bytes, struct iov_iter *i)
{
return iterate_and_advance(i, bytes, NULL,
zero_to_user_iter, zero_to_iter);
}
EXPORT_SYMBOL(iov_iter_zero);
Annotation
- Immediate include surface: `linux/export.h`, `linux/bvec.h`, `linux/fault-inject-usercopy.h`, `linux/uio.h`, `linux/pagemap.h`, `linux/highmem.h`, `linux/slab.h`, `linux/vmalloc.h`.
- Detected declarations: `function copy_to_user_iter`, `function copy_to_user_iter_nofault`, `function copy_from_user_iter`, `function memcpy_to_iter`, `function memcpy_from_iter`, `function in`, `function get_user_pages`, `function iov_iter_init`, `function _copy_to_iter`, `function copy_to_user_iter_mc`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.