From patchwork Fri Jan 12 00:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1803848dyi; Thu, 11 Jan 2024 16:08:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMthAw2gVM0/6k+V8Mycsweri39lu7op1CPWtOy9/f1lmZRxn9jWOTDLszf+3sReDXRwIi X-Received: by 2002:a05:620a:4144:b0:783:2a99:1a24 with SMTP id k4-20020a05620a414400b007832a991a24mr670494qko.98.1705018127582; Thu, 11 Jan 2024 16:08:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018127; cv=pass; d=google.com; s=arc-20160816; b=smaiHk95XHhCAwTUcI3Y4/UTwmslsjGlaoROZQla6LkygWic1LxHlE0lIwZWdZSqSI y1V8EAAb6Gx3Mq93pFubZvax6kudIAVlcwlquXZ4daILnRMPLCtpNeTSqyu2lzx4mQm3 N0T73s1+lWPsgheSxAXsV2exrmkYlrfZ4hHwlf6ZDD74zkX3yM+rzggyKl1K2d9lozFP M8/f96+nTD5t4ylmU6KpiFYJR2DOHnHNda8zCFNlDreUp1o4wgo5nmThhe/GLQIMiX/u SrJGZdCb1RvcqCxvOj7v3J2h8cO2H0BI7UeJ3RMPPFQQyGzJLcKFoqfWJchMsby9TpEw xN4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=//YdT+7tyguq7bE9Z/ENbW5plhkXZTzu8xe/E/1DUDA=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=E6Sx+13z96sRd+1ZYSkSWFFCKfTwlngVjfPSMPSPKlkQTIt+vzRybCYkyKViMJSAds 2xRBmjKAXtfUm4n8fVihUopCiyPP0vsjZJMvlxBLywYTr3Ia5h98Ai+7JLikR8KIY95k iqU0NM6SZOu61nlMhZ7iS2i61QSKHFS6MdfWxvCUu3F9yBFR8XFDh2yBkgoe683u48L8 LXsi83lnxBhjeso4Ffd1Lfe/7nkFTBnlJZdPZdBX+ZJ6+0luJk6CgSXkVdz4uTwNQcOX rgH1lrY5sA8ZKl9xRe0U0FccQMz6NzFs+fFAXH8IvYBfhrJBPzcEveEb7BYC4qfX72qk oAaw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=SP6mNu3T; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24165-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24165-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b16-20020a05620a04f000b00781cc3f5103si1906058qkh.511.2024.01.11.16.08.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:08:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24165-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=SP6mNu3T; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24165-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24165-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 519621C23E0E for ; Fri, 12 Jan 2024 00:08:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75ABDF4F4; Fri, 12 Jan 2024 00:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="SP6mNu3T" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2057.outbound.protection.outlook.com [40.107.223.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AD22ED5 for ; Fri, 12 Jan 2024 00:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bTlsB8BWDBQgJI6AUcyv0AvWDaRn0tsy7Rspr9OUN0z1qyZ8Mkl1JcYb9Y5LyYQY6LjZ11pt03YtGJVtCg1ppSK4enVxq6BqgOu/0z3NkXmtn9Kt1dksFCtkk4tR4MW/ZXCNBDLy91zBC9Y0T4OO0NFvybd+ztOQRzaiG/t1o+brA/1T9v+xmsc0V3dzqFhRS1KfXHFeyhYNirJCOXCOiQn/JKdXHoVx5WEMgXOD3syDwa3j1zkRa/u2+4RdyMW8lUPLw7vdBrGPA7mp9jK0Vr8+w1WUXYGqJ5rIQ0eQQxizBGM63jv4aPoTcI9xk41iHRFMZAulBIoUXs4mGgD8VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=//YdT+7tyguq7bE9Z/ENbW5plhkXZTzu8xe/E/1DUDA=; b=lcbLxVwMH5rpSbB9aFEM4qWWqh7emxwxqCaEWGfLHQ5SeWTq+I2zDsc9NewDONwN90WZVIj6cUAC7dknZrXq+ooasl6yho3sG5koP85CBYVBaUTH+bbAOiwp7ZX47JW7NgG5OL3/jlgo2uo2Hcqj9Pw5J1b0c5tpeVY+2+v+6F2xrjsAS2HZ/3H9zY6J5sDzharrpcXuF/jfFgzp8ZBnPGclHJqzyYAJbcl/0dxUKGUaCqcZZ1+HB8ejvB3eRX1wZErMBSMD45LIzN4FR4lMNOQbHOtJP4gYLPiIIn6feTi8Ik2XcK960GdRyrYswOuIbo1oPvNIx4oKuhow3S6P0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=//YdT+7tyguq7bE9Z/ENbW5plhkXZTzu8xe/E/1DUDA=; b=SP6mNu3TBnUplY3SRGRmAaKpiRQO4e7D6h7qLxeqnAOepoqTBY4B+tldymvcFkKHka41z8YwSyeSScF/oPwD0+oq5in3R7cSb8ltJB7W1FZjg6xVilJwTWQb2+hy2jqc0sFdI03xA3SO+7Xw2csdirQ2e8/03cxblq6DWQsj8dU= Received: from MW4P223CA0003.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::8) by PH0PR12MB8049.namprd12.prod.outlook.com (2603:10b6:510:28f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19; Fri, 12 Jan 2024 00:07:04 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::1c) by MW4P223CA0003.outlook.office365.com (2603:10b6:303:80::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19 via Frontend Transport; Fri, 12 Jan 2024 00:07:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:04 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:01 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 1/7] iommu/amd: Introduce struct gcr3_tbl_info.giov Date: Thu, 11 Jan 2024 18:06:40 -0600 Message-ID: <20240112000646.98001-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|PH0PR12MB8049:EE_ X-MS-Office365-Filtering-Correlation-Id: 178e9bbb-2145-4c80-3818-08dc13026861 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AVBuLjj4Z+v8vaFY9p0Tgc7p+1OQ69LTDK1DrS7COoTXXgb4HinaZ6VSHJM29i5iyWm2X3s8L1Q/weAGYRUTUyYiS5NJLx1g7C0yisOi3hm1KhxHGdfNzP6mJ4YPpbrjfGklyImutClvgUjwihXIZuwhbYwzEOzOUyeYIANVu02xAyQriqwG6XPmnfjDMmrvknsVnnwv5kcPTZ58ZHJZQB/x68H71EcmpoQrx+PMXpKx/gdzETWfO9wu0pGQWJV81ecYb/9MHGW9xf8lRoWiPsqktZ6n813a9XuO4a7UKPgwcVJoV/thujKDUB/eu8uFwipzjOPvrgExOT4NDmR2Qhp/i9OEfh3QYXeFeIn3rrm01HVDQIXyhiiu4SiQArYqowSMwAdyHLJtz+tZksDWriqlpM5bzmnlQ9LmHhcwHxey8TEg2iEtO2sxVkwomRu61bRl1XifLKxf/Sgxni/L9OIOJ2K3FwQXbU09+iYHV2Gqj6vwlm4hYuenIidvBkVZfvttsQiabCXZZq777PArowN3+Xu3E49jYJnDjpBkz6XmTTN3jEfXvmNy0IS5ni8xXR6uUM0i/Gpf8txZ8tVK+ankQoMQVRIKQCmLYa7MB3B+yx5M9FdWtkD2AakL80KcfkxUtl3tGYcavmIoKSYcKtZPLt3fcWtaBKqolL+9Iy7iyN1U4H6FMGwt+HOYT5kb52faBNVqHLs3y0HbJ+PxFp+tGijjvGoSQ7W/ccqqeYlHnGQ9Mry8gdh0lAsmZMviR4Qf67vn6QeyrtkkeEqy3SJarQGKG4vU3unUzmxC/Tw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(136003)(39860400002)(376002)(396003)(230922051799003)(82310400011)(1800799012)(64100799003)(186009)(451199024)(46966006)(40470700004)(36840700001)(40460700003)(40480700001)(47076005)(110136005)(81166007)(36756003)(356005)(86362001)(36860700001)(8676002)(4326008)(82740400003)(83380400001)(1076003)(2616005)(336012)(26005)(5660300002)(426003)(16526019)(54906003)(478600001)(6666004)(316002)(70586007)(70206006)(41300700001)(7416002)(2906002)(8936002)(44832011)(7696005)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:04.0425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 178e9bbb-2145-4c80-3818-08dc13026861 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8049 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841088444699358 X-GMAIL-MSGID: 1787841088444699358 To track DTE[GIOV] programming during IOMMU domain attach, also add logic to determine if the GIOV is required, and set the variable accordinglly. This is also a preparation for adding nested domain support, where the GIOV setting is determined by the child domain. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/iommu.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 3dc39bbc05fc..ff56c857f6ad 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -536,6 +536,7 @@ struct gcr3_tbl_info { u64 *gcr3_tbl; /* Guest CR3 table */ int glx; /* Number of levels for GCR3 table */ u32 pasid_cnt; /* Track attached PASIDs */ + bool giov; /* Track DTE[GIOV] */ }; struct amd_io_pgtable { diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4e4ff1550cf3..b9759f6d8be2 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1990,8 +1990,7 @@ static void set_dte_entry(struct amd_iommu *iommu, ((u64)GUEST_PGTABLE_5_LEVEL << DTE_GPT_LEVEL_SHIFT); } - /* GIOV is supported with V2 page table mode only */ - if (pdom_is_v2_pgtbl_mode(domain)) + if (gcr3_info->giov) pte_root |= DTE_FLAG_GIOV; } @@ -2067,6 +2066,14 @@ static int do_attach(struct iommu_dev_data *dev_data, free_gcr3_table(dev_data); return ret; } + + /* + * GIOV is required for PD_MODE_V2 because we need + * to support the case where the end-point device + * does not have PASID in the TLP prefix when setting + * up to use the v2 table. + */ + dev_data->gcr3_info.giov = true; } /* Update device table */ From patchwork Fri Jan 12 00:06:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1803715dyi; Thu, 11 Jan 2024 16:08:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkwJKuArf4Tr/smKcr9S93ftoatb9kJ+H6pogUER/n9ZG8BLT9ElJmX6O1mpBAUNZ5jpng X-Received: by 2002:a05:620a:b12:b0:783:3f8e:b437 with SMTP id t18-20020a05620a0b1200b007833f8eb437mr1077964qkg.0.1705018113555; Thu, 11 Jan 2024 16:08:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018113; cv=pass; d=google.com; s=arc-20160816; b=ZDW348oAFhNLstf+4z20VvE0WLXDEKKWmObbFl8n2D4QEW2SqVW9RM4Glw4/cBT0BK Jrtp2ecYkvdGL/ieudQjs1Efv/N89gQ44IAtMRzQ3cK8DmA2yBNh15bTSUu9I0nOmprr NxDxWTHGz4JwQcMRH6jsa3pxK6dSb9WX1uXgKfSEC84EsMpvQqVn2sVomOsDZUDcwWf8 Z1SORF9tvRRPBL0Cjekgij4MPkKOYiKOEqTtGcFyoAuhPUfqBcaMacSej2AM/t0Ib2kp Fl9+G93pj2n4yGu0uX5bFMjSEDRpvfo+5fRgOWqMAzWSuJre5wGzRC674X5pVBiN2nsP Ej/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FtNMXDQ/R1IcqkDmvWPHjjrqE7FMCvYBy+amnVhYPKE=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=FvHf5oyhcZk70rW0xxsb35A10o54E9jaB3BaptUwHqJ1HfaYaAl2EYzeQmVUoUFYw8 VyFa44IkpVypSiskR1Vww8B2WClCeZAoIVVVJpQDapFDSDdlccDsl1/75Tt8EisREs+Y 3P74vx8Qw9G/e00zjx+HSgyqM/+YldB25OzIrEuD2BS34snZ6Oo04UNJasvHnMF/35bF wCWMF64cT30KXiGmbRMsn93uS25Qruv/5uUZlk7zYFmM4zbNKStdWrztt95Gz+IKS+Qa PtHIx49saMm9FlAYRZ0/E6Gr0DkfEE3SxFl0B0unZtRHE4plN4il9UfcoWPRFVnMPwPW pXNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LffQBZQJ; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24164-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24164-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bl13-20020a05620a1a8d00b007833a984b49si2114859qkb.305.2024.01.11.16.08.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:08:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24164-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LffQBZQJ; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24164-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24164-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D7641C23E87 for ; Fri, 12 Jan 2024 00:08:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD5F6C151; Fri, 12 Jan 2024 00:07:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="LffQBZQJ" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2054.outbound.protection.outlook.com [40.107.244.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9CCA7F2 for ; Fri, 12 Jan 2024 00:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lExFJLd153+gsmdYO8p1jW8rlljHEPSEXMR/eoN8xgPua8oen9U9p4nLb93XZMcvC9DBp/imPjrbAOakLP4OK/gpLK5IyTNBr/Uugb2duCf9sMh8Ijpp44hJzreL4f8dZnjpJYke6/RbufZxiP5pRAUXD/nodgc/zTbonWiC5ymRyeQG3fukhZG1widonf6NnU3SGkuDluBJjDNJGR4APvxPiXqSeC4EpTV16Xx/0Sin9p64/7INAynbX9HEZESV2qW7bjsRznBfFd2G+AdBZDTVt12AJNbLSTn9ksUZQpB0YQfYlIYK6NFJn4tHgadfwixrPzkav94Pip4EquJlTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FtNMXDQ/R1IcqkDmvWPHjjrqE7FMCvYBy+amnVhYPKE=; b=ShfICYf1X/1ZYuF0lhdeQE6jNAveB49QNRYBvhEBg051IjxPiyEGGjW8wW71V3rTzOpLrQxdxR/OO53Iem7ie1WxnOFibOxqZifHh6tEDjlk+yetrTHWyCRlQ9X4++H1tzn1S2hEF7WmfDWRMZd2zwfEb1LJNGFUPfCKcb/KyG0o96guKWEomAAUYAacpNhIRqiwJy7M3OkSELJNWP28o8AzsVBmRK9ScN3BynxYiCEd6sqB6Bee6avv5iDx7GY4KEW8L4lRKc4lfxR5ed15y0HpfFmdfuV96Hk8Yl/R3pNpP9i9KaQU1OAGSrSXHDoa5TXc0zyg/ymbf8NuHP/qAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FtNMXDQ/R1IcqkDmvWPHjjrqE7FMCvYBy+amnVhYPKE=; b=LffQBZQJUpqFAH4TO3cRL52EhjsY4f0y/4dMaLWxjVcIdHQX3bWAOi6hxn8rfE4SJmD33htvHnRnvGcX0W4uV9ujTc2Rh3zF4yKh7AU4XPFnKv65OUjcB45DLSyAua4S/5wRv6ygmXnOgkJd4CbGx601f0vL4dnQ2kZdAHcPWvU= Received: from MW4P223CA0024.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::29) by CH3PR12MB7571.namprd12.prod.outlook.com (2603:10b6:610:147::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.23; Fri, 12 Jan 2024 00:07:05 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::ed) by MW4P223CA0024.outlook.office365.com (2603:10b6:303:80::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.18 via Frontend Transport; Fri, 12 Jan 2024 00:07:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:04 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:02 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 2/7] iommu/amd: Refactor set_dte_entry Date: Thu, 11 Jan 2024 18:06:41 -0600 Message-ID: <20240112000646.98001-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|CH3PR12MB7571:EE_ X-MS-Office365-Filtering-Correlation-Id: e163f7b2-019a-45ac-f6f1-08dc130268e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hzCswMhRPSy+4tCFuL6+rn06T/+4FBX9a7991uYiCX9awQQYmOGUVyYSV04xPIdoeLlaiI8S/1ZQV8BTyr7HGecINIkWBbLtTY4dYeoVwEKnrhHgiv8DmpBA7fGnjbM9g6ijOBu1scySXOQOmXiONvnhhmcDsQwX/AQaajepafgo1AOEhAwJ+WUZxOrgqTaGq+KP0pO+5JoPoJbCRFOUtL9pCAmpF1/smH5nH3eWYFPQMtL2Tn5XSyQ4qwD6lMyUMRRkhC3HPnNoO+VeKWOjgpFj+fcWRTzVFybLEHrZ0BcOEn8o927LCwN8qMqPcNTkRBvmthY9mwJoLdgfmnHWiX27XO0J7eTtLIt9Fz6ka1op3H+zFGXfzLibvYbKKtnDZvEOI4SW55Yx/OFwCuP/Eo+K7R8BjSJl69y8S4+fLMUOuNRgQkzM4SU3IzNls1gdddB6bV4leqeD4ycq63rEuH6BKsHHjGbl23qCa7vsyuU977xAsJX9Zni8qVThEoWxtVhcJppkkClvwkzfbrOXW+490CP3g9lPW9UNnFshaVq51y5k+KYseIrrpFkM7Pjxg5ZA3DUyajjblWVZRMi+P3NCOOjw7Uw8AdhcHjA76k0HcLY3sYkt5+b6Tei1onIGE3ia7Uv6prykjxt/CToiXZ5w5NG8goPcG7IHcZ95VD6FoVlWp7fCqRT4+86lT+pndwp55u3ysXqwm86bU1sA3Vl9TlSeLj3EzhGVN27SLTw46NS+UDVbKZXcd1z6gqjrgzP/wrr+5IAQxLNB8WMwMUuQl3uz2LWiXHqeE7XSHWs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(39860400002)(346002)(136003)(396003)(230922051799003)(451199024)(1800799012)(186009)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(36860700001)(7416002)(478600001)(6666004)(5660300002)(7696005)(86362001)(41300700001)(2616005)(8676002)(316002)(110136005)(70586007)(47076005)(8936002)(54906003)(70206006)(36756003)(82740400003)(26005)(83380400001)(336012)(426003)(1076003)(16526019)(356005)(81166007)(4326008)(44832011)(40480700001)(2906002)(40460700003)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:04.8863 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e163f7b2-019a-45ac-f6f1-08dc130268e1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7571 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841073513170652 X-GMAIL-MSGID: 1787841073513170652 Separate logic for setting DTE[GCR3 Root Pointer Table] into a helper function set_dte_gcr3_table() to prepare for adding nested domain support. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 124 ++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 52 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b9759f6d8be2..71099e5fbaee 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1917,89 +1917,109 @@ int amd_iommu_clear_gcr3(struct iommu_dev_data *dev_data, ioasid_t pasid) return ret; } +static void set_dte_gcr3_table(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *target) +{ + struct gcr3_tbl_info *gcr3_info = &dev_data->gcr3_info; + int devid = dev_data->devid; + u64 tmp, gcr3 = 0; + + if (!gcr3_info || !gcr3_info->gcr3_tbl) + return; + + pr_debug("%s: devid=%#x, glx=%#x, giov=%#x, gcr3_tbl=%#llx\n", + __func__, devid, gcr3_info->glx, gcr3_info->giov, + (unsigned long long)gcr3_info->gcr3_tbl); + + tmp = gcr3_info->glx; + target->data[0] |= (tmp & DTE_GLX_MASK) << DTE_GLX_SHIFT; + if (gcr3_info->giov) + target->data[0] |= DTE_FLAG_GIOV; + target->data[0] |= DTE_FLAG_GV; + + /* First mask out possible old values for GCR3 table */ + tmp = DTE_GCR3_VAL_A(~0ULL) << DTE_GCR3_SHIFT_A; + target->data[0] &= ~tmp; + tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; + target->data[1] &= ~tmp; + tmp = DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; + target->data[1] &= ~tmp; + + gcr3 = iommu_virt_to_phys(gcr3_info->gcr3_tbl); + + /* Encode GCR3 table into DTE */ + tmp = DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; + target->data[0] |= tmp; + tmp = DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; + target->data[1] |= tmp; + tmp = DTE_GCR3_VAL_B(gcr3) << DTE_GCR3_SHIFT_B; + target->data[1] |= tmp; + tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C; + target->data[1] |= tmp; + + /* Use system default */ + tmp = amd_iommu_gpt_level; + + /* Mask out old values for GuestPagingMode */ + target->data[2] &= ~(0x3ULL << DTE_GPT_LEVEL_SHIFT); + target->data[2] |= (tmp << DTE_GPT_LEVEL_SHIFT); +} + static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data) { - u64 pte_root = 0; - u64 flags = 0; - u32 old_domid; - u16 devid = dev_data->devid; u16 domid; + u16 devid = dev_data->devid; struct protection_domain *domain = dev_data->domain; + struct dev_table_entry target = {.data = {0, 0, 0, 0}}; struct dev_table_entry *dev_table = get_dev_table(iommu); - struct gcr3_tbl_info *gcr3_info = &dev_data->gcr3_info; + u32 old_domid = dev_table[devid].data[1] & DEV_DOMID_MASK; if (domain_id_is_per_dev(domain)) domid = dev_data->domid; else domid = domain->id; + /* + * Need to get the current value in dte[1,2] because they contain + * interrupt-remapping settings, which has been programmed earlier. + */ + target.data[1] = dev_table[devid].data[1]; + target.data[2] = dev_table[devid].data[2]; + if (domain->iop.mode != PAGE_MODE_NONE) - pte_root = iommu_virt_to_phys(domain->iop.root); + target.data[0] = iommu_virt_to_phys(domain->iop.root); - pte_root |= (domain->iop.mode & DEV_ENTRY_MODE_MASK) + target.data[0] |= (domain->iop.mode & DEV_ENTRY_MODE_MASK) << DEV_ENTRY_MODE_SHIFT; - pte_root |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V; + target.data[0] |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V; /* * When SNP is enabled, Only set TV bit when IOMMU * page translation is in use. */ if (!amd_iommu_snp_en || (domid != 0)) - pte_root |= DTE_FLAG_TV; - - flags = dev_table[devid].data[1]; + target.data[0] |= DTE_FLAG_TV; if (dev_data->ats_enabled) - flags |= DTE_FLAG_IOTLB; + target.data[1] |= DTE_FLAG_IOTLB; if (dev_data->ppr) - pte_root |= 1ULL << DEV_ENTRY_PPR; + target.data[0] |= 1ULL << DEV_ENTRY_PPR; if (domain->dirty_tracking) - pte_root |= DTE_FLAG_HAD; - - if (gcr3_info && gcr3_info->gcr3_tbl) { - u64 gcr3 = iommu_virt_to_phys(gcr3_info->gcr3_tbl); - u64 glx = gcr3_info->glx; - u64 tmp; - - pte_root |= DTE_FLAG_GV; - pte_root |= (glx & DTE_GLX_MASK) << DTE_GLX_SHIFT; - - /* First mask out possible old values for GCR3 table */ - tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; - flags &= ~tmp; + target.data[0] |= DTE_FLAG_HAD; - tmp = DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; - flags &= ~tmp; - - /* Encode GCR3 table into DTE */ - tmp = DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; - pte_root |= tmp; - - tmp = DTE_GCR3_VAL_B(gcr3) << DTE_GCR3_SHIFT_B; - flags |= tmp; - - tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C; - flags |= tmp; - - if (amd_iommu_gpt_level == PAGE_MODE_5_LEVEL) { - dev_table[devid].data[2] |= - ((u64)GUEST_PGTABLE_5_LEVEL << DTE_GPT_LEVEL_SHIFT); - } - - if (gcr3_info->giov) - pte_root |= DTE_FLAG_GIOV; - } + target.data[1] &= ~DEV_DOMID_MASK; + target.data[1] |= domid; - flags &= ~DEV_DOMID_MASK; - flags |= domid; + set_dte_gcr3_table(iommu, dev_data, &target); - old_domid = dev_table[devid].data[1] & DEV_DOMID_MASK; - dev_table[devid].data[1] = flags; - dev_table[devid].data[0] = pte_root; + dev_table[devid].data[0] = target.data[0]; + dev_table[devid].data[1] = target.data[1]; + dev_table[devid].data[2] = target.data[2]; /* * A kdump kernel might be replacing a domain ID that was copied from From patchwork Fri Jan 12 00:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1803477dyi; Thu, 11 Jan 2024 16:08:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnL2hcDjBgRFBb/EZkmLbN4uukPao8bRCOT9iRVs2PkKJFdlVIcGhLy6R0aoViUjivgg6s X-Received: by 2002:a05:6a00:1312:b0:6da:b57f:d4d7 with SMTP id j18-20020a056a00131200b006dab57fd4d7mr112880pfu.35.1705018080193; Thu, 11 Jan 2024 16:08:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018080; cv=pass; d=google.com; s=arc-20160816; b=NydUXR3fODyFPkJDni2Eq4ZJ9zqIp5vNInIXpjulMAEKCgcqTPa5G1ZjDsXf01jm2l irfiDt29wEXnpxtCFRHAJQ79BYLyk/7/WRHqyJn1p6uTgqto6Lr6TLvkNdKZww9YD78D GXktMh6wHgqOcyQql7bJWFaBF7hWkWSESqjUQcI5kwkuI+koe3CEmie29n2RnosDGlE3 A1kCfaQuTKGt4mtE+pmWNGC1SX4NFnF++MtL6JkT1rpL/SzIH4y/rDPMYmJlkzDodxMB t+etMEROKvog7MbWfmzlp4mqzYI3aOmOQeTrFHcA/2dNl56fvS+P1EDf6IvjJvShj/pE FwXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+Y8nEdtKzpA8yEZ1sXPkwkN3aTjYmrgaBdWlI8n1g3o=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=XK2+kWps6KHtBfa8NJ7vQu5atSAZt8WRYR5wyQD43akF5CbqxKel3KMnhqE2eKrfUW YaODqJ+9LNLQpfZcqtkqu8dnVOTmBzSvsMF14FcwDbpWsuqPlsfDPSrpVoin1lhDMPCt khBxLdhJ9bCCJvhd8uRL3vArwOT9e7ypefrcioQ8CM9QTk+xPhP60HiEGO9637UKbbsy 8AjPHSOskNkze0XCU29vkdpwO/Cw60iiYOReyJipuMRBMI5lCgF6Ml84RdF1R3kYsJ5p 7ypp//aCxBADnDc76ZTks+qWHS5XrTJ31+tG2BMGIfs8SzbgoOa49Wm5fxbDgcuu4tUv gYIQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=ju+jo7Ib; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24163-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24163-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lp9-20020a056a003d4900b006d09859390bsi2158872pfb.16.2024.01.11.16.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:08:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24163-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=ju+jo7Ib; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24163-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24163-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id ED5E22867AA for ; Fri, 12 Jan 2024 00:07:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3D0B291A; Fri, 12 Jan 2024 00:07:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ju+jo7Ib" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D19A464B for ; Fri, 12 Jan 2024 00:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MR5EXCj1VxOCoguKeDVOmo6JkQwpwVAIKNpESdnER8EMy6M6nFem5tPKHYsKxkHEZD+UfMQ09BgYZ9Vwg5/yxjfl4/kc8kxNGIvkX0T0DXowogDND0CL049xGuXnFFql3hm+rN5DgMLkMdEYYcTaT1QAexxUNIdBYIzHyppCiqRxhhsnCja484MBkksbdlByqrVibqw1t09cfzLHRFRxM4Tbyu9E5VKdoQfrN8o8xiwPH3MDysmzyE+TRY8jfE/SmfNGNp4ZbXx8eW1xxOm++ihPG+d/DvAlDSOnYEe1FaoyWWzSEheiDBOaEsk5JFcR+PKJVq2OAz5pl7fl0EL/Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+Y8nEdtKzpA8yEZ1sXPkwkN3aTjYmrgaBdWlI8n1g3o=; b=kbr915yLcGj57hM1sJ4dyiHz2EWfu+Tu1+qV/jUXrxmdD+KS8OEZmNyi+5vfqTXnW63Q+KAphlnRw0YrubHhTE4xShEYBc1GtS7iUn7KbU10gY1mH0+lv2k18OKvtg4uPtwCcjgV5j+/uqwobZ8upZyYOSlu91NI6da2o4hCwm8d7I9XHEbCbkFekhH6GI1Fxe0NSs3Wrp4OaBK3sizAYrBlfwNzvIKBw/i+E9tzJ69Ee1vxsQa+w4o2AsamXlNpBhLtMTR3GQtnokopZroyyEhtTC8bxu/eDXIpAhX03XQa38KxhbUWQYEeKTc8M8oArWewPvHW0uxFrA/Kozl4KQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+Y8nEdtKzpA8yEZ1sXPkwkN3aTjYmrgaBdWlI8n1g3o=; b=ju+jo7IbaNvw+6mc46xaWcNBEtPqDC4gpHEDH7D2Y1MIrRcES+/zEZ+syvL/uLQ1prJsfLsaqghcijpEUQJlcYdBkjmF72G82HbF61KMW6zQNjKblUpJAL5uFcc5l92VErG7soacgBc+WHDZZlabua/YAOl+aMx11cZmu32Sj4k= Received: from MW4P223CA0022.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::27) by SN7PR12MB7449.namprd12.prod.outlook.com (2603:10b6:806:299::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.18; Fri, 12 Jan 2024 00:07:06 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::c4) by MW4P223CA0022.outlook.office365.com (2603:10b6:303:80::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.21 via Frontend Transport; Fri, 12 Jan 2024 00:07:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:05 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:02 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 3/7] iommu/amd: Update PASID, GATS, and GLX feature related macros Date: Thu, 11 Jan 2024 18:06:42 -0600 Message-ID: <20240112000646.98001-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|SN7PR12MB7449:EE_ X-MS-Office365-Filtering-Correlation-Id: ba335f5c-149e-457e-19f9-08dc13026946 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bv7sQ8HdMpiN6KH3UajU+7r1lwU634CIu26GqOmMraipedjk3uQZC20ORci3YPutGSixr1F1d62QplnW3+uhSYt1cx3ih4WCosmbDUDr1QDclGxFrf7OhX1Vy6SbtVdL5v0bFcqsFyd/jp2bUw6bRZVchaPXhZN0g7W687nYX4EjuhAWm2eARzNRK+XT2EaTl1PpIWGSQK9hLekzepkvO7oNzeQhoWIo87zzb8aWwNblTKjrZK6edfFXoAwb3cxX1jKx/1G2irH2hg82Fhv0rSvG4L1hcFUsXa+b/zMFrczsq8aCMjUtOpdJslfHnmMY7sA2ngIEffxCrGRfzCvjnrY1OvtsUnpNuZRfM0NRDqcMpziliVKJUqmBgIZ9dntLSLYUkQAANbo0NhILRXfTwPzTdw/CU/lW6jCm5yNs2vmLShG9dk7MPZWqGnsocG6Ocot4SmpRqWGUynw0Gm66znloKDWVFJoZESGMePY+481UCSSIdQVSi/yxqi5t5Legphfc9HTjWtXpLI06CprIGozjNKTQePXjaKdrIfUcLrwcxhPBOLov2hlGKDxWMitOoQCLRF8x2nd2IzYeSDBqvqU9YoZK3AIEIEKC1ScNF+zW+xR6uToaiQ3p0hU1jPNL0//clZhweGu9Lgus5rol3/S03+/bw/v1fmp3SYV+3kELdBUWrCRkPfKENVlrFXDDyRCxBBIGQWs5BFT76gwUlJVfmx1/P3pPfaejxko1uLTe6JNGiby+R2uSR3ChgI2d841Yj0H992kUI3we6HxTakjcvkjfYnWyCNdVW6sXmJI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(346002)(39860400002)(136003)(376002)(230922051799003)(82310400011)(451199024)(186009)(1800799012)(64100799003)(46966006)(40470700004)(36840700001)(40460700003)(40480700001)(36756003)(478600001)(110136005)(86362001)(6666004)(81166007)(5660300002)(356005)(82740400003)(70206006)(1076003)(47076005)(26005)(2616005)(336012)(426003)(7416002)(16526019)(83380400001)(36860700001)(2906002)(8936002)(316002)(70586007)(7696005)(4326008)(8676002)(41300700001)(54906003)(44832011)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:05.5425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba335f5c-149e-457e-19f9-08dc13026946 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7449 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841038442520476 X-GMAIL-MSGID: 1787841038442520476 Clean up and reorder them according to the bit index. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 2 +- drivers/iommu/amd/amd_iommu_types.h | 13 +++++++------ drivers/iommu/amd/init.c | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index bbed268e8abc..108253edbeb0 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -106,7 +106,7 @@ static inline bool check_feature2(u64 mask) static inline int check_feature_gpt_level(void) { - return ((amd_iommu_efr >> FEATURE_GATS_SHIFT) & FEATURE_GATS_MASK); + return ((amd_iommu_efr & FEATURE_GATS_MASK) >> FEATURE_GATS_SHIFT); } static inline bool amd_iommu_gt_ppr_supported(void) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index ff56c857f6ad..f8baa8d88832 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -93,8 +93,6 @@ #define FEATURE_GA BIT_ULL(7) #define FEATURE_HE BIT_ULL(8) #define FEATURE_PC BIT_ULL(9) -#define FEATURE_GATS_SHIFT (12) -#define FEATURE_GATS_MASK (3ULL) #define FEATURE_GAM_VAPIC BIT_ULL(21) #define FEATURE_GIOSUP BIT_ULL(48) #define FEATURE_HASUP BIT_ULL(49) @@ -102,11 +100,14 @@ #define FEATURE_HDSUP BIT_ULL(52) #define FEATURE_SNP BIT_ULL(63) -#define FEATURE_PASID_SHIFT 32 -#define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT) +#define FEATURE_GATS_SHIFT 12 +#define FEATURE_GATS_MASK (0x03ULL << FEATURE_GATS_SHIFT) -#define FEATURE_GLXVAL_SHIFT 14 -#define FEATURE_GLXVAL_MASK (0x03ULL << FEATURE_GLXVAL_SHIFT) +#define FEATURE_GLX_SHIFT 14 +#define FEATURE_GLX_MASK (0x03ULL << FEATURE_GLX_SHIFT) + +#define FEATURE_PASMAX_SHIFT 32 +#define FEATURE_PASMAX_MASK (0x1FULL << FEATURE_PASMAX_SHIFT) /* Extended Feature 2 Bits */ #define FEATURE_SNPAVICSUP_SHIFT 5 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 959820ccfbcc..e84c69fe13d4 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -2080,14 +2080,14 @@ static int __init iommu_init_pci(struct amd_iommu *iommu) int glxval; u64 pasmax; - pasmax = amd_iommu_efr & FEATURE_PASID_MASK; - pasmax >>= FEATURE_PASID_SHIFT; + pasmax = amd_iommu_efr & FEATURE_PASMAX_MASK; + pasmax >>= FEATURE_PASMAX_SHIFT; iommu->iommu.max_pasids = (1 << (pasmax + 1)) - 1; BUG_ON(iommu->iommu.max_pasids & ~PASID_MASK); - glxval = amd_iommu_efr & FEATURE_GLXVAL_MASK; - glxval >>= FEATURE_GLXVAL_SHIFT; + glxval = amd_iommu_efr & FEATURE_GLX_MASK; + glxval >>= FEATURE_GLX_SHIFT; if (amd_iommu_max_glx_val == -1) amd_iommu_max_glx_val = glxval; From patchwork Fri Jan 12 00:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1803993dyi; Thu, 11 Jan 2024 16:09:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmSB97nWqL0zedslwaWKkkeSIL8ungeG/5pIQpsTGVLTBP02/FO8LuM7B9KX1gtMfQ1VRv X-Received: by 2002:a17:902:e9d5:b0:1d4:2956:c285 with SMTP id 21-20020a170902e9d500b001d42956c285mr82398plk.137.1705018143265; Thu, 11 Jan 2024 16:09:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018143; cv=pass; d=google.com; s=arc-20160816; b=PirO3uSJkEeXWVArIrfNDk/0ZPYknjLQtGLAY5eDGzGEWBADxg5F/aEcIeeS1dMO0I iPnFwyMzzIQ2GvWn19/Qtb6dxZR8GG8zpYnsxwtMLN6UzybRLfLlpUwLPBsNBzL2LSJc rZs2+Dm5yZmXfIMlVglGxgwW6nHp+gy9d8I57CVAkv1SAAzbgGZNuYeX0JH1bBk+Bo/4 ihsZLDhTKbHcLf61agfEss41yaOS1jPQ6kXgJuuTWRbNdGq1mMkAiQU/az5InGQQO4Br GFyaWay93LFVMpggbAPMII/3HYK2AdU+lLg6naNDJ6SLIOJo+pL4kXo2MPJFn3LsnZuJ jEZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PzC8bJ/HzCXiCVZ//dlwjp9dSTOOyGwaoh7nyIg3cyw=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=h6puymZdJ7uPUqjyrN5FDL7z+UXV63pxPhhTKPfhLwYZZs3IPkQY0nvSbcCPnsYyhn Bfx5Hql87ywiEX5ZR8BbCF0ZpZ24rFYu0edLr2jAjoxB1TLuCrI75WsDKfKtI3e3WQU9 mUzP549+5UstBzMbkpKO7/dhCLdxayBVJug/8UIOaEfROCiIECKVPBDXlCD0PmD+h37L nY+6onDxSlTmU+rj0svthS16sDDvCqqkLKMGlz+ZKG5noMB7sl7Ls87hHFQMpqqVgvm6 fNeZCssaJkMsPe82L0Xuie9sfioG4O7MAl9paeT7LVmJM+i22DYsuzKv+comFQJbfC3h ct0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=pkhFsy2J; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24167-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24167-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j10-20020a170902690a00b001cf50ffd38dsi1964388plk.164.2024.01.11.16.09.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:09:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24167-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=pkhFsy2J; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24167-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24167-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0CBB7286BCE for ; Fri, 12 Jan 2024 00:09:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 950E91548B; Fri, 12 Jan 2024 00:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="pkhFsy2J" Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2052.outbound.protection.outlook.com [40.107.101.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0811111A for ; Fri, 12 Jan 2024 00:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JMObaykG284d+Q45TBMKsbwrz5SSNvpLyFPrAxYuELbQvjcUQU1mH0AMOotW9ku+jRJbHCmHnvSs1SC9rYuSdqgBEVB2C2BNtbKZhy0IAfPdjh21/XJaZbzIt2FIV4K0Ukd/+47oXT/rfRZQs9xtlbb1u7PPMDCEIqMX7T7C2PiU0l16mWoy3HiDsI1K+UycBoaEcf91PE0lIClJ2kyFYIzj2mN2VAHhpsiPHpSbQFxOlOlC/v7XogPTJUGbypzD3lIWnuNr8lg/ShPZNXNbkMtYoPMfcb4cxZ4dqIfCD6123TURC6evkQWfVSCiEP8IIMiWn7P5kMYRnhj/djCjng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PzC8bJ/HzCXiCVZ//dlwjp9dSTOOyGwaoh7nyIg3cyw=; b=dBaEAk4ArWhZLZE04Rpu4Qk1XxGCzmF4V4JHoDslknl5MgLgXIi8xKxCgahFpQecnY9irXHHrA571b7vR0siw7RR5guUnZS1LSKzve7+4oaXQ+BwCcukPba/pdB0bsQM39EwRROBpQiV5HNEHofhVUrH52aUGaNBomfEXyELDm9c+AaNKX7MXRdsvr49B1D/oUCFzO/0fJED9dgy2nHlBrYYIfPP4jJfndziy98PDStaO/uXnN6JV4Z69X7G9Yizp5nj30AGfv3amJ5Q99bXmXwe9gQHLrvE5c9JamZQmkid2isYQpBzfSZIK9zFE7+gKqIMDQzzlrgF6T+6TfV45g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PzC8bJ/HzCXiCVZ//dlwjp9dSTOOyGwaoh7nyIg3cyw=; b=pkhFsy2JjRZSDgC7x88OgeuB57Ilz7YCzlg20eBqfYZkerXeRXw/g2CjpjLp7dZP+UARqObaT7Nl9n2i+IndZNZ+GkUsjVSz5rcL3M78jKGBBBQTCDMRY9vmm9sVV5AnsUxmt86s32VI72GOMSqG2jV+sZpkScggV4F2Og2Ia7Q= Received: from MW4P223CA0026.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::31) by PH8PR12MB7447.namprd12.prod.outlook.com (2603:10b6:510:215::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.17; Fri, 12 Jan 2024 00:07:07 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::d7) by MW4P223CA0026.outlook.office365.com (2603:10b6:303:80::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.18 via Frontend Transport; Fri, 12 Jan 2024 00:07:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:06 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:04 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 4/7] iommu/amd: Add support for hw_info for iommu capability query Date: Thu, 11 Jan 2024 18:06:43 -0600 Message-ID: <20240112000646.98001-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|PH8PR12MB7447:EE_ X-MS-Office365-Filtering-Correlation-Id: 2417fa7a-53e8-40ff-c4e2-08dc130269d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kyX9CwBJO/IryG6oQk7wdAPCnjJHl8Px1vLjJ6r7yDU4+caBl79HNks1FRnLYGURe4MqrIbhbGnC3OIj7Mg+Y0QrA8CHxy17IG890efHMJHf+DWu+sXwc7ipudwyQDP62Cg7B1y5a0vuR9CzpKTiyMIs/9IMcHjY9XfZzQgBSxQTBLWiTDAPfbkUOYmUCISG1kbYlciOaoDz+O5aMMmLvdWq92CUf9EmybKLL+ExOor5wtgXXdcdEsZmAC8smwAaBiXY0FeNMu8FsGRy+JvVXJjTeosRpbaXf3jR05GY2upOq923CqTXK1Pj7FmZSFM8c5NVVQl2hO7wpHCtvIRstj4jJq412WtK2RqI8Q9gB+1/tLmqO2cw2tQgjm4jwsYGL6PYbcQgXdDfuvLv3B49foOJ8ekjdnm+jRQ5wCfkqKjvCqxyuVr75Bb16y1Px3iRTF/ktK9HHQius2JxWG4hNw6atm0F7vZzImZGBVy9FUUoT61vDUIkd7XBrwY5EnMI37ry5rlZfhROmqhIClyjip3fanXzAk3iVOOJairnv5BG6UT3HSgV/QnPMtKpZza+2VYMJ7LHOrr1f4fqzLnwjH28JARsWD3X6D66vDV19SQrtEo8TuPMJD9Wy8H/NU7GjPhBxVHGhU9ZvQgWFDJ2dk0OPLxeMe8oV0ciYnuTgYeMAbIZ6qHyhNUf6kFAixkc+jXzeaBEHlIgwYjeKjnArt6cvaW7Wyyy2F5WnPJQYg1R4qMX0QexLCerhn5mcZQYYyHfvDkr/ID3CO7lMe2l22lcRW/vj5mpkcP5i03s3V0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(39860400002)(376002)(396003)(346002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(82310400011)(36840700001)(40470700004)(46966006)(70206006)(40480700001)(40460700003)(2906002)(7416002)(44832011)(5660300002)(47076005)(8936002)(6666004)(4326008)(7696005)(316002)(110136005)(41300700001)(54906003)(8676002)(70586007)(426003)(81166007)(356005)(86362001)(1076003)(26005)(336012)(82740400003)(16526019)(478600001)(36756003)(2616005)(36860700001)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:06.4644 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2417fa7a-53e8-40ff-c4e2-08dc130269d2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7447 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841104857575508 X-GMAIL-MSGID: 1787841104857575508 AMD IOMMU Extended Feature (EFR) and Extended Feature 2 (EFR2) registers specify features supported by each IOMMU hardware instance. The IOMMU driver checks each feature-specific bits before enabling each feature at run time. For IOMMUFD, the hypervisor determines which IOMMU features to support in the guest, and communicates this information to user-space (e.g. QEMU) via iommufd IOMMU_DEVICE_GET_HW_INFO ioctl. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 2 ++ drivers/iommu/amd/iommu.c | 36 +++++++++++++++++++++++++++++++++++ include/uapi/linux/iommufd.h | 20 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 108253edbeb0..4118129f4a24 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -72,6 +72,8 @@ void amd_iommu_dev_flush_pasid_pages(struct iommu_dev_data *dev_data, void amd_iommu_dev_flush_pasid_all(struct iommu_dev_data *dev_data, ioasid_t pasid); +void amd_iommu_build_efr(u64 *efr, u64 *efr2); + #ifdef CONFIG_IRQ_REMAP int amd_iommu_create_irq_domain(struct amd_iommu *iommu); #else diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 71099e5fbaee..134f4af921dc 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2849,8 +2849,44 @@ static const struct iommu_dirty_ops amd_dirty_ops = { .read_and_clear_dirty = amd_iommu_read_and_clear_dirty, }; +void amd_iommu_build_efr(u64 *efr, u64 *efr2) +{ + /* Build the EFR against the current hardware capabilities */ + if (efr) { + *efr = 0ULL; + *efr |= (amd_iommu_efr & FEATURE_GT); + *efr |= (amd_iommu_efr & FEATURE_GIOSUP); + *efr |= (amd_iommu_efr & FEATURE_PPR); + *efr |= (amd_iommu_efr & FEATURE_GATS_MASK); + *efr |= (amd_iommu_efr & FEATURE_GLX_MASK); + *efr |= (amd_iommu_efr & FEATURE_PASMAX_MASK); + pr_debug("%s: efr=%#llx\n", __func__, *efr); + } + + if (efr2) { + *efr2 = 0ULL; + pr_debug("%s: efr2=%#llx\n", __func__, *efr); + } +} + +static void *amd_iommu_hw_info(struct device *dev, u32 *length, u32 *type) +{ + struct iommu_hw_info_amd *hwinfo; + + hwinfo = kzalloc(sizeof(*hwinfo), GFP_KERNEL); + if (!hwinfo) + return ERR_PTR(-ENOMEM); + + *length = sizeof(*hwinfo); + *type = IOMMU_HW_INFO_TYPE_AMD; + + amd_iommu_build_efr(&hwinfo->efr, &hwinfo->efr2); + return hwinfo; +} + const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, + .hw_info = amd_iommu_hw_info, .domain_alloc = amd_iommu_domain_alloc, .domain_alloc_user = amd_iommu_domain_alloc_user, .probe_device = amd_iommu_probe_device, diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 0b2bc6252e2c..9901b9f4abe2 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -474,15 +474,35 @@ struct iommu_hw_info_vtd { __aligned_u64 ecap_reg; }; +/** + * struct iommu_hw_info_amd - AMD IOMMU device info + * + * @efr : Value of AMD IOMMU Extended Feature Register (EFR) + * @efr2: Value of AMD IOMMU Extended Feature 2 Register (EFR2) + * + * Please See description of these registers in the following sections of + * the AMD I/O Virtualization Technology (IOMMU) Specification. + * (https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf) + * + * - MMIO Offset 0030h IOMMU Extended Feature Register + * - MMIO Offset 01A0h IOMMU Extended Feature 2 Register + */ +struct iommu_hw_info_amd { + __aligned_u64 efr; + __aligned_u64 efr2; +}; + /** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware * info * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type + * @IOMMU_HW_INFO_TYPE_AMD: AMD IOMMU info type */ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_NONE, IOMMU_HW_INFO_TYPE_INTEL_VTD, + IOMMU_HW_INFO_TYPE_AMD, }; /** From patchwork Fri Jan 12 00:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1803842dyi; Thu, 11 Jan 2024 16:08:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8ab5yoA3hWS8xjBdZ2zXWvt5q4hA71mqbu1M2+T1DwgBoMBvI28DTqnJ7Fp6X3W+BAZ5V X-Received: by 2002:a17:90b:3602:b0:28d:531c:ee96 with SMTP id ml2-20020a17090b360200b0028d531cee96mr516647pjb.52.1705018126656; Thu, 11 Jan 2024 16:08:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018126; cv=pass; d=google.com; s=arc-20160816; b=Y/VOZJCppcDhgHcQ2Y3k7ChyDKALwQiJlPzMkf1IFSEp9NVbqSgnKMPRsQUlziuKrx vLFfeVy6ivxZDzugQweMgDuF5b0//oIdzxZlMD9XIuokIOzHjf5dxhiDsdeUDKWmXo2N NS5lN/9zvR2SbIdP3sMKTtlvoUdf7BRxjYK+/hC7MAJBkM8bWN1doAQPQgJbjPVbHLCZ Vw/o+WcCkMjvTDnwd/AesIaVp9e/2M+b/E+ZnHKBeSGwqSPd7aTmwVvSIg7p5iQ0yoxY sOHSkgtt3ephf6Y6YN1yLBgXzdVKh9vf/9aAHsUf4i20oa4fEDbgu5zLqXZVJ+gmLotl zisw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hMtMZUmwWRjZcfmxigSLp2kk2/qdEcBrj3/zeV8+AkY=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=y1kXDRDH/X+4kxZKIJRCLcqYz9mt4htRfHtC+f3ynmDIfWTjX63wc8TKea3vJQQBgV SFKmqpPVpalhA3P3r12zBoZmQwivu+iXIBl9KdBYiCU19AFKEZ/OYfizhEogoaVPbPYK iWDg6i8C4SOjpt/P/fefq8LTjJ0atf/jgPGSjra5sGmZ0mWTYMJZ3ETGey0Ro4k1Xdif /NFQO0fKI9SZfSevAZZyWdIKfFdd+Xbb83E/zRh5SBEYj7Df+/dgoe8yeYb9yDdq0GTs Hq8FtCTYekHDNEUKF7oR0D3QHDj1+D7nYXW97CWwTwVPSlkKuSgx4fJVGzDmh6sd8cRo 8rVg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=EgzcVnxu; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24166-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24166-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p12-20020a17090a868c00b0028cfa2f740asi4733755pjn.12.2024.01.11.16.08.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:08:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24166-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=EgzcVnxu; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24166-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24166-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 56E9A286C49 for ; Fri, 12 Jan 2024 00:08:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7997410783; Fri, 12 Jan 2024 00:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="EgzcVnxu" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FD8610F1 for ; Fri, 12 Jan 2024 00:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EqeF50yyD5KgMoPSHh80YtRV97WD2wE5ypKdu4LLhRo79A9phb12KUitaS+uLbKL3qVL0WBa7C41FvO6loX2ejZMNkhSaMHR9yYwRYY+jGQB0JFvMr2Jn5G8OFVzK4P1224ct6bMO2+4LODdJNyQUZT+3ohd/ePorQ7yJMJtKZM/nvBFmkwjBImwjIoLmmcywnVQZrCn5OE4lcIFt0D/FzUZp44jVbm7aCDrhx5XpkpSS5tldV3ePKKjzgfbcVjuc7W69szHagaeL0A4QbDCnmZqv+eIoiSCgkxTd2MHct9sT9wSVneQJKKUDnPMBps5Tk1C9SuStO3KTd2AM3upng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hMtMZUmwWRjZcfmxigSLp2kk2/qdEcBrj3/zeV8+AkY=; b=Jnty5Y6/DmFPgy03lSXrilMJPscUKoMDb73NYidC1KsVZG8mcui55SPtb7udqti6XDbLz378oZnkdLzMZdWQi+xIantdllguqwJ51LVUsoAxNwz6U5YcjkztFMgpa7Vpu5Ybe3Dc8Xevq6HV/lv0AlqF74Dkfu0qorsPsxtcrZt7yw3QgonYSAt4CsJTuFD//2b1xqB1SFv0pi6CUwY8mSoXR20OCUnQtSKcGWb5yFIzTIUkrU6lIRFoPhPrnN0x6hYpttmFpNZ+cf+tiZVIT6c0oVRTia8PiOx/sbFqf9YDlREoaGGOFEYaXMKRaVzO+jYBe1iHmzBKlxtuDs0KuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hMtMZUmwWRjZcfmxigSLp2kk2/qdEcBrj3/zeV8+AkY=; b=EgzcVnxuyO1Xscg2q90gYh/hA/qJ4GGRhQteFAoryzdnk4QwQi2mez0iBslUrPUumdng6Yi3+nqdmpPyQAqNl/RJM5iNM1WxnvBbrqKPJhCvDiIVmq/zynmu7yaJzVztWOaDXh1HKTGhT243+UcgvXJ1Z4e6EmJ0wA5VdiNeG0I= Received: from MW4P223CA0001.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::6) by CY5PR12MB6083.namprd12.prod.outlook.com (2603:10b6:930:29::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.17; Fri, 12 Jan 2024 00:07:08 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::dc) by MW4P223CA0001.outlook.office365.com (2603:10b6:303:80::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19 via Frontend Transport; Fri, 12 Jan 2024 00:07:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:08 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:04 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 5/7] iommufd: Introduce data struct for AMD nested domain allocation Date: Thu, 11 Jan 2024 18:06:44 -0600 Message-ID: <20240112000646.98001-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|CY5PR12MB6083:EE_ X-MS-Office365-Filtering-Correlation-Id: 22a9f63e-7b22-4c19-913b-08dc13026ae2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gpO5FXRXrtQIsAlaqWzte4ijTv48z739cRLDcFvhVaBKop3FjVqWhEWnBARXBdrGjBafasUBC9uX2vsZD/D2p648jquJDjqARc0ju1ucUvPqaurmkMMRAXB27pZFEkYBqZruessXsov/zqn6qzMEhjn3aMJ3DzQnxnr2Z272X4cgXN/WINP13i2kxTaNQQMPBM7ztajcHItsvGRRDIfH5SpRwwIrMj0JQsK/6SVdc9GVeIbFQyZTtLhDHvvRkGZZ0v9R0nVeLfV153gwC7e9z0JLKgzSXSR05KsCVCEnfDaCVxUmJnNHlBnp+YzEG4For2GzoqOXs+lv8nGQ+llR7+dUUPPCNL3VTLeco7KVjt1FHvJK8cWMEpQa4F2X1pXSAPeH5qoxytZxSuqHNvJIsY99G73yYrTj+ihtUl0uC1USm4x79/vfs7aLItSNQ3FmE3bUOQgDua5wukEMkz4LDoregw0lTdFCmhiyUz3HIVMF4HQJu1LVYKBa3jcdXEObKwahDiRjeCztqurXlIuLMdGMbMjTvOYi9vXZlFG/CQyal/fllN5ffaLx3scuLYJt1VxucvzmfqpDJqW7qcNCAoBFkuPLZZ4NH13DYdmnLh1qNk9rBYacnSbBWPd+HqW6KnOyvRx1FSWd7jazeos4Q+AYpjVjobgtrUhje2o6Z7+p6Xs+6KbIA5Xh2p207eHPqbpWi18isF4eXMJpbp6P9nzOujMZH4diGpEwVv2WevNPJoaO2cEejbU04fXFFl963oVVubhQza2L+UZu9msALwgidNanw4s2/9CGRQw8MxI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(39860400002)(136003)(346002)(376002)(230922051799003)(186009)(82310400011)(64100799003)(1800799012)(451199024)(46966006)(36840700001)(40470700004)(6666004)(110136005)(54906003)(478600001)(316002)(70206006)(7696005)(70586007)(47076005)(8936002)(36860700001)(8676002)(2616005)(1076003)(26005)(336012)(4326008)(5660300002)(44832011)(7416002)(41300700001)(2906002)(36756003)(426003)(16526019)(82740400003)(356005)(81166007)(86362001)(40460700003)(40480700001)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:08.2457 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22a9f63e-7b22-4c19-913b-08dc13026ae2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6083 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841087232558827 X-GMAIL-MSGID: 1787841087232558827 Introduce IOMMU_HWPT_DATA_AMD_V2 data type for AMD IOMMU v2 page table, which is used for stage-1 in nested translation. The data structure contains information necessary for setting up the AMD HW-vIOMMU support. Signed-off-by: Suravee Suthikulpanit --- include/uapi/linux/iommufd.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 9901b9f4abe2..b28ec5947571 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -389,14 +389,39 @@ struct iommu_hwpt_vtd_s1 { __u32 __reserved; }; +/** + * struct iommu_hwpt_amd_v2 - AMD IOMMU specific user-managed + * v2 I/O page table data + * @gcr3: GCR3 guest physical ddress + * @flags.glx: GCR3 table levels + * @flags.giov: GIOV mode + * @flags.guest_paging_mode: Guest v2 page table paging mode + * @flags.reserved : Must be 0 + * @gdom_id: Guest domain ID + * @__reserved: Must be 0 + */ +struct iommu_hwpt_amd_v2 { + __aligned_u64 gcr3; + struct { + __aligned_u64 glx : 1, + giov : 1, + guest_paging_mode : 2, + reserved : 60; + } flags; + __u32 gdom_id; + __u32 __reserved; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table + * @IOMMU_HWPT_DATA_AMD_V2: AMD IOMMUv2 page table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE, IOMMU_HWPT_DATA_VTD_S1, + IOMMU_HWPT_DATA_AMD_V2, }; /** From patchwork Fri Jan 12 00:06:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1804967dyi; Thu, 11 Jan 2024 16:10:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyHUDI1aRc0da+JaZZQjU+Va2UhBfpfPg98AC3FZj36HaOUuvxhjqn9ozi3hNcATKTUk3h X-Received: by 2002:a05:6358:189:b0:175:77d7:67b2 with SMTP id d9-20020a056358018900b0017577d767b2mr1233013rwa.32.1705018258403; Thu, 11 Jan 2024 16:10:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018258; cv=pass; d=google.com; s=arc-20160816; b=DoNtByFOUkLL+rnX+/AaT4hRySR52a9/0cT6oXjNlGo/mufAIJL2dKHzlBwsjVUHuJ 3WbCQpBGZ60DesLiJrADlK5Cw/1AAN+bEHnKQCdWVhgSQRol5Uxc5GuLtf5DOvonKPtD f7L0YZ5PTeK+QfEM28CiMzN1vxzHdoaxpoPMCB/Lx3IBMOESnZSZqMv8rUMcZmep0fxV BY9Bity2AzdeTgDYEiOfvY6N3XsV19VxrOLGGiInO7EE+WvWAy+1iNbgyMBQWAJmkE3G LgdJv+OkAqD55Lz8FehMcCok+zaD8MwGywx3qXQgL+Zx1mP8P7TyhG2jUymb35zjuEvy mWtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CDjOCBYRs3Bi6DGtMMHqdaftKbkEZWu3pN2q3tgL7Pk=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=zZLIEplmndOprDf0J19aoBbCKEv8RdovF6dQns8njCoVF/OuBgxjaGNXx2qCYEEwe7 PS24jXm7Hhi3KQfBNLG5K7ymDnZb0CZqTOZp1GsrQQf+ktnX3TX8wqA9d7pkNwfD2lnj QHj67O1uRcgPve93Bt3JhUxjCtQcWd0KXrvpQl7iVIv6qmA8ZS7US+JAcHp2D8GjOXXa FhTETyWm2TaswCipm8or76P0E+JIB/Co7n3mln9UrskpOkdborkYUtQ/Azbmx4edyvl2 WloXC0OAYXhW3qtylp+jzssZMo9FjEb30KhudwFCE5PaqWtdOA4rgwf+F52tKtorkSWP oDbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="rifU9/Ea"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24169-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24169-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y11-20020a17090a86cb00b0028bee19fad5si4655122pjv.91.2024.01.11.16.10.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:10:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24169-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="rifU9/Ea"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24169-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24169-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 71D97B24B5A for ; Fri, 12 Jan 2024 00:09:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D63FF17994; Fri, 12 Jan 2024 00:07:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="rifU9/Ea" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFFE6258D for ; Fri, 12 Jan 2024 00:07:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SEMIl/xGuREu2T/aIn71vMrH7VypGdcb2evMYUrA4sfaWtHB3hFm8M5IWN5myXqt808OVA+ltz60qFQJlA4R5ONv9B5bBBtBU/BpiQ6F+exRMclbLZnIKVQd4UH3EAJhhUmUgipv9aH+4P0/5Viuabxrv2w238ZqBajMIim9MXfryz4y0RacTEIJUVGEhdDv8PSMQTjSs9E2BwnJUUGd1CPjtwe/BpEP1XZptG2W+DKNi7v1t1XaIjmnZx+wN72IGU3+L0W/IunxWuNWHkF4nlpyyupcmIrbKMD2hV1uYt5Cz26IeQiC55tzfgQhqT6IODejaY8JJSt3Vr8qSWEFwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CDjOCBYRs3Bi6DGtMMHqdaftKbkEZWu3pN2q3tgL7Pk=; b=PCGDVd4qBrNX/LziCT/fBXQ71uiMIH8Cx+0rhrr3ktVTa/Iq+A9b3MVpGiO2XXB3NYNlGfFgATwxMt/pgb8fA/ylOu6GgFumr66pXF4R5phF5aIkervboV0hZXBWEq88EVyVilv/qeTIH9XxJGApTLrkjbEW9SeAt9ojXPDepf/pdloFe9gez1k3mqK5+JVU+M+v1jOD2xoFnRYHm2ZXm6lxij8KHHByx1SsVWp92gIZ5QBBJ31j14GKFlU+XBD1L9uTnvDCmn/IWN1/0bfuJI40yMg5nCGUAgfFERPEVmNJcdanKnRAXMEJrdUacV9cEJe8jdsaFULno8s3wHybwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CDjOCBYRs3Bi6DGtMMHqdaftKbkEZWu3pN2q3tgL7Pk=; b=rifU9/EaLmFo65sD6wx3RST5Y4u/rd2gPp3x8szeodaa3qZ2QmuzsxyuYYwx3rMRK27eLSHIIHDCzBYOcdsYXWvb7jpxWEvSynLBt/uawnGjeoQVYm8v3dd6ZoYbkXqyu3yaXmaUOZzOCuOacA9FDbvnzAiJRsoDrmCtLcla3mE= Received: from MW4P223CA0007.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::12) by DM6PR12MB4387.namprd12.prod.outlook.com (2603:10b6:5:2ac::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19; Fri, 12 Jan 2024 00:07:09 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::31) by MW4P223CA0007.outlook.office365.com (2603:10b6:303:80::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19 via Frontend Transport; Fri, 12 Jan 2024 00:07:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:08 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:06 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 6/7] iommu/amd: Add nested domain allocation support Date: Thu, 11 Jan 2024 18:06:45 -0600 Message-ID: <20240112000646.98001-7-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|DM6PR12MB4387:EE_ X-MS-Office365-Filtering-Correlation-Id: cc54c7fa-301e-43d4-7a26-08dc13026b2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b6qJnSQnKoUqEF8chQSMDMyhK+DwVXPCrZSDe4WfvmnfbOzLGYwUrYxkxlt6Roc8FmOLWZSbxgN47V9kscx4NCR88A6KbIVzDQwOlz74jYXraUlAVzoOg8JxDR5VBnJoDFkpAVS4PbJPFDw+QfBTaodLVbWlx2IppK4xUC5LvicBcYQr4L2naOW8QeW5HCGspxdi5E4UFO7yLQVq0DtOx3CIc4vXtixj6UttQUfBbvpqAcTuk3Foe6vSQ8Vz2VEWKD/l0FmcGUFluHQf8+K8FGyhQA90gRRb0qj8eyo41uHbWEOcsYJg4boXL540ZV/TjedsgsVFlAkVaBsfYzCSuX0hlEOzN5fEqpKIoPcDXrPsSxcDudhvK2YWgpNupAOREHAoh3wXsRJDg8piWQrJ7VFMMNv3B0iEe0BDrweOcl8FpR026K10nIjAhlS1rC65jUnDbGSLTQqBMMIIiTk8gR/SbgpVHIKCLpZfh66+YkRqrpXPBNB3y5t+jAVrY0RBoN0MNLR/FBn8JzbV2hodCn7051PuNJFlAGwfgAkZvTRUqgQhe7mMqIdH5OeeOFI2BpKlutjs6hjA+OzO8V9o+kIomEqVpoQ0p20Nr293ZvBh5sR9U4sWb/gQFFYZaYZAGQXw3SEHKO3cpnpRwaxvuXJf/+70k06IkqeYh8MHXrzI30sAbWRFCpi8h3XTf6Qz9f1lCYApAaWoTExnvMoE5oIHn7B0Ql+7AMZ6Vqw0V1eZB4r67MwjgUMIIavbnDBRQxU0KhKZ186JvNFePS09IMCYyovr3IBiqTF2+N1v7V0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(376002)(39860400002)(136003)(230922051799003)(186009)(1800799012)(82310400011)(64100799003)(451199024)(46966006)(40470700004)(36840700001)(6666004)(83380400001)(316002)(47076005)(70206006)(110136005)(54906003)(70586007)(7696005)(16526019)(426003)(26005)(1076003)(336012)(2616005)(81166007)(44832011)(8936002)(8676002)(40480700001)(40460700003)(82740400003)(36756003)(356005)(4326008)(5660300002)(86362001)(36860700001)(7416002)(30864003)(41300700001)(478600001)(2906002)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:08.7144 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc54c7fa-301e-43d4-7a26-08dc13026b2c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4387 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841225301606821 X-GMAIL-MSGID: 1787841225301606821 To support nested translation, the parent domain is allocated with flag IOMMU_HWPT_ALLOC_NEST_PARENT, and stores information of the v1 page table for stage 2 (i.e. GPA->SPA), whereas the child domain stores information of the GCR3 root pointer table for stage 1 (i.e. GVA->GPA). Modify the current driver to handle the domain allocation with type IOMMU_DOMAIN_NESTED. Also, when allocating the child domain (with the parent domain is specified), keeps track the parent using the struct protection_domain.parent. Note that current implementation requires AMD IOMMU GCR3TRPMode feature, which program DTE[GCR3 Table Root Pointer] with the GPA provided by the guest via struct iommu_hwpt_amd_v2, which is passed as a parameter of the struct iommu_ops.domain_alloc_user(). Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/Makefile | 2 +- drivers/iommu/amd/amd_iommu.h | 10 +++ drivers/iommu/amd/amd_iommu_types.h | 6 ++ drivers/iommu/amd/iommu.c | 96 ++++++++++++++++++++++++++--- drivers/iommu/amd/nested.c | 75 ++++++++++++++++++++++ 5 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 drivers/iommu/amd/nested.c diff --git a/drivers/iommu/amd/Makefile b/drivers/iommu/amd/Makefile index f454fbb1569e..447cb6bb48eb 100644 --- a/drivers/iommu/amd/Makefile +++ b/drivers/iommu/amd/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o +obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o nested.o obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += debugfs.o diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 4118129f4a24..bb25d7c3bff5 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -7,6 +7,7 @@ #ifndef AMD_IOMMU_H #define AMD_IOMMU_H +#include #include #include "amd_iommu_types.h" @@ -182,4 +183,13 @@ void amd_iommu_domain_set_pgtable(struct protection_domain *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); extern bool amd_iommu_snp_en; + +/* NESTED */ +struct protection_domain *to_pdomain(struct iommu_domain *dom); +bool amd_iommu_domain_is_nested(struct protection_domain *pdom); +struct iommu_domain * +amd_iommu_nested_domain_alloc(struct device *dev, unsigned int type, u32 flags, + struct iommu_hwpt_amd_v2 *hwpt, + struct iommu_domain *parent); + #endif diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index f8baa8d88832..db77b050a496 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -110,6 +110,8 @@ #define FEATURE_PASMAX_MASK (0x1FULL << FEATURE_PASMAX_SHIFT) /* Extended Feature 2 Bits */ +#define FEATURE_GCR3TRPMODE BIT_ULL(3) + #define FEATURE_SNPAVICSUP_SHIFT 5 #define FEATURE_SNPAVICSUP_MASK (0x07ULL << FEATURE_SNPAVICSUP_SHIFT) #define FEATURE_SNPAVICSUP_GAM(x) \ @@ -535,6 +537,7 @@ struct amd_irte_ops; struct gcr3_tbl_info { u64 *gcr3_tbl; /* Guest CR3 table */ + u64 trp_gpa; /* Guest CR3 TRP GPA for nested domain */ int glx; /* Number of levels for GCR3 table */ u32 pasid_cnt; /* Track attached PASIDs */ bool giov; /* Track DTE[GIOV] */ @@ -569,6 +572,9 @@ struct protection_domain { bool dirty_tracking; /* dirty tracking is enabled in the domain */ unsigned dev_cnt; /* devices assigned to this domain */ unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */ + struct protection_domain *parent; /* Nested parent domain */ + u16 guest_paging_mode; /* Guest paging mode */ + u16 guest_domain_id; /* Guest domain ID */ }; /* diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 134f4af921dc..51716fa5ccb5 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -77,11 +77,16 @@ struct iommu_cmd { struct kmem_cache *amd_iommu_irq_cache; +static int amd_iommu_attach_device(struct iommu_domain *dom, + struct device *dev); + static void detach_device(struct device *dev); static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data); +static void amd_iommu_domain_free(struct iommu_domain *dom); + /**************************************************************************** * * Helper functions @@ -191,7 +196,7 @@ static struct amd_iommu *rlookup_amd_iommu(struct device *dev) return __rlookup_amd_iommu(seg, PCI_SBDF_TO_DEVID(devid)); } -static struct protection_domain *to_pdomain(struct iommu_domain *dom) +struct protection_domain *to_pdomain(struct iommu_domain *dom) { return container_of(dom, struct protection_domain, domain); } @@ -2367,8 +2372,9 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) domain->nid = NUMA_NO_NODE; switch (type) { - /* No need to allocate io pgtable ops in passthrough mode */ + /* No need to allocate io pgtable ops in passthrough and nested mode */ case IOMMU_DOMAIN_IDENTITY: + case IOMMU_DOMAIN_NESTED: return domain; case IOMMU_DOMAIN_DMA: pgtable = amd_iommu_pgtable; @@ -2423,7 +2429,12 @@ static bool amd_iommu_hd_support(struct amd_iommu *iommu) return iommu && (iommu->features & FEATURE_HDSUP); } -static struct iommu_domain *do_iommu_domain_alloc(unsigned int type, +static const struct iommu_domain_ops nested_domain_ops = { + .attach_dev = amd_iommu_attach_device, + .free = amd_iommu_domain_free, +}; + +struct iommu_domain *do_iommu_domain_alloc(unsigned int type, struct device *dev, u32 flags) { bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING; @@ -2454,7 +2465,10 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type, if (iommu) { domain->domain.type = type; domain->domain.pgsize_bitmap = iommu->iommu.ops->pgsize_bitmap; - domain->domain.ops = iommu->iommu.ops->default_domain_ops; + if (type == IOMMU_DOMAIN_NESTED) + domain->domain.ops = &nested_domain_ops; + else + domain->domain.ops = iommu->iommu.ops->default_domain_ops; if (dirty_tracking) domain->domain.dirty_ops = &amd_dirty_ops; @@ -2474,18 +2488,86 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned int type) return domain; } +static int udata_to_iommu_hwpt_amd_v2(const struct iommu_user_data *user_data, + struct iommu_hwpt_amd_v2 *hwpt) +{ + if (!user_data) + return -EINVAL; + + if (user_data->type != IOMMU_HWPT_DATA_AMD_V2) + return -EOPNOTSUPP; + + return iommu_copy_struct_from_user(hwpt, user_data, + IOMMU_HWPT_DATA_AMD_V2, + __reserved); +} + +static bool check_nested_support(u32 flags) +{ + if (!(flags & IOMMU_HWPT_ALLOC_NEST_PARENT)) + return true; + + if (!check_feature(FEATURE_GT) || + !check_feature(FEATURE_GIOSUP) || + !check_feature2(FEATURE_GCR3TRPMODE)) + return false; + + return true; +} + +static u32 amd_iommu_hwpt_supported_flags = + IOMMU_HWPT_ALLOC_DIRTY_TRACKING | + IOMMU_HWPT_ALLOC_NEST_PARENT; + static struct iommu_domain * amd_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data) - { + struct iommu_domain *dom; + struct iommu_dev_data *dev_data; unsigned int type = IOMMU_DOMAIN_UNMANAGED; + bool nested_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; + + if (parent) { + int ret; + struct iommu_hwpt_amd_v2 hwpt; + + if (parent->ops != amd_iommu_ops.default_domain_ops) + return ERR_PTR(-EINVAL); + + ret = udata_to_iommu_hwpt_amd_v2(user_data, &hwpt); + if (ret) + return ERR_PTR(ret); - if ((flags & ~IOMMU_HWPT_ALLOC_DIRTY_TRACKING) || parent || user_data) + return amd_iommu_nested_domain_alloc(dev, type, flags, + &hwpt, parent); + } + + /* Check supported flags */ + if ((flags & ~amd_iommu_hwpt_supported_flags) || + !check_nested_support(flags)) return ERR_PTR(-EOPNOTSUPP); - return do_iommu_domain_alloc(type, dev, flags); + dev_data = dev_iommu_priv_get(dev); + + /* + * When allocated nested parent domain, the device may already + * have been attached to a domain. For example, a device is already + * attached to the domain allocated by VFIO, which contains GPA->SPA mapping. + * In such case, return reference to the same domain. + */ + if (dev_data->domain && nested_parent) { + pr_debug("%s: Found exist: protection domain id=%#x\n", + __func__, dev_data->domain->id); + dom = &dev_data->domain->domain; + } else { + dom = do_iommu_domain_alloc(type, dev, flags); + if (!dom) + return ERR_PTR(-ENOMEM); + } + + return dom; } static void amd_iommu_domain_free(struct iommu_domain *dom) diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c new file mode 100644 index 000000000000..1addcb21a38c --- /dev/null +++ b/drivers/iommu/amd/nested.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * Author: Suravee Suthikulpanit + */ + +#define pr_fmt(fmt) "AMD-Vi: " fmt +#define dev_fmt(fmt) pr_fmt(fmt) + +#include +#include + +#include "amd_iommu.h" + +bool amd_iommu_domain_is_nested(struct protection_domain *pdom) +{ + return (pdom && pdom->parent != NULL); +} + +static int nested_gcr3_update(struct iommu_hwpt_amd_v2 *hwpt, + struct protection_domain *pdom, + struct protection_domain *ppdom, + struct device *dev) +{ + struct pci_dev *pdev; + struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); + + pdev = to_pci_dev(dev); + if (!pdev) + return -EINVAL; + + /* Note: Currently only support GCR3TRPMode with nested translation */ + if (!check_feature2(FEATURE_GCR3TRPMODE)) + return -EOPNOTSUPP; + + pdom->parent = ppdom; + pdom->guest_domain_id = hwpt->gdom_id; + pdom->guest_paging_mode = hwpt->flags.guest_paging_mode; + + dev_data->gcr3_info.trp_gpa = hwpt->gcr3; + dev_data->gcr3_info.glx = hwpt->flags.glx; + dev_data->gcr3_info.giov = hwpt->flags.giov; + + return 0; +} + +struct iommu_domain *do_iommu_domain_alloc(unsigned int type, + struct device *dev, u32 flags); +struct iommu_domain * +amd_iommu_nested_domain_alloc(struct device *dev, unsigned int type, u32 flags, + struct iommu_hwpt_amd_v2 *hwpt, + struct iommu_domain *parent) +{ + int ret; + struct iommu_domain *dom; + struct protection_domain *pdom; + + pr_debug("%s: Allocating nested domain with parent domid=%#x\n", + __func__, to_pdomain(parent)->id); + + dom = do_iommu_domain_alloc(IOMMU_DOMAIN_NESTED, dev, flags); + if (IS_ERR(dom)) + return ERR_PTR(-ENOMEM); + + pdom = to_pdomain(dom); + ret = nested_gcr3_update(hwpt, pdom, to_pdomain(parent), dev); + if (ret) + goto err_out; + + return dom; + +err_out: + iommu_domain_free(dom); + return ERR_PTR(-EINVAL); +} From patchwork Fri Jan 12 00:06:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 187525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1804489dyi; Thu, 11 Jan 2024 16:10:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnN9gnwZTw2EUBKXX0lZlI7X10iQNK5RRBk9WCexqdELRk9SLNeXMkEwWxn5nQm9ZxzVKY X-Received: by 2002:a05:6808:aac:b0:3bd:3bfe:486d with SMTP id r12-20020a0568080aac00b003bd3bfe486dmr118975oij.119.1705018200332; Thu, 11 Jan 2024 16:10:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705018200; cv=pass; d=google.com; s=arc-20160816; b=rY3zNjan00pwRJ6S1f6Vxbxy8JoGyI5ZpRtQ2ZJW1ndF1JXLzw+4CQ7Xa/jehchMar o7onIHlIpxpW2jjsOV4TMKB+7bWcrmg4ic/G8JEHL8OpnilgoZqaOuiVrc/jztsCvTE4 ZR2CQ0xuA/1EAEBiKWq6g4MBPalkj+tMDUiZMtLaas/aCpUF0do9CD7KEEearpDQBYR8 zxWdfjwgfXtt0MtUvY3mZcNdrymIaxPalO6bU4CHr2TSWaHx3eSdkZllbFePNn/7IFRD MRZihR5LdU5sCZD/vBbYOX3OZjM17OkXs7JEvEQqaJgTOIo4fBKfjP0g/zxS1gmuSBBq otIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BfXe4XBzvZvb4xL/HqKvRdR1ZCyTZrTMWw1fobH+VJ8=; fh=e9PdO+rcGhV+cnwOMjmt98TGV0HSDydHzrUHrldjlVY=; b=PVahNmSYJroRF+TL74Tfz46a+3n3q5X8SG+MNqGXWVV30BwkiYqeJgnCJugc3ER8Lf jfhSjCrnsGvxGwkbhUcB0PlHt9MFagGGc7IV6nwHDX46bYIasujw/NqmiLIXBVbm2V8+ TAPmRekPrjM0x3exuCGHvRU1fVjH/rl1PIFfvPn0Kpvf5v48efmJxEt08eUPlX5oOaN4 xXgEmamI64wE3X7ph2UROXC59JBrw2ggnfMiJGHV+IEfb5HI4Zv2YgjzfmIT4cVFlVl9 0Mh5Wxeq5iktsrE2KfeJyczLR1t82WdHg5WRRsFEOsco975Q/OdRDhgkMyxGtke47l2G Ta7w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=IsGxnow7; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24168-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24168-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id cm5-20020a056a020a0500b005c221909d4asi2172532pgb.830.2024.01.11.16.09.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 16:10:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24168-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=IsGxnow7; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel+bounces-24168-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24168-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 653A7B223F0 for ; Fri, 12 Jan 2024 00:09:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15070171CA; Fri, 12 Jan 2024 00:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="IsGxnow7" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2087.outbound.protection.outlook.com [40.107.223.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65BD615BD for ; Fri, 12 Jan 2024 00:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W6fKscQVbfWAh/DMcHIsl+HobxWOKvYdMuifgP5njONJQmKgkaaY4rXwhSXh1dBqJ9abb1KS1U0fc1efjQKcCvKkfZbwm6HkVUYEjcxCNEbzU+f3B8y1h01LKOzidXOXNiOJURef2tOjbigYBPOPhP4haSR76c+c7PO9lFP+3hO6NmZKSa5pCXuR99b2h4ZmJYbmIgOVVnGlmg+R4uZdlV0Ox+aEDhuTjQbeM6eXhbY9Vp8deu+Ji9So+7H+v3csQ+XvFER2o21OSRFEILLnCdGoLoUEMC28sTgWyVIUPMBujiC+pIO7+Lr/ItRef4VB8tfIOuHbr2DMfhM6MopYmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BfXe4XBzvZvb4xL/HqKvRdR1ZCyTZrTMWw1fobH+VJ8=; b=YedveHroogPyiDH1kDWLksaNIhi7lABWr/AmKUtpB88J0Pa/0Sj7dYcYNwHK21HZY7YSVxn67OEEY4/9XMkNa196Mf+gCwGoI+k96SzQzWonQauNWlIjnYl6CZtGuWIfSNUfQH/UmSVo8HMSfPwrJu2qWz7mCbaU4B/vOzO6bIUMDx0h0nzERb1hXoZFmVCsKQydu1mpXlfLf7hF6izVFiqGMUnMjkfXBejcpjj+nnxgPvjoCtmm2WRbmriTVNKNMc6XLFgP7dtnbsaNHYZTiQb0+HsuU32HSLYAs1hm9lHm3Ca1/a9K6NFaM7yHlE0W1FokPKgDEqEr130Pkb2+oQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BfXe4XBzvZvb4xL/HqKvRdR1ZCyTZrTMWw1fobH+VJ8=; b=IsGxnow7zcJRozwcEBnEEEFSwf9+8cWSq1bnHVGp4aPn2JpR1nWLfys1q7BlTSsCjd1M99o/rcJomOzN5HB4XPp84v/7Oa2nrYCXP7Pj4fLLNFbp2STWtY/V0tSoXtKMSAOC0vFUgOg7OREltjddCf7F4GCIjMl3jAfbkaz3+bQ= Received: from MW4P223CA0016.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::21) by CH0PR12MB5236.namprd12.prod.outlook.com (2603:10b6:610:d3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.21; Fri, 12 Jan 2024 00:07:09 +0000 Received: from MWH0EPF000971E2.namprd02.prod.outlook.com (2603:10b6:303:80:cafe::7d) by MW4P223CA0016.outlook.office365.com (2603:10b6:303:80::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.18 via Frontend Transport; Fri, 12 Jan 2024 00:07:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E2.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.14 via Frontend Transport; Fri, 12 Jan 2024 00:07:09 +0000 Received: from ruby-95f9host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 11 Jan 2024 18:07:06 -0600 From: Suravee Suthikulpanit To: , , , CC: , , , , , , , , , , Suravee Suthikulpanit Subject: [RFCv2 PATCH 7/7] iommu/amd: Add nested domain attach/detach support Date: Thu, 11 Jan 2024 18:06:46 -0600 Message-ID: <20240112000646.98001-8-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> References: <20240112000646.98001-1-suravee.suthikulpanit@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E2:EE_|CH0PR12MB5236:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c5c6a1b-27fc-4081-124a-08dc13026ba6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g8Q/T9MOrEUjKL4ZbrLPatDf4TIUihihb0/1s0dalW9zpo9vlYByYETZ0nxeBskmJpLyVv/jLvVUXpwwIyvWgF8cFg7PiBI6k7gVU3fHTglFmYk6AGEoTzljG7Rswufd5HMg6lCvHUPRaosJIGfHDlF1yvG0hVjLA/t/KRwGLIMgh3MSkjkRJhi7C9Duu81z0DpsS3koXUok1AOmePuiUc7cqQBjLnCYvhPDEb7MX3dQN0tvLPdQ6DDNjIZwnCdiYOuM8qbCA0MdhvSR+A5zz8LfVgrg3VPbsAOjYtM8OkTpX4mlzbe6uw3uuFcdVEYwRKlSqe1gIQSygFKfVZY4Vfwj4q3Q/rW3oGNzqp36rZ6msQO4lDq+uq/yIWVOulfKxuyRZo+MPNjQUjCweKTN5OMKr540wMvQW9kP0YV7/n3l6WPXiBnoaGDCuBBc8epYORQmcqe+slThuMjTbk3K/EUVOwFgWQ9IVkwK4Nfi88ocjJszK8de7PDsRQ7SLdbYawkJ4v2g3qERryHgmKGKxm23w3dfwd9Fn0zfQaWLsgnR/3YvFpg8WEdu4J982LTzkcUtPy+3X9ZjetAeetqJhHFLI8kKD9tYNkxrdamE7BOZ1DFIKjrqOG0Zw4CvLGOqlV1ph2QUGE7NA7OFPTANtpaEvwrCQAsjeIbvf4bTNsfFrw86dJtoTBeQY/v5owavGEJ7vkiRSK4YeO/xfSeqISShO3tCC1hXKb0YCNpeUbukrm2muRkJOlnlt+T+HhGIPqkzJPt8CEz0ZuN/jRXhYDUalwfpF51hAu4XY/BcWyk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(376002)(396003)(39860400002)(136003)(230922051799003)(451199024)(64100799003)(186009)(82310400011)(1800799012)(36840700001)(40470700004)(46966006)(44832011)(40480700001)(40460700003)(2906002)(5660300002)(7416002)(478600001)(81166007)(356005)(4326008)(36756003)(70586007)(8676002)(8936002)(70206006)(54906003)(110136005)(41300700001)(316002)(2616005)(86362001)(1076003)(6666004)(7696005)(26005)(83380400001)(82740400003)(426003)(16526019)(336012)(47076005)(36860700001)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 00:07:09.5269 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5c6a1b-27fc-4081-124a-08dc13026ba6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5236 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787841164648030165 X-GMAIL-MSGID: 1787841164648030165 With GCR3TRPMode, the AMD IOMMU driver does not need to allocate the GCR3 table and the v2 (stage 1) table. Instead, it uses the GPA of the GCR3 table provided by the guest when attach/detach the nesting domain. Modify the set_dte_gcr3_table() to program DTE[GCR3 Table Root Pointer] for nesting domain with the provided GPA. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 45 +++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 51716fa5ccb5..4041ac3fcd1b 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1927,15 +1927,16 @@ static void set_dte_gcr3_table(struct amd_iommu *iommu, struct dev_table_entry *target) { struct gcr3_tbl_info *gcr3_info = &dev_data->gcr3_info; + struct protection_domain *pdom = dev_data->domain; int devid = dev_data->devid; u64 tmp, gcr3 = 0; - if (!gcr3_info || !gcr3_info->gcr3_tbl) + if (!gcr3_info || (!gcr3_info->gcr3_tbl && !gcr3_info->trp_gpa)) return; - pr_debug("%s: devid=%#x, glx=%#x, giov=%#x, gcr3_tbl=%#llx\n", + pr_debug("%s: devid=%#x, glx=%#x, giov=%#x, gcr3_tbl=%#llx, trp_gpa=%#llx\n", __func__, devid, gcr3_info->glx, gcr3_info->giov, - (unsigned long long)gcr3_info->gcr3_tbl); + (unsigned long long)gcr3_info->gcr3_tbl, gcr3_info->trp_gpa); tmp = gcr3_info->glx; target->data[0] |= (tmp & DTE_GLX_MASK) << DTE_GLX_SHIFT; @@ -1951,7 +1952,11 @@ static void set_dte_gcr3_table(struct amd_iommu *iommu, tmp = DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; target->data[1] &= ~tmp; - gcr3 = iommu_virt_to_phys(gcr3_info->gcr3_tbl); + /* For nested domain, use GCR3 GPA provided */ + if (amd_iommu_domain_is_nested(pdom)) + gcr3 = gcr3_info->trp_gpa; + else if (gcr3_info->gcr3_tbl) + gcr3 = iommu_virt_to_phys(gcr3_info->gcr3_tbl); /* Encode GCR3 table into DTE */ tmp = DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; @@ -1963,8 +1968,21 @@ static void set_dte_gcr3_table(struct amd_iommu *iommu, tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C; target->data[1] |= tmp; - /* Use system default */ - tmp = amd_iommu_gpt_level; + if (amd_iommu_domain_is_nested(pdom)) { + /* + * For nested domain, guest provide guest-paging mode. + * We need to check host capability before setting the mode. + */ + tmp = pdom->guest_paging_mode; + if (tmp > amd_iommu_gpt_level) { + pr_err("Cannot support Guest paging mode=%#x (dom_id=%#x).\n", + pdom->guest_paging_mode, pdom->id); + tmp = amd_iommu_gpt_level; + } + } else { + /* Use system default */ + tmp = amd_iommu_gpt_level; + } /* Mask out old values for GuestPagingMode */ target->data[2] &= ~(0x3ULL << DTE_GPT_LEVEL_SHIFT); @@ -1981,6 +1999,13 @@ static void set_dte_entry(struct amd_iommu *iommu, struct dev_table_entry *dev_table = get_dev_table(iommu); u32 old_domid = dev_table[devid].data[1] & DEV_DOMID_MASK; + /* + * For nested domain, use parent domain to setup v1 table + * information and domain id. + */ + if (amd_iommu_domain_is_nested(domain)) + domain = domain->parent; + if (domain_id_is_per_dev(domain)) domid = dev_data->domid; else @@ -2076,7 +2101,8 @@ static int do_attach(struct iommu_dev_data *dev_data, dev_data->domid = domain_id_alloc(); /* Init GCR3 table and update device table */ - if (domain->pd_mode == PD_MODE_V2) { + if (!amd_iommu_domain_is_nested(domain) && + pdom_is_v2_pgtbl_mode(domain)) { /* * By default, setup GCR3 table to support MAX PASIDs * support by the IOMMU HW. @@ -2117,8 +2143,9 @@ static void do_detach(struct iommu_dev_data *dev_data) iommu = get_amd_iommu_from_dev(dev_data->dev); - /* Clear GCR3 table */ - if (domain->pd_mode == PD_MODE_V2) { + if (!amd_iommu_domain_is_nested(domain) && + pdom_is_v2_pgtbl_mode(domain)) { + /* Clear GCR3 table */ __clear_gcr3(dev_data, 0); free_gcr3_table(dev_data); }