From patchwork Tue May 22 14:17:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8872 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 8838823F0A for ; Tue, 22 May 2012 14:20:04 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 43045A18B71 for ; Tue, 22 May 2012 14:20:04 +0000 (UTC) Received: by ghbz12 with SMTP id z12so1034804ghb.11 for ; Tue, 22 May 2012 07:20:03 -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=xzb/VuWVDRTr7NlB+wKeO6TE6nsaoM0v+9bVHVgbEv4=; b=jjycGX20a+5FnHyClQkUuQ3pnmpP0z9G9446/71MOtG/Nyy8QW4upGsNnlSf34U9Wg Indv8MTYfvp2Icqhjj9yzY+h4xx2trpI5CFWE4wA3MnxmAZHJMQO3RvgKFDboIvY3ywD fFTJhUC8uUZDELDbr47BMUb4nAxPI7klrliUsKBzQ7Svtt7T/dw4pioUTeJ/s/qdwBNY 6MJ1j3J/tb0aLmCAwPhUy5Vv5L3lf6WYQ4NuGXX1oNsbK+y2g2ucMbvcgEjQpS3R+E6r AiEIGPjDoAH39YYUyhGkXNxRoDihXBm4p5ou9N/OqjA2ySL0Z5jarLUQJC996rXWY9L+ xEsA== Received: by 10.50.46.232 with SMTP id y8mr9295465igm.57.1337696403253; Tue, 22 May 2012 07:20:03 -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 o8csp369485ibd; Tue, 22 May 2012 07:20:02 -0700 (PDT) Received: by 10.68.219.166 with SMTP id pp6mr80904025pbc.35.1337696402393; Tue, 22 May 2012 07:20:02 -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 t9si31663461pbj.12.2012.05.22.07.20.02 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 May 2012 07:20:02 -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 h15so9932040dan.37 for ; Tue, 22 May 2012 07:20:02 -0700 (PDT) Received: by 10.68.132.201 with SMTP id ow9mr80147282pbb.160.1337696402046; Tue, 22 May 2012 07:20:02 -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 pu5sm26871276pbc.28.2012.05.22.07.19.59 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 May 2012 07:20:01 -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 02/16] pstore/ram: Should update old dmesg buffer before reading Date: Tue, 22 May 2012 07:17:45 -0700 Message-Id: <1337696279-8994-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.9.2 In-Reply-To: <20120522141717.GA31574@lizard> References: <20120522141717.GA31574@lizard> X-Gm-Message-State: ALoCoQkqw7188aEeuRgtW0zOxKXw4C4jGj9PJiuw5wNS7AtxV1wohhm/xJ9JT4UnuEKbVubT+RHU 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);