From: Dmitry Osipenko Subject: Re: [PATCH v5 6/6] soc/tegra: Expose Boot Configuration Table via sysfs Date: Mon, 18 May 2020 11:00:46 +0300 Message-ID: <75e7d242-268c-07a3-a4f9-7b8252769140@gmail.com> References: <20200516153644.13748-1-digetx@gmail.com> <20200516153644.13748-7-digetx@gmail.com> <20200518074557.GA12306@qmqm.qmqm.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: <20200518074557.GA12306-cHozx32mtrEEUmgCuDUIdw@public.gmane.org> Content-Language: en-US Sender: linux-tegra-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Jens Axboe , Thierry Reding , Jonathan Hunter , David Heidelberg , Peter Geis , Stephen Warren , Nicolas Chauvet , Ulf Hansson , Adrian Hunter , Billy Laws , =?UTF-8?Q?Nils_=c3=96stlund?= , Christoph Hellwig , Ard Biesheuvel , Davidlohr Bueso , linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Andrey Danin , Gilles Grandou , Ryan Grachek , linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TaqPxH82wqD4g@public.gmane.org List-Id: linux-tegra@vger.kernel.org 18.05.2020 10:45, Michał Mirosław пишет: > On Sat, May 16, 2020 at 06:36:44PM +0300, Dmitry Osipenko wrote: >> It's quite useful to have unencrypted BCT exposed to userspace for >> debugging purposes, so let's expose it via sysfs. The BCT data will be >> present in '/sys/tegra/boot_config_table' binary file if BCT is available. > [...] >> +/* >> + * spare_bct[] will be released once kernel is booted, hence not wasting >> + * kernel space if BCT is missing. The tegra_bct can't be allocated during >> + * of BCT setting up because it's too early for the slab allocator. >> + */ >> +static u8 spare_bct[SZ_8K] __initdata; >> +static u8 *tegra_bct; >> + >> +static ssize_t boot_config_table_read(struct file *filp, >> + struct kobject *kobj, >> + struct bin_attribute *bin_attr, >> + char *buf, loff_t off, size_t count) >> +{ >> + memcpy(buf, tegra_bct + off, count); >> + return count; >> +} >> +static BIN_ATTR_RO(boot_config_table, 0); >> + >> +static int __init tegra_bootdata_bct_sysfs_init(void) >> +{ >> + if (!bin_attr_boot_config_table.size) >> + return 0; >> + >> + tegra_bct = kmalloc(GFP_KERNEL, bin_attr_boot_config_table.size); >> + if (!tegra_bct) >> + return -ENOMEM; >> + >> + memcpy(tegra_bct, spare_bct, bin_attr_boot_config_table.size); >> + >> + return sysfs_create_bin_file(tegra_soc_kobj, >> + &bin_attr_boot_config_table); > > Should we consider freeing the table if sysfs registration fails? This is a good suggestion, thank you :) >> +} >> +late_initcall(tegra_bootdata_bct_sysfs_init) >> + >> +void __init tegra_bootdata_bct_setup(void __iomem *bct_ptr, size_t bct_size) >> +{ >> + memcpy_fromio(spare_bct, bct_ptr, bct_size); >> + bin_attr_boot_config_table.size = bct_size; > [...] > > The size isn't checked anywhere. How the maximum is obtained? At least > a comment would be good if the 8k limit is guaranteed by other means. Yes, I can add a clarifying comment about the 8K. It also should be possible to create a union of T20/T30 BCT structs and then use use sizeof(bct_union). I'll consider this change for the next version, thank you for the suggestion.