From patchwork Thu Dec 13 12:02:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 153638 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp713921ljp; Thu, 13 Dec 2018 04:02:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/VXoXD44c/c+2LO3HBeSfdFScRm2iJQuPm8epBThSIm24kx6lcFVhqNcF9qIcC2zGkxHUDl X-Received: by 2002:adf:e911:: with SMTP id f17mr22166719wrm.126.1544702575480; Thu, 13 Dec 2018 04:02:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544702575; cv=none; d=google.com; s=arc-20160816; b=jffS+Zn3IsfG5uZxCaoBL89m8wTKUXWGyuPEh+Cv4N1SShuyEjVu82Xvh4amWJ+eRU Hf4JkbUqC1GYbLvw4mMrp0TNK4I5KBtltS49hq+Yj3avx3Fx258PJgkj8QqIPWyssMVD 0ur5GQEUeyDKWOZoXTa9crClOe4DH0hLMO71+obIMqosmRbF4sjcS6IhIo1l7UBULlvN +ActiX3ydH1CUItFufpjB9lo12ar4m+c97jYxnrRGaFvMQussNBLx0r4086TXF5fP44O 5xNtXnpScFwkCsiVUcZB+VGdGvZq+9yNbWPlIMdMbcPd/haO8fXARR1CtdHyUFykRkL7 uVGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=vrn+G4cOotfPcKmW9TpoqqLsJWg6q1iKg7/2tgq6Vzg=; b=xE4Lv1KzbuwiwLd6elEdPqfAZwLLIK3K/Dif4bCZVio74HXPlU4wEv07famGwI3C/9 P8nmkm5RAO/xwiyBCnrzcOKqJ1sV2fvxC9MkCx0T74dG9kFpioHgU9L7OSvi54R757ZA xo09ZuV6ZR9Vwf/G7Myg4qURYtD3SKOdHtyqa/+QCuqOt1EEtiimh7v0AkgWUFTlSE3+ zyhssNXrLQ0/tRD1Hf/+JDBm3cTdwJgwLGVz0UNq4uBkm1XFIJ36ESoci24lM2zXYVnc cVoIMDRraX346eDTzvqMRwUu1fel9ZvJn0HTxm5rYxA4tJA2l6PuTfQYL2t6YS17Ysip L4qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id q16si1417029wme.90.2018.12.13.04.02.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 04:02:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gXPhd-00076r-4R; Thu, 13 Dec 2018 12:02:53 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-s390x@nongnu.org, David Hildenbrand , Richard Henderson , Christian Borntraeger , Cornelia Huck , Thomas Huth , Farhan Ali Subject: [PATCH v2] hw/s390/ccw.c: Don't take address of packed members Date: Thu, 13 Dec 2018 12:02:52 +0000 Message-Id: <20181213120252.21697-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 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 --- v1->v2 changes: * add comment about why we're using locals * name locals with underscores, as QEMU's naming conventions recommend hw/s390x/css.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) -- 2.19.2 Reviewed-by: Farhan Ali Reviewed-by: Thomas Huth diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 04ec5cc9705..f92b046cd33 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; + /* + * 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; - copy_pmcw_to_guest(&dest->pmcw, &src->pmcw); - copy_scsw_to_guest(&dest->scsw, &src->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; + /* + * 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; - copy_pmcw_from_guest(&dest->pmcw, &src->pmcw); - copy_scsw_from_guest(&dest->scsw, &src->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];