From patchwork Mon Jul 10 01:30:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 785980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x5SQ81lYsz9s0Z for ; Mon, 10 Jul 2017 11:32:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Afb5LiIL"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id: References:In-Reply-To:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0uuGiHRqPtGzjONJ9NDEsRwnSCos8bphYwoOpaKoS7k=; b=Afb5LiILk8+ED6TEEhndMmJ/PW V0QoFEEY1R21hCXrbIBNyVCXuS3xXXfEM50SGwJSMBaOEGLN7IR98/FPs+zJfZKz5+RnQjs3SXX+L HX+3+HPr5dxJVsRCmnf4Lar0TzbY/TIQu0CsYNlCbd/gkZVUKaCe5whAyIKq3/XyyRJo/aLA5IMzz QP8zemYBpc9mtRWk3X4nlqcVuQsryo7AhTP3cISDmrBvxjKMwlSfoHKfU3wuROjlErNyL7ZQT63yh ML9RXN+xq4ZjxKT9UrJX+n8VzWJ2ZGOkWJZq/5yZTXStG0MYqIY64Y7IXfzW6aOZ2AZl0ReSKM8Fh r86xBOgQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dUNZ4-0001BV-1E; Mon, 10 Jul 2017 01:32:42 +0000 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dUNYI-0000wz-3F for linux-mtd@lists.infradead.org; Mon, 10 Jul 2017 01:31:55 +0000 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6A1SZtH028816 for ; Sun, 9 Jul 2017 21:31:34 -0400 Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bjukq9frx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 09 Jul 2017 21:31:33 -0400 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Jul 2017 11:31:31 +1000 Received: from d23relay09.au.ibm.com (202.81.31.228) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 10 Jul 2017 11:31:28 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6A1VSV316449668 for ; Mon, 10 Jul 2017 11:31:28 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v6A1VRjb030297 for ; Mon, 10 Jul 2017 11:31:27 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v6A1VRJT030294; Mon, 10 Jul 2017 11:31:27 +1000 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 12F8FA034A; Mon, 10 Jul 2017 11:31:27 +1000 (AEST) From: Cyril Bur To: linuxppc-dev@lists.ozlabs.org, linux-mtd@lists.infradead.org Subject: [PATCH v2 02/10] mtd: powernv_flash: Lock around concurrent access to OPAL Date: Mon, 10 Jul 2017 11:30:58 +1000 X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170710013106.27276-1-cyrilbur@gmail.com> References: <20170710013106.27276-1-cyrilbur@gmail.com> X-TM-AS-MML: disable x-cbid: 17071001-1617-0000-0000-000001F412FF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071001-1618-0000-0000-0000483BAF78 Message-Id: <20170710013106.27276-3-cyrilbur@gmail.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-09_14:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1707100024 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170709_183154_191110_DD8D4EF8 X-CRM114-Status: GOOD ( 13.56 ) X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [148.163.156.1 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [148.163.156.1 listed in wl.mailspike.net] 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (cyrilbur[at]gmail.com) 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 0.9 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stewart@linux.vnet.ibm.com, benh@kernel.crashing.org, alistair@popple.id.au, dwmw2@infradead.org, rlippert@google.com MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org OPAL can only manage one flash access at a time and will return an OPAL_BUSY error for each concurrent access to the flash. The simplest way to prevent this from happening is with a mutex. Signed-off-by: Cyril Bur --- drivers/mtd/devices/powernv_flash.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c index a9a20c00687c..7b41af06f4fe 100644 --- a/drivers/mtd/devices/powernv_flash.c +++ b/drivers/mtd/devices/powernv_flash.c @@ -38,6 +38,7 @@ struct powernv_flash { struct mtd_info mtd; + struct mutex lock; u32 id; }; @@ -59,12 +60,15 @@ static int powernv_flash_async_op(struct mtd_info *mtd, enum flash_op op, dev_dbg(dev, "%s(op=%d, offset=0x%llx, len=%zu)\n", __func__, op, offset, len); + mutex_lock(&info->lock); + token = opal_async_get_token_interruptible(); if (token < 0) { if (token != -ERESTARTSYS) dev_err(dev, "Failed to get an async token\n"); - return token; + rc = token; + goto out; } switch (op) { @@ -79,18 +83,21 @@ static int powernv_flash_async_op(struct mtd_info *mtd, enum flash_op op, break; default: WARN_ON_ONCE(1); - return -EIO; + rc = -EIO; + goto out; } if (rc != OPAL_ASYNC_COMPLETION) { dev_err(dev, "opal_flash_async_op(op=%d) failed (rc %d)\n", op, rc); opal_async_release_token(token); - return -EIO; + rc = -EIO; + goto out; } rc = opal_async_wait_response(token, &msg); opal_async_release_token(token); + mutex_unlock(&info->lock); if (rc) { dev_err(dev, "opal async wait failed (rc %d)\n", rc); return -EIO; @@ -106,6 +113,9 @@ static int powernv_flash_async_op(struct mtd_info *mtd, enum flash_op op, } return rc; +out: + mutex_unlock(&info->lock); + return rc; } /** @@ -237,6 +247,8 @@ static int powernv_flash_probe(struct platform_device *pdev) if (ret) goto out; + mutex_init(&data->lock); + dev_set_drvdata(dev, data); /*