nvmf/vfio-user: disallow doorbell reads

NVMe over PCIe Transport Spec 3.1.2:
The host should not read the doorbell registers.

Explicitly refuse these reads.

Co-authored-by: John Levon <john.levon@nutanix.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
Change-Id: Ie64fd5ce7988ee86c612b3ef6046a57af467e266
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11787
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Andreas Economides 2021-09-02 09:37:25 +00:00 committed by Tomasz Zawadzki
parent 797df3717e
commit f25c4c822c

View File

@ -1,7 +1,7 @@
/*-
* BSD LICENSE
* Copyright (c) Intel Corporation. All rights reserved.
* Copyright (c) 2019, Nutanix Inc. All rights reserved.
* Copyright (c) 2019-2022, Nutanix Inc. All rights reserved.
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -2048,6 +2048,13 @@ handle_dbl_access(struct nvmf_vfio_user_ctrlr *ctrlr, uint32_t *buf,
assert(ctrlr != NULL);
assert(buf != NULL);
if (!is_write) {
SPDK_WARNLOG("%s: host tried to read BAR0 doorbell %#lx\n",
ctrlr_id(ctrlr), pos);
errno = EPERM;
return -1;
}
if (count != sizeof(uint32_t)) {
SPDK_ERRLOG("%s: bad doorbell buffer size %ld\n",
ctrlr_id(ctrlr), count);
@ -2073,13 +2080,9 @@ handle_dbl_access(struct nvmf_vfio_user_ctrlr *ctrlr, uint32_t *buf,
return -1;
}
if (is_write) {
ctrlr->doorbells[pos] = *buf;
spdk_wmb();
} else {
spdk_rmb();
*buf = ctrlr->doorbells[pos];
}
ctrlr->doorbells[pos] = *buf;
spdk_wmb();
return 0;
}