Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1879851ybz; Sat, 18 Apr 2020 10:20:33 -0700 (PDT) X-Google-Smtp-Source: APiQypLX7N5GZrGDJrryvAZ2QJjeD0CnwH8S2tJhSjMukt2W+R2DgN+XWA9lIQXegoPC3D057q95 X-Received: by 2002:aa7:ca53:: with SMTP id j19mr8000634edt.229.1587230433694; Sat, 18 Apr 2020 10:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587230433; cv=none; d=google.com; s=arc-20160816; b=ZwcJmUUBKpsWrZcSqyi7PR8/gHFz8ZKMY32DMkvUWZUj7NWKJvv6wnRl6niYB66f1/ GP9kp7u6trF9w2u/hYjfREkzgO8uE4iAtRI4OZwtVtK3FwU7MrcQRHIlW/ZQ5LzV0IHi HQv3BDEK+JBNHuj8/ZjdHUe7xLflCcmjFcmLaV7cQmg/fZnjZt0qEg0fcblbfa5drItS lUEfinZKnNk/7CJ+ru9r+KGEvbWz+kpwEL36yFYWNAL1xfH1F62Lo8TmgS29tF6w3W4K S3WrRBExodvFvwAjdyhJDaO7Fn9aN3oRvmKpDyPMr43RYCcK5rpuxyWUbPEH5TkheFk+ meiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ie9EL70Lwd9PPSN1xNj6PeAxkZsghWSxXFhNLGVt4Vw=; b=xmcEm8Dr6ylzQ2A2sj9cOg4/xaN473gHn8TT78ye/C5G49VAN7LZJuDagDm5C7lkF4 gDAiHIRNTYVa+oy3WjgGoaUHwvP8fNJwEAnX8pIKfWbnOyat8ghRKUp6P/eRfNCAxzWo +eGaYoRiARl2N9HVSAr9cIXuW1XvarTtrtEFlpHpgC3t8cBSc40HCCFVhn5R7DyXAnwE STonsZkhPHBP1X2OvUjstoSGu29XgYjPokttzf3MtWvc6JqKv4OAlUzdsWIsemwP45CV qKC6yGy41KRo/2c0XdA0U6jYhFji46KUaacnK8fjxPRqrEuPdG+wYA58UMCz6oUv0O9t r9VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NlZR3lEZ; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si2411459edy.486.2020.04.18.10.20.10; Sat, 18 Apr 2020 10:20:33 -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=@redhat.com header.s=mimecast20190719 header.b=NlZR3lEZ; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726539AbgDRRST (ORCPT + 99 others); Sat, 18 Apr 2020 13:18:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60054 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725887AbgDRRSS (ORCPT ); Sat, 18 Apr 2020 13:18:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587230297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ie9EL70Lwd9PPSN1xNj6PeAxkZsghWSxXFhNLGVt4Vw=; b=NlZR3lEZhphKk1c/QeQ9WzcfZdNpOUglmzLDbwSqOANyjzJDYDe/CQteaankg5uiDFjSl9 gyJTeuO6WF0XUaIANo293KC2hsBh/WEAQq0+lumS/Zw2s00I8Uf9sIr846UpDqwgYhFhaG 1AXtFZRGyRUOpo2P/0rtSPM/mM0JuQQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-204-96sEaGbqPjel3zKRyqR_Pg-1; Sat, 18 Apr 2020 13:18:15 -0400 X-MC-Unique: 96sEaGbqPjel3zKRyqR_Pg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38ADDDB60; Sat, 18 Apr 2020 17:18:14 +0000 (UTC) Received: from treble (ovpn-112-81.rdu2.redhat.com [10.10.112.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D891012973B; Sat, 18 Apr 2020 17:18:12 +0000 (UTC) Date: Sat, 18 Apr 2020 12:18:10 -0500 From: Josh Poimboeuf To: Andy Lutomirski Cc: Peter Zijlstra , Alexandre Chartre , Thomas Gleixner , LKML , X86 ML , Masami Hiramatsu , Miroslav Benes , jthierry@redhat.com Subject: Re: [PATCH v5 02/17] objtool: Better handle IRET Message-ID: <20200418171810.n4vcaihdfksltuqg@treble> References: <20200416114706.625340212@infradead.org> <20200416115118.631224674@infradead.org> <8692ee18-e553-6f90-5291-62d6d57407cd@oracle.com> <20200417182339.GJ20730@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 17, 2020 at 04:53:31PM -0700, Andy Lutomirski wrote: > I'm wondering if this would be easier if we just moved the guts of > sync_core() into asm. > > In the near future, I think we want to rework it a tiny bit. In > particular, I think we're going to want to make sync_core() do: > > if (static_cpu_has(X86_FEATURE_SERIALIZE)) > asm volatile ("serialize"); > else > iret_to_self(); > > where iret_to_self() is the meat of the IRET hack. And then we're > going to add a new thingy unmask_nmi() that does iret_to_self() on > everything except SEV-ES. The near-term motivation is that I think we > have some genuine bugs in a couple of corner cases: > > 1. On AMD chips, if NMI hits user code with invalid CS or SS, we will > enter on the NMI stack, switch to the normal stack, and return with > IRET, and the IRET will fail. And then we end up in a nasty state in > which NMIs are masked but the code path we run doesn't expect that. > So we should unmask_nmi() in fixup_bad_iret() or similar. Intel CPUs > are unaffected because Intel is differently quirky. > > 2. do_nmi() does this: > > if (user_mode(regs)) > mds_user_clear_cpu_buffers(); > > because it can't safely call prepare_exit_to_usermode(). This is a > gross wart and I'd like to fix it. Fixing it involves teaching the > relevant code paths to unmask_nmis() if they're going to so IRQs-on > exit work. > > None of this is really relevant to the current patch, but it wouldn't > be unreasonable to turn the IRET thing from an inline asm into a real > asm function if it makes objtool's life easier. I don't think that would make objtool's life any easier -- it still has to understand the stack impact of the IRET-to-self thing regardless. -- Josh