From patchwork Tue Mar 1 12:40:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 12764706 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 39AF1C433FE for ; Tue, 1 Mar 2022 12:40:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.281334.479635 (Exim 4.92) (envelope-from ) id 1nP1nz-00068p-7m; Tue, 01 Mar 2022 12:40:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 281334.479635; Tue, 01 Mar 2022 12:40:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nP1nz-00068i-1f; Tue, 01 Mar 2022 12:40:39 +0000 Received: by outflank-mailman (input) for mailman id 281334; Tue, 01 Mar 2022 12:40:37 +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 1nP1nx-0005sl-8S for xen-devel@lists.xenproject.org; Tue, 01 Mar 2022 12:40:37 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20605.outbound.protection.outlook.com [2a01:111:f400:7e89::605]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c9aa9b9b-995c-11ec-8539-5f4723681683; Tue, 01 Mar 2022 13:40:35 +0100 (CET) Received: from SN2PR01CA0023.prod.exchangelabs.com (2603:10b6:804:2::33) by MN2PR02MB5789.namprd02.prod.outlook.com (2603:10b6:208:11e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Tue, 1 Mar 2022 12:40:30 +0000 Received: from SN1NAM02FT0008.eop-nam02.prod.protection.outlook.com (2603:10b6:804:2:cafe::8c) by SN2PR01CA0023.outlook.office365.com (2603:10b6:804:2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Tue, 1 Mar 2022 12:40:30 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by SN1NAM02FT0008.mail.protection.outlook.com (10.97.5.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Tue, 1 Mar 2022 12:40:29 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 1 Mar 2022 12:40:28 +0000 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 1 Mar 2022 12:40:28 +0000 Received: from [10.108.8.223] (port=53852 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nP1nn-0000Ui-E4; Tue, 01 Mar 2022 12:40:27 +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: c9aa9b9b-995c-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JWkYG6IsxD98zWO/PTntRRXAGNpiCFZ5m2MTz+NczXGmqgmzXOmb61sCiRrsx0cgTu470mGSpoOIwgubL03DW4y6u004an2sMrxbGTtjN6vpSGOGKghc5HUcPsXHjxpTlLQgR8I2z0kqepG3CaymOOKqWNNJUh2VWQLWWzaFTMEcHz3AW8sLEFqNVopN5mAYsF7IOKdXG63G9wamzEelJzjeamlHnwjxRml+4tFcb+wpnSpdlyCgRiHeXBIPxEHugnzyCENLkNXA3TMIAOAEPdEGTYzmyElqPAOc4CLl1QFUs8spwwR58a2keUWc6a82+HctRy6bFGe/jQA72QdDoA== 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=+8o+9YqgUrb/hZmnZVc0UJwjMZa2ok5VdKErypv1CWA=; b=nIs4ZL9Y50uOtuGMr2h+UDusOmyID/I2rqNPrtLrHLyXZJ96AuZUjvhfekB+YE4uZ7Ggjxzjay/Rct/nstZ2OSBI4PcACqaxKVNxg63XV5e0/nLIsqNwvY7ob3A74z42F+z2yCuTctJJVTQiPChLFdMQLSOs7r5ONU69bAQ449lxIniQwKfBrgIFKjtWZfpLgBUVwV5Tpv0b/6+8r0bHHVxZto0BWHbGQd67MLP/23HyFe1/2+IUMCyD0OhIoS7apbnzEJ+f6yAFW7vpRTgnjFUojbH7u+Qlrb7UrXGkIl2qoNVDF/7ue7dlGfvm4dX9pFqy1GIGytv2hLO4T1MS+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.80.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+8o+9YqgUrb/hZmnZVc0UJwjMZa2ok5VdKErypv1CWA=; b=AjSpIuuuitsivCu0lnB85CBTJ3YjBzlY24BA4tIHK6murMzFDZ+CP5yP3OVerAk7zSNLzeg2goZbcB1M/CCKAEHcm9ZBoL8+ofG8QZd5tHHL6N0DDPkgqgHtvogeVrzibP+7f4xfE/eqzHEgQ/w9XSmOgIlrvDkAaWuIUsxjUYk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch01.xlnx.xilinx.com; From: Ayan Kumar Halder To: CC: , , , , , , , , , , , Ayan Kumar Halder Subject: [XEN v9 1/4] xen/arm64: Decode ldr/str post increment operations Date: Tue, 1 Mar 2022 12:40:19 +0000 Message-ID: <20220301124022.10168-2-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301124022.10168-1-ayankuma@xilinx.com> References: <20220301124022.10168-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6defbd93-9392-4130-6e1c-08d9fb80ab89 X-MS-TrafficTypeDiagnostic: MN2PR02MB5789:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uAsw3kCEpuF9xuCyCTcGTWwwTIBaae0a3G805rvbUBXsGLqDZ5BAJx2XMQrYRkt+fJxsRJ2ZEA4xv7T8pMm9+RTKwp8lqFpnLP/uxRBMldPgZ1jF3NJGa655+A5WW17Or0lJn9rCP8Sg25nyfITxioy8h0JY4sWPIuzsEfajLAMO9qNENrt6SltaCVqffBnY32Wah5nPICHZSBEBcSOKtQsokWHHxmQxZhWmDfV0KtmmFWi+hms3a817A0KjU9sFj8+eaxk11zt0ct6Jg3elSZtp9CjXRHqv0rf7X8enfzUrETGIFBx0SfH28US8FzX63EM8WN4028SZPyeBEURde3VsyOiDaLAbY0ViEN8QroWyLF4uzD6LrH3xa66qLiYkArzGOta88tlR2TBku3j+J9Rdv3s42sKZnmwBAFQHvHksI29LBXEEwZ3P57WIo203Wo5vmkDc+4bN37Daojr2quD4MeDI4vM3VoXm8Oat1m1kXm7mSUz4oS+aUgw8yunApe5MwNm1sP+3lrnxL+O848djA3DExiP2PES9hiW+tUOabNEcnYuJzpzC4p+wWNqGFdVt/pryEnINpRA/Hc70Rm/uU7z3H9tzWK3UCE78BVtmMNaPHHaa2bQp9UcMyYylsWC3n/K5mEJ6I5rxR74eN2Pw1R2Ra2YVfjV4kZ6U60ZGjOR8IyLpGgfTCZNchnbj/1qTxgMqt8sSmYy0qf5U3Q== X-Forefront-Antispam-Report: CIP:149.199.80.198;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:xir-pvapexch01.xlnx.xilinx.com;PTR:unknown-80-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(26005)(54906003)(40460700003)(6916009)(6666004)(186003)(36756003)(356005)(7416002)(82310400004)(107886003)(2616005)(5660300002)(1076003)(316002)(508600001)(47076005)(7636003)(7696005)(83380400001)(2906002)(70586007)(8676002)(70206006)(336012)(426003)(8936002)(4326008)(36860700001)(9786002)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 12:40:29.9276 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6defbd93-9392-4130-6e1c-08d9fb80ab89 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.80.198];Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB5789 At the moment, Xen does not decode any of the arm64 instructions. This means that when hsr_dabt.isv == 0, Xen cannot handle those instructions. This will lead to Xen to abort the guests (from which those instructions originate). With this patch, Xen is able to decode ldr/str post indexing instructions. These are a subset of instructions for which hsr_dabt.isv == 0. The following instructions are now supported by Xen :- 1. ldr x2, [x1], #8 2. ldr w2, [x1], #-4 3. ldr x2, [x1], #-8 4. ldr w2, [x1], #4 5. ldrh w2, [x1], #2 6. ldrb w2, [x1], #1 7. str x2, [x1], #8 8. str w2, [x1], #-4 9. strh w2, [x1], #2 10. strb w2, [x1], #1 In the subsequent patch, decode_arm64() will get invoked when hsr_dabt.isv == 0. Signed-off-by: Ayan Kumar Halder Reviewed-by: Stefano Stabellini --- Changelog :- v2..v5 - Mentioned in the cover letter. v6 - 1. Fixed the code style issues as mentioned in v5. v7 - No change. v8 - 1. Removed some un-necessary header files inclusion. 2. Some style changes pointed out in v7. v9 - 1. Rebased on top of the master. 2. Renamed psr_mode_is_32bit to regs_mode_is_32bit. xen/arch/arm/decode.c | 79 ++++++++++++++++++++++++++++++++- xen/arch/arm/decode.h | 48 +++++++++++++++++--- xen/arch/arm/include/asm/mmio.h | 4 ++ xen/arch/arm/io.c | 2 +- 4 files changed, 124 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c index 792c2e92a7..3add87e83a 100644 --- a/xen/arch/arm/decode.c +++ b/xen/arch/arm/decode.c @@ -84,6 +84,78 @@ bad_thumb2: return 1; } +static int decode_arm64(register_t pc, mmio_info_t *info) +{ + union instr opcode = {0}; + struct hsr_dabt *dabt = &info->dabt; + struct instr_details *dabt_instr = &info->dabt_instr; + + if ( raw_copy_from_guest(&opcode.value, (void * __user)pc, sizeof (opcode)) ) + { + gprintk(XENLOG_ERR, "Could not copy the instruction from PC\n"); + return 1; + } + + /* + * Refer Arm v8 ARM DDI 0487G.b, Page - C6-1107 + * "Shared decode for all encodings" (under ldr immediate) + * If n == t && n != 31, then the return value is implementation defined + * (can be WBSUPPRESS, UNKNOWN, UNDEFINED or NOP). Thus, we do not support + * this. This holds true for ldrb/ldrh immediate as well. + * + * Also refer, Page - C6-1384, the above described behaviour is same for + * str immediate. This holds true for strb/strh immediate as well + */ + if ( (opcode.ldr_str.rn == opcode.ldr_str.rt) && (opcode.ldr_str.rn != 31) ) + { + gprintk(XENLOG_ERR, "Rn should not be equal to Rt except for r31\n"); + goto bad_loadstore; + } + + /* First, let's check for the fixed values */ + if ( (opcode.value & POST_INDEX_FIXED_MASK) != POST_INDEX_FIXED_VALUE ) + { + gprintk(XENLOG_ERR, + "Decoding instruction 0x%x is not supported\n", opcode.value); + goto bad_loadstore; + } + + if ( opcode.ldr_str.v != 0 ) + { + gprintk(XENLOG_ERR, + "ldr/str post indexing for vector types are not supported\n"); + goto bad_loadstore; + } + + /* Check for STR (immediate) */ + if ( opcode.ldr_str.opc == 0 ) + dabt->write = 1; + /* Check for LDR (immediate) */ + else if ( opcode.ldr_str.opc == 1 ) + dabt->write = 0; + else + { + gprintk(XENLOG_ERR, + "Decoding ldr/str post indexing is not supported for this variant\n"); + goto bad_loadstore; + } + + gprintk(XENLOG_INFO, + "opcode->ldr_str.rt = 0x%x, opcode->ldr_str.size = 0x%x, opcode->ldr_str.imm9 = %d\n", + opcode.ldr_str.rt, opcode.ldr_str.size, opcode.ldr_str.imm9); + + update_dabt(dabt, opcode.ldr_str.rt, opcode.ldr_str.size, false); + + dabt_instr->rn = opcode.ldr_str.rn; + dabt_instr->imm9 = opcode.ldr_str.imm9; + + return 0; + + bad_loadstore: + gprintk(XENLOG_ERR, "unhandled Arm instruction 0x%x\n", opcode.value); + return 1; +} + static int decode_thumb(register_t pc, struct hsr_dabt *dabt) { uint16_t instr; @@ -150,10 +222,13 @@ bad_thumb: return 1; } -int decode_instruction(const struct cpu_user_regs *regs, struct hsr_dabt *dabt) +int decode_instruction(const struct cpu_user_regs *regs, mmio_info_t *info) { if ( is_32bit_domain(current->domain) && regs->cpsr & PSR_THUMB ) - return decode_thumb(regs->pc, dabt); + return decode_thumb(regs->pc, &info->dabt); + + if ( !regs_mode_is_32bit(regs) ) + return decode_arm64(regs->pc, info); /* TODO: Handle ARM instruction */ gprintk(XENLOG_ERR, "unhandled ARM instruction\n"); diff --git a/xen/arch/arm/decode.h b/xen/arch/arm/decode.h index 4613763bdb..13db8ac968 100644 --- a/xen/arch/arm/decode.h +++ b/xen/arch/arm/decode.h @@ -23,19 +23,55 @@ #include #include -/** +/* + * Refer to the ARMv8 ARM (DDI 0487G.b), Section C4.1.4 Loads and Stores + * Page 318 specifies the following bit pattern for + * "load/store register (immediate post-indexed)". + * + * 31 30 29 27 26 25 23 21 20 11 9 4 0 + * ___________________________________________________________________ + * |size|1 1 1 |V |0 0 |opc |0 | imm9 |0 1 | Rn | Rt | + * |____|______|__|____|____|__|_______________|____|_________|_______| + */ +union instr { + uint32_t value; + struct { + unsigned int rt:5; /* Rt register */ + unsigned int rn:5; /* Rn register */ + unsigned int fixed1:2; /* value == 01b */ + signed int imm9:9; /* imm9 */ + unsigned int fixed2:1; /* value == 0b */ + unsigned int opc:2; /* opc */ + unsigned int fixed3:2; /* value == 00b */ + unsigned int v:1; /* vector */ + unsigned int fixed4:3; /* value == 111b */ + unsigned int size:2; /* size */ + } ldr_str; +}; + +#define POST_INDEX_FIXED_MASK 0x3B200C00 +#define POST_INDEX_FIXED_VALUE 0x38000400 + +/* * Decode an instruction from pc - * /!\ This function is not intended to fully decode an instruction. It - * considers that the instruction is valid. + * /!\ This function is intended to decode an instruction. It considers that the + * instruction is valid. * - * This function will get: - * - The transfer register + * In case of thumb mode, this function will get: + * - The transfer register (ie Rt) * - Sign bit * - Size + * + * In case of arm64 mode, this function will get: + * - The transfer register (ie Rt) + * - The source register (ie Rn) + * - Size + * - Immediate offset + * - Read or write */ int decode_instruction(const struct cpu_user_regs *regs, - struct hsr_dabt *dabt); + mmio_info_t *info); #endif /* __ARCH_ARM_DECODE_H_ */ diff --git a/xen/arch/arm/include/asm/mmio.h b/xen/arch/arm/include/asm/mmio.h index 7ab873cb8f..3354d9c635 100644 --- a/xen/arch/arm/include/asm/mmio.h +++ b/xen/arch/arm/include/asm/mmio.h @@ -29,6 +29,10 @@ typedef struct { struct hsr_dabt dabt; + struct instr_details { + unsigned long rn:5; + signed int imm9:9; + } dabt_instr; paddr_t gpa; } mmio_info_t; diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index 1a066f9ae5..fad103bdbd 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -141,7 +141,7 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, { int rc; - rc = decode_instruction(regs, &info.dabt); + rc = decode_instruction(regs, &info); if ( rc ) { gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); From patchwork Tue Mar 1 12:40:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 12764707 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 606ADC4332F for ; Tue, 1 Mar 2022 12:40:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.281336.479645 (Exim 4.92) (envelope-from ) id 1nP1nz-0006Hs-R6; Tue, 01 Mar 2022 12:40:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 281336.479645; Tue, 01 Mar 2022 12:40:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nP1nz-0006FM-KO; Tue, 01 Mar 2022 12:40:39 +0000 Received: by outflank-mailman (input) for mailman id 281336; Tue, 01 Mar 2022 12:40:38 +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 1nP1ny-0005sl-0t for xen-devel@lists.xenproject.org; Tue, 01 Mar 2022 12:40:38 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20619.outbound.protection.outlook.com [2a01:111:f400:7e8a::619]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c99c4667-995c-11ec-8539-5f4723681683; Tue, 01 Mar 2022 13:40:35 +0100 (CET) Received: from SN2PR01CA0018.prod.exchangelabs.com (2603:10b6:804:2::28) by CO6PR02MB8740.namprd02.prod.outlook.com (2603:10b6:303:137::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.13; Tue, 1 Mar 2022 12:40:31 +0000 Received: from SN1NAM02FT0008.eop-nam02.prod.protection.outlook.com (2603:10b6:804:2:cafe::5c) by SN2PR01CA0018.outlook.office365.com (2603:10b6:804:2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 1 Mar 2022 12:40:31 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by SN1NAM02FT0008.mail.protection.outlook.com (10.97.5.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Tue, 1 Mar 2022 12:40:31 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 1 Mar 2022 12:40:29 +0000 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 1 Mar 2022 12:40:29 +0000 Received: from [10.108.8.223] (port=53852 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nP1np-0000Ui-Kn; Tue, 01 Mar 2022 12:40:29 +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: c99c4667-995c-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dnf2ucCp7HQSW8784E9FbEEtd1BklkSLuEqx+v77R5SJB0i3XfNm8k3DsNRNZKd2GqlTyId+dJGCXge1ZvaMw+/8M5PFfLoaQnC+vnGx1eEILLPqjUzTG57ZozmKdbqPUv07YbhTky6v0iOWEuSkGLPOWTGMoblXJdG5qpVqXtA/InJ/u/2+K+K5eCiiHK5QoNY0erajmp4cU0sgQxFRQ4nlf4d80dxuy4BriX/hDXIs2EO9m/CXx6RDlWvkQQ8GzAoNgzoYFCZpEWCXR/wKnbbX7PIh68jWSIcK/tGdY31hr8WEN4ZnioQpHpACEN44tMwfqN4co+zcLYJ3JG031A== 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=Bhj1NX8FCoRo5gnmWG26pkZJvCkh97mFevBkM0EGpmA=; b=Feh0poPbLm2UzLO2lnEOPyLCMsehc6yVVDDoaEm1qkT+x4yvVGUh+Mo1nH6AjFgSRgBs0Nvw53BwoqIfKTZmXAY4eL8zBX/cCz2JSto5cIQqaOjRYBO/p5r9IuGaIpnhAhopqhyEzk8A80V32gkBhbVts25+6w4uCpQmv/qjXiW4xt/YtB2qgZZGjZJp2Tdwb/3HqZxUDZOLCwVA2f9wq4sHw/mY0xZpicj91UsiKsCq62SZJdzJJHfi/xsdceyrxP6pDfMf5lXKeyEpoq1WWJI0HlsKbxAYefCAoZ+aISff2sAV/hGEGQmreCEZCDGSmgb+oU4kZhjE39Z/Wtmqvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.80.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bhj1NX8FCoRo5gnmWG26pkZJvCkh97mFevBkM0EGpmA=; b=RmcDEf1nBumi+UTERObK3HTC/mkNyHmXDIVsp4f1WrnOLduUbpHsaEW2NCsP8Edd/56FCTjQt4wvLwb5eSIQTT+QItxcNGbbDDIV9g5VzQLyqFCJy43BQ7Y7ZfpcKOhNSdCUzGJAPREkPd1rN+GKWoS8QIM6xgf2UblNCiQnaCE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch01.xlnx.xilinx.com; From: Ayan Kumar Halder To: CC: , , , , , , , , , , , Ayan Kumar Halder Subject: [XEN v9 2/4] xen/arm64: io: Support instructions (for which ISS is not valid) on emulated MMIO region using MMIO/ioreq handler Date: Tue, 1 Mar 2022 12:40:20 +0000 Message-ID: <20220301124022.10168-3-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301124022.10168-1-ayankuma@xilinx.com> References: <20220301124022.10168-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5aff75a4-4b86-4aa3-fdd7-08d9fb80ac5f X-MS-TrafficTypeDiagnostic: CO6PR02MB8740:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b+hZrp6fQ+UscmT3sS9oUSOC42bmjJKZpZhAusJuUUg7kJ8WWelMVxPXNsPQbjEZojt4oKaQSwTNOcGmI/WZA7odax7SWdBGHHvCxTmnQs4/C0II5TZQugBtM3iNJ+R3MD/q8O+cikvIwk6dNSOyJ+u+lrFy9ciCHDS3rTQabT6uCmQhcWBjucWhOxlFJIyhyqlUVzwJF1e/ZajsVuJ1KkJiCSQXsSO5xGnPwudNYW/IdUd0a/OAwaW+Ct4BlHFTiXTcjcR59cKdBpYbDjg0mgOHoex492Ps0aq8r+P2EP8mDhhPokkrv6ylRvKK/FPcEC4PtmBpWI9qyudLAWbR1Wfe1oWTtXSSKwu4sAA8TkFNJw5Ody/NWAcjesj+FhvL2rBE2phB7IsYKvVT1eee/ZEFfJwGGyvK51CUa/0mNyqpv5We0i5eIqe+Bf4QuqLnSxtB0A3s2XOaNcgxzM9vL5xy/ksDQXBk0L0esIZkbOrg6jQrAKXBxzBk8K5bqlhpFnqlmpevkX5cNtdhSYuZMXefy8lzdyDr+JPjDx4aT1reYYqjIOWqCu5Xy0egKMt9WHTdLgUDMHcadhoZ5L1rpdY7eic8IUdyDGClIVnNHD0Ptz5GxbM+SuOj99swTsGoVHx5SabnjbpiXhWjhH8lRo/cMrMCQoqNVOMOmN2xzPEqIk0keKYSkMGiIqoS015b/oBeYaWFN0zLed126dLo1d2S4MTFPG0OaAvw7yz6db4= X-Forefront-Antispam-Report: CIP:149.199.80.198;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:xir-pvapexch01.xlnx.xilinx.com;PTR:unknown-80-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7636003)(356005)(5660300002)(7696005)(47076005)(426003)(336012)(2906002)(186003)(83380400001)(2616005)(82310400004)(36860700001)(26005)(1076003)(316002)(8936002)(6916009)(54906003)(9786002)(4326008)(8676002)(508600001)(36756003)(70206006)(70586007)(6666004)(30864003)(40460700003)(7416002)(107886003)(102446001)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 12:40:31.2400 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5aff75a4-4b86-4aa3-fdd7-08d9fb80ac5f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.80.198];Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR02MB8740 When an instruction is trapped in Xen due to translation fault, Xen checks if the ISS is invalid (for data abort) or it is an instruction abort. If so, Xen tries to resolve the translation fault using p2m page tables. In case of data abort, Xen will try to map the mmio region to the guest (ie tries to emulate the mmio region). If the ISS is not valid and it is a data abort, then Xen tries to decode the instruction. In case of ioreq, Xen saves the decoding state, rn and imm9 to vcpu_io. Whenever the vcpu handles the ioreq successfully, it will read the decoding state to determine if the instruction decoded was a ldr/str post indexing (ie INSTR_LDR_STR_POSTINDEXING). If so, it uses these details to post increment rn. In case of mmio handler, if the mmio operation was successful, then Xen retrives the decoding state, rn and imm9. For state == INSTR_LDR_STR_POSTINDEXING, Xen will update rn. If there is an error encountered while decoding/executing the instruction, Xen will forward the abort to the guest. Signed-off-by: Ayan Kumar Halder --- Changelog :- v2..v5 - Mentioned in the cover letter. v6 - 1. Mantained the decoding state of the instruction. This is used by the caller to either abort the guest or retry or ignore or perform read/write on the mmio region. 2. try_decode() invokes decoding for both aarch64 and thumb state. (Previously it used to invoke decoding only for aarch64 state). Thus, it handles all the checking of the registers before invoking any decoding of instruction. try_decode_instruction_invalid_iss() has thus been removed. 3. Introduced a new field('enum instr_decode_state state') inside 'struct instr_details'. This holds the decoding state of the instruction. This is later read by the post_increment_register() to determine if rn needs to be incremented. Also, this is read by the callers of try_decode_instruction() to determine if the instruction was valid or ignored or to be retried or error or decoded successfully. 4. Also stored 'instr_details' inside 'struct ioreq'. This enables arch_ioreq_complete_mmio() to invoke post_increment_register() without decoding the instruction again. 5. Check hsr.dabt.valid in do_trap_stage2_abort_guest(). If it is not valid, then decode the instruction. This ensures that try_handle_mmio() is invoked only when the instruction is either valid or decoded successfully. 6. Inside do_trap_stage2_abort_guest(), if hsr.dabt.valid is not set, then resolve the translation fault before trying to decode the instruction. If translation fault is resolved, then return to the guest to execute the instruction again. v7 - 1. Moved the decoding instruction details ie instr_details from 'struct ioreq' to 'struct vcpu_io'. 2. The instruction is decoded only when we get a data abort. 3. Replaced ASSERT_UNREACHABLE() with domain_crash(). The reason being asserts can be disabled in some builds. In this scenario when the guest's cpsr is in an erroneous state, Xen should crash the guest. 4. Introduced check_p2m() which invokes p2m_resolve_translation_fault() and try_map_mmio() to resolve translation fault by configuring the page tables. This gets invoked first if ISS is invalid and it is an instruction abort. If it is a data abort and hsr.dabt.s1ptw is set or try_handle_mmio() returns IO_UNHANDLED, then check_p2m() gets invoked again. v8 - 1. Removed the handling of data abort when info->dabt.cache is set. This will be implemented in a subsequent patch. (Not as part of this series) 2. When the data abort is due to access to stage 1 translation tables, Xen will try to fix the mapping of the page table for the corresponding address. If this returns an error, Xen will abort the guest. Else, it will ask the guest to retry the instruction. 3. Changed v->io.info.dabt_instr from pointer to variable. The reason being that arch_ioreq_complete_mmio() is called from leave_hypervisor_to_guest(). That is after do_trap_stage2_abort_guest() has been invoked. So the original variable will be no longer valid. 4. Some other style issues pointed out in v7. v9 - 1. Ensure that "Erratum 766422" is handled only when ISS is valid. 2. Whenever Xen receives and instruction abort or data abort (with invalid ISS), Xen should first try to resolve the p2m translation fault or see if it it needs to map a MMIO region. If it succeeds, it should return to the guest to retry the instruction. 3. Removed handling of "dabt.s1ptw == 1" aborts. This is addressed in patch3 as it is an existing bug in codebase. 4. Various style issues pointed by Julien in v8. xen/arch/arm/arm32/traps.c | 11 ++++ xen/arch/arm/arm64/traps.c | 47 ++++++++++++++++ xen/arch/arm/decode.c | 1 + xen/arch/arm/include/asm/domain.h | 4 ++ xen/arch/arm/include/asm/mmio.h | 17 +++++- xen/arch/arm/include/asm/traps.h | 2 + xen/arch/arm/io.c | 90 +++++++++++++++++++------------ xen/arch/arm/ioreq.c | 7 ++- xen/arch/arm/traps.c | 77 ++++++++++++++++++++------ xen/arch/x86/include/asm/ioreq.h | 3 ++ xen/include/xen/sched.h | 2 + 11 files changed, 207 insertions(+), 54 deletions(-) diff --git a/xen/arch/arm/arm32/traps.c b/xen/arch/arm/arm32/traps.c index 9c9790a6d1..159e3cef8b 100644 --- a/xen/arch/arm/arm32/traps.c +++ b/xen/arch/arm/arm32/traps.c @@ -18,9 +18,11 @@ #include #include +#include #include +#include #include #include @@ -82,6 +84,15 @@ void do_trap_data_abort(struct cpu_user_regs *regs) do_unexpected_trap("Data Abort", regs); } +void post_increment_register(const struct instr_details *instr) +{ + /* + * We have not implemented decoding of post indexing instructions for 32 bit. + * Thus, this should be unreachable. + */ + domain_crash(current->domain); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/arm64/traps.c b/xen/arch/arm/arm64/traps.c index 9113a15c7a..e18b6b2626 100644 --- a/xen/arch/arm/arm64/traps.c +++ b/xen/arch/arm/arm64/traps.c @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -44,6 +45,52 @@ void do_bad_mode(struct cpu_user_regs *regs, int reason) panic("bad mode\n"); } +void post_increment_register(const struct instr_details *instr) +{ + struct cpu_user_regs *regs = guest_cpu_user_regs(); + register_t val = 0; + + /* Currently, we handle only ldr/str post indexing instructions */ + if ( instr->state != INSTR_LDR_STR_POSTINDEXING ) + return; + + /* + * Handle when rn = SP + * Refer ArmV8 ARM DDI 0487G.b, Page - D1-2463 "Stack pointer register + * selection" + * t = SP_EL0 + * h = SP_ELx + * and M[3:0] (Page - C5-474 "When exception taken from AArch64 state:") + */ + if (instr->rn == 31 ) + { + if ( (regs->cpsr & PSR_MODE_MASK) == PSR_MODE_EL1h ) + val = regs->sp_el1; + else if ( ((regs->cpsr & PSR_MODE_MASK) == PSR_MODE_EL1t) || + ((regs->cpsr & PSR_MODE_MASK) == PSR_MODE_EL0t) ) + val = regs->sp_el0; + else + { + domain_crash(current->domain); + return; + } + } + else + val = get_user_reg(regs, instr->rn); + + val += instr->imm9; + + if ( instr->rn == 31 ) + { + if ( (regs->cpsr & PSR_MODE_MASK) == PSR_MODE_EL1h ) + regs->sp_el1 = val; + else + regs->sp_el0 = val; + } + else + set_user_reg(regs, instr->rn, val); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c index 3add87e83a..16ad0747bb 100644 --- a/xen/arch/arm/decode.c +++ b/xen/arch/arm/decode.c @@ -146,6 +146,7 @@ static int decode_arm64(register_t pc, mmio_info_t *info) update_dabt(dabt, opcode.ldr_str.rt, opcode.ldr_str.size, false); + dabt_instr->state = INSTR_LDR_STR_POSTINDEXING; dabt_instr->rn = opcode.ldr_str.rn; dabt_instr->imm9 = opcode.ldr_str.imm9; diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index c56f6e4398..ed63c2b6f9 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -281,6 +281,10 @@ static inline void arch_vcpu_block(struct vcpu *v) {} /* vPCI is not available on Arm */ #define has_vpci(d) ({ (void)(d); false; }) +struct arch_vcpu_io { + struct instr_details dabt_instr; /* when the instruction is decoded */ +}; + #endif /* __ASM_DOMAIN_H__ */ /* diff --git a/xen/arch/arm/include/asm/mmio.h b/xen/arch/arm/include/asm/mmio.h index 3354d9c635..ef2c57a2d5 100644 --- a/xen/arch/arm/include/asm/mmio.h +++ b/xen/arch/arm/include/asm/mmio.h @@ -26,12 +26,24 @@ #define MAX_IO_HANDLER 16 +enum instr_decode_state +{ + INSTR_ERROR, /* Error encountered while decoding instr */ + INSTR_VALID, /* ISS is valid, so no need to decode */ + /* + * Instruction is decoded successfully. It is a ldr/str post indexing + * instruction. + */ + INSTR_LDR_STR_POSTINDEXING +}; + typedef struct { struct hsr_dabt dabt; struct instr_details { unsigned long rn:5; signed int imm9:9; + enum instr_decode_state state; } dabt_instr; paddr_t gpa; } mmio_info_t; @@ -69,14 +81,15 @@ struct vmmio { }; enum io_state try_handle_mmio(struct cpu_user_regs *regs, - const union hsr hsr, - paddr_t gpa); + mmio_info_t *info); void register_mmio_handler(struct domain *d, const struct mmio_handler_ops *ops, paddr_t addr, paddr_t size, void *priv); int domain_io_init(struct domain *d, int max_count); void domain_io_free(struct domain *d); +void try_decode_instruction(const struct cpu_user_regs *regs, + mmio_info_t *info); #endif /* __ASM_ARM_MMIO_H__ */ diff --git a/xen/arch/arm/include/asm/traps.h b/xen/arch/arm/include/asm/traps.h index 2ed2b85c6f..95c46ad391 100644 --- a/xen/arch/arm/include/asm/traps.h +++ b/xen/arch/arm/include/asm/traps.h @@ -109,6 +109,8 @@ static inline register_t sign_extend(const struct hsr_dabt dabt, register_t r) return r; } +void post_increment_register(const struct instr_details *instr); + #endif /* __ASM_ARM_TRAPS__ */ /* * Local variables: diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index fad103bdbd..bea69ffb08 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -102,57 +102,79 @@ static const struct mmio_handler *find_mmio_handler(struct domain *d, return handler; } +void try_decode_instruction(const struct cpu_user_regs *regs, + mmio_info_t *info) +{ + int rc; + + if ( info->dabt.valid ) + { + info->dabt_instr.state = INSTR_VALID; + + /* + * Erratum 766422: Thumb store translation fault to Hypervisor may + * not have correct HSR Rt value. + */ + if ( check_workaround_766422() && (regs->cpsr & PSR_THUMB) && + info->dabt.write ) + { + rc = decode_instruction(regs, info); + if ( rc ) + { + gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); + info->dabt_instr.state = INSTR_ERROR; + } + } + return; + } + + /* + * Armv8 processor does not provide a valid syndrome for decoding some + * instructions. So in order to process these instructions, Xen must + * decode them. + */ + rc = decode_instruction(regs, info); + if ( rc ) + { + gprintk(XENLOG_ERR, "Unable to decode instruction\n"); + info->dabt_instr.state = INSTR_ERROR; + } +} + enum io_state try_handle_mmio(struct cpu_user_regs *regs, - const union hsr hsr, - paddr_t gpa) + mmio_info_t *info) { struct vcpu *v = current; const struct mmio_handler *handler = NULL; - const struct hsr_dabt dabt = hsr.dabt; - mmio_info_t info = { - .gpa = gpa, - .dabt = dabt - }; + int rc; - ASSERT(hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); + ASSERT(info->dabt.ec == HSR_EC_DATA_ABORT_LOWER_EL); - handler = find_mmio_handler(v->domain, info.gpa); - if ( !handler ) + if ( !((info->dabt_instr.state == INSTR_VALID) || (info->dabt_instr.state == INSTR_LDR_STR_POSTINDEXING)) ) { - int rc; + ASSERT_UNREACHABLE(); + return IO_ABORT; + } - rc = try_fwd_ioserv(regs, v, &info); + handler = find_mmio_handler(v->domain, info->gpa); + if ( !handler ) + { + rc = try_fwd_ioserv(regs, v, info); if ( rc == IO_HANDLED ) return handle_ioserv(regs, v); return rc; } - /* All the instructions used on emulated MMIO region should be valid */ - if ( !dabt.valid ) - return IO_ABORT; - /* - * Erratum 766422: Thumb store translation fault to Hypervisor may - * not have correct HSR Rt value. + * At this point, we know that the instruction is either valid or has been + * decoded successfully. Thus, Xen should be allowed to execute the + * instruction on the emulated MMIO region. */ - if ( check_workaround_766422() && (regs->cpsr & PSR_THUMB) && - dabt.write ) - { - int rc; - - rc = decode_instruction(regs, &info); - if ( rc ) - { - gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); - return IO_ABORT; - } - } - - if ( info.dabt.write ) - return handle_write(handler, v, &info); + if ( info->dabt.write ) + return handle_write(handler, v, info); else - return handle_read(handler, v, &info); + return handle_read(handler, v, info); } void register_mmio_handler(struct domain *d, diff --git a/xen/arch/arm/ioreq.c b/xen/arch/arm/ioreq.c index 308650b400..58cd320b5a 100644 --- a/xen/arch/arm/ioreq.c +++ b/xen/arch/arm/ioreq.c @@ -47,6 +47,7 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, struct vcpu *v, mmio_info_t *info) { struct vcpu_io *vio = &v->io; + struct dabt_instr instr = info->dabt_instr; ioreq_t p = { .type = IOREQ_TYPE_COPY, .addr = info->gpa, @@ -76,10 +77,10 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, if ( !s ) return IO_UNHANDLED; - if ( !info->dabt.valid ) - return IO_ABORT; + ASSERT(dabt.valid); vio->req = p; + vio->info.dabt_instr = instr; rc = ioreq_send(s, &p, 0); if ( rc != IO_RETRY || v->domain->is_shutting_down ) @@ -95,6 +96,7 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, bool arch_ioreq_complete_mmio(void) { struct vcpu *v = current; + struct instr_details dabt_instr = v->io.info.dabt_instr; struct cpu_user_regs *regs = guest_cpu_user_regs(); const union hsr hsr = { .bits = regs->hsr }; @@ -106,6 +108,7 @@ bool arch_ioreq_complete_mmio(void) if ( handle_ioserv(regs, v) == IO_HANDLED ) { + post_increment_register(&dabt_instr); advance_pc(regs, hsr); return true; } diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 7a1b679b8c..120c971b0f 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1893,6 +1893,21 @@ static bool try_map_mmio(gfn_t gfn) return !map_regions_p2mt(d, gfn, 1, mfn, p2m_mmio_direct_c); } +static inline bool check_p2m(bool is_data, paddr_t gpa) +{ + /* + * First check if the translation fault can be resolved by the P2M subsystem. + * If that's the case nothing else to do. + */ + if ( p2m_resolve_translation_fault(current->domain , gaddr_to_gfn(gpa)) ) + return true; + + if ( is_data && try_map_mmio(gaddr_to_gfn(gpa)) ) + return true; + + return false; +} + static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, const union hsr hsr) { @@ -1906,6 +1921,8 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, paddr_t gpa; uint8_t fsc = xabt.fsc & ~FSC_LL_MASK; bool is_data = (hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); + mmio_info_t info; + enum io_state state; /* * If this bit has been set, it means that this stage-2 abort is caused @@ -1959,21 +1976,52 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, return; } case FSC_FLT_TRANS: + { + info.gpa = gpa; + info.dabt = hsr.dabt; + /* - * Attempt first to emulate the MMIO as the data abort will - * likely happen in an emulated region. - * - * Note that emulated region cannot be executed + * Assumption :- Most of the times when we get a data abort and the ISS + * is invalid or an instruction abort, the underlying cause is that the + * page tables have not been set up correctly. */ - if ( is_data ) + if ( !is_data || !info.dabt.valid ) { - enum io_state state = try_handle_mmio(regs, hsr, gpa); + if ( check_p2m(is_data, gpa) ) + return; - switch ( state ) - { + /* + * If the instruction abort could not be resolved by setting the + * appropriate bits in the translation table, then Xen should + * forward the abort to the guest. + */ + if ( !is_data ) + goto inject_abt; + } + + try_decode_instruction(regs, &info); + + /* + * If Xen could not decode the instruction or encountered an error + * while decoding, then it should forward the abort to the guest. + */ + if ( info.dabt_instr.state == INSTR_ERROR ) + goto inject_abt; + + state = try_handle_mmio(regs, &info); + + switch ( state ) + { case IO_ABORT: goto inject_abt; case IO_HANDLED: + /* + * If the instruction was decoded and has executed successfully + * on the MMIO region, then Xen should execute the next part of + * the instruction. (for eg increment the rn if it is a + * post-indexing instruction. + */ + post_increment_register(&info.dabt_instr); advance_pc(regs, hsr); return; case IO_RETRY: @@ -1982,21 +2030,18 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, case IO_UNHANDLED: /* IO unhandled, try another way to handle it. */ break; - } } /* - * First check if the translation fault can be resolved by the - * P2M subsystem. If that's the case nothing else to do. + * If the instruction syndrome was invalid, then we already checked if + * this was due to a P2M fault. So no point to check again as the result + * will be the same. */ - if ( p2m_resolve_translation_fault(current->domain, - gaddr_to_gfn(gpa)) ) - return; - - if ( is_data && try_map_mmio(gaddr_to_gfn(gpa)) ) + if ( info.dabt.valid && check_p2m(is_data, gpa) ) return; break; + } default: gprintk(XENLOG_WARNING, "Unsupported FSC: HSR=%#"PRIregister" DFSC=%#x\n", diff --git a/xen/arch/x86/include/asm/ioreq.h b/xen/arch/x86/include/asm/ioreq.h index d06ce9a6ea..ecfe7f9fdb 100644 --- a/xen/arch/x86/include/asm/ioreq.h +++ b/xen/arch/x86/include/asm/ioreq.h @@ -26,6 +26,9 @@ #include #endif +struct arch_vcpu_io { +}; + #endif /* __ASM_X86_IOREQ_H__ */ /* diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 10ea969c7a..406d9bc610 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -160,6 +160,8 @@ struct vcpu_io { /* I/O request in flight to device model. */ enum vio_completion completion; ioreq_t req; + /* Arch specific info pertaining to the io request */ + struct arch_vcpu_io info; }; struct vcpu From patchwork Tue Mar 1 12:40:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 12764704 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 1A223C433EF for ; Tue, 1 Mar 2022 12:40:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.281335.479640 (Exim 4.92) (envelope-from ) id 1nP1nz-0006CB-II; Tue, 01 Mar 2022 12:40:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 281335.479640; Tue, 01 Mar 2022 12:40:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nP1nz-0006BL-Ak; Tue, 01 Mar 2022 12:40:39 +0000 Received: by outflank-mailman (input) for mailman id 281335; Tue, 01 Mar 2022 12:40:38 +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 1nP1nx-0005sf-SP for xen-devel@lists.xenproject.org; Tue, 01 Mar 2022 12:40:37 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060e.outbound.protection.outlook.com [2a01:111:f400:7e88::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ca9644c5-995c-11ec-8eba-a37418f5ba1a; Tue, 01 Mar 2022 13:40:37 +0100 (CET) Received: from SN2PR01CA0002.prod.exchangelabs.com (2603:10b6:804:2::12) by BY5PR02MB6740.namprd02.prod.outlook.com (2603:10b6:a03:202::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 1 Mar 2022 12:40:32 +0000 Received: from SN1NAM02FT0008.eop-nam02.prod.protection.outlook.com (2603:10b6:804:2:cafe::bf) by SN2PR01CA0002.outlook.office365.com (2603:10b6:804:2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 1 Mar 2022 12:40:32 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by SN1NAM02FT0008.mail.protection.outlook.com (10.97.5.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Tue, 1 Mar 2022 12:40:32 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 1 Mar 2022 12:40:31 +0000 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 1 Mar 2022 12:40:31 +0000 Received: from [10.108.8.223] (port=53852 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nP1nr-0000Ui-3l; Tue, 01 Mar 2022 12:40:31 +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: ca9644c5-995c-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gkgVaqNI0yTxHbJyJBQyLB0Ti7GigUfaOGqaFNxbXJQqGXeDMHdUTuSnF9Rpqq1e/TpoRNnCPMW+ZdcCvBCZxS+79eSpI95Sye9HSbNKP1pSS2prZ7z6Xru3mMznaMdHv1uA/IsOB1tzhTm9fwfPHUXqKcK+tcs9ByQ8x/8GCaIDpq6vXhNl9yn5KqzGjOnFHNvakh9WDLJqMbzMqgrpC8zY8z9S8oJbxR+BPiDlXeZ2ccP0pnH6FnYPsr9gsKOURFgBz/IckbzLGK2kcb5DOgU/BfnZe+XiQ9bNlPfrQjCyMdwUzHXGwvwtu3m3gk9zBNQSOaQGtBqOfk+2TZ+moQ== 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=oHuuIqCSklM84YJbzg3sQCXYQhhgJ1Du7gvCW1yJRv4=; b=e1z1tssqiorsGvXd/sGa9IgseF+W/1oe9ZYUeQjE3gTSVIabo9w6T45rVxR5NCpcU55OgIlKPndf9M0VE6JOsmjJqQWd9DQw+/2riqhY5Bvh6pl6PtK/3pFxql9QNeQgp94iGaieVBuPk6FfyEqRfITvtk8Q9PNJ4E8E6iBu0ziWOn4STgI6oaq0MmpSczGNWwEV3Dw7oEnM0+PPokwfw35Rapg2pwXCe1zW/+3Gyt4/9JyEczer3a/5ZmeqnoGE+PpzRiuoCa5dNO8w5H//KLnns35Jul0XaMU9uYZu3T3hxcytQ2pCM1yiTQvPzR6uz7onUTmQC+zYxy1xOnyEuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.80.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oHuuIqCSklM84YJbzg3sQCXYQhhgJ1Du7gvCW1yJRv4=; b=FgZYvxMV4nXMWCXOnq81852QJs8j6L2WB4k57FMWUcG/G2VYfeB+FM6xdZDlIABD/lZjKSFov1Z+XNhX8O6PxApSCtqkyDsMfn+8zMt8ivg6g3v7W+F4XAOkahQoSyx6F9DJDOP7WCNWWXhO8F3nUMp15rdZFfkBXvzPwdrVYkU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch01.xlnx.xilinx.com; From: Ayan Kumar Halder To: CC: , , , , , , , , , , , Ayan Kumar Halder Subject: [XEN v9 3/4] xen/arm64: io: Handle the abort due to access to stage1 translation table Date: Tue, 1 Mar 2022 12:40:21 +0000 Message-ID: <20220301124022.10168-4-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301124022.10168-1-ayankuma@xilinx.com> References: <20220301124022.10168-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 44db705b-959e-4b2f-582d-08d9fb80acde X-MS-TrafficTypeDiagnostic: BY5PR02MB6740:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d3dPeSJuBeHBOsCj/mVF2L7czXUBSoddBIZD1U7JiFU5r5ewhEu8Fvva/weZ6YQ/CoPZCWmhDzY/dvar0r4GBGbqO5wV458676kT5vrk+8o8/NOnW0qL6qMAzLmJ6Et2z15irNydlVNohKWmU0yzL+u5s4gngqnoeYCphxKWKbO7HQtVCvgWAXYnmPjvg94H00aAflODX5x+JT5jtFz6OkDa1B3/XMLSOPkieAAn3E7as/IitQZhy1fGjMXvPhgHvNsCN1MgYQfNfMT6hPYPbvZ8s8LuKAQZ5N9uUVQOrkuMcscQWeYLzOTLGJZ/3MZBAaYy6qeO/a/hpX92DmW/wq9ABu+cX1kpxuN5TW1nzD1fWJhatQLn7gc+IwwojZVR1OvHh60DGeUV553auX73PMvIwEnADP62HyVwemXh6++vVee5KNmeOx8UMPZ3sLKjiyDzNeAj+xSvlr4oYMLSaB7UDHvzEglkzRBAKRwrueqkXCJ7wDduxpAmyLgGVqB9czk23JAUxQeX+A5yThAggmN3goF1Inx2BmvqmUGa5hhRA3iDWX5gjxBS+S+CJKkvgf4+3eECPQGkxOpPhi6qESMy9L08x8RS1i94PnX+apndORwJsWiki6wUOwwpxuMGDFNIXk9iHlCX+QF80T0l8YaF7HzhAK/DclcM1SbtwMtAcaB0LpoJ072k33D0/Fiwtr+zrDDkVAFbMitku7XA0A== X-Forefront-Antispam-Report: CIP:149.199.80.198;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:xir-pvapexch01.xlnx.xilinx.com;PTR:unknown-80-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(6916009)(54906003)(316002)(8936002)(8676002)(9786002)(4326008)(26005)(1076003)(107886003)(7416002)(36756003)(508600001)(6666004)(70206006)(70586007)(36860700001)(5660300002)(7696005)(356005)(7636003)(2616005)(82310400004)(336012)(47076005)(426003)(186003)(83380400001)(2906002)(102446001)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 12:40:32.1618 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44db705b-959e-4b2f-582d-08d9fb80acde X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.80.198];Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB6740 If the abort was caused due to access to stage1 translation table, Xen will assume that the stage1 translation table is in the non MMIO region. It will try to resolve the translation fault. If it succeeds, it will return to the guest to retry the instruction. If not, then it means that the table is in MMIO region which is not expected by Xen. Thus, Xen will forward the abort to the guest. Signed-off-by: Ayan Kumar Halder --- Changelog :- v1..v8 - NA v9 - 1. Extracted this change from "[XEN v8 2/2] xen/arm64: io: Support instructions (for which ISS is not..." into a separate patch of its own. The reason being this is an existing bug in the codebase. xen/arch/arm/io.c | 11 +++++++++++ xen/arch/arm/traps.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index bea69ffb08..ebcb8ed548 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -128,6 +128,17 @@ void try_decode_instruction(const struct cpu_user_regs *regs, return; } + /* + * At this point, we know that the stage1 translation table is in the MMIO + * region. This is not expected by Xen and thus it forwards the abort to the + * guest. + */ + if ( info->dabt.s1ptw ) + { + info->dabt_instr.state = INSTR_ERROR; + return; + } + /* * Armv8 processor does not provide a valid syndrome for decoding some * instructions. So in order to process these instructions, Xen must diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 120c971b0f..e491ca15d7 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1923,6 +1923,7 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, bool is_data = (hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); mmio_info_t info; enum io_state state; + bool check_mmio_region = true; /* * If this bit has been set, it means that this stage-2 abort is caused @@ -1987,7 +1988,16 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, */ if ( !is_data || !info.dabt.valid ) { - if ( check_p2m(is_data, gpa) ) + /* + * If the translation fault was caused due to access to stage 1 + * translation table, then we try to set the translation table entry + * for page1 translation table (assuming that it is in the non mmio + * region). + */ + if ( xabt.s1ptw ) + check_mmio_region = false; + + if ( check_p2m((is_data && check_mmio_region), gpa) ) return; /* From patchwork Tue Mar 1 12:40:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 12764703 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 58BFAC433F5 for ; Tue, 1 Mar 2022 12:40:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.281337.479666 (Exim 4.92) (envelope-from ) id 1nP1o1-0006pu-BM; Tue, 01 Mar 2022 12:40:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 281337.479666; Tue, 01 Mar 2022 12:40:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nP1o1-0006o8-5x; Tue, 01 Mar 2022 12:40:41 +0000 Received: by outflank-mailman (input) for mailman id 281337; Tue, 01 Mar 2022 12:40:39 +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 1nP1nz-0005sf-ER for xen-devel@lists.xenproject.org; Tue, 01 Mar 2022 12:40:39 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060b.outbound.protection.outlook.com [2a01:111:f400:fe59::60b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cb8ae4f1-995c-11ec-8eba-a37418f5ba1a; Tue, 01 Mar 2022 13:40:38 +0100 (CET) Received: from SN4PR0501CA0065.namprd05.prod.outlook.com (2603:10b6:803:41::42) by SA2PR02MB7595.namprd02.prod.outlook.com (2603:10b6:806:146::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Tue, 1 Mar 2022 12:40:35 +0000 Received: from SN1NAM02FT0034.eop-nam02.prod.protection.outlook.com (2603:10b6:803:41:cafe::26) by SN4PR0501CA0065.outlook.office365.com (2603:10b6:803:41::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.9 via Frontend Transport; Tue, 1 Mar 2022 12:40:35 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by SN1NAM02FT0034.mail.protection.outlook.com (10.97.5.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Tue, 1 Mar 2022 12:40:35 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 1 Mar 2022 12:40:33 +0000 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 1 Mar 2022 12:40:33 +0000 Received: from [10.108.8.223] (port=53852 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nP1nt-0000Ui-HL; Tue, 01 Mar 2022 12:40:33 +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: cb8ae4f1-995c-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QBvOPPiNoDnbGzOmbH3T4GREgxfOa85ijjKj9CEo9jmIYlk4NqUW8WSGNA/m0fU6jJKfEupNgW+jvMov6BMGOUhbhst/vU+i88+LUNkeDxh5FjCyonWV/EAFttSqOK3X+FO/wt6Gm7/bkkN5DI/si7faEZWHzWBkfT1uZzZkuxyDIEObuJpEjAlseZYezfzB+dGDha0lupIfUVG/Sk8927p942CH66DIzvKid4jmBS0lfy1jqtiU09KmbQcZqtEv50aUJ8epQGLvThVZdL4ZvpSmek5MMOG6gNo2aaX++kRk4fK92sjj9YieSRlrPNTgAKzmW6l/MuyY3kgLD7UtjA== 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=uK2cUyN9RFSxW7UNMQ2w1UgKi3QyK4ZDqHMa9YicuXc=; b=akzf4FL2nbMYuDrXnkR9SnsFVLduGBFgX0wm1MoKMOSMeLw6Hzx8wuMtx3Tf09sT3819/AM3coQ8n8P39aPUJ/uW6lp2JIgQnz9TaRxZPQuv5VdgZpNufw9HErybXexx1Lw6GrbNJvOcoG3B8wkXzR22Hv3uG/ArS49XlVyLvUSKJVP5neUvOUnQ133UTh2h/jyTYHwc52kILXiIVpCF2qhtU3L4R109gW6aV0wl3rXbLgIoPtpq7D8hqSldbfpZ9T84rqn7S8KpliRZrgjXAjtb4xyyqwNeGFYpcnW3EKzIorPrZzcc2xn+Pi243v5lX4tdqC70/9QnWulOhxssRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.80.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uK2cUyN9RFSxW7UNMQ2w1UgKi3QyK4ZDqHMa9YicuXc=; b=dPvGtKI9WPAbWoyyyCSs+KTyFQBd2odKMPnh852RvpsbzThUVjM1KWiAA95Yd7tGlKahc5aQ/ay/uY1cNctQjybOn7sK5RTZZpAYXoi3x3NjF64s73DODmVWenuj4o8GlvVbRZqgEf4vfKx96+FI7WtA0tQf1i+OAAyxYTy44kg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch01.xlnx.xilinx.com; From: Ayan Kumar Halder To: CC: , , , , , , , , , , , Ayan Kumar Halder Subject: [XEN v9 4/4] xen/arm64: io: Handle data abort due to cache maintenance instructions Date: Tue, 1 Mar 2022 12:40:22 +0000 Message-ID: <20220301124022.10168-5-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220301124022.10168-1-ayankuma@xilinx.com> References: <20220301124022.10168-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 085d2622-7828-4709-ca18-08d9fb80ae8f X-MS-TrafficTypeDiagnostic: SA2PR02MB7595:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BtoEydReEZTQidQ1DtzbCrBExAzj0TMjUIm/3AEjIcSCmyY7yRfIMD9b2L1XP7j+QLya5LZ7jR3aRffjGvMaDLOICNS+flXkuBVlX49O3h0s2u0aOCuLhc15wT2YWwzx+M3USMW3MZxCA3RuU9T1X0NcShhvMmPITeQJcHJfaHIKzUYYftto09PkWjALgPauukb86Lcipnw29sdfSXnu3leRStRo7qJCViDbyeuJnYX3QVlQ0nxrrHJFnR6TSGAKLM7Vy84h6yW8YGSW7sHdk1qcPJ0zADDHEi2nI8ZVtfmdLcP1Hmo+avuVsIDA7v5GNmpdssaWe5b2cneVFJHWRfCnwT6zJ/ZCm9TF+OnjcYfweSolkphT4PIv0iwBw/bCHD3I7SvKe08qFLeh3d1L+bjgK4fg5eTDgTh2rZ6T4oi097hNzjOjAuKOwzxPIwIKoNTObpVd6fSpbJaObK+ul+x7cDv06Y9PwTALXo0j5SVTfffC5lhhkKvgN31CsOWkFo/52xYXDkR0gCrsdJZdq1G1IV9DAWNPFHhs64M9dVY/EzigmvoDpWg62YLOIRq8oDpVfiKfM9dreVddlocnlLfuv2CZMVHVlLy/sGTZyxGNkdeu3Pd0YUe8z81fDpuPvEHZ/cfdqeR9xeBQvzdsROajKoM3+JzZ8h70guf98xVuKE1yywimkUY/lP3wZ4HZ2IzuOBgxGuZWkBucSQAFpw== X-Forefront-Antispam-Report: CIP:149.199.80.198;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:xir-pvapexch01.xlnx.xilinx.com;PTR:unknown-80-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(316002)(1076003)(5660300002)(7416002)(40460700003)(8676002)(70586007)(70206006)(82310400004)(4326008)(2906002)(186003)(26005)(426003)(9786002)(107886003)(2616005)(36756003)(356005)(7636003)(7696005)(6666004)(8936002)(83380400001)(6916009)(508600001)(336012)(54906003)(36860700001)(47076005)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 12:40:35.0024 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 085d2622-7828-4709-ca18-08d9fb80ae8f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.80.198];Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0034.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR02MB7595 When the data abort is caused due to cache maintenance for an address, there are two scenarios:- 1. Address belonging to a non emulated region - For this, Xen should set the corresponding bit in the translation table entry to valid and return to the guest to retry the instruction. This can happen sometimes as Xen need to set the translation table entry to invalid. (for eg 'Break-Before-Make' sequence). 2. Address belongs to an emulated region - Xen should ignore the instruction (ie increment the PC) and return to the guest. We try to deal with scenario#1, by invoking check_p2m(). If this is unsuccessful, then we assume scenario#2. Signed-off-by: Ayan Kumar Halder Acked-by: Stefano Stabellini --- Changelog:- v1...v8 - NA v9 - Extracted this change from "[XEN v7 2/2] xen/arm64: io: Support instructions (for which ISS is not ..." into a separate patch of its own. The reason being this addresses an existing bug in the codebase. xen/arch/arm/include/asm/mmio.h | 3 ++- xen/arch/arm/io.c | 11 +++++++++++ xen/arch/arm/traps.c | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/mmio.h b/xen/arch/arm/include/asm/mmio.h index ef2c57a2d5..75d362d5f5 100644 --- a/xen/arch/arm/include/asm/mmio.h +++ b/xen/arch/arm/include/asm/mmio.h @@ -34,7 +34,8 @@ enum instr_decode_state * Instruction is decoded successfully. It is a ldr/str post indexing * instruction. */ - INSTR_LDR_STR_POSTINDEXING + INSTR_LDR_STR_POSTINDEXING, + INSTR_IGNORE /* Instruction is ignored */ }; typedef struct diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index ebcb8ed548..7e9dd4bb08 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -139,6 +139,17 @@ void try_decode_instruction(const struct cpu_user_regs *regs, return; } + /* + * When the data abort is caused due to cache maintenance, Xen should ignore + * this instruction as the cache maintenance was caused on an address belonging + * to the emulated region. + */ + if ( info->dabt.cache ) + { + info->dabt_instr.state = INSTR_IGNORE; + return; + } + /* * Armv8 processor does not provide a valid syndrome for decoding some * instructions. So in order to process these instructions, Xen must diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index e491ca15d7..5879640b73 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2011,6 +2011,12 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, try_decode_instruction(regs, &info); + if ( info.dabt_instr.state == INSTR_IGNORE ) + { + advance_pc(regs, hsr); + return; + } + /* * If Xen could not decode the instruction or encountered an error * while decoding, then it should forward the abort to the guest.