From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 181C3C433DF for ; Thu, 14 May 2020 09:38:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6313206A5 for ; Thu, 14 May 2020 09:38:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a+MluT38" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726056AbgENJib (ORCPT ); Thu, 14 May 2020 05:38:31 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:42968 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725878AbgENJia (ORCPT ); Thu, 14 May 2020 05:38:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589449108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=HGos39yl7LjTg9zQVvrjN8JesI5ex7ejOOIVAEuv8dg=; b=a+MluT38Xop1TD5J3hy0pGfJ9ARjBCzDiXIRIsW/m/wmwf+FfSf4ZH81A+jduRn/cOwd55 D5U5JAzevY9S2dTIuFuLZllwUmLk81A6Aw5TIhL+2GHVSbG1Y1XyvJNHfs4S69I2C73k0u exeLj75tJyky5qcMNxkM5jiJEWFvz0c= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-Xr8J1nR_P1OMVxiH5Q5tXw-1; Thu, 14 May 2020 05:38:26 -0400 X-MC-Unique: Xr8J1nR_P1OMVxiH5Q5tXw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D777803DA5; Thu, 14 May 2020 09:38:18 +0000 (UTC) Received: from [10.36.114.168] (ovpn-114-168.ams2.redhat.com [10.36.114.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07CCE5D9E8; Thu, 14 May 2020 09:37:47 +0000 (UTC) Subject: Re: [PATCH v6 2/2] s390/kvm: diagnose 318 handling To: Janosch Frank , Thomas Huth , Collin Walling , kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: pbonzini@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, imbrenda@linux.ibm.com, heiko.carstens@de.ibm.com, gor@linux.ibm.com References: <20200513221557.14366-1-walling@linux.ibm.com> <20200513221557.14366-3-walling@linux.ibm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBL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OcWSeFpLrSGRQ1Z7EMzFVU//qVs6uzhsNk0RYMyS0B6oloW3FpyQ+zOVylFWQCzoyyf227y GW8HnXunJSC+4PtlL2AY4yZjAVAPLK2l6mhgClVXTQ/S7cBoTQKP+jvVJOoYkpnFxWE9pn4t H5QIFk7Ip8TKr5k3fXVWk4lnUi9MTF/5L/mWqdyIO1s7cjharQCstfWCzWrVeVctpVoDfJWp 4LwTuQ5yEM2KcPeElLg5fR7WB2zH97oI6/Ko2DlovmfQqXh9xWozQt0iGy5tWzh6I0JrlcxJ ileZWLccC4XKD1037Hy2FLAjzfoWgwBLA6ULu0exOOdIa58H4PsXtkFPrUF980EEibUp0zFz GotRVekFAceUaRvAj7dh76cToeZkfsjAvBVb4COXuhgX6N4pofgNkW2AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: <88d27a61-b55b-ee68-f7f9-85ce7fcefd64@redhat.com> Date: Thu, 14 May 2020 11:37:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 14.05.20 10:52, Janosch Frank wrote: > On 5/14/20 9:53 AM, Thomas Huth wrote: >> On 14/05/2020 00.15, Collin Walling wrote: >>> DIAGNOSE 0x318 (diag318) is a privileged s390x instruction that must >>> be intercepted by SIE and handled via KVM. Let's introduce some >>> functions to communicate between userspace and KVM via ioctls. These >>> will be used to get/set the diag318 related information, as well as >>> check the system if KVM supports handling this instruction. >>> >>> This information can help with diagnosing the environment the VM is >>> running in (Linux, z/VM, etc) if the OS calls this instruction. >>> >>> By default, this feature is disabled and can only be enabled if a >>> user space program (such as QEMU) explicitly requests it. >>> >>> The Control Program Name Code (CPNC) is stored in the SIE block >>> and a copy is retained in each VCPU. The Control Program Version >>> Code (CPVC) is not designed to be stored in the SIE block, so we >>> retain a copy in each VCPU next to the CPNC. >>> >>> Signed-off-by: Collin Walling >>> --- >>> Documentation/virt/kvm/devices/vm.rst | 29 +++++++++ >>> arch/s390/include/asm/kvm_host.h | 6 +- >>> arch/s390/include/uapi/asm/kvm.h | 5 ++ >>> arch/s390/kvm/diag.c | 20 ++++++ >>> arch/s390/kvm/kvm-s390.c | 89 +++++++++++++++++++++++++++ >>> arch/s390/kvm/kvm-s390.h | 1 + >>> arch/s390/kvm/vsie.c | 2 + >>> 7 files changed, 151 insertions(+), 1 deletion(-) >> [...] >>> diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c >>> index 563429dece03..3caed4b880c8 100644 >>> --- a/arch/s390/kvm/diag.c >>> +++ b/arch/s390/kvm/diag.c >>> @@ -253,6 +253,24 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu) >>> return ret < 0 ? ret : 0; >>> } >>> >>> +static int __diag_set_diag318_info(struct kvm_vcpu *vcpu) >>> +{ >>> + unsigned int reg = (vcpu->arch.sie_block->ipa & 0xf0) >> 4; >>> + u64 info = vcpu->run->s.regs.gprs[reg]; >>> + >>> + if (!vcpu->kvm->arch.use_diag318) >>> + return -EOPNOTSUPP; >>> + >>> + vcpu->stat.diagnose_318++; >>> + kvm_s390_set_diag318_info(vcpu->kvm, info); >>> + >>> + VCPU_EVENT(vcpu, 3, "diag 0x318 cpnc: 0x%x cpvc: 0x%llx", >>> + vcpu->kvm->arch.diag318_info.cpnc, >>> + (u64)vcpu->kvm->arch.diag318_info.cpvc); >>> + >>> + return 0; >>> +} >>> + >>> int kvm_s390_handle_diag(struct kvm_vcpu *vcpu) >>> { >>> int code = kvm_s390_get_base_disp_rs(vcpu, NULL) & 0xffff; >>> @@ -272,6 +290,8 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu) >>> return __diag_page_ref_service(vcpu); >>> case 0x308: >>> return __diag_ipl_functions(vcpu); >>> + case 0x318: >>> + return __diag_set_diag318_info(vcpu); >>> case 0x500: >>> return __diag_virtio_hypercall(vcpu); >> >> I wonder whether it would make more sense to simply drop to userspace >> and handle the diag 318 call there? That way the userspace would always >> be up-to-date, and as we've seen in the past (e.g. with the various SIGP >> handling), it's better if the userspace is in control... e.g. userspace >> could also decide to only use KVM_S390_VM_MISC_ENABLE_DIAG318 if the >> guest just executed the diag 318 instruction. >> >> And you need the kvm_s390_vm_get/set_misc functions anyway, so these >> could also be simply used by the diag 318 handler in userspace? >> >>> default: >>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c >>> index d05bb040fd42..c3eee468815f 100644 >>> --- a/arch/s390/kvm/kvm-s390.c >>> +++ b/arch/s390/kvm/kvm-s390.c >>> @@ -159,6 +159,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { >>> { "diag_9c_ignored", VCPU_STAT(diagnose_9c_ignored) }, >>> { "instruction_diag_258", VCPU_STAT(diagnose_258) }, >>> { "instruction_diag_308", VCPU_STAT(diagnose_308) }, >>> + { "instruction_diag_318", VCPU_STAT(diagnose_318) }, >>> { "instruction_diag_500", VCPU_STAT(diagnose_500) }, >>> { "instruction_diag_other", VCPU_STAT(diagnose_other) }, >>> { NULL } >>> @@ -1243,6 +1244,76 @@ static int kvm_s390_get_tod(struct kvm *kvm, struct kvm_device_attr *attr) >>> return ret; >>> } >>> >>> +void kvm_s390_set_diag318_info(struct kvm *kvm, u64 info) >>> +{ >>> + struct kvm_vcpu *vcpu; >>> + int i; >>> + >>> + kvm->arch.diag318_info.val = info; >>> + >>> + VM_EVENT(kvm, 3, "SET: CPNC: 0x%x CPVC: 0x%llx", >>> + kvm->arch.diag318_info.cpnc, kvm->arch.diag318_info.cpvc); >>> + >>> + if (sclp.has_diag318) { >>> + kvm_for_each_vcpu(i, vcpu, kvm) { >>> + vcpu->arch.sie_block->cpnc = kvm->arch.diag318_info.cpnc; >>> + } >>> + } >>> +} >>> + >>> +static int kvm_s390_vm_set_misc(struct kvm *kvm, struct kvm_device_attr *attr) >>> +{ >>> + int ret; >>> + u64 diag318_info; >>> + >>> + switch (attr->attr) { >>> + case KVM_S390_VM_MISC_ENABLE_DIAG318: >>> + kvm->arch.use_diag318 = 1; >>> + ret = 0; >>> + break; >> >> Would it make sense to set kvm->arch.use_diag318 = 1 during the first >> execution of KVM_S390_VM_MISC_DIAG318 instead, so that we could get >> along without the KVM_S390_VM_MISC_ENABLE_DIAG318 ? > > I'm not an expert in feature negotiation, but why isn't this a cpu > feature like sief2 instead of a attribute? > > @David? In the end you want to have it somehow in the CPU model I guess. You cannot glue it to QEMU machines, because availability depends on HW+KVM support. How does the guest detect that it can use diag318? I assume/hope via a a STFLE feature. -- Thanks, David / dhildenb