Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2939369yba; Tue, 16 Apr 2019 00:55:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqykcqOJBuRl9Nx+9AlkaMlUOouaaaUgf3Y5BzLJa8e3Gi3AZF0R4t/6sNPSdmnKeRY3seSN X-Received: by 2002:a63:e304:: with SMTP id f4mr70724740pgh.374.1555401313828; Tue, 16 Apr 2019 00:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555401313; cv=none; d=google.com; s=arc-20160816; b=P5AxrXJ9pG45ykYse7xYYXCjyKnWnUBG/yljrMWNcf+VmmScZ/MB7VmKHQwCLB2yNX HZYMFyKQeq+Gxs5tPbwyYyDMPNN7lqU4zdhbheHWMfEXwp3yy5PLrpKUtSC2jqupGF9p xrrfL6EOGi9/vJ88p5CwY2xol1gyZEiT7c/jcSfNt/rGMMBTtBVKu4pWbDuwxzqwfUkB hhVtGvqE8FGwYo1Hj3kUHPJ7u4/MUX3onwUWPIRiC7L6xpt9/+8GwLguZwMJsDikkIiN H+0CPwXyapRyLqDRoofR4X8LVOSy9ZdKbLKrj/lJzMrDBz8F8CtMqzJmUTKsD+OFpFIr y76w== 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:reply-to; bh=pLKn/C9O6B1Uggul9aozRCax6tbkpNZ0c9wxGX8hQgI=; b=1Hlos40mVd2oFNCHgXnxTHOJewu/taz5xH7+Kk8aer2oklusN609BSzV0a8hMDEcpA /sVsuAmYcfmffZkqhmQb1wgXtmczB9/s5nvJ1ylzFjOzlCmXt3LcJ4tl5GjECx9ug0QR aD1MPpk4dEu9HUo/4VWqtymPTJBcROCZedmn+PW79eyAO8Z7KgMd0ImQwXwgMk2MaL6f QKz3MbqQfq/ymE8U+jk5tzCmC8/AaEiRDxHBQp303hDs3XkPcUQTckLdx19tfseQFsLv aQN9jMEGt0sneKGIcqHncsNMvnaOdzKunkfDjCwvyNrpxrPhCfVKJp4vgxFcryp02Wxn x3cQ== 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 n1si32300290pld.280.2019.04.16.00.54.57; Tue, 16 Apr 2019 00:55:13 -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 S1728622AbfDPHwg (ORCPT + 99 others); Tue, 16 Apr 2019 03:52:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44524 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727856AbfDPHwg (ORCPT ); Tue, 16 Apr 2019 03:52:36 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3G7iYVh010585 for ; Tue, 16 Apr 2019 03:52:34 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rw8xs59wm-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 16 Apr 2019 03:52:34 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Apr 2019 08:52:32 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 16 Apr 2019 08:52:29 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3G7qRcN31457382 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 07:52:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FAE8A4053; Tue, 16 Apr 2019 07:52:27 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC35EA404D; Tue, 16 Apr 2019 07:52:26 +0000 (GMT) Received: from [9.152.222.226] (unknown [9.152.222.226]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 16 Apr 2019 07:52:26 +0000 (GMT) Reply-To: pmorel@linux.ibm.com Subject: Re: [PATCH 1/7] s390: zcrypt: driver callback to indicate resource in use To: Tony Krowiak , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: freude@linux.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, frankja@linux.ibm.com, david@redhat.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, pasic@linux.ibm.com, alex.williamson@redhat.com, kwankhede@nvidia.com References: <1555016604-2008-1-git-send-email-akrowiak@linux.ibm.com> <1555016604-2008-2-git-send-email-akrowiak@linux.ibm.com> From: Pierre Morel Date: Tue, 16 Apr 2019 09:52:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <1555016604-2008-2-git-send-email-akrowiak@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19041607-0016-0000-0000-0000026F4A20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041607-0017-0000-0000-000032CB92F1 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-16_02:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160054 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/04/2019 23:03, Tony Krowiak wrote: > Introduces a new driver callback to prevent a root user from unbinding > an AP queue from its device driver if the queue is in use. This prevents > a root user from inadvertently taking a queue away from a guest and > giving it to the host, or vice versa. The callback will be invoked > whenever a change to the AP bus's apmask or aqmask sysfs interfaces may > result in one or more AP queues being removed from its driver. If the > callback responds in the affirmative for any driver queried, the change > to the apmask or aqmask will be rejected with a device in use error. > > For this patch, only non-default drivers will be queried. Currently, > there is only one non-default driver, the vfio_ap device driver. The > vfio_ap device driver manages AP queues passed through to one or more > guests and we don't want to unexpectedly take AP resources away from > guests which are most likely independently administered. > > Signed-off-by: Tony Krowiak > --- > drivers/s390/crypto/ap_bus.c | 138 +++++++++++++++++++++++++++++++++++++++++-- > drivers/s390/crypto/ap_bus.h | 3 + > 2 files changed, 135 insertions(+), 6 deletions(-) > > diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c > index 1546389d71db..66a5a9d9fae6 100644 > --- a/drivers/s390/crypto/ap_bus.c > +++ b/drivers/s390/crypto/ap_bus.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > > #include "ap_bus.h" > #include "ap_debug.h" > @@ -980,9 +981,11 @@ int ap_parse_mask_str(const char *str, > newmap = kmalloc(size, GFP_KERNEL); > if (!newmap) > return -ENOMEM; > - if (mutex_lock_interruptible(lock)) { > - kfree(newmap); > - return -ERESTARTSYS; > + if (lock) { > + if (mutex_lock_interruptible(lock)) { > + kfree(newmap); > + return -ERESTARTSYS; > + } > } > > if (*str == '+' || *str == '-') { > @@ -994,7 +997,10 @@ int ap_parse_mask_str(const char *str, > } > if (rc == 0) > memcpy(bitmap, newmap, size); > - mutex_unlock(lock); > + > + if (lock) > + mutex_unlock(lock); > + > kfree(newmap); > return rc; > } > @@ -1181,12 +1187,72 @@ static ssize_t apmask_show(struct bus_type *bus, char *buf) > return rc; > } > > +static int __verify_card_reservations(struct device_driver *drv, void *data) > +{ > + int rc = 0; > + struct ap_driver *ap_drv = to_ap_drv(drv); > + unsigned long *newapm = (unsigned long *)data; > + > + /* > + * If the reserved bits do not identify cards reserved for use by the > + * non-default driver, there is no need to verify the driver is using > + * the queues. > + */ > + if (ap_drv->flags & AP_DRIVER_FLAG_DEFAULT) > + return 0; I prefer you suppress this asymmetry with the assumption that the "default driver" will not register a "in_use" callback. > + > + /* Pin the driver's module code */ > + if (!try_module_get(drv->owner)) > + return 0; > + > + if (ap_drv->in_use) > + if (ap_drv->in_use(newapm, ap_perms.aqm)) > + rc = -EADDRINUSE; > + > + module_put(drv->owner); > + > + return rc; > +} > + -- Pierre Morel Linux/KVM/QEMU in Böblingen - Germany