From patchwork Tue Oct 9 04:17:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 190191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 02CDC2C00B1 for ; Tue, 9 Oct 2012 15:17:03 +1100 (EST) Received: from localhost ([::1]:39303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLRFb-00059R-38 for incoming@patchwork.ozlabs.org; Tue, 09 Oct 2012 00:16:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLRFO-00058b-L7 for qemu-devel@nongnu.org; Tue, 09 Oct 2012 00:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLRFN-0008Ti-9A for qemu-devel@nongnu.org; Tue, 09 Oct 2012 00:16:46 -0400 Received: from ozlabs.org ([203.10.76.45]:49498) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLRFM-0008TJ-Tp; Tue, 09 Oct 2012 00:16:45 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 50DC92C00B0; Tue, 9 Oct 2012 15:16:41 +1100 (EST) From: David Gibson To: agraf@suse.de Date: Tue, 9 Oct 2012 15:17:36 +1100 Message-Id: <1349756259-12975-2-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1349756259-12975-1-git-send-email-david@gibson.dropbear.id.au> References: <1349756259-12975-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH 1/4] pseries: Don't allow duplicate registration of hcalls or RTAS calls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently the pseries machine code allows a callback to be registered for a hypercall number twice, as long as it's the same callback the second time. We don't test for duplicate registrations of RTAS callbacks at all so it will effectively be last registratiojn wins. This was originally done because it was awkward to ensure that the registration happened exactly once, but the code has since been restructured so that's no longer the case. Duplicate registration of a hypercall or RTAS call could well suggest a duplicate initialization which could cause other problems, so this patch makes duplicate registrations a bug, to prevent the old behaviour from hiding other bugs. Signed-off-by: David Gibson --- hw/spapr_hcall.c | 3 +-- hw/spapr_rtas.c | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c index 194d9c2..762493a 100644 --- a/hw/spapr_hcall.c +++ b/hw/spapr_hcall.c @@ -670,11 +670,10 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn) } else { assert((opcode >= KVMPPC_HCALL_BASE) && (opcode <= KVMPPC_HCALL_MAX)); - slot = &kvmppc_hypercall_table[opcode - KVMPPC_HCALL_BASE]; } - assert(!(*slot) || (fn == *slot)); + assert(!(*slot)); *slot = fn; } diff --git a/hw/spapr_rtas.c b/hw/spapr_rtas.c index b808f80..b96078b 100644 --- a/hw/spapr_rtas.c +++ b/hw/spapr_rtas.c @@ -241,6 +241,15 @@ target_ulong spapr_rtas_call(sPAPREnvironment *spapr, void spapr_rtas_register(const char *name, spapr_rtas_fn fn) { + int i; + + for (i = 0; i < (rtas_next - rtas_table); i++) { + if (strcmp(name, rtas_table[i].name) == 0) { + fprintf(stderr, "RTAS call \"%s\" registered twice\n", name); + exit(1); + } + } + assert(rtas_next < (rtas_table + TOKEN_MAX)); rtas_next->name = name;