Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp974268imm; Fri, 11 May 2018 09:08:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp/V1dtrtUZR3rEUP5twn7SKnw9ogNeA9iB4mlELFSNnIFMIixAUieZmlpz9VmqiNGUVfoN X-Received: by 2002:a17:902:704c:: with SMTP id h12-v6mr6047458plt.269.1526054925378; Fri, 11 May 2018 09:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526054925; cv=none; d=google.com; s=arc-20160816; b=BR/khmXQbepTVlmhjGKszytmJ24U5+RFxW20GCm6gfXQi8sVgawcxCKRfJUQ3DoQpm ZMXPBXYdJIsZLzsOBghDLdWk3kBIT5PHaJv5wUuHrh1+5kOOsEjx20ld0RoZNd1F0RMc Snsu6fScGyRwhW4jm9bjUERa4nwBbjidAGOZWlkaAcMj8LOwC9AZ2WPpXsaSl3adMM4W K3q3oxUVNEUKIfpUFFcAHYmS+686A52Dt0vBs9fTnbQDKT1SWdclJKCRRA5huCqdUEsx I76sC4mjYjmWQ6BvshB+FOcp9rNg+PaE0Ba+gdRrOgA4/sHXOYNyi3x99hscwiETpKvA CBJg== 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-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject:arc-authentication-results; bh=/VmZoyXKIgVjbouZdEYb08UwWaxNQWF0VXhgB0Bvrwo=; b=P3CGIeWfYeKyNwaCZmC8HaMoVff1MgCrGi3h5yKzSnov9pM/iZH3d54Uqd6PGIOTiz /RQGb76RAWb4Ph+AFusEBY8BS5K8awcsfZAO19XrR/2me/vsL6FUrEJVVz2++35uGZAd 5zwz5Oifw71rQRNWa5kcSH5P5d9t6RxJ8+Ydq6pSF5f9ssoF1nsvcNV5DQ1k4RhDS9O8 RRp9M/zipp8LjGuENI8lJaOM3MjpTWzcMSPCaLwtNyw5rozzYm9mFWdAtTUWjnvqVaDY 7fvruNIP+mTl/vj1HqAxNmosCXjjBBBCQnkEsfyAKCglGPPuONfIxwcZiD4weIEkAXVI dNHg== 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 z19-v6si3360719plo.174.2018.05.11.09.08.30; Fri, 11 May 2018 09:08:45 -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 S1751890AbeEKQIN (ORCPT + 99 others); Fri, 11 May 2018 12:08:13 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36726 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751489AbeEKQIL (ORCPT ); Fri, 11 May 2018 12:08:11 -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 w4BG6Xn4063980 for ; Fri, 11 May 2018 12:08:11 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hwdbgkbwv-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 11 May 2018 12:08:11 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 May 2018 17:08:08 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 11 May 2018 17:08:04 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4BG83XJ7602580; Fri, 11 May 2018 16:08:03 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D7A55204B; Fri, 11 May 2018 15:58:18 +0100 (BST) Received: from oc3836556865.ibm.com (unknown [9.152.224.46]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 744B452047; Fri, 11 May 2018 15:58:17 +0100 (BST) Subject: Re: [PATCH v5 06/13] KVM: s390: interfaces to manage guest's AP matrix To: Tony Krowiak , 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: Halil Pasic Date: Fri, 11 May 2018 18:08:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1525705912-12815-7-git-send-email-akrowiak@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 18051116-0008-0000-0000-000004F59E09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051116-0009-0000-0000-00001E89F173 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-11_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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805110151 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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); > +