Re: [XTF] xenbus: Don't wait if the response ring is full

2020-07-10 Thread Wieczorkiewicz, Pawel


> On 9. Jul 2020, at 20:46, Julien Grall  wrote:
> 
> 
> From: Julien Grall 
> 
> XenStore response can be bigger than the response ring. In this case,
> it is possible to have the ring full (e.g cons = 19 and prod = 1043).
> 
> However, XTF will consider that there is no data and therefore wait for
> more input. This will result to block indefinitely as the ring is full.
> 
> This can be solved by avoiding to mask the difference between prod and
> cons.
> 
> Signed-off-by: Julien Grall 
> ---
> common/xenbus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/xenbus.c b/common/xenbus.c
> index 24fff4872372..f3bb30ac693f 100644
> --- a/common/xenbus.c
> +++ b/common/xenbus.c
> @@ -75,7 +75,7 @@ static void xenbus_read(void *data, size_t len)
> uint32_t prod = ACCESS_ONCE(xb_ring->rsp_prod);
> uint32_t cons = ACCESS_ONCE(xb_ring->rsp_cons);
> 
> -part = mask_xenbus_idx(prod - cons);
> +part = prod - cons;
> 
> /* No data?  Kick xenstored and wait for it to produce some data. */
> if ( !part )
> —
> 2.17.1
> 

Reviewed-by: Pawel Wieczorkiewicz 



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




Re: [Xen-devel] [PATCH v6 00/12] livepatch: new features and fixes

2020-06-12 Thread Wieczorkiewicz, Pawel

> On 11. Jun 2020, at 15:48, George Dunlap  wrote:
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> 
> On Tue, Nov 26, 2019 at 10:14 AM Pawel Wieczorkiewicz  
> wrote:
> This series introduces new features to the livepatch functionality as
> briefly discussed during Xen Developer Summit 2019: [a] and [b].
> It also provides a few fixes and some small improvements.
> 
> Main changes in v6:
> - Added missing action pad field zeroing
> 
> Main changes in v4:
> - Fix various typos and minor issues
> - Simplify arch_livepatch_{apply,revert} by using
>   common_livepatch_{apply,revert}
> - Improve python bindings and fix few issues
> 
> Main changes in v3:
> - Fix expectation test to work on Arm
> - Add test for metadata (Konrad)
> - Minor fixes to documentation
> 
> Main changes in v2:
> - added new features to livepatch documentation
> - added livepatch tests
> - enabled Arm support for [5]
> - make .modinfo optional for [11]
> - fixed typos
> 
> FEATURES:
> 
> 1. independent modules (patches: [1], [2])
> 
>   * livepatch-build-tools repo dependency [A]
> 
>   Livepatch enforces the following buildid-based dependency chain
>   between hotpatch modules:
> 1) first module depends on given hypervisor buildid
> 2) every consecutive module depends on previous module's buildid
>   This way proper hotpatch stack order is maintained and enforced.
>   While it is important for production hotpatches it limits agility and
>   blocks usage of testing or debug hotpatches. These kinds of hotpatch
>   modules are typically expected to be loaded at any time irrespective
>   of current state of the modules stack.
> 
>   [A] livepatch-build: Embed hypervisor build id into every hotpatch
> 
> 2. pre- and post- apply|revert actions hooks (patches: [3], [4])
> 
>   * livepatch-build-tools repo dependency [B]
> 
>   This is an implementation of 4 new livepatch module vetoing hooks,
>   that can be optionally supplied along with modules.
>   Hooks that currently exists in the livepatch mechanism aren't agile
>   enough and have various limitations:
>   * run only from within a quiescing zone
>   * cannot conditionally prevent applying or reverting
>   * do not have access to the module context
>   To address these limitations the following has been implemented:
>   1) pre-apply hook
>   2) post-apply hook
>   3) pre-revert hook
>   4) post-revert hook
> 
>   [B] create-diff-object: Handle extra pre-|post- hooks
> 
> 3. apply|revert actions replacement hooks (patches: [5], [6], [7])
> 
>   * livepatch-build-tools repo dependency: [C], [D], [E]
> 
>   To increase hotpatching system's agility and provide more flexiable
>   long-term hotpatch solution, allow to overwrite the default apply
>   and revert action functions with hook-like supplied alternatives.
>   The alternative functions are optional and the default functions are
>   used by default.
> 
>   [C] create-diff-object: Do not create empty .livepatch.funcs section
>   [D] create-diff-object: Handle optional apply|revert hooks
>   [E] create-diff-object: Add support for applied/reverted marker
> 
> 4. inline asm hotpatching expectations (patches: [8])
> 
>   * livepatch-build-tools repo dependency: [F]
> 
>   Expectations are designed as optional feature, since the main use of
>   them is planned for inline asm hotpatching.
>   The payload structure is modified as each expectation structure is
>   part of the livepatch_func structure and hence extends the payload.
>   The payload version is bumped to 3 with this change to highlight the
>   ABI modification and enforce proper support.
>   The expectation is manually enabled during inline asm module
>   construction. If enabled, expectation ensures that the expected
>   content of memory is to be found at a given patching (old_addr)
>   location.
> 
>   [F] create-diff-object: Add support for expectations
> 
> 5. runtime hotpatch metadata support (patches: [9], [10], [11])
> 
>   Having detailed hotpatch metadata helps to properly identify module's
>   origin and version. It also allows to keep track of the history of
>   hotpatch loads in the system (at least within dmesg buffer size
>   limits).
>   Extend the livepatch list operation to fetch also payloads' metadata.
>   This is achieved by extending the sysctl list interface with 2 extra
>   guest handles:
>   * metadata - an array of arbitrary size strings
>   * metadata_len - an array of metadata strings' lengths (uin32_t each)
>   To unify and simplify the interface, handle the modules' name strings
>   of arbitrary size by copying them in adhering chunks to the userland.
> 
> 6. python bindings for livepatch operations (patches: [12])
> 
>   Extend the XC python bindings library to support all common livepatch
>   operations and actions:
>   - status (pyxc_livepatch_status):
>   - action (pyxc_livepatch_action):
>   - 

Re: [PATCH XTF] vsnprintf: Expand \n to \r\n for console output

2020-06-05 Thread Wieczorkiewicz, Pawel

> On 4. Jun 2020, at 16:12, Andrew Cooper  wrote:
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> xenconsoled doesn't automatically convert \n into \r\n, which causes test
> output appear like this in a terminal:
> 
>  [root@host ~]# xl create -c tests/selftest/test-pv64-selftest.cfg
>  Parsing config from tests/selftest/test-pv64-selftest.cfg
>  --- Xen Test Framework ---
>Environment: PV 64bit (Long mode 4 levels)
>  XTF 
> Selftests
> 
> There are a number of ways to do this, but by far the most efficient way is to
> have vsnprintf() expand \n's in the output buffer.
> 
> This however is non-standard behaviour for vsnprintf().  Rename it to
> vsnprintf_internal() and take extra flags, and have vprintk() use the new
> LF_TO_CRLF control flag.
> 
> Inside vsnprintf_internal(), rearrange the non-format and %c logic to share
> the expansion logic, as well as extending the logic to fmt_string().
> 
> Extend the selftests to confirm correct behaviour in both modes, for all ways
> of being able to pass newline characters into a format operation.
> 
> Reported-by: Pawel Wieczorkiewicz 
> Signed-off-by: Andrew Cooper 
> ---
> Pawel: Does this fix the issues you were seeing?

Yes, it does fix the issue. Thanks.

> ---
> common/console.c|  2 +-
> common/libc/vsnprintf.c | 23 +++
> include/xtf/libc.h  | 15 ++-
> tests/selftest/main.c   | 38 ++
> 4 files changed, 68 insertions(+), 10 deletions(-)
> 
> 



Best Regards,
Pawel Wieczorkiewicz
wipa...@amazon.com




signature.asc
Description: Message signed with OpenPGP



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




Re: [XTF 2/4] lib: always append CR after LF in vsnprintf()

2020-04-21 Thread Wieczorkiewicz, Pawel

> On 20. Apr 2020, at 21:26, Andrew Cooper  wrote:
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On 16/04/2020 12:36, Wieczorkiewicz, Pawel wrote:
>>> Unfortunately, this comes with collateral damage.
>>> 
>>> # ./xtf-runner hvm64 example
>>> Executing 'xl create -p tests/example/test-hvm64-example.cfg'
>>> Executing 'xl console test-hvm64-example'
>>> Executing 'xl unpause test-hvm64-example'
>>> --- Xen Test Framework ---
>>> 
>>> Found Xen: 4.14
>>> 
>>> Environment: HVM 64bit (Long mode 4 levels)
>>> 
>>> Hello World
>>> 
>>> Test result: SUCCESS
>>> 
>>> 
>>> Combined test results:
>>> test-hvm64-example   CRASH
>>> 
>> I never use xtf-runner script to execute tests. I do it the old fashion way:
>> 
>> # xl create -c test-hvm64-example.cfg
>> Parsing config from test-hvm64-example.cfg
> 
> I presume you mean hvm64-cpuid here, but...
> 
>> Guest cpuid information
>>   Native cpuid:
>>  : -> 
>> 000d:756e6547:6c65746e:49656e69
>>  
>>   0001: -> 000306e4:00400800:f7ba2203:1fcbfbff
>>  
>> 
>> 0002: -> 76036301:00f0b2ff::00ca
>> 0003: -> :::
>>  0004: 
>> -> 7c000121:01c0003f:003f:
>>  
>>   0004:0001 -> 
>> 7c000122:01c0003f:003f:
>>  
>>  
>>0004:0002 -> 7c000143:01c0003f:01ff:
>>  
>>  
>>  
>> 0004:0003 -> 7c000163:04c0003f:4fff:0006
>> 0004:0004 -> :::
>>   0005: 
>> -> 0040:0040:0003:1120
>>  
>>0006: -> 
>> 0077:0002:0009:
>>  
>>  
>> 0007: -> :0281::9c000400
>>  
>>  
>>  
>>  0008: -> :::
>>  0009: -> :::
>>000a: 
>> -> 07300403:::0603
>>  
>> 000b: -> 
>> :::
>>  
>>  
>>  000c: -> :::
>>  
>>  
>>  
>>   000d: -> 0007:0240:0340:
>>   000d:0001 -> 00

Re: [XTF 4/4] setup: Setup PV console for HVM guests on xen >4.2

2020-04-16 Thread Wieczorkiewicz, Pawel

> On 16. Apr 2020, at 12:36, Andrew Cooper  wrote:
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On 16/04/2020 10:41, Pawel Wieczorkiewicz wrote:
>> @@ -272,9 +274,23 @@ void arch_setup(void)
>> 
>> init_hypercalls();
>> 
>> -if ( !is_initdomain() )
>> +xen_version = hypercall_xen_version(XENVER_version, NULL);
>> +if ( version )
>> +*version = xen_version;
>> +
>> +/*
>> + * The setup_pv_console function registers a writing function
>> + * that makes hvm guests crash on Xen 4.2
> 
> This comment in particular is rather concerning.  Even if there is a
> configuration issue in 4.2 stopping the PV console from being wired up
> properly, nothing involved in transmitting on the console should crash
> the guest.
> 

I am again a little short on details here. Maybe Paul could chime in.
But, I vagualy remember it was something about the init_pv_console()’s:

if ( port >= (sizeof(shared_info.evtchn_pending) * CHAR_BIT) )
panic("evtchn %u out of evtchn_pending[] range\n", port);

> ~Andrew


Best Regards,
Pawel Wieczorkiewicz
wipa...@amazon.com



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




Re: [XTF 3/4] Enabled serial writing for hvm guests

2020-04-16 Thread Wieczorkiewicz, Pawel

> On 16. Apr 2020, at 12:32, Andrew Cooper  wrote:
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On 16/04/2020 10:41, Pawel Wieczorkiewicz wrote:
>> From: Paul Semel 
>> 
>> setup.c: PV console writing is not working in Xen 4.2 for hvm
>> guests,
> 
> What is not working about it?
> 

Honestly I am little short on details here, I would have to ask Paul or refresh 
my memory.

>> so we make xtf write to COM1 serial port to get its output
>> 
>> Signed-off-by: Paul Semel 
>> Signed-off-by: Pawel Wieczorkiewicz 
>> ---
>> arch/x86/setup.c | 14 ++
>> 1 file changed, 14 insertions(+)
>> 
>> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
>> index 3c84e96..f6fa4df 100644
>> --- a/arch/x86/setup.c
>> +++ b/arch/x86/setup.c
>> @@ -238,6 +238,13 @@ static void qemu_console_write(const char *buf, size_t 
>> len)
>>  : "d" (0x12));
>> }
>> 
>> +static void com1_write(const char *buf, size_t len)
>> +{
>> +asm volatile("rep; outsb"
>> + : "+S" (buf), "+c" (len)
>> + : "d" (0x3f8));
> 
> Despite being 0x3f8, this really isn't uart-compatible COM1.  I presume
> it only works because Qemu doesn't have any real THR delays in its
> emulation.
> 

That can be. Nevertheless, it works for me[tm].

>> +}
>> +
>> static void xen_console_write(const char *buf, size_t len)
>> {
>> hypercall_console_write(buf, len);
>> @@ -246,7 +253,14 @@ static void xen_console_write(const char *buf, size_t 
>> len)
>> void arch_setup(void)
>> {
>> if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
>> +{
>> register_console_callback(qemu_console_write);
>> +}
>> +
>> +if ( IS_DEFINED(CONFIG_HVM) )
>> +{
>> +register_console_callback(com1_write);
> 
> This wires up 0x3f8 even for PVH guests, which I'm guessing isn't
> intentional?  This should be part of the previous if(), but does beg the
> question what is wrong with the existing qemu console?
> 

It turns out that both PVH and HVM guests are PVH ABI compatible,
but PVH does not need qemu console. As per:

01e16ceb arch/x86/hvm/head.S  (Andrew Cooper2018-01-26 16:39:15 
+ 36) /* All HVM XTF guests are compatible with the PVH ABI. */

In order to get serial console via qemu working, I always register com1
handler for both HVM and PVH. Register qemu console only for HVM guests.

> ~Andrew

I use the com1 to make qemu write console output to a file via: 
serial=“file:/tmp/…”

Best Regards,
Pawel Wieczorkiewicz
wipa...@amazon.com



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




Re: [XTF 2/4] lib: always append CR after LF in vsnprintf()

2020-04-16 Thread Wieczorkiewicz, Pawel



> On 16. Apr 2020, at 12:18, Andrew Cooper  wrote:
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On 16/04/2020 10:41, Pawel Wieczorkiewicz wrote:
>> The explicit LFCR sequence guarantees proper line by line formatting
>> in the output.
>> The '\n' character alone on some terminals is not automatically
>> converted to LFCR.
>> 
>> Signed-off-by: Pawel Wieczorkiewicz 
> 
> Up until now, all console destinations have expected POSIX text semantics.
> 
> I presume this is due to the COM1 use presented in the next patch?
> 

No, this is not about that.

> Unfortunately, this comes with collateral damage.
> 
> # ./xtf-runner hvm64 example
> Executing 'xl create -p tests/example/test-hvm64-example.cfg'
> Executing 'xl console test-hvm64-example'
> Executing 'xl unpause test-hvm64-example'
> --- Xen Test Framework ---
> 
> Found Xen: 4.14
> 
> Environment: HVM 64bit (Long mode 4 levels)
> 
> Hello World
> 
> Test result: SUCCESS
> 
> 
> Combined test results:
> test-hvm64-example   CRASH
> 

I never use xtf-runner script to execute tests. I do it the old fashion way:

# xl create -c test-hvm64-example.cfg
Parsing config from test-hvm64-example.cfg
Guest cpuid information
   Native cpuid:
  : -> 
000d:756e6547:6c65746e:49656e69

0001: -> 000306e4:00400800:f7ba2203:1fcbfbff

  
0002: -> 76036301:00f0b2ff::00ca
0003: -> :::
  0004: -> 
7c000121:01c0003f:003f:

0004:0001 -> 
7c000122:01c0003f:003f:


  0004:0002 -> 7c000143:01c0003f:01ff:



0004:0003 -> 7c000163:04c0003f:4fff:0006
 0004:0004 -> :::
   0005: -> 
0040:0040:0003:1120

 0006: -> 
0077:0002:0009:


   0007: -> :0281::9c000400


 
0008: -> :::
  0009: -> :::
000a: 
-> 07300403:::0603

  000b: -> 
:::


000c: -> :::


  
000d: -> 0007:0240:0340:
   000d:0001 -> 0001:::
 000d:0002 
-> 0100:0240::

   4000: -> 
4005:566e6558:65584d4d:4d4d566e

   

Re: [Xen-devel] [PATCH] docs/misc: livepatch: Espace backslash

2020-01-14 Thread Wieczorkiewicz, Pawel


> On 13. Jan 2020, at 23:12, Julien Grall  wrote:
> 
> pandoc is currently failing to generate the pdf with the following
> error:
> ! Undefined control sequence.
> l.1048   metadata string format is: key=value\0
> 
> In this case, we want to print \0 so we need to backslash-escape the
> first character.
> 
> Interestingly pandoc will not complain when creating html and will just
> ignore \0 completely.
> 
> Fixes: 5083e0ff93 ("livepatch: Add metadata runtime retrieval mechanism")
> Signed-off-by: Julien Grall 
> Cc: Pawel Wieczorkiewicz 
> ---
> docs/misc/livepatch.pandoc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/docs/misc/livepatch.pandoc b/docs/misc/livepatch.pandoc
> index 2f3f95ed37..9473ad5991 100644
> --- a/docs/misc/livepatch.pandoc
> +++ b/docs/misc/livepatch.pandoc
> @@ -739,7 +739,7 @@ The caller provides:
>Caller *MUST* allocate enough space to be able to store all received data
>(i.e. total allocated space *MUST* match the `metadata_total_size` value
>provided by the hypervisor). Individual payload metadata string can be of
> -   arbitrary length. The metadata string format is: 
> key=value\0...key=value\0.
> +   arbitrary length. The metadata string format is: 
> key=value\\0...key=value\\0.
>  * `metadata_len` - Virtual address of where to write the length of each 
> metadata
>string of the payload. Caller *MUST* allocate up to `nr` of them. Each 
> *MUST*
>be of sizeof(uint32_t) (4 bytes).
> -- 
> 2.17.1
> 


Sorry for yet another problem...

Reviewed-by: Pawel Wieczorkiewicz 







Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v6 07/12] livepatch: Add per-function applied/reverted state tracking marker

2020-01-06 Thread Wieczorkiewicz, Pawel


On 5. Jan 2020, at 12:36, Andrew Cooper 
mailto:andrew.coop...@citrix.com>> wrote:

On 26/11/2019 10:07, Pawel Wieczorkiewicz wrote:
@@ -1274,6 +1297,9 @@ static void livepatch_do_action(void)
else

break;
@@ -1309,6 +1338,9 @@ static void livepatch_do_action(void)
else
other->rc = revert_payload(other);

+if ( !was_action_consistent(other, rc ? LIVEPATCH_FUNC_APPLIED : 
LIVEPATCH_FUNC_NOT_APPLIED) )
+panic("livepatch: partially reverted payload '%s'!\n", 
other->name);
+
if ( other->rc == 0 )
revert_payload_tail(other);

Coverity highlights that this contains dead code.

The LIVEPATCH_ACTION_REPLACE case, unlike all others, uses other->rc,
which means the rc ? : check will always pass LIVEPATCH_FUNC_APPLIED
into was_action_consistent(), due to the rc = 0 at the head of the case
block.


Yes, this has to be other->rc instead of rc. Thanks!

If this were the only problem, switching rc to other->rc might be ok,
but there look to be other confusions in the surrounding code.  Would
you mind looking over the whole block of code for correct error handling?


What are the confusions in the code? Could you be more specific and point me to 
them?

I have just checked the LIVEPATCH_ACTION_REPLACE case block again.
It looks correct to me. That is, it preserves the original logic of error 
handling there.
I just added the extensions. But, the flow for rc and other->rc should be the 
same
and correct (modulo the was_action_consistent() bug).

For any resulting patch, the Coverity ID is 1457467

~Andrew

else
@@ -1329,6 +1361,9 @@ static void livepatch_do_action(void)
else
rc = apply_payload(data);

+if ( !was_action_consistent(data, rc ? LIVEPATCH_FUNC_NOT_APPLIED 
: LIVEPATCH_FUNC_APPLIED) )
+panic("livepatch: partially applied payload '%s'!\n", 
data->name);
+
if ( rc == 0 )
apply_payload_tail(data);
}



Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-12-02 Thread Wieczorkiewicz, Pawel


> On 27. Nov 2019, at 16:56, Sergey Dyasli  wrote:
> 
> On 27/11/2019 15:22, Wieczorkiewicz, Pawel wrote:
>> 
>> 
>>> On 27. Nov 2019, at 12:16, Sergey Dyasli  wrote:
>>> 
>>> On 26/11/2019 18:37, Wieczorkiewicz, Pawel wrote:
>>>> It looks like gcc plays the usual dirty tricks with local variables 
>>>> renaming:
>>>> 
>>>> - xen-syms
>>>> 7529: 82d0805fed50 8 OBJECT  LOCAL  DEFAULT 4230 lastpage.22857
>>>> - livepatch
>>>> 289:  8 OBJECT  GLOBAL DEFAULT  UND 
>>>> hvm.c#lastpage.22856
>>>> 
>>>> Then, symbols resolution by name fails..
>>>> 
>>>> Can you please try to build the livepatch module with additional option 
>>>> '—prelink' and give it a try ?
>>> 
>>> My LP loading error is:
>>> 
>>>  (XEN) livepatch: lp: Unknown symbol: .LC7
>>> 
>>> When I pass --prelink to livepatch-build, it complains in a similar way:
>>> 
>>>  livepatch-build-tools/prelink: ERROR: output.o: livepatch_resolve_symbols: 
>>> 80: lookup_local_symbol .LC7 (p2m.c)
>>> 
>> 
>> Could you give this testing patch a try?
>> 
>> diff --git a/create-diff-object.c b/create-diff-object.c
>> index 8d63940..10807d2 100644
>> --- a/create-diff-object.c
>> +++ b/create-diff-object.c
>> @@ -839,8 +839,10 @@ static void kpatch_compare_symbols(struct list_head 
>> *symlist)
>>   list_for_each_entry(sym, symlist, list) {
>>   if (sym->twin)
>>   kpatch_compare_correlated_symbol(sym);
>> -   else
>> +   else {
>>   sym->status = NEW;
>> +   sym->include = 1;
>> +   }
>> 
>>   log_debug("symbol %s is %s\n", sym->name, 
>> status_str(sym->status));
>>   }
>> 
> 
> Looks like this change fixed the issue for me!
> One thing to notice is that the size of a stripped LP binary increased
> from 45K to 60K.
> 

Yes, this was not supposed to be a proper fix. I was merely trying to establish 
if we were looking at the same issue.
I did fix it now the proper way, though. I shall send the patches soon.

> --
> Thanks,
> Sergey

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-11-27 Thread Wieczorkiewicz, Pawel


> On 27. Nov 2019, at 12:16, Sergey Dyasli  wrote:
> 
> On 26/11/2019 18:37, Wieczorkiewicz, Pawel wrote:
>> It looks like gcc plays the usual dirty tricks with local variables renaming:
>> 
>> - xen-syms
>>  7529: 82d0805fed50 8 OBJECT  LOCAL  DEFAULT 4230 lastpage.22857
>> - livepatch
>>   289:  8 OBJECT  GLOBAL DEFAULT  UND 
>> hvm.c#lastpage.22856
>> 
>> Then, symbols resolution by name fails..
>> 
>> Can you please try to build the livepatch module with additional option 
>> '—prelink' and give it a try ?
> 
> My LP loading error is:
> 
>(XEN) livepatch: lp: Unknown symbol: .LC7
> 
> When I pass --prelink to livepatch-build, it complains in a similar way:
> 
>livepatch-build-tools/prelink: ERROR: output.o: livepatch_resolve_symbols: 
> 80: lookup_local_symbol .LC7 (p2m.c)
> 

Could you give this testing patch a try?

diff --git a/create-diff-object.c b/create-diff-object.c
index 8d63940..10807d2 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -839,8 +839,10 @@ static void kpatch_compare_symbols(struct list_head 
*symlist)
list_for_each_entry(sym, symlist, list) {
if (sym->twin)
kpatch_compare_correlated_symbol(sym);
-   else
+   else {
sym->status = NEW;
+   sym->include = 1;
+   }

log_debug("symbol %s is %s\n", sym->name, 
status_str(sym->status));
}

> --
> Thanks,
> Sergey

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-11-26 Thread Wieczorkiewicz, Pawel
It looks like gcc plays the usual dirty tricks with local variables renaming:

- xen-syms
  7529: 82d0805fed50 8 OBJECT  LOCAL  DEFAULT 4230 lastpage.22857
- livepatch
   289:  8 OBJECT  GLOBAL DEFAULT  UND hvm.c#lastpage.22856

Then, symbols resolution by name fails..

Can you please try to build the livepatch module with additional option 
'—prelink' and give it a try ?

> On 26. Nov 2019, at 18:51, Wieczorkiewicz, Pawel  wrote:
> 
> 
> 
>> On 20. Nov 2019, at 12:42, Sergey Dyasli  wrote:
>> 
>> On 19/11/2019 17:21, Wieczorkiewicz, Pawel wrote:
>>> 
>>> 
>>>> On 18. Nov 2019, at 18:41, Sergey Dyasli  wrote:
>>>> 
>>>> On 18/11/2019 17:28, Wieczorkiewicz, Pawel wrote:
>>>>> 
>>>>> Could you build the lp with debug (-d) and provide me with the 
>>>>> create-diff-object.log file?
>>>>> 
>>>> 
>>>> I've attached the log. Btw, I think I provided all the necessary 
>>>> information
>>>> for others to repeat my experiment.
>>>> 
>>> 
>>> Sorry for another request, but I do not seem to be able to reproduce this 
>>> locally.
>>> Could you send me the livepatch module binary that fails to upload?
>> 
>> That's interesting. I've attached the binary that my system produces.
>> What version of gcc do you use?
> 
> The version used was: gcc (GCC) 7.2.1 20170915
> 
> But I have finally managed to reproduce the issue with:
> 1. gcc (Ubuntu 6.5.0-2ubuntu1~18.04) 6.5.0 20181026
> 2. gcc-7 (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
> 
> I think it is not related to the commit:
> commit 854a7ca60e35 "create-diff-object: Do not include all .rodata sections"
> 
> I managed to reproduce it also with earlier version commit:
> "0c10457 Remove section alignment requirement"
> 
> But this time a different symbol causes the failure:
> 
> (XEN) livepatch: 0001-live-patch: Unknown symbol: hvm.c#lastpage.22856
> 
>> 
>> --
>> Thanks,
>> Sergey
>> <0001-live-patch-stripped.livepatch>
> 
> Best Regards,
> Pawel Wieczorkiewicz

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-11-26 Thread Wieczorkiewicz, Pawel


> On 20. Nov 2019, at 12:42, Sergey Dyasli  wrote:
> 
> On 19/11/2019 17:21, Wieczorkiewicz, Pawel wrote:
>> 
>> 
>>> On 18. Nov 2019, at 18:41, Sergey Dyasli  wrote:
>>> 
>>> On 18/11/2019 17:28, Wieczorkiewicz, Pawel wrote:
>>>> 
>>>> Could you build the lp with debug (-d) and provide me with the 
>>>> create-diff-object.log file?
>>>> 
>>> 
>>> I've attached the log. Btw, I think I provided all the necessary information
>>> for others to repeat my experiment.
>>> 
>> 
>> Sorry for another request, but I do not seem to be able to reproduce this 
>> locally.
>> Could you send me the livepatch module binary that fails to upload?
> 
> That's interesting. I've attached the binary that my system produces.
> What version of gcc do you use?

The version used was: gcc (GCC) 7.2.1 20170915

But I have finally managed to reproduce the issue with:
1. gcc (Ubuntu 6.5.0-2ubuntu1~18.04) 6.5.0 20181026
2. gcc-7 (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0

I think it is not related to the commit:
commit 854a7ca60e35 "create-diff-object: Do not include all .rodata sections"

I managed to reproduce it also with earlier version commit:
"0c10457 Remove section alignment requirement"

But this time a different symbol causes the failure:

(XEN) livepatch: 0001-live-patch: Unknown symbol: hvm.c#lastpage.22856

> 
> --
> Thanks,
> Sergey
> <0001-live-patch-stripped.livepatch>

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 6/7] livepatch-build: Strip transient or unneeded symbols

2019-11-26 Thread Wieczorkiewicz, Pawel


> On 25. Nov 2019, at 15:38, Ross Lagerwall  wrote:
> 
> On 9/16/19 12:30 PM, Pawel Wieczorkiewicz wrote:
>> In the process of creating a final hotpatch module file make sure to
>> strip all transient symbols that have not been caught and removed by
>> create-diff-object processing. For now these are only the hooks
>> kpatch load/unload symbols.
>> 
>> 

snip

>> function create_patch()
>> {
>> echo "Extracting new and modified ELF sections..."
>> @@ -150,6 +172,7 @@ function create_patch()
>> NEW_FILES=$(comm -23 <(cd patched/xen && find . -type f -name '*.o' | 
>> sort) <(cd original/xen && find . -type f -name '*.o' | sort))
>> for i in $NEW_FILES; do
>> cp "patched/$i" "output/$i"
>> +strip --strip-unneeded "output/$i"
> 
> This strips debug symbols too which is not necessarily desirable and I think 
> for most software is normally left a high level process (e.g. rpmbuild). Can 
> you make this optional please?
> 

Yes, will do. Thanks for looking.

> Thanks,
> -- 
> Ross Lagerwall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v5 00/12] livepatch: new features and fixes

2019-11-20 Thread Wieczorkiewicz, Pawel


> On 20. Nov 2019, at 03:25, Konrad Rzeszutek Wilk  
> wrote:
> 
> On Thu, Nov 14, 2019 at 01:06:41PM +, Pawel Wieczorkiewicz wrote:
>> This series introduces new features to the livepatch functionality as
>> briefly discussed during Xen Developer Summit 2019: [a] and [b].
>> It also provides a few fixes and some small improvements.
>> 
>> Main changes in v4:
>> - Fix various typos and minor issues
>> - Simplify arch_livepatch_{apply,revert} by using
>>  common_livepatch_{apply,revert}
>> - Improve python bindings and fix few issues
> 
> This is https://github.com/konradwilk/xen.git (your patches on top of 
> staging):
> 
> On ARM64:
> root@hikey960:/home/linaro# xl info
> 



> root@hikey960:/home/linaro/xen.git/xen/test/livepatch# xen-livepatch load 
> xen_hello_world.livepatch 
> Uploading xen_hello_world.livepatch... completed
> Applying xen_hello_world... failed
> Error 22: Invalid argument
> Unloading xen_hello_world... failed
> Error 22: Invalid argument
> root@hikey960:/home/linaro/xen.git/xen/test/livepatch# git log
> commit 9f5f25f07a64e1b447f7bd124182a1c5ef422d6f
> Author: Pawel Wieczorkiewicz 
> Date:   Thu Nov 14 13:06:52 2019 +
> 
>livepatch: Add metadata runtime retrieval mechanism
> ...
> 
> 



> oot@hikey960:/# xen-livepatch list
> ID | status | metadata
> ++---
> xen_hello_world | CHECKED| LIVEPATCH_RULEZ
> root@hikey960:/# xl debug-keys x
> (XEN) 'x' pressed - Dumping all livepatch patches
> (XEN) build-id: 8bf9ec5fc0053f4d4fc3b7d256b66ec86f8e5ccc
> (XEN)  name=xen_hello_world state=CHECKED(1) 00a02000 
> (.data=00a03000, .rodata=00a04000) using 3 pages.
> (XEN) livepatch: module metadata:
> (XEN) livepatch:   LIVEPATCH_RULEZ
> (XEN) xen_extra_version patch 00242158(12) with 00a02000 
> (16)
> (XEN) build-id=50159adec7aaec9dae8a6ce3ac6c2d5f9e825bff
> (XEN) depend-on=8bf9ec5fc0053f4d4fc3b7d256b66ec86f8e5ccc
> (XEN) depend-on-xen=8bf9ec5fc0053f4d4fc3b7d256b66ec86f8e5ccc
> root@hikey960:/# xen-livepatch unload xen_hello_world
> Unloading xen_hello_world... failed
> Error 22: Invalid argument
> root@hikey960:/# xen-livepatch list
> ID | status | metadata
> ++---
> xen_hello_world | CHECKED| LIVEPATCH_RULEZ
> 
> 
> Thoughts? 

Yes, this hunk is missing (somehow it did not make it to the v5 patchset, 
sorry):

diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 7747ea83aa..0b21a6aca4 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -976,6 +976,7 @@ static int _xc_livepatch_action(xc_interface *xch,
 sysctl.u.livepatch.u.action.cmd = action;
 sysctl.u.livepatch.u.action.timeout = timeout;
 sysctl.u.livepatch.u.action.flags = flags;
+sysctl.u.livepatch.u.action.pad = 0;

 sysctl.u.livepatch.u.action.name = def_name;
 set_xen_guest_handle(sysctl.u.livepatch.u.action.name.name, name);


Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-11-19 Thread Wieczorkiewicz, Pawel


> On 18. Nov 2019, at 18:41, Sergey Dyasli  wrote:
> 
> On 18/11/2019 17:28, Wieczorkiewicz, Pawel wrote:
>> 
>> Could you build the lp with debug (-d) and provide me with the 
>> create-diff-object.log file?
>> 
> 
> I've attached the log. Btw, I think I provided all the necessary information
> for others to repeat my experiment.
> 

Sorry for another request, but I do not seem to be able to reproduce this 
locally.
Could you send me the livepatch module binary that fails to upload?

> --
> Thanks,
> Sergey
> 

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-11-18 Thread Wieczorkiewicz, Pawel


> On 18. Nov 2019, at 18:09, Sergey Dyasli  wrote:
> 
> On 18/11/2019 16:47, Wieczorkiewicz, Pawel wrote:
>> 
>> 
>>> On 18. Nov 2019, at 17:42, Sergey Dyasli  wrote:
>>> 
>>> Hello,
>>> 
>>> Trying to build a simple version of XSA-304 Live-Patch for 4.13 gives
>>> the following error during LP upload:
>>> 
>>>   (XEN) livepatch: lp: Unknown symbol: .LC7
>>> 
>>> Bisecting identified the first bad commit as:
>>> 
>>>   commit 854a7ca60e35 "create-diff-object: Do not include all .rodata 
>>> sections"
>>> 
>>> Base version of Xen used for this experiment is d13dfb02aafab
>>> The patch file used for LP is attached.
>>> 
>>> --
>>> Thanks,
>>> Sergey
>>> <0001-live-patch.patch>
>> 
>> Could you give this a try?
>> 
>> https://patchwork.kernel.org/patch/11228191/
>> https://patchwork.kernel.org/patch/11228189/
> 
> Unfortunately, those patches didn't resolve the issue for me.
> 
> Forgot to add, my gcc version is
> 
>   gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0

Could you build the lp with debug (-d) and provide me with the 
create-diff-object.log file?

> 
> --
> Thanks,
> Sergey

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] livepatch-build-tools regression

2019-11-18 Thread Wieczorkiewicz, Pawel


> On 18. Nov 2019, at 17:42, Sergey Dyasli  wrote:
> 
> Hello,
> 
> Trying to build a simple version of XSA-304 Live-Patch for 4.13 gives
> the following error during LP upload:
> 
>(XEN) livepatch: lp: Unknown symbol: .LC7
> 
> Bisecting identified the first bad commit as:
> 
>commit 854a7ca60e35 "create-diff-object: Do not include all .rodata 
> sections"
> 
> Base version of Xen used for this experiment is d13dfb02aafab
> The patch file used for LP is attached.
> 
> --
> Thanks,
> Sergey
> <0001-live-patch.patch>

Could you give this a try?

https://patchwork.kernel.org/patch/11228191/
https://patchwork.kernel.org/patch/11228189/

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v4 00/12] livepatch: new features and fixes

2019-10-19 Thread Wieczorkiewicz, Pawel


> On 18. Oct 2019, at 17:34, Ross Lagerwall  wrote:
> 
> On 10/18/19 3:25 PM, Konrad Rzeszutek Wilk wrote:
>> On Sat, Sep 28, 2019 at 03:12:53PM +, Pawel Wieczorkiewicz wrote:
>>> This series introduces new features to the livepatch functionality as
>>> briefly discussed during Xen Developer Summit 2019: [a] and [b].
>>> It also provides a few fixes and some small improvements.
>> Heya,
>> Is there an v5 of the patches somewhere brewing so that I can give them
>> one last test?

Yes, it is… but I am waiting for more reviews before publishing another 
revision.

>> Juergen,
>> Are you OK with giving them an Release-Ack? I think there are only two minor
>> changes that Jan requested.
> 
> I have not yet had time to review some of the patches in v4. I expect I will 
> have time on Monday to look at the rest.
> 

Due to other urgent work I won’t be able to look into this for a week or two.

> Thanks,
> -- 
> Ross Lagerwall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH for-4.13 2/2] xen/nospec: Introduce CONFIG_SPECULATIVE_BRANCH_HARDEN and disable it

2019-10-04 Thread Wieczorkiewicz, Pawel


> On 2. Oct 2019, at 23:02, Andrew Cooper  wrote:
> 
> On 02/10/2019 10:50, Wieczorkiewicz, Pawel wrote:
>>>>>> I've taken, as a simple example,
>>>>>> p2m_mem_access_sanity_check(), and this looks to be the way gcc9 has 
>>>>>> generated
>>>>>> code (in a non-debug build). Hence either I'm mis-remembering what we 
>>>>>> want
>>>>>> things to look like, or there's more to it than code generation simply 
>>>>>> being
>>>>>> "not correct".
>>>>>> 
>>>>> This example demonstrates the problem, and actually throws a further
>>>>> spanner in the works of how make this safe, which hadn't occurred to me
>>>>> before.
>>>>> 
>>>>> The instruction stream from a caller of p2m_mem_access_sanity_check()
>>>>> will look something like this:
>>>>> 
>>>>> call p2m_mem_access_sanity_check
>>>>> ...
>>>>> lfence
>>>>> ...
>>>>> ret   
>>>>> cmp $0, %eax
>>>>> jne ...
>>>>> 
>>>>> Which is unsafe, because the only safe way to arrange this code would be:
>>>>> 
>>>>> call p2m_mem_access_sanity_check
>>>>> ...
>>>>> ret
>>>>> cmp $0, %eax
>>>>> jne 1f
>>>>> lfence
>>>>> ...
>>>>> 1: lfence
>>>>> …
>>>>> 
>>>>> 
> 
> Answering out of order, because I think this will make things clearer.
> 
>> But the hardening wasn’t about spectre v1, but about cache-load gadgets?
> 
> Ultimately, yes - the goal is cache load gadgets.
> 
> Cache load gadgets are any memory read, where the attacker can influence the 
> position of the load.  The easy case to think about is the first half of a 
> Spectre v1 gadget (i.e. the first memory load), but a second common case is a 
> simple memory read with the wrong base pointer (as demonstrated clearly by 
> SpectreGS and CVE-2019-1125).
> 

Yes, that’s right.

> A 3rd case, which is actually the root of this discovery, is speculative type 
> confusion where the processor executes code expecting to use 
> {d,v}->arch.{pv,hvm}.$FOO, but is interpreting the data with the types of the 
> other union.  For people familiar with Speculative Store Bypass gadgets, this 
> is the same kind of thing as the integer/pointer confusion in that case.
> 

Yes, that’s right again. There is also a few other cases like abusing switch 
jump tables etc.
But, I would like to focus on the first half of a Spectre v1 gadgets.

> The only viable fix for these is to avoid entering the basic block with the 
> vulnerable code pattern in the first place.  I.e. "fixing" Spectre v1.
> 

I think that’s not the only viable fix option. But, that depends on the basic 
block construction.
There certainly are basic block where this is the only viable fix. But there 
are also others.

Example 1:

mov (REG1), REG2
cmp $0x0,(REG3)
jne 1
mov (REG2), REG4 # Gadget load
1:
...

In the above case a lfence does not need to protect the branch speculation to 
kill off the cache-load gadget.
The lfence before the cmp instruction would make sure the REG2 holds an actual 
value.

Example 2: (probably a better one)

mov (REG1), REG2
cmp $0x0,REG2
jne 1
mov (REG3), REG4 # Gadget load
1:
...

When putting lfence before the cmp instruction, we limit the chances of 
speculation over the branch.
Same applies to this:

call is_allowed
mov (REG1), REG2
….   
mov REG2, RAX
ret
cmp $0x0,RAX
jne 1
mov (REG2), REG4 # Gadget load
1:
...

Putting lfence before return from the function, so as to have the value for the 
cmp instruction fixed would be also good enough.
(I agree that might not be perfect, but just good enough…)

And finally:
Example 3:

cmp $0x0,(REG1)
jne 1
mov (REG2), REG3 # Gadget load
1:
…

Here indeed not much can be done and we have to put lfences the spectre v1 way.


>> Does it mean the CPU speculates over a direct call (assuming no #PF etc) and
>> assumes some default return value to be used?
>> 
> 
> That wasn't the point I was trying to make, although Intel CPUs will 
> speculatively execute the instructions following an indirect call/jmp while 
> the frontend works out where to fetch from next.
> 

Yes, indirect call/jmp instruction could speculate, but that’s out of scope for 
this discussion.

> The point was that, to avoid entering the wrong basic block, the lfence must 
> be later in the instruction stream than the conditional jump.  The frontend 
> has to follow the attacker control

Re: [Xen-devel] [PATCH for-4.13 2/2] xen/nospec: Introduce CONFIG_SPECULATIVE_BRANCH_HARDEN and disable it

2019-10-02 Thread Wieczorkiewicz, Pawel


> On 1. Oct 2019, at 17:37, Andrew Cooper  wrote:
> 
> On 01/10/2019 15:32, Jan Beulich wrote:
>> On 01.10.2019 14:51, Andrew Cooper wrote:
>>> On 01/10/2019 13:21, Jan Beulich wrote:
 On 30.09.2019 20:24, Andrew Cooper wrote:
> The code generation for barrier_nospec_true() is not correct.  We are 
> taking a
> perf it from the added fences, but not gaining any speculative safety.
 You want to be more specific here, I think: ISTR you saying that the 
 LFENCEs
 get inserted at the wrong place.
>>> Correct.
>>> 
 IIRC we want them on either side of a
 conditional branch, i.e. immediately following a branch insn as well as 
 right
 at the branch target.
>>> Specifically, they must be at the head of both basic blocks following
>>> the conditional jump.
>>> 
 I've taken, as a simple example,
 p2m_mem_access_sanity_check(), and this looks to be the way gcc9 has 
 generated
 code (in a non-debug build). Hence either I'm mis-remembering what we want
 things to look like, or there's more to it than code generation simply 
 being
 "not correct".
>>> This example demonstrates the problem, and actually throws a further
>>> spanner in the works of how make this safe, which hadn't occurred to me
>>> before.
>>> 
>>> The instruction stream from a caller of p2m_mem_access_sanity_check()
>>> will look something like this:
>>> 
>>> call p2m_mem_access_sanity_check
>>> ...
>>> lfence
>>> ...
>>> ret   
>>> cmp $0, %eax
>>> jne ...
>>> 
>>> Which is unsafe, because the only safe way to arrange this code would be:
>>> 
>>> call p2m_mem_access_sanity_check
>>> ...
>>> ret
>>> cmp $0, %eax
>>> jne 1f
>>> lfence
>>> ...
>>> 1: lfence
>>> …
>>> 

Does it mean the CPU speculates over a direct call (assuming no #PF etc) and
assumes some default return value to be used?

If not, maybe we should be more concerned about the value the cache-loading
gadget speculates with, rather than the sheer speculation over the branch.

Am I mis(understanding) something here? I would be thankful for explanation.

>>> There is absolutely no possible way for inline assembly to be used to
>>> propagate this safety property across translation units.  This is going
>>> to have to be an attribute of some form or another handled by the compiler.
>> But you realize that this particular example is basically a more
>> complex is_XYZ() check, which could be dealt with by inlining the
>> function. Of course there are going to be larger functions where
>> the result wants to be guarded like you say. But just like the
>> addition of the nospec macros to various is_XYZ() functions is a
>> manual operation (as long the compiler doesn't help), it would in
>> that case be a matter of latching the return value into a local
>> variable and using an appropriate guarding construct when
>> evaluating it.
> 
> And this reasoning demonstrates yet another problem (this one was raised
> at the meeting in Chicago).
> 
> evaluate_nospec() is not a useful construct if it needs inserting at
> every higher level predicate to result in safe code.  This is
> boarderline-impossible to review for, and extremely easy to break
> accidentally.
> 
>> 
>> So I'm afraid for now I still can't agree with your "not correct"
>> assessment - the generated code in the example looks correct to
>> me, and if further guarding was needed in users of this particular
>> function, it would be those users which would need further
>> massaging.
> 
> Safety against spectre v1 is not a matter of opinion.
> 

But the hardening wasn’t about spectre v1, but about cache-load gadgets?

> To protect against speculatively executing the wrong basic block, the
> pipeline must execute the conditional jump first, *then* hit an lfence
> to serialise the instruction stream and revector in the case of
> incorrect speculation.

That’s true, but there are also 2 aspects worth mentioning:
1) Example:

jne 1
PRIVILEGED
1:
ALWAYS_SAFE

We do not necessarily have to cover the 1: path with an lfence?
We could allow speculation there, as it is harmless.

2) cache-load protection

It might be ok to speculate over a conditional branch, when we can
guarantee that the value to be used in a dereference is not out-of-bound.
In that case an lfence is used to latch the value in the register. We can
still speculate over the branch and reach the dereference, but with a sane 
value.

I agree that lfence might not give us 100% security in every potential case,
but that is what "hardening" gives you...

> 
> The other way around is not safe.  Serialising the instruction stream
> doesn't do anything to protect against the attacker taking control of a
> later branch.
> 

Sure, but it may do something about the value used to dereference memory
when the speculation happens over the branch.

> The bigger problem is to do with classifying what we are protecting
> against.  In the case of is_control_domain(), it is any action based on
> the result of 

Re: [Xen-devel] [PATCH v4 12/12] livepatch: Add python bindings for livepatch operations

2019-10-01 Thread Wieczorkiewicz, Pawel


> On 30. Sep 2019, at 17:13, Ross Lagerwall  wrote:
> 
> On 9/28/19 4:13 PM, Pawel Wieczorkiewicz wrote:
>> Extend the XC python bindings library to support also all common
snip
>> 
>> +
>> +fd = open(filename, O_RDONLY);
>> +if ( fd < 0 )
>> +goto error;
>> +
>> +if ( fstat(fd, ) != 0 )
>> +goto error;
>> +
>> +len = buf.st_size;
>> +fbuf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
>> +if ( fbuf == MAP_FAILED )
>> +goto error;
>> +
>> +rc = xc_livepatch_upload(self->xc_handle, name, fbuf, len);
>> +
>> +saved_errno = errno;
>> +munmap(fbuf, len);
>> +close(fd);
>> +errno = saved_errno;
>> +
>> +error:
>> +return rc ? pyxc_error_to_exception(self->xc_handle) : Py_None;
>> +}
>> +
> The fstat() and mmap() error paths leak fd on error.
> 

Oh boy, the better is sometimes an enemy of good :-).
I will fix it, thanks!

> Regards,
> -- 
> Ross Lagerwall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v4 02/12] livepatch: Allow to override inter-modules buildid dependency

2019-09-30 Thread Wieczorkiewicz, Pawel


> On 30. Sep 2019, at 13:05, Jan Beulich  wrote:
> 
> On 28.09.2019 17:12, Pawel Wieczorkiewicz wrote:
>> --- a/xen/include/public/sysctl.h
>> +++ b/xen/include/public/sysctl.h
>> @@ -35,7 +35,7 @@
>> #include "domctl.h"
>> #include "physdev.h"
>> 
>> -#define XEN_SYSCTL_INTERFACE_VERSION 0x0012
>> +#define XEN_SYSCTL_INTERFACE_VERSION 0x0013
> 
> Oh, I see.
> 
>> @@ -956,6 +956,15 @@ struct xen_sysctl_livepatch_action {
>> /* hypervisor default. */
>> /* Or upper bound of time (ns) */
>> /* for operation to take. */
>> +
>> +/*
>> + * Overwrite default inter-module buildid dependency chain enforcement.
>> + * Check only if module is built for given hypervisor by comparing buildid.
>> + */
>> +#define LIVEPATCH_ACTION_APPLY_NODEPS (1 << 0)
>> +uint64_t flags; /* IN: action flags. */
>> +/* Provide additional 
>> parameters */
>> +/* for an action. */
> 
> 64 bits seems quite a lot (and unusual) for a flags field. Also,

When I use uint32_t for the flags, I would have to also add another
one for padding I suppose.
Why not just use that space for future flags? So, I chose uint64_t.

> as a nit, do you perhaps mean "override" instead of "overwrite"
> in the comment?
> 

Indeed I do. Will fix in v5.

> Jan

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v4 10/12] livepatch: Handle arbitrary size names with the list operation

2019-09-30 Thread Wieczorkiewicz, Pawel


> On 30. Sep 2019, at 10:50, Jan Beulich  wrote:
> 
> On 28.09.2019 17:13, Pawel Wieczorkiewicz wrote:
>> --- a/xen/include/public/sysctl.h
>> +++ b/xen/include/public/sysctl.h
>> @@ -925,10 +925,11 @@ struct xen_sysctl_livepatch_get {
>>  *
>> 
snip
>> uint32_t pad;   /* IN: Must be zero. */
>> +uint32_t name_total_size;   /* OUT: Total size of all 
>> transfer names */
>> XEN_GUEST_HANDLE_64(xen_livepatch_status_t) status;  /* OUT. Must have 
>> enough
>>space allocate for nr of 
>> them. */
>> XEN_GUEST_HANDLE_64(char) name; /* OUT: Array of names. Each 
>> member
>> -   MUST XEN_LIVEPATCH_NAME_SIZE 
>> in size.
>> -   Must have nr of them. */
>> +   may have an arbitrary length 
>> up to
>> +   XEN_LIVEPATCH_NAME_SIZE 
>> bytes. Must have
>> +   nr of them. */
>> XEN_GUEST_HANDLE_64(uint32) len;/* OUT: Array of lengths of 
>> name's.
>>Must have nr of them. */
>> };
> 
> Non-binary-compatible changes require an interface version bump.

The bump happens with this patch of the patchset:
https://patchwork.kernel.org/patch/11165427/

> I wonder though why you don't use the "pad" field; in fact the
> way you make the change you'd have to introduce a 2nd padding
> field, to make padding explicit _and_ check it's zero on input
> (for future extensibility _without_ having to bump the interface
> version).
> 

I do not use the pad field because I introduce another field with the
next patch of the patchset: https://patchwork.kernel.org/patch/11165433/
Then I would have to re-add the pad field again I suppose.
Also, I was (false?) impression that the pad field is dedicated to
the future input parameters, so I should not touch it.

> Jan

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v3 12/12] livepatch: Add python bindings for livepatch operations

2019-09-26 Thread Wieczorkiewicz, Pawel


> On 25. Sep 2019, at 18:47, Ross Lagerwall  wrote:
> 
> On 9/16/19 12:40 PM, Pawel Wieczorkiewicz wrote:
>> Extend the XC python bindings library to support also all common
>> livepatch operations and actions.
>> Add the python bindings for the following operations:
>> - status (pyxc_livepatch_status):
>>   Requires a payload name as an input.
>>   Returns a status dict containing a state string and a return code
>>   integer.
>> - action (pyxc_livepatch_action):
>>   Requires a payload name and an action id as an input. Timeout and
>>   flags are optional parameters.
>>   Returns a return code integer.
>> - upload (pyxc_livepatch_upload):
>>   Requires a payload name and a module's filename as an input.
>>   Returns a return code integer.
>> - list (pyxc_livepatch_list):
>>   Takes no parameters.
>>   Returns a list of dicts containing each payload's:
>>   * name as a string
>>   * state as a string
>>   * return code as an integer
>>   * list of metadata key=value strings
>> Each functions throws an exception error based on the errno value
>> received from its corresponding libxc function call.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Martin Mazein 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Leonard Foerster 
>> Reviewed-by: Norbert Manthey 
>> Acked-by: Marek Marczykowski-Górecki 
> 
> This will be very useful, thanks!
> 
>> ---
>> Changed since v1:
>>   * changed PyList_Append() with PyList_SetItem() as requested by
>> Marek
>>  tools/python/xen/lowlevel/xc/xc.c | 273 
>> ++
>>  1 file changed, 273 insertions(+)
> snip> +static PyObject *pyxc_livepatch_action(XcObject *self,
>> +   PyObject *args,
>> +   PyObject *kwds)
>> +{
>> +int (*action_func)(xc_interface *xch, char *name, uint32_t timeout, 
>> uint64_t flags);
>> +char *name;
>> +unsigned int action;
>> +uint32_t timeout;
>> +uint64_t flags;
>> +int rc;
>> +
>> +static char *kwd_list[] = { "name", "action", "timeout", "flags", NULL 
>> };
>> +
>> +if ( !PyArg_ParseTupleAndKeywords(args, kwds, "sI|Ik", kwd_list,
>> +  , , , ) )
>> +goto error;
>> +
>> +switch (action)
>> +{
>> +case LIVEPATCH_ACTION_UNLOAD:
>> +action_func = xc_livepatch_unload;
>> +break;
>> +case LIVEPATCH_ACTION_REVERT:
>> +action_func = xc_livepatch_revert;
>> +break;
>> +case LIVEPATCH_ACTION_APPLY:
>> +action_func = xc_livepatch_apply;
>> +break;
>> +case LIVEPATCH_ACTION_REPLACE:
>> +action_func = xc_livepatch_replace;
>> +break;
>> +default:
>> +goto error;
>> +}
>> +
>> +rc = action_func(self->xc_handle, name, timeout, flags);
>> +if ( rc )
>> +goto error;
>> +
>> +return Py_BuildValue("i", rc);
> 
> For this and all the other functions which return zero on success, IMO 
> returning None would be more Pythonic.
> 

OK, will change.

>> +error:
>> +return pyxc_error_to_exception(self->xc_handle);
>> +}
>> +
>> +static PyObject *pyxc_livepatch_upload(XcObject *self,
>> +   PyObject *args,
>> +   PyObject *kwds)
>> +{
>> +unsigned char *fbuf = MAP_FAILED;
>> +char *name, *filename;
>> +struct stat buf;
>> +int fd = 0, rc;
>> +ssize_t len;
>> +
>> +static char *kwd_list[] = { "name", "filename", NULL };
>> +
>> +if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ss", kwd_list,
>> +  , ))
>> +goto error;
>> +
>> +fd = open(filename, O_RDONLY);
>> +if ( fd < 0 )
>> +goto error;
>> +
>> +if ( stat(filename, ) != 0 )
>> +goto error;
> 
> I think it would be better to use fstat() to avoid a second path lookup 
> potentially pointing to a different file.
> 

Ah, certainly! Will fix.

>> +
>> +len = buf.st_size;
>> +fbuf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
>> +if ( fbuf == MAP_FAILED )
>> +goto error;
>> +
>> +rc = xc_livepatch_upload(self->xc_handle, name, fbuf, len);
>> +if ( rc )
>> +goto error;
>> +
>> +if ( munmap(fbuf, len) )
>> +{
>> +fbuf = MAP_FAILED;
>> +goto error;
>> +}
>> +close(fd);
>> +
>> +return Py_BuildValue("i", rc);;
> 
> Stray semicolon

ACK

> 
>> +error:
>> +if ( fbuf != MAP_FAILED )
>> +munmap(fbuf, len);
>> +if ( fd >= 0 )
>> +close(fd);
> 
> You should probably save & restore errno so you can return the original error.
> 

Yes, that’s right. Will fix.

>> +return pyxc_error_to_exception(self->xc_handle);
> 
> Maybe you can have a conditional return to avoid duplicating the munmap() & 
> close()? E.g.
> 
> return rc ? pyxc_error_to_exception(self->xc_handle) : …
> 

Oh, this indeed can work. Let me apply that. Thanks.

>> +}
>> +
>> +static 

Re: [Xen-devel] [PATCH v3 11/12] livepatch: Add metadata runtime retrieval mechanism

2019-09-25 Thread Wieczorkiewicz, Pawel


> On 25. Sep 2019, at 17:47, Ross Lagerwall  wrote:
> 
> On 9/16/19 11:59 AM, Pawel Wieczorkiewicz wrote:
>> Extend the livepatch list operation to fetch also payloads' metadata.
>> This is achieved by extending the sysctl list interface with 2 extra
>> guest handles:
>> * metadata - an array of arbitrary size strings
>> * metadata_len - an array of metadata strings' lengths (uin32_t each)
> 
> uint32_t

ACK

> 
>> Payloads' metadata is a string of arbitrary size and does not have an
>> upper bound limit. It may also vary in size between payloads.
>> In order to let the userland allocate enough space for the incoming
>> data add a metadata total size field to the list sysctl operation and
>> fill it with total size of all payloads' metadata.
> snip> + * `metadata` - Virtual address of where to write the metadata of the 
> payloads.
>> +   Caller *MUST* allocate enough space to be able to store all received data
>> +   (i.e. total allocated space *MUST* match the `metadata_total_size` value
>> +   provided by the hypervisor). Individual payload metadata string can be of
>> +   arbitrary length. The metadata string format is: 
>> key=value\0...key=value\0.
>> + * `metadata_len` - Virtual address of where to write the length of each 
>> metadata
>> +   string of the payload. Caller *MUST* allocate up to `nr` of them. Each 
>> *MUST*
>> +   be of sizeof(uint32_t) (4 bytes).
>>If the hypercall returns an positive number, it is the number (upto `nr`
>>  provided to the hypercall) of the payloads returned, along with `nr` updated
>>  with the number of remaining payloads, `version` updated (it may be the same
>>  across hypercalls - if it varies the data is stale and further calls could
>> -fail) and the `name_total_size` containing total size of transfered data for
>> -the array. The `status`, `name`, and `len` are updated at their designed 
>> index
>> -value (`idx`) with the returned value of data.
>> +fail), `name_total_size` and `metadata_total_size` containing total sizes of
>> +transfered data for both the arrays.
> 
> transferred

ACK

> 
>> +The `status`, `name`, `len`, `metadata` and `metadata_len` are updated at 
>> their
>> +designed index value (`idx`) with the returned value of data.
>>If the hypercall returns -XEN_E2BIG the `nr` is too big and should be
>>  lowered.
>> @@ -780,6 +790,7 @@ The structure is as follow:
>> OUT: How many payloads 
>> left. */
>>  uint32_t pad;   /* IN: Must be zero. */
>>  uint64_t name_total_size;   /* OUT: Total size of all 
>> transfer names */
>> +uint64_t metadata_total_size;   /* OUT: Total size of all 
>> transfer metadata */
>>  XEN_GUEST_HANDLE_64(xen_livepatch_status_t) status;  /* OUT. Must 
>> have enough
>> space allocate for nr of 
>> them. */
>>  XEN_GUEST_HANDLE_64(char) name; /* OUT: Array of names. 
>> Each member
>> @@ -788,6 +799,12 @@ The structure is as follow:
>> nr of them. */
>>  XEN_GUEST_HANDLE_64(uint32) len;/* OUT: Array of lengths of 
>> name's.
>> Must have nr of them. */
>> +XEN_GUEST_HANDLE_64(char) metadata; /* OUT: Array of metadata 
>> strings. Each
>> +   member may have an 
>> arbitrary length.
>> +   Must have nr of them. */
>> +XEN_GUEST_HANDLE_64(uint32) metadata_len;  /* OUT: Array of lengths 
>> of metadata's.
>> +  Must have nr of them. 
>> */
>> +
>>  };
>>  
> snip
>> @@ -744,6 +753,8 @@ int xc_livepatch_list(xc_interface *xch, const unsigned 
>> int max,
>>struct xen_livepatch_status *info,
>>char *name, uint32_t *len,
>>const uint64_t name_total_size,
>> +  char *metadata, uint32_t *metadata_len,
>> +  const uint64_t metadata_total_size,
>>unsigned int *done, unsigned int *left)
>>  {
>>  int rc;
>> @@ -752,13 +763,16 @@ int xc_livepatch_list(xc_interface *xch, const 
>> unsigned int max,
>>  DECLARE_HYPERCALL_BOUNCE(info, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
>>  DECLARE_HYPERCALL_BOUNCE(name, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
>>  DECLARE_HYPERCALL_BOUNCE(len, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
>> +DECLARE_HYPERCALL_BOUNCE(metadata, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
>> +DECLARE_HYPERCALL_BOUNCE(metadata_len, 0, 
>> XC_HYPERCALL_BUFFER_BOUNCE_OUT);
>>  uint32_t max_batch_sz, nr;
>>  uint32_t version = 0, retries = 0;
>>  uint32_t adjust = 0;
>> -off_t name_off = 0;
>> -uint64_t name_sz;
>> +off_t name_off = 0, metadata_off = 0;
>> +uint64_t 

Re: [Xen-devel] [PATCH v3 08/12] livepatch: Add support for inline asm hotpatching expectations

2019-09-23 Thread Wieczorkiewicz, Pawel


> On 19. Sep 2019, at 18:06, Ross Lagerwall  wrote:
> 
> On 9/16/19 11:59 AM, Pawel Wieczorkiewicz wrote:
>> This is the initial implementation of the expectations enhancement
>> to improve inline asm hotpatching.
>> Expectations are designed as optional feature, since the main use of
>> them is planned for inline asm hotpatching. The flag enabled allows
>> to control the expectation state.
>> Each expectation has data and len fields that describe the data
>> that is expected to be found at a given patching (old_addr) location.
>> The len must not exceed the data array size. The data array size
>> follows the size of the opaque array, since the opaque array holds
>> the original data and therefore must match what is specified in the
>> expectation (if enabled).
>> The payload structure is modified as each expectation structure is
>> part of the livepatch_func structure and hence extends the payload.
>> Each expectation is checked prior to the apply action (i.e. as late
>> as possible to check against the most current state of the code).
>> For the replace action a new payload's expectations are checked AFTER
>> all applied payloads are successfully reverted, but BEFORE new payload
>> is applied. That breaks the replace action's atomicity and in case of
>> an expectation check failure would leave a system with all payloads
>> reverted. That is obviously insecure. Use it with caution and act
>> upon replace errors!
> snip
>>   * Lookup specified section and when exists assign its address to a 
>> specified hook.
>>   * Perform section pointer and size validation: single hook sections must 
>> contain a
>> @@ -1345,6 +1400,20 @@ static void livepatch_do_action(void)
>>if ( rc == 0 )
>>  {
>> +/*
>> + * Make sure all expectation requirements are met.
>> + * Beware all the payloads are reverted at this point.
>> + * If expectations are not met the system is left in a
>> + * completely UNPATCHED state!
>> + */
>> +rc = livepatch_check_expectations(data);
>> +if ( rc )
>> +{
>> +printk(XENLOG_ERR LIVEPATCH "%s: SYSTEM MIGHT BE INSECURE: "
>> +   "Replace action has been aborted after reverting ALL 
>> payloads!\n", data->name);
>> +break;
>> +}
>> +
>>  if ( is_hook_enabled(data->hooks.apply.action) )
>>  {
>>  printk(XENLOG_INFO LIVEPATCH "%s: Calling apply action hook 
>> function\n", data->name);
>> @@ -1798,6 +1867,11 @@ static int livepatch_action(struct 
>> xen_sysctl_livepatch_action *action)
>>  break;
>>  }
>>  +/* Make sure all expectation requirements are met. */
>> +rc = livepatch_check_expectations(data);
>> +if ( rc )
>> +break;
>> +
>>  if ( is_hook_enabled(data->hooks.apply.pre) )
>>  {
>>  printk(XENLOG_INFO LIVEPATCH "%s: Calling pre-apply hook 
>> function\n", data->name);
> 
> I wonder if this should be done in the critical region for consistency with 
> the replace code and to minimize the chance of something going wrong between 
> calling the sysctl and the patching actually happening. Thoughts?
> 

I would not do it. At least not at the moment.
The intention behind the expectation feature is to prevent an attempt to load a 
livepatch module with some inline asm patching on a machine,
whose memory content of particular .text* section does not match.

I wanted to do it as early as possible, before any mutating action of a pre 
apply hook (an for inline asm patching preapply hook can be (ab)used often) 
kicks in.
Also, it would be good to have the expectation check always there, even with 
replaced default apply/revert action hooks.

Except from the replace action situation, the memory content of the affected 
.text* section is unlikely to change, so it should be good enough for the 
general case.
When it comes to the replace action, we should discuss it further I think, and 
maybe devise a solution on top of the current one.

> The patch looks fine otherwise.
> 

Thanks!

> Ross

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v3 07/12] livepatch: Add per-function applied/reverted state tracking marker

2019-09-20 Thread Wieczorkiewicz, Pawel

> On 19. Sep 2019, at 17:18, Ross Lagerwall  wrote:
> 
> On 9/16/19 11:59 AM, Pawel Wieczorkiewicz wrote:
>> Livepatch only tracks an entire payload applied/reverted state. But,
>> with an option to supply the apply_payload() and/or revert_payload()
>> functions as optional hooks, it becomes possible to intermix the
>> execution of the original apply_payload()/revert_payload() functions
>> with their dynamically supplied counterparts.
>> It is important then to track the current state of every function
>> being patched and prevent situations of unintentional double-apply
>> or unapplied revert.
>> To support that, it is necessary to extend public interface of the
>> livepatch. The struct livepatch_func gets additional field holding
>> the applied/reverted state marker.
>> To reflect the livepatch payload ABI change, bump the version flag
>> LIVEPATCH_PAYLOAD_VERSION up to 2.
>> [And also update the top of the design document]
> snip> @@ -834,6 +839,8 @@ struct livepatch_func {
>>  uint32_t old_size;
>>  uint8_t version;/* MUST be LIVEPATCH_PAYLOAD_VERSION. */
>>  uint8_t opaque[31];
>> +uint8_t applied;
>> +uint8_t _pad[7];
>>  };
>>  typedef struct livepatch_func livepatch_func_t;
>>  #endif
>> diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h
>> index 2aec532ee2..28f9536776 100644
>> --- a/xen/include/xen/livepatch.h
>> +++ b/xen/include/xen/livepatch.h
>> @@ -109,6 +109,31 @@ static inline int livepatch_verify_distance(const 
>> struct livepatch_func *func)
>>return 0;
>>  }
>> +
>> +static inline bool_t is_func_applied(const struct livepatch_func *func)
> 
> Use bool rather than bool_t (throughout the patch).
> 

ACK.

>> +{
>> +if ( func->applied == LIVEPATCH_FUNC_APPLIED )
>> +{
>> +printk(XENLOG_WARNING LIVEPATCH "%s: %s has been already applied 
>> before\n",
>> +__func__, func->name);
> 
> How about dropping this function and having a wrapper function like this:
> 
> common_livepatch_apply() {
>if (func->applied == LIVEPATCH_FUNC_APPLIED) {
>WARN(...)
>return
>}
> 
>arch_livepatch_apply()
> 
>func->applied = LIVEPATCH_FUNC_APPLIED
> }
> 
> This could be used by the normal apply code and any apply hooks.
> 
> This avoids having duplicate code in each of the architectures that is not 
> arch specific and also avoids having a state querying function emit a warning 
> which seems odd to me.
> 

Yes. That makes a lot of sense. Let me do that.

Thanks.

>> +return true;
>> +}
>> +
>> +return false;
>> +}
>> +
>> +static inline bool_t is_func_reverted(const struct livepatch_func *func)
>> +{
>> +if ( !func->old_addr || func->applied == LIVEPATCH_FUNC_NOT_APPLIED )
>> +{
>> +printk(XENLOG_WARNING LIVEPATCH "%s: %s has not been applied 
>> before\n",
>> +__func__, func->name);
>> +return true;
>> +}
>> +
>> +return false;
>> +}
>> +
>>  /*
>>   * These functions are called around the critical region patching live code,
>>   * for an architecture to take make appropratie global state adjustments.
>> @@ -117,7 +142,7 @@ int arch_livepatch_quiesce(void);
>>  void arch_livepatch_revive(void);
>>  
> -- 
> Ross Lagerwall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] create-diff-object: more precisely identify .rodata sections

2019-09-19 Thread Wieczorkiewicz, Pawel


> On 18. Sep 2019, at 17:23, Lars Kurth  wrote:
> 
> 
> 
> On 18/09/2019, 12:27, "Wieczorkiewicz, Pawel"  wrote:
> 
> 
> 
>> On 18. Sep 2019, at 13:19, Julien Grall  wrote:
>> 
>> Hi Pawel,
>> 
>> On 18/09/2019 11:44, Wieczorkiewicz, Pawel wrote:
>>>> On 18. Sep 2019, at 12:41, Ian Jackson  wrote:
>>>> 
>>>> Julien Grall writes ("Re: [PATCH] create-diff-object: more precisely 
>>>> identify .rodata sections"):
>>>>> On 18/09/2019 10:52, Wieczorkiewicz, Pawel wrote:
>>>>>> $ scripts/./add_maintainers.pl -d ~/git/livepatch-build-tools
>>>>> 
>>>>> '-d' only tells you where the patches files are. The script will look up 
>>>>> for the
>>>>> MAINTAINERS file in the current directory.
>>>> 
>>>> Hmmm.  I wonder if we could detect this situation somehow.  This will
>>>> be a common user error I think.
>>>> 
>>> I should have looked twice before sending the patch out. But, what would be 
>>> very helpful for me
>>> is additional option to the add_maintainers.pl script like: -m ./MAINTAINERS
>> 
>> Well the filename will always be the same, so at best you will provide 
>> redundant information.
> 
>Not if I create a git-ignored symlink to the other repo.
> 
> You could also put add_maintainers.pl on the path
> 
> Until I implement a fix,  I fixed the docs. See
> * 
> https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches#Using_add_maintainers.pl_.28or_get_maintainer.pl.29_from_outside_of_xen.git
>  
> * 
> https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches#Setting_that_help_save_you_time
>  
> 

Thank you Lars. I updated my scripts and workflows accordingly.

> Lars

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] create-diff-object: more precisely identify .rodata sections

2019-09-18 Thread Wieczorkiewicz, Pawel


> On 18. Sep 2019, at 13:19, Julien Grall  wrote:
> 
> Hi Pawel,
> 
> On 18/09/2019 11:44, Wieczorkiewicz, Pawel wrote:
>>> On 18. Sep 2019, at 12:41, Ian Jackson  wrote:
>>> 
>>> Julien Grall writes ("Re: [PATCH] create-diff-object: more precisely 
>>> identify .rodata sections"):
>>>> On 18/09/2019 10:52, Wieczorkiewicz, Pawel wrote:
>>>>> $ scripts/./add_maintainers.pl -d ~/git/livepatch-build-tools
>>>> 
>>>> '-d' only tells you where the patches files are. The script will look up 
>>>> for the
>>>> MAINTAINERS file in the current directory.
>>> 
>>> Hmmm.  I wonder if we could detect this situation somehow.  This will
>>> be a common user error I think.
>>> 
>> I should have looked twice before sending the patch out. But, what would be 
>> very helpful for me
>> is additional option to the add_maintainers.pl script like: -m ./MAINTAINERS
> 
> Well the filename will always be the same, so at best you will provide 
> redundant information.

Not if I create a git-ignored symlink to the other repo.

> 
> However, it is not uncommon to have script that needs to apply on the current 
> directory. What would a new option add? Is it just avoid to do a "cd ..." 
> before?
> 

Mainly the new option will avoid the 'cd', but it will also force me to specify 
the right file.

The option can be totally optional with a CWD as a default fallback.

> Cheers,
> 
> -- 
> Julien Grall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] create-diff-object: more precisely identify .rodata sections

2019-09-18 Thread Wieczorkiewicz, Pawel


> On 18. Sep 2019, at 12:41, Ian Jackson  wrote:
> 
> Julien Grall writes ("Re: [PATCH] create-diff-object: more precisely identify 
> .rodata sections"):
>> On 18/09/2019 10:52, Wieczorkiewicz, Pawel wrote:
>>> $ scripts/./add_maintainers.pl -d ~/git/livepatch-build-tools
>> 
>> '-d' only tells you where the patches files are. The script will look up for 
>> the 
>> MAINTAINERS file in the current directory.
> 
> Hmmm.  I wonder if we could detect this situation somehow.  This will
> be a common user error I think.
> 

I should have looked twice before sending the patch out. But, what would be 
very helpful for me
is additional option to the add_maintainers.pl script like: -m ./MAINTAINERS

> Ian.

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] create-diff-object: more precisely identify .rodata sections

2019-09-18 Thread Wieczorkiewicz, Pawel


> On 18. Sep 2019, at 11:49, Jan Beulich  wrote:
> 
> On 18.09.2019 09:35, Pawel Wieczorkiewicz wrote:
>> This is needed for more precise patchability verification.
>> Only non-special .rodata sections should be subject
>> for such a non-referenced check in kpatch_verify_patchability().
>> Current check (non-standard, non-rela, non-debug) is too weak and
>> allows also non-rodata sections without referenced symbols to slip
>> through.
>> 
>> Detect .rodata section by checking section's type (SHT_PROGBITS),
>> flags (no exec, no write) and finally name prefix.
>> 
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Bjoern Doebel 
>> Reviewed-by: Norbert Manthey 
>> ---
>> common.c |  7 +++
>> common.h |  1 +
>> create-diff-object.c | 13 ++---
>> 3 files changed, 14 insertions(+), 7 deletions(-)
> 
> Seeing that I have been Cc-ed here - what tree is this against? I
> don't recognize the file names as anything I'm a maintainer for.
> 
> Jan

You have been probably added because I have used the following command:

$ scripts/./add_maintainers.pl -d ~/git/livepatch-build-tools

@Lars: could you confirm?

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v3 04/12] livepatch: Implement pre-|post- apply|revert hooks

2019-09-17 Thread Wieczorkiewicz, Pawel


> On 16. Sep 2019, at 19:54, Ross Lagerwall  wrote:
> 
>> 
snip
>> 2) post-apply hook
>>   runs after the apply action has been executed and quiescing zone
>>   exited. Its main purpose is to provide an ability to follow-up on
>>   actions performed by the pre- hook, when module application was
>>   successful or undo certain preparation steps of the pre- hook in
>>   case of a failure. The success/failure error code is proviVded to
> 
> provided

ACK.

> 
>>   the post- hooks via the rc field of the payload structure.
>> 3) pre-revert hook
>>   runs before the revert action is scheduled for execution. Its main
>>   purpose is to prevent from reverting a hotpatch when certain
> 
> Let's stick with "livepatch" terminology to avoid confusion (throughout this 
> patch).
> 

ACK.

>>   expected conditions aren't met or when mutating actions implemented
>>   in the hook fail or cannot be executed.
>> 4) post-revert hook
>>   runs after the revert action has been executed and quiescing zone
>>   exited. Its main purpose is to perform cleanup of all previously
>>   executed mutating actions in order to restore the original system
>>   state from before the current module application.
>>   The success/failure error code is provided to the post- hooks via
>>   the rc field of the payload structure.
> 
> snip
> 
>> +/*
>> + * Check if payload has any of the vetoing, non-atomic hooks assigned.
>> + * A vetoing, non-atmic hook may perform an operation that changes the
>> + * hypervisor state and may not be guaranteed to succeed. Result of
>> + * such operation may be returned and may change the livepatch workflow.
>> + * Such hooks may require additional cleanup actions performed by other
>> + * hooks. Thus they are not suitable for replace action.
>> + */
>> +static inline bool_t has_payload_any_vetoing_hooks(const struct payload 
>> *payload)
> 
> Use bool instead (throughout this patch).

ACK.

> 
>> +{
>> +return is_hook_enabled(payload->hooks.apply.pre) ||
>> +   is_hook_enabled(payload->hooks.apply.post) ||
>> +   is_hook_enabled(payload->hooks.revert.pre) ||
>> +   is_hook_enabled(payload->hooks.revert.post);
>> +}
>> +
>> +/*
>> + * Checks if any of the already applied hotpatches has any vetoing,
>> + * non-atomic hooks assigned.
>> + */
> snip
> 
>> @@ -1560,6 +1681,30 @@ static int livepatch_action(struct 
>> xen_sysctl_livepatch_action *action)
>>  rc = build_id_dep(data, 1 /* against hypervisor. */);
>>  if ( rc )
>>  break;
>> +
>> +/*
>> + * REPLACE action is not supported on hotpatches with vetoing 
>> hooks.
>> + * Vetoing hooks usually perform mutating actions on the system 
>> and
>> + * typically exist in pairs (pre- hook doing an action and 
>> post- hook
>> + * undoing the action). Coalescing all hooks from all applied 
>> modules
>> + * cannot be performed without inspecting potential 
>> dependencies between
>> + * the mutating hooks and hence cannot be performed 
>> automatically by
>> + * the replace action. Also, the replace action cannot safely 
>> assume a
>> + * successful revert of all the module with vetoing hooks. When 
>> one
>> + * of the hooks fails due to not meeting certain conditions the 
>> whole
>> + * replace operation must have been reverted with all previous 
>> pre- and
>> + * post- hooks re-executed (which cannot be guaranteed to 
>> succeed).
>> + * The simplest response to this complication is disallow 
>> replace
>> + * action on modules with vetoing hooks.
>> + */
> 
> I think that allowing pre-apply veto hooks would be useful for the replace 
> action so the live patch can check if the system is in a good state before 
> doing the replace (this would certainly be useful for XenServer). It would be 
> safe as far as I can see with the caveat that it can't mutate state. But this 
> doesn't have to be done now.

Yes, I agree that allowing pre-apply hook makes sense for replace action and 
could be pretty useful.
Especially, that it runs before quiescing the CPUs, so any mutating actions 
must be chosen with care anyway.

Let’s create another patch for this, after the current patchset is merged.

> 
>> +if ( has_payload_any_vetoing_hooks(data) || 
>> livepatch_applied_have_vetoing_hooks() )
>> +{
>> +printk(XENLOG_ERR LIVEPATCH "%s: REPLACE action is not 
>> supported on hotpatches with vetoing hooks!\n",
>> +   data->name);
>> +rc = -EOPNOTSUPP;
>> +break;
>> +}
>> +
>>  data->rc = -EAGAIN;
>>  rc = schedule_work(data, action->cmd, action->timeout);
>>  }
>> diff --git a/xen/include/xen/livepatch_payload.h 
>> b/xen/include/xen/livepatch_payload.h
>> index 99613af2db..cd20944cc4 100644
>> --- 

Re: [Xen-devel] [PATCH v3 10/12] livepatch: Handle arbitrary size names with the list operation

2019-09-17 Thread Wieczorkiewicz, Pawel


> On 17. Sep 2019, at 10:48, Jan Beulich  wrote:
> 
> On 17.09.2019 10:40,  Wieczorkiewicz, Pawel  wrote:
>> 
>> 
>> On 17. Sep 2019, at 10:27, Jan Beulich 
>> mailto:jbeul...@suse.com>> wrote:
>> 
>> On 16.09.2019 12:59, Pawel Wieczorkiewicz wrote:
>> @@ -951,11 +952,13 @@ struct xen_sysctl_livepatch_list {
>>   amount of payloads and version.
>>   OUT: How many payloads left. */
>>uint32_t pad;   /* IN: Must be zero. */
>> +uint64_t name_total_size;   /* OUT: Total size of all 
>> transfer names */
>> 
>> Why uint64_t and not uint32_t? You don't expect this to grow
>> beyond 4GiB, do you?
>> 
>> I don’t, but uint32_t is not really compatible with size_t.
>> And I was thought to always use size_t compatible types for sizes.
> 
> That's a fair point, but I think we use 32-bit sizes elsewhere
> as well, when crossing the 4GiB boundary would seem entirely
> unexpected.
> 
> But what's worse here - you shouldn't use plain uint64_t in
> sysctl.h (and domctl.h) anyway. If anything, you ought to use
> uint64_aligned_t. (Going through the file I notice a few other
> bad instances have crept in.)
> 

I see. Noted, thanks for letting me know.

>> Anyway, I do not mind changing this to whatever type you prefer.
> 
> Well, preference - if anyone's - would be the livepatch maintainers'
> one here.
> 

Waiting for the maintainers' wise judgment then :-).

> Also - can you please see about adjusting your reply style? In plain
> text mode it's impossible to tell context from your responses.

Oh, sorry about that. I tweaked my settings.
Please let me know if it does not get better.

> 
> Jan

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v3 10/12] livepatch: Handle arbitrary size names with the list operation

2019-09-17 Thread Wieczorkiewicz, Pawel


On 17. Sep 2019, at 10:27, Jan Beulich 
mailto:jbeul...@suse.com>> wrote:

On 16.09.2019 12:59, Pawel Wieczorkiewicz wrote:
@@ -951,11 +952,13 @@ struct xen_sysctl_livepatch_list {
   amount of payloads and version.
   OUT: How many payloads left. */
uint32_t pad;   /* IN: Must be zero. */
+uint64_t name_total_size;   /* OUT: Total size of all transfer 
names */

Why uint64_t and not uint32_t? You don't expect this to grow
beyond 4GiB, do you?

I don’t, but uint32_t is not really compatible with size_t.
And I was thought to always use size_t compatible types for sizes.

Anyway, I do not mind changing this to whatever type you prefer.


And why OUT rather than IN/OUT? Once you make this "arbitrary
size", I don't see a need for limiting this to ...

XEN_GUEST_HANDLE_64(xen_livepatch_status_t) status;  /* OUT. Must have 
enough
   space allocate for nr of them. */
XEN_GUEST_HANDLE_64(char) name; /* OUT: Array of names. Each member
-   MUST XEN_LIVEPATCH_NAME_SIZE in 
size.
-   Must have nr of them. */
+   may have an arbitrary length up 
to
+   XEN_LIVEPATCH_NAME_SIZE bytes. 
Must have
+   nr of them. */

... XEN_LIVEPATCH_NAME_SIZE bytes per entry.

Changing the upper bound limitation will break certain assumptions and I did 
not want to pile all these on top of the current change.
But, yes, the upper bound limit could be dropped. I would prefer to do it as an 
independent patch.


And finally - please send to the list just once, i.e. please
don't have two xen-devel@ in the recipients list.


Sorry, I did not notice the add_maintainers.pl script adds an explicit To: for 
the xen-devel@.

Jan

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v3 02/12] livepatch: Allow to override inter-modules buildid dependency

2019-09-17 Thread Wieczorkiewicz, Pawel


On 16. Sep 2019, at 19:01, Ross Lagerwall 
mailto:ross.lagerw...@citrix.com>> wrote:

On 9/16/19 11:59 AM, Pawel Wieczorkiewicz wrote:
snip
+/*
+ * Parse user provided action flags.
+ * This function expects to only receive an array of input parameters being 
flags.
+ * Expected action is specified via idx paramater (index of flag_options[]).
+ */
+static int get_flags(int argc, char *argv[], unsigned int idx, uint64_t *flags)
+{
+int i, j;
+
+if ( !flags || idx >= ARRAY_SIZE(flag_options) )
+return -1;
+
+*flags = 0;
+for ( i = 0; i < argc; i++ )
+{
+for ( j = 0; j < ARRAY_SIZE(flag_options[idx]); j++ )
+{
+if ( !flag_options[idx][j].name )
+goto error;
+
+if ( !strcmp(flag_options[idx][j].name, argv[i]) )
+{
+*flags |= flag_options[idx][j].flag;
+break;
+}
+}
+
+if ( j == ARRAY_SIZE(flag_options[idx]) )
+goto error;
+}
+
+return 0;
+error:
+fprintf(stderr, "Unsupported flag: %s.\n", argv[i]);
+errno = EINVAL;
+return errno;
+}

You return -1 above but +ve errno here. Please make it consistent.

Well, I understood from the code of the file (e.g. action_func()) that the -1 
value indicates a unexpected runtime error (negative val).
Whereas, positive errno values are expected error to be dealt with.

So:
<0 - fatal errors
0 - ok
>0 - errors to be handled

Could you confirm please that I should make get_flags() return only positive 
errors?

Also, you don't need to set errno if returning the actual error.


Honestly, I just copied the code from get_name() and wanted to the get_flags() 
to follow similar pattern.

(The error handling in this file looks fairly inconsistent anyway but let's not 
make it worse.)

+
 /* The hypervisor timeout for the live patching operation is 30 msec,
  * but it could take some time for the operation to start, so wait twice
  * that period. */
@@ -291,8 +357,9 @@ int action_func(int argc, char *argv[], unsigned int idx)
 char name[XEN_LIVEPATCH_NAME_SIZE];
 int rc;
 xen_livepatch_status_t status;
+uint64_t flags;
 -if ( argc != 1 )
+if ( argc < 1 )
 {
 show_help();
 return -1;
@@ -301,7 +368,10 @@ int action_func(int argc, char *argv[], unsigned int idx)
 if ( idx >= ARRAY_SIZE(action_options) )
 return -1;
 -if ( get_name(argc, argv, name) )
+if ( get_name(argc--, argv++, name) )
+return EINVAL;
+
+if ( get_flags(argc, argv, idx, ) )
 return EINVAL;
   /* Check initial status. */
@@ -332,7 +402,7 @@ int action_func(int argc, char *argv[], unsigned int idx)
 if ( action_options[idx].allow & status.state )
 {
 printf("%s %s... ", action_options[idx].verb, name);
-rc = action_options[idx].function(xch, name, HYPERVISOR_TIMEOUT_NS);
+rc = action_options[idx].function(xch, name, HYPERVISOR_TIMEOUT_NS, 
flags);
 if ( rc )
 {
 int saved_errno = errno;
@@ -394,17 +464,23 @@ int action_func(int argc, char *argv[], unsigned int idx)
   static int load_func(int argc, char *argv[])
 {
-int rc;
-char *new_argv[2];
-char *path, *name, *lastdot;
+int i, rc = ENOMEM;
+char *upload_argv[2];
+char **apply_argv, *path, *name, *lastdot;
 -if ( argc != 1 )
+if ( argc < 1 )
 {
 show_help();
 return -1;
 }
+
+/* apply action has  [flags] input requirement, which must be 
constructed */
+apply_argv = (char **) malloc(argc * sizeof(*apply_argv));
+if ( !apply_argv )
+return rc;
+
 /*  */
-new_argv[1] = argv[0];
+upload_argv[1] = argv[0];
   /* Synthesize the  */
 path = strdup(argv[0]);
@@ -413,16 +489,23 @@ static int load_func(int argc, char *argv[])
 lastdot = strrchr(name, '.');
 if ( lastdot != NULL )
 *lastdot = '\0';
-new_argv[0] = name;
+upload_argv[0] = name;
+apply_argv[0] = name;
 -rc = upload_func(2 /*   */, new_argv);
+/* Fill in all user provided flags */
+for ( i = 0; i < argc - 1; i++ )
+apply_argv[i + 1] = argv[i + 1];

Wouldn't this make the loop body simpler?  i = 1; i < argc;


ACK. It would indeed.

Or alternatively, just a straight memcpy().

--
Ross Lagerwall

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v3 01/12] livepatch: Always check hypervisor build ID upon hotpatch upload

2019-09-17 Thread Wieczorkiewicz, Pawel


On 16. Sep 2019, at 18:23, Ross Lagerwall 
mailto:ross.lagerw...@citrix.com>> wrote:

On 9/16/19 11:59 AM, Pawel Wieczorkiewicz wrote:
This change is part of a independant stacked hotpatch modules
feature. This feature allows to bypass dependencies between modules
upon loading, but still verifies Xen build ID matching.
In order to prevent (up)loading any hotpatches built for different
hypervisor version as indicated by the Xen Build ID, add checking for
the payload's vs Xen's build id match.
To achieve that embed into every hotpatch another section with a
dedicated hypervisor build id in it. After the payload is loaded and
the .livepatch.xen_depends section becomes available, perform the
check and reject the payload if there is no match.
snip
+sec = livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_XEN_DEPENDS);
+if ( sec )
+{
+n = sec->load_addr;
+
+if ( sec->sec->sh_size <= sizeof(*n) )
+return -EINVAL;
+
+if ( xen_build_id_check(n, sec->sec->sh_size,
+>xen_dep.p, >xen_dep.len) )
+return -EINVAL;
+
+if ( !payload->xen_dep.len || !payload->xen_dep.p )
+return -EINVAL;
+}
+
 /* Setup the virtual region with proper data. */
 region = >region;
 @@ -882,6 +922,10 @@ static int load_payload_data(struct payload *payload, 
void *raw, size_t len)
 if ( rc )
 goto out;
 +rc = check_xen_build_id(payload);
+if ( rc )
+goto out;
+
 rc = build_symbol_table(payload, );
 if ( rc )
 goto out;

It is a bit confusing having a new function called check_xen_build_id() when 
there is already a xen_build_id_check(). Perhaps the new one should be called 
xen_build_id_dep() as it is analogous to the existing build_id_dep()?


Yes, that definitely makes sense. I will squash it into v4. Otherwise, I hope 
it can be fixed upon merging.

Either way,

Reviewed-by: Ross Lagerwall 
mailto:ross.lagerw...@citrix.com>>

Many thanks!

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 08/12] livepatch: Add support for inline asm hotpatching expectations

2019-08-29 Thread Wieczorkiewicz, Pawel


On 29. Aug 2019, at 19:49, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com>> wrote:

On Thu, Aug 29, 2019 at 04:16:13PM +, Wieczorkiewicz, Pawel wrote:


On 29. Aug 2019, at 17:58, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com><mailto:konrad.w...@oracle.com>>
 wrote:



…snip..


Could you please try with the patch attached?

It compiled, but the test-case was not happy. See attached the full serial log


Ah, I forgot about endianness of course...
I am sending an improved patch. I hope it works this time as expected.





Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879





If it still fails, could you please send me the output for the following
command with this build?

objdump -d xen-syms | sed -n -e '/:$/,/^$/ p' | tail -n +2

Also included in the serial log.


Best Regards,
Pawel Wieczorkiewicz








Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




0001-fixup-livepatch-Add-support-for-inline-asm-hotpatchi.patch
Description: 0001-fixup-livepatch-Add-support-for-inline-asm-hotpatchi.patch

Best Regards,Pawel Wieczorkiewicz

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 08/12] livepatch: Add support for inline asm hotpatching expectations

2019-08-29 Thread Wieczorkiewicz, Pawel


On 29. Aug 2019, at 17:58, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com>> wrote:

+CODE_GET_EXPECT=$(shell objdump -d --insn-width=1 $(1) | grep -A6 -E 
'<'$(2)'>:' | tail -n +2 | awk 'BEGIN {printf "{"} {printf "0x%s,", $$2}' | sed 
's/,$$/}/g')

Ony my Hikey 960 when I compile using an native compiler I get:

gcc  -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes 
-Wdeclaration-after-statement -Wno-unused-but-set-variable 
-Wno-unused-local-typedefs   -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin 
-fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ 
-include /home/xen.git/xen/include/xen/config.h 
'-D__OBJECT_FILE__="xen_expectations.o"' -Wa,--strip-local-absolute -g -MMD -MF 
./.xen_expectations.o.d -mcpu=generic -mgeneral-regs-only   
-I/home/xen.git/xen/include -fno-stack-protector -fno-exceptions 
-Wnested-externs -DGCC_HAS_VISIBILITY_ATTRIBUTE  -DBUILD_ID 
-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes 
-Wdeclaration-after-statement -Wno-unused-but-set-variable 
-Wno-unused-local-typedefs   -c xen_expectations.c -o xen_expectations.o
/home/xen.git/xen/Rules.mk:202: recipe for target 'xen_expectations.o' failed
make[3]: Circular expect_config.h <- xen_expectations.o dependency dropped.
In file included from xen_expectations.c:6:0:
expect_config.h:1:23: error: large integer implicitly truncated to unsigned type
[-Werror=overflow]
#define EXPECT_BYTES {0xf260,0x00f2,0xe000f000,0x12e000f0,0x9112e000,0x
c09112e0}
  ^
xen_expectations.c:28:17: note: in expansion of macro ‘EXPECT_BYTES’
.data = EXPECT_BYTES
^~~~
expect_config.h:1:34: error: large integer implicitly truncated to unsigned type
[-Werror=overflow]
#define EXPECT_BYTES {0xf260,0x00f2,0xe000f000,0x12e000f0,0x9112e000,0x
c09112e0}
 ^
xen_expectations.c:28:17: note: in expansion of macro ‘EXPECT_BYTES’
.data = EXPECT_BYTES
^~~~
expect_config.h:1:45: error: large integer implicitly truncated to unsigned type
[-Werror=overflow]
#define EXPECT_BYTES {0xf260,0x00f2,0xe000f000,0x12e000f0,0x9112e000,0x
c09112e0}
…

make[3]: Leaving directory '/home/xen.git/xen/test/livepatch'
Makefile:11: recipe for target 'build' failed
make[2]: Leaving directory '/home/xen.git/xen/test'
Makefile:85: recipe for target '_tests' failed
make[1]: Leaving directory '/home/xen.git/xen'
Makefile:45: recipe for target 'tests' failed
root@hikey960:/home/xen.git/xen# cat test/livepatch/expect_config.h
#define EXPECT_BYTES 
{0xf260,0x00f2,0xe000f000,0x12e000f0,0x9112e000,0xc09112e0}
#define EXPECT_BYTES_COUNT 6



Could you please try with the patch attached?




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




0001-fixup-livepatch-Add-support-for-inline-asm-hotpatchi.patch
Description: 0001-fixup-livepatch-Add-support-for-inline-asm-hotpatchi.patch
If it still fails, could you please send me the output for the following command with this build?objdump -d xen-syms | sed -n -e '/:$/,/^$/ p' | tail -n +2
Best Regards,Pawel Wieczorkiewicz

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 08/12] livepatch: Add support for inline asm hotpatching expectations

2019-08-29 Thread Wieczorkiewicz, Pawel


On 29. Aug 2019, at 16:34, Konrad Rzeszutek Wilk 
mailto:kon...@darnok.org>> wrote:



…snip...

+
+struct livepatch_func __section(".livepatch.funcs") livepatch_exceptions = {
+.version = LIVEPATCH_PAYLOAD_VERSION,
+.name = livepatch_exceptions_str,
+.new_addr = xen_hello_world,
+.old_addr = xen_extra_version,
+.new_size = EXPECT_BYTES_COUNT,
+.old_size = EXPECT_BYTES_COUNT,
+.expect = {
+.enabled = 1,
+.len = EXPECT_BYTES_COUNT,
+.data = EXPECT_BYTES
+},
+
+};

When I compile with 32-bit ARM 'make tests' I get:

arm-eabi-ld-EL -EL --build-id=sha1 -r -o 
xen_action_hooks_norevert.livepatch xen_action_hooks_marker.o 
xen_hello_world_func.o note.o xen_note.o
make[3]: Circular expect_config.h <- xen_expectations.o dependency dropped.
objdump: can't disassemble for architecture UNKNOWN!

(set -e; \
echo "#define EXPECT_BYTES {"; \
echo "#define EXPECT_BYTES_COUNT 6") > expect_config.h
arm-eabi-gcc -marm -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall 
-Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable 
-Wno-unused-local-typedefs   -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin 
-fno-common -Werror -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ 
-include /home/konrad/A20/xen.git/xen/include/xen/config.h 
'-D__OBJECT_FILE__="xen_expectations.o"' -Wa,--strip-local-absolute -g -MMD -MF 
./.xen_expectations.o.d -msoft-float -mcpu=cortex-a15 -DCONFIG_EARLY_PRINTK 
-DEARLY_PRINTK_INC=\"debug-8250.inc\" -DEARLY_PRINTK_BAUD= 
-DEARLY_UART_BASE_ADDRESS=0x01c28000 -DEARLY_UART_REG_SHIFT=2  
-I/home/konrad/A20/xen.git/xen/include -fno-stack-protector -fno-exceptions 
-Wnested-externs -DGCC_HAS_VISIBILITY_ATTRIBUTE -marm -DBUILD_ID 
-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes 
-Wdeclaration-after-statement -Wno-unused-but-set-variable 
-Wno-unused-local-typedefs   -c xen_expectations.c -o xen_expectations.o
xen_expectations.c:31:2: error: expected '}' before ';' token
};
 ^
xen_expectations.c:18:76: note: to match this '{'
struct livepatch_func __section(".livepatch.funcs") livepatch_exceptions = {
   ^
make[3]: *** [/home/konrad/A20/xen.git/xen/Rules.mk:202: xen_expectations.o] 
Error 1
make[3]: Leaving directory '/home/konrad/A20/xen.git/xen/test/livepatch'


And this is what expect_config.h looks like:

#define EXPECT_BYTES {
#define EXPECT_BYTES_COUNT 6

Hi Konrad,

I think I fixed it with the following change on top:

[DIFF START]
diff --git a/xen/test/livepatch/Makefile b/xen/test/livepatch/Makefile
index 067861903f..20bdeb6c6d 100644
--- a/xen/test/livepatch/Makefile
+++ b/xen/test/livepatch/Makefile
@@ -186,10 +186,17 @@ xen_actions_hooks_norevert.o: config.h
 $(LIVEPATCH_ACTION_HOOKS_NOREVERT): xen_action_hooks_marker.o 
xen_hello_world_func.o note.o xen_note.o
$(LD) $(LDFLAGS) $(build_id_linker) -r -o 
$(LIVEPATCH_ACTION_HOOKS_NOREVERT) $^

-CODE_GET_EXPECT=$(shell objdump -d --insn-width=1 $(1) | grep -A6 -E 
'<'$(2)'>:' | tail -n +2 | awk 'BEGIN {printf "{"} {printf "0x%s,", $$2}' | sed 
's/,$$/}/g')
+ifeq ($(findstring arm, $(TARGET_ARCH) $(ARCH)),arm)
+INSN_WIDTH := 4
+INSN_PER_LINE := 2
+else
+INSN_WIDTH := 1
+INSN_PER_LINE := 8
+endif
+CODE_GET_EXPECT=$(shell $(OBJDUMP) -d --insn-width=$(INSN_WIDTH) $(1) | sed -n 
-e '/<'$(2)'>:$$/,/^$$/ p' | tail -n +2 | head -n $(INSN_PER_LINE) | awk 
'{printf "%s", $$2}' | sed 's/.\{2\}/0x&,/g' | sed 's/^/{/;s/,$$/}/g')
 .PHONY: expect_config.h
 expect_config.h: EXPECT_BYTES=$(call 
CODE_GET_EXPECT,$(BASEDIR)/xen-syms,xen_extra_version)
-expect_config.h: EXPECT_BYTES_COUNT=6
+expect_config.h: EXPECT_BYTES_COUNT=8
 expect_config.h: xen_expectations.o
(set -e; \
 echo "#define EXPECT_BYTES $(EXPECT_BYTES)"; \
[DIFF END]

I will test that some more and add it to the v3 of the patchset.

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 05/12] livepatch: Add support for apply|revert action replacement hooks

2019-08-28 Thread Wieczorkiewicz, Pawel


On 27. Aug 2019, at 18:58, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com>> wrote:

On August 27, 2019 4:46:17 AM EDT, Pawel Wieczorkiewicz 
mailto:wipa...@amazon.de>> wrote:
By default, in the quiescing zone, a hotpatch payload is applied with
apply_payload() and reverted with revert_payload() functions. Both of
the functions receive the payload struct pointer as a parameter. The
functions are also a place where standard 'load' and 'unload' module
hooks are executed.

To increase hotpatching system's agility and provide more flexiable
long-term hotpatch solution, allow to overwrite the default apply
and revert action functions with hook-like supplied alternatives.
The alternative functions are optional and the default functions are
used by default.

Is there sense in having the old ones anymore? We could just remove them 
altogether and just use the new ones instead from the start?


Yes, I believe there is. The old ones represent well-tested, proven way of
payload application (or revert) which preserves conservative behavior of the 
system
via enforcing certain assumptions.
The old ones cover 99% of the production use cases, so I would insist on keeping
them in (at least for now).

Later, we could modify livepatch-build-tools to always generate the original
apply|revert functions (in a default case) as part of payloads (hooks).
But, I would not do it just now.

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker

2019-08-22 Thread Wieczorkiewicz, Pawel

On 22. Aug 2019, at 17:30, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi Pawel,

On 22/08/2019 12:02, Wieczorkiewicz, Pawel wrote:
On 22. Aug 2019, at 12:29, Julien Grall 
mailto:julien.gr...@arm.com> 
<mailto:julien.gr...@arm.com>> wrote:
On 21/08/2019 09:19, Pawel Wieczorkiewicz wrote:
More generally, I am not very comfortable to see panic() in the middle of the 
code. Could you explain why panic is the best solution over reverting the work?

Yes. Production-ready hotpatches must not contain inconsistent hooks or 
functions-to-be-applied/reverted.
The goal here is to detect such hotpatches and fail hard immediately 
highlighting the fact that such hotpatch
is broken.

Aside the len = 0 that you are going to fix. How would this condition happen? 
Are you going to add code that will potentially trigger the panic?


The default livepatch code path is very conservative (to the extent it does not 
even need this check and panic).
But, with the changes of this series, one can potentially construct a hotpatch 
that upon load would trigger the panic
(or without the panic, would silently leave the Xen code in memory in an 
inconsistent state). This obviously must not
happen in production, so the new livepatch feature should be used with care.The 
changes make livepatch more
flexible and universal, yet when using new features, more care is needed.

However, when someone is developing a hotpatch or is using the new feature for 
debugging or for whatever
non-production-related reason, it is very helpful to detect immediately any 
sort of undefined state.
I have been there myself when I was working on the changes presented here, and 
thought that would be a good idea
to add this checks permanently.
Also, when something changes in the future in the livepatch implementation, 
those checks could potentially highlight
any inconsistencies.

The inconsistent application of a hotpatch (some function applied, some 
reverted while other left behined) leaves
the system in a very bad state. I think the best what we could do here is 
panic() to enable post-mortem analysis
of what went wrong and avoid leaking such system into production.

Thank you for the explanation here (and on IRC). May I ask some documentation 
regarding the panic in at least commit message? Ideally, this would explain why 
the panic the most sensible solution.


Yes, certainly. I will add that.

Cheers,

--
Julien Grall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker

2019-08-22 Thread Wieczorkiewicz, Pawel


On 22. Aug 2019, at 12:43, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi,

On 22/08/2019 11:20, Wieczorkiewicz, Pawel wrote:


..snip..

Cross-compiler are nowadays widely available. So build testing your changes in 
common code would be the minimum.

I wish it was that simple. Nevertheless, I will try to prepare an environment 
to perform such builds.

Cross-compiling the hypervisor is really easy ;).

1) Download the cross-compiler tarball (here one [1]) and uncompress it. You 
can also install the one provided by your distro.

2) Build Xen hypervisor. Here an example for arm64:

42sh> cd xen.git/xen
42sh> make XEN_TARGET_ARCH=arm64 CROSS_COMPILER=-

In my case, I am using the Arm toolchain AArch64 GNU/Linux target 
(aarch64-linux-gnu). So the  would be aarch64-linux-gnu.

This is assuming you have the compilers binary in your PATH. If not, you can 
use give the full path:

CROSS_COMPILER=/opt/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-

Awesome! That really works (especially thanks for the [1] link… finally some 
toolstack that works on my system).

One change was needed: s/CROSS_COMPILER/CROSS_COMPILE/g

Thanks!

Having this in a wiki would really help. Or have I missed it?


In this case, as you dropped the const from the prototype, you will need to do 
the same in the declaration.

Yes, but I see 2 options here:
- Enable the feature also for Arm (I prefer that, but will not be able to test 
that in nearest future)

I think some of the code can be made common. So we could possibly rely on x86 
for that. Additionally, IIRC, Konrad has a setup on the cubietruck for testing 
livepatch.


Yes, I will do that.

- Keep Arm excluded and sprinkle code with #ifdef CONFIG_X86

Please no #ifdef CONFIG_X86 in the common code. If you don't plan to support 
Arm, then we should introduce a new Kconfig that will gate all those changes.

Ugh, you’re right. Removing all that from common code.


Cheers,

[1] 
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

--
Julien Grall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 10/14] livepatch: Add support for inline asm hotpatching expectations

2019-08-22 Thread Wieczorkiewicz, Pawel


On 22. Aug 2019, at 12:31, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi Pawel,

On 21/08/2019 09:19, Pawel Wieczorkiewicz wrote:
diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
index b55ad6d050..e18322350d 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -818,7 +818,7 @@ struct xen_sysctl_cpu_featureset {
  * If zero exit with success.
  */
 -#define LIVEPATCH_PAYLOAD_VERSION 2
+#define LIVEPATCH_PAYLOAD_VERSION 3

We usually only bump the version once per release. So this is unnecessary as 
you already did it in the previous patch.


Yes, I will keep all these changes under a single bump as promised to Konrad 
yesterday.

Cheers,

--
Julien Grall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker

2019-08-22 Thread Wieczorkiewicz, Pawel


On 22. Aug 2019, at 12:29, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi Pawel,

Hi Julien,

Thank for looking at this!


On 21/08/2019 09:19, Pawel Wieczorkiewicz wrote:
Livepatch only tracks an entire payload applied/reverted state. But,
with an option to supply the apply_payload() and/or revert_payload()
functions as optional hooks, it becomes possible to intermix the
execution of the original apply_payload()/revert_payload() functions
with their dynamically supplied counterparts.
It is important then to track the current state of every function
being patched and prevent situations of unintentional double-apply
or unapplied revert.
To support that, it is necessary to extend public interface of the
livepatch. The struct livepatch_func gets additional field holding
the applied/reverted state marker.
To reflect the livepatch payload ABI change, bump the version flag
LIVEPATCH_PAYLOAD_VERSION up to 2.
The above solution only applies to x86 architecture for now.
Signed-off-by: Pawel Wieczorkiewicz 
mailto:wipa...@amazon.de>>
Reviewed-by: Andra-Irina Paraschiv 
mailto:andra...@amazon.com>>
Reviewed-by: Bjoern Doebel mailto:doe...@amazon.de>>
Reviewed-by: Martin Pohlack mailto:mpohl...@amazon.de>>
---
 xen/arch/x86/livepatch.c| 20 +++-
 xen/common/livepatch.c  | 35 +++
 xen/include/public/sysctl.h | 11 ++-
 xen/include/xen/livepatch.h |  2 +-
 4 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index 436ee40fe1..76fa91a082 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -61,6 +61,14 @@ void noinline arch_livepatch_apply(struct livepatch_func 
*func)
 if ( !len )
 return;
 +/* If the apply action has been already executed on this function, do 
nothing... */
+if ( func->applied == LIVEPATCH_FUNC_APPLIED )
+{
+printk(XENLOG_WARNING LIVEPATCH "%s: %s has been already applied 
before\n",
+__func__, func->name);
+return;
+}

Does this need to in arch specific code?

As a matter of fact it does not.
Let me enable this feature for Arm as well and make this code a common inline.


+
 memcpy(func->opaque, old_ptr, len);
 if ( func->new_addr )
 {
@@ -77,15 +85,25 @@ void noinline arch_livepatch_apply(struct livepatch_func 
*func)
 add_nops(insn, len);
   memcpy(old_ptr, insn, len);
+func->applied = LIVEPATCH_FUNC_APPLIED;
 }
   /*
  * "noinline" to cause control flow change and thus invalidate I$ and
  * cause refetch after modification.
  */
-void noinline arch_livepatch_revert(const struct livepatch_func *func)
+void noinline arch_livepatch_revert(struct livepatch_func *func)
 {
+/* If the apply action hasn't been executed on this function, do 
nothing... */
+if ( !func->old_addr || func->applied == LIVEPATCH_FUNC_NOT_APPLIED )
+{
+printk(XENLOG_WARNING LIVEPATCH "%s: %s has not been applied before\n",
+__func__, func->name);
+return;
+}
+
 memcpy(func->old_addr, func->opaque, livepatch_insn_len(func));
+func->applied = LIVEPATCH_FUNC_NOT_APPLIED;
 }
   /*
diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index 585ec9819a..090a48977b 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -1242,6 +1242,29 @@ static inline void revert_payload_tail(struct payload 
*data)
 data->state = LIVEPATCH_STATE_CHECKED;
 }
 +/*
+ * Check if an action has applied the same state to all payload's functions 
consistently.
+ */
+static inline bool was_action_consistent(const struct payload *data, 
livepatch_func_state_t expected_state)
+{
+int i;
+
+for ( i = 0; i < data->nfuncs; i++ )
+{
+struct livepatch_func *f = &(data->funcs[i]);
+
+if ( f->applied != expected_state )

Per the definition of livepath_func, the field "applied" only exists for x86. 
So this will not compiled on Arm.

I will enable Arm too.


+{
+printk(XENLOG_ERR LIVEPATCH "%s: Payload has a function: '%s' with 
inconsistent applied state.\n",
+   data->name, f->name ?: "noname");
+
+return false;
+}
+}
+
+return true;
+}
+
 /*
  * This function is executed having all other CPUs with no deep stack (we may
  * have cpu_idle on it) and IRQs disabled.
@@ -1268,6 +1291,9 @@ static void livepatch_do_action(void)
 else
 rc = apply_payload(data);
 +if ( !was_action_consistent(data, rc ? LIVEPATCH_FUNC_NOT_APPLIED : 
LIVEPATCH_FUNC_APPLIED) )

Regardless the compilation issue above, none of the common code will set the 
state. So for Arm, this would likely mean the function return false.

True, I should have disabled this code for Arm too.
But now, let me just make it common for all archs.


+panic("livepatch: partially applied payload '%s'!\n", data->name);

I can see at least a case where the panic can be reached 

Re: [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker

2019-08-22 Thread Wieczorkiewicz, Pawel

On 22. Aug 2019, at 12:07, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi,

On 22/08/2019 08:44, Wieczorkiewicz, Pawel wrote:


…snip...


Is this going to break livepatch on Arm? If so, do you have any plan to fix it?

No, I do not think it is. But, I am unable to test on Arm (No access to HW and 
SW),
so I took the conservative approach here.
Arm provides decent free model (see FoundationModel) that you can use for basic 
testing. Alternatively, you QEMU also support virtualization extension.

Let me have a look at the code (I will answer separately) to see if I can spot 
anything.

[...]

diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h
index 2aec532ee2..a93126f631 100644
--- a/xen/include/xen/livepatch.h
+++ b/xen/include/xen/livepatch.h
@@ -117,7 +117,7 @@ int arch_livepatch_quiesce(void);
 void arch_livepatch_revive(void);
   void arch_livepatch_apply(struct livepatch_func *func);
-void arch_livepatch_revert(const struct livepatch_func *func);
+void arch_livepatch_revert(struct livepatch_func *func);

I doubt livepatch on Arm will compile after this change.

What would be you suggestion then?

Cross-compiler are nowadays widely available. So build testing your changes in 
common code would be the minimum.


I wish it was that simple. Nevertheless, I will try to prepare an environment 
to perform such builds.

In this case, as you dropped the const from the prototype, you will need to do 
the same in the declaration.


Yes, but I see 2 options here:
- Enable the feature also for Arm (I prefer that, but will not be able to test 
that in nearest future)
- Keep Arm excluded and sprinkle code with #ifdef CONFIG_X86

Shall I limit the change to X86 everywhere
 Or maybe drop the compilation flag completely?

I am a bit confused. Which compilation flag do you refer to?


CONFIG_X86

Cheers,

--
Julien Grall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker

2019-08-22 Thread Wieczorkiewicz, Pawel

On 21. Aug 2019, at 23:34, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi Pawel,

Hi Julien,


On 8/21/19 9:19 AM, Pawel Wieczorkiewicz wrote:
Livepatch only tracks an entire payload applied/reverted state. But,
with an option to supply the apply_payload() and/or revert_payload()
functions as optional hooks, it becomes possible to intermix the
execution of the original apply_payload()/revert_payload() functions
with their dynamically supplied counterparts.
It is important then to track the current state of every function
being patched and prevent situations of unintentional double-apply
or unapplied revert.
To support that, it is necessary to extend public interface of the
livepatch. The struct livepatch_func gets additional field holding
the applied/reverted state marker.
To reflect the livepatch payload ABI change, bump the version flag
LIVEPATCH_PAYLOAD_VERSION up to 2.
The above solution only applies to x86 architecture for now.

Is this going to break livepatch on Arm? If so, do you have any plan to fix it?


No, I do not think it is. But, I am unable to test on Arm (No access to HW and 
SW),
so I took the conservative approach here.

[...]

diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h
index 2aec532ee2..a93126f631 100644
--- a/xen/include/xen/livepatch.h
+++ b/xen/include/xen/livepatch.h
@@ -117,7 +117,7 @@ int arch_livepatch_quiesce(void);
 void arch_livepatch_revive(void);
   void arch_livepatch_apply(struct livepatch_func *func);
-void arch_livepatch_revert(const struct livepatch_func *func);
+void arch_livepatch_revert(struct livepatch_func *func);

I doubt livepatch on Arm will compile after this change.


What would be you suggestion then?
Shall I limit the change to X86 everywhere
 Or maybe drop the compilation flag completely?

 void arch_livepatch_post_action(void);
   void arch_livepatch_mask(void);

Cheers,

--
Julien Grall

Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 08/20] livepatch-build: detect special section group sizes

2019-08-21 Thread Wieczorkiewicz, Pawel

> On 21. Aug 2019, at 20:49, Konrad Rzeszutek Wilk  
> wrote:
> 
> 
>> +# Using xen-syms built in the previous step by build_full().
>> +SPECIAL_VARS=$(readelf -wi "$OUTPUT/xen-syms" |
> 
> What version of readelf supports this? Asking as in the past there were some 
> options with binutils that had conflicting options and we had to add some 
> custom hackery code to figure out which parameter to use.


The version I use does: GNU readelf version 2.23.52.0.1 20130226
The -wi is a shortcut for —debug-dump=info.
I do hope it’s a standard readelf feature by now.

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 06/14] livepatch: Add support for apply|revert action replacement hooks

2019-08-21 Thread Wieczorkiewicz, Pawel

On 21. Aug 2019, at 20:31, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com>> wrote:

On 8/21/19 4:19 AM, Pawel Wieczorkiewicz wrote:
By default, in the quiescing zone, a hotpatch payload is applied with
apply_payload() and reverted with revert_payload() functions. Both of
the functions receive the payload struct pointer as a parameter. The
functions are also a place where standard 'load' and 'unload' module
hooks are executed.
To increase hotpatching system's agility and provide more flexiable
long-term hotpatch solution, allow to overwrite the default apply
and revert action functions with hook-like supplied alternatives.
The alternative functions are optional and the default functions are
used by default.
Since the alternative functions have direct access to the hotpatch
payload structure, they can better control context of the 'load' and
'unload' hooks execution as well as exact instructions replacement
workflows. They can be also easily extended to support extra features
in the future.
To simplify the alternative function generation move code responsible
for payload and hotpatch region registration outside of the function.
That way it is guaranteed that the registration step occurs even for
newly supplied functions.

This logic looks legit, but I was wondering if you would be up for a writing a 
small test-case(s) livepatch that would exercise these parts just to make sure 
nothing in the future would screw it up?

Yes, I could do that. But, I would like to discuss (get guidelines about) the 
expected test coverage.
With this sort of changes, there is an unlimited set of test-cases to be 
created. So, I would like to focus on a few most important.
I am missing knowledge how these test cases are supposed to be used… hence the 
ask.

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 10/14] livepatch: Add support for inline asm hotpatching expectations

2019-08-21 Thread Wieczorkiewicz, Pawel

> On 21. Aug 2019, at 20:30, Konrad Rzeszutek Wilk  
> wrote:
> 
> On 8/21/19 4:19 AM, Pawel Wieczorkiewicz wrote:
>>  typedef enum livepatch_func_state {
>>  LIVEPATCH_FUNC_NOT_APPLIED = 0,
>>  LIVEPATCH_FUNC_APPLIED = 1
>> @@ -838,11 +850,12 @@ struct livepatch_func {
>>  uint32_t new_size;
>>  uint32_t old_size;
>>  uint8_t version;/* MUST be LIVEPATCH_PAYLOAD_VERSION. */
>> -uint8_t opaque[31];
>> +uint8_t opaque[LIVEPATCH_OPAQUE_SIZE];
>>  #if defined CONFIG_X86
>>  uint8_t applied;
>>  uint8_t _pad[7];
>>  #endif
>> +livepatch_expectation_t expect;
>>  };
> 
> Aaah, now I understand why you decide to create a new field _pad and applied 
> field!
> 

