Skip to contentSkip to conversation

x86/pv: drop unnecessary prefixes

PATCH In review Wei Liu 3 participants 7 messages Aug 31, 2017

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover x86/pv: drop unnecessary prefixes

Wei Liu (2):
x86/pv: drop priv_op prefix in emul-priv-op.c
x86/pv: drop gate_op prefix in emul-gate-op.c

 xen/arch/x86/pv/emul-gate-op.c | 15 +++----
 xen/arch/x86/pv/emul-priv-op.c | 99 +++++++++++++++++++++---------------------
 2 files changed, 55 insertions(+), 59 deletions(-)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH 1/2 x86/pv: drop priv_op prefix in emul-priv-op.c

Drop the prefix because they live in their own file now. One exception is wbinvd handler because drpooing the prefix will clash with the actual wbinvd function.

---
 xen/arch/x86/pv/emul-priv-op.c | 99 +++++++++++++++++++++---------------------
 1 file changed, 50 insertions(+), 49 deletions(-)
xen/arch/x86/pv/emul-priv-op.c +50 -49
index 54a63c27f8..1f3e24b169 100644
@@ -316,8 +316,8 @@ static unsigned int check_guest_io_breakpoint(struct vcpu *v,
     return match;
 }
 
-static int priv_op_read_io(unsigned int port, unsigned int bytes,
-                           unsigned long *val, struct x86_emulate_ctxt *ctxt)
+static int read_io(unsigned int port, unsigned int bytes,
+                   unsigned long *val, struct x86_emulate_ctxt *ctxt)
 {
     struct priv_op_ctxt *poc = container_of(ctxt, struct priv_op_ctxt, ctxt);
     struct vcpu *curr = current;
@@ -415,8 +415,8 @@ void guest_io_write(unsigned int port, unsigned int bytes, uint32_t data,
     }
 }
 
