Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3524041pxf; Mon, 15 Mar 2021 11:28:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKIuIEKKKq4XCnzej9BYQ6UMj40HZaV/Y6o1W+4bJ7uZ7auwKn0sld5hTxk4qZdl3p5PTm X-Received: by 2002:a17:906:4015:: with SMTP id v21mr26155939ejj.433.1615832888559; Mon, 15 Mar 2021 11:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832888; cv=none; d=google.com; s=arc-20160816; b=yzGJfLdQX7Elb2CSoTNv1xwz/KNVeS5y9geKr8yPCtl6nDcRtZMmHSxHP//yMxP5tO amdVYJ5IuVxd2SXKGjYSxuQPkfmJl1MGyoiY1oWUb2I+CWVmEUDo02eQA7GJyToTRz8O tcoUW2cMeQmpFHYDLGA6Vdnp9F2xiPwXEfWNi9zubdg/jS2w5BhztFfG5v7H4TUT5fhq r14mFrgXXQyvlpuBss2sJ42nc8Ps1dZNYnQAYpngE1EXvDyZDTKYF3iHl8kROjYsN+4b LBXDaqMqpRvfBuH07FMxaLwZNRk08pQqGAAXUYwYERqHrYOTa2JEQj8Z1b9w9Yivj2T1 63zQ== 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=wbLNQ0Hw9gcz7bcGvo8xmRIeeH8YwRozYtwO5owML5Q=; b=MsiW29zBmSiOHVt4InEMRTUbgoPJaqUNBoEb8W1vzyfZiAaWFbYYPPLID5tiii54Db GO2tujrfCZgwzZUNPNGNYYDohl07P6WkZwJvZZhCsf3aue0JH+sy3D9S7KKkszDs+dlz dK3uLdoFfprUldYBGsYgnoPbyxBesjOgtRiezNRBL7fq9ob5SRBnVDDHyjWTzwfsb2Gk 5ijM7gU2C1Xrx/qgmS1y+cEi/D+V1gzMwWROaY0IvkI83tIKV8AwK2rEeSF5vU0n/ONq q0o/4g3tFd3vfvEMLbP2OCPR21Vps5MPJWGr5OhgkSp1JvxjhdrxRODCSpfkZsdlsVFG Hs2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CYpAwApS; 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 ho7si10969910ejc.686.2021.03.15.11.27.28; Mon, 15 Mar 2021 11:28:08 -0700 (PDT) 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=CYpAwApS; 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 S238957AbhCOO1V (ORCPT + 99 others); Mon, 15 Mar 2021 10:27:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:37836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233094AbhCOOAi (ORCPT ); Mon, 15 Mar 2021 10:00:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CFFF464F6C; Mon, 15 Mar 2021 14:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816825; bh=U5cMJotNJXpC3v6PATpeGfYfsNOLP3ELGYUfgo9TaFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CYpAwApSQ6B1m3wGbtKgHgyB99R6OzVNiSsU4GXMyn+hk4eJTSsihJZfdn2FkXg6T 6d6SbeIsHYpsf5nkMuthP2BTwOXYOo+TYmbvKukhJL8r0HIn3vH5Ods/MNxv8CJMlg vbVbAIF24vUFPtp1i23K6FskTS94kXD7utadoEvs= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kevin Tian , Lu Baolu , Joerg Roedel , Sasha Levin Subject: [PATCH 5.10 135/290] iommu/vt-d: Clear PRQ overflow only when PRQ is empty Date: Mon, 15 Mar 2021 14:53:48 +0100 Message-Id: <20210315135546.470729126@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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: Greg Kroah-Hartman From: Lu Baolu [ Upstream commit 28a77185f1cd0650b664f54614143aaaa3a7a615 ] It is incorrect to always clear PRO when it's set w/o first checking whether the overflow condition has been cleared. Current code assumes that if an overflow condition occurs it must have been cleared by earlier loop. However since the code runs in a threaded context, the overflow condition could occur even after setting the head to the tail under some extreme condition. To be sane, we should read both head/tail again when seeing a pending PRO and only clear PRO after all pending PRs have been handled. Suggested-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/linux-iommu/MWHPR11MB18862D2EA5BD432BF22D99A48CA09@MWHPR11MB1886.namprd11.prod.outlook.com/ Link: https://lore.kernel.org/r/20210126080730.2232859-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel/svm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 43f392d27d31..b200a3acc6ed 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -1079,8 +1079,17 @@ static irqreturn_t prq_event_thread(int irq, void *d) * Clear the page request overflow bit and wake up all threads that * are waiting for the completion of this handling. */ - if (readl(iommu->reg + DMAR_PRS_REG) & DMA_PRS_PRO) - writel(DMA_PRS_PRO, iommu->reg + DMAR_PRS_REG); + if (readl(iommu->reg + DMAR_PRS_REG) & DMA_PRS_PRO) { + pr_info_ratelimited("IOMMU: %s: PRQ overflow detected\n", + iommu->name); + head = dmar_readq(iommu->reg + DMAR_PQH_REG) & PRQ_RING_MASK; + tail = dmar_readq(iommu->reg + DMAR_PQT_REG) & PRQ_RING_MASK; + if (head == tail) { + writel(DMA_PRS_PRO, iommu->reg + DMAR_PRS_REG); + pr_info_ratelimited("IOMMU: %s: PRQ overflow cleared", + iommu->name); + } + } if (!completion_done(&iommu->prq_complete)) complete(&iommu->prq_complete); -- 2.30.1