Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6113570ybi; Wed, 31 Jul 2019 08:33:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpkCrC9gMPoMYUeYWBOxxn5Vi3q1g7KzXKZPP5VOGyujLU3zd1xJCJCYRgJZ0ItZBMgxkp X-Received: by 2002:a63:2807:: with SMTP id o7mr85330160pgo.131.1564587189646; Wed, 31 Jul 2019 08:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564587189; cv=none; d=google.com; s=arc-20160816; b=IRddrJLySPlZcTtYmSsWmWHrXuiwfcRTI8WNxo2xSIJpnZFn++3uJuj/ZCZ+QxRIMf 1n4e/B1EQsKeKBo9TcV2Xdh6NiSXwCiwFRTKcUA6w+Vy3p4UZQSyj0iPiUrv8QDJJheh lPKBfNAyRhslhpAiLxULAGEZprx6Zx9IAk6o51tYOxAp5mRzdBqYMA8Y3Y+lFnARj4Or uFG+W1xttByt+izoifmzRaZG3/ghW68e+brBgTs6Fz2re5DT3wv6Bch6oF3tWieqx/4D 4aa62Qyh6Vi8Mv86FM2tmFu2HdeTmaVkshPea7LMd49EL97piLPtvoC4H7MwY9fkBf1w zcPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=D2VmdhJJDJQivC3xVT/ONLdB4VyppSBm95B27RyQcQo=; b=UUnuAtTKBz6TF9b8h00ESE4txfx0/wlwb96RPJvVzGm2UrD1l4rrRIDQeMCpBL5ivr +7qA/1pmTnkDrbmeqnktm6Z5eZPK7j9ogawdVwP81YSX1N0LnS+reiP5GESfyv3yPoOk k9yZtYogcVtcjklQYDAyx8FtjshZtABhGL4/bnFr4Ddcpb5gSOLgdH3NsbPoztpAzOcM 3aQDkdDkeIVUtJ1CqphSvNsf/U8pf6rOiZFS5FzOoota8TpWFPzM+WQ49xY+DnXoIF7K VguWunwJrLoMueqgoIoWZivHrSsFMxtGRF0sNfkXSha7snClwXIaQqr9njnuYhcXHuYM Xtzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si32798123pfa.198.2019.07.31.08.32.54; Wed, 31 Jul 2019 08:33:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730158AbfGaPYw (ORCPT + 99 others); Wed, 31 Jul 2019 11:24:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36454 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730143AbfGaPYv (ORCPT ); Wed, 31 Jul 2019 11:24:51 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B07AF89C3A; Wed, 31 Jul 2019 15:15:41 +0000 (UTC) Received: from thuth.com (dhcp-200-228.str.redhat.com [10.33.200.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF8F019C65; Wed, 31 Jul 2019 15:15:39 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Christian Borntraeger Cc: Janosch Frank , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, David Hildenbrand , Paolo Bonzini , Peter Xu , Andrew Jones Subject: [PATCH v3 2/3] KVM: selftests: Implement ucall() for s390x Date: Wed, 31 Jul 2019 17:15:24 +0200 Message-Id: <20190731151525.17156-3-thuth@redhat.com> In-Reply-To: <20190731151525.17156-1-thuth@redhat.com> References: <20190731151525.17156-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 31 Jul 2019 15:15:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On s390x, we can neither exit via PIO nor MMIO, but have to use an instruction like DIAGNOSE. Now that ucall() is implemented, we can use it in the sync_reg_test on s390x, too. Reviewed-by: Andrew Jones Signed-off-by: Thomas Huth --- tools/testing/selftests/kvm/Makefile | 2 +- tools/testing/selftests/kvm/lib/s390x/ucall.c | 56 +++++++++++++++++++ .../selftests/kvm/s390x/sync_regs_test.c | 6 +- 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/kvm/lib/s390x/ucall.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index a51e3b83df40..75ea1ecbf85a 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -10,7 +10,7 @@ UNAME_M := $(shell uname -m) LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/ucall.c LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c -LIBKVM_s390x = lib/s390x/processor.c +LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test diff --git a/tools/testing/selftests/kvm/lib/s390x/ucall.c b/tools/testing/selftests/kvm/lib/s390x/ucall.c new file mode 100644 index 000000000000..fd589dc9bfab --- /dev/null +++ b/tools/testing/selftests/kvm/lib/s390x/ucall.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ucall support. A ucall is a "hypercall to userspace". + * + * Copyright (C) 2019 Red Hat, Inc. + */ +#include "kvm_util.h" + +void ucall_init(struct kvm_vm *vm, void *arg) +{ +} + +void ucall_uninit(struct kvm_vm *vm) +{ +} + +void ucall(uint64_t cmd, int nargs, ...) +{ + struct ucall uc = { + .cmd = cmd, + }; + va_list va; + int i; + + nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS; + + va_start(va, nargs); + for (i = 0; i < nargs; ++i) + uc.args[i] = va_arg(va, uint64_t); + va_end(va); + + /* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ + asm volatile ("diag 0,%0,0x501" : : "a"(&uc) : "memory"); +} + +uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc) +{ + struct kvm_run *run = vcpu_state(vm, vcpu_id); + struct ucall ucall = {}; + + if (run->exit_reason == KVM_EXIT_S390_SIEIC && + run->s390_sieic.icptcode == 4 && + (run->s390_sieic.ipa >> 8) == 0x83 && /* 0x83 means DIAGNOSE */ + (run->s390_sieic.ipb >> 16) == 0x501) { + int reg = run->s390_sieic.ipa & 0xf; + + memcpy(&ucall, addr_gva2hva(vm, run->s.regs.gprs[reg]), + sizeof(ucall)); + + vcpu_run_complete_io(vm, vcpu_id); + if (uc) + memcpy(uc, &ucall, sizeof(ucall)); + } + + return ucall.cmd; +} diff --git a/tools/testing/selftests/kvm/s390x/sync_regs_test.c b/tools/testing/selftests/kvm/s390x/sync_regs_test.c index e85ff0d69548..bbc93094519b 100644 --- a/tools/testing/selftests/kvm/s390x/sync_regs_test.c +++ b/tools/testing/selftests/kvm/s390x/sync_regs_test.c @@ -25,9 +25,11 @@ static void guest_code(void) { + register u64 stage asm("11") = 0; + for (;;) { - asm volatile ("diag 0,0,0x501"); - asm volatile ("ahi 11,1"); + GUEST_SYNC(0); + asm volatile ("ahi %0,1" : : "r"(stage)); } } -- 2.21.0