[PATCH 2/2] nvme: add rotational support

Matias Bjørling posted 2 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 2/2] nvme: add rotational support
Posted by Matias Bjørling 1 month, 2 weeks ago
From: Matias Bjørling <matias.bjorling@wdc.com>

Rotational devices, such as hard-drives, can be detected using
the rotational bit in the namespace independent identify namespace
data structure. Make the bit visible to the block layer through the
rotational queue setting.

Note that rotational devices typically can be used to generate random
entropy, the device is therefore also added as a block device that adds
entropy.

Signed-off-by: Matias Bjørling <matias.bjorling@wdc.com>
---
 drivers/nvme/host/core.c | 5 +++++
 include/linux/nvme.h     | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9cbef6342c39..a445f13f5a28 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -41,6 +41,7 @@ struct nvme_ns_info {
 	bool is_readonly;
 	bool is_ready;
 	bool is_removed;
+	bool is_rotational;
 };
 
 unsigned int admin_timeout = 60;
@@ -1623,6 +1624,7 @@ static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,
 		info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
 		info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
 		info->is_ready = id->nstat & NVME_NSTAT_NRDY;
+		info->is_rotational = id->nsfeat & NVME_NS_ROTATIONAL;
 	}
 	kfree(id);
 	return ret;
@@ -2170,6 +2172,9 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 	else
 		lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA);
 
+	if (info->is_rotational)
+		lim.features |= BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM;
+
 	/*
 	 * Register a metadata profile for PI, or the plain non-integrity NVMe
 	 * metadata masquerading as Type 0 if supported, otherwise reject block
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 7b2ae2e43544..6d0eebb57544 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -560,6 +560,7 @@ enum {
 	NVME_NS_FLBAS_LBA_SHIFT	= 1,
 	NVME_NS_FLBAS_META_EXT	= 0x10,
 	NVME_NS_NMIC_SHARED	= 1 << 0,
+	NVME_NS_ROTATIONAL	= 1 << 4,
 	NVME_LBAF_RP_BEST	= 0,
 	NVME_LBAF_RP_BETTER	= 1,
 	NVME_LBAF_RP_GOOD	= 2,
-- 
2.46.0

Re: [PATCH 2/2] nvme: add rotational support
Posted by Christoph Hellwig 1 month, 2 weeks ago
On Tue, Oct 08, 2024 at 04:55:03PM +0200, Matias Bjørling wrote:
> +	if (info->is_rotational)
> +		lim.features |= BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM;

Entropy from block devices is pretty useless.  The only reason we still
keep it for SCSI is because of retro-computing platforms without a proper
platform hardware RNG.  NVMe HDDs reall should not show up in those kinds
of environments.  Also without a add_disk_randomness in the nvme I/O
completion handler this won't actually do anything.
Re: [PATCH 2/2] nvme: add rotational support
Posted by Matias Bjørling 1 month, 2 weeks ago
On 09-10-2024 09:48, Christoph Hellwig wrote:
> On Tue, Oct 08, 2024 at 04:55:03PM +0200, Matias Bjørling wrote:
>> +	if (info->is_rotational)
>> +		lim.features |= BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM;
> 
> Entropy from block devices is pretty useless.  The only reason we still
> keep it for SCSI is because of retro-computing platforms without a proper
> platform hardware RNG.  NVMe HDDs reall should not show up in those kinds
> of environments.  Also without a add_disk_randomness in the nvme I/O
> completion handler this won't actually do anything.
> 

Thanks for the details. I'll remove it in the next revision.
Re: [PATCH 2/2] nvme: add rotational support
Posted by Hannes Reinecke 1 month, 2 weeks ago
On 10/8/24 16:55, Matias Bjørling wrote:
> From: Matias Bjørling <matias.bjorling@wdc.com>
> 
> Rotational devices, such as hard-drives, can be detected using
> the rotational bit in the namespace independent identify namespace
> data structure. Make the bit visible to the block layer through the
> rotational queue setting.
> 
> Note that rotational devices typically can be used to generate random
> entropy, the device is therefore also added as a block device that adds
> entropy.
> 
> Signed-off-by: Matias Bjørling <matias.bjorling@wdc.com>
> ---
>   drivers/nvme/host/core.c | 5 +++++
>   include/linux/nvme.h     | 1 +
>   2 files changed, 6 insertions(+)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich