From patchwork Fri May 26 05:21:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 767228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wYvfm29Fpz9s8Y for ; Fri, 26 May 2017 15:23:12 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wYvfl2TX7zDqSy for ; Fri, 26 May 2017 15:23:11 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wYvfh12NGzDqSt for ; Fri, 26 May 2017 15:23:07 +1000 (AEST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4Q5K98Q074984 for ; Fri, 26 May 2017 01:23:00 -0400 Received: from e23smtp09.au.ibm.com (e23smtp09.au.ibm.com [202.81.31.142]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ap7mc5cb9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 26 May 2017 01:22:59 -0400 Received: from localhost by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 26 May 2017 15:22:57 +1000 Received: from d23relay07.au.ibm.com (202.81.31.226) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 26 May 2017 15:22:55 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4Q5Mk0D59572416 for ; Fri, 26 May 2017 15:22:54 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4Q5MMYt013986 for ; Fri, 26 May 2017 15:22:22 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4Q5MMYs013265; Fri, 26 May 2017 15:22:22 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 146B3A0109; Fri, 26 May 2017 15:21:58 +1000 (AEST) Received: from gwshan.ozlabs.ibm.com (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 0BC6DE3881; Fri, 26 May 2017 15:21:58 +1000 (AEST) Received: by gwshan.ozlabs.ibm.com (Postfix, from userid 1000) id EBD90AC1916; Fri, 26 May 2017 15:21:57 +1000 (AEST) From: Gavin Shan To: skiboot@lists.ozlabs.org Date: Fri, 26 May 2017 15:21:56 +1000 X-Mailer: git-send-email 2.7.4 X-TM-AS-MML: disable x-cbid: 17052605-0052-0000-0000-00000245083D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052605-0053-0000-0000-00000821A32F Message-Id: <1495776116-27890-1-git-send-email-gwshan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-26_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705260098 Subject: [Skiboot] [PATCH] core/mem_region: Give up on freeing unmanaged memory block X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" When adding memory regions to global list, the overlapped one (including it's descriptor) is purged. However, the descriptor might be in BSS (not HEAP) section. It will trigger the exception caused by assert() in mem_free() as below backtrace indicates. The memory regions causing this are "ibm,os-reserve" and "hostboot-reserve-0" separately. The former descriptor is resident in BSS section while the later one is in HEAP: CPU 0050 Backtrace: S: 0000000031d43a00 R: 00000000300136d0 .backtrace+0x2c S: 0000000031d43a90 R: 00000000300191ec ._abort+0x4c S: 0000000031d43b10 R: 0000000030019268 .assert_fail+0x34 S: 0000000031d43b90 R: 0000000030015d08 .mem_free+0x64 S: 0000000031d43c20 R: 0000000030017080 .__free+0x38 S: 0000000031d43cb0 R: 0000000030015518 .add_region+0x230 S: 0000000031d43d60 R: 0000000030016854 .mem_region_init+0x2c8 S: 0000000031d43e30 R: 0000000030014994 .main_cpu_entry+0x3ec S: 0000000031d43f00 R: 0000000030002648 boot_entry+0x198 This fixes the issue by doing nothing when trying to freeing memory block which is resident in unmanaged (not HEAP) region. Signed-off-by: Gavin Shan --- core/mem_region.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/mem_region.c b/core/mem_region.c index a314558..bfb5ac9 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -469,9 +469,10 @@ void mem_free(struct mem_region *region, void *mem, const char *location) if (!mem) return; - /* Your memory is in the region, right? */ - assert(mem >= region_start(region) + sizeof(*hdr)); - assert(mem < region_start(region) + region->len); + /* Give up if it is in unmanaged and invalid regions */ + if (mem < (region_start(region) + sizeof(*hdr)) || + mem >= (region_start(region) + region->len)) + return; /* Grab header. */ hdr = mem - sizeof(*hdr);