From patchwork Thu Dec 20 16:44:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 154347 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6409678ljp; Thu, 20 Dec 2018 08:48:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/V3yiatwtG4ye299pN5Y2xh4+Ma+WrJ+X9hMp7mrUuPJ7pLHGJyhuFUlotMmah6iheo5oxv X-Received: by 2002:ac8:47c2:: with SMTP id d2mr26966904qtr.311.1545324531553; Thu, 20 Dec 2018 08:48:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545324531; cv=none; d=google.com; s=arc-20160816; b=TucM/HydM9IB/NdYY+Mqo65eheOPe+vIZnXYAxWVZXQhxqCo+FS4nsBGASPEq8LvFg 8w38xcEYYRzU4uXcYJOtMetA5WqAbZIMK17mfFAikjXAwI+OJSff6kfj9otDoH/hwLwP bAp0I94ZJw3ZLPt5pZBQbPFRw8XMnWgai1Ra9uMYm3huWUpoSWAAXEV38du31M+N6swp GDABmUGpCr4ao6ag/KySc1VBRQ/TNLuHTBdM15i64VDFryx6N+gyi1+8q0C4P132jD2g BfDmQbnzWNRVjKshkeKcUaS+9tZRKPa3DOeCLVbslwJR0L+fNE+g8m0IzD5VIoyk3Rm/ tm0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from; bh=OnvHDyNVx03ztcXaJxW+ZvVo0kYsm7mCVI9pxAcwwvA=; b=G2nMM+dPHJLRIpaA7GSx+PQ5go711wxJsO8RemU0BbXzz7y5YYxfyfarZDktqAZ9oN UzK9ptIsM1LLtFWV64nGTQu7ne1WvMlNaYjliDp1k8wlmkyjUTfK84YwBaxDmIGRu5A4 mq+UFEwK0iokGgAnkqvMDKSr1v27Uv4TglK+Yb9C+GjRS0F+q7+fAQPAjxd/++1An3Hw tE5b7Asr2qHgId9+nUQMxzJ9rULVnUZLn1uYA+s8xSYrMSsW6emj/2Q661I8wbjPROr8 KWPs2WboeFggBOpUPJp2M2fKi2Nnf0KVOUho2MG/2iIGuvyxxB8c3jypu7q9FH3/2h8X 2MyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c5si2527206qth.210.2018.12.20.08.48.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 20 Dec 2018 08:48:51 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:38673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ga1VC-0002kw-OU for patch@linaro.org; Thu, 20 Dec 2018 11:48:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ga1RB-0000E6-Jt for qemu-devel@nongnu.org; Thu, 20 Dec 2018 11:44:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ga1R9-0004C9-Fx for qemu-devel@nongnu.org; Thu, 20 Dec 2018 11:44:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48410) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ga1R9-0004BL-97; Thu, 20 Dec 2018 11:44:39 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E57A3E2DE; Thu, 20 Dec 2018 16:44:38 +0000 (UTC) Received: from localhost (dhcp-192-187.str.redhat.com [10.33.192.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 369D461373; Thu, 20 Dec 2018 16:44:38 +0000 (UTC) From: Cornelia Huck To: Peter Maydell Date: Thu, 20 Dec 2018 17:44:32 +0100 Message-Id: <20181220164433.21705-2-cohuck@redhat.com> In-Reply-To: <20181220164433.21705-1-cohuck@redhat.com> References: <20181220164433.21705-1-cohuck@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 20 Dec 2018 16:44:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/2] hw/s390/ccw.c: Don't take address of packed members 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: qemu-s390x@nongnu.org, Cornelia Huck , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Avoid the problem by using local copies of the PMCW and SCSW struct fields in copy_schib_from_guest() and copy_schib_to_guest(). Signed-off-by: Peter Maydell Message-Id: <20181213120252.21697-1-peter.maydell@linaro.org> Reviewed-by: Farhan Ali Reviewed-by: Thomas Huth Signed-off-by: Cornelia Huck --- hw/s390x/css.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) -- 2.17.2 diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 04ec5cc970..f92b046cd3 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1290,9 +1290,19 @@ void copy_scsw_to_guest(SCSW *dest, const SCSW *src) static void copy_schib_to_guest(SCHIB *dest, const SCHIB *src) { int i; - - copy_pmcw_to_guest(&dest->pmcw, &src->pmcw); - copy_scsw_to_guest(&dest->scsw, &src->scsw); + /* + * We copy the PMCW and SCSW in and out of local variables to + * avoid taking the address of members of a packed struct. + */ + PMCW src_pmcw, dest_pmcw; + SCSW src_scsw, dest_scsw; + + src_pmcw = src->pmcw; + copy_pmcw_to_guest(&dest_pmcw, &src_pmcw); + dest->pmcw = dest_pmcw; + src_scsw = src->scsw; + copy_scsw_to_guest(&dest_scsw, &src_scsw); + dest->scsw = dest_scsw; dest->mba = cpu_to_be64(src->mba); for (i = 0; i < ARRAY_SIZE(dest->mda); i++) { dest->mda[i] = src->mda[i]; @@ -1339,9 +1349,19 @@ static void copy_scsw_from_guest(SCSW *dest, const SCSW *src) static void copy_schib_from_guest(SCHIB *dest, const SCHIB *src) { int i; - - copy_pmcw_from_guest(&dest->pmcw, &src->pmcw); - copy_scsw_from_guest(&dest->scsw, &src->scsw); + /* + * We copy the PMCW and SCSW in and out of local variables to + * avoid taking the address of members of a packed struct. + */ + PMCW src_pmcw, dest_pmcw; + SCSW src_scsw, dest_scsw; + + src_pmcw = src->pmcw; + copy_pmcw_from_guest(&dest_pmcw, &src_pmcw); + dest->pmcw = dest_pmcw; + src_scsw = src->scsw; + copy_scsw_from_guest(&dest_scsw, &src_scsw); + dest->scsw = dest_scsw; dest->mba = be64_to_cpu(src->mba); for (i = 0; i < ARRAY_SIZE(dest->mda); i++) { dest->mda[i] = src->mda[i];