From patchwork Wed Jun 21 09:38:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9801347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 845FB60329 for ; Wed, 21 Jun 2017 09:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 600D9285AF for ; Wed, 21 Jun 2017 09:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5088F285A5; Wed, 21 Jun 2017 09:40:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C1CB628563 for ; Wed, 21 Jun 2017 09:40:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNc5S-0000hj-9R; Wed, 21 Jun 2017 09:38:10 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNc5R-0000hF-0X for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 09:38:09 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 47/89-02006-08E3A495; Wed, 21 Jun 2017 09:38:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRWlGSWpSXmKPExsXS6fjDS7feziv SYO0+fYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPxqivsBVOlKvZsWMTYwDhXtIuRk0NIIE+i cfJFJhCbV8BOom3JLTYQW0LAUOL0wpssIDaLgKrE3h+PwWw2AXWJtmfbWbsYOThEBAwkzh1N6 mLk4mAWWMskcXHWXbA5wgIOEi8+7GOGmF8ksfXAanYQm1PAXmLOstdsIL28AoISf3cIg4SZgd Z+mraabQIjzyyEzCwkGQhbS+Lhr1ssELa2xLKFr5lBypkFpCWW/+OACFtLfHl+lw1VCYjtJnH l6FymBYwcqxg1ilOLylKLdI0s9JKKMtMzSnITM3N0DQ1M9XJTi4sT01NzEpOK9ZLzczcxAsO1 noGBcQdj3yq/Q4ySHExKorwXZL0ihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw+tsC5QSLUtNTK 9Iyc4CRA5OW4OBREuFdZg6U5i0uSMwtzkyHSJ1iVJQS52UF6RMASWSU5sG1waL1EqOslDAvIw MDgxBPQWpRbmYJqvwrRnEORiVh3gAboCk8mXklcNNfAS1mAlr84ogHyOKSRISUVANjSlMTh0N 3Xdw11+tdX9IO13Rm6nYKR7b8LTL4cTKZ4QFPwYQm56wfH7tOlk4+eMiqLiLhwTndW1+8k8vq 1lv6e9pUBn9/uLLyl2nGfRcFG5H1n3QyLZ7/sMsrOS/rtCpcbN3jouPyVZmp21rbxJVuS8z8/ 8l1iS+v1sL9Z/gMxPyC7t8ubFNiKc5INNRiLipOBAAY8kUq0QIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1498037885!104343485!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43796 invoked from network); 21 Jun 2017 09:38:07 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-4.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 21 Jun 2017 09:38:07 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 21 Jun 2017 03:38:05 -0600 Message-Id: <594A5A9C02000078001650BE@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Wed, 21 Jun 2017 03:38:04 -0600 From: "Jan Beulich" To: "xen-devel" References: <594A57B10200007800165012@prv-mh.provo.novell.com> <594A57B10200007800165012@prv-mh.provo.novell.com> In-Reply-To: <594A57B10200007800165012@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan Subject: [Xen-devel] [PATCH 10/11] gnttab: limit mapkind()'s iteration count X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP There's no need for the function to observe increases of the maptrack table (which can occur as the maptrack lock isn't being held) - actual population of maptrack entries is excluded while we're here (by way of holding the respective grant table lock for writing, while code populating entries acquires it for reading). Latch the limit ahead of the loop, allowing for the barrier to move out, too. Signed-by: Jan Beulich gnttab: limit mapkind()'s iteration count There's no need for the function to observe increases of the maptrack table (which can occur as the maptrack lock isn't being held) - actual population of maptrack entries is excluded while we're here (by way of holding the respective grant table lock for writing, while code populating entries acquires it for reading). Latch the limit ahead of the loop, allowing for the barrier to move out, too. Signed-by: Jan Beulich --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -712,7 +712,7 @@ static unsigned int mapkind( struct grant_table *lgt, const struct domain *rd, unsigned long mfn) { struct grant_mapping *map; - grant_handle_t handle; + grant_handle_t handle, limit = lgt->maptrack_limit; unsigned int kind = 0; /* @@ -726,10 +726,10 @@ static unsigned int mapkind( */ ASSERT(percpu_rw_is_write_locked(&rd->grant_table->lock)); - for ( handle = 0; !(kind & MAPKIND_WRITE) && - handle < lgt->maptrack_limit; handle++ ) + smp_rmb(); + + for ( handle = 0; !(kind & MAPKIND_WRITE) && handle < limit; handle++ ) { - smp_rmb(); map = &maptrack_entry(lgt, handle); if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) || map->domid != rd->domain_id ) Reviewed-by: Andrew Cooper --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -712,7 +712,7 @@ static unsigned int mapkind( struct grant_table *lgt, const struct domain *rd, unsigned long mfn) { struct grant_mapping *map; - grant_handle_t handle; + grant_handle_t handle, limit = lgt->maptrack_limit; unsigned int kind = 0; /* @@ -726,10 +726,10 @@ static unsigned int mapkind( */ ASSERT(percpu_rw_is_write_locked(&rd->grant_table->lock)); - for ( handle = 0; !(kind & MAPKIND_WRITE) && - handle < lgt->maptrack_limit; handle++ ) + smp_rmb(); + + for ( handle = 0; !(kind & MAPKIND_WRITE) && handle < limit; handle++ ) { - smp_rmb(); map = &maptrack_entry(lgt, handle); if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) || map->domid != rd->domain_id )