Skip to content

Commit

Permalink
[CR] Fix memory allocation in kernel pages for the SysGate
Browse files Browse the repository at this point in the history
  • Loading branch information
cyring committed Jun 16, 2024
1 parent e6d383a commit 7c8d354
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions aarch64/corefreqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,7 @@ void PerCore_Update( RO(SHM_STRUCT) *RO(Shm), RO(PROC) *RO(Proc),
int SysGate_OnDemand(REF *Ref, int operation)
{
int rc = -1;
const size_t allocPages = \
(size_t)PAGE_SIZE << Ref->RO(Proc)->Gate.ReqMem.Order;
const size_t allocPages = Ref->RO(Proc)->Gate.ReqMem.Size;

if (operation == 0) {
if (Ref->RO(SysGate) != NULL) {
Expand Down
11 changes: 5 additions & 6 deletions aarch64/corefreqk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3478,9 +3478,7 @@ static long SysGate_OnDemand(void)
GFP_KERNEL);
if (PUBLIC(OF(Gate)) != NULL)
{
const size_t
allocPages = PAGE_SIZE << PUBLIC(RO(Proc))->Gate.ReqMem.Order;
memset(PUBLIC(OF(Gate)), 0, allocPages);
memset(PUBLIC(OF(Gate)), 0, PUBLIC(RO(Proc))->Gate.ReqMem.Size);
rc = 0;
}
} else { /* Already allocated */
Expand Down Expand Up @@ -4897,9 +4895,7 @@ static int CoreFreqK_mmap(struct file *pfile, struct vm_area_struct *vma)
case 1:
fallthrough;
case 0: {
const unsigned long
secSize = PAGE_SIZE << PUBLIC(RO(Proc))->Gate.ReqMem.Order;
if (reqSize != secSize) {
if (reqSize != PUBLIC(RO(Proc))->Gate.ReqMem.Size) {
return -EAGAIN;
}

Expand Down Expand Up @@ -5644,6 +5640,9 @@ static int CoreFreqK_Scale_And_Compute_Level_Up(INIT_ARG *pArg)
PUBLIC(RO(Proc))->Gate.ReqMem.Order = \
get_order(PUBLIC(RO(Proc))->Gate.ReqMem.Size);

PUBLIC(RO(Proc))->Gate.ReqMem.Size = \
PAGE_SIZE << PUBLIC(RO(Proc))->Gate.ReqMem.Order;

PUBLIC(RO(Proc))->Registration.AutoClock = AutoClock;
PUBLIC(RO(Proc))->Registration.Experimental = Experimental;

Expand Down
3 changes: 1 addition & 2 deletions x86_64/corefreqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8143,8 +8143,7 @@ void PerCore_Update( RO(SHM_STRUCT) *RO(Shm), RO(PROC) *RO(Proc),
int SysGate_OnDemand(REF *Ref, int operation)
{
int rc = -1;
const size_t allocPages = \
(size_t)PAGE_SIZE << Ref->RO(Proc)->Gate.ReqMem.Order;
const size_t allocPages = Ref->RO(Proc)->Gate.ReqMem.Size;

if (operation == 0) {
if (Ref->RO(SysGate) != NULL) {
Expand Down
11 changes: 5 additions & 6 deletions x86_64/corefreqk.c
Original file line number Diff line number Diff line change
Expand Up @@ -20331,9 +20331,7 @@ static long SysGate_OnDemand(void)
GFP_KERNEL);
if (PUBLIC(OF(Gate)) != NULL)
{
const size_t
allocPages = PAGE_SIZE << PUBLIC(RO(Proc))->Gate.ReqMem.Order;
memset(PUBLIC(OF(Gate)), 0, allocPages);
memset(PUBLIC(OF(Gate)), 0, PUBLIC(RO(Proc))->Gate.ReqMem.Size);
rc = 0;
}
} else { /* Already allocated */
Expand Down Expand Up @@ -23376,9 +23374,7 @@ static int CoreFreqK_mmap(struct file *pfile, struct vm_area_struct *vma)
case 1:
fallthrough;
case 0: {
const unsigned long
secSize = PAGE_SIZE << PUBLIC(RO(Proc))->Gate.ReqMem.Order;
if (reqSize != secSize) {
if (reqSize != PUBLIC(RO(Proc))->Gate.ReqMem.Size) {
return -EAGAIN;
}

Expand Down Expand Up @@ -24141,6 +24137,9 @@ static int CoreFreqK_Scale_And_Compute_Level_Up(INIT_ARG *pArg)
PUBLIC(RO(Proc))->Gate.ReqMem.Order = \
get_order(PUBLIC(RO(Proc))->Gate.ReqMem.Size);

PUBLIC(RO(Proc))->Gate.ReqMem.Size = \
PAGE_SIZE << PUBLIC(RO(Proc))->Gate.ReqMem.Order;

PUBLIC(RO(Proc))->Registration.AutoClock = AutoClock;
PUBLIC(RO(Proc))->Registration.Experimental = Experimental;

Expand Down

0 comments on commit 7c8d354

Please sign in to comment.