Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp477720imi; Fri, 22 Jul 2022 03:16:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tfvWfgbD33ciD6yLFUFAWnSGf534fJwB5/o2SxT+hr4DHff6DahQYixQSQZLYzhDtwleXb X-Received: by 2002:a05:6a00:1688:b0:517:cf7b:9293 with SMTP id k8-20020a056a00168800b00517cf7b9293mr2765266pfc.7.1658485013990; Fri, 22 Jul 2022 03:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658485013; cv=none; d=google.com; s=arc-20160816; b=IS3pHgUKujydIKemSsJ7g8grvhAO4u+EkFQtUIZqrAg8nfOjblmiJTDIfxCfvOUyX+ g9bTMs7AizXXHoBQ6OQEWJ+xXY7fAFeMhZxJohi2hsS3M6Yn5XOrEPqIJ97WnuGzH98E WG0RLHcApppT6v+1+2iIHDHOSTtklfk5psGESTZdKkgcrBZjmL8C53WNQQszbkz/Ra4M KGGjnrXe24rEI9WVtRG2jQLfqGg8UZvriL02bBZv9NSdl8HOgycDcQDRsyVGgsMgfXbM bz6IkamMPAm3V0ZP8gjFm8NOIYlDsj3k9D3Nz4v/fHvl5SEa86RwDV9GEMGYsv2OU8/H 51HQ== 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=CbHCzUO7vVssE+JyyaW8aoEVa06FKUpV3tWBcMmMyZ0=; b=Sf8140F+9fZ3AOfxqqfiILMM14iMRNVTAdvzVsaNRAtbmb5HEB3IDDY1s4PyIL9IMe Rj3MsiOrvU4oMyOXdbdsmDQKhNSIgtW1wN9XSR207XeZ/JaZHO4Df7qVPV7qo4d6ghjw qUmRm6iEU/C/xOkU5bLcxkMvhd571nloiUINkJZRZ/o+iSvkZ3ICnlfvs7LzvB4W6RNS gUMqzo6BX0/HprPv+5arMa9LLWBOD2Ru1Ty6taEHPwBf22BoYdNewyVNqD+DSs0PFDju YjxxShdcJrHTUexXpntdOoD1oGWGcESpNoekIgqf2SkkpKiUKqpqX7nGxNaLkrLDuIOo uv2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2PMU0exZ; 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 k1-20020a17090a514100b001ecd45dda01si4819654pjm.88.2022.07.22.03.16.37; Fri, 22 Jul 2022 03:16:53 -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=2PMU0exZ; 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 S235627AbiGVJP1 (ORCPT + 99 others); Fri, 22 Jul 2022 05:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235366AbiGVJOR (ORCPT ); Fri, 22 Jul 2022 05:14:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B988A877C; Fri, 22 Jul 2022 02:11: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 43F4161E86; Fri, 22 Jul 2022 09:11:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 420DAC341DB; Fri, 22 Jul 2022 09:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658481068; bh=7kYZO7url9vCnULEUHvc4To4+6iskP5TW1gis/Dd/dk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2PMU0exZlBxAH5VjvCYr0rXBP1fAFE0n0xyfHFoTt3K8N5SCQFHut7Mft8+kUC/yb pDeXuKWBUGmx7/aJ/FZvF9ZTdVvKv5JtuPl2cDHXM9Uj6VBXQuyn0eMy/fQk/1ayjT V/BCbtzYhrC/IL4d2662F00E/R3dHlf+GZj3bOIY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Paolo Bonzini Subject: [PATCH 5.18 66/70] KVM: emulate: do not adjust size of fastop and setcc subroutines Date: Fri, 22 Jul 2022 11:08:01 +0200 Message-Id: <20220722090654.623871753@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722090650.665513668@linuxfoundation.org> References: <20220722090650.665513668@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: Paolo Bonzini commit 79629181607e801c0b41b8790ac4ee2eb5d7bc3e upstream. Instead of doing complicated calculations to find the size of the subroutines (which are even more complicated because they need to be stringified into an asm statement), just hardcode to 16. It is less dense for a few combinations of IBT/SLS/retbleed, but it has the advantage of being really simple. Cc: stable@vger.kernel.org # 5.15.x: 84e7051c0bc1: x86/kvm: fix FASTOP_SIZE when return thunks are enabled Cc: stable@vger.kernel.org Suggested-by: Linus Torvalds Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/emulate.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -189,13 +189,6 @@ #define X8(x...) X4(x), X4(x) #define X16(x...) X8(x), X8(x) -#define NR_FASTOP (ilog2(sizeof(ulong)) + 1) -#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETHUNK)) + \ - IS_ENABLED(CONFIG_SLS)) -#define FASTOP_LENGTH (ENDBR_INSN_SIZE + 7 + RET_LENGTH) -#define FASTOP_SIZE (8 << ((FASTOP_LENGTH > 8) & 1) << ((FASTOP_LENGTH > 16) & 1)) -static_assert(FASTOP_LENGTH <= FASTOP_SIZE); - struct opcode { u64 flags; u8 intercept; @@ -310,9 +303,15 @@ static void invalidate_registers(struct * Moreover, they are all exactly FASTOP_SIZE bytes long, so functions for * different operand sizes can be reached by calculation, rather than a jump * table (which would be bigger than the code). + * + * The 16 byte alignment, considering 5 bytes for the RET thunk, 3 for ENDBR + * and 1 for the straight line speculation INT3, leaves 7 bytes for the + * body of the function. Currently none is larger than 4. */ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop); +#define FASTOP_SIZE 16 + #define __FOP_FUNC(name) \ ".align " __stringify(FASTOP_SIZE) " \n\t" \ ".type " name ", @function \n\t" \ @@ -446,9 +445,7 @@ static int fastop(struct x86_emulate_ctx * RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETHUNK] * INT3 [1 byte; CONFIG_SLS] */ -#define SETCC_LENGTH (ENDBR_INSN_SIZE + 3 + RET_LENGTH) -#define SETCC_ALIGN (4 << ((SETCC_LENGTH > 4) & 1) << ((SETCC_LENGTH > 8) & 1)) -static_assert(SETCC_LENGTH <= SETCC_ALIGN); +#define SETCC_ALIGN 16 #define FOP_SETCC(op) \ ".align " __stringify(SETCC_ALIGN) " \n\t" \