From patchwork Sat May 26 13:07:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8986 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 CC85E23E37 for ; Sat, 26 May 2012 13:10:21 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 76CD0A18491 for ; Sat, 26 May 2012 13:10:21 +0000 (UTC) Received: by yhpp61 with SMTP id p61so1369300yhp.11 for ; Sat, 26 May 2012 06:10:21 -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:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=E7j4WbUeLUzw7g080eTyHwTv5fRX1pxJyGHryeqsPeo=; b=efK6yj0DRl8YYpx5gWGhCmMt39bHn/MOUMPblUKB9ms+1kihlkDUflVKO5fBD9WdgX Y3gMbQz82WwiA6eFshqMQw2j90J5PLSucE0B99ogkDgfE62fgffB7LrBrj3bKy6Zo7Pr YtPM8BWYW97NJUKz35cwgooJ+e80fi6dIsB+CLHzITHgckvg8uxKohXdqwLqp5LGhHNV Ah4vZZpdiAHoAJocsUDjCefpXLwSBodDseXvxDX8LIz8f2Zy1iiDkCkVirgZenyo8UkH ZapyjpSpMvGBTUec7XdGNmfPbA0TaP8LEVFxZRulYgXcCviU/abaUsj6yOYg6KyL2xcz FnDA== Received: by 10.42.163.129 with SMTP id c1mr786192icy.57.1338037820806; Sat, 26 May 2012 06:10:20 -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.24.148 with SMTP id v20csp85846ibb; Sat, 26 May 2012 06:10:20 -0700 (PDT) Received: by 10.68.132.201 with SMTP id ow9mr7382165pbb.160.1338037817880; Sat, 26 May 2012 06:10:17 -0700 (PDT) Received: from mail-pz0-f50.google.com (mail-pz0-f50.google.com [209.85.210.50]) by mx.google.com with ESMTPS id rj10si7802936pbc.304.2012.05.26.06.10.17 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 May 2012 06:10:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.210.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.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 danh15 with SMTP id h15so2714114dan.37 for ; Sat, 26 May 2012 06:10:17 -0700 (PDT) Received: by 10.68.223.35 with SMTP id qr3mr7811879pbc.83.1338037815381; Sat, 26 May 2012 06:10:15 -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 ny10sm12510807pbb.38.2012.05.26.06.10.12 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 May 2012 06:10:14 -0700 (PDT) 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 1/5] pstore/ram: Should update old dmesg buffer before reading Date: Sat, 26 May 2012 06:07:49 -0700 Message-Id: <1338037673-19909-1-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.9.2 In-Reply-To: <20120526130650.GA6242@lizard> References: <20120526130650.GA6242@lizard> X-Gm-Message-State: ALoCoQmSlMMU01ZExL8VzMeOPXkIhom2MTw+1PEPo+euwCKwG9FlybEHmXadAzEWRDwsDwTftsL9 Without the update, we'll only see the new dmesg buffer after the reboot, but previously we could see it right away. Making an oops visible in pstore filesystem before reboot is a somewhat dubious feature, but removing it wasn't an intentional change, so let's restore it. For this we have to make persistent_ram_save_old() safe for calling multiple times, and also extern it. Signed-off-by: Anton Vorontsov Acked-by: Kees Cook --- fs/pstore/ram.c | 2 ++ fs/pstore/ram_core.c | 15 ++++++++------- include/linux/pstore_ram.h | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 9123cce..16ff733 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -106,6 +106,8 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, time->tv_sec = 0; time->tv_nsec = 0; + /* Update old/shadowed buffer. */ + persistent_ram_save_old(prz); size = persistent_ram_old_size(prz); *buf = kmalloc(size, GFP_KERNEL); if (*buf == NULL) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 31f8d18..235513c 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -250,23 +250,24 @@ static void notrace persistent_ram_update(struct persistent_ram_zone *prz, persistent_ram_update_ecc(prz, start, count); } -static void __init -persistent_ram_save_old(struct persistent_ram_zone *prz) +void persistent_ram_save_old(struct persistent_ram_zone *prz) { struct persistent_ram_buffer *buffer = prz->buffer; size_t size = buffer_size(prz); size_t start = buffer_start(prz); - char *dest; - persistent_ram_ecc_old(prz); + if (!size) + return; - dest = kmalloc(size, GFP_KERNEL); - if (dest == NULL) { + if (!prz->old_log) { + persistent_ram_ecc_old(prz); + prz->old_log = kmalloc(size, GFP_KERNEL); + } + if (!prz->old_log) { pr_err("persistent_ram: failed to allocate buffer\n"); return; } - prz->old_log = dest; prz->old_log_size = size; memcpy(prz->old_log, &buffer->data[start], size - start); memcpy(prz->old_log + size - start, &buffer->data[0], start); diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 7ed7fd4..4491e8f 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -75,6 +75,7 @@ struct persistent_ram_zone *persistent_ram_init_ringbuffer(struct device *dev, int persistent_ram_write(struct persistent_ram_zone *prz, const void *s, unsigned int count); +void persistent_ram_save_old(struct persistent_ram_zone *prz); size_t persistent_ram_old_size(struct persistent_ram_zone *prz); void *persistent_ram_old(struct persistent_ram_zone *prz); void persistent_ram_free_old(struct persistent_ram_zone *prz);