From: Bill Wendling <morbo@google.com>
To: kvm@vger.kernel.org, pbonzini@redhat.com, alexandru.elisei@arm.com
Cc: jmattson@google.com, Bill Wendling <morbo@google.com>
Subject: [kvm-unit-tests PATCH 1/2] x86: realmode: explicitly copy structure to avoid memcpy
Date: Sat, 12 Oct 2019 16:58:58 -0700 [thread overview]
Message-ID: <20191012235859.238387-2-morbo@google.com> (raw)
In-Reply-To: <20191012235859.238387-1-morbo@google.com>
Clang prefers to use a "mempcy" (or equivalent) to copy the "regs"
structure. This doesn't work in 16-bit mode, as it will end up copying
over half the number of bytes. GCC performs a field-by-field copy of the
structure, so force clang to do the same thing.
Signed-off-by: Bill Wendling <morbo@google.com>
---
x86/realmode.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/x86/realmode.c b/x86/realmode.c
index 303d093..cf45fd6 100644
--- a/x86/realmode.c
+++ b/x86/realmode.c
@@ -117,6 +117,19 @@ struct regs {
u32 eip, eflags;
};
+#define COPY_REG(name, dst, src) (dst).name = (src).name
+#define COPY_REGS(dst, src) \
+ COPY_REG(eax, dst, src); \
+ COPY_REG(ebx, dst, src); \
+ COPY_REG(ecx, dst, src); \
+ COPY_REG(edx, dst, src); \
+ COPY_REG(esi, dst, src); \
+ COPY_REG(edi, dst, src); \
+ COPY_REG(esp, dst, src); \
+ COPY_REG(ebp, dst, src); \
+ COPY_REG(eip, dst, src); \
+ COPY_REG(eflags, dst, src)
+
struct table_descr {
u16 limit;
void *base;
@@ -148,11 +161,11 @@ static void exec_in_big_real_mode(struct insn_desc *insn)
extern u8 test_insn[], test_insn_end[];
for (i = 0; i < insn->len; ++i)
- test_insn[i] = ((u8 *)(unsigned long)insn->ptr)[i];
+ test_insn[i] = ((u8 *)(unsigned long)insn->ptr)[i];
for (; i < test_insn_end - test_insn; ++i)
test_insn[i] = 0x90; // nop
- save = inregs;
+ COPY_REGS(save, inregs);
asm volatile(
"lgdtl %[gdt_descr] \n\t"
"mov %%cr0, %[tmp] \n\t"
@@ -196,7 +209,7 @@ static void exec_in_big_real_mode(struct insn_desc *insn)
: [gdt_descr]"m"(gdt_descr), [bigseg]"r"((short)16)
: "cc", "memory"
);
- outregs = save;
+ COPY_REGS(outregs, save);
}
#define R_AX 1
--
2.23.0.700.g56cf767bdb-goog
next prev parent reply other threads:[~2019-10-13 0:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-12 23:58 [kvm-unit-tests PATCH 0/2] realmode test fixes for clang Bill Wendling
2019-10-12 23:58 ` Bill Wendling [this message]
2019-10-16 19:07 ` [kvm-unit-tests PATCH 1/2] x86: realmode: explicitly copy structure to avoid memcpy Jim Mattson
2019-10-21 15:38 ` Paolo Bonzini
2019-10-12 23:58 ` [kvm-unit-tests PATCH 2/2] x86: realmode: use inline asm to get stack pointer Bill Wendling
2019-10-16 19:53 ` Jim Mattson
2019-10-16 21:52 ` Jim Mattson
2019-10-21 15:41 ` Paolo Bonzini
2019-10-17 1:25 ` [kvm-unit-tests v2 PATCH 0/2] realmode test fixes for clang Bill Wendling
2019-10-17 1:25 ` [kvm-unit-tests v2 PATCH 1/2] x86: realmode: explicitly copy regs structure Bill Wendling
2019-10-17 1:25 ` [kvm-unit-tests v2 PATCH 2/2] x86: realmode: fix esp in call test Bill Wendling
2019-10-17 23:27 ` Jim Mattson
2019-10-21 15:43 ` Paolo Bonzini
2019-10-21 16:43 ` Jim Mattson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191012235859.238387-2-morbo@google.com \
--to=morbo@google.com \
--cc=alexandru.elisei@arm.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.