From patchwork Sat Feb 8 00:02:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13966112 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 607A2C021A2 for ; Sat, 8 Feb 2025 00:05:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.884153.1293957 (Exim 4.92) (envelope-from ) id 1tgYLL-0001oL-0M; Sat, 08 Feb 2025 00:05:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 884153.1293957; Sat, 08 Feb 2025 00:05:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tgYLK-0001oE-Tv; Sat, 08 Feb 2025 00:05:06 +0000 Received: by outflank-mailman (input) for mailman id 884153; Sat, 08 Feb 2025 00:05:05 +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 1tgYLJ-0001YL-Nm for xen-devel@lists.xenproject.org; Sat, 08 Feb 2025 00:05:05 +0000 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [2a00:1450:4864:20::343]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 58dcfaea-e5b0-11ef-b3ef-695165c68f79; Sat, 08 Feb 2025 01:05:04 +0100 (CET) Received: by mail-wm1-x343.google.com with SMTP id 5b1f17b1804b1-4361e89b6daso17507345e9.3 for ; Fri, 07 Feb 2025 16:05:04 -0800 (PST) Received: from andrewcoop.eng.citrite.net (host-92-26-98-202.as13285.net. [92.26.98.202]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391da9656fsm72336295e9.3.2025.02.07.16.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 16:05:02 -0800 (PST) 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: 58dcfaea-e5b0-11ef-b3ef-695165c68f79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1738973103; x=1739577903; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l/JTU8E7ncqUSv3tjrzaMPmZsR3+I1KsMdSHHDijONc=; b=Xkikaa9yYEnU/n6l3n1SxpntCOvvsBOkOtsFwUHn1wDn6KBtGbJxVw9k2P+HwU+ARy uFAqVe168IBR0UWgybK/x9qZ2mF5fqu1a1rvpkGD/pz3qOqSCg/D1mUQqesOIc5oMveA uqKfL8/tFB+rojacaGZJrcaFptDEuvkKPWu08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738973103; x=1739577903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l/JTU8E7ncqUSv3tjrzaMPmZsR3+I1KsMdSHHDijONc=; b=dY7y43qrAcYNp1EIO26kkSlcGpwb7zXK+vRxsbdOd7B8FFKLiMSGZhO3eyu1mXvLYs szBdT9XUEO6gAEUSNFSZ1vjixSirCwJojuT2ohGyQmOGS2Gy3pMCuHkKfiZ2unJH15ia rGZdj3w8u9L7LHSOullIqoJNgKOWkAkYOEFzA27UxLlLyNgjFOXfGQMWN3YVMy5YtHMR kyGuuGZQYqJRL0BNkVvGP6S0yeJutGq2xDnxN4RpAaD8K1ItxQuL2RZssj2llKFh4+yr XNIksVFmz7DWxmS+1wYFf0AK/B8HKmosOxN78TWxpOdJvj74Eb9yOs67G/retnlipeTF f90g== X-Gm-Message-State: AOJu0YxpX+hk5H72erN8MlgwbQOx63a9wdZDOYZ30F2E6rluDLnYe67q BB0ge+99tbUUllgp/7y5pq69p7l5AtvMANXeoRZGDiokuyRkENPX/ldI2vA5MOm28od7/HANCEf 0S8w9ng== X-Gm-Gg: ASbGnctyn9r8ni21hC5XJDhdrS0t5ciSst24hhjcXv9lRoRvl1DCSUMbjZHTR9plYFU dxR11wBZlgOtIyQB4P+KeU7Ownz1mulfLAEjOEZMquKrfjjtyaFvBVKI44O/nuAo9fYFR1vyMM5 XPVDBxRpBKmOTQ7urjywM+d/zcb9U7L//lVVCcjBIBkprvl5kfWTUjeyAWPyxfNxXQ2bgnb0/Cq lakOsaOStZFZNuQZsvV3O+Dauc/vf3glIvE8D2XbhOV1pFMN/xGpEizhP4QBMWLzvCzgLVALYbx Q/HdqUAFjyCGEe7al9QtfGRcI7WTPl6euynyf70SbCnx2Ju8gImXWx2EgHoXj5Nnvfu1uVM= X-Google-Smtp-Source: AGHT+IHYvycWEUIGEKe3t6G6gShQYPPQiohc3YZiKSG34e+e0c3zYqEPjfHn8RpER53bOkVXxkEPTA== X-Received: by 2002:a05:600c:c19:b0:434:a386:6ae with SMTP id 5b1f17b1804b1-439249842bamr44251245e9.7.1738973103303; Fri, 07 Feb 2025 16:05:03 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko Subject: [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text Date: Sat, 8 Feb 2025 00:02:53 +0000 Message-Id: <20250208000256.431883-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250208000256.431883-1-andrew.cooper3@citrix.com> References: <20250208000256.431883-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 While fixing some common/arch boundaries for UBSAN support on other architectures, the following debugging patch: diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index c1f2d1b89d43..58d1d048d339 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -504,6 +504,8 @@ void asmlinkage __init start_xen(unsigned long fdt_paddr) system_state = SYS_STATE_active; + dump_execution_state(); + for_each_domain( d ) domain_unpause_by_systemcontroller(d); fails with: (XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input) (XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) ----[ Xen-4.20-rc arm32 debug=n Not tainted ]---- (XEN) CPU: 0 (XEN) (XEN) **************************************** (XEN) Panic on CPU 0: (XEN) CPU0: Unexpected Trap: Undefined Instruction (XEN) **************************************** This is because the condition for init text is wrong. While there's nothing interesting from that point onwards in start_xen(), it's also wrong for any livepatch which brings in an adjusted BUG_FRAME(). Use is_active_kernel_text() which is the correct test for this purpose, and is aware of init and livepatch regions too. Commit c8d4b6304a5e ("xen/arm: add support for run_in_exception_handler()"), made run_in_exception_handler() work, but didn't complete the TODO left in commit 3e802c6ca1fb ("xen/arm: Correctly support WARN_ON"). Do so, to make ARM consistent with other architectures. Fixes: 3e802c6ca1fb ("xen/arm: Correctly support WARN_ON") Signed-off-by: Andrew Cooper Reviewed-by: Michal Orzel --- CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko Sample run going wrong: https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9078570105 Sample run with dump_execution_state() working: https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/9079185111 --- xen/arch/arm/arm32/traps.c | 3 +-- xen/arch/arm/include/asm/processor.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/arm32/traps.c b/xen/arch/arm/arm32/traps.c index a2fc1c22cbc9..b88d41811b49 100644 --- a/xen/arch/arm/arm32/traps.c +++ b/xen/arch/arm/arm32/traps.c @@ -36,8 +36,7 @@ void do_trap_undefined_instruction(struct cpu_user_regs *regs) uint32_t pc = regs->pc; uint32_t instr; - if ( !is_kernel_text(pc) && - (system_state >= SYS_STATE_active || !is_kernel_inittext(pc)) ) + if ( !is_active_kernel_text(pc) ) goto die; /* PC should be always a multiple of 4, as Xen is using ARM instruction set */ diff --git a/xen/arch/arm/include/asm/processor.h b/xen/arch/arm/include/asm/processor.h index 60b587db697f..d80d44aeaa8f 100644 --- a/xen/arch/arm/include/asm/processor.h +++ b/xen/arch/arm/include/asm/processor.h @@ -577,8 +577,7 @@ void panic_PAR(uint64_t par); void show_registers(const struct cpu_user_regs *regs); void show_stack(const struct cpu_user_regs *regs); -//#define dump_execution_state() run_in_exception_handler(show_execution_state) -#define dump_execution_state() WARN() +#define dump_execution_state() run_in_exception_handler(show_execution_state) #define cpu_relax() barrier() /* Could yield? */