Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1500479rda; Mon, 23 Oct 2023 14:48:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAcXeEEYDydqpDbYEsWFgBAbF38R1Dl3zwEdutMk5QgdHtrhzIZTQDzxixKZCd0gsfGrXH X-Received: by 2002:a17:90a:8997:b0:27d:66a9:3462 with SMTP id v23-20020a17090a899700b0027d66a93462mr7174560pjn.3.1698097688004; Mon, 23 Oct 2023 14:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698097687; cv=none; d=google.com; s=arc-20160816; b=LSI2b5GUD2nkGwd4vdHOiyBvhXyr/FtQpQxzkTD8aWZBm5Oat7KH+1MrNJ4jZ6whNP W7eTP3NPtTzLsswVO/yJTi9xQ8Y5kHiwNY+7T8ffuqVVbPTnsuRtdVIvqITe6SRxXqjs S8K+TyYUqmlP3GTqOsRHyDgrKz2+LfwbJvL5C/l4uh603Dcleh2ckGXAWzmj0c+AL/a2 wLFlCZT1QkJA/Mmd40Fb8wi+h/X0mhe1dZhhIVRmawnt5JjS8hqKyk7Q5lwVNNlvQNGA i72f8q3gKm4P24cMOCkq//LXanJFZOopCspd2h8aLkYUnFWwy2ETmf6SNEJgOGqoGq2x XCBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lEIAM3vwFJfAMVVsFGC6FCeU9Q+tUSLMAdObYWVx68w=; fh=EEmuDgHe7+GkkgYSN4e1h/DfOT9/bZas3+va72Szr1k=; b=kpEcWL+Yt2dh99unshRntLKE5hoQozv4nibih4Z/a12BHDEoYE3C55AB5dS7fJ/xQn VkICvcxC6MMyb3eqCuHrJPQZBy8HM1TKMKJe9CIrHbNhZFFeVRamlUfWfPgjwmZE8PIs +8qvrWFzdtdwRd7GHekZ3b5wy0vbkFPBRdJEQgjq4A4yrMSioWV8etecaePqfeLQWDNJ sfswgPIMz8nb3EcJXXaiqp4rFg2GNsbTF1mToKSqi873A5HxEGn7o1Xqpo4xJ9+vWfsY bmrl2rYNpU4Ojbm8uH/smlp+LIDbwCllhATnF+iiGaJZ90PEToD8bL3Mgq90jZIeN7TW VCRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u2LjfzR1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b11-20020a170902ed0b00b001c370dc4445si7141085pld.210.2023.10.23.14.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u2LjfzR1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B4E15807E40D; Mon, 23 Oct 2023 14:48:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbjJWVr6 (ORCPT + 99 others); Mon, 23 Oct 2023 17:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjJWVr5 (ORCPT ); Mon, 23 Oct 2023 17:47:57 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56E51BD; Mon, 23 Oct 2023 14:47:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B60EC433C7; Mon, 23 Oct 2023 21:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698097675; bh=XHWV4RVtniMvvQ4FFzRtkV3DH5t8b9UJU2TMo/5xG1Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u2LjfzR1DyITElencnYUZBJSxQhSGcdUh8qNi6hiAjhBeQgfLvgVVR3Hfhybeo7cI ShVL4HtQVGGNRqD9eOg345hWZQ+ClHFfhz78g6IxdSxJYnQ5IkYJYUixMbHjXfTwww zNpIBT2YeHMuQFtheSVnDQdgPsKx16BMIkXLmrWxjRZHKp2Q781G6runNpXpg+64DZ WHQ5A2kETEoqfZmB3qZMt5f2memgusVsD8M5Ch7hMJk62ZT5o1RYEYYYgH47OWvpXm 8w0BrCd51hL7ILMuxLEpaoVw92RLHWNVcBPVxDK9uorbyzfjiU7SMpeZbMVJ2dK+BG WT/PepqZYTMeQ== Date: Mon, 23 Oct 2023 14:47:52 -0700 From: Josh Poimboeuf To: Pawan Gupta Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Andy Lutomirski , Jonathan Corbet , Sean Christopherson , Paolo Bonzini , tony.luck@intel.com, ak@linux.intel.com, tim.c.chen@linux.intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, Alyssa Milburn , Daniel Sneddon , antonio.gomez.iglesias@linux.intel.com, Dave Hansen Subject: Re: [PATCH 2/6] x86/entry_64: Add VERW just before userspace transition Message-ID: <20231023214752.2d75h2m64yw6qzcw@treble> References: <20231020-delay-verw-v1-0-cff54096326d@linux.intel.com> <20231020-delay-verw-v1-2-cff54096326d@linux.intel.com> <20231023183521.zdlrfxvsdxftpxly@treble> <20231023210410.6oj7ekelf5puoud6@desk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231023210410.6oj7ekelf5puoud6@desk> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:48:05 -0700 (PDT) On Mon, Oct 23, 2023 at 02:04:10PM -0700, Pawan Gupta wrote: > On Mon, Oct 23, 2023 at 11:35:21AM -0700, Josh Poimboeuf wrote: > > On Fri, Oct 20, 2023 at 01:45:03PM -0700, Pawan Gupta wrote: > > > @@ -663,6 +665,10 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL) > > > /* Restore RDI. */ > > > popq %rdi > > > swapgs > > > + > > > + /* Mitigate CPU data sampling attacks .e.g. MDS */ > > > + USER_CLEAR_CPU_BUFFERS > > > + > > > jmp .Lnative_iret > > > > > > > > > @@ -774,6 +780,9 @@ native_irq_return_ldt: > > > */ > > > popq %rax /* Restore user RAX */ > > > > > > + /* Mitigate CPU data sampling attacks .e.g. MDS */ > > > + USER_CLEAR_CPU_BUFFERS > > > + > > > > Can the above two USER_CLEAR_CPU_BUFFERS be replaced with a single one > > just above native_irq_return_iret? Otherwise the native_irq_return_ldt > > case ends up getting two VERWs. > > Wouldn't that make interrupts returning to kernel also execute VERWs? > > idtentry_body > error_return > restore_regs_and_return_to_kernel > verw > > native_irq_return_ldt doesn't look to be a common case. Anyways, I will > see how to remove the extra VERW. Ah, right. > > > /* > > > * RSP now points to an ordinary IRET frame, except that the page > > > * is read-only and RSP[31:16] are preloaded with the userspace > > > @@ -1502,6 +1511,9 @@ nmi_restore: > > > std > > > movq $0, 5*8(%rsp) /* clear "NMI executing" */ > > > > > > + /* Mitigate CPU data sampling attacks .e.g. MDS */ > > > + USER_CLEAR_CPU_BUFFERS > > > + > > > /* > > > * iretq reads the "iret" frame and exits the NMI stack in a > > > * single instruction. We are returning to kernel mode, so this > > > > This isn't needed here. This is the NMI return-to-kernel path. > > Yes, the VERW here can be omitted. But probably need to check if an NMI > occuring between VERW and ring transition will still execute VERW after > the NMI. That window does exist, though I'm not sure it's worth worrying about. -- Josh