Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1578856rdb; Wed, 31 Jan 2024 03:04:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYMtr5bUXK91x8NVpzA6fmSP751D28NBM5NS9qRJ31OQzy2pBYxLQxEALBK+zkMw+gF6ZE X-Received: by 2002:a05:6402:1ad1:b0:55e:bbf5:d1d8 with SMTP id ba17-20020a0564021ad100b0055ebbf5d1d8mr815994edb.34.1706699055019; Wed, 31 Jan 2024 03:04:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706699055; cv=pass; d=google.com; s=arc-20160816; b=xatqtzGOkzQKQaoucgFo+Mkd4vCUwF/gELNTIhdEmWa9eND8NByvGJmynYsiVsiNAK HE2yn6YZ06rCJC0W3x4gg5lOtG6N95xOLq7mg31usI4pbxWPgEfcukPNb5tVXRxIr00m pITLsLwyXkFMqWwPFyBKKk2RuPy1/XFEOqZJt+GMyJCmNMYkrmnGVNHn1NUfULk0w7CI eksv3YIy9klJPnKnRzEn0wAs3ddXGWEAOG2K+4QTgXnw37tVPVq3JA/AATEnJyYpDzGq sC6JYkj+Boql9OEQisEN2gzvzVRM49p/xu0WLNsZ+NnK3xthNNo+dW8jXMusZl/irz1v OA0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+9dhGTuTrvDtNIxH7q5czr/K4CZ1+Dif8CoPgq5i65c=; fh=97Za1ukkGtgQwOBxkine7q7yYamAhilZ4jjJXhCV920=; b=fIlIFrBHRIpRuPpyCLFn8VwfXJA8x/m4iLt95fzoLkkst46dVLTAzt2+6fUg8IfKWO pKgFxMg8aUHGImXE0wbpScRIvgIdG97Bb+vwl4aG1uFEGf1HIz1mTUNTQkXagyNS/4PN ObHbt636AxlykzHQERVRFvIF5E9AX1WFYXom2JFq77/Qe0fJgUCCEcei0z/M77Zo+Lfl MJg+qcKgLlS2Bt4H84OS77JayOuaElUoCvn7AHQAG8hY2VSFSQOWWbKwyBxiCQdy+3RZ 7ELMe1PcEVlDQpz2EXjONgHuFZ3WGLeP7vXyOpaqgNPhj5deXV2eRVMU/Zjv9AKMLRCe 0YMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SEoXyIMM; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-46294-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=1; AJvYcCXppqulZnRvHvqIDMHbkDjBTzJjxeGTGWTRevQiaQygisv8dvTPXx6Q7lMKHnLY455mWMM2jUiq1n+T8rmyrXQ8p56uQUmSc/IlqibR3A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cs5-20020a0564020c4500b0055c5ca0f656si5621910edb.503.2024.01.31.03.04.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 03:04:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46294-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SEoXyIMM; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-46294-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 808011F2DB6F for ; Wed, 31 Jan 2024 11:02:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B2F57E571; Wed, 31 Jan 2024 10:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="SEoXyIMM" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B05FE7D3FF; Wed, 31 Jan 2024 10:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706698745; cv=none; b=T+pFd1r1AVBPBNoLtWth7OHnN9VCHoqCKowdbDH/NKMaMnWNR6zSuPQlOFrZMOvV1jm01v1bljMR1oVBqvUVLvXj0EhlEnEe4/ZMat0YbK4d3FULSjw0YrzSFILaXrGlZEe0IrS06StdaPHmQ9TbiX/+OAJk7NjT8F+47JGJ81U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706698745; c=relaxed/simple; bh=1ZxZNZCM1dcA+Ma7AiD7q3Mt0qj7DACwdROPA6/w67o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bTxR4MMrs7pMa6Hi5dkCpW+56UuuJ6GNvo8/OOIuOuSGHGBaUF03sBEVIjMgaYGHoWjdBYQP7CwwYsfUzdBcD2fhsixImmV03I8oe4c8n2qZgImgV6t1cu6zoxUuD5InKeJLIZNbHPWeDj7K1+cAnMp/BA3LcFZFYzruqAQXDcM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=SEoXyIMM; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40V77Tov002033; Wed, 31 Jan 2024 10:58:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=+9dhGTuTrvDtNIxH7q5czr/K4CZ1+Dif8CoPgq5i65c=; b=SE oXyIMMbUxb5qWqFPcA9gQlATTNL3e4cgkzexDMk28FBdFLkDYemfFoSQnvk8URXl ZQEvkTlFpLbMd27uQdPnCRyCDQN0w/FnFFzsvotEuSc7z2ikClQXD4XigDqMrXe2 RNhO8XfxXAcHK9dNumqWJhqvX6QVS927tr0WYl+WeCFjYced6VrPjslautkEjEGm vhGLSZqFK4S7CBXAbO0gAF/6NL3xdL59PVCuaq15wFangyTeaNyl1uziwM5L6WAF dMWv6rWBbQlV7R5uCpzsXtZFCX0p4/xLDYrFNz9Bi4I3JOWjRHTR8WLfm0sU25ml riuAJKHT/eo8Vql42QJg== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vy4rqabtk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 Jan 2024 10:58:44 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 40VAwh35017924 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 Jan 2024 10:58:44 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 31 Jan 2024 02:58:38 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v8 08/10] pstore/ram: Add dynamic ramoops region support through commandline Date: Wed, 31 Jan 2024 16:27:32 +0530 Message-ID: <20240131105734.13090-9-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240131105734.13090-1-quic_mojha@quicinc.com> References: <20240131105734.13090-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: mEiRlN5fdGyLSeDSi-TtI4lOqjhZSZeH X-Proofpoint-GUID: mEiRlN5fdGyLSeDSi-TtI4lOqjhZSZeH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-31_06,2024-01-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 clxscore=1015 bulkscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401190000 definitions=main-2401310083 The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This may not be required for something like Qualcomm's minidump which is interested in knowing addresses of ramoops region but it does not put hard requirement of address being fixed as most of its SoC does not support warm reset and does not use pstorefs at all instead it has firmware way of collecting ramoops region if it gets to know the address and register it with apss minidump table which is sitting in shared memory region in DDR and firmware will have access to these table during reset and collects it on crash of SoC. So, add the support of reserving ramoops region to be dynamically allocated early during boot if it is request through command line via 'dyn_ramoops_size=' and fill up reserved resource structure and export the structure, so that it can be read by ramoops driver. Signed-off-by: Mukesh Ojha --- Documentation/admin-guide/ramoops.rst | 23 +++++++++- fs/pstore/Kconfig | 15 ++++++ fs/pstore/ram.c | 66 +++++++++++++++++++++++++-- include/linux/pstore_ram.h | 5 ++ init/main.c | 3 ++ 5 files changed, 108 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/ramoops.rst b/Documentation/admin-guide/ramoops.rst index e9f85142182d..6de61002f9e9 100644 --- a/Documentation/admin-guide/ramoops.rst +++ b/Documentation/admin-guide/ramoops.rst @@ -33,6 +33,13 @@ memory are implementation defined, and won't work on many ARMs such as omaps. Setting ``mem_type=2`` attempts to treat the memory region as normal memory, which enables full cache on it. This can improve the performance. +Ramoops supports its memory to be allocated dynamically during early boot +for plaforms that do not have support for warm boot i.e., no assurance +that Ram content will be preserved across boot and for these platforms +giving static Ramoops memory is not necessary as it has separate backend +mechanism to retrieve ramoops content on system failure. More about +how to enable Dynamic ramoops in ``Setting the parameters`` A.b section. + The memory area is divided into ``record_size`` chunks (also rounded down to power of two) and each kmesg dump writes a ``record_size`` chunk of information. @@ -59,7 +66,7 @@ Setting the parameters Setting the ramoops parameters can be done in several different manners: - A. Use the module parameters (which have the names of the variables described + A.a Use the module parameters (which have the names of the variables described as before). For quick debugging, you can also reserve parts of memory during boot and then use the reserved memory for ramoops. For example, assuming a machine with > 128 MB of memory, the following kernel command line will tell @@ -68,6 +75,20 @@ Setting the ramoops parameters can be done in several different manners: mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1 + A.b Ramoops memory can be also be dynamically reserved by Kernel and in such + scenario ``mem_address`` i.e., Ramoops base address can be anywhere in the RAM + instead of being fixed and predefined. A separate command line option + ``dyn_ramoops_size=`` and kernel config CONFIG_PSTORE_DYNAMIC_RAMOOPS + are provided to facilitate Dynamic Ramoops memory reservation during early boot. + The command line option and the config should only be used in the presence of + separate backend which knows how to recover Dynamic Ramoops region otherwise + regular ramoops functionality will be impacted. + ``mem_size`` should not be used if Dynamic Ramoops support is requested and if + both are given ``mem_size`` value is overwritten with ``dyn_ramoops_size`` value + i.e., Dynamic Ramoops takes precedence:: + + dyn_ramoops_size=2M ramoops.console_size=2097152 + B. Use Device Tree bindings, as described in ``Documentation/devicetree/bindings/reserved-memory/ramoops.yaml``. For example:: diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index 3acc38600cd1..b8bdbd2f0e73 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -81,6 +81,21 @@ config PSTORE_RAM For more information, see Documentation/admin-guide/ramoops.rst. +config PSTORE_DYNAMIC_RAMOOPS + bool "Reserve ramoops region dynamically" + select PSTORE_RAM + help + This enables the dynamic reservation of ramoops region for a special case + where there is no need to access the logs from pstorefs on next boot; + instead there is separate backend mechanism like minidump present which has + awareness about the dynamic ramoops region and can recover the logs. This is + enabled via command line parameter dyn_ramoops_size= and should not be + used in absence of separate backend which knows how to recover this dynamic + region. + + Note whenever this config is selected ramoops driver will be built statically + into kernel. + config PSTORE_ZONE tristate depends on PSTORE diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 88b34fdbf759..1faf0835700b 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "internal.h" @@ -103,6 +104,59 @@ struct ramoops_context { }; static struct platform_device *dummy; +static struct resource dyn_ramoops_res = { + .name = "ramoops", + .start = 0, + .end = 0, + .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, + .desc = IORES_DESC_NONE, +}; +static int dyn_ramoops_size; + +#ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS +static int __init parse_dyn_ramoops_size(char *p) +{ + char *tmp; + + dyn_ramoops_size = memparse(p, &tmp); + if (p == tmp) { + pr_err("ramoops: memory size expected\n"); + dyn_ramoops_size = 0; + return -EINVAL; + } + + return 0; +} +early_param("dyn_ramoops_size", parse_dyn_ramoops_size); + +/* + * setup_dynamic_ramoops() - Reserve memory for dynamic ramoops + * + * Enables dynamic reserve memory support for ramoops through + * command line. + */ +void __init setup_dynamic_ramoops(void) +{ + unsigned long long ramoops_base; + unsigned long long ramoops_size; + + if (!dyn_ramoops_size) + return; + + ramoops_base = memblock_phys_alloc_range(dyn_ramoops_size, SMP_CACHE_BYTES, + 0, MEMBLOCK_ALLOC_NOLEAKTRACE); + if (!ramoops_base) { + pr_err("cannot allocate ramoops dynamic memory (size:0x%llx).\n", + ramoops_size); + dyn_ramoops_size = 0; + return; + } + + dyn_ramoops_res.start = ramoops_base; + dyn_ramoops_res.end = ramoops_base + dyn_ramoops_size - 1; + insert_resource(&iomem_resource, &dyn_ramoops_res); +} +#endif static int ramoops_pstore_open(struct pstore_info *psi) { @@ -915,13 +969,19 @@ static void __init ramoops_register_dummy(void) /* * Prepare a dummy platform data structure to carry the module - * parameters. If mem_size isn't set, then there are no module - * parameters, and we can skip this. + * parameters. + * + * dyn_ramoops_size takes precedence over mem_size if it is + * enabled and valid. */ - if (!mem_size) + if (!dyn_ramoops_size && !mem_size) return; pr_info("using module parameters\n"); + if (dyn_ramoops_size) { + mem_size = dyn_ramoops_size; + mem_address = dyn_ramoops_res.start; + } memset(&pdata, 0, sizeof(pdata)); pdata.mem_size = mem_size; diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 9d65ff94e216..1efff7a38333 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -39,4 +39,9 @@ struct ramoops_platform_data { struct persistent_ram_ecc_info ecc_info; }; +#ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS +void __init setup_dynamic_ramoops(void); +#else +static inline void __init setup_dynamic_ramoops(void) {} +#endif #endif diff --git a/init/main.c b/init/main.c index ef3ce41b8fc5..3d74241bcb2b 100644 --- a/init/main.c +++ b/init/main.c @@ -99,6 +99,8 @@ #include #include #include +#include +#include #include #include @@ -890,6 +892,7 @@ void start_kernel(void) pr_notice("%s", linux_banner); early_security_init(); setup_arch(&command_line); + setup_dynamic_ramoops(); setup_boot_config(); setup_command_line(command_line); setup_nr_cpu_ids(); -- 2.43.0.254.ga26002b62827