From: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
To: "Vineet.Gupta1@synopsys.com" <Vineet.Gupta1@synopsys.com>
Cc: "paltsev@snyopsys.com" <paltsev@snyopsys.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Alexey Brodkin <Alexey.Brodkin@synopsys.com>,
"linux-snps-arc@lists.infradead.org"
<linux-snps-arc@lists.infradead.org>
Subject: Re: [PATCH 4/9] ARC: mm: do_page_fault refactor #3: tidyup vma access permission code
Date: Thu, 16 May 2019 17:24:09 +0000 [thread overview]
Message-ID: <1558027448.2682.11.camel@synopsys.com> (raw)
In-Reply-To: <1557880176-24964-5-git-send-email-vgupta@synopsys.com>
On Tue, 2019-05-14 at 17:29 -0700, Vineet Gupta wrote:
> The coding pattern to NOT intialize variables at declaration time but
> rather near code which makes us eof them makes it much easier to grok
> the overall logic, specially when the init is not simply 0 or 1
>
> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
> ---
> arch/arc/mm/fault.c | 39 +++++++++++++++++++++------------------
> 1 file changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arc/mm/fault.c b/arch/arc/mm/fault.c
> index f1175685d914..ae890a8d5ebf 100644
> --- a/arch/arc/mm/fault.c
> +++ b/arch/arc/mm/fault.c
> @@ -67,9 +67,9 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
> struct task_struct *tsk = current;
> struct mm_struct *mm = tsk->mm;
> int si_code = SEGV_MAPERR;
> + unsigned int write = 0, exec = 0, mask;
Probably it's better to use 'bool' type for 'write' and 'exec' as we really use them as a boolean variables.
> vm_fault_t fault;
> - int write = regs->ecr_cause & ECR_C_PROTV_STORE; /* ST/EX */
> - unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
> + unsigned int flags;
>
> /*
> * NOTE! We MUST NOT take any locks for this case. We may
> @@ -91,8 +91,18 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
> if (faulthandler_disabled() || !mm)
> goto no_context;
>
> + if (regs->ecr_cause & ECR_C_PROTV_STORE) /* ST/EX */
> + write = 1;
> + else if ((regs->ecr_vec == ECR_V_PROTV) &&
> + (regs->ecr_cause == ECR_C_PROTV_INST_FETCH))
> + exec = 1;
> +
> + flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
> if (user_mode(regs))
> flags |= FAULT_FLAG_USER;
> + if (write)
> + flags |= FAULT_FLAG_WRITE;
> +
> retry:
> down_read(&mm->mmap_sem);
>
> @@ -105,24 +115,17 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
> }
>
> /*
> - * Ok, we have a good vm_area for this memory access, so
> - * we can handle it..
> + * vm_area is good, now check permissions for this memory access
> */
> - si_code = SEGV_ACCERR;
> -
> - /* Handle protection violation, execute on heap or stack */
> -
> - if ((regs->ecr_vec == ECR_V_PROTV) &&
> - (regs->ecr_cause == ECR_C_PROTV_INST_FETCH))
> + mask = VM_READ;
> + if (write)
> + mask = VM_WRITE;
> + if (exec)
> + mask = VM_EXEC;
> +
> + if (!(vma->vm_flags & mask)) {
> + si_code = SEGV_ACCERR;
> goto bad_area;
> -
> - if (write) {
> - if (!(vma->vm_flags & VM_WRITE))
> - goto bad_area;
> - flags |= FAULT_FLAG_WRITE;
> - } else {
> - if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
> - goto bad_area;
> }
>
> /*
--
Eugeniy Paltsev
next prev parent reply other threads:[~2019-05-16 17:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 0:29 [PATCH 0/9] ARC do_page_fault rework Vineet Gupta
2019-05-15 0:29 ` [PATCH 1/9] ARC: mm: SIGSEGV userspace trying to access kernel virtual memory Vineet Gupta
2019-05-15 0:29 ` [PATCH 2/9] ARC: mm: do_page_fault refactor #1: remove label @good_area Vineet Gupta
2019-05-15 0:29 ` [PATCH 3/9] ARC: mm: do_page_fault refactor #2: remove short lived variable Vineet Gupta
2019-05-15 0:29 ` [PATCH 4/9] ARC: mm: do_page_fault refactor #3: tidyup vma access permission code Vineet Gupta
2019-05-16 17:24 ` Eugeniy Paltsev [this message]
2019-05-16 17:37 ` Vineet Gupta
2019-05-16 17:44 ` Alexey Brodkin
2019-05-16 18:57 ` Vineet Gupta
2019-05-17 22:23 ` Eugeniy Paltsev
2019-05-30 17:58 ` extraneous generated EXTB (was Re: [PATCH 4/9] ARC: mm: do_page_fault refactor #3: tidyup vma access permission code) Vineet Gupta
2019-05-15 0:29 ` [PATCH 5/9] ARC: mm: do_page_fault refactor #4: consolidate retry related logic Vineet Gupta
2019-05-15 0:29 ` [PATCH 6/9] ARC: mm: do_page_fault refactor #5: scoot no_context to end Vineet Gupta
2019-05-15 0:29 ` [PATCH 7/9] ARC: mm: do_page_fault refactor #6: error handlers to use same pattern Vineet Gupta
2019-05-15 0:29 ` [PATCH 8/9] ARC: mm: do_page_fault refactor #7: fold the various error handling Vineet Gupta
2019-05-15 0:29 ` [PATCH 9/9] ARC: mm: do_page_fault refactor #8: release mmap_sem sooner Vineet Gupta
2019-05-30 16:48 ` Vineet Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1558027448.2682.11.camel@synopsys.com \
--to=eugeniy.paltsev@synopsys.com \
--cc=Alexey.Brodkin@synopsys.com \
--cc=Vineet.Gupta1@synopsys.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=paltsev@snyopsys.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).