Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp818802rdb; Wed, 6 Dec 2023 00:13:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+RT2OK2z63w2d0ISK4QFrgPZdxym+V7mJTkEpomi/wq5nEvpNIYW1HeqN+uhfPTXzknD6 X-Received: by 2002:a05:6a20:daa9:b0:18b:902f:892 with SMTP id iy41-20020a056a20daa900b0018b902f0892mr403583pzb.40.1701850412765; Wed, 06 Dec 2023 00:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850412; cv=none; d=google.com; s=arc-20160816; b=NKF9+8dLxmCZ/PVpxyPk+wtUsWVa4U8IheGgdVobkXnXo9Gmx+GZYHC0w0FSw+Y2Ye 270SosPn6Cs1bq9AzlCWfu19gpju8dKkn/rhwVqrY6xg0VfUKNhYsDzLKqbGT+I5TAka gkQpzcs2r73DzkEnpfIi3Wx9a3er0SQiTy6MsHxAws34UpoB2G2S41s9Mdi+Wpxm3KDJ d1UokypaORqBhnYAJJ1Cx2qDRhUQl9+MZS6gVDyED2v1neg/vNucW9v4yvKHRU7rDTii D0ZI7pX15kKVe9Vu27AzK0KzXjXcKNjpvw7993/oaeK9UfMTba9WyNDarOg1Y+zA5JGt AKjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Imb8r6kOq6i8JWWlzSW1fJ0121ll1Cx5vfdQ9cb7cJo=; fh=DJbT8ne4Efjik5M2lT8AzCh46QRFyMX3tPkPd3UGLh8=; b=eIyo0kqH1gEp1CGZfZ37Rc7JYOZmNDue+ifobSN7R7ugckLBIqNAm7om+XMKzFGToF 1wViFD+C1Pvk+vo72o6/eiOP2WYGzkn02b1PwBvAp2Mh5fGEwvwO9tpkAEXz20DxW7tt Bnf/NwhfCJOCw7AUkTivUe3BClwKRPFnQWSJZRaxU8MH/UoAEojxqch6OoYD0E+LIzc2 qS0XhnNBsGzXuQoaoezVy8jBCmtfWF3dwq/P2Hiur9arLQ+ZTj/Tr0ajhjnlQUXzAWw3 Th76aevkEnptVGdmDO0PeD2cW4rb5+4HcbVVpr1Ij769rvT+jFt+dDoL2nikqzWB0icA MoPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id pf17-20020a17090b1d9100b00286b8213904si4509732pjb.188.2023.12.06.00.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:13:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 807CB8221124; Wed, 6 Dec 2023 00:13:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377150AbjLFIMx (ORCPT + 99 others); Wed, 6 Dec 2023 03:12:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231697AbjLFIMr (ORCPT ); Wed, 6 Dec 2023 03:12:47 -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 F3AFD18D for ; Wed, 6 Dec 2023 00:12:52 -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 86C6222072; Wed, 6 Dec 2023 08:12:51 +0000 (UTC) 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 74358133DD; Wed, 6 Dec 2023 08:12:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id k+DmGgMtcGUZHgAAn2gu4w (envelope-from ); Wed, 06 Dec 2023 08:12:51 +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 v3 4/4] nvme: add csi, ms and nuse to sysfs Date: Wed, 6 Dec 2023 09:12:44 +0100 Message-ID: <20231206081244.32733-5-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231206081244.32733-1-dwagner@suse.de> References: <20231206081244.32733-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: 4.09 X-Spamd-Result: default: False [4.09 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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]; NEURAL_SPAM_SHORT(2.10)[0.700]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; 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)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spamd-Bar: ++++ X-Rspamd-Server: rspamd1 Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); 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-Queue-Id: 86C6222072 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:13:30 -0800 (PST) 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 max every 5 seconds). A more sophisticated update strategy can be added later if there is actually a need for it. Signed-off-by: Daniel Wagner --- drivers/nvme/host/core.c | 28 ++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 2 ++ drivers/nvme/host/sysfs.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index caa52c2f57c8..e7dd64ee1653 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1663,6 +1663,33 @@ static void nvme_ns_release(struct nvme_ns *ns) nvme_put_ns(ns); } +int nvme_ns_update_nuse(struct nvme_ns_head *head) +{ + static DEFINE_RATELIMIT_STATE(_rs, 5 * HZ, 1); + struct nvme_id_ns *id; + struct nvme_ns *ns; + int srcu_idx, ret = -EWOULDBLOCK; + + if (__ratelimit(&_rs)) + return 0; + + srcu_idx = srcu_read_lock(&head->srcu); + ns = nvme_find_path(head); + if (!ns) + goto out_unlock; + + ret = nvme_identify_ns(ns->ctrl, head->ns_id, &id); + if (ret) + goto out_unlock; + + head->nuse = le64_to_cpu(id->nuse); + kfree(id); + +out_unlock: + srcu_read_unlock(&head->srcu, srcu_idx); + return ret; +} + static int nvme_open(struct gendisk *disk, blk_mode_t mode) { return nvme_ns_open(disk->private_data); @@ -2068,6 +2095,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, blk_mq_freeze_queue(ns->disk->queue); lbaf = nvme_lbaf_index(id->flbas); ns->head->lba_shift = id->lbaf[lbaf].ds; + ns->head->nuse = le64_to_cpu(id->nuse); nvme_set_queue_limits(ns->ctrl, ns->queue); ret = nvme_configure_metadata(ns, id); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index e6c7890b14c9..6a928646dc09 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -456,6 +456,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 @@ -867,6 +868,7 @@ 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_ns_update_nuse(struct nvme_ns_head *head); int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo); int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags); diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c index c6b7fbd4d34d..c24854eca496 100644 --- a/drivers/nvme/host/sysfs.c +++ b/drivers/nvme/host/sysfs.c @@ -114,12 +114,43 @@ static ssize_t nsid_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(nsid); +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 ssize_t nuse_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nvme_ns_head *head = dev_to_ns_head(dev); + int ret; + + ret = nvme_ns_update_nuse(head); + if (ret) + return ret; + + return sysfs_emit(buf, "%llu\n", head->nuse); +} +static DEVICE_ATTR_RO(nuse); + static struct attribute *nvme_ns_id_attrs[] = { &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, -- 2.43.0