Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp302186imu; Tue, 27 Nov 2018 12:39:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/WWUXPV5hXfYwD89Uivl+u2loDGxNy4fr8gzYUx+x9TxMJG5RV0kUfADI9ITrfGqHUrZMC+ X-Received: by 2002:a63:554b:: with SMTP id f11mr31533742pgm.37.1543351172124; Tue, 27 Nov 2018 12:39:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543351172; cv=none; d=google.com; s=arc-20160816; b=fOmXVMZjwkLaGEmWUXGK8gjBe3ANUXYtRwCaK4Jb2RNvN1vBQajb/u8KCvviw0ZUH2 FeuGLOKYXNIF4l8HBIzpDiXivqb+j+eLhIkiM4cfA+wsprAromX9XDIoeh1WYV1IJ+3L QhtSQ0OZaJfxWSD2KMIGEbA5d/tVgZ7vmALc5xqOjVAOO2vAEnya2ZFxGlk/unoVonTq /DK7j1eRruAxuQCyMTJ29mDNECMNCciK5OGPnUArjPU/fXFlfTgfPta6mUYpyNwC5DXL Ra+Aap8uZWkl9qShC17PAIEaSrMOXcXquYhwQLZ27BH9VC1huoEWl4HNp8SUtX9mmJ3p aqJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=6Xosv/PYIlxW/7LcFhk2Y4xpoy0aK9/l/7lfGLQgQ6o=; b=AulcS/3u28flkZ3fwDpj0bZrUO1piuTbiq74I+k+frpsBOE3x2WUuHQPrVSq9pLDPG hYOOC314X4srGlUZudkRT+lKDTEbBjahE6++bPBKbfciCs4QUJ0eQEuFGrbaElci0Xiw km7GSxT1qqxYgkeBG1HQIUFBE1RGS/jeOu7qEg2ZOgylnKLr4Qgbfr5O5MQ9L+fbKQrG +D5cQL5sjySjeP5e0DAD8tZoiBzPjigj0hHzb8UjLY5BrrUDUMOkO1BqoPvoKEuyMLSV XNt4pPCHahf2zLD9gOfeN2ZcyW4Z/le7nCy1lUnsHGNENKsUAN5aD1DJ/YdJs5U8PVL1 UmOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nQpvp1Cu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y141si5660568pfc.180.2018.11.27.12.39.16; Tue, 27 Nov 2018 12:39:32 -0800 (PST) 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=@kernel.org header.s=default header.b=nQpvp1Cu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726551AbeK1HgO (ORCPT + 99 others); Wed, 28 Nov 2018 02:36:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:34464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbeK1HgO (ORCPT ); Wed, 28 Nov 2018 02:36:14 -0500 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB03A208E4; Tue, 27 Nov 2018 20:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543351028; bh=94tOdGSBsyehMaE+4coOrF+VVT+AjR1ahkqLitXkU/M=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=nQpvp1Cumjm7MhgLtA9iyOytXowFm4hR4BnRYPCQLhGKoLWA/lFLqZzgsbnqfMECF mN6VCwiHG7pe48YN2ALzLWpnrqklej9RPYzD/d+b6h9gkdAvn4rTLCmzm+sg0f+N7Z 4ufGOMcoakwEsB4CSzXZrDiVJgMHZiO4W19+WeHA= Date: Tue, 27 Nov 2018 12:37:05 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: PanBian cc: Boris Ostrovsky , Juergen Gross , Stefano Stabellini , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: Re: [Xen-devel] [PATCH] pvcalls-front: fixes incorrect error handling In-Reply-To: <20181127005823.GB125510@bp> Message-ID: References: <1542852432-30019-1-git-send-email-bianpan2016@163.com> <1f765e81-ed89-d110-74b1-cc8029a4555f@oracle.com> <20181127005823.GB125510@bp> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Nov 2018, PanBian wrote: > On Mon, Nov 26, 2018 at 03:31:39PM -0500, Boris Ostrovsky wrote: > > On 11/21/18 9:07 PM, Pan Bian wrote: > > > kfree() is incorrectly used to release the pages allocated by > > > __get_free_page() and __get_free_pages(). Use the matching deallocators > > > i.e., free_page() and free_pages(), respectively. > > > > > > Signed-off-by: Pan Bian > > > --- > > > drivers/xen/pvcalls-front.c | 4 ++-- > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c > > > index 2f11ca7..77224d8 100644 > > > --- a/drivers/xen/pvcalls-front.c > > > +++ b/drivers/xen/pvcalls-front.c > > > @@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn) > > > out_error: > > > if (*evtchn >= 0) > > > xenbus_free_evtchn(pvcalls_front_dev, *evtchn); > > > - kfree(map->active.data.in); > > > - kfree(map->active.ring); > > > + free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER); > > > > Is map->active.data.in guaranteed to be NULL when entering this routine? > > I am not sure yet. Sorry for that. I observed the mismatches between > __get_free_page and kfree, and submitted the patch. > > But I think your consideration is reasonable. A better solution is to > directly free bytes, a local variable that holds __get_free_pages return > value. If you agree, I will rewrite the patch. Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it? > > -boris > > > > > + free_page((unsigned long)map->active.ring); > > > return ret; > > > } > > > > > >