Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1851834pxb; Fri, 27 Aug 2021 20:19:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKv+RrrMlD3XKvifRD+L8OjP/45qJfZxZqljUiNKG7qQZu+AdIP3QYkZrV2f4eWP70Mh9l X-Received: by 2002:a5d:9304:: with SMTP id l4mr9987841ion.167.1630120764730; Fri, 27 Aug 2021 20:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630120764; cv=none; d=google.com; s=arc-20160816; b=RiZYHxn9Ns3isg23uNkIQGsQjDFU91Y4D5+0N8ZqYg816bM/ipCmt7xD0d6eSMBTvn Pj30arwQKHyNzMO3LHDZP9UdrGVoFUgBghTFcXRA3IhHJzz4MbL5h2Z4a+lC5IfwFbtl i6fdnE0rRmdM/eo6QEJguuDitGcg7YJLhigtKTFx7Vk8blsxeabvpb1B2qsMLoaxWkoy ZUd6Pgzd69snJImQAbP46+zn53E/vzwx+cVbUrnH2vGkkyeXVDpTVm71UzCbvVCFrwT3 FxYk/3oANvVihm68cPUkDYs9e4+c8U/5WPSMLVBMhwH7j/l6GW97Q9PCTyCIHAI05Xqn Rn+g== 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:dkim-signature; bh=3I2Cu0hBkyC0eu8QwfehQRNRrLF5kE2Nh3wW304WegI=; b=EuLoxBfs2F598VEHXGfOImf/2wsqhafl0pXlgwk4rCK3xaQKJSYSjTyOaLSdJBidxe pLk2F4Np3A6+rniCM4CM45g0wM2NW+7L6+V6dailMQolFgE5PycZw0Nk6IvRvOLQqR/e 2VP/bR09f5anvmWmem+ERKA7wLDBPbknSi8zZ6ETThiZplJ/3A8VI4w9WN6vhTaBN2PZ rnw/oHYfH5s9pZJZGr0jgvRGmx4jFK3sWd9mPMMWoaMZDRbyPzE+QGzR+LZ33NJi7t5n uicpzoBYPpYFgLMueJwkCoLovl6SlzgwY367XngfS+4p13/qoVvxJIRRmvk0J12uh43A s1TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=VFc6nnAr; 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 n22si7820768jaj.53.2021.08.27.20.19.11; Fri, 27 Aug 2021 20:19:24 -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; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=VFc6nnAr; 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 S233170AbhH1DTQ (ORCPT + 99 others); Fri, 27 Aug 2021 23:19:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233117AbhH1DTN (ORCPT ); Fri, 27 Aug 2021 23:19:13 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9F19C0613D9 for ; Fri, 27 Aug 2021 20:18:23 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id f6so11614319iox.0 for ; Fri, 27 Aug 2021 20:18:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3I2Cu0hBkyC0eu8QwfehQRNRrLF5kE2Nh3wW304WegI=; b=VFc6nnAr/WImQdqxvEVT41P7sUbT0ys0GLIzwNul0ab7smJx8tK8ypODc8gP/mERLl ZUsl/ci0RDvaEL1kdtTX7Cq+c4oV018Xm9DmOSP1LfEzZOGow0MUYCcTYWxXG4hYeV1w WrFmbucTiKSnLJcliTcKu59QWjzSWN8ijvOK0cNdsTBmf61n9sOHGknE7g+7Tw+PuYWh Fu4eztVYTECtsgMOAPGRbpFRtDNaZYddgU1ppgbqRIAkU/2GUmh1QQ7ZQvQEjL/U0pfx RW0fY3WGzah8VWtjaGgjpTvhS5HBkKQ1T7B2DywgLCvQP/zWCqFMbVVtNUTMrk2EKBxR X0Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3I2Cu0hBkyC0eu8QwfehQRNRrLF5kE2Nh3wW304WegI=; b=gFt99HLnntfpb1EH2CHZ1JTOjoWVMBApbtg5hh6Z4Xi9pqx632P9Vztkx7TuKCPehl 0JdAPhXhqeA6ZDHzhexCpmivm008r6KQ7CFZzxiJEiC56SBUKWIsFST+aLxeD106ZGDS dqdBzaTinlWyrl0dbKGs7wF1NWkwzCC0FlaBIL2Z9fBQHtJA5dVjq6qrfuj9tzPt6ngO SNBe6hVpV2xj1NqpWwkmdbAS9kJac1KGtZQbfI/DFVEzUsQVOh6OQu7g+tnYoZzaEmFD 5l0MpZZct5ODOvpSe46BGkM++XbTufr0TqXN41crD4hPih3J2bNZUAcovlGKRz4ahqfK 0v/g== X-Gm-Message-State: AOAM531BDkhP4r0WKA5YqBhvv2H1AsOF7AqySy5peBsJqUd3ZDbxH5ys /wqULgiw84s5sU6Gj5wVjN2w+VTNWJym/Q== X-Received: by 2002:a02:860d:: with SMTP id e13mr10974218jai.12.1630120702695; Fri, 27 Aug 2021 20:18:22 -0700 (PDT) Received: from [192.168.1.116] ([66.219.217.159]) by smtp.gmail.com with ESMTPSA id a17sm4527227ios.36.2021.08.27.20.18.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Aug 2021 20:18:22 -0700 (PDT) Subject: Re: [PATCH] drivers/cdrom: improved ioctl for media change detection To: Lukas Prediger Cc: linux-kernel@vger.kernel.org References: <20210805194417.12439-1-lumip@lumip.de> <6d6c533d-465e-33ee-5801-cb7ea84924a8@kernel.dk> From: Jens Axboe Message-ID: <5f3b7d8b-9e97-094b-efd1-cad6cab793b6@kernel.dk> Date: Fri, 27 Aug 2021 21:18:16 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/27/21 11:30 AM, Lukas Prediger wrote: >>> @@ -295,6 +297,19 @@ struct cdrom_generic_command >>> }; >>> }; >>> >>> +/* This struct is used by CDROM_TIMED_MEDIA_CHANGE */ >>> +struct cdrom_timed_media_change_info >>> +{ >>> + __u64 last_media_change; /* Timestamp of the last detected media >>> + * change. May be set by caller, updated >>> + * upon successful return of ioctl. >>> + */ >>> + __u8 has_changed; /* Set to 1 by ioctl if last detected media >>> + * change was more recent than >>> + * last_media_change set by caller. >>> + */ >>> +}; >>> >> The struct layout should be modified such that there are no holes or >> padding in it. Probably just make the has_changed a flags thing, and >> make it u64 as well. Then you can define bit 0 to be HAS_CHANGED, and >> that leaves you room to add more flags in the future. Though the latter >> probably isn't much of a concern here, but... > > 1. jiffies_to_msecs returns unsigned int. Should I reflect that in the > struct (i.e., make the last_media_change and has_changed fields also > of type unsigned int or should I keep them at a fixed bit width? You can make it an u32. Always use explicitly sized types for user API structures. > 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. -- Jens Axboe