diff --git a/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch b/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch
new file mode 100644
index 0000000..f9fc2fe
--- /dev/null
+++ b/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch
@@ -0,0 +1,103 @@
+From 7d1c18f581e489e0cedfd9991bc97a2f8239cf82 Mon Sep 17 00:00:00 2001
+From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
+Date: Thu, 3 Aug 2023 20:21:39 +0900
+Subject: [PATCH] fabrics: Use corresponding hostid when hostnqn is generated
+
+After the kernel commit ae8bd606e09b ("nvme-fabrics: prevent overriding
+of existing host"), kernel ensures hostid and hostnqn maintain 1:1
+mapping and "non 1:1 mapping will be rejected". This makes 'nvme
+discover' and 'nvme connect' commands fail when they generate hostnqn,
+since it does not use corresponding hostid.
+
+To avoid the failures, prepare and use corresponding hostid to the
+generated hostnqn, taking the hostid from the hostnqn string. Also add
+checks for prepared hostnqn and hostid. If the hostid taken from the
+generated hostnqn is different from the hostid from file, print a
+warning message. Also, if the prepared hostnqn are inconsistent with the
+prepared hostid, print a warning.
+
+Link: https://lore.kernel.org/linux-nvme/l7vk7fnzltpmvkwujsbf2btrzip6wh7ug62iwa3totqcda25l6@siqx7tj6lt3l/
+Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
+Signed-off-by: Daniel Wagner <dwagner@suse.de>
+---
+ fabrics.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 45 insertions(+), 2 deletions(-)
+
+diff --git a/fabrics.c b/fabrics.c
+index 14a91cc6b..40aef6932 100644
+--- a/fabrics.c
++++ b/fabrics.c
+@@ -689,6 +689,43 @@ static int nvme_read_volatile_config(nvme_root_t r)
+ 	return ret;
+ }
+ 
++char *nvmf_hostid_from_hostnqn(const char *hostnqn)
++{
++	const char *uuid;
++
++	if (!hostnqn)
++		return NULL;
++
++	uuid = strstr(hostnqn, "uuid:");
++	if (!uuid)
++		return NULL;
++
++	return strdup(uuid + strlen("uuid:"));
++}
++
++void nvmf_check_hostid_and_hostnqn(const char *hostid, const char *hostnqn)
++{
++	char *hostid_from_file, *hostid_from_hostnqn;
++
++	if (!hostid)
++		return;
++
++	hostid_from_file = nvmf_hostid_from_file();
++	if (hostid_from_file && strcmp(hostid_from_file, hostid)) {
++		fprintf(stderr, "warning: use generated hostid instead of hostid file\n");
++		free(hostid_from_file);
++	}
++
++	if (!hostnqn)
++		return;
++
++	hostid_from_hostnqn = nvmf_hostid_from_hostnqn(hostnqn);
++	if (hostid_from_hostnqn && strcmp(hostid_from_hostnqn, hostid)) {
++		fprintf(stderr, "warning: use hostid which does not match uuid in hostnqn\n");
++		free(hostid_from_hostnqn);
++	}
++}
++
+ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
+ {
+ 	char *subsysnqn = NVME_DISC_SUBSYS_NAME;
+@@ -765,10 +802,13 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
+ 	hostid_arg = hostid;
+ 	if (!hostnqn)
+ 		hostnqn = hnqn = nvmf_hostnqn_from_file();
+-	if (!hostnqn)
++	if (!hostnqn) {
+ 		hostnqn = hnqn = nvmf_hostnqn_generate();
++		hostid = hid = nvmf_hostid_from_hostnqn(hostnqn);
++	}
+ 	if (!hostid)
+ 		hostid = hid = nvmf_hostid_from_file();
++	nvmf_check_hostid_and_hostnqn(hostid, hostnqn);
+ 	h = nvme_lookup_host(r, hostnqn, hostid);
+ 	if (!h) {
+ 		ret = ENOMEM;
+@@ -978,10 +1018,13 @@ int nvmf_connect(const char *desc, int argc, char **argv)
+ 
+ 	if (!hostnqn)
+ 		hostnqn = hnqn = nvmf_hostnqn_from_file();
+-	if (!hostnqn)
++	if (!hostnqn) {
+ 		hostnqn = hnqn = nvmf_hostnqn_generate();
++		hostid = hid = nvmf_hostid_from_hostnqn(hostnqn);
++	}
+ 	if (!hostid)
+ 		hostid = hid = nvmf_hostid_from_file();
++	nvmf_check_hostid_and_hostnqn(hostid, hostnqn);
+ 	h = nvme_lookup_host(r, hostnqn, hostid);
+ 	if (!h) {
+ 		errno = ENOMEM;
diff --git a/nvme-cli.spec b/nvme-cli.spec
index 8f80740..e5145ac 100644
--- a/nvme-cli.spec
+++ b/nvme-cli.spec
@@ -3,7 +3,7 @@
 
 Name:           nvme-cli
 Version:        2.5
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        NVMe management command line interface
 
 License:        GPLv2
@@ -20,19 +20,13 @@ BuildRequires:  openssl-devel
 BuildRequires:  libnvme-devel >= 1.5
 BuildRequires:  json-c-devel >= 0.13
 
-%if (0%{?rhel} == 0)
-BuildRequires:  python3-nose2
-# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
-#BuildRequires:  python3-mypy
-#BuildRequires:  python3-flake8
-#BuildRequires:  python3-autopep8
-#BuildRequires:  python3-isort
-%endif
 BuildRequires:  asciidoc
 BuildRequires:  xmlto
 
 Requires:       util-linux
 
+Patch0:         nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch
+
 %description
 nvme-cli provides NVM-Express user space tooling for Linux.
 
@@ -84,6 +78,9 @@ rm -rf %{buildroot}%{_pkgdocdir}/nvme
 
 
 %changelog
+* Mon Aug 14 2023 Tomas Bzatek <tbzatek@redhat.com> - 2.5-3
+- Backport 'fabrics: Use corresponding hostid when hostnqn is generated'
+
 * Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 2.5-2
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild