Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2427194lqz; Tue, 2 Apr 2024 18:17:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZLHU2JKniQV70VHQ9knlYfwIKsoFQSecohvmrSYrFn3dPyXVylrSGkkCSQ8Ugg7uyEmY2gz8OU6pipMlxjkjO3u3wTcAQkdb9s3c5qw== X-Google-Smtp-Source: AGHT+IHyl8t3YN7h0bX7M184nKBiwQqYBKyDlQuw58kq4gUQFILyCqDFSnaUdZREUooTxXWLkQDe X-Received: by 2002:a0d:db8c:0:b0:615:6873:c524 with SMTP id d134-20020a0ddb8c000000b006156873c524mr30994ywe.48.1712107068060; Tue, 02 Apr 2024 18:17:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712107068; cv=pass; d=google.com; s=arc-20160816; b=Cn7NkalUbKwQSPr+DR/Qyx7VlCCCAQP03vQLzD6D8uyyNO5n8PLjQQO64ch+dBA0Sd e9X1iR0cZeYBr1PPVY+5WcVB7h+/lPNe+FLysfyIP9XA4AGmDWKQGtcVPBbkW24DxSPc E89PS2t1hWyTJvhFDRsOBXoH+1V9GmX5gm2H8H7sC6GvS9o27dYMLoHoke/yqfYettTn QpiqRzqwwWpo+kCgw/Ub+mFVX/kVruZFthGnzPgwwmER+P9+G/vY1TzIF4hPsFQY18MS ZFBdyYhx2cVYJU+kLAPSQmf4mDASyFQT3rr/P7I2U9uK/GQWLzQFAldQ5NgzzKvu9mau o2Gg== 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=NLG0zJsNER3Wtec3ajrYbEXW83ugqde3+NOEm7hz/No=; fh=tXslIEC/iII+0o9YvlUtRXapl6zSPusBr1yEidN1Q7w=; b=pBpWSPrpTFY2NaXlCIRaS721Na4i5HCx1Co9O4+gac0D1GkugLXFUTu4XHt3jUkjlJ C5uhOayG+oufjLIS0rtisTMIeeDPJ3WwB4ySueSVT9cQuG1LBr7EJZ/z8LCkT5msGD4q J6fGxTWAsKSYBZkafmx7YTQ4lhJsLhqmKl4VfYByPdO1MI83tpGBtDSBb8DpfTKVuSOX U8QHtf5j3VFPwdxMInuN4yg/IEMnSlmmRg6z7seidSRZR7RTvxdQFSIeIU8GHDz+8gep 3E2xcl3BIKQ64AgmI7pDlbijMXuoAy+X3STc8UDN9q92RMRSfGNPUjDSljXMO+l+baVI wDgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OCmQVOak; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-128919-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vr6-20020a05620a55a600b0078a5169d3ffsi12811445qkn.510.2024.04.02.18.17.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 18:17:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128919-linux.lists.archive=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=@intel.com header.s=Intel header.b=OCmQVOak; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-128919-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 A708B1C241D2 for ; Wed, 3 Apr 2024 01:17:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54DAD1CF9C; Wed, 3 Apr 2024 01:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OCmQVOak" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 DC28D1C280 for ; Wed, 3 Apr 2024 01:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712107002; cv=none; b=hkrgKVFbhvbfJAt9vGLTKtsgjSOBzxSsFBnT2SRd8WGztes9PmmqaQsMHWgT3ehL3ac6mcui/LajsbjiRpHlU3v36uR2zJE/WddL1fnKgjX+DUlXGH73WGk6LSj45yNSB+FY6oVPiISC7POrFqaLJrkrFsd463z2UQOi0LulFQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712107002; c=relaxed/simple; bh=tvoic8JEg5iwsCj9YBFoEAx3/4HZliI5/5DJbrdIfjQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CHgTRbXTemobFCnrzeHUHQJVkofgBwLm7PK6lpVfoSfd/NCuYw46fhzpXkgZT0aJO1amgWMmj1qCAElQBTNyL2BSAd3/ZV7BfWoqQGY47RQFxtvRmCCi1xMcNMgkojzHaZIkeWCmq5yBu4vNd3oFuN551YBPg+na1aD8OmvIXgg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OCmQVOak; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712107001; x=1743643001; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tvoic8JEg5iwsCj9YBFoEAx3/4HZliI5/5DJbrdIfjQ=; b=OCmQVOak0+fK4aq+GzrW3iaTvaJZtvA63ppRgC9sZe73vY0QMUR20chj AeZQH7G/JO77LmHVnJSa1KQz1AOmPaUkNIt53hCpBrwKxDQZPkEgpDKVb T8I3I9WuDRni5K/kB6pe+LWn1aKr2eucbermUszKSyuBsBR44/A1nNHgx 1tlAjzh3RbmjyGbM/tVkynfuaaeEtB7PAL6iQSCcpgSEQoe7R/f7l1CQK z60WCzTbF1NPSCUTaM4ZLEfor8K1HTXzBKAraeWSuJsgZzCpsy8htPgqu 9ngzYekcYMe5bXDYhzKo8tRJnMGDRzkiqSFYAzJmDpwZK+mdyT5g/woAY g==; X-CSE-ConnectionGUID: Y/K7lHe7Sg2IzfVV+7zcMg== X-CSE-MsgGUID: +wQIxxKLTQWuFTcd2IY0zg== X-IronPort-AV: E=McAfee;i="6600,9927,11032"; a="7439778" X-IronPort-AV: E=Sophos;i="6.07,176,1708416000"; d="scan'208";a="7439778" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 18:16:41 -0700 X-CSE-ConnectionGUID: ejLrWSjdRfuR2nGliBxExQ== X-CSE-MsgGUID: SJHBJIhNSEarsqoBdvGlPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,176,1708416000"; d="scan'208";a="22953289" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa003.jf.intel.com with ESMTP; 02 Apr 2024 18:16:38 -0700 From: Lu Baolu To: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , Joel Granados Cc: iommu@lists.linux.dev, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 5/9] iommufd: Add fault and response message definitions Date: Wed, 3 Apr 2024 09:15:15 +0800 Message-Id: <20240403011519.78512-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403011519.78512-1-baolu.lu@linux.intel.com> References: <20240403011519.78512-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit iommu_hwpt_pgfaults represent fault messages that the userspace can retrieve. Multiple iommu_hwpt_pgfaults might be put in an iopf group, with the IOMMU_PGFAULT_FLAGS_LAST_PAGE flag set only for the last iommu_hwpt_pgfault. An iommu_hwpt_page_response is a response message that the userspace should send to the kernel after finishing handling a group of fault messages. The @dev_id, @pasid, and @grpid fields in the message identify an outstanding iopf group for a device. The @cookie field, which matches the cookie field of the last fault in the group, will be used by the kernel to look up the pending message. Signed-off-by: Lu Baolu --- include/uapi/linux/iommufd.h | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 1dfeaa2e649e..83b45dce94a4 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -692,4 +692,100 @@ struct iommu_hwpt_invalidate { __u32 __reserved; }; #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) + +/** + * enum iommu_hwpt_pgfault_flags - flags for struct iommu_hwpt_pgfault + * @IOMMU_PGFAULT_FLAGS_PASID_VALID: The pasid field of the fault data is + * valid. + * @IOMMU_PGFAULT_FLAGS_LAST_PAGE: It's the last fault of a fault group. + */ +enum iommu_hwpt_pgfault_flags { + IOMMU_PGFAULT_FLAGS_PASID_VALID = (1 << 0), + IOMMU_PGFAULT_FLAGS_LAST_PAGE = (1 << 1), +}; + +/** + * enum iommu_hwpt_pgfault_perm - perm bits for struct iommu_hwpt_pgfault + * @IOMMU_PGFAULT_PERM_READ: request for read permission + * @IOMMU_PGFAULT_PERM_WRITE: request for write permission + * @IOMMU_PGFAULT_PERM_EXEC: (PCIE 10.4.1) request with a PASID that has the + * Execute Requested bit set in PASID TLP Prefix. + * @IOMMU_PGFAULT_PERM_PRIV: (PCIE 10.4.1) request with a PASID that has the + * Privileged Mode Requested bit set in PASID TLP + * Prefix. + */ +enum iommu_hwpt_pgfault_perm { + IOMMU_PGFAULT_PERM_READ = (1 << 0), + IOMMU_PGFAULT_PERM_WRITE = (1 << 1), + IOMMU_PGFAULT_PERM_EXEC = (1 << 2), + IOMMU_PGFAULT_PERM_PRIV = (1 << 3), +}; + +/** + * struct iommu_hwpt_pgfault - iommu page fault data + * @size: sizeof(struct iommu_hwpt_pgfault) + * @flags: Combination of enum iommu_hwpt_pgfault_flags + * @dev_id: id of the originated device + * @pasid: Process Address Space ID + * @grpid: Page Request Group Index + * @perm: Combination of enum iommu_hwpt_pgfault_perm + * @addr: Page address + * @length: a hint of how much data the requestor is expecting to fetch. For + * example, if the PRI initiator knows it is going to do a 10MB + * transfer, it could fill in 10MB and the OS could pre-fault in + * 10MB of IOVA. It's default to 0 if there's no such hint. + * @cookie: kernel-managed cookie identifying a group of fault messages. The + * cookie number encoded in the last page fault of the group should + * be echoed back in the response message. + */ +struct iommu_hwpt_pgfault { + __u32 size; + __u32 flags; + __u32 dev_id; + __u32 pasid; + __u32 grpid; + __u32 perm; + __u64 addr; + __u32 length; + __u32 cookie; +}; + +/** + * enum iommufd_page_response_code - Return status of fault handlers + * @IOMMUFD_PAGE_RESP_SUCCESS: Fault has been handled and the page tables + * populated, retry the access. This is the + * "Success" defined in PCI 10.4.2.1. + * @IOMMUFD_PAGE_RESP_INVALID: General error. Drop all subsequent faults + * from this device if possible. This is the + * "Response Failure" in PCI 10.4.2.1. + * @IOMMUFD_PAGE_RESP_FAILURE: Could not handle this fault, don't retry the + * access. This is the "Invalid Request" in PCI + * 10.4.2.1. + */ +enum iommufd_page_response_code { + IOMMUFD_PAGE_RESP_SUCCESS = 0, + IOMMUFD_PAGE_RESP_INVALID, + IOMMUFD_PAGE_RESP_FAILURE, +}; + +/** + * struct iommu_hwpt_page_response - IOMMU page fault response + * @size: sizeof(struct iommu_hwpt_page_response) + * @flags: Must be set to 0 + * @dev_id: device ID of target device for the response + * @pasid: Process Address Space ID + * @grpid: Page Request Group Index + * @code: One of response code in enum iommufd_page_response_code. + * @cookie: The kernel-managed cookie reported in the fault message. + */ +struct iommu_hwpt_page_response { + __u32 size; + __u32 flags; + __u32 dev_id; + __u32 pasid; + __u32 grpid; + __u32 code; + __u32 cookie; + __u32 reserved; +}; #endif -- 2.34.1