From patchwork Tue Feb 2 00:00:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Filippo Sironi X-Patchwork-Id: 374566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE7E5C433E0 for ; Tue, 2 Feb 2021 00:01:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C03F164EDC for ; Tue, 2 Feb 2021 00:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230000AbhBBABo (ORCPT ); Mon, 1 Feb 2021 19:01:44 -0500 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]:42968 "EHLO smtp-fw-9103.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbhBBABo (ORCPT ); Mon, 1 Feb 2021 19:01:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1612224103; x=1643760103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wg30tc+SDviKzmp+OPI+dqgVAhbbf9XWGMgs51nNyrw=; b=SQu5UysTcVtbXcYqwqzbCCLd8PkRxycnVB2MHPQoknR8ZBEgQ+C0tFYu sEP4yZfzc+JwwATF0grXaXr4O/W/xZoBDHYKJJOnCbIdudt0nJLupFIMC IvSOCipjvCdZ5JvFz+l6hO9+GlnKM+AJC+AxbX2bqi2UCP7050TVHuN4Y 0=; X-IronPort-AV: E=Sophos;i="5.79,393,1602547200"; d="scan'208";a="914839182" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9103.sea19.amazon.com with ESMTP; 02 Feb 2021 00:00:56 +0000 Received: from EX13D02EUC001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com (Postfix) with ESMTPS id 2D63BA1D19; Tue, 2 Feb 2021 00:00:56 +0000 (UTC) Received: from u2196cf9297dc59.ant.amazon.com (10.43.160.67) by EX13D02EUC001.ant.amazon.com (10.43.164.92) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 2 Feb 2021 00:00:51 +0000 From: Filippo Sironi To: CC: , , , , Bartosz Golaszewski , Joerg Roedel Subject: [PATCH 2/2 for Linux 5.4] iommu/vt-d: Don't dereference iommu_device if IOMMU_API is not built Date: Tue, 2 Feb 2021 01:00:09 +0100 Message-ID: <20210202000009.31392-2-sironi@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210202000009.31392-1-sironi@amazon.de> References: <20210202000009.31392-1-sironi@amazon.de> MIME-Version: 1.0 X-Originating-IP: [10.43.160.67] X-ClientProxiedBy: EX13D21UWA001.ant.amazon.com (10.43.160.154) To EX13D02EUC001.ant.amazon.com (10.43.164.92) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Bartosz Golaszewski commit 9def3b1a07c41e21c68a0eb353e3e569fdd1d2b1 upstream. Since commit c40aaaac1018 ("iommu/vt-d: Gracefully handle DMAR units with no supported address widths") dmar.c needs struct iommu_device to be selected. We can drop this dependency by not dereferencing struct iommu_device if IOMMU_API is not selected and by reusing the information stored in iommu->drhd->ignored instead. This fixes the following build error when IOMMU_API is not selected: drivers/iommu/dmar.c: In function ‘free_iommu’: drivers/iommu/dmar.c:1139:41: error: ‘struct iommu_device’ has no member named ‘ops’ 1139 | if (intel_iommu_enabled && iommu->iommu.ops) { ^ Fixes: c40aaaac1018 ("iommu/vt-d: Gracefully handle DMAR units with no supported address widths") Signed-off-by: Bartosz Golaszewski Acked-by: Lu Baolu Acked-by: David Woodhouse Link: https://lore.kernel.org/r/20201013073055.11262-1-brgl@bgdev.pl Signed-off-by: Joerg Roedel [ - context change due to moving drivers/iommu/dmar.c to drivers/iommu/intel/dmar.c - set the drhr in the iommu like in upstream commit b1012ca8dc4f ("iommu/vt-d: Skip TE disabling on quirky gfx dedicated iommu") ] Signed-off-by: Filippo Sironi --- drivers/iommu/dmar.c | 3 ++- include/linux/intel-iommu.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index a5f69d9bb0b8..1b9795743276 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c @@ -1114,6 +1114,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) } drhd->iommu = iommu; + iommu->drhd = drhd; return 0; @@ -1128,7 +1129,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) static void free_iommu(struct intel_iommu *iommu) { - if (intel_iommu_enabled && iommu->iommu.ops) { + if (intel_iommu_enabled && !iommu->drhd->ignored) { iommu_device_unregister(&iommu->iommu); iommu_device_sysfs_remove(&iommu->iommu); } diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 6b559d25a84e..88ac8edf44e3 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -556,6 +556,8 @@ struct intel_iommu { struct iommu_device iommu; /* IOMMU core code handle */ int node; u32 flags; /* Software defined flags */ + + struct dmar_drhd_unit *drhd; }; /* PCI domain-device relationship */