Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2729905imw; Wed, 6 Jul 2022 10:43:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uLhMnRrFf7Xji8F6SWDoR+MEZY6rDl9GuZfCS/m5M/h/9y9k0gbqV0dCypwtTVcGBiRoX1 X-Received: by 2002:a17:907:2d08:b0:726:35bd:b3c1 with SMTP id gs8-20020a1709072d0800b0072635bdb3c1mr39658304ejc.281.1657129429229; Wed, 06 Jul 2022 10:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657129429; cv=none; d=google.com; s=arc-20160816; b=xDbtakAjYMKVN6hMsv2lWN6g0/N7DO3EZqfOKPkZnNvOZHOQjH5g4hInovsdpudcYD z9t++p3PL308LqSWGEU4fx3zsquuCpk2YhJLzeuRUUE5PSuGJ339KmDQldA6oR5UUAsQ IH9YgCwOUgrdjsgR2h3dDYXaUHnwMMMCQBR2Ra9ovt0BSSlOkv2KiduBVV6PUt3uYCUU Oaab+tv5PGHrRITajwZUqfyeTmoXqrhRJ+B6NrMsVWG4Ce7fYmD6hO7EldduAH5DaAy2 6v6A9d7RuqKaLqzSnHM2wFIpB/s9a4WFdeBv0gZ9ySEhRmf1l3zbQ9BACqmbcjkKvoBA nnUg== 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=n6GVhQmBGVKBhGa5woMm6aogTfqoCNqPgCzOl2ffqrA=; b=MjqkzalgnOghr3VjrgyfulXrdRJ+UT6guIHss64ULeF15MfIDhP2fPXC/ec2w2PeN3 6Tary038c1gR2U/0Wux+kN+6VAA2QQD3S6M/kEG9T6bxmMvNvCJzYq2OTL7IgaphHUh+ m/EijaFi+qz04K+LedDgDK0IUVApcW3wkDqrp0gRO26MNrg3V0IXwUYNSTo285eixBhb 890yuYeojy6vC6oSBWw3Q2ITAzbeYk28k5r9QelTQTYem3shsRxSRW6qtYwWSF8M7X99 HGFzo7OPgd/GtM5IoPvAHm/I92ToFcFRHUOO0VQ4AfJPTDUJlAvv45HLIeU3f93uVsFq 9D2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=e1xeUsyT; 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 o18-20020a1709061d5200b0072ae77434a3si2365898ejh.297.2022.07.06.10.43.22; Wed, 06 Jul 2022 10:43:49 -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=e1xeUsyT; 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 S233786AbiGFRgs (ORCPT + 99 others); Wed, 6 Jul 2022 13:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233160AbiGFRgq (ORCPT ); Wed, 6 Jul 2022 13:36:46 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A1EE1E3E8 for ; Wed, 6 Jul 2022 10:36:45 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 89-20020a17090a09e200b001ef7638e536so12866250pjo.3 for ; Wed, 06 Jul 2022 10:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=n6GVhQmBGVKBhGa5woMm6aogTfqoCNqPgCzOl2ffqrA=; b=e1xeUsyT+W+flSShjjnjyN4TfbfrsLh9Fog2om/V0KJWvgtiMuK0jePKuTI8hlaAHX F+WQOOR1u9I03ck70NXzlfW2Ygp/WcfDkgRBchk7NZc7ZqXNjn4u3fDUoFwioxc1YUvK d37Fx05W0yx3P7PROVg1GXABbwtaeqIPhrIiEO+0I80c0W53bDFXFkgwYgv+qOrQELuP knK+IRouM8+hNF24Z5WPGNAVnI8ObiAWhbj1IEPrTV1rDci+wsq+4IR3OLINoGimlxfK D+4cB9HnimksBtqJ2Rg97LOR/dbhF0dYnp2I4jX7mtF0XsBublRREU029Pl4DpQdNiNj QCvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=n6GVhQmBGVKBhGa5woMm6aogTfqoCNqPgCzOl2ffqrA=; b=WRggsP9MUgmFfXIZQ6toDzdPx/QRv0Gj04PcyfHhtcWU4jNDSe+S8lyyArw1J0PADG PVXb+23FCmlNj/j+ZZWDYDb00YQnczbH0C9/5hSpmsIa4ns6ZsaPs8rFdVFuy/WC70MJ kNMN54cWBKzi1jKWlhPrqbQeKV49pIU0dYq+tiCv8URiE+ZaSpiZrQeGSzYzkimgnuZo Q7KfNjBbP1FhPuq5+elyeQGqq5BY3a8AsqepShE/6qaCONgq7121pdS9WbbPTnNAufLm 0146jkmipFl8UX6GfiwnatzyeWaot00PjySYehveIBId7teEsSdQG26AZdFnchLIApmT fMlA== X-Gm-Message-State: AJIora/udz8d6MNFcHolA4WVDFJmejbKRIAuu85nGu7PtbhmeI8FwDP/ 5k6kPHdSKwPuDjLNYqFduVEX/w== X-Received: by 2002:a17:903:2443:b0:16a:29ac:27c2 with SMTP id l3-20020a170903244300b0016a29ac27c2mr46952180pls.46.1657129004700; Wed, 06 Jul 2022 10:36:44 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id g15-20020a63564f000000b004129741dd9dsm1519871pgm.51.2022.07.06.10.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 10:36:43 -0700 (PDT) Date: Wed, 6 Jul 2022 17:36:39 +0000 From: Sean Christopherson To: Maxim Levitsky Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Upton , Peter Shier Subject: Re: [PATCH v2 13/21] KVM: x86: Formalize blocking of nested pending exceptions Message-ID: References: <20220614204730.3359543-1-seanjc@google.com> <20220614204730.3359543-14-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,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=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 On Wed, Jul 06, 2022, Maxim Levitsky wrote: > On Tue, 2022-06-14 at 20:47 +0000, Sean Christopherson wrote: > > Capture nested_run_pending as block_pending_exceptions so that the logic > > of why exceptions are blocked only needs to be documented once instead of > > at every place that employs the logic. > > > > No functional change intended. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/svm/nested.c | 20 ++++++++++---------- > > arch/x86/kvm/vmx/nested.c | 23 ++++++++++++----------- > > 2 files changed, 22 insertions(+), 21 deletions(-) > > > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > > index 471d40e97890..460161e67ce5 100644 > > --- a/arch/x86/kvm/svm/nested.c > > +++ b/arch/x86/kvm/svm/nested.c > > @@ -1347,10 +1347,16 @@ static inline bool nested_exit_on_init(struct vcpu_svm *svm) > > > > static int svm_check_nested_events(struct kvm_vcpu *vcpu) > > { > > - struct vcpu_svm *svm = to_svm(vcpu); > > - bool block_nested_events = > > - kvm_event_needs_reinjection(vcpu) || svm->nested.nested_run_pending; > > struct kvm_lapic *apic = vcpu->arch.apic; > > + struct vcpu_svm *svm = to_svm(vcpu); > > + /* > > + * Only a pending nested run blocks a pending exception. If there is a > > + * previously injected event, the pending exception occurred while said > > + * event was being delivered and thus needs to be handled. > > + */ > > Tiny nitpick about the comment: > > One can say that if there is an injected event, this means that we > are in the middle of handling it, thus we are not on instruction boundary, > and thus we don't process events (e.g interrupts). > > So maybe write something like that? Hmm, that's another way to look at things. My goal with the comment was to try and call out that any pending exception is a continuation of the injected event, i.e. that the injected event won't be lost. Talking about instruction boundaries only explains why non-exception events are blocked, it doesn't explain why exceptions are _not_ blocked. I'll add a second comment above block_nested_events to capture the instruction boundary angle. > > + bool block_nested_exceptions = svm->nested.nested_run_pending; > > + bool block_nested_events = block_nested_exceptions || > > + kvm_event_needs_reinjection(vcpu); > > Tiny nitpick: I don't like that much the name 'nested' as > it can also mean a nested exception (e.g exception that > happened while jumping to an exception handler). > > Here we mean just exception/events for the guest, so I would suggest > to just drop the word 'nested'. I don't disagree, but I'd prefer to keep the current naming because the helper itself is *_check_nested_events(). I'm not opposed to renaming things in the future, but I don't want to do that in this series.