From patchwork Wed Mar 28 07:39:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 10312457 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 4A8C760212 for ; Wed, 28 Mar 2018 07:39:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AF6A28A0F for ; Wed, 28 Mar 2018 07:39:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E9E12940F; Wed, 28 Mar 2018 07:39:58 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3CDB28A0F for ; Wed, 28 Mar 2018 07:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753484AbeC1Hjz (ORCPT ); Wed, 28 Mar 2018 03:39:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58548 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752853AbeC1Hjx (ORCPT ); Wed, 28 Mar 2018 03:39:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5172406E971; Wed, 28 Mar 2018 07:39:52 +0000 (UTC) Received: from thh440s.str.redhat.com (dhcp-192-189.str.redhat.com [10.33.192.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FAE10B2B38; Wed, 28 Mar 2018 07:39:51 +0000 (UTC) From: Thomas Huth To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: kvm@vger.kernel.org, David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 4/8] s390x: Add diag10 tests Date: Wed, 28 Mar 2018 09:39:40 +0200 Message-Id: <1522222784-7709-5-git-send-email-thuth@redhat.com> In-Reply-To: <1522222784-7709-1-git-send-email-thuth@redhat.com> References: <1522222784-7709-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Mar 2018 07:39:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Mar 2018 07:39:52 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Janosch Frank Let's add some tests for the diag10 "Release pages" instruction. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- s390x/Makefile | 1 + s390x/diag10.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 85 insertions(+) create mode 100644 s390x/diag10.c diff --git a/s390x/Makefile b/s390x/Makefile index c860ed8..1356246 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -4,6 +4,7 @@ tests += $(TEST_DIR)/emulator.elf tests += $(TEST_DIR)/sieve.elf tests += $(TEST_DIR)/sthyi.elf tests += $(TEST_DIR)/skey.elf +tests += $(TEST_DIR)/diag10.elf all: directories test_cases diff --git a/s390x/diag10.c b/s390x/diag10.c new file mode 100644 index 0000000..806ebc6 --- /dev/null +++ b/s390x/diag10.c @@ -0,0 +1,81 @@ +/* + * Release pages hypercall tests (DIAG 10) + * + * Copyright (c) 2018 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ + +#include +#include +#include +#include + +static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2))); +const unsigned long page0 = (unsigned long)pagebuf; +const unsigned long page1 = (unsigned long)(pagebuf + PAGE_SIZE); + +/* Tells the host to release pages from guest real addresses start to + * end. Parameters have to be page aligned, instruction is privileged. + */ +static inline void diag10(unsigned long start, unsigned long end) +{ + asm volatile ( + "diag %0,%1,0x10\n" + : : "a" (start), "a" (end)); +} + +/* Try freeing the prefix */ +static void test_prefix(void) +{ + expect_pgm_int(); + diag10(0, 0); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + expect_pgm_int(); + diag10(0x1000, 0x1000); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + expect_pgm_int(); + diag10(0, 0x1000); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); +} + +static void test_params(void) +{ + /* end < start */ + expect_pgm_int(); + diag10(page1, page0); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + /* Unaligned start */ + expect_pgm_int(); + diag10((unsigned long) pagebuf + 42, page1); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + /* Unaligned end */ + expect_pgm_int(); + diag10(page0, (unsigned long) pagebuf + PAGE_SIZE + 42); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); +} + +static void test_priv(void) +{ + expect_pgm_int(); + enter_pstate(); + diag10(page0, page0); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); +} + +int main(void) +{ + report_prefix_push("diag10"); + test_prefix(); + test_params(); + test_priv(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index c98cddd..d29d23e 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -40,3 +40,6 @@ file = sthyi.elf [skey] file = skey.elf + +[diag10] +file = diag10.elf