From patchwork Thu Oct 26 20:22:48 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: 10028775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0BF166022E for ; Thu, 26 Oct 2017 20:27:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F27E528ED0 for ; Thu, 26 Oct 2017 20:27:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6B1928ED6; Thu, 26 Oct 2017 20:27:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 17C7828ED0 for ; Thu, 26 Oct 2017 20:26:59 +0000 (UTC) Received: from localhost ([::1]:54522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7ojz-0004Zo-3Z for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 Oct 2017 16:26:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7ogO-0002j9-L9 for qemu-devel@nongnu.org; Thu, 26 Oct 2017 16:23:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7ogL-0007Pj-Et for qemu-devel@nongnu.org; Thu, 26 Oct 2017 16:23:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e7ogL-0007Ov-5i for qemu-devel@nongnu.org; Thu, 26 Oct 2017 16:23:13 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9QKN7uO050635 for ; Thu, 26 Oct 2017 16:23:08 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dujyvaq9k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 26 Oct 2017 16:23:08 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Oct 2017 16:23:06 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 26 Oct 2017 16:23:04 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9QKN4vq49872974; Thu, 26 Oct 2017 20:23:04 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E8BA1AC041; Thu, 26 Oct 2017 16:23:48 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.170.89]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 748B0AC03F; Thu, 26 Oct 2017 16:23:47 -0400 (EDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 26 Oct 2017 18:22:48 -0200 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171026202250.6118-1-danielhb@linux.vnet.ibm.com> References: <20171026202250.6118-1-danielhb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17102620-0052-0000-0000-000002780B70 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007956; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00936879; UDB=6.00472152; IPR=6.00717141; BA=6.00005660; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017729; XFM=3.00000015; UTC=2017-10-26 20:23:05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102620-0053-0000-0000-00005270FBB3 Message-Id: <20171026202250.6118-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-26_08:, , 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-1710260256 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 v1 1/3] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(); }