From: James Hogan <james.hogan@imgtec.com>
To: <jiang.biao2@zte.com.cn>
Cc: <linux-mips@linux-mips.org>, <pbonzini@redhat.com>,
<rkrcmar@redhat.com>, <ralf@linux-mips.org>,
<kvm@vger.kernel.org>
Subject: Re: [PATCH 2/13] KVM: MIPS: Pass type of fault down to kvm_mips_map_page()
Date: Wed, 18 Jan 2017 12:12:36 +0000 [thread overview]
Message-ID: <20170118121236.GA31545@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <201701181618464411994@zte.com.cn>
[-- Attachment #1: Type: text/plain, Size: 2511 bytes --]
Hi,
On Wed, Jan 18, 2017 at 04:18:46PM +0800, jiang.biao2@zte.com.cn wrote:
> Hi,
>
> > I presume you mean from the saved host cause register in the VCPU
> > context (since intervening exceptions/interrupts will clobber the actual
> > CP0 Cause register).
> >
> > It directly needs to know whether it can get away with a read-only
> > mapping, and although it directly depends on a GVA segment, it doesn't
> > necessarily relate to a memory access made by the guest.
> >
> > kvm_mips_map_page() is called via:
> >
> > - kvm_mips_handle_kseg0_tlb_fault()
> > for faults in guest KSeg0
> >
> > - kvm_mips_handle_mapped_seg_tlb_fault()
> > for faults in guest TLB mapped segments
> >
> > From these functions:
> >
> > - kvm_trap_emul_handle_tlb_mod() (write_fault = true)
> > in response to a write to a read-only page (exccode = MOD)
> >
> > - kvm_trap_emul_handle_tlb_miss() (write_fault = true or false)
> > in response to a read or write when TLB mapping absent or invalid
> > (exccode = TLBL/TLBS)
> >
> >
> > So there is a many:many mapping from exccode to write_fault for these
> > exccodes:
> >
> > - CPU (CoProcessor Unusable)
> > could be reading instruction or servicing a CACHE instruction
> > (write_fault = false) or replacing an instruction (write_fault =
> > true).
>
> > - MOD, TLBS, ADES
> > could be the write itself (write_fault = true), or a read of the
> > instruction triggering the exception or the prior branch instruction
> > (write_fault = false).
> >
> Thanks for the detail, it is more complicted than I thought.
>
> But there may be still bad smell from the long parameters, espacially from
>
>
> bool type ones.
Whats wrong with bool parameters?
It needs a GPA mapping created, either for a read or a write depending
on the caller. bool would seem ideally suited for just such a situation,
and in fact its exactly what the KVM GPA fault code path does to pass
whether the page needs to be writable:
kvm_mips_map_page() -> gfn_to_pfn_prot() -> __gfn_to_pfn_memslot() ->
hva_to_pfn() -> hva_to_pfn_slow().
so all this really does is extend that pattern up the other way as
necessary to be able to provide that information to gfn_to_pfn_prot().
Cheers
James
>
>
> Maybe there is better way to handle that, but I can not figure it out right now
>
>
> because of the complexity.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: James Hogan <james.hogan@imgtec.com>
To: jiang.biao2@zte.com.cn
Cc: linux-mips@linux-mips.org, pbonzini@redhat.com,
rkrcmar@redhat.com, ralf@linux-mips.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/13] KVM: MIPS: Pass type of fault down to kvm_mips_map_page()
Date: Wed, 18 Jan 2017 12:12:36 +0000 [thread overview]
Message-ID: <20170118121236.GA31545@jhogan-linux.le.imgtec.org> (raw)
Message-ID: <20170118121236.8_UpfVEFSmqSnkOrdLpn8UOJXCbd5qSa3dvA5_meZ-8@z> (raw)
In-Reply-To: <201701181618464411994@zte.com.cn>
[-- Attachment #1: Type: text/plain, Size: 2511 bytes --]
Hi,
On Wed, Jan 18, 2017 at 04:18:46PM +0800, jiang.biao2@zte.com.cn wrote:
> Hi,
>
> > I presume you mean from the saved host cause register in the VCPU
> > context (since intervening exceptions/interrupts will clobber the actual
> > CP0 Cause register).
> >
> > It directly needs to know whether it can get away with a read-only
> > mapping, and although it directly depends on a GVA segment, it doesn't
> > necessarily relate to a memory access made by the guest.
> >
> > kvm_mips_map_page() is called via:
> >
> > - kvm_mips_handle_kseg0_tlb_fault()
> > for faults in guest KSeg0
> >
> > - kvm_mips_handle_mapped_seg_tlb_fault()
> > for faults in guest TLB mapped segments
> >
> > From these functions:
> >
> > - kvm_trap_emul_handle_tlb_mod() (write_fault = true)
> > in response to a write to a read-only page (exccode = MOD)
> >
> > - kvm_trap_emul_handle_tlb_miss() (write_fault = true or false)
> > in response to a read or write when TLB mapping absent or invalid
> > (exccode = TLBL/TLBS)
> >
> >
> > So there is a many:many mapping from exccode to write_fault for these
> > exccodes:
> >
> > - CPU (CoProcessor Unusable)
> > could be reading instruction or servicing a CACHE instruction
> > (write_fault = false) or replacing an instruction (write_fault =
> > true).
>
> > - MOD, TLBS, ADES
> > could be the write itself (write_fault = true), or a read of the
> > instruction triggering the exception or the prior branch instruction
> > (write_fault = false).
> >
> Thanks for the detail, it is more complicted than I thought.
>
> But there may be still bad smell from the long parameters, espacially from
>
>
> bool type ones.
Whats wrong with bool parameters?
It needs a GPA mapping created, either for a read or a write depending
on the caller. bool would seem ideally suited for just such a situation,
and in fact its exactly what the KVM GPA fault code path does to pass
whether the page needs to be writable:
kvm_mips_map_page() -> gfn_to_pfn_prot() -> __gfn_to_pfn_memslot() ->
hva_to_pfn() -> hva_to_pfn_slow().
so all this really does is extend that pattern up the other way as
necessary to be able to provide that information to gfn_to_pfn_prot().
Cheers
James
>
>
> Maybe there is better way to handle that, but I can not figure it out right now
>
>
> because of the complexity.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next parent reply other threads:[~2017-01-18 12:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <201701181618464411994@zte.com.cn>
2017-01-18 12:12 ` James Hogan [this message]
2017-01-18 12:12 ` [PATCH 2/13] KVM: MIPS: Pass type of fault down to kvm_mips_map_page() James Hogan
[not found] <201701191629518310684@zte.com.cn>
2017-01-19 9:08 ` James Hogan
2017-01-19 9:08 ` James Hogan
[not found] <201701171906397244491@zte.com.cn>
2017-01-17 13:27 ` James Hogan
2017-01-17 13:27 ` James Hogan
2017-01-16 12:49 [PATCH 0/13] KVM: MIPS: Dirty logging, SYNC_MMU & READONLY_MEM James Hogan
2017-01-16 12:49 ` [PATCH 2/13] KVM: MIPS: Pass type of fault down to kvm_mips_map_page() James Hogan
2017-01-16 12:49 ` James Hogan
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=20170118121236.GA31545@jhogan-linux.le.imgtec.org \
--to=james.hogan@imgtec.com \
--cc=jiang.biao2@zte.com.cn \
--cc=kvm@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=pbonzini@redhat.com \
--cc=ralf@linux-mips.org \
--cc=rkrcmar@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox