summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-03-19 17:02:55 +0000
committergVisor bot <gvisor-bot@google.com>2020-03-19 17:02:55 +0000
commitc9d4ad641533e67cda1783c080d60e0a0a605a67 (patch)
tree445a2af98a3436243d287bdaeca9ee55e8630ea2 /pkg
parentbc8f399c9668fc31f342539ad19458adb23ea352 (diff)
parent3a37f6791745a26d38b69fbe9d4090f8fd0c7827 (diff)
Merge release-20200219.0-204-g3a37f67 (automated)
Diffstat (limited to 'pkg')
-rwxr-xr-xpkg/sentry/socket/netstack/netstack.go22
-rwxr-xr-xpkg/sentry/socket/netstack/netstack_state_autogen.go2
2 files changed, 4 insertions, 20 deletions
diff --git a/pkg/sentry/socket/netstack/netstack.go b/pkg/sentry/socket/netstack/netstack.go
index a2e1da02f..a6ef7a47e 100755
--- a/pkg/sentry/socket/netstack/netstack.go
+++ b/pkg/sentry/socket/netstack/netstack.go
@@ -29,7 +29,6 @@ import (
"io"
"math"
"reflect"
- "sync/atomic"
"syscall"
"time"
@@ -265,14 +264,8 @@ type SocketOperations struct {
skType linux.SockType
protocol int
- // readViewHasData is 1 iff readView has data to be read, 0 otherwise.
- // Must be accessed using atomic operations. It must only be written
- // with readMu held but can be read without holding readMu. The latter
- // is required to avoid deadlocks in epoll Readiness checks.
- readViewHasData uint32
-
// readMu protects access to the below fields.
- readMu sync.Mutex `state:"nosave"`
+ readMu sync.RWMutex `state:"nosave"`
// readView contains the remaining payload from the last packet.
readView buffer.View
// readCM holds control message information for the last packet read
@@ -428,13 +421,11 @@ func (s *SocketOperations) fetchReadView() *syserr.Error {
v, cms, err := s.Endpoint.Read(&s.sender)
if err != nil {
- atomic.StoreUint32(&s.readViewHasData, 0)
return syserr.TranslateNetstackError(err)
}
s.readView = v
s.readCM = cms
- atomic.StoreUint32(&s.readViewHasData, 1)
return nil
}
@@ -633,9 +624,11 @@ func (s *SocketOperations) Readiness(mask waiter.EventMask) waiter.EventMask {
// Check our cached value iff the caller asked for readability and the
// endpoint itself is currently not readable.
if (mask & ^r & waiter.EventIn) != 0 {
- if atomic.LoadUint32(&s.readViewHasData) == 1 {
+ s.readMu.RLock()
+ if len(s.readView) > 0 {
r |= waiter.EventIn
}
+ s.readMu.RUnlock()
}
return r
@@ -2342,9 +2335,6 @@ func (s *SocketOperations) coalescingRead(ctx context.Context, dst usermem.IOSeq
}
copied += n
s.readView.TrimFront(n)
- if len(s.readView) == 0 {
- atomic.StoreUint32(&s.readViewHasData, 0)
- }
dst = dst.DropFirst(n)
if e != nil {
@@ -2468,10 +2458,6 @@ func (s *SocketOperations) nonBlockingRead(ctx context.Context, dst usermem.IOSe
s.readView.TrimFront(int(n))
}
- if len(s.readView) == 0 {
- atomic.StoreUint32(&s.readViewHasData, 0)
- }
-
var flags int
if msgLen > int(n) {
flags |= linux.MSG_TRUNC
diff --git a/pkg/sentry/socket/netstack/netstack_state_autogen.go b/pkg/sentry/socket/netstack/netstack_state_autogen.go
index 9be6fe242..608f23f63 100755
--- a/pkg/sentry/socket/netstack/netstack_state_autogen.go
+++ b/pkg/sentry/socket/netstack/netstack_state_autogen.go
@@ -15,7 +15,6 @@ func (x *SocketOperations) save(m state.Map) {
m.Save("Endpoint", &x.Endpoint)
m.Save("skType", &x.skType)
m.Save("protocol", &x.protocol)
- m.Save("readViewHasData", &x.readViewHasData)
m.Save("readView", &x.readView)
m.Save("readCM", &x.readCM)
m.Save("sender", &x.sender)
@@ -33,7 +32,6 @@ func (x *SocketOperations) load(m state.Map) {
m.Load("Endpoint", &x.Endpoint)
m.Load("skType", &x.skType)
m.Load("protocol", &x.protocol)
- m.Load("readViewHasData", &x.readViewHasData)
m.Load("readView", &x.readView)
m.Load("readCM", &x.readCM)
m.Load("sender", &x.sender)