From patchwork Fri Oct 13 05:48:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 10003459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37CBF602B3 for ; Fri, 13 Oct 2017 05:50:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 291ED28FAA for ; Fri, 13 Oct 2017 05:50:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AC7E28FAC; Fri, 13 Oct 2017 05:50:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B47A628FAA for ; Fri, 13 Oct 2017 05:49:58 +0000 (UTC) Received: from localhost ([::1]:48505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2sr6-0000MQ-7F for patchwork-qemu-devel@patchwork.kernel.org; Fri, 13 Oct 2017 01:49:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2sq9-0000LR-28 for qemu-devel@nongnu.org; Fri, 13 Oct 2017 01:48:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2sq5-00033t-Ux for qemu-devel@nongnu.org; Fri, 13 Oct 2017 01:48:57 -0400 Received: from mail.weilnetz.de ([37.120.169.71]:34688 helo=v2201612906741603.powersrv.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2sq5-0002zC-L7 for qemu-devel@nongnu.org; Fri, 13 Oct 2017 01:48:53 -0400 Received: from localhost (localhost [127.0.0.1]) by v2201612906741603.powersrv.de (Postfix) with ESMTP id 3B3CADA8391; Fri, 13 Oct 2017 07:48:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at v2201612906741603.powersrv.de Received: from v2201612906741603.powersrv.de ([127.0.0.1]) by localhost (v2201612906741603.powersrv.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o67r68nk7Tyk; Fri, 13 Oct 2017 07:48:50 +0200 (CEST) Received: from qemu.weilnetz.de (qemu.weilnetz.de [188.68.58.204]) by v2201612906741603.powersrv.de (Postfix) with ESMTP id 9AE46DA8380; Fri, 13 Oct 2017 07:48:50 +0200 (CEST) Received: by qemu.weilnetz.de (Postfix, from userid 1000) id 5F9DB4620BA; Fri, 13 Oct 2017 07:48:50 +0200 (CEST) From: Stefan Weil To: Richard Henderson , qemu-devel@nongnu.org Date: Fri, 13 Oct 2017 07:48:42 +0200 Message-Id: <20171013054842.32120-1-sw@weilnetz.de> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 37.120.169.71 Subject: [Qemu-devel] [PATCH v2] oslib-posix: Fix compiler warning and some data types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Stefan Hajnoczi , Stefan Weil Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP gcc warning: /qemu/util/oslib-posix.c:304:11: error: variable ‘addr’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] Fix also some related data types: numpages, hpagesize are used as pointer offset. Always use size_t for them and for the derived numpages_per_thread. Avoid a type cast by declaring addr volatile. Signed-off-by: Stefan Weil Reviewed-by: Philippe Mathieu-Daudé --- v2: Fix more data types (partially as discussed with Richard) Please note that checkpatch.pl raises an error: ERROR: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt This error is wrong in the current context. It also refers to a file which exists in the Linux sources but not in the QEMU source. Regards Stefan util/oslib-posix.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 80086c549f..beef148c96 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -59,8 +59,8 @@ struct MemsetThread { char *addr; - uint64_t numpages; - uint64_t hpagesize; + size_t numpages; + size_t hpagesize; QemuThread pgthread; sigjmp_buf env; }; @@ -301,11 +301,7 @@ static void sigbus_handler(int signal) static void *do_touch_pages(void *arg) { MemsetThread *memset_args = (MemsetThread *)arg; - char *addr = memset_args->addr; - uint64_t numpages = memset_args->numpages; - uint64_t hpagesize = memset_args->hpagesize; sigset_t set, oldset; - int i = 0; /* unblock SIGBUS */ sigemptyset(&set); @@ -315,6 +311,10 @@ static void *do_touch_pages(void *arg) if (sigsetjmp(memset_args->env, 1)) { memset_thread_failed = true; } else { + volatile char *addr = memset_args->addr; + size_t numpages = memset_args->numpages; + size_t hpagesize = memset_args->hpagesize; + size_t i; for (i = 0; i < numpages; i++) { /* * Read & write back the same value, so we don't @@ -328,7 +328,7 @@ static void *do_touch_pages(void *arg) * don't need to write at all so we don't cause * wear on the storage backing the region... */ - *(volatile char *)addr = *addr; + *addr = *addr; addr += hpagesize; } } @@ -351,7 +351,8 @@ static inline int get_memset_num_threads(int smp_cpus) static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages, int smp_cpus) { - uint64_t numpages_per_thread, size_per_thread; + size_t numpages_per_thread; + size_t size_per_thread; char *addr = area; int i = 0;