From patchwork Tue May 21 13:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: CLEMENT MATHIEU--DRIF X-Patchwork-Id: 13669436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 027D0C25B7A for ; Tue, 21 May 2024 13:13:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9PI1-0008A1-2b; Tue, 21 May 2024 09:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9PHU-0007iH-V5 for qemu-devel@nongnu.org; Tue, 21 May 2024 09:11:55 -0400 Received: from smarthost3.eviden.com ([80.78.11.84]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9PHP-0001ZU-M0 for qemu-devel@nongnu.org; Tue, 21 May 2024 09:11:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1716297107; x=1747833107; h=from:to:cc:subject:date:message-id:content-id: content-transfer-encoding:mime-version; bh=UC955ve1PDtXXjeo7AbZf0igBYATbHJ9851haDKRd9o=; b=H83Gs97//Pp3t+EDp4Wysnr7m6YOUW8AsFmFTGnZlMHKZo2RyEJdVMJA tDt8FOCZudio5cajL0q0Y0CWqFRahrNMXkJI/Rtr2/WrbLqoYJFS+mAHh hx6ND5XbAu3RIEkiZQ9uOKDGTQY6JiccMlgSbQmyUB0BIVlGU+R1q7yEM //aO0lGVfGJxuUXlZJ3aj9OYgFO0OS0dejknDt5PMcTFaD6/GxyHvjm7B 5YsHufNu30KioQEsM0gUMy0ZH9PEjNTOxwZUrotCGdVBkRB0/EYyEi6BB qb6tPcbr52l+pzLIehr7duv6TQR00ShsIoJuf4RcqV0K6uktHrzuAKIXP w==; X-IronPort-AV: E=Sophos;i="6.08,177,1712613600"; d="scan'208";a="13007989" X-MGA-submission: MDF1mtFCsQanr84fsYZrmjGoHIjo6GLPMpvc3uz5on+xJm06eQ6VfEXY4+tbMcSHENBGjTn3BKJhTtVQJ4QqlqxvPMZRv78rxdVSziUKdi7aQalFpBYJCpSkVr7xW8L6hia9bsLRYizJ0VarRB7/txHu0QUHN+ILq/RHu3hjkUp7WA== Received: from mail-db8eur05lp2105.outbound.protection.outlook.com (HELO EUR05-DB8-obe.outbound.protection.outlook.com) ([104.47.17.105]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 15:11:40 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SzMk6flweDgEEZQIabrOF6KJRlw9Ardyb5aCwclMkBo7Zn7IAOwza+/QG9+uDcDTzjyWBnXdlHfg5hAH7Jfd7B6MMf02HJ44j7EOvP4mt851sS5QzQf1p3QEH0inCiApsm9q3+WOBgU+p5j/KgmSjmsKbQGMZlZXSvOuK9XOnaPEtUMXT/dNZ0Ph1NkFH9IqmwMBRZnOExeuKHc7lSwexz43QO0ZqLX1axBkE2S/26uIUajeOzB3UhmsXU3o0j7v9DCBH0AyBgz6uRbToBJZTZCizc2N3nsT3bH/JjBQ0+kxJETjwT1/cg/CmIWpJkz66cAN+9dBtAEvF1MMLPDnig== 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=UC955ve1PDtXXjeo7AbZf0igBYATbHJ9851haDKRd9o=; b=Q1BpdFnd6OUWaEHwdzD5C67GjCA+3EKOAJ2C7ANKAITZAGh90sw6zzkQvbyrrd9Vxr2ZhDVL71rv9IhUhmuQDBAuTrPF2tWeCihzaqVVg3nbe4rNGqAghfBVvLdtdYvERPWc1yliGFvA84B92w9jjJ0lkciEB7CNzw7j01fOJ5mgn8VvAoH6YEBqvx/y9Ba07RKDuMcLcgqVPwHwzog/TK+jsVTzzoUyhJod53mGQajsBThQbO8PXx2dI6SL5NmK9n+sb4TTgH1TLswn/KG/n4wcXyGJB6u34DmZRUa2v3J/LnejAZccJrvQEbiyOY39b6pv3L3h+ytEow4C3kP1FA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eviden.com; dmarc=pass action=none header.from=eviden.com; dkim=pass header.d=eviden.com; arc=none Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by AM8PR07MB8148.eurprd07.prod.outlook.com (2603:10a6:20b:323::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.35; Tue, 21 May 2024 13:11:37 +0000 Received: from AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d]) by AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d%5]) with mapi id 15.20.7587.035; Tue, 21 May 2024 13:11:37 +0000 From: CLEMENT MATHIEU--DRIF To: "qemu-devel@nongnu.org" CC: "jasowang@redhat.com" , "zhenzhong.duan@intel.com" , "kevin.tian@intel.com" , "yi.l.liu@intel.com" , "joao.m.martins@oracle.com" , "peterx@redhat.com" , CLEMENT MATHIEU--DRIF Subject: [PATCH ats_vtd 00/22] ATS support for VT-d Thread-Topic: [PATCH ats_vtd 00/22] ATS support for VT-d Thread-Index: AQHaq4Bp7DM+3gMpqEmkh696Y/p0ew== Date: Tue, 21 May 2024 13:11:37 +0000 Message-ID: <20240521130946.117849-1-clement.mathieu--drif@eviden.com> Accept-Language: en-GB, fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eviden.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AM8PR07MB7602:EE_|AM8PR07MB8148:EE_ x-ms-office365-filtering-correlation-id: fc05b5ac-43e4-46ee-986a-08dc79978bdc x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|366007|1800799015|376005|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?ehLxWyPHpB+zqtX/qQ84Xq4AigRpkzU?= =?utf-8?q?aBdU7rTrXK/jnlgpeVIT2+YqZMi6+KTNKDb/SvB9HSKScFBynhb/fMfh5On7pXUHH?= =?utf-8?q?+4zAHkcAtqchFzgrHCkksrrXZCBhHdxms6TLFjwgQMrLCkCxAHnWbrMfoiFyAinEY?= =?utf-8?q?C24AAwp44d83E+bbAwP7IoTsK9inad/Hqc2nikivp/tPrb//7a0Srg6LZoOU+QI6S?= =?utf-8?q?JJqIwiofc0hDpU2RCqzPPxBsJ1QPzkebW+x/Ik+51wRlPxaTNsdioVADdR5qTwZnC?= =?utf-8?q?4SDxm2F/L0qHe+W77EbILUp/MsiU6g4NP0Jbn+fRaZHsirqCITMhdbyXDYMbx2A/P?= =?utf-8?q?YIgu5brICIOMXHIeAW6CWTQtSJ+Tmz3T/dcmUX3OwBL4bDu9wev+fJIF4EIPPL1eZ?= =?utf-8?q?4JDmmuAoKROtUpniezNoHU3DAaju4Q4/vkMpgyK80VH/G8ULfJurSsW077Ek7m+Gc?= =?utf-8?q?4ITakArBG/876U1PqpEhfVPWmz5hPhFUrfgGiAUhoorQ3bcQulWSZ5YqRmtyI2D2R?= =?utf-8?q?IaymeA3qzszX4GNHagGEIMGcWEilJo+nACGjftc1V8T+wsR7drysvhxsE0JxXG9+G?= =?utf-8?q?0ZB7/N6YeA1zauoKJF1zcNnDEcncXKr+iBN2gAUAlmwq+qcp3tculWtmUbdfX4iIv?= =?utf-8?q?TWva9I+ECuB4XkSN43PG3CSt7C20I5HEZu7EcBRpUqGHhFi4LnB5FrWN+dvk2Mo2Q?= =?utf-8?q?ZAUKkcKKFrhsNtBjBWY6RofbaDaIL9vIwh8ZCfnG35MM/L1McXVLZ/bo4DR9pg6Qr?= =?utf-8?q?3lQ3bZJoHnwRg6yEJy810K1oaXTCmXxhZmwZlrtf8TlHuKmDg7q41eW2O+UOzikYc?= =?utf-8?q?pw7Yqc8Jyn7/SExG76qG7wVIVIUI4pHnSL4cX8EcB4cFUnERhVjCLY7LYuZB8sV+y?= =?utf-8?q?1uxcRUURi3FzFx+78wTxt7j6fc4TZ7F366EIHZJCUjkMpC/F0EVb0iA5hWg9Uxx9y?= =?utf-8?q?5zAAttwVDirV97GmlHgmCEtDiLZ11b0UTLYGS9XTIdqlySL0ktwp/yfVTmvYvNMOG?= =?utf-8?q?QoNZEN4pUyuhyD8B2tjcRBpNJlol4uHDbIpW/e6S28ThFysXcliYrvfplnng/my53?= =?utf-8?q?PopBpivp8ZRh/Th3GIHGwDjlwsWDWsKmWR8ZJd8BH697IUS36gPJ+AbT8dg7EOjnB?= =?utf-8?q?nszekChzg8j9KCD6lKjoxZSc4dnDRBzsnJZBChokh3V+xvl1Sk0PKfStA5j5waX2P?= =?utf-8?q?bG4L+81Le2tq9sMxbN8csDhjL2uSHVbWsJqg=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM8PR07MB7602.eurprd07.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366007)(1800799015)(376005)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?kgwAEFFV3YWI9bfcfzC0sdfWhYwy?= =?utf-8?q?iCm+iXJrkfcWzNd80yXTS9MOub+eLbWJ/UYn4snVVZA9Pbcxs/meZ6tJM+V4Oi6if?= =?utf-8?q?LVZD5swFREEAmvHIVq/5U0lkqJijQX+vJtTJX/3GphPkJ+YgXfQ060I5GqP0GrMNU?= =?utf-8?q?dRy2MJ0e26i2kfdpaIL+bFqY/6/W50D14MISbn3vpReSYEu+WZXTQkj0fOOxKetPe?= =?utf-8?q?etnchUwIe2r42/IXKNW4ewhPekuklTsXF2tdOSm7D6A/OOFjCofVH5dbU/mwVJvph?= =?utf-8?q?qpH2bRHj6B7kedahXGM/CTzYme8MdkMS2ZCTV1sKG+e/DaurG1XiRwE5W+V7yt1Rm?= =?utf-8?q?5EpJKEyoBfyeDiOn7uh5iSMDMeXSv5F4hytAYRwPWKAYfwYss7+l3VgDhNbvgMidh?= =?utf-8?q?/SNOfbV2orzMLvBifwkT95b2SfA1+5ls6xXIXBjmAIzJdgKE0H3sGLvlNLyAiafLv?= =?utf-8?q?M+sadt0ZsmAeCc0hLDiq8YFg7rvTe5yGliYyvfvG4U43/zUsoRIX7evGxq/UfnquX?= =?utf-8?q?f8k4megpuoX8BfBfKYJX4iYuJextpdN+rx6WWFvuUUd51hKc6Wei+6PuREJMUSNf4?= =?utf-8?q?uGzQso5i/zYSHYAM6DsVXE2DacdAubcVHBvUDcWZ9U/mKg+lktRPTrMtmKTfZ3t/F?= =?utf-8?q?2Bmmd9pXSP1VAkZV1eoL9pAVx/Q/I5oNIfLIeTnKNpHf5yvvqutQz6Lhd0CpcppzU?= =?utf-8?q?5nFtw2Izg/np3Q9riXDw841B/7w+EBS8spe9lRObiVG1kW1xrfpMCMm/GrV2gGFPa?= =?utf-8?q?DL9yics6SfgeU4Sw3KzTAuswz9u1nXwMzzV9okWr9gsrwxqIfW89sd4TDzpOpTEdN?= =?utf-8?q?3+CP8XPqIaqXfmHG7/PcqbxzxGcqaXOa1XHuxEu5nWY79N1xsTMEmPsx8T1d6sCzZ?= =?utf-8?q?2Aehrms1g1XP7LiZI1GKUkKp2iPRUgXhHu7Qtk3sZBMvvnuklB7DUuQ7f6cOZFZxQ?= =?utf-8?q?JYe3QMFa9YGiz+YcuApZz6HFsEWsRPx9Tk85pWWPuYZ00ckHHDCxfz5sE7pUGMltU?= =?utf-8?q?j1tPcZ9npzTEs0PDwoUifKAb25Fu22I8RQQqeKLqu0OMAhztrWVd7Q99K201Afsip?= =?utf-8?q?BQpH87BHb+5Mruk/Vn7tjQEHFXzSKYRPQrUjJr1JKI2FVtAPtJQt4TVbIXDZeKzFS?= =?utf-8?q?tCeICp46y/WCcQtEk45mlEBrAfX+64W5YgwOT+0V+3R7psdPT6Mr79fK9BK6pXwF4?= =?utf-8?q?AG00Q9PNoqj0d9GtunVj58cWRFC0PnLGOvlXA1OCdbxN/6yTkSVmth5yrf+gdLiif?= =?utf-8?q?VpD5APLOwrjIT7ytolzvyJMUsrXmmdw0r6kGOBbqEPHfQKLAkC0UkJvJtNBOr3dP8?= =?utf-8?q?ynmflMCBAJm++jdGDn/GAbbaZpajim9dRYHSU4MxXNYo4Qw+s85KieDI5IjMOoMtc?= =?utf-8?q?ST6mYMYmalchLNhT36wavAyH9oD+MNJj76cSAqy6dUPmd3c+sRGFF2WS5/HXuAViG?= =?utf-8?q?Ohhh1CmoPCuDAvFzT1Z4o0CXE3QW9c2b+qJ8GBQpj+VBg/95iGbeKoqvWrzNU2M3P?= =?utf-8?q?XX4U0v7WS3Rmqim723FM9e0eYKB5caiALDp680jNLCOxfybSe9pNISs=3D?= Content-ID: <8BF7193DBE3DB042AA29DA46BC29D8BA@eurprd07.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: eviden.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM8PR07MB7602.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc05b5ac-43e4-46ee-986a-08dc79978bdc X-MS-Exchange-CrossTenant-originalarrivaltime: 21 May 2024 13:11:37.3260 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7d1c7785-2d8a-437d-b842-1ed5d8fbe00a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 01EkUkQiqrpgc2E7pYgCJghEM9v5qkgsEqx7kHFa1vWx8B/Ws8dJwDa5c53nzkwaukIbLHZPjid5jChvYo0TNjboDGIyiknec3P6ZidQCC3xsmwUYLFrPGxkECEA8+xT X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR07MB8148 Received-SPF: pass client-ip=80.78.11.84; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost3.eviden.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This series belongs to a list of series that add SVM support for VT-d. As a starting point, we use the series called 'intel_iommu: Enable stage-1 translation for passthrough device' by Zhenzhong Duan and Yi Liu. Here we focus on the implementation of ATS support in the IOMMU and on a PCI-level API for ATS to be used by virtual devices. This work is based on the VT-d specification version 4.1 (March 2023). Here is a link to a GitHub repository where you can find the following elements : - Qemu with all the patches for SVM - ATS - PRI - Device IOTLB invalidations - Requests with already translated addresses - A demo device - A simple driver for the demo device - A userspace program (for testing and demonstration purposes) https://github.com/BullSequana/Qemu-in-guest-SVM-demo v2 - handle huge pages better by detecting the page table level at which the translation errors occur - Changes after review by ZhenZhong Duan : - Set the access bit after checking permissions - helper for PASID and ATS : make the commit message more accurate ('present' replaced with 'enabled') - pcie_pasid_init: add PCI_PASID_CAP_WIDTH_SHIFT and use it instead of PCI_EXT_CAP_PASID_SIZEOF for shifting the pasid width when preparing the capability register - pci: do not check pci_bus_bypass_iommu after calling pci_device_get_iommu_bus_devfn - do not alter formatting of IOMMUTLBEntry declaration - vtd_iova_fl_check_canonical : directly use s->aw_bits instead of aw for the sake of clarity v3 - rebase on new version of Zhenzhong's flts implementation (now contains some patches from v2) - fix the atc lookup operation (check the mask before returning an entry) - add a unit test for the ATC - store a user pointer in the iommu notifiers to simplify the implementation of svm devices Changes after review by Zhenzhong : - store the input pasid instead of rid2pasid when returning an entry after a translation - split the ATC implementation and its unit tests Clément Mathieu--Drif (22): intel_iommu: fix FRCD construction macro. intel_iommu: make types match intel_iommu: return page walk level even when the translation fails intel_iommu: do not consider wait_desc as an invalid descriptor memory: add permissions in IOMMUAccessFlags pcie: add helper to declare PASID capability for a pcie device pcie: helper functions to check if PASID and ATS are enabled intel_iommu: declare supported PASID size pci: cache the bus mastering status in the device pci: add IOMMU operations to get address spaces and memory regions with PASID memory: store user data pointer in the IOMMU notifiers pci: add a pci-level initialization function for iommu notifiers intel_iommu: implement the get_address_space_pasid iommu operation intel_iommu: implement the get_memory_region_pasid iommu operation memory: Allow to store the PASID in IOMMUTLBEntry intel_iommu: fill the PASID field when creating an instance of IOMMUTLBEntry atc: generic ATC that can be used by PCIe devices that support SVM atc: add unit tests memory: add an API for ATS support pci: add a pci-level API for ATS intel_iommu: set the address mask even when a translation fails intel_iommu: add support for ATS hw/i386/intel_iommu.c | 142 +++++- hw/i386/intel_iommu_internal.h | 6 +- hw/pci/pci.c | 127 +++++- hw/pci/pcie.c | 42 ++ include/exec/memory.h | 51 ++- include/hw/i386/intel_iommu.h | 2 +- include/hw/pci/pci.h | 101 +++++ include/hw/pci/pci_device.h | 1 + include/hw/pci/pcie.h | 9 +- include/hw/pci/pcie_regs.h | 3 + include/standard-headers/linux/pci_regs.h | 1 + system/memory.c | 20 + tests/unit/meson.build | 1 + tests/unit/test-atc.c | 527 ++++++++++++++++++++++ util/atc.c | 211 +++++++++ util/atc.h | 117 +++++ util/meson.build | 1 + 17 files changed, 1330 insertions(+), 32 deletions(-) create mode 100644 tests/unit/test-atc.c create mode 100644 util/atc.c create mode 100644 util/atc.h