Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3438885pxj; Mon, 24 May 2021 06:50:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrlEfnPldCNJPxlCki0Ye2VOJHVBM81nhH0OCCIaFBXk2a5h2YbOubGSmC22qnGq9g5Xzy X-Received: by 2002:a92:c881:: with SMTP id w1mr14718702ilo.276.1621864254979; Mon, 24 May 2021 06:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621864254; cv=none; d=google.com; s=arc-20160816; b=wyVfFp5xRHzTcQVkzCTStUbvtPmtkxQa781K8mvuxkZGJWhYdxx9sdnqWcXC6RFCbO e2NcJWYq3CCz0hSyAV98fkGfAdzc/YCcxdR8aMQrlZLEvzQK9Z0T5YyLlShUbIRaGMCs M+JkNZGKyR89EuqijA4t5rUGJ/CivNr3V62YCEeoVe2u2nvVEdHZrC16G9FLQ0fR6gud k84kfXSlEuWllFSNriFcvbEdROvM6pWBEa/g7NaUWparzBirWmtMh3kNMY5LN7+/AHHT m/lH/dj0OaVRpZ8C6cddcNYXlk8kXMGroHzNs294wy2tKusQMzNOfnwrRuN/0fFtqc9c toSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=TsRJK9bUG+f7oAKkH7rO4U2x+my3f03n8SpUCLxXD34=; b=VvdWFQqbEjdadAe5k/L4/rH67ora5DIflak5bDHMrHBS12n3AdSn32sB2uWkPJ2DIM aMQgM/UQ3Fenl/ifZkdFIOn1lmooNBscBYTBl+E/IvvIcy5G2P0YBNbsy0uq3i3opi7W yjLxIrnDK8MwKc/lCmiEwC1ohjxPN/iuUfXBkoLbAN8BMWU0o7NfgqdsfreOFi1H2lT5 B7VDu0V0RGO9+Hqk0/An/iqgnwTS/aTtfcuBZCpQKSJj8aS2voQeANofz/4cLAZYRWsT 74G5dgOcIZnyIQ7HZAIOQsmi7jFtpvAHdW04NO08fH+ydTZzv7jKlg2ZD8Ad/P9RWqlK f0Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JKh7W7kV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si18322398iow.71.2021.05.24.06.50.42; Mon, 24 May 2021 06:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JKh7W7kV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232867AbhEXNvb (ORCPT + 99 others); Mon, 24 May 2021 09:51:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26571 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232543AbhEXNv2 (ORCPT ); Mon, 24 May 2021 09:51:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621864200; 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: in-reply-to:in-reply-to:references:references; bh=TsRJK9bUG+f7oAKkH7rO4U2x+my3f03n8SpUCLxXD34=; b=JKh7W7kVGVbJSYj8Hb6MzfbczK677Cu5k5KaJhSYyyhpcw0Z8MoCDmTrLSCzngJzuW23qq VFhe8o3wIQF4hXTCpm+IGgfk3SxT/K28jTTM9QfOgQRoaeor2IuK/cG/HHNX93h2eR9BOo AOFNPFFqi1KFOoxCecwHiMaE8JkDwmw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-qyZTnXecPpCYkWSKa88-gQ-1; Mon, 24 May 2021 09:49:58 -0400 X-MC-Unique: qyZTnXecPpCYkWSKa88-gQ-1 Received: by mail-wm1-f69.google.com with SMTP id y193-20020a1c32ca0000b029014cbf30c3f2so5153063wmy.1 for ; Mon, 24 May 2021 06:49:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=TsRJK9bUG+f7oAKkH7rO4U2x+my3f03n8SpUCLxXD34=; b=kvSbpXH8CanF4xlwq/nUZDQZHf93dGuMiVCVW8tpCx8DoRb/6sX3IEeNHsp+eBg0p8 LT3l7ob5pjpmUWqdXTRDP3HcZPJc/MzQ3uKzF4W66S8CmMfZWkCQ8GXKMUMwX2C3PwNw /KxwO9amWsY9wjxhpCly6BOY7Je4ypifUtP84sWn8U/pMiS5vw+t+oEi58O9VaHW11Sn rf3U/CaoHMXaB4ULVO1Bji03laRNI4kIfXPw0f2KPQT9007MDHLLkzeamM68T78XSTlx V2ue2k1dpCE16gWz87ePBCS4UQfVJRgQ5MBhUebdgjeSSTHfLHrFcVZs2/XN7GqWIPT/ eLGw== X-Gm-Message-State: AOAM531UHFsbCjM7mes/vtQsS1u2aUNL1Vru86CX4ZVOeG7tdpkxw/1k UyqoUGi4wgrPMjC3TpwqwMDlVdB087yod9TPm1NjQ7Y9ltf/uGfJdV0fBdKm6GWxMDoPnbdpoKN WUnwD3MYMq3KT63eJL9u2GF4Y X-Received: by 2002:a5d:6804:: with SMTP id w4mr22745183wru.363.1621864197371; Mon, 24 May 2021 06:49:57 -0700 (PDT) X-Received: by 2002:a5d:6804:: with SMTP id w4mr22745157wru.363.1621864197121; Mon, 24 May 2021 06:49:57 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id q1sm8044605wmq.48.2021.05.24.06.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 06:49:56 -0700 (PDT) From: Vitaly Kuznetsov To: Tom Lendacky Cc: Paolo Bonzini , Jim Mattson , Joerg Roedel , Sean Christopherson , Wanpeng Li , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Brijesh Singh , Ashish Kalra , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH] KVM: SVM: Assume a 64-bit hypercall for guests with protected state In-Reply-To: References: <87pmxg73h7.fsf@vitty.brq.redhat.com> Date: Mon, 24 May 2021 15:49:55 +0200 Message-ID: <87tums8cn0.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tom Lendacky writes: > On 5/24/21 6:53 AM, Vitaly Kuznetsov wrote: >> Tom Lendacky writes: >> >>> When processing a hypercall for a guest with protected state, currently >>> SEV-ES guests, the guest CS segment register can't be checked to >>> determine if the guest is in 64-bit mode. For an SEV-ES guest, it is >>> expected that communication between the guest and the hypervisor is >>> performed to shared memory using the GHCB. In order to use the GHCB, the >>> guest must have been in long mode, otherwise writes by the guest to the >>> GHCB would be encrypted and not be able to be comprehended by the >>> hypervisor. Given that, assume that the guest is in 64-bit mode when >>> processing a hypercall from a guest with protected state. >>> >>> Fixes: f1c6366e3043 ("KVM: SVM: Add required changes to support intercepts under SEV-ES") >>> Reported-by: Sean Christopherson >>> Signed-off-by: Tom Lendacky >>> --- >>> arch/x86/kvm/x86.c | 7 ++++++- >>> 1 file changed, 6 insertions(+), 1 deletion(-) >>> >>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >>> index 9b6bca616929..e715c69bb882 100644 >>> --- a/arch/x86/kvm/x86.c >>> +++ b/arch/x86/kvm/x86.c >>> @@ -8403,7 +8403,12 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) >>> >>> trace_kvm_hypercall(nr, a0, a1, a2, a3); >>> >>> - op_64_bit = is_64_bit_mode(vcpu); >>> + /* >>> + * If running with protected guest state, the CS register is not >>> + * accessible. The hypercall register values will have had to been >>> + * provided in 64-bit mode, so assume the guest is in 64-bit. >>> + */ >>> + op_64_bit = is_64_bit_mode(vcpu) || vcpu->arch.guest_state_protected; >>> if (!op_64_bit) { >>> nr &= 0xFFFFFFFF; >>> a0 &= 0xFFFFFFFF; >> >> While this is might be a very theoretical question, what about other >> is_64_bit_mode() users? Namely, a very similar to the above check exists >> in kvm_hv_hypercall() and kvm_xen_hypercall(). > > Xen doesn't support SEV, so I think this one is ok until they do. Although > I guess we could be preemptive and hit all those call sites. The other > ones are in arch/x86/kvm/hyperv.c. > > Thoughts? Would it hurt if we just move 'vcpu->arch.guest_state_protected' check to is_64_bit_mode() itself? It seems to be too easy to miss this peculiar detail about SEV in review if new is_64_bit_mode() users are to be added. -- Vitaly