From patchwork Thu Oct 6 22:42:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33178C433F5 for ; Thu, 6 Oct 2022 22:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232190AbiJFWnB (ORCPT ); Thu, 6 Oct 2022 18:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbiJFWnA (ORCPT ); Thu, 6 Oct 2022 18:43:00 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AE77F2537; Thu, 6 Oct 2022 15:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ux48LLt57AGPgmUYDQ9s60SdNch88HLBtYUsjAHGl1I=; b=jAPeqo2Ws0y4fXsh0Yglfckq1e /jX4ZsrqEtq6jzai0vPaAJeGCpmGhhaEdOCz1aWzTz3iO/mFhUjYJJJKfKH2EvvnYMp/un8t+PNSW TmzhihtEaqJJBS/fCpQvBrH6eTiN9p0b7dOr5Tqdz/7H16zsWw4DCcKPywdEYsVmWPXbTA1vlngmC XbzQwUP1ynRLdkPEvNa1snNyR4WEpcvP8ednMvFobRfo6rSJ88zIii+Mo2z7DkXHz54RH1xZk7pTW x1ZuLvogrxTbWKAhx6Ajp6SkgcYRidv7GIvaT+gSwjUCY3oKtS0Ip9rTY5dvOiSdZ069ysyjDYgkk OOnTY30g==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZZw-00C4J5-QA; Fri, 07 Oct 2022 00:42:57 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" Subject: [PATCH 1/8] pstore: Improve error reporting in case of backend overlap Date: Thu, 6 Oct 2022 19:42:05 -0300 Message-Id: <20221006224212.569555-2-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The pstore infrastructure supports one single backend at a time; trying to load a another backend causes an error and displays a message, introduced on commit 0d7cd09a3dbb ("pstore: Improve register_pstore() error reporting"). Happens that this message is not really clear about the situation, also the current error returned (-EPERM) isn't accurate, whereas -EBUSY makes more sense. We have another place in the code that relies in the -EBUSY return for a similar check. So, make it consistent here by returning -EBUSY and using a similar message in both scenarios. Signed-off-by: Guilherme G. Piccoli --- fs/pstore/platform.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 0c034ea39954..c32957e4b256 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -562,8 +562,9 @@ static int pstore_write_user_compat(struct pstore_record *record, int pstore_register(struct pstore_info *psi) { if (backend && strcmp(backend, psi->name)) { - pr_warn("ignoring unexpected backend '%s'\n", psi->name); - return -EPERM; + pr_warn("backend '%s' already in use: ignoring '%s'\n", + backend, psi->name); + return -EBUSY; } /* Sanity check flags. */ From patchwork Thu Oct 6 22:42:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59EB2C433F5 for ; Thu, 6 Oct 2022 22:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232273AbiJFWnU (ORCPT ); Thu, 6 Oct 2022 18:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232294AbiJFWnO (ORCPT ); Thu, 6 Oct 2022 18:43:14 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80819142C9A; Thu, 6 Oct 2022 15:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ROxU9ZPvDJlhMxlhvGBHee4urUu69sraTMRl63LvHNo=; b=oebQFFy873qnFMejWs0yByUCJu qZOVtCliWUehonJMF4AVEmd6/c4MT+TrOtlHrP6Hbp1qjgWtsmf2iJLrTIz1PNpx0pmyFl/xtWoks JvNfIiFfEWFHeQwfcY31fVm2MI0gyL0FSecRBMfOW9TR4K45Ih2wVTsx0hZhdBZdBfDCpi6wRPxVf y89SLESrHPvtOFEvtKHyrr742UaWHpTOwsxM68Zc+BKYJ75s6asrQTvMuv3WoXZJe2EmLWW5i0iP6 /XIlY3Ex1qGehh4xHwCLUZodMi97dYlZpaL2iiXzpfnlScxgtGcEabm5B2jxoM1JuPrrQiAKbZtHs Musmo8gg==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZaA-00C4JQ-GL; Fri, 07 Oct 2022 00:43:11 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" Subject: [PATCH 2/8] pstore: Expose kmsg_bytes as a module parameter Date: Thu, 6 Oct 2022 19:42:06 -0300 Message-Id: <20221006224212.569555-3-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently this tuning is only exposed as a filesystem option, but most Linux distros automatically mount pstore, hence changing this setting requires remounting it. Also, if that mount option wasn't explicitly set it doesn't show up in mount information, so users cannot check what is the current value of kmsg_bytes. Let's then expose it as a module parameter, allowing both user visibility at all times (even if not manually set) and also the possibility of setting that as a boot/module parameter. Signed-off-by: Guilherme G. Piccoli --- fs/pstore/platform.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index c32957e4b256..be05090076ce 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -89,6 +89,11 @@ static char *compress = module_param(compress, charp, 0444); MODULE_PARM_DESC(compress, "compression to use"); +/* How much of the kernel log to snapshot */ +unsigned long kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES; +module_param(kmsg_bytes, ulong, 0444); +MODULE_PARM_DESC(kmsg_bytes, "amount of kernel log to snapshot (in bytes)"); + /* Compression parameters */ static struct crypto_comp *tfm; @@ -100,9 +105,6 @@ struct pstore_zbackend { static char *big_oops_buf; static size_t big_oops_buf_sz; -/* How much of the console log to snapshot */ -unsigned long kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES; - void pstore_set_kmsg_bytes(int bytes) { kmsg_bytes = bytes; From patchwork Thu Oct 6 22:42:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E9BCC433F5 for ; Thu, 6 Oct 2022 22:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232294AbiJFWnf (ORCPT ); Thu, 6 Oct 2022 18:43:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232288AbiJFWn2 (ORCPT ); Thu, 6 Oct 2022 18:43:28 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB326142C94; Thu, 6 Oct 2022 15:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BzPX7ATJ1oaxpGuf0PVinseY88CmdU+HARHaDj9AtIo=; b=XFTEarTMRQ8OPVLnEUe7ojm1rN KY2CyosasIJ4PjDyLd8UgRQhgpbO2C63gXavydiLAkrGkeBugdaoaMXSe/i2IrTVvqxoKQBCdtnbf T2FEzsQGQvW+fcQpwntv//6VjC7EZJ+kBwqArSTc5X4MsYdp1q78eFRAwYgKnw/uejGFoRZtnYp3B KlfEyqbxpctfP4Ml6yG7UPnZksHP9Cju9xhAKOagBStgz7kr4hpWR8aSx8d/HVNoAncZh55ssjkCg Hvvm2bu0ilt94rfR+O00FeVWKboVjPvrwOS477f/wjkz3KV6Aquu9rZ6G8rWjHOChDipD6Rqhh/QD APhNfXkA==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZaP-00C4Ks-CC; Fri, 07 Oct 2022 00:43:26 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" Subject: [PATCH 3/8] pstore: Inform unregistered backend names as well Date: Thu, 6 Oct 2022 19:42:07 -0300 Message-Id: <20221006224212.569555-4-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently we only show the registered ones in the kernel log; users that change backend for some reason require first to unregister the current one, so let's confirm this operation with a message in the log. Signed-off-by: Guilherme G. Piccoli --- fs/pstore/platform.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index be05090076ce..06c2c66af332 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -665,6 +665,8 @@ void pstore_unregister(struct pstore_info *psi) psinfo = NULL; kfree(backend); backend = NULL; + + pr_info("Unregistered %s as persistent store backend\n", psi->name); mutex_unlock(&psinfo_lock); } EXPORT_SYMBOL_GPL(pstore_unregister); From patchwork Thu Oct 6 22:42:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C904EC433F5 for ; Thu, 6 Oct 2022 22:43:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232280AbiJFWnn (ORCPT ); Thu, 6 Oct 2022 18:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232238AbiJFWnm (ORCPT ); Thu, 6 Oct 2022 18:43:42 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E7AAF2539; Thu, 6 Oct 2022 15:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=OOh5S7b6Hnc2HBjRQcJVdon08G2hglJQpnHO9T3Cemg=; b=ThouN2ayN/yFeffHynfhHg2/qD w4T8KYJlY8/StyOg87HM20xS9875r/MjXAPdnPBM+KQwsQOpHLwysnjEAtYWsTBrC2UAemnOSupPS OTPONbqDcq15jtfcB5JK/74xz7CtFKa7BdT9NQNyQgO3NXoGbTrKkqb/VAB7v/E4ObTGGjTX++Idr uQ0Pcdk/iruuagZWGebLNCeV/UOnL9QqAXMmIAI2IVua2QZ3zOt2v0sNzxuEbUHmDAOux+XjggbFE 59ln3xjTEDFlA+yOyVi5/5t+aFQLvN7V6W7vadqykvM4tCbHGN4PxQw8FuFSROQ1P8dTE9mRL9+KV UTg+C7+g==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZac-00C4MB-VT; Fri, 07 Oct 2022 00:43:39 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" Subject: [PATCH 4/8] pstore: Alert on backend write error Date: Thu, 6 Oct 2022 19:42:08 -0300 Message-Id: <20221006224212.569555-5-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The pstore dump function doesn't alert at all on errors - despite pstore is usually a last resource and if it fails users won't be able to read the kernel log, this is not the case for server users with serial access, for example. So, let's at least attempt to inform such advanced users on the first backend writing error detected during the kmsg dump - this is also very useful for pstore debugging purposes. Signed-off-by: Guilherme G. Piccoli --- fs/pstore/platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 06c2c66af332..ee50812fdd2e 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -463,6 +463,9 @@ static void pstore_dump(struct kmsg_dumper *dumper, if (ret == 0 && reason == KMSG_DUMP_OOPS) { pstore_new_entry = 1; pstore_timer_kick(); + } else { + pr_err_once("backend (%s) writing error (%d)\n", + psinfo->name, ret); } total += record.size; From patchwork Thu Oct 6 22:42:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 533B0C433FE for ; Thu, 6 Oct 2022 22:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232287AbiJFWoU (ORCPT ); Thu, 6 Oct 2022 18:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbiJFWoT (ORCPT ); Thu, 6 Oct 2022 18:44:19 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A8A9F2536; Thu, 6 Oct 2022 15:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KLu43BdB40PAFi1kbT/ShHwcA3VOit69eMAzfYRiS0E=; b=AXp8Xp2pvGCESaKsozgFRLSAOh +QgLqPXphRCM4paPJUSABdiveLT5PZd2v30d3zkPpmATiiNLyBkVzg/A3z9Jmaj7Xz8hhIbNCXV0f bkqH558/OuBEMRtZYGm6xMEA4LvOsOwVV1taDNe15xxytOUkpe4oqcnrPytBZBSB0RxkRc+JFMvDN 5JW0Hcun5BxkBn1dsvganpNqDyE34DtmujEvFWYP/u67F8cmXJTh7EzDXdgB8tiS0IwMG36x1Xa/P /kr8VwhbAm4hQupMUQOeDZDBZ8EUbpR7qX534f0hHk1ijTyi4MeX31wHotYDUAiNXTuCDfzuaSszM gG8r9NBQ==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZbD-00C4PM-6J; Fri, 07 Oct 2022 00:44:16 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" , Ard Biesheuvel Subject: [PATCH 5/8] pstore: Fix long-term implicit conversions in the compression routines Date: Thu, 6 Oct 2022 19:42:09 -0300 Message-Id: <20221006224212.569555-6-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The pstore infrastructure is capable of compressing collected logs, relying for that in many compression "libraries" present on kernel. Happens that the (de)compression code in pstore performs many implicit conversions from unsigned int/size_t to int, and vice-versa. Specially in the compress buffer size calculation, we notice that even the libs are not consistent, some of them return int, most of them unsigned int and others rely on preprocessor calculation. Here is an attempt to make it consistent: since we're talking about buffer sizes, let's go with unsigned types, since negative sizes don't make sense. While at it, improve pstore_compress() return semantic too. This function returns either some potential error or the size of the compressed buffer. Such output size is a parameter, so changing it to a pointer makes sense, even follows the compression libraries API (that does modify its parameter with the output size). In order to remove such ambiguity in the return of the function, was required to validate that all compression libraries return either 0 on success or some negative value on error - our analysis showed that all compress libraries potentially used by pstore do respect that [kudos to sw842_compress() as the most convoluted return semantic among them all!]. Cc: Ard Biesheuvel Signed-off-by: Guilherme G. Piccoli --- fs/pstore/platform.c | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index ee50812fdd2e..c10bfb8346fe 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -98,7 +98,7 @@ MODULE_PARM_DESC(kmsg_bytes, "amount of kernel log to snapshot (in bytes)"); static struct crypto_comp *tfm; struct pstore_zbackend { - int (*zbufsize)(size_t size); + unsigned int (*zbufsize)(size_t size); const char *name; }; @@ -169,9 +169,9 @@ static bool pstore_cannot_block_path(enum kmsg_dump_reason reason) } #if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS) -static int zbufsize_deflate(size_t size) +static unsigned int zbufsize_deflate(size_t size) { - size_t cmpr; + unsigned int cmpr; switch (size) { /* buffer range for efivars */ @@ -198,28 +198,28 @@ static int zbufsize_deflate(size_t size) #endif #if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) -static int zbufsize_lzo(size_t size) +static unsigned int zbufsize_lzo(size_t size) { return lzo1x_worst_compress(size); } #endif #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) -static int zbufsize_lz4(size_t size) +static unsigned int zbufsize_lz4(size_t size) { - return LZ4_compressBound(size); + return (unsigned int)LZ4_compressBound(size); } #endif #if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS) -static int zbufsize_842(size_t size) +static unsigned int zbufsize_842(size_t size) { return size; } #endif #if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS) -static int zbufsize_zstd(size_t size) +static unsigned int zbufsize_zstd(size_t size) { return zstd_compress_bound(size); } @@ -267,27 +267,27 @@ static const struct pstore_zbackend zbackends[] = { { } }; -static int pstore_compress(const void *in, void *out, - unsigned int inlen, unsigned int outlen) +static bool pstore_compress(const void *in, void *out, + unsigned int inlen, unsigned int *outlen) { int ret; if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS)) return -EINVAL; - ret = crypto_comp_compress(tfm, in, inlen, out, &outlen); + ret = crypto_comp_compress(tfm, in, inlen, out, outlen); if (ret) { pr_err("crypto_comp_compress failed, ret = %d!\n", ret); - return ret; + return false; } - return outlen; + return true; } static void allocate_buf_for_compression(void) { struct crypto_comp *ctx; - int size; + unsigned int size; char *buf; /* Skip if not built-in or compression backend not selected yet. */ @@ -304,15 +304,15 @@ static void allocate_buf_for_compression(void) } size = zbackend->zbufsize(psinfo->bufsize); - if (size <= 0) { - pr_err("Invalid compression size for %s: %d\n", + if (!size) { + pr_err("Invalid compression size for %s: %u\n", zbackend->name, size); return; } buf = kmalloc(size, GFP_KERNEL); if (!buf) { - pr_err("Failed %d byte compression buffer allocation for: %s\n", + pr_err("Failed %u byte compression buffer allocation for: %s\n", size, zbackend->name); return; } @@ -414,7 +414,6 @@ static void pstore_dump(struct kmsg_dumper *dumper, char *dst; size_t dst_size; int header_size; - int zipped_len = -1; size_t dump_size; struct pstore_record record; @@ -444,13 +443,10 @@ static void pstore_dump(struct kmsg_dumper *dumper, break; if (big_oops_buf) { - zipped_len = pstore_compress(dst, psinfo->buf, - header_size + dump_size, - psinfo->bufsize); - - if (zipped_len > 0) { + record.size = psinfo->bufsize; + if (pstore_compress(dst, psinfo->buf, + header_size + dump_size, (unsigned int *)&record.size)) { record.compressed = true; - record.size = zipped_len; } else { record.size = copy_kmsg_to_buffer(header_size, dump_size); @@ -677,7 +673,7 @@ EXPORT_SYMBOL_GPL(pstore_unregister); static void decompress_record(struct pstore_record *record) { int ret; - int unzipped_len; + unsigned int unzipped_len; char *unzipped, *workspace; if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !record->compressed) From patchwork Thu Oct 6 22:42:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D0C7C433FE for ; Thu, 6 Oct 2022 22:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbiJFWoi (ORCPT ); Thu, 6 Oct 2022 18:44:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232342AbiJFWog (ORCPT ); Thu, 6 Oct 2022 18:44:36 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 681AF142CA4; Thu, 6 Oct 2022 15:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=EVVRdLfHGU547JfhyTxvQ1HY3Wn3XFoxK5UyvM0hFKk=; b=S9nw97lEu8mn3bpxd94Yis8KLD mhDQD9qFVo6vdZKXGeqT5TqMtK+v08L58XhUUAconTmoklUwrzXczCpugRahGe0mwDG9T/67+BgCt PWJMq9Qjv5xaguPzqOeP9pLBovYq5kcbs2QTbpNYjQYXvFkC+uPm8kC8rJMqO7TikM/MXHSw6CIGK +6fUs2fR30xVHqYfzh4vYchDr9AUi9irXwTp0qeRsCNqAxzZZYXekk9Czol6TS5yYJkd27TxdJsJM ggQoYnHVMNNq+ep8BRYiWV/q1lpcM/gDG3KEOktniroY5yZmEsiuGqL5OP3mSIO74vzhH24+n3ibX /yGzGwdQ==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZbS-00C4Q8-B2; Fri, 07 Oct 2022 00:44:31 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" Subject: [PATCH 6/8] MAINTAINERS: Add a mailing-list for the pstore infrastructure Date: Thu, 6 Oct 2022 19:42:10 -0300 Message-Id: <20221006224212.569555-7-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently, this entry contains only the maintainers name. Add hereby a mailing-list as well, for archiving purposes. Signed-off-by: Guilherme G. Piccoli --- Hi Kees / all, not sure if up to me doing that (apologies if not) and maybe fsdevel is not the proper list, but I think worth having at least one list explicitely mentioned in MAINTAINERS in order people use that as a pstore archive of patches. If you prefer other list, lemme know. Cheers, Guilherme MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 72b9654f764c..16a18125bf0a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16465,6 +16465,7 @@ M: Kees Cook M: Anton Vorontsov M: Colin Cross M: Tony Luck +L: linux-fsdevel@vger.kernel.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore F: Documentation/admin-guide/ramoops.rst From patchwork Thu Oct 6 22:42:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000800 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 889A9C4332F for ; Thu, 6 Oct 2022 22:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232366AbiJFWox (ORCPT ); Thu, 6 Oct 2022 18:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232357AbiJFWou (ORCPT ); Thu, 6 Oct 2022 18:44:50 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB231AE4C; Thu, 6 Oct 2022 15:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fyTNkQo2umov1vOiOrWjKRPdNwFQ2sA+uyQXpivio3w=; b=qgqa9fPeQyI/PxxJrVajIRmbKM lN90Nsf7BVEGPmgyeE2vPm2u5lpq1kU1HXKS4LQP7lnuc6cJHNS691w9FQnpsuzFEJ1WevfEckY80 XEEIzxx8zeHyw0qFB/7qD8f3WacwPEVbc5cqpiLkluyHiFT1MMyWKcfmgDmG5iwI/0rbw27HB2edj 3OmLRSlNaTd/4wblcYOZga7dixjV8BPUJ9saFnoRCnTHdWm0EBT3unTk/+GMJnUApol0sUJKHIy9F LVucn2/hKXN/D3bh2lPsAAT8aNZ9YBQlMZxijxMH0I2QUfPUIcMIO9aDyt0ucvmMke8+PYm34N3fd QmxFaing==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZbh-00C4R4-PY; Fri, 07 Oct 2022 00:44:46 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" , linux-efi@vger.kernel.org, Ard Biesheuvel Subject: [PATCH 7/8] efi: pstore: Follow convention for the efi-pstore backend name Date: Thu, 6 Oct 2022 19:42:11 -0300 Message-Id: <20221006224212.569555-8-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org For some reason, the efi-pstore backend name (exposed through the pstore infrastructure) is hardcoded as "efi", whereas all the other backends follow a kind of convention in using the module name. Let's do it here as well, to make user's life easier (they might use this info for unloading the module backend, for example). Cc: Ard Biesheuvel Signed-off-by: Guilherme G. Piccoli Acked-by: Ard Biesheuvel --- drivers/firmware/efi/efi-pstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 3bddc152fcd4..97a9e84840a0 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -207,7 +207,7 @@ static int efi_pstore_erase(struct pstore_record *record) static struct pstore_info efi_pstore_info = { .owner = THIS_MODULE, - .name = "efi", + .name = KBUILD_MODNAME, .flags = PSTORE_FLAGS_DMESG, .open = efi_pstore_open, .close = efi_pstore_close, From patchwork Thu Oct 6 22:42:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 13000801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EB9AC4332F for ; Thu, 6 Oct 2022 22:45:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232400AbiJFWpO (ORCPT ); Thu, 6 Oct 2022 18:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232179AbiJFWpF (ORCPT ); Thu, 6 Oct 2022 18:45:05 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E97291F9D7; Thu, 6 Oct 2022 15:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4iG63sk4vA6rn/yAYwNv2iOxQi+fqpBsYdlN8BwQs3A=; b=GkBjgu1/TVuhbldpcnc9P5tti3 fnR6oQ6kIP4TQki6ka9doaNPif02IOOkEjMnGnAlVcsZ2m4RzPJ+yvOGo8qoVyze/TPi5tWWb8MI3 oCBDPPriCA2cFUpDVFSJmXQaAVQLMke85iDWY1+uNe3gvVv6urKd3mmi3X9RoA8wqesPzRlKDjB3j 1aWnPZIVemONMM1xqbmT7xLJhKuPPmVFAAC50BMWJeHt+oSivHwDSEz3RbTe2FBRy+3dUX6vqD+fE lpJKYy1wm7aSLThNt8T210VQD3WKY70L39mqJ3LrkLV/6sKgxk2RmIcq+R3TK85H/DxiwCAyaSY4y A4sCdKRQ==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ogZbv-00C4T8-QL; Fri, 07 Oct 2022 00:45:00 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, "Guilherme G. Piccoli" , linux-efi@vger.kernel.org, Ard Biesheuvel Subject: [PATCH 8/8] efi: pstore: Add module parameter for setting the record size Date: Thu, 6 Oct 2022 19:42:12 -0300 Message-Id: <20221006224212.569555-9-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221006224212.569555-1-gpiccoli@igalia.com> References: <20221006224212.569555-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org By default, the efi-pstore backend hardcode the UEFI variable size as 1024 bytes. That's not a big deal, but at the same time having no way to change that in the kernel is a bit bummer for specialized users - there is not such a limit in the UEFI specification. So, add here a module parameter to enable advanced users to change the UEFI record size for efi-pstore data collection. Through empirical analysis we observed that extreme low values (like 8 bytes) could eventually cause writing issues, so we limit the low end to 1024 bytes (which is also the default). Cc: Ard Biesheuvel Signed-off-by: Guilherme G. Piccoli --- drivers/firmware/efi/efi-pstore.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 97a9e84840a0..78c27f6a83aa 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -10,7 +10,9 @@ MODULE_IMPORT_NS(EFIVAR); #define DUMP_NAME_LEN 66 -#define EFIVARS_DATA_SIZE_MAX 1024 +static unsigned int record_size = 1024; +module_param(record_size, uint, 0444); +MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/default=1024)"); static bool efivars_pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE); @@ -30,7 +32,7 @@ static int efi_pstore_open(struct pstore_info *psi) if (err) return err; - psi->data = kzalloc(EFIVARS_DATA_SIZE_MAX, GFP_KERNEL); + psi->data = kzalloc(record_size, GFP_KERNEL); if (!psi->data) return -ENOMEM; @@ -52,7 +54,7 @@ static inline u64 generic_id(u64 timestamp, unsigned int part, int count) static int efi_pstore_read_func(struct pstore_record *record, efi_char16_t *varname) { - unsigned long wlen, size = EFIVARS_DATA_SIZE_MAX; + unsigned long wlen, size = record_size; char name[DUMP_NAME_LEN], data_type; efi_status_t status; int cnt; @@ -133,7 +135,7 @@ static ssize_t efi_pstore_read(struct pstore_record *record) efi_status_t status; for (;;) { - varname_size = EFIVARS_DATA_SIZE_MAX; + varname_size = record_size; /* * If this is the first read() call in the pstore enumeration, @@ -224,11 +226,14 @@ static __init int efivars_pstore_init(void) if (efivars_pstore_disable) return 0; + if (record_size < 1024) + record_size = 1024; + efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL); if (!efi_pstore_info.buf) return -ENOMEM; - efi_pstore_info.bufsize = 1024; + efi_pstore_info.bufsize = record_size; if (pstore_register(&efi_pstore_info)) { kfree(efi_pstore_info.buf);