From patchwork Fri Feb 21 22:54:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13986436 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 AE703253B4A for ; Fri, 21 Feb 2025 22:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740178453; cv=none; b=DqmAxhJXdKuiRIENCGi8DVZpQUC1mHCofgAzRpDwCXyaV05IiAQCSNkbavTli+aPkiF/gnN2h4idFoHFQalMfnON485J46InziXA9eBf8mCiWGC2RRKsOsvdOgplcbIXLD8Sxp2E4TkGNy9qaDb2yOQpyMQSzEoEw2NioJMYw7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740178453; c=relaxed/simple; bh=7c9YtpinxJ2An9V7LGd7mTdvQHnPOsyYvsvt8jLKWsM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q0ditNkLM/hcPLYg0YNWFdrP/KL6GKrcupNxfXLvAIy2jXXeNa/K5/KK/ObyVvClk7IDlQaZMeem8pBxLrzLVPyT1VkHrvzq3gyoEzht2GqO9VZwwzAkTQKyr4IkmXORcW86EU8ZbNzI9Q6hQk5H3iumxrUsjywfHB8BuPodM5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xJJXHez9; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xJJXHez9" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2f2a9f056a8so5735464a91.2 for ; Fri, 21 Feb 2025 14:54:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740178450; x=1740783250; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=o/FJi2X6SuwclR0PYWXyyYTo/Qtd0AY0J67XWAl+how=; b=xJJXHez97/t32r7xFcC1QnWeDAT094o0tAy2dfk3YstQDwn+WFrfbq8yU8tyctNJ2l UcM9fRrfpI7NQo8EBwFJF41dsqgYeRoRrDU+yVLQDz/qiNQNqd68F/nychzncbVDGqN0 WmDf/s+oFj9B1C8xTOlRYlLQBYjuWGK/yMB40GklQuTB1xc8Ygh0t6XPO3+YJMfYkn1t XdaV9dBzw+/jzFr0l+G67hafT3cNi1eT0P0nAqgHCCik8d/ejtB4DN9sOilHpaVgbZfg 4jqrXhhK8MpKIrJ9PED+8OFtUGvWNC6sDD+PyOHHNeFJ5SqU0/PatrxuQe3+H4ZTWVCI 8+kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740178450; x=1740783250; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o/FJi2X6SuwclR0PYWXyyYTo/Qtd0AY0J67XWAl+how=; b=HfChK37rJR7omNI/anvUOvBCGcKudrMP1qTpUJVlgSLmXMqZcAMmBnOkztMGdJWfle YR4bBm8poJQgOj2v+kh+ouJvnST0NE2Pm+5eiiDsGau+WwI7/mgAgF2PHF/VYyAxjPwV xDjRc+7okYiATPWkBxVMgz/wApakR6aEgLurhjRdAFhgHSMQv8jdmy1HE72gRmv7gwit DlfV5KMrkJFDtgYJrEjP9a5OhRgnCxwq2jBUqVZsb0oQQiTiCiMYUUXKdeZo8ubc5thO IcihuaWMVLk+pkd4V+OLCVYxjfT2y66TOjl1GcxTx87OX9Xo09o/G6oDeqJePqz16Lj9 mcow== X-Gm-Message-State: AOJu0YwO/tQZZ8izJQvqanqbZFeCPx/d+jHBJZM/oK3Pk0vAyiLE4pU5 NCjL3lTMRxnURnsYwuUIY8PWCrB8Iy+aZtTO9PrvCPxvzRUJH5x7t6gjNmrYRn6E+sowKWkpCd7 cOA== X-Google-Smtp-Source: AGHT+IELzXpdzD2DAnoll9k5nfB4rwHnK9En4kd5OfyY8fQeYvROvsP8fkKDoSQo7YODMq3F1X1lKskgHp0= X-Received: from pjbsc1.prod.google.com ([2002:a17:90b:5101:b0:2fc:2c9c:880]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e0d:b0:2f2:ab09:c256 with SMTP id 98e67ed59e1d1-2fce7b07205mr8916738a91.33.1740178449957; Fri, 21 Feb 2025 14:54:09 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 21 Feb 2025 14:54:04 -0800 In-Reply-To: <20250221225406.2228938-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250221225406.2228938-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250221225406.2228938-2-seanjc@google.com> Subject: [kvm-unit-tests PATCH 1/3] x86: Move descriptor table selector #defines to the top of desc.h From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Sean Christopherson , Hang SU Hoist the selector #defines in desc.h to the very top so that they can be exposed to assembly code with minimal #ifdefs. No functional change intended. Signed-off-by: Sean Christopherson --- lib/x86/desc.h | 114 ++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/x86/desc.h b/lib/x86/desc.h index 92c45a48..a4459127 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -1,7 +1,61 @@ #ifndef _X86_DESC_H_ #define _X86_DESC_H_ -#include +/* + * selector 32-bit 64-bit + * 0x00 NULL descriptor NULL descriptor + * 0x08 ring-0 code segment (32-bit) ring-0 code segment (64-bit) + * 0x10 ring-0 data segment (32-bit) ring-0 data segment (32/64-bit) + * 0x18 ring-0 code segment (P=0) ring-0 code segment (64-bit, P=0) + * 0x20 intr_alt_stack TSS ring-0 code segment (32-bit) + * 0x28 ring-0 code segment (16-bit) same + * 0x30 ring-0 data segment (16-bit) same + * 0x38 (0x3b) ring-3 code segment (32-bit) same + * 0x40 (0x43) ring-3 data segment (32-bit) ring-3 data segment (32/64-bit) + * 0x48 (0x4b) **unused** ring-3 code segment (64-bit) + * 0x50-0x78 free to use for test cases same + * 0x80-0x870 primary TSS (CPU 0..254) same + * 0x878-0x1068 percpu area (CPU 0..254) not used + * + * Note that the same segment can be used for 32-bit and 64-bit data segments + * (the L bit is only defined for code segments) + * + * Selectors 0x08-0x10 and 0x3b-0x4b are set up for use with the SYSCALL + * and SYSRET instructions. + */ + +#define KERNEL_CS 0x08 +#define KERNEL_DS 0x10 +#define NP_SEL 0x18 +#ifdef __x86_64__ +#define KERNEL_CS32 0x20 +#else +#define TSS_INTR 0x20 +#endif +#define KERNEL_CS16 0x28 +#define KERNEL_DS16 0x30 +#define USER_CS32 0x3b +#define USER_DS 0x43 +#ifdef __x86_64__ +#define USER_CS64 0x4b +#endif + +/* Synonyms */ +#define KERNEL_DS32 KERNEL_DS +#define USER_DS32 USER_DS + +#ifdef __x86_64__ +#define KERNEL_CS64 KERNEL_CS +#define USER_CS USER_CS64 +#define KERNEL_DS64 KERNEL_DS +#define USER_DS64 USER_DS +#else +#define KERNEL_CS32 KERNEL_CS +#define USER_CS USER_CS32 +#endif + +#define FIRST_SPARE_SEL 0x50 +#define TSS_MAIN 0x80 #ifdef __ASSEMBLY__ #define __ASM_FORM(x, ...) x,## __VA_ARGS__ @@ -15,6 +69,8 @@ #define __ASM_SEL(a,b) __ASM_FORM(b) #endif +#include + void setup_idt(void); void load_idt(void); void setup_alt_stack(void); @@ -120,62 +176,6 @@ fep_unavailable: return false; } -/* - * selector 32-bit 64-bit - * 0x00 NULL descriptor NULL descriptor - * 0x08 ring-0 code segment (32-bit) ring-0 code segment (64-bit) - * 0x10 ring-0 data segment (32-bit) ring-0 data segment (32/64-bit) - * 0x18 ring-0 code segment (P=0) ring-0 code segment (64-bit, P=0) - * 0x20 intr_alt_stack TSS ring-0 code segment (32-bit) - * 0x28 ring-0 code segment (16-bit) same - * 0x30 ring-0 data segment (16-bit) same - * 0x38 (0x3b) ring-3 code segment (32-bit) same - * 0x40 (0x43) ring-3 data segment (32-bit) ring-3 data segment (32/64-bit) - * 0x48 (0x4b) **unused** ring-3 code segment (64-bit) - * 0x50-0x78 free to use for test cases same - * 0x80-0x870 primary TSS (CPU 0..254) same - * 0x878-0x1068 percpu area (CPU 0..254) not used - * - * Note that the same segment can be used for 32-bit and 64-bit data segments - * (the L bit is only defined for code segments) - * - * Selectors 0x08-0x10 and 0x3b-0x4b are set up for use with the SYSCALL - * and SYSRET instructions. - */ - -#define KERNEL_CS 0x08 -#define KERNEL_DS 0x10 -#define NP_SEL 0x18 -#ifdef __x86_64__ -#define KERNEL_CS32 0x20 -#else -#define TSS_INTR 0x20 -#endif -#define KERNEL_CS16 0x28 -#define KERNEL_DS16 0x30 -#define USER_CS32 0x3b -#define USER_DS 0x43 -#ifdef __x86_64__ -#define USER_CS64 0x4b -#endif - -/* Synonyms */ -#define KERNEL_DS32 KERNEL_DS -#define USER_DS32 USER_DS - -#ifdef __x86_64__ -#define KERNEL_CS64 KERNEL_CS -#define USER_CS USER_CS64 -#define KERNEL_DS64 KERNEL_DS -#define USER_DS64 USER_DS -#else -#define KERNEL_CS32 KERNEL_CS -#define USER_CS USER_CS32 -#endif - -#define FIRST_SPARE_SEL 0x50 -#define TSS_MAIN 0x80 - typedef struct { unsigned short offset0; unsigned short selector; From patchwork Fri Feb 21 22:54:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13986437 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 1D3941EE028 for ; Fri, 21 Feb 2025 22:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740178453; cv=none; b=Bo6gQoEM5YyhSFBHe4ptDLJheer/xpjAP/NPJAKnuxWDqIr/sF6PxQ7n4fnx2ad+ONJsZrW3zJoxrSDkecXJWPF3tp5KeTiUnF/b5t+m+xwekssDT8+I7zPu3nxdT14aKuG4n1QzcMKm6KAOu4MzO2M6RHwT1i9R1h+EcnKIbj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740178453; c=relaxed/simple; bh=XRJeD15eAGh1DESpX1klhz612zOX4pybPqpYRmqGFeQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OKQt0YkPhOaR8hupdgvwU6xl2SUX8dMtUgHEmH2xVj28+RK9Y2+Q4Xrktas8I4aMMv+g1BQvrdyqj4Y3XQjRr8HqinGXMAWbGaE1O7dC6VkgUa7QXT30p6YjACiyKvjkG9cfn1/WBScJKQUbdqGYTgdpzmLeXxoI4u2ZMzgMA5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G190UbDv; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G190UbDv" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fc1a4c150bso5189541a91.2 for ; Fri, 21 Feb 2025 14:54:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740178451; x=1740783251; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=5h9ZTmUqiov5wTgWDI4PVWFLdLcBQuwZ6VSghRLfDi4=; b=G190UbDvlY/2a0isj1ovNKM9+UahrxiQh7wcRfRlvhnUZRyPXoaFXSoD9kYJQwV5va l8F5hPQZYKyzpXFwwY8k0kxWjToh3/H+LslDvejNZWYG5XHI4JM0h3meiUCcAZeaxBDa va/07qprzmfHCsL/URop/GytmIMiAsY1KFgKpWTBJr73qGBAcmFoGG7fDJAiLEehVitR ZlVMbI5eaLgbxB5Z4sQkjucX/+tyxooIpS8pCeg2sk+XMhu5b93ANL3FZiqC38vRkC+E mAJ/NL3Lpz8OkIae73K8imv2bGUaD+dvzug5Efcw8QExlVczHG7Kh18jiRojXJrrpBzL TDWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740178451; x=1740783251; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5h9ZTmUqiov5wTgWDI4PVWFLdLcBQuwZ6VSghRLfDi4=; b=ZnYTO4cha52GISIvfJBblgkhNT6G5WoO/Q1/d219FSlw5tfrJmcTKKtka4y+WXfoCN SqECwpPZLkX+yiGMjgpkLt5AiyGPMRJBK8ci5wXYvIrmTJNBtuzAe+YV8QZiMxAYRu2J xJU2uiHV7WWqmaZQi0kYQZRcvkf6U6dJuUzmzMxybbaGs2UYvRqOhEGIYg0hq3tvrTjy WkLT0J1gAykm2H1AXzWAuB2FW5Xv5w4TXgM+jbgZM7DMJoa+NrvGTXYQZtIShbQ+UK7w 1Ff8G51TuaGkqTW7JBja5PTLHdNEyr+sm0R54G6aHs8Wc/t20YaABAZkl9NNmJeBBktp 72NQ== X-Gm-Message-State: AOJu0Yx3zizQ4vhcYh04rQP1tCvrefjn2DDWbGQDkD/qNEI46lUov8cZ OL4ZL/JJrkx3fBtuJb1DPBZMCf7jsboxi7QSA5AVz2XlLDLeyfxTS6dWxH3FCt2EClIdo3Fcwav Gjg== X-Google-Smtp-Source: AGHT+IE4IBvF7Njf6iDDIMzxRYPAmYbHhm923zKO2PV17QJQ5MPw8E0w0ChaWmeLPOKUYFd7AD63QNBdHJE= X-Received: from pjh7.prod.google.com ([2002:a17:90b:3f87:b0:2fc:201d:6026]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1c08:b0:2ee:a127:ba96 with SMTP id 98e67ed59e1d1-2fce7b04ff7mr6938233a91.23.1740178451434; Fri, 21 Feb 2025 14:54:11 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 21 Feb 2025 14:54:05 -0800 In-Reply-To: <20250221225406.2228938-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250221225406.2228938-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250221225406.2228938-3-seanjc@google.com> Subject: [kvm-unit-tests PATCH 2/3] x86: Commit to using __ASSEMBLER__ instead of __ASSEMBLY__ From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Sean Christopherson , Hang SU Convert all two of x86's anti-assembly #ifdefs from __ASSEMBLY__ to __ASSEMBLER__. Usage of __ASSEMBLY__ was inherited blindly from the Linux kernel, and must be manually defined, e.g. through build rules or with explicit #defines in assembly code. __ASSEMBLER__ on the other hand is automatically defined by the compiler when preprocessing assembly, i.e. doesn't require manually #defines for the code to function correctly. Convert only x86 for the time being, as x86 doesn't actually rely on __ASSEMBLY__ (a clever observer will note that it's never #defined on x86). E.g. trying to include x86's page.h doesn't work as is. All other architectures actually rely on __ASSEMBLY__, and will be dealt with separately. Note, while only gcc appears to officially document __ASSEMBLER__, clang has followed suit since at least clang 6.0, and clang 6.0 doesn't come remotely close to being able to comple KVM-Unit-Tests. Link: https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros Signed-off-by: Sean Christopherson --- lib/x86/asm/page.h | 4 ++-- lib/x86/desc.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h index 298e7e8e..bc0e78c7 100644 --- a/lib/x86/asm/page.h +++ b/lib/x86/asm/page.h @@ -15,7 +15,7 @@ typedef unsigned long pgd_t; #include -#ifndef __ASSEMBLY__ +#ifndef __ASSEMBLER__ #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) @@ -79,5 +79,5 @@ extern unsigned long long get_amd_sev_addr_upperbound(void); #define PGDIR_BITS(lvl) (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT) #define PGDIR_OFFSET(va, lvl) (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK) -#endif /* !__ASSEMBLY__ */ +#endif /* !__ASSEMBLER__ */ #endif diff --git a/lib/x86/desc.h b/lib/x86/desc.h index a4459127..aa6213d1 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -57,7 +57,7 @@ #define FIRST_SPARE_SEL 0x50 #define TSS_MAIN 0x80 -#ifdef __ASSEMBLY__ +#ifdef __ASSEMBLER__ #define __ASM_FORM(x, ...) x,## __VA_ARGS__ #else #define __ASM_FORM(x, ...) " " xstr(x,##__VA_ARGS__) " " From patchwork Fri Feb 21 22:54:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13986438 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 A84BB254AE0 for ; Fri, 21 Feb 2025 22:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740178455; cv=none; b=FoRoPZ8A7CVPEmvauBCGy29fDZSPlZOpFaL4xtVrLSlpdyZRXk5q/2ecb/qmiFKErCe4HmEp5P9X4cpLvZpDCJDwGsPUzZNir3nwIdTb1auRb3BEFZq0Gq6eR2LIlWepNp/pppyVUlMQRYUsMvw2BowH4GfM/fJfNUy6t/gEcGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740178455; c=relaxed/simple; bh=zICg1q31qexijKRdIoRsJTp/MMS16c4Nm2MeZK2eGVM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nei8EidvjZh6u7UqQM9rWg0tSCKy1oVovmWnN9Jpo1Kmqar9bHreuT0Fn2COedacWOJ2OR3pI+eyHfGMg1r5qPNU98u7anfQyZAg2R1Pz27Lfo1SSyGuoPkr9IUKGKy3+GmWhHaccuclNFgyWNo/nB1DGK7P3eH2j5cpmuGDOY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=s6mZlJQU; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s6mZlJQU" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2fc4fc93262so5750467a91.1 for ; Fri, 21 Feb 2025 14:54:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740178453; x=1740783253; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=g9P0xwPdy6iFMXrJqHv4yRjV0aWb0ZuzTZ9aojlgcvw=; b=s6mZlJQUZTTLhl8yukvUC6rRxzT7iK6mKbv8x5ItV4bF3XjrYtzPOV4+uzPIhkuYIo Jg2BdMpbZc5W39TpOvxDU49ilOoyy4ba/Kreuyc6ymHM+GsFHL8VVh8mh9YmMIfRamGE JZVEyTyqcPGIZokac143BTrlepqu3WzMiAm5fqn3nT+99I9abP3Y5EEVmuNqwtXMg2p9 ClIJjoQEX2hh3GQnYYFL375a2b7BsucqWn0Yg0bYKDx4hSTN6iww92F3WkMWYiJan6vS ld5VrB4P89CYwZRWcMsi+vS3tKSQq32lB/5hU1Zw4F1pB0xfQF5oPm3MB4Jq2TcMbzVx 2ynw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740178453; x=1740783253; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g9P0xwPdy6iFMXrJqHv4yRjV0aWb0ZuzTZ9aojlgcvw=; b=t9YQMYMRt+XxEi0ig2IaCQ0QC+ImPSblsA2rB5KVZFiXt1e2may14EAgcpIKp1VUxP RQv0wMAZuXoJnelL18g98yQTuWxM0vPbfnHBPWKUdsMk12gqIk/6O10qxHvP/oNlfq38 TXdlIHCHk5PO6vEMcmb3BZ4nFjHfgf4k8hrqOiOT6u4fzDq8B5wtu2F1MwVXMdGYLN5/ JNLjQUal3R+ct2amHlO7HmydD291ctlAXkHsCEK47XMETkjejP9oyKUNqDDryg1Xal5M 4tJy8Rj+4SS18GPcv5vMek0roblLPU94qKbpIi0yzQw6bZv2Hwp2ZivE1XmaCx0wGApT 8rcQ== X-Gm-Message-State: AOJu0Yyzq8RXZk+qEDknpIJygxgZ2xxSZzyqpAzt+9chRWbHHwWd6RW3 xcYivLcu2Z26b3nAn6G4dO7b6Qf37AjsK6HmO3733vKpUQn5OlWov71D/dgkp51uF45seI8N5b1 law== X-Google-Smtp-Source: AGHT+IEASW1PZ9iosm1xJUBFUFI5wHyNRxTVoWB9CFeFDsXjfbwCfyQiju4QqiYGXy9XU5a0rYYuIX5W/aM= X-Received: from pfbkm49.prod.google.com ([2002:a05:6a00:3c71:b0:730:7c5b:2e2b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:17a2:b0:732:24ad:8e08 with SMTP id d2e1a72fcca58-73426c8555cmr7208224b3a.1.1740178452902; Fri, 21 Feb 2025 14:54:12 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 21 Feb 2025 14:54:06 -0800 In-Reply-To: <20250221225406.2228938-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250221225406.2228938-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250221225406.2228938-4-seanjc@google.com> Subject: [kvm-unit-tests PATCH 3/3] x86: replace segment selector magic number with macro definition From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Sean Christopherson , Hang SU From: Hang SU Add assembly check in desc.h, to replace segment selector magic number with macro definition. Signed-off-by: Hang SU Signed-off-by: Sean Christopherson --- lib/x86/desc.h | 7 ++++++- x86/cstart64.S | 8 ++++---- x86/trampolines.S | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/x86/desc.h b/lib/x86/desc.h index aa6213d1..5634de94 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -69,6 +69,8 @@ #define __ASM_SEL(a,b) __ASM_FORM(b) #endif +#ifndef __ASSEMBLER__ + #include void setup_idt(void); @@ -338,4 +340,7 @@ do { \ #define asm_safe_report_ex __asm_safe_report -#endif + +#endif /* __ASSEMBLER__ */ + +#endif /* _X86_DESC_H_ */ diff --git a/x86/cstart64.S b/x86/cstart64.S index 4dff1102..2b14c076 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -1,5 +1,5 @@ - #include "apic-defs.h" +#include "desc.h" ipi_vector = 0x20 @@ -66,7 +66,7 @@ start: mov $stacktop, %esp setup_percpu_area call prepare_64 - jmpl $8, $start64 + jmpl $KERNEL_CS, $start64 switch_to_5level: /* Disable CR4.PCIDE */ @@ -86,11 +86,11 @@ switch_to_5level: bts $12, %eax mov %eax, %cr4 - mov $0x10, %ax + mov $KERNEL_DS, %ax mov %ax, %ss call enter_long_mode - jmpl $8, $lvl5 + jmpl $KERNEL_CS, $lvl5 smp_stacktop: .long stacktop - 4096 diff --git a/x86/trampolines.S b/x86/trampolines.S index 6a3df9c1..f0b05ab5 100644 --- a/x86/trampolines.S +++ b/x86/trampolines.S @@ -3,6 +3,8 @@ * transition from 32-bit to 64-bit code (x86-64 only) */ +#include "desc.h" + /* EFI provides it's own SIPI sequence to handle relocation. */ #ifndef CONFIG_EFI .code16 @@ -15,7 +17,7 @@ sipi_entry: or $1, %eax mov %eax, %cr0 lgdtl ap_rm_gdt_descr - sipi_entry - ljmpl $8, $ap_start32 + ljmpl $KERNEL_CS32, $ap_start32 sipi_end: .globl ap_rm_gdt_descr @@ -66,7 +68,7 @@ MSR_GS_BASE = 0xc0000101 mov $MSR_GS_BASE, %ecx rdmsr - mov $0x10, %bx + mov $KERNEL_DS, %bx mov %bx, %ds mov %bx, %es mov %bx, %fs @@ -123,7 +125,7 @@ ap_start32: call prepare_64 load_absolute_addr $ap_start64, %edx - pushl $0x08 + pushl $KERNEL_CS pushl %edx lretl #endif