From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH v2 2/7] x86/alt: Clean up struct alt_instr and its users
Date: Mon, 26 Feb 2018 11:34:59 +0000 [thread overview]
Message-ID: <1519644904-11349-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1519644904-11349-1-git-send-email-andrew.cooper3@citrix.com>
* Rename some fields for consistency and clarity, and use standard types.
* Don't opencode the use of ALT_{ORIG,REPL}_PTR().
No functional change.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
v2:
* Change more types to standard ones
---
xen/arch/x86/alternative.c | 24 ++++++++++++------------
xen/include/asm-x86/alternative.h | 14 +++++++-------
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c
index 5c8b6f6..51ca53e 100644
--- a/xen/arch/x86/alternative.c
+++ b/xen/arch/x86/alternative.c
@@ -163,8 +163,6 @@ void init_or_livepatch apply_alternatives(const struct alt_instr *start,
const struct alt_instr *end)
{
const struct alt_instr *a;
- u8 *instr, *replacement;
- u8 insnbuf[MAX_PATCH_LEN];
printk(KERN_INFO "alt table %p -> %p\n", start, end);
@@ -179,23 +177,25 @@ void init_or_livepatch apply_alternatives(const struct alt_instr *start,
*/
for ( a = start; a < end; a++ )
{
- instr = (u8 *)&a->instr_offset + a->instr_offset;
- replacement = (u8 *)&a->repl_offset + a->repl_offset;
- BUG_ON(a->replacementlen > a->instrlen);
- BUG_ON(a->instrlen > sizeof(insnbuf));
+ uint8_t *orig = ALT_ORIG_PTR(a);
+ uint8_t *repl = ALT_REPL_PTR(a);
+ uint8_t buf[MAX_PATCH_LEN];
+
+ BUG_ON(a->repl_len > a->orig_len);
+ BUG_ON(a->orig_len > sizeof(buf));
BUG_ON(a->cpuid >= NCAPINTS * 32);
+
if ( !boot_cpu_has(a->cpuid) )
continue;
- memcpy(insnbuf, replacement, a->replacementlen);
+ memcpy(buf, repl, a->repl_len);
/* 0xe8/0xe9 are relative branches; fix the offset. */
- if ( a->replacementlen >= 5 && (*insnbuf & 0xfe) == 0xe8 )
- *(s32 *)(insnbuf + 1) += replacement - instr;
+ if ( a->repl_len >= 5 && (*buf & 0xfe) == 0xe8 )
+ *(int32_t *)(buf + 1) += repl - orig;
- add_nops(insnbuf + a->replacementlen,
- a->instrlen - a->replacementlen);
- text_poke(instr, insnbuf, a->instrlen);
+ add_nops(buf + a->repl_len, a->orig_len - a->repl_len);
+ text_poke(orig, buf, a->orig_len);
}
}
diff --git a/xen/include/asm-x86/alternative.h b/xen/include/asm-x86/alternative.h
index 325a29f..d9706fd 100644
--- a/xen/include/asm-x86/alternative.h
+++ b/xen/include/asm-x86/alternative.h
@@ -9,15 +9,15 @@
#include <xen/types.h>
struct alt_instr {
- s32 instr_offset; /* original instruction */
- s32 repl_offset; /* offset to replacement instruction */
- u16 cpuid; /* cpuid bit set for replacement */
- u8 instrlen; /* length of original instruction */
- u8 replacementlen; /* length of new instruction, <= instrlen */
+ int32_t orig_offset; /* original instruction */
+ int32_t repl_offset; /* offset to replacement instruction */
+ uint16_t cpuid; /* cpuid bit set for replacement */
+ uint8_t orig_len; /* length of original instruction */
+ uint8_t repl_len; /* length of new instruction, <= instrlen */
};
-#define __ALT_PTR(a,f) ((u8 *)((void *)&(a)->f + (a)->f))
-#define ALT_ORIG_PTR(a) __ALT_PTR(a, instr_offset)
+#define __ALT_PTR(a,f) ((uint8_t *)((void *)&(a)->f + (a)->f))
+#define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset)
#define ALT_REPL_PTR(a) __ALT_PTR(a, repl_offset)
extern void add_nops(void *insns, unsigned int len);
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-02-26 11:34 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-26 11:34 [PATCH RESEND v2 0/7] x86/alternatives: Support for automatic padding calculations Andrew Cooper
2018-02-26 11:34 ` [PATCH v2 1/7] x86/alt: Drop unused alternative infrastructure Andrew Cooper
2018-02-26 11:34 ` Andrew Cooper [this message]
2018-02-26 11:35 ` [PATCH v2 3/7] x86/alt: Clean up the assembly used to generate alternatives Andrew Cooper
2018-02-26 14:09 ` Roger Pau Monné
2018-02-28 15:59 ` Jan Beulich
2018-03-01 12:44 ` Wei Liu
2018-02-26 11:35 ` [PATCH v2 4/7] x86/asm: Remove opencoded uses of altinstruction_entry Andrew Cooper
2018-02-26 11:35 ` [PATCH v2 5/7] x86/alt: Support for automatic padding calculations Andrew Cooper
2018-02-28 16:16 ` Jan Beulich
2018-02-28 17:26 ` Andrew Cooper
2018-03-01 7:26 ` Jan Beulich
2018-02-26 11:35 ` [PATCH v2 6/7] x86/alt: Drop explicit padding of origin sites Andrew Cooper
2018-02-26 11:35 ` [PATCH v2 7/7] x86/build: Use new .nop directive when available Andrew Cooper
2018-02-26 12:31 ` Roger Pau Monné
2018-02-26 13:08 ` Andrew Cooper
2018-02-26 14:27 ` Roger Pau Monné
2018-02-28 16:22 ` Jan Beulich
2018-02-28 17:45 ` Andrew Cooper
2018-03-01 7:28 ` Jan Beulich
2018-03-01 10:36 ` Roger Pau Monné
2018-03-01 10:54 ` Jan Beulich
2018-03-01 16:58 ` Andrew Cooper
2018-03-02 7:10 ` Jan Beulich
2018-03-02 19:34 ` Andrew Cooper
2018-03-05 8:33 ` Jan Beulich
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=1519644904-11349-3-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=xen-devel@lists.xen.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).