Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6117955yba; Wed, 1 May 2019 06:25:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoNTdhaVHjioV7PPBMmd+lfTjbE8mYuQzcGmXza1iXH/UuudjryVLeJA3Sw39JqbpLSZvj X-Received: by 2002:a63:a441:: with SMTP id c1mr71689099pgp.307.1556717141233; Wed, 01 May 2019 06:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556717141; cv=none; d=google.com; s=arc-20160816; b=IZTlst1wUGfXXNFMVUMODY8lGwdglHYXoPTEU3hV7BsQfcffswQD+zJLNMEsU4/7/e iTd+tpVq9utnM6DAAvo3fk5sXPo4etGJogwZ4TLn79rwFtRYhZmAtumSW0DAoFyrhENW FdWgmWdBSmOmZY4M2A2hL0Sg9G4zXXYhGqQPCpRc0gJotDZj7l0Jv5Yi99VDivlQtMOY kdjaagykA/+fMJ5/WFD7dgjwaSjI4aGJbPpsx4O5YflxqkRkjSkrRNCcJDi/Agkf0eG9 fEvM2GeolrOkcXDuOxRAD2P5347poXdOJMfCXxrAcuMwkO5QEYDTsVqdjyG8w+LU9+jw OS1A== 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:subject:cc:to:from:date; bh=LrNUbAbsRkEFcmfBPuBFKK0z6eK3WD5w5A64+iTj0PQ=; b=GLcUR29igwOlCjXyS05CH0D26KQwF5cVPhbki/WmZUToNKKhhu775ozKMiT87WiyEZ 97sZT5pNJu74NRLV527yiXAhO74/haQu8V7tltUF++LPlDTTNEzpkouksiYl9Xk73OL9 Z2FYYskVlO7azWLFTU6eg1a8vMPHHtg4JjD08lBefSh1C+fc+DRa/KBG1tTAI2suP9dz 23qcxugqmbFRYGDmsE8yLdwN962cCrQb3/HmSYDWCr7FlvLV5dmICXfAKW0c+Aj+Ps9M Jd++mEj1VwprKVKzCSHUMjkbo/rekUJEsTuqpM1jbJYJrUaB0BRWIH3PBNwxsIXNDPHP FqNA== 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 u5si38091204pgp.240.2019.05.01.06.25.25; Wed, 01 May 2019 06:25:41 -0700 (PDT) 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 S1726543AbfEANWz (ORCPT + 99 others); Wed, 1 May 2019 09:22:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:42174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbfEANWy (ORCPT ); Wed, 1 May 2019 09:22:54 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67D95206DF; Wed, 1 May 2019 13:22:51 +0000 (UTC) Date: Wed, 1 May 2019 09:22:49 -0400 From: Steven Rostedt To: Nicolai Stange Cc: Linus Torvalds , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch\/x86 maintainers" , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan , Konrad Rzeszutek Wilk , Tim Chen , Sebastian Andrzej Siewior , Mimi Zohar , Juergen Gross , Nick Desaulniers , Nayna Jain , Masahiro Yamada , Joerg Roedel , Linux List Kernel Mailing , live-patching@vger.kernel.org, "open list\:KERNEL SELFTEST FRAMEWORK" Subject: Re: [RFC][PATCH v2] ftrace/x86: Emulate call function while updating in breakpoint handler Message-ID: <20190501092249.54cdbd94@gandalf.local.home> In-Reply-To: <87muk6vavb.fsf@suse.de> References: <20190428133826.3e142cfd@oasis.local.home> <20190430135602.GD2589@hirez.programming.kicks-ass.net> <20190430130359.330e895b@gandalf.local.home> <20190430132024.0f03f5b8@gandalf.local.home> <20190430134913.4e29ce72@gandalf.local.home> <20190430175334.423821c0@gandalf.local.home> <87muk6vavb.fsf@suse.de> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 01 May 2019 10:26:32 +0200 Nicolai Stange wrote: > > +extern asmlinkage void ftrace_emulate_call_irqon(void); > > +extern asmlinkage void ftrace_emulate_call_irqoff(void); > > +extern asmlinkage void ftrace_emulate_call_nmi(void); > > +extern asmlinkage void ftrace_emulate_call_update_irqoff(void); > > +extern asmlinkage void ftrace_emulate_call_update_irqon(void); > > +extern asmlinkage void ftrace_emulate_call_update_nmi(void); > > + > > +static DEFINE_PER_CPU(void *, ftrace_bp_call_return); > > +static DEFINE_PER_CPU(void *, ftrace_bp_call_nmi_return); > > Andy mentioned #DB and #MC exceptions here: > https://lkml.kernel.org/r/C55DED25-C60D-4731-9A6B-92BDA8771766@amacapital.net > > I think that #DB won't be possible, provided the trampolines below get > tagged as NOKPROBE (do_int3() and ftrace_int3_handler() already have > it). > > It's highly theoretic, but tracing do_machine_check() could clobber > ftrace_bp_call_return or ftrace_bp_call_nmi_return? Probably shouldn't trace do_machine_check() then ;-) > > > > +#ifdef CONFIG_SMP > > +#ifdef CONFIG_X86_64 > > +# define BP_CALL_RETURN "%gs:ftrace_bp_call_return" > > +# define BP_CALL_NMI_RETURN "%gs:ftrace_bp_call_nmi_return" > > +#else > > +# define BP_CALL_RETURN "%fs:ftrace_bp_call_return" > > +# define BP_CALL_NMI_RETURN "%fs:ftrace_bp_call_nmi_return" > > +#endif > > +#else /* SMP */ > > +# define BP_CALL_RETURN "ftrace_bp_call_return" > > +# define BP_CALL_NMI_RETURN "ftrace_bp_call_nmi_return" > > +#endif > > + > > +/* To hold the ftrace_caller address to push on the stack */ > > +void *ftrace_caller_func = (void *)ftrace_caller; > > The live patching ftrace_ops need ftrace_regs_caller. Ah, you're right. Luckily ftrace_regs_caller is a superset of ftrace_caller. That is, those only needing ftrace_caller can do fine with ftrace_regs_caller (but not vice versa). Easy enough to fix. > > > > + > > +asm( > > + ".text\n" > > + > > + /* Trampoline for function update with interrupts enabled */ > > + ".global ftrace_emulate_call_irqoff\n" > > + ".type ftrace_emulate_call_irqoff, @function\n" > > + "ftrace_emulate_call_irqoff:\n\t" > > + "push "BP_CALL_RETURN"\n\t" > > + "push ftrace_caller_func\n" > > + "sti\n\t" > > + "ret\n\t" > > + ".size ftrace_emulate_call_irqoff, .-ftrace_emulate_call_irqoff\n" > > + > > + /* Trampoline for function update with interrupts disabled*/ > > + ".global ftrace_emulate_call_irqon\n" > > The naming is perhaps a bit confusing, i.e. "update with interrupts > disabled" vs. "irqon"... How about swapping irqoff<->irqon? I just used the terminology Linus used. It is confusing. Perhaps just call it ftrace_emulate_call (for non sti case) and ftrace_emulate_call_sti for the sti case. That should remove the confusion. -- Steve