Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3326850ybh; Mon, 5 Aug 2019 16:33:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyiD00mnRRTFDx6PsYJNw9MHwTLUXfao42duUeemsFlfDKjb0NsuapKb1285tZUoFXqWCL X-Received: by 2002:a17:902:3181:: with SMTP id x1mr230458plb.135.1565047993822; Mon, 05 Aug 2019 16:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565047993; cv=none; d=google.com; s=arc-20160816; b=TUFSCDrX4h/A3x3GgBMhECduoD9y/IRAGi9KmH6HNDaPeHtDoYiSEXvW8fr7p7eZt1 n1Zckq5o8QQXSFhx4ChNtyxxAgeRHCyLJuhaOdh4PKP5buYvaexkLL2eocyPPvXTSYuj 60vMWES6HFvILabSC9MhuYksiIM3gTgQS8K8KMRQR5oIBLoTwRC+CczYEZ/sTOvzV712 lk8et/1jA10zC1Kz/tghUtYG/CInRKwZrq3XuOjdh6CaRW3Xg8359fYuzdpasii6lFI5 6BIbW9Z69eKoxN6bBiLI79za4ABfX2SF+8w4dCo5Z7i4A8Mt/LXKaZd5zYjyQ4pi6dab 54tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pkJZsBEn/CiiuZNhsnLr0nSUJKwxAQY9KFBx3uOaLzo=; b=Q8cBsKOiytodj4QSTU3DOonuC53OsdKkRCx1kG2wA2jj3vhLO5syc+2Gu/+WmOYwzU BpqIXIIi8W6GWC3DxX8KCRzjRPf0gw9aokVrSmBHteEe/cwkqo1ofjfHX2xStmy3Ksd9 e1lvM2mVgun5QW+4J+loZIt+aVvmTUXYPGPIn0t3oT93ghKUzxDeMF8iWRayZcdyFaG1 VTju3MUBJANYxy1MYCKZ6aMRpKTiih9CVjBpxGw32nl6BGCPa18RAEpmMQ0Op9MI2hWA fw0R05DqL314NbdqciNX+1HemNBwr3HsI8SlLGNspjzYbw/mvjnCp4xI4Qjoik1a4ekv a1wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BVla6KTE; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (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 c64si13285622pje.9.2019.08.05.16.32.51; Mon, 05 Aug 2019 16:33:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@chromium.org header.s=google header.b=BVla6KTE; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730733AbfHEXcn (ORCPT + 99 others); Mon, 5 Aug 2019 19:32:43 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40986 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728870AbfHEXcn (ORCPT ); Mon, 5 Aug 2019 19:32:43 -0400 Received: by mail-pf1-f194.google.com with SMTP id m30so40429230pff.8 for ; Mon, 05 Aug 2019 16:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pkJZsBEn/CiiuZNhsnLr0nSUJKwxAQY9KFBx3uOaLzo=; b=BVla6KTEpKUsi2JPfceTSbxAKyqH5jrH4XqqkmrMT1+57w231S3ir7e9VLkaSMDJlz FEuw5OnOBz+gBdON/yvqKUU+A1gTri8F7kEHVSGNS3YH9ES9+uDhp/Q+xeNyCrGzZJjw B0RcRCta5/6rpmtTYdJuwA2qMrR0Oln/7LTRE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pkJZsBEn/CiiuZNhsnLr0nSUJKwxAQY9KFBx3uOaLzo=; b=Ytg/P7n4MdkM+NL9Q61yX3InrKoEzsIx4al2b/WZhfa2zwDr2lGImu4BxO6uVK7LPE JxIqg5zkVZMFIJSw0K755gYN6FZEJRANtvwGh7xRSVl8W46WNGALO56e1m4vBri1o/G8 3jBo8f5hIs9UrmFeH/K6NKyGiEozYgZAAM78x3Knnm9k6EO0c79mmwvuLfrLu4MBwjN7 VfA8xmnuK92twZeqAqPWElqrrU8HjpmTwwSdYcTjKu5SwhRdrG5YwSWa/R3rLjsYnJIQ tOIp5QmP753inoSM7JvlAwbSeP+uvVVqMML+N4rmvNkr00CZb8TwovImMNy2gGP1V0y+ v4ag== X-Gm-Message-State: APjAAAU+yPfbZVR2tz2VI+EYlOJFypLW3Y5+JmHn/S4a5aKWpsZslQB8 w+pSkOvaJDNowyP1pZmYUEtb9w== X-Received: by 2002:a17:90a:c588:: with SMTP id l8mr228070pjt.16.1565047962658; Mon, 05 Aug 2019 16:32:42 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id u128sm97748195pfu.48.2019.08.05.16.32.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 16:32:42 -0700 (PDT) From: Stephen Boyd To: Herbert Xu Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Andrey Pronin , Duncan Laurie , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , Guenter Roeck , Alexander Steffen Subject: [PATCH v3] hwrng: core: Freeze khwrng thread during suspend Date: Mon, 5 Aug 2019 16:32:41 -0700 Message-Id: <20190805233241.220521-1-swboyd@chromium.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The hwrng_fill() function can run while devices are suspending and resuming. If the hwrng is behind a bus such as i2c or SPI and that bus is suspended, the hwrng may hang the bus while attempting to add some randomness. It's been observed on ChromeOS devices with suspend-to-idle (s2idle) and an i2c based hwrng that this kthread may run and ask the hwrng device for randomness before the i2c bus has been resumed. Let's make this kthread freezable so that we don't try to touch the hwrng during suspend/resume. This ensures that we can't cause the hwrng backing driver to get into a bad state because the device is guaranteed to be resumed before the hwrng kthread is thawed. Cc: Andrey Pronin Cc: Duncan Laurie Cc: Jason Gunthorpe Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: Guenter Roeck Cc: Alexander Steffen Signed-off-by: Stephen Boyd --- I'm splitting this patch off of the larger series so it can go through the crypto tree. See [1] for the prevoius round. Nothing has changed in this patch since then. [1] https://lkml.kernel.org/r/20190716224518.62556-2-swboyd@chromium.org drivers/char/hw_random/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 95be7228f327..3b88af3149a7 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -421,7 +422,9 @@ static int hwrng_fillfn(void *unused) { long rc; - while (!kthread_should_stop()) { + set_freezable(); + + while (!kthread_freezable_should_stop(NULL)) { struct hwrng *rng; rng = get_current_rng(); -- Sent by a computer through tubes