From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kt15O-00032b-K6 for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:22:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kt15N-00031W-0t for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:22:50 -0400 Received: from [199.232.76.173] (port=48550 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kt15M-00031R-RV for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:22:48 -0400 Received: from mx2.redhat.com ([66.187.237.31]:51208) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kt15M-0002Zc-JL for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:22:48 -0400 Date: Thu, 23 Oct 2008 12:24:09 -0200 From: Glauber Costa Message-ID: <20081023142409.GG18872@poweredge.glommer> References: <1224771556-11146-1-git-send-email-glommer@redhat.com> <1224771556-11146-11-git-send-email-glommer@redhat.com> <49008441.2030604@us.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49008441.2030604@us.ibm.com> Subject: [Qemu-devel] Re: [PATCH 10/32] turn info kqemu into generic info accelerator Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: jan.kiszka@siemens.com, jes@sgi.com, qemu-devel@nongnu.org, avi@qumranet.com, Glauber Costa , dmitry.baryshkov@siemens.com On Thu, Oct 23, 2008 at 09:03:45AM -0500, Anthony Liguori wrote: > Glauber Costa wrote: >> From: Glauber Costa >> >> Yet another accel field: info. >> From this point on, "info kqemu" is no more. "info accelerator" should >> be used instead. >> >> Signed-off-by: Glauber Costa >> --- >> accel.c | 6 ++++++ >> accel.h | 8 ++++++++ >> kqemu.c | 26 ++++++++++++++++++++++++++ >> monitor.c | 35 ++++++++++++----------------------- >> 4 files changed, 52 insertions(+), 23 deletions(-) >> >> diff --git a/accel.c b/accel.c >> index 6776244..cb615d7 100644 >> --- a/accel.c >> +++ b/accel.c >> @@ -8,6 +8,11 @@ int _accel_nop(void) >> return 0; >> } >> >> +int noaccel_info(CPUState *env, char *buf) >> +{ >> + return snprintf(buf, MAX_INFO_BUF, "no accelerator present.\n"); >> +} >> + >> #define accel_nop ((void *)_accel_nop) >> >> /* Accelerator wrapper for the no-accel (raw qemu) case */ >> @@ -16,5 +21,6 @@ QEMUAccel noaccel = { >> .init_env = accel_nop, >> .flush_cache = accel_nop, >> .flush_page = accel_nop, >> + .info = noaccel_info, >> }; >> >> diff --git a/accel.h b/accel.h >> index 935cfef..549ce01 100644 >> --- a/accel.h >> +++ b/accel.h >> @@ -1,11 +1,14 @@ >> #ifndef _ACCEL_H_ >> #define _ACCEL_H_ >> >> +#define MAX_INFO_BUF 1024 >> + >> typedef struct QEMUAccel { >> void (*cpu_interrupt)(CPUState *env); >> void (*init_env)(CPUState *env); >> void (*flush_cache)(CPUState *env, int global); >> void (*flush_page)(CPUState *env, target_ulong addr); >> + int (*info)(CPUState *env, char *buf); >> } QEMUAccel; >> >> extern QEMUAccel *current_accel; >> @@ -35,4 +38,9 @@ static inline void accel_flush_page(CPUState *env, target_ulong addr) >> { >> current_accel->flush_page(env, addr); >> } >> + >> +static inline int accel_info(CPUState *env, char *buf) >> +{ >> + return current_accel->info(env, buf); >> +} >> #endif >> diff --git a/kqemu.c b/kqemu.c >> index 3f2433a..424d8f4 100644 >> --- a/kqemu.c >> +++ b/kqemu.c >> @@ -1047,11 +1047,37 @@ static void qpi_init(void) >> 0x1000, qpi_io_memory); >> } >> >> +static int kqemu_info(CPUState *env, char *buf) >> +{ >> + int val, len; >> + int bufsiz = MAX_INFO_BUF; >> > > Why not just pass bufsiz as an argument to kqemu_info? ok, this makes sense. thanks. > >> + if (accel_info(env, buf)) >> + term_printf(buf); >> > > You should do term_printf("%s", buf); This is a common exploit if > there's ever a chance that buf has user-originated data. Therefore, > it's good practice to always use ("%s", buf) instead of passing buf > directly. > > Regards, > > Anthony Liguori