From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752514AbcCaIPW (ORCPT ); Thu, 31 Mar 2016 04:15:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:38335 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751455AbcCaIPS (ORCPT ); Thu, 31 Mar 2016 04:15:18 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 31 Mar 2016 10:15:16 +0200 From: Johannes Thumshirn To: Ming Lei Cc: Jens Axboe , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig , Naveen Kaje , stable@vger.kernel.org, linux-block-owner@vger.kernel.org Subject: Re: [PATCH v1] block: partition: initialize percpuref before new partition is visiable In-Reply-To: <1459392027-10266-1-git-send-email-ming.lei@canonical.com> References: <1459392027-10266-1-git-send-email-ming.lei@canonical.com> Message-ID: <22ca270520aa88a3e1312bb6af033a3e@suse.de> User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2016-03-31 04:40, Ming Lei wrote: > The initialization of partition's percpu_ref should have been done > before > the new partition is updated to partition table via > rcu_assign_pointer(), otherwise the uninitialized percpu_ref may be > accessed > in data path. > > This patch fixes this issue reported by Naveen. > > Reported-by: Naveen Kaje > Tested-by: Naveen Kaje > Fixes: 6c71013ecb7e2(block: partition: convert percpu ref) > Cc: # v4.3+ > Signed-off-by: Ming Lei > --- > V1: > - put 'if' around the actual device_remove_file at the label > as suggested by Christoph > - make commit log more accurate > > block/partition-generic.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/block/partition-generic.c b/block/partition-generic.c > index 5d87019..54d4be8 100644 > --- a/block/partition-generic.c > +++ b/block/partition-generic.c > @@ -361,15 +361,17 @@ struct hd_struct *add_partition(struct gendisk > *disk, int partno, > goto out_del; > } > > + err = hd_ref_init(p); > + if (err) > + goto out_remove_file; > + > /* everything is up and running, commence */ > rcu_assign_pointer(ptbl->part[partno], p); > > /* suppress uevent if the disk suppresses it */ > if (!dev_get_uevent_suppress(ddev)) > kobject_uevent(&pdev->kobj, KOBJ_ADD); > - > - if (!hd_ref_init(p)) > - return p; > + return p; > > out_free_info: > free_part_info(p); > @@ -378,6 +380,9 @@ out_free_stats: > out_free: > kfree(p); > return ERR_PTR(err); > +out_remove_file: > + if (flags & ADDPART_FLAG_WHOLEDISK) > + device_remove_file(pdev, &dev_attr_whole_disk); > out_del: > kobject_put(p->holder_dir); > device_del(pdev); Looks good, Reviewed-by: Johannes Thumshirn