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: 10465133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F0AD0600D0 for ; Thu, 14 Jun 2018 19:39:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD9AE28C1A for ; Thu, 14 Jun 2018 19:39:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF4B728C22; Thu, 14 Jun 2018 19:39:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8714628C1A for ; Thu, 14 Jun 2018 19:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=8KIKxIAjjOB1l24QxKlobnt5vzFfEziFSsR+8sbcLHs=; b=h/O fpZCKVoMCVvrjH0xs+vEtLlXtxV/jAaVkU3V+z4EAbjDZTfMRnI6dzEBx4tm4Cm8MVecxkzi0W8jA 002Ko5nrSOBA8Uitxbx0sXONmUP95TDpGgecchlA0R95tOLPxM4a6q7ks7DEsWJ/xpUMg6UzpH701 W1AqBF/N7aMSnz/VpIcazEiz17qs3CVjLNnQ000f4ToxyZ66m13XbOpn67+e4bIvaQUbS8x9e6kr+ zE/QGTJ9c3zaRns+d1VjF/k8rV+gZLRXwt5WcCfqurCQoCsYq9BiPBzsy4GjfxVgVtw17xFP40W+3 F21XnwOIrotMCP8gRBJXBosQ254HOZg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTY60-0005Qn-8j; Thu, 14 Jun 2018 19:39:48 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTY5v-0005OQ-Sp for linux-arm-kernel@lists.infradead.org; Thu, 14 Jun 2018 19:39:45 +0000 Received: by mail-wm0-x244.google.com with SMTP id v16-v6so12415963wmh.5 for ; Thu, 14 Jun 2018 12:39:32 -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=EagjTXQgRO871ThnHGpk2kRCmW1vUgQFFVyj0V63imyzxyN10oIGeK1mzdp0gSeMv9 D3sQacXrA65LXGuPIlDBsWEiMbQovN77TXv+/qcBcfCs6Q2VS6C8YZ7ID1AdF9rMRGnL pihvdqpd1N0Sgt+8U8HFxoEJU2W0ydFNzbO0+MRRdFoyMwmI3nuBFJTcMqS/euQsAs1a RxgA4v3eLoqeozL8nmMpRsjDSnyT73lO2cZ1ZJWoV/Db02r5xHc7q6QHKzO6N3BAydsx Q03uDBeKVbf9gQ9jj1zLM/Po9gAmQrO5MrJCg4x4IzgQf46+8vylQHmq1CpzR7XK+9de +PPw== X-Gm-Message-State: APt69E1v81bIvYuGl0K8UnUDA41o54BKIIS3FU0eYsayKGzrwtC1Zg/z tdE6cb2WxR8PwAOhW6PUx4I= X-Google-Smtp-Source: ADUXVKIn79+SeVB6/BhmEgZB06JeR38h08UmDnqtiLnk3m+0zyZ2bghHCRuh9GrLpY+S7NPRLs5cPw== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180614_123943_941932_7C1D9425 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-sunxi@googlegroups.com, Corentin Labbe , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: