Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2191716pxp; Mon, 21 Mar 2022 13:29:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBhyrXpYb4el5F7y4FKoMmZEjZkUPxCX9eUm3qFxgEapXkAjdihdvQ5uDBWtCe3n8mDtt4 X-Received: by 2002:a17:906:99c2:b0:6df:8834:4f4c with SMTP id s2-20020a17090699c200b006df88344f4cmr22273416ejn.496.1647894585935; Mon, 21 Mar 2022 13:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647894585; cv=none; d=google.com; s=arc-20160816; b=z5TZhD8ZPNnDQ40PnWtPMIVFGUTfKTcCvS5zb3dyQfYPnDoxxPX1kz864VWqbNzpWx PCe0Re4NjQOlpyjIKlURA8nulAvORlYCT9E0el7ZdvzTHxxRXJcs0CpWNp7+jInxfLkJ qwoqLTuFYwhfg/IOydNQOr6LGEeWQOd8V0Px3AvKnQuhhlZwVBR/xI019L3pmPpAJ5K8 SQOPC0La6JfjT0GgpfDEE0wPqWHXjIRqx92i3t9XcA18Hif0dgELXxfUFMYYkE+Gtj/l 3hesQduIcFXu3VKJ4DPJitcfy49vx/Ykatrzy85gb1R3WpWG8K0G+JcVKL3aOS3DtIQ9 +rHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=HEnmlDwpyZjcuvzIqjP5JJWtowc3f3ehGNPzqFNCQBM=; b=RIly5e1gN3yYuQ9xvVGHu0rOcbfOb8L3qQLZT00vS4/jOcKSYCM4ku2PZLLRib6pc4 AvqD3+5JvteYyj1LRmHTxjE2W57sggfVcR6ZnKCnhtJhH4YioanYxIHgu/sNCgHpiw4K fQrOZpL/0lNB8ps6M1rmJzeh/A75xwgI4fe97XZUcojZa5F+u/k1RH31n2GayCF4m2vF 6fuBNDG2VwNp5kVVjq7dmxBBvZ+kkr0GVg83aqTiOvc4XTlQAIsosQGTxIh2AsRkt4tZ pxMRfQhX8pF7UBCUHivLy7LqseEI/GTG/r0nBoMK3k+UERW1OmKwBQnJHFQiwIWAMrRd f8TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gTpMHy0L; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020a170906748200b006df76385bb5si8586307ejl.85.2022.03.21.13.29.20; Mon, 21 Mar 2022 13:29: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=@redhat.com header.s=mimecast20190719 header.b=gTpMHy0L; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245220AbiCTOFe (ORCPT + 99 others); Sun, 20 Mar 2022 10:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237560AbiCTOFc (ORCPT ); Sun, 20 Mar 2022 10:05:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 522DF3A5E6 for ; Sun, 20 Mar 2022 07:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647785048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HEnmlDwpyZjcuvzIqjP5JJWtowc3f3ehGNPzqFNCQBM=; b=gTpMHy0L0zP9j4qW0CunPMZdY2BnDVNYVAD1JsNz28i+aSpMCtAxmehFKXkLF9KYodzgi3 263K9OZaNxFKofM+cJRHkTXbtpkZaWTCZzDuhD3gUtHF48q+EEtMVuxpI0kcGX109PTpVF 1WACXxX5aOIHZO8McQr+l27nZnEIlWA= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-Z38d-yHfPDOR44y5lDbtNQ-1; Sun, 20 Mar 2022 10:04:07 -0400 X-MC-Unique: Z38d-yHfPDOR44y5lDbtNQ-1 Received: by mail-ej1-f70.google.com with SMTP id h22-20020a1709060f5600b006b11a2d3dcfso6066806ejj.4 for ; Sun, 20 Mar 2022 07:04:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=HEnmlDwpyZjcuvzIqjP5JJWtowc3f3ehGNPzqFNCQBM=; b=QV4PXSg+ZjmqF2iDEmDH9U1CXM2IT471WSACR35l1bdOA55x6JfBC54eSkeomfWhfV dYI8ZYP9qGNP1ybGlIROkuX/MlTF7o/qMMJgNlA+K7V+XTPEDY2DHMgm423obKNgDll3 Pw4iY2CtNdIBI1zR2yV8TFrS1RdfoGYq2ceDIRhAAexc+cS3dOJS+vd6FVFPT2iArWLb 6VTTdPZK1rj3tihHpnY4w07vx5wytH+dgSqldM62q3aniUxEM125CLPQ+BHj0z2QBk2r ZT+5F59MGXvGewTowqqn2gJ/WVuYMMqgkkeM/YD+7eloPU5WJ/aRsNRyZQwllHqHUlHM mONg== X-Gm-Message-State: AOAM531DWP4oGfcIB+KlGs4/3VKxynT9VoYjBEFFkNvH47fhmpk1vUhL M9PQJj/EbCW5haSkRdQ4W3dXp3kMpBacRU21uwtnZArP3LHibQEDHFuRXllQeyKvDFaYKTJpYos 8u2o86X3VthBoEIfuMB8DUyg4 X-Received: by 2002:a17:907:72c3:b0:6df:91a4:32f4 with SMTP id du3-20020a17090772c300b006df91a432f4mr14980697ejc.638.1647785045903; Sun, 20 Mar 2022 07:04:05 -0700 (PDT) X-Received: by 2002:a17:907:72c3:b0:6df:91a4:32f4 with SMTP id du3-20020a17090772c300b006df91a432f4mr14980663ejc.638.1647785045490; Sun, 20 Mar 2022 07:04:05 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.googlemail.com with ESMTPSA id u18-20020a17090617d200b006db07a16cf5sm5863067eje.77.2022.03.20.07.04.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Mar 2022 07:04:04 -0700 (PDT) Message-ID: <6970ccc4-1c42-23fa-0b31-99b102ed76c8@redhat.com> Date: Sun, 20 Mar 2022 15:04:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH -v1.2] kvm/emulate: Fix SETcc emulation function offsets with SLS Content-Language: en-US To: Borislav Petkov Cc: Peter Zijlstra , Jamie Heilman , linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, Sean Christopherson , kvm@vger.kernel.org References: <20220316220201.GM8939@worktop.programming.kicks-ass.net> <94df38ce-6bd7-a993-7d9f-0a1418a1c8df@redhat.com> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 3/19/22 14:50, Borislav Petkov wrote: > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 5719d8cfdbd9..f321abb9a4a8 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -429,8 +429,11 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop); > FOP_END > > /* Special case for SETcc - 1 instruction per cc */ > + > +#define SETCC_ALIGN (4 * (1 + IS_ENABLED(CONFIG_SLS))) > + > #define FOP_SETCC(op) \ > - ".align 4 \n\t" \ > + ".align " __stringify(SETCC_ALIGN) " \n\t" \ > ".type " #op ", @function \n\t" \ > #op ": \n\t" \ > #op " %al \n\t" \ > @@ -1047,7 +1050,7 @@ static int em_bsr_c(struct x86_emulate_ctxt *ctxt) > static __always_inline u8 test_cc(unsigned int condition, unsigned long flags) > { > u8 rc; > - void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf); > + void (*fop)(void) = (void *)em_setcc + SETCC_ALIGN * (condition & 0xf); > > flags = (flags & EFLAGS_MASK) | X86_EFLAGS_IF; > asm("push %[flags]; popf; " CALL_NOSPEC So this is what I squashed in: diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index f321abb9a4a8..e86d610dc6b7 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -430,7 +430,19 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop); /* Special case for SETcc - 1 instruction per cc */ -#define SETCC_ALIGN (4 * (1 + IS_ENABLED(CONFIG_SLS))) +/* + * 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. + */ +#define SETCC_LENGTH (4 + IS_ENABLED(CONFIG_SLS)) +#define SETCC_ALIGN (4 << IS_ENABLED(CONFIG_SLS)) +static_assert(SETCC_LENGTH <= SETCC_ALIGN); #define FOP_SETCC(op) \ ".align " __stringify(SETCC_ALIGN) " \n\t" \ Paolo