Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2114487ybx; Thu, 7 Nov 2019 23:42:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwI3gLDDz+rU/dZOnRBVN9SCUYTO5rjzaDwNZyD6CVsaQ0QVd1Zw5z6uLejkCKDmHqoI99M X-Received: by 2002:a17:907:20d2:: with SMTP id qq18mr7285452ejb.305.1573198919991; Thu, 07 Nov 2019 23:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573198919; cv=none; d=google.com; s=arc-20160816; b=by4LiB1fE2TyrFjacLZRJx6xi6ESeH+KeZU86A5Hhg7jwRNQxwROumsh6sLmk5lrIB tFylL3/WeFDsTh90inhJuWhD1BbUlMykbnpe5DGFIKyS71w/7t/H50ZDs/rHGRTCyhb0 /TJcgM1d5hCcoY7ujZXcBvqmfTWAh4fwNQaHPJOiPcKVn7970F98epixFpFvGH3JVYC+ 6k6A/6uUdZ/x8KQg0vliXqA/hG0lgd5AgXuuI9fap6HzLsHgJLMIi9rduvoMYh0oy3pR mVw6gqX98NqsjTbfR7g36PVt4/Y0aCkgkZVQVE5bKAFFIC7W11S9Lm+owrsSwhUlTlCH f6Ww== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=8p57qwOk81qIZzYrBvDYBp3MiSplInyVjuIvJT9EzBE=; b=w5WUjwdrpOoIt6cif1K4tfA6NcClzGsYljG4h9vnz7+c1wgABwP0S5gA8GjqdH1YH/ jqAldz1bW2O26BauqQmfDoN0lzP8YVZMJ9hEHJxK4fM2j2ahJI8LoM5yZplybzmQvMf+ nWKzFOXjvgmn5ZDnQshfBeoH9XmYm5IF4aZzLJhkJuLg/JGuwScKF7Fjb5jWs34Ku0X1 5eaSSgjFy6PGO3c1z9i93GSNkAb/Y262HkIa1tK4aWJbthLOG7WUvxmFZlFd8Esbh7hH TWc7AB4DuoLR8LuJ+7YTdskt9uM45Z5NxvPQugYcPyT7y5YKUR4H3RcnciaYIINyNiZQ 6kLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="QLHM/T7Q"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rk9si3101330ejb.301.2019.11.07.23.41.28; Thu, 07 Nov 2019 23:41:59 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b="QLHM/T7Q"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727016AbfKHHlQ (ORCPT + 99 others); Fri, 8 Nov 2019 02:41:16 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:50328 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbfKHHlQ (ORCPT ); Fri, 8 Nov 2019 02:41:16 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xA87f1JB064030; Fri, 8 Nov 2019 01:41:01 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1573198862; bh=8p57qwOk81qIZzYrBvDYBp3MiSplInyVjuIvJT9EzBE=; h=Subject:To:References:From:Date:In-Reply-To; b=QLHM/T7QV4DXcb4rvpTw7NQ42f4gHZ+sWcPZbWGEAJ36Yb9fE54BOkuE6OfZScEmG qNbRELdBFtcas80D5rWZr5rsu3EIgTqGZU95YmeCU8aQ/CjxXaNSk0ZRi5MmKL2O+v OeGPn2K+u5Bh/z4dI+oL2m5LQ7BTSeCWf4nfeSrc= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA87f1Cf001150; Fri, 8 Nov 2019 01:41:01 -0600 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 8 Nov 2019 01:40:45 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 8 Nov 2019 01:40:45 -0600 Received: from [127.0.0.1] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id xA87evV2090261; Fri, 8 Nov 2019 01:40:58 -0600 Subject: Re: [PATCH 09/10] crypto: add timeout to crypto_wait_req To: Gilad Ben-Yossef , Herbert Xu , David Miller , Linux Crypto Mailing List , Ard Biesheuvel , , Linux ARM References: <20191017122549.4634-1-t-kristo@ti.com> <20191017122549.4634-10-t-kristo@ti.com> <076f0bc6-ad04-9543-db02-d7c7060db036@ti.com> <20191108022759.GB1140@sol.localdomain> From: Tero Kristo Message-ID: Date: Fri, 8 Nov 2019 09:40:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191108022759.GB1140@sol.localdomain> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 08/11/2019 04:27, Eric Biggers wrote: > On Wed, Nov 06, 2019 at 09:33:20AM +0200, Gilad Ben-Yossef wrote: >> On Wed, Nov 6, 2019 at 9:25 AM Tero Kristo wrote: >>> >>> On 06/11/2019 08:39, Gilad Ben-Yossef wrote: >>>> Hi, >>>> >>>> >>>> On Thu, Oct 17, 2019 at 3:26 PM Tero Kristo wrote: >>>>> >>>>> Currently crypto_wait_req waits indefinitely for an async crypto request >>>>> to complete. This is bad as it can cause for example the crypto test >>>>> manager to hang without any notification as to why it has happened. >>>>> Instead of waiting indefinitely, add a 1 second timeout to the call, >>>>> and provide a warning print if a timeout happens. >>>> >>>> While the incentive is clear and positive, this suggested solution >>>> creates problems of its own. >>>> In many (most?) cases where we are waiting here, we are waiting for a >>>> DMA operation to finish from hardware. >>>> Exiting while this pending DMA operation is not finished, even with a >>>> proper error return value, is dangerous because >>>> unless the calling code takes great care to not release the memory the >>>> DMA is being done from/to, this can have disastrous effects. >>>> >>>> As Eric has already mentioned, one second might seem like a long time, >>>> but we don't really know if it is enough. >>>> >>>> How about adding a second API (ig. crypto_wait_req_timeout) which >>>> supports a calee specified timeout where >>>> the calle knows how to correctly deal with timeout and port the >>>> relevant call sites to use this? >>> >>> Yeah, that would work for me. I guess we could just swap the testmgr to >>> use this timeout API, as it is quite clear it should timeout rather than >>> wait indefinitely, and afaics, the data buffers it uses are limited >>> size. It doesn't really matter for it whether the timeout is 1 second or >>> 10 seconds, as long as it eventually times out. >> >> >> As long as you avoid releasing the memory used on timeout, that should >> work well, I think. >> > > The memory is always going to be freed eventually, though. Although the crypto > tests currently reuse the input/output buffers and the request structure from > one test to the next, they're freed at the end of the tests. Also, it's unsafe > for one request structure to be used for multiple requests concurrently anyway. > > I think crypto_wait_req_timeout() would just be fundamentally unsafe. > > Couldn't you just use CONFIG_DETECT_HUNG_TASK=y instead? It should report if > any thread is blocked for too long. The problem is not detecting a hung task, the problem is determining what caused the hang. Personally I don't care if the system dies if a crypto accelerator self test has failed, as long as I get reported about the exact nature of the failure. The failures are expected to happen only in development phase of a crypto driver. With the timeout patch in place, I get reported what exact crypto test case failed and I can focus my debug efforts on that one. Anyways, as said this is just a nice to have patch, and can be dropped no issues there. I was just thinking some other people might find it useful also. -Tero -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki