From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7A38C433EF for ; Sun, 20 Mar 2022 14:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245221AbiCTOFf (ORCPT ); Sun, 20 Mar 2022 10:05:35 -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-Google-Smtp-Source: ABdhPJxQGmyirZNe9b6sO0PJWsvv8mPfxVD8wfCRdvfa3DBmcAbh8uwX5f45eC15Bdc86Lph4lJSRA== 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 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