Skip to content

Commit fc7ffc9

Browse files
bonziniZhengShunQian
authored andcommitted
KVM: x86: introduce linear_{read,write}_system
commit 79367a6 upstream. Wrap the common invocation of ctxt->ops->read_std and ctxt->ops->write_std, so as to have a smaller patch when the functions grow another argument. Fixes: 129a72a ("KVM: x86: Introduce segmented_write_std", 2017-01-12) Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 464b532 commit fc7ffc9

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

arch/x86/kvm/emulate.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,19 @@ static inline int jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)
790790
return assign_eip_near(ctxt, ctxt->_eip + rel);
791791
}
792792

793+
static int linear_read_system(struct x86_emulate_ctxt *ctxt, ulong linear,
794+
void *data, unsigned size)
795+
{
796+
return ctxt->ops->read_std(ctxt, linear, data, size, &ctxt->exception);
797+
}
798+
799+
static int linear_write_system(struct x86_emulate_ctxt *ctxt,
800+
ulong linear, void *data,
801+
unsigned int size)
802+
{
803+
return ctxt->ops->write_std(ctxt, linear, data, size, &ctxt->exception);
804+
}
805+
793806
static int segmented_read_std(struct x86_emulate_ctxt *ctxt,
794807
struct segmented_address addr,
795808
void *data,
@@ -1488,8 +1501,7 @@ static int read_interrupt_descriptor(struct x86_emulate_ctxt *ctxt,
14881501
return emulate_gp(ctxt, index << 3 | 0x2);
14891502

14901503
addr = dt.address + index * 8;
1491-
return ctxt->ops->read_std(ctxt, addr, desc, sizeof *desc,
1492-
&ctxt->exception);
1504+
return linear_read_system(ctxt, addr, desc, sizeof *desc);
14931505
}
14941506

14951507
static void get_descriptor_table_ptr(struct x86_emulate_ctxt *ctxt,
@@ -1552,8 +1564,7 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt,
15521564
if (rc != X86EMUL_CONTINUE)
15531565
return rc;
15541566

1555-
return ctxt->ops->read_std(ctxt, *desc_addr_p, desc, sizeof(*desc),
1556-
&ctxt->exception);
1567+
return linear_read_system(ctxt, *desc_addr_p, desc, sizeof(*desc));
15571568
}
15581569

15591570
/* allowed just for 8 bytes segments */
@@ -1567,8 +1578,7 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
15671578
if (rc != X86EMUL_CONTINUE)
15681579
return rc;
15691580

1570-
return ctxt->ops->write_std(ctxt, addr, desc, sizeof *desc,
1571-
&ctxt->exception);
1581+
return linear_write_system(ctxt, addr, desc, sizeof *desc);
15721582
}
15731583

