Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3265556pxj; Tue, 1 Jun 2021 01:02:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnKmNjmO3l19jl/JFDt7zK4R9KdNiE/kKrrdk7OwLeo9dFXTDYGJ5T0P5bcWfjhdE1+2ze X-Received: by 2002:a50:9e2e:: with SMTP id z43mr30102035ede.70.1622534548122; Tue, 01 Jun 2021 01:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622534548; cv=none; d=google.com; s=arc-20160816; b=Axtpc8A5s8KCygiX9t+XF9BBjAwT6rOm+Ftv3NCjde8/X5wZOdlvusehx2zQTJJlQ2 07iOFVySiRad7mrRV2H9W3krNgjx+xRvdhv8RinzbVJ+q/OMarlI/G3vkTdLtH0mFlFx XjZXLZu8fNhPjnYoQFhBfX7Z9Le06tHWQgrOAFejg4cF7fNVNXfk58EXkhFn7l3NZBQ5 i/qUCLq0EY+Eqxq4lYM/+eL954ZGlMYwbhPa4/9dluz+gDsL6y4WkjaHIrY+bxgL+ZTR B6zKLJV7IbDWoGl8C9faFgnXsoFTWeA/8w4YiN8itpvj316504aa0Kpzh2EKR5I6dM2n xAEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=z+453clkerGibHcZ0EucViIS2XKpAljlQHglvx1j6go=; b=Xpn0qhLsLRgk+m6fxHvBT1L2PLcD78GIL1AvDsOxQIzb6SiQkK+t7CjBIRTVgTgEvd bdbiaPEY15XkAFEJ4tUNqxwwBaG7trTkPYE6WoYza6so2D6azuW1hKtPvhV8O3sNon4O /fSF6BAWn2/Qp3M72iZOGUzCy7tfC/5tmQz0vUt2n4aCLq/jmQNl9FhWj/me1mYAzLuK rzbDEbz4ix464DInJVwzZSfVBqafwEF2sR9JG9k5KGWz8raj/pFFsAQ8PE5VnRKPf7j9 +NdyL98wsV1odHyXc6FDOK9VNlq+iwBRsdCfz3ZEmSxsGo+kkfkQYMQGvKrv1jZ/wBzk zu5Q== 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=vaisala.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si15274753ejf.594.2021.06.01.01.02.05; Tue, 01 Jun 2021 01:02:28 -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=vaisala.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbhFAIAo (ORCPT + 99 others); Tue, 1 Jun 2021 04:00:44 -0400 Received: from hel-mailgw-01.vaisala.com ([193.143.230.17]:52740 "EHLO hel-mailgw-01.vaisala.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233182AbhFAIAn (ORCPT ); Tue, 1 Jun 2021 04:00:43 -0400 Received: from HEL-SMTP.corp.vaisala.com (HEL-SMTP.corp.vaisala.com [172.24.1.225]) by hel-mailgw-01.vaisala.com (Postfix) with ESMTP id 93191601D6F2; Tue, 1 Jun 2021 10:58:55 +0300 (EEST) Received: from localhost.localdomain ([172.24.252.62]) by HEL-SMTP.corp.vaisala.com over TLS secured channel with Microsoft SMTPSVC(8.5.9600.16384); Tue, 1 Jun 2021 10:59:00 +0300 Subject: Re: [PATCH v4 2/4] nvmem: bootcount: add bootcount driver To: Srinivas Kandagatla , robh+dt@kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: =?UTF-8?B?VmVzYSBKw6TDpHNrZWzDpGluZW4=?= , Tomas Melin References: <43e36704e9acbf89b3b29113554d3a79417d42db.1620211180.git.nandor.han@vaisala.com> From: Nandor Han Message-ID: Date: Tue, 1 Jun 2021 10:58:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 01 Jun 2021 07:59:00.0348 (UTC) FILETIME=[FB2AD3C0:01D756BB] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi and thanks for your answers. On 5/28/21 11:23 AM, Srinivas Kandagatla wrote: > > > On 05/05/2021 11:42, Nandor Han wrote: >> In order to have a robust system we want to be able to identify and take >> actions if a boot loop occurs. This is possible by using the bootcount >> feature, which can be used to identify the number of times device has >> booted since bootcount was last time reset. Bootcount feature (1) >> requires a collaboration between bootloader and user-space, where >> the bootloader will increase a counter and user-space reset it. >> If the counter is not reset and a pre-established threshold is reached, >> bootloader can react and take action. >> >> This is the kernel side implementation, which can be used to >> identify the number of times device has booted since bootcount was >> last time reset. >> > > If I understand this correctly, this driver is basically exposing a > nvmem cell via sysfs. > > Firstly, This sounds like totally a generic functionality that needs to > go into nvmem core rather than individual drivers. > > Do you see any reason for this not be in core? I agree that exposing a NVMEM cell via sysfs does look as a generic functionality. However, the bootcount feature contains also a magic value that needs to be taken in consideration when extracting the bootcount value. The size of the field storing the magic and value combo is configurable as well. The driver will handle this values transparentlry for the user and expose only the validated bootcount value. In case we will only use a generic implementation for exposing a NVMEM cell via sysfs the aformention functionality will have to be handled by userspace and this will force the userspace to have knolwdge about bootcount value format and magic since they will have to implement it's own functionality about this. In the current solution the user only have to reset the value to 0 and that's it, the driver will take care of the rest. > > Secondly, creating sysfs entries like this in probe will race with > userspace udev. udev might not notice this new entry in such cases. Thanks for point this out. I will have a look how to fix this. I'll appriciate any advice. > > Thirdly, You would need to document this in Documentation/ABI/ > I'll do that. > Finally I noticed that the changes to snvs_lpgpr.c  have not been cced > to the original author. > Sorry, my mistake. I will add it in the next patch-set. -- Regards, Nandor