Received: by 10.223.185.116 with SMTP id b49csp1632278wrg; Sun, 11 Feb 2018 17:15:45 -0800 (PST) X-Google-Smtp-Source: AH8x227HNenTpW7ZZa4jGmYQtuxFJRsoTrGhfEcJ5im9F+9sZ5ymkm/L7k+5XdN+fWK2csf06uqm X-Received: by 10.101.72.199 with SMTP id o7mr2396026pgs.303.1518398145563; Sun, 11 Feb 2018 17:15:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518398145; cv=none; d=google.com; s=arc-20160816; b=NqKA5ZEXSavvxksDeTde8aSBhFQS57dkATGVUw2OtAXy2bjk1EsHTqTiz/Y9P1ima2 B9e6GZtxmOlhi/483s0gvRpVEeNTWNGnp6EcnUfNbV27osLvHT9DLUmuK1ovCBWKHEiT TPzL9RpajgbD7QHEA/zoUCjON7ZJpURjzp138weZctB7xfgvH/2gX7r98QObLOK/7d8g 1cWDWoDWkS4Tzek5+iEs1vztr31d7KdwR5Cwn6HjziENrsu0uytPXagvlMJo1Pyv6UW0 XWNN4yW+GQFRXpqA7d2O2vT/envcQn9bIz/tc93D1/D7oGYrYIVTjlPTWVliVHPrjg8D w/VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:to:from:dkim-signature :arc-authentication-results; bh=tVNSV3Lq+jV/buR8nJHyip1vIr35Dl6hBkKM5zVdu8I=; b=0KSUrx7ZA4RjPryAZlNvKgP7Of2JTW8bncHWSjPKDsJLiHfB325kkYgOJBUUQsaIx7 RXb3QMKAwopdiAqRxw01pt6AgRDltNXJjXKkoaxF3Z98gtfgmfM+7VJ7pCwrhwPUP7vO PtyEsS/y+HQJK+qyfFWHNKZTCVFXdT43LTlMMUrhqCoAyWdMl+yojLhznDoAMoalFdr6 mt7NdloJtfNyg5poynuBahlVYxh4TZx9zUjlNfuBmQ9p7hEB91rOlCzRtrMwS69N32wR h2AkuHkTLGT7LiEJ7oixAtisgbN8KO4oUfjKFarFxiY9FZCH/zeSYDNDHhkmQP/fOa2W F0hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XfGj7FlV; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11-v6si5323160plk.225.2018.02.11.17.15.31; Sun, 11 Feb 2018 17:15:45 -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=@microsoft.com header.s=selector1 header.b=XfGj7FlV; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932394AbeBLBOV (ORCPT + 99 others); Sun, 11 Feb 2018 20:14:21 -0500 Received: from mail-by2nam01on0116.outbound.protection.outlook.com ([104.47.34.116]:50416 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932313AbeBLBOT (ORCPT ); Sun, 11 Feb 2018 20:14:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=tVNSV3Lq+jV/buR8nJHyip1vIr35Dl6hBkKM5zVdu8I=; b=XfGj7FlVkS1e9x67DIrnv17ddLlJ4lvTyAr/RhN8m/gH39vmGX3RGGyInVNmSRUuRTtmymA4kYrJYGWgCuJbYUi76No/35OTCwzXjXyuMmlQyAFoJg4Y2bgKKm1+D+INO79fNW1ed0JhIUHsKavolwaTvsT2FpLKtoHcxxkWSbg= Received: from DM5PR2101MB0888.namprd21.prod.outlook.com (52.132.132.157) by DM5PR2101MB1045.namprd21.prod.outlook.com (52.132.128.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.527.2; Mon, 12 Feb 2018 01:14:17 +0000 Received: from DM5PR2101MB0888.namprd21.prod.outlook.com ([fe80::60e3:7af:1961:8620]) by DM5PR2101MB0888.namprd21.prod.outlook.com ([fe80::60e3:7af:1961:8620%2]) with mapi id 15.20.0527.000; Mon, 12 Feb 2018 01:14:16 +0000 From: KY Srinivasan To: "Michael Kelley (EOSG)" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "devel@linuxdriverproject.org" , "olaf@aepfle.de" , "apw@canonical.com" , "vkuznets@redhat.com" , "jasowang@redhat.com" , "leann.ogasawara@canonical.com" , "marcelo.cerri@canonical.com" , Stephen Hemminger Subject: RE: [PATCH char-misc 1/1] Drivers: hv: vmbus: Fix ring buffer signaling Thread-Topic: [PATCH char-misc 1/1] Drivers: hv: vmbus: Fix ring buffer signaling Thread-Index: AQHTorCNaQB4t9RCq0qElSZLQrwNpaOf8abQ Date: Mon, 12 Feb 2018 01:14:16 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [2601:600:a280:b50:b076:3b2a:409c:285e] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1045;7:0Q/C9pNTCZUOOnqJgAH+6a4S6L2eqtFByAC9NieXbANtJJMwNl7Nu8r/eNgVYRlRs+gpnpy9JVhh4/oaFZdNNPxGt98/gca/CNT3yBUTdfC67+ojvNx4BXDfjPtUC5AySvB027zQU2dib8uqdZb/o23gj6RBHK1Z8C+8JHlkoHAOs4NUqbiF99ecf3fnp9JQdzI/JKX8UhaRo4kXxsh30eSx0mPgFofGyJm5LE8V39RfrPA53DYsKSvfqDjKKmzh x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(396003)(376002)(346002)(366004)(199004)(189003)(13464003)(86362001)(55016002)(7696005)(5660300001)(10290500003)(102836004)(68736007)(5250100002)(86612001)(2201001)(229853002)(59450400001)(22452003)(2501003)(6506007)(81156014)(3280700002)(53546011)(97736004)(81166006)(305945005)(8676002)(8936002)(74316002)(14454004)(9686003)(10090500001)(53936002)(7736002)(33656002)(110136005)(25786009)(99286004)(2950100002)(105586002)(6636002)(6436002)(76176011)(106356001)(316002)(2906002)(3660700001)(6346003)(6246003)(2900100001)(6116002)(1511001)(478600001)(8990500004)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1045;H:DM5PR2101MB0888.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: e43b9769-5343-43ed-75fb-08d571b5ef94 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:DM5PR2101MB1045; x-ms-traffictypediagnostic: DM5PR2101MB1045: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(9452136761055)(189930954265078)(198206253151910); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3231101)(944501161)(3002001)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB1045;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1045; x-forefront-prvs: 0581B5AB35 received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=kys@microsoft.com; x-microsoft-antispam-message-info: FNoUCN0htSu0J/n1ANpFrL93mV5UgLWR4Rf/BhjOwnqat541lsg9lICxeEgQixel2fGDuFTlOQB6WJtL3DUXTw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e43b9769-5343-43ed-75fb-08d571b5ef94 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Feb 2018 01:14:16.2804 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1045 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Michael Kelley [mailto:mhkelley@outlook.com] > Sent: Saturday, February 10, 2018 12:49 PM > To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org; > devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com; > vkuznets@redhat.com; jasowang@redhat.com; > leann.ogasawara@canonical.com; marcelo.cerri@canonical.com; Stephen > Hemminger ; KY Srinivasan > > Cc: Michael Kelley (EOSG) > Subject: [PATCH char-misc 1/1] Drivers: hv: vmbus: Fix ring buffer signal= ing >=20 > Fix bugs in signaling the Hyper-V host when freeing space in the > host->guest ring buffer: >=20 > 1. The interrupt_mask must not be used to determine whether to signal > on the host->guest ring buffer > 2. The ring buffer write_index must be read (via hv_get_bytes_to_write) > *after* pending_send_sz is read in order to avoid a race condition > 3. Comparisons with pending_send_sz must treat the "equals" case as > not-enough-space > 4. Don't signal if the pending_send_sz feature is not present. Older > versions of Hyper-V that don't implement this feature will poll. >=20 > Fixes: 03bad714a161 ("vmbus: more host signalling avoidance") > Signed-off-by: Michael Kelley > --- > drivers/hv/ring_buffer.c | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) >=20 > diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c > index 50e0714..b64be18 100644 > --- a/drivers/hv/ring_buffer.c > +++ b/drivers/hv/ring_buffer.c > @@ -423,7 +423,11 @@ struct vmpacket_descriptor * > void hv_pkt_iter_close(struct vmbus_channel *channel) > { > struct hv_ring_buffer_info *rbi =3D &channel->inbound; > - u32 orig_write_sz =3D hv_get_bytes_to_write(rbi); > + u32 curr_write_sz; > + u32 delta =3D rbi->ring_buffer->read_index < rbi->priv_read_index ? > + (rbi->priv_read_index - rbi->ring_buffer- > >read_index) : > + (rbi->ring_datasize - rbi->ring_buffer->read_index + > + rbi->priv_read_index); >=20 > /* > * Make sure all reads are done before we update the read index > since > @@ -446,27 +450,31 @@ void hv_pkt_iter_close(struct vmbus_channel > *channel) > */ > virt_mb(); >=20 > - /* If host has disabled notifications then skip */ > - if (rbi->ring_buffer->interrupt_mask) > - return; > - > if (rbi->ring_buffer->feature_bits.feat_pending_send_sz) { > u32 pending_sz =3D READ_ONCE(rbi->ring_buffer- > >pending_send_sz); >=20 > /* > + * Ensure the read of write_index in > hv_get_bytes_to_write() > + * happens after the read of pending_send_sz. > + */ > + virt_rmb(); We can avoid the read barrier by making the initialization of curr_write_sz= conditional on pending_send_sz being non-zero. Indeed you can make all the signaling co= de conditional on pending_send_sz being non-zero. > + curr_write_sz =3D hv_get_bytes_to_write(rbi); > + > + /* > * If there was space before we began iteration, > * then host was not blocked. Also handles case where > * pending_sz is zero then host has nothing pending > * and does not need to be signaled. > */ > - if (orig_write_sz > pending_sz) > + if (curr_write_sz - delta > pending_sz) > return; >=20 > /* If pending write will not fit, don't give false hope. */ > - if (hv_get_bytes_to_write(rbi) < pending_sz) > + if (curr_write_sz <=3D pending_sz) > return; > + > + vmbus_setevent(channel); > } >=20 > - vmbus_setevent(channel); > } > EXPORT_SYMBOL_GPL(hv_pkt_iter_close); > -- > 1.8.3.1