Changeset View
Standalone View
sys/opencrypto/criov.c
Show All 35 Lines | |||||
#include <sys/errno.h> | #include <sys/errno.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/limits.h> | #include <sys/limits.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <machine/vmparam.h> | |||||
#include <vm/vm.h> | |||||
#include <vm/vm_page.h> | |||||
#include <vm/pmap.h> | |||||
#include <opencrypto/cryptodev.h> | #include <opencrypto/cryptodev.h> | ||||
/* | /* | ||||
* This macro is only for avoiding code duplication, as we need to skip | * These macros are only for avoiding code duplication, as we need to skip | ||||
* given number of bytes in the same way in three functions below. | * given number of bytes in the same way in several functions below. | ||||
*/ | */ | ||||
#define CUIO_SKIP() do { \ | #define CUIO_SKIP() do { \ | ||||
KASSERT(off >= 0, ("%s: off %d < 0", __func__, off)); \ | KASSERT(off >= 0, ("%s: off %d < 0", __func__, off)); \ | ||||
KASSERT(len >= 0, ("%s: len %d < 0", __func__, len)); \ | KASSERT(len >= 0, ("%s: len %d < 0", __func__, len)); \ | ||||
while (off > 0) { \ | while (off > 0) { \ | ||||
KASSERT(iol >= 0, ("%s: empty in skip", __func__)); \ | KASSERT(iol >= 0, ("%s: empty in skip", __func__)); \ | ||||
if (off < iov->iov_len) \ | if (off < iov->iov_len) \ | ||||
break; \ | break; \ | ||||
off -= iov->iov_len; \ | off -= iov->iov_len; \ | ||||
iol--; \ | iol--; \ | ||||
iov++; \ | iov++; \ | ||||
} \ | } \ | ||||
} while (0) | } while (0) | ||||
#define CUNMAPPED_SKIP() do { \ | |||||
kib: I would not use VM_PAGE_ prefix for something not coming from vm_page.{h,c}. | |||||
Not Done Inline ActionsI agree. markj: I agree. | |||||
Not Done Inline ActionsHmm, I would have preferred calling all this VMPAGES instead of UNMAPPED. UNMAPPED could also have been backed by an sglist(9), so it is ambiguous. I think VMPAGES is a better name if it is an array of vm_page_t. This is also consistent with the sglist(9) API which uses "vmpages" and not "unmapped". There are other places where knowing it's an array of VMPAGES is important (KTLS is one I was planning on implementing this exact feature for, as well as an earlier prototype I had a few years ago to teach /dev/crypto to wire user pages to avoid the overhead of copies when using ccr(4) from OpenSSL's engine interface for TLS). jhb: Hmm, I would have preferred calling all this VMPAGES instead of UNMAPPED. UNMAPPED could also… | |||||
Not Done Inline ActionsMy thinking was that we're not just using VM pages, but are additionally relying on the direct map to access their contents. A name that captures this would be ideal IMO. sglist just fetches their physical addresses, so it's not quite the same. UNMAPPED is admittedly not a good name. I'd prefer something more specific than VMPAGES but I don't have any good suggestions, so I'm ok with reverting that change back. Sorry for causing churn. I still think we should avoid adding anything to the vm_page_* namespace. markj: My thinking was that we're not just using VM pages, but are additionally relying on the direct… | |||||
Not Done Inline ActionsI agree not adding to the vm_page_* namespace, but this is a VMPAGES suffix. Note that for some use cases you won't even use the direct map (e.g when using ccr(4) with KTLS and the separate AAD, the actual TLS payload would be an unmapped mbuf which uses physaddrs and in the case it's file-backed the output buffer would be a vm_page_t array and the driver would just DMA from one to the other without ever using the direct map). Note that if we bothered to have an sglist buffer type it would have similar mapping constraints. I think we just have to describe it as a limitation in the documentation (crypto_buffer.9 in this case) that this type of buffer only works with crypto cursors and the crypto_copy* API (and thus with all device drivers) if the architecture supports a direct map. jhb: I agree not adding to the vm_page_* namespace, but this is a VMPAGES suffix. Note that for… | |||||
KASSERT(off >= 0, ("%s: off %d < 0", __func__, off)); \ | |||||
KASSERT(len >= 0, ("%s: len %d < 0", __func__, len)); \ | |||||
while (off > 0) { \ | |||||
if (off < PAGE_SIZE) \ | |||||
break; \ | |||||
processed += PAGE_SIZE - off; \ | |||||
off -= PAGE_SIZE - off; \ | |||||
pages++; \ | |||||
} \ | |||||
} while (0) | |||||
static void | static void | ||||
cuio_copydata(struct uio* uio, int off, int len, caddr_t cp) | cuio_copydata(struct uio* uio, int off, int len, caddr_t cp) | ||||
{ | { | ||||
struct iovec *iov = uio->uio_iov; | struct iovec *iov = uio->uio_iov; | ||||
int iol = uio->uio_iovcnt; | int iol = uio->uio_iovcnt; | ||||
unsigned count; | unsigned count; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (ind > 0 && loc == 0) { | ||||
ind--; | ind--; | ||||
*off = uio->uio_iov[ind].iov_len; | *off = uio->uio_iov[ind].iov_len; | ||||
return (ind); | return (ind); | ||||
} | } | ||||
return (-1); | return (-1); | ||||
} | } | ||||
#if CRYPTO_HAS_UNMAPPED | |||||
/* | |||||
* Apply function f to the data in a vm_page_t list starting "off" bytes from | |||||
* the beginning, continuing for "len" bytes. | |||||
*/ | |||||
static int | |||||
cunmapped_apply(vm_page_t *pages, int off, int len, | |||||
Not Done Inline ActionsAgain, please do not use vm_page_ prefix for something not coming from vm_page.{c,h}. kib: Again, please do not use vm_page_ prefix for something not coming from vm_page.{c,h}. | |||||
int (*f)(void *, const void *, u_int), void *arg) | |||||
{ | |||||
int processed = 0; | |||||
unsigned count; | |||||
int rval; | |||||
CUNMAPPED_SKIP(); | |||||
while (len > 0) { | |||||
char *kaddr = (char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(*pages)); | |||||
Done Inline ActionsStyle: missing space after the second *. There are other instances of this below. markj: Style: missing space after the second `*`. There are other instances of this below. | |||||
count = min(PAGE_SIZE - off, len); | |||||
rval = (*f)(arg, kaddr + off, count); | |||||
if (rval) | |||||
return (rval); | |||||
len -= count; | |||||
processed += count; | |||||
off = 0; | |||||
pages++; | |||||
} | |||||
return (0); | |||||
} | |||||
static inline void * | |||||
cunmapped_contiguous_segment(vm_page_t *pages, size_t skip, int len) | |||||
{ | |||||
if ((skip + len - 1) / PAGE_SIZE > skip / PAGE_SIZE) | |||||
return (NULL); | |||||
pages += (skip / PAGE_SIZE); | |||||
Done Inline Actions() are not needed. also you can use atop() there kib: () are not needed. also you can use atop() there | |||||
skip -= rounddown(skip, PAGE_SIZE); | |||||
Done Inline ActionsIs this same as skip = trunc_page(skip); ? kib: Is this same as `skip = trunc_page(skip);` ? | |||||
Done Inline ActionsYes asomers: Yes | |||||
return (((char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(*pages))) + skip); | |||||
} | |||||
/* | |||||
* Copy len bytes of data from the vm_page_t array, skipping the first off | |||||
* bytes, into the pointer cp. Return the number of bytes skipped and copied. | |||||
* Does not verify the length of the array. | |||||
*/ | |||||
static int | |||||
cunmapped_copyback(vm_page_t *pages, int off, int len, c_caddr_t cp) | |||||
{ | |||||
int processed = 0; | |||||
unsigned count; | |||||
CUNMAPPED_SKIP(); | |||||
while (len > 0) { | |||||
count = min(PAGE_SIZE - off, len); | |||||
bcopy(cp, (char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(*pages)) + off, | |||||
count); | |||||
len -= count; | |||||
cp += count; | |||||
processed += count; | |||||
off = 0; | |||||
pages++; | |||||
} | |||||
return processed; | |||||
Done Inline Actionsreturn (processed); kib: `return (processed);` | |||||
Done Inline ActionsThis is still outstanding. markj: This is still outstanding. | |||||
} | |||||
/* | |||||
* Copy len bytes of data from the pointer cp into the vm_page_t array, | |||||
* skipping the first off bytes, Return the number of bytes skipped and copied. | |||||
* Does not verify the length of the array. | |||||
*/ | |||||
static int | |||||
cunmapped_copydata(vm_page_t *pages, int off, int len, caddr_t cp) | |||||
{ | |||||
int processed = 0; | |||||
unsigned count; | |||||
CUNMAPPED_SKIP(); | |||||
while (len > 0) { | |||||
count = min(PAGE_SIZE - off, len); | |||||
bcopy(((char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(*pages)) + off), cp, | |||||
count); | |||||
len -= count; | |||||
cp += count; | |||||
processed += count; | |||||
off = 0; | |||||
pages++; | |||||
} | |||||
return processed; | |||||
} | |||||
#endif /* CRYPTO_HAS_UNMAPPED */ | |||||
void | void | ||||
crypto_cursor_init(struct crypto_buffer_cursor *cc, | crypto_cursor_init(struct crypto_buffer_cursor *cc, | ||||
const struct crypto_buffer *cb) | const struct crypto_buffer *cb) | ||||
{ | { | ||||
memset(cc, 0, sizeof(*cc)); | memset(cc, 0, sizeof(*cc)); | ||||
cc->cc_type = cb->cb_type; | cc->cc_type = cb->cb_type; | ||||
switch (cc->cc_type) { | switch (cc->cc_type) { | ||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
cc->cc_buf = cb->cb_buf; | cc->cc_buf = cb->cb_buf; | ||||
cc->cc_buf_len = cb->cb_buf_len; | cc->cc_buf_len = cb->cb_buf_len; | ||||
break; | break; | ||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
cc->cc_mbuf = cb->cb_mbuf; | cc->cc_mbuf = cb->cb_mbuf; | ||||
break; | break; | ||||
case CRYPTO_BUF_UNMAPPED: | |||||
cc->cc_unmapped = cb->cb_unmapped; | |||||
cc->cc_buf_len = cb->cb_unmapped_len; | |||||
cc->cc_offset = cb->cb_unmapped_offset; | |||||
break; | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
cc->cc_iov = cb->cb_uio->uio_iov; | cc->cc_iov = cb->cb_uio->uio_iov; | ||||
break; | break; | ||||
default: | default: | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
panic("%s: invalid buffer type %d", __func__, cb->cb_type); | panic("%s: invalid buffer type %d", __func__, cb->cb_type); | ||||
#endif | #endif | ||||
break; | break; | ||||
Show All 20 Lines | for (;;) { | ||||
} | } | ||||
amount -= remain; | amount -= remain; | ||||
cc->cc_mbuf = cc->cc_mbuf->m_next; | cc->cc_mbuf = cc->cc_mbuf->m_next; | ||||
cc->cc_offset = 0; | cc->cc_offset = 0; | ||||
if (amount == 0) | if (amount == 0) | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case CRYPTO_BUF_UNMAPPED: | |||||
for (;;) { | |||||
remain = MIN(PAGE_SIZE - cc->cc_offset, cc->cc_buf_len); | |||||
cc->cc_buf_len -= amount; | |||||
Not Done Inline ActionsReally not sure I understand this code in general, but should the whole amount left to process be subtracted on every iteration that processes a small chunk of it? sigsys_gmail.com: Really not sure I understand this code in general, but should the whole amount left to process… | |||||
Done Inline ActionsGood catch. You're right, but testing didn't catch it because geli never tries to advance by more than 4096 bytes at a time. asomers: Good catch. You're right, but testing didn't catch it because geli never tries to advance by… | |||||
if (amount < remain) { | |||||
cc->cc_offset += amount; | |||||
break; | |||||
} | |||||
amount -= remain; | |||||
cc->cc_unmapped++; | |||||
cc->cc_offset = 0; | |||||
if (amount == 0) | |||||
break; | |||||
} | |||||
break; | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
for (;;) { | for (;;) { | ||||
remain = cc->cc_iov->iov_len - cc->cc_offset; | remain = cc->cc_iov->iov_len - cc->cc_offset; | ||||
if (amount < remain) { | if (amount < remain) { | ||||
cc->cc_offset += amount; | cc->cc_offset += amount; | ||||
break; | break; | ||||
} | } | ||||
amount -= remain; | amount -= remain; | ||||
Show All 18 Lines | crypto_cursor_segbase(struct crypto_buffer_cursor *cc) | ||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
return (cc->cc_buf); | return (cc->cc_buf); | ||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
if (cc->cc_mbuf == NULL) | if (cc->cc_mbuf == NULL) | ||||
return (NULL); | return (NULL); | ||||
KASSERT((cc->cc_mbuf->m_flags & M_EXTPG) == 0, | KASSERT((cc->cc_mbuf->m_flags & M_EXTPG) == 0, | ||||
("%s: not supported for unmapped mbufs", __func__)); | ("%s: not supported for unmapped mbufs", __func__)); | ||||
return (mtod(cc->cc_mbuf, char *) + cc->cc_offset); | return (mtod(cc->cc_mbuf, char *) + cc->cc_offset); | ||||
case CRYPTO_BUF_UNMAPPED: | |||||
return ((char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS( | |||||
*cc->cc_unmapped)) + cc->cc_offset); | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
return ((char *)cc->cc_iov->iov_base + cc->cc_offset); | return ((char *)cc->cc_iov->iov_base + cc->cc_offset); | ||||
default: | default: | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
panic("%s: invalid buffer type %d", __func__, cc->cc_type); | panic("%s: invalid buffer type %d", __func__, cc->cc_type); | ||||
#endif | #endif | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
} | } | ||||
size_t | size_t | ||||
crypto_cursor_seglen(struct crypto_buffer_cursor *cc) | crypto_cursor_seglen(struct crypto_buffer_cursor *cc) | ||||
{ | { | ||||
switch (cc->cc_type) { | switch (cc->cc_type) { | ||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
return (cc->cc_buf_len); | return (cc->cc_buf_len); | ||||
case CRYPTO_BUF_UNMAPPED: | |||||
return (PAGE_SIZE - cc->cc_offset); | |||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
if (cc->cc_mbuf == NULL) | if (cc->cc_mbuf == NULL) | ||||
return (0); | return (0); | ||||
return (cc->cc_mbuf->m_len - cc->cc_offset); | return (cc->cc_mbuf->m_len - cc->cc_offset); | ||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
return (cc->cc_iov->iov_len - cc->cc_offset); | return (cc->cc_iov->iov_len - cc->cc_offset); | ||||
default: | default: | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
Show All 34 Lines | for (;;) { | ||||
} | } | ||||
size -= todo; | size -= todo; | ||||
cc->cc_mbuf = cc->cc_mbuf->m_next; | cc->cc_mbuf = cc->cc_mbuf->m_next; | ||||
cc->cc_offset = 0; | cc->cc_offset = 0; | ||||
if (size == 0) | if (size == 0) | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case CRYPTO_BUF_UNMAPPED: | |||||
for (;;) { | |||||
dst = (char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS( | |||||
*cc->cc_unmapped)) + cc->cc_offset; | |||||
remain = MIN(PAGE_SIZE - cc->cc_offset, cc->cc_buf_len); | |||||
todo = MIN(remain, size); | |||||
memcpy(dst, src, todo); | |||||
src += todo; | |||||
cc->cc_buf_len -= todo; | |||||
if (todo < remain) { | |||||
cc->cc_offset += todo; | |||||
break; | |||||
} | |||||
size -= todo; | |||||
cc->cc_unmapped++; | |||||
cc->cc_offset = 0; | |||||
if (size == 0) | |||||
break; | |||||
} | |||||
break; | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
for (;;) { | for (;;) { | ||||
dst = (char *)cc->cc_iov->iov_base + cc->cc_offset; | dst = (char *)cc->cc_iov->iov_base + cc->cc_offset; | ||||
remain = cc->cc_iov->iov_len - cc->cc_offset; | remain = cc->cc_iov->iov_len - cc->cc_offset; | ||||
todo = MIN(remain, size); | todo = MIN(remain, size); | ||||
memcpy(dst, src, todo); | memcpy(dst, src, todo); | ||||
src += todo; | src += todo; | ||||
if (todo < remain) { | if (todo < remain) { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | for (;;) { | ||||
} | } | ||||
size -= todo; | size -= todo; | ||||
cc->cc_mbuf = cc->cc_mbuf->m_next; | cc->cc_mbuf = cc->cc_mbuf->m_next; | ||||
cc->cc_offset = 0; | cc->cc_offset = 0; | ||||
if (size == 0) | if (size == 0) | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case CRYPTO_BUF_UNMAPPED: | |||||
for (;;) { | |||||
src = (char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS( | |||||
*cc->cc_unmapped)) + cc->cc_offset; | |||||
remain = MIN(PAGE_SIZE - cc->cc_offset, cc->cc_buf_len); | |||||
todo = MIN(remain, size); | |||||
memcpy(dst, src, todo); | |||||
src += todo; | |||||
cc->cc_buf_len -= todo; | |||||
if (todo < remain) { | |||||
cc->cc_offset += todo; | |||||
break; | |||||
} | |||||
size -= todo; | |||||
cc->cc_unmapped++; | |||||
cc->cc_offset = 0; | |||||
if (size == 0) | |||||
break; | |||||
} | |||||
break; | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
for (;;) { | for (;;) { | ||||
src = (const char *)cc->cc_iov->iov_base + | src = (const char *)cc->cc_iov->iov_base + | ||||
cc->cc_offset; | cc->cc_offset; | ||||
remain = cc->cc_iov->iov_len - cc->cc_offset; | remain = cc->cc_iov->iov_len - cc->cc_offset; | ||||
todo = MIN(remain, size); | todo = MIN(remain, size); | ||||
memcpy(dst, src, todo); | memcpy(dst, src, todo); | ||||
dst += todo; | dst += todo; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | crypto_copyback(struct cryptop *crp, int off, int size, const void *src) | ||||
if (crp->crp_obuf.cb_type != CRYPTO_BUF_NONE) | if (crp->crp_obuf.cb_type != CRYPTO_BUF_NONE) | ||||
cb = &crp->crp_obuf; | cb = &crp->crp_obuf; | ||||
else | else | ||||
cb = &crp->crp_buf; | cb = &crp->crp_buf; | ||||
switch (cb->cb_type) { | switch (cb->cb_type) { | ||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
m_copyback(cb->cb_mbuf, off, size, src); | m_copyback(cb->cb_mbuf, off, size, src); | ||||
break; | break; | ||||
#if CRYPTO_HAS_UNMAPPED | |||||
Done Inline ActionsDoes this compile on powerpc? markj: Does this compile on powerpc? | |||||
case CRYPTO_BUF_UNMAPPED: | |||||
MPASS(size <= cb->cb_unmapped_len); | |||||
MPASS(size + off <= | |||||
cb->cb_unmapped_len + cb->cb_unmapped_offset); | |||||
cunmapped_copyback(cb->cb_unmapped, | |||||
off + cb->cb_unmapped_offset, size, src); | |||||
break; | |||||
#endif /* CRYPTO_HAS_UNMAPPED */ | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
cuio_copyback(cb->cb_uio, off, size, src); | cuio_copyback(cb->cb_uio, off, size, src); | ||||
break; | break; | ||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
MPASS(off + size <= cb->cb_buf_len); | MPASS(off + size <= cb->cb_buf_len); | ||||
bcopy(src, cb->cb_buf + off, size); | bcopy(src, cb->cb_buf + off, size); | ||||
break; | break; | ||||
default: | default: | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
panic("invalid crp buf type %d", cb->cb_type); | panic("invalid crp buf type %d", cb->cb_type); | ||||
#endif | #endif | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
void | void | ||||
crypto_copydata(struct cryptop *crp, int off, int size, void *dst) | crypto_copydata(struct cryptop *crp, int off, int size, void *dst) | ||||
{ | { | ||||
switch (crp->crp_buf.cb_type) { | switch (crp->crp_buf.cb_type) { | ||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
m_copydata(crp->crp_buf.cb_mbuf, off, size, dst); | m_copydata(crp->crp_buf.cb_mbuf, off, size, dst); | ||||
break; | break; | ||||
#if CRYPTO_HAS_UNMAPPED | |||||
case CRYPTO_BUF_UNMAPPED: | |||||
MPASS(size <= crp->crp_buf.cb_unmapped_len); | |||||
MPASS(size + off <= crp->crp_buf.cb_unmapped_len + | |||||
crp->crp_buf.cb_unmapped_offset); | |||||
cunmapped_copydata(crp->crp_buf.cb_unmapped, | |||||
off + crp->crp_buf.cb_unmapped_offset, size, dst); | |||||
break; | |||||
#endif /* CRYPTO_HAS_UNMAPPED */ | |||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
cuio_copydata(crp->crp_buf.cb_uio, off, size, dst); | cuio_copydata(crp->crp_buf.cb_uio, off, size, dst); | ||||
break; | break; | ||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
MPASS(off + size <= crp->crp_buf.cb_buf_len); | MPASS(off + size <= crp->crp_buf.cb_buf_len); | ||||
bcopy(crp->crp_buf.cb_buf + off, dst, size); | bcopy(crp->crp_buf.cb_buf + off, dst, size); | ||||
break; | break; | ||||
default: | default: | ||||
Show All 13 Lines | crypto_apply_buf(struct crypto_buffer *cb, int off, int len, | ||||
switch (cb->cb_type) { | switch (cb->cb_type) { | ||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
error = m_apply(cb->cb_mbuf, off, len, | error = m_apply(cb->cb_mbuf, off, len, | ||||
(int (*)(void *, void *, u_int))f, arg); | (int (*)(void *, void *, u_int))f, arg); | ||||
break; | break; | ||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
error = cuio_apply(cb->cb_uio, off, len, f, arg); | error = cuio_apply(cb->cb_uio, off, len, f, arg); | ||||
break; | break; | ||||
#if CRYPTO_HAS_UNMAPPED | |||||
case CRYPTO_BUF_UNMAPPED: | |||||
error = cunmapped_apply(cb->cb_unmapped, | |||||
off + cb->cb_unmapped_offset, len, f, arg); | |||||
break; | |||||
#endif /* CRYPTO_HAS_UNMAPPED */ | |||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
MPASS(off + len <= cb->cb_buf_len); | MPASS(off + len <= cb->cb_buf_len); | ||||
error = (*f)(arg, cb->cb_buf + off, len); | error = (*f)(arg, cb->cb_buf + off, len); | ||||
break; | break; | ||||
default: | default: | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
panic("invalid crypto buf type %d", cb->cb_type); | panic("invalid crypto buf type %d", cb->cb_type); | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | crypto_buffer_contiguous_subsegment(struct crypto_buffer *cb, size_t skip, | ||||
size_t len) | size_t len) | ||||
{ | { | ||||
switch (cb->cb_type) { | switch (cb->cb_type) { | ||||
case CRYPTO_BUF_MBUF: | case CRYPTO_BUF_MBUF: | ||||
return (m_contiguous_subsegment(cb->cb_mbuf, skip, len)); | return (m_contiguous_subsegment(cb->cb_mbuf, skip, len)); | ||||
case CRYPTO_BUF_UIO: | case CRYPTO_BUF_UIO: | ||||
return (cuio_contiguous_segment(cb->cb_uio, skip, len)); | return (cuio_contiguous_segment(cb->cb_uio, skip, len)); | ||||
#if CRYPTO_HAS_UNMAPPED | |||||
case CRYPTO_BUF_UNMAPPED: | |||||
MPASS(skip + len <= cb->cb_unmapped_len); | |||||
return (cunmapped_contiguous_segment(cb->cb_unmapped, | |||||
skip + cb->cb_unmapped_offset, len)); | |||||
#endif /* CRYPTO_HAS_UNMAPPED */ | |||||
case CRYPTO_BUF_CONTIG: | case CRYPTO_BUF_CONTIG: | ||||
MPASS(skip + len <= cb->cb_buf_len); | MPASS(skip + len <= cb->cb_buf_len); | ||||
return (cb->cb_buf + skip); | return (cb->cb_buf + skip); | ||||
default: | default: | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
panic("invalid crp buf type %d", cb->cb_type); | panic("invalid crp buf type %d", cb->cb_type); | ||||
#endif | #endif | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
} | } | ||||
void * | void * | ||||
crypto_contiguous_subsegment(struct cryptop *crp, size_t skip, size_t len) | crypto_contiguous_subsegment(struct cryptop *crp, size_t skip, size_t len) | ||||
{ | { | ||||
return (crypto_buffer_contiguous_subsegment(&crp->crp_buf, skip, len)); | return (crypto_buffer_contiguous_subsegment(&crp->crp_buf, skip, len)); | ||||
} | } |
I would not use VM_PAGE_ prefix for something not coming from vm_page.{h,c}.