From patchwork Mon Dec 20 19:34:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hari Bathini X-Patchwork-Id: 12688439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B91C7C433F5 for ; Mon, 20 Dec 2021 19:34:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 209F26B0073; Mon, 20 Dec 2021 14:34:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B8496B0074; Mon, 20 Dec 2021 14:34:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 059006B0075; Mon, 20 Dec 2021 14:34:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id ECB386B0073 for ; Mon, 20 Dec 2021 14:34:53 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B10D586E6D for ; Mon, 20 Dec 2021 19:34:53 +0000 (UTC) X-FDA: 78939175266.01.1C4D7BB Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf22.hostedemail.com (Postfix) with ESMTP id 91E0FC0041 for ; Mon, 20 Dec 2021 19:34:51 +0000 (UTC) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BKIh5V7003013; Mon, 20 Dec 2021 19:34:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=joAxMmpeOsLwSPVnz1W4tqCwW9Ry5Ontd8ment9YOA8=; b=oMesST7NrcAcPY6PtMcS0fK8uvzKdq57kyq4EqozdLx/7fYzfFH79g5PxTNDvUGQ1/rY OYHAJSiAJ2HtRkfedp0+z4fF6YJpuABnRdWI53NGNHBOHxNBNARtNg9kyj2P+XSGCq8c GGbe4hNgZT3m7oTtYQiH+3uFC93D+nkXql5a7JPKB7YucCmkFe5PHq8trMCxqvXD6pVf z7IYNQtXvIkWDa1cv60eF6fDPuc4p7SVDC4iS2ygXGyibVeupBN3bG8F9VsR0SyqqDH/ Td+bAsZwFShy7mnZ4UeS6tGnEucqbdWbuZyp1rfr47FSy5EkaejG+jXy1QhLjqeXu8Ty 5g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3d1s7qbspq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Dec 2021 19:34:48 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1BKJHU6r021150; Mon, 20 Dec 2021 19:34:48 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3d1s7qbsnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Dec 2021 19:34:47 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1BKJXxop027033; Mon, 20 Dec 2021 19:34:45 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3d179a7qup-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Dec 2021 19:34:45 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1BKJYgH537028114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Dec 2021 19:34:42 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8ACD34C044; Mon, 20 Dec 2021 19:34:42 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B62FD4C046; Mon, 20 Dec 2021 19:34:37 +0000 (GMT) Received: from hbathini-workstation.ibm.com.com (unknown [9.211.62.204]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 20 Dec 2021 19:34:37 +0000 (GMT) From: Hari Bathini To: akpm@linux-foundation.org, linux-mm@kvack.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org Cc: david@redhat.com, osalvador@suse.de, mike.kravetz@oracle.com, mahesh@linux.ibm.com, sourabhjain@linux.ibm.com, Hari Bathini Subject: [PATCH 1/2] mm/cma: provide option to opt out from exposing pages on activation failure Date: Tue, 21 Dec 2021 01:04:18 +0530 Message-Id: <20211220193419.104242-2-hbathini@linux.ibm.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211220193419.104242-1-hbathini@linux.ibm.com> References: <20211220193419.104242-1-hbathini@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: i_3HKsoo2l5g69k8oDvs5fXAyLjf1xzG X-Proofpoint-ORIG-GUID: oHsQMNE2EIR5KbQI-OIWWS4zw1ocyYsx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2021-12-20_09,2021-12-20_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112200109 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 91E0FC0041 X-Stat-Signature: wy1yhdcwyxp75d9u457u417zztw5ap8b Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=oMesST7N; spf=pass (imf22.hostedemail.com: domain of hbathini@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=hbathini@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-HE-Tag: 1640028891-718536 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Commit 072355c1cf2d ("mm/cma: expose all pages to the buddy if activation of an area fails") started exposing all pages to buddy allocator on CMA activation failure. But there can be CMA users that want to handle the reserved memory differently on CMA allocation failure. Provide an option to opt out from exposing pages to buddy for such cases. Signed-off-by: Hari Bathini --- include/linux/cma.h | 2 ++ mm/cma.c | 15 +++++++++++++-- mm/cma.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/cma.h b/include/linux/cma.h index bd801023504b..8c9e229e7080 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -50,4 +50,6 @@ extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count); extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data); + +extern void cma_dont_free_pages_on_error(struct cma *cma); #endif diff --git a/mm/cma.c b/mm/cma.c index bc9ca8f3c487..6dffc9b2dafe 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -131,8 +131,10 @@ static void __init cma_activate_area(struct cma *cma) bitmap_free(cma->bitmap); out_error: /* Expose all pages to the buddy, they are useless for CMA. */ - for (pfn = base_pfn; pfn < base_pfn + cma->count; pfn++) - free_reserved_page(pfn_to_page(pfn)); + if (cma->free_pages_on_error) { + for (pfn = base_pfn; pfn < base_pfn + cma->count; pfn++) + free_reserved_page(pfn_to_page(pfn)); + } totalcma_pages -= cma->count; cma->count = 0; pr_err("CMA area %s could not be activated\n", cma->name); @@ -150,6 +152,14 @@ static int __init cma_init_reserved_areas(void) } core_initcall(cma_init_reserved_areas); +void __init cma_dont_free_pages_on_error(struct cma *cma) +{ + if (!cma) + return; + + cma->free_pages_on_error = false; +} + /** * cma_init_reserved_mem() - create custom contiguous area from reserved memory * @base: Base address of the reserved area @@ -204,6 +214,7 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, cma->base_pfn = PFN_DOWN(base); cma->count = size >> PAGE_SHIFT; cma->order_per_bit = order_per_bit; + cma->free_pages_on_error = true; *res_cma = cma; cma_area_count++; totalcma_pages += (size / PAGE_SIZE); diff --git a/mm/cma.h b/mm/cma.h index 2c775877eae2..9e2438f9233d 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -30,6 +30,7 @@ struct cma { /* kobject requires dynamic object */ struct cma_kobject *cma_kobj; #endif + bool free_pages_on_error; }; extern struct cma cma_areas[MAX_CMA_AREAS]; From patchwork Mon Dec 20 19:34:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hari Bathini X-Patchwork-Id: 12688441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8883C433EF for ; Mon, 20 Dec 2021 19:35:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64CF86B0074; Mon, 20 Dec 2021 14:35:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FDB56B0075; Mon, 20 Dec 2021 14:35:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C5AA6B0078; Mon, 20 Dec 2021 14:35:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 3F0FD6B0074 for ; Mon, 20 Dec 2021 14:35:13 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F1A35181AC9CC for ; Mon, 20 Dec 2021 19:35:12 +0000 (UTC) X-FDA: 78939176064.30.963B0A6 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf20.hostedemail.com (Postfix) with ESMTP id 523641C0026 for ; Mon, 20 Dec 2021 19:35:08 +0000 (UTC) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BKIhrn3005646; Mon, 20 Dec 2021 19:35:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Fv6S8AGmtXS8Ah6jta33Z8s3iT7LAOibEZtDVE+Gkgs=; b=D0nz/hk6hC4MkI/ZJTmWOc2GbIQkrVzhGzt07F5RRVktT9C3oLd9D64b30SUP8d8VuNu w0LUfyVV+LXAgkjGV59VTVkvvbPm08AdLbKe7M0d9NrgaNxCBSUSpCcqe05PqmxtHr1G GfgpEfWKYESJALO2Fk80FAxBv+Yd3OqAThTMQpTgD57yYzDjZbNG4Toz0JvtecXEsFxP SDnyEhU6w18mR/Ni7+5oHTb3lx7UutP+l7+4x7fyMF2AnlLRpUDBCWa7hVWoa4iabX1g KU4zGJ3uWTSXreXI1M9DCPYeUibpjnEq5khrswc6WMsr2CGshH/UmbcJZBIFnOE371V/ xA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3d1s6su0xq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Dec 2021 19:35:09 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1BKJGViB012933; Mon, 20 Dec 2021 19:35:08 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3d1s6su0ws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Dec 2021 19:35:08 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1BKJWc9U013123; Mon, 20 Dec 2021 19:35:06 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3d16wjfu7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Dec 2021 19:35:05 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1BKJZ2nT44761554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Dec 2021 19:35:02 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 513814C044; Mon, 20 Dec 2021 19:35:02 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83A764C040; Mon, 20 Dec 2021 19:34:57 +0000 (GMT) Received: from hbathini-workstation.ibm.com.com (unknown [9.211.62.204]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 20 Dec 2021 19:34:57 +0000 (GMT) From: Hari Bathini To: akpm@linux-foundation.org, linux-mm@kvack.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org Cc: david@redhat.com, osalvador@suse.de, mike.kravetz@oracle.com, mahesh@linux.ibm.com, sourabhjain@linux.ibm.com, Hari Bathini Subject: [PATCH 2/2] powerpc/fadump: opt out from freeing pages on cma activation failure Date: Tue, 21 Dec 2021 01:04:19 +0530 Message-Id: <20211220193419.104242-3-hbathini@linux.ibm.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211220193419.104242-1-hbathini@linux.ibm.com> References: <20211220193419.104242-1-hbathini@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: w9IjLgFp5Y0bzSiyQOx6e-6v3kK3kHTX X-Proofpoint-GUID: pA_kIVZImsaMQaqqrRHhAdNmZxfDaAG0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2021-12-20_09,2021-12-20_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 bulkscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112200107 X-Rspamd-Queue-Id: 523641C0026 X-Stat-Signature: 5iobs3jitugo4w4sfzkfntg5rwon1s3r Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="D0nz/hk6"; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf20.hostedemail.com: domain of hbathini@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=hbathini@linux.ibm.com X-Rspamd-Server: rspam11 X-HE-Tag: 1640028908-632875 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With commit a4e92ce8e4c8 ("powerpc/fadump: Reservationless firmware assisted dump"), Linux kernel's Contiguous Memory Allocator (CMA) based reservation was introduced in fadump. That change was aimed at using CMA to let applications utilize the memory reserved for fadump while blocking it from being used for kernel pages. The assumption was, even if CMA activation fails for whatever reason, the memory still remains reserved to avoid it from being used for kernel pages. But commit 072355c1cf2d ("mm/cma: expose all pages to the buddy if activation of an area fails") breaks this assumption as it started exposing all pages to buddy allocator on CMA activation failure. It led to warning messages like below while running crash-utility on vmcore of a kernel having above two commits: crash: seek error: kernel virtual address: To fix this problem, opt out from exposing pages to buddy allocator on CMA activation failure for fadump reserved memory. Signed-off-by: Hari Bathini --- arch/powerpc/kernel/fadump.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index b7ceb041743c..d1f7f79dfbd8 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -112,6 +112,12 @@ static int __init fadump_cma_init(void) return 1; } + /* + * If CMA activation fails, do not let the reserved memory be exposed + * to buddy allocator. As good as 'fadump=nocma' case. + */ + cma_dont_free_pages_on_error(fadump_cma); + /* * So we now have successfully initialized cma area for fadump. */