From nobody Tue May 21 20:57:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662383449; cv=none; d=zohomail.com; s=zohoarc; b=NOyWrwRLkcTgZYFGrHheMLIgOMdsobbtZo33HRvUgYeHSIcUkM0UuIC4qX7H1u5Q2Gav9LWKlU4Mop/2T9K/SM54tAbhrp0y+xAzmXUzQaMKGip4ddQc1CZYY4DkcZ3OMxERgSB5kimLV13mk4GWkANHzJTn+MJHuea34vM+z1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662383449; 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=Ib5OUHJ7s7dSVL7IHHZjpGVNNwEflqbPGN5wYRKu1cA=; b=hcS84iFYdxHZGM06Z5xMzIlxWs3RVhZRfwTnxBC0SOMCgKwKrLRnGAgVkoVFdpF9pqnMV2e48WGXAQsyDr4a9Mb6kMijtCQD/06NHVhtJUqTxYGpthSEM1AMLuECsop6QwNkB3SGE+nAPeDV01C1AhYH/9xTg/dNGbj5QTG3q1A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662383449257140.04930604790127; Mon, 5 Sep 2022 06:10:49 -0700 (PDT) Received: from localhost ([::1]:40504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVBsF-0005gb-PE for importer@patchew.org; Mon, 05 Sep 2022 09:10:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVBfs-0002mU-SZ for qemu-devel@nongnu.org; Mon, 05 Sep 2022 08:58:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54359) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVBfo-0001mS-2j for qemu-devel@nongnu.org; Mon, 05 Sep 2022 08:58:00 -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-627-KRvHihI-MGqJlSxERHFcow-1; Mon, 05 Sep 2022 08:57:50 -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 E567E3C216C0; Mon, 5 Sep 2022 12:57:49 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB6FA1415102; Mon, 5 Sep 2022 12:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662382674; 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=Ib5OUHJ7s7dSVL7IHHZjpGVNNwEflqbPGN5wYRKu1cA=; b=G7xOemjjyCcK78Bv9o5mUywNjhaICA1y7OtA+2KpVdT76OWjO9Bs4QLJMaFQM6tmgj+POC F9hqbKWXQTWGMPwkCDbLfJrkcIfN8kJjxhVfBlZQTkMwLLPaj9/ahGxql9lmO6ftotQwZG w5Gzl5h0WnpruB5EyM+becZ5j853f/E= X-MC-Unique: KRvHihI-MGqJlSxERHFcow-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qiaonuohan@cn.fujitsu.com, Peter Maydell , Stefan Berger , David Hildenbrand , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 1/2] dump: simplify a bit kdump get_next_page() Date: Mon, 5 Sep 2022 16:57:40 +0400 Message-Id: <20220905125741.95516-2-marcandre.lureau@redhat.com> In-Reply-To: <20220905125741.95516-1-marcandre.lureau@redhat.com> References: <20220905125741.95516-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 2.85 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+importer=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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662383450928100001 From: Marc-Andr=C3=A9 Lureau This should be functionally equivalent, but slightly easier to read, with simplified paths and checks at the end of the function. The following patch is a major rewrite to get rid of the assert(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: David Hildenbrand --- dump/dump.c | 21 ++++++++------------- roms/SLOF | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 4d9658ffa2..f465830371 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1110,17 +1110,11 @@ static bool get_next_page(GuestPhysBlock **blockptr= , uint64_t *pfnptr, if (!block) { block =3D QTAILQ_FIRST(&s->guest_phys_blocks.head); *blockptr =3D block; - assert((block->target_start & ~target_page_mask) =3D=3D 0); - assert((block->target_end & ~target_page_mask) =3D=3D 0); - *pfnptr =3D dump_paddr_to_pfn(s, block->target_start); - if (bufptr) { - *bufptr =3D block->host_addr; - } - return true; + addr =3D block->target_start; + } else { + addr =3D dump_pfn_to_paddr(s, *pfnptr + 1); } - - *pfnptr =3D *pfnptr + 1; - addr =3D dump_pfn_to_paddr(s, *pfnptr); + assert(block !=3D NULL); =20 if ((addr >=3D block->target_start) && (addr + s->dump_info.page_size <=3D block->target_end)) { @@ -1132,12 +1126,13 @@ static bool get_next_page(GuestPhysBlock **blockptr= , uint64_t *pfnptr, if (!block) { return false; } - assert((block->target_start & ~target_page_mask) =3D=3D 0); - assert((block->target_end & ~target_page_mask) =3D=3D 0); - *pfnptr =3D dump_paddr_to_pfn(s, block->target_start); + addr =3D block->target_start; buf =3D block->host_addr; } =20 + assert((block->target_start & ~target_page_mask) =3D=3D 0); + assert((block->target_end & ~target_page_mask) =3D=3D 0); + *pfnptr =3D dump_paddr_to_pfn(s, addr); if (bufptr) { *bufptr =3D buf; } diff --git a/roms/SLOF b/roms/SLOF index 6b6c16b4b4..5b4c5acdcd 160000 --- a/roms/SLOF +++ b/roms/SLOF @@ -1 +1 @@ -Subproject commit 6b6c16b4b40763507cf1f518096f3c3883c5cf2d +Subproject commit 5b4c5acdcd552a4e1796aeca6bb700f6cbb0282d --=20 2.37.2 From nobody Tue May 21 20:57:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662383650; cv=none; d=zohomail.com; s=zohoarc; b=Z/iytyRTQJFLdkVvrldLLqXV2+pfT32zSV9+9LTGovsxg+yswMCAHJoNSikhlPcv3d1XWBaOZ7hUMFJULF2zUA1i5Z5m592oBjA/7tQIyqjLplpymInH5CBg6yU10Ip0BHHT/9U7gSeJlY3sS53Hh6R0QREOKdccbJTeOIooiJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662383650; 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=33MY53MhzkX7uol+cjzwlbU7yfO1koJ8zJLuzEguvNk=; b=S9167uEgkc56s/YtMDktCbQUFbq2dGfC5mCgqBFwvNP4XpaAkit0rhrhp4DK/yeLP4BKa+yACsVTkrxhaOuy3L1+xhhXcKSeHvwETBxtj6RJVVdpZ3+09UJna/fQZUO5+5W1PpVl/kmzsAkAukneFJdVHgimaf/RU6l+28KzT0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662383650940114.36116672828996; Mon, 5 Sep 2022 06:14:10 -0700 (PDT) Received: from localhost ([::1]:60484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVBvU-0003ih-JN for importer@patchew.org; Mon, 05 Sep 2022 09:14:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVBfz-0002pd-42 for qemu-devel@nongnu.org; Mon, 05 Sep 2022 08:58:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVBfs-0001n2-F4 for qemu-devel@nongnu.org; Mon, 05 Sep 2022 08:58:05 -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-426-HpWXyTynNaWOnqwAp2o1Gw-1; Mon, 05 Sep 2022 08:57:54 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0DA22805AF5; Mon, 5 Sep 2022 12:57:54 +0000 (UTC) Received: from localhost (unknown [10.39.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9D9EC15BBD; Mon, 5 Sep 2022 12:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662382679; 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=33MY53MhzkX7uol+cjzwlbU7yfO1koJ8zJLuzEguvNk=; b=EuMtFCnE+vqMLuDW5y23inT6wS7dYHHrzj8qt2WKpP3AazqvaGlYgkmDhZFUFhMXug2uSt cvoRneF45/EGG2ZUJzvSvB97Se/wYwhw1ktnVHR2uB2lRGAoiC/1DsgSQi3pcooCDF0OHG FF1kBU0fHif9Ljh36JpjgMkl/6FX27g= X-MC-Unique: HpWXyTynNaWOnqwAp2o1Gw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qiaonuohan@cn.fujitsu.com, Peter Maydell , Stefan Berger , David Hildenbrand , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 2/2] dump: fix kdump to work over non-aligned blocks Date: Mon, 5 Sep 2022 16:57:41 +0400 Message-Id: <20220905125741.95516-3-marcandre.lureau@redhat.com> In-Reply-To: <20220905125741.95516-1-marcandre.lureau@redhat.com> References: <20220905125741.95516-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 2.85 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662383652428100001 From: Marc-Andr=C3=A9 Lureau Rewrite get_next_page() to work over non-aligned blocks. When it encounters non aligned addresses, it will try to fill a page provided by the caller. This solves a kdump crash with "tpm-crb-cmd" RAM memory region, qemu-kvm: ../dump/dump.c:1162: _Bool get_next_page(GuestPhysBlock **, uint64_t *, uint8_t **, DumpState *): Assertion `(block->target_start & ~target_page_mask) =3D=3D 0' failed. because: guest_phys_block_add_section: target_start=3D00000000fed40080 target_end=3D= 00000000fed41000: added (count: 4) Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D2120480 Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: David Hildenbrand --- dump/dump.c | 79 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index f465830371..500357bafe 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1094,50 +1094,81 @@ static uint64_t dump_pfn_to_paddr(DumpState *s, uin= t64_t pfn) } =20 /* - * exam every page and return the page frame number and the address of the= page. - * bufptr can be NULL. note: the blocks here is supposed to reflect guest-= phys - * blocks, so block->target_start and block->target_end should be interal - * multiples of the target page size. + * Return the page frame number and the page content in *bufptr. bufptr ca= n be + * NULL. If not NULL, *bufptr must contains a target page size of pre-allo= cated + * memory. This is not necessarily the memory returned. */ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr, uint8_t **bufptr, DumpState *s) { GuestPhysBlock *block =3D *blockptr; - hwaddr addr, target_page_mask =3D ~((hwaddr)s->dump_info.page_size - 1= ); - uint8_t *buf; + uint32_t page_size =3D s->dump_info.page_size; + uint8_t *buf =3D NULL, *hbuf; + hwaddr addr; =20 /* block =3D=3D NULL means the start of the iteration */ if (!block) { block =3D QTAILQ_FIRST(&s->guest_phys_blocks.head); *blockptr =3D block; addr =3D block->target_start; + *pfnptr =3D dump_paddr_to_pfn(s, addr); } else { - addr =3D dump_pfn_to_paddr(s, *pfnptr + 1); + *pfnptr +=3D 1; + addr =3D dump_pfn_to_paddr(s, *pfnptr); } assert(block !=3D NULL); =20 - if ((addr >=3D block->target_start) && - (addr + s->dump_info.page_size <=3D block->target_end)) { - buf =3D block->host_addr + (addr - block->target_start); - } else { - /* the next page is in the next block */ - block =3D QTAILQ_NEXT(block, next); - *blockptr =3D block; - if (!block) { - return false; + while (1) { + if (addr >=3D block->target_start && addr < block->target_end) { + size_t n =3D MIN(block->target_end - addr, page_size - addr % = page_size); + hbuf =3D block->host_addr + (addr - block->target_start); + if (!buf) { + if (n =3D=3D page_size) { + /* this is a whole target page, go for it */ + assert(addr % page_size =3D=3D 0); + buf =3D hbuf; + break; + } else if (bufptr) { + assert(*bufptr); + buf =3D *bufptr; + memset(buf, 0, page_size); + } else { + return true; + } + } + + memcpy(buf + addr % page_size, hbuf, n); + addr +=3D n; + if (addr % page_size =3D=3D 0) { + /* we filled up the page */ + break; + } + } else { + /* the next page is in the next block */ + *blockptr =3D block =3D QTAILQ_NEXT(block, next); + if (!block) { + break; + } + + addr =3D block->target_start; + /* are we still in the same page? */ + if (dump_paddr_to_pfn(s, addr) !=3D *pfnptr) { + if (buf) { + /* no, but we already filled something earlier, return= it */ + break; + } else { + /* else continue from there */ + *pfnptr =3D dump_paddr_to_pfn(s, addr); + } + } } - addr =3D block->target_start; - buf =3D block->host_addr; } =20 - assert((block->target_start & ~target_page_mask) =3D=3D 0); - assert((block->target_end & ~target_page_mask) =3D=3D 0); - *pfnptr =3D dump_paddr_to_pfn(s, addr); if (bufptr) { *bufptr =3D buf; } =20 - return true; + return buf !=3D NULL; } =20 static void write_dump_bitmap(DumpState *s, Error **errp) @@ -1275,6 +1306,7 @@ static void write_dump_pages(DumpState *s, Error **er= rp) uint8_t *buf; GuestPhysBlock *block_iter =3D NULL; uint64_t pfn_iter; + g_autofree uint8_t *page =3D NULL; =20 /* get offset of page_desc and page_data in dump file */ offset_desc =3D s->offset_page; @@ -1310,12 +1342,13 @@ static void write_dump_pages(DumpState *s, Error **= errp) } =20 offset_data +=3D s->dump_info.page_size; + page =3D g_malloc(s->dump_info.page_size); =20 /* * dump memory to vmcore page by page. zero page will all be resided i= n the * first page of page section */ - while (get_next_page(&block_iter, &pfn_iter, &buf, s)) { + for (buf =3D page; get_next_page(&block_iter, &pfn_iter, &buf, s); buf= =3D page) { /* check zero page */ if (buffer_is_zero(buf, s->dump_info.page_size)) { ret =3D write_cache(&page_desc, &pd_zero, sizeof(PageDescripto= r), --=20 2.37.2