Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1852262pxb; Mon, 13 Sep 2021 06:57:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKzOfnReMLra2pQnUk2El0lu3z/lORn5b3qu2lswYdj5YK0+uv4xJVttaOKOsdsjIpbQ8p X-Received: by 2002:a17:906:19d8:: with SMTP id h24mr6133120ejd.490.1631541461954; Mon, 13 Sep 2021 06:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631541461; cv=none; d=google.com; s=arc-20160816; b=tioN9zYDkiRcuAYrcvxS+hbDf2uUkoYsK3jo97QAlJT6E0QOwfUbO9MZvmOPaFmzi5 beSBKkDilwQR0GtHgBjkPo85VFmKwIPtEz9mH8tMyp/jOc93PvvL3O0ESukLRti0+km6 U4GV+WvRfqiYw/j9kd0Wk0qk96noIk7iFTYzuXvIBGCFUry9SWS7YIWfhVFRPaDvqZsS CN8QkeRegvPTNgNzd6fFhasDo/tdlrIUx0Fr+nzwFwb4xDWnpTVF1j639sE4Jpk6nVzm WsyBjZ9acmt31pqI6kUdfdJTW1dgKc5bbN2KkPhuyNajuLgHx14ne695+nU0c9DQkHzk fiIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xy458qui97yz1XrMhfhpexlwAjVpXMnGuvdnhtHkHLk=; b=R21O8WrmIu67b2bi6FOogX8FsCsfY/175cUa1fAjvVyuC9N5wlAGBeuM4mI9FY0N5Q 529+BdLU+LG8/LDykcGxRMRPydHlv69dK1e43SMrIt94xSMu/0xOke6ppvaCLprpSawo Tkhxiv3bFXd+wd+tpP1jgSm2wX2MfjTYBvhE7/MRQ8n5YI9XIVrxIsmvR/c71ArlnKgn 7eb2pD7u0rl+oxWx2kykT0mXM/cmkHGUrY1+HadBv396bvBHNDozhE8h5J51hsRwjW0C KD4uZSBTrmd42ap25lpe7bExlUToQeBDsCiUJU/ht2UdkDt4enz1w5joRGghYxjcgKZB 7dPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=veQdcris; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si7839017ejc.571.2021.09.13.06.57.17; Mon, 13 Sep 2021 06:57:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=veQdcris; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243749AbhIMN4J (ORCPT + 99 others); Mon, 13 Sep 2021 09:56:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:40308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245023AbhIMNxg (ORCPT ); Mon, 13 Sep 2021 09:53:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C738617E2; Mon, 13 Sep 2021 13:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540085; bh=OWFul2QIC/gLurCpgBqET3is9T8/yc+YEFTbi6n4yJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=veQdcrisK/z5CXqjT2NyY49dLn+WHMmwwoFnsUYavMZWuxi21c6C6mJjxyTuji3y4 OSe1P0du3swVkte2QIF1qPHhbCTpOAtew8MLlo8lA2QZnYA4krCFzL3mS8afwHW8fN SmbzppWrFlxfTh2l2/6+Hi7SaK5/oPXQwI1vAsV4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Oberparleiter , Heiko Carstens , Sasha Levin Subject: [PATCH 5.13 044/300] s390/debug: keep debug data on resize Date: Mon, 13 Sep 2021 15:11:45 +0200 Message-Id: <20210913131110.823158445@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Oberparleiter [ Upstream commit 1204777867e8486a88dbb4793fe256b31ea05eeb ] Any previously recorded s390dbf debug data is reset when a debug area is resized using the 'pages' sysfs attribute. This can make live-debugging unnecessarily complex. Fix this by copying existing debug data to the newly allocated debug area when resizing. Signed-off-by: Peter Oberparleiter Signed-off-by: Heiko Carstens Signed-off-by: Sasha Levin --- arch/s390/kernel/debug.c | 74 ++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c index bb958d32bd81..7d3649dbaa8c 100644 --- a/arch/s390/kernel/debug.c +++ b/arch/s390/kernel/debug.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -92,6 +93,8 @@ static int debug_hex_ascii_format_fn(debug_info_t *id, struct debug_view *view, char *out_buf, const char *in_buf); static int debug_sprintf_format_fn(debug_info_t *id, struct debug_view *view, char *out_buf, debug_sprintf_entry_t *curr_event); +static void debug_areas_swap(debug_info_t *a, debug_info_t *b); +static void debug_events_append(debug_info_t *dest, debug_info_t *src); /* globals */ @@ -726,35 +729,28 @@ EXPORT_SYMBOL(debug_unregister); */ static int debug_set_size(debug_info_t *id, int nr_areas, int pages_per_area) { - debug_entry_t ***new_areas; + debug_info_t *new_id; unsigned long flags; - int rc = 0; if (!id || (nr_areas <= 0) || (pages_per_area < 0)) return -EINVAL; - if (pages_per_area > 0) { - new_areas = debug_areas_alloc(pages_per_area, nr_areas); - if (!new_areas) { - pr_info("Allocating memory for %i pages failed\n", - pages_per_area); - rc = -ENOMEM; - goto out; - } - } else { - new_areas = NULL; + + new_id = debug_info_alloc("", pages_per_area, nr_areas, id->buf_size, + id->level, ALL_AREAS); + if (!new_id) { + pr_info("Allocating memory for %i pages failed\n", + pages_per_area); + return -ENOMEM; } + spin_lock_irqsave(&id->lock, flags); - debug_areas_free(id); - id->areas = new_areas; - id->nr_areas = nr_areas; - id->pages_per_area = pages_per_area; - id->active_area = 0; - memset(id->active_entries, 0, sizeof(int)*id->nr_areas); - memset(id->active_pages, 0, sizeof(int)*id->nr_areas); + debug_events_append(new_id, id); + debug_areas_swap(new_id, id); + debug_info_free(new_id); spin_unlock_irqrestore(&id->lock, flags); pr_info("%s: set new size (%i pages)\n", id->name, pages_per_area); -out: - return rc; + + return 0; } /** @@ -821,6 +817,42 @@ static inline debug_entry_t *get_active_entry(debug_info_t *id) id->active_entries[id->active_area]); } +/* Swap debug areas of a and b. */ +static void debug_areas_swap(debug_info_t *a, debug_info_t *b) +{ + swap(a->nr_areas, b->nr_areas); + swap(a->pages_per_area, b->pages_per_area); + swap(a->areas, b->areas); + swap(a->active_area, b->active_area); + swap(a->active_pages, b->active_pages); + swap(a->active_entries, b->active_entries); +} + +/* Append all debug events in active area from source to destination log. */ +static void debug_events_append(debug_info_t *dest, debug_info_t *src) +{ + debug_entry_t *from, *to, *last; + + if (!src->areas || !dest->areas) + return; + + /* Loop over all entries in src, starting with oldest. */ + from = get_active_entry(src); + last = from; + do { + if (from->clock != 0LL) { + to = get_active_entry(dest); + memset(to, 0, dest->entry_size); + memcpy(to, from, min(src->entry_size, + dest->entry_size)); + proceed_active_entry(dest); + } + + proceed_active_entry(src); + from = get_active_entry(src); + } while (from != last); +} + /* * debug_finish_entry: * - set timestamp, caller address, cpu number etc. -- 2.30.2