From patchwork Fri Mar 12 14:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Zhang X-Patchwork-Id: 398876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF115C433DB for ; Fri, 12 Mar 2021 14:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 988F464FC3 for ; Fri, 12 Mar 2021 14:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231448AbhCLOTb (ORCPT ); Fri, 12 Mar 2021 09:19:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbhCLOT2 (ORCPT ); Fri, 12 Mar 2021 09:19:28 -0500 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76DA4C061574; Fri, 12 Mar 2021 06:19:27 -0800 (PST) Received: by mail-qk1-x72c.google.com with SMTP id 130so24320607qkh.11; Fri, 12 Mar 2021 06:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OxJLT8418g+8CTGdYJxAZUO03CbXWkewq51px4J1l9c=; b=l1wOkY9UFmhOMe2vNJNz5UNpNZ4wVVexRZp8OW2OtFaB0V4IOpGccAkJmBaS3eDdxA X5GhCb+eIeUnAr0cBNQ6Nk+XFf2IP9RBQ0MTs8KATN73C34FzFvhBvqyspF61MRfW8s4 tfL+O2cbOAu0dtOjKbrozVU1QBcJsRqOcmZHlvt+7l3w9r7MU4bNWJguGETF43tWBb7q LDrCZZG1GFPQER/nTDxgvuc/PWccuwV8kGAbDVjgie3YSTMjjEQGNkOEa3Ffmg/VaJNf g0j+1NJy72B5AAyfd8UVCEu8+IWb9ivxrVxrZsPuVngs5jHyjrKoz8HGM5ueWnf+JEKJ JnjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OxJLT8418g+8CTGdYJxAZUO03CbXWkewq51px4J1l9c=; b=qErMWlVRQi9BtBnRhQJ4F4qUdjanDOye0VDoJdM3xgaY2lDujtduFxLHE+g+SZYoND KcHzv5m9c3xbkAVdP+vQItufl8gzOLPjQaobY7uYesXWKpxTT2d60bcLKYLHEc4r9wD4 pq+BNG/1CiymKByU667bF6g7cBzQhrZ6VyXcl8crHpaBUyjB5YMaLJHZAsha25aZ0wOy hsWovw/RRtwl1mex970/98i/tCuk7r1Z9RbDYpaDcceCr7qLlz7uqK1idVq/6XCJl1JZ PGAduS6NCA1dvNnF6TsxEAd++FjbZtZdi+QoZC2Bjcz5lx03P3IlZfHkOzdH5LkFNuDm DTIA== X-Gm-Message-State: AOAM530T7S7A4yv9lSVPMgMrTrc0GHO6Ov8G/+mctdyjFZl/oBBDIREE jWShnHQoZ5c5n1PswV08nEU= X-Google-Smtp-Source: ABdhPJwmYN7yxXbKPkmztayI58KX5dDrUUItWHluAxXj1Z1MrqfcvOK1Rsh0FL+K1905KxAUPan/4Q== X-Received: by 2002:a37:4641:: with SMTP id t62mr12352353qka.147.1615558766727; Fri, 12 Mar 2021 06:19:26 -0800 (PST) Received: from tong-desktop.local ([2601:5c0:c200:27c6:b9e0:c84:da81:d749]) by smtp.googlemail.com with ESMTPSA id v2sm3979478qti.94.2021.03.12.06.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 06:19:26 -0800 (PST) From: Tong Zhang To: Giovanni Cabiddu , Herbert Xu , "David S. Miller" , Tong Zhang , Fiona Trahe , Wojciech Ziemba , qat-linux@intel.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: [PATCH v2 2/2] crypto: qat: ADF_STATUS_PF_RUNNING should be set after adf_dev_init Date: Fri, 12 Mar 2021 09:19:08 -0500 Message-Id: <20210312141908.2388121-3-ztong0001@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312141908.2388121-1-ztong0001@gmail.com> References: <20210312141908.2388121-1-ztong0001@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org ADF_STATUS_PF_RUNNING is (only) used and checked by adf_vf2pf_shutdown() before calling adf_iov_putmsg()->mutex_lock(vf2pf_lock), however the vf2pf_lock is initialized in adf_dev_init(), which can fail and when it fail, the vf2pf_lock is either not initialized or destroyed, a subsequent use of vf2pf_lock will cause issue. To fix this issue, only set this flag if adf_dev_init() returns 0. [ 7.178404] BUG: KASAN: user-memory-access in __mutex_lock.isra.0+0x1ac/0x7c0 [ 7.180345] Call Trace: [ 7.182576] mutex_lock+0xc9/0xd0 [ 7.183257] adf_iov_putmsg+0x118/0x1a0 [intel_qat] [ 7.183541] adf_vf2pf_shutdown+0x4d/0x7b [intel_qat] [ 7.183834] adf_dev_shutdown+0x172/0x2b0 [intel_qat] [ 7.184127] adf_probe+0x5e9/0x600 [qat_dh895xccvf] Signed-off-by: Tong Zhang --- drivers/crypto/qat/qat_c3xxxvf/adf_drv.c | 4 ++-- drivers/crypto/qat/qat_c62xvf/adf_drv.c | 4 ++-- drivers/crypto/qat/qat_dh895xccvf/adf_drv.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/qat/qat_c3xxxvf/adf_drv.c b/drivers/crypto/qat/qat_c3xxxvf/adf_drv.c index 1d1532e8fb6d..067ca5e17d38 100644 --- a/drivers/crypto/qat/qat_c3xxxvf/adf_drv.c +++ b/drivers/crypto/qat/qat_c3xxxvf/adf_drv.c @@ -184,12 +184,12 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) goto out_err_free_reg; - set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); - ret = adf_dev_init(accel_dev); if (ret) goto out_err_dev_shutdown; + set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); + ret = adf_dev_start(accel_dev); if (ret) goto out_err_dev_stop; diff --git a/drivers/crypto/qat/qat_c62xvf/adf_drv.c b/drivers/crypto/qat/qat_c62xvf/adf_drv.c index 04742a6d91ca..51ea88c0b17d 100644 --- a/drivers/crypto/qat/qat_c62xvf/adf_drv.c +++ b/drivers/crypto/qat/qat_c62xvf/adf_drv.c @@ -184,12 +184,12 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) goto out_err_free_reg; - set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); - ret = adf_dev_init(accel_dev); if (ret) goto out_err_dev_shutdown; + set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); + ret = adf_dev_start(accel_dev); if (ret) goto out_err_dev_stop; diff --git a/drivers/crypto/qat/qat_dh895xccvf/adf_drv.c b/drivers/crypto/qat/qat_dh895xccvf/adf_drv.c index c972554a755e..29999da716cc 100644 --- a/drivers/crypto/qat/qat_dh895xccvf/adf_drv.c +++ b/drivers/crypto/qat/qat_dh895xccvf/adf_drv.c @@ -184,12 +184,12 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) goto out_err_free_reg; - set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); - ret = adf_dev_init(accel_dev); if (ret) goto out_err_dev_shutdown; + set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status); + ret = adf_dev_start(accel_dev); if (ret) goto out_err_dev_stop;