From nobody Sat Feb 7 15:09:42 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 587642512C1 for ; Wed, 5 Mar 2025 16:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741192022; cv=none; b=By9HUWYNdzttYuyBp6ExbuyG8FObqBbx3PSGxvspRs7IyjOI2cZ6GkxGj2qILlsflBjmRzCfA6c6jX2HpKT+iyh+ECSetLnJGztGNQYGyKPDEeydvMLY4MNLXRQySZhtObsaCgJjh76N2V8UIxeADkavvIoZi3ylAFMXTdswWqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741192022; c=relaxed/simple; bh=NufEolRxNPU40ht+CZp74NctFQAb3wfmh8Gc5PxIQeE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kUrRi+/XFS24MpVOvVcJMeURje6maehBAqZSpD/HcRWSJljOZy1kOMHnkLfUPkEn6b3BfGtaxqKAi6z9p9V3PWi70Qs4Q9AKNPqmLpXlw+Jg/p4I7esI28qmPdZocZgCOd3aD9zuRCmWB0P1p519olycy4xT1Lxl0kO2k1d8MMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dypaf9OB; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dypaf9OB" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aaf900cc7fbso1290753966b.3 for ; Wed, 05 Mar 2025 08:27:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741192018; x=1741796818; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IB1gjJRKzsGUjoFlHcs0x65GD8vsyFDAaTOj7W/RGZ0=; b=Dypaf9OB1Cq9jcpqxoq5+vyMBp4yhQTlq+fNEXaXZ096E/S1Zjv7rXcnWLm/mZ5haU yZvUpqarSfLspivXv+YPutOM2+tIIflS/jSKEfjAeQ/lJKKsh5aUjS9EHTAvhmm93DTa 5tR7lXk9W2LLqXmH716HdAqCuoL9nmaM7Tn0TrYeDAIOAWSQoxCP7ZuV/wcALlp5h7lA 0G22Aq14n1rKeSrkbhGEjAkj+oybZTS2b8EMjFUVF3gUJa/a24GGuTncqCAmnZvJLrIi zQDecEZbhtjr0A8527GaFSvwKWsVpwf1EIQOVyEWGnazXQbdrcmcRohm7a5uLLTN7rWa 2+gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741192018; x=1741796818; 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=IB1gjJRKzsGUjoFlHcs0x65GD8vsyFDAaTOj7W/RGZ0=; b=dvWK6LVvqOFCFsQjK2Oe1yv1b27bVkcTgO1IiyFVecT+VKSXbJAB38vanqBe2Nj5po yA3OOD3ypMxfSRwEABOw4i1sKv1XHrEzCKH4JczYeh84P+mepRPTNxe8ObE5z72p2Guk a0HetW6CwXyjC2rlovarghIwIeoZVn+Bx8CcQTTNmeRe7g8ssYClmyxDyZ08b+LT7z5x HPOUTi11osB0MI4x9t4TTcGK1FK68lHLdLCLgn6uYDRwvczWHXmvJbTknlaqpgqzO+bJ Cz2mD0y4DLIEcXdU6xcGjG0RYE9VqlieE313lLxJQQR/yLi62PLQ+Fl6RXWywn+V1a1j sOJA== X-Forwarded-Encrypted: i=1; AJvYcCV11p7HoCCAbVseAKDZ+xeIA3GGVKw23Ph6HUuj4IvVPTwo5ylJ8ZCjML3q9JgzdvOvHYhAvWKf12JgGko=@vger.kernel.org X-Gm-Message-State: AOJu0YxWA4KVd8HfF8g7JrlT/Fo94O/WAbs2/8NCzXvdQ+OlN06eNp74 sDvL0eglzVbHxQk34+WZBmQRjjguWxdDfbyp24ttTAzueu3aYxY5 X-Gm-Gg: ASbGncsvqCvZkdImDbi9Toh9xRksc9/1oJNKkjR3f50sbtbNZRq7WALfmPsIfoP/u2f /cIlOpRxgxfpcqo91k1tAOeydY5OO5s9MK+zYBL6Hx13yMAOscKjVfqMtIgH9+E+UBvT4ZKvnoe uVD99t6qbVs3X5Raj2red5tcoRzSDYjMSuosveMNLOywJrTZPZJqG7V4s+qtFAEK63jgdoSKg/Z quA5UZsot6gtzLZFE/EIE5QEDxfN2DSgzaDEy8LMcewuAP3FNBOp3G3LbA0TPuCwdUhmMOM7Qaw nhviYjgJKvu08NQx1RSPUKe3W3/mHASknU+Rh2MkNVzstA50h1E6/g== X-Google-Smtp-Source: AGHT+IFwGVTvFx5WFAKAaoE6f1+EmkdqxbwAa5lkpI8zjwVRBoWJlwXMvIrXWlkoT34bi8OCXCjt5Q== X-Received: by 2002:a17:906:7314:b0:ac1:17fe:c773 with SMTP id a640c23a62f3a-ac20da86f0cmr447062466b.41.1741192018293; Wed, 05 Mar 2025 08:26:58 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac1fa431529sm281412066b.148.2025.03.05.08.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 08:26:57 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH] x86/kexec: Merge x86_32 and x86_64 code using macros from asm.h Date: Wed, 5 Mar 2025 17:26:37 +0100 Message-ID: <20250305162649.130270-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Merge common x86_32 and x86_64 code in crash_setup_regs() using macros from asm/asm.h. The compiled object files before and after the patch are unchanged. Signed-off-by: Uros Bizjak Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" --- arch/x86/include/asm/asm.h | 2 ++ arch/x86/include/asm/kexec.h | 44 +++++++++++++++--------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h index 975ae7a9397e..2bccc063d30b 100644 --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -41,6 +41,8 @@ #define _ASM_SUB __ASM_SIZE(sub) #define _ASM_XADD __ASM_SIZE(xadd) #define _ASM_MUL __ASM_SIZE(mul) +#define _ASM_PUSHF __ASM_SIZE(pushf) +#define _ASM_POP __ASM_SIZE(pop) =20 #define _ASM_AX __ASM_REG(ax) #define _ASM_BX __ASM_REG(bx) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 8ad187462b68..56040ae6bda0 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -18,6 +18,7 @@ #include #include =20 +#include #include #include =20 @@ -71,29 +72,15 @@ static inline void crash_setup_regs(struct pt_regs *new= regs, if (oldregs) { memcpy(newregs, oldregs, sizeof(*newregs)); } else { -#ifdef CONFIG_X86_32 - asm volatile("movl %%ebx,%0" : "=3Dm"(newregs->bx)); - asm volatile("movl %%ecx,%0" : "=3Dm"(newregs->cx)); - asm volatile("movl %%edx,%0" : "=3Dm"(newregs->dx)); - asm volatile("movl %%esi,%0" : "=3Dm"(newregs->si)); - asm volatile("movl %%edi,%0" : "=3Dm"(newregs->di)); - asm volatile("movl %%ebp,%0" : "=3Dm"(newregs->bp)); - asm volatile("movl %%eax,%0" : "=3Dm"(newregs->ax)); - asm volatile("movl %%esp,%0" : "=3Dm"(newregs->sp)); - asm volatile("movl %%ss, %%eax;" :"=3Da"(newregs->ss)); - asm volatile("movl %%cs, %%eax;" :"=3Da"(newregs->cs)); - asm volatile("movl %%ds, %%eax;" :"=3Da"(newregs->ds)); - asm volatile("movl %%es, %%eax;" :"=3Da"(newregs->es)); - asm volatile("pushfl; popl %0" :"=3Dm"(newregs->flags)); -#else - asm volatile("movq %%rbx,%0" : "=3Dm"(newregs->bx)); - asm volatile("movq %%rcx,%0" : "=3Dm"(newregs->cx)); - asm volatile("movq %%rdx,%0" : "=3Dm"(newregs->dx)); - asm volatile("movq %%rsi,%0" : "=3Dm"(newregs->si)); - asm volatile("movq %%rdi,%0" : "=3Dm"(newregs->di)); - asm volatile("movq %%rbp,%0" : "=3Dm"(newregs->bp)); - asm volatile("movq %%rax,%0" : "=3Dm"(newregs->ax)); - asm volatile("movq %%rsp,%0" : "=3Dm"(newregs->sp)); + asm volatile(_ASM_MOV " %%" _ASM_BX ",%0" : "=3Dm"(newregs->bx)); + asm volatile(_ASM_MOV " %%" _ASM_CX ",%0" : "=3Dm"(newregs->cx)); + asm volatile(_ASM_MOV " %%" _ASM_DX ",%0" : "=3Dm"(newregs->dx)); + asm volatile(_ASM_MOV " %%" _ASM_SI ",%0" : "=3Dm"(newregs->si)); + asm volatile(_ASM_MOV " %%" _ASM_DI ",%0" : "=3Dm"(newregs->di)); + asm volatile(_ASM_MOV " %%" _ASM_BP ",%0" : "=3Dm"(newregs->bp)); + asm volatile(_ASM_MOV " %%" _ASM_AX ",%0" : "=3Dm"(newregs->ax)); + asm volatile(_ASM_MOV " %%" _ASM_SP ",%0" : "=3Dm"(newregs->sp)); +#ifdef CONFIG_X86_64 asm volatile("movq %%r8,%0" : "=3Dm"(newregs->r8)); asm volatile("movq %%r9,%0" : "=3Dm"(newregs->r9)); asm volatile("movq %%r10,%0" : "=3Dm"(newregs->r10)); @@ -102,10 +89,15 @@ static inline void crash_setup_regs(struct pt_regs *ne= wregs, asm volatile("movq %%r13,%0" : "=3Dm"(newregs->r13)); asm volatile("movq %%r14,%0" : "=3Dm"(newregs->r14)); asm volatile("movq %%r15,%0" : "=3Dm"(newregs->r15)); - asm volatile("movl %%ss, %%eax;" :"=3Da"(newregs->ss)); - asm volatile("movl %%cs, %%eax;" :"=3Da"(newregs->cs)); - asm volatile("pushfq; popq %0" :"=3Dm"(newregs->flags)); #endif + asm volatile("movl %%ss,%k0" :"=3Da"(newregs->ss)); + asm volatile("movl %%cs,%k0" :"=3Da"(newregs->cs)); +#ifdef CONFIG_X86_32 + asm volatile("movl %%ds,%k0" :"=3Da"(newregs->ds)); + asm volatile("movl %%es,%k0" :"=3Da"(newregs->es)); +#endif + asm volatile(_ASM_PUSHF "\n\t" + _ASM_POP " %0" : "=3Dm"(newregs->flags)); newregs->ip =3D _THIS_IP_; } } --=20 2.42.0