From nobody Mon Nov 3 18:36:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1726066727; cv=none; d=zohomail.com; s=zohoarc; b=GMXbWVItXCVcYzOUe6Svo3yelAH1bRK6ao1Y2befgClMaaKPYHYuL1bqHuJ0z81YsXvEZ0JJ7b/QKorhT4QOZbiVsIDjHBMZY11igD4G1UAK3cvd69C2eNg5RVVQtWEKLxd8k97AXcYn+do+Cq4YBr7URAu2Hdhy+hzQwvn8wZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726066727; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i+gBrrFhvYWAHE0noy24PPtPMyE+3z6FZk0gxLp1lsk=; b=aizYE8mQh2//B2p4JvOOv4gYUWOOUEUo8zUzfwQIMUZeoWOzCWzBXjChGAKa1hi/aYIJg1ss6ZsYRSMHO+NPlDT9sQzAUI+dxtc/VpPeGWAMLrfzGRT7Rrm8bskx2F556vTbkS9GnC092CEh22IdGrS099d6sc0t7LSOAPOMUpg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17260667271656.383848301292801; Wed, 11 Sep 2024 07:58:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.796744.1206495 (Exim 4.92) (envelope-from ) id 1soOnd-0003JM-Hq; Wed, 11 Sep 2024 14:58:29 +0000 Received: by outflank-mailman (output) from mailman id 796744.1206495; Wed, 11 Sep 2024 14:58:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1soOnd-0003JF-Ek; Wed, 11 Sep 2024 14:58:29 +0000 Received: by outflank-mailman (input) for mailman id 796744; Wed, 11 Sep 2024 14:58: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 1soOnc-0003HA-8z for xen-devel@lists.xenproject.org; Wed, 11 Sep 2024 14:58:28 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4c886bdb-704e-11ef-99a1-01e77a169b0f; Wed, 11 Sep 2024 16:58:26 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-536584f6c84so7279503e87.0 for ; Wed, 11 Sep 2024 07:58:26 -0700 (PDT) Received: from mewpvdipd1023.corp.cloud.com ([52.166.251.127]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25cf03fcsm618050766b.162.2024.09.11.07.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 07:58:25 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4c886bdb-704e-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1726066706; x=1726671506; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=i+gBrrFhvYWAHE0noy24PPtPMyE+3z6FZk0gxLp1lsk=; b=KIgC+xAMooWbCNqhLCxaai8o13hHp2jGe6HPKC17YyC0Hm0WyrtK/Tg8ZlOviotM2g YrQKMGVru9cUGFdN9ws4F6ucGEoiDCVDnerkvMirJu1Fwx3U4fJ1rhnv7T6t0y5wtt28 OT2jSLjXH6GavTlz6c7295kReB+rJ2cgh2I2c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726066706; x=1726671506; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i+gBrrFhvYWAHE0noy24PPtPMyE+3z6FZk0gxLp1lsk=; b=XVcsEwYaI9Erfb/dLkHO78orOqFuvjfYhfZqkecvdS2a94hobA8rHxLIgQ12tKA82F FhwdOQHK4rHFK5l7nvPwhu+Jp7jKcUhf4hsSWysGPSmYJ2ughmuT+snv8IZpFGwaT13x KFz6roeS3cx3QDxxs3SzGUSKPE5Hans/2Ow0MUrcxBQaNnRaG4gZD0MH/q10g5NB4h7J RIKbKa423HsEpC7HUSeXQTXgRy03a+6CWztswgK7bV7B4AnavfmZTAppmQyAVkz09X0c wn3XUc+yWHd72T2IbnDmJl5eHoVYE55aAXtrIuRX0Fx33/hXtk2eDC+7S2jkXx3Tqtal LpAg== X-Gm-Message-State: AOJu0YzLnuO0riQfw2J/3NQeyMiWSC+2G2eV+o4Q4qVHplPwJB3xPCmI GyXdvKr3nkU9wPQwf5h0kGVrtoE6FEdOhqCamDOYWgEb3H89hTQgPZ3PevzmZH7RGEBqGg+dBd3 r X-Google-Smtp-Source: AGHT+IGcFTtGHOBfu/w2cwaUItwF043cUBlKuNL9E42Dc3/Fn2SAvgLroaEKxLd5lZ4szfCaXTSM9Q== X-Received: by 2002:a05:6512:2c0e:b0:530:ba92:f9a5 with SMTP id 2adb3069b0e04-536587f56c5mr11552055e87.45.1726066705585; Wed, 11 Sep 2024 07:58:25 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH] x86/traps: Re-enable IRQs after reading cr2 in the #PF handler Date: Wed, 11 Sep 2024 15:58:23 +0100 Message-ID: <20240911145823.12066-1-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1726066728484116600 Content-Type: text/plain; charset="utf-8" Moves sti directly after the cr2 read and immediately after the #PF handler. While in the area, remove redundant q suffix to a movq in entry.S Signed-off-by: Alejandro Vallejo --- I don't think this is a bug as much as an accident about to happen. Even if there's no cases at the moment in which the IRQ handler may page fault, that might change in the future. Note: I haven't tested it extensively beyond running it on GitLab. pipeline: https://gitlab.com/xen-project/people/agvallejo/xen/-/pipelines/1449182= 525 --- xen/arch/x86/traps.c | 2 ++ xen/arch/x86/x86_64/entry.S | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 708136f625..1c04c03d9f 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1600,6 +1600,8 @@ void asmlinkage do_page_fault(struct cpu_user_regs *r= egs) =20 addr =3D read_cr2(); =20 + local_irq_enable(); + /* fixup_page_fault() might change regs->error_code, so cache it here.= */ error_code =3D regs->error_code; =20 diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index b8482de8ee..ef803f6288 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -844,8 +844,7 @@ handle_exception_saved: #elif !defined(CONFIG_PV) ASSERT_CONTEXT_IS_XEN #endif /* CONFIG_PV */ - sti -1: movq %rsp,%rdi +1: mov %rsp,%rdi movzbl UREGS_entry_vector(%rsp),%eax #ifdef CONFIG_PERF_COUNTERS lea per_cpu__perfcounters(%rip), %rcx @@ -866,7 +865,15 @@ handle_exception_saved: jmp .L_exn_dispatch_done; \ .L_ ## vec ## _done: =20 + /* + * IRQs kept off to derisk being hit by a nested interrupt before + * reading %cr2. Otherwise a page fault in the nested interrupt ha= dnler + * would corrupt %cr2. + */ DISPATCH(X86_EXC_PF, do_page_fault) + + sti + DISPATCH(X86_EXC_GP, do_general_protection) DISPATCH(X86_EXC_UD, do_invalid_op) DISPATCH(X86_EXC_NM, do_device_not_available) --=20 2.46.0