Skip to content

Commit

Permalink
Merge pull request kata-containers#713 from rhafer/issue-712
Browse files Browse the repository at this point in the history
Fix mem-hotplug on x86 when ARCH_MEMORY_PROBE is set
  • Loading branch information
Julio Montes authored Jan 20, 2020
2 parents 1b3628c + 2f49115 commit 7c2d8ab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
19 changes: 18 additions & 1 deletion grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
sysfsMemOnlinePath = "/sys/devices/system/memory"
sysfsMemoryBlockSizePath = "/sys/devices/system/memory/block_size_bytes"
sysfsMemoryHotplugProbePath = "/sys/devices/system/memory/probe"
sysfsAcpiMemoryHotplugPath = "/sys/firmware/acpi/hotplug/memory/enabled"
sysfsConnectedCPUsPath = filepath.Join(sysfsCPUOnlinePath, "online")
containersRootfsPath = "/run"

Expand Down Expand Up @@ -1576,6 +1577,16 @@ func (a *agentGRPC) ReseedRandomDev(ctx context.Context, req *pb.ReseedRandomDev
return emptyResp, reseedRNG(req.Data)
}

func (a *agentGRPC) haveAcpiMemoryHotplug() bool {
enabled, err := ioutil.ReadFile(sysfsAcpiMemoryHotplugPath)
if err != nil {
return false
} else if strings.TrimSpace(string(enabled)) == "1" {
return true
}
return false
}

func (a *agentGRPC) GetGuestDetails(ctx context.Context, req *pb.GuestDetailsRequest) (*pb.GuestDetailsResponse, error) {
var details pb.GuestDetailsResponse
if req.MemBlockSize {
Expand Down Expand Up @@ -1603,7 +1614,13 @@ func (a *agentGRPC) GetGuestDetails(ctx context.Context, req *pb.GuestDetailsReq
} else if err != nil {
return nil, err
} else {
details.SupportMemHotplugProbe = true
// Avoid triggering memory hotplugging notifications when ACPI
// hotplugging is enabled
if a.haveAcpiMemoryHotplug() {
details.SupportMemHotplugProbe = false
} else {
details.SupportMemHotplugProbe = true
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,38 @@ func TestGetGuestDetails(t *testing.T) {
probeFile, err := ioutil.TempFile("", "probe")
assert.NoError(err)

// sysfsAcpiMemoryHotplugPath exist and is 1
hotplugEnabledFile, err := ioutil.TempFile("", "enabled")
assert.NoError(err)
_, err = hotplugEnabledFile.WriteString("1")
assert.NoError(err)
hotplugEnabledFile.Sync()

oldSysfsMemoryHotplugProbePath := sysfsMemoryHotplugProbePath
oldSysfsAcpiMemoryHotplugPath := sysfsAcpiMemoryHotplugPath
defer func() {
sysfsMemoryHotplugProbePath = oldSysfsMemoryHotplugProbePath
sysfsAcpiMemoryHotplugPath = oldSysfsAcpiMemoryHotplugPath
}()

sysfsMemoryHotplugProbePath = probeFile.Name()
sysfsAcpiMemoryHotplugPath = hotplugEnabledFile.Name()
resp, err = a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)
assert.Equal(resp.SupportMemHotplugProbe, false)

// sysfsAcpiMemoryHotplugPath exist and is 0
_, err = hotplugEnabledFile.Seek(0, 0)
assert.NoError(err)
_, err = hotplugEnabledFile.WriteString("0")
assert.NoError(err)
hotplugEnabledFile.Sync()
resp, err = a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)
assert.Equal(resp.SupportMemHotplugProbe, true)

// sysfsAcpiMemoryHotplugPath does not exist
os.Remove(sysfsAcpiMemoryHotplugPath)
resp, err = a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)
assert.Equal(resp.SupportMemHotplugProbe, true)
Expand Down

0 comments on commit 7c2d8ab

Please sign in to comment.