From patchwork Wed Sep 30 09:09:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 7293781 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 560F89F1D5 for ; Wed, 30 Sep 2015 09:09:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DF7E2068E for ; Wed, 30 Sep 2015 09:09:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91A0920687 for ; Wed, 30 Sep 2015 09:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754837AbbI3JJa (ORCPT ); Wed, 30 Sep 2015 05:09:30 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:38522 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754738AbbI3JJY (ORCPT ); Wed, 30 Sep 2015 05:09:24 -0400 Received: by wiclk2 with SMTP id lk2so51665032wic.1 for ; Wed, 30 Sep 2015 02:09:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MGqGKsxYteIVYtXkig+WPfaYg9LKjoJI9CzA6b/VsJ0=; b=ativeLLZf+yjzfDI6egpXpIK2KAFKfe5gVVu5PeUrDJ3GrQOxJJnomMv10jXq2OLUO BU21ycuWP6Xz/qWN/es+AWbabD7cFwxQr5kE06wxffp1KLqC45jnwotCScC/cZKTz1V1 XXikWWy7hr9KqeWGFLVvOZM3EAGvCzHmM402lojyLMW/QC13K4q2TNcKArSg6BHLcmXe r6irQ+WPFTD2id1UouhGMaPlbOgfiQ7pwrRkphM+DzVu5QSEgcLUF07FqJ8hDf7Drya3 pdHuiq+xWpUYll9fOczZEMTw0cAwzrROA81lxwybY40eIUX3AqARez5DuKb2ABwMUTce fwJw== X-Gm-Message-State: ALoCoQl1zLZ0BS8moSVWbiAENzNg6NsdR3Drp9piUmJMPbsSqoyz0tCjqxkp/j6cB/1KqpODvzL8 X-Received: by 10.180.182.84 with SMTP id ec20mr3576950wic.42.1443604163269; Wed, 30 Sep 2015 02:09:23 -0700 (PDT) Received: from localhost (ip-31.net-81-220-164.nice.rev.numericable.fr. [81.220.164.31]) by smtp.gmail.com with ESMTPSA id w1sm102207wjz.37.2015.09.30.02.09.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Sep 2015 02:09:22 -0700 (PDT) From: Baptiste Reynal To: kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org, alex.williamson@redhat.com, christoffer.dall@linaro.org, eric.auger@linaro.org Cc: tech@virtualopensystems.com, kvm@vger.kernel.org (open list:VFIO PLATFORM DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [RFC PATCH v5 3/3] vfio: platform: return device properties as arrays of unsigned integers Date: Wed, 30 Sep 2015 11:09:07 +0200 Message-Id: <1443604149-3242-3-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.6.0 In-Reply-To: <1443604149-3242-1-git-send-email-b.reynal@virtualopensystems.com> References: <1443604149-3242-1-git-send-email-b.reynal@virtualopensystems.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antonios Motakis Certain properties of a device are accessible as an array of unsigned integers, either u64, u32, u16, or u8. Let the VFIO user query this type of device properties. Signed-off-by: Antonios Motakis Signed-off-by: Baptiste Reynal --- v4 -> v5: - fix return error when the buffer size is too small --- drivers/vfio/platform/properties.c | 62 +++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/platform/properties.c b/drivers/vfio/platform/properties.c index 212755f..a4b6955 100644 --- a/drivers/vfio/platform/properties.c +++ b/drivers/vfio/platform/properties.c @@ -70,7 +70,67 @@ static int dev_property_get_uint(struct device *dev, char *name, uint32_t type, unsigned *lenp, void __user *datap, unsigned long datasz) { - return -EINVAL; + int ret, n; + u8 *out; + size_t sz; + int (*func)(const struct device *, const char *, void *, size_t) + = NULL; + + switch (type) { + case VFIO_DEV_PROPERTY_TYPE_U64: + sz = sizeof(u64); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u64_array; + break; + case VFIO_DEV_PROPERTY_TYPE_U32: + sz = sizeof(u32); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u32_array; + break; + case VFIO_DEV_PROPERTY_TYPE_U16: + sz = sizeof(u16); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u16_array; + break; + case VFIO_DEV_PROPERTY_TYPE_U8: + sz = sizeof(u8); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u8_array; + break; + + default: + return -EINVAL; + } + + /* get size of array */ + n = func(dev, name, NULL, 0); + if (n < 0) + return n; + + if (lenp) + *lenp = n * sz; + + if (n * sz > datasz) + return -ENOSPC; + + out = kcalloc(n, sz, GFP_KERNEL); + if (!out) + return -ENOMEM; + + ret = func(dev, name, out, n); + if (ret) + goto out; + + if (copy_to_user(datap, out, n * sz)) + ret = -EFAULT; + +out: + kfree(out); + return ret; } int vfio_platform_dev_properties(struct device *dev,