+ mm-hmm-improve-driver-api-to-work-and-wait-over-a-range-fix.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: mm/hmm: potential deadlock in nonblocking code
has been added to the -mm tree.  Its filename is
     mm-hmm-improve-driver-api-to-work-and-wait-over-a-range-fix.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/mm-hmm-improve-driver-api-to-work-and-wait-over-a-range-fix.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/mm-hmm-improve-driver-api-to-work-and-wait-over-a-range-fix.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Subject: mm/hmm: potential deadlock in nonblocking code

There is a deadlock bug when these functions are used in nonblocking mode.

The else side of the if/else statement is only meant to be taken in when
the code is used in blocking mode.  But, unfortunately, the way the code
is now, if we're in non-blocking mode and we succeed in taking the lock
then we do the else statement.  The else side tries to take lock a second
time which results in a deadlock.

Link: http://lkml.kernel.org/r/20190204182304.GA8756@kadam
Fixes: a3402cb621c1 ("mm/hmm: improve driver API to work and wait over a range")
Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Cc: Jérôme Glisse <jglisse@xxxxxxxxxx>
Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---


--- a/mm/hmm.c~mm-hmm-improve-driver-api-to-work-and-wait-over-a-range-fix
+++ a/mm/hmm.c
@@ -206,11 +206,12 @@ static int hmm_invalidate_range_start(st
 	update.event = HMM_UPDATE_INVALIDATE;
 	update.blockable = nrange->blockable;
 
-	if (!nrange->blockable && !mutex_trylock(&hmm->lock)) {
+	if (nrange->blockable)
+		mutex_lock(&hmm->lock);
+	else if (!mutex_trylock(&hmm->lock)) {
 		ret = -EAGAIN;
 		goto out;
-	} else
-		mutex_lock(&hmm->lock);
+	}
 	hmm->notifiers++;
 	list_for_each_entry(range, &hmm->ranges, list) {
 		if (update.end < range->start || update.start >= range->end)
@@ -220,12 +221,12 @@ static int hmm_invalidate_range_start(st
 	}
 	mutex_unlock(&hmm->lock);
 
-
-	if (!nrange->blockable && !down_read_trylock(&hmm->mirrors_sem)) {
+	if (nrange->blockable)
+		down_read(&hmm->mirrors_sem);
+	else if (!down_read_trylock(&hmm->mirrors_sem)) {
 		ret = -EAGAIN;
 		goto out;
-	} else
-		down_read(&hmm->mirrors_sem);
+	}
 	list_for_each_entry(mirror, &hmm->mirrors, list) {
 		int ret;
 
_

Patches currently in -mm which might be from dan.carpenter@xxxxxxxxxx are

mm-hmm-improve-driver-api-to-work-and-wait-over-a-range-fix.patch
rapidio-potential-oops-in-riocm_ch_listen.patch




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux