Commit f25c4c82 authored by Andreas Economides's avatar Andreas Economides Committed by Tomasz Zawadzki
Browse files

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: default avatarJohn Levon <john.levon@nutanix.com>
Signed-off-by: default avatarJohn 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarThanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 797df371
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
/*-
 *   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];
	}

	return 0;
}