Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp214333ybx; Tue, 5 Nov 2019 22:40:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwfQBMpxcw8VKWlJ4BkflyMtLqxJ5ZsXT2YQpazFd3CWHVASDz/sHgVJxQu7svDmT7aweCD X-Received: by 2002:a50:c191:: with SMTP id m17mr882717edf.259.1573022400130; Tue, 05 Nov 2019 22:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573022400; cv=none; d=google.com; s=arc-20160816; b=ll8rUXsUETD6vYzQHVJ8EREzKyQ+mHKQIu8B4ESI11rx1AfsEjZG+KzU2gRA+iFf6M XM8/71A3X5yjJHGNHCMYLPOwgrDbaZh/pcMMtBO9pViPYmm+EGPxwvvEv7vUycerHmvD OCknPfQsBmrWhM6KK75iLqE4gIxFzl9KpojBPbEcIv3fAKqPgyeEIF3woQwzoUWKsx/Y /ydrPDwYmP6R6oPRkojRzOBWrRJMRlzurbCTW2u73fOth373zVSxpuIkMHth6RU8yKz7 f4X3CqG8Zom1koEgrN4gmin4fK8XL/mp8V3sSQkWuxEK1Ta9PeCwnaVzhs36sE2HmAqV HOug== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=naIjmil/eDlIhuN1fRpN8utbfrj7V2f7nfg6i0zi9os=; b=sJk1Q6fBGhRcuITFvjwuXk9q5ILsch8uAVQlLrAMCPer7+xbL6r1LLjlvoWEgcQNat CGbqE1Vuq38FugVFgSFwT8sfRkt0/MAOjv5zlIXY48bXXDagVs79ECq/ilNOSqw41caz 7dObFMUWtqh9hmmxba8PF34kch881w94bughu48z74OL30gfrnplugZCKbZw1CkZPB9H z5UFBe7A93iXQVx0ZNaiDwAI7eWj27pr14H5QE58xIUB/NIl738Vm9GdO0DBmGTbKxth e7hFx1+W0DPL6XDwAhH2p2+q2tzFyXcVnXbofb1UZYMFiXqXvsyjCpzd/bACCqapHKgu 6T1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@benyossef-com.20150623.gappssmtp.com header.s=20150623 header.b=O8lvHuCY; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g19si12436126edb.280.2019.11.05.22.39.35; Tue, 05 Nov 2019 22:40:00 -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=@benyossef-com.20150623.gappssmtp.com header.s=20150623 header.b=O8lvHuCY; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729086AbfKFGj3 (ORCPT + 99 others); Wed, 6 Nov 2019 01:39:29 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]:36148 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729470AbfKFGj3 (ORCPT ); Wed, 6 Nov 2019 01:39:29 -0500 Received: by mail-vs1-f66.google.com with SMTP id q21so15253739vsg.3 for ; Tue, 05 Nov 2019 22:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benyossef-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=naIjmil/eDlIhuN1fRpN8utbfrj7V2f7nfg6i0zi9os=; b=O8lvHuCYOsjSvIspZjZEamNdAc57lSBhmQ4BHC0WDcT4VZ6sGPlb8JILexnhOnK5uk C+/pbM6qg/RShmMIJccN1TdVIsXzH1Ast6gI9pUXWwnoZFK3BqBKfTdsm/dwNGR9kqg8 YqllsdJCRsf/MRH3XLhBVT6BtP8wOvN4UWElp70sZNQBnQA8M4OQr+NMWr4D+fBOnzX4 oV2gc1kFuavAza+0lWf4HkSgyoZKkJiaVdd2UNHd+NH5Wj7VG3fDt6BCAUVOpTmNo5k1 e1Jl3oMoAkNSQgDZ+0IeK9AZb1z5WHXlZFzwziF6CCXfipjcjeaoWpEgiBzaD6jNR+ft Hqsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=naIjmil/eDlIhuN1fRpN8utbfrj7V2f7nfg6i0zi9os=; b=J66ex49s3zsVzrpViTs8bKoITdsZD2ysICgeaHx5u53MDlIrE4UIu6ZcVfQjGT6LIb 5lG2OQ5PMDezslXgUP8MIksAb5h4q8DXdVKC80Qmu+t0kpM1bLYtl8h1PJu1F1IB59es eKk+fiTuiqEVmFBiUeP0+5OEIiQcPdln8Nz1mvG9Dj/9Sd71X3Oct8I7hXzwufzG72ot Y23sRQq3ZqfTB2WNiw7RIaYiY+PepPlJ7V91H3GAQbAjUNUajt+OSjIiEdG6NyCEN5Hn piXlmVhbt+0DnWmy0q4YPqF9+oPFwDHbo+NxDmA4tomUdg4iVCmwYxI48DyEQu0TSt0a xBiw== X-Gm-Message-State: APjAAAV1oEqbUCqMLihn4ndE77hfIsi9o1icxq3xOEFyad4lU0mNaxVL +IYg+iSWd+CGSUlb40UK/I7jbXzDIgRF6sE7t8dHzKtNyjevHw== X-Received: by 2002:a67:324d:: with SMTP id y74mr504583vsy.193.1573022367862; Tue, 05 Nov 2019 22:39:27 -0800 (PST) MIME-Version: 1.0 References: <20191017122549.4634-1-t-kristo@ti.com> <20191017122549.4634-10-t-kristo@ti.com> In-Reply-To: <20191017122549.4634-10-t-kristo@ti.com> From: Gilad Ben-Yossef Date: Wed, 6 Nov 2019 08:39:16 +0200 Message-ID: Subject: Re: [PATCH 09/10] crypto: add timeout to crypto_wait_req To: Tero Kristo Cc: Herbert Xu , Eric Biggers , David Miller , Linux Crypto Mailing List , Ard Biesheuvel , linux-omap@vger.kernel.org, Linux ARM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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? Thanks! Gilad > > Signed-off-by: Tero Kristo > --- > include/linux/crypto.h | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/include/linux/crypto.h b/include/linux/crypto.h > index 19ea3a371d7b..b8f0e5c3cc0c 100644 > --- a/include/linux/crypto.h > +++ b/include/linux/crypto.h > @@ -682,8 +682,15 @@ static inline int crypto_wait_req(int err, struct cr= ypto_wait *wait) > switch (err) { > case -EINPROGRESS: > case -EBUSY: > - wait_for_completion(&wait->completion); > + err =3D wait_for_completion_timeout(&wait->completion, > + msecs_to_jiffies(1000))= ; > reinit_completion(&wait->completion); > + if (!err) { > + pr_err("%s: timeout for %p\n", __func__, wait); > + err =3D -ETIMEDOUT; > + break; > + } > + > err =3D wait->err; > break; > }; > -- > 2.17.1 > > -- > Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/= Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki -- Gilad Ben-Yossef Chief Coffee Drinker values of =CE=B2 will give rise to dom!