From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774662; cv=none; d=zohomail.com; s=zohoarc; b=SOJDU99Zg7qQHroqxCyjKGXNiKHy3i3RY26R11aqoiGPOAqx6CwdZwsY49NQecJYzZtkwrlyl/52FJTetf4wSO4wTpmzyUMtvInysmbH3+WWoOnmmHONDlZ+5E4tuZHnqh1c8mDgnas+Ih4OWURqQwVgn68HM6jrW5VBOLsDCH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774662; 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=YB4V5ihMQ6DA/f+0fE4sJLzVdNzD5DFNFZBuoZGA7ts=; b=Z3qdtFPBm4prA+pUvmK05OplOml56A6lVqX0vZ393HzP6tbO5B5fqm0nbPWh+op4XTNTKTqSn8g4Z1PRtwn/LgQLAvFaVKnqAy8Sbb4Dvw7sw5T+ZS4z6nqvnMWXCr5MQzNWg+QrVEg9tL9xWey//inTOY44jz9lNFjUOO9x7zU= 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+importer2=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 1666774662511806.8612607968945; Wed, 26 Oct 2022 01:57:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDE-0001qK-Cg; Wed, 26 Oct 2022 04:56:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCZ-0007Lv-Jm for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:55:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCX-0000JQ-2F for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:55:55 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-hZbhxJwhM8qLRdSaA7sJcA-1; Wed, 26 Oct 2022 04:55:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B1E086EB2F; Wed, 26 Oct 2022 08:55:48 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20CB22166B2B; Wed, 26 Oct 2022 08:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774552; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YB4V5ihMQ6DA/f+0fE4sJLzVdNzD5DFNFZBuoZGA7ts=; b=bic26UrVdDGRVqqoYYilyAGd7V+7pRfRZ19qUrhqmANXDtNYXpkJALKHMfZjLtcVjHO23J Imdb9o0TSDLSF08pB8zgyXbyVRakTJhlEdrA7a/YLp5IXo79YqDFr1ECtGHz6zIIKKWDu5 7PQlfQvp/V99Z6TYc7vuYQSBjMMWBkA= X-MC-Unique: hZbhxJwhM8qLRdSaA7sJcA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 01/11] dump: Use a buffer for ELF section data and headers Date: Wed, 26 Oct 2022 12:55:29 +0400 Message-Id: <20221026085540.254253-2-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774664372100006 From: Janosch Frank 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 Message-Id: <20221017083822.43118-2-frankja@linux.ibm.com> --- include/sysemu/dump.h | 2 ++ dump/dump.c | 75 +++++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 24 deletions(-) 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 */ 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; - int ret; + if (dump_is_64bit(s)) { + Elf64_Shdr *shdr64 =3D s->elf_section_hdrs; =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; + shdr64->sh_info =3D cpu_to_dump32(s, s->phdr_num); } 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; + 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); } +} =20 - ret =3D fd_write_vmcore(shdr, shdr_size, 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; + + 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 table"); + error_setg_errno(errp, -ret, "dump: failed to write section header= s"); } + + 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 */ --=20 2.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774649; cv=none; d=zohomail.com; s=zohoarc; b=QfXVwy1+qHE5KoxVaAX0gNODvFzKh/LT7zcnNMM3rSGZ18yrWjkmNx2Ixay7JtIPVBnwaiSpuPUw+kBQcFC+mOgT9g1qTq4yL+7+16OlRtEFVE0Ut2qD4z9ZYZiEv1uugDbVsDJgaDnQHq52DK4X3I4E0N1bBeaAwYvMQo4HBSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774649; 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=51si67oMLHfMigUNv16V9jLVZNglhcVFQhgyfCf3TyU=; b=ED+33p+sKAjNOlHIECSaDJy9tphWddw1KTRaUYNjEsVrReJHyyRlqP1zw+bv6+Xq9p5LWf2aqcRJeMAkhCYUXguA32RaRTaIZQgg4ggly6GivrS/t544zM3acSlf5p3ucZkjWMkFD14KdKSRAOcezpSwxeFTi5NrpOpclHAB7Kw= 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+importer2=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 1666774649543263.2181622463603; Wed, 26 Oct 2022 01:57:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDX-0003W7-TR; Wed, 26 Oct 2022 04:56:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCd-0008G8-Bh for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCb-0000KA-Q3 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:55:59 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-160-3aWeoHCKMOuAOunSkzkHdA-1; Wed, 26 Oct 2022 04:55:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9985D1C07827; Wed, 26 Oct 2022 08:55:52 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CED212166B2B; Wed, 26 Oct 2022 08:55:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=51si67oMLHfMigUNv16V9jLVZNglhcVFQhgyfCf3TyU=; b=EOs/y0KeBMYJBx3ZBPmo2FpbHj/yoyiXG6AK8D1Q3plUH3grQRE15kW9DsJHTfr2sfOaK/ Vt6BnJvgnvJs8d8mAi8tIjmaKm9rfqoh6JFLyrTOmmtk3oojjW5o8deZtY6WhHM9tvM+0e DlW9/HCBXynRUjxZc6iNhtD9iBpLhY4= X-MC-Unique: 3aWeoHCKMOuAOunSkzkHdA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 02/11] dump: Write ELF section headers right after ELF header Date: Wed, 26 Oct 2022 12:55:30 +0400 Message-Id: <20221026085540.254253-3-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774650320100001 From: Janosch Frank 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 Message-Id: <20221017083822.43118-3-frankja@linux.ibm.com> --- 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,20 +608,20 @@ static void dump_begin(DumpState *s, Error **errp) return; } =20 - /* write PT_NOTE to vmcore */ - write_elf_phdr_note(s, errp); + /* write section headers to vmcore */ + write_elf_section_headers(s, errp); if (*errp) { return; } =20 - /* write all PT_LOADs to vmcore */ - write_elf_phdr_loads(s, errp); + /* write PT_NOTE to vmcore */ + write_elf_phdr_note(s, errp); if (*errp) { return; } =20 - /* write section headers to vmcore */ - write_elf_section_headers(s, errp); + /* write all PT_LOADs to vmcore */ + write_elf_phdr_loads(s, errp); if (*errp) { return; } @@ -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.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774792; cv=none; d=zohomail.com; s=zohoarc; b=aPCLcQ8CrjgKhGLCmYP2joLhYYVmzBCbJAcKlfb9xA7bwrNQ3uhEbsAui06tslUo4mPXdB1tWLEMJ2HQGvPRDeCC09SNyxtf66cJ2rlrPoHmxW+BzgNHc1I6piXh7WQ7r2sRZOhO2jqwYdNufW6DkrF/Px2m361yYBdMQjDaWkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774792; 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=CyQu35qqPeTmSx+O8zA1Jgg4eu8z0lgRUiDgVwFs7b0=; b=IWJO/xS8HV1Zkv9UqwZMyYvhSrSwTjjrOYxtDfr1mWjCzIIxAFAw94Zc4/M0LwildNVxTjPYI+eiQcpVAg+ZkM4YHwUz73Y/BUwh/oedC/1B42Q7HJk3udAq94w1znS/U4AUU1T3REE8dSFlPpshCimH7ihoyW5arK5RBWSo1+c= 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+importer2=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 1666774792539999.7759004804524; Wed, 26 Oct 2022 01:59:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDk-0005KJ-KJ; Wed, 26 Oct 2022 04:57:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCp-0000WI-CV for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCl-0000L2-M8 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:09 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-350-8MiUyl9WPk6d0HUbbGPw9A-1; Wed, 26 Oct 2022 04:55:57 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 09FA7101A54E; Wed, 26 Oct 2022 08:55:57 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EA36492B16; Wed, 26 Oct 2022 08:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CyQu35qqPeTmSx+O8zA1Jgg4eu8z0lgRUiDgVwFs7b0=; b=AktWUFsIeUIQ/6/XwgBJVePvwkymm5vfjEjRt9JCvujKafQApDvMgcp/RpeiPOhhuyVy3K Xy8Xt6Xq0AuZ6ymUZzAcikDbo+S3hkomT7znJdOwkMgFbhGST9AufeMMkdaYlgLaOpolYY vlShH50nT4RzMC33ZVGonxZP1j7bcV0= X-MC-Unique: 8MiUyl9WPk6d0HUbbGPw9A-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 03/11] dump: Reorder struct DumpState Date: Wed, 26 Oct 2022 12:55:31 +0400 Message-Id: <20221026085540.254253-4-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774794091100001 From: Janosch Frank 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 Message-Id: <20221017083822.43118-4-frankja@linux.ibm.com> --- 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.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774693; cv=none; d=zohomail.com; s=zohoarc; b=EKS9As8aEmi7cE3ZyIbkwlX/zpgo60FAT2dIm7I2MsyLkCtkMqLWwLACU4cEjdnWagYWu61AndgAl/PObkXf4p4D6y6NxItethuAsBU+tA/2SNnwqJz6DskDsWfLfbqhEkOU+ABYhlrieQJtey3fH7BRAvRVAq/pM2n2kGJ/eLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774693; 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=Jt5RhjTPCv0y0JGg/yBx6JZsS3LnJt8Wjc04GdqPNPo=; b=nJD2Ty9KakkP/gKJqKJ0RdUm9UTCwVolKjnssvmsEeYO+x47iS39CRbLPoihflx/l6UJM+EXRYdW//Iy9jPtYllaENzrLiAgWV1eMXfSm7e2HcQGczlVAVvG0Fjg/okQHAffenfmpGhyBOmgIzbzYvEfm6dIeqPoERnCnaP6iz0= 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+importer2=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 1666774693725166.9315986308361; Wed, 26 Oct 2022 01:58:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDf-0004TB-IO; Wed, 26 Oct 2022 04:57:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCq-0000Xc-HE for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCp-0000Lc-28 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:12 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-8-q6qyemr7Ps-0jLondsLKqg-1; Wed, 26 Oct 2022 04:56:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A64D41C09040; Wed, 26 Oct 2022 08:56:02 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 583FD40C94AD; Wed, 26 Oct 2022 08:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jt5RhjTPCv0y0JGg/yBx6JZsS3LnJt8Wjc04GdqPNPo=; b=fj4P+LscLWoIxCYN2KNVjVXws9x6HPzqqOARb1JyMV6n6f8/obq8e3S37snt77q+g+FbmX SUf+WBdXzuXkko/dpIQn8Tjz6eReC0SxhANUcWfj9eGRqx3+k0xRJMTf41SsQBsrJAsDQV EEM/1DedTtBhFOjQGws2rOFpDH8refU= X-MC-Unique: q6qyemr7Ps-0jLondsLKqg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 04/11] dump: Reintroduce memory_offset and section_offset Date: Wed, 26 Oct 2022 12:55:32 +0400 Message-Id: <20221026085540.254253-5-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774694430100003 From: Janosch Frank 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 Message-Id: <20221017083822.43118-5-frankja@linux.ibm.com> --- 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.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774792; cv=none; d=zohomail.com; s=zohoarc; b=Q0bHAu4EKlnNQMdizERtpfGZDKUwjFlEsPvRHMC68fN2H3Gvo1YzilviNQUcD3K4XyJXObV/QIJyq06CwBi63isXHTRRH90JwTB4c4tKdTrXExZadgVQJsLLi7LhqfkSiGVeoCsIEQql52a8GrB2x8rVEtbt8ch7IjR/q7coUXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774792; 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=9HG7g3uvc3zS6AQkb3eDYkOWEDXLlGZqks/JPekIlw8=; b=KiZp6J6qUfXnsN8z2eSS338HOx2HC2XBYXdh4M/kZb/rKmAUxurj5JQ6GrQovoGH8lKjuJ87/55G+AJPgMQstH0Jrwnp655htzuth1x8+uv0aB1KPnblgZ/IOycyhfMJj5x7tsQt7NLDV83M5MmOFFSxxwjQqYlevsFczrYAszg= 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+importer2=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 1666774792828641.4922792906282; Wed, 26 Oct 2022 01:59:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDg-0004gK-CC; Wed, 26 Oct 2022 04:57:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCv-0000Xf-IN for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncCt-0000MD-M9 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:17 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-53-XrLq4YnsN-qoLI_6JHMVWA-1; Wed, 26 Oct 2022 04:56:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1EA29884341; Wed, 26 Oct 2022 08:56:08 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93D1D111F3BB; Wed, 26 Oct 2022 08:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9HG7g3uvc3zS6AQkb3eDYkOWEDXLlGZqks/JPekIlw8=; b=ZuBP5yZ//m29d/2f99zNpRPUGZYwrL0We0BQI5ECX1fAdZepKYSZCBHwY7e4v+Ap9Zd4C3 /rXxxKJQgdE0dVGnvf7a44BFOFaYgJtLqygLWZVCNny2YnEPWbDnrzvRi96wt9S9dzZSj3 VuZ1spwToo4e8iIbayJNT+WgZG5965o= X-MC-Unique: XrLq4YnsN-qoLI_6JHMVWA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 05/11] dump: Add architecture section and section string table support Date: Wed, 26 Oct 2022 12:55:33 +0400 Message-Id: <20221026085540.254253-6-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774794129100003 From: Janosch Frank 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 Message-Id: <20221017113210.41674-1-frankja@linux.ibm.com> --- include/sysemu/dump-arch.h | 3 + include/sysemu/dump.h | 3 + dump/dump.c | 186 +++++++++++++++++++++++++++++++------ 3 files changed, 166 insertions(+), 26 deletions(-) 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 */ diff --git a/dump/dump.c b/dump/dump.c index 626f7b2fd0..9428d1fde9 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 bool 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 false; + } + } + + /* + * String table is the last section since strings are added via + * arch_sections_write_hdr(). + */ + prepare_elf_section_hdr_string(s, buff_hdr); + return true; } =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 first section header is always a special one in which most + * fields are 0. The section header string table is also always + * set. + */ + s->shdr_num =3D 2; + + /* + * 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); + } + + /* + * calculate shdr_num so we know the offsets and sizes of all + * parts. + * Calculate phdr_num * - * the type of ehdr->e_phnum is uint16_t, so we should avoid overflow + * 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; /* PT_NOTE */ - if (s->list.num < UINT16_MAX - 2) { - s->shdr_num =3D 0; + s->phdr_num =3D 1; /* Reserve PT_NOTE */ + if (s->list.num <=3D UINT32_MAX - 1) { s->phdr_num +=3D s->list.num; } else { - /* sh_info of section 0 holds the real number of phdrs */ - s->shdr_num =3D 1; - - /* 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; - } + s->phdr_num =3D UINT32_MAX; } =20 + /* + * 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; --=20 2.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774662; cv=none; d=zohomail.com; s=zohoarc; b=VnmKU7ZYJoe3mFxCi5TNJD2sfSuLaxPc7nFNlKCa3JkO2H34JSn/1hdEB+fgaGY4egu9KyrwKkm42Uv8jx6QnGbJmFg9oFpI8cmBHNHfz4gLlxQwjDjzVLnlGSX30hxp6Gcr6rEzouj2Bv5ZblVxsD6dNrj3YtX00lbCfABdEAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774662; 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=LZJgPKLzPU4FFqUHCLH3fQ6VerF4lcNEh7In/aB3oYA=; b=YbabWds1N+dAxqFlR8AXnl+tXWgk6cszg+Dzzu3XelVDLAEIBYeStSIMrUZWBYTbdcJosSd+VKmtpzhV0SL7eg+3ukubCdcWbw7PIH/pdSPKjUrFdt9przImxbY6K4t6EzzrFcYiGw+OwCvbpx0E3rUpMT5uFKD2+Vk9G2OxdHo= 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+importer2=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 16667746625031019.3502007043116; Wed, 26 Oct 2022 01:57:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDp-0005qF-Ah; Wed, 26 Oct 2022 04:57:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDJ-0002jc-Hx for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncD8-0000N7-M5 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:41 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-408-5DSJO3UWP3qq5SIXrUBmFg-1; Wed, 26 Oct 2022 04:56:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 01EAB3C1E72E; Wed, 26 Oct 2022 08:56:25 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86C8717595; Wed, 26 Oct 2022 08:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LZJgPKLzPU4FFqUHCLH3fQ6VerF4lcNEh7In/aB3oYA=; b=Get9eoE1LpaQi+3nmv4yEFoBliWhnsh7E9NDGrLqXT3HxBH3wkffkj4Z4eu2bnZkMoUFXK RZG4OxQmYwoIG14FvrQ3DcpDtfNeffnKL+OhOVQCkp9ioxFe2sQgjaJVpC522JqE+VKUoH 7IrwwMoA0RSV17DtORiu8KVYuEaWmig= X-MC-Unique: 5DSJO3UWP3qq5SIXrUBmFg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 06/11] s390x: Add protected dump cap Date: Wed, 26 Oct 2022 12:55:34 +0400 Message-Id: <20221026085540.254253-7-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774664349100005 From: Janosch Frank 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 Message-Id: <20221017083822.43118-7-frankja@linux.ibm.com> [ Marc-Andr=C3=A9 - Add missing stubs when !kvm ] Signed-off-by: Marc-Andr=C3=A9 Lureau --- target/s390x/kvm/kvm_s390x.h | 1 + target/s390x/kvm/kvm.c | 7 +++++++ target/s390x/kvm/stubs.c | 12 ++++++++++++ target/s390x/kvm/meson.build | 2 ++ 4 files changed, 22 insertions(+) create mode 100644 target/s390x/kvm/stubs.c 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); diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 508c24cfec..04cae0b999 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/stubs.c b/target/s390x/kvm/stubs.c new file mode 100644 index 0000000000..5fd63b9a7e --- /dev/null +++ b/target/s390x/kvm/stubs.c @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "kvm_s390x.h" + +int kvm_s390_get_protected_dump(void) +{ + return false; +} diff --git a/target/s390x/kvm/meson.build b/target/s390x/kvm/meson.build index d1356356b1..aef52b6686 100644 --- a/target/s390x/kvm/meson.build +++ b/target/s390x/kvm/meson.build @@ -1,6 +1,8 @@ =20 s390x_ss.add(when: 'CONFIG_KVM', if_true: files( 'kvm.c' +), if_false: files( + 'stubs.c' )) =20 # Newer kernels on s390 check for an S390_PGSTE program header and --=20 2.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774678; cv=none; d=zohomail.com; s=zohoarc; b=N8VtiekVjE6I4QgEo8qqm9mfK4gGvDGzbRz9Rf/QIGlJSuUhDYu+f/Y2zEcq+kZ3ZBBO81/XxjVubCuyjDV+Z86EGsdHAAZOvUYUGPLKdtJYe3IFBV3HQ7fSMyIGiaKHRPWhHsJVK57zq5TwEWAhoMj9Ft5i5M4tnzJ8pApiwdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774678; 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=p1EGsGNJqZR2tziqXLokPkR5z2ueiD1sLUFLeVnCqPg=; b=CL1Atyr/PMbloL2SRgHWBVHS2XYlV8wy2/9kcuDATBlkL0QVCFwJYnlYF0KLvfOQnt/mCfQo84/q8xiqcht4vVthgcrOyW90/it5bZNjw2Uej8ukrhoj/ePRne4K6fSfugSCX4thPvrpchZmbnEwnmnl9qxGOKAIbCcaJPP89w8= 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+importer2=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 1666774678395601.8407101703732; Wed, 26 Oct 2022 01:57:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDi-0004xJ-Fo; Wed, 26 Oct 2022 04:57:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDB-0001Ef-MG for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncD8-0000NB-MV for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:32 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-358-Kqz3oQdbNuK30EPr_MH1gg-1; Wed, 26 Oct 2022 04:56:24 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50F6E293249C; Wed, 26 Oct 2022 08:56:24 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABA39492B19; Wed, 26 Oct 2022 08:56:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p1EGsGNJqZR2tziqXLokPkR5z2ueiD1sLUFLeVnCqPg=; b=Ak3SLkUCpGcfmlHQq0qLFEIC0gyizHW85CT05k4atXzxFWdtoT9J8jbpuku8s4HVTcgodz fR1e9NHHNhIGCKD2a+dOVP1oKeVlmcM0f2Iz1Htt6IdHBTDMoI2feqabTO3wcxZtXqf2DP Lrkh9mukNyXvoS7OMY+g5qzrl5tAgsQ= X-MC-Unique: Kqz3oQdbNuK30EPr_MH1gg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 07/11] s390x: Introduce PV query interface Date: Wed, 26 Oct 2022 12:55:35 +0400 Message-Id: <20221026085540.254253-8-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774680389100003 Content-Type: text/plain; charset="utf-8" From: Janosch Frank 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 Message-Id: <20221017083822.43118-8-frankja@linux.ibm.com> --- include/hw/s390x/pv.h | 10 +++++++ hw/s390x/pv.c | 61 ++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 6 ++++ 3 files changed, 77 insertions(+) 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); 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) { --=20 2.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666775114; cv=none; d=zohomail.com; s=zohoarc; b=L9ZtIqFJoq1iteAMdnMNqiDrROoe9R53M5F1nAgukh/WTZAeBW/qirUbo7QCFYHaPYbIN+KNqSMpED8luEdQNaYfPwSdCJWWH88qxBRVbUi/bmGRvtZAIRlwuALVtAEW7Sej6WnT3MnigsUuAoUQto4t90jl0xrUGcAdSdMNbxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666775114; 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=Z+tuF9NxtegY4Tbg7sWTcsxDmANcSbzvi65yANVeOLg=; b=GD2LySZAJXPAX3ZBbQKUX/ee4NIPUvJaGrvkv++KyHhn6oz766uBsvi+J1a8DloRqdOD6on7UchAMRnkUzGkGPL7QN1t3hZv8suRw1lRN4rMC7+ydlL5ks6DpjWwDPiQ06Zdvg81uT87iAzUD7PVCG5ABjyZsqsgxhH+gVWhobw= 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+importer2=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 1666775114446685.098807983937; Wed, 26 Oct 2022 02:05:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDn-0005d4-6E; Wed, 26 Oct 2022 04:57:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDD-0001aN-CS for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDB-0000Nk-V0 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:56:35 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-294-nq3i4IDwOQmO-wzMzRfeBw-1; Wed, 26 Oct 2022 04:56:29 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D9548185A7A3; Wed, 26 Oct 2022 08:56:28 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE19749BB63; Wed, 26 Oct 2022 08:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z+tuF9NxtegY4Tbg7sWTcsxDmANcSbzvi65yANVeOLg=; b=FjUmhx4LYyQeIA5o73crhFhpd4cNGZ6rv2B3IoCptgJHVHsY2lE4+bUYZZlw6vWdYbh6mr 2E/NkWxC3Rx000aV6V9hJPRcqooLgyiT2ox7gEQSmOLi2S9iIdzxa/ujJNDxVwv96oo+ed qHwXXUipkkkOZ6KPzJfoH91dih2epJ0= X-MC-Unique: nq3i4IDwOQmO-wzMzRfeBw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 08/11] include/elf.h: add s390x note types Date: Wed, 26 Oct 2022 12:55:36 +0400 Message-Id: <20221026085540.254253-9-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666775115788100001 Content-Type: text/plain; charset="utf-8" From: Janosch Frank Adding two s390x note types Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20221017083822.43118-9-frankja@linux.ibm.com> --- 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.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774973; cv=none; d=zohomail.com; s=zohoarc; b=d/j1Wke+eagsaEHYEglItPKA8a5Apt/sR4sC8uybQtrHq+2RFHW9/Jbs1yUO5Qg72e6Or5fZA/EXrIAmLLjKUsKAN3aObTrUc2uyU6qNf0k5ZUtFq7FmNAwfF2anQRGHBz7Puatstq+g/RqfyuClp4YNiiBbIAJr6l4tzmJ8Sbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774973; 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=RSyNDNyP588Efkhc/If9+u59f4TkyEPg4UO3cris5og=; b=MzUkzVRts3gmuC3C4nnLF6UEQFpbxMZuvfWQX+CRsxru04FGbqwHtV7ITA0d6F9xhIn3md/RVTGigP0MTDngMFGU4yaBHRWS+T713BMLwi4LArR416cyvMOaubcBH4TdqRKABHs3LZsLJzsmWRrtp5s5M9AbWG2J4zTUT+nz8qs= 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+importer2=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 1666774973688226.30100100500363; Wed, 26 Oct 2022 02:02:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDr-0005y8-LD; Wed, 26 Oct 2022 04:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDn-0005di-DO for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:57:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDZ-0000Vy-PF for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:57:11 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-533-hqd4oYXfPTODMcUb1S9WoQ-1; Wed, 26 Oct 2022 04:56:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FA86800B30; Wed, 26 Oct 2022 08:56:39 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C08740C2140; Wed, 26 Oct 2022 08:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RSyNDNyP588Efkhc/If9+u59f4TkyEPg4UO3cris5og=; b=Lik7A1qS7gZ9eNPHkOpUfljqqW8iiZ/Xx6jU2JEMjS/o+sR7neVxZwc9x5o+TYWrmXTfGc YV8V++gxH2NvvkMHace/kHEM+sXU99DZiBbLKF04Lk1z9tn5hStuLF6Sm9/BqdbhqlHK5/ gFFIRFr+xOdaUb0x4hoPkoeDsoo9jfo= X-MC-Unique: hqd4oYXfPTODMcUb1S9WoQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 09/11] s390x: Add KVM PV dump interface Date: Wed, 26 Oct 2022 12:55:37 +0400 Message-Id: <20221026085540.254253-10-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774975625100003 From: Janosch Frank 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 [ Marc-Andr=C3=A9: fix up for compilation issue ] Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20221017083822.43118-10-frankja@linux.ibm.com> --- include/hw/s390x/pv.h | 9 ++++++++ hw/s390x/pv.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h index e5ea0eca16..9360aa1091 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) { 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); 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 --=20 2.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774806; cv=none; d=zohomail.com; s=zohoarc; b=Ls/uEZ8qFOzXq5YCi07n2PRdmR7ceZFRY5AyvbrZKg0/x84GNQrNew7QdKB6qzCoyW6YRJKZtKGSm3adsBSRvrPGGtbLa3Kepjj96qwuvXS4mqdlAtVROJGr0UUr1qhr26ehRylYQnftorp7VdTWc3G9q3Mna7CQ802MXJ1BIk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774806; 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=8W+0lsRFrsXYklk2ZJ8WWRZDw5fFkubpsCZcwlypM6o=; b=iGguehAZbGINqz8Qpck4FRKXCzEfqcUWiLQeJx+o9enZHbBiNotnP1HIo7UebzCy6TO0jii6k/TY0aECfBQDlEcogBbHUeLMk0As1o0E3umNx+PTaJPWkVMCH+qk7SE/dkJwDtdwY6EEjFRwAK1awrMwIbqZ1tp8FINyzSu1U34= 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+importer2=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 1666774806427267.2702697474649; Wed, 26 Oct 2022 02:00:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDt-00060d-GQ; Wed, 26 Oct 2022 04:57:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDq-0005uO-1x for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:57:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDi-0000WY-8T for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:57:13 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-640-XFMfhtFeNMqIzxq45SnRLQ-1; Wed, 26 Oct 2022 04:57:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6078823F91; Wed, 26 Oct 2022 08:56:49 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F1CE1401C57; Wed, 26 Oct 2022 08:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8W+0lsRFrsXYklk2ZJ8WWRZDw5fFkubpsCZcwlypM6o=; b=Fb/GUQkc9TTg1N9pqV60+GsKVeYt/vV2rsZlMeKDbgrQlLcbNztof7N8jHl8ar2QY6mj2u 7/BbzFIwYgblZnRCSbJ6Pngo7Bjw9D2Mycp/X53alqPxsiwhm0fu47HtixcltPk7qczMow PZSy6KgZGs/9vKXoKb51/3w+VzkwmNE= X-MC-Unique: XFMfhtFeNMqIzxq45SnRLQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Janosch Frank Subject: [PULL v3 10/11] s390x: pv: Add dump support Date: Wed, 26 Oct 2022 12:55:38 +0400 Message-Id: <20221026085540.254253-11-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774808178100001 Content-Type: text/plain; charset="utf-8" From: Janosch Frank 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 Message-Id: <20221017083822.43118-11-frankja@linux.ibm.com> --- include/sysemu/dump.h | 5 + dump/dump.c | 12 +- target/s390x/arch_dump.c | 262 +++++++++++++++++++++++++++++++++++---- 3 files changed, 246 insertions(+), 33 deletions(-) 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/dump/dump.c b/dump/dump.c index 9428d1fde9..df117c847f 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/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; + } + + 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)); =20 - note_size =3D sizeof(note) - sizeof(note.contents) + nf->contents_= size; - ret =3D f(¬e, note_size, s); + /* 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.37.3 From nobody Fri May 10 10:59:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666774742; cv=none; d=zohomail.com; s=zohoarc; b=ao8vlHx8eNalH7DtWPVVBW8MyUPxz4dCkdivnRYgSAV3GuJrMQbIbfV8D2Ew7ZrhoXMMEPvUw5kpM4zEk7DT6eoLDnff2efN0rssM8OB6cBuYkk4N/vpKudet0MAyZN6/KIMP6/ZM7+yB3zW3SA8PaN8zXld19ITQrKgWPGi844= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666774742; 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=3y6uBtQ/zA2SdT/qrNkOEOIaXH4LO+St7na1j07ASJU=; b=iE9jMQ+MdcwptC1OXV956iRc7UW3R6GGlqKjXjBeWiTXQp3D2YijhRcBrmLI9AT9w5A4M7iv9Pb9prtTwvwEXfYM9mYq/L6IRdKrTUNkxJzjOG8JZVFKnf221coHZDLNKRbzG4JY3ZBdAwHwN2kYw/RLSm+PAVd8df+05KjrtUk= 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+importer2=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 1666774742597749.4542730768551; Wed, 26 Oct 2022 01:59:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oncDw-0006F1-Cy; Wed, 26 Oct 2022 04:57:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDv-0006B9-33 for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:57:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oncDf-0000WN-5b for qemu-devel@nongnu.org; Wed, 26 Oct 2022 04:57:18 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-578-YHxt_mwiPtmHWEpq2io-IA-1; Wed, 26 Oct 2022 04:56:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 530823C1E74B; Wed, 26 Oct 2022 08:56:57 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 169BE2022EA2; Wed, 26 Oct 2022 08:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666774622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3y6uBtQ/zA2SdT/qrNkOEOIaXH4LO+St7na1j07ASJU=; b=Rnc+6w5A28s2ejdccLKjEsShJpKZFFZyvj6relRe70cmKccUxTRoYEV99Jgdh63oeqKHmu LyQyafmxPj0HFhvhiKLkOUEllxrf8cKHFDybuHpaJ1285i9Qbplj1rh/aHRg7ara/46P4q fvhkbrVtlQkceBmULAr29yx8GLa/tUk= X-MC-Unique: YHxt_mwiPtmHWEpq2io-IA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Cornelia Huck , Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , David Hildenbrand , qemu-s390x@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , Viktor Prutyanov Subject: [PULL v3 11/11] dump/win_dump: limit number of processed PRCBs Date: Wed, 26 Oct 2022 12:55:39 +0400 Message-Id: <20221026085540.254253-12-marcandre.lureau@redhat.com> In-Reply-To: <20221026085540.254253-1-marcandre.lureau@redhat.com> References: <20221026085540.254253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.517, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666774744760100003 From: Viktor Prutyanov When number of CPUs utilized by guest Windows is less than defined in QEMU (i.e., desktop versions of Windows severely limits number of CPU sockets), patch_and_save_context routine accesses non-existent PRCB and fails. So, limit number of processed PRCBs by NumberProcessors taken from guest Windows driver. Signed-off-by: Viktor Prutyanov Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20221019235948.656411-1-viktor.prutyanov@redhat.com> --- dump/win_dump.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dump/win_dump.c b/dump/win_dump.c index fd91350fbb..f20b6051b6 100644 --- a/dump/win_dump.c +++ b/dump/win_dump.c @@ -273,6 +273,13 @@ static void patch_and_save_context(WinDumpHeader *h, b= ool x64, uint64_t Context; WinContext ctx; =20 + if (i >=3D WIN_DUMP_FIELD(NumberProcessors)) { + warn_report("win-dump: number of QEMU CPUs is bigger than" + " NumberProcessors (%u) in guest Windows", + WIN_DUMP_FIELD(NumberProcessors)); + return; + } + if (cpu_read_ptr(x64, first_cpu, KiProcessorBlock + i * win_dump_ptr_size(x64), &Prcb)) { --=20 2.37.3