Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp649614ybg; Wed, 3 Jun 2020 09:56:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUiDZjejusBlQiGJvsUYkSj1GH3bCNz4PanBYPkdA7UbRf3Q6p4er5V32eHsHIIgZvv77l X-Received: by 2002:a05:6402:155:: with SMTP id s21mr383733edu.144.1591203376316; Wed, 03 Jun 2020 09:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591203376; cv=none; d=google.com; s=arc-20160816; b=VWWTltw9/lvVzwlHa3PX/mtZ2eD0YrJ1bVLz6ztgc9Y5fcvu5ttRV6fNSB1kAxgmqN kIiXvdfMhFQmsqWd6PVVXxZWRWnKcHA1mMrriycMZrCiVPjcPFvplLOfV6ZRiN1MY7ZO MxUIxJKywuAYRioH+ir0yHVRKXXwZExlRDksKMF5tjLXj2jL2yFUavm9rvp2Qh+VBUzn alpL7lzKnkRh25+4cIO29byhkRc4rG4a+E2F11AnKPdSUqjbHI9wqYVekZegRZZxMO/k bifAMYWEjNkV5Gc0rqibmvYQ9vn184UmUPn4ceCb4pO1zPvLwXyob3YZaLyMPWOb7nxW 5hVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=cUUCX0RFG/CHZqtbVzTkck2M4AL313wp4iUZTMY+xvs=; b=O7jcd5tYRwWHzAgCywnnunzbKBgw675eKWaPckvwBIOEjIx2ONCIM0+/rzwosKaJRU rzI4DHHGng2RYMDn3TzSFVVdI08fl8MyOj3PeGiesEUHMnqVLeYSrbjjZEh01grw4Zcv e1O4pBVH84ZgjguLAiCM2QUON6exWoFRA+9iBgkVqXuswa3Y+MkZULMacybGSntKuU5F k3q1Tug80Rmjpbm3xL22/tHHlwEPMmjpMBDgrYkDr2Xkwrfu46+nZpjHmAJW+ym+6II3 HadRbhia2uGjHyOqQ7HB7KI+0xm7DZXZbdBVtzNWaHIyEKn01hSmhIOA/eSKbZmJx1BP LqsA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si81543eja.118.2020.06.03.09.55.42; Wed, 03 Jun 2020 09:56:16 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726112AbgFCQzi (ORCPT + 99 others); Wed, 3 Jun 2020 12:55:38 -0400 Received: from mga14.intel.com ([192.55.52.115]:36931 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgFCQzh (ORCPT ); Wed, 3 Jun 2020 12:55:37 -0400 IronPort-SDR: nK8wXzYILaloEvlhlFzjeIIeLwnI7auRtXKZ5QeCfv1cbPUX2bOgYm0p9DCXesaoPUPKONIos/ tYxilp7B7AbQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2020 09:55:35 -0700 IronPort-SDR: WKRqeYFKUfkwnW818PUa6ufHD74xo5iNMbK21IndAdRMGpgmRrNkc9slLaTer08ETd5LEx+3cr pZXY/xIMwwWA== X-IronPort-AV: E=Sophos;i="5.73,468,1583222400"; d="scan'208";a="445179678" Received: from silpixa00400314.ir.intel.com (HELO silpixa00400314) ([10.237.222.51]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2020 09:55:33 -0700 Date: Wed, 3 Jun 2020 17:55:26 +0100 From: Giovanni Cabiddu To: Mikulas Patocka 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, ahsan.atta@intel.com Subject: Re: [PATCH 1/4] qat: fix misunderstood -EBUSY return code Message-ID: <20200603165526.GA94360@silpixa00400314> References: <20200601160418.171851200@debian-a64.vm> <20200602220516.GA20880@silpixa00400314> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Mikulas, On Wed, Jun 03, 2020 at 04:31:54AM -0400, Mikulas Patocka wrote: > 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. Fair. > > The proper solution would be to add the request to a queue and process the > queue when some other request ended This is tricky. We explored a solution that was enqueuing to a sw queue when the hw queue was full and then re-submitting in the callback. Didn't work due to response ordering. > - but it would need substantial > rewrite of the driver. Do you want to rewrite it using a queue? We are looking at using the crypto-engine for this. However, since that patch is not ready, we can use your solution for the time being. I asked our validation team to run our regression suite on your patch set. > > Or, should we just move to the crypto-engine? > What do you mean by the crypto-engine? Herbert answered already this question :-) https://www.kernel.org/doc/html/latest/crypto/crypto_engine.html > > > - 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 From bdc48fa11 I see that "80 columns is certainly still _preferred_". 80 is still my preference. I can fix this and send a v2. > > > > 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. Yes, I understood this. My question was about the actual number. 93% of the depth of the queue. > > 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. Ok makes sense. Thanks. Regards, -- Giovanni