From patchwork Tue Sep 8 22:03:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 515615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A9732140325 for ; Wed, 9 Sep 2015 08:05:13 +1000 (AEST) Received: from localhost ([::1]:38177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZR0p-0003DE-S4 for incoming@patchwork.ozlabs.org; Tue, 08 Sep 2015 18:05:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZR01-00027Q-RP for qemu-devel@nongnu.org; Tue, 08 Sep 2015 18:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZQzx-0007cN-Og for qemu-devel@nongnu.org; Tue, 08 Sep 2015 18:04:21 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:33373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZQzx-0007c3-JN for qemu-devel@nongnu.org; Tue, 08 Sep 2015 18:04:17 -0400 Received: from /spool/local by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 8 Sep 2015 16:04:16 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 8 Sep 2015 16:04:10 -0600 X-Helo: d03dlp03.boulder.ibm.com X-MailFrom: mdroth@linux.vnet.ibm.com X-RcptTo: qemu-ppc@nongnu.org Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 9E91C19D803E; Tue, 8 Sep 2015 15:55:04 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t88M4A0q52494444; Tue, 8 Sep 2015 15:04:10 -0700 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t88M49m6001578; Tue, 8 Sep 2015 16:04:10 -0600 Received: from localhost ([9.41.105.109]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t88M4829001494; Tue, 8 Sep 2015 16:04:08 -0600 From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 8 Sep 2015 17:03:59 -0500 Message-Id: <1441749839-30540-1-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15090822-0021-0000-0000-000012977181 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 32.97.110.154 Cc: Bharata B Rao , qemu-ppc@nongnu.org, Michael Roth , David Gibson Subject: [Qemu-devel] [PATCH] spapr_drc: don't allow 'empty' DRCs to be unisolated 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 Logical resources start with allocation-state:UNUSABLE / isolation-state:ISOLATED. During hotplug, guests will transition them to allocate-state:USABLE, and then to isolate-state:UNISOLATED. The former transition does not seem to have any failure path for cases where a DRC does not have any resources associated with it to allocate for guest, but instead relies on the subsequent isolation-state:UNISOLATED transition to indicate failure in this situation. Currently DRC code does not implement this logic, but instead tries to indicate failure by refusing the allocation-state:USABLE transition. Unfortunately, since that's not a documented failure path, guests continue undeterred, causing undefined behavior in QEMU and guest code. Fix this by handling things as PAPR defines (13.7 and 13.7.3.1). Cc: qemu-ppc@nongnu.org Cc: David Gibson Cc: Bharata B Rao Signed-off-by: Michael Roth --- hw/ppc/spapr_drc.c | 12 ++++++++++++ include/hw/ppc/spapr_drc.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 9ce844a..c1f664f 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -66,6 +66,18 @@ static int set_isolation_state(sPAPRDRConnector *drc, DPRINTFN("drc: %x, set_isolation_state: %x", get_index(drc), state); + if (state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) { + /* cannot unisolate a non-existant resource. this generally + * happens for logical resources where transitions from + * allocation-state:UNUSABLE to allocation-state:USABLE are + * unguarded, but instead rely on a subsequent + * isolation-state:UNISOLATED transition to indicate failure + */ + if (!drc->dev) { + return -1; + } + } + drc->isolation_state = state; if (drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) { diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 28ffeae..3fbe9ea 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -109,6 +109,7 @@ typedef enum { * unusable: device not currently available to OS * exchange: (currently unused) * recover: (currently unused) + * no_sensor: for logical DR only, returned when no resource available */ typedef enum { SPAPR_DR_ENTITY_SENSE_EMPTY = 0, @@ -116,6 +117,7 @@ typedef enum { SPAPR_DR_ENTITY_SENSE_UNUSABLE = 2, SPAPR_DR_ENTITY_SENSE_EXCHANGE = 3, SPAPR_DR_ENTITY_SENSE_RECOVER = 4, + SPAPR_DR_ENTITY_SENSE_NO_SENSOR = -3, } sPAPRDREntitySense; typedef enum {