From patchwork Thu Jun 14 19:36:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 138616 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2527421lji; Thu, 14 Jun 2018 12:39:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIDkbeJvbxMY839DLYNsP7rDm7fMHQ6Lz/s+QP+VvGq3ChXAtvG26HHl5gI1hJxWBwis0MK X-Received: by 2002:a63:b008:: with SMTP id h8-v6mr3434390pgf.137.1529005174461; Thu, 14 Jun 2018 12:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529005174; cv=none; d=google.com; s=arc-20160816; b=qfSHb/GojmMvp+CJlzYM2r/yahS0AikftBFYbDMsq9FZVaNmCNHLKIhrIyhm+7GWEA qxLslkxpsa5wOYbrXazGdJ/t0KYkcH/E+We+1psXis8WtKTuIDRXSAOrji5TQfUF8gHc yIQsxXPlR/bm306gpPgAJOIJutPPydQNyjGPGpE0hWibHIG6ivvImcG2t79vpIq9M6R3 eEoTE6v5+7lqCLWYK7qiGXioXtC+c3lQnOu/UyfStnNHMOu2/dLrZq/WRH3e3/FxZFr8 uxkhZeXcxckr9pTRf3Y4d8wcG2W68siZVZYUK6NLwwyioGDIDgaW9SSdHeCY1TrUnjNS 7Olg== 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 :dkim-signature:arc-authentication-results; bh=7/VwfvDOIgbM1idBc27xHY6hWSKZkVGC47yrwOMenOQ=; b=Y307XvBUUDRQfjhDC29/wkg4EsDi7kbeGXhuGsWMoTQGbYwVz3ow/rWXc/1IW2BIlx fOJn/uLx02Fk2mGdKDPsDTC7dxskH7hqnDBdoHJ1wEWd5TRURTpfzyYRCagq8P9aULsO O84MoKYzzmKDFfU6W7PMGZeq9u+YLmVumhGzo/9jA8MUJhArOjIJZhOghzbpL4rWR6m1 F0IbOzPq6atLE7xnz7NdVzu23VwBQ3oqLJqMDqjpGeTNKhM519VR07jWR3c4i2zWc5dT 0jNPPxvueOHRLyFY7uSMiha+dX5KEq4ke2S8idGwdHo+66d68+OujISTc39GOusU4tCC yxkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s6dl6BF3; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u22-v6si5806659pfg.62.2018.06.14.12.39.34; Thu, 14 Jun 2018 12:39:34 -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=@gmail.com header.s=20161025 header.b=s6dl6BF3; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755265AbeFNTjd (ORCPT + 1 other); Thu, 14 Jun 2018 15:39:33 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51005 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755234AbeFNTjc (ORCPT ); Thu, 14 Jun 2018 15:39:32 -0400 Received: by mail-wm0-f66.google.com with SMTP id e16-v6so12417418wmd.0; Thu, 14 Jun 2018 12:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7/VwfvDOIgbM1idBc27xHY6hWSKZkVGC47yrwOMenOQ=; b=s6dl6BF3vZL3wmnGb588DsRoR6Zwn4/3Xa5X4vrwGnKFsSGcPdJ2Vs3uSMvUbOUwsO xRRxIe0fszMctlVWxRb5qSWECsj5Nm8bgtZJwb47shcwrYE0fuMOI6oRdLol4hXYxWo/ 1XsxB1HYrm4vyXKq6SRcxBmx3jV36q4iv3o7Nx+ZXgtDIyBngiXzqG+IRKKUqLPzx2EG 66aUJbiw9+SsKFqf/kcVF/rBje40/mLtrTSGuIV9pr287pjLQ8kNb9EPEW/6mZlzJyrG LYIjXcm2DlyaFfwiCoUiw3eSx5B5zqqcRKuiy7D2wVV5q3CpAFIdPHURbOGMFqjDpLHA dAbQ== 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; bh=7/VwfvDOIgbM1idBc27xHY6hWSKZkVGC47yrwOMenOQ=; b=D+RThd6FoKDWLJ57G+nSD67OkE0QBKi22gZ6YNZRDiVhGqYJ426C6JvN45ty0Rrusl mBhfT8cgM/UNztMKoVNutoBb36D/wEBUktCXJ9FnGq6xozQo//mXi1udwsvFfUl3av8S YTZzBQZRDjBTId0WRojCgRjZd30gy9nCJNtRT5JzB9buMoUaMxfz8LUhrIpLuKBnPr53 qRLNq2mlUXG/E9RE69EiImqHPf+d1ndPP8E/T1wghTmGta+nQP63/tSUP3geadRdocvW glnyMFMqDxIFhES24GMi170ZdDGf8Jf2EQi5w1AJV8+QP8epK5rWpYK7R/pE0FQkEQVd 4Xqw== X-Gm-Message-State: APt69E1dbuLl7ByD/Drvx7VTtWhuxmyE+TSuXRq/6MiMwWaucjVCTk+9 0ElbbFIZajBJ/RXIYaIq+2U= X-Received: by 2002:a1c:ed07:: with SMTP id l7-v6mr3095203wmh.139.1529005170994; Thu, 14 Jun 2018 12:39:30 -0700 (PDT) Received: from Red.localdomain (LFbn-NIC-1-240-64.w2-15.abo.wanadoo.fr. [2.15.84.64]) by smtp.googlemail.com with ESMTPSA id p196-v6sm7974367wmb.20.2018.06.14.12.39.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 12:39:30 -0700 (PDT) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, maxime.ripard@bootlin.com, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH] crypto: sun4i-ss: prevent deadlock on emulated hardware Date: Thu, 14 Jun 2018 21:36:59 +0200 Message-Id: <20180614193659.29261-1-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.16.4 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Running a qemu emulated cubieboard with sun4i-ss driver enabled led to a never ending boot. This is due to sun4i-ss deadlocked and taking all cpu in an infinite loop. Since the crypto hardware is not implemented, all registers are read as 0. So sun4i-ss will never progress in any operations. (TX_CNT being always 0) The first idea is to add a "TX_CNT always zero timeout" but this made cipher/hash loops more complex and prevent a case that never happen on real hardware. The best way to fix is to check at probe time if we run on a virtual machine with hardware emulated but non-implemented and prevent sun4i-ss to be loaded in that case. Letting sun4i-ss to load is useless anyway since all crypto algorithm will be disabled since they will fail crypto selftests. Tested-on: qemu-cubieboard Tested-on: cubieboard2 Signed-off-by: Corentin Labbe --- drivers/crypto/sunxi-ss/sun4i-ss-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.16.4 diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-core.c b/drivers/crypto/sunxi-ss/sun4i-ss-core.c index a81d89b3b7d8..a178e80adcf3 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss-core.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-core.c @@ -341,9 +341,18 @@ static int sun4i_ss_probe(struct platform_device *pdev) * I expect to be a sort of Security System Revision number. * Since the A80 seems to have an other version of SS * this info could be useful + * Detect virtual machine with non-implemented hardware + * (qemu-cubieboard) by checking the register value after a write to it. + * On non-implemented hardware, all registers are read as 0. + * On real hardware we should have a value > 0. */ writel(SS_ENABLED, ss->base + SS_CTL); v = readl(ss->base + SS_CTL); + if (!v) { + dev_err(&pdev->dev, "Qemu with non-implemented SS detected.\n"); + err = -ENODEV; + goto error_rst; + } v >>= 16; v &= 0x07; dev_info(&pdev->dev, "Die ID %d\n", v); @@ -398,6 +407,7 @@ static int sun4i_ss_probe(struct platform_device *pdev) break; } } +error_rst: if (ss->reset) reset_control_assert(ss->reset); error_clk: