Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3901755yba; Tue, 7 May 2019 08:49:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZV1RadlxgKo++FU+VWX7Bw1XgHrQv/F5okPLi4ObslDHWyU9dQSinLYjxfkp0YBuQTB0k X-Received: by 2002:a17:902:ea:: with SMTP id a97mr34045511pla.158.1557244142813; Tue, 07 May 2019 08:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557244142; cv=none; d=google.com; s=arc-20160816; b=KNaaZlVWyfsSwfW8cviBWZ5nJ/lRokUAur8Gb2ANv5UB806sAr8mIJ2kFfx9A9y9C7 XgO/oDkV5BGJRXe4jtRuKhUXXMPiKIR075mArqvb/xNirqFOwb5xv04n8f/iXh0MlLu1 AbeYQZML7I3C13JFiVDu1oo0pUzWPqO92h+3H1ppVf43z5fjSz/+d9uF2T5yH7j8V1QJ A6+TUjL5HE1QjXT/GFOL0RoP8eMH0kAKqT2o8Gh6nX7Qg4NfJTJUMKLP4poc0LpoEXam Lj/DlWMiF7ok7oizqBe2HuL4X1I1H0SVuLKAVGNNfISFX9+VB9T/TYsLd32YMPeZVR2a kAKg== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=jtkOYwsawDB3CylcY1wWodIWCwr8rHBq30CflY4bE9E=; b=B+iSCkBlrFVL19WVjYdDCSvivozcUjNM0129sWJ7qn1UoNP2o7VYE6A00RwAOX7JaR 5Iq4JuoYfCT+irAV/pUwe5TI+YJ8dGQeCMED3o+IyK2aU1BFSW6RUWYZ8DcBOTwdtwRa iHTwAB96yj49SdTqYOm9f6EX8dNDnsk2u9Cinll9Hrd3vz1HnHoaJycS2TOyPeOM/vjY tWI2scwQDjxin6Xb0guqOSZvTMwUOyi0kvb/c1WSEKYTf7eicgdxBlygvPZaU+QH6OCB pE4RbwB9GGt6AgpuRH+E96FGxfHGBl8k7cCZBtKpl3WslZk5mASutciEQAYhIMK93peS 2mHg== 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 m6si18447307pgq.116.2019.05.07.08.48.45; Tue, 07 May 2019 08:49:02 -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 S1726966AbfEGPqz convert rfc822-to-8bit (ORCPT + 99 others); Tue, 7 May 2019 11:46:55 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([146.101.78.151]:57894 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbfEGPqz (ORCPT ); Tue, 7 May 2019 11:46:55 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-181-LGeneRpPP1-n91Ii04Istg-1; Tue, 07 May 2019 16:46:52 +0100 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 7 May 2019 16:46:51 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 7 May 2019 16:46:50 +0100 From: David Laight To: 'Steven Rostedt' CC: 'Peter Zijlstra' , Linus Torvalds , Andy Lutomirski , "Linux List Kernel Mailing" , Ingo Molnar , Andrew Morton , "Andy Lutomirski" , Nicolai Stange , "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" , "open list:KERNEL SELFTEST FRAMEWORK" , stable Subject: RE: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions Thread-Topic: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions Thread-Index: AQHVBLOOpe57oOoUm0iPpfi6TWW3V6ZfXgyAgAAYbgCAACXZIP//9vwAgAARSgCAAAuXAIAAEj/g Date: Tue, 7 May 2019 15:46:50 +0000 Message-ID: <9820e70016e0454e89e70d8f7dd90259@AcuMS.aculab.com> References: <20190502185225.0cdfc8bc@gandalf.local.home> <20190502193129.664c5b2e@gandalf.local.home> <20190502195052.0af473cf@gandalf.local.home> <20190503092959.GB2623@hirez.programming.kicks-ass.net> <20190503092247.20cc1ff0@gandalf.local.home> <2045370D-38D8-406C-9E94-C1D483E232C9@amacapital.net> <20190506081951.GJ2606@hirez.programming.kicks-ass.net> <20190507085753.GO2606@hirez.programming.kicks-ass.net> <20190507113050.GR2606@hirez.programming.kicks-ass.net> <20190507091403.556daba7@gandalf.local.home> <20190507105724.02abe6f6@gandalf.local.home> In-Reply-To: <20190507105724.02abe6f6@gandalf.local.home> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-MC-Unique: LGeneRpPP1-n91Ii04Istg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt > Sent: 07 May 2019 15:57 > On Tue, 7 May 2019 14:50:26 +0000 > David Laight wrote: > > > From: Steven Rostedt > > > Sent: 07 May 2019 14:14 > > > On Tue, 7 May 2019 12:57:15 +0000 > > > David Laight wrote: > > > The 'user' (ie the kernel code that needs to emulate the call) doesn't > > write the data to the stack, just to some per-cpu location. > > (Actually it could be on the stack at the other end of pt-regs.) > > So you get to the 'register restore and iret' code with the stack unaltered. > > It is then a SMOP to replace the %flags saved by the int3 with the %ip > > saved by the int3, the %ip with the address of the function to call, > > restore the flags (push and popf) and issue a ret.f to remove the %ip and %cs. > > How would you handle NMIs doing the same thing? Yes, the NMI handlers > have breakpoints that will need to emulated calls as well. That means you'd have to use a field in the on-stack pt_regs for the 'address to call' rather than a per-cpu variable. Then it would all nest. ... > > Actually that means you can do the following in both modes: > > if not emulated_call_address then pop %ax; iret else > > # assume kernel<->kernel return > > push emulated_call_address; > > push flags_saved_by_int3 > > load %ax, return_address_from_iret > > add %ax,#4 > > store %ax, first_stack_location_written_by_int3 > > load %ax, value_saved_by_int3_entry > > popf > > ret.n > > > > The ret.n discards everything from the %ax to the required return address. > > So 'n' is the size of the int3 frame, so 12 for i386 and 40 for amd64. > > > > If the register restore (done just before this code) finished with > > 'add %sp, sizeof *pt_regs' then the emulated_call_address can be > > loaded in %ax from the other end of pt_regs. ... > > This all sounds much more complex and fragile than the proposed > solution. Why would we do this over what is being proposed? It is all complex and fragile however you do it. I see a problem with converting the 3 register trap frame to a 5 register one is that the entry code and exit code both have to know whether it is necessary or was done. AFAICT it is actually quite hard to tell from the stack which form it is. Although the %sp value might tell you because %ss:%sp might only be pushed when a stack switch happens so the kernel %sp will be a known value (for the switched to stack). The advantage of converting the frame is that, as pointed out earlier it does let you have a pt_regs that always contains %ss:%sp. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)