Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp310497rdb; Thu, 8 Feb 2024 06:44:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV33Xhj+1kFhH0JmsjSY2y34UCBSrxSjZ9i+exIed0xbu9rpMwkpWEBo7a7NtwGYqUihAKo+oSA00Nq9cRd9nyCQhXMjovlS7B3yPG8sg== X-Google-Smtp-Source: AGHT+IHTYQwTKMHkEz38DQzFd1iwjpi0AHXcQNsFyjMBbFhWVv3Mspqm6G58a1zdTFT24vilqSMs X-Received: by 2002:a17:906:2011:b0:a38:4f2b:8591 with SMTP id 17-20020a170906201100b00a384f2b8591mr4784494ejo.69.1707403445958; Thu, 08 Feb 2024 06:44:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707403445; cv=pass; d=google.com; s=arc-20160816; b=h17fXC24u3SKpg5NwFyR7oqmnsUJsOgBE6dEO6KMIvit1MKO26IRTTIzdmr9ivT3gr VpJVw9ssyEuubWJmgjCFRyYD4y5/je1dAIW/n5UPE/Mx2+9dub54ZbQ8jipipvGiufEF XeexiEGyxEO4XuwSdhdWcCGLI7mIg2/DuQZgljq4K56MNCPBp9nI2QKI12sFuNBESeJS +daH90Pu1OgaSZK00qHd4mjs+GPApjUxzAUmVzGKM86oKbWkSg9KTd5djyk1dFAo5Ivu dhICi66Y0zy1hQnZyWfAzQSexiUPHk0OP3FrDZSU1vlXMQ/9rIFr5JsknS6n+101Wi3S uu2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:date:from :dkim-signature; bh=z8XZunxyqYdMPeqD6B7UDzV7jXZFbniSESuNe73x/fw=; fh=H74iVCZmx0lEQqdnj4dr9l5GVBjwsjNJlvsmcHgP9cA=; b=Xmk7rwuV7yrBd+B3+zS4BRr4effRCfr3zK2JEEHnsicLzmtqxRp5pvcmClHwvx4NmU LCfHswLkw/1MGGU+3hgzNMl1hqZTWYZZJoraYItmaqVZOWTj1DL4A3jitqdhnA6RMJF4 FXC+4QZxWvWS4kqA3UY/pOLjL2V3n9axCvBNRWpoeJKRWVrWyfbjHFGBshsS6TAoeV/5 PI3Jo/lf0IhSRT09lQUXTPcW8ggcqadDctrXBfgJrFPje/RvycSi9ExnqUdqO4OZqj7F P+RIw9rzXmlsBS7PdN1a48YzmrAHXmMZXFZlkFV0CYK6e4a52SbA0G1xSaLk+enb8wV7 9Mag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cgpXii9w; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVcR13k+VnWaRipNbut4yfW86iCaggQtCYSAVoT42toQu/X6Ni9jZPvQrw05k/VN8gFlTspaqJNig6lkaUw83TxzIrm5M+NW3G6PRjioQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j7-20020a170906278700b00a37bea99905si106767ejc.451.2024.02.08.06.44.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 06:44:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cgpXii9w; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 541B31F24A3E for ; Thu, 8 Feb 2024 14:44:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00FD57B3C2; Thu, 8 Feb 2024 14:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cgpXii9w" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 426A979956; Thu, 8 Feb 2024 14:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707403432; cv=none; b=We4ZURFc6hKXGOBjSV16pEVFl2aR9bMHyne9qSR2XLnk4BohTMSAotY0uvM3oetwHd8/UGBoMZDmWp0+ubJffmYGJzRVUPL2cWoK9DpVXgA9mpVBRT2gd66zh0jLvUoDxDwzP7rVCM6ynaTaZ4c6+57KweNKzmRP8c/LVB4oX5Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707403432; c=relaxed/simple; bh=HfSHLYsgKhk5M3JSS42Ig5lg08AF0g9eFj70VaxI34M=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=JM0Kuw2+3ykXodfh3mHlldlS2MBDA/VjFzkCwm+yaYBQCz1ITSJOo1stM/acKfwxKB9jqYYt03Tatt5LMGgzIta2VFX+yzMQ2kKcwyhGX4IK0CeBBZm7o8f+cNUDSUKWE7qszSOszUDcM699rt16favkqmOkE6z27Dy6QKZWJB8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cgpXii9w; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707403431; x=1738939431; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=HfSHLYsgKhk5M3JSS42Ig5lg08AF0g9eFj70VaxI34M=; b=cgpXii9wdsObmtzRErk1M8rCLz1FF2/6YbDa91/VkNSe/4tp7hr+jCJ7 u9cWGbq650sLC7XMSlaEWxnJt1usC3CEf3hK2ZDiHXnE092ZZmBITod9E d0hIk+YegATwmzPsffkbgakGP/X3uFAbsNG644yNlUUDOjIDSStcWXskc 49gbRrBxTNQIRjmeS2UC+/ikrVCeT1QqDrSpKxKvTuXHolDFvey3Q+T9Q 9RliVHMSS44/HpOKanNzX9dgdmD6aHhdYV63A5RxykXtQT2DMgblXAiG5 tbSRba4/iIpgD7p4ZDbj79et1ZrQgVJbx4fZk2CT67+2bFPe6SPIYIGqe A==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1097098" X-IronPort-AV: E=Sophos;i="6.05,254,1701158400"; d="scan'208";a="1097098" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 06:43:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,254,1701158400"; d="scan'208";a="6283651" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.246.52.95]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 06:43:47 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Thu, 8 Feb 2024 16:43:44 +0200 (EET) To: "David E. Box" cc: Netdev , sathyanarayanan.kuppuswamy@linux.intel.com, LKML , platform-driver-x86@vger.kernel.org Subject: Re: [PATCH 6/8] platform/x86/intel/sdsi: Add attribute to read the current meter state In-Reply-To: <20240201010747.471141-7-david.e.box@linux.intel.com> Message-ID: <1b91ed16-ab06-8b67-187d-c6de596cb176@linux.intel.com> References: <20240201010747.471141-1-david.e.box@linux.intel.com> <20240201010747.471141-7-david.e.box@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 > --- > 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.