Commit Graph

101 Commits

Author SHA1 Message Date
Thomas Schoebel-Theuer d5e7798310 copy: avoid race between run_copy() and clash 2024-01-23 09:50:02 +01:00
Thomas Schoebel-Theuer e273447add copy: improve state barriers 2023-08-07 16:09:50 +02:00
Thomas Schoebel-Theuer 7c59774177 copy: safeguard writeout flag 2023-08-07 16:08:55 +02:00
Thomas Schoebel-Theuer b53b3777d4 copy: safeguard allocation barriers 2023-08-07 16:08:55 +02:00
Thomas Schoebel-Theuer 7caf2341ea copy: safeguard allocation problems 2023-08-07 16:08:55 +02:00
Thomas Schoebel-Theuer 49c408cac2 copy: constify state table subpages
I have seen some "strange" behaviour so infrequently, so I am unsure whether
this is a bugfix at all.

I am unsure, whether this _suspected_ bug would be in gcc, or whether
the bug would be mine.

If it is mine, then I assumed that gcc would produce better machine code
than required by ISO C.

Currently, I don't (yet) have the newest version of the ISO C standard,
so I cannot claim the truth.

Whatever: I found the _suspected_ bug by _dissassembling_ before vs after this
patch had been applied:

        .type   copy_brick_construct, @function                                                                 .type   copy_brick_construct, @function
copy_brick_construct:                                                                                   copy_brick_construct:
                                                                                                   >            pushq   %r13    #
        pushq   %r12    #                                                                                       pushq   %r12    #
        pushq   %rbp    #                                                                          |    # block/mars/kernel/mars_copy.c:        st = brick_block_alloc(0, PAGE_SIZE);
        movl    $1155, %edx     #,                                                                 <
                                                                                                   >            pushq   %rbp    #
        pushq   %rbx    #                                                                                       pushq   %rbx    #
        movl    $4096, %esi     #,                                                                 <
        movq    %rdi, %rbx      # brick, brick                                                     |            movq    %rdi, %r12      # brick, brick
                                                                                                   >            movl    $4096, %esi     #,
        xorl    %edi, %edi      #                                                                               xorl    %edi, %edi      #
        call    _brick_block_alloc      #                                                                       call    _brick_block_alloc      #
        movq    %rax, %rdx      #, tmp99                                                           |            movq    %rax, %rbx      #, _res_
        movl    $1024, %ecx     #, tmp102                                                                       movl    $1024, %ecx     #, tmp102
        movq    %rax, 408(%rbx) # tmp99, brick_11(D)->st                                           <
        movq    %rdx, %rdi      # tmp99, tmp99                                                     <
        xorl    %eax, %eax      # tmp101                                                                        xorl    %eax, %eax      # tmp101
        xorl    %ebp, %ebp      # ivtmp.179                                                        |            movq    %rbx, %rdi      # _res_, _res_
        xorl    %r12d, %r12d    # tmp106                                                           <
        rep stosl                                                                                               rep stosl
                                                                                                   >            xorl    %ebp, %ebp      # ivtmp.174
                                                                                                   >            xorl    %r13d, %r13d    # tmp105
