From nobody Mon May 13 13:51:30 2024 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1708952119; cv=none; d=zohomail.com; s=zohoarc; b=bfptJYizx0hjXXKXGetr5Q9+60b3QhHFYLbIU4WDtdV40tuWCnZG46EndAMp/xpDvP/Wv/jkYF2or76jc8XnzDEZMwO2w5KqgGixUDwCKCfALmppOodSJGUbU2CeNmUPdMvNaZsEw1vQ1XS9jz5Q5Sp2iNay5tEg+L87mFNZq8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708952119; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5w2NVQzEy0Ft7WjMPLYhygiLJCz4wsG8joT9atA1+T0=; b=IQneRNfIFAPjMgluabN+94LBkx4VADgdFuqp8usVbK2ZrBuIzHRZqN6qf3LjSJuN2RN7hnQw/RJgnf2WLosv2kWQXAx49llFooa49T6HaZSE6H5oqAYLRua7cQom/jiMO8suFYpcx/IESzW0fFaAQpMfT0I1KKkmVqu0+Ng729E= 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 1708952119964462.19415100402546; Mon, 26 Feb 2024 04:55:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.685524.1066367 (Exim 4.92) (envelope-from ) id 1reaVe-0004yy-4S; Mon, 26 Feb 2024 12:55:06 +0000 Received: by outflank-mailman (output) from mailman id 685524.1066367; Mon, 26 Feb 2024 12:55: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 1reaVe-0004yr-1o; Mon, 26 Feb 2024 12:55:06 +0000 Received: by outflank-mailman (input) for mailman id 685524; Mon, 26 Feb 2024 12:55:04 +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 1reaVc-0004yB-Ou for xen-devel@lists.xenproject.org; Mon, 26 Feb 2024 12:55:04 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 424aa120-d4a6-11ee-8a58-1f161083a0e0; Mon, 26 Feb 2024 13:55:03 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a3ee69976c9so380968166b.0 for ; Mon, 26 Feb 2024 04:55:03 -0800 (PST) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id ll9-20020a170907190900b00a42e4b5ab00sm2379645ejc.41.2024.02.26.04.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:55:03 -0800 (PST) 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: 424aa120-d4a6-11ee-8a58-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1708952103; x=1709556903; 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=5w2NVQzEy0Ft7WjMPLYhygiLJCz4wsG8joT9atA1+T0=; b=hO9r8gen6CzVyADc0NrIgyyZkflG5+7qFTw+sHz425Qjga04nLlx6ulcglBkMGNXgs IRma+fEJ1U9h0he1Tb6EMnxuBVBBODpMHgT6bR0IPcR3bCgWcoUPvQQ8K9uADzfcJ24Z 4yswxwlUtf07QHXz9KosETFyMKllIotwh+ATY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708952103; x=1709556903; 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=5w2NVQzEy0Ft7WjMPLYhygiLJCz4wsG8joT9atA1+T0=; b=TEZQdRKjgssPu+JimXKQk65koO3BoH1aDA/b9UhHjQ8Ct8msciNcC7JKAg/59O53h1 iGU0Idn6iAdYzTbTOshtalB15R5b7xr7rVD26KYDPBOEpkO6oo7YukTcog4xj7L10V3y RFDpx6zcYOJJnlV9fy/zvhaR8xa5ILSzCUhdF3EDgAn/7bnAk7ixTKUmmSyLkFnzL/gK 63AlBChtvEx2sGBXq6ivdwQwQ8zIA+Aqkqri6s2Pzv5DmDF6oQlTcNer+kxkgd+Y4SV0 R95wPSX0hJYwyCN6TG7LXNAZwxJpgxkZGc7NKm0oTB5GPUQXA+aI6KuzaJweWFRQ85xN BUsA== X-Gm-Message-State: AOJu0YyDZlyW1qKqt9C1zJK+3t55iik81gac45kj2S8UFArVxdKCFd5c hGbptDvuC/Ivrjsfam3Pc1Ihgy67jsPLI6ceHaV0X1g6/4l992FzvcpjjUcyl2ZHRBww0nPDQF2 c X-Google-Smtp-Source: AGHT+IGeaEd9YSZ7F9GJ7i9W2ZNEQs6xzaQ1pXBI/vZpIn9E1CaFfrRiUdzlb2w6xdIdhxRn+1+Jtg== X-Received: by 2002:a17:906:b115:b0:a3f:5b9b:a17b with SMTP id u21-20020a170906b11500b00a3f5b9ba17bmr4178004ejy.53.1708952103233; Mon, 26 Feb 2024 04:55:03 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 1/3] x86/entry: Adjustments to "reduce assembly code size of entry points" Date: Mon, 26 Feb 2024 12:54:59 +0000 Message-Id: <20240226125501.1233599-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240226125501.1233599-1-andrew.cooper3@citrix.com> References: <20240226125501.1233599-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1708952120374100001 Some retroactive review, for if I'd got to the patch in time. * The new ASM-friendly BUILD_BUG_ON() should be in a header file. * entry_int82() wants the movl->movb treatment too. Fixes: c144b9e32427 ("x86: Reduce assembly code size of entry points") Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu Fixes just to link the two patches. --- xen/arch/x86/include/asm/asm_defns.h | 12 ++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 2 +- xen/arch/x86/x86_64/entry.S | 8 -------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/include/asm/asm_defns.h b/xen/arch/x86/include/as= m/asm_defns.h index a9a6c21c76cd..f18a11b36198 100644 --- a/xen/arch/x86/include/asm/asm_defns.h +++ b/xen/arch/x86/include/asm/asm_defns.h @@ -56,6 +56,18 @@ register unsigned long current_stack_pointer asm("rsp"); #define ASSERT_INTERRUPTS_DISABLED \ ASSERT_INTERRUPT_STATUS(z, "INTERRUPTS DISABLED") =20 +#ifdef __ASSEMBLY__ + +.macro BUILD_BUG_ON condstr cond:vararg + .if \cond + .error "Condition \"\condstr\" not satisfied" + .endif +.endm +/* preprocessor macro to make error message more user friendly */ +#define BUILD_BUG_ON(cond) BUILD_BUG_ON #cond cond + +#endif /* __ASSEMBLY__ */ + #ifdef __ASSEMBLY__ # define _ASM_EX(p) p-. #else diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compa= t/entry.S index d4f0e4804090..93fbbeb4ae18 100644 --- a/xen/arch/x86/x86_64/compat/entry.S +++ b/xen/arch/x86/x86_64/compat/entry.S @@ -15,7 +15,7 @@ FUNC(entry_int82) ENDBR64 ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 - movl $HYPERCALL_VECTOR, 4(%rsp) + movb $HYPERCALL_VECTOR, 4(%rsp) SAVE_ALL compat=3D1 /* DPL1 gate, restricted to 32bit PV guests on= ly. */ =20 SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=3Dregs/cpuinfo, %rdx=3D0, Clo= b: acd */ diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index a7bd8f0ca5b1..f8938b0b42fd 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -22,14 +22,6 @@ #endif .endm =20 -.macro BUILD_BUG_ON condstr cond:vararg - .if \cond - .error "Condition \"\condstr\" not satisfied" - .endif -.endm -/* preprocessor macro to make error message more user friendly */ -#define BUILD_BUG_ON(cond) BUILD_BUG_ON #cond cond - #ifdef CONFIG_PV /* %rbx: struct vcpu */ FUNC_LOCAL(switch_to_kernel) --=20 2.30.2 From nobody Mon May 13 13:51:30 2024 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1708952123; cv=none; d=zohomail.com; s=zohoarc; b=OzLpwt3TQuxhJidQdhZIoHOTFRzTFH1QA5b4mAyGDnpGrF+WQ5t5b2t2B6YwvSA65dfH/fe0s+XqS2wsZl8FE06hCTOap/Qt8dLsaMicZ0VgWtvlHp53c4AUQFHtNUJxc47u69S6zhaHSn9Asf3IxcHjkKLRMRIq7vTA6bzEZG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708952123; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cUPkBSwvovweP2Vn5x5Slws9PAyzIz15Jh15k5P3vWY=; b=AS1wsNeLFZ8ttyZpocw0LN1hto0mFhvXmYqNCZSU5g30cN33egOEJi0Y9UTxm4zLktOVBPStRJMiCjc/WHaiInwDahYSDU8iWq2bmD9OyLV1wNMLPQDF46xVp16aZjuOhFWz9dxwwz24HDBrgFy/PGGT9Pm6hDBLQxKdgdJr7/s= 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 1708952123226173.61581714749764; Mon, 26 Feb 2024 04:55:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.685526.1066388 (Exim 4.92) (envelope-from ) id 1reaVf-0005Sv-Kk; Mon, 26 Feb 2024 12:55:07 +0000 Received: by outflank-mailman (output) from mailman id 685526.1066388; Mon, 26 Feb 2024 12:55:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1reaVf-0005Ro-GJ; Mon, 26 Feb 2024 12:55:07 +0000 Received: by outflank-mailman (input) for mailman id 685526; Mon, 26 Feb 2024 12:55:06 +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 1reaVe-0004hn-2h for xen-devel@lists.xenproject.org; Mon, 26 Feb 2024 12:55:06 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 429d66e0-d4a6-11ee-98f5-efadbce2ee36; Mon, 26 Feb 2024 13:55:04 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a3e75e30d36so585120466b.1 for ; Mon, 26 Feb 2024 04:55:04 -0800 (PST) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id ll9-20020a170907190900b00a42e4b5ab00sm2379645ejc.41.2024.02.26.04.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:55:03 -0800 (PST) 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: 429d66e0-d4a6-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1708952104; x=1709556904; 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=cUPkBSwvovweP2Vn5x5Slws9PAyzIz15Jh15k5P3vWY=; b=DfOoHuQR819ayTj+9RmgidFAecxkIKZqWBoD+g0No+0ZClGRsD/OkC7RDjf0bg4Imo cqx2WlKan6Op6JYOmuaUhp8nryRlGkdpqcPOl5COUX39U1FHCbJ3ZdJacfkxgDkwNvC8 qMvphZGBcYp89r3ebuPjqz2CyyLzPvmvgS3fU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708952104; x=1709556904; 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=cUPkBSwvovweP2Vn5x5Slws9PAyzIz15Jh15k5P3vWY=; b=iWuee0cxc7Sy0CluBeqV2wOCIFscROkh/oOkDHEkkmZaUQ/6SdlOE4Mh10UysvghJK NRHDYnXFHLoHY8XQOiMuWrirVQbE3E3hrRmf+pHNcLQKhn3b2GkX/2rFcwj4BF/VLqOd JOOTAaJKGAa+6l27zi/rS4xKpB3CakGxm2K6TsrMbySwQPYLSIjrp7s2tgaz7lhmZ43e ICKbNijrUz5Bc/Qu23A7fpgrtELkBa+/rcgicKuQy6EDRmBWWmauFXQOHweE2n3tTpMR VyoaIKGJ7uwOzZxxu6OG4J+4CYxoRRDhG5fBukzIj9sPWbwDcHYMCP8EWycMt/Ec0OsA N5Mw== X-Gm-Message-State: AOJu0YzThXl2Tzk4UCuKUBBSMDo4LtOfusLrBn4BW50rbbnKGXq/cjs8 /he2/JrW5H25DGMqOtT9gCtY/IFL9uo6ZVXZP5TvN7m5il8ZOlDbRT4MaGNxVTNMvk9ibuiZChD r X-Google-Smtp-Source: AGHT+IEKNzT7MZ4rDTxGGiXsJK7wd2sxKAEBDCZBcMxCYN7prH6PCeoNPa15iBXbH092aJEeovGm2g== X-Received: by 2002:a17:906:1159:b0:a3f:3d0d:30cc with SMTP id i25-20020a170906115900b00a3f3d0d30ccmr5855933eja.1.1708952103876; Mon, 26 Feb 2024 04:55:03 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 2/3] x86/entry: Simplify expressions in compat_restore_all_guest() Date: Mon, 26 Feb 2024 12:55:00 +0000 Message-Id: <20240226125501.1233599-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240226125501.1233599-1-andrew.cooper3@citrix.com> References: <20240226125501.1233599-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1708952124375100005 compat_restore_all_guest() already has SPEC_CTRL_EXIT_TO_PV with a document= ed requirement for %rsp to be both regs and cpuinfo. Use the now-normal annotations and simplify the expressions which happen to= be a subtraction of 0. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/x86_64/compat/entry.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compa= t/entry.S index 93fbbeb4ae18..727ab65290de 100644 --- a/xen/arch/x86/x86_64/compat/entry.S +++ b/xen/arch/x86/x86_64/compat/entry.S @@ -117,19 +117,19 @@ compat_process_trap: jmp compat_test_all_events END(compat_test_all_events) =20 -/* %rbx: struct vcpu, interrupts disabled */ +/* %rbx: struct vcpu, interrupts disabled, %rsp=3Dregs/cpuinfo */ FUNC(compat_restore_all_guest) ASSERT_INTERRUPTS_DISABLED mov $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), %r11d and UREGS_eflags(%rsp),%r11d =20 -.macro alt_cr4_pv32 +.macro alt_cr4_pv32 /* %rsp=3Dregs/cpuinfo */ testb $3,UREGS_cs(%rsp) jpe 2f - mov CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp), %rax + mov CPUINFO_cr4(%rsp), %rax and $~XEN_CR4_PV32_BITS, %rax 1: - mov %rax, CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp) + mov %rax, CPUINFO_cr4(%rsp) mov %rax, %cr4 /* * An NMI or MCE may have occurred between the previous two @@ -141,7 +141,7 @@ FUNC(compat_restore_all_guest) * loop to cause a live lock: If NMIs/MCEs occurred at that * high a rate, we'd be live locked anyway. */ - cmp %rax, CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp) + cmp %rax, CPUINFO_cr4(%rsp) jne 1b 2: .endm --=20 2.30.2 From nobody Mon May 13 13:51:30 2024 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1708952127; cv=none; d=zohomail.com; s=zohoarc; b=IMDeKDHd0WNqf5voN2uH7wkgD24vA1bNzcdy1aRYp9WUW4Qedd4CrgtMzW5bQ+r+rbp4uYKs4bWburPQ0h8KxGrUf3SJa/qSaCIR9pIQ6UYY1ViiFS5zbDIvFqvKsukEcUDotwyig/rcW0rm/wJ0ku8vUT3vn+4HZPr1UE4ObS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708952127; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iwdL6fju3yL7qCFHqrnxqIG6VGZd2rsCO2B5E1ELuco=; b=aaWO9g5mVlJo4q1CXQVSJJhn/fGyyndVnh58xOaWgCC3Og+Eg7gxVph4eMr8ZXQh3CCejw5K/LxtaXt9KZkUpfioYX4Tgu1HNqmbGd6bEOmcE8Y+DQd9QaBDesXfBp7GwB9PDtPqpEmZG/5VwJJJKqWLkc36YbgJVUThjUG0Jco= 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 1708952127621988.5030184681583; Mon, 26 Feb 2024 04:55:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.685527.1066394 (Exim 4.92) (envelope-from ) id 1reaVg-0005ae-5e; Mon, 26 Feb 2024 12:55:08 +0000 Received: by outflank-mailman (output) from mailman id 685527.1066394; Mon, 26 Feb 2024 12:55:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1reaVf-0005Z4-Vw; Mon, 26 Feb 2024 12:55:07 +0000 Received: by outflank-mailman (input) for mailman id 685527; Mon, 26 Feb 2024 12:55:07 +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 1reaVf-0004hn-2l for xen-devel@lists.xenproject.org; Mon, 26 Feb 2024 12:55:07 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 430a8b83-d4a6-11ee-98f5-efadbce2ee36; Mon, 26 Feb 2024 13:55:05 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a2f22bfb4e6so399551066b.0 for ; Mon, 26 Feb 2024 04:55:05 -0800 (PST) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id ll9-20020a170907190900b00a42e4b5ab00sm2379645ejc.41.2024.02.26.04.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:55:04 -0800 (PST) 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: 430a8b83-d4a6-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1708952104; x=1709556904; 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=iwdL6fju3yL7qCFHqrnxqIG6VGZd2rsCO2B5E1ELuco=; b=FPXCLop5y5Fmug6EbeIqryKW/Hwk+uVDYAeSGE2Z5XAEsg6ni+Jdq3zMAHUv2UXqDf 5g7rJ+j8PvxD+io7l2r32Y6bG0Q+GD0sks2HXvEbPaWK8ccT0yTnuEw4S3XoOnYocv0n FiKSZxDDtPMBL38gR3P+ebg5TBygJ4R80yVFg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708952104; x=1709556904; 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=iwdL6fju3yL7qCFHqrnxqIG6VGZd2rsCO2B5E1ELuco=; b=OuEzg6hUpp8eDrSfnltJcr6oy5cq3GDWCgIO5dn+Kfw8KCFjIMAnOK6AGzgC6/hmDH DXvmhuzt62Js1lvwTIsoXiP0zPYKdAL8Sxt6qfHcHMzl5xt7Z5b905hpOYJ9PKqQEJcH 29DDOx1UtU7WndN1Q12YoaEhiwuSl7OK0TAcisy82S77iKUvn+0KYu2MPDY/q/hU52mp a1dYLFdKrZnKBWqAefxdtW5sBqhluNX8m0phkr1OF+P2Iobh4uRuzGbfjH0jJ/kp0n5i 7KNiP0+XlOO74JDqijV3NnKTrMC2R7Coget9XqEBT537C0nurPA9T0NHGJe/kiySMO+D lsjQ== X-Gm-Message-State: AOJu0Ywohu4KyGCYDFFkiLYCj3Ce6E87uYPkJbj/0nnNewhKaHQUtFs6 21dSPKTETW1MkG96a49MN6/gwjJnt1iT56TuWkUUMk9tcvzWmhLaFYtN4WYyEJE1DLzhcMNmBG3 S X-Google-Smtp-Source: AGHT+IEiO4/3u92iuWSWX1XLK6tyUrg8vJ3vqcOHRIZXVtosNyOvF+7YKfdvK7IrnDxa4yULQuLlIg== X-Received: by 2002:a17:906:57d3:b0:a43:239c:3d0d with SMTP id u19-20020a17090657d300b00a43239c3d0dmr2556694ejr.37.1708952104635; Mon, 26 Feb 2024 04:55:04 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 3/3] x86/entry: Introduce EFRAME_* constants Date: Mon, 26 Feb 2024 12:55:01 +0000 Message-Id: <20240226125501.1233599-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240226125501.1233599-1-andrew.cooper3@citrix.com> References: <20240226125501.1233599-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1708952128418100001 restore_all_guest() does a lot of manipulation of the stack after popping t= he GPRs, and uses raw %rsp displacements to do so. Also, almost all entrypaths use raw %rsp displacements prior to pushing GPRs. Provide better mnemonics, to aid readability and reduce the chance of errors when editing. No functional change. The resulting binary is identical. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/x86_64/asm-offsets.c | 17 ++++++++ xen/arch/x86/x86_64/compat/entry.S | 2 +- xen/arch/x86/x86_64/entry.S | 68 +++++++++++++++--------------- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/xen/arch/x86/x86_64/asm-offsets.c b/xen/arch/x86/x86_64/asm-of= fsets.c index fee0edc61abb..4cc23cd032c1 100644 --- a/xen/arch/x86/x86_64/asm-offsets.c +++ b/xen/arch/x86/x86_64/asm-offsets.c @@ -51,6 +51,23 @@ void __dummy__(void) OFFSET(UREGS_kernel_sizeof, struct cpu_user_regs, es); BLANK(); =20 + /* + * EFRAME_* is for the entry/exit logic where %rsp is pointing at + * UREGS_error_code and GPRs are still guest values. + */ +#define OFFSET_EF(sym, mem) \ + DEFINE(sym, offsetof(struct cpu_user_regs, mem) - \ + offsetof(struct cpu_user_regs, error_code)) + + OFFSET_EF(EFRAME_entry_vector, entry_vector); + OFFSET_EF(EFRAME_rip, rip); + OFFSET_EF(EFRAME_cs, cs); + OFFSET_EF(EFRAME_eflags, eflags); + OFFSET_EF(EFRAME_rsp, rsp); + BLANK(); + +#undef OFFSET_EF + OFFSET(VCPU_processor, struct vcpu, processor); OFFSET(VCPU_domain, struct vcpu, domain); OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info_area.map); diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compa= t/entry.S index 727ab65290de..2f8fe5ebfbe4 100644 --- a/xen/arch/x86/x86_64/compat/entry.S +++ b/xen/arch/x86/x86_64/compat/entry.S @@ -15,7 +15,7 @@ FUNC(entry_int82) ENDBR64 ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 - movb $HYPERCALL_VECTOR, 4(%rsp) + movb $HYPERCALL_VECTOR, EFRAME_entry_vector(%rsp) SAVE_ALL compat=3D1 /* DPL1 gate, restricted to 32bit PV guests on= ly. */ =20 SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=3Dregs/cpuinfo, %rdx=3D0, Clo= b: acd */ diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index f8938b0b42fd..1b846f3aaff0 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -188,15 +188,15 @@ FUNC_LOCAL(restore_all_guest) =20 RESTORE_ALL BUILD_BUG_ON(TRAP_syscall & 0xff) - testb $TRAP_syscall >> 8, 4+1(%rsp) + testb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) jz iret_exit_to_guest =20 - movq 24(%rsp),%r11 # RFLAGS + mov EFRAME_eflags(%rsp), %r11 andq $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), %r11 orq $X86_EFLAGS_IF,%r11 =20 /* Don't use SYSRET path if the return address is not canonical. */ - movq 8(%rsp),%rcx + mov EFRAME_rip(%rsp), %rcx sarq $47,%rcx incl %ecx cmpl $1,%ecx @@ -211,19 +211,19 @@ FUNC_LOCAL(restore_all_guest) ALTERNATIVE "", rag_clrssbsy, X86_FEATURE_XEN_SHSTK #endif =20 - movq 8(%rsp), %rcx # RIP - cmpw $FLAT_USER_CS32,16(%rsp)# CS - movq 32(%rsp),%rsp # RSP + mov EFRAME_rip(%rsp), %rcx + cmpw $FLAT_USER_CS32, EFRAME_cs(%rsp) + mov EFRAME_rsp(%rsp), %rsp je 1f sysretq 1: sysretl =20 LABEL_LOCAL(.Lrestore_rcx_iret_exit_to_guest) - movq 8(%rsp), %rcx # RIP + mov EFRAME_rip(%rsp), %rcx /* No special register assumptions. */ iret_exit_to_guest: - andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), 24(%rsp) - orl $X86_EFLAGS_IF,24(%rsp) + andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), EFRAME_eflags(%rsp) + orl $X86_EFLAGS_IF, EFRAME_eflags(%rsp) addq $8,%rsp .Lft0: iretq _ASM_PRE_EXTABLE(.Lft0, handle_exception) @@ -256,7 +256,7 @@ FUNC(lstar_enter) pushq %rcx pushq $0 BUILD_BUG_ON(TRAP_syscall & 0xff) - movb $TRAP_syscall >> 8, 4+1(%rsp) + movb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) SAVE_ALL =20 SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=3Dregs/cpuinfo, %rdx=3D0, Clo= b: acd */ @@ -295,7 +295,7 @@ FUNC(cstar_enter) pushq %rcx pushq $0 BUILD_BUG_ON(TRAP_syscall & 0xff) - movb $TRAP_syscall >> 8, 4+1(%rsp) + movb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) SAVE_ALL =20 SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=3Dregs/cpuinfo, %rdx=3D0, Clo= b: acd */ @@ -338,7 +338,7 @@ LABEL(sysenter_eflags_saved, 0) pushq $0 /* null rip */ pushq $0 BUILD_BUG_ON(TRAP_syscall & 0xff) - movb $TRAP_syscall >> 8, 4+1(%rsp) + movb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) SAVE_ALL =20 SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=3Dregs/cpuinfo, %rdx=3D0, Clo= b: acd */ @@ -393,7 +393,7 @@ FUNC(entry_int80) ENDBR64 ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 - movb $0x80, 4(%rsp) + movb $0x80, EFRAME_entry_vector(%rsp) SAVE_ALL =20 SPEC_CTRL_ENTRY_FROM_PV /* Req: %rsp=3Dregs/cpuinfo, %rdx=3D0, Clo= b: acd */ @@ -658,7 +658,7 @@ END(ret_from_intr) .section .init.text, "ax", @progbits FUNC(early_page_fault) ENDBR64 - movb $X86_EXC_PF, 4(%rsp) + movb $X86_EXC_PF, EFRAME_entry_vector(%rsp) SAVE_ALL movq %rsp, %rdi call do_early_page_fault @@ -727,7 +727,7 @@ END(common_interrupt) =20 FUNC(entry_PF) ENDBR64 - movb $X86_EXC_PF, 4(%rsp) + movb $X86_EXC_PF, EFRAME_entry_vector(%rsp) END(entry_PF) /* No special register assumptions. */ FUNC(handle_exception, 0) @@ -911,98 +911,98 @@ END(entry_DE) FUNC(entry_MF) ENDBR64 pushq $0 - movb $X86_EXC_MF, 4(%rsp) + movb $X86_EXC_MF, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_MF) =20 FUNC(entry_XM) ENDBR64 pushq $0 - movb $X86_EXC_XM, 4(%rsp) + movb $X86_EXC_XM, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_XM) =20 FUNC(entry_NM) ENDBR64 pushq $0 - movb $X86_EXC_NM, 4(%rsp) + movb $X86_EXC_NM, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_NM) =20 FUNC(entry_DB) ENDBR64 pushq $0 - movb $X86_EXC_DB, 4(%rsp) + movb $X86_EXC_DB, EFRAME_entry_vector(%rsp) jmp handle_ist_exception END(entry_DB) =20 FUNC(entry_BP) ENDBR64 pushq $0 - movb $X86_EXC_BP, 4(%rsp) + movb $X86_EXC_BP, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_BP) =20 FUNC(entry_OF) ENDBR64 pushq $0 - movb $X86_EXC_OF, 4(%rsp) + movb $X86_EXC_OF, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_OF) =20 FUNC(entry_BR) ENDBR64 pushq $0 - movb $X86_EXC_BR, 4(%rsp) + movb $X86_EXC_BR, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_BR) =20 FUNC(entry_UD) ENDBR64 pushq $0 - movb $X86_EXC_UD, 4(%rsp) + movb $X86_EXC_UD, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_UD) =20 FUNC(entry_TS) ENDBR64 - movb $X86_EXC_TS, 4(%rsp) + movb $X86_EXC_TS, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_TS) =20 FUNC(entry_NP) ENDBR64 - movb $X86_EXC_NP, 4(%rsp) + movb $X86_EXC_NP, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_NP) =20 FUNC(entry_SS) ENDBR64 - movb $X86_EXC_SS, 4(%rsp) + movb $X86_EXC_SS, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_SS) =20 FUNC(entry_GP) ENDBR64 - movb $X86_EXC_GP, 4(%rsp) + movb $X86_EXC_GP, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_GP) =20 FUNC(entry_AC) ENDBR64 - movb $X86_EXC_AC, 4(%rsp) + movb $X86_EXC_AC, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_AC) =20 FUNC(entry_CP) ENDBR64 - movb $X86_EXC_CP, 4(%rsp) + movb $X86_EXC_CP, EFRAME_entry_vector(%rsp) jmp handle_exception END(entry_CP) =20 FUNC(entry_DF) ENDBR64 - movb $X86_EXC_DF, 4(%rsp) + movb $X86_EXC_DF, EFRAME_entry_vector(%rsp) /* Set AC to reduce chance of further SMAP faults */ ALTERNATIVE "", stac, X86_FEATURE_XEN_SMAP SAVE_ALL @@ -1028,7 +1028,7 @@ END(entry_DF) FUNC(entry_NMI) ENDBR64 pushq $0 - movb $X86_EXC_NMI, 4(%rsp) + movb $X86_EXC_NMI, EFRAME_entry_vector(%rsp) END(entry_NMI) =20 FUNC(handle_ist_exception) @@ -1164,7 +1164,7 @@ END(handle_ist_exception) FUNC(entry_MC) ENDBR64 pushq $0 - movb $X86_EXC_MC, 4(%rsp) + movb $X86_EXC_MC, EFRAME_entry_vector(%rsp) jmp handle_ist_exception END(entry_MC) =20 @@ -1203,7 +1203,7 @@ FUNC_LOCAL(autogen_stubs, 0) /* Automatically generat= ed stubs. */ 1: ENDBR64 pushq $0 - movb $vec,4(%rsp) + movb $vec, EFRAME_entry_vector(%rsp) jmp common_interrupt =20 entrypoint 1b @@ -1217,7 +1217,7 @@ FUNC_LOCAL(autogen_stubs, 0) /* Automatically generat= ed stubs. */ test $8,%spl /* 64bit exception frames are 16 byte aligned= , but the word */ jz 2f /* size is 8 bytes. Check whether the proces= sor gave us an */ pushq $0 /* error code, and insert an empty one if not= . */ -2: movb $vec,4(%rsp) +2: movb $vec, EFRAME_entry_vector(%rsp) jmp handle_exception =20 entrypoint 1b --=20 2.30.2