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] [thread-next>] [day] [month] [year] [list]
Message-ID: <1b91ed16-ab06-8b67-187d-c6de596cb176@linux.intel.com>
Date: Thu, 8 Feb 2024 16:43:44 +0200 (EET)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: "David E. Box" <david.e.box@...ux.intel.com>
cc: Netdev <netdev@...r.kernel.org>, 
    sathyanarayanan.kuppuswamy@...ux.intel.com, 
    LKML <linux-kernel@...r.kernel.org>, platform-driver-x86@...r.kernel.org
Subject: Re: [PATCH 6/8] platform/x86/intel/sdsi: Add attribute to read the
 current meter state

On Wed, 31 Jan 2024, David E. Box wrote:

> The meter_certificate file provides access to metering information that may
> be attested but is only updated every 8 hours. Add new attribute,
> meter_current, to allow reading an untested snapshot of the current values.
> 
> Signed-off-by: David E. Box <david.e.box@...ux.intel.com>
> ---
>  drivers/platform/x86/intel/sdsi.c | 42 ++++++++++++++++++++++++++++---
>  drivers/platform/x86/intel/sdsi.h |  2 ++
>  2 files changed, 41 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c
> index 287780fe65bb..171899b4a671 100644
> --- a/drivers/platform/x86/intel/sdsi.c
> +++ b/drivers/platform/x86/intel/sdsi.c
> @@ -62,6 +62,7 @@
>  #define CTRL_COMPLETE			BIT(6)
>  #define CTRL_READY			BIT(7)
>  #define CTRL_INBAND_LOCK		BIT(32)
> +#define CTRL_METER_ENABLE_DRAM		BIT(33)
>  #define CTRL_STATUS			GENMASK(15, 8)
>  #define CTRL_PACKET_SIZE		GENMASK(31, 16)
>  #define CTRL_MSG_SIZE			GENMASK(63, 48)
> @@ -235,8 +236,10 @@ static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *inf
>  	control = FIELD_PREP(CTRL_EOM, 1) |
>  		  FIELD_PREP(CTRL_SOM, 1) |
>  		  FIELD_PREP(CTRL_RUN_BUSY, 1) |
> -		  FIELD_PREP(CTRL_PACKET_SIZE, info->size);
> +		  FIELD_PREP(CTRL_PACKET_SIZE, info->size) |
> +		  priv->control_flags;
>  	writeq(control, priv->control_addr);
> +	priv->control_flags = 0;

I'm slightly worried about this. The function is named with a generic 
name but I suppose meter_lock that has less generic name is supposed to 
protect this also?

Also, resetting it after every use smells like it should be a parameter 
instead of struct member.

>  	return sdsi_mbox_poll(priv, info, data_size);
>  }
> @@ -468,11 +471,42 @@ meter_certificate_read(struct file *filp, struct kobject *kobj,
>  {
>  	struct device *dev = kobj_to_dev(kobj);
>  	struct sdsi_priv *priv = dev_get_drvdata(dev);
> +	int ret;
>  
> -	return certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
> +	ret = mutex_lock_interruptible(&priv->meter_lock);
> +	if (ret)
> +		return ret;
> +
> +	ret = certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
> +
> +	mutex_unlock(&priv->meter_lock);
> +
> +	return ret;
>  }
>  static BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG);
>  
> +static ssize_t
> +meter_current_read(struct file *filp, struct kobject *kobj,
> +		   struct bin_attribute *attr, char *buf, loff_t off,
> +		   size_t count)
> +{
> +	struct device *dev = kobj_to_dev(kobj);
> +	struct sdsi_priv *priv = dev_get_drvdata(dev);
> +	int ret;
> +
> +	ret = mutex_lock_interruptible(&priv->meter_lock);
> +	if (ret)
> +		return ret;
> +
> +	priv->control_flags = CTRL_METER_ENABLE_DRAM;
> +	ret = certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
> +
> +	mutex_unlock(&priv->meter_lock);
> +
> +	return ret;
> +}
> +static BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG);
> +
>  static ssize_t registers_read(struct file *filp, struct kobject *kobj,
>  			      struct bin_attribute *attr, char *buf, loff_t off,
>  			      size_t count)
> @@ -503,6 +537,7 @@ static struct bin_attribute *sdsi_bin_attrs[] = {
>  	&bin_attr_registers,
>  	&bin_attr_state_certificate,
>  	&bin_attr_meter_certificate,
> +	&bin_attr_meter_current,
>  	&bin_attr_provision_akc,
>  	&bin_attr_provision_cap,
>  	NULL
> @@ -522,7 +557,7 @@ sdsi_battr_is_visible(struct kobject *kobj, struct bin_attribute *attr, int n)
>  	if (!(priv->features & SDSI_FEATURE_SDSI))
>  		return 0;
>  
> -	if (attr == &bin_attr_meter_certificate)
> +	if (attr == &bin_attr_meter_certificate || attr == &bin_attr_meter_current)
>  		return (priv->features & SDSI_FEATURE_METERING) ?
>  				attr->attr.mode : 0;
>  
> @@ -725,6 +760,7 @@ static int sdsi_probe(struct auxiliary_device *auxdev, const struct auxiliary_de
>  	priv->dev = &auxdev->dev;
>  	priv->id = auxdev->id;
>  	mutex_init(&priv->mb_lock);
> +	mutex_init(&priv->meter_lock);
>  	auxiliary_set_drvdata(auxdev, priv);
>  
>  	/* Get the SDSi discovery table */
> diff --git a/drivers/platform/x86/intel/sdsi.h b/drivers/platform/x86/intel/sdsi.h
> index 256618eb3136..e20cf279212e 100644
> --- a/drivers/platform/x86/intel/sdsi.h
> +++ b/drivers/platform/x86/intel/sdsi.h
> @@ -18,12 +18,14 @@ struct device;
>  
>  struct sdsi_priv {
>  	struct mutex			mb_lock;	/* Mailbox access lock */
> +	struct mutex			meter_lock;

Please add information what this protects.


-- 
 i.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