From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753993AbcB2LDA (ORCPT ); Mon, 29 Feb 2016 06:03:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41776 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752802AbcB2LC5 (ORCPT ); Mon, 29 Feb 2016 06:02:57 -0500 Date: Mon, 29 Feb 2016 19:06:46 +0800 From: Minfei Huang To: Andrew Morton Cc: ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Minfei Huang Subject: Re: [PATCH] kexec: Make a pair of map/unmap reserved pages in error path Message-ID: <20160229110646.GA27178@dhcp-128-25.nay.redhat.com> References: <1456408960-12296-1-git-send-email-mhuang@redhat.com> <20160226165605.efc4bc6fe3e90faccff79fd9@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160226165605.efc4bc6fe3e90faccff79fd9@linux-foundation.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/26/16 at 04:56pm, Andrew Morton wrote: > On Thu, 25 Feb 2016 22:02:40 +0800 Minfei Huang wrote: > > > From: Minfei Huang > > > > For some arch, kexec shall map the reserved pages, then use them, when > > we try to start the kdump service. > > > > kexec may return directly, without unmaping the reserved pages, if it > > fails during starting service. To fix it, we make a pair of map/unmap > > reserved pages both in generic path and error path. > > This patch both refactors the code AND fixes the bug. It is a > decent-looking refactoring, but mixing the two together makes it *much* > harder to review the bugfix. These two steps should be separated > please, with the bugfix patch coming first. I will bisect this patch to make it more simple to be reviewed. > > > --- a/kernel/kexec.c > > +++ b/kernel/kexec.c > > @@ -103,6 +103,68 @@ out_free_image: > > return ret; > > } > > > > +static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > + struct kexec_segment __user *segments, unsigned long flags) > > +{ > > + struct kimage **dest_image, *image; > > + unsigned long i; > > + int ret; > > + > > + if (flags & KEXEC_ON_CRASH) > > + dest_image = &kexec_crash_image; > > + else > > + dest_image = &kexec_image; > > + > > + if (nr_segments == 0) { > > + /* Uninstall image */ > > + kimage_free(xchg(dest_image, NULL)); > > + return 0; > > + } > > + if (flags & KEXEC_ON_CRASH) { > > + /* > > + * Loading another kernel to switch to if this one > > + * crashes. Free any current crash dump kernel before > > + * we corrupt it. > > + */ > > + kimage_free(xchg(&kexec_crash_image, NULL)); > > + } > > + > > + ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags); > > + if (ret) > > + return ret; > > This is a bug, isn't it? Missed kimage_free(). The variable image is NULL, if kimage_alloc_init returns with error. And kimage_alloc_init will do the cleanup before returning. So it's fine without calling kimage_free. Thanks Minfei