From patchwork Wed Nov 28 10:19:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Mueller X-Patchwork-Id: 10702273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8488E13A4 for ; Wed, 28 Nov 2018 10:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 759872CF98 for ; Wed, 28 Nov 2018 10:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69A132CFAA; Wed, 28 Nov 2018 10:20:23 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 DFBDD2CF81 for ; Wed, 28 Nov 2018 10:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728569AbeK1VVa (ORCPT ); Wed, 28 Nov 2018 16:21:30 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43160 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728563AbeK1VV3 (ORCPT ); Wed, 28 Nov 2018 16:21:29 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wASAJFxM021024 for ; Wed, 28 Nov 2018 05:20:20 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p1p3p7juh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 05:20:20 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 10:20:18 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 10:20:16 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASAKExv28180528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 10:20:14 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B01A852067; Wed, 28 Nov 2018 10:20:14 +0000 (GMT) Received: from s38lp84.lnxne.boe (unknown [9.152.108.100]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 614A452059; Wed, 28 Nov 2018 10:20:14 +0000 (GMT) From: Michael Mueller To: KVM Mailing List , Linux-S390 Mailing List Cc: Martin Schwidefsky , Heiko Carstens , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Halil Pasic , Pierre Morel , Michael Mueller Subject: [PATCH v3 09/12] KVM: s390: add functions to (un)register GISC with GISA Date: Wed, 28 Nov 2018 11:19:40 +0100 X-Mailer: git-send-email 2.13.4 In-Reply-To: <20181128101943.155542-1-mimu@linux.ibm.com> References: <20181128101943.155542-1-mimu@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18112810-4275-0000-0000-000002E7EADE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112810-4276-0000-0000-000037F52A94 Message-Id: <20181128101943.155542-10-mimu@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-28_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=870 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280093 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the IAM (Interruption Alert Mask) to the architectue specific kvm struct. This mask in the GISA is used to define for which ISC a GIB alert can be issued. The functions kvm_s390_gisc_register() and kvm_s390_gisc_unregister() are used to (un)register a GISC (guest ISC) with a virtual machine and its GISA. Upon successful completion, kvm_s390_gisc_register() returns the ISC to be used for GIB alert interruptions. A negative return code indicates an error during registration. Signed-off-by: Michael Mueller Reviewed-by: Pierre Morel --- arch/s390/include/asm/kvm_host.h | 6 ++++++ arch/s390/kvm/interrupt.c | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index 3e3225ea303b..3b7902a8573d 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -850,6 +850,9 @@ struct kvm_arch{ struct kvm_s390_gisa *gisa; int gib_in_use; atomic_t vcpus_in_sie; + u8 iam; + u32 iam_ref_count[MAX_ISC + 1]; + spinlock_t iam_ref_lock; }; #define KVM_HVA_ERR_BAD (-1UL) @@ -883,6 +886,9 @@ void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm, extern int sie64a(struct kvm_s390_sie_block *, u64 *); extern char sie_exit; +extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc); +extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc); + static inline void kvm_arch_hardware_disable(void) {} static inline void kvm_arch_check_processor_compat(void *rtn) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 37a5df4e8dac..dd80bdc056a5 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -2962,6 +2962,8 @@ void kvm_s390_gisa_init(struct kvm *kvm) { if (css_general_characteristics.aiv) { kvm->arch.gisa = &kvm->arch.sie_page2->gisa; + kvm->arch.iam = 0; + spin_lock_init(&kvm->arch.iam_ref_lock); VM_EVENT(kvm, 3, "gisa 0x%pK initialized", kvm->arch.gisa); kvm_s390_gisa_clear(kvm); kvm->arch.gib_in_use = !!gib; @@ -2973,8 +2975,50 @@ void kvm_s390_gisa_destroy(struct kvm *kvm) if (!kvm->arch.gisa) return; kvm->arch.gisa = NULL; + kvm->arch.iam = 0; } +int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc) +{ + if (!kvm->arch.gib_in_use) + return -ENODEV; + if (gisc > MAX_ISC) + return -EINVAL; + + spin_lock(&kvm->arch.iam_ref_lock); + if (kvm->arch.iam_ref_count[gisc] == 0) + kvm->arch.iam |= 0x80 >> gisc; + kvm->arch.iam_ref_count[gisc]++; + spin_unlock(&kvm->arch.iam_ref_lock); + + return gib->nisc; +} +EXPORT_SYMBOL_GPL(kvm_s390_gisc_register); + +int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc) +{ + int rc = 0; + + if (!kvm->arch.gib_in_use) + return -ENODEV; + if (gisc > MAX_ISC) + return -EINVAL; + + spin_lock(&kvm->arch.iam_ref_lock); + if (kvm->arch.iam_ref_count[gisc] == 0) { + rc = -EFAULT; + goto out; + } + kvm->arch.iam_ref_count[gisc]--; + if (kvm->arch.iam_ref_count[gisc] == 0) + kvm->arch.iam &= ~(0x80 >> gisc); +out: + spin_unlock(&kvm->arch.iam_ref_lock); + + return rc; +} +EXPORT_SYMBOL_GPL(kvm_s390_gisc_unregister); + void kvm_s390_gib_destroy(void) { if (!gib)