Yup, that was premeditated! :-)

> Any particular reason why the version can't be 2 since this can be part of 
> this changeset? Also you would need to have a Documentation change.

It surely can be 2. I wasn’t sure before if the changes could go together. Will 
change to 2 for both

And, I will also update the doc. 

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker

2019-08-21 Thread Wieczorkiewicz, Pawel

> On 21. Aug 2019, at 20:28, Konrad Rzeszutek Wilk  
> wrote:
> 
> On 8/21/19 4:19 AM, Pawel Wieczorkiewicz wrote:
>>  struct livepatch_func {
>>  const char *name;   /* Name of function to be patched. */
>>  void *new_addr;
>> @@ -834,6 +839,10 @@ struct livepatch_func {
>>  uint32_t old_size;
>>  uint8_t version;/* MUST be LIVEPATCH_PAYLOAD_VERSION. */
>>  uint8_t opaque[31];
>> +#if defined CONFIG_X86
>> +uint8_t applied;
>> +uint8_t _pad[7];
>> +#endif
> 
> Replying here as well. Could you use part of the 'opaque[31]' space instead 
> for this field?


No, as explained earlier, I must not do that. The opaque[] is not a padding.

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-hooks-2 PATCH 4/4] livepatch: Add per-function applied/reverted state tracking marker

2019-08-21 Thread Wieczorkiewicz, Pawel

> On 21. Aug 2019, at 20:12, Konrad Rzeszutek Wilk  
> wrote:
> 
> On 8/14/19 4:39 AM, Pawel Wieczorkiewicz wrote:
>> #ifdef __XEN__
>> +typedef enum livepatch_func_state {
>> +LIVEPATCH_FUNC_NOT_APPLIED = 0,
>> +LIVEPATCH_FUNC_APPLIED = 1
>> +} livepatch_func_state_t;
>> +
>>  struct livepatch_func {
>>  const char *name;   /* Name of function to be patched. */
>>  void *new_addr;
>> @@ -834,6 +839,10 @@ struct livepatch_func {
>>  uint32_t old_size;
>>  uint8_t version;/* MUST be LIVEPATCH_PAYLOAD_VERSION. */
>>  uint8_t opaque[31];
>> +#if defined CONFIG_X86
>> +uint8_t applied;
>> +uint8_t _pad[7];
>> +#endif
>>  };
> 
> Three requests:
>  - Why does it have to be X86 specific?

Mostly because I am unable to test that on ARM (ENODEV…).

>  - Can you also include the change in the documentation where the spec 
> resides?

Yes, will do.

>  - You are bumping the version to 2, but not making it backwards 
> compatible. If so ,you also need to update the documentation to mention 
> this.


Ok, I will update that as well.

Best Regards,
Pawel Wieczorkiewicz




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-hooks-2 PATCH 2/4] create-diff-object: Add support for applied/reverted marker

2019-08-21 Thread Wieczorkiewicz, Pawel

On 21. Aug 2019, at 20:09, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com>> wrote:

On 8/14/19 4:38 AM, Pawel Wieczorkiewicz wrote:
With version 2 of a payload structure additional field is supported
to track whether given function has been applied or reverted.
There also comes additional 8-byte alignment padding to reserve
place for future flags and options.

The new fields are zero-out upon .livepatch.funcs section creation.

Signed-off-by: Pawel Wieczorkiewicz 
mailto:wipa...@amazon.de>>
---
 common.h | 2 ++
 create-diff-object.c | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/common.h b/common.h
index 06e19e7..d8cde35 100644
--- a/common.h
+++ b/common.h
@@ -124,6 +124,8 @@ struct livepatch_patch_func {
  uint32_t old_size;
  uint8_t version;
  unsigned char pad[31];

So the 31 pad is for this purpose - that you can make it smaller. Why
not use that?

No, I must not use that. The 31 pad should be actually called opaque,
and corresponds to the location where hypervisor stores replaced bytes
of the replaced functions.


+ uint8_t applied;
+ uint8_t _pad[7];
 };

 struct special_section {
diff --git a/create-diff-object.c b/create-diff-object.c
index 263c7d2..534516b 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -2009,8 +2009,10 @@ static void livepatch_create_patches_sections(struct 
kpatch_elf *kelf,
  funcs[index].old_size = result.size;
  funcs[index].new_addr = 0;
  funcs[index].new_size = sym->sym.st_size;
- funcs[index].version = 1;
+ funcs[index].version = 2;
  memset(funcs[index].pad, 0, sizeof funcs[index].pad);
+ funcs[index].applied = 0;
+ memset(funcs[index]._pad, 0, sizeof funcs[index]._pad);

  /*
   * Add a relocation that will populate

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-hooks-2 PATCH 3/4] livepatch: Add support for apply|revert action replacement hooks

2019-08-21 Thread Wieczorkiewicz, Pawel

On 21. Aug 2019, at 20:10, Konrad Rzeszutek Wilk 
mailto:konrad.w...@oracle.com>> wrote:

On 8/14/19 4:38 AM, Pawel Wieczorkiewicz wrote:
By default, in the quiescing zone, a hotpatch payload is applied with
apply_payload() and reverted with revert_payload() functions. Both of
the functions receive the payload struct pointer as a parameter. The
functions are also a place where standard 'load' and 'unload' module
hooks are executed.

To increase hotpatching system's agility and provide more flexiable
long-term hotpatch solution, allow to overwrite the default apply
and revert action functions with hook-like supplied alternatives.
The alternative functions are optional and the default functions are
used by default.

Since the alternative functions have direct access to the hotpatch
payload structure, they can better control context of the 'load' and
'unload' hooks execution as well as exact instructions replacement
workflows. They can be also easily extended to support extra features
in the future.

To simplify the alternative function generation move code responsible
for payload and hotpatch region registration outside of the function.
That way it is guaranteed that the registration step occurs even for
newly supplied functions.


You MUST also include the test-cases for this new functionality.

Yeah, I will add them. How comprehensive tests do you have in mind?
I would add 1 or 2 general cases for both of the new hooks. Is it good enough?

Please add them, you know where they are right?

I think, I do.

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch: independ. modules v2 2/3] livepatch: Allow to override inter-modules buildid dependency

2019-08-20 Thread Wieczorkiewicz, Pawel

> On 20. Aug 2019, at 16:28, Julien Grall  wrote:
> 
> Hi,
> 
>>> 
…snip...
>> Yeah, since I got feedback and reviews on various patches that I have 
>> already submitted the way I did,
>> I simply continue with what I have until all comments are addressed (I do 
>> not want to lose anything).
> 
> What do you mean by "all comments are addressed"? Usually you gather a set of 
> comments for a series, address them and then resend the series with all of 
> them addressed.
> 

Yeah, but people invested time in reviews and replied to my incorrectly sent 
threads, so I find it rude to ignore such comments and start a new thread 
instead.
But if this is the recommended practice, I will obey.

>> Then, I will re-send the patches in 2 series: livepatch-build-tools and xen 
>> with all changes,
>> Reviewed-by/Acked-by and cover letters. This is the way recommended by 
>> Andrew.
> 
> Please don't send the patch one by one to check if everyone is happy. Just 
> resend all of them in one go once you gathered enough feedback.
> 

Ok.

>> Unfortunately, it will be also quite confusing I think, because various 
>> changes belonging to different topics,
>> are distributed between those 2 distinct repos.
> 
> That also happen when you have multiple patches in a series. Feature 
> implemented accross multiple patch needs a place to discuss. This can usually 
> be done in the cover letter. For multi repo series, you can steer the 
> discussion on a single repo and just replicate the changes in the other one 
> once there are an agreement.

Fine. Let me then send the 2 full series for each repo with all the changes and 
corresponding cover letters.

> 
> Cheers,
> 
> -- 
> Julien Grall


Best Regards,
Pawel Wieczorkiewicz




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch: independ. modules v2 2/3] livepatch: Allow to override inter-modules buildid dependency

2019-08-20 Thread Wieczorkiewicz, Pawel

> On 20. Aug 2019, at 15:35, Julien Grall  wrote:
> 
> Hi,
> 
> Something looks fishy in the threading:
> 
>  - The patch #1 is answered in reply-to the patch #1 of version 1.
>  - This patch (#2) is answered in reply-to the patch #2 of version 1.
>  - The patch #3 is labeled as v3 an in reply-to the patch #3 of version 1.
> 
> If you send them as series, then they should be sent together for a new 
> version and in a new thread. Not mangled to the previous thread as this makes 
> quite difficult to follow what's going on.
> 
> Also it looks like the series is still lacking of the cover letter. So I 
> still have no clue what "livepatch: independ. modules" in your [...] refers 
> to.
> 

Yeah, since I got feedback and reviews on various patches that I have already 
submitted the way I did,
I simply continue with what I have until all comments are addressed (I do not 
want to lose anything).

Then, I will re-send the patches in 2 series: livepatch-build-tools and xen 
with all changes,
Reviewed-by/Acked-by and cover letters. This is the way recommended by Andrew.

Unfortunately, it will be also quite confusing I think, because various changes 
belonging to different topics,
are distributed between those 2 distinct repos. 

Best,
Pawel

> Cheers,
> 
> On 20/08/2019 14:28, Pawel Wieczorkiewicz wrote:
>> By default Livepatch enforces the following buildid-based dependency
>> chain between hotpatch modules:
>>   1) first module depends on given hypervisor buildid
>>   2) every consecutive module depends on previous module's buildid
>> This way proper hotpatch stack order is maintained and enforced.
>> While it is important for production hotpatches it limits agility and
>> blocks usage of testing or debug hotpatches. These kinds of hotpatch
>> modules are typically expected to be loaded at any time irrespective
>> of current state of the modules stack.
>> To enable testing and debug hotpatches allow user dynamically ignore
>> the inter-modules dependency. In this case only hypervisor buildid
>> match is verified and enforced.
>> To allow userland pass additional paremeters for livepatch actions
>> add support for action flags.
>> Each of the apply, revert, unload and revert action gets additional
>> 64-bit parameter 'flags' where extra flags can be applied in a mask
>> form.
>> Initially only one flag '--nodeps' is added for the apply action.
>> This flag modifies the default buildid dependency check as described
>> above.
>> The global sysctl interface input flag parameter is defined with a
>> single corresponding flag macro:
>>   LIVEPATCH_ACTION_APPLY_NODEPS (1 << 0)
>> The userland xen-livepatch tool is modified to support the '--nodeps'
>> flag for apply and load commands. A general mechanism for specifying
>> more flags in the future for apply and other action is however added.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Eslam Elnikety 
>> Reviewed-by: Petre Eftime 
>> Reviewed-by: Leonard Foerster 
>> Reviewed-by: Martin Pohlack 
>> Reviewed-by: Norbert Manthey 
>> ---
>> v2:
>> * Bump XEN_SYSCTL_INTERFACE_VERSION to 0x0013
>> ---
>>  tools/libxc/include/xenctrl.h |   9 ++--
>>  tools/libxc/xc_misc.c |  20 +++
>>  tools/misc/xen-livepatch.c| 121 
>> +++---
>>  xen/common/livepatch.c|  14 +++--
>>  xen/include/public/sysctl.h   |  11 +++-
>>  5 files changed, 139 insertions(+), 36 deletions(-)
>> diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
>> index 0ff6ed9e70..725697c132 100644
>> --- a/tools/libxc/include/xenctrl.h
>> +++ b/tools/libxc/include/xenctrl.h
>> @@ -2607,11 +2607,12 @@ int xc_livepatch_list(xc_interface *xch, unsigned 
>> int max, unsigned int start,
>>   * to complete them. The `timeout` offers an option to expire the
>>   * operation if it could not be completed within the specified time
>>   * (in ns). Value of 0 means let hypervisor decide the best timeout.
>> + * The `flags` allows to pass extra parameters to the actions.
>>   */
>> -int xc_livepatch_apply(xc_interface *xch, char *name, uint32_t timeout);
>> -int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout);
>> -int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout);
>> -int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout);
>> +int xc_livepatch_apply(xc_interface *xch, char *name, uint32_t timeout, 
>> uint64_t flags);
>> +int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout, 
>> uint64_t flags);
>> +int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout, 
>> uint64_t flags);
>> +int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, 
>> uint64_t flags);
>>/*
>>   * Ensure cache coherency after memory modifications. A call to this 
>> function
>> diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
>> index 8e60b6e9f0..a8e9e7d1e2 100644
>> --- a/tools/libxc/xc_misc.c

Re: [Xen-devel] [PATCH livepatch-python 1/1] livepatch: Add python bindings for livepatch operations

2019-08-20 Thread Wieczorkiewicz, Pawel
On 19. Aug 2019, at 23:39, Marek Marczykowski-Górecki 
mailto:marma...@invisiblethingslab.com>> wrote:

On Thu, Aug 15, 2019 at 11:36:46AM +, Pawel Wieczorkiewicz wrote:
Extend the XC python bindings library to support also all common
livepatch operations and actions.


…snip...
+
+static PyObject *pyxc_livepatch_action(XcObject *self,
+   PyObject *args,
+   PyObject *kwds)
+{
+int (*action_func)(xc_interface *xch, char *name, uint32_t timeout, 
uint64_t flags);

This makes it dependent on "livepatch: Allow to override inter-modules
buildid dependency" patch. Since it's part of a different series, if
there is going to be v2, please name the dependency explicitly in the
commit message or at least after —.

ACK. Will do.

+char *name;
+unsigned int action;
+uint32_t timeout;
+uint64_t flags;
+int rc;
+

…snip...
+static PyObject *pyxc_livepatch_upload(XcObject *self,
+   PyObject *args,
+   PyObject *kwds)
+{
+unsigned char *fbuf = MAP_FAILED;
+char *name, *filename;
+struct stat buf;
+int fd = 0, rc;
+ssize_t len;
+
+static char *kwd_list[] = { "name", "filename", NULL };
+
+if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ss", kwd_list,
+  , ))

It would be nice to support Path-like objects on python >= 3.6. See
note about "s" format here:
https://docs.python.org/3/c-api/arg.html#strings-and-buffers

But since it's python 3 only, that would need to be under #if
PY_MAJOR_VERSION >= 3.


I’d prefer to add it as a separate commit (adding it to my TODO).

+goto error;
+
+fd = open(filename, O_RDONLY);
+if ( fd < 0 )
+goto error;
+
+if ( stat(filename, ) != 0 )
+goto error;
+

…snip...
+
+rc = xc_livepatch_list_get_sizes(self->xc_handle, ,
+ _total_size, _total_size);

This makes it dependent on lp-metadata series. Same note as previously.
BTW for some reason your patch series are not handled as a mail threads,
which makes it harder to look for other patches in the series. Is it
only me?


ACK, Will do.

No, unfortunately it’s me, who incorrectly sent out the series. I divided them
by functionality instead of per repo. I also did not create a cover letter. But,
I got more than one advice how to do it next time.

+if ( rc )
+goto error;
+

…snip...
+
+list = PyList_New(0);

Better use PyList_New(done) and later PyList_SetItem() instead of 
PyList_Append().


ACK. Will change.

+name_off = metadata_off = 0;
+for ( i = 0; i < done; i++ )
+{
+PyObject *info_dict, *metadata_list;
+char *name_str, *metadata_str;
+
…snip...
(m, "LIVEPATCH_STATE_CHECKED", LIVEPATCH_STATE_CHECKED);
+
#if PY_MAJOR_VERSION >= 3
  return m;
#endif

--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH livepatch-python 1/1] livepatch: Add python bindings for livepatch operations

2019-08-20 Thread Wieczorkiewicz, Pawel




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




PGPMIME Versions Identification
Description: PGP/MIME Versions Identification


encrypted.asc
Description: OpenPGP encrypted message.asc
___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch: independ. modules 3/3] python: Add XC binding for Xen build ID

2019-08-20 Thread Wieczorkiewicz, Pawel

> On 19. Aug 2019, at 22:40, Marek Marczykowski-Górecki 
>  wrote:
> 
> On Thu, Aug 15, 2019 at 09:44:00AM +, Pawel Wieczorkiewicz wrote:
>> Extend the list of xc() object methods with additional one to display
>> Xen's buildid. The implementation follows the libxl implementation
>> (e.g. max buildid size assumption being XC_PAGE_SIZE).
>> 
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Martin Mazein 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Norbert Manthey 
>> ---
>> v2:
>> 
…snip...
>> 
>> +static PyObject *pyxc_xenbuildid(XcObject *self)
>> +{
>> +xen_build_id_t *buildid;
>> +int i, r;
>> +char *str;
>> +
>> +buildid = alloca(sizeof(buildid->len) + XC_PAGE_SIZE);
>> +buildid->len = XC_PAGE_SIZE - sizeof(*buildid);
> 
> Those doesn't match. You allocated XC_PAGE_SIZE in addition to
> sizeof(buildid->len). I'd change to alloca(XC_PAGE_SIZE) - it is
> unlikely that izeof(buildid->len) would be larger than XC_PAGE_SIZE and
> we do assume it in other places anyway.

ACK. Will fix.

> 
>> +
>> +r = xc_version(self->xc_handle, XENVER_build_id, buildid);
>> +if ( r <= 0 )
>> +return pyxc_error_to_exception(self->xc_handle);
>> +
>> 

…snip...

> 
> -- 
> Best Regards,
> Marek Marczykowski-Górecki
> Invisible Things Lab
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?


Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part3 v2 3/3] create-diff-object: Strip all undefined entires of known size

2019-08-19 Thread Wieczorkiewicz, Pawel

On 16. Aug 2019, at 17:02, Ross Lagerwall 
mailto:ross.lagerw...@citrix.com>> wrote:

On 8/8/19 1:51 PM, Pawel Wieczorkiewicz wrote:
The patched ELF object file contains all sections and symbols as
resulted from the compilation. However, certain symbols may not be
copied over to the resulting object file, due to being unchanged or
not included for other reasons.
In such situation the resulting object file has the entire sections
copied along (with all their entries unchanged), while some of the
corresponding symbols are not copied along at all.
This leads to having incorrect undefined (STN_UNDEF) entries in the
final hotpatch ELF file.
The newly added function livepatch_strip_undefined_elements() detects
and removes all undefined RELA entries as well as their corresponding
PROGBITS section entries.
Since the sections may contain elements of unknown size (sh.sh_entsize
== 0), perform the strip only on sections with well defined entry
sizes.
After replacing the stripped rela list, it is assumed that the next
invocation of the kpatch_rebuild_rela_section_data() will adjust all
section header parameters according to the current state.

The code in this patch seems to be very similar (i.e. somewhat copy-and-pasted) 
to kpatch_regenerate_special_section() which prunes the rela list and rebuilds 
the corresponding text section according to the predicate 
should_keep_rela_group(). The intent of the function also seems to be the same 
(only keep elements that are needed).

In what situations does the existing function not do the right thing?

Can should_keep_rela_group() be updated instead?


Yes, the code is largely based on the kpatch_regenerate_special_section(). 
However, the livepatch_strip_undefined_elements() and 
kpatch_regenerate_special_section() have different "granularity" and different 
scope.
1. Scope
- livepatch_strip_undefined_elements(): all RELA sections
- kpatch_regenerate_special_section(): special RELA sections

2. "granularity"
- livepatch_strip_undefined_elements(): all relas to be checked
- kpatch_regenerate_special_section(): all relas in a group are copied

I think it should be possible to create a common function with the base 
functionality that could take most of the common code in and then be used from 
within both of the functions.
However, I did not want to touch existing functionality and I am afraid the 
changes may result in a pretty convoluted code.

If you think it is still worth it, I can give it a shot.

Thanks,
--
Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH livepatch-python 1/1] livepatch: Add python bindings for livepatch operations

2019-08-16 Thread Wieczorkiewicz, Pawel

> On 16. Aug 2019, at 14:37, Wei Liu  wrote:
> 
> On Thu, Aug 15, 2019 at 11:36:46AM +, Pawel Wieczorkiewicz wrote:
>> Extend the XC python bindings library to support also all common
>> livepatch operations and actions.
>> 
>> 

…snip...

>> 
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Martin Mazein 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Leonard Foerster 
>> Reviewed-by: Norbert Manthey 
> 
> I haven't looked in details, but I'm fine with these new functionalities
> in general. Let's see if Marek has any objections.

Thanks.

> 
> Which version of Python do you use to build these? The requirement here
> is the code should build with both Python 2.5 and Python 3.
> 

Ah, I see. Thanks for pointing this out. We’re planing to upstream the tool 
using those bindings as well.
But, it still requires some work. Let us add the python versions support for 
the tool.

> Wei.


Best Regards,
Pawel Wieczorkiewicz


signature.asc
Description: Message signed with OpenPGP



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH lp-metadata 3/3] livepatch: Add metadata runtime retrieval mechanism

2019-08-16 Thread Wieczorkiewicz, Pawel

> On 16. Aug 2019, at 14:44, Wei Liu  wrote:
> 
> On Thu, Aug 15, 2019 at 11:27:50AM +, Pawel Wieczorkiewicz wrote:
>> Extend the livepatch list operation to fetch also payloads' metadata.
>> This is achieved by extending the sysctl list interface with 2 extra
>> guest handles:
>> * metadata - an array of arbitrary size strings
>> * metadata_len - an array of metadata strings' lengths (uin32_t each)

…snip...

>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Martin Pohlack 
>> Reviewed-by: Norbert Manthey 
>> ---
>> tools/libxc/include/xenctrl.h | 22 +++
>> tools/libxc/xc_misc.c | 66 
>> +++
>> tools/misc/xen-livepatch.c| 43 ++--
>> xen/common/livepatch.c| 22 +++
>> xen/include/public/sysctl.h   | 19 +
> 
> Mostly look good. One comment below...
> 
>> diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
>> index b86804b7a6..e4c8f4fe63 100644
>> --- a/xen/include/public/sysctl.h
>> +++ b/xen/include/public/sysctl.h
> 
> If it hasn't been done for this release already, changing sysctl interface 
> requires
> bumping the version number in this header.
> 

ACK. Will do (also for earlier patches…).

> Wei.

Best Regards,
Pawel Wieczorkiewicz


signature.asc
Description: Message signed with OpenPGP



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch: independ. modules 3/3] python: Add XC binding for Xen build ID

2019-08-16 Thread Wieczorkiewicz, Pawel

On 16. Aug 2019, at 14:47, Wei Liu mailto:w...@xen.org>> wrote:

On Thu, Aug 15, 2019 at 09:44:00AM +, Pawel Wieczorkiewicz wrote:
Extend the list of xc() object methods with additional one to display
Xen's buildid. The implementation follows the libxl implementation
(e.g. max buildid size assumption being XC_PAGE_SIZE).

Signed-off-by: Pawel Wieczorkiewicz 
mailto:wipa...@amazon.de>>
Reviewed-by: Martin Mazein mailto:amaz...@amazon.de>>
Reviewed-by: Andra-Irina Paraschiv 
mailto:andra...@amazon.com>>
Reviewed-by: Norbert Manthey mailto:nmant...@amazon.de>>

I'm a bit confused by the tag in the subject line. Which series does
this patch belong to?

Wei.

Thanks for taking a look.

This is the series: https://marc.info/?t=15554198232=1=4

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part2 v2 6/6] create-diff-object: Do not include all .rodata sections

2019-08-16 Thread Wieczorkiewicz, Pawel

> On 16. Aug 2019, at 11:57, Ross Lagerwall  wrote:
> 
> On 8/8/19 1:39 PM, Pawel Wieczorkiewicz wrote:
>> 

…snip...

>>  #define inc_printf(fmt, ...) \
>>  log_debug("%*s" fmt, recurselevel, "", ##__VA_ARGS__);
> This patch looks good. There is a comment at the top of 
> should_include_str_section() which should probably be updated as well:
> 
> /*
> * String sections are always included even if unchanged.
> * The format is either:
> * .rodata..str1.[0-9]+ (new in GCC 6.1.0)
> * or .rodata.str1.[0-9]+ (older versions of GCC)
> * For the new format we could be smarter and only include the needed
> * strings sections.
> */
> 

