Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2553036pxb; Sat, 28 Aug 2021 19:00:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBkDTkchEpavJOZBhWJrswHf+PKK2CO9CQ0uRjgau59CMnmxNSVFvNWwOlo+ip3xt75QGo X-Received: by 2002:a17:906:1299:: with SMTP id k25mr17533419ejb.139.1630202408905; Sat, 28 Aug 2021 19:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630202408; cv=none; d=google.com; s=arc-20160816; b=hZTRKWTpz/VYBhteMmQgfqGo6Glrbqlku5+rM0kMLN3l38+g0u13i4HncmX9oeAcmH uY5Ms+RTJ1wF27Nju9izktrqNEVgCOiFHXpet/1KEm4dz8QPlOJWiZnFLaHyM/+ILApB /y0p6hda7yltrwQuMYIHpOK7KCRTTIXx0rc9vY9AC0VPTU6iTI80zbJpzvCTRz6kF0p9 2JWtMTuSLmIvtKWhBDX6RmzTEkfk2pN30otcTvJbC6PsXt9bYZv82SyemCxmdMiU+UIE xA1Yad5Okko629SJYBCsK3oVrk3+zcMMvU2ID6bGx2ZLI23Gz1hT5dgHFzgt3ImaViwY Kbow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=Drj7IcQoCBs/dEmsDr8+db2OAo1zOt1DRQAHqyUgWtE=; b=oh5WLkBp16A2WxtB3pZfA0hhn4Qp6oUWLxlJrv2mplJt6IPuPnv115zlt2JKGt/JUs UDZ8S5U0+4ZqnrbpDnfITjkA8+7vW/sj8ciJ+zwgpSRVoS8AsG3SYkZ8uZpFqgo4gDGk 5ybhmeSavMvCH5BRuqMiwjJkhzCgGH1Z0TP/edvs3ZAYyxR4r6mdkgxk0/LU8yobXoB6 DvYa2cMiwlO6SyLQ+3rEwddRd3SBtSL6pTF5jErHGe9RwxOnJ0gbvzXNahyxGeZpkwwd Z9U1QUYKrNMZh6gtgWH+GoNB7RYxbuM2pvvP880DbrE7CClS65S4zxuUDlfgNzrW7ffv YSvA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si11578790edz.49.2021.08.28.18.59.42; Sat, 28 Aug 2021 19:00:08 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233763AbhH2BT3 (ORCPT + 99 others); Sat, 28 Aug 2021 21:19:29 -0400 Received: from smtprelay06.ispgateway.de ([80.67.18.29]:45031 "EHLO smtprelay06.ispgateway.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbhH2BT2 (ORCPT ); Sat, 28 Aug 2021 21:19:28 -0400 X-Greylist: delayed 21711 seconds by postgrey-1.27 at vger.kernel.org; Sat, 28 Aug 2021 21:19:27 EDT Received: from [87.92.210.171] (helo=[192.168.0.111]) by smtprelay06.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mJvWn-0000E5-1t; Sat, 28 Aug 2021 12:25:33 +0200 Subject: Re: [PATCH] drivers/cdrom: improved ioctl for media change detection To: Jens Axboe Cc: linux-kernel@vger.kernel.org References: <20210805194417.12439-1-lumip@lumip.de> <6d6c533d-465e-33ee-5801-cb7ea84924a8@kernel.dk> <5f3b7d8b-9e97-094b-efd1-cad6cab793b6@kernel.dk> From: Lukas Prediger Message-ID: <6bbfc86d-8e3b-db5e-0bf5-8bce63d2049f@lumip.de> Date: Sat, 28 Aug 2021 13:27:41 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <5f3b7d8b-9e97-094b-efd1-cad6cab793b6@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Df-Sender: bHVrYXMucHJlZGlnZXJAbHVtaXAuZGU= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for the reply and sorry for the spam :/. I am not sure what happened there. >> 2. As the last_media_change field will be in ms now, is it safe to >> convert those back to jiffies for comparison or is there a risk of >> information loss (due to rounding or whatever) in either conversion? >> More technically, can I make the assumption that for any jiffies value >> x it holds that > The granularity of jiffies depends on the HZ setting, generally just > consider it somewhere in between 100 and 1000. That's where my initial > granularity numbers came from. > >> time_before(msecs_to_jiffies(jiffies_to_msecs(x)), x) is always false ? > I don't think that matters. Internally, always keep things in jiffies. > That's what you use to compare with, and to check if it's changed since > last time. The only time you convert to ms is to pass it back to > userspace. And that's going to be a delta of jiffies always, just ensure > you assign last_checked = jiffies when it's setup initially. > The issue I have is that the value I am comparing to is provided by the code calling the ioctl so that I don't have to maintain state for every potential calling process in the kernel. Therefore, if we want the API to work with ms, I have to convert the user provided value back to jiffies for comparison. I now ran a brief test that suggests that the above condition does not hold and therefore the value returned in has_changed may be 1 for subsequent calls when the disc was not in fact changed. Workarounds I see would be to either expose the jiffies value through the API (which is maybe not really clean), or making the comparison on the ms value (but how to deal with potential wraparounds then?). Of those, I would currently tend to the first and treat the nature of the returned timestamp as an opaque value from the user perspective - it is probably not really of any use to them outside of passing it back into the ioctl for subsequent calls. Do you see other ways to resolve this I may not have thought of? Kind regards, Lukas