From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758946AbbJIARa (ORCPT ); Thu, 8 Oct 2015 20:17:30 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35195 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752367AbbJIAR2 (ORCPT ); Thu, 8 Oct 2015 20:17:28 -0400 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "=?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=" , "David Vrabel" Date: Fri, 09 Oct 2015 01:12:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 004/107] xen/gntdevt: Fix race condition in gntdev_release() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.247 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.72-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Marek Marczykowski-Górecki commit 30b03d05e07467b8c6ec683ea96b5bffcbcd3931 upstream. While gntdev_release() is called the MMU notifier is still registered and can traverse priv->maps list even if no pages are mapped (which is the case -- gntdev_release() is called after all). But gntdev_release() will clear that list, so make sure that only one of those things happens at the same time. Signed-off-by: Marek Marczykowski-Górecki Signed-off-by: David Vrabel [bwh: Backported to 3.2: - Adjust context - gntdev_priv::lock is a spinlock rather than a mutex. As gntdev_put_map() may sleep, we need to unlock inside the loop.] Signed-off-by: Ben Hutchings --- --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -493,11 +493,15 @@ static int gntdev_release(struct inode * pr_debug("priv %p\n", priv); + spin_lock(&priv->lock); while (!list_empty(&priv->maps)) { map = list_entry(priv->maps.next, struct grant_map, next); list_del(&map->next); + spin_unlock(&priv->lock); gntdev_put_map(map); + spin_lock(&priv->lock); } + spin_unlock(&priv->lock); if (use_ptemod) mmu_notifier_unregister(&priv->mn, priv->mm);