Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3336404pxf; Mon, 15 Mar 2021 07:25:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK/9sOlO2SIp84hAaWAIMCq0OOZLPHl3iSCOgFrVtoevt4hwgUaSrmIteSdxyMTZGP7x6l X-Received: by 2002:a17:906:af91:: with SMTP id mj17mr23055800ejb.230.1615818301630; Mon, 15 Mar 2021 07:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615818301; cv=none; d=google.com; s=arc-20160816; b=MYmyhI0sij1t2arKJNjkf0s5KCY6n5Rv/hSFi7TM53eY1mZTLJVO4LO6kmyix1P0nL o5xblH0xnmK/uyqImhy7MBgDCRRKI2yCKlmFL9cqLit55a4/x+3KAIe1D6NRftMmtBbP DG3FpGBLqs7sR9FdyyitkcDSBk7IkUO3rLe1Aa/EwieiK4LPvGwmWSfiuyZMEgwqwY3C 8+CBmjT7TWZcR9WhF8Y1SIWaQO546XtBl6DCNjvu9BXw3y0y8PSdd1g3eTl4+yr0QuDj 01H6xoeB9DCcpwzf6GzN9L2MV/rvV71zrIQA3cqGKz9tH/xfVDY3h7/Zc70b0XZwu/Hm JCjw== 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=bVNutk7txP3IvFbJ3xoMtcEpMu92d5WBrR0rfh2dT7s=; b=1LvtVUisDxBUXefvApIEzTI3Cm5zBQSdnxZD0yEE55pBqaQknI8b5QxCduuJve+JDc +aj+QUFjovtZD0Fk6NbrMzWk57+psFFGyjQb8VsFxfVhdRXQXBZRXtcaLTL+ozJFHe3q IBB2CrT7RGr+04oq8d+T3iWkmobe7Tqp/sTfGSClWubLU8DoDyGC5TbcrvOwW4gqxqt1 LAU77qzGx87fjAZswPzV0N5X47nVF/o4tlcdaLisxowOgN8Lq4EJ/CZ2xhoSWWxdz+pF otUkbVJhlTpOWU+MOxs0eZCuvOVjU2ZEnVjNdOk5P7twz1O+7kdDWVWjCI1xoWN1vjY5 4siQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J0+i59yf; 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 g7si10951720edb.286.2021.03.15.07.24.35; Mon, 15 Mar 2021 07:25:01 -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=J0+i59yf; 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 S237902AbhCOOWW (ORCPT + 99 others); Mon, 15 Mar 2021 10:22:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232926AbhCOOAL (ORCPT ); Mon, 15 Mar 2021 10:00:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EAB3864F29; Mon, 15 Mar 2021 13:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816797; bh=fIp6IdXQAyyI0c+e1A99N7sVQg5EIe8/xZD5EV0ZVQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0+i59yf6nqilE8bpibNVdlIvgWR7qDsmxjmtE5XrNCeq/xVEfe5QQFq9dMS0koCa RP96P5byJauVhuUpyBmMeH5Qe8ekuxS4TbXNcRVDELfNqpa+8bVJysqJdIyU54Zw0z egMluj6Divr3+mhpbg89DtKKwuLnwz/OyM92e304= 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.11 130/306] iommu/vt-d: Clear PRQ overflow only when PRQ is empty Date: Mon, 15 Mar 2021 14:53:13 +0100 Message-Id: <20210315135512.047519645@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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 18a9f05df407..b3bcd6dec93e 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