Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1127434rwi; Mon, 31 Oct 2022 11:42:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/Z3cMuDYEU3NjmafR5uhxWQbXepiJEhv1IWmlp/kFWyDBWNH3GM3eoG8n5tFc9/a2jIsG X-Received: by 2002:a05:6a00:a94:b0:56d:5c36:7eb8 with SMTP id b20-20020a056a000a9400b0056d5c367eb8mr8280011pfl.38.1667241747813; Mon, 31 Oct 2022 11:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667241747; cv=none; d=google.com; s=arc-20160816; b=ovQUVJaOrVTbXZ7cZlKAaT2U3JQND1JZaOOgUUuE7Kb/txIXDfbPyK8YscucbkbTnw oNr3ewIlgjcoPeN5jd+Mc72aKxwYsgDokStclXMubECBuyEbd/sZGhWBatlY8EK0poyl Lb3yb07t3b/vHuRe8dFxniBpHw0F+jH8BM62U+eyiIqgv58DNCLJARXHb6GZCY/pQ43G 8Oyu11+QmIaAcOyJ2I4fmcRq/YzjkKVO+pEeWJseLfbe5yr/nIIwK2pDIeFTcNf14Xmo xW974Hj/7FoEV3bQTYqQ5e3cMEAHGVr04QIGF9AGbXp43jtQAsx4PULIqNqxRWJTE1sO qZhw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=Han0v1EhipVx7nXZczOxjKPxO/ttPTla8BXRUI4e1t0=; b=waIMG618lrr+XiYS0roNvfbkEgbqifMRvXKeVJ5tyNaZlQxXdRu7Ot+9ZO4H2kied4 G69lHkeqWaAXE60nHacuqOxglctlW1hMWFtJODUSxLL95PuB66Amvay+sRnNwU1QF+ad IU5t3AeoOUHx/cO2BdhA0QV789Gl3CVX/0tqUroN/RygRm0+KeTZbbnKuac6iZRIKi0I HxU7O5t5Q/rGL1415FXCNIjvlPxpssjBrbcu2/ul4zkGRi4LsaS9+oUEEX+SlqjizNpP YQS1fDc7W6GnCv4jrGgZngXPqrngo/I+xD45uFbxLGdpxJcw5FgICJuQPAHAARW/C+Y3 PIOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZIGCw/I8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j16-20020a170902da9000b00179f8a3f838si11273785plx.593.2022.10.31.11.42.14; Mon, 31 Oct 2022 11:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZIGCw/I8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbiJaSTS (ORCPT + 99 others); Mon, 31 Oct 2022 14:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiJaSTR (ORCPT ); Mon, 31 Oct 2022 14:19:17 -0400 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4186F1260C; Mon, 31 Oct 2022 11:19:16 -0700 (PDT) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-13bd19c3b68so14319689fac.7; Mon, 31 Oct 2022 11:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=Han0v1EhipVx7nXZczOxjKPxO/ttPTla8BXRUI4e1t0=; b=ZIGCw/I8CRv8qnxHdy2zHqoXF4NhUV92icLrcjFKpOx8SBhmbg+BMqkFQ/BluQ1hnd EAemG5Tu7kux/ZPsZMORRotT893ZYH/10qoWz/56otSiQFW9NGEXZdLtVAacJkWtoMQ9 eJv6J37p/1cxgeoK2j+nmOzfuPv4se9YsSyMDYXYq2xaSq7VhS97r4k3U9FN1clPI53v TbdBxI0BuKT/hC7559pb6zYhaLK38kWZxiJJUHBSscyrq5STRZ1VK313T/sRtd9SBVSa 8qBraYTwhTrkI1WqJspllK2pIlEynjn7zhHrPTyus4LtXb+Qh0P3IFkhNo1sOs32ccHq n4jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Han0v1EhipVx7nXZczOxjKPxO/ttPTla8BXRUI4e1t0=; b=DKITw2xTz0rrw9PoRmd4d50zO9TLo9lvBcHl90T3Aw7TNTQuX8EWpvwCPfDp/vpWf4 TOFVLjBH4SpTYKdQGJiW61+F1UL1EL4idCRPEEE+QaV9yARQDHkm6iKEuevVkjfxZxwX PwuuzPieIzeys918A8S5DL3jRZoxzvEnWfRc/BmnWJFE1wTwS4YDp0DPAwWtrUmdCw8J 78bLd+eFCIdw8/F5bfEfMJkUt33rbzWm18/CrERk6a4ZHstIBEKb+FU2fcQ+UYE3hy0L ZaC1oXmkKmRg/vtHF1yv027tSTmDn5/12XQ1fDxQT5EuXxEmCV3bA6p723ZO1d3bqYj7 ZRSA== X-Gm-Message-State: ACrzQf2SHOVi6u2iZfXXoZpV7i38tm2d2Mm4xoENrA6bf6ZfhwA7U/Tc AN2SIppBlf9Zd25QAm35GY8egPAI0Rc= X-Received: by 2002:a05:6870:e88a:b0:13b:6e13:a9a5 with SMTP id q10-20020a056870e88a00b0013b6e13a9a5mr8230404oan.264.1667240355394; Mon, 31 Oct 2022 11:19:15 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id w67-20020acadf46000000b0035770fc6ca9sm2551579oig.16.2022.10.31.11.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 11:19:14 -0700 (PDT) Sender: Guenter Roeck Date: Mon, 31 Oct 2022 11:19:13 -0700 From: Guenter Roeck To: Alexandre Belloni Cc: Alessandro Zummo , Benson Leung , linux-rtc@vger.kernel.org, chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, Brian Norris Subject: Re: [PATCH] rtc: cros-ec: Limit RTC alarm range if needed Message-ID: <20221031181913.GA3841664@roeck-us.net> References: <20221029005400.2712577-1-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 31, 2022 at 06:10:53PM +0100, Alexandre Belloni wrote: > Hello, > > On 28/10/2022 17:54:00-0700, Guenter Roeck wrote: > > RTC chips on some older Chromebooks can only handle alarms less than 24 > > hours in the future. Attempts to set an alarm beyond that range fails. > > The most severe impact of this limitation is that suspend requests fail > > if alarmtimer_suspend() tries to set an alarm for more than 24 hours > > in the future. > > > > Try to set the real-time alarm to just below 24 hours if setting it to > > a larger value fails to work around the problem. While not perfect, it > > is better than just failing the call. A similar workaround is already > > implemented in the rtc-tps6586x driver. > > I'm not super convinced this is actually better than failing the call > because your are implementing policy in the driver which is bad from a > user point of view. It would be way better to return -ERANGE and let > userspace select a better alarm time. The failing call is from alarmtimer_suspend() which is called during suspend. It is not from userspace, and userspace has no chance to intervene. It is also not just one userspace application which could request a large timeout, it is a variety of userspace applications, and not all of them are written by Google. Some are Android applications. I don't see how it would be realistic to expect all such applications to fix their code (if that is even possible - there might be an application which called sleep(100000) or something equivalent, which works just fine as long as the system is not suspended. > Do you have to know in advance which are the "older" chromebooks that > are affected? Not sure I understand the question. Technically we know, but the cros_ec rtc driver doesn't know because the EC doesn't have an API to report the maximum timeout to the Linux driver. Even if that existed, it would not help because the rtc API only supports absolute maximum clock values, not clock offsets relative to the current time. So ultimately there is no means for an RTC driver to tell the maximum possible alarm timer offset to the RTC subsystem, and there is no means for a user such as alarmtimer_suspend() to obtain the maximum time offset. Does that answer your question ? On a side note, I tried an alternate implementation by adding a retry into alarmtimer_suspend(), where it would request a smaller timeout if the requested timeout failed. I did not pursue/submit this since it seemed hacky. To solve that problem, I'd rather discuss extending the RTC API to provide a maximum offset to its users. Such a solution would probably be desirable, but that it more longer term and would not solve the immediate problem. If you see a better solution, please let me know. Again, the problem is that alarmtimer_suspend() fails because the requested timeout is too large. Thanks, Guenter > > > > > Drop error messages in cros_ec_rtc_get() and cros_ec_rtc_set() since the > > calling code also logs an error and to avoid spurious error messages if > > setting the alarm ultimately succeeds. > > > > Cc: Brian Norris > > Signed-off-by: Guenter Roeck > > --- > > drivers/rtc/rtc-cros-ec.c | 35 ++++++++++++++++++++--------------- > > 1 file changed, 20 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c > > index 887f5193e253..a3ec066d8066 100644 > > --- a/drivers/rtc/rtc-cros-ec.c > > +++ b/drivers/rtc/rtc-cros-ec.c > > @@ -14,6 +14,8 @@ > > > > #define DRV_NAME "cros-ec-rtc" > > > > +#define SECS_PER_DAY (24 * 60 * 60) > > + > > /** > > * struct cros_ec_rtc - Driver data for EC RTC > > * > > @@ -43,13 +45,8 @@ static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command, > > msg.msg.insize = sizeof(msg.data); > > > > ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg); > > - if (ret < 0) { > > - dev_err(cros_ec->dev, > > - "error getting %s from EC: %d\n", > > - command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm", > > - ret); > > + if (ret < 0) > > return ret; > > - } > > > > *response = msg.data.time; > > > > @@ -59,7 +56,7 @@ static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command, > > static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command, > > u32 param) > > { > > - int ret = 0; > > + int ret; > > struct { > > struct cros_ec_command msg; > > struct ec_response_rtc data; > > @@ -71,13 +68,8 @@ static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command, > > msg.data.time = param; > > > > ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg); > > - if (ret < 0) { > > - dev_err(cros_ec->dev, "error setting %s on EC: %d\n", > > - command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm", > > - ret); > > + if (ret < 0) > > return ret; > > - } > > - > > return 0; > > } > > > > @@ -190,8 +182,21 @@ static int cros_ec_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) > > > > ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, alarm_offset); > > if (ret < 0) { > > - dev_err(dev, "error setting alarm: %d\n", ret); > > - return ret; > > + if (ret == -EINVAL && alarm_offset >= SECS_PER_DAY) { > > + /* > > + * RTC chips on some older Chromebooks can only handle > > + * alarms up to 24h in the future. Try to set an alarm > > + * below that limit to avoid suspend failures. > > + */ > > + ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, > > + SECS_PER_DAY - 1); > > + } > > + > > + if (ret < 0) { > > + dev_err(dev, "error setting alarm in %u seconds: %d\n", > > + alarm_offset, ret); > > + return ret; > > + } > > } > > > > return 0; > > -- > > 2.36.2 > > > > -- > Alexandre Belloni, co-owner and COO, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com