Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2130969imj; Fri, 8 Feb 2019 13:08:38 -0800 (PST) X-Google-Smtp-Source: AHgI3IZIHBZbriIjtLpYfmipPJwg8eBHsaeYd8EyWOwntO/CFGldLRihQeF84LybM+5m+hvWkmCa X-Received: by 2002:a62:2781:: with SMTP id n123mr24436589pfn.138.1549660118016; Fri, 08 Feb 2019 13:08:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549660118; cv=none; d=google.com; s=arc-20160816; b=PUjaU6bB7MG62RDh/TAZqfiF3cYr3GnpJ0/4GHHe4mGiNXY/UP/XPUqQ9HBeN+5MPt c35v9W2gKB0ufG4XsTBuJsb/18r2FgGirQdHRvNLFcSVNx4whe4hwLNrnRzHNZx9BFyo IQ5lc0QW9UamklUr+tpEbjfodGpmYMM9PTYVibYBBnU1GpjIQKSPRLSChIYbes39C5/t olDkHGafVQypVXnIx5U5IXYr/FxNoXE/naPbazl+gA7ZoPRgQwQeV3tpt5GBEgGjFxYh WDaA8KUiceqSQw7uGQ0iKOvc7jzByhqsRbIV9sMYI25kF8XQ9M1H0yzurEAq5rS1lawF bJ8g== 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=62nDTy6qKxNjZuFKmMcolNmapdGOF8KUclifVF9s4ss=; b=LNQOPHSoTHlXI7qoH5g5kmjSLDzmnOWm5rlp0SaBVEJqYC2He37G4jbdXHKmvBQyZD ZHVyrnGzyXTyclGtgth2VfD1eIav64jIWg2LCkiOD6pm7x6AhfducfafsNXAlovVgAev GmWtDqHro/mh9+/koaXTKx5yegQ3EFkHo+2Ra9DpPv/bWuwNnUEBt4WU2y5M/aAobqXt 7u/UtCVeENIFHSnIuTqCgEkTwd7zP/ANUo0dTTLJs0ROCNncVfP/TMG9L3XZA1YD5Jol zWu02BaBlhAhNbvEatQpehFlOlqWAV/xqB0YS+xHjxOfKkv76vtY1BDnh7by50Sg0izw 6xGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aQknJl3P; 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 r4si2868147pgv.245.2019.02.08.13.08.22; Fri, 08 Feb 2019 13:08:38 -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=aQknJl3P; 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 S1726916AbfBHVIA (ORCPT + 99 others); Fri, 8 Feb 2019 16:08:00 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:54752 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726222AbfBHVIA (ORCPT ); Fri, 8 Feb 2019 16:08:00 -0500 Received: by mail-it1-f194.google.com with SMTP id i145so12261347ita.4 for ; Fri, 08 Feb 2019 13:07:59 -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=62nDTy6qKxNjZuFKmMcolNmapdGOF8KUclifVF9s4ss=; b=aQknJl3PxepEEfkh8lTxd9hVg7YrUVyaqBRDtWyANCNqe32/dTUYZMs/Zh/6Rfn7e+ fJTXZKoMZJ4hsm3g47sDnI3EgsUdmVVRrWlDAstsPNK39d9TMZzehZch5P1vmAg/lJbp P1qR3Oa2DtYtZxAkirNFJYWQkmphkbTtW4Nf0KzaGEAMwQubf7YvGPPXPeY/tPhAf4eD 6o0Jt+LaRr1QHS3KN4msTHTMl0lGRrWgRCTDFNnATw059Iav/SblvEHAzd9UYjtjsSnc Ul/4qKyIF0dkSrTzo8ueYnwHlqRvEobM3ydJMKNEVkF5A8pOKX236F83Lo5OFBNJjI4G B7Og== 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=62nDTy6qKxNjZuFKmMcolNmapdGOF8KUclifVF9s4ss=; b=WpbTHY8d6JfgCpaWwJrn8IP0NtvCBphuyfwcU397K3apsr7TSyIjReTk6mxULu3ixz JoCRNorgRO6ORQpSOrTFD6XLPFBROryM4Yb+kDOCjvlviFkAgongfE9p/c1htcRJ2imR xLxhb0H/e/mU/h43Uq1Te/K4mdYVcfoBSwJLvJd680+6H1sCvnPYeeZ9Y21bRUFn57/D eN8HZu3BCXcJ4QIuBem1b1sK1dDV87E5aAxLhwCBuqKvGok77wn9YDpwrAomPw1N5ppz Vmwkl1skqk9jVM4Za38h5qlOmE9YOHrTrbDaK8INBKPngBejZpdyTeA3UsgCuVGS+YkN fdgQ== X-Gm-Message-State: AHQUAuZcwoJ+/XseK4MMofkjl1EKz5ZtKOlbnzlhbkNd5QYrREZErp/O uQtwUmZyR9C99IvTZY7W43OVwWnO1b8= X-Received: by 2002:a05:660c:b43:: with SMTP id m3mr306993itl.126.1549660078733; Fri, 08 Feb 2019 13:07:58 -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 s184sm1686900itb.44.2019.02.08.13.07.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Feb 2019 13:07:58 -0800 (PST) Date: Fri, 8 Feb 2019 05:01:12 -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 2/2] Drivers: hv: vmbus: Display nothing in sysfs if monitor_allocated not set Message-ID: <52d58fe5805f2ba2405c9091b4c86033d434d2b9.1549619051.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 If monitor pages are not allocated to a channel, the channel does not have a valid monitor id or valid monitor page data. In these cases, some of the "_show" functions display incorrect data. The "_show" functions that display monitor page data access and display data that is beyond the bounds of the hv_monitor_page array fields, which is obviously incorrect. The "_show" functions that display the monitor id display an invalid monitor id. 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, display nothing. Signed-off-by: Kimberly Brown --- Documentation/ABI/stable/sysfs-bus-vmbus | 9 ++++-- drivers/hv/vmbus_drv.c | 37 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus b/Documentation/ABI/stable/sysfs-bus-vmbus index 3fed8fdb873d..af52be4ffc5d 100644 --- a/Documentation/ABI/stable/sysfs-bus-vmbus +++ b/Documentation/ABI/stable/sysfs-bus-vmbus @@ -81,7 +81,8 @@ What: /sys/bus/vmbus/devices//channels//latency Date: September. 2017 KernelVersion: 4.14 Contact: Stephen Hemminger -Description: Channel signaling latency +Description: Channel signaling latency. If monitor pages are not allocated + to the channel, nothing is displayed. Users: Debugging tools What: /sys/bus/vmbus/devices//channels//out_mask @@ -95,7 +96,8 @@ 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. If monitor pages are not + allocated to the channel, nothing is displayed. Users: Debugging tools What: /sys/bus/vmbus/devices//channels//read_avail @@ -137,7 +139,8 @@ 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. If monitor pages are not + allocated to the channel, nothing is displayed. 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..c88a3623be56 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + 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 sprintf(buf, "\n"); + return sprintf(buf, "%u\n", channel->offermsg.monitorid); } static VMBUS_CHAN_ATTR(monitor_id, S_IRUGO, subchannel_monitor_id_show, NULL); -- 2.17.1