Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1335366rdb; Fri, 20 Oct 2023 16:14:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8U+POFjbsrOdwpUi9cbvMiZaWGV0j+Ln1zUMQ10kROWri6af09Tofe4Sr2D1ZUaATszon X-Received: by 2002:a92:c543:0:b0:351:ab2:2626 with SMTP id a3-20020a92c543000000b003510ab22626mr4307327ilj.24.1697843644539; Fri, 20 Oct 2023 16:14:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697843644; cv=none; d=google.com; s=arc-20160816; b=P8CcqQN11bRezeYYSFqIs59uFLy7DgSp0mFRJlu/jDpaUA7/tBDyQeORynp/acbGSL kjspQ/UvYVnefemfaTKQUrhNNGgj+3y4cxpXUaRuNGfcV340vFpOM75TZHSm7ZQpJ051 nSXRSX6iNFDkk9ixFUK/1MtQzZwU5ET4X06MwWWJ1EkcYEqm3Jp6HMvWQUEBZmMzjEoN 3Hz5n1Z9CCBtL8a3Un7hDuGQVNBAAR8RhLheit9Iu+KrYGZgN5Ofed5p6EIJ46o/2WX/ 3DjlGZJVxiEBssCcWGluirfj+odvUWLmNRzWDueo69wQLCAH1ftFQ2Z6QBsuJbHnm6Dp X9MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=CgAVXy/axx8rbE3S2sz/Fpl+Q5PtMzZyyI0NieynS1Q=; fh=lDXW/muAJstKhPlQacsxi4Yu+KruKMNq+atr8pdTMaM=; b=o6Qfa1rx8fJ23Xy0WtfYV7TJ8WPG22MfWCT1zYPlOLtprX+hPrAeJIZEDO6QZqPSWd ZWJ8cmW9PTm/7Wc+R2klYUcsSHALnj/wVuPBausr4FntZ/uDeNkNArFkW6Oq09szQ6ha uZMGFlhEIjMtHdQUm5UO7/6M3hKUcWXgQt3XV7n69yuzZcUnDkk6eneIdPsXC92hKcGC zfZ60qNozH/SbhgiO9RF/k5pDDco0DvRksPktqjLSnfbhPtv7sSqOyuy3SjFSlPs23g8 sMw9nnxfGOUxrsJpjIhFVQpXD7mk5iUxUUE7reEvqIncW+y+0fsKv1nVBvDzU+Hup9qF RSoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3dzEKRkQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t15-20020a63954f000000b00564929df8besi2622140pgn.568.2023.10.20.16.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 16:14:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3dzEKRkQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1436783B00B3; Fri, 20 Oct 2023 16:13:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbjJTXNS (ORCPT + 99 others); Fri, 20 Oct 2023 19:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjJTXNQ (ORCPT ); Fri, 20 Oct 2023 19:13:16 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C6D2D4C for ; Fri, 20 Oct 2023 16:13:15 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-6936a25f49bso1236763b3a.1 for ; Fri, 20 Oct 2023 16:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697843595; x=1698448395; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CgAVXy/axx8rbE3S2sz/Fpl+Q5PtMzZyyI0NieynS1Q=; b=3dzEKRkQ3gyICAewppe2ffS6ZcMlYJNYdSp0UhbUUy9GAMvGPZSTOBDQBYOvfNPb8q /aO3YepGbcj1wHzD60P6vX61zRnFjr8Sn32IIAlzvbWDrrHH5sqsTav6I8eyTxe+YRnR Pa3A3j1/YJRXX87xGouWpsID1BeypQFBeq0Sa10b042o6IOLXZ2hmOExcuOqsE6KH5YF gVtVGvMPwGLfrhEUJdrPmA9NKcRn+pbf1UhmzQbNri+SO6tmFlR4TYSILZjmic3cp79T mR62nI6y3qkkL7kZ77ISvQdCFQ4g/wKBnhYkUaiNyhRfcsOASyAuEV66smJ82chJpOe7 SQaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697843595; x=1698448395; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CgAVXy/axx8rbE3S2sz/Fpl+Q5PtMzZyyI0NieynS1Q=; b=TSWsE1pOvipDsOwqg3IIn9/E7GzboqylfLZ97huCv4ilKPSyfMC5wUFHcVtb6Dn1dr ygWVDjZhYvL0+QRHMwyc2RLVvNBH/w5Q3lHTdHa0CIY7tR1pYAArqXAuq2D3j5g3NR4Z zuqYUc2d1yCoUaPawpQnutMzEszpFf7y0P9yVUzYe9g3pAkMpXqEZLliqW475vVSW3AD pemf38AE7NAdodwes1VAuSKc2kZIhYTZ9WSQzfAZ8QX9EbgJxclUSH14AkGOvoN+3L/x RqXCh3WkDO2U9heAiOoRV8jFw+o36jMnBIHFpLkuPDWuF0/mCY2blnR8Nr0u+7ucURDD PTIQ== X-Gm-Message-State: AOJu0YwoqTBwtjEstYNa748155quj/drlz/jK4uR7A89WWJlp0Rv+wQr BQo+P3nXgwAUz4R7sk0h2ebaPnsde4Y= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:26e4:b0:6bc:ff89:a30e with SMTP id p36-20020a056a0026e400b006bcff89a30emr86478pfw.3.1697843594765; Fri, 20 Oct 2023 16:13:14 -0700 (PDT) Date: Fri, 20 Oct 2023 16:13:13 -0700 In-Reply-To: <20231020-delay-verw-v1-1-cff54096326d@linux.intel.com> Mime-Version: 1.0 References: <20231020-delay-verw-v1-0-cff54096326d@linux.intel.com> <20231020-delay-verw-v1-1-cff54096326d@linux.intel.com> Message-ID: Subject: Re: [PATCH 1/6] x86/bugs: Add asm helpers for executing VERW From: Sean Christopherson To: Pawan Gupta Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , Jonathan Corbet , 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, Alyssa Milburn Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 20 Oct 2023 16:13:38 -0700 (PDT) On Fri, Oct 20, 2023, Pawan Gupta wrote: > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h > index c55cc243592e..e1b623a27e1b 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -111,6 +111,24 @@ > #define RESET_CALL_DEPTH_FROM_CALL > #endif > > +/* > + * Macro to execute VERW instruction to mitigate transient data sampling > + * attacks such as MDS. On affected systems a microcode update overloaded VERW > + * instruction to also clear the CPU buffers. > + * > + * Note: Only the memory operand variant of VERW clears the CPU buffers. To > + * handle the case when VERW is executed after user registers are restored, use > + * RIP to point the memory operand to a part NOPL instruction that contains > + * __KERNEL_DS. > + */ > +#define __EXEC_VERW(m) verw _ASM_RIP(m) > + > +#define EXEC_VERW \ > + __EXEC_VERW(551f); \ > + /* nopl __KERNEL_DS(%rax) */ \ > + .byte 0x0f, 0x1f, 0x80, 0x00, 0x00; \ > +551: .word __KERNEL_DS; \ Why are there so many macro layers? Nothing jumps out to justfying two layers, let alone three. > + > /* > * Fill the CPU return stack buffer. > * > @@ -329,6 +347,13 @@ > #endif > .endm > > +/* Clear CPU buffers before returning to user */ > +.macro USER_CLEAR_CPU_BUFFERS > + ALTERNATIVE "jmp .Lskip_verw_\@;", "", X86_FEATURE_USER_CLEAR_CPU_BUF > + EXEC_VERW Rather than a NOP after VERW, why not something like this? /* Clear CPU buffers before returning to user */ .macro USER_CLEAR_CPU_BUFFERS ALTERNATIVE "jmp .Lskip_verw_\@;", "jmp .Ldo_verw_\@;", X86_FEATURE_USER_CLEAR_CPU_BUF 551: .word __KERNEL_DS .Ldo_verw_\@: verw _ASM_RIP(551b) .Lskip_verw_\@: .endm > +.Lskip_verw_\@: > +.endm