From patchwork Wed Feb 2 17:30:15 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: 12733318 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 B0477C433EF for ; Wed, 2 Feb 2022 17:30:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.264367.457452 (Exim 4.92) (envelope-from ) id 1nFJSh-0005ar-Tx; Wed, 02 Feb 2022 17:30:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 264367.457452; Wed, 02 Feb 2022 17:30:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nFJSh-0005ak-R0; Wed, 02 Feb 2022 17:30:31 +0000 Received: by outflank-mailman (input) for mailman id 264367; Wed, 02 Feb 2022 17:30:30 +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 1nFJSg-0005L1-0u for xen-devel@lists.xenproject.org; Wed, 02 Feb 2022 17:30:30 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060e.outbound.protection.outlook.com [2a01:111:f400:fe5a::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cf6604af-844d-11ec-8eb8-a37418f5ba1a; Wed, 02 Feb 2022 18:30:27 +0100 (CET) Received: from BN6PR1401CA0022.namprd14.prod.outlook.com (2603:10b6:405:4b::32) by MN2PR02MB6047.namprd02.prod.outlook.com (2603:10b6:208:186::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.18; Wed, 2 Feb 2022 17:30:23 +0000 Received: from BN1NAM02FT016.eop-nam02.prod.protection.outlook.com (2603:10b6:405:4b:cafe::1b) by BN6PR1401CA0022.outlook.office365.com (2603:10b6:405:4b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 17:30:23 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by BN1NAM02FT016.mail.protection.outlook.com (10.13.2.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 17:30:23 +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; Wed, 2 Feb 2022 17:30:22 +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; Wed, 2 Feb 2022 17:30:22 +0000 Received: from [10.108.8.223] (port=56994 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nFJSX-0004a1-Pg; Wed, 02 Feb 2022 17:30: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: cf6604af-844d-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RLXFXSiieKmMTa5slGorqqR7bhw0nLW01YbH1O4Nzp5ZoYzM+1jRUnVwCsdBMhUg0aTsY7PO6aCO29pBkBFNFzqq631vmU+ahy8O5rMvruPYmChJr9spOECrxLYj4bBU53dUWs3ldUTNKzbAln3UZpsX95bbOdj7AWrXwtnuYMnRoJdRd/musX+ReoeEZWkctutT5l4sG3a4oLj/RwbEog5279C8ht6NZY2+/WuQhNudB1gjNmTVjWwWCnDBQU2OL2iRitJfMspDR7CBt4P7VOmXXAaNFEAex23FU0jjLCX7wzpwfZPWBPMvNGKq087Nw0/Sm4Hh4IMj/IehQmD29g== 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=iHcAHp3QwX/xhztHCNTGGIUaHDk5FJxGg7bcpcAGof4=; b=Tq5EQI0tKGqtgLQe14UYJoWp3txg/Jp8waHRMZu2lIzuDxo9SuZt+SJGwbKfOWaDH/gpk6DlLVMKQ5JzsdKWW0zvbp/A6CJ2opssqCFsUz49e7/j3vP13Jj/ZNMmW/16noyc4mJOvxt0RQMiPhSYhCa/lqAJwPtFPckRHLruuiWaUlpC3XNx5fXfBhrCR4LpAagDt3F//j3H7EXF0PZO1aLCMvozorFQgjGxIIRwSzg8mRmCcqeNVY55PbN8F00YwyPBWhkY+WWqb06hki5FJNL21MfUFjg5JNFbZqZVMUa03KQCXiI+YOYW9GImIFEQDy4FKR4r8WJkOovHqldQlQ== 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=iHcAHp3QwX/xhztHCNTGGIUaHDk5FJxGg7bcpcAGof4=; b=PI1hjXZL34e3DBVVYNRqnbr7HklYqk+0t9v5MxSHi0McK865EPpi1iCqHb0gPzQI+ly3nzoGC9G8i0nefHcNJ4o12BW6uvoLMo6YVddG2/2JDlZ1BZFSlVRKJqe+HElKbtTZTpFu8s4w7S9roI+uyr+lmD0EAilVU8OGOgPhlKQ= 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 v6 1/3] xen/arm64: Decode ldr/str post increment operations Date: Wed, 2 Feb 2022 17:30:15 +0000 Message-ID: <20220202173017.48463-2-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220202173017.48463-1-ayankuma@xilinx.com> References: <20220202173017.48463-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f04e706-26ab-4a20-21be-08d9e671b1a9 X-MS-TrafficTypeDiagnostic: MN2PR02MB6047:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pp/qUUdgAi7skKAeTWLv0CX0i9P/+CsvvoZHkLFkvNFh5IY3yXw/lEHFAH4gWI3p/MoTL2xhRBuiEQdPaMn0J2WvU6eU8AJuRdtVNM/lQ6D3DiuUS0oYY7QqOxkM77N2pgcD4buvHraXHOdiy0b0JJ5ygyEl/wg2ia7ZNY6OPCaWMt8mQmnvQfkn9P105V1kWddmhGA9PZJ5G1vnkeWI4HVxyo/HpwKoCDf/x142ru6GkOWNZztCXnctdu9bSRYecmpta/KC3PwJe7JF2KiGAQKXKU2p+S7ijUDmts5cdhe5DvKUdYWhzupB2iS0uUtYGSEpMne3XFaqtcnNOBaA0w+0XvdCCnxjzQBEkr4yGj5TYy5ZU3TwBczGQCrZ99mSEGlzbeiWkLARAp0+7EW86a+x7CtN+Q/oSh87s+aDvGkAWezR3H3nw14LW/01/zHX25XKF+ZBEn7ipC43/+vzqGWfkgi5+ByKjSwZHKgN4zeNAvZ8gqPPDaQ83UlHsAA59Hwnc2Qm1my7zuZkbDSFbdB3QU3vqlc4J9nSGmMIiR8xjwN56Tkx0W6tX+7q2Q4a4mIeQ6VVwmLMByNUidhBWbDbZqDB+aw4hOfanZBKR+Ll5ro6cPOLKY0q19gzMNTkN+HttyLS4hEoW++fOrkJOvdMzED1efFZYowc0S0jSRid4og+dS4HD6vrP4hP/MrU 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)(83380400001)(7696005)(426003)(36756003)(2906002)(316002)(26005)(336012)(54906003)(6916009)(2616005)(186003)(1076003)(356005)(107886003)(36860700001)(7636003)(70206006)(47076005)(5660300002)(8676002)(82310400004)(4326008)(8936002)(9786002)(508600001)(70586007)(6666004)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 17:30:23.4261 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f04e706-26ab-4a20-21be-08d9e671b1a9 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: BN1NAM02FT016.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB6047 At the moment, Xen does not decode any of the arm64 instructions. This means that hsr_dabt.isv = 0, Xen cannot handle those instructions. This will lead to Xen abort the guests (from which those instructions originated). 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 patches, decode_arm64() will get invoked when hsr_dabt.isv=0. Signed-off-by: Ayan Kumar Halder --- Changelog :- v2..v5 - Mentioned in the cover letter. v6 - 1. Fixed the code style issues as mentioned in v5. xen/arch/arm/decode.c | 80 ++++++++++++++++++++++++++++++++- xen/arch/arm/decode.h | 49 +++++++++++++++++--- xen/arch/arm/include/asm/mmio.h | 4 ++ xen/arch/arm/io.c | 2 +- 4 files changed, 125 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c index 792c2e92a7..3f2d2a3f62 100644 --- a/xen/arch/arm/decode.c +++ b/xen/arch/arm/decode.c @@ -23,6 +23,7 @@ #include #include +#include #include "decode.h" @@ -84,6 +85,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"); + goto bad_loadstore; + } + + /* + * 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", 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 +223,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 ( !psr_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..fe7512a053 100644 --- a/xen/arch/arm/decode.h +++ b/xen/arch/arm/decode.h @@ -23,19 +23,54 @@ #include #include -/** - * Decode an instruction from pc - * /!\ This function is not intended to fully decode an instruction. It - * considers that the instruction is valid. +/* + * 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 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 729287e37c..a289d393f9 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -134,7 +134,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 Wed Feb 2 17:30:16 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: 12733316 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 708A1C4332F for ; Wed, 2 Feb 2022 17:30:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.264368.457457 (Exim 4.92) (envelope-from ) id 1nFJSi-0005da-7s; Wed, 02 Feb 2022 17:30:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 264368.457457; Wed, 02 Feb 2022 17:30:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nFJSi-0005ck-37; Wed, 02 Feb 2022 17:30:32 +0000 Received: by outflank-mailman (input) for mailman id 264368; Wed, 02 Feb 2022 17:30:30 +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 1nFJSg-0005L1-KN for xen-devel@lists.xenproject.org; Wed, 02 Feb 2022 17:30:30 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20602.outbound.protection.outlook.com [2a01:111:f400:7e8a::602]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cf8c5d90-844d-11ec-8eb8-a37418f5ba1a; Wed, 02 Feb 2022 18:30:28 +0100 (CET) Received: from BN1PR10CA0024.namprd10.prod.outlook.com (2603:10b6:408:e0::29) by BY5PR02MB7059.namprd02.prod.outlook.com (2603:10b6:a03:235::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 2 Feb 2022 17:30:25 +0000 Received: from BN1NAM02FT032.eop-nam02.prod.protection.outlook.com (2603:10b6:408:e0:cafe::fc) by BN1PR10CA0024.outlook.office365.com (2603:10b6:408:e0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 17:30:24 +0000 Received: from xir-pvapexch02.xlnx.xilinx.com (149.199.80.198) by BN1NAM02FT032.mail.protection.outlook.com (10.13.3.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 17:30:24 +0000 Received: from xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) by xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 2 Feb 2022 17:30:23 +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; Wed, 2 Feb 2022 17:30:23 +0000 Received: from [10.108.8.223] (port=56994 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nFJSZ-0004a1-Ex; Wed, 02 Feb 2022 17:30:23 +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: cf8c5d90-844d-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ecr0UWO4SyOlSiknVVcc+mMeSm6YDy1WGbIqZTjCsehAUh1NZmzu8zC2WtroeeEvk0c+JFSDQ6YxLyZWnINnz30EyxxPzns+o6JHv3+Amr8X9i/CbikJJcct+PL0yeyFDr4LuClyJidy9D7oIGNbV7+o14fHpaZ+PscH3e5/qhwK+wuPG2pJQ6NcENBIYFKHlV1vH32txKjj0xIhgvG3jGsUwIz6zwJyKWN/RVGs0DzSdpvWPlzSaM0t1yYj1AnxPZrlB8abbpnflXb7MZwoKhOkKYnbqGihDegDx/c5MuWrc30k4dM08/9jRAnLM3HiFYdE/qmn5rnEjXg1khs8kg== 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=4YH8/TrWz9r2OfPhgV0o4hdK3ZeJHqkEfhXElLsPw90=; b=AQxsYg+UT8wU6xAxwV+mJS5VVWhMpfYJAJrROWe8u8pTxbbSTtzxk155kTe4p3OvF9Vk8LqoWvnqUnOncNk/Z8byyvoe6+wjk2VYLbi56cKltcT0sP5ugmLWawwNPhjhpgafaQ/+eGfdpoARYYPPHtjvSj4xejLG+TaSZ+on7+2u9AS0476mTpn973GJQ5Uy94q5uPbsBGBArWcutbSpPYrAiTrRBjRE8s+Db5nitZPbpcY1e77OGfcAw7HgiKcFaH47dGLvgsBYMC8aYcZ1m2B8RB47WbKxbn0ZjjJ9EDVzEYupY2G/hFyZsspN25xQcePw0CKdIWDaEEXuafDYoA== 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=4YH8/TrWz9r2OfPhgV0o4hdK3ZeJHqkEfhXElLsPw90=; b=o3Dfco2M8+r0G5do2elLljl/5DAg8rHmrxK4/2v/H/lyGuEOMNN15/E4I/qyVF/mwmXafWOqYmMj18aIaqv9NFsJ7he4BPPGTfffVmz85EgcX3sO9cYn4QJNJPd2HuNeAJbktmna2er7ooK586YKsDnVMnE9VC42FiVJOxO6J20= 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-pvapexch02.xlnx.xilinx.com; From: Ayan Kumar Halder To: CC: , , , , , Ayan Kumar Halder Subject: [XEN v6 2/3] xen/arm64: io: Support instructions (for which ISS is not valid) on emulated MMIO region using MMIO handler Date: Wed, 2 Feb 2022 17:30:16 +0000 Message-ID: <20220202173017.48463-3-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220202173017.48463-1-ayankuma@xilinx.com> References: <20220202173017.48463-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f3963ef-38f8-40c3-ddbc-08d9e671b249 X-MS-TrafficTypeDiagnostic: BY5PR02MB7059:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J53F8qZaLUKi8WWrGKTSjg1Nnids8JVZDRyDH+E+DwlqdDXXW/yJR4uroenFaCayNSCy6v91NZoHUdSr4QHx+2QXnqs0VbYdE4mKT5IEeyZuAv7R4sSaskx53cmOXa5Kclm1LeEZmlu30xeJ7+BUBUkhtpdiZ97C33VFxs/t3HBfnBLlQyRz+V+xMBJc1zb870glpgKlwJ9mrMiKsvAomXitQkZbDUlz17Wel2Sn7tSBuU+84vfthgi6Meabh86YG+MUXN95R+avMthc7g9DVzcKv86w57pscouy8g8NkR1yS/OOqSZWp96Do/jqPlCGAT/vn7CfNGnyvGohPlrUVo8pREau3lzigyvloMTQJ5f1/RIhfBhA/iWhCrKLqptedocooewktJhli6zqhHwEjZYNv+MR9TdjT8l1OBstvdIRVQr7cnOia+gNhdZTtChQlNjDPC+g17bK3gPkhEyo1iEmooP8kL7FoAq6tF2Zz4UAneUEqQ6DhxW3/rCDPQox3DvxEBN1y8pCya17D8GMosVCOGPK33RTBwb2itwsPsw/Q9ch39gp5739lqUPdDw+V7nQafEScSUFEkAs+8XSGzUUJ/9G/nB3CETjjdN6VPURrqGEKaMXLhAbDl6CwVlC5qLhD/sramyP9XFjbD+d8Kdbq6HPVl3t8YjHPJkIs12y/ceIFPhAbQPKLLpJ5BBU4/R4Ke1FUaFSifDy5W0C9g== X-Forefront-Antispam-Report: CIP:149.199.80.198;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:xir-pvapexch02.xlnx.xilinx.com;PTR:unknown-80-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(2616005)(2906002)(36756003)(6666004)(36860700001)(508600001)(26005)(186003)(1076003)(6916009)(107886003)(7696005)(316002)(54906003)(426003)(83380400001)(7636003)(47076005)(70206006)(70586007)(4326008)(8936002)(8676002)(82310400004)(336012)(356005)(5660300002)(9786002)(102446001)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 17:30:24.4795 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f3963ef-38f8-40c3-ddbc-08d9e671b249 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-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT032.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB7059 For instructions on MMIO regions emulated by Xen, Xen reads the remaining bits of the HSR. It determines if the instruction is to be ignored, retried or decoded. If it gets an error while decoding the instruction, then it sends an abort to the guest. If the instruction is valid or successfully decoded, Xen tries to execute the instruction for the emulated MMIO region. If the instruction was successfully executed, then Xen determines if the instruction needs further processing. For eg:- In case of ldr/str post indexing on arm64, the rn register needs to be updated. 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. xen/arch/arm/arm32/traps.c | 6 ++ xen/arch/arm/arm64/traps.c | 41 ++++++++++++ xen/arch/arm/decode.h | 12 +++- xen/arch/arm/include/asm/traps.h | 2 + xen/arch/arm/io.c | 108 +++++++++++++++++++++++++------ 5 files changed, 148 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/arm32/traps.c b/xen/arch/arm/arm32/traps.c index 9c9790a6d1..6ad9a31499 100644 --- a/xen/arch/arm/arm32/traps.c +++ b/xen/arch/arm/arm32/traps.c @@ -21,6 +21,7 @@ #include +#include #include #include @@ -82,6 +83,11 @@ 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) +{ + ASSERT_UNREACHABLE(); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/arm64/traps.c b/xen/arch/arm/arm64/traps.c index 9113a15c7a..4de2206801 100644 --- a/xen/arch/arm/arm64/traps.c +++ b/xen/arch/arm/arm64/traps.c @@ -18,9 +18,12 @@ #include +#include #include +#include #include #include +#include #include @@ -44,6 +47,44 @@ 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; + + /* + * 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 + ASSERT_UNREACHABLE(); + } + 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.h b/xen/arch/arm/decode.h index fe7512a053..5efd72405e 100644 --- a/xen/arch/arm/decode.h +++ b/xen/arch/arm/decode.h @@ -52,7 +52,17 @@ union instr { #define POST_INDEX_FIXED_MASK 0x3B200C00 #define POST_INDEX_FIXED_VALUE 0x38000400 -/* Decode an instruction from pc +enum instr_decode_state +{ + INSTR_ERROR, /* Error encountered while decoding the instruction */ + INSTR_VALID, /* ISS is valid, so there is no need to decode */ + INSTR_SUCCESS, /* Instruction is decoded successfully */ + INSTR_IGNORE, /* Instruction is to be ignored (similar to NOP) */ + INSTR_RETRY /* Instruction is to be retried */ +}; + +/* + * Decode an instruction from pc * /!\ This function is intended to decode an instruction. It considers that the * instruction is valid. * 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 a289d393f9..1011327058 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -95,6 +95,59 @@ static const struct mmio_handler *find_mmio_handler(struct domain *d, return handler; } +enum instr_decode_state try_decode_instruction(const struct cpu_user_regs *regs, + mmio_info_t *info) +{ + int rc; + + /* + * 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"); + return INSTR_ERROR; + } + } + + /* If ISS is valid, then no need to decode the instruction any further */ + if (info->dabt.valid) + return INSTR_VALID; + + /* + * Xen should not decode the instruction when it was trapped due to + * translation fault. + */ + if ( info->dabt.s1ptw ) + return INSTR_RETRY; + + /* + * If the fault occurred due to cache maintenance or address translation + * instructions, then Xen needs to ignore these instructions. + */ + if ( info->dabt.cache ) + return INSTR_IGNORE; + + /* + * 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"); + return INSTR_ERROR; + } + else + return INSTR_SUCCESS; +} + enum io_state try_handle_mmio(struct cpu_user_regs *regs, const union hsr hsr, paddr_t gpa) @@ -106,14 +159,14 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, .gpa = gpa, .dabt = dabt }; + int rc; + enum instr_decode_state state; ASSERT(hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); handler = find_mmio_handler(v->domain, info.gpa); if ( !handler ) { - int rc; - rc = try_fwd_ioserv(regs, v, &info); if ( rc == IO_HANDLED ) return handle_ioserv(regs, v); @@ -121,31 +174,46 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, return rc; } - /* All the instructions used on emulated MMIO region should be valid */ - if ( !dabt.valid ) + state = try_decode_instruction(regs, &info); + + /* + * If the instruction was to be ignored by Xen, then it should return to the + * caller which will increment the PC, so that the guest can execute the + * next instruction. + */ + if ( state == INSTR_IGNORE ) + return IO_HANDLED; + /* + * If Xen could not decode the instruction for any reason, then it should + * ask the caller to abort the guest. + */ + else if ( state == INSTR_ERROR ) return IO_ABORT; + /* When the instruction needs to be retried by the guest */ + else if ( state == INSTR_RETRY ) + return IO_UNHANDLED; /* - * 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; + if ( info.dabt.write ) + rc = handle_write(handler, v, &info); + else + rc = handle_read(handler, v, &info); - rc = decode_instruction(regs, &info); - if ( rc ) - { - gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); - return IO_ABORT; - } + /* + * 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. + */ + if ( (rc == IO_HANDLED) && (state == INSTR_SUCCESS) ) + { + post_increment_register(&info.dabt_instr); } - if ( info.dabt.write ) - return handle_write(handler, v, &info); - else - return handle_read(handler, v, &info); + return rc; } void register_mmio_handler(struct domain *d, From patchwork Wed Feb 2 17:30:17 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: 12733317 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 10117C433F5 for ; Wed, 2 Feb 2022 17:30:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.264369.457475 (Exim 4.92) (envelope-from ) id 1nFJSk-00067g-MA; Wed, 02 Feb 2022 17:30:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 264369.457475; Wed, 02 Feb 2022 17:30:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nFJSk-00067X-Ij; Wed, 02 Feb 2022 17:30:34 +0000 Received: by outflank-mailman (input) for mailman id 264369; Wed, 02 Feb 2022 17:30:33 +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 1nFJSj-0005L1-85 for xen-devel@lists.xenproject.org; Wed, 02 Feb 2022 17:30:33 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20619.outbound.protection.outlook.com [2a01:111:f400:fe5a::619]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d15def38-844d-11ec-8eb8-a37418f5ba1a; Wed, 02 Feb 2022 18:30:31 +0100 (CET) Received: from BN6PR17CA0019.namprd17.prod.outlook.com (2603:10b6:404:65::29) by MW2PR02MB3723.namprd02.prod.outlook.com (2603:10b6:907:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 2 Feb 2022 17:30:27 +0000 Received: from BN1NAM02FT059.eop-nam02.prod.protection.outlook.com (2603:10b6:404:65:cafe::55) by BN6PR17CA0019.outlook.office365.com (2603:10b6:404:65::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 17:30:26 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by BN1NAM02FT059.mail.protection.outlook.com (10.13.2.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 17:30:26 +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; Wed, 2 Feb 2022 17:30:25 +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; Wed, 2 Feb 2022 17:30:25 +0000 Received: from [10.108.8.223] (port=56994 helo=xcbayankuma41x.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nFJSb-0004a1-40; Wed, 02 Feb 2022 17:30:25 +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: d15def38-844d-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K/xXI7VBDuHNUcEW09Pw1ZV/ca2/buIrkWbnM/kAEGyegdmLNjEbqrZwAp+aHnpJlWI1Pp0D5HHXfLHQNuxlBm9eQ12u0a3gsUbrZZvrDT43H1E8ZcIh/4sSSPFy7fm+ybuC4Bz4T99oGXSEokIihXTwLCwO3EesdV2mfVzpWuLauLI56QQDt1qIsSsolG51HRhleXS9fr6RrLXDpMegIEmVAnOXrQfC4Gbh7Q3KCQxIIMYM2dN4hNfjZstaRL22v1R3L6KpdB9GvYfb5t3nVS1UEXCiG1uyTOdkTlbNYpjuRV7c2d0UHJMHKdvfz7vMGrbwaMIbJhuLk8LD2J0c7A== 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=tbCuvUCFusZf+eCXK+aysJFXbfAHB5vy5OzbqrLtyaI=; b=PO9UHz0QMO5H08b7doM1oo1RdfsFCRCYrk/w8LAwTnveuV5ueY5ca3Wcg89kBFB2raC0FlmFEZ70DZOXe/dh7mZqnrjMXhqX0ir/SHtrLRtFQfXtywXSImjjGZR7yGlmu8SUo0IpAHdiCM/9QlJcS89VQbMoMHXwI7n1CKD5T4eczBFPHVRI6wPwXj8vmCiTSqzRYM3fTCRGjOKtKFdDDlCCEMThwOWSxxj+jK2EgHmt9WeyvHeHG+zmEdJLXXVbU8JSFXCaFhAaxgRuiV0eYvEy7YgwA2QBKlEtM1K9/EOXnVFgDC8OQrvhFP6Hz5AD9hY5jRNGhTBe6LtMyD1JJg== 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=tbCuvUCFusZf+eCXK+aysJFXbfAHB5vy5OzbqrLtyaI=; b=SMxxHNGZRLH06eLu1RF9MiSdrY2tQ3XpRzYwjRNtMskpSnn6uV+gxwlOaNAdQmo1QrE3jdRJFTH2+Ubk3GU8tvjo/KOACnob9MGArRSRJ6sqzFtVlhiEetIvYnGSzq+zk/aOG5dwu5UkHpJEGOfvnSQIA76Dfjpx815ttQsirq8= 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 v6 3/3] xen/arm64: io: Support instructions (for which ISS is not valid) on emulated MMIO region using ioreq handler Date: Wed, 2 Feb 2022 17:30:17 +0000 Message-ID: <20220202173017.48463-4-ayankuma@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220202173017.48463-1-ayankuma@xilinx.com> References: <20220202173017.48463-1-ayankuma@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ccfdd79-e2d4-4e90-5ac6-08d9e671b360 X-MS-TrafficTypeDiagnostic: MW2PR02MB3723:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wd1Ryo6gPBmRpXWngbYO46x8ZFXKawG6/21eIeZqz+toOQrbWs24X9o2N3nP+l1RzWIKy8llJ36y+D0V5JYZuFtelPg7pFwQSjgg2jfBCiAe5MdY661Va9w148ARP/r/I5qCweZ33uKNCXYq+H+6eun888CM5NVnEKTzB8NKbshD3pBCNBHCbYxp4C/hVbIL9rwUKhwYkDh/MDd5uGS9owyX7MeBqj2R5nXsF0JL8A3TPXQNtU0xtb5dxJoR061NgtC1i4stSzrbTHFcK1QcSpblZhVYmP723oern1Ma+o/vYYgWoLykqjTE8gAq8fBWNes1002L6Pxb+Sq0m+KO2lA/Fy16pMaFXLtsUjUfCy9o2AThKhP+qxpdnvM0v6jajsSpncvhyMHBhcPqQKWgYTLH4YTWWALspxW1DQ24JZ74ueAu98HuVpq2qJa0vPhg/1bI1EZUmBxi3aZSLUEIu2geKO/la8kRCdJLcH6+C4uHhQph4Dxe1pc3n4QZ1O+y1CTYf9WPFZSaddMEurFNByvCn96NTzAlsVxWTx4tMETTLts1LN/5z8CHR8og6tuDt7cAdE7Bs9tvYFHIa9+xPkSHXXlv2Ml/6s34yD7sNOfdFPY+O0ilSIYGkgfCxc6GwkDVtkRKzn4qZL/3ksDo2zX+Bdl+RWKP6eeVGzGMRFuVp0jQxNQncwCmJ2emWJZn9AC59hWCrBwc6N55Pyy+lg== 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)(36840700001)(46966006)(7636003)(82310400004)(2906002)(356005)(7696005)(6666004)(5660300002)(2616005)(9786002)(36860700001)(336012)(107886003)(47076005)(83380400001)(70586007)(70206006)(1076003)(8936002)(8676002)(54906003)(36756003)(4326008)(6916009)(426003)(186003)(316002)(26005)(30864003)(508600001)(102446001)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 17:30:26.3046 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ccfdd79-e2d4-4e90-5ac6-08d9e671b360 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: BN1NAM02FT059.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR02MB3723 When an instruction is trapped in Xen due to translation fault, Xen checks if the ISS is valid. If not, Xen tries to resolve the translation fault using p2m page tables. In case if it is a data abort, Xen will try to map the mmio region to the guest (ie tries to emulate the mmio region). If it is not successfull, then it tries to decode the instruction. It saves the decoding state, rn and imm9 to ioreq. 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. Signed-off-by: Ayan Kumar Halder --- Changelog :- v2..v5 - Provided in cover letter. v6 - 1. 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. 2. Also stored 'instr_details' inside 'struct ioreq'. This enables arch_ioreq_complete_mmio() to invoke post_increment_register() without decoding the instruction again. 3. 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. 4. 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. xen/arch/arm/arm64/traps.c | 4 +++ xen/arch/arm/decode.c | 1 + xen/arch/arm/decode.h | 9 ------ xen/arch/arm/include/asm/mmio.h | 13 ++++++++ xen/arch/arm/io.c | 56 ++++++++++----------------------- xen/arch/arm/ioreq.c | 13 +++++--- xen/arch/arm/traps.c | 56 +++++++++++++++++++++++++++++++-- xen/include/public/hvm/ioreq.h | 19 +++++------ 8 files changed, 108 insertions(+), 63 deletions(-) diff --git a/xen/arch/arm/arm64/traps.c b/xen/arch/arm/arm64/traps.c index 4de2206801..505a843b07 100644 --- a/xen/arch/arm/arm64/traps.c +++ b/xen/arch/arm/arm64/traps.c @@ -52,6 +52,10 @@ void post_increment_register(const struct instr_details *instr) struct cpu_user_regs *regs = guest_cpu_user_regs(); register_t val; + /* 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" diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c index 3f2d2a3f62..0a4d9d2772 100644 --- a/xen/arch/arm/decode.c +++ b/xen/arch/arm/decode.c @@ -147,6 +147,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/decode.h b/xen/arch/arm/decode.h index 5efd72405e..6a09b07b46 100644 --- a/xen/arch/arm/decode.h +++ b/xen/arch/arm/decode.h @@ -52,15 +52,6 @@ union instr { #define POST_INDEX_FIXED_MASK 0x3B200C00 #define POST_INDEX_FIXED_VALUE 0x38000400 -enum instr_decode_state -{ - INSTR_ERROR, /* Error encountered while decoding the instruction */ - INSTR_VALID, /* ISS is valid, so there is no need to decode */ - INSTR_SUCCESS, /* Instruction is decoded successfully */ - INSTR_IGNORE, /* Instruction is to be ignored (similar to NOP) */ - INSTR_RETRY /* Instruction is to be retried */ -}; - /* * Decode an instruction from pc * /!\ This function is intended to decode an instruction. It considers that the diff --git a/xen/arch/arm/include/asm/mmio.h b/xen/arch/arm/include/asm/mmio.h index 3354d9c635..f7cdf66a5b 100644 --- a/xen/arch/arm/include/asm/mmio.h +++ b/xen/arch/arm/include/asm/mmio.h @@ -26,12 +26,23 @@ #define MAX_IO_HANDLER 16 +enum instr_decode_state +{ + INSTR_ERROR, /* Error encountered while decoding the instruction */ + INSTR_VALID, /* ISS is valid, so there is no need to decode */ + INSTR_LDR_STR_POSTINDEXING, /* Instruction is decoded successfully. + It is ldr/str post indexing */ + INSTR_IGNORE, /* Instruction is to be ignored (similar to NOP) */ + INSTR_RETRY /* Instruction is to be retried */ +}; + 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; @@ -77,6 +88,8 @@ void register_mmio_handler(struct domain *d, 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/io.c b/xen/arch/arm/io.c index 1011327058..46726637c6 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -95,8 +95,8 @@ static const struct mmio_handler *find_mmio_handler(struct domain *d, return handler; } -enum instr_decode_state try_decode_instruction(const struct cpu_user_regs *regs, - mmio_info_t *info) +void try_decode_instruction(const struct cpu_user_regs *regs, + mmio_info_t *info) { int rc; @@ -111,27 +111,37 @@ enum instr_decode_state try_decode_instruction(const struct cpu_user_regs *regs, if ( rc ) { gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); - return INSTR_ERROR; + info->dabt_instr.state = INSTR_ERROR; + return; } } /* If ISS is valid, then no need to decode the instruction any further */ if (info->dabt.valid) - return INSTR_VALID; + { + info->dabt_instr.state = INSTR_VALID; + return; + } /* * Xen should not decode the instruction when it was trapped due to * translation fault. */ if ( info->dabt.s1ptw ) - return INSTR_RETRY; + { + info->dabt_instr.state = INSTR_RETRY; + return; + } /* * If the fault occurred due to cache maintenance or address translation * instructions, then Xen needs to ignore these instructions. */ if ( info->dabt.cache ) - return INSTR_IGNORE; + { + info->dabt_instr.state = INSTR_IGNORE; + return; + } /* * Armv8 processor does not provide a valid syndrome for decoding some @@ -142,10 +152,8 @@ enum instr_decode_state try_decode_instruction(const struct cpu_user_regs *regs, if ( rc ) { gprintk(XENLOG_ERR, "Unable to decode instruction\n"); - return INSTR_ERROR; + info->dabt_instr.state = INSTR_ERROR; } - else - return INSTR_SUCCESS; } enum io_state try_handle_mmio(struct cpu_user_regs *regs, @@ -160,7 +168,6 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, .dabt = dabt }; int rc; - enum instr_decode_state state; ASSERT(hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); @@ -174,25 +181,6 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, return rc; } - state = try_decode_instruction(regs, &info); - - /* - * If the instruction was to be ignored by Xen, then it should return to the - * caller which will increment the PC, so that the guest can execute the - * next instruction. - */ - if ( state == INSTR_IGNORE ) - return IO_HANDLED; - /* - * If Xen could not decode the instruction for any reason, then it should - * ask the caller to abort the guest. - */ - else if ( state == INSTR_ERROR ) - return IO_ABORT; - /* When the instruction needs to be retried by the guest */ - else if ( state == INSTR_RETRY ) - return IO_UNHANDLED; - /* * At this point, we know that the instruction is either valid or has been * decoded successfully. Thus, Xen should be allowed to execute the @@ -203,16 +191,6 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs, else rc = handle_read(handler, v, &info); - /* - * 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. - */ - if ( (rc == IO_HANDLED) && (state == INSTR_SUCCESS) ) - { - post_increment_register(&info.dabt_instr); - } - return rc; } diff --git a/xen/arch/arm/ioreq.c b/xen/arch/arm/ioreq.c index 308650b400..d8909aa903 100644 --- a/xen/arch/arm/ioreq.c +++ b/xen/arch/arm/ioreq.c @@ -23,10 +23,13 @@ #include +#include "decode.h" + enum io_state handle_ioserv(struct cpu_user_regs *regs, struct vcpu *v) { const union hsr hsr = { .bits = regs->hsr }; - const struct hsr_dabt dabt = hsr.dabt; + struct hsr_dabt dabt = hsr.dabt; + /* Code is similar to handle_read */ register_t r = v->io.req.data; @@ -61,10 +64,13 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, */ .df = 0, .data = get_user_reg(regs, info->dabt.reg), + .dabt_instr = &info->dabt_instr, .state = STATE_IOREQ_READY, }; struct ioreq_server *s = NULL; enum io_state rc; + bool instr_decoded = false; + const union hsr hsr = { .bits = regs->hsr }; if ( vio->req.state != STATE_IOREQ_NONE ) { @@ -76,9 +82,6 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs, if ( !s ) return IO_UNHANDLED; - if ( !info->dabt.valid ) - return IO_ABORT; - vio->req = p; rc = ioreq_send(s, &p, 0); @@ -95,6 +98,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.req.dabt_instr; struct cpu_user_regs *regs = guest_cpu_user_regs(); const union hsr hsr = { .bits = regs->hsr }; @@ -106,6 +110,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 9339d12f58..6cce2379fa 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1906,6 +1906,7 @@ 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; /* * If this bit has been set, it means that this stage-2 abort is caused @@ -1959,6 +1960,51 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, return; } case FSC_FLT_TRANS: + + info.gpa = gpa; + info.dabt = hsr.dabt; + + /* Check if the ISS is valid. */ + if ( !hsr.dabt.valid ) + { + + /* + * Assumption :- Most of the times when we get a translation fault + * and the ISS is invalid, the underlying cause is that the page + * tables have not been set up correctly. + * 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; + + if ( is_data && try_map_mmio(gaddr_to_gfn(gpa)) ) + return; + + try_decode_instruction(regs, &info); + + /* + * If the instruction was to be ignored by Xen, then it should return to the + * caller which will increment the PC, so that the guest can execute the + * next instruction. + */ + if ( info.dabt_instr.state == INSTR_IGNORE ) + { + advance_pc(regs, hsr); + return; + } + /* + * If Xen could not decode the instruction for any reason, then it should + * ask the caller to abort the guest. + */ + else if ( info.dabt_instr.state == INSTR_ERROR ) + goto inject_abt; + /* When the instruction needs to be retried by the guest */ + else if ( info.dabt_instr.state == INSTR_RETRY ) + return; + } + /* * Attempt first to emulate the MMIO as the data abort will * likely happen in an emulated region. @@ -1975,6 +2021,13 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, goto inject_abt; case IO_HANDLED: advance_pc(regs, hsr); + /* + * 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); return; case IO_RETRY: /* finish later */ @@ -1985,8 +2038,7 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, } } - /* - * First check if the translation fault can be resolved by the + /* 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, diff --git a/xen/include/public/hvm/ioreq.h b/xen/include/public/hvm/ioreq.h index c511fae8e7..e4183960d8 100644 --- a/xen/include/public/hvm/ioreq.h +++ b/xen/include/public/hvm/ioreq.h @@ -50,19 +50,20 @@ * SEGMENT |BUS |DEV |FN |OFFSET */ struct ioreq { - uint64_t addr; /* physical address */ - uint64_t data; /* data (or paddr of data) */ - uint32_t count; /* for rep prefixes */ - uint32_t size; /* size in bytes */ - uint32_t vp_eport; /* evtchn for notifications to/from device model */ + uint64_t addr; /* physical address */ + uint64_t data; /* data (or paddr of data) */ + uint32_t count; /* for rep prefixes */ + uint32_t size; /* size in bytes */ + uint32_t vp_eport; /* evtchn for notifications to/from device model */ uint16_t _pad0; uint8_t state:4; - uint8_t data_is_ptr:1; /* if 1, data above is the guest paddr - * of the real data to use. */ - uint8_t dir:1; /* 1=read, 0=write */ + uint8_t data_is_ptr:1; /* if 1, data above is the guest paddr + * of the real data to use. */ + uint8_t dir:1; /* 1=read, 0=write */ uint8_t df:1; uint8_t _pad1:1; - uint8_t type; /* I/O type */ + uint8_t type; /* I/O type */ + struct instr_details *dabt_instr; /* when the instruction is decoded */ }; typedef struct ioreq ioreq_t;