All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/6] Coverity patch queue
@ 2022-04-27  4:39 Richard Henderson
  2022-04-27  4:39 ` [PULL 1/6] accel/tcg: Assert mmu_idx in range before use in cputlb Richard Henderson
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel

The following changes since commit a72d9008092e39c2c37e47a91bae4e170d0f1b33:

  Merge tag 'pull-nbd-2022-04-26' of https://repo.or.cz/qemu/ericb into staging (2022-04-26 14:39:09 -0700)

are available in the Git repository at:

  https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20220426

for you to fetch changes up to dee3fcfbb399a0e4ccedbf737b5b0b7f56ecd398:

  softfloat: Use FloatRelation for fracN_cmp (2022-04-26 20:01:55 -0700)

----------------------------------------------------------------
Fix s390x ICMH cc computation.
Minor adjustments to satisfy Coverity.

----------------------------------------------------------------
Richard Henderson (6):
      accel/tcg: Assert mmu_idx in range before use in cputlb
      target/s390x: Fix the accumulation of ccm in op_icm
      target/i386: Suppress coverity warning on fsave/frstor
      softfloat: Fix declaration of partsN_compare
      softfloat: Use FloatRelation within partsN_compare
      softfloat: Use FloatRelation for fracN_cmp

 accel/tcg/cputlb.c           | 40 +++++++++++++++++++++++++++-------------
 fpu/softfloat.c              | 20 +++++++++++---------
 target/i386/tcg/fpu_helper.c |  4 ++--
 target/s390x/tcg/translate.c |  2 +-
 fpu/softfloat-parts.c.inc    | 11 +++++++----
 5 files changed, 48 insertions(+), 29 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PULL 1/6] accel/tcg: Assert mmu_idx in range before use in cputlb
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
@ 2022-04-27  4:39 ` Richard Henderson
  2022-04-27  4:39 ` [PULL 2/6] target/s390x: Fix the accumulation of ccm in op_icm Richard Henderson
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Alex Bennée

Coverity reports out-of-bound accesses within cputlb.c.
This should be a false positive due to how the index is
decoded from MemOpIdx.  To be fair, nothing is checking
the correct bounds during encoding either.

Assert index in range before use, both to catch user errors
and to pacify static analysis.

Fixes: Coverity CID 1487120, 1487127, 1487170, 1487196, 1487215, 1487238
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20220401170813.318609-1-richard.henderson@linaro.org>
---
 accel/tcg/cputlb.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index dd45e0467b..f90f4312ea 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -1761,7 +1761,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
                                MemOpIdx oi, int size, int prot,
                                uintptr_t retaddr)
 {
-    size_t mmu_idx = get_mmuidx(oi);
+    uintptr_t mmu_idx = get_mmuidx(oi);
     MemOp mop = get_memop(oi);
     int a_bits = get_alignment_bits(mop);
     uintptr_t index;
@@ -1769,6 +1769,8 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
     target_ulong tlb_addr;
     void *hostaddr;
 
+    tcg_debug_assert(mmu_idx < NB_MMU_MODES);
+
     /* Adjust the given return address.  */
     retaddr -= GETPC_ADJ;
 
@@ -1908,18 +1910,20 @@ load_helper(CPUArchState *env, target_ulong addr, MemOpIdx oi,
             uintptr_t retaddr, MemOp op, bool code_read,
             FullLoadHelper *full_load)
 {
-    uintptr_t mmu_idx = get_mmuidx(oi);
-    uintptr_t index = tlb_index(env, mmu_idx, addr);
-    CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
-    target_ulong tlb_addr = code_read ? entry->addr_code : entry->addr_read;
     const size_t tlb_off = code_read ?
         offsetof(CPUTLBEntry, addr_code) : offsetof(CPUTLBEntry, addr_read);
     const MMUAccessType access_type =
         code_read ? MMU_INST_FETCH : MMU_DATA_LOAD;
-    unsigned a_bits = get_alignment_bits(get_memop(oi));
+    const unsigned a_bits = get_alignment_bits(get_memop(oi));
+    const size_t size = memop_size(op);
+    uintptr_t mmu_idx = get_mmuidx(oi);
+    uintptr_t index;
+    CPUTLBEntry *entry;
+    target_ulong tlb_addr;
     void *haddr;
     uint64_t res;
-    size_t size = memop_size(op);
+
+    tcg_debug_assert(mmu_idx < NB_MMU_MODES);
 
     /* Handle CPU specific unaligned behaviour */
     if (addr & ((1 << a_bits) - 1)) {
@@ -1927,6 +1931,10 @@ load_helper(CPUArchState *env, target_ulong addr, MemOpIdx oi,
                              mmu_idx, retaddr);
     }
 
+    index = tlb_index(env, mmu_idx, addr);
+    entry = tlb_entry(env, mmu_idx, addr);
+    tlb_addr = code_read ? entry->addr_code : entry->addr_read;
+
     /* If the TLB entry is for a different page, reload and try again.  */
     if (!tlb_hit(tlb_addr, addr)) {
         if (!victim_tlb_hit(env, mmu_idx, index, tlb_off,
@@ -2310,14 +2318,16 @@ static inline void QEMU_ALWAYS_INLINE
 store_helper(CPUArchState *env, target_ulong addr, uint64_t val,
              MemOpIdx oi, uintptr_t retaddr, MemOp op)
 {
-    uintptr_t mmu_idx = get_mmuidx(oi);
-    uintptr_t index = tlb_index(env, mmu_idx, addr);
-    CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
-    target_ulong tlb_addr = tlb_addr_write(entry);
     const size_t tlb_off = offsetof(CPUTLBEntry, addr_write);
-    unsigned a_bits = get_alignment_bits(get_memop(oi));
+    const unsigned a_bits = get_alignment_bits(get_memop(oi));
+    const size_t size = memop_size(op);
+    uintptr_t mmu_idx = get_mmuidx(oi);
+    uintptr_t index;
+    CPUTLBEntry *entry;
+    target_ulong tlb_addr;
     void *haddr;
-    size_t size = memop_size(op);
+
+    tcg_debug_assert(mmu_idx < NB_MMU_MODES);
 
     /* Handle CPU specific unaligned behaviour */
     if (addr & ((1 << a_bits) - 1)) {
@@ -2325,6 +2335,10 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,
                              mmu_idx, retaddr);
     }
 
+    index = tlb_index(env, mmu_idx, addr);
+    entry = tlb_entry(env, mmu_idx, addr);
+    tlb_addr = tlb_addr_write(entry);
+
     /* If the TLB entry is for a different page, reload and try again.  */
     if (!tlb_hit(tlb_addr, addr)) {
         if (!victim_tlb_hit(env, mmu_idx, index, tlb_off,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 2/6] target/s390x: Fix the accumulation of ccm in op_icm
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
  2022-04-27  4:39 ` [PULL 1/6] accel/tcg: Assert mmu_idx in range before use in cputlb Richard Henderson
