Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751765AbdIULOI (ORCPT ); Thu, 21 Sep 2017 07:14:08 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:47132 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbdIULOG (ORCPT ); Thu, 21 Sep 2017 07:14:06 -0400 X-Google-Smtp-Source: AOwi7QApwrW+64/pboJxB/pV0wuYRvSc8/eDLFy/7l+hnJ/gEzeuUnTHcmyRCe7/56t7FQb4Ny4MUA== Subject: Re: [PATCH V2] lightnvm: protect target type list with correct locks To: =?UTF-8?Q?Javier_Gonz=c3=a1lez?= , Rakesh Pandit Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20170916183931.GA2824@hercules.tuxera.com> <3891AF6A-D87D-4727-BF9C-E6689C232BC9@lightnvm.io> From: =?UTF-8?Q?Matias_Bj=c3=b8rling?= Message-ID: Date: Thu, 21 Sep 2017 13:14:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <3891AF6A-D87D-4727-BF9C-E6689C232BC9@lightnvm.io> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1923 Lines: 61 On 09/18/2017 09:53 AM, Javier González wrote: >> On 16 Sep 2017, at 20.39, Rakesh Pandit wrote: >> >> nvm_tgt_types list was protected by wrong lock for NVM_INFO ioctl call >> and can race with addition or removal of target types. Also >> unregistering target type was not protected correctly. >> >> Fixes: 5cd907853 ("lightnvm: remove nested lock conflict with mm") >> Signed-off-by: Rakesh Pandit >> --- >> >> V2: also add correct lock while unregistering and fix "Fixes" tag at >> end. Note I found these while investigating another issue and >> skimming the core code but worth fixing. >> >> drivers/lightnvm/core.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c >> index 9f9a137..1b8338d 100644 >> --- a/drivers/lightnvm/core.c >> +++ b/drivers/lightnvm/core.c >> @@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt) >> if (!tt) >> return; >> >> - down_write(&nvm_lock); >> + down_write(&nvm_tgtt_lock); >> list_del(&tt->list); >> - up_write(&nvm_lock); >> + up_write(&nvm_tgtt_lock); >> } >> EXPORT_SYMBOL(nvm_unregister_tgt_type); >> >> @@ -1190,7 +1190,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) >> info->version[1] = NVM_VERSION_MINOR; >> info->version[2] = NVM_VERSION_PATCH; >> >> - down_write(&nvm_lock); >> + down_write(&nvm_tgtt_lock); >> list_for_each_entry(tt, &nvm_tgt_types, list) { >> struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter]; >> >> @@ -1203,7 +1203,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) >> } >> >> info->tgtsize = tgt_iter; >> - up_write(&nvm_lock); >> + up_write(&nvm_tgtt_lock); >> >> if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) { >> kfree(info); >> -- >> 2.7.4 > > LGTM. > > Reviewed-by: Javier González > Thanks Rakesh.