Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp960629pxb; Wed, 3 Mar 2021 22:36:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwe4EEcZAXFT32ZXdbB0+VharbcFAnWYKvhRWE5gEmSgPrROc6p0ZgHTlH2v43iA95aJ1nx X-Received: by 2002:a17:906:f0d0:: with SMTP id dk16mr2658442ejb.48.1614839790178; Wed, 03 Mar 2021 22:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839790; cv=none; d=google.com; s=arc-20160816; b=Cp0yXPBIPD4eMDKuWdeDLNa5W7ee5J9UV1PxbTJDthcxKAcvkjJvBcNywyyWWU31BM RK8TrFdoPJbiM9kbBHoXIRx9fZeWVCm/Uc89kQtD9ApKgzqhDYUOUyvl41s3Pp4SILj8 sYT4POd8a+Y5k1RhoneVaBA8hi81LmMs73OSCidgvtmhst3bbg59sv4cHskTZXSfSS7i MWdLK+3uSX9aq7iMur57zAibHQxUx5hqW7X5SL1+P7y5SIy3BIhRRgXCRkTETbZ6Oc2a DkeDMWN3au0HeGdWJHe6nKrLG8I0XOWMapR6Y+cjDVkRVgoiYD2laaT9IkvP1HF8InK0 nMRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=3JlHuWOPny519lb/zyMBEgaPndadrigbre2ILZ7KICM=; b=N7QU0FddHkJnyAJ0UG7diqIQghjsrfPdr5GQPdfOcpt4O3zNzsLUMv2oVb8lW22lND +lREci/DsyhViyephMmqY1r45FBVDM7ZtKxV1vddW8MB6f8ir8al2S1cCT9JXovNbiXM mN8y5S8a1lueoQB3YqUWDfaV8dGTuJRAsgNKrxda/zTvAEOMeQO3+kAxpE6ottDUdJm7 05MfTY0IcTswWssa2lY83N3UHEZBGW0X1vLTVpnYQj1IC6fO4GGfYQw8X2j+HmQQIhUK 2VzRkv/PKdH0UCP+EudjJosGixTOY1eQFS7sZCaMUflOpxTS/V3euIjVCwOEvTDBmd/B bvwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=aIsuZAW7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g23si9480448ejx.623.2021.03.03.22.36.08; Wed, 03 Mar 2021 22:36:30 -0800 (PST) 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; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=aIsuZAW7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1835788AbhCBTTX (ORCPT + 99 others); Tue, 2 Mar 2021 14:19:23 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:41937 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344137AbhCBRAw (ORCPT ); Tue, 2 Mar 2021 12:00:52 -0500 Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id C75A72223E; Tue, 2 Mar 2021 17:59:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1614704371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3JlHuWOPny519lb/zyMBEgaPndadrigbre2ILZ7KICM=; b=aIsuZAW7/uUq74cQH1wwlv/1J3mx4NjhSE0hH9sfWpgoSOpOGr20SMjMytSNk/22A0IEy1 PuuqQofyh3kiJq25UbGJEB0hyYU5+FP9so/6u1mzW5D5Sn0qy4VIW+RR5NVFZ/4slQeHBe o8U3Dia5iS2yciyNfdM6sj1y0jbt2fs= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 02 Mar 2021 17:59:31 +0100 From: Michael Walle To: Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Miquel Raynal , Richard Weinberger , Tudor.Ambarus@microchip.com Subject: Re: [RFC PATCH] mtd: add OTP (one-time-programmable) erase ioctl In-Reply-To: References: <20210302110927.6520-1-michael@walle.cc> <74df918148be8c9820acc877e39adf3f@walle.cc> User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: michael@walle.cc Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 2021-03-02 17:33, schrieb Vignesh Raghavendra: > On 3/2/21 9:49 PM, Michael Walle wrote: >> Am 2021-03-02 16:30, schrieb Vignesh Raghavendra: >>> Hi, >>> >>> On 3/2/21 4:39 PM, Michael Walle wrote: >>>> This may sound like a contradiction but some SPI-NOR flashes really >>>> support erasing their OTP region until it is finally locked. Having >>>> the >>>> possibility to erase an OTP region might come in handy during >>>> development. >>>> >>>> The ioctl argument follows the OTPLOCK style. >>>> >>>> Signed-off-by: Michael Walle >>>> --- >>>> OTP support for SPI-NOR flashes may be merged soon: >>>> https://lore.kernel.org/linux-mtd/20210216162807.13509-1-michael@walle.cc/ >>>> >>>> >>>> Tudor suggested to add support for the OTP erase operation most >>>> SPI-NOR >>>> flashes have: >>>> https://lore.kernel.org/linux-mtd/d4f74b1b-fa1b-97ec-858c-d807fe1f9e57@microchip.com/ >>>> >>>> >>>> Therefore, this is an RFC to get some feedback on the MTD side, once >>>> this >>>> is finished, I can post a patch for mtd-utils. Then we'll have a >>>> foundation >>>> to add the support to SPI-NOR. >>>> >>>>  drivers/mtd/mtdchar.c      |  7 ++++++- >>>>  drivers/mtd/mtdcore.c      | 12 ++++++++++++ >>>>  include/linux/mtd/mtd.h    |  3 +++ >>>>  include/uapi/mtd/mtd-abi.h |  2 ++ >>>>  4 files changed, 23 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c >>>> index 323035d4f2d0..da423dd031ae 100644 >>>> --- a/drivers/mtd/mtdchar.c >>>> +++ b/drivers/mtd/mtdchar.c >>>> @@ -661,6 +661,7 @@ static int mtdchar_ioctl(struct file *file, >>>> u_int >>>> cmd, u_long arg) >>>>      case OTPGETREGIONCOUNT: >>>>      case OTPGETREGIONINFO: >>>>      case OTPLOCK: >>>> +    case OTPERASE: >>> >>> This is not a Safe IOCTL. We are destroying OTP data. Need to check >>> for >>> write permission before allowing the ioctl right? >> >> Ah yes, of course. But this makes me wonder why OTPLOCK >> is considered a safe command. As well as MEMLOCK and >> MEMUNLOCK. And MEMSETBADBLOCK. Shouldn't these also >> require write permissions? >> > > Well, one argument would be that LOCK/UNLOCK in itself won't modify > data > and thus does not need write permission.. Although can brick a flash > from ever being writable again and change content of flash registers. Whether not you can brick a device (I agree with you), it is writing to the protection bits. But what is more imporant is that OTPLOCK is actually write-once. > I am fine with moving these to require write permissions as well > (probably OTPLOCK as well). Ok, I'm unsure about MEMSETBADBLOCK, though. -michael