@ 2022-04-27  4:39 ` Richard Henderson
  2022-04-27  4:39 ` [PULL 3/6] target/i386: Suppress coverity warning on fsave/frstor Richard Henderson
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Huth, David Hildenbrand

Coverity rightly reports that 0xff << pos can overflow.
This would affect the ICMH instruction.

Fixes: Coverity CID 1487161
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220401193659.332079-1-richard.henderson@linaro.org>
---
 target/s390x/tcg/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index ae70368966..8f092dab95 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -2622,7 +2622,7 @@ static DisasJumpType op_icm(DisasContext *s, DisasOps *o)
                 tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
                 tcg_gen_addi_i64(o->in2, o->in2, 1);
                 tcg_gen_deposit_i64(o->out, o->out, tmp, pos, 8);
-                ccm |= 0xff << pos;
+                ccm |= 0xffull << pos;
             }
             m3 = (m3 << 1) & 0xf;
             pos -= 8;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 3/6] target/i386: Suppress coverity warning on fsave/frstor
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
  2022-04-27  4:39 ` [PULL 1/6] accel/tcg: Assert mmu_idx in range before use in cputlb Richard Henderson
  2022-04-27  4:39 ` [PULL 2/6] target/s390x: Fix the accumulation of ccm in op_icm Richard Henderson
@ 2022-04-27  4:39 ` Richard Henderson
  2022-04-27  4:39 ` [PULL 4/6] softfloat: Fix declaration of partsN_compare Richard Henderson
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Damien Hedde

Coverity warns that 14 << data32 may overflow with respect
to the target_ulong to which it is subsequently added.
We know this wasn't true because data32 is in [1,2],
but the suggested fix is perfectly fine.

Fixes: Coverity CID 1487135, 1487256
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Message-Id: <20220401184635.327423-1-richard.henderson@linaro.org>
---
 target/i386/tcg/fpu_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c
index ebf5e73df9..30bc44fcf8 100644
--- a/target/i386/tcg/fpu_helper.c
+++ b/target/i386/tcg/fpu_helper.c
@@ -2466,7 +2466,7 @@ static void do_fsave(CPUX86State *env, target_ulong ptr, int data32,
 
     do_fstenv(env, ptr, data32, retaddr);
 
-    ptr += (14 << data32);
+    ptr += (target_ulong)14 << data32;
     for (i = 0; i < 8; i++) {
         tmp = ST(i);
         do_fstt(env, tmp, ptr, retaddr);
@@ -2488,7 +2488,7 @@ static void do_frstor(CPUX86State *env, target_ulong ptr, int data32,
     int i;
 
     do_fldenv(env, ptr, data32, retaddr);
-    ptr += (14 << data32);
+    ptr += (target_ulong)14 << data32;
 
     for (i = 0; i < 8; i++) {
         tmp = do_fldt(env, ptr, retaddr);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 4/6] softfloat: Fix declaration of partsN_compare
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
                   ` (2 preceding siblings ...)
  2022-04-27  4:39 ` [PULL 3/6] target/i386: Suppress coverity warning on fsave/frstor Richard Henderson
@ 2022-04-27  4:39 ` Richard Henderson
  2022-04-27  4:39 ` [PULL 5/6] softfloat: Use FloatRelation within partsN_compare Richard Henderson
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

The declaration used 'int', while the definition used 'FloatRelation'.
This should have resulted in a compiler error, but mysteriously didn't.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220401132240.79730-2-richard.henderson@linaro.org>
---
 fpu/softfloat.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 5e2cf20448..e7d7ad56bc 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -874,10 +874,10 @@ static FloatParts128 *parts128_minmax(FloatParts128 *a, FloatParts128 *b,
 #define parts_minmax(A, B, S, F) \
     PARTS_GENERIC_64_128(minmax, A)(A, B, S, F)
 
-static int parts64_compare(FloatParts64 *a, FloatParts64 *b,
-                           float_status *s, bool q);
-static int parts128_compare(FloatParts128 *a, FloatParts128 *b,
-                            float_status *s, bool q);
+static FloatRelation parts64_compare(FloatParts64 *a, FloatParts64 *b,
+                                     float_status *s, bool q);
+static FloatRelation parts128_compare(FloatParts128 *a, FloatParts128 *b,
+                                      float_status *s, bool q);
 
 #define parts_compare(A, B, S, Q) \
     PARTS_GENERIC_64_128(compare, A)(A, B, S, Q)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 5/6] softfloat: Use FloatRelation within partsN_compare
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
                   ` (3 preceding siblings ...)
  2022-04-27  4:39 ` [PULL 4/6] softfloat: Fix declaration of partsN_compare Richard Henderson
@ 2022-04-27  4:39 ` Richard Henderson
  2022-04-27  4:39 ` [PULL 6/6] softfloat: Use FloatRelation for fracN_cmp Richard Henderson
  2022-04-27  5:54 ` [PULL 0/6] Coverity patch queue Richard Henderson
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

As the return type is FloatRelation, it's clearer to
use the type for 'cmp' within the function.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220401132240.79730-3-richard.henderson@linaro.org>
---
 fpu/softfloat-parts.c.inc | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
index db3e1f393d..bbeadaa189 100644
--- a/fpu/softfloat-parts.c.inc
+++ b/fpu/softfloat-parts.c.inc
@@ -1327,16 +1327,19 @@ static FloatRelation partsN(compare)(FloatPartsN *a, FloatPartsN *b,
                                      float_status *s, bool is_quiet)
 {
     int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
-    int cmp;
 
     if (likely(ab_mask == float_cmask_normal)) {
+        FloatRelation cmp;
+
         if (a->sign != b->sign) {
             goto a_sign;
         }
-        if (a->exp != b->exp) {
-            cmp = a->exp < b->exp ? -1 : 1;
-        } else {
+        if (a->exp == b->exp) {
             cmp = frac_cmp(a, b);
+        } else if (a->exp < b->exp) {
+            cmp = float_relation_less;
+        } else {
+            cmp = float_relation_greater;
         }
         if (a->sign) {
             cmp = -cmp;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 6/6] softfloat: Use FloatRelation for fracN_cmp
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
                   ` (4 preceding siblings ...)
  2022-04-27  4:39 ` [PULL 5/6] softfloat: Use FloatRelation within partsN_compare Richard Henderson
@ 2022-04-27  4:39 ` Richard Henderson
  2022-04-27  5:54 ` [PULL 0/6] Coverity patch queue Richard Henderson
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  4:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

Since the caller, partsN_compare, is now exclusively
using FloatRelation, it's clearer to use it here too.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220401132240.79730-4-richard.henderson@linaro.org>
---
 fpu/softfloat.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index e7d7ad56bc..4a871ef2a1 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -957,21 +957,23 @@ static void frac128_allones(FloatParts128 *a)
 
 #define frac_allones(A)  FRAC_GENERIC_64_128(allones, A)(A)
 
-static int frac64_cmp(FloatParts64 *a, FloatParts64 *b)
+static FloatRelation frac64_cmp(FloatParts64 *a, FloatParts64 *b)
 {
-    return a->frac == b->frac ? 0 : a->frac < b->frac ? -1 : 1;
+    return (a->frac == b->frac ? float_relation_equal
+            : a->frac < b->frac ? float_relation_less
+            : float_relation_greater);
 }
 
-static int frac128_cmp(FloatParts128 *a, FloatParts128 *b)
+static FloatRelation frac128_cmp(FloatParts128 *a, FloatParts128 *b)
 {
     uint64_t ta = a->frac_hi, tb = b->frac_hi;
     if (ta == tb) {
         ta = a->frac_lo, tb = b->frac_lo;
         if (ta == tb) {
-            return 0;
+            return float_relation_equal;
         }
     }
-    return ta < tb ? -1 : 1;
+    return ta < tb ? float_relation_less : float_relation_greater;
 }
 
 #define frac_cmp(A, B)  FRAC_GENERIC_64_128(cmp, A)(A, B)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PULL 0/6] Coverity patch queue
  2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
                   ` (5 preceding siblings ...)
  2022-04-27  4:39 ` [PULL 6/6] softfloat: Use FloatRelation for fracN_cmp Richard Henderson
@ 2022-04-27  5:54 ` Richard Henderson
  6 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2022-04-27  5:54 UTC (permalink / raw)
  To: qemu-devel

On 4/26/22 21:39, Richard Henderson wrote:
> The following changes since commit a72d9008092e39c2c37e47a91bae4e170d0f1b33:
> 
>    Merge tag 'pull-nbd-2022-04-26' of https://repo.or.cz/qemu/ericb into staging (2022-04-26 14:39:09 -0700)
> 
> are available in the Git repository at:
> 
>    https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20220426
> 
> for you to fetch changes up to dee3fcfbb399a0e4ccedbf737b5b0b7f56ecd398:
> 
>    softfloat: Use FloatRelation for fracN_cmp (2022-04-26 20:01:55 -0700)
> 
> ----------------------------------------------------------------
> Fix s390x ICMH cc computation.
> Minor adjustments to satisfy Coverity.

Applied, thanks.  Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.


r~



> 
> ----------------------------------------------------------------
> Richard Henderson (6):
>        accel/tcg: Assert mmu_idx in range before use in cputlb
>        target/s390x: Fix the accumulation of ccm in op_icm
>        target/i386: Suppress coverity warning on fsave/frstor
>        softfloat: Fix declaration of partsN_compare
>        softfloat: Use FloatRelation within partsN_compare
>        softfloat: Use FloatRelation for fracN_cmp
> 
>   accel/tcg/cputlb.c           | 40 +++++++++++++++++++++++++++-------------
>   fpu/softfloat.c              | 20 +++++++++++---------
>   target/i386/tcg/fpu_helper.c |  4 ++--
>   target/s390x/tcg/translate.c |  2 +-
>   fpu/softfloat-parts.c.inc    | 11 +++++++----
>   5 files changed, 48 insertions(+), 29 deletions(-)



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-27  5:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27  4:39 [PULL 0/6] Coverity patch queue Richard Henderson
2022-04-27  4:39 ` [PULL 1/6] accel/tcg: Assert mmu_idx in range before use in cputlb Richard Henderson
2022-04-27  4:39 ` [PULL 2/6] target/s390x: Fix the accumulation of ccm in op_icm Richard Henderson
2022-04-27  4:39 ` [PULL 3/6] target/i386: Suppress coverity warning on fsave/frstor Richard Henderson
2022-04-27  4:39 ` [PULL 4/6] softfloat: Fix declaration of partsN_compare Richard Henderson
2022-04-27  4:39 ` [PULL 5/6] softfloat: Use FloatRelation within partsN_compare Richard Henderson
2022-04-27  4:39 ` [PULL 6/6] softfloat: Use FloatRelation for fracN_cmp Richard Henderson
2022-04-27  5:54 ` [PULL 0/6] Coverity patch queue Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.