Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp478670imi; Fri, 22 Jul 2022 03:18:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vHC1CQrjJSIBkRlIfC0yH3A8U3kZTebKa3pgsTzG2/vrNux+KyIbev2TK8mF/F47/R477A X-Received: by 2002:a17:902:b681:b0:16d:31bb:7cd3 with SMTP id c1-20020a170902b68100b0016d31bb7cd3mr2699644pls.154.1658485084078; Fri, 22 Jul 2022 03:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658485084; cv=none; d=google.com; s=arc-20160816; b=wIhohqLK8n3LxR1iv/5lOMFEf8du8hhdQ4+gAl2C5gGpppRlsMbnYmQ5ifbvkJ5qWL 1neVZJSiqNVpl5ATOiOfxUQybBBpwRtX1ORZSQ/Ac5UgH+a8D9Mpz4te6m63QLZtYAVW 8TXpPC2xyH//Xix6HZ6l8ZhzfWqGBxUl5icCAxfuARBdk8gAAFDGp93l1fZnyJINOtTX yrsIz0240PSJInmFKZvSthAMUjZ++YX0Z0EhIbsx29GdBzgDnORQE1nFPUrvXVoFE71+ sVdFKwHYGR5DPZnPMKXxitPofRKdCLJ6QeN1Hng6YeRUn33OuPHuDCzTOIRSLkF6OnJu ODHQ== 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=AM4BoYx8lxHvthUzl48jE8oOsRVtqanwj2FD3TGSjP8=; b=Qy+oS6WyUrzACL7wDmOBX/jDZ+0XAhde9tqqgicDD3T9bwupTdP08awy5kAhB8biBq ll0/wSdmImaWi9SHD4vbLKVogbiSCce3NXhuZqUk1Fz/7AZFMFsA08gvmh4+ADEMrgDH zMlHYXeakgELLMv8uR88hUFVPaLG3eUxhjrH0NZa6acYlvy54g72wDJiiKAZPDeYYD7u Y8OlNAx1U7Wxl7ocOGTWFWJqSTG8zkhAWkUt0qonT9Pvi9hL0H2w2DwWZGNPifYq6MVg wA+uv4RTYhXAHzbFCfEN32CNCBlKwf6hEMQL9GMSnSbxjP7DjGjYA3oj6tG9DzGzY9c/ 8+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="HSvEI/C9"; 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 z7-20020a6553c7000000b00419b8c33922si5184696pgr.79.2022.07.22.03.17.48; Fri, 22 Jul 2022 03:18:04 -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="HSvEI/C9"; 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 S236313AbiGVJYL (ORCPT + 99 others); Fri, 22 Jul 2022 05:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236291AbiGVJXt (ORCPT ); Fri, 22 Jul 2022 05:23:49 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2663B26556; Fri, 22 Jul 2022 02:15:14 -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 sin.source.kernel.org (Postfix) with ESMTPS id 06134CE288C; Fri, 22 Jul 2022 09:15:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94F9FC341C6; Fri, 22 Jul 2022 09:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481311; bh=5RuloE8Cs02J8LXghnnFBDDHsz8LkONNlijG0Dd4Fvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSvEI/C9f+8zD0KHf2mioVKRRDOdbo+17TJ4O3UekLDUsPq8DZ5KNLJfu0zkZX46B G6SrWp2ADJwF91s4DdEfOWoaaH1gOE2KPvPih0EvCnoi4Ejf5SrqiKiddRYruKIZ6z xmkFdRgBlf8N5IpCGwIxKxmoAcp+vOH4DdW05MCc= 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 Subject: [PATCH 5.15 35/89] x86/kvm: Fix SETcc emulation for return thunks Date: Fri, 22 Jul 2022 11:11:09 +0200 Message-Id: <20220722091135.327192365@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722091133.320803732@linuxfoundation.org> References: <20220722091133.320803732@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: 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 @@ -321,13 +321,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") @@ -431,15 +433,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) \ @@ -447,13 +448,14 @@ 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" "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)