15741584
static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
@@ -1729,8 +1739,7 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
17291739
return ret;
17301740
}
17311741
} else if (ctxt->mode == X86EMUL_MODE_PROT64) {
1732-
ret = ctxt->ops->read_std(ctxt, desc_addr+8, &base3,
1733-
sizeof(base3), &ctxt->exception);
1742+
ret = linear_read_system(ctxt, desc_addr+8, &base3, sizeof(base3));
17341743
if (ret != X86EMUL_CONTINUE)
17351744
return ret;
17361745
if (is_noncanonical_address(get_desc_base(&seg_desc) |
@@ -2043,11 +2052,11 @@ static int __emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq)
20432052
eip_addr = dt.address + (irq << 2);
20442053
cs_addr = dt.address + (irq << 2) + 2;
20452054

2046-
rc = ops->read_std(ctxt, cs_addr, &cs, 2, &ctxt->exception);
2055+
rc = linear_read_system(ctxt, cs_addr, &cs, 2);
20472056
if (rc != X86EMUL_CONTINUE)
20482057
return rc;
20492058

2050-
rc = ops->read_std(ctxt, eip_addr, &eip, 2, &ctxt->exception);
2059+
rc = linear_read_system(ctxt, eip_addr, &eip, 2);
20512060
if (rc != X86EMUL_CONTINUE)
20522061
return rc;
20532062

@@ -3025,35 +3034,30 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
30253034
u16 tss_selector, u16 old_tss_sel,
30263035
ulong old_tss_base, struct desc_struct *new_desc)
30273036
{
3028-
const struct x86_emulate_ops *ops = ctxt->ops;
30293037
struct tss_segment_16 tss_seg;
30303038
int ret;
30313039
u32 new_tss_base = get_desc_base(new_desc);
30323040

3033-
ret = ops->read_std(ctxt, old_tss_base, &tss_seg, sizeof tss_seg,
3034-
&ctxt->exception);
3041+
ret = linear_read_system(ctxt, old_tss_base, &tss_seg, sizeof tss_seg);
30353042
if (ret != X86EMUL_CONTINUE)
30363043
return ret;
30373044

30383045
save_state_to_tss16(ctxt, &tss_seg);
30393046

3040-
ret = ops->write_std(ctxt, old_tss_base, &tss_seg, sizeof tss_seg,
3041-
&ctxt->exception);
3047+
ret = linear_write_system(ctxt, old_tss_base, &tss_seg, sizeof tss_seg);
30423048
if (ret != X86EMUL_CONTINUE)
30433049
return ret;
30443050

3045-
ret = ops->read_std(ctxt, new_tss_base, &tss_seg, sizeof tss_seg,
3046-
&ctxt->exception);
3051+
ret = linear_read_system(ctxt, new_tss_base, &tss_seg, sizeof tss_seg);
30473052
if (ret != X86EMUL_CONTINUE)
30483053
return ret;
30493054

30503055
if (old_tss_sel != 0xffff) {
30513056
tss_seg.prev_task_link = old_tss_sel;
30523057

3053-
ret = ops->write_std(ctxt, new_tss_base,
3054-
&tss_seg.prev_task_link,
3055-
sizeof tss_seg.prev_task_link,
3056-
&ctxt->exception);
3058+
ret = linear_write_system(ctxt, new_tss_base,
3059+
&tss_seg.prev_task_link,
3060+
sizeof tss_seg.prev_task_link);
30573061
if (ret != X86EMUL_CONTINUE)
30583062
return ret;
30593063
}
@@ -3169,38 +3173,34 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
31693173
u16 tss_selector, u16 old_tss_sel,
31703174
ulong old_tss_base, struct desc_struct *new_desc)
31713175
{
3172-
const struct x86_emulate_ops *ops = ctxt->ops;
31733176
struct tss_segment_32 tss_seg;
31743177
int ret;
31753178
u32 new_tss_base = get_desc_base(new_desc);
31763179
u32 eip_offset = offsetof(struct tss_segment_32, eip);
31773180
u32 ldt_sel_offset = offsetof(struct tss_segment_32, ldt_selector);
31783181

3179-
ret = ops->read_std(ctxt, old_tss_base, &tss_seg, sizeof tss_seg,
3180-
&ctxt->exception);
3182+
ret = linear_read_system(ctxt, old_tss_base, &tss_seg, sizeof tss_seg);
31813183
if (ret != X86EMUL_CONTINUE)
31823184
return ret;
31833185

31843186
save_state_to_tss32(ctxt, &tss_seg);
31853187

31863188
/* Only GP registers and segment selectors are saved */
3187-
ret = ops->write_std(ctxt, old_tss_base + eip_offset, &tss_seg.eip,
3188-
ldt_sel_offset - eip_offset, &ctxt->exception);
3189+
ret = linear_write_system(ctxt, old_tss_base + eip_offset, &tss_seg.eip,
3190+
ldt_sel_offset - eip_offset);
31893191
if (ret != X86EMUL_CONTINUE)
31903192
return ret;
31913193

3192-
ret = ops->read_std(ctxt, new_tss_base, &tss_seg, sizeof tss_seg,
3193-
&ctxt->exception);
3194+
ret = linear_read_system(ctxt, new_tss_base, &tss_seg, sizeof tss_seg);
31943195
if (ret != X86EMUL_CONTINUE)
31953196
return ret;
31963197

31973198
if (old_tss_sel != 0xffff) {
31983199
tss_seg.prev_task_link = old_tss_sel;
31993200

3200-
ret = ops->write_std(ctxt, new_tss_base,
3201-
&tss_seg.prev_task_link,
3202-
sizeof tss_seg.prev_task_link,
3203-
&ctxt->exception);
3201+
ret = linear_write_system(ctxt, new_tss_base,
3202+
&tss_seg.prev_task_link,
3203+
sizeof tss_seg.prev_task_link);
32043204
if (ret != X86EMUL_CONTINUE)
32053205
return ret;
32063206
}

0 commit comments

Comments
 (0)