Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp372458ybx; Wed, 6 Nov 2019 01:59:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwKsZd1Lx1/X1MDgns6wU/hjoBIKlvew9jTSK2s/C/SWfZGjmAu8iU5UpNcNhxHTxtTghOx X-Received: by 2002:a50:ec83:: with SMTP id e3mr1637402edr.292.1573034344663; Wed, 06 Nov 2019 01:59:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573034344; cv=none; d=google.com; s=arc-20160816; b=uLWf/Znjk4IgOe8r72fUdApEjBI+b1tS2DJb49/Sa070ynrXQIdXgjSxuTWK28qRrl 5BlIw9nuCgi0TxB7J3HcCOR8a14i1pPBFfOPPMtb+x1+H2ZHbIBn/oULGtQqjhcUactj 1mvVJlvRiU8takGBM3a+02XsNGtDOVQ6/lh2P3Gvag/AHqenDW0KD54f18DtHEAR6pgH TOH1tStVNJkMdfKZHBt8PRj7857aAJzFhtncOms6Y1zTiSzxhEVQ1JwkSLg7dy8N/pOE o7R/EqqDwW2vEe/Pc7GEPuB7gjvCpfADMk6lwEpxlO0dsljtOkGn+Sg/q/Rb4F7NcFMM 7osA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=v5wYc21FedcS2oLC1oP2QSn5oXcQMuRzF3xN2vnbqCk=; b=e1WMrBeehmBG21JiirOLuuAvzZVgHqO5zAr1cfP3+ACkaXuibMEaXAwUKzrRUUvpOl 4LQLKsPtlEgOZYpVrjZze7QDasFGoZCtAWK2GzM4xU1vkw/DZb+rupyh9flZe1l4VFuG L2t5DATG9tq5jt+chuPdXEvBFytPoQvc7YRn4ApXbgixC5FxizCGW/EoSHt2UFmQVIge IxyfkDUTDT+IPLU1fg67jt4JR5UD84tJyX16MhYh5kDOnJDinYK1kBq8Yg1QkEu6DLbE o0YtoHdNBKKrj3KHD3mmxyb6888DkE8ebAPhuscViHgTmVUQzksKcLzXHrgek9rgF5SR vDFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jt21si812582ejb.390.2019.11.06.01.58.41; Wed, 06 Nov 2019 01:59:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731229AbfKFJ4H (ORCPT + 99 others); Wed, 6 Nov 2019 04:56:07 -0500 Received: from mx2.suse.de ([195.135.220.15]:49974 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726755AbfKFJ4G (ORCPT ); Wed, 6 Nov 2019 04:56:06 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BEB04B35F; Wed, 6 Nov 2019 09:56:03 +0000 (UTC) From: Miroslav Benes To: heiko.carstens@de.ibm.com, gor@linux.ibm.com, borntraeger@de.ibm.com, jpoimboe@redhat.com, joe.lawrence@redhat.com Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, jikos@kernel.org, pmladek@suse.com, nstange@suse.de, live-patching@vger.kernel.org, Miroslav Benes Subject: [PATCH v3 2/4] s390/unwind: split unwind_next_frame() to several functions Date: Wed, 6 Nov 2019 10:55:59 +0100 Message-Id: <20191106095601.29986-3-mbenes@suse.cz> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191106095601.29986-1-mbenes@suse.cz> References: <20191106095601.29986-1-mbenes@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function unwind_next_frame() becomes less readable with each new change. Split it to several functions to amend it and prepare for new additions. No functional change. Suggested-by: Petr Mladek Signed-off-by: Miroslav Benes --- arch/s390/kernel/unwind_bc.c | 136 ++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 48 deletions(-) diff --git a/arch/s390/kernel/unwind_bc.c b/arch/s390/kernel/unwind_bc.c index 5a78deacb972..96da99ec7b59 100644 --- a/arch/s390/kernel/unwind_bc.c +++ b/arch/s390/kernel/unwind_bc.c @@ -36,55 +36,10 @@ static bool update_stack_info(struct unwind_state *state, unsigned long sp) return true; } -bool unwind_next_frame(struct unwind_state *state) +static bool unwind_update_state(struct unwind_state *state, + unsigned long sp, unsigned long ip, + struct pt_regs *regs, bool reliable) { - struct stack_info *info = &state->stack_info; - struct stack_frame *sf; - struct pt_regs *regs; - unsigned long sp, ip; - bool reliable; - - regs = state->regs; - if (unlikely(regs)) { - if (state->reuse_sp) { - sp = state->sp; - state->reuse_sp = false; - } else { - sp = READ_ONCE_NOCHECK(regs->gprs[15]); - if (unlikely(outside_of_stack(state, sp))) { - if (!update_stack_info(state, sp)) - goto out_err; - } - } - sf = (struct stack_frame *) sp; - ip = READ_ONCE_NOCHECK(sf->gprs[8]); - reliable = false; - regs = NULL; - } else { - sf = (struct stack_frame *) state->sp; - sp = READ_ONCE_NOCHECK(sf->back_chain); - if (likely(sp)) { - /* Non-zero back-chain points to the previous frame */ - if (unlikely(outside_of_stack(state, sp))) { - if (!update_stack_info(state, sp)) - goto out_err; - } - sf = (struct stack_frame *) sp; - ip = READ_ONCE_NOCHECK(sf->gprs[8]); - reliable = true; - } else { - /* No back-chain, look for a pt_regs structure */ - sp = state->sp + STACK_FRAME_OVERHEAD; - if (!on_stack(info, sp, sizeof(struct pt_regs))) - goto out_stop; - regs = (struct pt_regs *) sp; - if (READ_ONCE_NOCHECK(regs->psw.mask) & PSW_MASK_PSTATE) - goto out_stop; - ip = READ_ONCE_NOCHECK(regs->psw.addr); - reliable = true; - } - } - ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, (void *) sp); @@ -94,13 +49,98 @@ bool unwind_next_frame(struct unwind_state *state) state->regs = regs; state->reliable = reliable; return true; +} + +static bool unwind_use_regs(struct unwind_state *state) +{ + struct stack_frame *sf; + unsigned long sp, ip; + struct pt_regs *regs = state->regs; + + if (state->reuse_sp) { + sp = state->sp; + state->reuse_sp = false; + } else { + sp = READ_ONCE_NOCHECK(regs->gprs[15]); + if (unlikely(outside_of_stack(state, sp))) { + if (!update_stack_info(state, sp)) + goto out_err; + } + } + + sf = (struct stack_frame *) sp; + ip = READ_ONCE_NOCHECK(sf->gprs[8]); + + return unwind_update_state(state, sp, ip, NULL, false); + +out_err: + state->error = true; + state->stack_info.type = STACK_TYPE_UNKNOWN; + return false; +} + +static bool unwind_use_frame(struct unwind_state *state, unsigned long sp) +{ + struct stack_frame *sf; + unsigned long ip; + + if (unlikely(outside_of_stack(state, sp))) { + if (!update_stack_info(state, sp)) + goto out_err; + } + + sf = (struct stack_frame *) sp; + ip = READ_ONCE_NOCHECK(sf->gprs[8]); + + return unwind_update_state(state, sp, ip, NULL, true); out_err: state->error = true; + state->stack_info.type = STACK_TYPE_UNKNOWN; + return false; +} + +static bool unwind_look_for_regs(struct unwind_state *state) +{ + struct stack_info *info = &state->stack_info; + struct pt_regs *regs; + unsigned long sp, ip; + + sp = state->sp + STACK_FRAME_OVERHEAD; + if (!on_stack(info, sp, sizeof(struct pt_regs))) + goto out_stop; + + regs = (struct pt_regs *) sp; + if (READ_ONCE_NOCHECK(regs->psw.mask) & PSW_MASK_PSTATE) + goto out_stop; + + ip = READ_ONCE_NOCHECK(regs->psw.addr); + + return unwind_update_state(state, sp, ip, regs, true); + out_stop: state->stack_info.type = STACK_TYPE_UNKNOWN; return false; } + +bool unwind_next_frame(struct unwind_state *state) +{ + struct stack_frame *sf; + unsigned long sp; + + if (unlikely(state->regs)) + return unwind_use_regs(state); + + sf = (struct stack_frame *) state->sp; + sp = READ_ONCE_NOCHECK(sf->back_chain); + + /* Non-zero back-chain points to the previous frame */ + if (likely(sp)) + return unwind_use_frame(state, sp); + + /* No back-chain, look for a pt_regs structure */ + return unwind_look_for_regs(state); +} EXPORT_SYMBOL_GPL(unwind_next_frame); void __unwind_start(struct unwind_state *state, struct task_struct *task, -- 2.23.0