From: Steven Rostedt Subject: Re: [PATCH] kvm: log directly from the guest to the host kvm buffer Date: Tue, 17 May 2011 11:50:34 -0400 Message-ID: <1305647434.5456.738.camel@gandalf.stny.rr.com> References: <1305207413.18715.3.camel@gondor.retis> <4DCBF904.6040104@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: 7bit Cc: Avi Kivity , kvm@vger.kernel.org, joro@8bytes.org, agraf@suse.de, linux-kernel@vger.kernel.org, Fabio Checconi , Tommaso Cucinotta To: Dhaval Giani Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Thu, 2011-05-12 at 17:39 +0200, Dhaval Giani wrote: > >> > >> +int kvm_pv_ftrace(struct kvm_vcpu *vcpu, unsigned long ip, gpa_t addr) > >> +{ > >> + int ret; > >> + char *fmt = (char *) kzalloc(PAGE_SIZE, GFP_KERNEL); > >> + > >> + ret = kvm_read_guest(vcpu->kvm, addr, fmt, PAGE_SIZE); > >> + > >> + trace_printk("KVM instance %p: VCPU %d, IP %lu: %s", > >> + vcpu->kvm, vcpu->vcpu_id, ip, fmt); > >> + > >> + kfree(fmt); > >> + > >> + return 0; > >> +} > > > > A kmalloc and printf seem expensive here. I'd prefer to log the arguments > > and format descriptor instead. Similarly the guest should pass unformatted > > parameters.+int kvm_ftrace_printk(unsigned long ip, const char *fmt, ...) > >> > > the trace_printk is actually quite cheap (IIRC), but I guess Steve is > the best person to let us know about that. We can avoid the kzalloc > overhead though. You could replace the kzalloc with a static page. Perhaps, one page per CPU. Then you just need to disable interrupts (unless this is never called by an interrupt) to get the information into the page, without any allocation. trace_printk() does basically the same thing, but uses a single page with locks. I've thought about replacing that with per cpu pages too, but haven't gotten around to it. I also agree that you should just write to some buffer and when it overflows, flush it. -- Steve