From patchwork Wed May 24 15:22:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13254173 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 05978C77B7A for ; Wed, 24 May 2023 15:22:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.539137.839726 (Exim 4.92) (envelope-from ) id 1q1qJw-0006IF-NN; Wed, 24 May 2023 15:22:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 539137.839726; Wed, 24 May 2023 15:22:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q1qJw-0006I6-KX; Wed, 24 May 2023 15:22:36 +0000 Received: by outflank-mailman (input) for mailman id 539137; Wed, 24 May 2023 15:22:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q1qJu-00060I-Qv for xen-devel@lists.xenproject.org; Wed, 24 May 2023 15:22:35 +0000 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cccfdb45-fa46-11ed-8611-37d641c3527e; Wed, 24 May 2023 17:22:32 +0200 (CEST) Received: from mail-mw2nam12lp2043.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.43]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 May 2023 11:22:19 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by LV8PR03MB7472.namprd03.prod.outlook.com (2603:10b6:408:18f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.28; Wed, 24 May 2023 15:22:17 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::192:6bdf:b105:64dd]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::192:6bdf:b105:64dd%3]) with mapi id 15.20.6411.028; Wed, 24 May 2023 15:22:17 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cccfdb45-fa46-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1684941752; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=o76yZ4k497HOZQhx8YNmmMYxCb66VFuaVaseEYwZvWw=; b=dn65mXJ9/ycP3W/5s5FU3CCqaby88my6tDsGb5Xh5zrHt+fhr9l0oe1F lIkxyd/w1T2rCl4cytlf3FYQTeoPHi2E2UZIyIcgSzO4ULl8fU26rVof/ R2RMGO3lf1ikhLycOAmrYwuIJrLOz/vi4+l4YYouHc+H++Kt/AzHjcXJ3 o=; X-IronPort-RemoteIP: 104.47.66.43 X-IronPort-MID: 109567907 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:51bo66KKseUoK6FHFE+RzZQlxSXFcZb7ZxGr2PjKsXjdYENS3zVSx 2AYUWiEb/7eamX8e9p1YY6y80xXuJPVx9cxSgdlqX01Q3x08seUXt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jb D30l8dFvU2z0mUUnC+oBPr1QWl+DEy60X6wVvdpXf4u8T2SB8zFsIE3OtiA1LkwntlmOs5/L NA3mqfuZYSJRTcnB7l79yNcx1xjEK7rVcrjOZWpX1CVok1bqNXsOUkjTVoOaZFOBi/xJEsEe FoAs2ZzPFKcWmCZ3SchWVryMzEZAVAIj62Bmw5/uCF2Tlfm350i2ECwtYEo3sG/JUhD7FZ+u XtKM1T5f5zZ/5TSZg4KPYKQMOxBGCIawnLKniuLVPuE7xCE27RqqTw/K4+6IiRCdA1JaMJ6d X8uW5jxC4PkxqEM7zM4HQLyGGBfIyFZ0Wi9ikEjKIJ+IEVR9LQQF6+oR4V4o6dSs4kc7Pmss aISe5r6sDYXBTT8P5yrmvDsrlpWAwjuZ4uy6IGcmPLhP73AavXkcGeWMrvBdPWYEYZsyXEcz E+YAQ= X-Talos-CUID: 9a23:tMFRDGP3f82iO+5DW3J/7E05N+4ZXyOM/W+OOxWHWGtncejA X-Talos-MUID: 9a23:yNlMKwnMV+4dFOrFAu1Bdno+GOVCvLuMKXtX0s1dgpCLKCIhP3CS2WE= X-IronPort-AV: E=Sophos;i="6.00,189,1681185600"; d="scan'208";a="109567907" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KsRf5++0xf5A+sk8HxU+DbQz+3tF3tOe5pjRdABYP1nmAOv0+LtJlsomJpZxdZtaiN577t5kklZXC/fyn4Vz9WN4/J6PaBzSMgFaoXRn7bKAJ+P326/yRU6uwwR0ivmc02pEMpp81DP92+Jwu7+uvjhajwF98aMVYeP4Y/mboPXMr8ae6pZkl1Ax0gOYA3zTIVpanfwGSCrNC431Ea+1oXhSHMu2XavS2XM8fCGhN08frVe9WowwTkJAHUXr6PI8Nd9G/XJJiTK6dsXR20A9iGbi1dI/6NmRQzsEsG4szcXztK4VjEc5ndGMgPR+giWUHZ3Mrhk2ok8mApEk1LWEdg== 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=30ru+lLePwOyS4uvchiCqk6eSxy4Oc0C9zDO72tKQss=; b=FfjddFRe46QMf5MIKEHJIIyzS25SoM0VvbAGbX2vQPxxfihqF2ndELV5W9mWWeVFCHHwbo9ZtOmDdecX4Jby7dKoHXK9vMZ3ERLIJPX43Wo85Iy3rkAaUf+NApbpunU3AuZUOxckBn0MzxKFuoPRHmJL8gLD8GrWnf1erQpTJQfr7SPxHY3ZDP0EZnQnp5F6h/Wz+oiU7wB1Qb7XfD/XJvZRyhHFe/7HJEn9n2Lon+gvzFdwhEguijnqdbiyxRJZp6kEOfuomM4MTJDjdeJWZ6opawLpjKxfA/SMYFULCwfQPhQ7Wu6crJBQCcwcyGjONNhvwcxuGpiqgjgw01bZYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=30ru+lLePwOyS4uvchiCqk6eSxy4Oc0C9zDO72tKQss=; b=sESwpvZrGW0hJ/QkSJDIlulWghC4YtdONy5WzbkUYSlyX5m2V8pBYRg8Wwe24R4ZLFhKHj441K/lUROZS5lZ6JgMPBQ8jMz6IBd7YCRv+Pgo56AxYw0ZdO1rVPMFEp0XjhDqznEpjgkM+ee+LI1gNfEEiIVCXCUtKY+GyV+fV8A= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Kevin Tian Subject: [PATCH v2] iommu/vtd: fix address translation for superpages Date: Wed, 24 May 2023 17:22:08 +0200 Message-Id: <20230524152208.18302-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.40.0 X-ClientProxiedBy: LO2P265CA0164.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::32) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|LV8PR03MB7472:EE_ X-MS-Office365-Filtering-Correlation-Id: 630431e9-139c-4744-e7ce-08db5c6aa874 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8nzlfNSFzuxVyZ+QAUUm6PXy1flwqXjDF767tDZAy8L2kYY85+r/M9BIjzB5hFycOsxfLB9qvkCeFbk7kz7aYjhN7z4h5U7ESAc5yAX9fQpeeNHRFWGjpCM+bPRm5E/Prr7GZoqsEuW9FSxRox58jbFvlyvk5gGwhSe9kXAg6viJQGiwAqBFw8kNIRldqF+Ugjn6ZCkvGPRM4okAbF/y9SjVCgmsdjvxI+VX7vzJ1ZbnHuTIUwgtFJ05QVjtW8hBMggvYkNLe430DTeKs67bc4M5TjZrG+dif8YZFfpxJvxBQyFoDbb3J1ruHLor6u6IN0ZjvQEk5Ol7tUunyRENqbR9EpSOUAFmYMtbEfaDn0gqeLZV6JeUJijb8Lp1m0L/Fq7Vmz5UifxL+MmqG5rd3ffr+nAqDNAygZnEVtQiintJ3JTeDEY/Bq9+DeLQflA33H1z9LbNuM9ve/R2e8q0em59cdSbelmi7zr8jduvNjUVV0+hTIGPIHo3OqGEhPt++TdYCBxj3Va5ZZsJ9lyAL1DVRHhA8cq9zM5p+irx3gu1GdlU0BcaTJ7vlbsd5fBq X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(41300700001)(66556008)(66476007)(66946007)(2906002)(26005)(186003)(6916009)(1076003)(478600001)(6486002)(6666004)(4326008)(316002)(5660300002)(54906003)(6512007)(8676002)(8936002)(36756003)(2616005)(6506007)(83380400001)(86362001)(82960400001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?mfHGycDLUuKnh1fxBzgj9YsX1UPQ?= =?utf-8?q?aPkS6i+3qhuvIR+BXNT5U13CiEShzFFjnuXOs8iiHf4PY+wEY/cGV6UAV0R1qtTkc?= =?utf-8?q?IfCJu60KRqp3OHYfOv7UWN+chHWo2rYsxLNF3wutROB22dsybNCPyrC4drb0hFvei?= =?utf-8?q?TaEUPl5LPpoA5O9CXHLeSz89rV8QyFNMfiXl1Iz7N4MTbGzOwkv5Zu0CEPQ3HWl2b?= =?utf-8?q?ALxwUYO90znNE7ivjaHq4SBXSI4ltGjk6OJHLmFLBBgPfRqhBNcWqSmlh4ImM4FkZ?= =?utf-8?q?aAA+nGyanFYrHH1xHwG/JqKGotLX9cWJ70MGEdW9VKjtEJOLPf5bb/fItdNVYCcUV?= =?utf-8?q?BDUzs1jDkNFMTrKK2D7c9Rq6m6e6kwjGB1WYRaerze2fhGypL5Qrtd5soKVYkTiDz?= =?utf-8?q?ABMxil8VfaZhB1JGZ0n/uyanWwmzGgTaZEKMgmp1SK1CsxsBQZRrXn5KfokHQ0F1j?= =?utf-8?q?MBxvhqS6DFFOFUD30QIVq+I9TV6W+O0wspsCALguEJeT2ZqWhECZH3BtczO2TaSU4?= =?utf-8?q?j6FyTZ89s8wEbTGt6R63DrXdlsrDWqcNyqvK3KVDGhxfm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QncfwMeld8FoplKTwkRve8/2tf/c?= =?utf-8?q?4Q0+J7U1oKXlfhOmpOT9q1HaTA/gXyx35OFIZeQS7esYdE1Op/i1qA684X8imkm78?= =?utf-8?q?sA3/VUsuM0b/?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6/SI3eXurq9bb04URCGQkumCu1k394xGBtF5jz1eZdnfKuOs393aJ0bwuGoYHJf4SLXiUpqegbZS7YfOQKmLynSyLN4sR+KKFH6EnHHNgml5kCVXGI2RjCWAfl05jfkpZxmOrZsUl76CdbsEqZPPS7KIAVmrc2eAujYEWmMrlrRGimjGqc3wR7LDsfTTQwcLROiHTSozYBKrBx+jy4N8h6aNrLOhlKjzqF0cmcKfbMNUccUpqrRkNkCdP8CcjXDuUQy+LsbWGJtKKwrlHDS8ob2hIX4ExFrBsoZuu71qVtqNHFiyfzxpeCnXhp/CGugHlh2+5IjhhlXknz4UzbssaRo3euSmCeZRztvDx/8cWNaiKe9p7qppZ1xRbDRRX0b30Z3LNsXuUh1I5t21VdzQ2XNvMl5ck5fqeOQPUQluvT9q12puqOIRcFuHxNNbmFMj4FYTw4FnJye92FzlzAcNWeZDnHSMltAy2UMzwUGiNPnHZcydDTgnzB3pv/pUJ47X81YhqgYvswsibgmmD+6mDWL3/Ji1NpWw97M0jHMdNH7e2D2cPUhnVx/BXYNx2SMVZ8zj6EpR2PVJlZJYWAD4VMhDwahGbmEGqm6PFjYUN41pcc+3Au2yJhbv1kQHN5InxHcjeaCh+PyY+sZxD1RHSrizyU4oxDilimi6RxtQCR8qwimB6UvLF2aoJc0eZAbub1s+gpcf+maEa4nsJSQHd/Uo6tw6VvsfOcWN1tD/IuKPEwqsIubLlEva02/en4k2yGAAMF2y75AR1xUEnAIJXOcxOuqH+qs5gRuvljAEFXWnjW/62yS+ictxY/lMryMk X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 630431e9-139c-4744-e7ce-08db5c6aa874 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2023 15:22:16.7951 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oL4qMSaMqmiyC9Hz10RY+d4KKmWzGImBeiDwY+nze1xuNYnw1Hz7fwuhhKHIQMbfu3mOfa11RN+DatGWR9JjJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR03MB7472 When translating an address that falls inside of a superpage in the IOMMU page tables the fetching of the PTE value wasn't masking of the contiguous related data, which caused the returned data to be corrupt as it would contain bits that the caller would interpret as part of the address. Fix this by masking off the contiguous bits. Fixes: c71e55501a61 ('VT-d: have callers specify the target level for page table walks') Signed-off-by: Roger Pau Monné --- Changes since v1: - Return all the PTE bits except for the contiguous count ones. --- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 130a159cde07..d7ba9a9c349f 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -368,7 +368,7 @@ static uint64_t addr_to_dma_page_maddr(struct domain *domain, daddr_t addr, * with the address adjusted to account for the residual of * the walk. */ - pte_maddr = pte->val + + pte_maddr = (pte->val & ~DMA_PTE_CONTIG_MASK) + (addr & ((1UL << level_to_offset_bits(level)) - 1) & PAGE_MASK); if ( !target )