Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1590220ybv; Thu, 20 Feb 2020 23:52:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwzChQcLgnsmpnxKpdEbVMHcZFU2vX9YoZA97rwlTWdpZ5RLhzVoHWQkxQmiBKNUBZ9lvD6 X-Received: by 2002:a9d:7852:: with SMTP id c18mr25835158otm.247.1582271535943; Thu, 20 Feb 2020 23:52:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271535; cv=none; d=google.com; s=arc-20160816; b=vuKmncdo4G5dT2Jt9KYoKu3lpcGtkdMZzAFk09onj20LCUyElwAoMrkk3r/pWGGq1C TrSqazovfT4EzjRHQHozSCrr7zrbKPwdG7LRttux5sFl++r+n5zlNoWsefB2IEL//C2Z SlS57ZScQc2RuEhEeTnMaVfjvDr4doOpyPOadQe4tg94YnK1+Tj4sXcgCmSnyevNJrjj xFkY6Q6kqkSt4MJN96xqW4vFET6DpchdGJGjX9IRerADYw/fiu5j67Kohi1XM7zqrLFH 6T3X66A1Vmxht0tx2M2mh+rTBg5+obF+LaMhOB+b2SDTjFBcYanDJ0oV65Km4TYT35Oy oj3w== 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=W33eMnpzgl0PyQSsJFF5vQvVfasDXR0J8ug6dvDW2e8=; b=tZ51BY0OM9FNYswRF9lwf6Yw65PXISBR4XXs8Ew+N3rLgkE3yPnO2vnyxoTV7OjxR+ r5ZFuy5oKJiFzH4sWT02eixc/XDfgBgIOmkJ6fn8I7Pv8fAuSeijO3PZ2GZ/QV03DCuJ V4lCLsAy7YNvKA3DvMDxar/bpRFCkwLRvwNz7aNq3ScpYi9htBNoyCeKXZBhyccQp52j kkYW4MuOIJPvBrM+sDnE/3FVwbcBUKhVhN7qififPZyZ/mTZCPpC+Sl6++d7Caf0NIOq nag/eNCs99GiGxBUcNRKRmr0a8SVcNNluqZJ/21LjWgs9Ze/SkXbfM/B1TEBi0wp9w1Y 71Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="gTLPKGl/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si81333oij.275.2020.02.20.23.52.04; Thu, 20 Feb 2020 23:52:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="gTLPKGl/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729698AbgBUHvM (ORCPT + 99 others); Fri, 21 Feb 2020 02:51:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:48358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729688AbgBUHvK (ORCPT ); Fri, 21 Feb 2020 02:51:10 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 4F8E324653; Fri, 21 Feb 2020 07:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271469; bh=uGPoaQq5sIQF55e4UpMPnmFtF7DSigxvWVTWul9hHJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gTLPKGl/GrOdhnCjSGY7sO2TNg19ZBjJqMA087T9Lier+urJisSuSSnmrV/QLJPfu dEV9F/K9F3P9/JE0uG4vgdHueO3cjCXAMDTeW5ZcVwXwuL6ryoeibreJgux8q/rZ9+ hu1xyNZI95HmD1ghpsslJH6HcAE4psPmOuW53Lh0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suravee Suthikulpanit , Joerg Roedel , Sasha Levin Subject: [PATCH 5.5 178/399] iommu/amd: Check feature support bit before accessing MSI capability registers Date: Fri, 21 Feb 2020 08:38:23 +0100 Message-Id: <20200221072420.022833137@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@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: Suravee Suthikulpanit [ Upstream commit 813071438e83d338ba5cfe98b3b26c890dc0a6c0 ] The IOMMU MMIO access to MSI capability registers is available only if the EFR[MsiCapMmioSup] is set. Current implementation assumes this bit is set if the EFR[XtSup] is set, which might not be the case. Fix by checking the EFR[MsiCapMmioSup] before accessing the MSI address low/high and MSI data registers via the MMIO. Fixes: 66929812955b ('iommu/amd: Add support for X2APIC IOMMU interrupts') Signed-off-by: Suravee Suthikulpanit Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd_iommu_init.c | 17 ++++++++++++----- drivers/iommu/amd_iommu_types.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 483f7bc379fa8..61628c906ce11 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -147,7 +147,7 @@ bool amd_iommu_dump; bool amd_iommu_irq_remap __read_mostly; int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC; -static int amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE; +static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE; static bool amd_iommu_detected; static bool __initdata amd_iommu_disabled; @@ -1534,8 +1534,15 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET; if (((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0)) amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY; - if (((h->efr_reg & (0x1 << IOMMU_EFR_XTSUP_SHIFT)) == 0)) - amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE; + /* + * Note: Since iommu_update_intcapxt() leverages + * the IOMMU MMIO access to MSI capability block registers + * for MSI address lo/hi/data, we need to check both + * EFR[XtSup] and EFR[MsiCapMmioSup] for x2APIC support. + */ + if ((h->efr_reg & BIT(IOMMU_EFR_XTSUP_SHIFT)) && + (h->efr_reg & BIT(IOMMU_EFR_MSICAPMMIOSUP_SHIFT))) + amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE; break; default: return -EINVAL; @@ -1996,8 +2003,8 @@ static int iommu_init_intcapxt(struct amd_iommu *iommu) struct irq_affinity_notify *notify = &iommu->intcapxt_notify; /** - * IntCapXT requires XTSup=1, which can be inferred - * amd_iommu_xt_mode. + * IntCapXT requires XTSup=1 and MsiCapMmioSup=1, + * which can be inferred from amd_iommu_xt_mode. */ if (amd_iommu_xt_mode != IRQ_REMAP_X2APIC_MODE) return 0; diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index f52f59d5c6bd4..f8a7945f3df90 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -383,6 +383,7 @@ /* IOMMU Extended Feature Register (EFR) */ #define IOMMU_EFR_XTSUP_SHIFT 2 #define IOMMU_EFR_GASUP_SHIFT 7 +#define IOMMU_EFR_MSICAPMMIOSUP_SHIFT 46 #define MAX_DOMAIN_ID 65536 -- 2.20.1