Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp794382rwe; Thu, 25 Aug 2022 09:11:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JmHmOqlTkflq4YJz0eVaFfVn66saLvY7UWTQ9LqmjkCXD3v0LE8nOne9zXqu+F47xZ3yx X-Received: by 2002:a17:907:16a6:b0:73d:de5f:8b22 with SMTP id hc38-20020a17090716a600b0073dde5f8b22mr642900ejc.261.1661443879491; Thu, 25 Aug 2022 09:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661443879; cv=none; d=google.com; s=arc-20160816; b=eG+UXmcsu2tBw/9f51ePEO5phQvqSN/Zo8XMisfaD/qi8vlchD4yyG8zXK60J4BkIG sV5bHl/0ygEgJvcoXN7thzmArr7yXMzcii2QOd51d3U4Lvv/8o5oJMS4blKTROiFAN4i TztzHUbC3eJU1N+BqZPCjgJj8uL7Rw4Kd0+rFJvrCkiziluOctUmIUF8ZL9GObn96muZ lvODaNvpMStwYXgx/LwqjH3kVqJAhBWyLbJQ3py/7OE5DpxralxFw8P6EGv9Sf/eb2+k gXBJLYKkItsA1BuZuBVkmbV5uFHDQi6yZKS9qFhtnoqXvsdZ1Q1xWjmCEpIiQhJmH9sa vjhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lkpFp7wJllz+fu6eLPih5PvFqPT3ByhDxfAjsVV14FA=; b=02Ykyo+0m1OtcmDMllpe4Bq1Go3qoLEX5eXcMEaWX0ilqRnKV3t5rbR2NDwnG4hHXq fUR+e5fBVZzt85Ltzocx1Jqj2PbwwHpPuOR16FkE1d1NwsTScCgAwNDtJ90Tkxuu3i5A FGsNbQRnRkjLy+k1WHwYi988EfI3BxwQjaTLQ6YuXwzIE4bRv6mWD9ZGpfroo0Bg9N6r 65QIemnUgV+3b/YAzdF8fvA1jM+zgnt4tJRS81HAqw86NvLOZJLtfmCj/HLIVS/gmkjq r9AhDnmobUQ4qS0TRpZoF0NsSStXwHXVuWYLK+1zN1UgSQPxJBwdZdeVKFJWn9OPpkEe uV+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cxKhA2Zb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a50c907000000b00446090a70f0si5932807edh.488.2022.08.25.09.10.52; Thu, 25 Aug 2022 09:11:19 -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=@google.com header.s=20210112 header.b=cxKhA2Zb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233141AbiHYPof (ORCPT + 99 others); Thu, 25 Aug 2022 11:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237660AbiHYPoc (ORCPT ); Thu, 25 Aug 2022 11:44:32 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEE3DAA3CF for ; Thu, 25 Aug 2022 08:44:31 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id y127so17195496pfy.5 for ; Thu, 25 Aug 2022 08:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=lkpFp7wJllz+fu6eLPih5PvFqPT3ByhDxfAjsVV14FA=; b=cxKhA2ZbI3qXBQ9J+dqf+awbKPsIqG7QTdGumRHtTPcq9s0h7GNthbM7hPWbG6mCDv 8/pYm7f6tUspB31Zwg2WJZ8uHQleKkQ52ZvYmhq8uqjErHNyUJkH/taj+xN8vVhjcQAi k0Y+3sLbmE1w88vY6ibS21WxKF8re4nG4jCA49WQUz1OEbLOE/5q5kmtWxPdfXILiamo HjRy/Pq1kccl8sQNSf/wNFM8XMtCEii4LQZSBp/WXn9XIuRug9EiQYvGcsDUp5sP6UpM T5gpUy3FYWnvpzmCpeLmlvSPowgKziH4/evG2QP/aS5qCpPmCCC/63gpDNzy1qvwhvLs N0Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=lkpFp7wJllz+fu6eLPih5PvFqPT3ByhDxfAjsVV14FA=; b=GdgaJ82DX/YOj2yH5A36ZI+JthbzgLsJ77YpF9QV50LC9HTtwZCpKL8cNkoLdPFlMn A0nmfgjgRC+ShZ+HFW4Hm9M9WZGxZzn8WgeKOunMeTmJ5Una4egzBM0zBacIrK/0VhZd MYlm3B32CZ58tVS5z/qeKVmCnsFT9jbtPZYSzWFN7UF1EsqELUf196KYVIGc/cdVR2D5 N7RmqM7mSn+xSJyUw4EZ0XArvNH78nL3gRM4lwUJFbudlgJGuCeZHa1ZOTbsqNil9Qbg wqX14dIWpBypIVszc+HD26m6QbqEA/k0gjpU9R+AtwY2nFHgoiYORP22gWICpOJ/omUk SE/Q== X-Gm-Message-State: ACgBeo2sm19tggtG0IuEKIa8wFUNhHjPtQZCCDm1MuQLr7qTP2LF4lOt E5GgX9NoGZXPCbIHJakjFYcUNw== X-Received: by 2002:a63:88c1:0:b0:42b:49b3:3a7f with SMTP id l184-20020a6388c1000000b0042b49b33a7fmr3400773pgd.64.1661442270940; Thu, 25 Aug 2022 08:44:30 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id z6-20020a63e106000000b0042a2777550dsm12434721pgh.47.2022.08.25.08.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:44:30 -0700 (PDT) Date: Thu, 25 Aug 2022 15:44:26 +0000 From: Sean Christopherson To: Maxim Levitsky Cc: kvm@vger.kernel.org, Borislav Petkov , Dave Hansen , linux-kernel@vger.kernel.org, Wanpeng Li , Ingo Molnar , x86@kernel.org, Jim Mattson , Kees Cook , Thomas Gleixner , "H. Peter Anvin" , Joerg Roedel , Vitaly Kuznetsov , Paolo Bonzini Subject: Re: [PATCH v3 13/13] KVM: x86: emulator/smm: preserve interrupt shadow in SMRAM Message-ID: References: <20220803155011.43721-1-mlevitsk@redhat.com> <20220803155011.43721-14-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,FSL_HELO_FAKE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=no 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 Thu, Aug 25, 2022, Maxim Levitsky wrote: > On Wed, 2022-08-24 at 23:50 +0000, Sean Christopherson wrote: > > On Wed, Aug 03, 2022, Maxim Levitsky wrote: > > > @@ -518,7 +519,8 @@ struct kvm_smram_state_32 { > > > u32 reserved1[62]; > > > u32 smbase; > > > u32 smm_revision; > > > - u32 reserved2[5]; > > > + u32 reserved2[4]; > > > + u32 int_shadow; /* KVM extension */ > > > > Looking at this with fresh(er) eyes, I agree with Jim: KVM shouldn't add its own > > fields in SMRAM. There's no need to use vmcb/vmcs memory either, just add fields > > in kvm_vcpu_arch to save/restore the state across SMI/RSM, and then borrow VMX's > > approach of supporting migration by adding flags to do out-of-band migration, > > e.g. KVM_STATE_NESTED_SMM_STI_BLOCKING and KVM_STATE_NESTED_SMM_MOV_SS_BLOCKING. > > > > /* SMM state that's not saved in SMRAM. */ > > struct { > > struct { > > u8 interruptibility; > > } smm; > > } nested; > > > > That'd finally give us an excuse to move nested_run_pending to common code too :-) > > > Paolo told me that he wants it to be done this way (save the state in the > smram). Paolo, what's the motivation for using SMRAM? I don't see any obvious advantage for KVM. QEMU apparently would need to migrate interrupt.shadow, but QEMU should be doing that anyways, no? > My first version of this patch was actually saving the state in kvm internal > state, I personally don't mind that much if to do it this way or another. > > But note that I can't use nested state - the int shadow thing has nothing to > do with nesting. Oh, duh. > I think that 'struct kvm_vcpu_events' is the right place for this, and in fact it already > has interrupt.shadow (which btw Qemu doesn't migrate...) > > My approach was to use upper 4 bits of 'interrupt.shadow' since it is hightly unlikely > that we will ever see more that 16 different interrupt shadows. Heh, unless we ensure STI+MOVSS are mutually exclusive... s/16/4, because KVM_X86_SHADOW_INT_* are currently treated as masks, not values. Pedantry aside, using interrupt.shadow definitely seems like the way to go. We wouldn't even technically need to use the upper four bits since the bits are KVM controlled and not hardware-defined, though I agree that using bits 5 and 6 would give us more flexibility if we ever need to convert the masks to values. > It would be a bit more clean to put it into the 'smi' substruct, but we already > have the 'triple_fault' afterwards > > (but I think that this was very recent addition - maybe it is not too late?) > > A new 'KVM_VCPUEVENT_VALID_SMM_SHADOW' flag can be added to the struct to indicate the > extra bits if you want. > > Best regards, > Maxim Levitsky > > >