Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp929493ybh; Wed, 18 Mar 2020 11:43:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vso2g7Ip0nYwqHN0uzX0rteqozSNOMvLUs7jE70zByV9Kuf0oP907ZFHszErwsxVsyxUxwi X-Received: by 2002:aca:bd46:: with SMTP id n67mr4107350oif.120.1584557020599; Wed, 18 Mar 2020 11:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584557020; cv=none; d=google.com; s=arc-20160816; b=Tf1WCwSfPZGKwWt81psXhM5faOmjHRD5Cgm28ob2oGm9MHZPyBzXWykUqBZFIfLr7E oMHekR7RmYnEEelWTWSvahrXQ6R7qcjtSfK9gHXTVVSvM99UY5nNqJx8CjAfUY7FG6BD BNDkIhpfhBTlkCnl1a8qqg/YvKkXxBocl1Qtc7oxoldkN8lQczgOj4C+do+Ybcf6K/B4 NYQ1N+i8KbjBWZ/RGcES3pVBZZUGeUbGE+Akh4NYBE7XOEVj1VROOIPVjE+VT37fd9ia kx2jpjxx3avhkFPxkLuPR6F0txfKLwcWdBM3rDUIXP9ftitKuT2UfrD9YO66VKHVbxPy JnRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=FgQUeqczmCOiMLXJY/YgmlhiPodfwWFEQ6rmmnOqT2I=; b=LVkXkRb/6gBiOcdW/dVEfOHd2grCc2NmNqEhPDnUibKwwUKvr8C/4ScX6fFqlV2aEy Hgvxp9TbISVhCceIjur8tjBW+kTFcZ/v7vFcbvM89W7PMUfk6fBPCFOiiyPLelyrU563 wnOCqkLOd/BRvsYtaNp/i5WIGn8ai2SXWDgtS0J9gRdTQQiswrflgWbnAdFtVkI11TJZ P2RzH8bVLfwieoqiLhfVuvR/2j5ZxHyvXlT2JpEg/vDJbydBtHSLxzG/Nd8oMfsHKiDo JE9UF/YVmu9kXYvs0pYUkpWaeoYkq6PiNXpt2GhGE52jShb90PEgb1+5v4Mun2Qm/5W3 6SQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RNshLByR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p131si3917846oib.179.2020.03.18.11.43.27; Wed, 18 Mar 2020 11:43:40 -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=@chromium.org header.s=google header.b=RNshLByR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbgCRSm4 (ORCPT + 99 others); Wed, 18 Mar 2020 14:42:56 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:34966 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbgCRSm4 (ORCPT ); Wed, 18 Mar 2020 14:42:56 -0400 Received: by mail-pj1-f68.google.com with SMTP id j20so818540pjz.0 for ; Wed, 18 Mar 2020 11:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FgQUeqczmCOiMLXJY/YgmlhiPodfwWFEQ6rmmnOqT2I=; b=RNshLByRet19hMEwb8FtxHQ4qbBwmjLc285o6H3HiHgrUaqRFtLN58W3KdnKNDFM4a IYWCrg7B/XijnDcoo2wLu4Gtt/R1vc/xnDhz0CeI9707c9g3g6nwxgPTVxujHeG0Vu5/ ec96267kJA4rrGMPZ0HQHOE0rZODIqhj99ULQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FgQUeqczmCOiMLXJY/YgmlhiPodfwWFEQ6rmmnOqT2I=; b=bZwBLdrMRuQn0IC9tbCzfZtJIRx/EdNhe9zLXjRmCA1kh/M4F8t1P1x8n0GwndC/H/ 1etXc9TmbB85vmDiIXI2HUlVI1oGrYWYFqO42SuUXhBho/r/O1EAGBbJ4LAugE5JgQYY xDL3Dz9k3UkU/TVLjWJFlXijIVqiiIf4cJ9AhuZal5munJJ8Us9g6yBycbB129kGsKKi LNRNgxfaATXCvBeIcZBjICvZpFFnTIPjo0UQemL28JbrBgpmORBccFZi6xlXYNXm9b00 e3JgyUrG57VNSK1yVwyj0PTZxbh8/nNgX7cYoU3c3QXg7NaePpsuJGC6kXbOlMyfCmTB iHBQ== X-Gm-Message-State: ANhLgQ3vzOW5lmvZdvFNz+CnucMpRLmw6+shXTiSdzb+7GyWNtUIauQl KwMJgbDhC9LYZtBJU1ClotwaBKTPxG4= X-Received: by 2002:a17:902:9349:: with SMTP id g9mr5374705plp.16.1584556973360; Wed, 18 Mar 2020 11:42:53 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id l67sm3087706pjb.23.2020.03.18.11.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 11:42:52 -0700 (PDT) Date: Wed, 18 Mar 2020 11:42:50 -0700 From: Kees Cook To: WeiXiong Liao Cc: Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: Re: [PATCH v2 08/11] blkoops: respect for device to pick recorders Message-ID: <202003181136.5F115BFCC1@keescook> References: <1581078355-19647-1-git-send-email-liaoweixiong@allwinnertech.com> <1581078355-19647-9-git-send-email-liaoweixiong@allwinnertech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1581078355-19647-9-git-send-email-liaoweixiong@allwinnertech.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the subject and through-out: s/recorders/pstore front-ends/ On Fri, Feb 07, 2020 at 08:25:52PM +0800, WeiXiong Liao wrote: > It's one of a series of patches for adaptive to MTD device. typo: adapting > > MTD device is not block device. The sector of flash (MTD device) will be > broken if erase over limited cycles. Avoid damaging block so fast, we > can not write to a sector frequently. So, the recorders of pstore/blk > like console and ftrace recorder should not be supported. > > Besides, mtd device need aligned write/erase size. To avoid > over-erasing/writing flash, we should keep a aligned cache and read old > data to cache before write/erase, which make codes more complex. So, > pmsg do not be supported now because it writes misaligned. > > How about dmesg? Luckly, pstore/blk keeps several aligned chunks for > dmesg and uses one by one for wear balance. > > So, MTD device for pstore should pick recorders, that is why the patch > here. > > Signed-off-by: WeiXiong Liao > --- > Documentation/admin-guide/pstore-block.rst | 9 +++++++++ > fs/pstore/blkoops.c | 29 +++++++++++++++++++++-------- > include/linux/blkoops.h | 14 +++++++++++++- > 3 files changed, 43 insertions(+), 9 deletions(-) > > diff --git a/Documentation/admin-guide/pstore-block.rst b/Documentation/admin-guide/pstore-block.rst > index be865dfc1a28..299142b3d8e6 100644 > --- a/Documentation/admin-guide/pstore-block.rst > +++ b/Documentation/admin-guide/pstore-block.rst > @@ -166,6 +166,15 @@ It is only required by block device which is registered by > ``blkoops_register_blkdev``. It's the major device number of registered > devices, by which blkoops can get the matching driver for @blkdev. > > +flags > +~~~~~ > + > +Refer to macro starting with *BLKOOPS_DEV_SUPPORT_* which is defined in > +*linux/blkoops.h*. They tell us that which pstore/blk recorders this device > +supports. Default zero means all recorders for compatible, witch is the same typo: witch -> which > +as BLKOOPS_DEV_SUPPORT_ALL. Recorder works only when chunk size is not zero > +and device support. There are already flags for this, please see "Supported frontends" in include/linux/pstore.h > + > total_size > ~~~~~~~~~~ > > diff --git a/fs/pstore/blkoops.c b/fs/pstore/blkoops.c > index c76bab671b0b..01170b344f00 100644 > --- a/fs/pstore/blkoops.c > +++ b/fs/pstore/blkoops.c > @@ -128,9 +128,16 @@ int blkoops_register_device(struct blkoops_device *bo_dev) > return -ENOMEM; > } > > -#define verify_size(name, defsize, alignsize) { \ > - long _##name_ = (name); \ > - if (_##name_ < 0) \ > + /* zero means all recorders for compatible */ > + if (bo_dev->flags == BLKOOPS_DEV_SUPPORT_DEFAULT) > + bo_dev->flags = BLKOOPS_DEV_SUPPORT_ALL; > +#define verify_size(name, defsize, alignsize, enable) { \ > + long _##name_; \ > + if (!(enable)) \ > + _##name_ = 0; \ > + else if ((name) >= 0) \ > + _##name_ = (name); \ > + else \ > _##name_ = (defsize); \ > _##name_ = _##name_ <= 0 ? 0 : (_##name_ * 1024); \ > if (_##name_ & ((alignsize) - 1)) { \ > @@ -142,10 +149,14 @@ int blkoops_register_device(struct blkoops_device *bo_dev) > bzinfo->name = _##name_; \ > } > > - verify_size(dmesg_size, DEFAULT_DMESG_SIZE, 4096); > - verify_size(pmsg_size, DEFAULT_PMSG_SIZE, 4096); > - verify_size(console_size, DEFAULT_CONSOLE_SIZE, 4096); > - verify_size(ftrace_size, DEFAULT_FTRACE_SIZE, 4096); > + verify_size(dmesg_size, DEFAULT_DMESG_SIZE, 4096, > + bo_dev->flags & BLKOOPS_DEV_SUPPORT_DMESG); > + verify_size(pmsg_size, DEFAULT_PMSG_SIZE, 4096, > + bo_dev->flags & BLKOOPS_DEV_SUPPORT_PMSG); > + verify_size(console_size, DEFAULT_CONSOLE_SIZE, 4096, > + bo_dev->flags & BLKOOPS_DEV_SUPPORT_CONSOLE); > + verify_size(ftrace_size, DEFAULT_FTRACE_SIZE, 4096, > + bo_dev->flags & BLKOOPS_DEV_SUPPORT_FTRACE); I'd kind of prefer this patch be moved much earlier in the series so that the later additions of front-end support doesn't have to be touched twice. i.e. when PMSG support is added, it is added as a whole here and does the flag check in that patch, etc. > #undef verify_size > dump_oops = !!(dump_oops < 0 ? DEFAULT_DUMP_OOPS : dump_oops); > > @@ -336,6 +347,7 @@ static ssize_t blkoops_blk_panic_write(const char *buf, size_t size, > * register block device to blkoops > * @major: the major device number of registering device > * @panic_write: the write interface for panic case. > + * @flags: Refer to macro starting with BLKOOPS_DEV_SUPPORT. > * > * It is ONLY used for block device to register to blkoops. In this case, > * the module parameter @blkdev must be valid. Generic read/write interfaces > @@ -349,7 +361,7 @@ static ssize_t blkoops_blk_panic_write(const char *buf, size_t size, > * panic occurs but pstore/blk does not recover yet, the first zone of dmesg > * will be used. > */ > -int blkoops_register_blkdev(unsigned int major, > +int blkoops_register_blkdev(unsigned int major, unsigned int flags, > blkoops_blk_panic_write_op panic_write) > { > struct block_device *bdev; > @@ -372,6 +384,7 @@ int blkoops_register_blkdev(unsigned int major, > if (bo_dev.total_size == 0) > goto err_put_bdev; > bo_dev.panic_write = panic_write ? blkoops_blk_panic_write : NULL; > + bo_dev.flags = flags; > bo_dev.read = blkoops_generic_blk_read; > bo_dev.write = blkoops_generic_blk_write; > > diff --git a/include/linux/blkoops.h b/include/linux/blkoops.h > index 71c596fd4cc8..bc7665d14a98 100644 > --- a/include/linux/blkoops.h > +++ b/include/linux/blkoops.h > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > > /** > * struct blkoops_device - backend blkoops driver structure. > @@ -14,6 +15,10 @@ > * blkoops_register_device(). If block device, you are strongly recommended > * to use blkoops_register_blkdev(). > * > + * @flags: > + * Refer to macro starting with BLKOOPS_DEV_SUPPORT_. These macros tell > + * us that which pstore/blk recorders this device supports. Zero means > + * all recorders for compatible. > * @total_size: > * The total size in bytes pstore/blk can use. It must be greater than > * 4096 and be multiple of 4096. > @@ -38,6 +43,13 @@ > * On error, negative number should be returned. > */ > struct blkoops_device { > + unsigned int flags; > +#define BLKOOPS_DEV_SUPPORT_ALL UINT_MAX > +#define BLKOOPS_DEV_SUPPORT_DEFAULT (0) > +#define BLKOOPS_DEV_SUPPORT_DMESG BIT(0) > +#define BLKOOPS_DEV_SUPPORT_PMSG BIT(1) > +#define BLKOOPS_DEV_SUPPORT_CONSOLE BIT(2) > +#define BLKOOPS_DEV_SUPPORT_FTRACE BIT(3) > unsigned long total_size; > blkz_read_op read; > blkz_write_op write; > @@ -54,7 +66,7 @@ typedef int (*blkoops_blk_panic_write_op)(const char *buf, sector_t start_sect, > > int blkoops_register_device(struct blkoops_device *bo_dev); > void blkoops_unregister_device(struct blkoops_device *bo_dev); > -int blkoops_register_blkdev(unsigned int major, > +int blkoops_register_blkdev(unsigned int major, unsigned int flags, > blkoops_blk_panic_write_op panic_write); > void blkoops_unregister_blkdev(unsigned int major); > int blkoops_blkdev_info(dev_t *devt, sector_t *nr_sects, sector_t *start_sect); > -- > 1.9.1 > -- Kees Cook