Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1687686ybg; Thu, 4 Jun 2020 16:46:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUA0jyuKZz+6FutNfN4JTuhOo6T1zJOdYN1lEUvnuUOKxCaEzafyZeBLKXmE7shRwGHdCR X-Received: by 2002:aa7:d613:: with SMTP id c19mr6565581edr.321.1591314382392; Thu, 04 Jun 2020 16:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591314382; cv=none; d=google.com; s=arc-20160816; b=Q4AJawJXqsovZzViW5bIpq4n1LjfB1GH7pvVd4xMaBT5gZDPBgxvwSaO+is+pHQYT3 j38TR4iTF6dtD+ckNbvqSUCcEmiJzEosMN5uF25TmsrloWaXd4DVBFA53EiDYQqx0r6j 0y79K2Vlw1sUWKlEhs/whgSIgSkhTiD9GMZfoHTH7VjkPLrIw1XL7xTYer4sn+L5T4rM mezENSQXuXxPenhMLlaLUfjDrBFdLhIh6IJwqYnd5XjCNOB7PYQVI3a6uICEak9NF7xE 3SVa2N35JZtdkxu7wHG9vLMACO/kq7MbJsEPTK1iJ5OvmphAhrU18HGVkAgmInhpEstr 1PwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xQpIrzzlxGygGYBNo222zECx1leiHNhhm3NEYDudDEs=; b=tzQfQ8LgqBsGB3CkLmp9/g8ajI6aC9oyBDeSmtDz7JrLg0equ840HTW13cEZtQVGLC DtIh6U7+Z/SfU69PYDwNJRNxGKcc5K/48G6RW+ranPotOllWJQljBEo4ZiW3MEd86eth 2w5doSNW7F+I97xdiS8wmoe9UueBYvFIC19mt9sT5+7nTcxqjcbL/m+Ew3XAT7H7b99G K9Ly//9PBa2wG7CiGWFBmVJSFAAlDTXZ9oqLmekR5zh0LWCs0a+bwtsTmnWEDPSk6HYP BsWGYrTxn5o3W7QuRg3f7/eGZ6VyMKJyVpEl+C0BswDGtNCRtQiKOYLwnwG8QFjzxM/I E9Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si2595746eju.21.2020.06.04.16.45.59; Thu, 04 Jun 2020 16:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726195AbgFDXnJ (ORCPT + 99 others); Thu, 4 Jun 2020 19:43:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:30230 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725863AbgFDXnI (ORCPT ); Thu, 4 Jun 2020 19:43:08 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 054NZ0EA046616; Thu, 4 Jun 2020 19:42:27 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31f90htftd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jun 2020 19:42:27 -0400 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 054NaPQ3061085; Thu, 4 Jun 2020 19:42:26 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 31f90htfsh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jun 2020 19:42:26 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 054NehP9015096; Thu, 4 Jun 2020 23:42:24 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 31bf482wy3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jun 2020 23:42:24 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 054NgKVC66191564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 4 Jun 2020 23:42:20 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A237A11C04C; Thu, 4 Jun 2020 23:42:20 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 351DB11C052; Thu, 4 Jun 2020 23:42:16 +0000 (GMT) Received: from vajain21-in-ibm-com (unknown [9.85.71.124]) by d06av25.portsmouth.uk.ibm.com (Postfix) with SMTP; Thu, 4 Jun 2020 23:42:15 +0000 (GMT) Received: by vajain21-in-ibm-com (sSMTP sendmail emulation); Fri, 05 Jun 2020 05:12:14 +0530 From: Vaibhav Jain To: linuxppc-dev@lists.ozlabs.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Cc: Vaibhav Jain , Dan Williams , "Aneesh Kumar K . V" , Michael Ellerman , "Oliver O'Halloran" , Santosh Sivaraj , Steven Rostedt , Ira Weiny Subject: [PATCH v10 6/6] powerpc/papr_scm: Implement support for PAPR_PDSM_HEALTH Date: Fri, 5 Jun 2020 05:11:36 +0530 Message-Id: <20200604234136.253703-7-vaibhav@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604234136.253703-1-vaibhav@linux.ibm.com> References: <20200604234136.253703-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-04_13:2020-06-04,2020-06-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 cotscore=-2147483648 priorityscore=1501 mlxscore=0 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006040164 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements support for PDSM request 'PAPR_PDSM_HEALTH' that returns a newly introduced 'struct nd_papr_pdsm_health' instance containing dimm health information back to user space in response to ND_CMD_CALL. This functionality is implemented in newly introduced papr_pdsm_health() that queries the nvdimm health information and then copies this information to the package payload whose layout is defined by 'struct nd_papr_pdsm_health'. Cc: "Aneesh Kumar K . V" Cc: Dan Williams Cc: Michael Ellerman Cc: Ira Weiny Signed-off-by: Vaibhav Jain --- Changelog: v9..v10: * Removed code in papr_pdsm_health that performed validation on pdsm payload version and corrosponding struct and defines used for validation of payload version. * Dropped usage of struct papr_pdsm_health in 'struct papr_scm_priv'. Instead papr_psdm_health() now uses 'papr_scm_priv.health_bitmap' to populate the pdsm payload. * Above change also fixes the problem where this patch was removing the code that was previously introduced in this patch-series. [ Ira ] * Introduced a new def ND_PDSM_ENVELOPE_HDR_SIZE that indicates the space allocated to 'struct nd_pdsm_cmd_pkg' fields except 'struct nd_cmd_pkg'. This def is useful in validating payload sizes. * Reworked papr_pdsm_health() to enforce a specific payload size for 'PAPR_PDSM_HEALTH' pdsm request. Resend: * Added ack from Aneesh. v8..v9: * s/PAPR_SCM_PDSM_HEALTH/PAPR_PDSM_HEALTH/g [ Dan , Aneesh ] * s/PAPR_SCM_PSDM_DIMM_*/PAPR_PDSM_DIMM_*/g * Renamed papr_scm_get_health() to papr_psdm_health() * Updated patch description to replace papr-scm dimm with nvdimm. v7..v8: * None Resend: * None v6..v7: * Updated flags_show() to use seq_buf_printf(). [Mpe] * Updated papr_scm_get_health() to use newly introduced __drc_pmem_query_health() bypassing the cache [Mpe]. v5..v6: * Added attribute '__packed' to 'struct nd_papr_pdsm_health_v1' to gaurd against possibility of different compilers adding different paddings to the struct [ Dan Williams ] * Updated 'struct nd_papr_pdsm_health_v1' to use __u8 instead of 'bool' and also updated drc_pmem_query_health() to take this into account. [ Dan Williams ] v4..v5: * None v3..v4: * Call the DSM_PAPR_SCM_HEALTH service function from papr_scm_service_dsm() instead of papr_scm_ndctl(). [Aneesh] v2..v3: * Updated struct nd_papr_scm_dimm_health_stat_v1 to use '__xx' types as its exported to the userspace [Aneesh] * Changed the constants DSM_PAPR_SCM_DIMM_XX indicating dimm health from enum to #defines [Aneesh] v1..v2: * New patch in the series --- arch/powerpc/include/uapi/asm/papr_pdsm.h | 33 +++++++++++ arch/powerpc/platforms/pseries/papr_scm.c | 70 +++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/arch/powerpc/include/uapi/asm/papr_pdsm.h b/arch/powerpc/include/uapi/asm/papr_pdsm.h index 8b1a4f8fa316..c4c990ede5d4 100644 --- a/arch/powerpc/include/uapi/asm/papr_pdsm.h +++ b/arch/powerpc/include/uapi/asm/papr_pdsm.h @@ -71,12 +71,17 @@ struct nd_pdsm_cmd_pkg { __u8 payload[]; /* In/Out: Sub-cmd data buffer */ } __packed; +/* Calculate size used by the pdsm header fields minus 'struct nd_cmd_pkg' */ +#define ND_PDSM_ENVELOPE_HDR_SIZE \ + (sizeof(struct nd_pdsm_cmd_pkg) - sizeof(struct nd_cmd_pkg)) + /* * Methods to be embedded in ND_CMD_CALL request. These are sent to the kernel * via 'nd_pdsm_cmd_pkg.hdr.nd_command' member of the ioctl struct */ enum papr_pdsm { PAPR_PDSM_MIN = 0x0, + PAPR_PDSM_HEALTH, PAPR_PDSM_MAX, }; @@ -95,4 +100,32 @@ static inline void *pdsm_cmd_to_payload(struct nd_pdsm_cmd_pkg *pcmd) return (void *)(pcmd->payload); } +/* Various nvdimm health indicators */ +#define PAPR_PDSM_DIMM_HEALTHY 0 +#define PAPR_PDSM_DIMM_UNHEALTHY 1 +#define PAPR_PDSM_DIMM_CRITICAL 2 +#define PAPR_PDSM_DIMM_FATAL 3 + +/* + * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH + * Various flags indicate the health status of the dimm. + * + * dimm_unarmed : Dimm not armed. So contents wont persist. + * dimm_bad_shutdown : Previous shutdown did not persist contents. + * dimm_bad_restore : Contents from previous shutdown werent restored. + * dimm_scrubbed : Contents of the dimm have been scrubbed. + * dimm_locked : Contents of the dimm cant be modified until CEC reboot + * dimm_encrypted : Contents of dimm are encrypted. + * dimm_health : Dimm health indicator. One of PAPR_PDSM_DIMM_XXXX + */ +struct nd_papr_pdsm_health { + __u8 dimm_unarmed; + __u8 dimm_bad_shutdown; + __u8 dimm_bad_restore; + __u8 dimm_scrubbed; + __u8 dimm_locked; + __u8 dimm_encrypted; + __u16 dimm_health; +} __packed; + #endif /* _UAPI_ASM_POWERPC_PAPR_PDSM_H_ */ diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c index 05eb56ecab5e..984942be24c1 100644 --- a/arch/powerpc/platforms/pseries/papr_scm.c +++ b/arch/powerpc/platforms/pseries/papr_scm.c @@ -421,6 +421,72 @@ static int is_cmd_valid(struct nvdimm *nvdimm, unsigned int cmd, void *buf, return 0; } +/* Fetch the DIMM health info and populate it in provided package. */ +static int papr_pdsm_health(struct papr_scm_priv *p, + struct nd_pdsm_cmd_pkg *pkg) +{ + int rc; + struct nd_papr_pdsm_health health = { 0 }; + u16 copysize = sizeof(struct nd_papr_pdsm_health); + u16 payload_size = pkg->hdr.nd_size_out - ND_PDSM_ENVELOPE_HDR_SIZE; + + /* Ensure correct payload size that can hold struct nd_papr_pdsm_health */ + if (payload_size != copysize) { + dev_dbg(&p->pdev->dev, + "Unexpected payload-size (%u). Expected (%u)", + pkg->hdr.nd_size_out, copysize); + rc = -ENOSPC; + goto out; + } + + /* Ensure dimm health mutex is taken preventing concurrent access */ + rc = mutex_lock_interruptible(&p->health_mutex); + if (rc) + goto out; + + /* Always fetch upto date dimm health data ignoring cached values */ + rc = __drc_pmem_query_health(p); + if (rc) { + mutex_unlock(&p->health_mutex); + goto out; + } + + /* update health struct with various flags derived from health bitmap */ + health = (struct nd_papr_pdsm_health) { + .dimm_unarmed = p->health_bitmap & PAPR_PMEM_UNARMED_MASK, + .dimm_bad_shutdown = p->health_bitmap & PAPR_PMEM_BAD_SHUTDOWN_MASK, + .dimm_bad_restore = p->health_bitmap & PAPR_PMEM_BAD_RESTORE_MASK, + .dimm_encrypted = p->health_bitmap & PAPR_PMEM_ENCRYPTED, + .dimm_locked = p->health_bitmap & PAPR_PMEM_SCRUBBED_AND_LOCKED, + .dimm_scrubbed = p->health_bitmap & PAPR_PMEM_SCRUBBED_AND_LOCKED, + .dimm_health = PAPR_PDSM_DIMM_HEALTHY, + }; + + /* Update field dimm_health based on health_bitmap flags */ + if (p->health_bitmap & PAPR_PMEM_HEALTH_FATAL) + health.dimm_health = PAPR_PDSM_DIMM_FATAL; + else if (p->health_bitmap & PAPR_PMEM_HEALTH_CRITICAL) + health.dimm_health = PAPR_PDSM_DIMM_CRITICAL; + else if (p->health_bitmap & PAPR_PMEM_HEALTH_UNHEALTHY) + health.dimm_health = PAPR_PDSM_DIMM_UNHEALTHY; + + /* struct populated hence can release the mutex now */ + mutex_unlock(&p->health_mutex); + + dev_dbg(&p->pdev->dev, "Copying payload size=%u\n", copysize); + + /* Copy the health struct to the payload */ + memcpy(pdsm_cmd_to_payload(pkg), &health, copysize); + + /* Update fw size including size of struct nd_pdsm_cmd_pkg fields */ + pkg->hdr.nd_fw_size = copysize + ND_PDSM_ENVELOPE_HDR_SIZE; + +out: + dev_dbg(&p->pdev->dev, "completion code = %d\n", rc); + + return rc; +} + /* * For a given pdsm request call an appropriate service function. * Note: Use 'nd_pdsm_cmd_pkg.cmd_status to report psdm servicing errors. Hence @@ -435,6 +501,10 @@ static void papr_scm_service_pdsm(struct papr_scm_priv *p, /* Call pdsm service function */ switch (pdsm) { + case PAPR_PDSM_HEALTH: + pkg->cmd_status = papr_pdsm_health(p, pkg); + break; + default: dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Unsupported PDSM request\n", pdsm); -- 2.26.2