drivers/nvme/host/auth.c
Source file repositories/reference/linux-study-clean/drivers/nvme/host/auth.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/host/auth.c- Extension
.c- Size
- 30173 bytes
- Lines
- 1117
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/crc32.hlinux/base64.hlinux/prandom.hlinux/unaligned.hcrypto/dh.hnvme.hfabrics.hlinux/nvme-auth.hlinux/nvme-keyring.h
Detected Declarations
struct nvme_dhchap_queue_contextfunction ctrl_max_dhchapsfunction nvme_auth_submitfunction nvme_auth_receive_validatefunction nvme_auth_set_dhchap_negotiate_datafunction nvme_auth_process_dhchap_challengefunction nvme_auth_set_dhchap_reply_datafunction nvme_auth_process_dhchap_success1function nvme_auth_set_dhchap_success2_datafunction nvme_auth_set_dhchap_failure2_datafunction nvme_auth_dhchap_setup_host_responsefunction nvme_auth_dhchap_setup_ctrl_responsefunction nvme_auth_dhchap_exponentialfunction nvme_auth_reset_dhchapfunction nvme_auth_free_dhchapfunction nvme_auth_revoke_tls_keyfunction nvme_auth_secure_concatfunction nvme_queue_auth_workfunction nvme_auth_negotiatefunction nvme_auth_waitfunction nvme_ctrl_auth_workfunction nvme_auth_init_ctrlfunction nvme_auth_stopfunction nvme_auth_freefunction nvme_init_authfunction nvme_exit_authexport nvme_auth_revoke_tls_keyexport nvme_auth_negotiateexport nvme_auth_waitexport nvme_auth_init_ctrlexport nvme_auth_stopexport nvme_auth_free
Annotated Snippet
struct nvme_dhchap_queue_context {
struct list_head entry;
struct work_struct auth_work;
struct nvme_ctrl *ctrl;
struct crypto_kpp *dh_tfm;
struct nvme_dhchap_key *transformed_key;
void *buf;
int qid;
int error;
u32 s1;
u32 s2;
bool bi_directional;
bool authenticated;
u16 transaction;
u8 status;
u8 dhgroup_id;
u8 hash_id;
u8 sc_c;
size_t hash_len;
u8 c1[NVME_AUTH_MAX_DIGEST_SIZE];
u8 c2[NVME_AUTH_MAX_DIGEST_SIZE];
u8 response[NVME_AUTH_MAX_DIGEST_SIZE];
u8 *ctrl_key;
u8 *host_key;
u8 *sess_key;
int ctrl_key_len;
int host_key_len;
int sess_key_len;
};
static struct workqueue_struct *nvme_auth_wq;
static inline int ctrl_max_dhchaps(struct nvme_ctrl *ctrl)
{
return ctrl->opts->nr_io_queues + ctrl->opts->nr_write_queues +
ctrl->opts->nr_poll_queues + 1;
}
static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
void *data, size_t data_len, bool auth_send)
{
struct nvme_command cmd = {};
nvme_submit_flags_t flags = NVME_SUBMIT_RETRY;
struct request_queue *q = ctrl->fabrics_q;
int ret;
if (qid != 0) {
flags |= NVME_SUBMIT_NOWAIT | NVME_SUBMIT_RESERVED;
q = ctrl->connect_q;
}
cmd.auth_common.opcode = nvme_fabrics_command;
cmd.auth_common.secp = NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER;
cmd.auth_common.spsp0 = 0x01;
cmd.auth_common.spsp1 = 0x01;
if (auth_send) {
cmd.auth_send.fctype = nvme_fabrics_type_auth_send;
cmd.auth_send.tl = cpu_to_le32(data_len);
} else {
cmd.auth_receive.fctype = nvme_fabrics_type_auth_receive;
cmd.auth_receive.al = cpu_to_le32(data_len);
}
ret = __nvme_submit_sync_cmd(q, &cmd, NULL, data, data_len,
qid == 0 ? NVME_QID_ANY : qid, flags);
if (ret > 0)
dev_warn(ctrl->device,
"qid %d auth_send failed with status %d\n", qid, ret);
else if (ret < 0)
dev_err(ctrl->device,
"qid %d auth_send failed with error %d\n", qid, ret);
return ret;
}
static int nvme_auth_receive_validate(struct nvme_ctrl *ctrl, int qid,
struct nvmf_auth_dhchap_failure_data *data,
u16 transaction, u8 expected_msg)
{
dev_dbg(ctrl->device, "%s: qid %d auth_type %d auth_id %x\n",
__func__, qid, data->auth_type, data->auth_id);
if (data->auth_type == NVME_AUTH_COMMON_MESSAGES &&
data->auth_id == NVME_AUTH_DHCHAP_MESSAGE_FAILURE1) {
return data->rescode_exp;
}
if (data->auth_type != NVME_AUTH_DHCHAP_MESSAGES ||
data->auth_id != expected_msg) {
dev_warn(ctrl->device,
"qid %d invalid message %02x/%02x\n",
qid, data->auth_type, data->auth_id);
Annotation
- Immediate include surface: `linux/crc32.h`, `linux/base64.h`, `linux/prandom.h`, `linux/unaligned.h`, `crypto/dh.h`, `nvme.h`, `fabrics.h`, `linux/nvme-auth.h`.
- Detected declarations: `struct nvme_dhchap_queue_context`, `function ctrl_max_dhchaps`, `function nvme_auth_submit`, `function nvme_auth_receive_validate`, `function nvme_auth_set_dhchap_negotiate_data`, `function nvme_auth_process_dhchap_challenge`, `function nvme_auth_set_dhchap_reply_data`, `function nvme_auth_process_dhchap_success1`, `function nvme_auth_set_dhchap_success2_data`, `function nvme_auth_set_dhchap_failure2_data`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- 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.