From patchwork Tue Oct 31 20:43:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 832728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yRNgM6qm3z9t3r for ; Wed, 1 Nov 2017 07:46:39 +1100 (AEDT) Received: from localhost ([::1]:47318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dQk-0002Xs-2i for incoming@patchwork.ozlabs.org; Tue, 31 Oct 2017 16:46:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dO3-0000xM-6X for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9dO0-0004BA-2s for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:51 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52590) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9dNz-0004Ak-QX for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:48 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9VKeisl080699 for ; Tue, 31 Oct 2017 16:43:45 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dxy79bsrp-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 31 Oct 2017 16:43:44 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Oct 2017 14:43:44 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 31 Oct 2017 14:43:41 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9VKhe2Q59506796; Tue, 31 Oct 2017 13:43:40 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 78D93C6042; Tue, 31 Oct 2017 14:43:40 -0600 (MDT) Received: from localhost.localdomain (unknown [9.85.136.158]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id DADD8C6037; Tue, 31 Oct 2017 14:43:38 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 31 Oct 2017 18:43:27 -0200 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> References: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17103120-0004-0000-0000-00001324C485 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007988; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00939263; UDB=6.00473526; IPR=6.00719524; BA=6.00005666; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017811; XFM=3.00000015; UTC=2017-10-31 20:43:42 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17103120-0005-0000-0000-000084B11F8A Message-Id: <20171031204330.14803-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-31_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710310252 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 1/4] tests: adding 'check_exception' RTAS implementation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In the sPAPR guest, events such as device hotplug/unplug are retrieved by the check_exception RTAS call after the guest receives an IRQ pulse. For both hotplug and unplug operations, guest intervention is required to transit the DRC state of the attached device to the configured state. Without guest intervention, we are still able of qtesting hotplug devices in the same manner that we support device hotplug in early (pre-CAS) stages. Unfortunately, hot unplugs qtests relies on callbacks that demands guest intervention to complete - otherwise we risk leaving the guest in an inconsistent state that might impact other hotplug/unplug operations later on. If we want to make hot unplug qtests we'll need to simulate the guest behavior in the scenario in which a hot unplug is received, allowing the hot unplug process to go as intended. This patch is the first step towards hot unplug qtests in sPAPR, implementing the check_exception RTAS hypercall in libqos. This hypercall is used to fetch events such as hotplug/hot unplug from the sPAPR machine after the guest receives an IRQ pulse (or, in the case of the test implemented here, we simply know when there is/isn't an event to be retrieved). Signed-off-by: Daniel Henrique Barboza --- tests/libqos/rtas.c | 37 +++++++++++++++++++++++++ tests/libqos/rtas.h | 2 ++ tests/rtas-test.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/tests/libqos/rtas.c b/tests/libqos/rtas.c index 0269803ce0..fdeab448f7 100644 --- a/tests/libqos/rtas.c +++ b/tests/libqos/rtas.c @@ -114,3 +114,40 @@ int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid, return 0; } + +/* + * check_exception as defined by PAPR 2.7+, 7.3.3.2 + * + * nargs = 7 (with Extended Information) + * nrets = 1 + * + * arg[2] = mask of event classes to process + * arg[4] = real address of error log + * arg[5] = length of error log + * + * arg[0] (Vector Offset), arg[1] and arg[6] (Additional information) + * and arg[3] (Critical) aren't used in the logic of check_exception + * in hw/ppc/spapr_events.c and can be ignored. + * + * If there is an event that matches the given mask, check-exception writes + * it in buf_addr up to a max of buf_len bytes. + * + */ +int qrtas_check_exception(QGuestAllocator *alloc, uint32_t mask, + uint32_t buf_addr, uint32_t buf_len) +{ + uint32_t args[7], ret[1]; + int res; + + args[0] = args[1] = args[3] = args[6] = 0; + args[2] = mask; + args[4] = buf_addr; + args[5] = buf_len; + + res = qrtas_call(alloc, "check-exception", 7, args, 1, ret); + if (res != 0) { + return -1; + } + + return ret[0]; +} diff --git a/tests/libqos/rtas.h b/tests/libqos/rtas.h index 498eb19230..330ecfd397 100644 --- a/tests/libqos/rtas.h +++ b/tests/libqos/rtas.h @@ -12,4 +12,6 @@ uint32_t qrtas_ibm_read_pci_config(QGuestAllocator *alloc, uint64_t buid, uint32_t addr, uint32_t size); int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid, uint32_t addr, uint32_t size, uint32_t val); +int qrtas_check_exception(QGuestAllocator *alloc, uint32_t mask, + uint32_t buf_addr, uint32_t buf_len); #endif /* LIBQOS_RTAS_H */ diff --git a/tests/rtas-test.c b/tests/rtas-test.c index 276c87ef84..c5a6080043 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -5,6 +5,9 @@ #include "libqos/libqos-spapr.h" #include "libqos/rtas.h" +#define EVENT_MASK_EPOW (1 << 30) +#define EVENT_LOG_LEN 2048 + static void test_rtas_get_time_of_day(void) { QOSState *qs; @@ -24,6 +27,76 @@ static void test_rtas_get_time_of_day(void) qtest_shutdown(qs); } +static void test_rtas_check_exception_no_events(void) +{ + QOSState *qs; + uint64_t ret; + uintptr_t guest_buf_addr; + uint8_t *buf = g_malloc0(EVENT_LOG_LEN); + + qs = qtest_spapr_boot("-machine pseries"); + guest_buf_addr = guest_alloc(qs->alloc, EVENT_LOG_LEN * sizeof(uint8_t)); + + /* + * mask = 0 should return no events, returning + * RTAS_OUT_NO_ERRORS_FOUND (1). + */ + ret = qrtas_check_exception(qs->alloc, 0, guest_buf_addr, EVENT_LOG_LEN); + g_assert_cmpint(ret, ==, 1); + + /* + * Using a proper event mask should also return + * no events since no hotplugs happened. + */ + ret = qrtas_check_exception(qs->alloc, EVENT_MASK_EPOW, guest_buf_addr, + EVENT_LOG_LEN); + g_assert_cmpint(ret, ==, 1); + + guest_free(qs->alloc, guest_buf_addr); + g_free(buf); + + qtest_shutdown(qs); +} + +static void test_rtas_check_exception_hotplug_event(void) +{ + QOSState *qs; + uint64_t ret; + uintptr_t guest_buf_addr; + uint8_t *buf = g_malloc0(EVENT_LOG_LEN); + uint8_t *zero_buf = g_malloc0(EVENT_LOG_LEN); + + qs = qtest_spapr_boot("-machine pseries -cpu POWER8_v2.0 " + "-smp 1,sockets=4,cores=1,threads=1,maxcpus=4"); + + guest_buf_addr = guest_alloc(qs->alloc, EVENT_LOG_LEN * sizeof(uint8_t)); + + qtest_qmp_device_add("power8_v2.0-spapr-cpu-core", "id-1", + "'core-id':'1'"); + /* + * We use EPOW mask instead of HOTPLUG because the code defaults + * the hotplug interrupt source to EPOW if the guest didn't change + * OV5_HP_EVT during CAS. + */ + ret = qrtas_check_exception(qs->alloc, EVENT_MASK_EPOW, + guest_buf_addr, EVENT_LOG_LEN); + + memread(guest_buf_addr, buf, EVENT_LOG_LEN); + guest_free(qs->alloc, guest_buf_addr); + + /* + * Calling check_exception after a hotplug needs to return + * RTAS_OUT_SUCCESS (0) and a non-zero error_log. + */ + g_assert_cmpint(ret, ==, 0); + g_assert(memcmp(buf, zero_buf, EVENT_LOG_LEN) != 0); + + g_free(buf); + g_free(zero_buf); + + qtest_shutdown(qs); +} + int main(int argc, char *argv[]) { const char *arch = qtest_get_arch(); @@ -35,6 +108,10 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } qtest_add_func("rtas/get-time-of-day", test_rtas_get_time_of_day); + qtest_add_func("rtas/rtas-check-exception-no-events", + test_rtas_check_exception_no_events); + qtest_add_func("rtas/rtas-check-exception-hotplug-event", + test_rtas_check_exception_hotplug_event); return g_test_run(); } From patchwork Tue Oct 31 20:43:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 832727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yRNdC35xbz9t3m for ; Wed, 1 Nov 2017 07:44:47 +1100 (AEDT) Received: from localhost ([::1]:47303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dOv-00011o-Eo for incoming@patchwork.ozlabs.org; Tue, 31 Oct 2017 16:44:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dO4-0000yG-Aa for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9dO0-0004BS-Bq for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:52 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48494 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9dO0-0004B4-68 for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:48 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9VKeLU1070345 for ; Tue, 31 Oct 2017 16:43:46 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0b-001b2d01.pphosted.com with ESMTP id 2dxva4vvn1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 31 Oct 2017 16:43:46 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Oct 2017 14:43:45 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 31 Oct 2017 14:43:44 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9VKhhfT4325808; Tue, 31 Oct 2017 13:43:43 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7EF26C6043; Tue, 31 Oct 2017 14:43:43 -0600 (MDT) Received: from localhost.localdomain (unknown [9.85.136.158]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id E0C90C6037; Tue, 31 Oct 2017 14:43:41 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 31 Oct 2017 18:43:28 -0200 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> References: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17103120-0028-0000-0000-00000894D554 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007988; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00939263; UDB=6.00473526; IPR=6.00719524; BA=6.00005666; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017811; XFM=3.00000015; UTC=2017-10-31 20:43:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17103120-0029-0000-0000-000038282AAA Message-Id: <20171031204330.14803-3-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-31_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710310252 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 2/4] tests: adding 'set_indicator' RTAS call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 'set_indicator' is a RTAS hypercall that is used to change the state of both physical and logical devices DRCs by setting allocation-state, isolation-state and dr-indicator. This patch implements the set_indicator RTAS call in tests/libqos/rtas.c, adding its test in tests/rtas-test.c. Signed-off-by: Daniel Henrique Barboza --- tests/libqos/rtas.c | 33 ++++++++++++++++++++++++ tests/libqos/rtas.h | 2 ++ tests/rtas-test.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/tests/libqos/rtas.c b/tests/libqos/rtas.c index fdeab448f7..ade572a84f 100644 --- a/tests/libqos/rtas.c +++ b/tests/libqos/rtas.c @@ -151,3 +151,36 @@ int qrtas_check_exception(QGuestAllocator *alloc, uint32_t mask, return ret[0]; } + +/* + * set_indicator as defined by PAPR 2.7+, 7.3.5.4 + * + * nargs = 3 + * nrets = 1 + * + * arg[0] = the type of the indicator + * arg[1] = index of the specific indicator + * arg[2] = desired new state + * + * Depending on the input, set_indicator will call set_isolation_state, + * set_allocation_state or set_dr_indicator in hw/ppc/spapr_drc.c. + * These functions allows the guest to control the state of hotplugged + * and hot unplugged devices. + */ +int qrtas_set_indicator(QGuestAllocator *alloc, uint32_t type, uint32_t idx, + uint32_t new_state) +{ + uint32_t args[3], ret[1]; + int res; + + args[0] = type; + args[1] = idx; + args[2] = new_state; + + res = qrtas_call(alloc, "set-indicator", 3, args, 1, ret); + if (res != 0) { + return -1; + } + + return ret[0]; +} diff --git a/tests/libqos/rtas.h b/tests/libqos/rtas.h index 330ecfd397..9dfa18f32b 100644 --- a/tests/libqos/rtas.h +++ b/tests/libqos/rtas.h @@ -14,4 +14,6 @@ int qrtas_ibm_write_pci_config(QGuestAllocator *alloc, uint64_t buid, uint32_t addr, uint32_t size, uint32_t val); int qrtas_check_exception(QGuestAllocator *alloc, uint32_t mask, uint32_t buf_addr, uint32_t buf_len); +int qrtas_set_indicator(QGuestAllocator *alloc, uint32_t type, uint32_t idx, + uint32_t new_state); #endif /* LIBQOS_RTAS_H */ diff --git a/tests/rtas-test.c b/tests/rtas-test.c index c5a6080043..2c34b6e83c 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -8,6 +8,13 @@ #define EVENT_MASK_EPOW (1 << 30) #define EVENT_LOG_LEN 2048 +#define RTAS_SENSOR_TYPE_ISOLATION_STATE 9001 +#define RTAS_SENSOR_TYPE_ALLOCATION_STATE 9003 +#define SPAPR_DR_ISOLATION_STATE_ISOLATED 0 +#define SPAPR_DR_ALLOCATION_STATE_UNUSABLE 0 +#define SPAPR_DR_ALLOCATION_STATE_USABLE 1 +#define SPAPR_DR_ISOLATION_STATE_UNISOLATED 1 + static void test_rtas_get_time_of_day(void) { QOSState *qs; @@ -97,6 +104,71 @@ static void test_rtas_check_exception_hotplug_event(void) qtest_shutdown(qs); } +/* + * To test the 'set-indicator' RTAS call we will hotplug a device + * (in this case a CPU) and then make its DRC state go from + * the starting state UNUSABLE(1) to UNISOLATE(3). These DRC + * states transitions are described in further detail in + * PAPR 2.7+ 13.4. + */ +static void test_rtas_set_indicator(void) +{ + QOSState *qs; + uint64_t ret; + uintptr_t guest_buf_addr; + uint32_t drc_index; + uint8_t *buf = g_malloc0(EVENT_LOG_LEN); + + qs = qtest_spapr_boot("-machine pseries -cpu POWER8_v2.0 " + "-smp 1,sockets=4,cores=1,threads=1,maxcpus=4"); + + guest_buf_addr = guest_alloc(qs->alloc, EVENT_LOG_LEN * sizeof(uint8_t)); + qtest_qmp_device_add("power8_v2.0-spapr-cpu-core", "id-1", + "'core-id':'1'"); + + ret = qrtas_check_exception(qs->alloc, EVENT_MASK_EPOW, + guest_buf_addr, EVENT_LOG_LEN); + + memread(guest_buf_addr, buf, EVENT_LOG_LEN); + guest_free(qs->alloc, guest_buf_addr); + + g_assert_cmpint(ret, ==, 0); + + /* + * This time we can't ignore the event log written in the + * check_exception call - we need the DRC index of the + * recently added CPU to make the state changes using set_indicator. + * + * A bit of magic to go straight to the DRC index by checking the + * error log format in hw/ppc/spapr_events.c: + * + * - rtas_error_log size = 8 bytes + * - all other structures until the hotplug event log = 88 bytes + * - inside the hotplug event log, skip 8 + 4 bytes to get to + * the drc_id union. + * + * This gives us a 108 bytes skip to get the drc info, which is + * written in be32. + */ + drc_index = be32toh(*((uint32_t *)(buf + 108))); + g_free(buf); + + /* + * According to the DRC state diagram, the guest first sets a device + * to USABLE (2), then UNISOLATED (3). Both should return + * RTAS_OUT_SUCCESS(0). + */ + ret = qrtas_set_indicator(qs->alloc, RTAS_SENSOR_TYPE_ALLOCATION_STATE, + drc_index, SPAPR_DR_ALLOCATION_STATE_USABLE); + g_assert_cmpint(ret, ==, 0); + + ret = qrtas_set_indicator(qs->alloc, RTAS_SENSOR_TYPE_ISOLATION_STATE, + drc_index, SPAPR_DR_ISOLATION_STATE_UNISOLATED); + g_assert_cmpint(ret, ==, 0); + + qtest_shutdown(qs); +} + int main(int argc, char *argv[]) { const char *arch = qtest_get_arch(); @@ -112,6 +184,7 @@ int main(int argc, char *argv[]) test_rtas_check_exception_no_events); qtest_add_func("rtas/rtas-check-exception-hotplug-event", test_rtas_check_exception_hotplug_event); + qtest_add_func("rtas/test_rtas_set_indicator", test_rtas_set_indicator); return g_test_run(); } From patchwork Tue Oct 31 20:43:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 832729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yRNgY09S2z9t3r for ; Wed, 1 Nov 2017 07:46:49 +1100 (AEDT) Received: from localhost ([::1]:47320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dQt-0002fW-3w for incoming@patchwork.ozlabs.org; Tue, 31 Oct 2017 16:46:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dO7-00010i-Aa for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9dO4-0004DO-PM for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:55 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56388) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9dO4-0004CJ-Hi for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:52 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9VKeoji086163 for ; Tue, 31 Oct 2017 16:43:51 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dxv42nqf3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 31 Oct 2017 16:43:51 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Oct 2017 14:43:50 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 31 Oct 2017 14:43:47 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9VKhknV8061322; Tue, 31 Oct 2017 13:43:46 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91E7AC603E; Tue, 31 Oct 2017 14:43:46 -0600 (MDT) Received: from localhost.localdomain (unknown [9.85.136.158]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id E5ECBC603C; Tue, 31 Oct 2017 14:43:44 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 31 Oct 2017 18:43:29 -0200 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> References: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17103120-8235-0000-0000-00000C7EA671 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007988; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00939263; UDB=6.00473526; IPR=6.00719524; BA=6.00005666; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017811; XFM=3.00000015; UTC=2017-10-31 20:43:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17103120-8236-0000-0000-00003E43733D Message-Id: <20171031204330.14803-4-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-31_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710310252 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 3/4] tests: ibm, configure-connector RTAS call implementation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 'ibm,configure-connector' hypercall is used by the guest OS to start the configuration of a given device, where the machine configures the said device and all its sub-devices, giving back FDTs to the caller for each sub-device. This hypercall is supposed to be called multiple times by the guest OS until it returns RTAS_OUT_SUCESS (code 0), indicating that the device is now properly configured and ready to be used, or a return value < 0 when an error occurs. This patch implements the 'ibm,configure-connector' RTAS hypercall in tests/libqos/rtas.c, with an extra test case for it inside tests/rtas-tests.c. Signed-off-by: Daniel Henrique Barboza --- tests/libqos/rtas.c | 35 +++++++++++++++++++++++++++ tests/libqos/rtas.h | 1 + tests/rtas-test.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/tests/libqos/rtas.c b/tests/libqos/rtas.c index ade572a84f..1cb9e2b495 100644 --- a/tests/libqos/rtas.c +++ b/tests/libqos/rtas.c @@ -184,3 +184,38 @@ int qrtas_set_indicator(QGuestAllocator *alloc, uint32_t type, uint32_t idx, return ret[0]; } + +/* + * ibm,configure-connector as defined by PAPR 2.7+, 13.5.3.5 + * + * nargs = 2 + * nrets = 1 + * + * args[0] and args[1] compose the 64 bit Work Area address. + * + * This call will configure not only the device reported in the first + * offset of the Work Area but all of its siblingis as well, returning + * the FDT of each configured sub-device as well as a return code + * 'Next child', 'Next property' or 'Previous parent'. When the whole + * configuration is done, 'Configuration completed' (0) is returned. + * + * configure-connector will always reply with status code 'Next child'(2) + * on the first successful call. The DRC configuration will be + * completed when configure-connector returns status 0. Any return + * status < 0 indicates an error. + */ +int qrtas_ibm_configure_connector(QGuestAllocator *alloc, uintptr_t wa_addr) +{ + uint32_t args[2], ret[1]; + int res; + + args[0] = (uint32_t)(wa_addr); + args[1] = (uint32_t)(wa_addr >> 32); + + res = qrtas_call(alloc, "ibm,configure-connector", 2, args, 1, ret); + if (res != 0) { + return -1; + } + + return ret[0]; +} diff --git a/tests/libqos/rtas.h b/tests/libqos/rtas.h index 9dfa18f32b..35c44fb967 100644 --- a/tests/libqos/rtas.h +++ b/tests/libqos/rtas.h @@ -16,4 +16,5 @@ int qrtas_check_exception(QGuestAllocator *alloc, uint32_t mask, uint32_t buf_addr, uint32_t buf_len); int qrtas_set_indicator(QGuestAllocator *alloc, uint32_t type, uint32_t idx, uint32_t new_state); +int qrtas_ibm_configure_connector(QGuestAllocator *alloc, uintptr_t wa_addr); #endif /* LIBQOS_RTAS_H */ diff --git a/tests/rtas-test.c b/tests/rtas-test.c index 2c34b6e83c..b3538bf878 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -15,6 +15,8 @@ #define SPAPR_DR_ALLOCATION_STATE_USABLE 1 #define SPAPR_DR_ISOLATION_STATE_UNISOLATED 1 +#define CC_WA_LEN 4096 + static void test_rtas_get_time_of_day(void) { QOSState *qs; @@ -169,6 +171,70 @@ static void test_rtas_set_indicator(void) qtest_shutdown(qs); } +static void test_rtas_ibm_configure_connector(void) +{ + QOSState *qs; + uint64_t ret; + uintptr_t guest_buf_addr, guest_drc_addr; + uint32_t drc_index; + uint8_t *buf = g_malloc0(EVENT_LOG_LEN); + + qs = qtest_spapr_boot("-machine pseries -cpu POWER8_v2.0 " + "-smp 1,sockets=4,cores=1,threads=1,maxcpus=4"); + + guest_buf_addr = guest_alloc(qs->alloc, EVENT_LOG_LEN * sizeof(uint8_t)); + qtest_qmp_device_add("power8_v2.0-spapr-cpu-core", "id-1", + "'core-id':'1'"); + + ret = qrtas_check_exception(qs->alloc, EVENT_MASK_EPOW, + guest_buf_addr, EVENT_LOG_LEN); + + memread(guest_buf_addr, buf, EVENT_LOG_LEN); + guest_free(qs->alloc, guest_buf_addr); + + g_assert_cmpint(ret, ==, 0); + + /* + * Same 108 bytes offset magic used and explained in + * test_rtas_set_indicator. + */ + drc_index = be32toh(*((uint32_t *)(buf + 108))); + g_free(buf); + + ret = qrtas_set_indicator(qs->alloc, RTAS_SENSOR_TYPE_ALLOCATION_STATE, + drc_index, SPAPR_DR_ALLOCATION_STATE_USABLE); + g_assert_cmpint(ret, ==, 0); + + ret = qrtas_set_indicator(qs->alloc, RTAS_SENSOR_TYPE_ISOLATION_STATE, + drc_index, SPAPR_DR_ISOLATION_STATE_UNISOLATED); + g_assert_cmpint(ret, ==, 0); + + /* + * Call ibm,configure-connector to finish the hotplugged device + * configuration, putting its DRC into 'ready' state. + * + * We're not interested in the generated FDTs during the config + * process, thus we simply keep calling configure-connector + * until it returns SUCCESS(0) or an error. + * + * The full explanation logic behind this process can be found + * at PAPR 2.7+, 13.5.3.5. + */ + guest_drc_addr = guest_alloc(qs->alloc, CC_WA_LEN * sizeof(uint32_t)); + writel(guest_drc_addr, drc_index); + writel(guest_drc_addr + sizeof(uint32_t), 0); + + do { + ret = qrtas_ibm_configure_connector(qs->alloc, guest_drc_addr); + } while (ret > 0); + + guest_free(qs->alloc, guest_drc_addr); + + g_assert_cmpint(ret, ==, 0); + + qtest_shutdown(qs); +} + int main(int argc, char *argv[]) { const char *arch = qtest_get_arch(); @@ -185,6 +251,8 @@ int main(int argc, char *argv[]) qtest_add_func("rtas/rtas-check-exception-hotplug-event", test_rtas_check_exception_hotplug_event); qtest_add_func("rtas/test_rtas_set_indicator", test_rtas_set_indicator); + qtest_add_func("rtas/test_rtas_ibm_configure_connector", + test_rtas_ibm_configure_connector); return g_test_run(); } From patchwork Tue Oct 31 20:43:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 832730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yRNjX0sKwz9t3r for ; Wed, 1 Nov 2017 07:48:32 +1100 (AEDT) Received: from localhost ([::1]:47323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dSY-0003pa-7c for incoming@patchwork.ozlabs.org; Tue, 31 Oct 2017 16:48:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9dOA-00013v-RO for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9dO7-0004Ea-OP for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:58 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9dO7-0004EA-FJ for qemu-devel@nongnu.org; Tue, 31 Oct 2017 16:43:55 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9VKf8r4087449 for ; Tue, 31 Oct 2017 16:43:53 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dy04ugwvy-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 31 Oct 2017 16:43:52 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Oct 2017 14:43:52 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 31 Oct 2017 14:43:50 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9VKhnaS51511524; Tue, 31 Oct 2017 13:43:49 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9917CC6037; Tue, 31 Oct 2017 14:43:49 -0600 (MDT) Received: from localhost.localdomain (unknown [9.85.136.158]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 04EE6C603C; Tue, 31 Oct 2017 14:43:47 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 31 Oct 2017 18:43:30 -0200 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> References: <20171031204330.14803-1-danielhb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17103120-0008-0000-0000-000008CBB885 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007988; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00939263; UDB=6.00473526; IPR=6.00719524; BA=6.00005666; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017811; XFM=3.00000015; UTC=2017-10-31 20:43:51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17103120-0009-0000-0000-000044950A20 Message-Id: <20171031204330.14803-5-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-31_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710310252 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 4/4] tests/rtas-test.c: fix Apple endian.h include X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Recent rtas-test.c changes added a call to 'be32toh', a function from the header 'endian.h' in Linux. This caused QEMU Travis build to break because be32toh is undefined in Mac OS (even using the machine/endian.h header). This patch makes a conditional code to include the proper header file if we're compiling in an __APPLE__ env. Signed-off-by: Daniel Henrique Barboza --- tests/rtas-test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/rtas-test.c b/tests/rtas-test.c index b3538bf878..511980ad17 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -5,6 +5,17 @@ #include "libqos/libqos-spapr.h" #include "libqos/rtas.h" +#if defined(__APPLE__) +# include + +# define be32toh(x) OSSwapBigToHostInt32(x) +# define __BYTE_ORDER BYTE_ORDER +# define __BIG_ENDIAN BIG_ENDIAN +# define __LITTLE_ENDIAN LITTLE_ENDIAN +#else +# include +#endif + #define EVENT_MASK_EPOW (1 << 30) #define EVENT_LOG_LEN 2048