Skip to contentSkip to conversation

Load data from shared page (magic page) using 'kvmppc_ld'

DISCUSSION Dushyant Bansal 2 participants 4 messages Dec 20, 2011 – Dec 23, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

The Book3S KVM implementation contains one helper function 'kvmppc_ld' to load data from guest virtual addresses.

Usually, this works fine for me. But this doesn't work when I try to read data from the shared page (magic page).

/* Writing data on shared page */
u32 * p = (u32 *) (vcpu->arch.shared + 192); /* p becomes the host address corresponding to guest address of '0xfffff0c0' */ p[0] = 20;

/* Reading data on shared page */
u32 inst = 0;
ulong pc = 0xfffff0c0; /* Or, any other address on the shared page */ r = kvmppc_ld(vcpu, &pc, sizeof(u32), &inst, false);

'inst' still contains '0'. Also, value returned by this call is '0' which means 'kvmppc_ld' has not failed.

Am I missing something here? If you have any pointers, please let me know.

Regards,
Dushyant

#1 lore raw
Quoted 10 lines · Dushyant Bansal

Hi,

The Book3S KVM implementation contains one helper function 'kvmppc_ld' to load data from guest virtual addresses.

Usually, this works fine for me. But this doesn't work when I try to read data from the shared page (magic page).

/* Writing data on shared page */
u32 * p = (u32 *) (vcpu->arch.shared + 192); /* p becomes the host address corresponding to guest address of '0xfffff0c0' */ p[0] = 20;

Quoted 8 lines

/* Reading data on shared page */
u32 inst = 0;
ulong pc = 0xfffff0c0; /* Or, any other address on the shared page */ r = kvmppc_ld(vcpu, &pc, sizeof(u32), &inst, false);

'inst' still contains '0'. Also, value returned by this call is '0' which means 'kvmppc_ld' has not failed.

Am I missing something here? If you have any pointers, please let me know.

Uh. Looks like the kvmppc_ld code path doesn't take the magic page into consideration. Could you please verify if you can read the value from guest code? Also, why do you want to load it using kvmppc_ld on the host?

Alex

#2 lore raw
In reply to Dushyant Bansal
Quoted 17 lines · Alexander Graf
Quoted 15 lines · Dushyant Bansal

Hi,

The Book3S KVM implementation contains one helper function 'kvmppc_ld' to load data from guest virtual addresses.

Usually, this works fine for me. But this doesn't work when I try to read data from the shared page (magic page).

/* Writing data on shared page */
u32 * p = (u32 *) (vcpu->arch.shared + 192); /* p becomes the host address corresponding to guest address of '0xfffff0c0' */ p[0] = 20;

/* Reading data on shared page */
u32 inst = 0;
ulong pc = 0xfffff0c0; /* Or, any other address on the shared page */ r = kvmppc_ld(vcpu,&pc, sizeof(u32),&inst, false);

Quoted 4 lines
Quoted 3 lines

'inst' still contains '0'. Also, value returned by this call is '0' which means 'kvmppc_ld' has not failed.

Am I missing something here? If you have any pointers, please let me know.

Uh. Looks like the kvmppc_ld code path doesn't take the magic page into consideration. Could you please verify if you can read the value from guest code? Also, why do you want to load it using kvmppc_ld on the host?

Yes, I can read it from the guest.

Actually, I am storing a few instructions on the shared page which get executed from inside guest VM. Most of the times, this works fine. But quite a few times, I have noticed that if there is an exit on any of those instructions residing on the shared page then, it doesn't show the expected instruction in the exit trace.

kvm_book3s_exit: exit=0x400 | pc=0xfffff0c0 | inst=0x7fe000a6

Here, inst should be some other instruction. I haven't checked it thoroughly but it looks to me that 'inst' here is the instruction corresponding to an earlier VM exit.

So, I was trying to read the actual instruction for this pc after a VM exit using kvmppc_ld.

Regards,
Dushyant

#3 lore raw
In reply to Dushyant Bansal
Quoted 23 lines · Dushyant Bansal
Quoted 17 lines · Alexander Graf
Quoted 15 lines · Dushyant Bansal

Hi,

The Book3S KVM implementation contains one helper function 'kvmppc_ld' to load data from guest virtual addresses.

Usually, this works fine for me. But this doesn't work when I try to read data from the shared page (magic page).

/* Writing data on shared page */
u32 * p = (u32 *) (vcpu->arch.shared + 192); /* p becomes the host address corresponding to guest address of '0xfffff0c0' */ p[0] = 20;

/* Reading data on shared page */
u32 inst = 0;
ulong pc = 0xfffff0c0; /* Or, any other address on the shared page */ r = kvmppc_ld(vcpu,&pc, sizeof(u32),&inst, false);

Quoted 4 lines
Quoted 3 lines

'inst' still contains '0'. Also, value returned by this call is '0' which means 'kvmppc_ld' has not failed.

Am I missing something here? If you have any pointers, please let me know.

Uh. Looks like the kvmppc_ld code path doesn't take the magic page into consideration. Could you please verify if you can read the value from guest code? Also, why do you want to load it using kvmppc_ld on the host?

Quoted 8 lines

Yes, I can read it from the guest.

Actually, I am storing a few instructions on the shared page which get executed from inside guest VM. Most of the times, this works fine.
But quite a few times, I have noticed that if there is an exit on any of those instructions residing on the shared page then, it doesn't show the expected instruction in the exit trace.

kvm_book3s_exit: exit=0x400 | pc=0xfffff0c0 | inst=0x7fe000a6

Here, inst should be some other instruction. I haven't checked it thoroughly but it looks to me that 'inst' here is the instruction corresponding to an earlier VM exit.

Yes, that's expected. The exit code here is 0x400, pointing to an ISI exception. For ISIs, we need to map the guest's address space and are very sure we won't have to emulate the instruction, so we can just not load last_inst (which wouldn't work in the fast path anyway, because it's not mapped).

Quoted 1 line

So, I was trying to read the actual instruction for this pc after a VM exit using kvmppc_ld.

kvmppc_ld doesn't support the magic page as it is today. While I agree that it's unpretty, we only use it for very few use cases, most prominently loading last_inst if the fast path failed. Since we don't store instructions in the magic page, that hasn't emerged yet.

So you can either implement magic_page handling in kvmppc_ld (or its underlying functions) or just accept the fact that last_inst isn't correct in this case and move on :).

Alex