Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3166696imj; Mon, 18 Feb 2019 21:39:36 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia8NHao/oSQvfKDe0g5J3we6nX7UsMZrw3jwf9PQfjRqNakH0xKNUKdfJHUSD8seRoQpXLG X-Received: by 2002:a63:1321:: with SMTP id i33mr22607811pgl.380.1550554776731; Mon, 18 Feb 2019 21:39:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550554776; cv=none; d=google.com; s=arc-20160816; b=uXfCdnAJ0ys/pfJnlwTTXGM6Kj7IPX0wzipdnAK3NmC4U378bT2sJ0ZIWQ9xg9pt3j kuFH09bqO7v7jvm0dsAbH7902Yp5xZJbQZ+Oo7AM8jXV9FxxVs+PpJ0/MsmKOrUbVywL EfQzdo4S2DA96PTbnROy+WnoJI7b2WmXxciPMftwOHMxkquQ3flnY1oX+yc/sCJ1km6g QPfg7Gtfw0R/i29WtOWBNcnrjuyEb2Ft6QnO+ReV6joG2CPUjtxtBBYL7wcmHq1xIRzD EPv7wlAvLW932XXya1/eyYYnsIX8yU7f2ewpsXc0FE0yezrSO3ELWZDfOijXJz9WtWbw CJWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ilYZg60tYK0PECjdORWVcIr1d8PImYmY8jAy7jBal6Y=; b=r7xBT8pLOrKjlbaDM/a3eTulDLj9RqLj0o6tjK4jWh5+GjPKgznTq1Um9gO9LKZZkZ rL+0bXhXJM9LHQjottZuX2n6YC2uGR+9yhgJUZ2xugJO3JxqE/KS9r3GhkNdq4/DNA4f xBgDcUaKiEz5DjFhZl3oqWxnDpdQ2W6gKa1w3ZlKFF+sQV6xQOOZA1HuVEoR6i0vSMhu NWHcGaUQ+8JqARJIsXSEGcCeh9i8JmSX/RjrdC62tu265UESVW+6tu4RO5JdTeJWoV8P Z8XqQqXzcvfiObbYTv8pZLCPUx1CH0wUbqRir3dMRuj3Rz0x4bdEQCNGC5TxOXTvNDvL zi/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pGWoiJrV; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si15813835plg.408.2019.02.18.21.39.22; Mon, 18 Feb 2019 21:39:36 -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=@gmail.com header.s=20161025 header.b=pGWoiJrV; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726469AbfBSFiV (ORCPT + 99 others); Tue, 19 Feb 2019 00:38:21 -0500 Received: from mail-it1-f195.google.com ([209.85.166.195]:52839 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725763AbfBSFiU (ORCPT ); Tue, 19 Feb 2019 00:38:20 -0500 Received: by mail-it1-f195.google.com with SMTP id r11so3420970itc.2 for ; Mon, 18 Feb 2019 21:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ilYZg60tYK0PECjdORWVcIr1d8PImYmY8jAy7jBal6Y=; b=pGWoiJrVPeVK+SNlwyIhC4nX1BDcdy+m4Y2saPpCrIry0ZmKpZRczlkXm07rcGRly4 0yVZwVirglObDOclnIg6gQC7Al1p7+Df89N4LsknO4OX72wDxwkntb9E/fmEbEQTDfSs UUYWlbB8d1CQc4CAxGHT+zIw9Ov7LlU6g36UPamVnlWEWCfAs9vm5jLmIGgSnFDQfkEV gJWJ7SAQEG2NZkuydmxZ4UuQdJCtZnWh0qAVhrAlBFB1SKjvbpiL9zMnL08ypVLmT8u3 sSAevHzm243f6PSWdF7NdWNoAn+qBnaHBNhrdjspMl7bKpwGGqF0hApKoLaQ1i+0/LC8 eUgw== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ilYZg60tYK0PECjdORWVcIr1d8PImYmY8jAy7jBal6Y=; b=XEOMxCMVVtmhOawH6oFWmQrtYmEh6/k+Kuq1Ohrnlbcw094LzZOfGqINpJF6x4MVDf woEKmRz2ucRNPOV5ZnzHLwMXk9uRKfLli1J/uflxdZoyQOc+86dd7guBl2vnyCtnBCjA ruCBo0KVDfgSZnQs7/XAO4OSYqeqlwyiqzdqXXEFpsdOsp1JnGl2Li5lHgn386NoIunp +mGL/v3uMK3Szymyn5T/DjbL3/kUVp2vJH8OvbW0Q5OhFqqOjQlk/P1qSqvks4UUPmsb 0toAGE4YAo/5MWGNLco7o5Eiz7IMPpVkD7G1qGnT2t2amWpV1cgZ7cFAJep0PQBiMkma OFmw== X-Gm-Message-State: AHQUAuZ0Nd6cUUD3A15b3ZQnBCtPMS68O+nqxbV+SknChSDL6EDlVvOH g7MAJm0kqlvGoZwu1lzlPRM= X-Received: by 2002:a5e:8d13:: with SMTP id m19mr14540346ioj.43.1550554699418; Mon, 18 Feb 2019 21:38:19 -0800 (PST) Received: from ubu-Virtual-Machine (66-188-57-61.dhcp.bycy.mi.charter.com. [66.188.57.61]) by smtp.gmail.com with ESMTPSA id y190sm745946itb.26.2019.02.18.21.38.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 21:38:18 -0800 (PST) Date: Tue, 19 Feb 2019 00:38:16 -0500 From: Kimberly Brown To: Michael Kelley , Long Li , Sasha Levin , Stephen Hemminger , Dexuan Cui Cc: "K. Y. Srinivasan" , Haiyang Zhang , devel@linuxdriverproject.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] Drivers: hv: vmbus: Return -EINVAL if monitor_allocated not set Message-ID: <7481d15f52427917a5f620e29308c1aa5c63f3eb.1550554279.git.kimbrownkd@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two methods for signaling the host: the monitor page mechanism and hypercalls. The monitor page mechanism is used by performance critical channels (storage, networking, etc.) because it provides improved throughput. However, latency is increased. Monitor pages are allocated to these channels. Monitor pages are not allocated to channels that do not use the monitor page mechanism. Therefore, these channels do not have a valid monitor id or valid monitor page data. In these cases, some of the "_show" functions return incorrect data. They return an invalid monitor id and data that is beyond the bounds of the hv_monitor_page array fields. The "channel->offermsg.monitor_allocated" value can be used to determine whether monitor pages have been allocated to a channel. In the affected "_show" functions, verify that "channel->offermsg.monitor_allocated" is set before accessing the monitor id or the monitor page data. If "channel->offermsg.monitor_allocated" is not set, return -EINVAL. Signed-off-by: Kimberly Brown --- Documentation/ABI/stable/sysfs-bus-vmbus | 15 ++++++++-- drivers/hv/vmbus_drv.c | 37 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus b/Documentation/ABI/stable/sysfs-bus-vmbus index 3fed8fdb873d..9e8a7a29b3ff 100644 --- a/Documentation/ABI/stable/sysfs-bus-vmbus +++ b/Documentation/ABI/stable/sysfs-bus-vmbus @@ -81,7 +81,10 @@ What: /sys/bus/vmbus/devices//channels//latency Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger -Description: Channel signaling latency +Description: Channel signaling latency. The monitor page mechanism is used + for performance critical channels (storage, network, etc.). + Channels that do not use the monitor page mechanism will return + EINVAL. Users: Debugging tools What: /sys/bus/vmbus/devices//channels//out_mask @@ -95,7 +98,10 @@ What: /sys/bus/vmbus/devices//channels//pending Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger -Description: Channel interrupt pending state +Description: Channel interrupt pending state. The monitor page mechanism is + used for performance critical channels (storage, network, + etc.). Channels that do not use the monitor page mechanism will + return EINVAL. Users: Debugging tools What: /sys/bus/vmbus/devices//channels//read_avail @@ -137,7 +143,10 @@ What: /sys/bus/vmbus/devices//channels//monitor_id Date: January. 2018 KernelVersion: 4.16 Contact: Stephen Hemminger -Description: Monitor bit associated with channel +Description: Monitor bit associated with channel. The monitor page mechanism + is used for performance critical channels (storage, network, + etc.). Channels that do not use the monitor page mechanism will + return EINVAL. Users: Debugging tools and userspace drivers What: /sys/bus/vmbus/devices//channels//ring diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index f2a79f5129d7..0ff9a09a3f71 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -171,6 +171,10 @@ static ssize_t monitor_id_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", hv_dev->channel->offermsg.monitorid); } static DEVICE_ATTR_RO(monitor_id); @@ -232,6 +236,10 @@ static ssize_t server_monitor_pending_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_pending(hv_dev->channel, vmbus_connection.monitor_pages[0])); @@ -246,6 +254,10 @@ static ssize_t client_monitor_pending_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_pending(hv_dev->channel, vmbus_connection.monitor_pages[1])); @@ -260,6 +272,10 @@ static ssize_t server_monitor_latency_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_latency(hv_dev->channel, vmbus_connection.monitor_pages[0])); @@ -274,6 +290,10 @@ static ssize_t client_monitor_latency_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_latency(hv_dev->channel, vmbus_connection.monitor_pages[1])); @@ -288,6 +308,10 @@ static ssize_t server_monitor_conn_id_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_conn_id(hv_dev->channel, vmbus_connection.monitor_pages[0])); @@ -302,6 +326,10 @@ static ssize_t client_monitor_conn_id_show(struct device *dev, if (!hv_dev->channel) return -ENODEV; + + if (!hv_dev->channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_conn_id(hv_dev->channel, vmbus_connection.monitor_pages[1])); @@ -1469,6 +1497,9 @@ static VMBUS_CHAN_ATTR(cpu, S_IRUGO, show_target_cpu, NULL); static ssize_t channel_pending_show(const struct vmbus_channel *channel, char *buf) { + if (!channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_pending(channel, vmbus_connection.monitor_pages[1])); @@ -1478,6 +1509,9 @@ static VMBUS_CHAN_ATTR(pending, S_IRUGO, channel_pending_show, NULL); static ssize_t channel_latency_show(const struct vmbus_channel *channel, char *buf) { + if (!channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%d\n", channel_latency(channel, vmbus_connection.monitor_pages[1])); @@ -1499,6 +1533,9 @@ static VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL); static ssize_t subchannel_monitor_id_show(const struct vmbus_channel *channel, char *buf) { + if (!channel->offermsg.monitor_allocated) + return -EINVAL; + return sprintf(buf, "%u\n", channel->offermsg.monitorid); } static VMBUS_CHAN_ATTR(monitor_id, S_IRUGO, subchannel_monitor_id_show, NULL); -- 2.17.1