Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3168230imu; Mon, 17 Dec 2018 14:42:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/UOjHnDVjyAauRRbNXqs/WmnOK/gzjg/O2cc+I3i5lrxUUvg8aejjn8z8rXoLL1FTIY/Omn X-Received: by 2002:a17:902:6bc9:: with SMTP id m9mr14006711plt.173.1545086567947; Mon, 17 Dec 2018 14:42:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545086567; cv=none; d=google.com; s=arc-20160816; b=r3jEkZAy6kYqEcY8RY1zTypEdCDJ2m1L+ZFassSA/gyFF1ROsQcuq2rll+hqj1WfHj 19HhElMJbgSWFmeH9uhrfM2KBB37167TalYdocGjK6JoepC5M2wdvVIthW64XGJXcW/c Ck1qr+DckceDOEE9BJDJyFVidGNxZbzR2Ujz8extFA8WJmJiJyN+F5rukla8vWazufa3 LsSDOERB+7m+QqE5TP/gNrcUSLqq7EE4SFy1ZXXJqLM1YUA1EkXWR9gIhoMuV1EACy/9 X/DtMbDLoy1hnhhbQcheuFYXHRtn9a02b4eKcq61DLdWuWTGxJnmNNGheFK/fXs7GPVs /Ntw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=kkfcbf586gQhuhWbJ/CjJr0JrDh12V7PDJAswCw8ShU=; b=RBc/AK13i3GjM9TA8UcgDzQg2ujItLLncyYqSpySSKgUmFXGK4KsaNg1hYxBl5mKwx +LLMRuseEI6LZ3gNNSwlF9IkLun8ITXqVNsyArXyZbKSZ+kebTaHLsDZy3geqW4ldnRA Y9KQXnYGbfPciCZX45PM4S2ef/LIx6yb82EUYfa3GAhE5m7rRQJvKuSDO2j9FpDH1SFw GwOrYM03PL+H+6RiFasBac3/O78JDaLJ1Pxc1dCDr6tczlFyvPrfVEXyNi8fFjo5hafb +vklj2qVnt12+orztEbRopOdtO3n7R+psayhNlCI+4Fq4L4nXNz7Gx/cNy8Y37eHjLN2 Q4UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@networkplumber-org.20150623.gappssmtp.com header.s=20150623 header.b=nGIJb0pI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e16si11788646pge.364.2018.12.17.14.42.32; Mon, 17 Dec 2018 14:42:47 -0800 (PST) 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; dkim=pass header.i=@networkplumber-org.20150623.gappssmtp.com header.s=20150623 header.b=nGIJb0pI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732960AbeLQRPp (ORCPT + 99 others); Mon, 17 Dec 2018 12:15:45 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39083 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727315AbeLQRPp (ORCPT ); Mon, 17 Dec 2018 12:15:45 -0500 Received: by mail-pl1-f196.google.com with SMTP id 101so6436402pld.6 for ; Mon, 17 Dec 2018 09:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kkfcbf586gQhuhWbJ/CjJr0JrDh12V7PDJAswCw8ShU=; b=nGIJb0pIzkcj1mU7Oan7wzRB5g9TwwGYfl0rU0d572v0MlDWFK5fPAQK2RAvnnAJMF XnI3q/OJHHFsQsV1s5exereUsS0pcsjpdwrAgyn/LjjfLQt5pWcY5ZH2wwN/OSnGg5P5 3pxhhYMhFqCEqa4p38Tdfyn9MDgwGrKIczkR5+YM+cJDGwcmsINCaz+8te13I0qkolGM FiJ7SMaQy4hxPVlXLoIoD/P8/WwLIAzD9J51ry0h9vFwRE0u4HKQx/gcmDgCZkHn3DKS AinxNwUUUSomEo2FDAFSV2aRVdg9j2f8UIw4nkLCaa6HTSGfQooIQQwA86HOzaF3uNNq gi8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kkfcbf586gQhuhWbJ/CjJr0JrDh12V7PDJAswCw8ShU=; b=Llv9ysI0JicbVRd49giYNM8eFYsBZHpA2/G2UQxmXYzOSSx3SUio7fPplHzG+69UaA LsqvWFphrEkPC1tRBFmI3FflQcLzWoWpgcN/iBSbpel1hI6eha8LSpHFj5BK4+qz13zM 4GD8HPBnJSaD+PZZsUzP/xKQfTP9atkwt1Wyng/Oc5pdWg+zD4WbAcNCObx064AUFEqW +l8KUWOMUjccvboufNiH41lF4oevIILuZsxwcx0GsOgF9WLtDApRGTjyh/WIW8hoYllF pD/4sm154EN1J0e2X0D9xSztuY1PlyWjT2YazaCUWpbtKZiaaFBxxr05SLWrrpkUPq3K MVyQ== X-Gm-Message-State: AA+aEWY+1c5X4SH36Q299qswU9GW2VDR+w+k5VZubyRsdT6JQ4R2Cb0E T/bOTF1cnoeKXN8kUo4azsGDMw== X-Received: by 2002:a17:902:a03:: with SMTP id 3mr13525827plo.112.1545066943925; Mon, 17 Dec 2018 09:15:43 -0800 (PST) Received: from xeon-e3 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id b26sm27597337pfe.91.2018.12.17.09.15.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Dec 2018 09:15:43 -0800 (PST) Date: Mon, 17 Dec 2018 09:15:36 -0800 From: Stephen Hemminger To: Dexuan Cui Cc: "'gregkh@linuxfoundation.org'" , KY Srinivasan , Haiyang Zhang , "'linux-kernel@vger.kernel.org'" , "'devel@linuxdriverproject.org'" , "'olaf@aepfle.de'" , "'jasowang@redhat.com'" , Michael Kelley , Sasha Levin , "'apw@canonical.com'" , vkuznets Subject: Re: [PATCH] Drivers: hv: vmbus: Return -EINVAL for the sys files for unopened channels Message-ID: <20181217091518.5004d4c7@xeon-e3> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Dec 2018 16:35:43 +0000 Dexuan Cui wrote: > Before 98f4c651762c, we returned zeros for unopened channels. > With 98f4c651762c, we started to return random on-stack values. >=20 > We'd better return -EINVAL instead. >=20 > Fixes: 98f4c651762c ("hv: move ringbuffer bus attributes to dev_groups") > Cc: stable@vger.kernel.org > Cc: K. Y. Srinivasan > Cc: Haiyang Zhang > Cc: Stephen Hemminger > Signed-off-by: Dexuan Cui The concept looks fine, but maybe it would be simpler to move it into hv_ringbuffer_get_debuginfo and have it return an error code. Since so much of the code is repeated, I would probably make a macro which generates the code as well. Something like this: =46rom c6bbdbcde933c85098f7b3e71650a8479d52810c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 17 Dec 2018 09:13:24 -0800 Subject: [PATCH] hv: vmbus: check for ring in debug info --- drivers/hv/ring_buffer.c | 31 +++++++++--------- drivers/hv/vmbus_drv.c | 71 ++++++++++++++++++++++++++++++++++------ include/linux/hyperv.h | 5 +-- 3 files changed, 79 insertions(+), 28 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 64d0c85d5161..1f1a55e07733 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -164,26 +164,25 @@ hv_get_ringbuffer_availbytes(const struct hv_ring_buf= fer_info *rbi, } =20 /* Get various debug metrics for the specified ring buffer. */ -void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_in= fo, - struct hv_ring_buffer_debug_info *debug_info) +int hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_inf= o, + struct hv_ring_buffer_debug_info *debug_info) { u32 bytes_avail_towrite; u32 bytes_avail_toread; =20 - if (ring_info->ring_buffer) { - hv_get_ringbuffer_availbytes(ring_info, - &bytes_avail_toread, - &bytes_avail_towrite); - - debug_info->bytes_avail_toread =3D bytes_avail_toread; - debug_info->bytes_avail_towrite =3D bytes_avail_towrite; - debug_info->current_read_index =3D - ring_info->ring_buffer->read_index; - debug_info->current_write_index =3D - ring_info->ring_buffer->write_index; - debug_info->current_interrupt_mask =3D - ring_info->ring_buffer->interrupt_mask; - } + if (!ring_info->ring_buffer) + return -EINVAL; + + hv_get_ringbuffer_availbytes(ring_info, + &bytes_avail_toread, + &bytes_avail_towrite); + debug_info->bytes_avail_toread =3D bytes_avail_toread; + debug_info->bytes_avail_towrite =3D bytes_avail_towrite; + debug_info->current_read_index =3D ring_info->ring_buffer->read_index; + debug_info->current_write_index =3D ring_info->ring_buffer->write_index; + debug_info->current_interrupt_mask + =3D ring_info->ring_buffer->interrupt_mask; + return 0; } EXPORT_SYMBOL_GPL(hv_ringbuffer_get_debuginfo); =20 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 283d184280af..403fee01572c 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -313,10 +313,16 @@ static ssize_t out_intr_mask_show(struct device *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, + &outbound); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", outbound.current_interrupt_mask); } static DEVICE_ATTR_RO(out_intr_mask); @@ -326,10 +332,15 @@ static ssize_t out_read_index_show(struct device *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, + &outbound); + if (ret < 0) + return ret; return sprintf(buf, "%d\n", outbound.current_read_index); } static DEVICE_ATTR_RO(out_read_index); @@ -340,10 +351,15 @@ static ssize_t out_write_index_show(struct device *de= v, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, + &outbound); + if (ret < 0) + return ret; return sprintf(buf, "%d\n", outbound.current_write_index); } static DEVICE_ATTR_RO(out_write_index); @@ -354,10 +370,15 @@ static ssize_t out_read_bytes_avail_show(struct devic= e *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, + &outbound); + if (ret < 0) + return ret; return sprintf(buf, "%d\n", outbound.bytes_avail_toread); } static DEVICE_ATTR_RO(out_read_bytes_avail); @@ -368,10 +389,15 @@ static ssize_t out_write_bytes_avail_show(struct devi= ce *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info outbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, + &outbound); + if (ret < 0) + return ret; return sprintf(buf, "%d\n", outbound.bytes_avail_towrite); } static DEVICE_ATTR_RO(out_write_bytes_avail); @@ -381,10 +407,15 @@ static ssize_t in_intr_mask_show(struct device *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", inbound.current_interrupt_mask); } static DEVICE_ATTR_RO(in_intr_mask); @@ -394,10 +425,15 @@ static ssize_t in_read_index_show(struct device *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", inbound.current_read_index); } static DEVICE_ATTR_RO(in_read_index); @@ -407,10 +443,15 @@ static ssize_t in_write_index_show(struct device *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", inbound.current_write_index); } static DEVICE_ATTR_RO(in_write_index); @@ -421,10 +462,15 @@ static ssize_t in_read_bytes_avail_show(struct device= *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", inbound.bytes_avail_toread); } static DEVICE_ATTR_RO(in_read_bytes_avail); @@ -435,10 +481,15 @@ static ssize_t in_write_bytes_avail_show(struct devic= e *dev, { struct hv_device *hv_dev =3D device_to_hv_device(dev); struct hv_ring_buffer_debug_info inbound; + int ret; =20 if (!hv_dev->channel) return -ENODEV; - hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + + ret =3D hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", inbound.bytes_avail_towrite); } static DEVICE_ATTR_RO(in_write_bytes_avail); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 14131b6fae68..ed74888087f1 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1176,8 +1176,9 @@ struct hv_ring_buffer_debug_info { u32 bytes_avail_towrite; }; =20 -void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_in= fo, - struct hv_ring_buffer_debug_info *debug_info); + +int hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_inf= o, + struct hv_ring_buffer_debug_info *debug_info); =20 /* Vmbus interface */ #define vmbus_driver_register(driver) \ --=20 2.19.2