From nobody Tue Dec 16 16:38:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92C65C4167B for ; Fri, 8 Dec 2023 10:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573453AbjLHKxp (ORCPT ); Fri, 8 Dec 2023 05:53:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573678AbjLHKxj (ORCPT ); Fri, 8 Dec 2023 05:53:39 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A8E115 for ; Fri, 8 Dec 2023 02:53:43 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 755C62118A; Fri, 8 Dec 2023 10:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032822; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2m6nayRKgXH2piN2PWQyDqfFBTz3iS878F9SLHT2gk=; b=VAsuwtecHl5w4CdWFPSJVaP2wx4sqa/BIZepy4NqU9oyKBzaBc4dOktCl+MIvw4rJdqVqg 0hjIMaWi2GmvySgpCKVha4qUGqoK07LCkdig8UckPY1546YKckr6e4VRZJR8qpc8hj7fnO Uj+xqGyNVz5vv/6xnq41DZRcn8MmpkM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032822; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2m6nayRKgXH2piN2PWQyDqfFBTz3iS878F9SLHT2gk=; b=thn4TClagVR/56wXY6TGDKOxhyVWFyZIedjBnO+f5upVfZ0lw7JDjH9rBtXUXyiOgeuOdI YQ6LwnnqSufryRAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032822; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2m6nayRKgXH2piN2PWQyDqfFBTz3iS878F9SLHT2gk=; b=VAsuwtecHl5w4CdWFPSJVaP2wx4sqa/BIZepy4NqU9oyKBzaBc4dOktCl+MIvw4rJdqVqg 0hjIMaWi2GmvySgpCKVha4qUGqoK07LCkdig8UckPY1546YKckr6e4VRZJR8qpc8hj7fnO Uj+xqGyNVz5vv/6xnq41DZRcn8MmpkM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032822; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2m6nayRKgXH2piN2PWQyDqfFBTz3iS878F9SLHT2gk=; b=thn4TClagVR/56wXY6TGDKOxhyVWFyZIedjBnO+f5upVfZ0lw7JDjH9rBtXUXyiOgeuOdI YQ6LwnnqSufryRAw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 62168138FF; Fri, 8 Dec 2023 10:53:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id Cj9+Frb1cmUxVgAAn2gu4w (envelope-from ); Fri, 08 Dec 2023 10:53:42 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v5 1/6] nvme: move ns id info to struct nvme_ns_head Date: Fri, 8 Dec 2023 11:53:32 +0100 Message-ID: <20231208105337.23409-2-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208105337.23409-1-dwagner@suse.de> References: <20231208105337.23409-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] Authentication-Results: smtp-out1.suse.de; none Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the namesapce info to struct nvme_ns_head, because it's the same for all associated namespaces. Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig --- drivers/nvme/host/core.c | 81 ++++++++++++++++++++------------------- drivers/nvme/host/ioctl.c | 8 ++-- drivers/nvme/host/nvme.h | 28 +++++++------- drivers/nvme/host/rdma.c | 2 +- drivers/nvme/host/zns.c | 17 ++++---- 5 files changed, 70 insertions(+), 66 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d699f0c8b13e..72908e622049 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -312,12 +312,12 @@ static void nvme_log_error(struct request *req) struct nvme_request *nr =3D nvme_req(req); =20 if (ns) { - pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %llu blocks, %s (sct 0x%x /= sc 0x%x) %s%s\n", + pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %u blocks, %s (sct 0x%x / s= c 0x%x) %s%s\n", ns->disk ? ns->disk->disk_name : "?", nvme_get_opcode_str(nr->cmd->common.opcode), nr->cmd->common.opcode, - (unsigned long long)nvme_sect_to_lba(ns, blk_rq_pos(req)), - (unsigned long long)blk_rq_bytes(req) >> ns->lba_shift, + nvme_sect_to_lba(ns, blk_rq_pos(req)), + blk_rq_bytes(req) >> ns->head->lba_shift, nvme_get_error_status_str(nr->status), nr->status >> 8 & 7, /* Status Code Type */ nr->status & 0xff, /* Status Code */ @@ -794,7 +794,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, =20 if (queue_max_discard_segments(req->q) =3D=3D 1) { u64 slba =3D nvme_sect_to_lba(ns, blk_rq_pos(req)); - u32 nlb =3D blk_rq_sectors(req) >> (ns->lba_shift - 9); + u32 nlb =3D blk_rq_sectors(req) >> (ns->head->lba_shift - 9); =20 range[0].cattr =3D cpu_to_le32(0); range[0].nlb =3D cpu_to_le32(nlb); @@ -803,7 +803,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, } else { __rq_for_each_bio(bio, req) { u64 slba =3D nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); - u32 nlb =3D bio->bi_iter.bi_size >> ns->lba_shift; + u32 nlb =3D bio->bi_iter.bi_size >> ns->head->lba_shift; =20 if (n < segments) { range[n].cattr =3D cpu_to_le32(0); @@ -841,7 +841,7 @@ static void nvme_set_ref_tag(struct nvme_ns *ns, struct= nvme_command *cmnd, u64 ref48; =20 /* both rw and write zeroes share the same reftag format */ - switch (ns->guard_type) { + switch (ns->head->guard_type) { case NVME_NVM_NS_16B_GUARD: cmnd->rw.reftag =3D cpu_to_le32(t10_pi_ref_tag(req)); break; @@ -871,15 +871,16 @@ static inline blk_status_t nvme_setup_write_zeroes(st= ruct nvme_ns *ns, cmnd->write_zeroes.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); cmnd->write_zeroes.length =3D - cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); + cpu_to_le16((blk_rq_bytes(req) >> ns->head->lba_shift) - 1); =20 - if (!(req->cmd_flags & REQ_NOUNMAP) && (ns->features & NVME_NS_DEAC)) + if (!(req->cmd_flags & REQ_NOUNMAP) && + (ns->head->features & NVME_NS_DEAC)) cmnd->write_zeroes.control |=3D cpu_to_le16(NVME_WZ_DEAC); =20 if (nvme_ns_has_pi(ns)) { cmnd->write_zeroes.control |=3D cpu_to_le16(NVME_RW_PRINFO_PRACT); =20 - switch (ns->pi_type) { + switch (ns->head->pi_type) { case NVME_NS_DPS_PI_TYPE1: case NVME_NS_DPS_PI_TYPE2: nvme_set_ref_tag(ns, cmnd, req); @@ -912,12 +913,13 @@ static inline blk_status_t nvme_setup_rw(struct nvme_= ns *ns, cmnd->rw.cdw3 =3D 0; cmnd->rw.metadata =3D 0; cmnd->rw.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); - cmnd->rw.length =3D cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); + cmnd->rw.length =3D + cpu_to_le16((blk_rq_bytes(req) >> ns->head->lba_shift) - 1); cmnd->rw.reftag =3D 0; cmnd->rw.apptag =3D 0; cmnd->rw.appmask =3D 0; =20 - if (ns->ms) { + if (ns->head->ms) { /* * If formated with metadata, the block layer always provides a * metadata buffer if CONFIG_BLK_DEV_INTEGRITY is enabled. Else @@ -930,7 +932,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns= *ns, control |=3D NVME_RW_PRINFO_PRACT; } =20 - switch (ns->pi_type) { + switch (ns->head->pi_type) { case NVME_NS_DPS_PI_TYPE3: control |=3D NVME_RW_PRINFO_PRCHK_GUARD; break; @@ -1676,9 +1678,9 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, { struct blk_integrity integrity =3D { }; =20 - switch (ns->pi_type) { + switch (ns->head->pi_type) { case NVME_NS_DPS_PI_TYPE3: - switch (ns->guard_type) { + switch (ns->head->guard_type) { case NVME_NVM_NS_16B_GUARD: integrity.profile =3D &t10_pi_type3_crc; integrity.tag_size =3D sizeof(u16) + sizeof(u32); @@ -1696,7 +1698,7 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, break; case NVME_NS_DPS_PI_TYPE1: case NVME_NS_DPS_PI_TYPE2: - switch (ns->guard_type) { + switch (ns->head->guard_type) { case NVME_NVM_NS_16B_GUARD: integrity.profile =3D &t10_pi_type1_crc; integrity.tag_size =3D sizeof(u16); @@ -1717,7 +1719,7 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, break; } =20 - integrity.tuple_size =3D ns->ms; + integrity.tuple_size =3D ns->head->ms; blk_integrity_register(disk, &integrity); blk_queue_max_integrity_segments(disk->queue, max_integrity_segments); } @@ -1776,11 +1778,11 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) int ret =3D 0; u32 elbaf; =20 - ns->pi_size =3D 0; - ns->ms =3D le16_to_cpu(id->lbaf[lbaf].ms); + ns->head->pi_size =3D 0; + ns->head->ms =3D le16_to_cpu(id->lbaf[lbaf].ms); if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { - ns->pi_size =3D sizeof(struct t10_pi_tuple); - ns->guard_type =3D NVME_NVM_NS_16B_GUARD; + ns->head->pi_size =3D sizeof(struct t10_pi_tuple); + ns->head->guard_type =3D NVME_NVM_NS_16B_GUARD; goto set_pi; } =20 @@ -1803,13 +1805,13 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) if (nvme_elbaf_sts(elbaf)) goto free_data; =20 - ns->guard_type =3D nvme_elbaf_guard_type(elbaf); - switch (ns->guard_type) { + ns->head->guard_type =3D nvme_elbaf_guard_type(elbaf); + switch (ns->head->guard_type) { case NVME_NVM_NS_64B_GUARD: - ns->pi_size =3D sizeof(struct crc64_pi_tuple); + ns->head->pi_size =3D sizeof(struct crc64_pi_tuple); break; case NVME_NVM_NS_16B_GUARD: - ns->pi_size =3D sizeof(struct t10_pi_tuple); + ns->head->pi_size =3D sizeof(struct t10_pi_tuple); break; default: break; @@ -1818,10 +1820,10 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) free_data: kfree(nvm); set_pi: - if (ns->pi_size && (first || ns->ms =3D=3D ns->pi_size)) - ns->pi_type =3D id->dps & NVME_NS_DPS_PI_MASK; + if (ns->head->pi_size && (first || ns->head->ms =3D=3D ns->head->pi_size)) + ns->head->pi_type =3D id->dps & NVME_NS_DPS_PI_MASK; else - ns->pi_type =3D 0; + ns->head->pi_type =3D 0; =20 return ret; } @@ -1835,8 +1837,8 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) if (ret) return ret; =20 - ns->features &=3D ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); - if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) + ns->head->features &=3D ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); + if (!ns->head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) return 0; =20 if (ctrl->ops->flags & NVME_F_FABRICS) { @@ -1848,7 +1850,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT))) return 0; =20 - ns->features |=3D NVME_NS_EXT_LBAS; + ns->head->features |=3D NVME_NS_EXT_LBAS; =20 /* * The current fabrics transport drivers support namespace @@ -1860,7 +1862,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * gain the ability to use other metadata formats. */ if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)) - ns->features |=3D NVME_NS_METADATA_SUPPORTED; + ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; } else { /* * For PCIe controllers, we can't easily remap the separate @@ -1869,9 +1871,9 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * We allow extended LBAs for the passthrough interface, though. */ if (id->flbas & NVME_NS_FLBAS_META_EXT) - ns->features |=3D NVME_NS_EXT_LBAS; + ns->head->features |=3D NVME_NS_EXT_LBAS; else - ns->features |=3D NVME_NS_METADATA_SUPPORTED; + ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; } return 0; } @@ -1898,7 +1900,7 @@ static void nvme_update_disk_info(struct gendisk *dis= k, struct nvme_ns *ns, struct nvme_id_ns *id) { sector_t capacity =3D nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); - u32 bs =3D 1U << ns->lba_shift; + u32 bs =3D 1U << ns->head->lba_shift; u32 atomic_bs, phys_bs, io_opt =3D 0; =20 /* @@ -1906,7 +1908,8 @@ static void nvme_update_disk_info(struct gendisk *dis= k, * or smaller than a sector size yet, so catch this early and don't * allow block I/O. */ - if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) { + if (ns->head->lba_shift > PAGE_SHIFT || + ns->head->lba_shift < SECTOR_SHIFT) { capacity =3D 0; bs =3D (1 << 9); } @@ -1949,9 +1952,9 @@ static void nvme_update_disk_info(struct gendisk *dis= k, * I/O to namespaces with metadata except when the namespace supports * PI, as it can strip/insert in that case. */ - if (ns->ms) { + if (ns->head->ms) { if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) && - (ns->features & NVME_NS_METADATA_SUPPORTED)) + (ns->head->features & NVME_NS_METADATA_SUPPORTED)) nvme_init_integrity(disk, ns, ns->ctrl->max_integrity_segments); else if (!nvme_ns_has_pi(ns)) @@ -2052,7 +2055,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, =20 blk_mq_freeze_queue(ns->disk->queue); lbaf =3D nvme_lbaf_index(id->flbas); - ns->lba_shift =3D id->lbaf[lbaf].ds; + ns->head->lba_shift =3D id->lbaf[lbaf].ds; nvme_set_queue_limits(ns->ctrl, ns->queue); =20 ret =3D nvme_configure_metadata(ns, id); @@ -2078,7 +2081,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, * do not return zeroes. */ if ((id->dlfeat & 0x7) =3D=3D 0x1 && (id->dlfeat & (1 << 3))) - ns->features |=3D NVME_NS_DEAC; + ns->head->features |=3D NVME_NS_DEAC; set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info)); set_bit(NVME_NS_READY, &ns->flags); blk_mq_unfreeze_queue(ns->disk->queue); diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 529b9954d2b8..feee9cf50670 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -283,10 +283,10 @@ static int nvme_submit_io(struct nvme_ns *ns, struct = nvme_user_io __user *uio) return -EINVAL; } =20 - length =3D (io.nblocks + 1) << ns->lba_shift; + length =3D (io.nblocks + 1) << ns->head->lba_shift; =20 if ((io.control & NVME_RW_PRINFO_PRACT) && - ns->ms =3D=3D sizeof(struct t10_pi_tuple)) { + ns->head->ms =3D=3D sizeof(struct t10_pi_tuple)) { /* * Protection information is stripped/inserted by the * controller. @@ -296,11 +296,11 @@ static int nvme_submit_io(struct nvme_ns *ns, struct = nvme_user_io __user *uio) meta_len =3D 0; metadata =3D NULL; } else { - meta_len =3D (io.nblocks + 1) * ns->ms; + meta_len =3D (io.nblocks + 1) * ns->head->ms; metadata =3D nvme_to_user_ptr(io.metadata); } =20 - if (ns->features & NVME_NS_EXT_LBAS) { + if (ns->head->features & NVME_NS_EXT_LBAS) { length +=3D meta_len; meta_len =3D 0; } else if (meta_len) { diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 578e6d311bc9..1ebe6a9b42c9 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -451,6 +451,17 @@ struct nvme_ns_head { bool shared; int instance; struct nvme_effects_log *effects; + int lba_shift; + u16 ms; + u16 pi_size; + u16 sgs; + u32 sws; + u8 pi_type; + u8 guard_type; +#ifdef CONFIG_BLK_DEV_ZONED + u64 zsze; +#endif + unsigned long features; =20 struct cdev cdev; struct device cdev_device; @@ -492,17 +503,6 @@ struct nvme_ns { struct kref kref; struct nvme_ns_head *head; =20 - int lba_shift; - u16 ms; - u16 pi_size; - u16 sgs; - u32 sws; - u8 pi_type; - u8 guard_type; -#ifdef CONFIG_BLK_DEV_ZONED - u64 zsze; -#endif - unsigned long features; unsigned long flags; #define NVME_NS_REMOVING 0 #define NVME_NS_ANA_PENDING 2 @@ -519,7 +519,7 @@ struct nvme_ns { /* NVMe ns supports metadata actions by the controller (generate/strip) */ static inline bool nvme_ns_has_pi(struct nvme_ns *ns) { - return ns->pi_type && ns->ms =3D=3D ns->pi_size; + return ns->head->pi_type && ns->head->ms =3D=3D ns->head->pi_size; } =20 struct nvme_ctrl_ops { @@ -653,7 +653,7 @@ static inline int nvme_reset_subsystem(struct nvme_ctrl= *ctrl) */ static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) { - return sector >> (ns->lba_shift - SECTOR_SHIFT); + return sector >> (ns->head->lba_shift - SECTOR_SHIFT); } =20 /* @@ -661,7 +661,7 @@ static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, = sector_t sector) */ static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba) { - return lba << (ns->lba_shift - SECTOR_SHIFT); + return lba << (ns->head->lba_shift - SECTOR_SHIFT); } =20 /* diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 81e2621169e5..fc0df91e6b36 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1423,7 +1423,7 @@ static int nvme_rdma_map_sg_pi(struct nvme_rdma_queue= *queue, goto mr_put; =20 nvme_rdma_set_sig_attrs(blk_get_integrity(bio->bi_bdev->bd_disk), c, - req->mr->sig_attrs, ns->pi_type); + req->mr->sig_attrs, ns->head->pi_type); nvme_rdma_set_prot_checks(c, &req->mr->sig_attrs->check_mask); =20 ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey)); diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index ec8557810c21..fa9e8f664ae7 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -11,7 +11,7 @@ int nvme_revalidate_zones(struct nvme_ns *ns) { struct request_queue *q =3D ns->queue; =20 - blk_queue_chunk_sectors(q, ns->zsze); + blk_queue_chunk_sectors(q, ns->head->zsze); blk_queue_max_zone_append_sectors(q, ns->ctrl->max_zone_append); =20 return blk_revalidate_disk_zones(ns->disk, NULL); @@ -99,11 +99,12 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned = lbaf) goto free_data; } =20 - ns->zsze =3D nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); - if (!is_power_of_2(ns->zsze)) { + ns->head->zsze =3D + nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); + if (!is_power_of_2(ns->head->zsze)) { dev_warn(ns->ctrl->device, "invalid zone size:%llu for namespace:%u\n", - ns->zsze, ns->head->ns_id); + ns->head->zsze, ns->head->ns_id); status =3D -ENODEV; goto free_data; } @@ -128,7 +129,7 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_n= s *ns, sizeof(struct nvme_zone_descriptor); =20 nr_zones =3D min_t(unsigned int, nr_zones, - get_capacity(ns->disk) >> ilog2(ns->zsze)); + get_capacity(ns->disk) >> ilog2(ns->head->zsze)); =20 bufsize =3D sizeof(struct nvme_zone_report) + nr_zones * sizeof(struct nvme_zone_descriptor); @@ -162,7 +163,7 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns, =20 zone.type =3D BLK_ZONE_TYPE_SEQWRITE_REQ; zone.cond =3D entry->zs >> 4; - zone.len =3D ns->zsze; + zone.len =3D ns->head->zsze; zone.capacity =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->zcap)); zone.start =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->zslba)); if (zone.cond =3D=3D BLK_ZONE_COND_FULL) @@ -196,7 +197,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t s= ector, c.zmr.zrasf =3D NVME_ZRASF_ZONE_REPORT_ALL; c.zmr.pr =3D NVME_REPORT_ZONE_PARTIAL; =20 - sector &=3D ~(ns->zsze - 1); + sector &=3D ~(ns->head->zsze - 1); while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); =20 @@ -220,7 +221,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t s= ector, zone_idx++; } =20 - sector +=3D ns->zsze * nz; + sector +=3D ns->head->zsze * nz; } =20 if (zone_idx > 0) --=20 2.43.0 From nobody Tue Dec 16 16:38:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0461C4167B for ; Fri, 8 Dec 2023 10:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573737AbjLHKxs (ORCPT ); Fri, 8 Dec 2023 05:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573647AbjLHKxj (ORCPT ); Fri, 8 Dec 2023 05:53:39 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89C37171C for ; Fri, 8 Dec 2023 02:53:44 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 14BF02118B; Fri, 8 Dec 2023 10:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fHbk2JjN7EXvP8PeM1oaou4QbQonJ3GZrk3q5E8KEm4=; b=XCTLfJQFrAlnMgYkSmP1fycJ0+yxoQRXLa3Mu0CgoTJ0M1AGD14UstEuoU5P/SlWx9K5g9 ytIUxIFoN8n6t+HlgU7fkxrsNlEIIBqW0XoWT6Z4hgriA+5gt9heqzDNhxUsu7G7vLttuH Xt+P3NK5lj22rFI8Nd6qQgWkr6V9ieA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fHbk2JjN7EXvP8PeM1oaou4QbQonJ3GZrk3q5E8KEm4=; b=SwSe8+akkJW9NZu5+m1wTYXShU1U42R5ReSWsyLofYDlWpbiEoDgT0pVOdZy4+LyZp1/Kg Y1vFn5pl0RKo1EDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fHbk2JjN7EXvP8PeM1oaou4QbQonJ3GZrk3q5E8KEm4=; b=XCTLfJQFrAlnMgYkSmP1fycJ0+yxoQRXLa3Mu0CgoTJ0M1AGD14UstEuoU5P/SlWx9K5g9 ytIUxIFoN8n6t+HlgU7fkxrsNlEIIBqW0XoWT6Z4hgriA+5gt9heqzDNhxUsu7G7vLttuH Xt+P3NK5lj22rFI8Nd6qQgWkr6V9ieA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fHbk2JjN7EXvP8PeM1oaou4QbQonJ3GZrk3q5E8KEm4=; b=SwSe8+akkJW9NZu5+m1wTYXShU1U42R5ReSWsyLofYDlWpbiEoDgT0pVOdZy4+LyZp1/Kg Y1vFn5pl0RKo1EDA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 026AB138FF; Fri, 8 Dec 2023 10:53:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id AOW3Orb1cmUzVgAAn2gu4w (envelope-from ); Fri, 08 Dec 2023 10:53:42 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v5 2/6] nvme: refactor ns info helpers Date: Fri, 8 Dec 2023 11:53:33 +0100 Message-ID: <20231208105337.23409-3-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208105337.23409-1-dwagner@suse.de> References: <20231208105337.23409-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=XCTLfJQF; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=SwSe8+ak; dmarc=pass (policy=none) header.from=suse.de; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:98 is neither permitted nor denied by domain of dwagner@suse.de) smtp.mailfrom=dwagner@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-9.01 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+]; DMARC_POLICY_ALLOW(0.00)[suse.de,none]; RCPT_COUNT_SEVEN(0.00)[7]; MX_GOOD(-0.01)[]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; WHITELIST_DMARC(-7.00)[suse.de:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 14BF02118B Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Pass in the nvme_ns_head pointer directly. This reduces the necessity on the caller side have the nvme_ns data structure present. Thus we can refactor the caller side in the next step as well. Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 36 +++++++++++++++++++++--------------- drivers/nvme/host/nvme.h | 12 ++++++------ drivers/nvme/host/rdma.c | 2 +- drivers/nvme/host/zns.c | 12 ++++++------ 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 72908e622049..f0fe41afc958 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -316,7 +316,7 @@ static void nvme_log_error(struct request *req) ns->disk ? ns->disk->disk_name : "?", nvme_get_opcode_str(nr->cmd->common.opcode), nr->cmd->common.opcode, - nvme_sect_to_lba(ns, blk_rq_pos(req)), + nvme_sect_to_lba(ns->head, blk_rq_pos(req)), blk_rq_bytes(req) >> ns->head->lba_shift, nvme_get_error_status_str(nr->status), nr->status >> 8 & 7, /* Status Code Type */ @@ -372,9 +372,12 @@ static inline enum nvme_disposition nvme_decide_dispos= ition(struct request *req) static inline void nvme_end_req_zoned(struct request *req) { if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && - req_op(req) =3D=3D REQ_OP_ZONE_APPEND) - req->__sector =3D nvme_lba_to_sect(req->q->queuedata, + req_op(req) =3D=3D REQ_OP_ZONE_APPEND) { + struct nvme_ns *ns =3D req->q->queuedata; + + req->__sector =3D nvme_lba_to_sect(ns->head, le64_to_cpu(nvme_req(req)->result.u64)); + } } =20 static inline void nvme_end_req(struct request *req) @@ -793,7 +796,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, } =20 if (queue_max_discard_segments(req->q) =3D=3D 1) { - u64 slba =3D nvme_sect_to_lba(ns, blk_rq_pos(req)); + u64 slba =3D nvme_sect_to_lba(ns->head, blk_rq_pos(req)); u32 nlb =3D blk_rq_sectors(req) >> (ns->head->lba_shift - 9); =20 range[0].cattr =3D cpu_to_le32(0); @@ -802,7 +805,8 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, n =3D 1; } else { __rq_for_each_bio(bio, req) { - u64 slba =3D nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); + u64 slba =3D nvme_sect_to_lba(ns->head, + bio->bi_iter.bi_sector); u32 nlb =3D bio->bi_iter.bi_size >> ns->head->lba_shift; =20 if (n < segments) { @@ -869,7 +873,7 @@ static inline blk_status_t nvme_setup_write_zeroes(stru= ct nvme_ns *ns, cmnd->write_zeroes.opcode =3D nvme_cmd_write_zeroes; cmnd->write_zeroes.nsid =3D cpu_to_le32(ns->head->ns_id); cmnd->write_zeroes.slba =3D - cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); + cpu_to_le64(nvme_sect_to_lba(ns->head, blk_rq_pos(req))); cmnd->write_zeroes.length =3D cpu_to_le16((blk_rq_bytes(req) >> ns->head->lba_shift) - 1); =20 @@ -877,7 +881,7 @@ static inline blk_status_t nvme_setup_write_zeroes(stru= ct nvme_ns *ns, (ns->head->features & NVME_NS_DEAC)) cmnd->write_zeroes.control |=3D cpu_to_le16(NVME_WZ_DEAC); =20 - if (nvme_ns_has_pi(ns)) { + if (nvme_ns_has_pi(ns->head)) { cmnd->write_zeroes.control |=3D cpu_to_le16(NVME_RW_PRINFO_PRACT); =20 switch (ns->head->pi_type) { @@ -912,7 +916,8 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns= *ns, cmnd->rw.cdw2 =3D 0; cmnd->rw.cdw3 =3D 0; cmnd->rw.metadata =3D 0; - cmnd->rw.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); + cmnd->rw.slba =3D + cpu_to_le64(nvme_sect_to_lba(ns->head, blk_rq_pos(req))); cmnd->rw.length =3D cpu_to_le16((blk_rq_bytes(req) >> ns->head->lba_shift) - 1); cmnd->rw.reftag =3D 0; @@ -927,7 +932,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns= *ns, * namespace capacity to zero to prevent any I/O. */ if (!blk_integrity_rq(req)) { - if (WARN_ON_ONCE(!nvme_ns_has_pi(ns))) + if (WARN_ON_ONCE(!nvme_ns_has_pi(ns->head))) return BLK_STS_NOTSUPP; control |=3D NVME_RW_PRINFO_PRACT; } @@ -1736,8 +1741,9 @@ static void nvme_config_discard(struct gendisk *disk,= struct nvme_ns *ns) struct request_queue *queue =3D disk->queue; u32 size =3D queue_logical_block_size(queue); =20 - if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns, UINT_MAX)) - ctrl->max_discard_sectors =3D nvme_lba_to_sect(ns, ctrl->dmrsl); + if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) + ctrl->max_discard_sectors =3D + nvme_lba_to_sect(ns->head, ctrl->dmrsl); =20 if (ctrl->max_discard_sectors =3D=3D 0) { blk_queue_max_discard_sectors(queue, 0); @@ -1861,7 +1867,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * Note, this check will need to be modified if any drivers * gain the ability to use other metadata formats. */ - if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)) + if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns->head)) ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; } else { /* @@ -1899,7 +1905,7 @@ static void nvme_set_queue_limits(struct nvme_ctrl *c= trl, static void nvme_update_disk_info(struct gendisk *disk, struct nvme_ns *ns, struct nvme_id_ns *id) { - sector_t capacity =3D nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); + sector_t capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze)); u32 bs =3D 1U << ns->head->lba_shift; u32 atomic_bs, phys_bs, io_opt =3D 0; =20 @@ -1957,7 +1963,7 @@ static void nvme_update_disk_info(struct gendisk *dis= k, (ns->head->features & NVME_NS_METADATA_SUPPORTED)) nvme_init_integrity(disk, ns, ns->ctrl->max_integrity_segments); - else if (!nvme_ns_has_pi(ns)) + else if (!nvme_ns_has_pi(ns->head)) capacity =3D 0; } =20 @@ -1988,7 +1994,7 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns= , struct nvme_id_ns *id) is_power_of_2(ctrl->max_hw_sectors)) iob =3D ctrl->max_hw_sectors; else - iob =3D nvme_lba_to_sect(ns, le16_to_cpu(id->noiob)); + iob =3D nvme_lba_to_sect(ns->head, le16_to_cpu(id->noiob)); =20 if (!iob) return; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 1ebe6a9b42c9..eb748cc3e897 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -517,9 +517,9 @@ struct nvme_ns { }; =20 /* NVMe ns supports metadata actions by the controller (generate/strip) */ -static inline bool nvme_ns_has_pi(struct nvme_ns *ns) +static inline bool nvme_ns_has_pi(struct nvme_ns_head *head) { - return ns->head->pi_type && ns->head->ms =3D=3D ns->head->pi_size; + return head->pi_type && head->ms =3D=3D head->pi_size; } =20 struct nvme_ctrl_ops { @@ -651,17 +651,17 @@ static inline int nvme_reset_subsystem(struct nvme_ct= rl *ctrl) /* * Convert a 512B sector number to a device logical block number. */ -static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) +static inline u64 nvme_sect_to_lba(struct nvme_ns_head *head, sector_t sec= tor) { - return sector >> (ns->head->lba_shift - SECTOR_SHIFT); + return sector >> (head->lba_shift - SECTOR_SHIFT); } =20 /* * Convert a device logical block number to a 512B sector number. */ -static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba) +static inline sector_t nvme_lba_to_sect(struct nvme_ns_head *head, u64 lba) { - return lba << (ns->head->lba_shift - SECTOR_SHIFT); + return lba << (head->lba_shift - SECTOR_SHIFT); } =20 /* diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index fc0df91e6b36..c89503da24d7 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -2017,7 +2017,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_= hw_ctx *hctx, queue->pi_support && (c->common.opcode =3D=3D nvme_cmd_write || c->common.opcode =3D=3D nvme_cmd_read) && - nvme_ns_has_pi(ns)) + nvme_ns_has_pi(ns->head)) req->use_sig_mr =3D true; else req->use_sig_mr =3D false; diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index fa9e8f664ae7..ded52ab05424 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -100,7 +100,7 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned = lbaf) } =20 ns->head->zsze =3D - nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); + nvme_lba_to_sect(ns->head, le64_to_cpu(id->lbafe[lbaf].zsze)); if (!is_power_of_2(ns->head->zsze)) { dev_warn(ns->ctrl->device, "invalid zone size:%llu for namespace:%u\n", @@ -164,12 +164,12 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns, zone.type =3D BLK_ZONE_TYPE_SEQWRITE_REQ; zone.cond =3D entry->zs >> 4; zone.len =3D ns->head->zsze; - zone.capacity =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->zcap)); - zone.start =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->zslba)); + zone.capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->zcap)); + zone.start =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->zslba)); if (zone.cond =3D=3D BLK_ZONE_COND_FULL) zone.wp =3D zone.start + zone.len; else - zone.wp =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->wp)); + zone.wp =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->wp)); =20 return cb(&zone, idx, data); } @@ -201,7 +201,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t s= ector, while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); =20 - c.zmr.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, sector)); + c.zmr.slba =3D cpu_to_le64(nvme_sect_to_lba(ns->head, sector)); ret =3D nvme_submit_sync_cmd(ns->queue, &c, report, buflen); if (ret) { if (ret > 0) @@ -240,7 +240,7 @@ blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *= ns, struct request *req, =20 c->zms.opcode =3D nvme_cmd_zone_mgmt_send; c->zms.nsid =3D cpu_to_le32(ns->head->ns_id); - c->zms.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); + c->zms.slba =3D cpu_to_le64(nvme_sect_to_lba(ns->head, blk_rq_pos(req))); c->zms.zsa =3D action; =20 if (req_op(req) =3D=3D REQ_OP_ZONE_RESET_ALL) --=20 2.43.0 From nobody Tue Dec 16 16:38:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B734C4167B for ; Fri, 8 Dec 2023 10:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573762AbjLHKx5 (ORCPT ); Fri, 8 Dec 2023 05:53:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573683AbjLHKxk (ORCPT ); Fri, 8 Dec 2023 05:53:40 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C8CCAC for ; Fri, 8 Dec 2023 02:53:45 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B0DAB2118D; Fri, 8 Dec 2023 10:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FBiDaOFzP8RLJjbUw4tyCylAQX06GbRBT0ixmFvMiM=; b=Yrn/Ettdd2uAK4Hp3j7LSZxcFDmQ6BNHa8J/GRiW9YE5gt/NBdN81zY4G2n6HHdK/ndzqa JfwJANI7d3eR3ur3qsWD0KMtIGADyuUvU+JrIifB9YsHh6FQb19XqmECdxc9YWwuGZpVqm UDSOg1bGZKtdlvx9pdCdz3YvPCRUtpY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FBiDaOFzP8RLJjbUw4tyCylAQX06GbRBT0ixmFvMiM=; b=ekL8eaKY1UUk+hYG/myghSVMWc+sSa/bBjv34/xBh5FZyr6sduBhrBcLKOirtteLdzCzq2 wNv+JmXZzj3+LPDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FBiDaOFzP8RLJjbUw4tyCylAQX06GbRBT0ixmFvMiM=; b=Yrn/Ettdd2uAK4Hp3j7LSZxcFDmQ6BNHa8J/GRiW9YE5gt/NBdN81zY4G2n6HHdK/ndzqa JfwJANI7d3eR3ur3qsWD0KMtIGADyuUvU+JrIifB9YsHh6FQb19XqmECdxc9YWwuGZpVqm UDSOg1bGZKtdlvx9pdCdz3YvPCRUtpY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FBiDaOFzP8RLJjbUw4tyCylAQX06GbRBT0ixmFvMiM=; b=ekL8eaKY1UUk+hYG/myghSVMWc+sSa/bBjv34/xBh5FZyr6sduBhrBcLKOirtteLdzCzq2 wNv+JmXZzj3+LPDw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 94F6A138FF; Fri, 8 Dec 2023 10:53:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id DYfcIrf1cmU3VgAAn2gu4w (envelope-from ); Fri, 08 Dec 2023 10:53:43 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v5 3/6] nvme: refactor ns info setup function Date: Fri, 8 Dec 2023 11:53:34 +0100 Message-ID: <20231208105337.23409-4-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208105337.23409-1-dwagner@suse.de> References: <20231208105337.23409-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] Authentication-Results: smtp-out1.suse.de; none Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use nvme_ns_head instead of nvme_ns where possible. This reduces the coupling between the different data structures. Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 107 +++++++++++++++++++-------------------- drivers/nvme/host/zns.c | 16 +++--- 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f0fe41afc958..2468076d64c6 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1678,14 +1678,14 @@ int nvme_getgeo(struct block_device *bdev, struct h= d_geometry *geo) } =20 #ifdef CONFIG_BLK_DEV_INTEGRITY -static void nvme_init_integrity(struct gendisk *disk, struct nvme_ns *ns, - u32 max_integrity_segments) +static void nvme_init_integrity(struct gendisk *disk, + struct nvme_ns_head *head, u32 max_integrity_segments) { struct blk_integrity integrity =3D { }; =20 - switch (ns->head->pi_type) { + switch (head->pi_type) { case NVME_NS_DPS_PI_TYPE3: - switch (ns->head->guard_type) { + switch (head->guard_type) { case NVME_NVM_NS_16B_GUARD: integrity.profile =3D &t10_pi_type3_crc; integrity.tag_size =3D sizeof(u16) + sizeof(u32); @@ -1703,7 +1703,7 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, break; case NVME_NS_DPS_PI_TYPE1: case NVME_NS_DPS_PI_TYPE2: - switch (ns->head->guard_type) { + switch (head->guard_type) { case NVME_NVM_NS_16B_GUARD: integrity.profile =3D &t10_pi_type1_crc; integrity.tag_size =3D sizeof(u16); @@ -1724,26 +1724,26 @@ static void nvme_init_integrity(struct gendisk *dis= k, struct nvme_ns *ns, break; } =20 - integrity.tuple_size =3D ns->head->ms; + integrity.tuple_size =3D head->ms; blk_integrity_register(disk, &integrity); blk_queue_max_integrity_segments(disk->queue, max_integrity_segments); } #else -static void nvme_init_integrity(struct gendisk *disk, struct nvme_ns *ns, - u32 max_integrity_segments) +static void nvme_init_integrity(struct gendisk *disk, + struct nvme_ns_head *head, u32 max_integrity_segments) { } #endif /* CONFIG_BLK_DEV_INTEGRITY */ =20 -static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) +static void nvme_config_discard(struct nvme_ctrl *ctrl, struct gendisk *di= sk, + struct nvme_ns_head *head) { - struct nvme_ctrl *ctrl =3D ns->ctrl; struct request_queue *queue =3D disk->queue; u32 size =3D queue_logical_block_size(queue); =20 - if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) + if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(head, UINT_MAX)) ctrl->max_discard_sectors =3D - nvme_lba_to_sect(ns->head, ctrl->dmrsl); + nvme_lba_to_sect(head, ctrl->dmrsl); =20 if (ctrl->max_discard_sectors =3D=3D 0) { blk_queue_max_discard_sectors(queue, 0); @@ -1774,21 +1774,21 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a= , struct nvme_ns_ids *b) a->csi =3D=3D b->csi; } =20 -static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id) +static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + struct nvme_id_ns *id) { bool first =3D id->dps & NVME_NS_DPS_PI_FIRST; unsigned lbaf =3D nvme_lbaf_index(id->flbas); - struct nvme_ctrl *ctrl =3D ns->ctrl; struct nvme_command c =3D { }; struct nvme_id_ns_nvm *nvm; int ret =3D 0; u32 elbaf; =20 - ns->head->pi_size =3D 0; - ns->head->ms =3D le16_to_cpu(id->lbaf[lbaf].ms); + head->pi_size =3D 0; + head->ms =3D le16_to_cpu(id->lbaf[lbaf].ms); if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { - ns->head->pi_size =3D sizeof(struct t10_pi_tuple); - ns->head->guard_type =3D NVME_NVM_NS_16B_GUARD; + head->pi_size =3D sizeof(struct t10_pi_tuple); + head->guard_type =3D NVME_NVM_NS_16B_GUARD; goto set_pi; } =20 @@ -1797,11 +1797,11 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) return -ENOMEM; =20 c.identify.opcode =3D nvme_admin_identify; - c.identify.nsid =3D cpu_to_le32(ns->head->ns_id); + c.identify.nsid =3D cpu_to_le32(head->ns_id); c.identify.cns =3D NVME_ID_CNS_CS_NS; c.identify.csi =3D NVME_CSI_NVM; =20 - ret =3D nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, nvm, sizeof(*nvm)); + ret =3D nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm)); if (ret) goto free_data; =20 @@ -1811,13 +1811,13 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) if (nvme_elbaf_sts(elbaf)) goto free_data; =20 - ns->head->guard_type =3D nvme_elbaf_guard_type(elbaf); - switch (ns->head->guard_type) { + head->guard_type =3D nvme_elbaf_guard_type(elbaf); + switch (head->guard_type) { case NVME_NVM_NS_64B_GUARD: - ns->head->pi_size =3D sizeof(struct crc64_pi_tuple); + head->pi_size =3D sizeof(struct crc64_pi_tuple); break; case NVME_NVM_NS_16B_GUARD: - ns->head->pi_size =3D sizeof(struct t10_pi_tuple); + head->pi_size =3D sizeof(struct t10_pi_tuple); break; default: break; @@ -1826,25 +1826,25 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) free_data: kfree(nvm); set_pi: - if (ns->head->pi_size && (first || ns->head->ms =3D=3D ns->head->pi_size)) - ns->head->pi_type =3D id->dps & NVME_NS_DPS_PI_MASK; + if (head->pi_size && (first || head->ms =3D=3D head->pi_size)) + head->pi_type =3D id->dps & NVME_NS_DPS_PI_MASK; else - ns->head->pi_type =3D 0; + head->pi_type =3D 0; =20 return ret; } =20 -static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *= id) +static int nvme_configure_metadata(struct nvme_ctrl *ctrl, + struct nvme_ns_head *head, struct nvme_id_ns *id) { - struct nvme_ctrl *ctrl =3D ns->ctrl; int ret; =20 - ret =3D nvme_init_ms(ns, id); + ret =3D nvme_init_ms(ctrl, head, id); if (ret) return ret; =20 - ns->head->features &=3D ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); - if (!ns->head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) + head->features &=3D ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); + if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) return 0; =20 if (ctrl->ops->flags & NVME_F_FABRICS) { @@ -1856,7 +1856,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT))) return 0; =20 - ns->head->features |=3D NVME_NS_EXT_LBAS; + head->features |=3D NVME_NS_EXT_LBAS; =20 /* * The current fabrics transport drivers support namespace @@ -1867,8 +1867,8 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * Note, this check will need to be modified if any drivers * gain the ability to use other metadata formats. */ - if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns->head)) - ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; + if (ctrl->max_integrity_segments && nvme_ns_has_pi(head)) + head->features |=3D NVME_NS_METADATA_SUPPORTED; } else { /* * For PCIe controllers, we can't easily remap the separate @@ -1877,9 +1877,9 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * We allow extended LBAs for the passthrough interface, though. */ if (id->flbas & NVME_NS_FLBAS_META_EXT) - ns->head->features |=3D NVME_NS_EXT_LBAS; + head->features |=3D NVME_NS_EXT_LBAS; else - ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; + head->features |=3D NVME_NS_METADATA_SUPPORTED; } return 0; } @@ -1902,11 +1902,11 @@ static void nvme_set_queue_limits(struct nvme_ctrl = *ctrl, blk_queue_write_cache(q, vwc, vwc); } =20 -static void nvme_update_disk_info(struct gendisk *disk, - struct nvme_ns *ns, struct nvme_id_ns *id) +static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *= disk, + struct nvme_ns_head *head, struct nvme_id_ns *id) { - sector_t capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze)); - u32 bs =3D 1U << ns->head->lba_shift; + sector_t capacity =3D nvme_lba_to_sect(head, le64_to_cpu(id->nsze)); + u32 bs =3D 1U << head->lba_shift; u32 atomic_bs, phys_bs, io_opt =3D 0; =20 /* @@ -1914,8 +1914,7 @@ static void nvme_update_disk_info(struct gendisk *dis= k, * or smaller than a sector size yet, so catch this early and don't * allow block I/O. */ - if (ns->head->lba_shift > PAGE_SHIFT || - ns->head->lba_shift < SECTOR_SHIFT) { + if (head->lba_shift > PAGE_SHIFT || head->lba_shift < SECTOR_SHIFT) { capacity =3D 0; bs =3D (1 << 9); } @@ -1932,7 +1931,7 @@ static void nvme_update_disk_info(struct gendisk *dis= k, if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) atomic_bs =3D (1 + le16_to_cpu(id->nawupf)) * bs; else - atomic_bs =3D (1 + ns->ctrl->subsys->awupf) * bs; + atomic_bs =3D (1 + ctrl->subsys->awupf) * bs; } =20 if (id->nsfeat & NVME_NS_FEAT_IO_OPT) { @@ -1958,20 +1957,20 @@ static void nvme_update_disk_info(struct gendisk *d= isk, * I/O to namespaces with metadata except when the namespace supports * PI, as it can strip/insert in that case. */ - if (ns->head->ms) { + if (head->ms) { if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) && - (ns->head->features & NVME_NS_METADATA_SUPPORTED)) - nvme_init_integrity(disk, ns, - ns->ctrl->max_integrity_segments); - else if (!nvme_ns_has_pi(ns->head)) + (head->features & NVME_NS_METADATA_SUPPORTED)) + nvme_init_integrity(disk, head, + ctrl->max_integrity_segments); + else if (!nvme_ns_has_pi(head)) capacity =3D 0; } =20 set_capacity_and_notify(disk, capacity); =20 - nvme_config_discard(disk, ns); + nvme_config_discard(ctrl, disk, head); blk_queue_max_write_zeroes_sectors(disk->queue, - ns->ctrl->max_zeroes_sectors); + ctrl->max_zeroes_sectors); } =20 static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *i= nfo) @@ -2064,13 +2063,13 @@ static int nvme_update_ns_info_block(struct nvme_ns= *ns, ns->head->lba_shift =3D id->lbaf[lbaf].ds; nvme_set_queue_limits(ns->ctrl, ns->queue); =20 - ret =3D nvme_configure_metadata(ns, id); + ret =3D nvme_configure_metadata(ns->ctrl, ns->head, id); if (ret < 0) { blk_mq_unfreeze_queue(ns->disk->queue); goto out; } nvme_set_chunk_sectors(ns, id); - nvme_update_disk_info(ns->disk, ns, id); + nvme_update_disk_info(ns->ctrl, ns->disk, ns->head, id); =20 if (ns->head->ids.csi =3D=3D NVME_CSI_ZNS) { ret =3D nvme_update_zone_info(ns, lbaf); @@ -2100,7 +2099,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, =20 if (nvme_ns_head_multipath(ns->head)) { blk_mq_freeze_queue(ns->head->disk->queue); - nvme_update_disk_info(ns->head->disk, ns, id); + nvme_update_disk_info(ns->ctrl, ns->head->disk, ns->head, id); set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); nvme_mpath_revalidate_paths(ns); blk_stack_limits(&ns->head->disk->queue->limits, diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index ded52ab05424..56b27aabcad9 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -148,7 +148,8 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_n= s *ns, return NULL; } =20 -static int nvme_zone_parse_entry(struct nvme_ns *ns, +static int nvme_zone_parse_entry(struct nvme_ctrl *ctrl, + struct nvme_ns_head *head, struct nvme_zone_descriptor *entry, unsigned int idx, report_zones_cb cb, void *data) @@ -156,20 +157,20 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns, struct blk_zone zone =3D { }; =20 if ((entry->zt & 0xf) !=3D NVME_ZONE_TYPE_SEQWRITE_REQ) { - dev_err(ns->ctrl->device, "invalid zone type %#x\n", + dev_err(ctrl->device, "invalid zone type %#x\n", entry->zt); return -EINVAL; } =20 zone.type =3D BLK_ZONE_TYPE_SEQWRITE_REQ; zone.cond =3D entry->zs >> 4; - zone.len =3D ns->head->zsze; - zone.capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->zcap)); - zone.start =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->zslba)); + zone.len =3D head->zsze; + zone.capacity =3D nvme_lba_to_sect(head, le64_to_cpu(entry->zcap)); + zone.start =3D nvme_lba_to_sect(head, le64_to_cpu(entry->zslba)); if (zone.cond =3D=3D BLK_ZONE_COND_FULL) zone.wp =3D zone.start + zone.len; else - zone.wp =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->wp)); + zone.wp =3D nvme_lba_to_sect(head, le64_to_cpu(entry->wp)); =20 return cb(&zone, idx, data); } @@ -214,7 +215,8 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t s= ector, break; =20 for (i =3D 0; i < nz && zone_idx < nr_zones; i++) { - ret =3D nvme_zone_parse_entry(ns, &report->entries[i], + ret =3D nvme_zone_parse_entry(ns->ctrl, ns->head, + &report->entries[i], zone_idx, cb, data); if (ret) goto out_free; --=20 2.43.0 From nobody Tue Dec 16 16:38:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB392C4167B for ; Fri, 8 Dec 2023 10:54:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573749AbjLHKxw (ORCPT ); Fri, 8 Dec 2023 05:53:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573661AbjLHKxj (ORCPT ); Fri, 8 Dec 2023 05:53:39 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB21B171D for ; Fri, 8 Dec 2023 02:53:45 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 511DA1F38E; Fri, 8 Dec 2023 10:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GomM3EpyG/paTprJTV6m4GXtr6dHAbVPRpRzOGdAVqo=; b=UXDBekQcmFR08RFL28KodkDcqEQkQGIpXUn7g6M/mMnWc/Dh5K594rtDdwL7vmpQ2pWacB 7ScjStpGxflx5/3HurNLA1W6KLw/S4e8NPvh9KYqSOxN7IJUbB+eezn2ASApFuzPAKAyQZ twV/BxGf8dXBTDTNKoDAOwYArwAsPkY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GomM3EpyG/paTprJTV6m4GXtr6dHAbVPRpRzOGdAVqo=; b=LleqCbSbmHNTeIXlM2Ku2YVt1kweVlWKeT2HzehpwoVz3bStCk6LAj2Ld7fSGd3qpLuQv6 iu+fe3w+VnwM0PDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GomM3EpyG/paTprJTV6m4GXtr6dHAbVPRpRzOGdAVqo=; b=UXDBekQcmFR08RFL28KodkDcqEQkQGIpXUn7g6M/mMnWc/Dh5K594rtDdwL7vmpQ2pWacB 7ScjStpGxflx5/3HurNLA1W6KLw/S4e8NPvh9KYqSOxN7IJUbB+eezn2ASApFuzPAKAyQZ twV/BxGf8dXBTDTNKoDAOwYArwAsPkY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GomM3EpyG/paTprJTV6m4GXtr6dHAbVPRpRzOGdAVqo=; b=LleqCbSbmHNTeIXlM2Ku2YVt1kweVlWKeT2HzehpwoVz3bStCk6LAj2Ld7fSGd3qpLuQv6 iu+fe3w+VnwM0PDQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 3DDD3138FF; Fri, 8 Dec 2023 10:53:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id oAyqDbj1cmU5VgAAn2gu4w (envelope-from ); Fri, 08 Dec 2023 10:53:44 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v5 4/6] nvme: rename ns attribute group Date: Fri, 8 Dec 2023 11:53:35 +0100 Message-ID: <20231208105337.23409-5-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208105337.23409-1-dwagner@suse.de> References: <20231208105337.23409-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Drop the 'id' part of the attribute group name because we want to expose non 'id' related attributes via the ns attribute group. Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/multipath.c | 2 +- drivers/nvme/host/nvme.h | 2 +- drivers/nvme/host/sysfs.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 2468076d64c6..c537914b75e3 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3674,7 +3674,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, str= uct nvme_ns_info *info) up_write(&ctrl->namespaces_rwsem); nvme_get_ctrl(ctrl); =20 - if (device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups)) + if (device_add_disk(ctrl->device, ns->disk, nvme_ns_attr_groups)) goto out_cleanup_ns_from_list; =20 if (!nvme_ns_head_multipath(ns->head)) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 0a88d7bdc5e3..2dd4137a08b2 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -579,7 +579,7 @@ static void nvme_mpath_set_live(struct nvme_ns *ns) */ if (!test_and_set_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) { rc =3D device_add_disk(&head->subsys->dev, head->disk, - nvme_ns_id_attr_groups); + nvme_ns_attr_groups); if (rc) { clear_bit(NVME_NSHEAD_DISK_LIVE, &ns->flags); return; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index eb748cc3e897..b783b37328fa 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -870,7 +870,7 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *iou= cmd, int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo); int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_fla= gs); =20 -extern const struct attribute_group *nvme_ns_id_attr_groups[]; +extern const struct attribute_group *nvme_ns_attr_groups[]; extern const struct pr_ops nvme_pr_ops; extern const struct block_device_operations nvme_ns_head_ops; extern const struct attribute_group nvme_dev_attrs_group; diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c index c6b7fbd4d34d..d682d0a667a0 100644 --- a/drivers/nvme/host/sysfs.c +++ b/drivers/nvme/host/sysfs.c @@ -114,7 +114,7 @@ static ssize_t nsid_show(struct device *dev, struct dev= ice_attribute *attr, } static DEVICE_ATTR_RO(nsid); =20 -static struct attribute *nvme_ns_id_attrs[] =3D { +static struct attribute *nvme_ns_attrs[] =3D { &dev_attr_wwid.attr, &dev_attr_uuid.attr, &dev_attr_nguid.attr, @@ -127,7 +127,7 @@ static struct attribute *nvme_ns_id_attrs[] =3D { NULL, }; =20 -static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj, +static umode_t nvme_ns_attrs_are_visible(struct kobject *kobj, struct attribute *a, int n) { struct device *dev =3D container_of(kobj, struct device, kobj); @@ -157,13 +157,13 @@ static umode_t nvme_ns_id_attrs_are_visible(struct ko= bject *kobj, return a->mode; } =20 -static const struct attribute_group nvme_ns_id_attr_group =3D { - .attrs =3D nvme_ns_id_attrs, - .is_visible =3D nvme_ns_id_attrs_are_visible, +static const struct attribute_group nvme_ns_attr_group =3D { + .attrs =3D nvme_ns_attrs, + .is_visible =3D nvme_ns_attrs_are_visible, }; =20 -const struct attribute_group *nvme_ns_id_attr_groups[] =3D { - &nvme_ns_id_attr_group, +const struct attribute_group *nvme_ns_attr_groups[] =3D { + &nvme_ns_attr_group, NULL, }; =20 --=20 2.43.0 From nobody Tue Dec 16 16:38:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A820DC4167B for ; Fri, 8 Dec 2023 10:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573763AbjLHKyC (ORCPT ); Fri, 8 Dec 2023 05:54:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573699AbjLHKxk (ORCPT ); Fri, 8 Dec 2023 05:53:40 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69058171F for ; Fri, 8 Dec 2023 02:53:46 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E80F72118E; Fri, 8 Dec 2023 10:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hWczCS20tTRrwDpvwe8/CSLdZ7ac/VDOdxeHB+SKxMI=; b=IHsm223H1P1U4r7Eji/BGR5s099PArvMt8Gt/UMckdqQ7fWZ5ViIzcaI42LRbcujlktYqs +3n7Xkr1vX0GKT/lFGuWNtQyHgo86y3Lm/jQzeosRNO38rH9/IdkzqMC2pjamH1FgjGxz2 r7x2sM7zGcqca+beePCj2/kTkUHAK68= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hWczCS20tTRrwDpvwe8/CSLdZ7ac/VDOdxeHB+SKxMI=; b=Ljd9YXXO1FdfrOmzNuF5RVlvmEY365GmBqsz9tREmTnchGd4XuQIU3n9qnnzoEB3I6YVVs nIa2NZ94sFx6XJCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hWczCS20tTRrwDpvwe8/CSLdZ7ac/VDOdxeHB+SKxMI=; b=FYg1nsf/pUHgyWqOw9QdWXvHGxahOsmrtwSJchtojW1QLeleRvxgm0g6DNiNPGB3x2H3Zg SBpaO8W2tXdVvlBAPpNBeLsXOS63B5smMjPQuluQdmQ5K/NzqZX4X5kVkAtlQ5uicZqNVf sm9k7coB1OPlydS1OugGArrC/BARyRI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hWczCS20tTRrwDpvwe8/CSLdZ7ac/VDOdxeHB+SKxMI=; b=k5AveeftcK6eLCcRnmk5qr09Ze+8kxs/x925wKJJSVibB9ABJoJx7FR4fJ2u6majrKtj1y Mvcq9Td0iA5rM7AQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id D6347138FF; Fri, 8 Dec 2023 10:53:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id gNviMrj1cmU7VgAAn2gu4w (envelope-from ); Fri, 08 Dec 2023 10:53:44 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v5 5/6] nvme: add csi, ms and nuse to sysfs Date: Fri, 8 Dec 2023 11:53:36 +0100 Message-ID: <20231208105337.23409-6-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208105337.23409-1-dwagner@suse.de> References: <20231208105337.23409-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] Authentication-Results: smtp-out1.suse.de; none Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" libnvme is using the sysfs for enumarating the nvme resources. Though there are few missing attritbutes in the sysfs. For these libnvme issues commands during discovering. As the kernel already knows all these attributes and we would like to avoid libnvme to issue commands all the time, expose these missing attributes. The nuse value is updated on request because the nuse is a volatile value. Since any user can read the sysfs attribute, a very simple rate limit is added (update once every 5 seconds). A more sophisticated update strategy can be added later if there is actually a need for it. Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 6 ++- drivers/nvme/host/nvme.h | 6 +++ drivers/nvme/host/sysfs.c | 85 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index c537914b75e3..3138cbb3b380 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -20,6 +20,7 @@ #include #include #include +#include #include =20 #include "nvme.h" @@ -1459,7 +1460,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *c= trl, return status; } =20 -static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, +int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, struct nvme_id_ns **id) { struct nvme_command c =3D { }; @@ -2061,6 +2062,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, blk_mq_freeze_queue(ns->disk->queue); lbaf =3D nvme_lbaf_index(id->flbas); ns->head->lba_shift =3D id->lbaf[lbaf].ds; + ns->head->nuse =3D le64_to_cpu(id->nuse); nvme_set_queue_limits(ns->ctrl, ns->queue); =20 ret =3D nvme_configure_metadata(ns->ctrl, ns->head, id); @@ -3423,6 +3425,8 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct= nvme_ctrl *ctrl, head->ns_id =3D info->nsid; head->ids =3D info->ids; head->shared =3D info->is_shared; + ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1); + ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE); kref_init(&head->ref); =20 if (head->ids.csi) { diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index b783b37328fa..8912292720d4 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 #include =20 @@ -456,6 +457,7 @@ struct nvme_ns_head { u16 pi_size; u16 sgs; u32 sws; + u64 nuse; u8 pi_type; u8 guard_type; #ifdef CONFIG_BLK_DEV_ZONED @@ -463,6 +465,8 @@ struct nvme_ns_head { #endif unsigned long features; =20 + struct ratelimit_state rs_nuse; + struct cdev cdev; struct device cdev_device; =20 @@ -867,6 +871,8 @@ int nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags); int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags); +int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, + struct nvme_id_ns **id); int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo); int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_fla= gs); =20 diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c index d682d0a667a0..3cfae0c3af76 100644 --- a/drivers/nvme/host/sysfs.c +++ b/drivers/nvme/host/sysfs.c @@ -114,12 +114,97 @@ static ssize_t nsid_show(struct device *dev, struct d= evice_attribute *attr, } static DEVICE_ATTR_RO(nsid); =20 +static ssize_t csi_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ids.csi); +} +static DEVICE_ATTR_RO(csi); + +static ssize_t metadata_bytes_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ms); +} +static DEVICE_ATTR_RO(metadata_bytes); + +static int ns_head_update_nuse(struct nvme_ns_head *head) +{ + struct nvme_id_ns *id; + struct nvme_ns *ns; + int srcu_idx, ret =3D -EWOULDBLOCK; + + /* Avoid issuing commands too often by rate limiting the update */ + if (!__ratelimit(&head->rs_nuse)) + return 0; + + srcu_idx =3D srcu_read_lock(&head->srcu); + ns =3D nvme_find_path(head); + if (!ns) + goto out_unlock; + + ret =3D nvme_identify_ns(ns->ctrl, head->ns_id, &id); + if (ret) + goto out_unlock; + + head->nuse =3D le64_to_cpu(id->nuse); + kfree(id); + +out_unlock: + srcu_read_unlock(&head->srcu, srcu_idx); + return ret; +} + +static int ns_update_nuse(struct nvme_ns *ns) +{ + struct nvme_id_ns *id; + int ret; + + /* Avoid issuing commands too often by rate limiting the update. */ + if (!__ratelimit(&ns->head->rs_nuse)) + return 0; + + ret =3D nvme_identify_ns(ns->ctrl, ns->head->ns_id, &id); + if (ret) + goto out_free_id; + + ns->head->nuse =3D le64_to_cpu(id->nuse); + +out_free_id: + kfree(id); + + return ret; +} + +static ssize_t nuse_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvme_ns_head *head =3D dev_to_ns_head(dev); + struct gendisk *disk =3D dev_to_disk(dev); + struct block_device *bdev =3D disk->part0; + int ret; + + if (IS_ENABLED(CONFIG_NVME_MULTIPATH) && + bdev->bd_disk->fops =3D=3D &nvme_ns_head_ops) + ret =3D ns_head_update_nuse(head); + else + ret =3D ns_update_nuse(bdev->bd_disk->private_data); + if (ret) + return ret; + + return sysfs_emit(buf, "%llu\n", head->nuse); +} +static DEVICE_ATTR_RO(nuse); + static struct attribute *nvme_ns_attrs[] =3D { &dev_attr_wwid.attr, &dev_attr_uuid.attr, &dev_attr_nguid.attr, &dev_attr_eui.attr, + &dev_attr_csi.attr, &dev_attr_nsid.attr, + &dev_attr_metadata_bytes.attr, + &dev_attr_nuse.attr, #ifdef CONFIG_NVME_MULTIPATH &dev_attr_ana_grpid.attr, &dev_attr_ana_state.attr, --=20 2.43.0 From nobody Tue Dec 16 16:38:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A457C4167B for ; Fri, 8 Dec 2023 10:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573734AbjLHKyH (ORCPT ); Fri, 8 Dec 2023 05:54:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573718AbjLHKxm (ORCPT ); Fri, 8 Dec 2023 05:53:42 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A698115 for ; Fri, 8 Dec 2023 02:53:47 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8E89D2118C; Fri, 8 Dec 2023 10:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wG/WgEHtQYUHrRNwmOMTcsj+OVIRNNcNPPGKhtYYRik=; b=WyhIZb8fVCvvI6mfbtAmMkupFo7uo1Pnv/lOwO5I5jSvf86VJBfeovcwmhZOZhGFs0Yb/o XlCZe/ZBV3RPcOu8BwtIgzv/DjlOGlQf6CsxypuqBLU29+SP3Ki10IQoX+U5yAmp31hCv3 wTRmFEC7+B4lppEumCPzXJIx4rFXag0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wG/WgEHtQYUHrRNwmOMTcsj+OVIRNNcNPPGKhtYYRik=; b=5x3x1RcVmlqzRVzwELwHCh7VWuOJWwjt2hC/p/MTq82Ja9D112HXCwqh2FTWH2I8kOnrDq ps65B1kJlRR/Q1CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702032825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wG/WgEHtQYUHrRNwmOMTcsj+OVIRNNcNPPGKhtYYRik=; b=WyhIZb8fVCvvI6mfbtAmMkupFo7uo1Pnv/lOwO5I5jSvf86VJBfeovcwmhZOZhGFs0Yb/o XlCZe/ZBV3RPcOu8BwtIgzv/DjlOGlQf6CsxypuqBLU29+SP3Ki10IQoX+U5yAmp31hCv3 wTRmFEC7+B4lppEumCPzXJIx4rFXag0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702032825; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wG/WgEHtQYUHrRNwmOMTcsj+OVIRNNcNPPGKhtYYRik=; b=5x3x1RcVmlqzRVzwELwHCh7VWuOJWwjt2hC/p/MTq82Ja9D112HXCwqh2FTWH2I8kOnrDq ps65B1kJlRR/Q1CQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 7BA22138FF; Fri, 8 Dec 2023 10:53:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id mqauHLn1cmU9VgAAn2gu4w (envelope-from ); Fri, 08 Dec 2023 10:53:45 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v5 6/6] nvme: repack struct nvme_ns_head Date: Fri, 8 Dec 2023 11:53:37 +0100 Message-ID: <20231208105337.23409-7-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208105337.23409-1-dwagner@suse.de> References: <20231208105337.23409-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=WyhIZb8f; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5x3x1RcV; dmarc=pass (policy=none) header.from=suse.de; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:98 is neither permitted nor denied by domain of dwagner@suse.de) smtp.mailfrom=dwagner@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-6.01 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+]; DMARC_POLICY_ALLOW(0.00)[suse.de,none]; RCPT_COUNT_SEVEN(0.00)[7]; MX_GOOD(-0.01)[]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[27.39%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; WHITELIST_DMARC(-7.00)[suse.de:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 8E89D2118C Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" ns_id, lba_shift and ms are always accessed for every read/write I/O in nvme_setup_rw. By grouping these variables into one cacheline we can safe some cycles. 4k sequential reads: baseline patched Bandwidth: 1620 1634 IOPs 66345579 66910939 Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner Reviewed-by: Sagi Grimberg --- drivers/nvme/host/nvme.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 8912292720d4..416794727364 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -445,21 +445,21 @@ struct nvme_ns_head { struct list_head list; struct srcu_struct srcu; struct nvme_subsystem *subsys; - unsigned ns_id; struct nvme_ns_ids ids; struct list_head entry; struct kref ref; bool shared; int instance; struct nvme_effects_log *effects; + u64 nuse; + unsigned ns_id; int lba_shift; u16 ms; u16 pi_size; - u16 sgs; - u32 sws; - u64 nuse; u8 pi_type; u8 guard_type; + u16 sgs; + u32 sws; #ifdef CONFIG_BLK_DEV_ZONED u64 zsze; #endif --=20 2.43.0