Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp603152imm; Wed, 15 Aug 2018 02:53:58 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxZQPzjCnTt0tOijn+zVk/KscXvLtrURwYMPfiX8udJi9quh5Ut6KshIIP2CGirdVrqp5ms X-Received: by 2002:a17:902:9695:: with SMTP id n21-v6mr12051527plp.6.1534326838662; Wed, 15 Aug 2018 02:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534326838; cv=none; d=google.com; s=arc-20160816; b=kN3Lov40O+Yewydc+ExoaoMBYgXN8imfEPjmQYWfJEi2D2A1w7Q9bGgqFF7CzAftDj iV5VcwTtoBXFxC+JKuIZE8RgrKf4SlBK4nmmpsDTbQS9L4EgS+KwLQuWpOt2+7nzMjll nUEatpBCKy8piL4r+eoHp9hOORoiOyl42pNrtrYvX8YdQ44OxeBSuh6YMXZB/3aZuw+j UycLlWsFQL3JjArTuYgieJefhbxzwiq0BBYO8IIJWtvAZjaXJ+0jZgltbD7BxrbAHQ8y ynzZh2H3B8nfbr1Khf4PuQnzQXvkxVWgvjuUpMM+7XD7MQ/S70nzq9L80C0pK4LQsRlz VtAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=67LaTjU7VL2M5bi0pqcj3BJPd87lVS0fjS8dZPStmVE=; b=fPlWTpqBWyugOU7V582jGoOIuK/9a69sdDr2Q92GrqaqWw2pKhHNW9HXAeI9xM4KlV 8xtHzMa3TZjg7P0wRYCWdYOShqsj3Dd8A21kcELeQdQl2U3nt47yVPxDDZy0WuU+/lOn Ou/FMVmcs3uXx2ds9vUn+HN2ZVAe+7oFefQp1BfWp6VUozsdCG/uVW1qNhC4GufSbQYX lR5j828NaLh3Ro9zCT3CcgwRyG0Hg1TuFYi7PkcEOMqhB+BIhHNPSqRTKgsXkaxaW2cO 19MBnKWwUkmK2oN6KTP2Yc+EwflRAv69w6Btbcb3RSFUCv5IS15G/ontKxuZFLcY/3Ch nkUg== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l59-v6si17897452plb.519.2018.08.15.02.53.43; Wed, 15 Aug 2018 02:53:58 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729001AbeHOMoW (ORCPT + 99 others); Wed, 15 Aug 2018 08:44:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57770 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727141AbeHOMoW (ORCPT ); Wed, 15 Aug 2018 08:44:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 141598197039; Wed, 15 Aug 2018 09:52:52 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 936042166BA5; Wed, 15 Aug 2018 09:52:48 +0000 (UTC) Date: Wed, 15 Aug 2018 11:52:42 +0200 From: Cornelia Huck To: Tony Krowiak 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, 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, frankja@linux.ibm.com, Tony Krowiak Subject: Re: [PATCH v9 10/22] s390: vfio-ap: sysfs interfaces to configure adapters Message-ID: <20180815115242.35a2a1ce.cohuck@redhat.com> In-Reply-To: <1534196899-16987-11-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1534196899-16987-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1534196899-16987-11-git-send-email-akrowiak@linux.vnet.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 15 Aug 2018 09:52:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 15 Aug 2018 09:52:52 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 13 Aug 2018 17:48:07 -0400 Tony Krowiak wrote: > +/** > + * assign_adapter_store > + * > + * @dev: the matrix device > + * @attr: a mediated matrix device attribute > + * @buf: a buffer containing the adapter ID (APID) to be assigned > + * @count: the number of bytes in @buf > + * > + * Parses the APID from @buf and assigns it to the mediated matrix device. > + * > + * Returns the number of bytes processed if the APID is valid; otherwise returns > + * an error. > + */ > +static ssize_t assign_adapter_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + int ret = 0; You don't need to initialize this to 0, as kstrtoul will set it in any case. > + unsigned long apid; > + struct mdev_device *mdev = mdev_from_dev(dev); > + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); > + unsigned long max_apid = matrix_mdev->matrix.apm_max; > + > + ret = kstrtoul(buf, 0, &apid); > + if (ret) > + return ret; > + if (apid > max_apid) > + return -EINVAL; > + > + /* Set the bit in the AP mask (APM) corresponding to the AP adapter > + * number (APID). The bits in the mask, from most significant to least > + * significant bit, correspond to APIDs 0-255. > + */ > + mutex_lock(&matrix_dev.lock); > + > + ret = vfio_ap_mdev_verify_queues_reserved_for_apid(matrix_mdev, apid); That function name really is a mouthful :) I don't have any better suggestions, though. > + if (ret) > + goto done; > + > + set_bit_inv(apid, matrix_mdev->matrix.apm); > + > + ret = vfio_ap_mdev_verify_no_sharing(matrix_mdev); > + if (ret) > + goto share_err; > + > + ret = count; > + goto done; > + > +share_err: > + clear_bit_inv(apid, matrix_mdev->matrix.apm); > +done: > + mutex_unlock(&matrix_dev.lock); > + > + return ret; > +} > +static DEVICE_ATTR_WO(assign_adapter); > + > +/** > + * unassign_adapter_store > + * > + * @dev: the matrix device > + * @attr: a mediated matrix device attribute > + * @buf: a buffer containing the adapter ID (APID) to be assigned > + * @count: the number of bytes in @buf > + * > + * Parses the APID from @buf and unassigns it from the mediated matrix device. > + * The APID must be a valid value A valid value, but not necessarily assigned, right? > + * > + * Returns the number of bytes processed if the APID is valid; otherwise returns > + * an error. > + */ > +static ssize_t unassign_adapter_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + int ret; > + unsigned long apid; > + struct mdev_device *mdev = mdev_from_dev(dev); > + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); > + > + ret = kstrtoul(buf, 0, &apid); > + if (ret) > + return ret; > + > + if (apid > matrix_mdev->matrix.apm_max) > + return -EINVAL; > + > + mutex_lock(&matrix_dev.lock); > + clear_bit_inv((unsigned long)apid, matrix_mdev->matrix.apm); > + mutex_unlock(&matrix_dev.lock); > + > + return count; > +} > +DEVICE_ATTR_WO(unassign_adapter); In general, looks good to me.