From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996735; cv=none; d=zohomail.com; s=zohoarc; b=eYp0GiBRzc2+dHHplzsAXXsYFerpnd4L9ia41z1sJhsuGiUGQ8TYsecQZtayUzwd3nL0NXn3+gTLqeyw9EZ4FRmXz6a7OseNznNIbG1/L0G2GlMa8oOsboOwbL2eSyPTMlLjpdmO/J4H2W9XOMwU3a/sIKAMr4xu0edqDiR1H3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996735; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CgyHlvADeH3H/n8ahqVFoV42NtM1czDhHqHTdupqPJY=; b=OOl/MiugCDSVT4WDqgF8trtTOCPS8luzT8WedcZ/2gLm+fGEBuuUnr2bBMUzWNZ5Mc07SjmzfsfllJZbOOZPpCOHi71nYUhecQCOQw1fup6fWsmaqwxN4W47lxTSHTJlAAF7Fc+pwxtMKASLUyjeEZvwyBUjg2dsiuNkHQNTVGc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996735074181.70611644231656; Mon, 17 Oct 2022 01:52:15 -0700 (PDT) Received: from localhost ([::1]:33842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLr1-0001nE-DX for importer@patchew.org; Mon, 17 Oct 2022 04:52:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLev-0007t3-Al; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLer-0003eq-Va; Mon, 17 Oct 2022 04:39:41 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H6vGv9031716; Mon, 17 Oct 2022 08:39:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k866bha5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:33 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H8ZiUU003994; Mon, 17 Oct 2022 08:39:32 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k866bha51-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:32 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8cv8N030308; Mon, 17 Oct 2022 08:39:30 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3k7m4jjnca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:30 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dRqQ1114688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB7D8A404D; Mon, 17 Oct 2022 08:39:26 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C91C1A4053; Mon, 17 Oct 2022 08:39:25 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:25 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=CgyHlvADeH3H/n8ahqVFoV42NtM1czDhHqHTdupqPJY=; b=dtYrW01Pjtld862JMWRX3WoruhcBsxBahVjGQV11oCD2d8RYb4LU+nG3P+w5OxinZ15t phOOi21p/QXIUBy/hEjnyco02TnWgRTwBLfM7e5FI6JE+42OKM/TP/VSL+6RQHiGRnJD MWzYfytSh45b0Uht56wI52iPPzXJdjCQN71C3D7yQljkckXp6CGpiqOF7DDC55NZIXo/ DErLHQyt9HfMaWCZECWua/sFsXxZ3rMzlvezk5MHh4LvSv/t9dKewQnQ87mDbZbxeuiN bjIjwjj94Pa4D/JcrR86+P9xY1o46AAgRbkS1YLlcpiTJO4jtIb7EzUoF0jnJLPwebLZ xw== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 01/10] dump: Use a buffer for ELF section data and headers Date: Mon, 17 Oct 2022 08:38:13 +0000 Message-Id: <20221017083822.43118-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: L8sKCCpMnqe9N3YBkuX4fl_g8eQVxMfy X-Proofpoint-ORIG-GUID: F-opjxVzAlnumJq4V0iSwAzsq86zbWRx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_07,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996736668100001 Content-Type: text/plain; charset="utf-8" Currently we're writing the NULL section header if we overflow the physical header number in the ELF header. But in the future we'll add custom section headers AND section data. To facilitate this we need to rearange section handling a bit. As with the other ELF headers we split the code into a prepare and a write step. Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau --- dump/dump.c | 79 +++++++++++++++++++++++++++++-------------- include/sysemu/dump.h | 2 ++ 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 236559b03a..e7a3b54ebe 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -380,31 +380,60 @@ static void write_elf_phdr_note(DumpState *s, Error *= *errp) } } =20 -static void write_elf_section(DumpState *s, int type, Error **errp) +static void prepare_elf_section_hdr_zero(DumpState *s) { - Elf32_Shdr shdr32; - Elf64_Shdr shdr64; - int shdr_size; - void *shdr; + if (dump_is_64bit(s)) { + Elf64_Shdr *shdr64 =3D s->elf_section_hdrs; + + shdr64->sh_info =3D cpu_to_dump32(s, s->phdr_num); + } else { + Elf32_Shdr *shdr32 =3D s->elf_section_hdrs; + + shdr32->sh_info =3D cpu_to_dump32(s, s->phdr_num); + } +} + +static void prepare_elf_section_hdrs(DumpState *s) +{ + size_t len, sizeof_shdr; + + /* + * Section ordering: + * - HDR zero + */ + sizeof_shdr =3D dump_is_64bit(s) ? sizeof(Elf64_Shdr) : sizeof(Elf32_S= hdr); + len =3D sizeof_shdr * s->shdr_num; + s->elf_section_hdrs =3D g_malloc0(len); + + /* + * The first section header is ALWAYS a special initial section + * header. + * + * The header should be 0 with one exception being that if + * phdr_num is PN_XNUM then the sh_info field contains the real + * number of segment entries. + * + * As we zero allocate the buffer we will only need to modify + * sh_info for the PN_XNUM case. + */ + if (s->phdr_num >=3D PN_XNUM) { + prepare_elf_section_hdr_zero(s); + } +} + +static void write_elf_section_headers(DumpState *s, Error **errp) +{ + size_t sizeof_shdr =3D dump_is_64bit(s) ? sizeof(Elf64_Shdr) : sizeof(= Elf32_Shdr); int ret; =20 - if (type =3D=3D 0) { - shdr_size =3D sizeof(Elf32_Shdr); - memset(&shdr32, 0, shdr_size); - shdr32.sh_info =3D cpu_to_dump32(s, s->phdr_num); - shdr =3D &shdr32; - } else { - shdr_size =3D sizeof(Elf64_Shdr); - memset(&shdr64, 0, shdr_size); - shdr64.sh_info =3D cpu_to_dump32(s, s->phdr_num); - shdr =3D &shdr64; + prepare_elf_section_hdrs(s); + + ret =3D fd_write_vmcore(s->elf_section_hdrs, s->shdr_num * sizeof_shdr= , s); + if (ret < 0) { + error_setg_errno(errp, -ret, "dump: failed to write section header= s"); } =20 - ret =3D fd_write_vmcore(shdr, shdr_size, s); - if (ret < 0) { - error_setg_errno(errp, -ret, - "dump: failed to write section header table"); - } + g_free(s->elf_section_hdrs); } =20 static void write_data(DumpState *s, void *buf, int length, Error **errp) @@ -591,12 +620,10 @@ static void dump_begin(DumpState *s, Error **errp) return; } =20 - /* write section to vmcore */ - if (s->shdr_num) { - write_elf_section(s, 1, errp); - if (*errp) { - return; - } + /* write section headers to vmcore */ + write_elf_section_headers(s, errp); + if (*errp) { + return; } =20 /* write notes to vmcore */ diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index b62513d87d..9995f65dc8 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -177,6 +177,8 @@ typedef struct DumpState { int64_t filter_area_begin; /* Start address of partial guest memory a= rea */ int64_t filter_area_length; /* Length of partial guest memory area */ =20 + void *elf_section_hdrs; /* Pointer to section header buffer */ + uint8_t *note_buf; /* buffer for notes */ size_t note_buf_offset; /* the writing place in note_buf */ uint32_t nr_cpus; /* number of guest's cpu */ --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996725; cv=none; d=zohomail.com; s=zohoarc; b=Ql9oLgMu6wSlgAcSpbhQfFRWB9wgVJUICnlEub1HFnYi9wlZKey88ylqSXuTneWt9h1boCmJ6c/nFWrxYfBWecQl0k222flcPpk1alIF9Uq/t5jOV3ExkmnbJurF/QgXN/cUZBtse041H81ycb83kZ9E1RtIvtpCIVOr7axGKQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996725; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/IDzQIhXAkq3jrBq1ANyf9Nm05KksKODJ+RHgaKOnA4=; b=L56i099M/iw9nDuSSSX2C13Ks/SmbWgiGXBganh8LYHC7yohFgJb3G88gNmIS9dHrydBQbMzyyoojSiWOElGRCG99zlnmXVsk/vY3f+cHVHnTPBiTwpvfot+rovbsk7TtrO9CwSG/jirq6iaESYWFPw1B6mSQfpZeU6z5Q19KcQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996725503960.3835523485903; Mon, 17 Oct 2022 01:52:05 -0700 (PDT) Received: from localhost ([::1]:33876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLqs-0001vS-8A for importer@patchew.org; Mon, 17 Oct 2022 04:52:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0007u9-Eu; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLes-0003fA-IZ; Mon, 17 Oct 2022 04:39:43 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H8WNq4036220; Mon, 17 Oct 2022 08:39:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86ug9ghg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:36 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H5sXwj024564; Mon, 17 Oct 2022 08:39:36 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86ug9gfd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:36 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8bPGH026457; Mon, 17 Oct 2022 08:39:31 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3k7mg92n4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:31 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8e0p645351184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:40:00 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F1DEA4057; Mon, 17 Oct 2022 08:39:28 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D6A2A404D; Mon, 17 Oct 2022 08:39:27 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:27 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=/IDzQIhXAkq3jrBq1ANyf9Nm05KksKODJ+RHgaKOnA4=; b=MV36BE/XpgclJUj9Ak4NjR5vbtLmwz8UlJ1bHSlfApuWdvh8LxqgD/sjTFoQNPj5C8Sn yRgeAUm01PlnuHlAOAdDwAMO6E8P/VoGJwgUwdKERzJoy2itVm1Z9IWNejPNyYKpW50L Kb72IWKZOdANWSCgZXm3xzUuhMEdoNUYo4/GTZg0HV3ubEi/FVRACbSLgq1oZ41pe2aK ceiaUbyqHdfCC78vcryyX4Gf3SiJLI5whPsGeZbvwuJFWLZmnvBbtauIdrqUBXOiI7uY GT18sR14SvHgcVZNZHdtAqf5DX7YUA8LcYdDX0LmChyp/ro2O4f02J7zLn+JSGp92jbk Eg== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 02/10] dump: Write ELF section headers right after ELF header Date: Mon, 17 Oct 2022 08:38:14 +0000 Message-Id: <20221017083822.43118-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SjKdR6-n8_rMvllPYjxwdbultqMNu5ce X-Proofpoint-ORIG-GUID: BW_W5EJtQwz4R_ybBopnJ-Tml4iExY0w X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_07,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=919 phishscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996726581100002 Content-Type: text/plain; charset="utf-8" Let's start bundling the writes of the headers and of the data so we have a clear ordering between them. Since the ELF header uses offsets to the headers we can freely order them. Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau --- dump/dump.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index e7a3b54ebe..b168a25321 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -583,6 +583,8 @@ static void dump_begin(DumpState *s, Error **errp) * -------------- * | elf header | * -------------- + * | sctn_hdr | + * -------------- * | PT_NOTE | * -------------- * | PT_LOAD | @@ -591,8 +593,6 @@ static void dump_begin(DumpState *s, Error **errp) * -------------- * | PT_LOAD | * -------------- - * | sec_hdr | - * -------------- * | elf note | * -------------- * | memory | @@ -608,6 +608,12 @@ static void dump_begin(DumpState *s, Error **errp) return; } =20 + /* write section headers to vmcore */ + write_elf_section_headers(s, errp); + if (*errp) { + return; + } + /* write PT_NOTE to vmcore */ write_elf_phdr_note(s, errp); if (*errp) { @@ -620,12 +626,6 @@ static void dump_begin(DumpState *s, Error **errp) return; } =20 - /* write section headers to vmcore */ - write_elf_section_headers(s, errp); - if (*errp) { - return; - } - /* write notes to vmcore */ write_elf_notes(s, errp); } @@ -1868,16 +1868,13 @@ static void dump_init(DumpState *s, int fd, bool ha= s_format, } =20 if (dump_is_64bit(s)) { - s->phdr_offset =3D sizeof(Elf64_Ehdr); - s->shdr_offset =3D s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_n= um; - s->note_offset =3D s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_n= um; - s->memory_offset =3D s->note_offset + s->note_size; + s->shdr_offset =3D sizeof(Elf64_Ehdr); + s->phdr_offset =3D s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_n= um; + s->note_offset =3D s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_n= um; } else { - - s->phdr_offset =3D sizeof(Elf32_Ehdr); - s->shdr_offset =3D s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_n= um; - s->note_offset =3D s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_n= um; - s->memory_offset =3D s->note_offset + s->note_size; + s->shdr_offset =3D sizeof(Elf32_Ehdr); + s->phdr_offset =3D s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_n= um; + s->note_offset =3D s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_n= um; } =20 return; --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996718; cv=none; d=zohomail.com; s=zohoarc; b=HsBV7dhHO2iWpXy+mFmEEhX35JQ/kLyJV5DEEML5P0eAIq4/XogtVEkh0OWqhAEeAiv2aejiaMwvJ5K7oW00SyZLcaDzq/UR8ogmXI4nVU1BpjgGSecsNmmUStUO8SnL9mdCMzmfDlnY2uu1StofESXrevvlyRKpPkqOYZ+FA74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996718; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kZ8h8d1xaw35bNHcVTqHyEdx+i2sKTFhn6OdtsGsu+c=; b=n621cRp+OCp0SRtxaTC4eF2lQcJBFSudqzvKl8NE7qbyzKecNiK2mheROMA9iABYUQMMwPgLIhwhmIFAswayCKsFKprOLb1oyRuNOU3KIaFcN6il/aL/csaT8qg95XRM/dq+F9iRuZHDpGaff+c0qL12Z7VILMCj1L1uwubXPXQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996718205591.2833947969114; Mon, 17 Oct 2022 01:51:58 -0700 (PDT) Received: from localhost ([::1]:33856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLqm-0001np-8W for importer@patchew.org; Mon, 17 Oct 2022 04:51:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0007uC-FJ; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLes-0003f4-4Z; Mon, 17 Oct 2022 04:39:43 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H7c8nm035766; Mon, 17 Oct 2022 08:39:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86ug9gh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:35 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H8DYn0007124; Mon, 17 Oct 2022 08:39:35 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86ug9gg3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:35 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8bdew003448; Mon, 17 Oct 2022 08:39:32 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06fra.de.ibm.com with ESMTP id 3k7m4ja19c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:32 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8YY7x49873216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:34:34 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86C1DA4051; Mon, 17 Oct 2022 08:39:29 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6549FA4055; Mon, 17 Oct 2022 08:39:28 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:28 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=kZ8h8d1xaw35bNHcVTqHyEdx+i2sKTFhn6OdtsGsu+c=; b=TssiOLG5FwGIcAObR9uoW/ej5WTUvL0rREu43SPlBu6Vy07BCOTKrIChnBU6fjfHUQaf /1AGCmxPn8gFsou0VDFfW/g7yrnsLp9i+ydG4BYGF8jgOf1UhysOwSzS7L0tevjUwOHo aJfkBtioqTeyhKvhwXBbWR0Z1N/SXaMigRKsLlctSp+D5yNuo3oEyuPWA9iWaZmG1jbV Z82SoVLoWjWPhC2tzIz9giNEqLM44qcqayU69L0Os3bomeercs11pX3iXydF3GqNbyyB AVRjog1N7H61E6SC0j3rLzsSaYAgjT/e9YMYD1U8ONziDU8wQOtOfHYb3NA1Owzsa7a/ mQ== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 03/10] dump: Reorder struct DumpState Date: Mon, 17 Oct 2022 08:38:15 +0000 Message-Id: <20221017083822.43118-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 8a-XgLMxlmMLDDFtQmdxLq_ZeZtYU1dP X-Proofpoint-ORIG-GUID: h1pTjbKl96nxwxxNhIGknOuqza1CZw05 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_07,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=884 phishscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996718600100001 Let's move ELF related members into one block and guest memory related ones into another to improve readability. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-Andr=C3=A9 Lureau --- include/sysemu/dump.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 9995f65dc8..9ed811b313 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -154,15 +154,8 @@ typedef struct DumpState { GuestPhysBlockList guest_phys_blocks; ArchDumpInfo dump_info; MemoryMappingList list; - uint32_t phdr_num; - uint32_t shdr_num; bool resume; bool detached; - ssize_t note_size; - hwaddr shdr_offset; - hwaddr phdr_offset; - hwaddr section_offset; - hwaddr note_offset; hwaddr memory_offset; int fd; =20 @@ -177,6 +170,15 @@ typedef struct DumpState { int64_t filter_area_begin; /* Start address of partial guest memory a= rea */ int64_t filter_area_length; /* Length of partial guest memory area */ =20 + /* Elf dump related data */ + uint32_t phdr_num; + uint32_t shdr_num; + ssize_t note_size; + hwaddr shdr_offset; + hwaddr phdr_offset; + hwaddr section_offset; + hwaddr note_offset; + void *elf_section_hdrs; /* Pointer to section header buffer */ =20 uint8_t *note_buf; /* buffer for notes */ --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996725; cv=none; d=zohomail.com; s=zohoarc; b=MUtJlJfPTkEWE0KtmyippJQNyHBxTh+twwv9MPAwBPoKvf1JLZFlm++YsSVV6FkUeiOIHXKIOV6IqjLLq4VK/s4sIvHQgAZPrnqDm4jmEh4OE+6ocZSnlhLzCYL+cFn4LvRKW0+8q8SNznSup8idRKd5W/qbSFpymRoexgdT1dQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996725; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ihcyzdaTbDT5cwlGqNku/2YsTq8jCdtPF/3ztkFfD84=; b=GzW/TpLoy5/yPOnzg7OlUyNf1+hjSJVzGol5I2KfcurJdjFkGiqgL+9OtChkmb5aK50JiNJkflCjBxfdHgVUHOMIaWwXmPUU2RTxcDJBhsegLQOyE19b8xVzlu7zr2/ZhF1CuEZ3s5ETEbbvIr8yWkNvKNNuVykANOG+u25tt00= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996725549188.1773433614477; Mon, 17 Oct 2022 01:52:05 -0700 (PDT) Received: from localhost ([::1]:33866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLqs-0001uP-8J for importer@patchew.org; Mon, 17 Oct 2022 04:52:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLev-0007t4-Ex; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:57528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLes-0003fC-L2; Mon, 17 Oct 2022 04:39:41 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H7rFZ8001846; Mon, 17 Oct 2022 08:39:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k866bha7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:36 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H8V97T008053; Mon, 17 Oct 2022 08:39:36 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k866bha6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:36 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8b8hA026025; Mon, 17 Oct 2022 08:39:34 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03ams.nl.ibm.com with ESMTP id 3k7mg92n4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:33 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dUsc64553264 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:30 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9265A404D; Mon, 17 Oct 2022 08:39:30 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD0F0A4051; Mon, 17 Oct 2022 08:39:29 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:29 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ihcyzdaTbDT5cwlGqNku/2YsTq8jCdtPF/3ztkFfD84=; b=i7JN04dJOYzMXZz86ktuMyhhkFmnD49zfGWSGs4TXjVHvnOndGf1SrNdtOt+Qfmd+jPu tqF6jG/WcT2VumtcOYRoAixFs/S7J/I97LW2wEuZTJwvezzksco7NNUhoBK9y3KY+Dwx gPR7+4QpfGWWh8oCjZqLsnXg7D6Khgr5X6bk78V61uc5GRlEndVGCoUBZGf36dTzhzWC udR16+7/2j/F4MDB82gzDeHJ6pdMs+MIZ56Pmvdkgx849WPNfMilWfJtvjZX2MDt295b rd1e12wPzBo1kJkPhwugwL53ik2w/dDg3boNdMsFpL4e8NhhQS6U7pQOYxp6IUmaARrh Yw== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 04/10] dump: Reintroduce memory_offset and section_offset Date: Mon, 17 Oct 2022 08:38:16 +0000 Message-Id: <20221017083822.43118-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 95KmpSQBMVmoi0by6-psYqEP_uBTVGsW X-Proofpoint-ORIG-GUID: jncNJ2l4LYZGriAimml6brb5za8mLHAC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_07,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 mlxscore=0 adultscore=0 mlxlogscore=799 lowpriorityscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996726572100001 Content-Type: text/plain; charset="utf-8" section_offset will later be used to store the offset to the section data which will be stored last. For now memory_offset is only needed to make section_offset look nicer. Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau --- dump/dump.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dump/dump.c b/dump/dump.c index b168a25321..626f7b2fd0 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1876,6 +1876,8 @@ static void dump_init(DumpState *s, int fd, bool has_= format, s->phdr_offset =3D s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_n= um; s->note_offset =3D s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_n= um; } + s->memory_offset =3D s->note_offset + s->note_size; + s->section_offset =3D s->memory_offset + s->total_size; =20 return; =20 --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996781; cv=none; d=zohomail.com; s=zohoarc; b=M0vOox7DEcdiV6dWIGYKW5PPjNhq8PfOz3jHbJ9H7KjVtE8w50q5ACYn3U5L5HXXedEeM8TkfUCTCoBIESgt/N5FN3JTMml3IoKjnNKsc02VRo37FfKLfs1oTJxl+O1PBaR/AAlKSrjwFkAV+e2v26Leys822ZNccEi3VqOa+90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996781; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A4HQ6E713KcKxEA4GIs7jkRLHX/WzDGi+jfZtAVL2XE=; b=ZSHXMbtq9bUxb+hElWCUSbMyyDr5Wi0cfUN4zWaR9utMBETJ1sEGALG3ZnFr86FX6IAk1LiyZoLT+kdi8CFu10cUPqMBVwUasb7G2AQG5afD41hxg+ykcpDnjlr8vhDg5UHeW3XI3stGiEsOy9WrEpg7E/TuU4kUNL72FkFBc8g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996781652662.739540016069; Mon, 17 Oct 2022 01:53:01 -0700 (PDT) Received: from localhost ([::1]:51050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLro-0002va-4o for importer@patchew.org; Mon, 17 Oct 2022 04:53:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0007ts-D9; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLeu-0003fb-6K; Mon, 17 Oct 2022 04:39:44 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H6qt89017339; Mon, 17 Oct 2022 08:39:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86sjhtnw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:38 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H6RvqB013832; Mon, 17 Oct 2022 08:39:38 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86sjhtn6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:37 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8cv8O030308; Mon, 17 Oct 2022 08:39:35 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3k7m4jjncd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:35 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dWtw4915858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:32 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 378D9A404D; Mon, 17 Oct 2022 08:39:32 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B918A4051; Mon, 17 Oct 2022 08:39:31 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:30 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=A4HQ6E713KcKxEA4GIs7jkRLHX/WzDGi+jfZtAVL2XE=; b=Vq7KjK3nEz79DgHLE2EQfhdejIjVOCGEvHvPeiKJATPou9QhDYpvWzv5zIgPQgg8Zyhb Z164uSx4YWi20g2TDOg9F5xYYuBkJKw4zuWkH9qAfZ/RYt8qgiVsLHeyB17ccum+wg7i XRIola9LL492DmotLdqu0jUk4+24w6ARoATgI4E0BkelPYo/XyFq4Ix7NGvRLS67S5Pu jAn6R40TUnsB1myrwYnyOPI9yDu4KhHszmM7yOJJWODGEHf9nKlKZnguPBE+ngJgO5Eq 0KnJH5Xd/4jCsKiOh81yyRlH6SVYlxqv90QshpygTS6gDeABJOwcrz/rwVJQ86YNbthw 3g== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 05/10] dump: Add architecture section and section string table support Date: Mon, 17 Oct 2022 08:38:17 +0000 Message-Id: <20221017083822.43118-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: UqaRDZUJgzEIvlYlvYwZH4RUziE-WA6- X-Proofpoint-GUID: VFV_tWfcsOc_RIaqkQXIFJquDFMBVKsm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_07,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 priorityscore=1501 phishscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996782910100001 Content-Type: text/plain; charset="utf-8" Add hooks which architectures can use to add arbitrary data to custom sections. Also add a section name string table in order to identify section contents Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau --- dump/dump.c | 190 +++++++++++++++++++++++++++++++------ include/sysemu/dump-arch.h | 3 + include/sysemu/dump.h | 3 + 3 files changed, 168 insertions(+), 28 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 626f7b2fd0..b5bc4f7119 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -103,6 +103,7 @@ static int dump_cleanup(DumpState *s) memory_mapping_list_free(&s->list); close(s->fd); g_free(s->guest_note); + g_array_unref(s->string_table_buf); s->guest_note =3D NULL; if (s->resume) { if (s->detached) { @@ -152,11 +153,10 @@ static void prepare_elf64_header(DumpState *s, Elf64_= Ehdr *elf_header) elf_header->e_phoff =3D cpu_to_dump64(s, s->phdr_offset); elf_header->e_phentsize =3D cpu_to_dump16(s, sizeof(Elf64_Phdr)); elf_header->e_phnum =3D cpu_to_dump16(s, phnum); - if (s->shdr_num) { - elf_header->e_shoff =3D cpu_to_dump64(s, s->shdr_offset); - elf_header->e_shentsize =3D cpu_to_dump16(s, sizeof(Elf64_Shdr)); - elf_header->e_shnum =3D cpu_to_dump16(s, s->shdr_num); - } + elf_header->e_shoff =3D cpu_to_dump64(s, s->shdr_offset); + elf_header->e_shentsize =3D cpu_to_dump16(s, sizeof(Elf64_Shdr)); + elf_header->e_shnum =3D cpu_to_dump16(s, s->shdr_num); + elf_header->e_shstrndx =3D cpu_to_dump16(s, s->shdr_num - 1); } =20 static void prepare_elf32_header(DumpState *s, Elf32_Ehdr *elf_header) @@ -180,11 +180,10 @@ static void prepare_elf32_header(DumpState *s, Elf32_= Ehdr *elf_header) elf_header->e_phoff =3D cpu_to_dump32(s, s->phdr_offset); elf_header->e_phentsize =3D cpu_to_dump16(s, sizeof(Elf32_Phdr)); elf_header->e_phnum =3D cpu_to_dump16(s, phnum); - if (s->shdr_num) { - elf_header->e_shoff =3D cpu_to_dump32(s, s->shdr_offset); - elf_header->e_shentsize =3D cpu_to_dump16(s, sizeof(Elf32_Shdr)); - elf_header->e_shnum =3D cpu_to_dump16(s, s->shdr_num); - } + elf_header->e_shoff =3D cpu_to_dump32(s, s->shdr_offset); + elf_header->e_shentsize =3D cpu_to_dump16(s, sizeof(Elf32_Shdr)); + elf_header->e_shnum =3D cpu_to_dump16(s, s->shdr_num); + elf_header->e_shstrndx =3D cpu_to_dump16(s, s->shdr_num - 1); } =20 static void write_elf_header(DumpState *s, Error **errp) @@ -195,6 +194,8 @@ static void write_elf_header(DumpState *s, Error **errp) void *header_ptr; int ret; =20 + /* The NULL header and the shstrtab are always defined */ + assert(s->shdr_num >=3D 2); if (dump_is_64bit(s)) { prepare_elf64_header(s, &elf64_header); header_size =3D sizeof(elf64_header); @@ -393,17 +394,49 @@ static void prepare_elf_section_hdr_zero(DumpState *s) } } =20 -static void prepare_elf_section_hdrs(DumpState *s) +static void prepare_elf_section_hdr_string(DumpState *s, void *buff) +{ + uint64_t index =3D s->string_table_buf->len; + const char strtab[] =3D ".shstrtab"; + Elf32_Shdr shdr32 =3D {}; + Elf64_Shdr shdr64 =3D {}; + int shdr_size; + void *shdr; + + g_array_append_vals(s->string_table_buf, strtab, sizeof(strtab)); + if (dump_is_64bit(s)) { + shdr_size =3D sizeof(Elf64_Shdr); + shdr64.sh_type =3D SHT_STRTAB; + shdr64.sh_offset =3D s->section_offset + s->elf_section_data_size; + shdr64.sh_name =3D index; + shdr64.sh_size =3D s->string_table_buf->len; + shdr =3D &shdr64; + } else { + shdr_size =3D sizeof(Elf32_Shdr); + shdr32.sh_type =3D SHT_STRTAB; + shdr32.sh_offset =3D s->section_offset + s->elf_section_data_size; + shdr32.sh_name =3D index; + shdr32.sh_size =3D s->string_table_buf->len; + shdr =3D &shdr32; + } + memcpy(buff, shdr, shdr_size); +} + +static int prepare_elf_section_hdrs(DumpState *s, Error **errp) { size_t len, sizeof_shdr; + void *buff_hdr; =20 /* * Section ordering: * - HDR zero + * - Arch section hdrs + * - String table hdr */ sizeof_shdr =3D dump_is_64bit(s) ? sizeof(Elf64_Shdr) : sizeof(Elf32_S= hdr); len =3D sizeof_shdr * s->shdr_num; s->elf_section_hdrs =3D g_malloc0(len); + buff_hdr =3D s->elf_section_hdrs; =20 /* * The first section header is ALWAYS a special initial section @@ -419,6 +452,26 @@ static void prepare_elf_section_hdrs(DumpState *s) if (s->phdr_num >=3D PN_XNUM) { prepare_elf_section_hdr_zero(s); } + buff_hdr +=3D sizeof_shdr; + + /* Add architecture defined section headers */ + if (s->dump_info.arch_sections_write_hdr_fn + && s->shdr_num > 2) { + buff_hdr +=3D s->dump_info.arch_sections_write_hdr_fn(s, buff_hdr); + + if (s->shdr_num >=3D SHN_LORESERVE) { + error_setg_errno(errp, EINVAL, + "dump: too many architecture defined sections= "); + return -EINVAL; + } + } + + /* + * String table is the last section since strings are added via + * arch_sections_write_hdr(). + */ + prepare_elf_section_hdr_string(s, buff_hdr); + return 0; } =20 static void write_elf_section_headers(DumpState *s, Error **errp) @@ -426,7 +479,9 @@ static void write_elf_section_headers(DumpState *s, Err= or **errp) size_t sizeof_shdr =3D dump_is_64bit(s) ? sizeof(Elf64_Shdr) : sizeof(= Elf32_Shdr); int ret; =20 - prepare_elf_section_hdrs(s); + if (prepare_elf_section_hdrs(s, errp)) { + return; + } =20 ret =3D fd_write_vmcore(s->elf_section_hdrs, s->shdr_num * sizeof_shdr= , s); if (ret < 0) { @@ -436,6 +491,29 @@ static void write_elf_section_headers(DumpState *s, Er= ror **errp) g_free(s->elf_section_hdrs); } =20 +static void write_elf_sections(DumpState *s, Error **errp) +{ + int ret; + + if (s->elf_section_data_size) { + /* Write architecture section data */ + ret =3D fd_write_vmcore(s->elf_section_data, + s->elf_section_data_size, s); + if (ret < 0) { + error_setg_errno(errp, -ret, + "dump: failed to write architecture section d= ata"); + return; + } + } + + /* Write string table */ + ret =3D fd_write_vmcore(s->string_table_buf->data, + s->string_table_buf->len, s); + if (ret < 0) { + error_setg_errno(errp, -ret, "dump: failed to write string table d= ata"); + } +} + static void write_data(DumpState *s, void *buf, int length, Error **errp) { int ret; @@ -692,6 +770,31 @@ static void dump_iterate(DumpState *s, Error **errp) } } =20 +static void dump_end(DumpState *s, Error **errp) +{ + int rc; + ERRP_GUARD(); + + if (s->elf_section_data_size) { + s->elf_section_data =3D g_malloc0(s->elf_section_data_size); + } + + /* Adds the architecture defined section data to s->elf_section_data = */ + if (s->dump_info.arch_sections_write_fn && + s->elf_section_data_size) { + rc =3D s->dump_info.arch_sections_write_fn(s, s->elf_section_data); + if (rc) { + error_setg_errno(errp, rc, + "dump: failed to get arch section data"); + g_free(s->elf_section_data); + return; + } + } + + /* write sections to vmcore */ + write_elf_sections(s, errp); +} + static void create_vmcore(DumpState *s, Error **errp) { ERRP_GUARD(); @@ -701,7 +804,14 @@ static void create_vmcore(DumpState *s, Error **errp) return; } =20 + /* Iterate over memory and dump it to file */ dump_iterate(s, errp); + if (*errp) { + return; + } + + /* Write the section data */ + dump_end(s, errp); } =20 static int write_start_flat_header(int fd) @@ -1711,6 +1821,14 @@ static void dump_init(DumpState *s, int fd, bool has= _format, s->filter_area_begin =3D begin; s->filter_area_length =3D length; =20 + /* First index is 0, it's the special null name */ + s->string_table_buf =3D g_array_new(FALSE, TRUE, 1); + /* + * Allocate the null name, due to the clearing option set to true + * it will be 0. + */ + g_array_set_size(s->string_table_buf, 1); + memory_mapping_list_init(&s->list); =20 guest_phys_blocks_init(&s->guest_phys_blocks); @@ -1847,26 +1965,42 @@ static void dump_init(DumpState *s, int fd, bool ha= s_format, } =20 /* - * calculate phdr_num - * - * the type of ehdr->e_phnum is uint16_t, so we should avoid overflow + * The first section header is always a special one in which most + * fields are 0. The section header string table is also always + * set. */ - s->phdr_num =3D 1; /* PT_NOTE */ - if (s->list.num < UINT16_MAX - 2) { - s->shdr_num =3D 0; - s->phdr_num +=3D s->list.num; - } else { - /* sh_info of section 0 holds the real number of phdrs */ - s->shdr_num =3D 1; + s->shdr_num =3D 2; =20 - /* the type of shdr->sh_info is uint32_t, so we should avoid overf= low */ - if (s->list.num <=3D UINT32_MAX - 1) { - s->phdr_num +=3D s->list.num; - } else { - s->phdr_num =3D UINT32_MAX; - } + /* + * Adds the number of architecture sections to shdr_num and sets + * elf_section_data_size so we know the offsets and sizes of all + * parts. + */ + if (s->dump_info.arch_sections_add_fn) { + s->dump_info.arch_sections_add_fn(s); } =20 + /* + * calculate shdr_num so we know the offsets and sizes of all + * parts. + * Calculate phdr_num + * + * The absolute maximum amount of phdrs is UINT32_MAX - 1 as + * sh_info is 32 bit. There's special handling once we go over + * UINT16_MAX - 1 but that is handled in the ehdr and section + * code. + */ + s->phdr_num =3D 1; /* Reserve PT_NOTE */ + if (s->list.num <=3D UINT32_MAX - 1) { + s->phdr_num +=3D s->list.num; + } else { + s->phdr_num =3D UINT32_MAX; + } + + /* + * Now that the number of section and program headers is known we + * can calculate the offsets of the headers and data. + */ if (dump_is_64bit(s)) { s->shdr_offset =3D sizeof(Elf64_Ehdr); s->phdr_offset =3D s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_n= um; diff --git a/include/sysemu/dump-arch.h b/include/sysemu/dump-arch.h index e25b02e990..59bbc9be38 100644 --- a/include/sysemu/dump-arch.h +++ b/include/sysemu/dump-arch.h @@ -21,6 +21,9 @@ typedef struct ArchDumpInfo { uint32_t page_size; /* The target's page size. If it's variable a= nd * unknown, then this should be the maximum. = */ uint64_t phys_base; /* The target's physmem base. */ + void (*arch_sections_add_fn)(DumpState *s); + uint64_t (*arch_sections_write_hdr_fn)(DumpState *s, uint8_t *buff); + int (*arch_sections_write_fn)(DumpState *s, uint8_t *buff); } ArchDumpInfo; =20 struct GuestPhysBlockList; /* memory_mapping.h */ diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 9ed811b313..38ccac7190 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -180,6 +180,9 @@ typedef struct DumpState { hwaddr note_offset; =20 void *elf_section_hdrs; /* Pointer to section header buffer */ + void *elf_section_data; /* Pointer to section data buffer */ + uint64_t elf_section_data_size; /* Size of section data */ + GArray *string_table_buf; /* String table data buffer */ =20 uint8_t *note_buf; /* buffer for notes */ size_t note_buf_offset; /* the writing place in note_buf */ --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996734; cv=none; d=zohomail.com; s=zohoarc; b=WOPEs8OwpBuTYo3+N/Y/pWPf0Et3jedxFhjLmv+yTHD+ja+cNILnLWu/P8/0lydBbu3zic0L/FJs6N8JS3WkPGE0oRivyjR6HjnYoNUxAYP2Qc1Y9xnXIhp+SCqddz4APrBQqLteyYkQes7BzgESzinEfKU9GMvqywg3IOMRNJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996734; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CFZWawMqHeQzH6iy33ST0YVbijsFegmiORIVkzEzTU0=; b=jZcNLj+s8FrObI/8R/sWG3cCddwkLMFA20J2ZAN9KtYumb59iiPq25XgD+AXmUGsBuLFeHQ0IWoIMqazayWgm8s3XNN2NvSduBT9HGfyevge1Cj2xcVItvaJtG3nmSiGozgYPzGiXwzmWc+536CXXXL77AZ6KPV5+QruYJQdjhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166599673432136.95351142318361; Mon, 17 Oct 2022 01:52:14 -0700 (PDT) Received: from localhost ([::1]:33892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLr1-00020m-Nc for importer@patchew.org; Mon, 17 Oct 2022 04:52:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0007u0-EF; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51798 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLeu-0003fh-R7; Mon, 17 Oct 2022 04:39:45 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H6ZM4m012953; Mon, 17 Oct 2022 08:39:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86g5sfa9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:39 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H6iiM8021727; Mon, 17 Oct 2022 08:39:38 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86g5sf9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:38 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8csKv030276; Mon, 17 Oct 2022 08:39:36 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3k7m4jjnce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:36 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dXkm32309980 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:33 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FE16A4051; Mon, 17 Oct 2022 08:39:33 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D9DFA404D; Mon, 17 Oct 2022 08:39:32 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:32 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=CFZWawMqHeQzH6iy33ST0YVbijsFegmiORIVkzEzTU0=; b=jj6O5le83VE87ct7Rz/wT0CB7dfJ4FWcHQyTWefNI8Kwr3gEW74yDNTgGNnYCRR9VjV7 g5DvSZ8jaQasabOcGXXRCahdtteUi6qpwCYD0ZGVd6AnIjQ63GIESn/VGRTuLLhp4s5z PE+5uyohvzvrM3ehhLfI9MvhRFeIdtwkAl8HuBmSWyuCaKbIgrkK/B/9HuAZWBI9O4tz /RiW636TtmleH0wvlMuXrkosdpNNOroArovuo/sIIcfBMtVAfTboonouqBWge+BDTOim 34vZMMFdVIuEqqRbDx50nrwnax/C9rFCbmYML11Bsp5lMfvx9rcOlhVFbiPKXKs9evKP RQ== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 06/10] s390x: Add protected dump cap Date: Mon, 17 Oct 2022 08:38:18 +0000 Message-Id: <20221017083822.43118-7-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Q8Oa_0dlpRxg-jM6vlBPhwUqlcwwKnvc X-Proofpoint-ORIG-GUID: 5cGXWaiDzsH2Fwo1EdCdI_81odL_E3am X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_06,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=958 bulkscore=0 impostorscore=0 phishscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996734623100003 Content-Type: text/plain; charset="utf-8" Add a protected dump capability for later feature checking. Signed-off-by: Janosch Frank Reviewed-by: Steffen Eiden Reviewed-by: Thomas Huth Reviewed-by: Janis Schoetterl-Glausch --- target/s390x/kvm/kvm.c | 7 +++++++ target/s390x/kvm/kvm_s390x.h | 1 + 2 files changed, 8 insertions(+) diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 6a8dbadf7e..2ca0d46453 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -158,6 +158,7 @@ static int cap_hpage_1m; static int cap_vcpu_resets; static int cap_protected; static int cap_zpci_op; +static int cap_protected_dump; =20 static bool mem_op_storage_key_support; =20 @@ -364,6 +365,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) cap_vcpu_resets =3D kvm_check_extension(s, KVM_CAP_S390_VCPU_RESETS); cap_protected =3D kvm_check_extension(s, KVM_CAP_S390_PROTECTED); cap_zpci_op =3D kvm_check_extension(s, KVM_CAP_S390_ZPCI_OP); + cap_protected_dump =3D kvm_check_extension(s, KVM_CAP_S390_PROTECTED_D= UMP); =20 kvm_vm_enable_cap(s, KVM_CAP_S390_USER_SIGP, 0); kvm_vm_enable_cap(s, KVM_CAP_S390_VECTOR_REGISTERS, 0); @@ -2045,6 +2047,11 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *n= otifier, uint32_t sch, return kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick); } =20 +int kvm_s390_get_protected_dump(void) +{ + return cap_protected_dump; +} + int kvm_s390_get_ri(void) { return cap_ri; diff --git a/target/s390x/kvm/kvm_s390x.h b/target/s390x/kvm/kvm_s390x.h index aaae8570de..f9785564d0 100644 --- a/target/s390x/kvm/kvm_s390x.h +++ b/target/s390x/kvm/kvm_s390x.h @@ -26,6 +26,7 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_stat= e); void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu); int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu); int kvm_s390_get_hpage_1m(void); +int kvm_s390_get_protected_dump(void); int kvm_s390_get_ri(void); int kvm_s390_get_zpci_op(void); int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_clock); --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996731; cv=none; d=zohomail.com; s=zohoarc; b=OFqBRjVrY5t0SRTDq3p+1WYxrdKyhRJkM0KdTrpGI+MZZnlKKfp4/te1nuXGxPK5//dAfR2TxIF/NkpsmvcCNdvNsWCuRn2jkcyFOmpie7yCnFWpevYDydJKlwYiIbG/nhMIWbpjdAdmM0kdTvDX2SSf2EveF60KarxhHW3hVbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996731; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a077gisI0PRfl4lHg8aH5+QEZcajBoxLYKvG0LxFS8c=; b=TEOhGCufddLHUrvvH5O5E/ofM3Zsdt1L+HllxMf5cuLtl3N+QefJY74/nrguLXbFYx3leauTtRHRNxBdzYAOlhsBQg2Xnl45YNX/6GRLSY39IdwOyed0q9gHAX2lKFQCftu+Zw6chOB0b7k0K4hPp6OeUA0ykUrT4wtZuLC3knM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996731454326.05804153359156; Mon, 17 Oct 2022 01:52:11 -0700 (PDT) Received: from localhost ([::1]:33832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLqy-0001ij-8f for importer@patchew.org; Mon, 17 Oct 2022 04:52:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0007u8-Eu; Mon, 17 Oct 2022 04:39:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40728 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLev-0003fz-S4; Mon, 17 Oct 2022 04:39:45 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H7KSXZ021893; Mon, 17 Oct 2022 08:39:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86g5sfb0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:40 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H7V08Y003951; Mon, 17 Oct 2022 08:39:39 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86g5sfa5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:39 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8aiPX009140; Mon, 17 Oct 2022 08:39:37 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma01fra.de.ibm.com with ESMTP id 3k7mg8t0je-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:37 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dYmD43057494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:34 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C88E1A4051; Mon, 17 Oct 2022 08:39:34 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6360A404D; Mon, 17 Oct 2022 08:39:33 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:33 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=a077gisI0PRfl4lHg8aH5+QEZcajBoxLYKvG0LxFS8c=; b=ESj/vg7sbbspig+ILdeT0AYcAmvgdYbhxBuo8/L+lFUWwHq7fM9mTUfmlm9dsqVyVpWF xTT306suawg7iEuiP38/svjRNc5TBjYay4GFmbyBZjXlFTq2hPN4v/p9jS/+4ZJxXY0t M23rLknGsITvLc6+kc/QSwx6Z1IJBj39TGMi0glEJ66QYKT7EtI3tjd/OXJ7m7w102K+ lGNfWTH/q0pI7T5PsrJR+VqERwFXOjsslPN3lwlBI5WLk4/SI072Ph1CgUkjaZPqgyNy GkKmjCeZv3/YZQTumonnfygy9FkUcYLPeT8F3z8Jerk6MJSynvKeT5dRhi/lY6p3urm5 uA== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 07/10] s390x: Introduce PV query interface Date: Mon, 17 Oct 2022 08:38:19 +0000 Message-Id: <20221017083822.43118-8-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: kveSHc-jMFbli8pF-Yyob772Hqg7fQjj X-Proofpoint-ORIG-GUID: irCJ5F0-qYue1wOEl6QcdHz2ZEnbu5_Z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_06,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 impostorscore=0 phishscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996732600100001 Content-Type: text/plain; charset="utf-8" Introduce an interface over which we can get information about UV data. Signed-off-by: Janosch Frank Reviewed-by: Steffen Eiden Reviewed-by: Janis Schoetterl-Glausch Acked-by: Thomas Huth --- hw/s390x/pv.c | 61 ++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 6 ++++ include/hw/s390x/pv.h | 10 +++++++ 3 files changed, 77 insertions(+) diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index 401b63d6cb..4c012f2eeb 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -20,6 +20,11 @@ #include "exec/confidential-guest-support.h" #include "hw/s390x/ipl.h" #include "hw/s390x/pv.h" +#include "target/s390x/kvm/kvm_s390x.h" + +static bool info_valid; +static struct kvm_s390_pv_info_vm info_vm; +static struct kvm_s390_pv_info_dump info_dump; =20 static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data) { @@ -56,6 +61,42 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdna= me, void *data) } \ } =20 +int s390_pv_query_info(void) +{ + struct kvm_s390_pv_info info =3D { + .header.id =3D KVM_PV_INFO_VM, + .header.len_max =3D sizeof(info.header) + sizeof(info.vm), + }; + int rc; + + /* Info API's first user is dump so they are bundled */ + if (!kvm_s390_get_protected_dump()) { + return 0; + } + + rc =3D s390_pv_cmd(KVM_PV_INFO, &info); + if (rc) { + error_report("KVM PV INFO cmd %x failed: %s", + info.header.id, strerror(-rc)); + return rc; + } + memcpy(&info_vm, &info.vm, sizeof(info.vm)); + + info.header.id =3D KVM_PV_INFO_DUMP; + info.header.len_max =3D sizeof(info.header) + sizeof(info.dump); + rc =3D s390_pv_cmd(KVM_PV_INFO, &info); + if (rc) { + error_report("KVM PV INFO cmd %x failed: %s", + info.header.id, strerror(-rc)); + return rc; + } + + memcpy(&info_dump, &info.dump, sizeof(info.dump)); + info_valid =3D true; + + return rc; +} + int s390_pv_vm_enable(void) { return s390_pv_cmd(KVM_PV_ENABLE, NULL); @@ -114,6 +155,26 @@ void s390_pv_inject_reset_error(CPUState *cs) env->regs[r1 + 1] =3D DIAG_308_RC_INVAL_FOR_PV; } =20 +uint64_t kvm_s390_pv_dmp_get_size_cpu(void) +{ + return info_dump.dump_cpu_buffer_len; +} + +uint64_t kvm_s390_pv_dmp_get_size_completion_data(void) +{ + return info_dump.dump_config_finalize_len; +} + +uint64_t kvm_s390_pv_dmp_get_size_mem_state(void) +{ + return info_dump.dump_config_mem_buffer_per_1m; +} + +bool kvm_s390_pv_info_basic_valid(void) +{ + return info_valid; +} + #define TYPE_S390_PV_GUEST "s390-pv-guest" OBJECT_DECLARE_SIMPLE_TYPE(S390PVGuest, S390_PV_GUEST) =20 diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 03855c7231..1cc20d8717 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -366,6 +366,12 @@ static int s390_machine_protect(S390CcwMachineState *m= s) =20 ms->pv =3D true; =20 + /* Will return 0 if API is not available since it's not vital */ + rc =3D s390_pv_query_info(); + if (rc) { + goto out_err; + } + /* Set SE header and unpack */ rc =3D s390_ipl_prepare_pv_header(); if (rc) { diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h index 1f1f545bfc..e5ea0eca16 100644 --- a/include/hw/s390x/pv.h +++ b/include/hw/s390x/pv.h @@ -38,6 +38,7 @@ static inline bool s390_is_pv(void) return ccw->pv; } =20 +int s390_pv_query_info(void); int s390_pv_vm_enable(void); void s390_pv_vm_disable(void); int s390_pv_set_sec_parms(uint64_t origin, uint64_t length); @@ -46,8 +47,13 @@ void s390_pv_prep_reset(void); int s390_pv_verify(void); void s390_pv_unshare(void); void s390_pv_inject_reset_error(CPUState *cs); +uint64_t kvm_s390_pv_dmp_get_size_cpu(void); +uint64_t kvm_s390_pv_dmp_get_size_mem_state(void); +uint64_t kvm_s390_pv_dmp_get_size_completion_data(void); +bool kvm_s390_pv_info_basic_valid(void); #else /* CONFIG_KVM */ static inline bool s390_is_pv(void) { return false; } +static inline int s390_pv_query_info(void) { return 0; } static inline int s390_pv_vm_enable(void) { return 0; } static inline void s390_pv_vm_disable(void) {} static inline int s390_pv_set_sec_parms(uint64_t origin, uint64_t length) = { return 0; } @@ -56,6 +62,10 @@ static inline void s390_pv_prep_reset(void) {} static inline int s390_pv_verify(void) { return 0; } static inline void s390_pv_unshare(void) {} static inline void s390_pv_inject_reset_error(CPUState *cs) {}; +static inline uint64_t kvm_s390_pv_dmp_get_size_cpu(void) { return 0; } +static inline uint64_t kvm_s390_pv_dmp_get_size_mem_state(void) { return 0= ; } +static inline uint64_t kvm_s390_pv_dmp_get_size_completion_data(void) { re= turn 0; } +static inline bool kvm_s390_pv_info_basic_valid(void) { return false; } #endif /* CONFIG_KVM */ =20 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp); --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996748; cv=none; d=zohomail.com; s=zohoarc; b=Nd+aBn26PDFP3btbywNjX583aQGD9EsE9eblUplEEx+BKIoG6IM9QtWYXn1ntHckdlHgtTA/zQEV1O8UbguJ+jRiOKzUJ5HdaK2pD8+E7fWEzzzhThPdyliu0BPfJd2zlMxq3OzNWO10wa9zj6wDCs9YXP2BKyYbV1hz1S3Oxm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996748; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IhmeEv/ieKKX9BDpf9FlbI7LhSj42bj2S+4jNMMsFi4=; b=WUASUHJzTYdUd11cphKCTEVaSRMg/XqXU5jIsIkPdtMQPYUMf3lOcWA1HY49NOZZI88o70DoSFb86e/KmSPIzvkvF/NIVdozkrUQcI6hLGTamNkWVK4ErnqFNi6YLI3g62t/aaOcCTWN4w2zkbL1Kq6sUNXRMNHm78s9WyDwY8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996748397421.9862518952423; Mon, 17 Oct 2022 01:52:28 -0700 (PDT) Received: from localhost ([::1]:43510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLrH-0002Cq-42 for importer@patchew.org; Mon, 17 Oct 2022 04:52:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf1-0007yY-W8; Mon, 17 Oct 2022 04:39:48 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:1050 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0003gJ-F0; Mon, 17 Oct 2022 04:39:47 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H8cAvv001565; Mon, 17 Oct 2022 08:39:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86g5sfbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:41 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H79F99004999; Mon, 17 Oct 2022 08:39:41 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86g5sfat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:41 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8bB3c007755; Mon, 17 Oct 2022 08:39:39 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 3k7mg920ja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:39 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8Yex443123124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:34:40 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 25790A4051; Mon, 17 Oct 2022 08:39:36 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EE905A404D; Mon, 17 Oct 2022 08:39:34 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:34 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=IhmeEv/ieKKX9BDpf9FlbI7LhSj42bj2S+4jNMMsFi4=; b=IiRoHUidp4BFzVXjFZhRYde3dG8PDzKXP4B3VmOd/NYO2cpZxZqsDZjMZcgn8Z5TCLLg I07phSjyVssOStNnd3Xq2Tafx5OaO9e8LXP4XCcKqsNdYUIPcv8ish+89WVYn8hnqrEI Rnm8zfNSsULN8STj3AFrZtYYFYJqJevXKSityfws5x3hb1FZ5eLSFaib5QzJ33hOpYUO pkkJvtrGeY1kZqv6lGeMRs741YClRjWrwmZREX6eTRXwfWztAksTk/DcO7Hoo0FQoB5J lPSo/tNsniwR8kPiBP/JapKIS9kuFwWBpP3OG0c45rifZn6JeZcIH/SnQ9KLTP+T6gQf Lw== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 08/10] RFC: elf.h changes Date: Mon, 17 Oct 2022 08:38:20 +0000 Message-Id: <20221017083822.43118-9-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: XKSeTQC8yyBzlNbPruq4v1V6uRqA8sby X-Proofpoint-ORIG-GUID: 7phwr_DyRoKKL6UM_1VvhfDnuFZKxFaE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_06,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=831 bulkscore=0 impostorscore=0 phishscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996748659100001 Content-Type: text/plain; charset="utf-8" Adding two s390x note types Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth --- include/elf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/elf.h b/include/elf.h index 3d6b9062c0..8bf1e72720 100644 --- a/include/elf.h +++ b/include/elf.h @@ -1650,6 +1650,8 @@ typedef struct elf64_shdr { #define NT_TASKSTRUCT 4 #define NT_AUXV 6 #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/= common.h */ +#define NT_S390_PV_CPU_DATA 0x30e /* s390 protvirt cpu dump data */ +#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation */ #define NT_S390_GS_CB 0x30b /* s390 guarded storage registers = */ #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */ #define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 (low= er half) */ --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996840; cv=none; d=zohomail.com; s=zohoarc; b=W13mMfZZBnfoFvukhpgy2KCPjoVzvRUvPMV1nuyicJeW9HS3sW15RhwL1W1lD7wNnfGh6b9x1K2+2ioMoejkQdGBSlyWnKiaQz/+/Ith0AhGhMPsXXOir1CAuCc91sSSoTn1FAllz4BaUUVsj97z9z/90O9W+8gpzhCXPwd1b/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996840; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=42tAQUP85Z8fwbCa6bQy5Dxe9ZyGCzu20YSf8Mu3uSA=; b=hrS5AK6Z3Ww0J2WyF1uioHXDSB5zxPtUj9Okf/qziOHD5LZGXdiawdQW1XzJ6pBz8SVH49lNkXvkuUK/I9EqOIet8DespMDqX8LQGyuSU4XhEPgEd/qVP5Nd4QOW8D2QVwWntlAruU5LjLeFcq+KiRF4knKUSlfHSBReuRt5QnQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996840573255.62212263763922; Mon, 17 Oct 2022 01:54:00 -0700 (PDT) Received: from localhost ([::1]:55310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLsl-00060R-Df for importer@patchew.org; Mon, 17 Oct 2022 04:53:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf2-0007yc-65; Mon, 17 Oct 2022 04:39:48 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:9058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0003gP-FG; Mon, 17 Oct 2022 04:39:47 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H7oQwV016588; Mon, 17 Oct 2022 08:39:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86hk98pu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:42 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H8bmdX000618; Mon, 17 Oct 2022 08:39:42 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86hk98p1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:42 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8bdf0003448; Mon, 17 Oct 2022 08:39:40 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06fra.de.ibm.com with ESMTP id 3k7m4ja19n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:40 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dbwb262666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:37 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DFC0A4040; Mon, 17 Oct 2022 08:39:37 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BC01A404D; Mon, 17 Oct 2022 08:39:36 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:36 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=42tAQUP85Z8fwbCa6bQy5Dxe9ZyGCzu20YSf8Mu3uSA=; b=M5sVe0/GtxM5OzoOVbr74w//OYXNsPjHSlJtA4zwdhbvUxhtXX5EyzjCJZdhEYhLTtoo CeEAfOUc1zNMYEeRgkT3mYQeQ8IWeANte1bCR5h6Q6eoqD3smuTFvfKwwpk0GWe0V0r2 HCofDWLMrDZp7MjpBJSX7c7H7AjG1TSKuO3fFolN6rPoIAvg4HxBgqELFinzTCNGK48B WNqBfFV6D9EOno42BQGzIx/f+icv4PFaxlkOgLtTcKyx+YJLtpAzhnTMrxDta2Ar4Epl b/D4pynoMIe3vjHjg7yB11s2oJKhseDywIkiwlcxaaJubXkD4aOAK4lVEhvxO7FPkNLF 1g== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 09/10] s390x: Add KVM PV dump interface Date: Mon, 17 Oct 2022 08:38:21 +0000 Message-Id: <20221017083822.43118-10-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: TOauBdeJxuI0l-RVfA_y2jErYOFlkHow X-Proofpoint-ORIG-GUID: lS0GgEpEGp_8p1FDtNjflVVpIMH_Y8Wn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_06,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 spamscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170046 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996841444100001 Content-Type: text/plain; charset="utf-8" Let's add a few bits of code which hide the new KVM PV dump API from us via new functions. Signed-off-by: Janosch Frank Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Steffen Eiden --- hw/s390x/pv.c | 51 +++++++++++++++++++++++++++++++++++++++++++ include/hw/s390x/pv.h | 9 ++++++++ 2 files changed, 60 insertions(+) diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index 4c012f2eeb..728ba24547 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -175,6 +175,57 @@ bool kvm_s390_pv_info_basic_valid(void) return info_valid; } =20 +static int s390_pv_dump_cmd(uint64_t subcmd, uint64_t uaddr, uint64_t gadd= r, + uint64_t len) +{ + struct kvm_s390_pv_dmp dmp =3D { + .subcmd =3D subcmd, + .buff_addr =3D uaddr, + .buff_len =3D len, + .gaddr =3D gaddr, + }; + int ret; + + ret =3D s390_pv_cmd(KVM_PV_DUMP, (void *)&dmp); + if (ret) { + error_report("KVM DUMP command %ld failed", subcmd); + } + return ret; +} + +int kvm_s390_dump_cpu(S390CPU *cpu, void *buff) +{ + struct kvm_s390_pv_dmp dmp =3D { + .subcmd =3D KVM_PV_DUMP_CPU, + .buff_addr =3D (uint64_t)buff, + .gaddr =3D 0, + .buff_len =3D info_dump.dump_cpu_buffer_len, + }; + struct kvm_pv_cmd pv =3D { + .cmd =3D KVM_PV_DUMP, + .data =3D (uint64_t)&dmp, + }; + + return kvm_vcpu_ioctl(CPU(cpu), KVM_S390_PV_CPU_COMMAND, &pv); +} + +int kvm_s390_dump_init(void) +{ + return s390_pv_dump_cmd(KVM_PV_DUMP_INIT, 0, 0, 0); +} + +int kvm_s390_dump_mem_state(uint64_t gaddr, size_t len, void *dest) +{ + return s390_pv_dump_cmd(KVM_PV_DUMP_CONFIG_STOR_STATE, (uint64_t)dest, + gaddr, len); +} + +int kvm_s390_dump_completion_data(void *buff) +{ + return s390_pv_dump_cmd(KVM_PV_DUMP_COMPLETE, (uint64_t)buff, 0, + info_dump.dump_config_finalize_len); +} + #define TYPE_S390_PV_GUEST "s390-pv-guest" OBJECT_DECLARE_SIMPLE_TYPE(S390PVGuest, S390_PV_GUEST) =20 diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h index e5ea0eca16..3164006674 100644 --- a/include/hw/s390x/pv.h +++ b/include/hw/s390x/pv.h @@ -51,6 +51,10 @@ uint64_t kvm_s390_pv_dmp_get_size_cpu(void); uint64_t kvm_s390_pv_dmp_get_size_mem_state(void); uint64_t kvm_s390_pv_dmp_get_size_completion_data(void); bool kvm_s390_pv_info_basic_valid(void); +int kvm_s390_dump_init(void); +int kvm_s390_dump_cpu(S390CPU *cpu, void *buff); +int kvm_s390_dump_mem_state(uint64_t addr, size_t len, void *dest); +int kvm_s390_dump_completion_data(void *buff); #else /* CONFIG_KVM */ static inline bool s390_is_pv(void) { return false; } static inline int s390_pv_query_info(void) { return 0; } @@ -66,6 +70,11 @@ static inline uint64_t kvm_s390_pv_dmp_get_size_cpu(void= ) { return 0; } static inline uint64_t kvm_s390_pv_dmp_get_size_mem_state(void) { return 0= ; } static inline uint64_t kvm_s390_pv_dmp_get_size_completion_data(void) { re= turn 0; } static inline bool kvm_s390_pv_info_basic_valid(void) { return false; } +static inline int kvm_s390_dump_init(void) { return 0; } +static inline int kvm_s390_dump_cpu(S390CPU *cpu, void *buff, size_t len) = { return 0; } +static inline int kvm_s390_dump_mem_state(uint64_t addr, size_t len, + void *dest) { return 0; } +static inline int kvm_s390_dump_completion_data(void *buff) { return 0; } #endif /* CONFIG_KVM */ =20 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp); --=20 2.34.1 From nobody Thu May 16 15:33:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1665996756; cv=none; d=zohomail.com; s=zohoarc; b=bpLjpLRH7P7N8nEqrMPxflPQaz5s/pdYw2jKeWdFQQKFqgEevCkQF29wSMWTXiFc04kW8fn5DSqPXto5DAQhooJ7UL6VIRpRC018m/Z3Z396ASuY1jVe5dR3RSwhV8oEAA8D1FHkBhoiFiqxi+Ycigiee7TxLNtDwz/lvIfjJeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665996756; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SWbZ7HJ/5O/laHrYC9DJdoVQc8ZuhfD8aMa6RHnEcG0=; b=WBnD6GXkRwY8OWr31gmqkXbT6nt56aqo/iQcic0sE4fNzuaa+hFrG8XObnwCkfCQ2RtFUo5++v4I6JhzyTW2WVjHDX/p8f+p7lZxKaO/pbheUjEBcZyRj9Crv1E3br/nZxs86jFqYp/yvcFbPoSw7/4Qu9OWSDOcNbsJjodBIoY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665996756534552.9451355555335; Mon, 17 Oct 2022 01:52:36 -0700 (PDT) Received: from localhost ([::1]:43520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okLrL-0002St-VL for importer@patchew.org; Mon, 17 Oct 2022 04:52:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf8-0008Gf-50; Mon, 17 Oct 2022 04:39:58 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:63822 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okLf0-0003gT-H4; Mon, 17 Oct 2022 04:39:53 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29H7BUDJ032162; Mon, 17 Oct 2022 08:39:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86x8953h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:44 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29H8aWGv009468; Mon, 17 Oct 2022 08:39:43 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3k86x8952g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:43 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29H8bALO007748; Mon, 17 Oct 2022 08:39:42 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04fra.de.ibm.com with ESMTP id 3k7mg920jd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 08:39:41 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29H8dcDt41353514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 08:39:38 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFA46A4040; Mon, 17 Oct 2022 08:39:38 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94263A404D; Mon, 17 Oct 2022 08:39:37 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Oct 2022 08:39:37 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=SWbZ7HJ/5O/laHrYC9DJdoVQc8ZuhfD8aMa6RHnEcG0=; b=O5CLTPu9a9ApZ1zMmYnVWHIobcRtOsjnJ4xl21WQEG9JKLmBE4MX1iOiZZL+x6qWDXxT GxIEQGW7ZpIpZ6xopqPuLZOQnDhfftALssRTOTzKvbRAaq8dvNly/DV8bXxH8EsHwGGT mM6u1ADV4wwxSeXWFHBdX4tiJOg6B1UV0tmh6soRbf8CUf+frOATp13IeE4Eq0sXtuoM Aeis4NOgq0JE9JIoc45lGSMeY/6+i5kIUWbE7YjzB8PShWBzuec8PohHKf1jI1GBJ9we A0+TtASZWoLFdwdBt3UWdpELB4s1ATDY7w6jr0MoLUf5JcY5luoTx7jO0O+Ka70o/JnC EQ== From: Janosch Frank To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com, mhartmay@linux.ibm.com, borntraeger@linux.ibm.com, imbrenda@linux.ibm.com, pasic@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, qemu-s390x@nongnu.org, seiden@linux.ibm.com, scgl@linux.ibm.com Subject: [PATCH v6 10/10] s390x: pv: Add dump support Date: Mon, 17 Oct 2022 08:38:22 +0000 Message-Id: <20221017083822.43118-11-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017083822.43118-1-frankja@linux.ibm.com> References: <20221017083822.43118-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: dDGjDOSQGr6YSswiremxwDj7JhABu0sc X-Proofpoint-GUID: A758_vVGN9AAR7eWXamEqBEVCjg9otr9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_06,2022-10-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 spamscore=0 adultscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 bulkscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170049 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=frankja@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1665996756890100001 Content-Type: text/plain; charset="utf-8" Sometimes dumping a guest from the outside is the only way to get the data that is needed. This can be the case if a dumping mechanism like KDUMP hasn't been configured or data needs to be fetched at a specific point. Dumping a protected guest from the outside without help from fw/hw doesn't yield sufficient data to be useful. Hence we now introduce PV dump support. The PV dump support works by integrating the firmware into the dump process. New Ultravisor calls are used to initiate the dump process, dump cpu data, dump memory state and lastly complete the dump process. The UV calls are exposed by KVM via the new KVM_PV_DUMP command and its subcommands. The guest's data is fully encrypted and can only be decrypted by the entity that owns the customer communication key for the dumped guest. Also dumping needs to be allowed via a flag in the SE header. On the QEMU side of things we store the PV dump data in the newly introduced architecture ELF sections (storage state and completion data) and the cpu notes (for cpu dump data). Users can use the zgetdump tool to convert the encrypted QEMU dump to an unencrypted one. Signed-off-by: Janosch Frank Reviewed-by: Steffen Eiden --- dump/dump.c | 12 +- include/sysemu/dump.h | 5 + target/s390x/arch_dump.c | 262 +++++++++++++++++++++++++++++++++++---- 3 files changed, 246 insertions(+), 33 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index b5bc4f7119..9feaf0e238 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -708,9 +708,9 @@ static void dump_begin(DumpState *s, Error **errp) write_elf_notes(s, errp); } =20 -static int64_t dump_filtered_memblock_size(GuestPhysBlock *block, - int64_t filter_area_start, - int64_t filter_area_length) +int64_t dump_filtered_memblock_size(GuestPhysBlock *block, + int64_t filter_area_start, + int64_t filter_area_length) { int64_t size, left, right; =20 @@ -728,9 +728,9 @@ static int64_t dump_filtered_memblock_size(GuestPhysBlo= ck *block, return size; } =20 -static int64_t dump_filtered_memblock_start(GuestPhysBlock *block, - int64_t filter_area_start, - int64_t filter_area_length) +int64_t dump_filtered_memblock_start(GuestPhysBlock *block, + int64_t filter_area_start, + int64_t filter_area_length) { if (filter_area_length) { /* return -1 if the block is not within filter area */ diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 38ccac7190..4ffed0b659 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -215,4 +215,9 @@ typedef struct DumpState { uint16_t cpu_to_dump16(DumpState *s, uint16_t val); uint32_t cpu_to_dump32(DumpState *s, uint32_t val); uint64_t cpu_to_dump64(DumpState *s, uint64_t val); + +int64_t dump_filtered_memblock_size(GuestPhysBlock *block, int64_t filter_= area_start, + int64_t filter_area_length); +int64_t dump_filtered_memblock_start(GuestPhysBlock *block, int64_t filter= _area_start, + int64_t filter_area_length); #endif diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c index f60a14920d..a2329141e8 100644 --- a/target/s390x/arch_dump.c +++ b/target/s390x/arch_dump.c @@ -12,11 +12,13 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/units.h" #include "cpu.h" #include "s390x-internal.h" #include "elf.h" #include "sysemu/dump.h" - +#include "hw/s390x/pv.h" +#include "kvm/kvm_s390x.h" =20 struct S390xUserRegsStruct { uint64_t psw[2]; @@ -76,9 +78,16 @@ typedef struct noteStruct { uint64_t todcmp; uint32_t todpreg; uint64_t ctrs[16]; + uint8_t dynamic[1]; /* + * Would be a flexible array member, if + * that was legal inside a union. Real + * size comes from PV info interface. + */ } contents; } QEMU_PACKED Note; =20 +static bool pv_dump_initialized; + static void s390x_write_elf64_prstatus(Note *note, S390CPU *cpu, int id) { int i; @@ -177,28 +186,39 @@ static void s390x_write_elf64_prefix(Note *note, S390= CPU *cpu, int id) note->contents.prefix =3D cpu_to_be32((uint32_t)(cpu->env.psa)); } =20 +static void s390x_write_elf64_pv(Note *note, S390CPU *cpu, int id) +{ + note->hdr.n_type =3D cpu_to_be32(NT_S390_PV_CPU_DATA); + if (!pv_dump_initialized) { + return; + } + kvm_s390_dump_cpu(cpu, ¬e->contents.dynamic); +} =20 typedef struct NoteFuncDescStruct { int contents_size; + uint64_t (*note_size_func)(void); /* NULL for non-dynamic sized conten= ts */ void (*note_contents_func)(Note *note, S390CPU *cpu, int id); + bool pvonly; } NoteFuncDesc; =20 static const NoteFuncDesc note_core[] =3D { - {sizeof_field(Note, contents.prstatus), s390x_write_elf64_prstatus}, - {sizeof_field(Note, contents.fpregset), s390x_write_elf64_fpregset}, - { 0, NULL} + {sizeof_field(Note, contents.prstatus), NULL, s390x_write_elf64_prstat= us, false}, + {sizeof_field(Note, contents.fpregset), NULL, s390x_write_elf64_fpregs= et, false}, + { 0, NULL, NULL, false} }; =20 static const NoteFuncDesc note_linux[] =3D { - {sizeof_field(Note, contents.prefix), s390x_write_elf64_prefix}, - {sizeof_field(Note, contents.ctrs), s390x_write_elf64_ctrs}, - {sizeof_field(Note, contents.timer), s390x_write_elf64_timer}, - {sizeof_field(Note, contents.todcmp), s390x_write_elf64_todcmp}, - {sizeof_field(Note, contents.todpreg), s390x_write_elf64_todpreg}, - {sizeof_field(Note, contents.vregslo), s390x_write_elf64_vregslo}, - {sizeof_field(Note, contents.vregshi), s390x_write_elf64_vregshi}, - {sizeof_field(Note, contents.gscb), s390x_write_elf64_gscb}, - { 0, NULL} + {sizeof_field(Note, contents.prefix), NULL, s390x_write_elf64_prefix= , false}, + {sizeof_field(Note, contents.ctrs), NULL, s390x_write_elf64_ctrs, = false}, + {sizeof_field(Note, contents.timer), NULL, s390x_write_elf64_timer,= false}, + {sizeof_field(Note, contents.todcmp), NULL, s390x_write_elf64_todcmp= , false}, + {sizeof_field(Note, contents.todpreg), NULL, s390x_write_elf64_todpre= g, false}, + {sizeof_field(Note, contents.vregslo), NULL, s390x_write_elf64_vregsl= o, false}, + {sizeof_field(Note, contents.vregshi), NULL, s390x_write_elf64_vregsh= i, false}, + {sizeof_field(Note, contents.gscb), NULL, s390x_write_elf64_gscb, = false}, + {0, kvm_s390_pv_dmp_get_size_cpu, s390x_write_elf64_pv, true}, + { 0, NULL, NULL, false} }; =20 static int s390x_write_elf64_notes(const char *note_name, @@ -207,22 +227,41 @@ static int s390x_write_elf64_notes(const char *note_n= ame, DumpState *s, const NoteFuncDesc *funcs) { - Note note; + Note note, *notep; const NoteFuncDesc *nf; - int note_size; + int note_size, content_size; int ret =3D -1; =20 assert(strlen(note_name) < sizeof(note.name)); =20 for (nf =3D funcs; nf->note_contents_func; nf++) { - memset(¬e, 0, sizeof(note)); - note.hdr.n_namesz =3D cpu_to_be32(strlen(note_name) + 1); - note.hdr.n_descsz =3D cpu_to_be32(nf->contents_size); - g_strlcpy(note.name, note_name, sizeof(note.name)); - (*nf->note_contents_func)(¬e, cpu, id); + notep =3D ¬e; + if (nf->pvonly && !s390_is_pv()) { + continue; + } =20 - note_size =3D sizeof(note) - sizeof(note.contents) + nf->contents_= size; - ret =3D f(¬e, note_size, s); + content_size =3D nf->note_size_func ? nf->note_size_func() : nf->c= ontents_size; + note_size =3D sizeof(note) - sizeof(notep->contents) + content_siz= e; + + /* Notes with dynamic sizes need to allocate a note */ + if (nf->note_size_func) { + notep =3D g_malloc(note_size); + } + + memset(notep, 0, sizeof(note)); + + /* Setup note header data */ + notep->hdr.n_descsz =3D cpu_to_be32(content_size); + notep->hdr.n_namesz =3D cpu_to_be32(strlen(note_name) + 1); + g_strlcpy(notep->name, note_name, sizeof(notep->name)); + + /* Get contents and write them out */ + (*nf->note_contents_func)(notep, cpu, id); + ret =3D f(notep, note_size, s); + + if (nf->note_size_func) { + g_free(notep); + } =20 if (ret < 0) { return -1; @@ -247,13 +286,179 @@ int s390_cpu_write_elf64_note(WriteCoreDumpFunction = f, CPUState *cs, return s390x_write_elf64_notes("LINUX", f, cpu, cpuid, s, note_linux); } =20 +/* PV dump section size functions */ +static uint64_t get_mem_state_size_from_len(uint64_t len) +{ + return (len / (MiB)) * kvm_s390_pv_dmp_get_size_mem_state(); +} + +static uint64_t get_size_mem_state(DumpState *s) +{ + return get_mem_state_size_from_len(s->total_size); +} + +static uint64_t get_size_completion_data(DumpState *s) +{ + return kvm_s390_pv_dmp_get_size_completion_data(); +} + +/* PV dump section data functions*/ +static int get_data_completion(DumpState *s, uint8_t *buff) +{ + int rc; + + if (!pv_dump_initialized) { + return 0; + } + rc =3D kvm_s390_dump_completion_data(buff); + if (!rc) { + pv_dump_initialized =3D false; + } + return rc; +} + +static int get_mem_state(DumpState *s, uint8_t *buff) +{ + int64_t memblock_size, memblock_start; + GuestPhysBlock *block; + uint64_t off; + int rc; + + QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { + memblock_start =3D dump_filtered_memblock_start(block, s->filter_a= rea_begin, + s->filter_area_lengt= h); + if (memblock_start =3D=3D -1) { + continue; + } + + memblock_size =3D dump_filtered_memblock_size(block, s->filter_are= a_begin, + s->filter_area_length); + + off =3D get_mem_state_size_from_len(block->target_start); + + rc =3D kvm_s390_dump_mem_state(block->target_start, + get_mem_state_size_from_len(memblock_= size), + buff + off); + if (rc) { + return rc; + } + } + + return 0; +} + +static struct sections { + uint64_t (*sections_size_func)(DumpState *s); + int (*sections_contents_func)(DumpState *s, uint8_t *buff); + char sctn_str[12]; +} sections[] =3D { + { get_size_mem_state, get_mem_state, "pv_mem_meta"}, + { get_size_completion_data, get_data_completion, "pv_compl"}, + {NULL , NULL, ""} +}; + +static uint64_t arch_sections_write_hdr(DumpState *s, uint8_t *buff) +{ + Elf64_Shdr *shdr =3D (void *)buff; + struct sections *sctn =3D sections; + uint64_t off =3D s->section_offset; + + if (!pv_dump_initialized) { + return 0; + } + + for (; sctn->sections_size_func; off +=3D shdr->sh_size, sctn++, shdr+= +) { + memset(shdr, 0, sizeof(*shdr)); + shdr->sh_type =3D SHT_PROGBITS; + shdr->sh_offset =3D off; + shdr->sh_size =3D sctn->sections_size_func(s); + shdr->sh_name =3D s->string_table_buf->len; + g_array_append_vals(s->string_table_buf, sctn->sctn_str, sizeof(sc= tn->sctn_str)); + } + + return (uintptr_t)shdr - (uintptr_t)buff; +} + + +/* Add arch specific number of sections and their respective sizes */ +static void arch_sections_add(DumpState *s) +{ + struct sections *sctn =3D sections; + + /* + * We only do a PV dump if we are running a PV guest, KVM supports + * the dump API and we got valid dump length information. + */ + if (!s390_is_pv() || !kvm_s390_get_protected_dump() || + !kvm_s390_pv_info_basic_valid()) { + return; + } + + /* + * Start the UV dump process by doing the initialize dump call via + * KVM as the proxy. + */ + if (!kvm_s390_dump_init()) { + pv_dump_initialized =3D true; + } else { + /* + * Dump init failed, maybe the guest owner disabled dumping. + * We'll continue the non-PV dump process since this is no + * reason to crash qemu. + */ + return; + } + + for (; sctn->sections_size_func; sctn++) { + s->shdr_num +=3D 1; + s->elf_section_data_size +=3D sctn->sections_size_func(s); + } +} + +/* + * After the PV dump has been initialized, the CPU data has been + * fetched and memory has been dumped, we need to grab the tweak data + * and the completion data. + */ +static int arch_sections_write(DumpState *s, uint8_t *buff) +{ + struct sections *sctn =3D sections; + int rc; + + if (!pv_dump_initialized) { + return -EINVAL; + } + + for (; sctn->sections_size_func; sctn++) { + rc =3D sctn->sections_contents_func(s, buff); + buff +=3D sctn->sections_size_func(s); + if (rc) { + return rc; + } + } + return 0; +} + int cpu_get_dump_info(ArchDumpInfo *info, const struct GuestPhysBlockList *guest_phys_blocks) { info->d_machine =3D EM_S390; info->d_endian =3D ELFDATA2MSB; info->d_class =3D ELFCLASS64; - + /* + * This is evaluated for each dump so we can freely switch + * between PV and non-PV. + */ + if (s390_is_pv() && kvm_s390_get_protected_dump() && + kvm_s390_pv_info_basic_valid()) { + info->arch_sections_add_fn =3D *arch_sections_add; + info->arch_sections_write_hdr_fn =3D *arch_sections_write_hdr; + info->arch_sections_write_fn =3D *arch_sections_write; + } else { + info->arch_sections_add_fn =3D NULL; + info->arch_sections_write_hdr_fn =3D NULL; + info->arch_sections_write_fn =3D NULL; + } return 0; } =20 @@ -261,7 +466,7 @@ ssize_t cpu_get_note_size(int class, int machine, int n= r_cpus) { int name_size =3D 8; /* "LINUX" or "CORE" + pad */ size_t elf_note_size =3D 0; - int note_head_size; + int note_head_size, content_size; const NoteFuncDesc *nf; =20 assert(class =3D=3D ELFCLASS64); @@ -270,12 +475,15 @@ ssize_t cpu_get_note_size(int class, int machine, int= nr_cpus) note_head_size =3D sizeof(Elf64_Nhdr); =20 for (nf =3D note_core; nf->note_contents_func; nf++) { - elf_note_size =3D elf_note_size + note_head_size + name_size + - nf->contents_size; + elf_note_size =3D elf_note_size + note_head_size + name_size + nf-= >contents_size; } for (nf =3D note_linux; nf->note_contents_func; nf++) { + if (nf->pvonly && !s390_is_pv()) { + continue; + } + content_size =3D nf->contents_size ? nf->contents_size : nf->note_= size_func(); elf_note_size =3D elf_note_size + note_head_size + name_size + - nf->contents_size; + content_size; } =20 return (elf_note_size) * nr_cpus; --=20 2.34.1