From patchwork Thu Apr 20 01:56:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 752596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w7hqQ6M1Fz9s3s for ; Thu, 20 Apr 2017 11:58:42 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3w7hqQ5hPVzDqK7 for ; Thu, 20 Apr 2017 11:58:42 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3w7hq35ZxgzDqGv for ; Thu, 20 Apr 2017 11:58:23 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3K1rixK143895 for ; Wed, 19 Apr 2017 21:58:16 -0400 Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) by mx0a-001b2d01.pphosted.com with ESMTP id 29xgvf5rfp-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 19 Apr 2017 21:58:15 -0400 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Apr 2017 11:58:01 +1000 Received: from d23relay08.au.ibm.com (202.81.31.227) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 20 Apr 2017 11:58:00 +1000 Received: from d23av05.au.ibm.com (d23av05.au.ibm.com [9.190.234.119]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3K1vpvC6619622 for ; Thu, 20 Apr 2017 11:57:59 +1000 Received: from d23av05.au.ibm.com (localhost [127.0.0.1]) by d23av05.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3K1vRx4026490 for ; Thu, 20 Apr 2017 11:57:27 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av05.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3K1vR46026188; Thu, 20 Apr 2017 11:57: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 5771AA0212; Thu, 20 Apr 2017 11:57:03 +1000 (AEST) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Thu, 20 Apr 2017 11:56:38 +1000 X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170420015639.4274-1-cyril.bur@au1.ibm.com> References: <20170420015639.4274-1-cyril.bur@au1.ibm.com> X-TM-AS-MML: disable x-cbid: 17042001-1617-0000-0000-000001C174D6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042001-1618-0000-0000-000048012650 Message-Id: <20170420015639.4274-2-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-19_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704200012 Subject: [Skiboot] [PATCH 1/2] libflash/file: Only use 64bit MTD erase ioctl() when needed X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au, mikey@neuling.org MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Commit e5720d3fe94f5b85c374520b89fb8fbb2143df94 introduced using the 64bit MTD erase ioctl() after a rework of blocklevel to make it fully 64bit safe. It turns out that not all kernels on which pflash might run actually have the 64bit MTD ioctl(), this is probably due to the kernel being based off 2.6.28.10. This bug is partially exposed by making the blocklevel_erase() path better from d6a5b53f878bb422cfd2a960fff9dce5e3bb4117 which added blocklevel_smart_erase(). This patch addresses this by only using the 64bit version of the erase ioctl() if the parameters exceed 32bit in size. Signed-off-by: Cyril Bur --- libflash/file.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/libflash/file.c b/libflash/file.c index 5f074cf2..ac4ceeaf 100644 --- a/libflash/file.c +++ b/libflash/file.c @@ -15,6 +15,7 @@ */ #define _GNU_SOURCE #include +#include #include #include #include @@ -130,13 +131,42 @@ static int file_erase(struct blocklevel_device *bl, uint64_t dst, uint64_t len) static int mtd_erase(struct blocklevel_device *bl, uint64_t dst, uint64_t len) { struct file_data *file_data = container_of(bl, struct file_data, bl); - struct erase_info_user64 erase_info = { - .start = dst, - .length = len - }; + int err; - if (ioctl(file_data->fd, MEMERASE64, &erase_info) == -1) - return FLASH_ERR_PARM_ERROR; + FL_DBG("%s: dst: 0x%" PRIx64 ", len: 0x%" PRIx64 "\n", __func__, dst, len); + + /* + * Some kernels that pflash supports do not know about the 64bit + * version of the IOCTL therefore we'll just use the 32bit (which + * should always be supported...) unless we MUST use the 64bit and + * then lets just hope the kernel knows how to deal with it + */ + if (dst > UINT_MAX || len > UINT_MAX) { + struct erase_info_user64 erase_info = { + .start = dst, + .length = len + }; + + if (ioctl(file_data->fd, MEMERASE64, &erase_info) == -1) { + err = errno; + if (err == 25) /* Kernel doesn't do 64bit MTD erase ioctl() */ + FL_DBG("Attempted a 64bit erase on a kernel which doesn't support it\n"); + FL_ERR("%s: IOCTL to kernel failed! %s\n", __func__, strerror(err)); + errno = err; + return FLASH_ERR_PARM_ERROR; + } + } else { + struct erase_info_user erase_info = { + .start = dst, + .length = len + }; + if (ioctl(file_data->fd, MEMERASE, &erase_info) == -1) { + err = errno; + FL_ERR("%s: IOCTL to kernel failed! %s\n", __func__, strerror(err)); + errno = err; + return FLASH_ERR_PARM_ERROR; + } + } return 0; }