Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1470732imm; Wed, 17 Oct 2018 21:42:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV63pGs7KcBwGfpR7MlMAWh1SKagYdkZskwGNrwyFWp/KB6q4xhBEvgjom7nECsehGX6sLh5V X-Received: by 2002:a17:902:5a8b:: with SMTP id r11-v6mr29394695pli.305.1539837768436; Wed, 17 Oct 2018 21:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539837768; cv=none; d=google.com; s=arc-20160816; b=Zf2kus/tdGYQjWm4W+zR98JWckvAXyJjxTrZUAEYwY6bDDaS9ysTW0ceeQ0X9MsHkA iCgUz9IQ03SX67k1tmSf9MuguxnpXCmUHFBkGMZlq266xO8xMQjgW6qrCeojVrN/RpbT ZLV8NHpLH4eeDevmEGgCoaD3zgVh+bp4pMAfNWYRMp9IuCxZiKvlDhY4V3EBSIv778xQ 8ell459KhLDV/v6CPHJ+z2BpBGFjbBMrdkLHB9/GOGFWAnw9osz/rjRoeR7Vn4ily9P5 ropMF24Hc4GfwttQ+XtN9uFqdBM24qoX54NJEYqduIRQKJYsRAEXtApI1ZF6gN3vNDmz v/pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature; bh=RM5dgozE5x6vAbfrD+yew7Z7hdkxIwqo445/FYoenPg=; b=UjIPoTJmCbFZWVUuNqPXc7Hh38M/xbOU/Zrk0lWcT/NmDldHVe9QlcMLo33yKhFJo1 6Jr1XB6Q6G9g7Ng52dj6fWViCI5rGP0ktpGmNotdUd0biFZpYlv6B2XKlGzZTk18oq3a M2vjUWtxuY6RhHpiXhn4inEWR86b2JBaj9lJubRcRqaZYFXhTfA68iY+/z9smC98clsk wAekn0kG5HyvtIH03M6/WR4w30UWM/A/O9ttW3usICG2FSlE3RJ6ycbKAcLveMKaUkyy ZTBThkS19UD3qSsDsQl2m+Iai03+2Zuu0YHSweLdJ50QAjfLGYqpip6jvMt1YprYzgPG rFDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=QXPltvLf; dkim=pass header.i=@codeaurora.org header.s=default header.b=QXPltvLf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15-v6si18806760pgg.477.2018.10.17.21.42.31; Wed, 17 Oct 2018 21:42:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=QXPltvLf; dkim=pass header.i=@codeaurora.org header.s=default header.b=QXPltvLf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbeJRMlM (ORCPT + 99 others); Thu, 18 Oct 2018 08:41:12 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:50000 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbeJRMlM (ORCPT ); Thu, 18 Oct 2018 08:41:12 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DE145612EE; Thu, 18 Oct 2018 04:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1539837727; bh=4XlsK3cmdN3AtQsjcNJQ/wnce6q4O587RBK4aboYSHk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=QXPltvLf/nxw1e6ot0tVEW4guFulcE3kFUMULyZxZWR8/4JC8uzZOWNf8UIiRWHml uWmEv8QOfL+yNdYPXjeGXxGbA0mralmG8mht1cVxfdjcR+kjjS/PO4fSAE6EZkSxz2 q/ldi7MlsSLDujV9zyv4u1r9g0DLOHqs+KMGWGn0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from [10.79.129.10] (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: saiprakash.ranjan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D1DDF604BE; Thu, 18 Oct 2018 04:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1539837727; bh=4XlsK3cmdN3AtQsjcNJQ/wnce6q4O587RBK4aboYSHk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=QXPltvLf/nxw1e6ot0tVEW4guFulcE3kFUMULyZxZWR8/4JC8uzZOWNf8UIiRWHml uWmEv8QOfL+yNdYPXjeGXxGbA0mralmG8mht1cVxfdjcR+kjjS/PO4fSAE6EZkSxz2 q/ldi7MlsSLDujV9zyv4u1r9g0DLOHqs+KMGWGn0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D1DDF604BE Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=saiprakash.ranjan@codeaurora.org Subject: Re: [PATCH] pstore: Refactor compression initialization To: Kees Cook , Joel Fernandes Cc: linux-kernel@vger.kernel.org References: <20181017214124.GA8239@beast> <20181018013001.GA99677@joelaf.mtv.corp.google.com> From: Sai Prakash Ranjan Message-ID: <9ebe40c0-5acc-70e1-587d-ba3f0edf2e7b@codeaurora.org> Date: Thu, 18 Oct 2018 10:12:03 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181018013001.GA99677@joelaf.mtv.corp.google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/18/2018 7:00 AM, Joel Fernandes wrote: On Wed, Oct 17, 2018 at 02:41:24PM -0700, Kees Cook wrote: >> With compression initialization now separated from pstore_register(), >> there is no longer a good reason to do compression method selection >> during fs init. Instead, merge everything together into the late init. >> Additionally cleans up the reporting to be more clear. >> >> Signed-off-by: Kees Cook >> --- >> This patch goes on top of Joel's. I'll have both in linux-next shortly... >> --- >> fs/pstore/inode.c | 2 -- >> fs/pstore/internal.h | 3 -- >> fs/pstore/platform.c | 65 ++++++++++++++++++++++++++++---------------- >> 3 files changed, 41 insertions(+), 29 deletions(-) >> >> diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c >> index 5fcb845b9fec..d814723fb27d 100644 >> --- a/fs/pstore/inode.c >> +++ b/fs/pstore/inode.c >> @@ -486,8 +486,6 @@ static int __init init_pstore_fs(void) >> { >> int err; >> >> - pstore_choose_compression(); >> - >> /* Create a convenient mount point for people to access pstore */ >> err = sysfs_create_mount_point(fs_kobj, "pstore"); >> if (err) >> diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h >> index fb767e28aeb2..c029314478fa 100644 >> --- a/fs/pstore/internal.h >> +++ b/fs/pstore/internal.h >> @@ -37,7 +37,4 @@ extern bool pstore_is_mounted(void); >> extern void pstore_record_init(struct pstore_record *record, >> struct pstore_info *psi); >> >> -/* Called during module_init() */ >> -extern void __init pstore_choose_compression(void); >> - >> #endif >> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c >> index f09066db2d4d..e4737a5fa68c 100644 >> --- a/fs/pstore/platform.c >> +++ b/fs/pstore/platform.c >> @@ -274,36 +274,56 @@ static int pstore_decompress(void *in, void *out, >> >> static void allocate_buf_for_compression(void) >> { >> + struct crypto_comp *ctx; >> + int size; >> + char *buf; >> + >> + /* Skip if not built-in or compression backend not selected yet. */ >> if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend) >> return; >> >> + /* Skip if no pstore backend yet or compression init already done. */ >> + if (!psinfo || tfm) >> + return; >> + >> if (!crypto_has_comp(zbackend->name, 0, 0)) { >> - pr_err("No %s compression\n", zbackend->name); >> + pr_err("Unknown compression: %s\n", zbackend->name); >> return; >> } >> >> - big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize); >> - if (big_oops_buf_sz <= 0) >> + size = zbackend->zbufsize(psinfo->bufsize); >> + if (size <= 0) { >> + pr_err("Invalid compression size for %s: %d\n", >> + zbackend->name, size); >> return; >> + } >> >> - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); >> - if (!big_oops_buf) { >> - pr_err("allocate compression buffer error!\n"); >> + buf = kmalloc(size, GFP_KERNEL); >> + if (!buf) { >> + pr_err("Failed %d byte compression buffer allocation for: %s\n", >> + size, zbackend->name); >> return; >> } >> >> - tfm = crypto_alloc_comp(zbackend->name, 0, 0); >> - if (IS_ERR_OR_NULL(tfm)) { >> - kfree(big_oops_buf); >> - big_oops_buf = NULL; >> - pr_err("crypto_alloc_comp() failed!\n"); >> + ctx = crypto_alloc_comp(zbackend->name, 0, 0); >> + if (IS_ERR_OR_NULL(ctx)) { >> + kfree(buf); >> + pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name, >> + PTR_ERR(ctx)); >> return; >> } >> + >> + /* A non-NULL big_oops_buf indicates compression is available. */ >> + tfm = ctx; >> + big_oops_buf_sz = size; >> + big_oops_buf = buf; >> + >> + pr_info("Using compression: %s\n", zbackend->name); >> } >> >> static void free_buf_for_compression(void) >> { >> - if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && !IS_ERR_OR_NULL(tfm)) >> + if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) >> crypto_free_comp(tfm); >> kfree(big_oops_buf); >> big_oops_buf = NULL; >> @@ -764,31 +784,28 @@ static void pstore_timefunc(struct timer_list *unused) >> jiffies + msecs_to_jiffies(pstore_update_ms)); >> } >> >> -void __init pstore_choose_compression(void) >> +static int __init pstore_compression_late_init(void) >> { >> const struct pstore_zbackend *step; >> >> if (!compress) >> - return; >> + return 0; >> >> + /* Locate desired compression method. */ >> for (step = zbackends; step->name; step++) { >> if (!strcmp(compress, step->name)) { >> zbackend = step; >> - pr_info("using %s compression\n", zbackend->name); >> - return; >> + break; >> } >> } >> -} >> >> -static int __init pstore_compression_late_init(void) >> -{ >> /* >> - * Check if any pstore backends registered earlier but did not allocate >> - * for compression because crypto was not ready, if so then initialize >> - * compression. >> + * Check if any pstore backends registered earlier but did not >> + * initialize compression because crypto was not ready. If so, >> + * then initialize compression now. >> */ >> - if (psinfo && !tfm) >> - allocate_buf_for_compression(); >> + allocate_buf_for_compression(); > > We can also get rid of the 'zbackend' global variable since choosing the > compression backend and allocating the buffers are done at the same time? > > Otherwise looks good to me, > > Reviewed-by: Joel Fernandes (Google) > Tested this on top of Joel's patch, works fine on getting early crash pstore dmesg logs, thanks. Tested-by: Sai Prakash Ranjan -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation