All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Sanjay Lal <sanjayl@kymasys.com>
Cc: kvm@vger.kernel.org, linux-mips@linux-mips.org
Subject: Re: [PATCH v2 07/18] KVM/MIPS32: MMU/TLB operations for the Guest.
Date: Fri, 15 Feb 2013 20:41:59 +0200	[thread overview]
Message-ID: <20130215184159.GA16755@redhat.com> (raw)
In-Reply-To: <69F3ED2A-A9B3-4046-9B40-98125ED5A8FB@kymasys.com>

On Fri, Feb 15, 2013 at 01:19:29PM -0500, Sanjay Lal wrote:
> 
> On Feb 6, 2013, at 7:08 AM, Gleb Natapov wrote:
> 
> >> 
> >> +static void kvm_mips_map_page(struct kvm *kvm, gfn_t gfn)
> >> +{
> >> +	pfn_t pfn;
> >> +
> >> +	if (kvm->arch.guest_pmap[gfn] != KVM_INVALID_PAGE)
> >> +		return;
> >> +
> >> +	pfn =kvm_mips_gfn_to_pfn(kvm, gfn);
> > This call should be in srcu read section since it access memory slots which
> > are srcu protected. You should test with RCU debug enabled.
> 
> kvm_mips_gfn_to_pfn just maps to gfn_to_pfn. I don't see an instance where gfn_to_pfn is in a scru read section?
> 
Where are you looking?  On x86 if vcpu is not in a guest mode it is in
srcu read section. The lock is taken immediately after exit and released
before entry. This is because x86 access memory slots a lot. Other
arches, that do not access memory slots as much, take the lock around
each individual access. As far as I see this is the only place in MIPS
kvm where this is needed.

> > 
> >> 
> >> +
> >> +uint32_t kvm_get_inst(uint32_t *opc, struct kvm_vcpu *vcpu)
> >> +{
> >> +	uint32_t inst;
> >> +	struct mips_coproc *cop0 __unused = vcpu->arch.cop0;
> >> +	int index;
> >> +	ulong paddr, flags;
> >> +
> >> +	if (KVM_GUEST_KSEGX((ulong) opc) < KVM_GUEST_KSEG0 ||
> >> +	    KVM_GUEST_KSEGX((ulong) opc) == KVM_GUEST_KSEG23) {
> >> +		local_irq_save(flags);
> >> +		index = kvm_mips_host_tlb_lookup(vcpu, (ulong) opc);
> >> +		if (index >= 0) {
> >> +			inst = *(opc);
> > Here and in some more places below you access __user memory. Shouldn't you
> > use get_user() to access it? What prevents the kernel crash by access fault here
> > if userspace remaps the memory to be non-readable? Hmm, may be it uses
> > guest translation here so it cannot happen, but still, sparse will not
> > be happy and kvm_mips_translate_guest_kseg0_to_hpa() case below uses
> > host translation anyway.
> > 
> Actually, I don't need the __user declaration in most cases, since KVM/MIPS handles mapping the page (if needed) and does not rely on the usual kernel mechanisms.
Yes I see that you check/populate tlb for non KVM_GUEST_KSEG0 access,
for kvm_mips_translate_guest_kseg0_to_hpa() you do not, but now I notice
that you are not using the address directly but uses CKSEG0ADDR() on it,
which, as far as I can tell, gives you kernel mapping for the page,
correct? Why this is better than using get_user()? To save tlb entries?

--
			Gleb.

  reply	other threads:[~2013-02-15 18:42 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-22  2:33 [PATCH v2 00/18] KVM for MIPS32 Processors Sanjay Lal
2012-11-22  2:33 ` [PATCH v2 01/18] KVM/MIPS32: Infrastructure/build files Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 02/18] KVM/MIPS32: Arch specific KVM data structures Sanjay Lal
2012-12-26 13:14   ` Gleb Natapov
2013-01-24 13:22     ` Ralf Baechle
2013-01-31 20:12   ` David Daney
2013-02-06 13:11   ` Gleb Natapov
2012-11-22  2:34 ` [PATCH v2 03/18] KVM/MIPS32: Entry point for trampolining to the guest and trap handlers Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 04/18] KVM/MIPS32: MIPS arch specific APIs for KVM Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 05/18] KVM/MIPS32: KVM Guest kernel support Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 06/18] KVM/MIPS32: Privileged instruction/target branch emulation Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 07/18] KVM/MIPS32: MMU/TLB operations for the Guest Sanjay Lal
2013-02-06 12:08   ` Gleb Natapov
2013-02-15 18:19     ` Sanjay Lal
2013-02-15 18:41       ` Gleb Natapov [this message]
2013-02-16 15:57         ` Sanjay Lal
2013-02-16 16:21           ` Gleb Natapov
2012-11-22  2:34 ` [PATCH v2 08/18] KVM/MIPS32: Release notes and KVM module Makefile Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 09/18] KVM/MIPS32: COP0 accesses profiling Sanjay Lal
2012-11-22 11:45   ` Sergei Shtylyov
2013-02-06 13:17   ` Gleb Natapov
2013-02-15 18:22     ` Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 10/18] KVM/MIPS32: Guest interrupt delivery Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 11/18] KVM/MIPS32: Routines to handle specific traps/exceptions while executing the guest Sanjay Lal
2013-02-06 13:20   ` Gleb Natapov
2013-02-15 16:10     ` Sanjay Lal
2013-02-18  9:44       ` Gleb Natapov
2013-02-19  2:31         ` Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 12/18] MIPS: Export routines needed by the KVM module Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 13/18] MIPS: If KVM is enabled then use the KVM specific routine to flush the TLBs on a ASID wrap Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 14/18] MIPS: ASM offsets for VCPU arch specific fields Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 15/18] MIPS: Pull in MIPS fix: fix endless loop when processing signals for kernel tasks Sanjay Lal
2013-01-24 13:07   ` Ralf Baechle
2012-11-22  2:34 ` [PATCH v2 16/18] MIPS: Export symbols used by KVM/MIPS module Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 17/18] KVM/MIPS32: Do not call vcpu_load when injecting interrupts Sanjay Lal
2012-11-22  2:34 ` [PATCH v2 18/18] KVM/MIPS32: Binary patching of select privileged instructions Sanjay Lal
2012-11-26 18:53 ` [PATCH v2 00/18] KVM for MIPS32 Processors David Daney
2012-11-27 19:35   ` Sanjay Lal
2013-01-24 15:05 ` Ralf Baechle
2013-01-24 15:59   ` Sanjay Lal

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=20130215184159.GA16755@redhat.com \
    --to=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=sanjayl@kymasys.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.