From patchwork Thu May 17 08:40:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8707 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 28A7223E1B for ; Thu, 17 May 2012 08:42:14 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id EC402A18AE0 for ; Thu, 17 May 2012 08:42:13 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so1869871yen.11 for ; Thu, 17 May 2012 01:42:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:date:from :to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:x-gm-message-state; bh=6XD9WnCE89KYRk/Qk0gRNajFsl5SNbOrm6qy2fnC6xo=; b=k6cVIKPb1bYxeJhpfC9/vJ3Vfpms/pNCqyVtH3QopRtsQTe30cTc93c9zFScmhhpaj AF513fHW3Tdfps8ti+vPu7+aLuiDRqyPYNoth5b6GCuBGOwNBkmWS2UXncjDr05dOozd DedYfgyBxUEYdbPyvwi9YGUWd775JzAuX/m1ou18hFVuqe+HvHIoBFyEJmJ8iwW9J1KB MnotqI8UuwP7pxg7NuvaNYZj8P6GRl6l02u2DJ2d+tS37quFuvV0ALbj+U2c8MBMcH9d pota7GceY8bUYGZQDnC3Bt7EXBSc7EjOpHxrzOEH7RXH0IDOuqE/IrJGUQyYzeG+AWvu OWlA== Received: by 10.50.195.234 with SMTP id ih10mr4583364igc.0.1337244133543; Thu, 17 May 2012 01:42:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp12011ibd; Thu, 17 May 2012 01:42:13 -0700 (PDT) Received: by 10.68.132.102 with SMTP id ot6mr8314287pbb.6.1337244132744; Thu, 17 May 2012 01:42:12 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id ou2si9090042pbb.69.2012.05.17.01.42.12 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 01:42:12 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id rr4so2728950pbb.37 for ; Thu, 17 May 2012 01:42:12 -0700 (PDT) Received: by 10.68.217.132 with SMTP id oy4mr26028860pbc.4.1337244132480; Thu, 17 May 2012 01:42:12 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id gq5sm6626674pbc.65.2012.05.17.01.42.09 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 01:42:11 -0700 (PDT) Date: Thu, 17 May 2012 01:40:43 -0700 From: Anton Vorontsov To: Greg Kroah-Hartman , Kees Cook , Colin Cross , Tony Luck Cc: Arnd Bergmann , John Stultz , Shuah Khan , arve@android.com, Rebecca Schultz Zavin , Jesper Juhl , Randy Dunlap , Stephen Boyd , Thomas Meyer , Andrew Morton , Marco Stornelli , WANG Cong , linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com Subject: [PATCH 2/6] pstore/ram: Add console messages handling Message-ID: <20120517084042.GB31753@lizard> References: <20120517083740.GA25627@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120517083740.GA25627@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQnisg9ixe4aPkHVg0qc0pWorDb0x//Dr9Qu2dWjfDnBjhAU/OdcWOyFqmR6mDBUpf1OzZd2 This is all straightforward: we just use the last region for console logging. If there's just one region, we fall-back to the old behaviour: just a oops/dumps logging. Signed-off-by: Anton Vorontsov Acked-by: Kees Cook --- fs/pstore/ram.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 9123cce..5d6d53e 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -63,6 +63,7 @@ MODULE_PARM_DESC(ramoops_ecc, struct ramoops_context { struct persistent_ram_zone **przs; + struct persistent_ram_zone *cprz; phys_addr_t phys_addr; unsigned long size; size_t record_size; @@ -70,6 +71,7 @@ struct ramoops_context { bool ecc; unsigned int count; unsigned int max_count; + unsigned int max_dump_count; unsigned int read_count; struct pstore_info pstore; }; @@ -92,16 +94,20 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, { ssize_t size; struct ramoops_context *cxt = psi->data; - struct persistent_ram_zone *prz; - - if (cxt->read_count >= cxt->max_count) - return -EINVAL; + struct persistent_ram_zone *prz = cxt->przs[cxt->read_count]; *id = cxt->read_count++; - prz = cxt->przs[*id]; - /* Only supports dmesg output so far. */ - *type = PSTORE_TYPE_DMESG; + if (*id < cxt->max_dump_count && persistent_ram_old_size(prz)) { + *type = PSTORE_TYPE_DMESG; + } else if (*id < cxt->max_count) { + *type = PSTORE_TYPE_CONSOLE; + prz = cxt->cprz; + cxt->read_count = cxt->max_count; + } else { + return 0; + } + /* TODO(kees): Bogus time for the moment. */ time->tv_sec = 0; time->tv_nsec = 0; @@ -142,7 +148,13 @@ static int ramoops_pstore_write(enum pstore_type_id type, struct persistent_ram_zone *prz = cxt->przs[cxt->count]; size_t hlen; - /* Currently ramoops is designed to only store dmesg dumps. */ + if (type == PSTORE_TYPE_CONSOLE) { + if (!cxt->cprz) + return -ENOMEM; + persistent_ram_write(cxt->cprz, cxt->pstore.buf, size); + return 0; + } + if (type != PSTORE_TYPE_DMESG) return -EINVAL; @@ -170,7 +182,7 @@ static int ramoops_pstore_write(enum pstore_type_id type, size = prz->buffer_size - hlen; persistent_ram_write(prz, cxt->pstore.buf, size); - cxt->count = (cxt->count + 1) % cxt->max_count; + cxt->count = (cxt->count + 1) % cxt->max_dump_count; return 0; } @@ -264,6 +276,16 @@ static int __init ramoops_probe(struct platform_device *pdev) } } + /* + * The last zone is for TYPE_CONSOLE, unless we have only + * one, in which case we use it for oops/panic logging. + */ + cxt->max_dump_count = cxt->max_count; + if (cxt->max_count > 1) { + cxt->max_dump_count--; + cxt->cprz = cxt->przs[cxt->max_count - 1]; + } + cxt->pstore.data = cxt; cxt->pstore.bufsize = cxt->przs[0]->buffer_size; cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL);