Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1365916imi; Sat, 23 Jul 2022 03:47:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1skEw0+bmNc+Fmw1h8DlrhE0A5XY6bxrr7P5oNicpZrNzW7C9secnBdbTxras2cxGWEbtGC X-Received: by 2002:a05:6a00:e0e:b0:522:990c:ab60 with SMTP id bq14-20020a056a000e0e00b00522990cab60mr4316404pfb.8.1658573265960; Sat, 23 Jul 2022 03:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573265; cv=none; d=google.com; s=arc-20160816; b=M8OKCVUxeB0b3lQwh2Z0kdUcltTLaLynV3LwWJ001l+ZQvF/ehOxfEsrHQyiajizG7 vO1R+m8XrwFSB5X3WkK72muKGT+bYRFv9BU95Q7WMf8SH7uWhR7fo7+yeUm1O2CnhzxT HIdX1g40ZDUCI8UReXWo+OGUGN/GxDxY0TlhAVe5nB8lxedfy1Yd9x5y5he0W1PSJrSU 4taa0WDsUo0Q6vHJkSgYnsAq0PUTUMESeVxoMEgSKXL1nWnLNg91HPzTTWn5PWuSWACd BLhGmUDosl9Mvo3obI5VdyFSv8Go3LYOs+M5r5b6IeZbTHOs3sHtI8RamvhKUa31h/2W 7xpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y/ah+ATGZIlfUjYp+TaM96FgoI9Rqi1rd+xq7+CCgC0=; b=Tjz+RghIhD/rIkyoyeMzr3YoEE+df9aPfmpGSjPxwerqEuyAakMPczT+tKhD45v62n vGHLY9xyvMco1eBPmXivyHFWBlGYTSk/AGbOvJqSIYhYNyXs8l7W8WkoeJ73YnOPvs3d pNbfvsRQCS8fPDLKUBAruBYxrQH+PclttrzHwA5yeL7S89CxfFXgQp7Z1cg8GKHmlcge thlHDmQtNx2SaCjhmEDpS+HM/2aeSmSO1ngbQw+hlN9G7b/6zdSGg3SMHi2ksbn8uK3E eXpaM8NkkEvlbw/PXnVuqaAycMyu6x7NZvOwsWIQiGbXPU2FQrvQ1PzcHdgg+DS0s15l OLng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YwRK+Lbn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a170903300300b0016c66bf1a15si7318908pla.34.2022.07.23.03.47.30; Sat, 23 Jul 2022 03:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YwRK+Lbn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238716AbiGWKHY (ORCPT + 99 others); Sat, 23 Jul 2022 06:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238494AbiGWKG4 (ORCPT ); Sat, 23 Jul 2022 06:06:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E70C3805; Sat, 23 Jul 2022 03:01:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1BA2361260; Sat, 23 Jul 2022 10:00:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 296EAC341C0; Sat, 23 Jul 2022 10:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570447; bh=9U0r2uHXT1NBk+EpHeWfpqK2tFsMJfPQcA+s6ZHAngc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YwRK+LbnMO2woH1uu9U+bGqmWSUcNZZ0Nxsr2ALIBm+pfYvolJhW4BkuuJZEpDgLV 5fIZyNcKmbWbG6oEVBOtEBE7XT0e03TNGYNfwkdEsC0kX9+GambvNfSfHW13ovfiRM g1ioFS+fvFX62DZMKJys8vAPITFjsVZkGqfJXrw8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 090/148] x86/kvm: Fix SETcc emulation for return thunks Date: Sat, 23 Jul 2022 11:55:02 +0200 Message-Id: <20220723095249.632470153@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra commit af2e140f34208a5dfb6b7a8ad2d56bda88f0524d upstream. Prepare the SETcc fastop stuff for when RET can be larger still. The tricky bit here is that the expressions should not only be constant C expressions, but also absolute GAS expressions. This means no ?: and 'true' is ~0. Also ensure em_setcc() has the same alignment as the actual FOP_SETCC() ops, this ensures there cannot be an alignment hole between em_setcc() and the first op. Additionally, add a .skip directive to the FOP_SETCC() macro to fill any remaining space with INT3 traps; however the primary purpose of this directive is to generate AS warnings when the remaining space goes negative. Which is a very good indication the alignment magic went side-ways. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov [cascardo: ignore ENDBR when computing SETCC_LENGTH] [cascardo: conflict fixup] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/emulate.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -322,13 +322,15 @@ static int fastop(struct x86_emulate_ctx #define FOP_RET(name) \ __FOP_RET(#name) -#define FOP_START(op) \ +#define __FOP_START(op, align) \ extern void em_##op(struct fastop *fake); \ asm(".pushsection .text, \"ax\" \n\t" \ ".global em_" #op " \n\t" \ - ".align " __stringify(FASTOP_SIZE) " \n\t" \ + ".align " __stringify(align) " \n\t" \ "em_" #op ":\n\t" +#define FOP_START(op) __FOP_START(op, FASTOP_SIZE) + #define FOP_END \ ".popsection") @@ -432,15 +434,14 @@ static int fastop(struct x86_emulate_ctx /* * Depending on .config the SETcc functions look like: * - * SETcc %al [3 bytes] - * RET [1 byte] - * INT3 [1 byte; CONFIG_SLS] - * - * Which gives possible sizes 4 or 5. When rounded up to the - * next power-of-two alignment they become 4 or 8. + * SETcc %al [3 bytes] + * RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETPOLINE] + * INT3 [1 byte; CONFIG_SLS] */ -#define SETCC_LENGTH (4 + IS_ENABLED(CONFIG_SLS)) -#define SETCC_ALIGN (4 << IS_ENABLED(CONFIG_SLS)) +#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETPOLINE)) + \ + IS_ENABLED(CONFIG_SLS)) +#define SETCC_LENGTH (3 + RET_LENGTH) +#define SETCC_ALIGN (4 << ((SETCC_LENGTH > 4) & 1) << ((SETCC_LENGTH > 8) & 1)) static_assert(SETCC_LENGTH <= SETCC_ALIGN); #define FOP_SETCC(op) \ @@ -448,14 +449,15 @@ static_assert(SETCC_LENGTH <= SETCC_ALIG ".type " #op ", @function \n\t" \ #op ": \n\t" \ #op " %al \n\t" \ - __FOP_RET(#op) + __FOP_RET(#op) \ + ".skip " __stringify(SETCC_ALIGN) " - (.-" #op "), 0xcc \n\t" asm(".pushsection .fixup, \"ax\"\n" ".global kvm_fastop_exception \n" "kvm_fastop_exception: xor %esi, %esi; " ASM_RET ".popsection"); -FOP_START(setcc) +__FOP_START(setcc, SETCC_ALIGN) FOP_SETCC(seto) FOP_SETCC(setno) FOP_SETCC(setc)