)]}'
{
  "commit": "980095205f18beab0ff98c800e4a45dd6b8306ab",
  "tree": "fec2e29acc7b5bb7b7713ec2c6d7f4cc678a3a38",
  "parents": [
    "dd6fdb9b8d33b360082ddbab59b92557c2511e16"
  ],
  "author": {
    "name": "Soheil Hassas Yeganeh",
    "email": "soheil@google.com",
    "time": "Fri Dec 18 14:01:44 2020 -0800"
  },
  "committer": {
    "name": "COS Cherry Picker",
    "email": "cloud-image-release@prod.google.com",
    "time": "Thu Dec 08 15:03:24 2022 -0800"
  },
  "message": "epoll: check for events when removing a timed out thread from the wait queue\n\ncommit 289caf5d8f6c61c6d2b7fd752a7f483cd153f182 upstream.\n\nPatch series \"simplify ep_poll\".\n\nThis patch series is a followup based on the suggestions and feedback by\nLinus:\nhttps://lkml.kernel.org/r/CAHk-\u003dwizk\u003dOxUyQPbO8MS41w2Pag1kniUV5WdD5qWL-gq1kjDA@mail.gmail.com\n\nThe first patch in the series is a fix for the epoll race in presence of\ntimeouts, so that it can be cleanly backported to all affected stable\nkernels.\n\nThe rest of the patch series simplify the ep_poll() implementation.  Some\nof these simplifications result in minor performance enhancements as well.\nWe have kept these changes under self tests and internal benchmarks for a\nfew days, and there are minor (1-2%) performance enhancements as a result.\n\nThis patch (of 8):\n\nAfter abc610e01c66 (\"fs/epoll: avoid barrier after an epoll_wait(2)\ntimeout\"), we break out of the ep_poll loop upon timeout, without checking\nwhether there is any new events available.  Prior to that patch-series we\nalways called ep_events_available() after exiting the loop.\n\nThis can cause races and missed wakeups.  For example, consider the\nfollowing scenario reported by Guantao Liu:\n\nSuppose we have an eventfd added using EPOLLET to an epollfd.\n\nThread 1: Sleeps for just below 5ms and then writes to an eventfd.\nThread 2: Calls epoll_wait with a timeout of 5 ms. If it sees an\n          event of the eventfd, it will write back on that fd.\nThread 3: Calls epoll_wait with a negative timeout.\n\nPrior to abc610e01c66, it is guaranteed that Thread 3 will wake up either\nby Thread 1 or Thread 2.  After abc610e01c66, Thread 3 can be blocked\nindefinitely if Thread 2 sees a timeout right before the write to the\neventfd by Thread 1.  Thread 2 will be woken up from\nschedule_hrtimeout_range and, with evail 0, it will not call\nep_send_events().\n\nTo fix this issue:\n1) Simplify the timed_out case as suggested by Linus.\n2) while holding the lock, recheck whether the thread was woken up\n   after its time out has reached.\n\nNote that (2) is different from Linus\u0027 original suggestion: It do not set\n\"eavail \u003d ep_events_available(ep)\" to avoid unnecessary contention (when\nthere are too many timed-out threads and a small number of events), as\nwell as races mentioned in the discussion thread.\n\nThis is the first patch in the series so that the backport to stable\nreleases is straightforward.\n\nBUG\u003db/261210368\nTEST\u003dhttp://sponge2/f4e275e3-783d-42cc-a5d0-6b98c074a221\nRELEASE_NOTE\u003dFixed issue where thread would get stuck in epoll_wait.\n\ncos-patch: bug\nLink: https://lkml.kernel.org/r/20201106231635.3528496-1-soheil.kdev@gmail.com\nLink: https://lkml.kernel.org/r/CAHk-\u003dwizk\u003dOxUyQPbO8MS41w2Pag1kniUV5WdD5qWL-gq1kjDA@mail.gmail.com\nLink: https://lkml.kernel.org/r/20201106231635.3528496-2-soheil.kdev@gmail.com\nFixes: abc610e01c66 (\"fs/epoll: avoid barrier after an epoll_wait(2) timeout\")\nSigned-off-by: Soheil Hassas Yeganeh \u003csoheil@google.com\u003e\nTested-by: Guantao Liu \u003cguantaol@google.com\u003e\nSuggested-by: Linus Torvalds \u003ctorvalds@linux-foundation.org\u003e\nReported-by: Guantao Liu \u003cguantaol@google.com\u003e\nReviewed-by: Eric Dumazet \u003cedumazet@google.com\u003e\nReviewed-by: Willem de Bruijn \u003cwillemb@google.com\u003e\nReviewed-by: Khazhismel Kumykov \u003ckhazhy@google.com\u003e\nReviewed-by: Davidlohr Bueso \u003cdbueso@suse.de\u003e\nSigned-off-by: Andrew Morton \u003cakpm@linux-foundation.org\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@linux-foundation.org\u003e\nAcked-by: Thadeu Lima de Souza Cascardo \u003ccascardo@canonical.com\u003e\nChange-Id: I5af8cbef4ad30c5843c4e3b3a45ff853731dd888\nSigned-off-by: Rishabh Bhatnagar \u003crisbhat@amazon.com\u003e\nSigned-off-by: Greg Kroah-Hartman \u003cgregkh@linuxfoundation.org\u003e\nReviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/39808\nReviewed-by: Oleksandr Tymoshenko \u003covt@google.com\u003e\nReviewed-by: Vaibhav Rustagi \u003cvaibhavrustagi@google.com\u003e\nTested-by: Cusky Presubmit Bot \u003cpresubmit@cos-infra-prod.iam.gserviceaccount.com\u003e\nMain-Branch-Verified: Cusky Presubmit Bot \u003cpresubmit@cos-infra-prod.iam.gserviceaccount.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "e5496483a882d0c722abd9faa31615b9ee7d3944",
      "old_mode": 33188,
      "old_path": "fs/eventpoll.c",
      "new_id": "877f9f61a4e8d712aa2d472157939070760d823a",
      "new_mode": 33188,
      "new_path": "fs/eventpoll.c"
    }
  ]
}
