From patchwork Tue Mar 20 11:19:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10296909 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 3C5E060349 for ; Tue, 20 Mar 2018 11:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C14C28AC9 for ; Tue, 20 Mar 2018 11:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FC2629139; Tue, 20 Mar 2018 11:20:41 +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 16B2E28CD4 for ; Tue, 20 Mar 2018 11:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752935AbeCTLUi (ORCPT ); Tue, 20 Mar 2018 07:20:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43010 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752780AbeCTLUY (ORCPT ); Tue, 20 Mar 2018 07:20:24 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2KBJL61042663 for ; Tue, 20 Mar 2018 07:20:23 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2gtvu9jt4n-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 20 Mar 2018 07:20:23 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Mar 2018 11:20:21 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Mar 2018 11:20:18 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2KBKIqI45613088; Tue, 20 Mar 2018 11:20:18 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77EE552047; Tue, 20 Mar 2018 10:11:42 +0000 (GMT) Received: from s38lp20.boeblingen.de.ibm.com (unknown [9.152.224.155]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 560D152043; Tue, 20 Mar 2018 10:11:42 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 5/8] s390x: Add pfmf tests Date: Tue, 20 Mar 2018 12:19:33 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521544776-149935-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1521544776-149935-1-git-send-email-frankja@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18032011-0040-0000-0000-000004233CEF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032011-0041-0000-0000-000026265696 Message-Id: <1521544776-149935-6-git-send-email-frankja@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-20_05:, , 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-1709140000 definitions=main-1803200133 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Perform Frame Management Functions (pfmf) is an instruction that sets storage keys or clears memory for frames in the size of 4k, 1m and 2g. Hence it's quite complex and deserves some testing. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth --- s390x/Makefile | 1 + s390x/pfmf.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 148 insertions(+) create mode 100644 s390x/pfmf.c diff --git a/s390x/Makefile b/s390x/Makefile index bc5dd91..438c6b2 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -5,6 +5,7 @@ tests += $(TEST_DIR)/sieve.elf tests += $(TEST_DIR)/sthyi.elf tests += $(TEST_DIR)/skey.elf tests += $(TEST_DIR)/diag10.elf +tests += $(TEST_DIR)/pfmf.elf all: directories test_cases diff --git a/s390x/pfmf.c b/s390x/pfmf.c new file mode 100644 index 0000000..838f7bd --- /dev/null +++ b/s390x/pfmf.c @@ -0,0 +1,144 @@ +/* + * Perform Frame Management Function (pfmf) tests + * + * Copyright (c) 2018 IBM + * + * 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 +#include +#include + +#define FSC_4K 0 +#define FSC_1M 1 +#define FSC_2G 2 + +union r1 { + struct { + unsigned long pad0 : 32; + unsigned long pad1 : 12; + unsigned long pad_fmfi : 2; + unsigned long sk : 1; /* set key*/ + unsigned long cf : 1; /* clear frame */ + unsigned long ui : 1; /* usage indication */ + unsigned long fsc : 3; + unsigned long pad2 : 1; + unsigned long mr : 1; + unsigned long mc : 1; + unsigned long pad3 : 1; + unsigned long key : 8; /* storage keys */ + } reg; + unsigned long val; +}; + +static uint8_t pagebuf[PAGE_SIZE * 256] __attribute__((aligned(PAGE_SIZE * 256))); + +static inline unsigned long pfmf(unsigned long r1, unsigned long paddr) +{ + register uint64_t addr asm("1") = paddr; + + asm volatile(".insn rre,0xb9af0000,%[r1],%[addr]" + : [addr] "+a" (addr) : [r1] "d" (r1) : "memory"); + return addr; +} + +static void test_priv(void) +{ + expect_pgm_int(); + enter_pstate(); + pfmf(0, (unsigned long) pagebuf); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); +} + +static void test_4k_key(void) +{ + union r1 r1; + union skey skey; + + r1.val = 0; + r1.reg.sk = 1; + r1.reg.fsc = FSC_4K; + r1.reg.key = 0x30; + pfmf(r1.val, (unsigned long) pagebuf); + skey.val = get_storage_key((unsigned long) pagebuf); + report("set 4k", skey.val == 0x30); +} + +static void test_1m_key(void) +{ + int i; + union r1 r1; + + r1.val = 0; + r1.reg.sk = 1; + r1.reg.fsc = FSC_1M; + r1.reg.key = 0x30; + pfmf(r1.val, (unsigned long) pagebuf); + for (i = 0; i < 256; i++) { + if (get_storage_key((unsigned long) pagebuf + i * PAGE_SIZE) != 0x30) { + report("set 1M", false); + return; + } + } + report("set 1M", true); +} + +static void test_4k_clear(void) +{ + union r1 r1; + + r1.val = 0; + r1.reg.cf = 1; + r1.reg.fsc = FSC_4K; + + memset(pagebuf, 42, PAGE_SIZE); + pfmf(r1.val, (unsigned long) pagebuf); + report("clear 4k", !memcmp(pagebuf, pagebuf + PAGE_SIZE, PAGE_SIZE)); +} + +static void test_1m_clear(void) +{ + int i; + union r1 r1; + unsigned long sum = 0; + + r1.val = 0; + r1.reg.cf = 1; + r1.reg.fsc = FSC_1M; + + memset(pagebuf, 42, PAGE_SIZE * 256); + pfmf(r1.val, (unsigned long) pagebuf); + for (i = 0; i < PAGE_SIZE * 256; i++) + sum |= pagebuf[i]; + report("clear 1m", !sum); +} + +int main(void) +{ + bool has_edat = test_facility(8); + + report_prefix_push("pfmf"); + report_xfail("PFMF available", !has_edat, has_edat); + if (!has_edat) + goto done; + + test_priv(); + /* Force the buffer pages in */ + memset(pagebuf, 0, PAGE_SIZE * 256); + + test_4k_key(); + test_1m_key(); + test_4k_clear(); + test_1m_clear(); + +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 5531590..3b975ca 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -44,3 +44,6 @@ file = skey.elf [diag10] file = diag10.elf + +[pfmf] +file = pfmf.elf