Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp322523ybg; Wed, 3 Jun 2020 01:32:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3OBEMFiZmSKzE2hpUqnkvnoULdludw29+vEexM19ewADm/B89FaZnkviCtw8XyQB0w+Zm X-Received: by 2002:a17:907:270d:: with SMTP id w13mr7213973ejk.134.1591173160483; Wed, 03 Jun 2020 01:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591173160; cv=none; d=google.com; s=arc-20160816; b=O9L/dtHHbMLQgYIGnBD41kvq1u/BumlOosak/6BN8LULuJPKXW58h/muXNvmIrw9Bl s8B/OsiG55LLJYlX9dnCWap1CWg2Nw++ZRBmxzn5fxpZUrGZ1Fq9oW0fUkM36tAk1Ph3 fihUMq6fX9iTrtVTeptnmTIt8ROOShmDsdGZIFbKJd2u1MwkMYdmhcA88WJiNPJhjGt1 66KG3GR9IK28jQzyk53UgxLFULTz+7Q4R4W7LO2IIY5inb2YNllLFZ1w/U5MiZ+okSMU 2p9Cw3WObPVyDE9H4RwXPGNqmpkWEzudiH14JhBzDtAGcjdBqAhMMAbixQtLwl67ppcx 64Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=vkeVxA/zhwqG4/6AGws5hEt6QBsQvR60ExyhAzUC90U=; b=tBpI25erqakcW054WlAThEhzNXKrXntwqnUkWDhcNqsuV79tsPCdhh/cWTlFLzNpj7 w4DY7eyQj5WNSxbcFSjKh0n5j3/mz/Gf+9D+7Np24BSaQhpAegNTwaF8EqUNMIX7sRNn x6f+E8vv6diqyvZm7hRFIA0RqnjDigUiCz33zk/ycLhCFLsAH2NCjcMmUv2IY5Ks2v5y YXlvDpQfsze7Bx/AaGcp9UIPBSL1xgWXLPbpE0m/CCfPc6inqMb2CF9O9fxNJ74joT4u AN0/l60GgLdFQNNJxa6nOSzMw59g29cg0FiKaQPbqwHsbs3o6jyCSG6nSjTa1w7+832F LZbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XiXQZlQ+; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si648939edl.557.2020.06.03.01.32.07; Wed, 03 Jun 2020 01:32:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XiXQZlQ+; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726262AbgFCIcD (ORCPT + 99 others); Wed, 3 Jun 2020 04:32:03 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:59915 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726123AbgFCIcD (ORCPT ); Wed, 3 Jun 2020 04:32:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591173121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vkeVxA/zhwqG4/6AGws5hEt6QBsQvR60ExyhAzUC90U=; b=XiXQZlQ+cswxAYErrqUyd2A3/xxk+eRmR+VQnS7gsVxMmtbVPN3cwabgpi4jcLqWUON6hx pdUvQ175uvL39SSStNLJ2nkYOsjoa200tte0LFVl0rUng64bdLyHxwbAveqqOK42XzA3X/ xWh8kX5i6LDBcf/RkGWqFjjWMSozpb8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-wnrmj7lAO1ObML6LIFMvOw-1; Wed, 03 Jun 2020 04:31:59 -0400 X-MC-Unique: wnrmj7lAO1ObML6LIFMvOw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 811EF107ACCA; Wed, 3 Jun 2020 08:31:58 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FD2519C4F; Wed, 3 Jun 2020 08:31:55 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 0538VshI016653; Wed, 3 Jun 2020 04:31:54 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 0538VsTC016649; Wed, 3 Jun 2020 04:31:54 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Wed, 3 Jun 2020 04:31:54 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Giovanni Cabiddu cc: Mike Snitzer , Herbert Xu , "David S. Miller" , Milan Broz , djeffery@redhat.com, dm-devel@redhat.com, qat-linux@intel.com, linux-crypto@vger.kernel.org, guazhang@redhat.com, jpittman@redhat.com Subject: Re: [PATCH 1/4] qat: fix misunderstood -EBUSY return code In-Reply-To: <20200602220516.GA20880@silpixa00400314> Message-ID: References: <20200601160418.171851200@debian-a64.vm> <20200602220516.GA20880@silpixa00400314> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, 2 Jun 2020, Giovanni Cabiddu wrote: > Hi Mikulas, > > thanks for your patch. See below. > > > + qat_req->backed_off = backed_off = adf_should_back_off(ctx->inst->sym_tx); > > +again: > > + ret = adf_send_message(ctx->inst->sym_tx, (uint32_t *)msg); > > if (ret == -EAGAIN) { > > - qat_alg_free_bufl(ctx->inst, qat_req); > > - return -EBUSY; > > + qat_req->backed_off = backed_off = 1; > > + cpu_relax(); > > + goto again; > > } > I am a bit concerned about this potential infinite loop. > If an error occurred on the device and the queue is full, we will be > stuck here forever. > Should we just retry a number of times and then fail? It's better to get stuck in an infinite loop than to cause random I/O errors. The infinite loop requires reboot, but it doesn't damage data on disks. The proper solution would be to add the request to a queue and process the queue when some other request ended - but it would need substantial rewrite of the driver. Do you want to rewrite it using a queue? > Or, should we just move to the crypto-engine? What do you mean by the crypto-engine? > > - do { > > - ret = adf_send_message(ctx->inst->sym_tx, (uint32_t *)msg); > > - } while (ret == -EAGAIN && ctr++ < 10); > > - > > + qat_req->backed_off = backed_off = adf_should_back_off(ctx->inst->sym_tx); > checkpatch: line over 80 characters - same in every place > adf_should_back_off is used. Recently, Linus announced that we can have larger lines than 80 bytes. See bdc48fa11e46f867ea4d75fa59ee87a7f48be144 > > static int qat_alg_skcipher_blk_decrypt(struct skcipher_request *req) > > Index: linux-2.6/drivers/crypto/qat/qat_common/adf_transport.c > > =================================================================== > > --- linux-2.6.orig/drivers/crypto/qat/qat_common/adf_transport.c > > +++ linux-2.6/drivers/crypto/qat/qat_common/adf_transport.c > > @@ -114,10 +114,19 @@ static void adf_disable_ring_irq(struct > > WRITE_CSR_INT_COL_EN(bank->csr_addr, bank->bank_number, bank->irq_mask); > > } > > > > +bool adf_should_back_off(struct adf_etr_ring_data *ring) > > +{ > > + return atomic_read(ring->inflights) > ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size) * 15 / 16; > How did you came up with 15/16? I want the sender to back off before the queue is full, to avoid busy-waiting. There may be more concurrent senders, so we want to back off at some point before the queue is full. > checkpatch: WARNING: line over 80 characters > > > +} > > + > > int adf_send_message(struct adf_etr_ring_data *ring, uint32_t *msg) > > { > > - if (atomic_add_return(1, ring->inflights) > > > - ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size)) { > > + int limit = ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size); > > + > > + if (atomic_read(ring->inflights) >= limit) > > + return -EAGAIN; > Can this be removed and leave only the condition below? > Am I missing something here? atomic_read is light, atomic_add_return is heavy. We may be busy-waiting here, so I want to use the light instruction. Spinlocks do the same - when they are spinning, they use just a light "read" instruction and when the "read" instruction indicates that the spinlock is free, they execute the read-modify-write instruction to actually acquire the lock. > > + > > + if (atomic_add_return(1, ring->inflights) > limit) { > > atomic_dec(ring->inflights); > > return -EAGAIN; > > } Mikulas