.L26:                                                                                                   .L26:
        movl    $1172, %edx     #,                                                                 |            movl    $1177, %edx     #,
        movl    $4096, %esi     #,                                                                              movl    $4096, %esi     #,
        xorl    %edi, %edi      #                                                                               xorl    %edi, %edi      #
        call    _brick_block_alloc      #                                                                       call    _brick_block_alloc      #
        movq    %rax, %rdx      #, tmp103                                                                       movq    %rax, %rdx      #, tmp103
        movq    408(%rbx), %rax # brick_11(D)->st, brick_11(D)->st                                 |            movq    %rdx, (%rbx,%rbp,8)     # tmp103, MEM[base: _res__9, index: ivtmp.174_28, step:
                                                                                                   >            incq    %rbp    # ivtmp.174
        movl    $1024, %ecx     #, tmp107                                                          |            movq    %rax, %rdi      # tmp103, _res_
        movq    %rdx, %rdi      # tmp103, tmp103                                                   |            movl    $1024, %ecx     #, tmp106
        movq    %rdx, (%rax,%rbp)       # tmp103, *_4                                              <
        addq    $8, %rbp        #, ivtmp.179                                                       <
        movl    %r12d, %eax     # tmp106, tmp106                                                   <
        cmpq    $2048, %rbp     #, ivtmp.179                                                       |            cmpq    $256, %rbp      #, ivtmp.174
        rep stosl                                                                                               rep stosl
        jne     .L26    #,                                                                                      jne     .L26    #,
        leaq    376(%rbx), %rdi #, tmp108                                                          |            leaq    376(%r12), %rdi #, tmp107
        movq    $__key.72209, %rdx      #,                                                         |            movq    $__key.72227, %rdx      #,
        movq    $.LC3, %rsi     #,                                                                              movq    $.LC3, %rsi     #,
        call    __init_waitqueue_head   #                                                                       call    __init_waitqueue_head   #
                                                                                                   >    # block/mars/kernel/mars_copy.c:        brick->st = st;
                                                                                                   >            movq    %rbx, 408(%r12) # _res_, brick_10(D)->st
        xorl    %eax, %eax      #                                                                               xorl    %eax, %eax      #
        popq    %rbx    #                                                                                       popq    %rbx    #
        popq    %rbp    #                                                                                       popq    %rbp    #
        popq    %r12    #                                                                                       popq    %r12    #
                                                                                                   >            popq    %r13    #
        ret                                                                                                     ret

Hint: the 2-dimenional array indexing looks _suspicious_ to me.

But analysis is not as easy as one might assume.

Please help me:

If this would be really a bug in gcc (I am not sure), it should be fixed
by the upstream of gcc. Please contact me if you know / can show that

  (a) if it is _really_ a bug (currently very hard to reproduce via MARS), and
  (b) the bug is really in gcc but not mine (unsure for now), and
  (c) how to convert this into a _reproducer_ for the gcc team.

I am not sure whether this is a _full_ reproducer, because it might
depend on the arch (amd64) and/or on specific Linux kernel compile options.

I don't have the time for ananlysis of all of these, or maybe even more
thingies to do.
2023-08-07 16:08:55 +02:00
Thomas Schoebel-Theuer 602d1380ec copy: reduce address evaluation
Prototect against future use of ++ operators in arguments ;)
2023-08-07 16:08:55 +02:00
Thomas Schoebel-Theuer 44f371ca7f copy: convert state lvalues to references 2023-08-07 16:08:52 +02:00
Thomas Schoebel-Theuer 976857a9d7 copy: fix indirect race from index wraparound 2023-08-03 13:24:47 +02:00
Thomas Schoebel-Theuer ae8e7611d5 copy: simplify notify_clash() 2023-05-30 10:49:55 +02:00
Thomas Schoebel-Theuer bdf8d6e7eb copy: safeguard potential race 2023-05-30 10:49:55 +02:00
Thomas Schoebel-Theuer e58488a777 copy: factor out and simplify reset code 2023-05-30 10:49:50 +02:00
Thomas Schoebel-Theuer d41ea13d37 copy: reduce clash overhead 2023-05-30 10:05:30 +02:00
Thomas Schoebel-Theuer 8e1e2f81a3 copy: yield CPU more often 2023-05-30 10:05:30 +02:00
Thomas Schoebel-Theuer 1a53f589d4 copy: improve error code 2023-05-23 10:47:39 +02:00
Andrea Gelmini dd1e4e1323 Fix typos
[small adaptations by Thomas Schoebel-Theuer, and
some problems with LyX-specific file format fixed]
2023-04-05 13:30:38 +02:00
Thomas Schoebel-Theuer 5a6cfa7798 copy: replace st->prev with computation 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer 2740de0422 copy: safeguard coercions 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer 40e0fdd519 copy: v2 limit via MAX_ACTIVE_AREA 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer 9804d7456e copy: v2 stable_copy{start,end} 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer 5efeb7545b copy: length and offset paranoia for debugging 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer 60b1f238d7 copy: safeguard prev 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer 9701b0b0cc copy: optimize ref_len 2022-12-02 22:17:36 +01:00
Thomas Schoebel-Theuer a72af6a9e3 copy: introduce brick shutdown phase with timeout 2022-12-02 22:17:33 +01:00
Thomas Schoebel-Theuer fd8185e9c9 copy: use new smp waiting 2022-08-24 10:22:27 +02:00
Thomas Schoebel-Theuer f92a44ecfa copy: safeguard against strange compiler warnings 2022-08-01 15:03:38 +02:00
Thomas Schoebel-Theuer b555ba5d81 copy: safeguard any re-triggered writes 2022-07-28 14:47:47 +02:00
Thomas Schoebel-Theuer c9f1854f3c copy: safeguard start conditions 2022-07-28 14:47:47 +02:00
Thomas Schoebel-Theuer 2d5b708ff6 copy: safeguard advance on concluded states 2022-07-28 14:42:10 +02:00
Thomas Schoebel-Theuer 1e551e624b copy: safeguard ref_len 2022-07-28 14:41:53 +02:00
Thomas Schoebel-Theuer b6a5ee3227 copy: fix COPY_CHUNK border crossing 2022-07-28 14:37:23 +02:00
Thomas Schoebel-Theuer 1932198fd9 copy: clarify error messages 2022-07-28 14:35:52 +02:00
Thomas Schoebel-Theuer c5204c605f copy: remove superfluous checks 2022-07-27 10:36:55 +02:00
Thomas Schoebel-Theuer 1f4f044914 copy: setup callback after allocation succeeded 2022-07-12 11:28:12 +02:00
Thomas Schoebel-Theuer 15f96ea5e2 copy: fix ENOMEM error path 2022-07-12 11:28:12 +02:00
Thomas Schoebel-Theuer 1c6d0fd2bd copy: simplify currently unused determine_input 2022-05-20 00:16:29 +02:00
Thomas Schoebel-Theuer afc4366145 copy: simplify len shortening code 2022-05-20 00:16:29 +02:00
Thomas Schoebel-Theuer 40651f0646 copy: index paranoia 2022-05-20 00:16:28 +02:00
Thomas Schoebel-Theuer e6115c4e76 copy: improve error msg 2022-05-20 00:04:59 +02:00
Thomas Schoebel-Theuer 0615ab3a23 copy: fix enum type checking
block/mars/kernel/mars_copy.c:466:2: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
2022-04-02 18:55:19 +02:00
Thomas Schoebel-Theuer d18290d1f9 copy: remove redundant inputs 2021-07-15 11:20:51 +02:00
Thomas Schoebel-Theuer 5f13e810b7 all: safeguard mb on indirect calls 2021-07-08 07:44:38 +02:00
Thomas Schoebel-Theuer 8761f8739d copy: pretty spacing 2021-04-16 11:30:12 +02:00
Thomas Schoebel-Theuer 344c3a7e95 copy: safeguard underflow 2021-04-16 11:30:12 +02:00
Thomas Schoebel-Theuer 8412411390 copy: make offset and len unsigned 2021-04-16 11:30:12 +02:00
Thomas Schoebel-Theuer 532065f9b4 copy: make index unsigned 2021-04-16 11:30:12 +02:00
Thomas Schoebel-Theuer c7fd43b03d copy: safeguard negative positions 2021-04-16 11:30:12 +02:00
Thomas Schoebel-Theuer 89c29da9c5 copy: safeguard queue deref 2021-04-16 11:30:12 +02:00
Thomas Schoebel-Theuer be3ebd11b6 copy: safeguard state table index 2021-04-16 11:30:10 +02:00
Thomas Schoebel-Theuer fff046e1d0 copy: safeguard cursor position 2021-04-16 10:07:55 +02:00