Received: by 10.223.185.116 with SMTP id b49csp5536249wrg; Tue, 27 Feb 2018 15:22:12 -0800 (PST) X-Google-Smtp-Source: AH8x2275BG3CQ3EleHHNtyoegZqC3uE10x6Jl2WxIjzbxubU5vm94PEj7yjlealbSTKSjNgOXdEl X-Received: by 2002:a17:902:8302:: with SMTP id bd2-v6mr15311830plb.295.1519773732120; Tue, 27 Feb 2018 15:22:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519773732; cv=none; d=google.com; s=arc-20160816; b=gd2HP+dHkoiKogK3ikPDnpqlV/TAQvXBUVi0Gtt34ZT6g3sV7sTjKE2UOPGSPfrrz3 hhEGkt5ccwyfgPoIojo1dN3G+hDWNWls8XJD63LNGICfYmborGqi+IXFHXiDjAwI1zTr ZOQF8uT3mOPrrFX6egs90O8DIJ8+sVzIlItneK4mVYw6O7gj7eAX6bs24uyUtvzkGDp9 oAT0+JYn7gBEAtP52IHij22zPSeDWLhrqwIFDWFwVjBowxLyCGVSXbslnknQFcZIye6I cCyaVJ75w36rONGDRBNPgD7Di+a6l3j6N+qk1d+xc6NhwIM6M9ffNaggrE9HD7L+v1Zp tu9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=mtAsFo0sZfdeeeFgQpkFjrxjb6y1B/6ZvVKwvjmmwPw=; b=tmi22QHtSbMsDf+sEyE5ttluS6m8tz/guHN1t2+cHk4gHjNhWcocB4adX69pqYttJZ +Z5OuYN1rnnwOaBTr2PHRLeyIUfwOt0xHGQFmiYimR1k97Rg0+UKgHLskr8bz2wf9Ixv SooncaXxJhaY8vbvdTHvFRS6ehjFL1BbsPksciCyymjvQK+e1miGKlIMwzmr9LVB8TA3 PzHU+9qr92D88uU8uDJ+BIWcD3qJVjlfznhVfeUKIZ7KekugLtxYpuy0CY82HfEOFh0p kWIviijbNgQemK6fQjilErwBsII+vydlvm83c0tiG/JlynCICwqi0Emvptbqo/DZCCQj o+iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=mSBWNSZ2; dkim=fail header.i=@chromium.org header.s=google header.b=oYEORbt2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3si162267pgo.349.2018.02.27.15.21.57; Tue, 27 Feb 2018 15:22:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=mSBWNSZ2; dkim=fail header.i=@chromium.org header.s=google header.b=oYEORbt2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752105AbeB0XUz (ORCPT + 99 others); Tue, 27 Feb 2018 18:20:55 -0500 Received: from mail-vk0-f67.google.com ([209.85.213.67]:41985 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982AbeB0XUx (ORCPT ); Tue, 27 Feb 2018 18:20:53 -0500 Received: by mail-vk0-f67.google.com with SMTP id y127so357650vky.9 for ; Tue, 27 Feb 2018 15:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=mtAsFo0sZfdeeeFgQpkFjrxjb6y1B/6ZvVKwvjmmwPw=; b=mSBWNSZ23RDTMh85e86m0izCgiityuFp6Jtbg+EJqgBXNJvGKcr0Lcw617CC9/nxLl WElNFt3TOjsD6PSVMFabx3OxFbSWL7tVQ7KgNlI2ij4I922aIJMcD3cXFttP8QBXtC1q gEIdeztwUSD29M6X/01vahX2BlzKxiSE7CIrGESnnUenKwthO2mFyvXyq+vc6WlKU8iy VKi1kmhq0pjaxE8raFHQ7TqWg8G9u/5FmUCaGZ8gkgMn9V34hhPjpPnj6euDxau7zXI3 qf+OcBKljEooFnHzNCFjFQZiE3N8tLttftEAORYfzq3q/JjAdPhxU47o7Dlnx5kXWBOm FNWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=mtAsFo0sZfdeeeFgQpkFjrxjb6y1B/6ZvVKwvjmmwPw=; b=oYEORbt2ChL5pouN+ozjuDJZdAGjdw4TPrJ7h1+8+mZ4ODwoo5u7Gn9cZYUx1P8aX8 QfT5ZJOQ2rAK3o31HhDAvQM/Y3Ki7JJzLSSZBolsyNFtxdm717vMHBrVOYmJTbtAqIBt WThrvJ56FQrpebHSRn/FvzCBkY4NxvaLhCtDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=mtAsFo0sZfdeeeFgQpkFjrxjb6y1B/6ZvVKwvjmmwPw=; b=VZNbJ8iMJyPqnpAPZXQXN4Jh59OUfOUOh5JeX4m8XcgZd9BMJN5mQG+G0mywdZhn91 MGpZx1/HRTB0duXXrQJSqk2JTFIHNnOG4/4jXBLSs0nMUaahw1EI/IZzTpE0Y08L+apT oufxrgv8pg9OWXNzZXJThJsNnp5s2052JNsW5QoLyZC+hYHXGNINw7MzWVRZwLiaS8zM yS5+MJQJN17h6QS8CmSr6+3nqilRINBSEmRLmw1qXjJlPno9u/Q922dRk9OeUWBDF4dH bGJ9gt3nopxX6VwsL8wIysUj+lgs/0Ti/XoZ1nOIHIv9InDGvZQeNesb5/nCv6dpQh9h SFAg== X-Gm-Message-State: APf1xPCEZYHEYGDFEGZKZasnmFsbMIe3OTNqWGsB1nlA534DBrbwvjQ7 W/67DaUjpYl9p+Jnky6/0crHuNkR5/blvhK3kRnSBw== X-Received: by 10.31.230.132 with SMTP id d126mr11856871vkh.123.1519773652665; Tue, 27 Feb 2018 15:20:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.242.140 with HTTP; Tue, 27 Feb 2018 15:20:51 -0800 (PST) In-Reply-To: <20180224024613.24078-6-mcgrof@kernel.org> References: <20180224024613.24078-1-mcgrof@kernel.org> <20180224024613.24078-6-mcgrof@kernel.org> From: Kees Cook Date: Tue, 27 Feb 2018 15:20:51 -0800 X-Google-Sender-Auth: 0v6JhHxvLQn495FZb4Vzu1jAiS4 Message-ID: Subject: Re: [PATCH v2 05/11] firmware: use helpers for setting up a temporary cache timeout To: "Luis R. Rodriguez" Cc: Greg KH , Andrew Morton , Shuah Khan , Martin Fuzzey , Mimi Zohar , David Howells , pali.rohar@gmail.com, Takashi Iwai , arend.vanspriel@broadcom.com, =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , nbroeking@me.com, Vikram Mulukutla , stephen.boyd@linaro.org, Mark Brown , Dmitry Torokhov , David Woodhouse , Linus Torvalds , Abhay_Salunke@dell.com, bjorn.andersson@linaro.org, jewalt@lgsinnovations.com, LKML , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 23, 2018 at 6:46 PM, Luis R. Rodriguez wrote: > We only use the timeout for the firmware fallback mechanism > except for trying to set the timeout during the cache setup > for resume/suspend. For those cases, setting the timeout should > be a no-op, so just reflect this in code by adding helpers for it. > > This change introduces no functional changes. > > Signed-off-by: Luis R. Rodriguez Acked-by: Kees Cook -Kees > --- > drivers/base/firmware_loader.c | 49 ++++++++++++++++++++++++++---------------- > 1 file changed, 30 insertions(+), 19 deletions(-) > > diff --git a/drivers/base/firmware_loader.c b/drivers/base/firmware_loader.c > index 59dba794ce1a..2d819875348d 100644 > --- a/drivers/base/firmware_loader.c > +++ b/drivers/base/firmware_loader.c > @@ -191,13 +191,6 @@ static inline bool fw_is_builtin_firmware(const struct firmware *fw) > } > #endif > > -static int loading_timeout = 60; /* In seconds */ > - > -static inline long firmware_loading_timeout(void) > -{ > - return loading_timeout > 0 ? loading_timeout * HZ : MAX_JIFFY_OFFSET; > -} > - > static void fw_state_init(struct fw_priv *fw_priv) > { > struct fw_state *fw_st = &fw_priv->fw_st; > @@ -282,6 +275,32 @@ static const struct firmware_fallback_config fw_fallback_config = { > .force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK), > }; > > +static int old_timeout; > +static int loading_timeout = 60; /* In seconds */ > + > +static inline long firmware_loading_timeout(void) > +{ > + return loading_timeout > 0 ? loading_timeout * HZ : MAX_JIFFY_OFFSET; > +} > + > +/* > + * use small loading timeout for caching devices' firmware because all these > + * firmware images have been loaded successfully at lease once, also system is > + * ready for completing firmware loading now. The maximum size of firmware in > + * current distributions is about 2M bytes, so 10 secs should be enough. > + */ > +static void fw_fallback_set_cache_timeout(void) > +{ > + old_timeout = loading_timeout; > + loading_timeout = 10; > +} > + > +/* Restores the timeout to the value last configured during normal operation */ > +static void fw_fallback_set_default_timeout(void) > +{ > + loading_timeout = old_timeout; > +} > + > static inline bool fw_sysfs_done(struct fw_priv *fw_priv) > { > return __fw_state_check(fw_priv, FW_STATUS_DONE); > @@ -1206,6 +1225,8 @@ static int fw_sysfs_fallback(struct firmware *fw, const char *name, > } > > static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { } > +static inline void fw_fallback_set_cache_timeout(void) { } > +static inline void fw_fallback_set_default_timeout(void) { } > > static inline int register_sysfs_loader(void) > { > @@ -1752,7 +1773,6 @@ static void __device_uncache_fw_images(void) > static void device_cache_fw_images(void) > { > struct firmware_cache *fwc = &fw_cache; > - int old_timeout; > DEFINE_WAIT(wait); > > pr_debug("%s\n", __func__); > @@ -1760,16 +1780,7 @@ static void device_cache_fw_images(void) > /* cancel uncache work */ > cancel_delayed_work_sync(&fwc->work); > > - /* > - * use small loading timeout for caching devices' firmware > - * because all these firmware images have been loaded > - * successfully at lease once, also system is ready for > - * completing firmware loading now. The maximum size of > - * firmware in current distributions is about 2M bytes, > - * so 10 secs should be enough. > - */ > - old_timeout = loading_timeout; > - loading_timeout = 10; > + fw_fallback_set_cache_timeout(); > > mutex_lock(&fw_lock); > fwc->state = FW_LOADER_START_CACHE; > @@ -1779,7 +1790,7 @@ static void device_cache_fw_images(void) > /* wait for completion of caching firmware for all devices */ > async_synchronize_full_domain(&fw_cache_domain); > > - loading_timeout = old_timeout; > + fw_fallback_set_default_timeout(); > } > > /** > -- > 2.16.2 > -- Kees Cook Pixel Security