Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2017780imm; Fri, 7 Sep 2018 09:33:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbEipUVwEopKj2Jz7tX2fhqL4kxEnyYDgPTKEn7iYmE3CCpu/M4Rm8SUjUqv+7WcossfxOa X-Received: by 2002:a62:e511:: with SMTP id n17-v6mr9373843pff.210.1536337994688; Fri, 07 Sep 2018 09:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536337994; cv=none; d=google.com; s=arc-20160816; b=gw3YFD/EUBlQkkHLAYiBPEGUuqxkIBss6zBWlE87mppmzoHsoYSDye69u5kfKu/Tai FP1by2MxyAZYJa3MDeNeygEASf8IbMBPRmEBff3JKs3cy/YEm7P8++190y45gYPPsFtB KQgVBwiVfJl+3ZffEHUjkZWPgwmBMw5UFdbkdKZ1gS3Qznb1IeCpa3hro6lynKaMFYW9 vErC4YqyKnXPxCLBlats5NqdYUvIkVOQ/p60dyOa41DFzLsDjzC7JA3YVqCDDrnkT9Li 7lDcR37+CYOVm+v8Va+2wArqdenBzjH6oZIATjzp1uPXW4KPUBrny7fES7u24cHnNBPz I+yg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0TJcHoBwXzdm6fmxZjOILmgHWhLqBEKjOKvTX7OK8A8=; b=xEqAz7iloAK65gFX7/q6hlZOeyhT6Mj2zNI0LBc2wps6g4bBTE+OaZBQABYGx3uWSj hiIV4eE3N+hW05PnBMBiiBP9f2w6iUnI457XYqcHBmFDlCvtoLjO/r3Hi8Eko3ydsVFa 3b6Y+B2AbDt5UKqWnv9FvIb3uChmbO8g4qQkN/ZBmAZMP5GWTvj12U1ffdx3ZMjzIKK+ rslLjGWIrOm3nCs/oqv3qkqL1VcCb9Yq0pWu62SW+m4mxzVydXBEQwbsMSHvbGLIfAiB rJ5BZRQFCNBDhw2G5uQsxApxm8QvSrXBa+wdtUUuIZKpIWIV0XeZSOOCql/YtPm7+JkU rU/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=Z+PLw7zm; 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 d129-v6si9377184pfd.113.2018.09.07.09.32.59; Fri, 07 Sep 2018 09:33:14 -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=@owltronix-com.20150623.gappssmtp.com header.s=20150623 header.b=Z+PLw7zm; 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 S1728944AbeIGRe1 (ORCPT + 99 others); Fri, 7 Sep 2018 13:34:27 -0400 Received: from mail-ua1-f66.google.com ([209.85.222.66]:42507 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728691AbeIGRe0 (ORCPT ); Fri, 7 Sep 2018 13:34:26 -0400 Received: by mail-ua1-f66.google.com with SMTP id w7-v6so11799079uan.9 for ; Fri, 07 Sep 2018 05:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=owltronix-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=0TJcHoBwXzdm6fmxZjOILmgHWhLqBEKjOKvTX7OK8A8=; b=Z+PLw7zm+69qWSYkbUryfYVMZ+HYSCLfBniMIxvrZGTlGxyMEXk741IXI1XHbGPEeS 5ymy0fUZ7L1lDk8b5gdMxG1fMOlr3y9rxDMQrbPnNrmt3u3c4W3j8xiC8/TznuoISaKF 5rhyJgOnAcNZgnkff1y1i69dV9BrVa6g2RqvJm1rScXnYNQD5LNt+Hi0VTKvLOLukTvg dTaBABfL2gykQnzeSQIJEzVMDU9xaXRjtVN7pyjlBx4XiIrR0ZtoZmeQLpdQ5CVyzfKL 6+RIzSFyCocFI8MRV4dmWT0z2pvymLpRUjSMhSnTM/P45Efg03yjM5VMZykj0feAOaPV CnVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=0TJcHoBwXzdm6fmxZjOILmgHWhLqBEKjOKvTX7OK8A8=; b=mWweX+y5OjvOkl95294KxQzeV/yj6B6EN7d9Wwvmv4WcPb/6v2hTvEIvuavBwjlruk X1BSo0Sxm7WJhA/uDVdxNtclDx9cy82OKUTgRb6B1BvnNR1cux8oBCUqtDFRqoj1GjPj 5QvCrB5JQfovp01P+RIfv9CgPM0HgDOAtYAqn3s2zCtdnduCc9kjhfYjJgRbHeY1vrYN ahCf2VKlLrfZpK4uEEG83AiLInwCBD73Y1ibbi6XmrJAZzqNlvCPipFUd+lUs846Lfh5 OYrHKhTBHIZqOyjkKpVUxRekRlNWyXX71Wh9LYfNJhOq18dQ6KkcDbVDyjQCivarigDB ltDA== X-Gm-Message-State: APzg51CBbuKZVmuUe39WstD5z9fm3UbJVzh1gId89qUOzyttY0C/Mn0+ 4P/zElPEWop0gwiN66WU+Cdc7AnKTPaIHux669QhU9vpfyc= X-Received: by 2002:ab0:5097:: with SMTP id c23-v6mr2438798uaa.43.1536324816483; Fri, 07 Sep 2018 05:53:36 -0700 (PDT) MIME-Version: 1.0 References: <1535537370-10729-1-git-send-email-javier@cnexlabs.com> <1535537370-10729-2-git-send-email-javier@cnexlabs.com> In-Reply-To: <1535537370-10729-2-git-send-email-javier@cnexlabs.com> From: Hans Holmberg Date: Fri, 7 Sep 2018 14:53:25 +0200 Message-ID: Subject: Re: [PATCH 1/3] lightnvm: use internal allocation for chunk log page To: =?UTF-8?Q?Javier_Gonz=C3=A1lez?= Cc: Matias Bjorling , igor.j.konopko@intel.com, marcin.dziegielewski@intel.com, linux-block@vger.kernel.org, Linux Kernel Mailing List , Javier Gonzalez Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 29, 2018 at 12:10 PM Javier Gonz=C3=A1lez = wrote: > > 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=C3=A1lez > --- > 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 structur= e > */ > 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 =3D 0; > > len =3D geo->all_chunks * sizeof(*meta); > - meta =3D kzalloc(len, GFP_KERNEL); > + meta =3D 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 =3D &ndev->geo; > struct nvme_ns *ns =3D ndev->q->queuedata; > struct nvme_ctrl *ctrl =3D ns->ctrl; > - struct nvme_nvm_chk_meta *dev_meta =3D (struct nvme_nvm_chk_meta = *)meta; > + struct nvme_nvm_chk_meta *dev_meta, *dev_meta_off; > struct ppa_addr ppa; > size_t left =3D 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 *nde= v, > */ > max_len =3D min_t(unsigned int, ctrl->max_hw_sectors << 9, 256 * = 1024); > > + dev_meta =3D kmalloc(max_len, GFP_KERNEL); > + if (!dev_meta) > + return -ENOMEM; We should free the memory after using it. Pardon the late review, I just now discovered the memory leak during testing. > + > /* Normalize lba address space to obtain log offset */ > ppa.ppa =3D slba; > ppa =3D dev_to_generic_addr(ndev, ppa); > @@ -604,6 +608,9 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev= , > while (left) { > len =3D min_t(unsigned int, left, max_len); > > + memset(dev_meta, 0, max_len); > + dev_meta_off =3D dev_meta; > + > ret =3D nvme_get_log_ext(ctrl, ns, NVME_NVM_LOG_REPORT_CH= UNK, > dev_meta, len, offset); > if (ret) { > @@ -612,15 +619,15 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *nd= ev, > } > > for (i =3D 0; i < len; i +=3D sizeof(struct nvme_nvm_chk_= meta)) { > - meta->state =3D dev_meta->state; > - meta->type =3D dev_meta->type; > - meta->wi =3D dev_meta->wi; > - meta->slba =3D le64_to_cpu(dev_meta->slba); > - meta->cnlb =3D le64_to_cpu(dev_meta->cnlb); > - meta->wp =3D le64_to_cpu(dev_meta->wp); > + meta->state =3D dev_meta_off->state; > + meta->type =3D dev_meta_off->type; > + meta->wi =3D dev_meta_off->wi; > + meta->slba =3D le64_to_cpu(dev_meta_off->slba); > + meta->cnlb =3D le64_to_cpu(dev_meta_off->cnlb); > + meta->wp =3D le64_to_cpu(dev_meta_off->wp); > > meta++; > - dev_meta++; > + dev_meta_off++; > } > > offset +=3D len; > -- > 2.7.4 >