From patchwork Fri Mar 29 11:10:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E256F14DE for ; Fri, 29 Mar 2019 11:12:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD59B28DD9 for ; Fri, 29 Mar 2019 11:12:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0BE62900C; Fri, 29 Mar 2019 11:12:53 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6091928DD9 for ; Fri, 29 Mar 2019 11:12:53 +0000 (UTC) Received: from localhost ([127.0.0.1]:50853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pRL-0004Wk-LV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:12:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQ5-0003PS-Ue for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQ1-000609-Bj for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40006) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pPz-0005K6-JF; Fri, 29 Mar 2019 07:11:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F4E1307D848; Fri, 29 Mar 2019 11:11:22 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id E44E465F45; Fri, 29 Mar 2019 11:11:19 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:51 +0000 Message-Id: <20190329111104.17223-2-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 29 Mar 2019 11:11:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/14] target/xtensa: fix break_dependency for repeated resources 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Max Filippov break_dependency incorrectly handles the case of dependency on an opcode that references the same register multiple times. E.g. the following instruction is translated incorrectly: { or a2, a3, a3 ; or a3, a2, a2 } This happens because resource indices of both dependency graph nodes are incremented, and a copy for the second instance of the same register in the ending node is not done. Only increment resource index of the ending node of the dependency. Add test. Signed-off-by: Max Filippov --- target/xtensa/translate.c | 1 - tests/tcg/xtensa/test_flix.S | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 77bc04d6b0..65561d2c49 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1041,7 +1041,6 @@ static bool break_dependency(struct slot_prop *a, copy[n].resource = b->in[j].resource; copy[n].arg = b->arg + index; ++n; - ++i; ++j; rv = true; } diff --git a/tests/tcg/xtensa/test_flix.S b/tests/tcg/xtensa/test_flix.S index 7c259e7018..7af06b2b88 100644 --- a/tests/tcg/xtensa/test_flix.S +++ b/tests/tcg/xtensa/test_flix.S @@ -55,6 +55,23 @@ test sum .previous test_end +test rep_dependency + + { + movi a2, 1 + movi a3, 2 + nop + } + { + or a2, a3, a3 + or a3, a2, a2 + nop + } + assert eqi, a2, 2 + assert eqi, a3, 1 + +test_end + #endif test_suite_end From patchwork Fri Mar 29 11:10:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B27121708 for ; Fri, 29 Mar 2019 11:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B49428DD9 for ; Fri, 29 Mar 2019 11:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F5222900C; Fri, 29 Mar 2019 11:13:50 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 41D6628DD9 for ; Fri, 29 Mar 2019 11:13:50 +0000 (UTC) Received: from localhost ([127.0.0.1]:50855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pSF-0005J1-LE for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:13:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQ6-0003Pu-V0 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQ3-0006Eb-Bg for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30717) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQ3-0005bB-3N; Fri, 29 Mar 2019 07:11:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CA765D688; Fri, 29 Mar 2019 11:11:25 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B48560BFB; Fri, 29 Mar 2019 11:11:22 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:52 +0000 Message-Id: <20190329111104.17223-3-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 29 Mar 2019 11:11:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/14] target/xtensa: don't announce exit simcall 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Richard Henderson , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Max Filippov Don't announce that exit simcall has been invoked: this is just noise. Reviewed-by: Richard Henderson Signed-off-by: Max Filippov --- target/xtensa/xtensa-semi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 2f76216276..5f5ce4f344 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -202,7 +202,6 @@ void HELPER(simcall)(CPUXtensaState *env) switch (regs[2]) { case TARGET_SYS_exit: - qemu_log("exit(%d) simcall\n", regs[3]); exit(regs[3]); break; From patchwork Fri Mar 29 11:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87BA01390 for ; Fri, 29 Mar 2019 11:15:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E22E28A95 for ; Fri, 29 Mar 2019 11:15:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D61228ACE; Fri, 29 Mar 2019 11:15:08 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CEFF328A95 for ; Fri, 29 Mar 2019 11:15:07 +0000 (UTC) Received: from localhost ([127.0.0.1]:50890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pTW-0006Zu-4e for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:15:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQG-0003WS-8u for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQD-0007G2-Bq for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQ8-0005yc-5j; Fri, 29 Mar 2019 07:11:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4EDD83F51; Fri, 29 Mar 2019 11:11:28 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D45260BFB; Fri, 29 Mar 2019 11:11:25 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:53 +0000 Message-Id: <20190329111104.17223-4-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 29 Mar 2019 11:11:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/14] tests/tcg/xtensa: clean up test set 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Max Filippov Drop test_fail: we know that exit simcall works. Now that it's not run automatically there's no point in keeping it. Drop test_pipeline: we're not modeling pipeline, we don't control ccount and there's no plan to do so. Enable test_boolean: it won't break on cores without boolean option, it will do testing on cores with boolean option. Signed-off-by: Max Filippov --- tests/tcg/xtensa/Makefile.softmmu-target | 2 +- tests/tcg/xtensa/test_fail.S | 9 -- tests/tcg/xtensa/test_pipeline.S | 157 ----------------------- 3 files changed, 1 insertion(+), 167 deletions(-) delete mode 100644 tests/tcg/xtensa/test_fail.S delete mode 100644 tests/tcg/xtensa/test_pipeline.S diff --git a/tests/tcg/xtensa/Makefile.softmmu-target b/tests/tcg/xtensa/Makefile.softmmu-target index 86bb47db77..8212d96b81 100644 --- a/tests/tcg/xtensa/Makefile.softmmu-target +++ b/tests/tcg/xtensa/Makefile.softmmu-target @@ -8,7 +8,7 @@ XTENSA_SRC = $(SRC_PATH)/tests/tcg/xtensa XTENSA_ALL = $(filter-out $(XTENSA_SRC)/linker.ld.S,$(wildcard $(XTENSA_SRC)/*.S)) XTENSA_TESTS = $(patsubst $(XTENSA_SRC)/%.S, %, $(XTENSA_ALL)) # Filter out common blobs and broken tests -XTENSA_BROKEN_TESTS = crt vectors test_boolean test_pipeline test_fail +XTENSA_BROKEN_TESTS = crt vectors XTENSA_USABLE_TESTS = $(filter-out $(XTENSA_BROKEN_TESTS), $(XTENSA_TESTS)) # add to the list of tests diff --git a/tests/tcg/xtensa/test_fail.S b/tests/tcg/xtensa/test_fail.S deleted file mode 100644 index 1c26d50790..0000000000 --- a/tests/tcg/xtensa/test_fail.S +++ /dev/null @@ -1,9 +0,0 @@ -#include "macros.inc" - -test_suite fail - -test fail - test_fail -test_end - -test_suite_end diff --git a/tests/tcg/xtensa/test_pipeline.S b/tests/tcg/xtensa/test_pipeline.S deleted file mode 100644 index f418c11974..0000000000 --- a/tests/tcg/xtensa/test_pipeline.S +++ /dev/null @@ -1,157 +0,0 @@ -#include "macros.inc" - -.purgem test -.macro test name - movi a2, 1f - movi a3, 99f -0: - ipf a2, 0 - ipf a2, 4 - ipf a2, 8 - ipf a2, 12 - addi a2, a2, 16 - blt a2, a3, 0b - j 1f - .align 4 -1: -.endm - -test_suite pipeline - -test register_no_stall - rsr a3, ccount - add a5, a6, a6 - add a6, a5, a5 - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 3 -test_end - -test register_stall - l32i a5, a1, 0 /* data cache preload */ - nop - rsr a3, ccount - l32i a5, a1, 0 - add a6, a5, a5 /* M-to-E interlock */ - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 4 -test_end - -test j0_stall - rsr a3, ccount - j 1f /* E + 2-cycle penalty */ -1: - rsr a4, ccount /* E */ - sub a3, a4, a3 - assert eqi, a3, 4 -test_end - -test j1_stall - rsr a3, ccount - j 1f - nop -1: - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 4 -test_end - -test j5_stall - rsr a3, ccount - j 1f - nop - nop - nop - nop - nop -1: - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 4 -test_end - -test b_no_stall - movi a5, 1 - rsr a3, ccount - beqi a5, 2, 1f - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 2 -1: -test_end - -test b1_stall - movi a5, 1 - rsr a3, ccount - beqi a5, 1, 1f - nop -1: - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 4 -test_end - -test b5_stall - movi a5, 1 - rsr a3, ccount - beqi a5, 1, 1f - nop - nop - nop - nop - nop -1: - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 4 -test_end - -/* PS *SYNC */ - -test ps_dsync - rsr a5, ps - isync - rsr a3, ccount - wsr a5, ps - dsync - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 5 -test_end - -test ps_esync - rsr a5, ps - isync - rsr a3, ccount - wsr a5, ps - esync - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 5 -test_end - -test ps_rsync - rsr a5, ps - isync - rsr a3, ccount - wsr a5, ps - rsync - rsr a4, ccount - sub a3, a4, a3 - assert eqi, a3, 5 -test_end - -test ps_isync - rsr a5, ps - isync - rsr a3, ccount - wsr a5, ps - isync - rsr a4, ccount - sub a3, a4, a3 - movi a4, 9 - assert eq, a3, a4 -test_end - -test_suite_end From patchwork Fri Mar 29 11:10:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73DFF1390 for ; Fri, 29 Mar 2019 11:16:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F00D28A95 for ; Fri, 29 Mar 2019 11:16:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5173128ACE; Fri, 29 Mar 2019 11:16:06 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 41A9328A95 for ; Fri, 29 Mar 2019 11:16:05 +0000 (UTC) Received: from localhost ([127.0.0.1]:50919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pUS-0007jl-GC for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:16:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQP-0003fj-0O for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQI-0007lU-Kd for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQG-00078V-CZ; Fri, 29 Mar 2019 07:11:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEF80C0B6178; Fri, 29 Mar 2019 11:11:39 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D4C460BFB; Fri, 29 Mar 2019 11:11:29 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:54 +0000 Message-Id: <20190329111104.17223-5-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 29 Mar 2019 11:11:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/14] linux-user: avoid string truncation warnings in uname field copying 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In file included from /usr/include/string.h:494, from include/qemu/osdep.h:101, from linux-user/uname.c:20: In function ‘strncpy’, inlined from ‘sys_uname’ at linux-user/uname.c:94:3: /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We don't care where the NUL terminator in the original uname field was. It suffices to copy the entire original field and simply force a NUL terminator at the end of the new field. Signed-off-by: Daniel P. Berrangé --- linux-user/uname.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/uname.c b/linux-user/uname.c index 313b79dbad..3dff33effe 100644 --- a/linux-user/uname.c +++ b/linux-user/uname.c @@ -73,7 +73,7 @@ const char *cpu_to_uname_machine(void *cpu_env) #define COPY_UTSNAME_FIELD(dest, src) \ do { \ /* __NEW_UTS_LEN doesn't include terminating null */ \ - (void) strncpy((dest), (src), __NEW_UTS_LEN); \ + memcpy((dest), (src), MIN(sizeof(src), __NEW_UTS_LEN)); \ (dest)[__NEW_UTS_LEN] = '\0'; \ } while (0) From patchwork Fri Mar 29 11:10:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C081B1390 for ; Fri, 29 Mar 2019 11:17:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACA2728A95 for ; Fri, 29 Mar 2019 11:17:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0D7B28ACE; Fri, 29 Mar 2019 11:17:30 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4EF2F28A95 for ; Fri, 29 Mar 2019 11:17:30 +0000 (UTC) Received: from localhost ([127.0.0.1]:50935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pVp-0000qQ-Io for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:17:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQV-0003me-T7 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQO-0008KB-Pc for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQN-0007ai-1B; Fri, 29 Mar 2019 07:11:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 988AF3689B; Fri, 29 Mar 2019 11:11:44 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31D9D60BFB; Fri, 29 Mar 2019 11:11:40 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:55 +0000 Message-Id: <20190329111104.17223-6-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 29 Mar 2019 11:11:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/14] linux-user: avoid string truncation warnings in elf field copying 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In file included from /usr/include/string.h:494, from include/qemu/osdep.h:101, from linux-user/elfload.c:2: In function ‘strncpy’, inlined from ‘fill_psinfo’ at linux-user/elfload.c:3208:12, inlined from ‘fill_note_info’ at linux-user/elfload.c:3390:5, inlined from ‘elf_core_dump’ at linux-user/elfload.c:3539:9: /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We don't require the field to be NUL terminated, so can just copy the lower of the string length and the target field size using memcpy. Signed-off-by: Daniel P. Berrangé --- linux-user/elfload.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c1a26021f8..caa060f7b7 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3180,6 +3180,7 @@ static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts) { char *base_filename; unsigned int i, len; + size_t pathlen; (void) memset(psinfo, 0, sizeof (*psinfo)); @@ -3201,12 +3202,9 @@ static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts) psinfo->pr_gid = getgid(); base_filename = g_path_get_basename(ts->bprm->filename); - /* - * Using strncpy here is fine: at max-length, - * this field is not NUL-terminated. - */ - (void) strncpy(psinfo->pr_fname, base_filename, - sizeof(psinfo->pr_fname)); + pathlen = strlen(base_filename) + 1; + pathlen = MIN(pathlen, sizeof(psinfo->pr_fname)); + memcpy(psinfo->pr_fname, base_filename, pathlen); g_free(base_filename); bswap_psinfo(psinfo); From patchwork Fri Mar 29 11:10:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B972D1390 for ; Fri, 29 Mar 2019 11:18:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4D3B28ACE for ; Fri, 29 Mar 2019 11:18:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97B3C29006; Fri, 29 Mar 2019 11:18:36 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 30B1228ACE for ; Fri, 29 Mar 2019 11:18:36 +0000 (UTC) Received: from localhost ([127.0.0.1]:50939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pWt-0001pn-8k for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:18:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQV-0003m0-7Z for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQO-0008LE-UA for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:11:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQN-0007rB-Tv; Fri, 29 Mar 2019 07:11:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 442D13087BAD; Fri, 29 Mar 2019 11:11:47 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA7F160BFB; Fri, 29 Mar 2019 11:11:44 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:56 +0000 Message-Id: <20190329111104.17223-7-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 29 Mar 2019 11:11:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/14] sockets: avoid string truncation warnings when copying UNIX path 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In file included from /usr/include/string.h:494, from include/qemu/osdep.h:101, from util/qemu-sockets.c:18: In function ‘strncpy’, inlined from ‘unix_connect_saddr.isra.0’ at util/qemu-sockets.c:925:5: /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 108 equals destination size [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘strncpy’, inlined from ‘unix_listen_saddr.isra.0’ at util/qemu-sockets.c:880:5: /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 108 equals destination size [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We are already validating the UNIX socket path length earlier in the functions. If we save this string length when we first check it, then we can simply use memcpy instead of strcpy later, avoiding the gcc truncation warnings. Signed-off-by: Daniel P. Berrangé --- util/qemu-sockets.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 9705051690..ba6335e71a 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -830,6 +830,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, int sock, fd; char *pathbuf = NULL; const char *path; + size_t pathlen; sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -845,7 +846,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX", tmpdir); } - if (strlen(path) > sizeof(un.sun_path)) { + pathlen = strlen(path); + if (pathlen > sizeof(un.sun_path)) { error_setg(errp, "UNIX socket path '%s' is too long", path); error_append_hint(errp, "Path must be less than %zu bytes\n", sizeof(un.sun_path)); @@ -877,7 +879,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, memset(&un, 0, sizeof(un)); un.sun_family = AF_UNIX; - strncpy(un.sun_path, path, sizeof(un.sun_path)); + memcpy(un.sun_path, path, pathlen); if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { error_setg_errno(errp, errno, "Failed to bind socket to %s", path); @@ -901,6 +903,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) { struct sockaddr_un un; int sock, rc; + size_t pathlen; if (saddr->path == NULL) { error_setg(errp, "unix connect: no path specified"); @@ -913,7 +916,8 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) return -1; } - if (strlen(saddr->path) > sizeof(un.sun_path)) { + pathlen = strlen(saddr->path); + if (pathlen > sizeof(un.sun_path)) { error_setg(errp, "UNIX socket path '%s' is too long", saddr->path); error_append_hint(errp, "Path must be less than %zu bytes\n", sizeof(un.sun_path)); @@ -922,7 +926,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) memset(&un, 0, sizeof(un)); un.sun_family = AF_UNIX; - strncpy(un.sun_path, saddr->path, sizeof(un.sun_path)); + memcpy(un.sun_path, saddr->path, pathlen); /* connect to peer */ do { From patchwork Fri Mar 29 11:10:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63D3A1708 for ; Fri, 29 Mar 2019 11:15:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50D3928A95 for ; Fri, 29 Mar 2019 11:15:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 449C528ACE; Fri, 29 Mar 2019 11:15:10 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E76CB28A95 for ; Fri, 29 Mar 2019 11:15:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:50894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pTZ-0006bZ-5K for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:15:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQc-0003uA-BI for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQa-0000ve-DZ for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQa-0000VV-50; Fri, 29 Mar 2019 07:12:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F2B830718E1; Fri, 29 Mar 2019 11:11:59 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FD1460BFB; Fri, 29 Mar 2019 11:11:47 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:57 +0000 Message-Id: <20190329111104.17223-8-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 29 Mar 2019 11:11:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/14] hw/usb: avoid format truncation warning when formatting port name 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP hw/usb/hcd-xhci.c: In function ‘usb_xhci_realize’: hw/usb/hcd-xhci.c:3339:66: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 5 [-Wformat-trunca\ tion=] 3339 | snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1); | ^~ hw/usb/hcd-xhci.c:3339:54: note: directive argument in the range [1, 2147483647] 3339 | snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1); | ^~~~~~~~~~~~~~~ The xhci code formats the port name into a fixed length buffer which is only large enough to hold port numbers upto 5 digits in decimal representation. We're never going to have a port number that large, so aserting the port number is sensible is sufficient to tell GCC the formatted string won't be truncated. Signed-off-by: Daniel P. Berrangé --- hw/usb/hcd-xhci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index ec28bee319..7222f9b1af 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3336,6 +3336,7 @@ static void usb_xhci_init(XHCIState *xhci) USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL | USB_SPEED_MASK_HIGH; + assert(i < MAXPORTS); snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1); speedmask |= port->speedmask; } @@ -3349,6 +3350,7 @@ static void usb_xhci_init(XHCIState *xhci) } port->uport = &xhci->uports[i]; port->speedmask = USB_SPEED_MASK_SUPER; + assert(i < MAXPORTS); snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1); speedmask |= port->speedmask; } From patchwork Fri Mar 29 11:10:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7A8318A6 for ; Fri, 29 Mar 2019 11:20:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C308E2900C for ; Fri, 29 Mar 2019 11:20:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0BBF29014; Fri, 29 Mar 2019 11:20: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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F60C29027 for ; Fri, 29 Mar 2019 11:20:00 +0000 (UTC) Received: from localhost ([127.0.0.1]:50959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pYF-0003d9-IT for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:19:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQi-0003xH-Cm for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQf-0001LH-7X for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39182) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQe-0000k9-TH; Fri, 29 Mar 2019 07:12:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AF093168905; Fri, 29 Mar 2019 11:12:02 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9ABA160BFB; Fri, 29 Mar 2019 11:11:59 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:58 +0000 Message-Id: <20190329111104.17223-9-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 29 Mar 2019 11:12:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/14] qxl: avoid unaligned pointer reads/writes 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The SPICE_RING_PROD_ITEM() macro is initializing a local 'uint64_t *' variable to point to the 'el' field inside the QXLReleaseRing struct. This uint64_t field is not guaranteed aligned as the struct is packed. Code should not take the address of fields within a packed struct. Changing the SPICE_RING_PROD_ITEM() macro to avoid taking the address of the field is impractical. It is clearer to just remove the macro and inline its functionality in the three call sites that need it. Signed-off-by: Daniel P. Berrangé --- hw/display/qxl.c | 55 +++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index c8ce5781e0..5c38e6e906 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -33,24 +33,6 @@ #include "qxl.h" -/* - * NOTE: SPICE_RING_PROD_ITEM accesses memory on the pci bar and as - * such can be changed by the guest, so to avoid a guest trigerrable - * abort we just qxl_set_guest_bug and set the return to NULL. Still - * it may happen as a result of emulator bug as well. - */ -#undef SPICE_RING_PROD_ITEM -#define SPICE_RING_PROD_ITEM(qxl, r, ret) { \ - uint32_t prod = (r)->prod & SPICE_RING_INDEX_MASK(r); \ - if (prod >= ARRAY_SIZE((r)->items)) { \ - qxl_set_guest_bug(qxl, "SPICE_RING_PROD_ITEM indices mismatch " \ - "%u >= %zu", prod, ARRAY_SIZE((r)->items)); \ - ret = NULL; \ - } else { \ - ret = &(r)->items[prod].el; \ - } \ - } - #undef SPICE_RING_CONS_ITEM #define SPICE_RING_CONS_ITEM(qxl, r, ret) { \ uint32_t cons = (r)->cons & SPICE_RING_INDEX_MASK(r); \ @@ -414,7 +396,8 @@ static void init_qxl_rom(PCIQXLDevice *d) static void init_qxl_ram(PCIQXLDevice *d) { uint8_t *buf; - uint64_t *item; + uint32_t prod; + QXLReleaseRing *ring; buf = d->vga.vram_ptr; d->ram = (QXLRam *)(buf + le32_to_cpu(d->shadow_rom.ram_header_offset)); @@ -426,9 +409,12 @@ static void init_qxl_ram(PCIQXLDevice *d) SPICE_RING_INIT(&d->ram->cmd_ring); SPICE_RING_INIT(&d->ram->cursor_ring); SPICE_RING_INIT(&d->ram->release_ring); - SPICE_RING_PROD_ITEM(d, &d->ram->release_ring, item); - assert(item); - *item = 0; + + ring = &d->ram->release_ring; + prod = ring->prod & SPICE_RING_INDEX_MASK(ring); + assert(prod < ARRAY_SIZE(ring->items)); + ring->items[prod].el = 0; + qxl_ring_set_dirty(d); } @@ -732,7 +718,7 @@ static int interface_req_cmd_notification(QXLInstance *sin) static inline void qxl_push_free_res(PCIQXLDevice *d, int flush) { QXLReleaseRing *ring = &d->ram->release_ring; - uint64_t *item; + uint32_t prod; int notify; #define QXL_FREE_BUNCH_SIZE 32 @@ -759,11 +745,15 @@ static inline void qxl_push_free_res(PCIQXLDevice *d, int flush) if (notify) { qxl_send_events(d, QXL_INTERRUPT_DISPLAY); } - SPICE_RING_PROD_ITEM(d, ring, item); - if (!item) { + + ring = &d->ram->release_ring; + prod = ring->prod & SPICE_RING_INDEX_MASK(ring); + if (prod >= ARRAY_SIZE(ring->items)) { + qxl_set_guest_bug(d, "SPICE_RING_PROD_ITEM indices mismatch " + "%u >= %zu", prod, ARRAY_SIZE(ring->items)); return; } - *item = 0; + ring->items[prod].el = 0; d->num_free_res = 0; d->last_release = NULL; qxl_ring_set_dirty(d); @@ -775,7 +765,8 @@ static void interface_release_resource(QXLInstance *sin, { PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl); QXLReleaseRing *ring; - uint64_t *item, id; + uint32_t prod; + uint64_t id; if (ext.group_id == MEMSLOT_GROUP_HOST) { /* host group -> vga mode update request */ @@ -792,16 +783,18 @@ static void interface_release_resource(QXLInstance *sin, * pci bar 0, $command.release_info */ ring = &qxl->ram->release_ring; - SPICE_RING_PROD_ITEM(qxl, ring, item); - if (!item) { + prod = ring->prod & SPICE_RING_INDEX_MASK(ring); + if (prod >= ARRAY_SIZE(ring->items)) { + qxl_set_guest_bug(qxl, "SPICE_RING_PROD_ITEM indices mismatch " + "%u >= %zu", prod, ARRAY_SIZE(ring->items)); return; } - if (*item == 0) { + if (ring->items[prod].el == 0) { /* stick head into the ring */ id = ext.info->id; ext.info->next = 0; qxl_ram_set_dirty(qxl, &ext.info->next); - *item = id; + ring->items[prod].el = id; qxl_ring_set_dirty(qxl); } else { /* append item to the list */ From patchwork Fri Mar 29 11:10:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 094721390 for ; Fri, 29 Mar 2019 11:17:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E965328A95 for ; Fri, 29 Mar 2019 11:17:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD2A628ACE; Fri, 29 Mar 2019 11:17:32 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9543328A95 for ; Fri, 29 Mar 2019 11:17:32 +0000 (UTC) Received: from localhost ([127.0.0.1]:50937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pVr-0000s0-U1 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:17:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQg-0003vy-LJ for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQd-0001DW-Qo for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQd-0000zU-Iq; Fri, 29 Mar 2019 07:12:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAFCDC07EFE0; Fri, 29 Mar 2019 11:12:04 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57B2660BFB; Fri, 29 Mar 2019 11:12:02 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:10:59 +0000 Message-Id: <20190329111104.17223-10-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 29 Mar 2019 11:12:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/14] usb-mtp: fix string length for filename when writing metadata 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The ObjectInfo 'length' field provides the length of the wide character string filename. This is then converted to a multi-byte character string. This may have a different byte count to the wide character string. We should use the C string length of the multi-byte string instead. Signed-off-by: Daniel P. Berrangé --- hw/usb/dev-mtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 06e376bcd2..5343449663 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1718,7 +1718,7 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen) return; } - o = usb_mtp_object_lookup_name(p, filename, dataset->length); + o = usb_mtp_object_lookup_name(p, filename, -1); if (o != NULL) { next_handle = o->handle; } From patchwork Fri Mar 29 11:11:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01DDE13B5 for ; Fri, 29 Mar 2019 11:22:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E374728FD2 for ; Fri, 29 Mar 2019 11:22:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7B3729160; Fri, 29 Mar 2019 11:22:24 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B32C28FD2 for ; Fri, 29 Mar 2019 11:22:24 +0000 (UTC) Received: from localhost ([127.0.0.1]:51017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9paZ-0005U9-Kz for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:22:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQj-0003yV-GP for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQf-0001N2-JX for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44962) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQf-0001DI-9Q; Fri, 29 Mar 2019 07:12:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 809E086673; Fri, 29 Mar 2019 11:12:07 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 131E760BFB; Fri, 29 Mar 2019 11:12:04 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:11:00 +0000 Message-Id: <20190329111104.17223-11-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Mar 2019 11:12:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/14] usb-mtp: avoid warning about unaligned access to filename 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The 'filename' field in ObjectInfo struct is declared as a zero length array of uint16_t. Accessing it is equivalent to taking the address of the field, and taking the address of fields in a packed struct causes unaligned pointer warnings: hw/usb/dev-mtp.c: In function ‘usb_mtp_write_metadata’: hw/usb/dev-mtp.c:1712:36: warning: taking address of packed member of ‘struct ’ may result in an unaligned pointer value [-Waddress-of-packed-member] 1712 | dataset->filename); | ~~~~~~~^~~~~~~~~~ The warning is in fact correct because the 'filename' field is preceeded by a uint8_t field which causes it to have bad alignment. Using pointer arithmetic instead of accessing the zero length array field directly avoids the compiler warning but doesn't ultimately fix the bad alignment. Fixing that probably requires allocating a new array of uint16_t in the heap & then memcpy() the data before accessing the array elements. Signed-off-by: Daniel P. Berrangé --- hw/usb/dev-mtp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 5343449663..9ddcfbe7a6 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -225,7 +225,7 @@ typedef struct { uint16_t assoc_type; uint32_t assoc_desc; uint32_t seq_no; /*unused*/ - uint8_t length; /*part of filename field*/ + uint8_t length; /*length of filename field*/ uint16_t filename[0]; char date_created[0]; /*unused*/ char date_modified[0]; /*unused*/ @@ -1703,13 +1703,15 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen) MTPObject *o; MTPObject *p = usb_mtp_object_lookup(s, s->dataset.parent_handle); uint32_t next_handle = s->next_handle; + uint16_t *wfilename = (uint16_t *)(d->data + + offsetof(ObjectInfo, filename)); assert(!s->write_pending); assert(p != NULL); filename = utf16_to_str(MIN(dataset->length, dlen - offsetof(ObjectInfo, filename)), - dataset->filename); + wfilename); if (strchr(filename, '/')) { usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans, From patchwork Fri Mar 29 11:11:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCD9818A6 for ; Fri, 29 Mar 2019 11:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A58E029011 for ; Fri, 29 Mar 2019 11:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99E5D29013; Fri, 29 Mar 2019 11:19:56 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 06C5328FE8 for ; Fri, 29 Mar 2019 11:19:56 +0000 (UTC) Received: from localhost ([127.0.0.1]:50957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pYB-0003YT-6S for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:19:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQo-00043f-N0 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQl-0001tp-F1 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQl-0001eW-5F; Fri, 29 Mar 2019 07:12:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67772307D914; Fri, 29 Mar 2019 11:12:12 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC09D60BFB; Fri, 29 Mar 2019 11:12:07 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:11:01 +0000 Message-Id: <20190329111104.17223-12-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 29 Mar 2019 11:12:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/14] hw/vfio/ccw: avoid taking address members in packed structs 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The GCC 9 compiler complains about many places in s390 code that take the address of members of the 'struct SCHIB' which is marked packed: hw/vfio/ccw.c: In function ‘vfio_ccw_io_notifier_handler’: hw/vfio/ccw.c:133:15: warning: taking address of packed member of ‘struct SCHIB’ may result in an unaligned pointer value \ [-Waddress-of-packed-member] 133 | SCSW *s = &sch->curr_status.scsw; | ^~~~~~~~~~~~~~~~~~~~~~ hw/vfio/ccw.c:134:15: warning: taking address of packed member of ‘struct SCHIB’ may result in an unaligned pointer value \ [-Waddress-of-packed-member] 134 | PMCW *p = &sch->curr_status.pmcw; | ^~~~~~~~~~~~~~~~~~~~~~ ...snip many more... Almost all of these are just done for convenience to avoid typing out long variable/field names when referencing struct members. We can get most of this convenience by taking the address of the 'struct SCHIB' instead, avoiding triggering the compiler warnings. In a couple of places we copy via a local variable which is a technique already applied elsewhere in s390 code for this problem. Signed-off-by: Daniel P. Berrangé Reviewed-by: Eric Farman Reviewed-by: Halil Pasic Reviewed-by: Farhan Ali --- hw/vfio/ccw.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 9246729a75..c44d13cc50 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -130,8 +130,8 @@ static void vfio_ccw_io_notifier_handler(void *opaque) S390CCWDevice *cdev = S390_CCW_DEVICE(vcdev); CcwDevice *ccw_dev = CCW_DEVICE(cdev); SubchDev *sch = ccw_dev->sch; - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; + SCSW s; IRB irb; int size; @@ -145,33 +145,33 @@ static void vfio_ccw_io_notifier_handler(void *opaque) switch (errno) { case ENODEV: /* Generate a deferred cc 3 condition. */ - s->flags |= SCSW_FLAGS_MASK_CC; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND); + schib->scsw.flags |= SCSW_FLAGS_MASK_CC; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND); goto read_err; case EFAULT: /* Memory problem, generate channel data check. */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->cstat = SCSW_CSTAT_DATA_CHECK; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.cstat = SCSW_CSTAT_DATA_CHECK; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; goto read_err; default: /* Error, generate channel program check. */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->cstat = SCSW_CSTAT_PROG_CHECK; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.cstat = SCSW_CSTAT_PROG_CHECK; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; goto read_err; } } else if (size != vcdev->io_region_size) { /* Information transfer error, generate channel-control check. */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->cstat = SCSW_CSTAT_CHN_CTRL_CHK; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.cstat = SCSW_CSTAT_CHN_CTRL_CHK; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; goto read_err; } @@ -179,11 +179,13 @@ static void vfio_ccw_io_notifier_handler(void *opaque) memcpy(&irb, region->irb_area, sizeof(IRB)); /* Update control block via irb. */ - copy_scsw_to_guest(s, &irb.scsw); + s = schib->scsw; + copy_scsw_to_guest(&s, &irb.scsw); + schib->scsw = s; /* If a uint check is pending, copy sense data. */ - if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) && - (p->chars & PMCW_CHARS_MASK_CSENSE)) { + if ((schib->scsw.dstat & SCSW_DSTAT_UNIT_CHECK) && + (schib->pmcw.chars & PMCW_CHARS_MASK_CSENSE)) { memcpy(sch->sense_data, irb.ecw, sizeof(irb.ecw)); } From patchwork Fri Mar 29 11:11:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D98E13B5 for ; Fri, 29 Mar 2019 11:24:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F339728DF6 for ; Fri, 29 Mar 2019 11:24:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E398A28BE2; Fri, 29 Mar 2019 11:24:48 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48DD328BE2 for ; Fri, 29 Mar 2019 11:24:47 +0000 (UTC) Received: from localhost ([127.0.0.1]:51047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pcs-0007ID-Cu for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:24:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQz-0004DG-S9 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQt-0002gs-K1 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50244) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQt-0002K5-7j; Fri, 29 Mar 2019 07:12:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74B2185528; Fri, 29 Mar 2019 11:12:19 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id A444860BFB; Fri, 29 Mar 2019 11:12:12 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:11:02 +0000 Message-Id: <20190329111104.17223-13-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 29 Mar 2019 11:12:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/14] hw/s390/css: avoid taking address members in packed structs 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The GCC 9 compiler complains about many places in s390 code that take the address of members of the 'struct SCHIB' which is marked packed: hw/s390x/css.c: In function ‘sch_handle_clear_func’: hw/s390x/css.c:698:15: warning: taking address of packed member of ‘struct SCHIB’ may result in an unaligned pointer val\ ue [-Waddress-of-packed-member] 698 | PMCW *p = &sch->curr_status.pmcw; | ^~~~~~~~~~~~~~~~~~~~~~ hw/s390x/css.c:699:15: warning: taking address of packed member of ‘struct SCHIB’ may result in an unaligned pointer val\ ue [-Waddress-of-packed-member] 699 | SCSW *s = &sch->curr_status.scsw; | ^~~~~~~~~~~~~~~~~~~~~~ ...snip many more... Almost all of these are just done for convenience to avoid typing out long variable/field names when referencing struct members. We can get most of this convenience by taking the address of the 'struct SCHIB' instead, avoiding triggering the compiler warnings. In a couple of places we copy via a local variable which is a technique already applied elsewhere in s390 code for this problem. Signed-off-by: Daniel P. Berrangé Reviewed-by: Thomas Huth Reviewed-by: Halil Pasic --- hw/s390x/css.c | 388 ++++++++++++++++++++++++------------------------- 1 file changed, 187 insertions(+), 201 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index f92b046cd3..8fc9e35ba5 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -695,35 +695,32 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc) static void sch_handle_clear_func(SubchDev *sch) { - PMCW *p = &sch->curr_status.pmcw; - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; int path; /* Path management: In our simple css, we always choose the only path. */ path = 0x80; /* Reset values prior to 'issuing the clear signal'. */ - p->lpum = 0; - p->pom = 0xff; - s->flags &= ~SCSW_FLAGS_MASK_PNO; + schib->pmcw.lpum = 0; + schib->pmcw.pom = 0xff; + schib->scsw.flags &= ~SCSW_FLAGS_MASK_PNO; /* We always 'attempt to issue the clear signal', and we always succeed. */ sch->channel_prog = 0x0; sch->last_cmd_valid = false; - s->ctrl &= ~SCSW_ACTL_CLEAR_PEND; - s->ctrl |= SCSW_STCTL_STATUS_PEND; + schib->scsw.ctrl &= ~SCSW_ACTL_CLEAR_PEND; + schib->scsw.ctrl |= SCSW_STCTL_STATUS_PEND; - s->dstat = 0; - s->cstat = 0; - p->lpum = path; + schib->scsw.dstat = 0; + schib->scsw.cstat = 0; + schib->pmcw.lpum = path; } static void sch_handle_halt_func(SubchDev *sch) { - - PMCW *p = &sch->curr_status.pmcw; - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; hwaddr curr_ccw = sch->channel_prog; int path; @@ -733,20 +730,22 @@ static void sch_handle_halt_func(SubchDev *sch) /* We always 'attempt to issue the halt signal', and we always succeed. */ sch->channel_prog = 0x0; sch->last_cmd_valid = false; - s->ctrl &= ~SCSW_ACTL_HALT_PEND; - s->ctrl |= SCSW_STCTL_STATUS_PEND; + schib->scsw.ctrl &= ~SCSW_ACTL_HALT_PEND; + schib->scsw.ctrl |= SCSW_STCTL_STATUS_PEND; - if ((s->ctrl & (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) || - !((s->ctrl & SCSW_ACTL_START_PEND) || - (s->ctrl & SCSW_ACTL_SUSP))) { - s->dstat = SCSW_DSTAT_DEVICE_END; + if ((schib->scsw.ctrl & (SCSW_ACTL_SUBCH_ACTIVE | + SCSW_ACTL_DEVICE_ACTIVE)) || + !((schib->scsw.ctrl & SCSW_ACTL_START_PEND) || + (schib->scsw.ctrl & SCSW_ACTL_SUSP))) { + schib->scsw.dstat = SCSW_DSTAT_DEVICE_END; } - if ((s->ctrl & (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) || - (s->ctrl & SCSW_ACTL_SUSP)) { - s->cpa = curr_ccw + 8; + if ((schib->scsw.ctrl & (SCSW_ACTL_SUBCH_ACTIVE | + SCSW_ACTL_DEVICE_ACTIVE)) || + (schib->scsw.ctrl & SCSW_ACTL_SUSP)) { + schib->scsw.cpa = curr_ccw + 8; } - s->cstat = 0; - p->lpum = path; + schib->scsw.cstat = 0; + schib->pmcw.lpum = path; } @@ -1111,9 +1110,7 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr, static void sch_handle_start_func_virtual(SubchDev *sch) { - - PMCW *p = &sch->curr_status.pmcw; - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; int path; int ret; bool suspend_allowed; @@ -1121,27 +1118,27 @@ static void sch_handle_start_func_virtual(SubchDev *sch) /* Path management: In our simple css, we always choose the only path. */ path = 0x80; - if (!(s->ctrl & SCSW_ACTL_SUSP)) { + if (!(schib->scsw.ctrl & SCSW_ACTL_SUSP)) { /* Start Function triggered via ssch, i.e. we have an ORB */ ORB *orb = &sch->orb; - s->cstat = 0; - s->dstat = 0; + schib->scsw.cstat = 0; + schib->scsw.dstat = 0; /* Look at the orb and try to execute the channel program. */ - p->intparm = orb->intparm; + schib->pmcw.intparm = orb->intparm; if (!(orb->lpm & path)) { /* Generate a deferred cc 3 condition. */ - s->flags |= SCSW_FLAGS_MASK_CC; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND); + schib->scsw.flags |= SCSW_FLAGS_MASK_CC; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND); return; } sch->ccw_fmt_1 = !!(orb->ctrl0 & ORB_CTRL0_MASK_FMT); - s->flags |= (sch->ccw_fmt_1) ? SCSW_FLAGS_MASK_FMT : 0; + schib->scsw.flags |= (sch->ccw_fmt_1) ? SCSW_FLAGS_MASK_FMT : 0; sch->ccw_no_data_cnt = 0; suspend_allowed = !!(orb->ctrl0 & ORB_CTRL0_MASK_SPND); } else { /* Start Function resumed via rsch */ - s->ctrl &= ~(SCSW_ACTL_SUSP | SCSW_ACTL_RESUME_PEND); + schib->scsw.ctrl &= ~(SCSW_ACTL_SUSP | SCSW_ACTL_RESUME_PEND); /* The channel program had been suspended before. */ suspend_allowed = true; } @@ -1154,40 +1151,40 @@ static void sch_handle_start_func_virtual(SubchDev *sch) break; case 0: /* success */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_STATUS_PEND; - s->dstat = SCSW_DSTAT_CHANNEL_END | SCSW_DSTAT_DEVICE_END; - s->cpa = sch->channel_prog + 8; + schib->scsw.dstat = SCSW_DSTAT_CHANNEL_END | SCSW_DSTAT_DEVICE_END; + schib->scsw.cpa = sch->channel_prog + 8; break; case -EIO: /* I/O errors, status depends on specific devices */ break; case -ENOSYS: /* unsupported command, generate unit check (command reject) */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->dstat = SCSW_DSTAT_UNIT_CHECK; + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.dstat = SCSW_DSTAT_UNIT_CHECK; /* Set sense bit 0 in ecw0. */ sch->sense_data[0] = 0x80; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; - s->cpa = sch->channel_prog + 8; + schib->scsw.cpa = sch->channel_prog + 8; break; case -EINPROGRESS: /* channel program has been suspended */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->ctrl |= SCSW_ACTL_SUSP; + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.ctrl |= SCSW_ACTL_SUSP; break; default: /* error, generate channel program check */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->cstat = SCSW_CSTAT_PROG_CHECK; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.cstat = SCSW_CSTAT_PROG_CHECK; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; - s->cpa = sch->channel_prog + 8; + schib->scsw.cpa = sch->channel_prog + 8; break; } } while (ret == -EAGAIN); @@ -1196,14 +1193,11 @@ static void sch_handle_start_func_virtual(SubchDev *sch) static IOInstEnding sch_handle_start_func_passthrough(SubchDev *sch) { - - PMCW *p = &sch->curr_status.pmcw; - SCSW *s = &sch->curr_status.scsw; - + SCHIB *schib = &sch->curr_status; ORB *orb = &sch->orb; - if (!(s->ctrl & SCSW_ACTL_SUSP)) { + if (!(schib->scsw.ctrl & SCSW_ACTL_SUSP)) { assert(orb != NULL); - p->intparm = orb->intparm; + schib->pmcw.intparm = orb->intparm; } return s390_ccw_cmd_request(sch); } @@ -1216,14 +1210,13 @@ static IOInstEnding sch_handle_start_func_passthrough(SubchDev *sch) */ IOInstEnding do_subchannel_work_virtual(SubchDev *sch) { + SCHIB *schib = &sch->curr_status; - SCSW *s = &sch->curr_status.scsw; - - if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) { + if (schib->scsw.ctrl & SCSW_FCTL_CLEAR_FUNC) { sch_handle_clear_func(sch); - } else if (s->ctrl & SCSW_FCTL_HALT_FUNC) { + } else if (schib->scsw.ctrl & SCSW_FCTL_HALT_FUNC) { sch_handle_halt_func(sch); - } else if (s->ctrl & SCSW_FCTL_START_FUNC) { + } else if (schib->scsw.ctrl & SCSW_FCTL_START_FUNC) { /* Triggered by both ssch and rsch. */ sch_handle_start_func_virtual(sch); } @@ -1234,15 +1227,15 @@ IOInstEnding do_subchannel_work_virtual(SubchDev *sch) IOInstEnding do_subchannel_work_passthrough(SubchDev *sch) { - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; - if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) { + if (schib->scsw.ctrl & SCSW_FCTL_CLEAR_FUNC) { /* TODO: Clear handling */ sch_handle_clear_func(sch); - } else if (s->ctrl & SCSW_FCTL_HALT_FUNC) { + } else if (schib->scsw.ctrl & SCSW_FCTL_HALT_FUNC) { /* TODO: Halt handling */ sch_handle_halt_func(sch); - } else if (s->ctrl & SCSW_FCTL_START_FUNC) { + } else if (schib->scsw.ctrl & SCSW_FCTL_START_FUNC) { return sch_handle_start_func_passthrough(sch); } return IOINST_CC_EXPECTED; @@ -1370,46 +1363,45 @@ static void copy_schib_from_guest(SCHIB *dest, const SCHIB *src) IOInstEnding css_do_msch(SubchDev *sch, const SCHIB *orig_schib) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; uint16_t oldflags; - SCHIB schib; + SCHIB schib_copy; - if (!(sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_DNV)) { + if (!(schib->pmcw.flags & PMCW_FLAGS_MASK_DNV)) { return IOINST_CC_EXPECTED; } - if (s->ctrl & SCSW_STCTL_STATUS_PEND) { + if (schib->scsw.ctrl & SCSW_STCTL_STATUS_PEND) { return IOINST_CC_STATUS_PRESENT; } - if (s->ctrl & + if (schib->scsw.ctrl & (SCSW_FCTL_START_FUNC|SCSW_FCTL_HALT_FUNC|SCSW_FCTL_CLEAR_FUNC)) { return IOINST_CC_BUSY; } - copy_schib_from_guest(&schib, orig_schib); + copy_schib_from_guest(&schib_copy, orig_schib); /* Only update the program-modifiable fields. */ - p->intparm = schib.pmcw.intparm; - oldflags = p->flags; - p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA | + schib->pmcw.intparm = schib_copy.pmcw.intparm; + oldflags = schib->pmcw.flags; + schib->pmcw.flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA | PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME | PMCW_FLAGS_MASK_MP); - p->flags |= schib.pmcw.flags & + schib->pmcw.flags |= schib_copy.pmcw.flags & (PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA | PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME | PMCW_FLAGS_MASK_MP); - p->lpm = schib.pmcw.lpm; - p->mbi = schib.pmcw.mbi; - p->pom = schib.pmcw.pom; - p->chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE); - p->chars |= schib.pmcw.chars & + schib->pmcw.lpm = schib_copy.pmcw.lpm; + schib->pmcw.mbi = schib_copy.pmcw.mbi; + schib->pmcw.pom = schib_copy.pmcw.pom; + schib->pmcw.chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE); + schib->pmcw.chars |= schib_copy.pmcw.chars & (PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE); - sch->curr_status.mba = schib.mba; + schib->mba = schib_copy.mba; /* Has the channel been disabled? */ if (sch->disable_cb && (oldflags & PMCW_FLAGS_MASK_ENA) != 0 - && (p->flags & PMCW_FLAGS_MASK_ENA) == 0) { + && (schib->pmcw.flags & PMCW_FLAGS_MASK_ENA) == 0) { sch->disable_cb(sch); } return IOINST_CC_EXPECTED; @@ -1417,82 +1409,80 @@ IOInstEnding css_do_msch(SubchDev *sch, const SCHIB *orig_schib) IOInstEnding css_do_xsch(SubchDev *sch) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; - if (~(p->flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { + if (~(schib->pmcw.flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { return IOINST_CC_NOT_OPERATIONAL; } - if (s->ctrl & SCSW_CTRL_MASK_STCTL) { + if (schib->scsw.ctrl & SCSW_CTRL_MASK_STCTL) { return IOINST_CC_STATUS_PRESENT; } - if (!(s->ctrl & SCSW_CTRL_MASK_FCTL) || - ((s->ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) || - (!(s->ctrl & + if (!(schib->scsw.ctrl & SCSW_CTRL_MASK_FCTL) || + ((schib->scsw.ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) || + (!(schib->scsw.ctrl & (SCSW_ACTL_RESUME_PEND | SCSW_ACTL_START_PEND | SCSW_ACTL_SUSP))) || - (s->ctrl & SCSW_ACTL_SUBCH_ACTIVE)) { + (schib->scsw.ctrl & SCSW_ACTL_SUBCH_ACTIVE)) { return IOINST_CC_BUSY; } /* Cancel the current operation. */ - s->ctrl &= ~(SCSW_FCTL_START_FUNC | + schib->scsw.ctrl &= ~(SCSW_FCTL_START_FUNC | SCSW_ACTL_RESUME_PEND | SCSW_ACTL_START_PEND | SCSW_ACTL_SUSP); sch->channel_prog = 0x0; sch->last_cmd_valid = false; - s->dstat = 0; - s->cstat = 0; + schib->scsw.dstat = 0; + schib->scsw.cstat = 0; return IOINST_CC_EXPECTED; } IOInstEnding css_do_csch(SubchDev *sch) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; - if (~(p->flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { + if (~(schib->pmcw.flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { return IOINST_CC_NOT_OPERATIONAL; } /* Trigger the clear function. */ - s->ctrl &= ~(SCSW_CTRL_MASK_FCTL | SCSW_CTRL_MASK_ACTL); - s->ctrl |= SCSW_FCTL_CLEAR_FUNC | SCSW_ACTL_CLEAR_PEND; + schib->scsw.ctrl &= ~(SCSW_CTRL_MASK_FCTL | SCSW_CTRL_MASK_ACTL); + schib->scsw.ctrl |= SCSW_FCTL_CLEAR_FUNC | SCSW_ACTL_CLEAR_PEND; return do_subchannel_work(sch); } IOInstEnding css_do_hsch(SubchDev *sch) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; - if (~(p->flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { + if (~(schib->pmcw.flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { return IOINST_CC_NOT_OPERATIONAL; } - if (((s->ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_STATUS_PEND) || - (s->ctrl & (SCSW_STCTL_PRIMARY | + if (((schib->scsw.ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_STATUS_PEND) || + (schib->scsw.ctrl & (SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT))) { return IOINST_CC_STATUS_PRESENT; } - if (s->ctrl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { + if (schib->scsw.ctrl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { return IOINST_CC_BUSY; } /* Trigger the halt function. */ - s->ctrl |= SCSW_FCTL_HALT_FUNC; - s->ctrl &= ~SCSW_FCTL_START_FUNC; - if (((s->ctrl & SCSW_CTRL_MASK_ACTL) == + schib->scsw.ctrl |= SCSW_FCTL_HALT_FUNC; + schib->scsw.ctrl &= ~SCSW_FCTL_START_FUNC; + if (((schib->scsw.ctrl & SCSW_CTRL_MASK_ACTL) == (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) && - ((s->ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_INTERMEDIATE)) { - s->ctrl &= ~SCSW_STCTL_STATUS_PEND; + ((schib->scsw.ctrl & SCSW_CTRL_MASK_STCTL) == + SCSW_STCTL_INTERMEDIATE)) { + schib->scsw.ctrl &= ~SCSW_STCTL_STATUS_PEND; } - s->ctrl |= SCSW_ACTL_HALT_PEND; + schib->scsw.ctrl |= SCSW_ACTL_HALT_PEND; return do_subchannel_work(sch); } @@ -1534,18 +1524,17 @@ static void css_update_chnmon(SubchDev *sch) IOInstEnding css_do_ssch(SubchDev *sch, ORB *orb) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; - if (~(p->flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { + if (~(schib->pmcw.flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { return IOINST_CC_NOT_OPERATIONAL; } - if (s->ctrl & SCSW_STCTL_STATUS_PEND) { + if (schib->scsw.ctrl & SCSW_STCTL_STATUS_PEND) { return IOINST_CC_STATUS_PRESENT; } - if (s->ctrl & (SCSW_FCTL_START_FUNC | + if (schib->scsw.ctrl & (SCSW_FCTL_START_FUNC | SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) { return IOINST_CC_BUSY; @@ -1558,13 +1547,13 @@ IOInstEnding css_do_ssch(SubchDev *sch, ORB *orb) sch->orb = *orb; sch->channel_prog = orb->cpa; /* Trigger the start function. */ - s->ctrl |= (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND); - s->flags &= ~SCSW_FLAGS_MASK_PNO; + schib->scsw.ctrl |= (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND); + schib->scsw.flags &= ~SCSW_FLAGS_MASK_PNO; return do_subchannel_work(sch); } -static void copy_irb_to_guest(IRB *dest, const IRB *src, PMCW *pmcw, +static void copy_irb_to_guest(IRB *dest, const IRB *src, const PMCW *pmcw, int *irb_len) { int i; @@ -1603,24 +1592,24 @@ static void copy_irb_to_guest(IRB *dest, const IRB *src, PMCW *pmcw, int css_do_tsch_get_irb(SubchDev *sch, IRB *target_irb, int *irb_len) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; + PMCW p; uint16_t stctl; IRB irb; - if (~(p->flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { + if (~(schib->pmcw.flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { return 3; } - stctl = s->ctrl & SCSW_CTRL_MASK_STCTL; + stctl = schib->scsw.ctrl & SCSW_CTRL_MASK_STCTL; /* Prepare the irb for the guest. */ memset(&irb, 0, sizeof(IRB)); /* Copy scsw from current status. */ - memcpy(&irb.scsw, s, sizeof(SCSW)); + irb.scsw = schib->scsw; if (stctl & SCSW_STCTL_STATUS_PEND) { - if (s->cstat & (SCSW_CSTAT_DATA_CHECK | + if (schib->scsw.cstat & (SCSW_CSTAT_DATA_CHECK | SCSW_CSTAT_CHN_CTRL_CHK | SCSW_CSTAT_INTF_CTRL_CHK)) { irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF; @@ -1629,8 +1618,8 @@ int css_do_tsch_get_irb(SubchDev *sch, IRB *target_irb, int *irb_len) irb.esw[0] = 0x00800000; } /* If a unit check is pending, copy sense data. */ - if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) && - (p->chars & PMCW_CHARS_MASK_CSENSE)) { + if ((schib->scsw.dstat & SCSW_DSTAT_UNIT_CHECK) && + (schib->pmcw.chars & PMCW_CHARS_MASK_CSENSE)) { int i; irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF | SCSW_FLAGS_MASK_ECTL; @@ -1643,34 +1632,34 @@ int css_do_tsch_get_irb(SubchDev *sch, IRB *target_irb, int *irb_len) } } /* Store the irb to the guest. */ - copy_irb_to_guest(target_irb, &irb, p, irb_len); + p = schib->pmcw; + copy_irb_to_guest(target_irb, &irb, &p, irb_len); return ((stctl & SCSW_STCTL_STATUS_PEND) == 0); } void css_do_tsch_update_subch(SubchDev *sch) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; uint16_t stctl; uint16_t fctl; uint16_t actl; - stctl = s->ctrl & SCSW_CTRL_MASK_STCTL; - fctl = s->ctrl & SCSW_CTRL_MASK_FCTL; - actl = s->ctrl & SCSW_CTRL_MASK_ACTL; + stctl = schib->scsw.ctrl & SCSW_CTRL_MASK_STCTL; + fctl = schib->scsw.ctrl & SCSW_CTRL_MASK_FCTL; + actl = schib->scsw.ctrl & SCSW_CTRL_MASK_ACTL; /* Clear conditions on subchannel, if applicable. */ if (stctl & SCSW_STCTL_STATUS_PEND) { - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; if ((stctl != (SCSW_STCTL_INTERMEDIATE | SCSW_STCTL_STATUS_PEND)) || ((fctl & SCSW_FCTL_HALT_FUNC) && (actl & SCSW_ACTL_SUSP))) { - s->ctrl &= ~SCSW_CTRL_MASK_FCTL; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_FCTL; } if (stctl != (SCSW_STCTL_INTERMEDIATE | SCSW_STCTL_STATUS_PEND)) { - s->flags &= ~SCSW_FLAGS_MASK_PNO; - s->ctrl &= ~(SCSW_ACTL_RESUME_PEND | + schib->scsw.flags &= ~SCSW_FLAGS_MASK_PNO; + schib->scsw.ctrl &= ~(SCSW_ACTL_RESUME_PEND | SCSW_ACTL_START_PEND | SCSW_ACTL_HALT_PEND | SCSW_ACTL_CLEAR_PEND | @@ -1678,20 +1667,20 @@ void css_do_tsch_update_subch(SubchDev *sch) } else { if ((actl & SCSW_ACTL_SUSP) && (fctl & SCSW_FCTL_START_FUNC)) { - s->flags &= ~SCSW_FLAGS_MASK_PNO; + schib->scsw.flags &= ~SCSW_FLAGS_MASK_PNO; if (fctl & SCSW_FCTL_HALT_FUNC) { - s->ctrl &= ~(SCSW_ACTL_RESUME_PEND | + schib->scsw.ctrl &= ~(SCSW_ACTL_RESUME_PEND | SCSW_ACTL_START_PEND | SCSW_ACTL_HALT_PEND | SCSW_ACTL_CLEAR_PEND | SCSW_ACTL_SUSP); } else { - s->ctrl &= ~SCSW_ACTL_RESUME_PEND; + schib->scsw.ctrl &= ~SCSW_ACTL_RESUME_PEND; } } } /* Clear pending sense data. */ - if (p->chars & PMCW_CHARS_MASK_CSENSE) { + if (schib->pmcw.chars & PMCW_CHARS_MASK_CSENSE) { memset(sch->sense_data, 0 , sizeof(sch->sense_data)); } } @@ -1804,20 +1793,19 @@ void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo) IOInstEnding css_do_rsch(SubchDev *sch) { - SCSW *s = &sch->curr_status.scsw; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; - if (~(p->flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { + if (~(schib->pmcw.flags) & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA)) { return IOINST_CC_NOT_OPERATIONAL; } - if (s->ctrl & SCSW_STCTL_STATUS_PEND) { + if (schib->scsw.ctrl & SCSW_STCTL_STATUS_PEND) { return IOINST_CC_STATUS_PRESENT; } - if (((s->ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) || - (s->ctrl & SCSW_ACTL_RESUME_PEND) || - (!(s->ctrl & SCSW_ACTL_SUSP))) { + if (((schib->scsw.ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) || + (schib->scsw.ctrl & SCSW_ACTL_RESUME_PEND) || + (!(schib->scsw.ctrl & SCSW_ACTL_SUSP))) { return IOINST_CC_BUSY; } @@ -1826,7 +1814,7 @@ IOInstEnding css_do_rsch(SubchDev *sch) css_update_chnmon(sch); } - s->ctrl |= SCSW_ACTL_RESUME_PEND; + schib->scsw.ctrl |= SCSW_ACTL_RESUME_PEND; return do_subchannel_work(sch); } @@ -1927,28 +1915,27 @@ static int css_add_chpid(uint8_t cssid, uint8_t chpid, uint8_t type, void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type) { - PMCW *p = &sch->curr_status.pmcw; - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; int i; CssImage *css = channel_subsys.css[sch->cssid]; assert(css != NULL); - memset(p, 0, sizeof(PMCW)); - p->flags |= PMCW_FLAGS_MASK_DNV; - p->devno = sch->devno; + memset(&schib->pmcw, 0, sizeof(PMCW)); + schib->pmcw.flags |= PMCW_FLAGS_MASK_DNV; + schib->pmcw.devno = sch->devno; /* single path */ - p->pim = 0x80; - p->pom = 0xff; - p->pam = 0x80; - p->chpid[0] = chpid; + schib->pmcw.pim = 0x80; + schib->pmcw.pom = 0xff; + schib->pmcw.pam = 0x80; + schib->pmcw.chpid[0] = chpid; if (!css->chpids[chpid].in_use) { css_add_chpid(sch->cssid, chpid, type, true); } - memset(s, 0, sizeof(SCSW)); - sch->curr_status.mba = 0; - for (i = 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) { - sch->curr_status.mda[i] = 0; + memset(&schib->scsw, 0, sizeof(SCSW)); + schib->mba = 0; + for (i = 0; i < ARRAY_SIZE(schib->mda); i++) { + schib->mda[i] = 0; } } @@ -2246,30 +2233,30 @@ int css_enable_mss(void) void css_reset_sch(SubchDev *sch) { - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; - if ((p->flags & PMCW_FLAGS_MASK_ENA) != 0 && sch->disable_cb) { + if ((schib->pmcw.flags & PMCW_FLAGS_MASK_ENA) != 0 && sch->disable_cb) { sch->disable_cb(sch); } - p->intparm = 0; - p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA | + schib->pmcw.intparm = 0; + schib->pmcw.flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA | PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME | PMCW_FLAGS_MASK_MP | PMCW_FLAGS_MASK_TF); - p->flags |= PMCW_FLAGS_MASK_DNV; - p->devno = sch->devno; - p->pim = 0x80; - p->lpm = p->pim; - p->pnom = 0; - p->lpum = 0; - p->mbi = 0; - p->pom = 0xff; - p->pam = 0x80; - p->chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_XMWME | + schib->pmcw.flags |= PMCW_FLAGS_MASK_DNV; + schib->pmcw.devno = sch->devno; + schib->pmcw.pim = 0x80; + schib->pmcw.lpm = schib->pmcw.pim; + schib->pmcw.pnom = 0; + schib->pmcw.lpum = 0; + schib->pmcw.mbi = 0; + schib->pmcw.pom = 0xff; + schib->pmcw.pam = 0x80; + schib->pmcw.chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_XMWME | PMCW_CHARS_MASK_CSENSE); - memset(&sch->curr_status.scsw, 0, sizeof(sch->curr_status.scsw)); - sch->curr_status.mba = 0; + memset(&schib->scsw, 0, sizeof(schib->scsw)); + schib->mba = 0; sch->channel_prog = 0x0; sch->last_cmd_valid = false; @@ -2433,7 +2420,7 @@ static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id) FILE *fd; uint32_t chpid[8]; int i; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; fid_path = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/chpids", dev_id->cssid, dev_id->ssid, dev_id->devid); @@ -2452,8 +2439,8 @@ static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id) return -EINVAL; } - for (i = 0; i < ARRAY_SIZE(p->chpid); i++) { - p->chpid[i] = chpid[i]; + for (i = 0; i < ARRAY_SIZE(schib->pmcw.chpid); i++) { + schib->pmcw.chpid[i] = chpid[i]; } fclose(fd); @@ -2467,7 +2454,7 @@ static int css_sch_get_path_masks(SubchDev *sch, CssDevId *dev_id) char *fid_path; FILE *fd; uint32_t pim, pam, pom; - PMCW *p = &sch->curr_status.pmcw; + SCHIB *schib = &sch->curr_status; fid_path = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/pimpampom", dev_id->cssid, dev_id->ssid, dev_id->devid); @@ -2484,9 +2471,9 @@ static int css_sch_get_path_masks(SubchDev *sch, CssDevId *dev_id) return -EINVAL; } - p->pim = pim; - p->pam = pam; - p->pom = pom; + schib->pmcw.pim = pim; + schib->pmcw.pam = pam; + schib->pmcw.pom = pom; fclose(fd); g_free(fid_path); @@ -2528,16 +2515,15 @@ static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id) { CssImage *css = channel_subsys.css[sch->cssid]; - PMCW *p = &sch->curr_status.pmcw; - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; uint32_t type; int i, ret; assert(css != NULL); - memset(p, 0, sizeof(PMCW)); - p->flags |= PMCW_FLAGS_MASK_DNV; + memset(&schib->pmcw, 0, sizeof(PMCW)); + schib->pmcw.flags |= PMCW_FLAGS_MASK_DNV; /* We are dealing with I/O subchannels only. */ - p->devno = sch->devno; + schib->pmcw.devno = sch->devno; /* Grab path mask from sysfs. */ ret = css_sch_get_path_masks(sch, dev_id); @@ -2552,20 +2538,20 @@ int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id) } /* Build chpid type. */ - for (i = 0; i < ARRAY_SIZE(p->chpid); i++) { - if (p->chpid[i] && !css->chpids[p->chpid[i]].in_use) { - ret = css_sch_get_chpid_type(p->chpid[i], &type, dev_id); + for (i = 0; i < ARRAY_SIZE(schib->pmcw.chpid); i++) { + if (schib->pmcw.chpid[i] && !css->chpids[schib->pmcw.chpid[i]].in_use) { + ret = css_sch_get_chpid_type(schib->pmcw.chpid[i], &type, dev_id); if (ret) { return ret; } - css_add_chpid(sch->cssid, p->chpid[i], type, false); + css_add_chpid(sch->cssid, schib->pmcw.chpid[i], type, false); } } - memset(s, 0, sizeof(SCSW)); - sch->curr_status.mba = 0; - for (i = 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) { - sch->curr_status.mda[i] = 0; + memset(&schib->scsw, 0, sizeof(SCSW)); + schib->mba = 0; + for (i = 0; i < ARRAY_SIZE(schib->mda); i++) { + schib->mda[i] = 0; } return 0; From patchwork Fri Mar 29 11:11:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDC7C13B5 for ; Fri, 29 Mar 2019 11:21:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBEB228FEB for ; Fri, 29 Mar 2019 11:21:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF6EF2901B; Fri, 29 Mar 2019 11:21:02 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F0682915A for ; Fri, 29 Mar 2019 11:21:01 +0000 (UTC) Received: from localhost ([127.0.0.1]:50991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pZE-0004V2-Dv for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:21:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQz-0004Dn-EW for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQv-0002q7-Bv for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20443) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQv-0002Zz-1t; Fri, 29 Mar 2019 07:12:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30B33308339F; Fri, 29 Mar 2019 11:12:22 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFAB960BFB; Fri, 29 Mar 2019 11:12:19 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:11:03 +0000 Message-Id: <20190329111104.17223-14-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 29 Mar 2019 11:12:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/14] hw/s390x/ipl: avoid taking address of fields in packed struct 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Compiling with GCC 9 complains hw/s390x/ipl.c: In function ‘s390_ipl_set_boot_menu’: hw/s390x/ipl.c:256:25: warning: taking address of packed member of ‘struct QemuIplParameters’ may result in an unaligned pointer value [-Waddress-of-packed-member] 256 | uint32_t *timeout = &ipl->qipl.boot_menu_timeout; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ This local variable is only present to save a little bit of typing when setting the field later. Get rid of this to avoid the warning about unaligned accesses. Signed-off-by: Daniel P. Berrangé Reviewed-by: David Hildenbrand Reviewed-by: Thomas Huth Reviewed-by: Farhan Ali --- hw/s390x/ipl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 896888bf8f..51b272e190 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -252,8 +252,6 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) { QemuOptsList *plist = qemu_find_opts("boot-opts"); QemuOpts *opts = QTAILQ_FIRST(&plist->head); - uint8_t *flags = &ipl->qipl.qipl_flags; - uint32_t *timeout = &ipl->qipl.boot_menu_timeout; const char *tmp; unsigned long splash_time = 0; @@ -269,7 +267,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) case S390_IPL_TYPE_CCW: /* In the absence of -boot menu, use zipl parameters */ if (!qemu_opt_get(opts, "menu")) { - *flags |= QIPL_FLAG_BM_OPTS_ZIPL; + ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_ZIPL; return; } break; @@ -286,23 +284,23 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) return; } - *flags |= QIPL_FLAG_BM_OPTS_CMD; + ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_CMD; tmp = qemu_opt_get(opts, "splash-time"); if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) { error_report("splash-time is invalid, forcing it to 0"); - *timeout = 0; + ipl->qipl.boot_menu_timeout = 0; return; } if (splash_time > 0xffffffff) { error_report("splash-time is too large, forcing it to max value"); - *timeout = 0xffffffff; + ipl->qipl.boot_menu_timeout = 0xffffffff; return; } - *timeout = cpu_to_be32(splash_time); + ipl->qipl.boot_menu_timeout = cpu_to_be32(splash_time); } static CcwDevice *s390_get_ccw_device(DeviceState *dev_st) From patchwork Fri Mar 29 11:11:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10876897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A8C813B5 for ; Fri, 29 Mar 2019 11:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45BFA28FE8 for ; Fri, 29 Mar 2019 11:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43A7D29178; Fri, 29 Mar 2019 11:22:16 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E2D412914D for ; Fri, 29 Mar 2019 11:22:15 +0000 (UTC) Received: from localhost ([127.0.0.1]:51008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9paR-0005PG-3R for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 07:22:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pR1-0004Fz-RE for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQy-00038Y-UC for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQy-0002oq-Lf; Fri, 29 Mar 2019 07:12:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB9253083391; Fri, 29 Mar 2019 11:12:24 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69FAB60BFB; Fri, 29 Mar 2019 11:12:22 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:11:04 +0000 Message-Id: <20190329111104.17223-15-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 29 Mar 2019 11:12:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 14/14] hw/s390x/3270-ccw: avoid taking address of fields in packed struct 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Compiling with GCC 9 complains hw/s390x/3270-ccw.c: In function ‘emulated_ccw_3270_cb’: hw/s390x/3270-ccw.c:81:19: error: taking address of packed member of ‘struct SCHIB’ may result in an unaligned pointer value [-Werror=address-of-packed-member] 81 | SCSW *s = &sch->curr_status.scsw; | ^~~~~~~~~~~~~~~~~~~~~~ This local variable is only present to save a little bit of typing when setting the field later. Get rid of this to avoid the warning about unaligned accesses. Signed-off-by: Daniel P. Berrangé Reviewed-by: David Hildenbrand Reviewed-by: Thomas Huth --- hw/s390x/3270-ccw.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/s390x/3270-ccw.c b/hw/s390x/3270-ccw.c index 2c8d16ccf7..14882242c3 100644 --- a/hw/s390x/3270-ccw.c +++ b/hw/s390x/3270-ccw.c @@ -78,13 +78,13 @@ static int emulated_ccw_3270_cb(SubchDev *sch, CCW1 ccw) if (rc == -EIO) { /* I/O error, specific devices generate specific conditions */ - SCSW *s = &sch->curr_status.scsw; + SCHIB *schib = &sch->curr_status; sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_CHECK; sch->sense_data[0] = 0x40; /* intervention-req */ - s->ctrl &= ~SCSW_ACTL_START_PEND; - s->ctrl &= ~SCSW_CTRL_MASK_STCTL; - s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; }