linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Christophe Leroy <christophe.leroy@c-s.fr>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 3/3] powerpc/kprobes: Check return value of patch_instruction()
Date: Mon, 27 Apr 2020 22:41:58 +0530	[thread overview]
Message-ID: <1588007337.m8xwhbyyyq.naveen@linux.ibm.com> (raw)
In-Reply-To: <e743c9db-847a-2612-bf36-c23a57a056c5@c-s.fr>

Christophe Leroy wrote:
> 
> 
> On 04/24/2020 06:26 PM, Naveen N. Rao wrote:
>> Steven Rostedt wrote:
>>> On Thu, 23 Apr 2020 17:41:52 +0200
>>> Christophe Leroy <christophe.leroy@c-s.fr> wrote:
>>>> > diff --git a/arch/powerpc/kernel/optprobes.c 
>>>> b/arch/powerpc/kernel/optprobes.c
>>>> > index 024f7aad1952..046485bb0a52 100644
>>>> > --- a/arch/powerpc/kernel/optprobes.c
>>>> > +++ b/arch/powerpc/kernel/optprobes.c
>>>> > @@ -139,52 +139,67 @@ void arch_remove_optimized_kprobe(struct 
>>>> optimized_kprobe *op)
>>>> >       }
>>>> >   }
>>>> > > +#define PATCH_INSN(addr, instr)                             \
>>>> > +do {                                         \
>>>> > +    int rc = patch_instruction((unsigned int *)(addr), 
>>>> instr);         \
>>>> > +    if (rc) {                                 \
>>>> > +        pr_err("%s:%d Error patching instruction at 0x%pK (%pS): 
>>>> %d\n", \
>>>> > +                __func__, __LINE__,                 \
>>>> > +                (void *)(addr), (void *)(addr), rc);         \
>>>> > +        return rc;                             \
>>>> > +    }                                     \
>>>> > +} while (0)
>>>> > +
>>>> I hate this kind of macro which hides the "return".
>>>>
>>>> What about keeping the return action in the caller ?
>>>>
>>>> Otherwise, what about implementing something based on the use of 
>>>> goto, on the same model as unsafe_put_user() for instance ?
>> 
>> Thanks for the review.
>> 
>> I noticed this as a warning from checkpatch.pl, but this looked compact 
>> and correct for use in the two following functions. You'll notice that I 
>> added it just before the two functions this is used in.
>> 
>> I suppose 'goto err' is usable too, but the ftrace code (patch 2) will 
>> end up with more changes. I'm also struggling to see how a 'goto' is 
>> less offensive. I think Steve's suggestion below would be the better way 
>> to go, to make things explicit.
>> 
> 
> Sure it's be more explicit, but then more lines also. 3 lines for only 
> one really usefull.
> 
> With goto, I would look like:
> 
> diff --git a/arch/powerpc/kernel/optprobes.c 
> b/arch/powerpc/kernel/optprobes.c
> index 046485bb0a52..938208f824da 100644
> --- a/arch/powerpc/kernel/optprobes.c
> +++ b/arch/powerpc/kernel/optprobes.c
> @@ -139,14 +139,14 @@ void arch_remove_optimized_kprobe(struct 
> optimized_kprobe *op)
>   	}
>   }
> 
> -#define PATCH_INSN(addr, instr)						     \
> +#define PATCH_INSN(addr, instr, label)						     \
>   do {									     \
>   	int rc = patch_instruction((unsigned int *)(addr), instr);	     \
>   	if (rc) {							     \
>   		pr_err("%s:%d Error patching instruction at 0x%pK (%pS): %d\n", \
>   				__func__, __LINE__,			     \
>   				(void *)(addr), (void *)(addr), rc);	     \
> -		return rc;						     \
> +		goto label;						     \
>   	}								     \
>   } while (0)

My earlier complaint was that this would still add a flow control 
statement, so didn't look to immediately address your original concern.  
However, I suppose introduction of an explicit label makes things a bit 
better.

In addition:

<snip>
> @@ -291,23 +297,8 @@ int arch_prepare_optimized_kprobe(struct 
> optimized_kprobe *op, struct kprobe *p)
>   		goto error;
>   	}
> 
> -	rc = patch_instruction(buff + TMPL_CALL_HDLR_IDX, branch_op_callback);
> -	if (rc) {
> -		pr_err("%s:%d: Error patching instruction at 0x%pK: %d\n",
> -				__func__, __LINE__,
> -				(void *)(buff + TMPL_CALL_HDLR_IDX), rc);
> -		rc = -EFAULT;
> -		goto error;
> -	}
> -
> -	rc = patch_instruction(buff + TMPL_EMULATE_IDX, branch_emulate_step);
> -	if (rc) {
> -		pr_err("%s:%d: Error patching instruction at 0x%pK: %d\n",
> -				__func__, __LINE__,
> -				(void *)(buff + TMPL_EMULATE_IDX), rc);
> -		rc = -EFAULT;
> -		goto error;
> -	}
> +	PATCH_INSN(buff + TMPL_CALL_HDLR_IDX, branch_op_callback, efault);
> +	PATCH_INSN(buff + TMPL_EMULATE_IDX, branch_emulate_step, efault);

I like how this variant can cover additional uses of patch_instruction() 
here.

I will use this variant. Thanks for the suggestion!


- Naveen


      parent reply	other threads:[~2020-04-27 17:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 15:09 [PATCH 0/3] powerpc: Enhance error handling with patch_instruction() Naveen N. Rao
2020-04-23 15:09 ` [PATCH 1/3] powerpc: Properly return error code from do_patch_instruction() Naveen N. Rao
2020-04-23 16:21   ` Christophe Leroy
2020-04-24 13:15     ` Steven Rostedt
2020-04-24 18:07       ` Naveen N. Rao
2020-04-24 18:29         ` Steven Rostedt
2020-04-24 19:26       ` Christopher M. Riedl
2020-04-25 14:10         ` Steven Rostedt
2020-04-25 14:11           ` Steven Rostedt
2020-04-27 17:14         ` Naveen N. Rao
2020-04-24 18:02     ` Naveen N. Rao
2022-01-14 16:19   ` Christophe Leroy
2020-04-23 15:09 ` [PATCH 2/3] powerpc/ftrace: Simplify error checking when patching instructions Naveen N. Rao
2020-04-23 15:44   ` Christophe Leroy
2020-04-23 15:09 ` [PATCH 3/3] powerpc/kprobes: Check return value of patch_instruction() Naveen N. Rao
2020-04-23 15:41   ` Christophe Leroy
2020-04-24 13:22     ` Steven Rostedt
2020-04-24 18:26       ` Naveen N. Rao
2020-04-24 18:31         ` Steven Rostedt
2020-04-24 19:38           ` Naveen N. Rao
2020-04-25 10:11         ` Christophe Leroy
2020-04-25 14:06           ` Steven Rostedt
2020-04-27 17:13             ` Naveen N. Rao
2020-04-27 17:11           ` Naveen N. Rao [this message]

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=1588007337.m8xwhbyyyq.naveen@linux.ibm.com \
    --to=naveen.n.rao@linux.vnet.ibm.com \
    --cc=christophe.leroy@c-s.fr \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=rostedt@goodmis.org \
    /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).