From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kt0oS-0008Ce-0u for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:05:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kt0oO-0008AP-86 for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:05:19 -0400 Received: from [199.232.76.173] (port=58679 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kt0oN-0008AF-TQ for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:05:15 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:57565) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kt0oN-0004Di-11 for qemu-devel@nongnu.org; Thu, 23 Oct 2008 10:05:15 -0400 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by e38.co.us.ibm.com (8.13.1/8.13.1) with ESMTP id m9NE4Ufk030504 for ; Thu, 23 Oct 2008 08:04:30 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id m9NE3nN4049872 for ; Thu, 23 Oct 2008 08:03:49 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m9NE3mOn023236 for ; Thu, 23 Oct 2008 08:03:48 -0600 Message-ID: <49008441.2030604@us.ibm.com> Date: Thu, 23 Oct 2008 09:03:45 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1224771556-11146-1-git-send-email-glommer@redhat.com> <1224771556-11146-11-git-send-email-glommer@redhat.com> In-Reply-To: <1224771556-11146-11-git-send-email-glommer@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: Glauber Costa Cc: jan.kiszka@siemens.com, jes@sgi.com, qemu-devel@nongnu.org, avi@qumranet.com, Glauber Costa , dmitry.baryshkov@siemens.com 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? > + 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