Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp58255rdb; Wed, 1 Nov 2023 17:02:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHu1Z8iYBQuAeQER4cRamRVTnq/Fc8LNpLo54l8i16IkYAf1It1hsEx2zapiXGd6ls4Fjd9 X-Received: by 2002:a17:90a:88a:b0:27e:22b:dce5 with SMTP id v10-20020a17090a088a00b0027e022bdce5mr14372625pjc.27.1698883330529; Wed, 01 Nov 2023 17:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698883330; cv=none; d=google.com; s=arc-20160816; b=BFR71KcMbzNWqjOwONYnfC3zmtQ6UBexgLj5SuZKKg35MKfruWNImd2CUNN+w8PGQ4 oqbg6OY91oIh6mg5uX8WFBhzGzwo0hSN8rCoS0nefcF5y4C9hwea45FzzHFYfP1YTdbP CEcMwWBLy+ok24osweWt7YiqbvkEY3z8T6U172p6M0f+63qYGJXwBOd2Kyb6u4wqQBfz IQzAmfC9etN24MsqgM5MQ9oYU8YJvFlZiXwvhungHawhFzQVVoSRMQuJvTiUKyYxshdQ ksB+Z0IqH01rc6/zn70cRtX3wEeCfnwEgMzBqwXmMDkNHDeWm2vMSKBrySdeaLfV1dFg kiRg== 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=Hzg+I80QZpKpCLqdXUAa5v/yGxLwg1pRVE20guGSWmw=; fh=Bgqdm1d17zd41jQ26pGtUteg4D7eSGQS6+01FPCJWL8=; b=svGw0Np2/0m+b1ammFlg7aHCp8LGSI1X4GiLj85Kp2j5arCA/bO3ieMMO7VFUKqfR1 VuhKAX7XN5cn1Wf6xXBbZtpTE9eIA7n8H5hHqknY/VlbYdXb5pM899WLf71C14mavBFn 6yIFbpvUmOFn23m0Vz/HhVocxVbxsgDb0ISL+PryfIoCIZtg9BSLFkKfjilxMvP27LFj xgwF1m5ErBOenzf0uw/vEPVGLb6Gva6JPMUOHcqglRX5Tl2oeilEU1cHt8FywLyyFe8l yigOe0ZTFYLUS1bzFaXmQd21Fz/vEUC3FwBomiUntI0WlAFwTljtVwBKKwH9EqjYnRZc NFew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qh7q9oMQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id jn9-20020a170903050900b001ca336f48bdsi3778294plb.556.2023.11.01.17.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 17:02:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qh7q9oMQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id D8EC28084628; Wed, 1 Nov 2023 17:02:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbjKBABx (ORCPT + 99 others); Wed, 1 Nov 2023 20:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbjKBABv (ORCPT ); Wed, 1 Nov 2023 20:01:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0DB9122; Wed, 1 Nov 2023 17:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698883304; x=1730419304; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=M8msWLszZPb7Wc0YXeNVNV9srP1v8FBDUCNkoBEItec=; b=Qh7q9oMQzhO1tBeJBVSj3a9ByMQNLp9okIDlxkJQLrFhvNPSuDUpXvhQ xY0APrHhX58DZcXSMt0PwTt7gVWBF6ro1+CdeIfhOyZrOp/5RnRv41YSH c5p1jsCqdiUjuwahPK1MllwMvWSfLl4u5Bpeco0jiV5SX+0Grrmf8NI2P 2zk/eUC+xyNu7e2AgPDN9NmPEdhBxB1nELu9ktridtJHszcPK2njtFtSM sDgUhfMIzwtIN1bk8qIGhdBiRwODHw32XRa9NKHF4v47q+06yTQtGyzvU QY6b2YfVlAASGOcJ4rsu7q6+IWjtvGAQp6Ftc2b+9cqT/EM/gsD/+E4Is Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10881"; a="367947182" X-IronPort-AV: E=Sophos;i="6.03,269,1694761200"; d="scan'208";a="367947182" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2023 17:01:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10881"; a="904837206" X-IronPort-AV: E=Sophos;i="6.03,269,1694761200"; d="scan'208";a="904837206" Received: from dkammer-mobl2.amr.corp.intel.com (HELO desk) ([10.255.230.88]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2023 17:01:43 -0700 Date: Wed, 1 Nov 2023 17:01:34 -0700 From: Pawan Gupta To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , Jonathan Corbet , Sean Christopherson , Paolo Bonzini , tony.luck@intel.com, ak@linux.intel.com, tim.c.chen@linux.intel.com, Andrew Cooper , Nikolay Borisov , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, Alyssa Milburn , Daniel Sneddon , antonio.gomez.iglesias@linux.intel.com, Greg Kroah-Hartman , Alyssa Milburn Subject: Re: [PATCH v4 1/6] x86/bugs: Add asm helpers for executing VERW Message-ID: <20231102000134.ophdmdy5ht6btlfi@desk> References: <20231027-delay-verw-v4-0-9a3622d4bcf7@linux.intel.com> <20231027-delay-verw-v4-1-9a3622d4bcf7@linux.intel.com> <20231027153203.GJZTvX84mr+63lVWIH@fat_crate.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231027153203.GJZTvX84mr+63lVWIH@fat_crate.local> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 01 Nov 2023 17:02:06 -0700 (PDT) On Fri, Oct 27, 2023 at 05:32:03PM +0200, Borislav Petkov wrote: > On Fri, Oct 27, 2023 at 07:38:40AM -0700, Pawan Gupta wrote: > > 1. Kernel data accessed by an NMI between VERW and return-to-user can > > remain in CPU buffers ( since NMI returning to kernel does not > > Some leftover '(' Ok. > > In preparation for moving VERW to entry/exit asm code, create macros > > that can be used in asm. Also make them depend on a new feature flag > > X86_FEATURE_CLEAR_CPU_BUF. > > The macros don't depend on the feature flag - VERW patching is done > based on it. Will fix. > > @@ -20,3 +23,17 @@ SYM_FUNC_END(entry_ibpb) > > EXPORT_SYMBOL_GPL(entry_ibpb); > > > > .popsection > > + > > +.pushsection .entry.text, "ax" > > + > > +.align L1_CACHE_BYTES, 0xcc > > +SYM_CODE_START_NOALIGN(mds_verw_sel) > > That weird thing needs a comment explaining what it is for. Right. > > +#define X86_FEATURE_CLEAR_CPU_BUF (11*32+27) /* "" Clear CPU buffers */ > > ... using VERW Ok. > > +/* > > + * Macros to execute VERW instruction that mitigate transient data sampling > > + * attacks such as MDS. On affected systems a microcode update overloaded VERW > > + * instruction to also clear the CPU buffers. VERW clobbers CFLAGS.ZF. > > + * > > + * Note: Only the memory operand variant of VERW clears the CPU buffers. > > + */ > > +.macro EXEC_VERW > > + verw _ASM_RIP(mds_verw_sel) > > +.endm > > + > > +.macro CLEAR_CPU_BUFFERS > > + ALTERNATIVE "", __stringify(EXEC_VERW), X86_FEATURE_CLEAR_CPU_BUF > > +.endm > > Why can't this simply be: > > .macro CLEAR_CPU_BUFFERS > ALTERNATIVE "", "verw mds_verw_sel(%rip)", X86_FEATURE_CLEAR_CPU_BUF This will not work in 32-bit mode that uses the same macro. Thanks for the review.