-static int priv_op_write_io(unsigned int port, unsigned int bytes,
-                            unsigned long val, struct x86_emulate_ctxt *ctxt)
+static int write_io(unsigned int port, unsigned int bytes,
+                    unsigned long val, struct x86_emulate_ctxt *ctxt)
 {
     struct priv_op_ctxt *poc = container_of(ctxt, struct priv_op_ctxt, ctxt);
     struct vcpu *curr = current;
@@ -447,9 +447,9 @@ static int priv_op_write_io(unsigned int port, unsigned int bytes,
     return X86EMUL_OKAY;
 }
 
-static int priv_op_read_segment(enum x86_segment seg,
-                                struct segment_register *reg,
-                                struct x86_emulate_ctxt *ctxt)
+static int read_segment(enum x86_segment seg,
+                        struct segment_register *reg,
+                        struct x86_emulate_ctxt *ctxt)
 {
     /* Check if this is an attempt to access the I/O bitmap. */
     if ( seg == x86_seg_tr )
@@ -561,10 +561,10 @@ static int pv_emul_virt_to_linear(unsigned long base, unsigned long offset,
     return rc;
 }
 
-static int priv_op_rep_ins(uint16_t port,
-                           enum x86_segment seg, unsigned long offset,
-                           unsigned int bytes_per_rep, unsigned long *reps,
-                           struct x86_emulate_ctxt *ctxt)
+static int rep_ins(uint16_t port,
+                   enum x86_segment seg, unsigned long offset,
+                   unsigned int bytes_per_rep, unsigned long *reps,
+                   struct x86_emulate_ctxt *ctxt)
 {
     struct priv_op_ctxt *poc = container_of(ctxt, struct priv_op_ctxt, ctxt);
     struct vcpu *curr = current;
@@ -580,7 +580,7 @@ static int priv_op_rep_ins(uint16_t port,
     if ( !guest_io_okay(port, bytes_per_rep, curr, ctxt->regs) )
         return X86EMUL_UNHANDLEABLE;
 
-    rc = priv_op_read_segment(x86_seg_es, &sreg, ctxt);
+    rc = read_segment(x86_seg_es, &sreg, ctxt);
     if ( rc != X86EMUL_OKAY )
         return rc;
 
@@ -628,10 +628,10 @@ static int priv_op_rep_ins(uint16_t port,
     return X86EMUL_OKAY;
 }
 
-static int priv_op_rep_outs(enum x86_segment seg, unsigned long offset,
-                            uint16_t port,
-                            unsigned int bytes_per_rep, unsigned long *reps,
-                            struct x86_emulate_ctxt *ctxt)
+static int rep_outs(enum x86_segment seg, unsigned long offset,
+                    uint16_t port,
+                    unsigned int bytes_per_rep, unsigned long *reps,
+                    struct x86_emulate_ctxt *ctxt)
 {
     struct priv_op_ctxt *poc = container_of(ctxt, struct priv_op_ctxt, ctxt);
     struct vcpu *curr = current;
@@ -645,7 +645,7 @@ static int priv_op_rep_outs(enum x86_segment seg, unsigned long offset,
     if ( !guest_io_okay(port, bytes_per_rep, curr, ctxt->regs) )
         return X86EMUL_UNHANDLEABLE;
 
-    rc = priv_op_read_segment(seg, &sreg, ctxt);
+    rc = read_segment(seg, &sreg, ctxt);
     if ( rc != X86EMUL_OKAY )
         return rc;
 
@@ -696,8 +696,8 @@ static int priv_op_rep_outs(enum x86_segment seg, unsigned long offset,
     return X86EMUL_OKAY;
 }
 
-static int priv_op_read_cr(unsigned int reg, unsigned long *val,
-                           struct x86_emulate_ctxt *ctxt)
+static int read_cr(unsigned int reg, unsigned long *val,
+                   struct x86_emulate_ctxt *ctxt)
 {
     const struct vcpu *curr = current;
 
@@ -740,8 +740,8 @@ static int priv_op_read_cr(unsigned int reg, unsigned long *val,
     return X86EMUL_UNHANDLEABLE;
 }
 
-static int priv_op_write_cr(unsigned int reg, unsigned long val,
-                            struct x86_emulate_ctxt *ctxt)
+static int write_cr(unsigned int reg, unsigned long val,
+                    struct x86_emulate_ctxt *ctxt)
 {
     struct vcpu *curr = current;
 
@@ -797,8 +797,8 @@ static int priv_op_write_cr(unsigned int reg, unsigned long val,
     return X86EMUL_UNHANDLEABLE;
 }
 
-static int priv_op_read_dr(unsigned int reg, unsigned long *val,
-                           struct x86_emulate_ctxt *ctxt)
+static int read_dr(unsigned int reg, unsigned long *val,
+                   struct x86_emulate_ctxt *ctxt)
 {
     unsigned long res = do_get_debugreg(reg);
 
@@ -810,8 +810,8 @@ static int priv_op_read_dr(unsigned int reg, unsigned long *val,
     return X86EMUL_OKAY;
 }
 
-static int priv_op_write_dr(unsigned int reg, unsigned long val,
-                            struct x86_emulate_ctxt *ctxt)
+static int write_dr(unsigned int reg, unsigned long val,
+                    struct x86_emulate_ctxt *ctxt)
 {
     return do_set_debugreg(reg, val) == 0
            ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;
@@ -833,8 +833,8 @@ static inline bool is_cpufreq_controller(const struct domain *d)
             is_hardware_domain(d));
 }
 
-static int priv_op_read_msr(unsigned int reg, uint64_t *val,
-                            struct x86_emulate_ctxt *ctxt)
+static int read_msr(unsigned int reg, uint64_t *val,
+                    struct x86_emulate_ctxt *ctxt)
 {
     struct priv_op_ctxt *poc = container_of(ctxt, struct priv_op_ctxt, ctxt);
     const struct vcpu *curr = current;
@@ -997,8 +997,8 @@ static int priv_op_read_msr(unsigned int reg, uint64_t *val,
     return X86EMUL_UNHANDLEABLE;
 }
 
-static int priv_op_write_msr(unsigned int reg, uint64_t val,
-                             struct x86_emulate_ctxt *ctxt)
+static int write_msr(unsigned int reg, uint64_t val,
+                     struct x86_emulate_ctxt *ctxt)
 {
     struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
@@ -1205,6 +1205,7 @@ static int priv_op_write_msr(unsigned int reg, uint64_t val,
     return X86EMUL_UNHANDLEABLE;
 }
 
+/* Name it differently to avoid clashing with wbinvd() */
 static int priv_op_wbinvd(struct x86_emulate_ctxt *ctxt)
 {
     /* Ignore the instruction if unprivileged. */
@@ -1228,8 +1229,8 @@ int pv_emul_cpuid(uint32_t leaf, uint32_t subleaf,
     return X86EMUL_OKAY;
 }
 
-static int priv_op_validate(const struct x86_emulate_state *state,
-                            struct x86_emulate_ctxt *ctxt)
+static int validate(const struct x86_emulate_state *state,
+                    struct x86_emulate_ctxt *ctxt)
 {
     switch ( ctxt->opcode )
     {
@@ -1278,11 +1279,11 @@ static int priv_op_validate(const struct x86_emulate_state *state,
     return X86EMUL_UNHANDLEABLE;
 }
 
-static int priv_op_insn_fetch(enum x86_segment seg,
-                              unsigned long offset,
-                              void *p_data,
-                              unsigned int bytes,
-                              struct x86_emulate_ctxt *ctxt)
+static int insn_fetch(enum x86_segment seg,
+                      unsigned long offset,
+                      void *p_data,
+                      unsigned int bytes,
+                      struct x86_emulate_ctxt *ctxt)
 {
     const struct priv_op_ctxt *poc =
         container_of(ctxt, struct priv_op_ctxt, ctxt);
@@ -1316,20 +1317,20 @@ static int priv_op_insn_fetch(enum x86_segment seg,
 
 
 static const struct x86_emulate_ops priv_op_ops = {
-    .insn_fetch          = priv_op_insn_fetch,
+    .insn_fetch          = insn_fetch,
     .read                = x86emul_unhandleable_rw,
-    .validate            = priv_op_validate,
-    .read_io             = priv_op_read_io,
-    .write_io            = priv_op_write_io,
-    .rep_ins             = priv_op_rep_ins,
-    .rep_outs            = priv_op_rep_outs,
-    .read_segment        = priv_op_read_segment,
-    .read_cr             = priv_op_read_cr,
-    .write_cr            = priv_op_write_cr,
-    .read_dr             = priv_op_read_dr,
-    .write_dr            = priv_op_write_dr,
-    .read_msr            = priv_op_read_msr,
-    .write_msr           = priv_op_write_msr,
+    .validate            = validate,
+    .read_io             = read_io,
+    .write_io            = write_io,
+    .rep_ins             = rep_ins,
+    .rep_outs            = rep_outs,
+    .read_segment        = read_segment,
+    .read_cr             = read_cr,
+    .write_cr            = write_cr,
+    .read_dr             = read_dr,
+    .write_dr            = write_dr,
+    .read_msr            = read_msr,
+    .write_msr           = write_msr,
     .cpuid               = pv_emul_cpuid,
     .wbinvd              = priv_op_wbinvd,
 };
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] x86/pv: drop priv_op prefix in emul-priv-op.c

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 31.08.17 at 13:45, <[email protected]> wrote:

Drop the prefix because they live in their own file now. One exception is wbinvd handler because drpooing the prefix will clash with the actual wbinvd function.

How about _wbinvd() (single underscores as prefix are okay for static functions) or do_wbinvd()? With either of these ...

Quoted 1 line

... and thanks for doing this!

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#3 lore raw

PATCH 2/2 x86/pv: drop gate_op prefix in emul-gate-op.c

In reply to Wei Liu

There is only one function gate_op_read that needs to be modified.

---
 xen/arch/x86/pv/emul-gate-op.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
xen/arch/x86/pv/emul-gate-op.c +5 -10
index 0a7381a094..002fb782f2 100644
@@ -117,12 +117,8 @@ struct gate_op_ctxt {
     bool insn_fetch;
 };
 
-static int gate_op_read(
-    enum x86_segment seg,
-    unsigned long offset,
-    void *p_data,
-    unsigned int bytes,
-    struct x86_emulate_ctxt *ctxt)
+static int read(enum x86_segment seg, unsigned long offset, void *p_data,
+                unsigned int bytes, struct x86_emulate_ctxt *ctxt)
 {
     const struct gate_op_ctxt *goc =
         container_of(ctxt, struct gate_op_ctxt, ctxt);
@@ -230,7 +226,7 @@ void pv_emulate_gate_op(struct cpu_user_regs *regs)
 
     ctxt.ctxt.addr_size = ar & _SEGMENT_DB ? 32 : 16;
     /* Leave zero in ctxt.ctxt.sp_size, as it's not needed for decoding. */
-    state = x86_decode_insn(&ctxt.ctxt, gate_op_read);
+    state = x86_decode_insn(&ctxt.ctxt, read);
     ctxt.insn_fetch = false;
     if ( IS_ERR_OR_NULL(state) )
     {
@@ -265,9 +261,8 @@ void pv_emulate_gate_op(struct cpu_user_regs *regs)
         case 3:
             ++jump;
             base = x86_insn_operand_ea(state, &seg);
-            rc = gate_op_read(seg,
-                              base + (x86_insn_opsize(state) >> 3),
-                              &opnd_sel, sizeof(opnd_sel), &ctxt.ctxt);
+            rc = read(seg, base + (x86_insn_opsize(state) >> 3),
+                      &opnd_sel, sizeof(opnd_sel), &ctxt.ctxt);
             break;
         }
         break;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] x86/pv: drop gate_op prefix in emul-gate-op.c

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 31.08.17 at 13:45, <[email protected]> wrote:

There is only one function gate_op_read that needs to be modified.

I'm fine with it just being read() here, but I can see this being possibly controversial. Please double check that Andrew isn't entirely opposed to it. An alternative suggestion would then be read_mem().

Quoted 1 line

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH 2/2] x86/pv: drop gate_op prefix in emul-gate-op.c

Quoted 5 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 31.08.17 at 13:45, <[email protected]> wrote:

There is only one function gate_op_read that needs to be modified.

I'm fine with it just being read() here, but I can see this being possibly controversial. Please double check that Andrew isn't entirely opposed to it. An alternative suggestion would then be read_mem().

I'm not opposed generally, but simply 'read' has a chance of angering Coverity, because it has inbuilt models for most functions specified by core standards like POSIX.

read_mem() would be better.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#6 lore raw

Re: [PATCH 2/2] x86/pv: drop gate_op prefix in emul-gate-op.c

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 31.08.17 at 13:45, <[email protected]> wrote:

There is only one function gate_op_read that needs to be modified.

I'm fine with it just being read() here, but I can see this being possibly controversial. Please double check that Andrew isn't entirely opposed to it. An alternative suggestion would then be read_mem().

Quoted 6 lines

I'm not opposed generally, but simply 'read' has a chance of angering Coverity, because it has inbuilt models for most functions specified by core standards like POSIX.

read_mem() would be better.

read_mem it is.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel