From patchwork Wed May 22 22:59:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13671159 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 D5E1EC25B7C for ; Wed, 22 May 2024 23:00:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727904.1132600 (Exim 4.92) (envelope-from ) id 1s9uw5-0007ea-JD; Wed, 22 May 2024 22:59:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727904.1132600; Wed, 22 May 2024 22:59:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uw5-0007eT-GT; Wed, 22 May 2024 22:59:53 +0000 Received: by outflank-mailman (input) for mailman id 727904; Wed, 22 May 2024 22:59:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uw4-0007HJ-7G for xen-devel@lists.xenproject.org; Wed, 22 May 2024 22:59:52 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20600.outbound.protection.outlook.com [2a01:111:f403:200a::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fe6007c1-188e-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 00:59:51 +0200 (CEST) Received: from MN2PR04CA0035.namprd04.prod.outlook.com (2603:10b6:208:d4::48) by IA1PR12MB6649.namprd12.prod.outlook.com (2603:10b6:208:3a2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Wed, 22 May 2024 22:59:45 +0000 Received: from BL6PEPF0001AB56.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::11) by MN2PR04CA0035.outlook.office365.com (2603:10b6:208:d4::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36 via Frontend Transport; Wed, 22 May 2024 22:59:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF0001AB56.mail.protection.outlook.com (10.167.241.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Wed, 22 May 2024 22:59:45 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 17:59:44 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 17:59:44 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 22 May 2024 17:59:38 -0500 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: fe6007c1-188e-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kSWqwj34lnSTz24C5X/+EHE/FPg2TljQtm89RzfiE1VKHedCnedBCw8ut4lHusSeYPRK6Ps/vDPnTm3xQAe9pEQqpe5tSD+NI5KGYK8re6VP9FbEiJNEZGxVGdIIueDqcyGow7oi1l0WNwxb3MIuA6X0F4RVXbvhmGbFrnPOFzhVMeKTibKg0Pal1Xy4IOnp69nVrIclj3mFdGEfz/cgenj7hvMnUyvamCjh2XuNpZZ9Ge0JuUGXsT6CLmf8d5Jr4oT4dWV9O8rcwlFetzIrPIWXDUKcyMt8mCBd8lgawi8+nYgfBZs2ymNSjO0I7So1Bc8Le1yC5XX7TUBOezYw3g== 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=k8+/xJpZRZsK6+RKr2c/38/ePPkO2ljT1mguCOagC4g=; b=Z9ZfhUPdEEEFkmrZExIslnLi2/EYu5qEpVyaQoxlo/UwEEBUFO+oz13p6lExGxOo2j1rORaU1MAdqFBK5jqpI0X6ZWNVQEB8oL2EZWmcagnkpm2GgAUTJG+xEIjWeeG8qEhdC9Y2U/J8/WQaUPkaFj+fXjUIvZqWl134mVvwM/BVE1Wn+tl69RQN2Upyfkh5GGjCyInRvjYt8PT8ZliaSJywl1UsO+hMTVKBCA+km/FJ9OIrmofegy+UwuhZV69seuHFbIaFAhCs8zwbKwQg586X7OOb8ft0yB6pVYI77YqP0jlPzHuC1gBOQBti6RRFlFBj5hZbCevzJvwWJuUOwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=k8+/xJpZRZsK6+RKr2c/38/ePPkO2ljT1mguCOagC4g=; b=F8xSekaFfvRxCBuE4BX5RQahAK8ZR/fBn72L/nuol54TDUUfQbOAwSQVtpWKa9CDOr8kRAjmqoieCMsHSQhjVJYfVn2TUt+Q0GIwqogx7bPZBqwIKV8yFroHHyf5o6E5YXmDZlkjQ0+V639DFe4VnzHuXAHLpuBESWJ0WSuoB9o= 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=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Volodymyr Babchuk , Stewart Hildebrand , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v16 1/5] arm/vpci: honor access size when returning an error Date: Wed, 22 May 2024 18:59:20 -0400 Message-ID: <20240522225927.77398-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522225927.77398-1-stewart.hildebrand@amd.com> References: <20240522225927.77398-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB56:EE_|IA1PR12MB6649:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ffd48ec-c467-4d07-6ea5-08dc7ab2df95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: ngdG/B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gYAxqeqAL4E+SKd0eaflIJJdu39ih1oKJiApIRpLEijz7fVZmsG/csNGVSzFnronDM0/qlz8IBiEkSxW94/2x4T1K69ZyDvdPRFl087VZ218oy/j33F7fjstDzoOoYNjK/dlaEg4W1Mc6DG/ACnxh3KqzxKSQ+2flLmlvUowxq5YSuYrMKzV5AU2tPXkxYhsSbYlwjxwsD2G055QWlD2vsRmRXGc0qMlpnQ7UFE6HepFOsnDe7ZFAjZvLweF4BOZQsu9h1G6OUYXhXL8kVpyJJey/z59YXBy3opQ/fK9u7RbSYVLhP7iZglIit X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 22:59:45.3178 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ffd48ec-c467-4d07-6ea5-08dc7ab2df95 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB56.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6649 From: Volodymyr Babchuk Guest can try to read config space using different access sizes: 8, 16, 32, 64 bits. We need to take this into account when we are returning an error back to MMIO handler, otherwise it is possible to provide more data than requested: i.e. guest issues LDRB instruction to read one byte, but we are writing 0xFFFFFFFFFFFFFFFF in the target register. Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand --- v14->v15: * re-order so this patch comes before ("xen/arm: translate virtual PCI bus topology for guests") * s/access_mask/invalid/ * add U suffix to 1 * s/uint8_t/unsigned int/ * s/uint64_t/register_t/ * although Julien gave an Acked-by on v14, I omitted it due to the changes made in v15 v9->10: * New patch in v10. --- xen/arch/arm/vpci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3bc4bb55082a..b63a356bb4a8 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -29,6 +29,8 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, { struct pci_host_bridge *bridge = p; pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + const unsigned int access_size = (1U << info->dabt.size) * 8; + const register_t invalid = GENMASK_ULL(access_size - 1, 0); /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; @@ -39,7 +41,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, return 1; } - *r = ~0ul; + *r = invalid; return 0; }