Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2161956imm; Thu, 19 Jul 2018 14:26:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf8kleHGMF9GE1irVQMNsNahkobx2Z87RV14HB4kat5PA6PdVV4VB02CPr5IAhw3K/LD+8H X-Received: by 2002:a65:4c41:: with SMTP id l1-v6mr11735828pgr.310.1532035588113; Thu, 19 Jul 2018 14:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532035588; cv=none; d=google.com; s=arc-20160816; b=HaT8B0Rw9USwlpNp8I+H/Bi0d+dz6x4HXe285Q5OpXkkN+ts7pDXhRYd55UNs5tCKS mTza8UIUmLQRwvHr7P5aw9GI6oMdH5mW4NKs5dCaOBKr8+vqBv+XBZr+vN15Nr/S5cCr JtnvfUcNOVeGWRcCgCurvX1eZU30w1gUYm2r3aeHC7RcPd6oS+c9u10KdR9kmuc1k+ZL o7kiLwxraT4+pWrwSvN0aS3e9jUJpVXlTIp1shSs4sYssBV/uCglqYlRCno96jH27R5i f1cJnwYgYvFgegv62ZvX3akzAFqx7J1LDy9hnY7zx03A3HEPgczMyBY1mOWSrynrZqXL emnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=ZaFvOJsyryc9BibNgPbIFkb/+eOkkLYPKj4pqFywpdg=; b=jFkGAxqXLUupFkLgIr3RyVZdIYdIreinjdUOt9BZFmL6qfeybqnQxlpJhvctzai1ej Bj6XYKXv0fkwm3uIK036VGXG9iuUQHE+dPskkwXgkp9+i2YdwsQ1j28O0F8+VAItJfvd 6HawCxgeEFOLiXE0aChVrnl5+wHEtkw8ERFudrx0CYALiBoqiYnuAGw7ZAZ7+FUbnKnb 4GTScs8O0NB9dkyvY/mBwKTTxh8zMS10Qpu3mv7H8s9sAgw7UoagAR1sNP1ORFUvRcm1 n/uDH568ITxX6LrgVQua/O+idzp8g7sLqqsE3Jg5Vjw1RH+xdkDeJCp29U61/7wsZjOx 6AEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=JNWv0M3V; dkim=pass header.i=@codeaurora.org header.s=default header.b=JNWv0M3V; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11-v6si174199plb.100.2018.07.19.14.26.13; Thu, 19 Jul 2018 14:26:28 -0700 (PDT) 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=pass header.i=@codeaurora.org header.s=default header.b=JNWv0M3V; dkim=pass header.i=@codeaurora.org header.s=default header.b=JNWv0M3V; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730889AbeGSWK0 (ORCPT + 99 others); Thu, 19 Jul 2018 18:10:26 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:57816 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727609AbeGSWK0 (ORCPT ); Thu, 19 Jul 2018 18:10:26 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CB8D860791; Thu, 19 Jul 2018 21:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1532035528; bh=TG/ONVQvV8iZq/Tli8p/7DC6ZVQR9sreW0mUflm+k5A=; h=From:To:Cc:Subject:Date:From; b=JNWv0M3VijwzNXW6ewme2G7c8mi6bw8AuJjk1NKajbZImj1npzpFz9jnFZhCl8hf4 B1A6IUvdRYAVee65XfJd/BRFqxaU4HB8F469FG3tMLAmyoP6+/6w7bnP5ot55ATybn JF0vpUDEfnx0eeDH0Lb6DHTn+x3kpL47v9sDvGXo= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from rishabhb-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rishabhb@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1F2A4602B3; Thu, 19 Jul 2018 21:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1532035528; bh=TG/ONVQvV8iZq/Tli8p/7DC6ZVQR9sreW0mUflm+k5A=; h=From:To:Cc:Subject:Date:From; b=JNWv0M3VijwzNXW6ewme2G7c8mi6bw8AuJjk1NKajbZImj1npzpFz9jnFZhCl8hf4 B1A6IUvdRYAVee65XfJd/BRFqxaU4HB8F469FG3tMLAmyoP6+/6w7bnP5ot55ATybn JF0vpUDEfnx0eeDH0Lb6DHTn+x3kpL47v9sDvGXo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1F2A4602B3 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=rishabhb@codeaurora.org From: Rishabh Bhatnagar To: gregkh@linuxfoundation.org, mcgrof@kernel.org Cc: linux-kernel@vger.kernel.org, ckadabi@codeaurora.org, tsoni@codeaurora.org, Rishabh Bhatnagar , Vikram Mulukutla Subject: [PATCH] firmware: Avoid caching firmware when FW_OPT_NOCACHE is set Date: Thu, 19 Jul 2018 14:25:21 -0700 Message-Id: <1532035521-7917-1-git-send-email-rishabhb@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When calling request_firmware_into_buf(), we pass the FW_OPT_NOCACHE flag with the intent of skipping the caching mechanism of the firmware loader. Unfortunately, that doesn't work, because alloc_lookup_fw_priv() isn't told to _not_ add the struct firmware_buf to the firmware cache (fwc) list. So when we call request_firmware_into_buf() the second time, we find the buffer in the cache and return it immediately without reloading. This may break users of request_firmware_into_buf that are expecting a fresh copy of the firmware to be reloaded into memory. The existing copy may either be modified by drivers, remote processors or even freed. Fix fw_lookup_and_allocate_buf to not add to the fwc list if FW_OPT_NOCACHE is set, and also don't do the lookup in the list. Fixes: 0e742e9271 ("firmware: provide infrastructure to make fw caching optional") Signed-off-by: Vikram Mulukutla Signed-off-by: Rishabh Bhatnagar --- drivers/base/firmware_loader/main.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index 2e0c37a..db9038c0 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -210,21 +210,24 @@ static struct fw_priv *__lookup_fw_priv(const char *fw_name) static int alloc_lookup_fw_priv(const char *fw_name, struct firmware_cache *fwc, struct fw_priv **fw_priv, void *dbuf, - size_t size) + size_t size, enum fw_opt opt_flags) { struct fw_priv *tmp; spin_lock(&fwc->lock); - tmp = __lookup_fw_priv(fw_name); - if (tmp) { - kref_get(&tmp->ref); - spin_unlock(&fwc->lock); - *fw_priv = tmp; - pr_debug("batched request - sharing the same struct fw_priv and lookup for multiple requests\n"); - return 1; + if (!(opt_flags & FW_OPT_NOCACHE)) { + tmp = __lookup_fw_priv(fw_name); + if (tmp) { + kref_get(&tmp->ref); + spin_unlock(&fwc->lock); + *fw_priv = tmp; + pr_debug("batched request - sharing the same struct fw_priv and lookup for multiple requests\n"); + return 1; + } } + tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size); - if (tmp) + if (tmp && !(opt_flags & FW_OPT_NOCACHE)) list_add(&tmp->list, &fwc->head); spin_unlock(&fwc->lock); @@ -500,7 +503,8 @@ int assign_fw(struct firmware *fw, struct device *device, */ static int _request_firmware_prepare(struct firmware **firmware_p, const char *name, - struct device *device, void *dbuf, size_t size) + struct device *device, void *dbuf, size_t size, + enum fw_opt opt_flags) { struct firmware *firmware; struct fw_priv *fw_priv; @@ -518,7 +522,8 @@ int assign_fw(struct firmware *fw, struct device *device, return 0; /* assigned */ } - ret = alloc_lookup_fw_priv(name, &fw_cache, &fw_priv, dbuf, size); + ret = alloc_lookup_fw_priv(name, &fw_cache, &fw_priv, dbuf, size, + opt_flags); /* * bind with 'priv' now to avoid warning in failure path @@ -578,7 +583,8 @@ static void fw_abort_batch_reqs(struct firmware *fw) goto out; } - ret = _request_firmware_prepare(&fw, name, device, buf, size); + ret = _request_firmware_prepare(&fw, name, device, buf, size, + opt_flags); if (ret <= 0) /* error or already assigned */ goto out; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project