From patchwork Wed Jun 16 16:40:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12325681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38450C48BE8 for ; Wed, 16 Jun 2021 16:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CC2F61359 for ; Wed, 16 Jun 2021 16:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230343AbhFPQmy (ORCPT ); Wed, 16 Jun 2021 12:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbhFPQmy (ORCPT ); Wed, 16 Jun 2021 12:42:54 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF26FC061767 for ; Wed, 16 Jun 2021 09:40:47 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id l184so2439401pgd.8 for ; Wed, 16 Jun 2021 09:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AwtgVJkhTDK7FkC0vaUra0M374ERbF8RXthI68zkQrk=; b=PjKgFRjHSJToA5x31UIrlT2kQz8QWjvtUtYBHJLyMvk0e1Hb9GK88sJy3Wo1ywei+B z0DhACruELJPvs+3RZ33FJaX8HsHYVzcpOxltyO2La4fkO2wGBv6zH1UaGS7yZ5me6mJ vUp5deeq1o/Htj824MXRwhI+mkytJCSWrZDnU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AwtgVJkhTDK7FkC0vaUra0M374ERbF8RXthI68zkQrk=; b=cLdpMeLkY/7N0s+KoQ3KnXfFBOS4eExh6Rissf2CpghKQKrL4rLYp5IUnajAyx02nw lsfpDS+u7mw1ERrOksX8sqW1O/yDMMQmyAQZecyUnlEi66iSoszPRRXPR3nNJC1oUVF4 XL1FkkEYuYcgTonAAjJxEVU4LOWjul1xfKGWOIpDHksIqXCLhe8UnqvnNSMdUh8B2WgQ 2TfeVsbePyziCpAxoYxDIOLKoY+gdxn+Az2CPusEghmPH4OEC0rjguuAxr5n357uvWRP XUaqgsg9LMcBvA/QQwE6Olj7nnS7Ubf58AWbkGdh98BTEfPXDBmySSdx7MuYlzRy2k/M AJxQ== X-Gm-Message-State: AOAM5330mSBLa0ZmZSmNOJYp2MbBwV3ZooPnqcz8oO8q1rLAIL06XIip /z4Jsjis9cNQWGOBgtnr3xKn5Q== X-Google-Smtp-Source: ABdhPJyZY0hoVBBpbAB8LGirsSlZb/UXJaZdGclDdXDTOIGGnPZxvbdmt6gy8/o3bWoM59xye5Uu7g== X-Received: by 2002:a05:6a00:844:b029:2f8:5436:dc39 with SMTP id q4-20020a056a000844b02902f85436dc39mr624754pfk.10.1623861646934; Wed, 16 Jun 2021 09:40:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id ip7sm2663266pjb.39.2021.06.16.09.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 09:40:46 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Christoph Hellwig , Al Viro , gmpy.liaowx@gmail.com, Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-doc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 1/5] pstore/blk: Improve failure reporting Date: Wed, 16 Jun 2021 09:40:39 -0700 Message-Id: <20210616164043.1221861-2-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616164043.1221861-1-keescook@chromium.org> References: <20210616164043.1221861-1-keescook@chromium.org> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=95c1880167375f358445fa6b36d9d46efbebcc09; i=x+eth6WIY3ZV3RikljpGvsEDOkHC4+JR/D6VkOL4MwM=; m=KWKLltarrgCHVaChKkiXTTMXR+nWhEDb2yQ+7Fx0dy0=; p=hVqcquLAjJY5MNtchTMAytKSIfiafQn164H7tkcB2Bg= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDKKYkACgkQiXL039xtwCZgHhAAode R8F21Ztaztm9OD+m51tZDz9H7Jmr3b179RR3mjQtLY5uCy9QlEpGuYAsz/ABz9YrgP0QBOkMztOPC oQPxj2VnCVVuMJRSzFTue9HH70ItKKMz/VIHIFeV7GPStnetLsLWB+ndgzT9ustwokFew+5O35X/l pOmZy7Ol4tvlE44IfAyL6U9z8p9P9r+3a9UyoxW9Hm+KrSC9fxCG0wayJe8PqBkEdSvJ7VolFsRPr bT2bKgOb1F1vZFcHVIK00XvErTh0b6lTlWZWU9m91uH0S47Z7T+rnsJyiRLAldZiTQW2TMWo4zkIs 0QXC77HT2aXShl9P8FZkqmxDS/bYJqYFmt8ags6dV7EPjaOdAt42WMXdYEYuwsZBUVjFVwqpxZPm6 v+z7VzEJQYXs4rrkOOdcUVk4p+BuoyTrmR6/YbOjHkmvW8ufWZxNlndmPcAXW2+CMqV+U8p3LiHnF Yt8bHShaW175vGPMGqhldiLQpQQvJUMtlfrf35EBWHfvA4lDbhJPkvYW/nytaYgyjrnSUmdNqcLTA sb5e0RWD0gXDZqBhYJX7byjf49AFfMoBn3f/Jke02up/jENft69J+Zz4+g+yXD8yERwRPUVy/A8fG Mty73UjHC9R3wIIIG2JsoPGhsP+8rLEgD7c7d6KYl/Pu9NcT44LdTcznpdHhVMi0= Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There was no feedback on bad registration attempts. Add details on the failure cause. Signed-off-by: Kees Cook Reviewed-by: Christoph Hellwig --- fs/pstore/blk.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c index 4bb8a344957a..eca83820fb5d 100644 --- a/fs/pstore/blk.c +++ b/fs/pstore/blk.c @@ -114,8 +114,22 @@ static int __register_pstore_device(struct pstore_device_info *dev) lockdep_assert_held(&pstore_blk_lock); - if (!dev || !dev->total_size || !dev->read || !dev->write) + if (!dev) { + pr_err("NULL device info\n"); return -EINVAL; + } + if (!dev->total_size) { + pr_err("zero sized device\n"); + return -EINVAL; + } + if (!dev->read) { + pr_err("no read handler for device\n"); + return -EINVAL; + } + if (!dev->write) { + pr_err("no write handler for device\n"); + return -EINVAL; + } /* someone already registered before */ if (pstore_zone_info) From patchwork Wed Jun 16 16:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12325685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28020C49EA6 for ; Wed, 16 Jun 2021 16:40:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06FC5613C1 for ; Wed, 16 Jun 2021 16:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbhFPQm5 (ORCPT ); Wed, 16 Jun 2021 12:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbhFPQmz (ORCPT ); Wed, 16 Jun 2021 12:42:55 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AB87C0617AE for ; Wed, 16 Jun 2021 09:40:48 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id i34so2440192pgl.9 for ; Wed, 16 Jun 2021 09:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZbeP6cm14CZUAAE88Br6wxap9iGbpSZd/EkXccR0A3U=; b=bnktMkJeEMXaq2naBXQHHiPU9Nqu8YkQpUHyvp9e4ZqX1uHSnZ//7SWNXqUK8RVZlo MKblS1DawG8i0m4NFZwI88IgtFu737O+iLXY/3rBDEdGotZ20KiE6ydO7YdIYhh5OLaK GxQd2fJKgIpqWyi2tKPWBnNYkZlfjadHowhEY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZbeP6cm14CZUAAE88Br6wxap9iGbpSZd/EkXccR0A3U=; b=ufDAl2Rdsj1SVNDs//fUpgX2S4izG5QiF5Pz5qpz5MeP2WGyRWkuodd4Gq5fsbpwd+ 8BQhw2/dn47jjMGvetup7mY57m46yqnO2a89UdqAtUHOtBWep3wtZoJYNpDDPdY0V623 vrAWRqzWki+FU0AIwOQg9FA4WHRpgjageoeme0OtYpjoPoxgwJ7UYY6+3Kw1qiEU7BJu 9WVlBCS56rO1GCYI1HNfGv4G6xnbOHMOJePYHGfZTuBNaujKgtHhA68jKhSh6xdxlIFU E+qFO986VXxbvFH5Hz17iQmk67NHr6jp56EsGuDJ0Nz9Cj1Y7V5lMyrVexcitiovlAjf ct5A== X-Gm-Message-State: AOAM531+F+AY6FwWhTAkQpGeLXgyy+BCmcYbPRFboy0IR/FvkgNNMfvK ezjU4SJZ8eI2rBvaUPIrJ/SoVA== X-Google-Smtp-Source: ABdhPJyoO9kfQlkov8l5Uxc1pFtGZKisJjo0wbmfUm+U2ZAPtFP25C9NSbVOCG4UMmZIEZmP/R5SqQ== X-Received: by 2002:a62:e102:0:b029:2e9:fc9f:1199 with SMTP id q2-20020a62e1020000b02902e9fc9f1199mr574719pfh.33.1623861647624; Wed, 16 Jun 2021 09:40:47 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u23sm3285017pgk.38.2021.06.16.09.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 09:40:46 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Christoph Hellwig , Al Viro , gmpy.liaowx@gmail.com, Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-doc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 2/5] pstore/blk: Move verify_size() macro out of function Date: Wed, 16 Jun 2021 09:40:40 -0700 Message-Id: <20210616164043.1221861-3-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616164043.1221861-1-keescook@chromium.org> References: <20210616164043.1221861-1-keescook@chromium.org> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=2653a11ba7eb96c6cd268cbd6402b18f7e12a7e7; i=tdzQEUdv9hbSbxK6tngoJDCwzHdNjm/mAUD5mY/vv0A=; m=nTfn6wzbaP76t31hQfkeekCpmWlwPPU/REYfq9FPMqk=; p=Fkn949fV8jhBHEnW9OWz/kDi3+x9elYT1NBMFnskfo8= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDKKYkACgkQiXL039xtwCaNfQ//boE CcbVOKKdTErDuY+Q1oZgZCVMTLGpgfxWvFwMHLm8JG62YgnCM4UcRTaSri2g5rdP5aDylHS8Drftp gEelBGBUllciu6qRaKpKqwmCb+UB8HXEilK/hYzvt6u1GbezR6wzymXXYqT7+1ZODwfVPllpATV4I aIHs7Vf/pujpeOeBC386D+i3AOhJtIBmaschpq1MKNZn86MhA3+yqTL4g0RVC8+Ckm2yKeYNz5veV M9L/Z4OngJDUmmoyPY7SeeqgyPy1meyfPKnoSuzYphJcZEiFwGeVxl6nV6EaaqEaf3y3An8PILvQ3 R34qDfPazTH+AZFr+xPumv5JwIn9rUyDzAToJMCS5Ypk+xuaZ2loAQheXgMHbjw6eWDVdZN1usoB3 2NvJ9iahs+UGZLZE0jLaOv24fm8/MQMtp7qQTA7KrOcLnJECuQhBYyepQAy4Ov/ajbLPVXSI8pxZd G6qyB/dUYs07g22BU/as0XBt3iV1L5t9tM8fERcEzRo+WXu6J7yRWXyj56Dbxxq+pW1sUuVRZnR22 kIUQUTvmyQLFWoy/mbQFNysVTnf8kaBLIPwiJpKYG3KeJ5qgEh07sBvoCYAzmVK2tntraw0xGxc16 geVilcpUOr4MyH8UpGhSqsRZj3BOsEJWJSZ6jKAlU8MPEQOgtP9l9+KTIIaIg6as= Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There's no good reason for the verify_size macro to live inside the function. Move it up with the check_size() macro and fix indenting. Signed-off-by: Kees Cook Signed-off-by: Christoph Hellwig --- fs/pstore/blk.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c index eca83820fb5d..7d8e5a1ddd5b 100644 --- a/fs/pstore/blk.c +++ b/fs/pstore/blk.c @@ -108,6 +108,17 @@ struct bdev_info { _##name_; \ }) +#define verify_size(name, alignsize, enabled) { \ + long _##name_; \ + if (enabled) \ + _##name_ = check_size(name, alignsize); \ + else \ + _##name_ = 0; \ + /* Synchronize module parameters with resuls. */ \ + name = _##name_ / 1024; \ + pstore_zone_info->name = _##name_; \ +} + static int __register_pstore_device(struct pstore_device_info *dev) { int ret; @@ -143,21 +154,10 @@ static int __register_pstore_device(struct pstore_device_info *dev) if (!dev->flags) dev->flags = UINT_MAX; -#define verify_size(name, alignsize, enabled) { \ - long _##name_; \ - if (enabled) \ - _##name_ = check_size(name, alignsize); \ - else \ - _##name_ = 0; \ - name = _##name_ / 1024; \ - pstore_zone_info->name = _##name_; \ - } - verify_size(kmsg_size, 4096, dev->flags & PSTORE_FLAGS_DMESG); verify_size(pmsg_size, 4096, dev->flags & PSTORE_FLAGS_PMSG); verify_size(console_size, 4096, dev->flags & PSTORE_FLAGS_CONSOLE); verify_size(ftrace_size, 4096, dev->flags & PSTORE_FLAGS_FTRACE); -#undef verify_size pstore_zone_info->total_size = dev->total_size; pstore_zone_info->max_reason = max_reason; From patchwork Wed Jun 16 16:40:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12325689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD2A0C49EA3 for ; Wed, 16 Jun 2021 16:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D888613B9 for ; Wed, 16 Jun 2021 16:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230503AbhFPQnA (ORCPT ); Wed, 16 Jun 2021 12:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbhFPQm4 (ORCPT ); Wed, 16 Jun 2021 12:42:56 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9E1C0617AF for ; Wed, 16 Jun 2021 09:40:49 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id x10so1407938plg.3 for ; Wed, 16 Jun 2021 09:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j7QUDwC2EPEuD6DlH3pxmHwtJHgqhkfKbQUcKenskMw=; b=ZCdfrphV3dB5zlbDHKiuVpwdDt4sMlvzJGQQgBMXUFaiHwTCmZmt4J3GpvydjFySW3 w2jlhZ5/mPyplNuRD6XksvWXobmt51zj5N4jefTeXM6zui8q9W+4Q80tV+MCb//CH7PP I92j114VJ2U9Bo/YnE3m3AXq7DhUqJqL7NBC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j7QUDwC2EPEuD6DlH3pxmHwtJHgqhkfKbQUcKenskMw=; b=oGU77n6U3hgSKUa3AXUh3swtsG2NQEBg/TZYxhAO9NJnkvjWIq2HthAyhc3Gf6zkVs gyR2pPB8xG4xtk+B9Lgb6UQUWn4iH+wP01YtVozqGordDnW+Qh1//ZWB8yePFgGAl6rj vlCGLoBWKMlqZMLUEyeXwO+8to9fu0Zz5OWQkvJT6WaoAI7lF5GkmywtFsOFaCZNFYfc 7Q3GtWH7ZX+brp7v0r3mpvstlZoqncz4AkRnXxjm5CQ/2ENuxUH1ICtYpgRGA4+GYwEF s9bJYnuoatWw2YVDF1z4He6yWzfqJpzFWwfYDDomZaS3to6DtYDRujgeTzkn49I/NN3/ FhJg== X-Gm-Message-State: AOAM5331MnOjKsRmomwUodxGWAdBp/UoEKdLH2rdwhl0XWqZtaELOoqM Yfc12J9LqrjlD7vge4tzlhG9vw== X-Google-Smtp-Source: ABdhPJxEdmwP8K6Xh2thladeJiDTTJl9AykTfJtSWOWgDzFWoDz5+ZlvIOjmVNrUtl5sto5e2q1FNw== X-Received: by 2002:a17:902:b288:b029:f8:fb4f:f8d3 with SMTP id u8-20020a170902b288b02900f8fb4ff8d3mr340757plr.25.1623861649012; Wed, 16 Jun 2021 09:40:49 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g204sm2655813pfb.107.2021.06.16.09.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 09:40:46 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Christoph Hellwig , Al Viro , gmpy.liaowx@gmail.com, Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-doc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 3/5] pstore/blk: Use the normal block device I/O path Date: Wed, 16 Jun 2021 09:40:41 -0700 Message-Id: <20210616164043.1221861-4-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616164043.1221861-1-keescook@chromium.org> References: <20210616164043.1221861-1-keescook@chromium.org> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=d7a0d1871c46c87d312fa072b281fc2f84918c5c; i=SsOtgEq5qb4nZxhHBpq4SPkuFKirt6TdeGDEanJT//k=; m=oAlwYgOPy6cUOJBMN2N65cQmVA0MlO3aACbBT/7A9mM=; p=3go9GHfcbfGGvGSkn9vIl/DGa7s9OrV3LPAmJf69dw4= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDKKYoACgkQiXL039xtwCb8SQ//Xf+ HUDAQKsgP4bL0ObAPGjY+vBfBxjRE9P2d8uUVBb3nSr5/g7hPjDPR/LjxCOaNZ9lIvzApH+Q/rb3h cIGjbX6H9H68GfGJ03QY97NISnoHDUK1wa9SHcgm2pBMeuy3j971itguPkjDjNsCI7023WMxnOyIM cIQxfpgwCD/E2reQZujVgJLMjk2iVM1KS+UI0ynJxIw9q8CzHaAeA+XV27jn6QQUwRRa4tcUUGTln 0AVb3gwRaTIKZOp00Y/CnuUNDoAuIJVoIhvzGZYHz7gBRiZkWFjhVFGPQiKX0KlE/MPL0ovk5xBTV vBWcUNmhnjNOyLZOX1Kn4e06pTMxKPkOgAlIHahPkBFw1Y/lzk8S706rmjiFYqyoeh/vkpYf+sKXV 7aIyy1JW5WfSU3d5bmN6Y2bEod9NLcQe53Mr20A9M7XstziS+PP6BypaplpDbDikVEBve/ZwxqagO O+l9jBf/wqEm1irOBX1gEjHGe+crc92fJuHYpkVVjhS37lUae+YnP+ODd2tLlf8J3zFrbGej/w8Py Yu+uOGMHZwZ2L99cW9uCpy4rISaaa4RPmGkNHM3BckbKDThV9w2gIe7678VH7foP6vYA/Axv8SLbx iYlUb00oXYvUddm8kWd9mdJTw1BJLaVSAYCYeLCJv7vBU8rziN/eBa6UrxgBvveo= Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Stop poking into block layer internals and just open the block device file an use kernel_read and kernel_write on it. Note that this means the transformation from name_to_dev_t can't be used anymore when pstore_blk is loaded as a module: a full filesystem device path name must be used instead. Additionally removes ":internal:" kerndoc link, since no such documentation remains. Co-developed-by: Christoph Hellwig Signed-off-by: Christoph Hellwig Reviewed-by: Christoph Hellwig Signed-off-by: Kees Cook --- Documentation/admin-guide/pstore-blk.rst | 3 - fs/pstore/blk.c | 264 +++++++---------------- 2 files changed, 83 insertions(+), 184 deletions(-) diff --git a/Documentation/admin-guide/pstore-blk.rst b/Documentation/admin-guide/pstore-blk.rst index 49d8149f8d32..79f6d23e8cda 100644 --- a/Documentation/admin-guide/pstore-blk.rst +++ b/Documentation/admin-guide/pstore-blk.rst @@ -227,8 +227,5 @@ For developer reference, here are all the important structures and APIs: .. kernel-doc:: include/linux/pstore_zone.h :internal: -.. kernel-doc:: fs/pstore/blk.c - :internal: - .. kernel-doc:: include/linux/pstore_blk.h :internal: diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c index 7d8e5a1ddd5b..dc5ff763d414 100644 --- a/fs/pstore/blk.c +++ b/fs/pstore/blk.c @@ -8,15 +8,16 @@ #include #include -#include "../../block/blk.h" #include #include #include #include #include #include +#include +#include +#include #include -#include static long kmsg_size = CONFIG_PSTORE_BLK_KMSG_SIZE; module_param(kmsg_size, long, 0400); @@ -60,23 +61,25 @@ MODULE_PARM_DESC(best_effort, "use best effort to write (i.e. do not require sto * * Usually, this will be a partition of a block device. * - * blkdev accepts the following variants: - * 1) device number in hexadecimal representation, - * with no leading 0x, for example b302. - * 2) /dev/ represents the device number of disk - * 3) /dev/ represents the device number + * blkdev accepts the following variants, when built as a module: + * 1) /dev/ represents the device number of disk + * 2) /dev/ represents the device number * of partition - device number of disk plus the partition number - * 4) /dev/p - same as the above, that form is + * 3) /dev/p - same as the above, that form is * used when disk name of partitioned disk ends on a digit. - * 5) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the + * + * blkdev accepts the following variants when built into the kernel: + * 1) device number in hexadecimal representation, + * with no leading 0x, for example b302. + * 2) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the * unique id of a partition if the partition table provides it. * The UUID may be either an EFI/GPT UUID, or refer to an MSDOS * partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero- * filled hex representation of the 32-bit "NT disk signature", and PP * is a zero-filled hex representation of the 1-based partition number. - * 6) PARTUUID=/PARTNROFF= to select a partition in relation to + * 3) PARTUUID=/PARTNROFF= to select a partition in relation to * a partition with a known unique id. - * 7) : major and minor number of the device separated by + * 4) : major and minor number of the device separated by * a colon. */ static char blkdev[80] = CONFIG_PSTORE_BLK_BLKDEV; @@ -88,15 +91,9 @@ MODULE_PARM_DESC(blkdev, "block device for pstore storage"); * during the register/unregister functions. */ static DEFINE_MUTEX(pstore_blk_lock); -static struct block_device *psblk_bdev; +static struct file *psblk_file; static struct pstore_zone_info *pstore_zone_info; -struct bdev_info { - dev_t devt; - sector_t nr_sects; - sector_t start_sect; -}; - #define check_size(name, alignsize) ({ \ long _##name_ = (name); \ _##name_ = _##name_ <= 0 ? 0 : (_##name_ * 1024); \ @@ -219,203 +216,73 @@ void unregister_pstore_device(struct pstore_device_info *dev) } EXPORT_SYMBOL_GPL(unregister_pstore_device); -/** - * psblk_get_bdev() - open block device - * - * @holder: Exclusive holder identifier - * @info: Information about bdev to fill in - * - * Return: pointer to block device on success and others on error. - * - * On success, the returned block_device has reference count of one. - */ -static struct block_device *psblk_get_bdev(void *holder, - struct bdev_info *info) -{ - struct block_device *bdev = ERR_PTR(-ENODEV); - fmode_t mode = FMODE_READ | FMODE_WRITE; - sector_t nr_sects; - - lockdep_assert_held(&pstore_blk_lock); - - if (pstore_zone_info) - return ERR_PTR(-EBUSY); - - if (!blkdev[0]) - return ERR_PTR(-ENODEV); - - if (holder) - mode |= FMODE_EXCL; - bdev = blkdev_get_by_path(blkdev, mode, holder); - if (IS_ERR(bdev)) { - dev_t devt; - - devt = name_to_dev_t(blkdev); - if (devt == 0) - return ERR_PTR(-ENODEV); - bdev = blkdev_get_by_dev(devt, mode, holder); - if (IS_ERR(bdev)) - return bdev; - } - - nr_sects = bdev_nr_sectors(bdev); - if (!nr_sects) { - pr_err("not enough space for '%s'\n", blkdev); - blkdev_put(bdev, mode); - return ERR_PTR(-ENOSPC); - } - - if (info) { - info->devt = bdev->bd_dev; - info->nr_sects = nr_sects; - info->start_sect = get_start_sect(bdev); - } - - return bdev; -} - -static void psblk_put_bdev(struct block_device *bdev, void *holder) -{ - fmode_t mode = FMODE_READ | FMODE_WRITE; - - lockdep_assert_held(&pstore_blk_lock); - - if (!bdev) - return; - - if (holder) - mode |= FMODE_EXCL; - blkdev_put(bdev, mode); -} - static ssize_t psblk_generic_blk_read(char *buf, size_t bytes, loff_t pos) { - struct block_device *bdev = psblk_bdev; - struct file file; - struct kiocb kiocb; - struct iov_iter iter; - struct kvec iov = {.iov_base = buf, .iov_len = bytes}; - - if (!bdev) - return -ENODEV; - - memset(&file, 0, sizeof(struct file)); - file.f_mapping = bdev->bd_inode->i_mapping; - file.f_flags = O_DSYNC | __O_SYNC | O_NOATIME; - file.f_inode = bdev->bd_inode; - file_ra_state_init(&file.f_ra, file.f_mapping); - - init_sync_kiocb(&kiocb, &file); - kiocb.ki_pos = pos; - iov_iter_kvec(&iter, READ, &iov, 1, bytes); - - return generic_file_read_iter(&kiocb, &iter); + return kernel_read(psblk_file, buf, bytes, &pos); } static ssize_t psblk_generic_blk_write(const char *buf, size_t bytes, loff_t pos) { - struct block_device *bdev = psblk_bdev; - struct iov_iter iter; - struct kiocb kiocb; - struct file file; - ssize_t ret; - struct kvec iov = {.iov_base = (void *)buf, .iov_len = bytes}; - - if (!bdev) - return -ENODEV; - /* Console/Ftrace backend may handle buffer until flush dirty zones */ if (in_interrupt() || irqs_disabled()) return -EBUSY; - - memset(&file, 0, sizeof(struct file)); - file.f_mapping = bdev->bd_inode->i_mapping; - file.f_flags = O_DSYNC | __O_SYNC | O_NOATIME; - file.f_inode = bdev->bd_inode; - - init_sync_kiocb(&kiocb, &file); - kiocb.ki_pos = pos; - iov_iter_kvec(&iter, WRITE, &iov, 1, bytes); - - inode_lock(bdev->bd_inode); - ret = generic_write_checks(&kiocb, &iter); - if (ret > 0) - ret = generic_perform_write(&file, &iter, pos); - inode_unlock(bdev->bd_inode); - - if (likely(ret > 0)) { - const struct file_operations f_op = {.fsync = blkdev_fsync}; - - file.f_op = &f_op; - kiocb.ki_pos += ret; - ret = generic_write_sync(&kiocb, ret); - } - return ret; + return kernel_write(psblk_file, buf, bytes, &pos); } /* * This takes its configuration only from the module parameters now. - * See psblk_get_bdev() and blkdev. */ -static int __register_pstore_blk(void) +static int __register_pstore_blk(const char *devpath) { - char bdev_name[BDEVNAME_SIZE]; - struct block_device *bdev; - struct pstore_device_info dev; - struct bdev_info binfo; - void *holder = blkdev; + struct pstore_device_info dev = { + .read = psblk_generic_blk_read, + .write = psblk_generic_blk_write, + }; + struct inode *inode; int ret = -ENODEV; lockdep_assert_held(&pstore_blk_lock); - /* hold bdev exclusively */ - memset(&binfo, 0, sizeof(binfo)); - bdev = psblk_get_bdev(holder, &binfo); - if (IS_ERR(bdev)) { - pr_err("failed to open '%s'!\n", blkdev); - return PTR_ERR(bdev); + psblk_file = filp_open(devpath, O_RDWR | O_DSYNC | O_NOATIME | O_EXCL, 0); + if (IS_ERR(psblk_file)) { + ret = PTR_ERR(psblk_file); + pr_err("failed to open '%s': %d!\n", devpath, ret); + goto err; } - /* only allow driver matching the @blkdev */ - if (!binfo.devt) { - pr_debug("no major\n"); - ret = -ENODEV; - goto err_put_bdev; + inode = file_inode(psblk_file); + if (!S_ISBLK(inode->i_mode)) { + pr_err("'%s' is not block device!\n", devpath); + goto err_fput; } - /* psblk_bdev must be assigned before register to pstore/blk */ - psblk_bdev = bdev; - - memset(&dev, 0, sizeof(dev)); - dev.total_size = binfo.nr_sects << SECTOR_SHIFT; - dev.read = psblk_generic_blk_read; - dev.write = psblk_generic_blk_write; + inode = I_BDEV(psblk_file->f_mapping->host)->bd_inode; + dev.total_size = i_size_read(inode); ret = __register_pstore_device(&dev); if (ret) - goto err_put_bdev; + goto err_fput; - bdevname(bdev, bdev_name); - pr_info("attached %s (no dedicated panic_write!)\n", bdev_name); return 0; -err_put_bdev: - psblk_bdev = NULL; - psblk_put_bdev(bdev, holder); +err_fput: + fput(psblk_file); +err: + psblk_file = NULL; + return ret; } -static void __unregister_pstore_blk(unsigned int major) +static void __unregister_pstore_blk(struct file *device) { struct pstore_device_info dev = { .read = psblk_generic_blk_read }; - void *holder = blkdev; lockdep_assert_held(&pstore_blk_lock); - if (psblk_bdev && MAJOR(psblk_bdev->bd_dev) == major) { + if (psblk_file && psblk_file == device) { __unregister_pstore_device(&dev); - psblk_put_bdev(psblk_bdev, holder); - psblk_bdev = NULL; + fput(psblk_file); + psblk_file = NULL; } } @@ -433,13 +300,48 @@ int pstore_blk_get_config(struct pstore_blk_config *info) } EXPORT_SYMBOL_GPL(pstore_blk_get_config); + +#ifndef MODULE +static const char devname[] = "/dev/pstore-blk"; +static __init const char *early_boot_devpath(const char *initial_devname) +{ + /* + * During early boot the real root file system hasn't been + * mounted yet, and no device nodes are present yet. Use the + * same scheme to find the device that we use for mounting + * the root file system. + */ + dev_t dev = name_to_dev_t(initial_devname); + + if (!dev) { + pr_err("failed to resolve '%s'!\n", initial_devname); + return initial_devname; + } + + init_unlink(devname); + init_mknod(devname, S_IFBLK | 0600, new_encode_dev(dev)); + + return devname; +} +#else +static inline const char *early_boot_devpath(const char *initial_devname) +{ + return initial_devname; +} +#endif + static int __init pstore_blk_init(void) { int ret = 0; mutex_lock(&pstore_blk_lock); - if (!pstore_zone_info && best_effort && blkdev[0]) - ret = __register_pstore_blk(); + if (!pstore_zone_info && best_effort && blkdev[0]) { + ret = __register_pstore_blk(early_boot_devpath(blkdev)); + if (ret == 0 && pstore_zone_info) + pr_info("attached %s:%s (%zu) (no dedicated panic_write!)\n", + pstore_zone_info->name, blkdev, + pstore_zone_info->total_size); + } mutex_unlock(&pstore_blk_lock); return ret; @@ -449,8 +351,8 @@ late_initcall(pstore_blk_init); static void __exit pstore_blk_exit(void) { mutex_lock(&pstore_blk_lock); - if (psblk_bdev) - __unregister_pstore_blk(MAJOR(psblk_bdev->bd_dev)); + if (psblk_file) + __unregister_pstore_blk(psblk_file); else { struct pstore_device_info dev = { }; From patchwork Wed Jun 16 16:40:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12325687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E1DDC49EA7 for ; Wed, 16 Jun 2021 16:40:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 785D861359 for ; Wed, 16 Jun 2021 16:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbhFPQm7 (ORCPT ); Wed, 16 Jun 2021 12:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbhFPQmz (ORCPT ); Wed, 16 Jun 2021 12:42:55 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34CB7C061767 for ; Wed, 16 Jun 2021 09:40:49 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id t13so2430638pgu.11 for ; Wed, 16 Jun 2021 09:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eSj7QMM867fTBuxD4WinDi+YMzIWmxuOMcHgu40wLvE=; b=DyQz5l7fpg7DJHxBpx+gaUleysT7fIha1KRTi2aysMIVFvhjDQdRTUQTtOQGIJSrO1 lsZEUc349QhacNULCXDdTjNE7YPtFtNAJ3AjHV9zZWcr8Pu8c65/NaQtOlsrvg6bV12h lgZaKPCey7DRAYpFzufgp1ZgG7SfxtZxAopKQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eSj7QMM867fTBuxD4WinDi+YMzIWmxuOMcHgu40wLvE=; b=JIcBpAP/9GQIWKUY2B7FnDTjh1cRIVHTavXCXt43AI65J4sodM8feUSs+yQzuqOJMp nzWWFDhXv66QXmfScXbCqzh/z0JH8xnFk1B/kkwkgs6Bx0tuu8WjqL20DuYZJAkm4KhE c/YkB6lEqKMlCTbuC+2+xkSiTnEeiSEp1tkQUTHK6rolLf2PTmRZ4HESPbyq9MpiFo+Y sGnIz2oCcd1Vx2Q44QeYegNkPu7/z2eSyoJLiciZMqWY/guW4PuMnMva03g1DgLsMxA8 90Qn4e/UCeBOp1OOtcgqaF3OVllQXt5ZbZAoQKcW2ITn+owYxEgo/FAAY59NhQhsC221 ch9w== X-Gm-Message-State: AOAM532Ut/LL+tv2W/4f0mdfugeY/qfELk7ymnBw00ktH+DXz1d4o5N1 mH1dD+fqMbMDvP/tfiKl5yzjYg== X-Google-Smtp-Source: ABdhPJy3MA/bMpIrn8612O4lt2YxXA4tGPu4lGhMOvCNonn/0H42hZku6Xg6BUsLLwaushFAC8dGtw== X-Received: by 2002:a05:6a00:b8a:b029:2ec:761e:33e3 with SMTP id g10-20020a056a000b8ab02902ec761e33e3mr555954pfj.35.1623861648707; Wed, 16 Jun 2021 09:40:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id b21sm2773113pfp.134.2021.06.16.09.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 09:40:46 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Christoph Hellwig , Al Viro , gmpy.liaowx@gmail.com, Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-doc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 4/5] pstore/blk: Fix kerndoc and redundancy on blkdev param Date: Wed, 16 Jun 2021 09:40:42 -0700 Message-Id: <20210616164043.1221861-5-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616164043.1221861-1-keescook@chromium.org> References: <20210616164043.1221861-1-keescook@chromium.org> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=0cec17aa50667cf776ad33debd4d5d780669e07f; i=yTEuvN+d2QlI+CgetW2A/mnEULnwbC3Uy5kOoKgmB9Q=; m=nv3cX+zCGZ64OKaS6k3hCuIb776pM3aoPeSdwsW4l+g=; p=USoGnLZwk4a402OJka3HYldDNWjTYcaDbaDrZ+4qeFA= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDKKYoACgkQiXL039xtwCbD5g//WUB YueFZ8I0eRHi1rVMlUFvST6Tou0jUWvjup1L9XYSQ7CObRFMf5whc9+7yjyAXu6d73aH4FI9Hu/6X T7Hyx7yu3/yh08A94+EGmCw3x3tG+u2+YsaXC61syZ655r2Y/5srYaFS3JTBDHr8secOyxNrvqtW7 JacflvvLmBnr/UYiHn65oAFthh8XAzyj1e6eNek3bCJZwYhmf/E2C8yNY6Rns7jD894FG3ce2tVAD 2h+wILUbWcrLNZRoHHosY8ma7rye5JHBtf2/2dhr3zJRHx7CtaMwNn8f8v4B8BdbHN4O039E10Tzi hD7DvJPoow6zrMy39jrThL/RccFIMlzc8EdlmZgcJaixxuIeVgy9TKO4Qzz2Rg/HvCypEKrE2xoal 04ktdhkwTCH7uOI25jkm8dPaDzmrZ5nRLaOW7iT+dMtWYiGnEq1hkqVnV9aQFBzTIE7P7cY1fmqEj Q2kdlcSwWGJRIk9hvj2E1fuM1nvf116U7ERdLjtpHA92XvKoFHEjFNF39MWQJXG3VU5LN3AuuHKc5 nlBMBAlWsbRbQs1Wlj1vv0L+9vIsZ/jHBrc4FAPdsFXMXFzZbD4EDDoDn1e3OEUkqKnd8Dk0QECDY bDtz72/3myeeQVCpSCVqY4O3Glf3Q3SN/eTwLvh2RovIV6uIgkpOHtayxGaGP6GY= Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Remove redundant details of blkdev and fix up resulting kerndoc. Reviewed-by: Christoph Hellwig Signed-off-by: Kees Cook --- Documentation/admin-guide/pstore-blk.rst | 11 +++++++---- fs/pstore/blk.c | 24 +----------------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Documentation/admin-guide/pstore-blk.rst b/Documentation/admin-guide/pstore-blk.rst index 79f6d23e8cda..2d22ead9520e 100644 --- a/Documentation/admin-guide/pstore-blk.rst +++ b/Documentation/admin-guide/pstore-blk.rst @@ -45,15 +45,18 @@ blkdev The block device to use. Most of the time, it is a partition of block device. It's required for pstore/blk. It is also used for MTD device. -It accepts the following variants for block device: +When pstore/blk is built as a module, "blkdev" accepts the following variants: -1. device number in hexadecimal represents itself; no - leading 0x, for example b302. -#. /dev/ represents the device number of disk +1. /dev/ represents the device number of disk #. /dev/ represents the device number of partition - device number of disk plus the partition number #. /dev/p - same as the above; this form is used when disk name of partitioned disk ends with a digit. + +When pstore/blk is built into the kernel, "blkdev" accepts the following variants: + +#. device number in hexadecimal representation, + with no leading 0x, for example b302. #. PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF represents the unique id of a partition if the partition table provides it. The UUID may be either an EFI/GPT UUID, or refer to an MSDOS partition using the format SSSSSSSS-PP, diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c index dc5ff763d414..c373e0d73e6c 100644 --- a/fs/pstore/blk.c +++ b/fs/pstore/blk.c @@ -58,29 +58,7 @@ MODULE_PARM_DESC(best_effort, "use best effort to write (i.e. do not require sto /* * blkdev - the block device to use for pstore storage - * - * Usually, this will be a partition of a block device. - * - * blkdev accepts the following variants, when built as a module: - * 1) /dev/ represents the device number of disk - * 2) /dev/ represents the device number - * of partition - device number of disk plus the partition number - * 3) /dev/p - same as the above, that form is - * used when disk name of partitioned disk ends on a digit. - * - * blkdev accepts the following variants when built into the kernel: - * 1) device number in hexadecimal representation, - * with no leading 0x, for example b302. - * 2) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the - * unique id of a partition if the partition table provides it. - * The UUID may be either an EFI/GPT UUID, or refer to an MSDOS - * partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero- - * filled hex representation of the 32-bit "NT disk signature", and PP - * is a zero-filled hex representation of the 1-based partition number. - * 3) PARTUUID=/PARTNROFF= to select a partition in relation to - * a partition with a known unique id. - * 4) : major and minor number of the device separated by - * a colon. + * See Documentation/admin-guide/pstore-blk.rst for details. */ static char blkdev[80] = CONFIG_PSTORE_BLK_BLKDEV; module_param_string(blkdev, blkdev, 80, 0400); From patchwork Wed Jun 16 16:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12325691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19551C48BE8 for ; Wed, 16 Jun 2021 16:41:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEC22613BD for ; Wed, 16 Jun 2021 16:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbhFPQnG (ORCPT ); Wed, 16 Jun 2021 12:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbhFPQm5 (ORCPT ); Wed, 16 Jun 2021 12:42:57 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D67C2C061574 for ; Wed, 16 Jun 2021 09:40:50 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id mj8-20020a17090b3688b029016ee34fc1b3so2125577pjb.0 for ; Wed, 16 Jun 2021 09:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uK58C0QtDNcahqJUODnJkhg6UnfaTIghgCe8Hvo81CM=; b=HLSDT+7wUHY8LpTUjhJI1RoaqvvzJ8CbeGa1mlLDdidW+2R1M1TEhtvYM7yz+eWIrX KvQv9652FaY6AXcLIj1bqdc1ooiiyg/Zrd86bydD6vbzdb3xskLp+KBJcF3FR50cQB6n qKRguDajdMaWHfageonZo7jsoXdZh7+Dy0rD8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uK58C0QtDNcahqJUODnJkhg6UnfaTIghgCe8Hvo81CM=; b=HA0sQpfnDUhy5l9JlV7GZ6YCJ6xBiMnStsFeyfv8YvSqx9scZRbevjpyAAlVcA+5p7 j/gnQSkQHxh6PS98Dc+bbuwNRScLP/Ze5Epcsf5pEGO71DwlutIFgpT+/Nv9e13HvnEg k5i2LVoO22S1tO1GVIaQiD7REG1NR3T8h32BqKLgSH7pULXSTxCDjWu1rNUS8aa8Xysb gLNzlXI6KACs94mTEWnobQSAi0UVEoHdqGLRyBQRPH7ubvg99YVhYp9bStryjs6AtgUU 8Vgth1S38sljmoEMoH8J5Nj2OQOa8G3QjlyvFjK3bSZ6QbMfTqDvS/H9Pj+Za62BPPU8 vw4A== X-Gm-Message-State: AOAM533Vh69VV75zgvq1SrUO+LyNqH+x5S2XrThrrPHBaRN0ZiWN4CO1 5rwWkb0f85Bp9cWdld0htMqa/A== X-Google-Smtp-Source: ABdhPJwlTj2cDO93OlRliFpEUmheK1SgPnMQrH2UNhETk3H6RxkXF0EXk5NDiMLaXRmE082Rijd1Sw== X-Received: by 2002:a17:90b:190a:: with SMTP id mp10mr11930432pjb.145.1623861650375; Wed, 16 Jun 2021 09:40:50 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x22sm2748199pjp.37.2021.06.16.09.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 09:40:49 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Christoph Hellwig , Al Viro , gmpy.liaowx@gmail.com, Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-doc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 5/5] pstore/blk: Include zone in pstore_device_info Date: Wed, 16 Jun 2021 09:40:43 -0700 Message-Id: <20210616164043.1221861-6-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616164043.1221861-1-keescook@chromium.org> References: <20210616164043.1221861-1-keescook@chromium.org> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=c97831fb0c8399e525140afebf8001d0f40da49a; i=OzHp+/X5c8B1qT+xdnUXKoWwSY89uY95adXbT6Ztj74=; m=WOqt0d4utZlTaiUKpB0qyaFAJBWPe3VuJCNaOBLEDLw=; p=wbFugwaR98gj5F6ZJcTti2VyGOc7eeRpR29pqb1+kEM= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDKKYoACgkQiXL039xtwCYvsA/6ApV 9oqn2tzk1t8uMGJIn3m65c8MwIVr818wTAMFJnW9u82WYoJCWvo32Qh0f3PmX43ZDi40Xi4WgHoU+ DWoUxhSQhUU1j7C7XgrJN41FLiylFLPdPSgFKBl33CeDOOFMsYoB2prcRBpl5mdp+HzsSB+pHH2qZ pnVBhl8YGHq9YdTzQP9WefqTL8DrpbWpOzRQr3YsIpVlkwnbdnk47mnBTOmIrPevoE+HQfJZOsjJh ndvcUnLRCYIUuayQkXi2NuPTS2K61vW4rBMBzoHImcIYMtZbg1uLXTC9D1vJRRWwRh57FvUXXoxak jjaT+0CjnV/Ulq1oMiKmp2PYnrwztj4R0oydjQqtR0jE+Zd4e+GU2kF/YrNTERZCLTOhnM4j/RJjd R+7j5TQtwgppoqNLjWu2Z5+8ouJuKTQW3JSAUHCJGA7+Vrw5xcQSF2/3L4CRwQmS/HyOCrH8Ysan/ jgQMjbFxVXh7o7K83BhbgYIYEtx7zYfshZ5ZRAQU6iccE14L30Gf2rvDf2b68f205OSKQlTS5+S5d WyaDqbN1qIqj98FEQR85QYGg2tdB11VTDSZWOTCXdGAmVOgepD12myNxG/FGm0yboZ/IGx60g2DwC uoGHNT2b4NMHEcO/j2BgYAhKLXy1nAJONBIDpaqy/avuWQlmCio+FEIHEmpJRyb4= Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Information was redundant between struct pstore_zone_info and struct pstore_device_info. Use struct pstore_zone_info, with member name "zone". Additionally untangle the logic for the "best effort" block device instance. Signed-off-by: Kees Cook Reviewed-by: Christoph Hellwig --- drivers/mtd/mtdpstore.c | 10 +-- fs/pstore/blk.c | 143 ++++++++++++++++++++----------------- include/linux/pstore_blk.h | 27 +------ 3 files changed, 87 insertions(+), 93 deletions(-) diff --git a/drivers/mtd/mtdpstore.c b/drivers/mtd/mtdpstore.c index a3ae8778f6a9..e13d42c0acb0 100644 --- a/drivers/mtd/mtdpstore.c +++ b/drivers/mtd/mtdpstore.c @@ -423,13 +423,13 @@ static void mtdpstore_notify_add(struct mtd_info *mtd) longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize)); cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL); - cxt->dev.total_size = mtd->size; /* just support dmesg right now */ cxt->dev.flags = PSTORE_FLAGS_DMESG; - cxt->dev.read = mtdpstore_read; - cxt->dev.write = mtdpstore_write; - cxt->dev.erase = mtdpstore_erase; - cxt->dev.panic_write = mtdpstore_panic_write; + cxt->dev.zone.read = mtdpstore_read; + cxt->dev.zone.write = mtdpstore_write; + cxt->dev.zone.erase = mtdpstore_erase; + cxt->dev.zone.panic_write = mtdpstore_panic_write; + cxt->dev.zone.total_size = mtd->size; ret = register_pstore_device(&cxt->dev); if (ret) { diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c index c373e0d73e6c..ccb82bcde7a8 100644 --- a/fs/pstore/blk.c +++ b/fs/pstore/blk.c @@ -70,7 +70,7 @@ MODULE_PARM_DESC(blkdev, "block device for pstore storage"); */ static DEFINE_MUTEX(pstore_blk_lock); static struct file *psblk_file; -static struct pstore_zone_info *pstore_zone_info; +static struct pstore_device_info *pstore_device_info; #define check_size(name, alignsize) ({ \ long _##name_ = (name); \ @@ -91,7 +91,7 @@ static struct pstore_zone_info *pstore_zone_info; _##name_ = 0; \ /* Synchronize module parameters with resuls. */ \ name = _##name_ / 1024; \ - pstore_zone_info->name = _##name_; \ + dev->zone.name = _##name_; \ } static int __register_pstore_device(struct pstore_device_info *dev) @@ -104,50 +104,42 @@ static int __register_pstore_device(struct pstore_device_info *dev) pr_err("NULL device info\n"); return -EINVAL; } - if (!dev->total_size) { + if (!dev->zone.total_size) { pr_err("zero sized device\n"); return -EINVAL; } - if (!dev->read) { + if (!dev->zone.read) { pr_err("no read handler for device\n"); return -EINVAL; } - if (!dev->write) { + if (!dev->zone.write) { pr_err("no write handler for device\n"); return -EINVAL; } /* someone already registered before */ - if (pstore_zone_info) + if (pstore_device_info) return -EBUSY; - pstore_zone_info = kzalloc(sizeof(struct pstore_zone_info), GFP_KERNEL); - if (!pstore_zone_info) - return -ENOMEM; - /* zero means not limit on which backends to attempt to store. */ if (!dev->flags) dev->flags = UINT_MAX; + /* Copy in module parameters. */ verify_size(kmsg_size, 4096, dev->flags & PSTORE_FLAGS_DMESG); verify_size(pmsg_size, 4096, dev->flags & PSTORE_FLAGS_PMSG); verify_size(console_size, 4096, dev->flags & PSTORE_FLAGS_CONSOLE); verify_size(ftrace_size, 4096, dev->flags & PSTORE_FLAGS_FTRACE); + dev->zone.max_reason = max_reason; + + /* Initialize required zone ownership details. */ + dev->zone.name = KBUILD_MODNAME; + dev->zone.owner = THIS_MODULE; + + ret = register_pstore_zone(&dev->zone); + if (ret == 0) + pstore_device_info = dev; - pstore_zone_info->total_size = dev->total_size; - pstore_zone_info->max_reason = max_reason; - pstore_zone_info->read = dev->read; - pstore_zone_info->write = dev->write; - pstore_zone_info->erase = dev->erase; - pstore_zone_info->panic_write = dev->panic_write; - pstore_zone_info->name = KBUILD_MODNAME; - pstore_zone_info->owner = THIS_MODULE; - - ret = register_pstore_zone(pstore_zone_info); - if (ret) { - kfree(pstore_zone_info); - pstore_zone_info = NULL; - } return ret; } /** @@ -174,10 +166,9 @@ EXPORT_SYMBOL_GPL(register_pstore_device); static void __unregister_pstore_device(struct pstore_device_info *dev) { lockdep_assert_held(&pstore_blk_lock); - if (pstore_zone_info && pstore_zone_info->read == dev->read) { - unregister_pstore_zone(pstore_zone_info); - kfree(pstore_zone_info); - pstore_zone_info = NULL; + if (pstore_device_info && pstore_device_info == dev) { + unregister_pstore_zone(&dev->zone); + pstore_device_info = NULL; } } @@ -211,12 +202,9 @@ static ssize_t psblk_generic_blk_write(const char *buf, size_t bytes, /* * This takes its configuration only from the module parameters now. */ -static int __register_pstore_blk(const char *devpath) +static int __register_pstore_blk(struct pstore_device_info *dev, + const char *devpath) { - struct pstore_device_info dev = { - .read = psblk_generic_blk_read, - .write = psblk_generic_blk_write, - }; struct inode *inode; int ret = -ENODEV; @@ -236,9 +224,9 @@ static int __register_pstore_blk(const char *devpath) } inode = I_BDEV(psblk_file->f_mapping->host)->bd_inode; - dev.total_size = i_size_read(inode); + dev->zone.total_size = i_size_read(inode); - ret = __register_pstore_device(&dev); + ret = __register_pstore_device(dev); if (ret) goto err_fput; @@ -252,18 +240,6 @@ static int __register_pstore_blk(const char *devpath) return ret; } -static void __unregister_pstore_blk(struct file *device) -{ - struct pstore_device_info dev = { .read = psblk_generic_blk_read }; - - lockdep_assert_held(&pstore_blk_lock); - if (psblk_file && psblk_file == device) { - __unregister_pstore_device(&dev); - fput(psblk_file); - psblk_file = NULL; - } -} - /* get information of pstore/blk */ int pstore_blk_get_config(struct pstore_blk_config *info) { @@ -308,18 +284,63 @@ static inline const char *early_boot_devpath(const char *initial_devname) } #endif +static int __init __best_effort_init(void) +{ + struct pstore_device_info *best_effort_dev; + int ret; + + /* No best-effort mode requested. */ + if (!best_effort) + return 0; + + /* Reject an empty blkdev. */ + if (!blkdev[0]) { + pr_err("blkdev empty with best_effort=Y\n"); + return -EINVAL; + } + + best_effort_dev = kzalloc(sizeof(*best_effort_dev), GFP_KERNEL); + if (!best_effort) + return -ENOMEM; + + best_effort_dev->zone.read = psblk_generic_blk_read; + best_effort_dev->zone.write = psblk_generic_blk_write; + + ret = __register_pstore_blk(best_effort_dev, + early_boot_devpath(blkdev)); + if (ret) + kfree(best_effort_dev); + else + pr_info("attached %s (%zu) (no dedicated panic_write!)\n", + blkdev, best_effort_dev->zone.total_size); + + return ret; +} + +static void __exit __best_effort_exit(void) +{ + /* + * Currently, the only user of psblk_file is best_effort, so + * we can assume that pstore_device_info is associated with it. + * Once there are "real" blk devices, there will need to be a + * dedicated pstore_blk_info, etc. + */ + if (psblk_file) { + struct pstore_device_info *dev = pstore_device_info; + + __unregister_pstore_device(dev); + kfree(dev); + fput(psblk_file); + psblk_file = NULL; + } +} + static int __init pstore_blk_init(void) { - int ret = 0; + int ret; mutex_lock(&pstore_blk_lock); - if (!pstore_zone_info && best_effort && blkdev[0]) { - ret = __register_pstore_blk(early_boot_devpath(blkdev)); - if (ret == 0 && pstore_zone_info) - pr_info("attached %s:%s (%zu) (no dedicated panic_write!)\n", - pstore_zone_info->name, blkdev, - pstore_zone_info->total_size); - } + ret = __best_effort_init(); mutex_unlock(&pstore_blk_lock); return ret; @@ -329,15 +350,9 @@ late_initcall(pstore_blk_init); static void __exit pstore_blk_exit(void) { mutex_lock(&pstore_blk_lock); - if (psblk_file) - __unregister_pstore_blk(psblk_file); - else { - struct pstore_device_info dev = { }; - - if (pstore_zone_info) - dev.read = pstore_zone_info->read; - __unregister_pstore_device(&dev); - } + __best_effort_exit(); + /* If we've been asked to unload, unregister any remaining device. */ + __unregister_pstore_device(pstore_device_info); mutex_unlock(&pstore_blk_lock); } module_exit(pstore_blk_exit); diff --git a/include/linux/pstore_blk.h b/include/linux/pstore_blk.h index 99564f93d774..924ca07aafbd 100644 --- a/include/linux/pstore_blk.h +++ b/include/linux/pstore_blk.h @@ -10,36 +10,15 @@ /** * struct pstore_device_info - back-end pstore/blk driver structure. * - * @total_size: The total size in bytes pstore/blk can use. It must be greater - * than 4096 and be multiple of 4096. * @flags: Refer to macro starting with PSTORE_FLAGS defined in * linux/pstore.h. It means what front-ends this device support. * Zero means all backends for compatible. - * @read: The general read operation. Both of the function parameters - * @size and @offset are relative value to bock device (not the - * whole disk). - * On success, the number of bytes should be returned, others - * means error. - * @write: The same as @read, but the following error number: - * -EBUSY means try to write again later. - * -ENOMSG means to try next zone. - * @erase: The general erase operation for device with special removing - * job. Both of the function parameters @size and @offset are - * relative value to storage. - * Return 0 on success and others on failure. - * @panic_write:The write operation only used for panic case. It's optional - * if you do not care panic log. The parameters are relative - * value to storage. - * On success, the number of bytes should be returned, others - * excluding -ENOMSG mean error. -ENOMSG means to try next zone. + * @zone: The struct pstore_zone_info details. + * */ struct pstore_device_info { - unsigned long total_size; unsigned int flags; - pstore_zone_read_op read; - pstore_zone_write_op write; - pstore_zone_erase_op erase; - pstore_zone_write_op panic_write; + struct pstore_zone_info zone; }; int register_pstore_device(struct pstore_device_info *dev);