Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3966165pxf; Mon, 29 Mar 2021 17:05:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz2yACVrqpyUDafqFC2CVt829jFIDZO9IrXkiS58UIVleV4MiOLfBEUXElgYQuexWTBpD+ X-Received: by 2002:a05:6402:31b7:: with SMTP id dj23mr31563662edb.245.1617062715386; Mon, 29 Mar 2021 17:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617062715; cv=none; d=google.com; s=arc-20160816; b=Yjz7W25UW1s5AcJLs+sDpAgHtEB9Gh6uYNR52IMw9PSJZ0RM4EiaJmIpnG0ozggqjD K5vbtk8zTKn6htSHCxP429PPe5cv0E8GZk4G5hFwGay8LGrsNddhnxDHqnAlkdeCiJJJ RI95dF700FRlvZ468wTEmAiu73vkF2jx5WGkzcl87QtGkBkv/0YY4x/HL71IDWXYp9nH FWR/Q1NLCCP0uyDzZ2m54lN8P1/sRFiGsiGV3yNZ9M/60xGRGJvvTcySRewmUHT9lLsy HMfaATp4P2sCJAeHFbZl7ta31Tttaw7U+XbYPj9AFofA1GOh1TY/BM0sFuuxwx7ZK3KK QhDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xp1+sQXFez1cFDhSwo2jFpia96+RSw7zLhlVR16UHxg=; b=0y3ATmA6nJ/OgAbNLoXMFhZ7HKzkmWNgtnD1OfctpDJVFLfu/d40qlAxG4Z8Wvwlrn B+m4q9TpNYsMOGc0STHsSyl/2ut3+AWRinoX+oteJprIrt+j+UHpmX1PYMORw1KCTANR kHKMo/FK9AX8Z5HZSEfqhpClY0W6axDZSIMoq3rq4Icvz7lObqQ1/j2xLPnooO3Cv0fC v9kVOIhRSnpSxNrtsDbZtAJ6ytybsXt8IDXYpYscrAkiNi9thQ11d+qRJXLfxbAiYLSD 6+6ZsSEDJ15OW8zIMJ9Fu56j4PZAxrrUNnVv9Su8wjyOQqomTGIar5/sg5gfNa63G2Ed zdlA== 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 f1si13550049ejz.585.2021.03.29.17.04.50; Mon, 29 Mar 2021 17:05:15 -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 S230361AbhC3ACa convert rfc822-to-8bit (ORCPT + 99 others); Mon, 29 Mar 2021 20:02:30 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:38497 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbhC3ACH (ORCPT ); Mon, 29 Mar 2021 20:02:07 -0400 Received: from localhost (lfbn-lyo-1-1676-55.w90-65.abo.wanadoo.fr [90.65.108.55]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id EBE6F100002; Tue, 30 Mar 2021 00:02:05 +0000 (UTC) Date: Tue, 30 Mar 2021 02:02:05 +0200 From: Alexandre Belloni To: Lukasz Stelmach Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, =?utf-8?Q?Bart=C5=82omiej_=C5=BBolnierkiewicz?= , Marek Szyprowski , linux-kernel@vger.kernel.org Subject: Re: [PATCH] rtc: ds1307: set uie_unsupported if no interrupt is available Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/03/2021 19:04:14+0100, Lukasz Stelmach wrote: > OK, you are right. The problem seems to be elsewhere. > > How about this scnario? We call rtc_update_irq_enable(). We read rtc > with __rtc_read_time() and calculate the alarm time. We get through > rtc_timer_enqueue() and down to __rtc_set_alarm(). We loose the race > condition (I can do it, I've got really slow connection to DS3231) and > we return -ETIME from __rtc_set_alarm() > > if (scheduled <= now) > return -ETIME; > > and 0 from rtc_timer_enqueue() and the very same zero from > rtc_update_irq_enable(). The caller of ioctl() thinks they can expect > interrupts when, in fact, they won't receive any. > > The really weird stuff happens in rtc_timer_do_work(). For the timer to > be dequeued __rtc_set_alarm() needs to return EINVAL three times in a > row. In my setup this doesn't happen and the code keeps running loops > around "reporogram" and "again" labels. > > With my patch we never risk the above race condition between > __rtc_read_time() in rtc_update_irq_enable() and the one in > __rtc_set_alarm(), because we know rtc doesn't support alarms before we > start the race. In fact there is another race between __rtc_read_time() > and actually setting the alarm in the chip. > > IMHO the solution is to introduce RTC_HAS_ALARM flag for struct > rtc_device and check it at the very beginning of __rtc_set_alarm() the > same way it is being done in ds1337_set_alarm(). What are your thoughts? > I did introduce RTC_FEATURE_ALARM for that in v5.12. I'm sending patches that are not well tested but should solve your issue. -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com