Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2877893ybg; Sat, 6 Jun 2020 04:25:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsOK1Ytcj8aq+o/u3WNKLotWHD2v5k+rAVTljarUApcFzaTpkbaG6dUY4U/IlgqssEsHWe X-Received: by 2002:aa7:cc84:: with SMTP id p4mr13671754edt.216.1591442744737; Sat, 06 Jun 2020 04:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591442744; cv=none; d=google.com; s=arc-20160816; b=of6IHt+VJIKu5Ti5nuS0j1DlceTyenjZPG720XSahola3kSyVoxzo6KKwiTpblm0GA yVyvYyPT76lzqfTbR0BucfNh4hCKCXlE+lNCzNawOGTvVFtzRgdFXVeF50o4uX2bifY0 bswXhEMM4uYzMZRhzZ8vDKPNFY13D4XI5gRJNQB4O2w9c6n/ie6Q+61xfhixGKsZTDdR CuP7UEcjoUlOWzy/G3lihtFaPJpG7V5Jdvpr5bRnsL7Jjv43qenIAzEmGjkubyzAkpEw wmqLXyiKHFg8eH8VJ76gAlQwZkdHhFLQl4gUBM7hZ8/Wx1YrUO1veHSt97lClJVhC6Tw gWjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=2HXnBon3QVB7D6IcSm2TR5cR8DI7l6uK+uP6eD84GOQ=; b=TR7unXbR0wCHXKNUA0WjiEag171E/4gqMqw+jj5ZkGMKlTPpnIKevv3iUZeM0d4tZc tiyfrfFigNxEzAN61b7tcHYqURebMpEDG5oVDn8VZcAn0F7bT9pjeYHnjRSA0KH5tZnc L2Y4zZfVlUAae+25kuV6m8iezZD8tGq+9Ta7q6CDMNIkWBGU5+Mk/hPCFSXRDHlwJ+lB ob7iv/yd6G3y9d74xZlvSVmW+XoNbBakHTI4H9XWHCTF9CsB4mRMycdPAiXpU+GA7vct YiOfAGAJQYKpLodmDagID7JSwaJuEJNIYeAqWxxX0sdbnLUbFwyDRpBPJQZfhOEVAkjO LcmA== 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 w9si5386881edu.326.2020.06.06.04.25.22; Sat, 06 Jun 2020 04:25:44 -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 S1728774AbgFFLW3 (ORCPT + 99 others); Sat, 6 Jun 2020 07:22:29 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:23048 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728718AbgFFLW2 (ORCPT ); Sat, 6 Jun 2020 07:22:28 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 056B1KJP149205; Sat, 6 Jun 2020 07:21:51 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31g42qq2d9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 06 Jun 2020 07:21:51 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 056BClkk177079; Sat, 6 Jun 2020 07:21:50 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 31g42qq2cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 06 Jun 2020 07:21:50 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 056BF2Od015969; Sat, 6 Jun 2020 11:21:49 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 31g2s7rj7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 06 Jun 2020 11:21:48 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 056BLkna67043406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 6 Jun 2020 11:21:46 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3934A4060; Sat, 6 Jun 2020 11:21:46 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D48F4A4054; Sat, 6 Jun 2020 11:21:42 +0000 (GMT) Received: from vajain21-in-ibm-com (unknown [9.85.89.98]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with SMTP; Sat, 6 Jun 2020 11:21:42 +0000 (GMT) Received: by vajain21-in-ibm-com (sSMTP sendmail emulation); Sat, 06 Jun 2020 16:51:41 +0530 From: Vaibhav Jain To: Dan Williams , Ira Weiny Cc: Santosh Sivaraj , linux-nvdimm , Linux Kernel Mailing List , Steven Rostedt , "Oliver O'Halloran" , "Aneesh Kumar K . V" , linuxppc-dev Subject: Re: [PATCH v10 4/6] powerpc/papr_scm: Improve error logging and handling papr_scm_ndctl() In-Reply-To: References: <20200604234136.253703-1-vaibhav@linux.ibm.com> <20200604234136.253703-5-vaibhav@linux.ibm.com> <20200605171313.GO1505637@iweiny-DESK2.sc.intel.com> Date: Sat, 06 Jun 2020 16:51:41 +0530 Message-ID: <87zh9gfni2.fsf@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-06_06:2020-06-04,2020-06-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=1 cotscore=-2147483648 lowpriorityscore=0 adultscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006060084 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ira and Dan, Thanks for reviewing this patch. Have updated the patch based on your feedback to upadate cmd_rc only when the nd_cmd was handled and return '0' in that case. Other errors in case the nd_cmd was unrecognized or invalid result in error returned from this functions as you suggested. ~ Vaibhav Dan Williams writes: > On Fri, Jun 5, 2020 at 10:13 AM Ira Weiny wrote: >> >> On Fri, Jun 05, 2020 at 05:11:34AM +0530, Vaibhav Jain wrote: >> > Since papr_scm_ndctl() can be called from outside papr_scm, its >> > exposed to the possibility of receiving NULL as value of 'cmd_rc' >> > argument. This patch updates papr_scm_ndctl() to protect against such >> > possibility by assigning it pointer to a local variable in case cmd_rc >> > == NULL. >> > >> > Finally the patch also updates the 'default' clause of the switch-case >> > block removing a 'return' statement thereby ensuring that value of >> > 'cmd_rc' is always logged when papr_scm_ndctl() returns. >> > >> > Cc: "Aneesh Kumar K . V" >> > Cc: Dan Williams >> > Cc: Michael Ellerman >> > Cc: Ira Weiny >> > Signed-off-by: Vaibhav Jain >> > --- >> > Changelog: >> > >> > v9..v10 >> > * New patch in the series >> >> Thanks for making this a separate patch it is easier to see what is going on >> here. >> >> > --- >> > arch/powerpc/platforms/pseries/papr_scm.c | 10 ++++++++-- >> > 1 file changed, 8 insertions(+), 2 deletions(-) >> > >> > diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c >> > index 0c091622b15e..6512fe6a2874 100644 >> > --- a/arch/powerpc/platforms/pseries/papr_scm.c >> > +++ b/arch/powerpc/platforms/pseries/papr_scm.c >> > @@ -355,11 +355,16 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, >> > { >> > struct nd_cmd_get_config_size *get_size_hdr; >> > struct papr_scm_priv *p; >> > + int rc; >> > >> > /* Only dimm-specific calls are supported atm */ >> > if (!nvdimm) >> > return -EINVAL; >> > >> > + /* Use a local variable in case cmd_rc pointer is NULL */ >> > + if (!cmd_rc) >> > + cmd_rc = &rc; >> > + >> >> This protects you from the NULL. However... >> >> > p = nvdimm_provider_data(nvdimm); >> > >> > switch (cmd) { >> > @@ -381,12 +386,13 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, >> > break; >> > >> > default: >> > - return -EINVAL; >> > + dev_dbg(&p->pdev->dev, "Unknown command = %d\n", cmd); >> > + *cmd_rc = -EINVAL; >> >> ... I think you are conflating rc and cmd_rc... >> >> > } >> > >> > dev_dbg(&p->pdev->dev, "returned with cmd_rc = %d\n", *cmd_rc); >> > >> > - return 0; >> > + return *cmd_rc; >> >> ... this changes the behavior of the current commands. Now if the underlying >> papr_scm_meta_[get|set]() fails you return that failure as rc rather than 0. >> >> Is that ok? > > The expectation is that rc is "did the command get sent to the device, > or did it fail for 'transport' reasons". The role of cmd_rc is to > translate the specific status response of the command into a common > error code. The expectations are: > > rc < 0: Error code, Linux terminated the ioctl before talking to hardware > > rc == 0: Linux successfully submitted the command to hardware, cmd_rc > is valid for command specific response > > rc > 0: Linux successfully submitted the command, but detected that > only a subset of the data was accepted for "write"-style commands, or > that only subset of data was returned for "read"-style commands. I.e. > short-write / short-read semantics. cmd_rc is valid in this case and > its up to userspace to determine if a short transfer is an error or > not. > >> Also 'logging cmd_rc' in the invalid cmd case does not seem quite right unless >> you really want rc to be cmd_rc. >> >> The architecture is designed to separate errors which occur in the kernel vs >> errors in the firmware/dimm. Are they always the same? The current code >> differentiates them. > > Yeah, they're distinct, transport vs end-point / command-specific > status returns. -- Cheers ~ Vaibhav