Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5063172pxb; Mon, 15 Feb 2021 08:32:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzir81Zm11nYByAYhsMjfd+UfjEThXxsiZ2MaV2TCq7NVGdYvoFxj7g/5whLXi/upSavNZu X-Received: by 2002:a17:906:4b0a:: with SMTP id y10mr5898432eju.327.1613406764061; Mon, 15 Feb 2021 08:32:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613406764; cv=none; d=google.com; s=arc-20160816; b=SB3sgRc/t4VMv/HoYa0R1KjkugIHrC+uaIXmRG2U3ELPxZGnZYDty4fT4nXMBOTXQB AyaVzW9sZ+/6y+gBSHFqX5QzE4voQ5odHgsRw9cdtVDLmd1VDUQDLGRXVrOHM+rJc19p eOtGDRuA8l7IR1WXjzuHawEgBh26WAGvXPk1nS9B5Sa6PqwApMyJq8R/zcyYxOEvdnT5 ViLxljkD3tptyFYwlH4aRqAvpeOWWwmUyUQ9bdNEgaV+4tkHsKLuHOUE1qWl/Ee6uccQ f37cVleNfACU+W9PTM3VBfDjEZmboQd71WNEbjN7DTymikSDwmSbW1xXXGJKda7QYba7 PK8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Nx+WnzPNb5RCmGxgXA6/irVsiZJ+S0pHL1U8j/JIDHk=; b=EENy83aK8gF45Op0kOMEVY6YQzfhWDdTZY+bXCZF6//ac3i6s0TykIEPb/NJHOToqQ wHV1M639+k/XaOYW9RKruhBxk3tQeCJKvC4Zp9xdVHNRo5wwIwpjiAmUQf9BvM38btb+ xbZtPC6k5gAxeLRTtk+G0NfjiKf1eYB1+MxJHMSrap0HwXZprKch9pd81p09Ntq9MFDd cEYzBXf8FdgA6BUmp7zjuZqlvQ6ToMBBQ6wsr5+6Dew4AABvnXIJeaU7sst3NXPGDBvd ICj86nBhXo/9RHb4bErw9Lc2ZEjwdlxCpEVAMDqJR+puXKECxVR5ZKrHo7bEQ8OCWdbr 9xDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AIxmaTSo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm18si12701934edb.545.2021.02.15.08.32.20; Mon, 15 Feb 2021 08:32:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=AIxmaTSo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbhBOQbo (ORCPT + 99 others); Mon, 15 Feb 2021 11:31:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:49782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbhBOPhS (ORCPT ); Mon, 15 Feb 2021 10:37:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B486D64E9B; Mon, 15 Feb 2021 15:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403167; bh=4RtjZHLi7/YjwmChPaUuXBDuz3b+W46ekT5abyQYwU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIxmaTSoszdT+CcK0n73lcVcH27izj4ms8ON1Tg2pK2FUuBNaSeOfi22CMMPkm/cJ vkmOr42kvn5ZnK1qpSCRCwEUT4tew/Wjai+i4X6t2PiyRvuVoNz7/eLAXqJujkFUdg JjG8FIVcR9G+vuXXBjjerq9ifiG4cJqxPsXPVe38= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sanjay Kumar , Dave Jiang , Vinod Koul , Sasha Levin Subject: [PATCH 5.10 054/104] dmaengine: idxd: check device state before issue command Date: Mon, 15 Feb 2021 16:27:07 +0100 Message-Id: <20210215152721.221177527@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Jiang [ Upstream commit 89e3becd8f821e507052e012d2559dcda59f538e ] Add device state check before executing command. Without the check the command can be issued while device is in halt state and causes the driver to block while waiting for the completion of the command. Reported-by: Sanjay Kumar Signed-off-by: Dave Jiang Tested-by: Sanjay Kumar Fixes: 0d5c10b4c84d ("dmaengine: idxd: add work queue drain support") Link: https://lore.kernel.org/r/161219313921.2976211.12222625226450097465.stgit@djiang5-desk3.ch.intel.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/idxd/device.c | 23 ++++++++++++++++++++++- drivers/dma/idxd/idxd.h | 2 +- drivers/dma/idxd/init.c | 5 ++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c index 663344987e3f3..a6704838ffcb7 100644 --- a/drivers/dma/idxd/device.c +++ b/drivers/dma/idxd/device.c @@ -325,17 +325,31 @@ static inline bool idxd_is_enabled(struct idxd_device *idxd) return false; } +static inline bool idxd_device_is_halted(struct idxd_device *idxd) +{ + union gensts_reg gensts; + + gensts.bits = ioread32(idxd->reg_base + IDXD_GENSTATS_OFFSET); + + return (gensts.state == IDXD_DEVICE_STATE_HALT); +} + /* * This is function is only used for reset during probe and will * poll for completion. Once the device is setup with interrupts, * all commands will be done via interrupt completion. */ -void idxd_device_init_reset(struct idxd_device *idxd) +int idxd_device_init_reset(struct idxd_device *idxd) { struct device *dev = &idxd->pdev->dev; union idxd_command_reg cmd; unsigned long flags; + if (idxd_device_is_halted(idxd)) { + dev_warn(&idxd->pdev->dev, "Device is HALTED!\n"); + return -ENXIO; + } + memset(&cmd, 0, sizeof(cmd)); cmd.cmd = IDXD_CMD_RESET_DEVICE; dev_dbg(dev, "%s: sending reset for init.\n", __func__); @@ -346,6 +360,7 @@ void idxd_device_init_reset(struct idxd_device *idxd) IDXD_CMDSTS_ACTIVE) cpu_relax(); spin_unlock_irqrestore(&idxd->dev_lock, flags); + return 0; } static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand, @@ -355,6 +370,12 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand, DECLARE_COMPLETION_ONSTACK(done); unsigned long flags; + if (idxd_device_is_halted(idxd)) { + dev_warn(&idxd->pdev->dev, "Device is HALTED!\n"); + *status = IDXD_CMDSTS_HW_ERR; + return; + } + memset(&cmd, 0, sizeof(cmd)); cmd.cmd = cmd_code; cmd.operand = operand; diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h index d48f193daacc0..953ef6536aac4 100644 --- a/drivers/dma/idxd/idxd.h +++ b/drivers/dma/idxd/idxd.h @@ -281,7 +281,7 @@ void idxd_mask_msix_vector(struct idxd_device *idxd, int vec_id); void idxd_unmask_msix_vector(struct idxd_device *idxd, int vec_id); /* device control */ -void idxd_device_init_reset(struct idxd_device *idxd); +int idxd_device_init_reset(struct idxd_device *idxd); int idxd_device_enable(struct idxd_device *idxd); int idxd_device_disable(struct idxd_device *idxd); void idxd_device_reset(struct idxd_device *idxd); diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 0a4432b063b5c..fa8c4228f358a 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -289,7 +289,10 @@ static int idxd_probe(struct idxd_device *idxd) int rc; dev_dbg(dev, "%s entered and resetting device\n", __func__); - idxd_device_init_reset(idxd); + rc = idxd_device_init_reset(idxd); + if (rc < 0) + return rc; + dev_dbg(dev, "IDXD reset complete\n"); idxd_read_caps(idxd); -- 2.27.0