Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3709155yba; Tue, 7 May 2019 05:59:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZkhylGCk1rG/lD+U3hBmGaXmjIfSVnmYhAmO/YFJmAb9pbk0/4Hu0lCWde2KS8zepKXIC X-Received: by 2002:a17:902:5c6:: with SMTP id f64mr26093699plf.208.1557233947344; Tue, 07 May 2019 05:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557233947; cv=none; d=google.com; s=arc-20160816; b=d3z5muZwHJKhSeqmwGWtCiN+eLaQEuOygq+7X1Xa7sM/X3k2NmaVNNnMvrUaz2l82Q u7+aysSZeACWKwZ+9aRTjg+Skcu+0Y9Oy5Y793cU1GwnoE6hMY64fnn1gxK9EG1SElUK EtpP8PyvXsWpN8xm99djmBkaFcPVxGEzSNZmJ0pXpsxQ327zTv9GUnRKQEQyiMytFCnD 8YljkJQ4hrb6V9VVkDZudvN7iAioBpXNq8qzfqAU3XJHBFz8uZl3WC5enJZ+l8QkzyP0 Nsn+4IpQoVJXtAdxw9FA0GHcqIiRHEnbNviGf7avARrdTUdRld33up2PDJl5GTBO6yeA /x/g== 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=pnMhW5ApwoGyDbWAg/JSYKZKL44nLMVSvuq9JKjG51I=; b=GxM6LpVwTU+VE8ODsIPULuizSDYUZ8V9mWuR6pkte8/f+MvLDXr5tcCfJvTkSEmMaW FUmj/oq8//pUQp53OzmusPlniJwx8ug1Y3JWVM75hmIPExVU5s7nB4Jkb1O/kKQcAKlT NbdB0j/hbYiSZT/07HK6eG3ZdxD/tjeQc10i/Ev7sIzF9pl5r38VC8vSKq4gDZ/CXfSC kRcnmXyi7XJ1JbxlNVJ5OdK4ittdnBZ3+Igvce5UlqrEr9F68uOER2lck4mrK8skFJY2 A+yFThYKPT16dTVBADUFIwfP48HbXVTDwBVZOIMTV5EFtRLl1fEQFDcPwDY2LoPo2Q18 PQHg== 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 i36si4933733pgl.491.2019.05.07.05.58.52; Tue, 07 May 2019 05:59:07 -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 S1726775AbfEGM5V convert rfc822-to-8bit (ORCPT + 99 others); Tue, 7 May 2019 08:57:21 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:42364 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbfEGM5V (ORCPT ); Tue, 7 May 2019 08:57:21 -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-90--vy_klLVNSOvRBjrRdIVmQ-1; Tue, 07 May 2019 13:57:17 +0100 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b::d117) by AcuMS.aculab.com (fd9f:af1c:a25b::d117) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 7 May 2019 13:57:15 +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 13:57:15 +0100 From: David Laight To: 'Peter Zijlstra' CC: Linus Torvalds , Andy Lutomirski , Steven Rostedt , "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: AQHVBLOOpe57oOoUm0iPpfi6TWW3V6ZfXgyAgAAYbgCAACXZIA== Date: Tue, 7 May 2019 12:57:15 +0000 Message-ID: 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> In-Reply-To: <20190507113050.GR2606@hirez.programming.kicks-ass.net> 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: -vy_klLVNSOvRBjrRdIVmQ-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: Peter Zijlstra > Sent: 07 May 2019 12:31 > To: David Laight > On Tue, May 07, 2019 at 09:18:51AM +0000, David Laight wrote: > > From: Peter Zijlstra > > > Sent: 07 May 2019 09:58 > > ... > > > + /* > > > + * When we're here from kernel mode; the (exception) stack looks like: > > > + * > > > + * 4*4(%esp) - > > > + * 3*4(%esp) - flags > > > + * 2*4(%esp) - cs > > > + * 1*4(%esp) - ip > > > + * 0*4(%esp) - orig_eax > > > > Am I right in thinking that this is the only 'INT3' stack frame that > > needs to be 'fiddled' with? > > And that the 'emulate a call instruction' has verified that is the case?? > > So the %cs is always the kernel %cs. > > Only the INT3 thing needs 'the gap', but the far bigger change here is > that kernel frames now have a complete pt_regs set and all sorts of > horrible crap can go away. I'm not doubting that generating the 'five register' interrupt stack frame for faults in kernel space makes life simpler just suggesting that the 'emulated call' can be done by emulating the 'iret' rather than generating a gap in the stack. > For 32bit 'the gap' happens naturally when building a 5 entry frame. Yes > it is possible to build a 5 entry frame on top of the old 3 entry one, > but why bother... Presumably there is 'horrid' code to generate the gap in 64bit mode? (less horrid than 32bit, but still horrid?) Or does it copy the entire pt_regs into a local stack frame and use that for the iret? I've just tried to parse the pseudo code for IRET in the intel docs. Does anyone find that readable? I wonder if you can force 32bit mode to do a stack switch 'iret' by doing something like a far jump to a different %cs ? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)