Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp421347pxk; Fri, 11 Sep 2020 10:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCCG736Rh6XxDdHZ/5wQ/gQHnZMlbSUQdLcGArfuJfbiJznRk5rFjAG27GgtNSYspxYaIC X-Received: by 2002:a50:ab1d:: with SMTP id s29mr3435802edc.246.1599845061424; Fri, 11 Sep 2020 10:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599845061; cv=none; d=google.com; s=arc-20160816; b=Br0/1DZIjaFFrlrwEX29aQLE50s4cV7j686GG6aS97ImC7v6p9i0zy8uoGf+nuor9k 13B0a4CRJakgxHXhOAwTeNGufmI7/+9aSI0cKghaCOplx74IJI/znua1eaH/tZudlNcP xM5IXvRangYpM7/OIeSZR1ME4e4ivG+CtrIapk/dOtv85sMGRGW/f9UOqd8iYPGZ31Ue V1fp6rvE4jTZPM+Glgdl1X+t5iuPcDZR5UxN2P+O7oI+w1on1mG5kMGODviq5Ml2zgvU yoVsloZFG6e6KBbSjr9VSPYjAMQ6YYnhMauptXNKhI2PkEFnP/y4TA0gYT0A1i5JKtWq ez8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/zH5dA+3n7li8/P/A1qqdZlqYcap/WH8un+QyjjhqCQ=; b=SeeaWhfpgk71sYBPujpSWpsjdsKejsXmdLNJiT2LnXccpphFMbEhdKYKiNZbzM8U3C EIjM19LuToLQTmEuXrBuIvXzDtCYzt7P7HlWjV5qG82h8UVAkFEbg/mBpFyRFRBdcEpQ DnnIJPJrsCMjmYb8Ku7SWEF5RdjurEya3CmSCaX0E497tOnP+r735Nt9LeaUPIGB5HnE lWvNLOXbevFcWxwHIWaJYawPacqTKOupSeGrhnRhCIcdc4G+Sj9KzzLwC4FyKmjdbVmw W4miHPfRnM00CaZe1whs3QT1BpmorlRnA4jig2qEX6+xGLOsaeDXQFOXQF6IJE/9gsti 6NRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NDlaiks1; 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=fail (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 t12si1908107edc.174.2020.09.11.10.23.58; Fri, 11 Sep 2020 10:24:21 -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=@kernel.org header.s=default header.b=NDlaiks1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726416AbgIKRWi (ORCPT + 99 others); Fri, 11 Sep 2020 13:22:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:52820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgIKNAL (ORCPT ); Fri, 11 Sep 2020 09:00:11 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6F43322274; Fri, 11 Sep 2020 12:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829000; bh=nCJ/LEhl7wKjpj2NUqkEt2s1w9T0+lXZhzCNOn9f6bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NDlaiks1+CAG+F0p8o5AZIuGGK5UoFPvcLE3QNz7JdJmlesny/lbaEY27SPU7dR6j fcrnfZPIwKTUCCNxlM8Ij8qJPRW8+VSluKkdGsBovlnLLJO5ZikskP5KL1N1HFdxdA 7xkCK/KyRLtq2+dMhXXAvCUPjZdCU2DEABtT6jPA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lu Baolu , Kevin Tian , Andy Lutomirski , Jacob Pan , Ashok Raj , Joerg Roedel , Sasha Levin Subject: [PATCH 4.9 26/71] iommu/vt-d: Serialize IOMMU GCMD register modifications Date: Fri, 11 Sep 2020 14:46:10 +0200 Message-Id: <20200911122506.238456130@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122504.928931589@linuxfoundation.org> References: <20200911122504.928931589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lu Baolu [ Upstream commit 6e4e9ec65078093165463c13d4eb92b3e8d7b2e8 ] The VT-d spec requires (10.4.4 Global Command Register, GCMD_REG General Description) that: If multiple control fields in this register need to be modified, software must serialize the modifications through multiple writes to this register. However, in irq_remapping.c, modifications of IRE and CFI are done in one write. We need to do two separate writes with STS checking after each. It also checks the status register before writing command register to avoid unnecessary register write. Fixes: af8d102f999a4 ("x86/intel/irq_remapping: Clean up x2apic opt-out security warning mess") Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Cc: Andy Lutomirski Cc: Jacob Pan Cc: Kevin Tian Cc: Ashok Raj Link: https://lore.kernel.org/r/20200828000615.8281-1-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel_irq_remapping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c index ac596928f6b40..ce125ec23d2a5 100644 --- a/drivers/iommu/intel_irq_remapping.c +++ b/drivers/iommu/intel_irq_remapping.c @@ -486,12 +486,18 @@ static void iommu_enable_irq_remapping(struct intel_iommu *iommu) /* Enable interrupt-remapping */ iommu->gcmd |= DMA_GCMD_IRE; - iommu->gcmd &= ~DMA_GCMD_CFI; /* Block compatibility-format MSIs */ writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); - IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, readl, (sts & DMA_GSTS_IRES), sts); + /* Block compatibility-format MSIs */ + if (sts & DMA_GSTS_CFIS) { + iommu->gcmd &= ~DMA_GCMD_CFI; + writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG); + IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, + readl, !(sts & DMA_GSTS_CFIS), sts); + } + /* * With CFI clear in the Global Command register, we should be * protected from dangerous (i.e. compatibility) interrupts -- 2.25.1