Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp410603imm; Wed, 29 Aug 2018 03:11:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaWs2fkHe/DfOpvi6KB6YI1qkvmVl6F7a+hSbwTk7S94IxluJArYdowmnPN92OeI8sUR5ic X-Received: by 2002:a65:6086:: with SMTP id t6-v6mr5133968pgu.424.1535537517291; Wed, 29 Aug 2018 03:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535537517; cv=none; d=google.com; s=arc-20160816; b=EgwFBSUpgg+XZ9r+a7s0YeZFLwA7+PpB1lhyF22xRQOSlZ2gN3YDyccPmme+gJ8UBp 9nR1R5WdS52uBV2sFi+2JphJ34UdUC1L1MLwzGLBdi4Op/uAek0E9jKf5yjje7siPC/V nLjelpp0RzmjYFPFon9SmSIZfn6L3kJwNFWb9l6M26un/vaUJsUvy6AEFUNI0vMMT3MS /yjavdf53qkHsdyMmB/sHkRc+HTj0OPwjElwhAWd4HmPKrdxAcggZkt0guN0CReX77T3 cXK8GKRyTd6wQQBIIrxbhRdTXWCNXSQo0acdkN3xwvDobZczt7hGseQtWQHJMfRkdhbA QtIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1ODcjidieP2i8+4PKVs+kvCzZXfnHJ/1WtHIaljN8HY=; b=Ry1o2VDlbrrD7/V5l+++ETse8c7ZU1AxQVFOoO/laGqi8ZlRYom51HTVN5mqHFRTaj VPTYkhMUZtmmnezCJdIHTuJ2U5dBVJPiyLkoiYv+nUNwR+tiLNcM3AsyWk7t8EgZhJDY tKnyDu5AD6HYbZccunW+u/tx2pY+JTTIPhVy0/T4A8blHKmHi0JTHZGv1B8yKodqlTyQ Wthk6JQ2ky/t+tkZrjhDysaeI65/v+ApinsJRgBb5PlLzRpqbRpObKLyYmJy0QbF4y1G 6MOUhjBc9IyPhURpIBT87ptdf/ApaKfIhNkEutWL5NN4m7qhNOeSXr6IdgkxjnnIBhAo q3ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=FtLAQcPr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184-v6si3404687pgj.421.2018.08.29.03.11.42; Wed, 29 Aug 2018 03:11:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=FtLAQcPr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbeH2OGC (ORCPT + 99 others); Wed, 29 Aug 2018 10:06:02 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:39044 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728242AbeH2OGB (ORCPT ); Wed, 29 Aug 2018 10:06:01 -0400 Received: by mail-it0-f65.google.com with SMTP id h1-v6so4514948itj.4 for ; Wed, 29 Aug 2018 03:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1ODcjidieP2i8+4PKVs+kvCzZXfnHJ/1WtHIaljN8HY=; b=FtLAQcProxh3GzyK/M3ewHLenRYJ3RDwQSAIqB745Pt8hCJcVH+CDoe8qhlMBXgD0U bfrnODw4ioonb3A1bzLVclL2s6bHwzJRgCfHz1I7eF2bVRDRmGP67Sld+uVB9vGua1tT 4TlX1Dpm2ZqHS9B517/F1E2Oq3hq8bwUJGfCHF26XjT3y7zenctPwKnxCa4eAQzvv9Dj 4vLDGr9Jyn0CAUsfL4F3P1aeQtSj+KZyTbhf9szFvAMykjOGJeJVwy8xBWwmBd+jrkKQ gs6SAoG7sbfmexFDiPMpsUKBWy+j689abdkdKWv5eN6px/AfC4kV1iKcs4fSPrFotr8J 5DvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1ODcjidieP2i8+4PKVs+kvCzZXfnHJ/1WtHIaljN8HY=; b=TWcof+R0JyPte3F8WPfannNcY4cXBsJggo2Ocop/08e5A44pKlzMt8jmhaHwmYdzJz 4hUWTFlsxyRA9oXuAq3L2cdCKzOeIVZ9zELq228NruyHSSsVM53B8mfAH16mlC7M31w6 3TCyLZovw6G5xHWpbl3aQNTutwHokg9v8bw39/wH8Ond5K80Cai4Ox/b/TGHTFBhYr7e fwqUVZogAWDw97DqZ8biXhWRc54901UJ1EIOyUuHK3WGj8oku9YpP9e6VeeZm5Lr7a1r FiXn0MTfSANVlTyXa++YEgVLA8iRaKrLgEjvHzCNoFaLSJdThqavdFgflVopDt6Wl39c 9P5Q== X-Gm-Message-State: APzg51CBhbpguSjKFpcG22mcUnmOIZPqzDO4ERWI1P2IQU6j/nWjnjk3 X4vjBQnXEzxkkl8PN9KHC2Q1tA== X-Received: by 2002:a24:190c:: with SMTP id b12-v6mr4624781itb.79.1535537391726; Wed, 29 Aug 2018 03:09:51 -0700 (PDT) Received: from ch-wrk-javier.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id v14-v6sm1721501iog.42.2018.08.29.03.09.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Aug 2018 03:09:51 -0700 (PDT) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: igor.j.konopko@intel.com, marcin.dziegielewski@intel.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH 1/3] lightnvm: use internal allocation for chunk log page Date: Wed, 29 Aug 2018 12:09:28 +0200 Message-Id: <1535537370-10729-2-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535537370-10729-1-git-send-email-javier@cnexlabs.com> References: <1535537370-10729-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The lightnvm subsystem provides helpers to retrieve chunk metadata, where the target needs to provide a buffer to store the metadata. An implicit assumption is that this buffer is contiguous and can be used to retrieve the data from the device. If the device exposes too many chunks, then kmalloc might fail, thus failing instance creation. This patch removes this assumption by implementing an internal buffer in the lightnvm subsystem to retrieve chunk metadata. Targets can then use virtual memory allocations. Since this is a target API change, adapt pblk accordingly. Signed-off-by: Javier González --- drivers/lightnvm/pblk-core.c | 4 ++-- drivers/lightnvm/pblk-init.c | 2 +- drivers/nvme/host/lightnvm.c | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c index fdcbeb920c9e..a311cc29afd8 100644 --- a/drivers/lightnvm/pblk-core.c +++ b/drivers/lightnvm/pblk-core.c @@ -120,7 +120,7 @@ static void pblk_end_io_erase(struct nvm_rq *rqd) /* * Get information for all chunks from the device. * - * The caller is responsible for freeing the returned structure + * The caller is responsible for freeing (vmalloc) the returned structure */ struct nvm_chk_meta *pblk_get_chunk_meta(struct pblk *pblk) { @@ -134,7 +134,7 @@ struct nvm_chk_meta *pblk_get_chunk_meta(struct pblk *pblk) ppa.ppa = 0; len = geo->all_chunks * sizeof(*meta); - meta = kzalloc(len, GFP_KERNEL); + meta = vzalloc(len); if (!meta) return ERR_PTR(-ENOMEM); diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index e0db6de137d6..a99854439224 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -983,7 +983,7 @@ static int pblk_lines_init(struct pblk *pblk) pblk_set_provision(pblk, nr_free_chks); - kfree(chunk_meta); + vfree(chunk_meta); return 0; fail_free_lines: diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c index 2c96e7fcdcac..5bfa354c5dd5 100644 --- a/drivers/nvme/host/lightnvm.c +++ b/drivers/nvme/host/lightnvm.c @@ -579,7 +579,7 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev, struct nvm_geo *geo = &ndev->geo; struct nvme_ns *ns = ndev->q->queuedata; struct nvme_ctrl *ctrl = ns->ctrl; - struct nvme_nvm_chk_meta *dev_meta = (struct nvme_nvm_chk_meta *)meta; + struct nvme_nvm_chk_meta *dev_meta, *dev_meta_off; struct ppa_addr ppa; size_t left = nchks * sizeof(struct nvme_nvm_chk_meta); size_t log_pos, offset, len; @@ -591,6 +591,10 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev, */ max_len = min_t(unsigned int, ctrl->max_hw_sectors << 9, 256 * 1024); + dev_meta = kmalloc(max_len, GFP_KERNEL); + if (!dev_meta) + return -ENOMEM; + /* Normalize lba address space to obtain log offset */ ppa.ppa = slba; ppa = dev_to_generic_addr(ndev, ppa); @@ -604,6 +608,9 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev, while (left) { len = min_t(unsigned int, left, max_len); + memset(dev_meta, 0, max_len); + dev_meta_off = dev_meta; + ret = nvme_get_log_ext(ctrl, ns, NVME_NVM_LOG_REPORT_CHUNK, dev_meta, len, offset); if (ret) { @@ -612,15 +619,15 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev, } for (i = 0; i < len; i += sizeof(struct nvme_nvm_chk_meta)) { - meta->state = dev_meta->state; - meta->type = dev_meta->type; - meta->wi = dev_meta->wi; - meta->slba = le64_to_cpu(dev_meta->slba); - meta->cnlb = le64_to_cpu(dev_meta->cnlb); - meta->wp = le64_to_cpu(dev_meta->wp); + meta->state = dev_meta_off->state; + meta->type = dev_meta_off->type; + meta->wi = dev_meta_off->wi; + meta->slba = le64_to_cpu(dev_meta_off->slba); + meta->cnlb = le64_to_cpu(dev_meta_off->cnlb); + meta->wp = le64_to_cpu(dev_meta_off->wp); meta++; - dev_meta++; + dev_meta_off++; } offset += len; -- 2.7.4