lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240103155344.GCZZWDCLfrRR2N18JU@fat_crate.local>
Date: Wed, 3 Jan 2024 16:53:44 +0100
From: Borislav Petkov <bp@...en8.de>
To: Shubhrajyoti Datta <shubhrajyoti.datta@....com>
Cc: linux-edac@...r.kernel.or, git@....com, linux-kernel@...r.kernel.org,
	rric@...nel.org, mchehab@...nel.org, james.morse@....com,
	tony.luck@...el.com, sai.krishna.potthuri@....com,
	shubhrajyoti.datta@...il.com
Subject: Re: [PATCH] EDAC/versal: Make the bits in error injection
 configurable

On Wed, Dec 20, 2023 at 09:58:32AM +0530, Shubhrajyoti Datta wrote:
> Currently the error injection bits are hardcoded.
> Make them configurable. We have separate entries to configure the

Who's "We"?

> bits to inject errors.
> 
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@....com>
> ---
> 
>  drivers/edac/versal_edac.c | 122 ++++++++++++++++++++++++++++++++-----
>  1 file changed, 106 insertions(+), 16 deletions(-)

...

> @@ -847,12 +849,14 @@ static ssize_t xddr_inject_data_poison_store(struct mem_ctl_info *mci,
>  	return 0;
>  }
>  
> -static ssize_t inject_data_poison_store(struct file *file, const char __user *data,
> -					size_t count, loff_t *ppos)
> +static ssize_t inject_data_ce_store(struct file *file, const char __user *data,
> +				    size_t count, loff_t *ppos)
>  {
>  	struct device *dev = file->private_data;
>  	struct mem_ctl_info *mci = to_mci(dev);
>  	struct edac_priv *priv = mci->pvt_info;
> +	u8 ce_bitpos;
> +	int ret;
>  
>  	/* Unlock the PCSR registers */
>  	writel(PCSR_UNLOCK_VAL, priv->ddrmc_baseaddr + XDDR_PCSR_OFFSET);
> @@ -863,14 +867,98 @@ static ssize_t inject_data_poison_store(struct file *file, const char __user *da
>  	/* Lock the PCSR registers */
>  	writel(1, priv->ddrmc_noc_baseaddr + XDDR_PCSR_OFFSET);

You lock the PCSR registers...

> -	xddr_inject_data_poison_store(mci, data);
> +	ret = kstrtou8_from_user(data, count, 0, &ce_bitpos);
> +	if (ret)
> +		return ret;
> +	ret = xddr_inject_data_ce_store(mci, ce_bitpos);

... and you lock them here *again*. This doesn't make sense.
>  
>  	return count;
>  }
>  
> -static const struct file_operations xddr_inject_enable_fops = {
> +static void xddr_inject_data_ue_store(struct mem_ctl_info *mci, u32 val0, u32 val1)
> +{
> +	struct edac_priv *priv = mci->pvt_info;
> +
> +	writel(val0, priv->ddrmc_baseaddr + ECCW0_FLIP0_OFFSET);
> +	writel(val0, priv->ddrmc_baseaddr + ECCW0_FLIP1_OFFSET);
> +	writel(val1, priv->ddrmc_baseaddr + ECCW1_FLIP1_OFFSET);
> +	writel(val1, priv->ddrmc_baseaddr + ECCW1_FLIP1_OFFSET);
> +}
> +
> +static ssize_t inject_data_ue_store(struct file *file, const char __user *data,
> +				    size_t count, loff_t *ppos)
> +{
> +	struct device *dev = file->private_data;
> +	struct mem_ctl_info *mci = to_mci(dev);
> +	struct edac_priv *priv = mci->pvt_info;
> +	u8 pos0, pos1, len;
> +	u32 val0 = 0;
> +	u32 val1 = 0;
> +	u8 ue0, ue1;
> +	char buf[6];
> +	int ret;
> +
> +	len = min_t(size_t, count, sizeof(buf));
> +	if (copy_from_user(buf, data, len))
> +		return -EFAULT;
> +
> +	for (pos0 = 0; buf[pos0] != ' ' && pos0 <= len; pos0++)
> +		;
> +
> +	if (pos0 > len)
> +		return -EINVAL;
> +
> +	ret = kstrtou8_from_user(data, pos0, 0, &ue0);
> +	if (ret)
> +		return ret;
> +
> +	for (pos1 = pos0 + 1; buf[pos1] != '\n' && pos1 <= len; pos1++)
> +		;
> +
> +	if (pos1 > count)
> +		return -EINVAL;
> +
> +	ret = kstrtou8_from_user(&data[pos0 + 1], pos1 - pos0 - 1, 0,
> +				 &ue1);
> +	if (ret)
> +		return ret;
> +
> +	if (ue0 < 31) {
> +		val0 = BIT(ue0);
> +	} else {
> +		ue0 = ue0 - 31;
> +		val1 = BIT(ue0);
> +	}
> +	if (ue1 < 31) {
> +		val0 |= BIT(ue1);
> +	} else {
> +		ue1 = ue1 - 31;
> +		val1 |= BIT(ue1);
> +	}
> +
> +	/* Unlock the PCSR registers */
> +	writel(PCSR_UNLOCK_VAL, priv->ddrmc_baseaddr + XDDR_PCSR_OFFSET);
> +	writel(PCSR_UNLOCK_VAL, priv->ddrmc_noc_baseaddr + XDDR_PCSR_OFFSET);
> +
> +	poison_setup(priv);
> +
> +	/* Lock the PCSR registers */
> +	writel(1, priv->ddrmc_noc_baseaddr + XDDR_PCSR_OFFSET);
> +
> +	xddr_inject_data_ue_store(mci, val0, val1);
> +
> +	return count;
> +}
> +
> +static const struct file_operations xddr_inject_ue_fops = {
> +	.open = simple_open,
> +	.write = inject_data_ue_store,
> +	.llseek = generic_file_llseek,
> +};
> +
> +static const struct file_operations xddr_inject_ce_fops = {
>  	.open = simple_open,
> -	.write = inject_data_poison_store,
> +	.write = inject_data_ce_store,
>  	.llseek = generic_file_llseek,
>  };

Put the fops underneath the respective functions.

Also, the injection algorithm needs to be explained in a comment here,
step by step, and not have people figure out what they need to do by
parsing inject_data_{ce,ue}_store() by foot.

> @@ -882,8 +970,10 @@ static void create_debugfs_attributes(struct mem_ctl_info *mci)
>  	if (!priv->debugfs)
>  		return;
>  
> -	edac_debugfs_create_file("inject_error", 0200, priv->debugfs,
> -				 &mci->dev, &xddr_inject_enable_fops);
> +	edac_debugfs_create_file("inject_ce", 0200, priv->debugfs,
> +				 &mci->dev, &xddr_inject_ce_fops);
> +	edac_debugfs_create_file("inject_ue", 0200, priv->debugfs,
> +				 &mci->dev, &xddr_inject_ue_fops);

That function can return NULL.

>  	debugfs_create_x64("address", 0600, priv->debugfs,
>  			   &priv->err_inject_addr);
>  	mci->debugfs = priv->debugfs;
> -- 

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