Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1693478

Re: [PATCH v2 1/2] livepatch: introduce shadow variable API

From Petr Mladek <pmladek@suse.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 1/2] livepatch: introduce shadow variable API
Date 2017-07-21 10:50 +0200
Message-ID <u5BNf-2yc-7@gated-at.bofh.it> (permalink)
References (2 earlier) <u4g8a-6OB-17@gated-at.bofh.it> <u4Hi2-71I-5@gated-at.bofh.it> <u52w9-4uk-13@gated-at.bofh.it> <u5kW7-lk-35@gated-at.bofh.it> <u5lS9-XA-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu 2017-07-20 11:48:41, Joe Lawrence wrote:
> On 07/20/2017 10:45 AM, Miroslav Benes wrote:
> > 
> >>>>> + *
> >>>>> + * Note: allocates @new_size space for shadow variable data and copies
> >>>>> + * @new_size bytes from @new_data into the shadow varaible's own @new_data
> >>>>> + * space.  If @new_data is NULL, @new_size is still allocated, but no
> >>>>> + * copy is performed.
> >>>>
> >>>> I must say I'm not entirely happy with this. I don't know if this is what 
> >>>> Petr had in mind (I'm sure he'll get to the patch set soon). Calling 
> >>>> memcpy instead of a simple assignment in v1 seems worse. 
> >>>
> >>> This change was a bit of a experiment on my part in reaction to
> >>> adding klp_shadow_get_or_attach().
> >>>
> >>> I like the simplicity of v1's pointer assignment -- in fact, moving all
> >>> allocation responsiblity (klp_shadow meta-data and data[] area) out to
> >>> the caller is doable, though implementing klp_shadow_get_or_attach() and
> >>> and klp_shadow_detach_all() complicates matters, for example, adding an
> >>> alloc/release callback.  I originally attempted this for v2, but turned
> >>> back when the API and implementation grew complicated.  If the memcpy
> >>> and gfp_flag restrictions are too ugly, I can try revisting that
> >>> approach.  Ideas welcome :)
> >>
> >> Well, I didn't like callbacks either :). And no, I do not have a better 
> >> idea. I still need to think about it.
> > 
> > Done and I agree that memcpy approach is not so bad after all :). So I'm 
> > fine with it.
> 
> I looked at it again this morning and a "pass-your-own" allocation API
> always comes back to adding callbacks and other complications :(  In the
> end, most callers will be shadowing pointers and not entire structures,
> so I think the copy isn't too bad.

I agree.

> On a related note, if we keep the allocations and memcpy, how about I
> shift around the attach/get calls like so:
> 
>   __klp_shadow_attach
>     set shadow variable member values
>     memcpy
>     add to hash
> 
>   klp_shadow_attach
>     alloc new shadow var
>     lock
>     call __klp_shadow_attach with new alloc
>     unlock
>
>   klp_shadow_get_or_attach
>     be optimistic, call klp_shadow_get (if found, return it)
>     be pessimistic, alloc new shadow var
>     lock
>       call klp_shadow_get again
>       if unlikely found
>         kfree unneeded alloc
>       else
>         call __klp_shadow_attach with new alloc
>     unlock
>     return whichever shadow var we used

I would really suggest that klp_shadow_attach() prevents adding
duplicates. We should make the API as safe as possible.
Catching unexpected duplicate could safe people a lot of
headaches.

Please read more on this in my review
https://lkml.kernel.org/r/20170718124500.GF3393@pathway.suse.cz

Best Regards,
Petr

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Joe Lawrence <joe.lawrence@redhat.com> - 2017-07-18 22:30 +0200
  Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Josh Poimboeuf <jpoimboe@redhat.com> - 2017-07-19 04:30 +0200
  Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Miroslav Benes <mbenes@suse.cz> - 2017-07-19 21:10 +0200
    Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Miroslav Benes <mbenes@suse.cz> - 2017-07-20 16:50 +0200
      Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Joe Lawrence <joe.lawrence@redhat.com> - 2017-07-20 17:50 +0200
        Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Josh Poimboeuf <jpoimboe@redhat.com> - 2017-07-20 22:30 +0200
        Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Petr Mladek <pmladek@suse.com> - 2017-07-21 10:50 +0200
        Re: [PATCH v2 1/2] livepatch: introduce shadow variable API Miroslav Benes <mbenes@suse.cz> - 2017-07-21 11:10 +0200

csiph-web