Oh yes, right. Let me update the comment. Thanks!

> In fact, it is probably a good idea to rename the function to something like 
> "is_rodata_str_section()" since this more accurately describes what it does 
> now.

ACK, will do.

> 
> Thanks,
> --
> Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz





signature.asc
Description: Message signed with OpenPGP



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part2 v2 5/6] create-diff-object: Add new entries to special sections array array

2019-08-16 Thread Wieczorkiewicz, Pawel

On 16. Aug 2019, at 11:40, Ross Lagerwall 
mailto:ross.lagerw...@citrix.com>> wrote:

On 8/8/19 1:35 PM, Pawel Wieczorkiewicz wrote:


…snip...

  * The rela groups in the .fixup section vary in size.  The beginning of each
  * .fixup rela group is referenced by the .ex_table section. To find the size
@@ -1072,6 +1090,18 @@ static struct special_section special_sections[] = {
  .name = ".altinstructions",
  .group_size = altinstructions_group_size,
  },
+ {
+ .name = ".altinstr_replacement",
+ .group_size = undefined_group_size,
+ },
+ {
+ .name = ".livepatch.hooks.load",
+ .group_size = livepatch_hooks_group_size,
+ },
+ {
+ .name = ".livepatch.hooks.unload",
+ .group_size = livepatch_hooks_group_size,
+ },
  {},
 };


Unless I'm misunderstanding something, I can't see how 
kpatch_regenerate_special_section would work with .altinstr_replacement having 
a group size of 0. It looks to me like the for loop in that function would 
become an infinite loop (due to incrementing by group_size) and 
should_keep_rela_group would always return false.


AFAICS, the group_size 0 sections are never actually processed by the 
kpatch_regenerate_special_section().
They are not RELA sections and the following check excludes them from this 
processing:

static void kpatch_process_special_sections(struct kpatch_elf *kelf)
{
[…]
for (special = special_sections; special->name; special++) {
[…]

sec = sec->rela;
if (!sec)
continue;

kpatch_regenerate_special_section(kelf, special, sec);
}

Nevertheless, you are right. It does not make much sense to rely on this 
assumption.
I will add explicit checks to kpatch_regenerate_special_section() and friends 
dealing with group_size 0 sections.

Regards,
--
Ross Lagerwall

Best,
Pawel Wieczorkiewicz




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH lp-metadata 2/3] livepatch: Handle arbitrary size names with the list operation

2019-08-15 Thread Wieczorkiewicz, Pawel
Thanks Julien. I will do that next time (unless you guys want me to re-send all 
this ;-)).

BTW, I also pushed my changes onto the xenbits server:
http://xenbits.xenproject.org/gitweb/?p=people/wipawel/livepatch-build-tools;a=summary
http://xenbits.xenproject.org/gitweb/?p=people/wipawel/xen;a=summary

I hope that makes navigation and dealing with the swarm of patches a bit easier.

Best Regards,
Pawel Wieczorkiewicz



On 15. Aug 2019, at 17:29, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:



On 15/08/2019 16:19, Wieczorkiewicz, Pawel wrote:
Hi Lars, Julien,

Hi,

Thanks for the pointers, I will read them up and follow the recommendations 
with my future contributions.
Sorry for the mess…
But, let me ask first before reading the wikis, how do you prefer submitting 
series that contain patches belonging to 2 distinct repos (e.g. xen and 
livepatch-build-tools)?

I can see two ways:

 1) One series per project and mention in the cover letter that modifications 
are required in another project (with link/title).
 2) Combine all the patches in one series and tag them differently. I.e [XEN] 
[LIVEPATCH].

1) is preferable if you have a lot of patches in each repo. 2) can be handy if 
you have only a couple of patches for one repo.

Cheers,

Best Regards,
Pawel Wieczorkiewicz
On 15. Aug 2019, at 16:58, Lars Kurth 
mailto:lars.kurth@gmail.com> 
<mailto:lars.kurth@gmail.com>> wrote:



On 15 Aug 2019, at 12:38, Julien Grall 
mailto:julien.gr...@arm.com> 
<mailto:julien.gr...@arm.com>> wrote:

Hi,

I am not going to answer on the patch itself but the process.

Any series (i.e more than one patch) should contain a cover letter with a rough 
summary of the goal of the series.

Furthermore, this 3 patches series has been received as 3 separate threads (i.e 
in-reply-to is missing). This is making difficult to know that all the patches 
belongs to the same series. In general, all patches are send as in-reply-to the 
cover letter. So all the patches sticks together in one thread.

The cover letter can be generated via git format-patch --cover-letter. 
Threading is done automatically with git-send-email when all the patches as 
passed in arguments.

For more details how to do it, you can read:

https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches#Sending_a_Patch_Series

Cheers,

Hi Pawel,

thank you for submitting the patch series.

We had a couple of new starters recently who followed a similar pattern to you. 
As a result of this, I recently updated the following docs

https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches - Definitions 
and general workflow
The bit which saves the most work is 
https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches#Sending_a_Patch_Series
As for Julien's comment on the threading: see the --thread and --cover-letter 
option as described in the Sending a Patch Series

https://wiki.xenproject.org/wiki/Managing_Xen_Patches_with_Git - Basic Git 
commands fitting into the workflow, including how to deal with reviews
https://wiki.xenproject.org/wiki/Managing_Xen_Patches_with_StGit - Basic StGit 
commands fitting into the workflow, including how to deal with reviews
I have not had time to play with git series yet. If anyone in your team uses it 
let me know

In any case: if you follow the instructions the entire submission process and 
dealing with review comments becomes much easier.

As a newcomer, to contributing to Xen, I would greatly appreciate if you could 
let me know of any issues with the docs, such that we can fix them

Regards
Lars



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879

--
Julien Grall




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH lp-metadata 2/3] livepatch: Handle arbitrary size names with the list operation

2019-08-15 Thread Wieczorkiewicz, Pawel
Hi Lars, Julien,

Thanks for the pointers, I will read them up and follow the recommendations 
with my future contributions.
Sorry for the mess…

But, let me ask first before reading the wikis, how do you prefer submitting 
series that contain patches belonging to 2 distinct repos (e.g. xen and 
livepatch-build-tools)?

Best Regards,
Pawel Wieczorkiewicz



On 15. Aug 2019, at 16:58, Lars Kurth 
mailto:lars.kurth@gmail.com>> wrote:



On 15 Aug 2019, at 12:38, Julien Grall 
mailto:julien.gr...@arm.com>> wrote:

Hi,

I am not going to answer on the patch itself but the process.

Any series (i.e more than one patch) should contain a cover letter with a rough 
summary of the goal of the series.

Furthermore, this 3 patches series has been received as 3 separate threads (i.e 
in-reply-to is missing). This is making difficult to know that all the patches 
belongs to the same series. In general, all patches are send as in-reply-to the 
cover letter. So all the patches sticks together in one thread.

The cover letter can be generated via git format-patch --cover-letter. 
Threading is done automatically with git-send-email when all the patches as 
passed in arguments.

For more details how to do it, you can read:

https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches#Sending_a_Patch_Series

Cheers,

Hi Pawel,

thank you for submitting the patch series.

We had a couple of new starters recently who followed a similar pattern to you. 
As a result of this, I recently updated the following docs

https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches - Definitions 
and general workflow
The bit which saves the most work is 
https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches#Sending_a_Patch_Series
As for Julien's comment on the threading: see the --thread and --cover-letter 
option as described in the Sending a Patch Series

https://wiki.xenproject.org/wiki/Managing_Xen_Patches_with_Git - Basic Git 
commands fitting into the workflow, including how to deal with reviews
https://wiki.xenproject.org/wiki/Managing_Xen_Patches_with_StGit - Basic StGit 
commands fitting into the workflow, including how to deal with reviews
I have not had time to play with git series yet. If anyone in your team uses it 
let me know

In any case: if you follow the instructions the entire submission process and 
dealing with review comments becomes much easier.

As a newcomer, to contributing to Xen, I would greatly appreciate if you could 
let me know of any issues with the docs, such that we can fix them

Regards
Lars







Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part2 6/6] create-diff-object: Do not include all .rodata sections

2019-04-30 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 18:11, Ross Lagerwall  wrote:
> 
> On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
>> Starting with the "2af6f1aa6233 Fix patch creation with GCC 6.1+" commit
>> all .rodata sections are included by default (regardless of whether they
>> are needed or not).
>> During stacked hotpatch builds it leads to unnecessary duplication of
>> the .rodata sections as each and every consecutive hotpatch contains all
>> the .rodata section of previous hotpatches.
> 
> This commit message is a bit confusing.
> 
> 1) All of this only applies to .rodata.str* sections. Other .rodata sections 
> are handled separately.

Yes, that’s right. I will make the commit message precise.

ACK. Will fix.

> 
> 2) The above commit _did not_ introduce the problem. Previous versions of GCC 
> did not split .rodata.str sections by function which meant that the entire 
> section was always included. The commit fixed patch creation and _maintained_ 
> the existing behaviour for GCC 6.1+ by including all the

I see, thanks for the clarification. I will update the wording to avoid 
confusion and incorrect attribution here.

