From patchwork Thu Mar 10 17:44:58 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: 12776825 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 5264FC433FE for ; Thu, 10 Mar 2022 17:45:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288558.489354 (Exim 4.92) (envelope-from ) id 1nSMqm-0002vm-Kl; Thu, 10 Mar 2022 17:45:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288558.489354; Thu, 10 Mar 2022 17:45:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSMqm-0002vf-Hp; Thu, 10 Mar 2022 17:45:20 +0000 Received: by outflank-mailman (input) for mailman id 288558; Thu, 10 Mar 2022 17:45:19 +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 1nSMql-0002fW-7i for xen-devel@lists.xenproject.org; Thu, 10 Mar 2022 17:45:19 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20625.outbound.protection.outlook.com [2a01:111:f400:7eae::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d8db92ae-a099-11ec-853a-5f4723681683; Thu, 10 Mar 2022 18:45:17 +0100 (CET) Received: from DM5PR18CA0086.namprd18.prod.outlook.com (2603:10b6:3:3::24) by DM6PR02MB6619.namprd02.prod.outlook.com (2603:10b6:5:217::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Thu, 10 Mar 2022 17:45:15 +0000 Received: from DM3NAM02FT022.eop-nam02.prod.protection.outlook.com (2603:10b6:3:3:cafe::33) by DM5PR18CA0086.outlook.office365.com (2603:10b6:3:3::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 17:45:14 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by DM3NAM02FT022.mail.protection.outlook.com (10.13.5.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 17:45:14 +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; Thu, 10 Mar 2022 17:45:13 +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; Thu, 10 Mar 2022 17:45:13 +0000 Received: from [10.108.8.223] (port=47674 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nSMqf-00062C-3L; Thu, 10 Mar 2022 17:45:13 +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: d8db92ae-a099-11ec-853a-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GEqoDXRq0PGYOS+xORDtKTIJ+k5Opg4gAO9tXJ/rpuBJt9gvSiqlHh+He+DrOo6pImL9rRn0QOONyBqt0LAGRu1J1nZdmVYIKjN+JXKG14yUfua3IYB7VWm7YhW3jvkamTUgxPnzoTodU8B7d8NR6Gp/QcvhsdHv7qo+6+le0xpbO3Xz+QafdLY2JhrgCt2aGWnxI5KF+7JsvR9uBAkreRzB4xUG40W3M862yt3pNoXuOH923mwWjwKuBljxy0Pryw8MIIDHuwCMtMe6+jKKrUQhqd0scbpG8KqqSGkqPVvuIuGfKZO/+owmw3NEKDz5TsB0L4ETRuo4eiCmRTKRsg== 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=Frs8haldHJhErbGXIyYNEdcgB/b9gbBfW73XjCo47n4=; b=nSX+Omjfyn0Fx+Qe+cABbQ9uoXe8D/B8zpGioL+ccahEaHKLVRL1mRYUULUahVo/aZ/5ErkdPAL9D2Z4O4QNU/2TRXXvurNWqyEIS2pX4PPO2WfULOfmja/MIE7QuFukcNVTjY+qroOCQyCk0+hW842w5avL4oQuomtzF8tQ/MXALJYXH+rg56/41wWAnNMgE/G9puXIzZNiXundtiCAsD2f9vdQ8MOVC+3tdgyXSwF6yIJY0HEZU2aUq6XGIYo0CErVP3jN/9WgCxwP9B4fCluxqrPX4OZ1w7S/v11uIFedOnb1lez452eYeZQMOr0hCoQ6F/PS0uZTdUpODfvP5w== 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=Frs8haldHJhErbGXIyYNEdcgB/b9gbBfW73XjCo47n4=; b=nmHDbadIgx1a6vM0Bb9rtwkMIjIsqVOdwTh57nW94fuwr7Nb9/BpBaXvhXSJNjfm3IscYZ7xqRDMn04F2opz4u4JfSkVAXGK2X8LxkYHh/XzTEbDQDlx1trUYA/A1ViDmRn9m+GFEr06OC7E+Y+pkwCgC3VfaFkas0P6D6yVGEQ= 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 v10 1/4] xen/arm64: Decode ldr/str post increment operations Date: Thu, 10 Mar 2022 17:44:58 +0000 Message-ID: <20220310174501.62040-2-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220310174501.62040-1-ayankuma@xilinx.com> References: <20220310174501.62040-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1e0c61c6-b68a-4452-9681-08da02bdbba4 X-MS-TrafficTypeDiagnostic: DM6PR02MB6619: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: p80tPSOVy/PihOFTDCgwWBYYFG9yw6jw/L9ZBWuORcAQDbm5TkOE1BziyWfpfa/rse6St8JUMH+nlNnfmXlhDN4rxT16H0Cl0WklwKnRZxP7gGLOi1pe098dkf+k7zn0OtDL7nCTZ/0BW6zuwbd/K2D7e+2/KZsGxdvPOTFPh4NAH9xBTtT+5lW8Y53wc5a5A3GHdiqh7Fy+DZmc0JJW+0cizPjFGTqxAQs1Xvt3GgJtIFdVGv3Z0o0uAb3zHXtOdjAVCs7BpO4zhNJWzW2l5XbYQYTL1ugzPKjLigD3qmAWvOM5yDRHC0Z5u7tz6eQUGoywL2d7zVvj1zfwoMMjv3SVcIT5Beq7a/0GBXLotvAGChoL9eXQb3Fbb4chUH5ovFzqiIOWxb3FxSZKFzIInTLfuKvOhDymJCk3RAjgMYaRRZ1pQ57MzyPwrjbUTtEnjz+Kfqes+RLj76uYZbiC3iBTposVSqT0VaufiwwPCDItidshZmEqCYVSdUJReC51DcVJMi1bRROF/gP3sBbccUzRaZUWk0CaXIDDEzXVf14FpwBeYINlIIlCu0HuAwoDDYqqZM766HMsETDKTrCzlNlIwWzS2O2Z0BJZZEqL89nzjsSJpggWpZITgHbREYGVmVitK99eK+jDSQD7sZg9r+MgLFfHb9kl/okStvm3Pu4G4oxVhOurmuxqjDuDYPYK98c6K/EzpGRxKvtwDFkh9A== 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)(40470700004)(426003)(1076003)(26005)(336012)(40460700003)(356005)(7636003)(83380400001)(2906002)(8936002)(5660300002)(36756003)(9786002)(7416002)(36860700001)(54906003)(6916009)(186003)(508600001)(107886003)(70586007)(70206006)(6666004)(7696005)(8676002)(2616005)(47076005)(316002)(82310400004)(4326008)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 17:45:14.4203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e0c61c6-b68a-4452-9681-08da02bdbba4 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: DM3NAM02FT022.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB6619 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. v10 - 1. No change. 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 Thu Mar 10 17:44:59 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: 12776828 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 4AAD8C433EF for ; Thu, 10 Mar 2022 17:45:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288560.489371 (Exim 4.92) (envelope-from ) id 1nSMqu-0003Ka-6i; Thu, 10 Mar 2022 17:45:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288560.489371; Thu, 10 Mar 2022 17:45:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSMqu-0003JX-0f; Thu, 10 Mar 2022 17:45:28 +0000 Received: by outflank-mailman (input) for mailman id 288560; Thu, 10 Mar 2022 17:45:26 +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 1nSMqs-0002fW-7Y for xen-devel@lists.xenproject.org; Thu, 10 Mar 2022 17:45:26 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20608.outbound.protection.outlook.com [2a01:111:f400:fe5b::608]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id db3fe2f0-a099-11ec-853a-5f4723681683; Thu, 10 Mar 2022 18:45:23 +0100 (CET) Received: from DM5PR16CA0038.namprd16.prod.outlook.com (2603:10b6:4:15::24) by BYAPR02MB5192.namprd02.prod.outlook.com (2603:10b6:a03:72::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Thu, 10 Mar 2022 17:45:18 +0000 Received: from DM3NAM02FT003.eop-nam02.prod.protection.outlook.com (2603:10b6:4:15:cafe::28) by DM5PR16CA0038.outlook.office365.com (2603:10b6:4:15::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Thu, 10 Mar 2022 17:45:18 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by DM3NAM02FT003.mail.protection.outlook.com (10.13.4.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 17:45:17 +0000 Received: from xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) 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; Thu, 10 Mar 2022 17:45:16 +0000 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 10 Mar 2022 17:45:16 +0000 Received: from [10.108.8.223] (port=47674 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nSMqi-00062C-Aw; Thu, 10 Mar 2022 17:45:16 +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: db3fe2f0-a099-11ec-853a-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TjJGV2h6sPEamDwntDiIHc7Vg/jiOeLcQeJMEHEaye6N+3muZEJT6FizsYBvTsMlQZPiZ7/nVxbXj/DPpUKpRxZobbuSuS6x52ohhH451Wejwmo7mW133iyr27jYTxSMnv2euUtDbG6hMvwwk/nHMx+GIwhwYHnk3QqD4kyCYk7v+lLlRU6X9bFGAngs8GpvhFiup9lRtXN3rN7SHu/fSMxijW94x+dcI/0m4nMVlQgmWcofL1DAUVzf05JckpgPZullpxZN4eUkRTsaEigT/r1nZ0rK1xoRHXqrjXVntU7/VHOa4VztG12iwuXisWWvIyjl3ocyQY4rclzj75q2AQ== 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=/rVOnmzQQ4ELGJW7g72ReoXq3HvVRus6YPjNI5sBSyE=; b=UajEnVz09LQSYkTTuKvIGge7qPmbx6qK+xBxgtLJfP7H523sU88QRmQ9nGGMa1xi0WNDd4aiqmM3Jpma2BeaqbbXOtzZJf1wk7HuuLh/76zmjD07PvYyGDD22uIQNRximGmKScnzm3VM2AW3J8FEnVBpYNVFvfAAK1WUSSwM/6Zb+U8orXZgLnvA1J/eLzgcovWS1d8rtP9bDCgOpugDBGoIURZeTS/X7FTOaCnXt8Nx6+FoKPOyl1XB0D7Dbi3zxI/xSSeR2UWZlXFaNJpTSMLG3u4rblJIx2UwBs4k2lTy90bh9totmZ+fmdThsU2rQRaHmiTg88evJf+yJ9BJDg== 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=/rVOnmzQQ4ELGJW7g72ReoXq3HvVRus6YPjNI5sBSyE=; b=nwRiV5lsGarCe5/oiWRz/B+lHhPzgbn4GuOTblgtatdXxEniJacQGANYdAv2IcMbcfPKCDCgg0kAgZUJis/l3mpSsQF3AjvK2MJCWoOul9OIxR884xwQWydKaV1hhl3ZcRJUg/UY16RmDJZSan+jiKqlJhjUQi4FWbUAOFnCLms= 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 v10 2/4] xen/arm64: io: Support instructions (for which ISS is not valid) on emulated MMIO region using MMIO/ioreq handler Date: Thu, 10 Mar 2022 17:44:59 +0000 Message-ID: <20220310174501.62040-3-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220310174501.62040-1-ayankuma@xilinx.com> References: <20220310174501.62040-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6074dbec-6a7c-4783-d747-08da02bdbd94 X-MS-TrafficTypeDiagnostic: BYAPR02MB5192: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: Qn8eqAOEMI+3n6WignynOITtX49UjSwcNOYvy+iDRANVAF+0xdsViX5MN1/6FfiTTF5m8sESMBAgjXVhbpYfT5kocH4Xy+BvrAsGkr74nJvJUOgXLUQDIP4qzNuOlg/QuY+Bi5N0mwL/tQktOeTemm5J4vnzed2nloYosAb0QI7iDQmly/xxqEiArRAfp4Rt2XfmBfJhonv0LoVT7uECxlg9G9jK1HDivLL3vya7XulMACp8330o52rNh8jxCszZqet5W9KOkoY4io3WZiKOs32roUNPY07cVKEJJ4BHT7495W0zjn75T8gBLF3pCIWtqmbD16kSdrQK382gSmhVThruFQ9hOFiaUx9tnY17VSlBhVIKd6On9WGD5+qgmJ1zAKh9EtAVBYwUu+OtSnkwBxgFzavIgetBmvvEsdbMmQe60Od4UMVjtJ7O/s35y1VgZzHPi6fqc9A6RKJDM07EdM27SxVFBaOT4BAlqXUUVbRs1FDYOgZN7fC/VZ5WqIS/MviH7znvkTd/uncNkuOHNdTiZE3W9t577+Fho6pboxv/mx/m7NqY20gmC1M8L6AdPcW11TiuPNdnQ+FYvQyuZhmKMi/fjKYmo0UnxTsesu/bkhrPp4X85v5BahgvZZRzHJ+EeyQzB7g9BTUi97wP4EdvMIPtToYga/ncckFK5ng7IdA+Kpc5bRSxbd79bdJhnSYBjDtiT24+KQegO35OCA== 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)(508600001)(5660300002)(47076005)(8936002)(356005)(9786002)(54906003)(6666004)(30864003)(7416002)(2906002)(8676002)(4326008)(7636003)(83380400001)(70206006)(70586007)(7696005)(6916009)(82310400004)(36860700001)(316002)(107886003)(2616005)(336012)(186003)(426003)(26005)(36756003)(1076003)(102446001)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 17:45:17.6881 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6074dbec-6a7c-4783-d747-08da02bdbd94 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: DM3NAM02FT003.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5192 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. Also, the logic to infer the type of instruction has been moved from try_handle_mmio() to try_decode_instruction() which is called before. try_handle_mmio() is solely responsible for handling the mmio operation. Signed-off-by: Ayan Kumar Halder Reviewed-by: Stefano Stabellini Acked-by: Julien Grall --- 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. v10 - 1. Set 'dabt.valid=1' when the instruction is fully decoded. This is checked in try_handle_mmio() and try_fwd_ioserv(). 2. Various other style issues pointed in v9. xen/arch/arm/arm32/traps.c | 11 ++++ xen/arch/arm/arm64/traps.c | 52 ++++++++++++++++++ xen/arch/arm/decode.c | 2 + 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 | 8 ++- xen/arch/arm/traps.c | 77 ++++++++++++++++++++------ xen/arch/x86/include/asm/ioreq.h | 3 ++ xen/include/xen/sched.h | 2 + 11 files changed, 214 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..6ce4a1fa8c 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,57 @@ 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; + uint8_t psr_mode = (regs->cpsr & PSR_MODE_MASK); + + /* 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 ) + { + switch ( psr_mode ) + { + case PSR_MODE_EL1h: + val = regs->sp_el1; + break; + case PSR_MODE_EL1t: + case PSR_MODE_EL0t: + val = regs->sp_el0; + break; + + default: + 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..f5f6562600 100644 --- a/xen/arch/arm/decode.c +++ b/xen/arch/arm/decode.c @@ -146,8 +146,10 @@ 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; + dabt->valid = 1; return 0; 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..ca259a79c2 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..fd903b7b03 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.valid ) { - 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..cc9bf23213 100644 --- a/xen/arch/arm/ioreq.c +++ b/xen/arch/arm/ioreq.c @@ -47,6 +47,8 @@ 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 instr_details instr = info->dabt_instr; + struct hsr_dabt dabt = info->dabt; ioreq_t p = { .type = IOREQ_TYPE_COPY, .addr = info->gpa, @@ -76,10 +78,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 +97,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 +109,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..53652d7781 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_instr.state == INSTR_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 Thu Mar 10 17:45:00 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: 12776827 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 44312C4332F for ; Thu, 10 Mar 2022 17:45:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288559.489366 (Exim 4.92) (envelope-from ) id 1nSMqt-0003HK-Sf; Thu, 10 Mar 2022 17:45:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288559.489366; Thu, 10 Mar 2022 17:45:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSMqt-0003HD-PV; Thu, 10 Mar 2022 17:45:27 +0000 Received: by outflank-mailman (input) for mailman id 288559; Thu, 10 Mar 2022 17:45:26 +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 1nSMqs-0003Et-4J for xen-devel@lists.xenproject.org; Thu, 10 Mar 2022 17:45:26 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061c.outbound.protection.outlook.com [2a01:111:f400:fe5b::61c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dcacf8aa-a099-11ec-8eba-a37418f5ba1a; Thu, 10 Mar 2022 18:45:24 +0100 (CET) Received: from DS7PR03CA0219.namprd03.prod.outlook.com (2603:10b6:5:3ba::14) by DM6PR02MB4860.namprd02.prod.outlook.com (2603:10b6:5:10::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Thu, 10 Mar 2022 17:45:21 +0000 Received: from DM3NAM02FT051.eop-nam02.prod.protection.outlook.com (2603:10b6:5:3ba:cafe::eb) by DS7PR03CA0219.outlook.office365.com (2603:10b6:5:3ba::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Thu, 10 Mar 2022 17:45:21 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by DM3NAM02FT051.mail.protection.outlook.com (10.13.4.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 17:45:20 +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; Thu, 10 Mar 2022 17:45:19 +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; Thu, 10 Mar 2022 17:45:19 +0000 Received: from [10.108.8.223] (port=47674 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nSMqk-00062C-Jp; Thu, 10 Mar 2022 17:45:18 +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: dcacf8aa-a099-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dC0POvUCGY22IqX4w8cDzMRsnwrX5gDB9BahAXMgnsMq7TaayNOqrJ13GLxxbStfEj2xJBK7TTQWd/L78HmhBv3xwUCLSuxRCe1PCFzc6wtlGRp0b+cxT5Pr4jGcLNQR93gc3QJlyI2qzFWgTRXVelexkN2DdJeEBPgAWV/cYgIQFwG3UV+kgNzQzdng/h3jBtT0677huhc+2AqaBJSUzXg6hpcp1HnZFWiiXiLfPucXUhEKDsqXkEbgUgajS9KGxP68MJHbF0j+hghnbxDBvFiaLits+VN/TMqjjkoYcAiGLnbpHHh9OhGBWJtQAvBZJaELPexpi1oAwV5MlYKEfQ== 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=v+THwbN4oTMoGKFH1lRCrmOSyHRnq+hrefN92IPF7io=; b=NxLpeD/ECAWW5f3oLQVhaRGvjhp6tTvpbBMNHqv2/wTsub+4YTxV0oqnOtuMg+pJTThM7oygTV2mkSRbU9iRkJwmgDoYi9wm3zKzR4PGRvDHaccK/4PC5vvV8Cnn+DKqz5wLXLxgsQcVpSMT+tpYLeQE85JR8s1zL50hp7eT2CLMWjXp0f8ixP3io6MOt9XW91hryl1txC/QYnD0PajK4o7SGbjYVMh72s5z6aKp6WiAQRBaZw4eNHIyiXwn9ZW3vNbbvRu2ojUjwuxFO/rBvjOxbnbgRj/xFnCRLh9WlspKUjuXx8NAqovHw+TlKlXuYHwC35TBKsJ1EvXHYip+qg== 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=v+THwbN4oTMoGKFH1lRCrmOSyHRnq+hrefN92IPF7io=; b=Mv2vtrv4ibpGfW5bnBZnPEkt14N1zTLmN0X1bM6yQH0kVg2eWjvU9ofs28dT8azGBpK+Tzeqjv/BWMW57EXu2GBY7DDIZ2JtafRakj6WFhCtsjcMDvJe0NP3m87ttCtU9mqDxr6jy7nEn1/9pqz3C9AEBWv/Z5QEN6r+LEFbo9c= 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 v10 3/4] xen/arm64: io: Handle the abort due to access to stage1 translation table Date: Thu, 10 Mar 2022 17:45:00 +0000 Message-ID: <20220310174501.62040-4-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220310174501.62040-1-ayankuma@xilinx.com> References: <20220310174501.62040-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 537e6435-fd6d-4a4c-50a7-08da02bdbf50 X-MS-TrafficTypeDiagnostic: DM6PR02MB4860: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: GUzf2Jn6iZUQe64FK7vLO416Hns+lrUh6wnuJWKxMVdyXrKdhE446MDt+tSlPZjLzp8yIlKtmKWRTOyuoP/URU283nSe3iWvAzfftUiY9S5tp5pV92xRkgzNyIKT/XO0fv+qPCp3BMOzQBjSQtg8woonAnWqAiBbGDu8E9V3VruwTN1glnSu/bU1dfC1Ipzw8zHpaMMEDy0ojtg1Q2/4TNestLXE9Vny/6uuLIMeCMvApkRPHHiOJxmyUaqrIMuUH8PnkRorCiLyyxfRzgtOS0MOv5UOKt3bJZ3GQh0PA3OQgVJroSldnyMpWeHreeyucdXR/1t315NrB2sSb2XJzPUYYkhwSTk3SzpP++Fgai07r6ws7BD9nKDD8pbiQFFx1CwUPwabJDWKlZTUI/SscNhLiXnK4iGBW4IfFYXnFWIQYIyKnad4IJtlOLJ3VP36+UR4KSk/wMeVhzsvMrWPA3odSIM5j6WmNR15wsv9W69o4m1d+6DZWoJAmRhEV1ouZj1jimGkHud5oj03Q8x4LrgzhqI9kUu29mb2R+NCKvj/keIuEfVlvuRDvUijNpdqKvXsdVj0H92bnMUOROZftP8pFAFZUGp0z0BgzDJlMSiYwjqN5eZcgQ3rAWwYjH6xsbVcmuIUOnLZqzw1dj5H5g7x+qav4zZioDeH1qZjCo61juZRrig8Z6H/hJOWNOjkB/4R+uBEJcSe6iQ9K6m7ht3z5PwV0kv79akd+nH1KGA= 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)(46966006)(36840700001)(70206006)(70586007)(2906002)(8676002)(356005)(4326008)(82310400004)(54906003)(7636003)(107886003)(40460700003)(6916009)(8936002)(5660300002)(9786002)(7416002)(47076005)(508600001)(7696005)(316002)(36860700001)(186003)(26005)(36756003)(336012)(426003)(83380400001)(1076003)(6666004)(2616005)(102446001)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 17:45:20.5164 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 537e6435-fd6d-4a4c-50a7-08da02bdbf50 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: DM3NAM02FT051.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB4860 If the abort was caused due to access to stage1 translation table, Xen will try to set the p2m entry (assuming that the Stage 1 translation table is in the non MMIO region). If there is no such entry found, then Xen will try to map the address as a MMIO region (assuming that the Stage 1 translation table is in the direct MMIO region). If that fails as well, then there are the two following scenarios:- 1. Stage 1 translation table being in the emulated MMIO region - Xen can read the region, but it has no way to return the value read to the CPU page table walker (which tries to go through the stage1 tables to resolve the translation fault). 2. Stage 1 translation table address is invalid. In both the above scenarios, Xen will forward the abort to the guest. Signed-off-by: Ayan Kumar Halder Reviewed-by: Julien Grall --- 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. v10 - 1. Enabled checking for stage1 translation table address in the MMIO region. The reason being Arm Arm does not have any restrictions. 2. Updated the commit message to explain all the possible scenarios. xen/arch/arm/io.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index fd903b7b03..e6c77e16bf 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 either in the + * emulated MMIO region or its address is invalid . 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 From patchwork Thu Mar 10 17:45:01 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: 12776829 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 0087DC433FE for ; Thu, 10 Mar 2022 17:45:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288561.489387 (Exim 4.92) (envelope-from ) id 1nSMqw-0003qT-Ic; Thu, 10 Mar 2022 17:45:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288561.489387; Thu, 10 Mar 2022 17:45:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSMqw-0003qI-Ec; Thu, 10 Mar 2022 17:45:30 +0000 Received: by outflank-mailman (input) for mailman id 288561; Thu, 10 Mar 2022 17:45:28 +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 1nSMqu-0002fW-Jx for xen-devel@lists.xenproject.org; Thu, 10 Mar 2022 17:45:28 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eab::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dda620cb-a099-11ec-853a-5f4723681683; Thu, 10 Mar 2022 18:45:26 +0100 (CET) Received: from DM5PR2001CA0023.namprd20.prod.outlook.com (2603:10b6:4:16::33) by MN2PR02MB6222.namprd02.prod.outlook.com (2603:10b6:208:186::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Thu, 10 Mar 2022 17:45:23 +0000 Received: from DM3NAM02FT053.eop-nam02.prod.protection.outlook.com (2603:10b6:4:16:cafe::c6) by DM5PR2001CA0023.outlook.office365.com (2603:10b6:4:16::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Thu, 10 Mar 2022 17:45:23 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by DM3NAM02FT053.mail.protection.outlook.com (10.13.5.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 17:45:22 +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; Thu, 10 Mar 2022 17:45:21 +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; Thu, 10 Mar 2022 17:45:21 +0000 Received: from [10.108.8.223] (port=47674 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nSMqn-00062C-5M; Thu, 10 Mar 2022 17:45:21 +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: dda620cb-a099-11ec-853a-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l9rW8e3nlyxAPZhmTZO2hZmr5KYrg7E9eC+v0/xzN/uvkIKEMDNyAeFy77NryyT+nDbn2F5dB4szITsXv27pL3DBueUyLgvxXqzEuhRCcMHrnUsOCwC/GeFQk+DhuOEUF7TCKs/btZD9tYfdUKrNsTZgvTaVDoKyd5dma0qgjwdXStVIyMvHmR3eN7h4X/9SuJ8yZWaSNzyi5wXczbhLii9H+JyoeYd3WQBmLfSWSJHJ2T9NGPmveIBRCNNly4B9DPa+eumfGIXxAXTAuaIIQhPekpLCS73uWmK3nL9AYBpt9gPSek+WtgXbjoWNhdGZ898dBp/L5uEjOdxlQL3AwA== 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=+xhAyzOJKcFQjR6pp7HDy+csplKGaoofhTDl9R0cDo8=; b=YBihvOkKUEXYjuRKLNWgDc+oWC3y7rj2dU395NdaRgSelO4sn8bm4pLR3NzvZd/QBVfN5bzAVRN/uejqsuobZMDCbx8IwRpeDIiyJNeLPL2VxWMTuUz2RLQA0sDyV+yuUv9DlvEmmeZqOnctHrdHnzX6FsN9a/u7UeBI9pd15Jb/UMxh2oDHyr6aru3tgKIZTFlbnzQDMC1Ip0E9Fm7hQtxr5WA+LLmyPuPwWpqk+38SybGqNYh9l0c4B3b0Je9TZw5Vk0rATijx8CT9mlndP8yYVzsZQciBLp8pE8GEYbgZTuDuwAPCAXwsxpf5uEAC0rfcN8Hh++NDsc0Sas7vKQ== 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=+xhAyzOJKcFQjR6pp7HDy+csplKGaoofhTDl9R0cDo8=; b=GU8uyhQwohfsXpme0ENnovUH9p0KHEmxqk/Hk+CuK5SMcfvJ37Ae4/Hqa0KdoKUmdqDmE1Q0Jwugm/8pgedGAVzT4kEJj4weDrKMdlThlr8BtYSaNenCyxvjA4c6IV/ARNxhzMJHLieQMXPe5V7vnZfn+v6qN0DyzIl2cim0pIY= 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 v10 4/4] xen/arm64: io: Handle data abort due to cache maintenance instructions Date: Thu, 10 Mar 2022 17:45:01 +0000 Message-ID: <20220310174501.62040-5-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220310174501.62040-1-ayankuma@xilinx.com> References: <20220310174501.62040-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb30c7df-e11e-4db7-119e-08da02bdc091 X-MS-TrafficTypeDiagnostic: MN2PR02MB6222: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: ExoxggTiO7rgoSABqSfQs3O16Fe8pG3pV41IAMWktr/yL5PMbgpv4DeZqCIvQ8KJvNK+SmVOCc8UYWZ8nOilGA+TunM4gI6kqCdyioVF/xI61P6s+ddg6nqoHByKqIftVrKDzIjNWb4Er8CKnzrlrYrz+LyQzo9pdfOdRQkkYe0vaFkoG2byLSYHsJhgGbAATa4GYCcB/YLXhLoFW/C5wr/8qhZx+eJNkv02r29ngobzmTZpc1kmhK7mtIrd2FBl+iCwFSA1ATP0QBEiQeeSZo5f4Obhgv0T4y9+Yki5tVjt7FJVnBvmNkhaCYSos56zGMbl9CPRCBKJm9vemgGC+/LXHHQXn+/NTnkJOTKydT9JCksKdEO1SYT+bqQPgMK2Bewvb2lmEc6M35Ug7X/yB6J4s9amUanFxyVRaySjgvh9KIfDPH4JGTbhvPz8eVIRgHArPsGLrMmrPFhAedgB7Yvbo87OJ9Gu/7x5lDzKjaypRkm5V42NlPSPPKSB0fo4DJPmGLHMiPqd3H4XZcNywHHrCjm6pQK9KSJnf2PpKLe6bfEbtsLiQeXUGqITwNK0gUSWzwtlWSb6xy6GBawHcC+1D3Gw67UDmuUMQ/1idNLojz12fs13oZ70Z0LnIqWEAD05s6E39AA5bKM4QAMN2ev8fFUBvFCtsHvGAH8TIgvhLl3RsVScYmhJaMd41PTI2fzAnCpLckgS3VsIWcTD9A== 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)(40470700004)(6666004)(7636003)(40460700003)(4326008)(7696005)(356005)(70586007)(70206006)(8676002)(508600001)(2906002)(7416002)(82310400004)(2616005)(186003)(83380400001)(36860700001)(8936002)(9786002)(47076005)(1076003)(107886003)(5660300002)(36756003)(26005)(336012)(426003)(54906003)(316002)(6916009)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 17:45:22.6185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb30c7df-e11e-4db7-119e-08da02bdc091 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: DM3NAM02FT053.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB6222 When the data abort is caused due to cache maintenance for an address, there are three 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). Xen returns to the guest to retry the instruction. 2. Address belongs to an emulated region - Xen should ignore the instruction (ie increment the PC) and return to the guest. 3. Address is invalid - Xen should forward the data abort to the guest. Signed-off-by: Ayan Kumar Halder Reviewed-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. v10 - 1. To check if the address belongs to an emulated region, one needs to check if it has a mmio handler or an ioreq server. In this case, Xen should increment the PC 2. If the address is invalid (niether emulated MMIO nor the translation could be resolved via p2m or mapping the MMIO region), then Xen should forward the abort to the guest. xen/arch/arm/include/asm/mmio.h | 1 + xen/arch/arm/io.c | 20 ++++++++++++++++++++ xen/arch/arm/ioreq.c | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/mmio.h b/xen/arch/arm/include/asm/mmio.h index ca259a79c2..79e64d9af8 100644 --- a/xen/arch/arm/include/asm/mmio.h +++ b/xen/arch/arm/include/asm/mmio.h @@ -35,6 +35,7 @@ enum instr_decode_state * instruction. */ INSTR_LDR_STR_POSTINDEXING, + INSTR_CACHE, /* Cache Maintenance instr */ }; typedef struct diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index e6c77e16bf..c5b2980a5f 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 check + * if the address belongs to an emulated MMIO region or not. The behavior + * will differ accordingly. + */ + if ( info->dabt.cache ) + { + info->dabt_instr.state = INSTR_CACHE; + return; + } + /* * Armv8 processor does not provide a valid syndrome for decoding some * instructions. So in order to process these instructions, Xen must @@ -177,6 +188,15 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, return rc; } + /* + * When the data abort is caused due to cache maintenance and the address + * belongs to an emulated region, Xen should ignore this instruction. + */ + if ( info->dabt_instr.state == INSTR_CACHE ) + { + return IO_HANDLED; + } + /* * At this point, we know that the instruction is either valid or has been * decoded successfully. Thus, Xen should be allowed to execute the diff --git a/xen/arch/arm/ioreq.c b/xen/arch/arm/ioreq.c index cc9bf23213..0dd2d452f7 100644 --- a/xen/arch/arm/ioreq.c +++ b/xen/arch/arm/ioreq.c @@ -29,10 +29,14 @@ enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v) const struct hsr_dabt dabt = hsr.dabt; /* Code is similar to handle_read */ register_t r = v->io.req.data; + const struct instr_details instr = v->io.info.dabt_instr; /* We are done with the IO */ v->io.req.state = STATE_IOREQ_NONE; + if ( instr.state == INSTR_CACHE ) + return IO_HANDLED; + if ( dabt.write ) return IO_HANDLED; @@ -47,7 +51,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 instr_details instr = info->dabt_instr; + const struct instr_details instr = info->dabt_instr; struct hsr_dabt dabt = info->dabt; ioreq_t p = { .type = IOREQ_TYPE_COPY, @@ -78,6 +82,15 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, if ( !s ) return IO_UNHANDLED; + /* + * When the data abort is caused due to cache maintenance and the address + * belongs to an emulated region, Xen should ignore this instruction. + */ + if ( instr.state == INSTR_CACHE ) + { + return IO_HANDLED; + } + ASSERT(dabt.valid); vio->req = p;