Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2073857imm; Wed, 16 May 2018 07:30:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq088ec9txgCZANxMZc5mUYrmpE+HiuwkteoB+JuvHhcldzYC7qGHohW9T3zueE8TvBAGMk X-Received: by 2002:a65:5b4d:: with SMTP id y13-v6mr951792pgr.152.1526481012859; Wed, 16 May 2018 07:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526481012; cv=none; d=google.com; s=arc-20160816; b=ttl9rQZwssvkEXbdA+en18mU0JANmDlCUMrcbjUvCEvUVP2Wt2TQGTzFVsikcHS7Ml 8QmQrYR6ehNyjKaJszX6Vi/7YRCDw4fOhswxUvYsP8x2inwPK9AN1YZcy2UWOaMWGNsq hM5+7k4aRYIf/ceVXe8fxIqMYpTkbH4/7HnLYCW0WjgqfgMb3y3hiNhUQR4zFTZQr8z5 1lJRpvbWUfcu9In/xNDQJX16AcbvvSjpESs6EjP1APcv4jcVeUanU3A4dkCCEYL3rrIB EeUNnehNgsMJy95OtbMfXPeHWI0MjchVEE5/Dd+diTn+/8FYdyUmIFjW0G7kXsEYrGId QQLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:arc-authentication-results; bh=62Fyx9QdQTrGd6IYYDbVFQhc35xjdBhhTWeUcD35Hts=; b=hEp2i/pgzhEw68ugn8OVeUU8BqdWX1BoTbmqpavxCJZ7z0aGtU13Nnr/Xxyhtd8U8a XUxZHXQULFtRsK2ncW5uXPimRKYVvG5C6ldASEOwL1Dc4dOoprT8dI6FMAqcyZiotCEp CFyafbnvR8gnx3sRRY+j2bjkDFLOp0yyxaj5HAwpGswItc0pdrTOYHGrAc87XnCIVkNp EMkjZKQFqSu6xj0vaDoThayUAPB9vcIKZ5pmsB8oB6Hc3Cu3/+O9rZQnaPuqm45fp9EJ SBa6Q5akXCK/N+JBAs9JR9yonTCFkaIgjhHAmCiq80mEpZKzpiqHi1EqcC6ezwhTNWsf baVg== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si2815509pfc.106.2018.05.16.07.29.58; Wed, 16 May 2018 07:30:12 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752568AbeEPO3W (ORCPT + 99 others); Wed, 16 May 2018 10:29:22 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51274 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752119AbeEPO3U (ORCPT ); Wed, 16 May 2018 10:29:20 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4GEPhPr007212 for ; Wed, 16 May 2018 10:29:19 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j0kjb0xcs-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 May 2018 10:29:19 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 May 2018 08:29:18 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 16 May 2018 08:29:15 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4GETAJL14352762; Wed, 16 May 2018 07:29:13 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6CB0136048; Wed, 16 May 2018 08:29:13 -0600 (MDT) Received: from oc8043147753.ibm.com (unknown [9.80.200.126]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id CD515136040; Wed, 16 May 2018 08:29:10 -0600 (MDT) Subject: Re: [PATCH v5 06/13] KVM: s390: interfaces to manage guest's AP matrix To: Halil Pasic , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, kwankhede@nvidia.com, bjsdjshi@linux.vnet.ibm.com, pbonzini@redhat.com, alex.williamson@redhat.com, pmorel@linux.vnet.ibm.com, alifm@linux.vnet.ibm.com, mjrosato@linux.vnet.ibm.com, jjherne@linux.vnet.ibm.com, thuth@redhat.com, pasic@linux.vnet.ibm.com, berrange@redhat.com, fiuczy@linux.vnet.ibm.com, buendgen@de.ibm.com References: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1525705912-12815-7-git-send-email-akrowiak@linux.vnet.ibm.com> From: Tony Krowiak Date: Wed, 16 May 2018 10:29:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18051614-8235-0000-0000-00000D82B897 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009034; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000260; SDB=6.01033162; UDB=6.00528250; IPR=6.00812293; MB=3.00021146; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-16 14:29:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051614-8236-0000-0000-000040FD47D1 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-16_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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805160146 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/11/2018 12:08 PM, Halil Pasic wrote: > > > On 05/07/2018 05:11 PM, Tony Krowiak wrote: >> Provides interfaces to manage the AP adapters, usage domains >> and control domains assigned to a KVM guest. >> >> The guest's SIE state description has a satellite structure called the >> Crypto Control Block (CRYCB) containing three bitmask fields >> identifying the adapters, queues (domains) and control domains >> assigned to the KVM guest: > > [..] > >> index 00bcfb0..98b53c7 100644 >> --- a/arch/s390/kvm/kvm-ap.c >> +++ b/arch/s390/kvm/kvm-ap.c >> @@ -7,6 +7,7 @@ > > [..] > >> + >> +/** >> + * kvm_ap_validate_queue_sharing >> + * >> + * Verifies that the APQNs derived from the cross product of the AP >> adapter IDs >> + * and AP queue indexes comprising the AP matrix are not configured for >> + * another guest. AP queue sharing is not allowed. >> + * >> + * @kvm: the KVM guest >> + * @matrix: the AP matrix >> + * >> + * Returns 0 if the APQNs are valid, otherwise; returns -EBUSY. >> + */ >> +static int kvm_ap_validate_queue_sharing(struct kvm *kvm, >> + struct kvm_ap_matrix *matrix) >> +{ >> + struct kvm *vm; >> + unsigned long *apm, *aqm; >> + unsigned long apid, apqi; >> + >> + >> + /* No other VM may share an AP Queue with the input VM */ >> + list_for_each_entry(vm, &vm_list, vm_list) { >> + if (kvm == vm) >> + continue; >> + >> + apm = kvm_ap_get_crycb_apm(vm); >> + if (!bitmap_and(apm, apm, matrix->apm, matrix->apm_max + 1)) >> + continue; >> + >> + aqm = kvm_ap_get_crycb_aqm(vm); >> + if (!bitmap_and(aqm, aqm, matrix->aqm, matrix->aqm_max + 1)) >> + continue; >> + >> + for_each_set_bit_inv(apid, apm, matrix->apm_max + 1) >> + for_each_set_bit_inv(apqi, aqm, matrix->aqm_max + 1) >> + kvm_ap_log_sharing_err(vm, apid, apqi); >> + >> + return -EBUSY; >> + } >> + >> + return 0; >> +} >> + >> +int kvm_ap_configure_matrix(struct kvm *kvm, struct kvm_ap_matrix >> *matrix) >> +{ >> + int ret = 0; >> + >> + mutex_lock(&kvm->lock); > > You seem to take only kvm->lock, vm_list however (used in > kvm_ap_validate_queue_sharing()) seems to be protected by > kvm_lock. > > Can you tell me why is this supposed to be safe? > > What is supposed to prevent an execution like > vm1: call kvm_ap_configure_matrix(m1) > vm2: call kvm_ap_configure_matrix(m2) > vm1: call kvm_ap_validate_queue_sharing(m1) > vm2: call kvm_ap_validate_queue_sharing(m2) > vm1: call kvm_ap_set_crycb_masks(m1) > vm2: call kvm_ap_set_crycb_masks(m2) > > where, let's say, m1 and m2 are equal in the sense that the > mask values are the same? vm1 will get the kvm->lock first in your scenario when kvm_ap_configure_matrix(m1) is invoked. Since the other functions - i.e., kvm_ap_validate_queue_sharing(m1) and kvm_ap_set_crycb_masks(m1) - are static and only called from the kvm_ap_configure_matrix(m1), your scenario can never happen because vm2 will not get the lock until kvm_ap_configure_matrix(m1) has completed. I see your point, however, and maybe I should also acquire the kvm_lock. > > > Regards, > Halil > >> + >> + ret = kvm_ap_validate_queue_sharing(kvm, matrix); >> + if (ret) >> + goto done; >> + >> + kvm_ap_set_crycb_masks(kvm, matrix); >> + >> +done: >> + mutex_unlock(&kvm->lock); >> + >> + return ret; >> +} >> +EXPORT_SYMBOL(kvm_ap_configure_matrix); >> +