> .rodata.str* sections. This patch now includes only what is needed (but it 
> should be noted that this would likely not be useful on older versions of GCC 
> since they don't split .rodata.str properly).

OK, I suppose users of older versions of GCC have to accept the fact.

> 
>> To prevent this situation, mark the .rodata section for inclusion only
>> if they are referenced by any of the current hotpatch symbols (or a
>> corresponding RELA section).
>> Extend patchability verification to detect all non-standard, non-rela,
>> non-debug and non-special sections that are not referenced by any of
>> the symbols or RELA sections.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Bjoern Doebel 
>> Reviewed-by: Norbert Manthey 
>> ---
>>  create-diff-object.c | 27 ++-
>>  1 file changed, 26 insertions(+), 1 deletion(-)
>> diff --git a/create-diff-object.c b/create-diff-object.c
>> index f6060cd..f7eb421 100644
>> --- a/create-diff-object.c
>> +++ b/create-diff-object.c
>> @@ -1341,7 +1341,7 @@ static void kpatch_include_standard_elements(struct 
>> kpatch_elf *kelf)
>>  list_for_each_entry(sec, >sections, list) {
>>  /* include these sections even if they haven't changed */
>> -if (is_standard_section(sec) || 
>> should_include_str_section(sec->name)) {
>> +if (is_standard_section(sec)) {
>>  sec->include = 1;
>>  if (sec->secsym)
>>  sec->secsym->include = 1;
>> @@ -1352,6 +1352,19 @@ static void kpatch_include_standard_elements(struct 
>> kpatch_elf *kelf)
>>  list_entry(kelf->symbols.next, struct symbol, list)->include = 1;
>>  }
>>  +static void kpatch_include_standard_string_elements(struct kpatch_elf 
>> *kelf)
>> +{
>> +struct section *sec;
>> +
>> +list_for_each_entry(sec, >sections, list) {
>> +if (should_include_str_section(sec->name) && 
>> is_referenced_section(sec, kelf)) {
>> +sec->include = 1;
>> +if (sec->secsym)
>> +sec->secsym->include = 1;
>> +}
>> +}
>> +}
> 
> I think it would be simpler to just amend the previous function rather than 
> introducing a new one. E.g.
> 
> ... || (should_include_str_section(sec->name) && is_referenced_section(sec, 
> kelf))

IIRC, it is unfortunately too early to do that from within 
kpatch_include_standard_elements().
I want to call the kpatch_include_standard_string_elements() after the 
following functions are called:
- kpatch_include_changed_functions()
- kpatch_include_debug_sections()
- kpatch_include_hook_elements()
because they may affect is_referenced_section() result.

> 
> Regards,
> -- 
> Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part2 5/6] create-diff-object: Add new entries to special sections array

2019-04-30 Thread Wieczorkiewicz, Pawel

On 29. Apr 2019, at 17:47, Ross Lagerwall 
mailto:ross.lagerw...@citrix.com>> wrote:

On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
Handle .livepatch.hooks* and .altinstr_replacement sections as the
special sections with assigned group_size resolution function.
By default each .livepatch.hooks* sections' entry is 8 bytes long (a
pointer). The .altinstr_replacement section follows the .altinstructions
section settings.
Allow to specify different .livepatch.hooks* section entry size using
shell environment variable HOOK_STRUCT_SIZE.
Cleanup an incorrect indentation around group_size resulution functions.
Signed-off-by: Pawel Wieczorkiewicz 
mailto:wipa...@amazon.de>>
Reviewed-by: Andra-Irina Paraschiv 
mailto:andra...@amazon.com>>
Reviewed-by: Bjoern Doebel mailto:doe...@amazon.de>>
Reviewed-by: Norbert Manthey mailto:nmant...@amazon.de>>
---
 create-diff-object.c | 87 
 1 file changed, 54 insertions(+), 33 deletions(-)
diff --git a/create-diff-object.c b/create-diff-object.c
index b0b4dcb..f6060cd 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -960,51 +960,64 @@ static void kpatch_mark_constant_labels_same(struct 
kpatch_elf *kelf)

Fix the indentation in the patch which introduces the problem rather than 
fixing it in a subsequent patch.

Oh, certainly. I forgot to update the commits involved properly.

ACK. Will fix.


   static int bug_frames_group_size(struct kpatch_elf *kelf, int offset)
 {
-static int size = 0;
-char *str;
-if (!size) {
-str = getenv("BUG_STRUCT_SIZE");
-size = str ? atoi(str) : 8;
-}
-
-return size;
+ static int size = 0;
+ char *str;
+ if (!size) {
+ str = getenv("BUG_STRUCT_SIZE");
+ size = str ? atoi(str) : 8;
+ }
+
+ return size;
 }
   static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset)
 {
-static int size = 0;
-char *str;
-if (!size) {
-str = getenv("BUG_STRUCT_SIZE");
-size = str ? atoi(str) : 16;
-}
-
-return size;
+ static int size = 0;
+ char *str;
+ if (!size) {
+ str = getenv("BUG_STRUCT_SIZE");
+ size = str ? atoi(str) : 16;
+ }
+
+ return size;
 }
   static int ex_table_group_size(struct kpatch_elf *kelf, int offset)
 {
-static int size = 0;
-char *str;
-if (!size) {
-str = getenv("EX_STRUCT_SIZE");
-size = str ? atoi(str) : 8;
-}
-
-return size;
+ static int size = 0;
+ char *str;
+ if (!size) {
+ str = getenv("EX_STRUCT_SIZE");
+ size = str ? atoi(str) : 8;
+ }
+
+ return size;
 }
   static int altinstructions_group_size(struct kpatch_elf *kelf, int offset)
 {
-static int size = 0;
-char *str;
-if (!size) {
-str = getenv("ALT_STRUCT_SIZE");
-size = str ? atoi(str) : 12;
-}
-
-printf("altinstr_size=%d\n", size);
-return size;
+ static int size = 0;
+ char *str;
+ if (!size) {
+ str = getenv("ALT_STRUCT_SIZE");
+ size = str ? atoi(str) : 12;
+ }
+
+ printf("altinstr_size=%d\n", size);
+ return size;
+}
+
+static int livepatch_hooks_group_size(struct kpatch_elf *kelf, int offset)
+{
+ static int size = 0;
+ char *str;
+ if (!size) {
+ str = getenv("HOOK_STRUCT_SIZE");
+ size = str ? atoi(str) : 8;
+ }
+
+ printf("livepatch_hooks_size=%d\n", size);

If you want to keep this debugging output, rather use log_debug().

ACK. Will fix.


+ return size;
 }
   /*
@@ -1084,6 +1097,14 @@ static struct special_section special_sections[] = {
  .name = ".altinstructions",
  .group_size = altinstructions_group_size,
  },
+ {
+ .name = ".altinstr_replacement",
+ .group_size = altinstructions_group_size,
+ },
+ {
+ .name = ".livepatch.hooks",
+ .group_size = livepatch_hooks_group_size,
+ },
  {},
 };


I don't understand the point of this change.

IIUC unlike .altinstructions, the .altinstr_replacement section does not have a 
fixed group size, so this change would not work other than by luck. If

That’s true. The .altinstr_replacement group_size should be 0 (aka undefined).

ACK. Will fix.

the goal was to prune bits of the .altinstr_replacement table that do not need 
to be included, you need to update the code in 
kpatch_process_special_sections() which has special handling for 
.altinstr_replacement. It needs to parse the updated, pruned .altinstructions 
section and regenerate .altinstr_replacement, including only what is needed.


No this was not the goal. I am explaining it below.

I don't know why .livepatch.hooks is included in this list either since all 
hooks are always included and there is nothing to regenerate/prune.

As discussed when reviewing [1], I need a function telling which section is 
special.
By special I mean:
a) should not be a subject of extra validation (See [2])
b) should not be a subject of STN_UNDEF purging (See [3])

Thus, I want to explicitly call out all "special" sections by their name and 
specify
their group_size whenever applicable (I did it incorrectly for 
.altinstr_replacement,
as you have spotted - thanks!) in 

Re: [Xen-devel] [livepatch-build-tools part2 3/6] create-diff-object: Add is_special_section() helper function

2019-04-30 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 17:25, Ross Lagerwall  wrote:
> 
> On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
>> This function determines, based on the given section name, if the
>> sections belongs to the special sections category.
>> It treats a name from the special_sections array as a prefix. Any
>> sections whose name starts with special section prefix is considered
>> a special section.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Bjoern Doebel 
>> Reviewed-by: Norbert Manthey 
>> ---
>>  common.c | 23 +++
>>  common.h |  1 +
>>  2 files changed, 24 insertions(+)
>> diff --git a/common.c b/common.c
>> index c968299..a2c860b 100644
>> --- a/common.c
>> +++ b/common.c
>> @@ -290,6 +290,29 @@ int is_referenced_section(const struct section *sec, 
>> const struct kpatch_elf *ke
>>  return false;
>>  }
>>  +int is_special_section(struct section *sec)
> 
> const for the parameter?

ACK. Will add.

> 
>> +{
>> +static struct special_section_names {
>> +const char *name;
>> +} names[] = {
>> +{ .name = ".bug_frames" },
>> +{ .name = ".fixup"  },
>> +{ .name = ".ex_table"   },
>> +{ .name = ".altinstructions"},
>> +{ .name = ".altinstr_replacement"   },
>> +{ .name = ".livepatch.hooks"},
>> +{ .name = NULL  },
>> +};
>> +struct special_section_names *special;
> 
> Wouldn't it be better to reuse the existing special_sections array rather 
> than partially duplicating it here?

After looking at this code again, I think you’re right and it would be better.
It would require to explicitly call out all sections to be considered special in
the special_sections array, but this is actually what I need for further 
changes anyway.

ACK. Will fix. 

> 
>> +
>> +for (special = names; special->name; special++) {
>> +if (!strncmp(sec->name, special->name, strlen(special->name)))
>> +return true;
> 
> This check is not as precise as it could be, since ".altinstructionsfoo" 
> would be considered special when it actually means nothing to this tool.

Given the above reasoning, that’s right.

ACK. Will fix.

> 
> -- 
> Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part2 2/6] common: Add is_referenced_section() helper function

2019-04-29 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 17:14, Ross Lagerwall  wrote:
> 
> On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
>> This function checks if given section has an included corresponding
>> RELA section and/or any of the symbols table symbols references the
>> section. Section associated symbols are ignored here as there is
>> always such a symbol for every section.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Bjoern Doebel 
>> Reviewed-by: Norbert Manthey 
>> ---
>>  common.c | 22 +-
>>  common.h |  1 +
>>  2 files changed, 22 insertions(+), 1 deletion(-)
>> diff --git a/common.c b/common.c
>> index 1fb07cb..c968299 100644
>> --- a/common.c
>> +++ b/common.c
>> @@ -15,7 +15,7 @@
>>int is_rela_section(struct section *sec)
>>  {
>> -return (sec->sh.sh_type == SHT_RELA);
>> +return sec && (sec->sh.sh_type == SHT_RELA);
>>  }
>>int is_local_sym(struct symbol *sym)
>> @@ -270,6 +270,26 @@ int is_standard_section(struct section *sec)
>>  }
>>  }
>>  +int is_referenced_section(const struct section *sec, const struct 
>> kpatch_elf *kelf)
> 
> Let's keep to 80 chars where practical (and throughout the rest of the 
> patches).

ACK. Will fix. Although, sometimes it makes the code pretty unreadable.

> 
>> +{
>> +struct symbol *sym;
>> +
>> +if (is_rela_section(sec->rela) && sec->rela->include)
>> +return true;
>> +
>> +list_for_each_entry(sym, >symbols, list) {
>> +if (!sym->include || !sym->sec)
>> +continue;
>> +/* Ignore section associated sections */
>> +if (sym->type == STT_SECTION)
>> +continue;
>> +if (sym->sec->index == sec->index)
>> +return true;
> 
> You can simplify this check to `sym->sec == sec` like the rest of the code 
> does.

Might be my paranoia again (or I am simply missing some obvious 
assumptions/invariants),
but I explicitly wanted to check whether given section/symbol is referenced 
using other means
than addresses.

> 
> -- 
> Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B



___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools 4/4] livepatch-build: Handle newly created object files

2019-04-29 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 15:53, Ross Lagerwall  wrote:
> 
> On 4/8/19 9:32 AM, Pawel Wieczorkiewicz wrote:
>> Up to now the livepatch-build ignores newly created object files.
>> When patch applies new .c file and augments its Makefile to build it
>> the resulting object file is not taken into account for final linking
>> step.
>> Such newly created object files can be detected by comparing patched/
>> and original/ directories and copied over to the output directory for
>> the final linking step.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Andra-Irina Paraschiv 
>> Reviewed-by: Bjoern Doebel 
>> Reviewed-by: Norbert Manthey 
>> ---
>>  livepatch-build | 6 ++
>>  1 file changed, 6 insertions(+)
>> diff --git a/livepatch-build b/livepatch-build
>> index 796838c..b43730c 100755
>> --- a/livepatch-build
>> +++ b/livepatch-build
>> @@ -146,6 +146,12 @@ function create_patch()
>>  fi
>>  done
>>  +NEW_FILES=$(comm -23 <(find patched -type f -name '*.o' | cut -f2- 
>> -d'/' | sort -u) <(find original -type f -name '*.o' | cut -f2- -d'/' | sort 
>> -u))
> 
> The paths should be `patched/xen` and `original/xen` so that only hypervisor 
> changes are processed. It is done this way earlier (see FILES="$(find xen 
> ...)").

ACK. Will fix.

> 
> Since process substitution creates a subshell, it might be simpler to do <(cd 
> patched/xen && find . ...) and then drop the `cut`. Also, the `-u` argument 
> to sort seems unnecessary.

ACK. Will fix.
The -u for sort is just my paranoia.

> 
>> +for i in $NEW_FILES; do
>> +cp "patched/$i" "output/$i"
>> +CHANGED=1
>> +done
> 
> If the live patch for whatever reason has no "patched" object files and only 
> "new" object files, then it is not going to do anything useful since nothing 
> will use the new functions. This should fail to build with an error. E.g. set 
> NEW=1 above and then later check for CHANGED=0 && NEW=1.
> 

I disagree here. Inline assembly patching can use new functions even without 
having any "patched" objects.
Also hotpatch modules with hooks (functionality I will send upstream soon) can 
use the "new" objects provided
functionality for various reasons (re-registrating a callback for instance, or 
some testing related activities).

> Previously all object files that were linked into the livepatch were from the 
> output of create-diff-object. This change just includes the newly built 
> object files directly. I wonder if there are any issues or subtle differences 
> when doing this? A couple of differences off the top of my head:
> 
> 1) The object file will include _everything_ (e.g. potentially unused 
> functions) while create-diff-object generally only includes the minimum that 
> is needed.

Yes, that’s right. When a patch defines new files (and thereby new object 
files) it should do it wisely.

> 
> 2) Hooks and ignored functions/sections in the new object file would not be 
> processed at all.

Not sure I follow the point here, but hooks and functions properly defined in 
new object files will be
processed and used during link time.

I have a test hotpatch that does that.

> 
> The was previously a patch on xen-devel which took a different approach 
> (https://lists.xenproject.org/archives/html/xen-devel/2017-06/msg03532.html). 
> Perhaps you could look at it and see which approach would be better?

Taking a look. Thanks.

> 
> Thanks,
> -- 
> Ross Lagerwall
> 
> 

Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part2 4/6] livepatch-build: detect special section group sizes

2019-04-29 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 16:21, Ross Lagerwall  wrote:
> 
> On 4/29/19 3:10 PM, Ross Lagerwall wrote:
>> On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
>>> Hard-coding the special section group sizes is unreliable. Instead,
>>> determine them dynamically by finding the related struct definitions
>>> in the DWARF metadata.
>>> 
>>> This is a livepatch backport of kpatch upstream commit [1]:
>>> kpatch-build: detect special section group sizes 170449847136a48b19fc
>>> 
>>> Xen only deals with alt_instr, bug_frame and exception_table_entry
>>> structures, so sizes of these structers are obtained from xen-syms.
>> structers -> structures

Thanks, will fix.

>>> 
>>> This change is needed since with recent Xen the alt_instr structure
>>> has changed size from 12 to 14 bytes.
>>> 
>>> [1] 
>>> https://github.com/jpoimboe/kpatch/commit/170449847136a48b19fcceb19c1d4d257d386b56
>>>  
>>> 
>>> Signed-off-by: Pawel Wieczorkiewicz 
>>> Reviewed-by: Bjoern Doebel 
>>> Reviewed-by: Martin Mazein 
>>> ---
>>>   create-diff-object.c | 60 
>>> 
>>>   livepatch-build  | 23 
>>>   2 files changed, 74 insertions(+), 9 deletions(-)
>>> 
>>> diff --git a/create-diff-object.c b/create-diff-object.c
>>> index 1e6e617..b0b4dcb 100644
>>> --- a/create-diff-object.c
>>> +++ b/create-diff-object.c
>>> @@ -958,12 +958,54 @@ static void kpatch_mark_constant_labels_same(struct 
>>> kpatch_elf *kelf)
>>>   }
>>>   }
>>> -static int bug_frames_0_group_size(struct kpatch_elf *kelf, int offset) { 
>>> return 8; }
>>> -static int bug_frames_1_group_size(struct kpatch_elf *kelf, int offset) { 
>>> return 8; }
>>> -static int bug_frames_2_group_size(struct kpatch_elf *kelf, int offset) { 
>>> return 8; }
>>> -static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset) { 
>>> return 16; }
>>> -static int ex_table_group_size(struct kpatch_elf *kelf, int offset) { 
>>> return 8; }
>>> -static int altinstructions_group_size(struct kpatch_elf *kelf, int offset) 
>>> { return 12; }
>>> +static int bug_frames_group_size(struct kpatch_elf *kelf, int offset)
>>> +{
>>> +static int size = 0;
>>> +char *str;
>>> +if (!size) {
>>> +str = getenv("BUG_STRUCT_SIZE");
>>> +size = str ? atoi(str) : 8;
>> Why did you remove the hard error here from the original kpatch commit? I 
>> think a hard error is preferable to guessing.

Previously the sizes were hard-coded. I prefer to use them directly over 
failing hard here.
If we could not come up with a sane defaults, than failing hard would be the 
only option.
Anyway, I am cool to go either way upon your good judgment.

>>> +}
>>> +
>>> +return size;
>>> +}
>>> +
>>> +static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset)
>>> +{
>>> +static int size = 0;
>>> +char *str;
>>> +if (!size) {
>>> +str = getenv("BUG_STRUCT_SIZE");
>>> +size = str ? atoi(str) : 16;
>>> +}
>>> +
>>> +return size;
>>> +}
>>> +
>>> +static int ex_table_group_size(struct kpatch_elf *kelf, int offset)
>>> +{
>>> +static int size = 0;
>>> +char *str;
>>> +if (!size) {
>>> +str = getenv("EX_STRUCT_SIZE");
>>> +size = str ? atoi(str) : 8;
>>> +}
>>> +
>>> +return size;
>>> +}
>>> +
>>> +static int altinstructions_group_size(struct kpatch_elf *kelf, int offset)
>>> +{
>>> +static int size = 0;
>>> +char *str;
>>> +if (!size) {
>>> +str = getenv("ALT_STRUCT_SIZE");
>>> +size = str ? atoi(str) : 12;
>>> +}
>>> +
>>> +printf("altinstr_size=%d\n", size);
>>> +return size;
>>> +}
>>>   /*
>>>* The rela groups in the .fixup section vary in size.  The beginning of 
>>> each
>>> @@ -1016,15 +1058,15 @@ static int fixup_group_size(struct kpatch_elf 
>>> *kelf, int offset)
>>>   static struct special_section special_sections[] = {
>>>   {
>>>   .name= ".bug_frames.0",
>>> -.group_size= bug_frames_0_group_size,
>>> +.group_size= bug_frames_group_size,
>>>   },
>>>   {
>>>   .name= ".bug_frames.1",
>>> -.group_size= bug_frames_1_group_size,
>>> +.group_size= bug_frames_group_size,
>>>   },
>>>   {
>>>   .name= ".bug_frames.2",
>>> -.group_size= bug_frames_2_group_size,
>>> +.group_size= bug_frames_group_size,
>>>   },
>>>   {
>>>   .name= ".bug_frames.3",
>>> diff --git a/livepatch-build b/livepatch-build
>>> index c057fa1..a6cae12 100755
>>> --- a/livepatch-build
>>> +++ b/livepatch-build
>>> @@ -284,6 +284,29 @@ echo "Output directory: ${OUTPUT}"
>>>   echo ""
>>>   echo
>>> +if [ -f "$XENSYMS" ]; then
>>> +echo "Reading special section data"
>>> +SPECIAL_VARS=$(readelf -wi "$XENSYMS" |
>>> +   gawk --non-decimal-data '
>>> +   BEGIN { a = b = e = 0 }
>>> +

Re: [Xen-devel] [livepatch-build-tools 3/4] livepatch-build: Do not follow every symlink for patch file

2019-04-29 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 14:40, Ross Lagerwall  wrote:
> 
> On 4/8/19 9:32 AM, Pawel Wieczorkiewicz wrote:
>> In some build systems symlinks might be used for patch file names
>> to point from target directories to actual patches. Following those
>> symlinks breaks naming convention as the resulting built modules
>> would be named after the actual hardlink insteads of the symlink.
>> Livepatch-build obtains hotpatch name from the patch file, so it
>> should not canonicalize the file path resolving all the symlinks to
>> not lose the original symlink name.
>> Signed-off-by: Pawel Wieczorkiewicz 
>> Reviewed-by: Martin Pohlack 
>> Reviewed-by: Bjoern Doebel 
>> Reviewed-by: Norbert Manthey 
>> ---
>>  livepatch-build | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>> diff --git a/livepatch-build b/livepatch-build
>> index c057fa1..796838c 100755
>> --- a/livepatch-build
>> +++ b/livepatch-build
>> @@ -265,7 +265,9 @@ done
>>  [ -z "$DEPENDS" ] && die "Build-id dependency not given"
>>SRCDIR="$(readlink -m -- "$srcarg")"
>> -PATCHFILE="$(readlink -m -- "$patcharg")"
>> +# We need an absolute path because we move around, but we need to
>> +# retain the name of the symlink (= realpath -s)
>> +PATCHFILE="$(readlink -f "$(dirname "$patcharg")")/$(basename "$patcharg")"
>>  CONFIGFILE="$(readlink -m -- "$configarg")"
>>  OUTPUT="$(readlink -m -- "$outputarg")"
>>  
> 
> This works, but would it not be simpler to just pass $patcharg into 
> make_patch_name()?
> 

No strong opinion here, but the readlink change felt less invasive (no changes 
to the existing semantics).

Thank you for looking into this.

> -- 
> Ross Lagerwall
> 


Best Regards,
Pawel Wieczorkiewicz





Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B



___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [livepatch-build-tools part3 1/3] create-diff-object: Do not create empty .livepatch.funcs section

2019-04-29 Thread Wieczorkiewicz, Pawel

> On 29. Apr 2019, at 16:37, Ross Lagerwall  wrote:
> 
> On 4/25/19 5:51 AM, Konrad Rzeszutek Wilk wrote:
>> On Tue, Apr 16, 2019 at 12:22:39PM +, Pawel Wieczorkiewicz wrote:
>>> When there is no changed function in the generated payload, do not
>>> create an empty .livepatch.funcs section. Hypervisor code considers
>>> such payloads as broken and rejects to load them.
>>> 
>>> Such payloads without any changed functions may appear when only
>>> hooks are specified.
>> Ross, I am going to push this in next week unless you have other thoughts?
> Reviewed-by: Ross Lagerwall 
> 
> This code change looks OK to me. However:
> 

Thank you for reviewing.

> 1) I think that the hypervisor should treat an empty .livepatch.funcs section 
> the same as it treats a non-present .livepatch.funcs section (i.e. it allows 
> it) which would make this change unnecessary.
> 

I do not have a strong opinion here, but it felt unnecessary (and a bit 
confusing) to generate an empty section.
Also I did not want to touch hypervisor code for this.

> 2) Unless I'm being stupid, I don't see how this change would work anyway. 
> Surely this code at the start of prepare_payload() would fail if the section 
> were missing?
> 
>sec = livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_FUNC);
>ASSERT(sec);
>if ( !section_ok(elf, sec, sizeof(*payload->funcs)) )
>return -EINVAL;
> 

In my soon-to-be-upstreamed backlog I have the following commit:
livepatch: Do not enforce ELF_LIVEPATCH_FUNC section presence
Where I actually make use of this new functionality.

The main idea behind this change, was to enable generation of hooks-only 
hotpatch modules
(i.e. modules that does not patch anything, just trigger actions).

> Regards,
> -- 
> Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B



___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] xen/tools: Fix symbols segfaults

2019-04-03 Thread Wieczorkiewicz, Pawel


On 3. Apr 2019, at 10:10, Jan Beulich 
mailto:jbeul...@suse.com>> wrote:

On 03.04.19 at 09:56, mailto:wipa...@amazon.de>> wrote:
The symbols tool is outdated and has a bug in it leading to crashes.
The tool is derived from linux kernel where this bug has been already
fixed.

Thanks for noticing this omission of ours.

Anytime.


Original linux kernel commit:
e0a04b11e4059cab033469617 scripts/kallsyms.c: fix potential segfault

Signed-off-by: Pawel Wieczorkiewicz 
mailto:wipa...@amazon.de>>
Reviewed-by: Bjoern Doebel mailto:doe...@amazon.de>>
Reviewed-by: Norbert Manthey mailto:nmant...@amazon.de>>

When we pull in changes (almost) verbatim from Linux, we typically
retain original authorship as well as the (possibly massaged)
title and description. See xen/arch/x86/cpu/mwait-idle.c's
history for some examples. I'll do this transformation before
committing the change, but in the future I'd appreciate if ported
patches were submitted that way.

Sure, I will be submitting patches that way.
It might make sense to add this explanation into the CONTRIBUTING
file to avoid this problem in the future (unless it documented already
somewhere and I simply missed it).


Acked-by: Jan Beulich mailto:jbeul...@suse.com>>

I'm btw also confused by the Cc list you've used: You should
have Cc-ed THE REST, not just the tool stack maintainers.

You’re right. My bad. Sorry.


Jan



Best Regards,
Pawel Wieczorkiewicz






Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel