From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbdJRRzf (ORCPT ); Wed, 18 Oct 2017 13:55:35 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37650 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750932AbdJRRzc (ORCPT ); Wed, 18 Oct 2017 13:55:32 -0400 Subject: Re: [RFC 04/19] s390/zcrypt: create an AP matrix device on the AP matrix bus To: Cornelia Huck Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.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, qemu-s390x@nongnu.org, jjherne@linux.vnet.ibm.com, thuth@redhat.com, pasic@linux.vnet.ibm.com References: <1507916344-3896-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1507916344-3896-5-git-send-email-akrowiak@linux.vnet.ibm.com> <20171018182045.292bc5fd.cohuck@redhat.com> From: Tony Krowiak Date: Wed, 18 Oct 2017 13:54:34 -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: <20171018182045.292bc5fd.cohuck@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17101817-0008-0000-0000-000002929A58 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007915; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000237; SDB=6.00933000; UDB=6.00469895; IPR=6.00713291; BA=6.00005648; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017594; XFM=3.00000015; UTC=2017-10-18 17:54:39 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101817-0009-0000-0000-0000370C44FC Message-Id: <84a937c5-25dc-64c0-c0f9-84d278d12207@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-18_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710180246 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/18/2017 12:20 PM, Cornelia Huck wrote: > On Fri, 13 Oct 2017 13:38:49 -0400 > Tony Krowiak wrote: > > [Please take with a grain of salt as I did not yet have time to take > more than a very superficial glance at the whole structure.] > >> Creates a single AP matrix device on the AP matrix bus. >> The matrix device will be created as part of the AP matrix bus >> initialization. The matrix device will hold the AP queues that >> have been reserved for use by KVM guests. Mediated matrix devices >> can then be created for each guest. The mediated matrix devices can >> then be configured with a matrix of AP adapters, usage and >> control domains that will be made accessible to the guest. >> >> The sysfs location of the matrix device is: >> >> /sys/bus/ap_matrix >> ... [devices] >> ...... [matrix] > Also /sys/devices/ap_matrix/matrix, isn't it? Yes > >> Signed-off-by: Tony Krowiak >> --- >> drivers/s390/crypto/ap_matrix_bus.c | 54 +++++++++++++++++++++++++++++++++++ >> drivers/s390/crypto/ap_matrix_bus.h | 6 ++++ >> 2 files changed, 60 insertions(+), 0 deletions(-) >> >> diff --git a/drivers/s390/crypto/ap_matrix_bus.c b/drivers/s390/crypto/ap_matrix_bus.c >> index fbae175..4eb1e3c 100644 >> --- a/drivers/s390/crypto/ap_matrix_bus.c >> +++ b/drivers/s390/crypto/ap_matrix_bus.c >> @@ -12,6 +12,7 @@ >> >> #include >> #include >> +#include >> #include >> >> #include "ap_matrix_bus.h" >> @@ -21,13 +22,59 @@ >> MODULE_LICENSE("GPL v2"); >> >> #define AP_MATRIX_BUS_NAME "ap_matrix" >> +#define AP_MATRIX_DEV_TYPE_NAME "ap_matrix" >> +#define AP_MATRIX_DEV_NAME "matrix" >> >> static struct device *ap_matrix_root_device; >> +static struct ap_matrix *matrix; >> >> static struct bus_type ap_matrix_bus_type = { >> .name = AP_MATRIX_BUS_NAME, >> }; >> >> +static struct device_type ap_matrix_type = { >> + .name = AP_MATRIX_DEV_TYPE_NAME, >> +}; >> + >> +static void ap_matrix_dev_release(struct device *dev) >> +{ >> + struct ap_matrix *ap_matrix; >> + >> + ap_matrix = container_of(dev, struct ap_matrix, device); >> + >> + if (matrix == ap_matrix) >> + kfree(matrix); >> + >> + matrix = NULL; > This looks very, very odd. Refcounting should take care that the > release function is only invoked if the device is really gone. > > Also, I don't think you need to keep a pointer to the device as it is a > singleton: It's simply the only device on the list and you should be > able to easily pick it that way. If your code does not register further > devices on the bus, there won't be ambiguities. Okay, I'll make that change > >> +} >> + >> +static int ap_matrix_dev_create(void) >> +{ >> + int ret; >> + >> + matrix = kzalloc(sizeof(*matrix), GFP_KERNEL); >> + if (!matrix) >> + return -ENOMEM; >> + >> + matrix->device.type = &ap_matrix_type; >> + dev_set_name(&matrix->device, "%s", AP_MATRIX_DEV_NAME); >> + matrix->device.bus = &ap_matrix_bus_type; >> + matrix->device.parent = ap_matrix_root_device; >> + matrix->device.release = ap_matrix_dev_release; >> + >> + ret = device_register(&matrix->device); >> + if (ret) { >> + put_device(&matrix->device); >> + kfree(matrix); >> + matrix = NULL; > That's wrong. The release function needs to clean up the embedding > structure, so that kfree is at best useless and at worst wrong, if > something else grabbed a reference. Good point. > >> + return ret; >> + } >> + >> + get_device(&matrix->device); > Why should you need an extra reference here? I'd expect the code > hanging devices off this one to properly grab a reference, so you > should be all good? I'll remove this. > >> + >> + return 0; >> +} >> + >> int __init ap_matrix_init(void) >> { >> int ret; >> @@ -41,8 +88,15 @@ int __init ap_matrix_init(void) >> if (ret) >> goto bus_reg_err; >> >> + ret = ap_matrix_dev_create(); >> + if (ret) >> + goto matrix_create_err; >> + >> return 0; >> >> +matrix_create_err: >> + bus_unregister(&ap_matrix_bus_type); >> + >> bus_reg_err: >> root_device_unregister(ap_matrix_root_device);