Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1481861rda; Mon, 23 Oct 2023 14:06:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1V5UkjhyDw9ckNoSlTMpKD5etUtZdbpZC3TEJmVKVP7TUXyPxQpz5XB/ovzw9P/C2RyqP X-Received: by 2002:a17:902:ca0b:b0:1c3:a4f2:7c92 with SMTP id w11-20020a170902ca0b00b001c3a4f27c92mr7461381pld.65.1698095170005; Mon, 23 Oct 2023 14:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095169; cv=none; d=google.com; s=arc-20160816; b=PqzlPDLCAdSqtG29Sbpn+z9n0eKo9ihGhcBwrjD5SsRuEBn9EZxUWequxCYPPCoqxc GOpjhP8D5ihweU2pooi2vtWRHOzJjlraYyU4jiFprhbOsYC7IoO9zBq5VIMYJt9TP7sE 8RBIulZMYLv53lg9TdGJJOLzkStoEKRWn/IRvNwM2zvoLagr2Xaj6AaevaUDDNzC17Qy 5YVYFjKkVRkh9NA8V5ngINzL/zu9fPpIC2Hl9MZuM9LprRzpTylR5bf7qp33BCGD0glS rKmvH7oExuAMQ/e9GLPq33tYQfQPIpXLXHA2n21qtPzXms4QwgO78WWn1R5AArUu0r80 yVKg== 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=ZQVLI45T51Y0zuNEyZ+IEUrj0ge5ZY8+0jUAGCC+8mw=; fh=dncd8ud6L9IovtlDluSfOA7x+HzSYgMNdhRYLwrRJy0=; b=zIg3pu8tXrNFf4zyjl96KnQZPf9zpKLW99JqAduWqHfP31XeZGIKjzCmtXxk6e/Chd RnIhfYPOWSTD7h0fp/81KnfzNIj1F1fQhEyQ9jT7XGs8rzD9pJbIuZq8xTTuqbdG4DLD x6QYEHr8kQnQ2NuYU8dECfF5Disn7FLqlHrR18LSVOR3lFttULoxd4R05GXBhMQdygI6 w9D/ppFqTRtUguGZ0QG72xFK7xcV4d1k88OATAMKd2oBLTi0ViQqhplK9YKjQ7TG9xln ajJpqV7Lm/wkRLaVlTVJ524Vm3UsVAOL7mK/1KhMubhoRBbx7Z/UB/WD9gdcVBjXh/qO SOKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VSDs0Vg5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id m1-20020a170902db0100b001cbd8dd09e8si1547515plx.537.2023.10.23.14.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VSDs0Vg5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4EFBF8068957; Mon, 23 Oct 2023 14:06:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbjJWVFu (ORCPT + 99 others); Mon, 23 Oct 2023 17:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjJWVFs (ORCPT ); Mon, 23 Oct 2023 17:05:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C577DBE; Mon, 23 Oct 2023 14:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698095146; x=1729631146; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=4M5y2i+2W2PLq06Wz4aCTn1NnMGfVddGl4aYzB45fmg=; b=VSDs0Vg5O8LqKxy9pptsjViY1IZ6S3ga/VCAlXva9lracVwOx+6wgqU9 qsSgvHtkLwggH9hyu1RV4UeF2vUnAmKM6weG8er+LrcjL4WcaWjob94hd 5GbStZAGuBj/No6SNbfrxf5gFLubMfQJvHOKDopIcFrp1pXo66BnuPdOf jYVQMm3GkBKSfEpEp0JY/C/myqZBSbUkQ2vjwetRL5Lq5GRT11SLYtzl5 O/LKPLnxeWS+cEm9div8cbAgOiuHgAaYUMQk1Me8jX9nAyjb/P5NEJgtv HksYTXh9RglrQvFi1FFygEF5lYAiX7GYHjjy7FWX4Vgpm8uFexI8nHNAm g==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="473155797" X-IronPort-AV: E=Sophos;i="6.03,246,1694761200"; d="scan'208";a="473155797" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2023 14:05:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="761879358" X-IronPort-AV: E=Sophos;i="6.03,246,1694761200"; d="scan'208";a="761879358" Received: from qwilliam-mobl.amr.corp.intel.com (HELO desk) ([10.212.150.186]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2023 14:05:45 -0700 Date: Mon, 23 Oct 2023 14:04:10 -0700 From: Pawan Gupta To: Josh Poimboeuf 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: <20231023210410.6oj7ekelf5puoud6@desk> References: <20231020-delay-verw-v1-0-cff54096326d@linux.intel.com> <20231020-delay-verw-v1-2-cff54096326d@linux.intel.com> <20231023183521.zdlrfxvsdxftpxly@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231023183521.zdlrfxvsdxftpxly@treble> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:06:07 -0700 (PDT) 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. > > /* > > * 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.