Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5796647imw; Wed, 20 Jul 2022 12:45:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uVU/LJzCJL8mzKXTpU62mVvjzPGu6sVkSqVbUuO7XO7SrhvifVDM2hd5vcxYXHrE7qsoS2 X-Received: by 2002:a63:ff66:0:b0:412:6f4c:1e11 with SMTP id s38-20020a63ff66000000b004126f4c1e11mr35156701pgk.396.1658346312102; Wed, 20 Jul 2022 12:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658346312; cv=none; d=google.com; s=arc-20160816; b=jEIamh2ZDYB3m9RoCbW9TWgwCdaBwhOOEnoBvUuz1uSQrBZIKhm+P93E/MPF0m988w n4M92LO9XpZBYRUNTkP0SrCm0C+vExyZcsy9ZMi3DZXNVUKNl35BXUxwmzeFEKoYLcNZ x8BfxAuCxAYS87a8TWOswJABBBykTZWqtDcDVmd3gFft4bnrfj3edh/IohKBx2TukaV4 k7XzY1JD0CaZx2+e3Z5A/hFxXsPgNY8HOuyhzFQscsqDr2x/+SHREchF7z5zVn/QzmNr Ks9f5AqXUKHb0qcXmSKuute7x648PQpTLcWXKGx68IpQQxPfDsGKxPY1dR1KhSNPjRg7 OayA== 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=R5uXVH2fF6MLNsy3ov8PgE+td36txTWTocMZT8dvLYI=; b=rPNaOgvpTgseYFM78lXc5ucXzZ4FaYL1EzV5Y9UoJeHCXsHrjPHQWQujE/j/LXgUlH N04hug+3mw/bLLaoKMJUpJvhEpWTGy+2RYO2JBw8W7JFpHxvyRHN36Tz/wJIUKsCU9Sr cRwl9fsInQGuAie5AZohtWHV4v49RO5tmrtazunAZ4438t3PGTiP9j4FSkUVWTmzP/iw qsDINvL1cBqAQT6j7FYkYD1ztDoNkj4P5mj+78I1zyHejRU+PX/P5g8A/A3TAoQkfF4e AhKnAftaknKVpmHs45NhJf1k/pjr5QWeamlIVpD+g6icQAsTtmz9+AJHRb1NvAuHWVAk C69w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tUpMUK3C; 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 n6-20020a170902d2c600b0016a44f6174bsi24859323plc.593.2022.07.20.12.44.57; Wed, 20 Jul 2022 12:45:12 -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=tUpMUK3C; 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 S234299AbiGTTad (ORCPT + 99 others); Wed, 20 Jul 2022 15:30:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbiGTTac (ORCPT ); Wed, 20 Jul 2022 15:30:32 -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 1E0714C60B for ; Wed, 20 Jul 2022 12:30:31 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id q41-20020a17090a1b2c00b001f2043c727aso3219008pjq.1 for ; Wed, 20 Jul 2022 12:30:31 -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=R5uXVH2fF6MLNsy3ov8PgE+td36txTWTocMZT8dvLYI=; b=tUpMUK3CXSSqTqSsNSyfVAvczsgHExIXku9xqI2aVqo1miZ2YkD3PMPf2FBcMhkjcd MsiaoSCo9lYd6hv+ZaRJ6uEjQes7UhEna1YSkBfFfdQAXJ/VBGQm7rhNioqj6Bdt8uSl InihP5ilTMzjnWZ6PuyyBWnJ2NTd79b/iLx+di0EouWVPLw8G+gEzblFjAuFqzhl8oEw 9BEGp+dK3ji3CAa/FgNF5qi6E39MeG1tYhxTBOaMm5COP+PefRVEAMBhhN+GkUnEjEeq iwPIM+v+dAh+pqgN1nBSQs53MAf8aZBxq2QzKEvjnkLNQKmpo+2/SEYU69xKYzJzM7rE MzNQ== 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=R5uXVH2fF6MLNsy3ov8PgE+td36txTWTocMZT8dvLYI=; b=q5as1RWNBF1CMW+kWiQqx+UChqbI7iW8m/EF1qgYgVjhqKmLhC4y2UUn06dOG0+G1u rSe1fEeUZnFytHJMUkDbdMr7atb6SymHADN8c1gsH7ecpTwDimvNlAL3dVdnQRvlyUXf gkpgGUXfywcrIhzs94xnS0+nJQcIk3X8zHULmqgI8GeEs+4GIOwnPcGp1p7eNXesTHEO 9o/xCC61v7faVEPqJya1MF/MSgPnBf32lVmJUKjHDXL0kobPuY7rm8O5kqCKz30RAi6k vhg8yOBTL3HHHFz9PFHJwWMZODumqLiYQ6kHtDsrenUlh511Dc/IL6XwfuWFd4Vbq785 OCEg== X-Gm-Message-State: AJIora92h8Q+6BGl4lte0Rr6ei9WxCOQoq5aNzncIV/S9SMCBFX6R8lx mKtEny3d46NiALksP6re6VLQow== X-Received: by 2002:a17:90b:38d0:b0:1f0:5205:4b5c with SMTP id nn16-20020a17090b38d000b001f052054b5cmr7013547pjb.201.1658345430481; Wed, 20 Jul 2022 12:30:30 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id a8-20020a170902710800b0015e8d4eb1d7sm14122579pll.33.2022.07.20.12.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 12:30:29 -0700 (PDT) Date: Wed, 20 Jul 2022 19:30:25 +0000 From: Sean Christopherson To: Kechen Lu Cc: "kvm@vger.kernel.org" , "pbonzini@redhat.com" , "chao.gao@intel.com" , "vkuznets@redhat.com" , Somdutta Roy , "linux-kernel@vger.kernel.org" Subject: Re: [RFC PATCH v4 5/7] KVM: x86: add vCPU scoped toggling for disabled exits Message-ID: References: <20220622004924.155191-1-kechenl@nvidia.com> <20220622004924.155191-6-kechenl@nvidia.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, 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 20, 2022, Kechen Lu wrote: > > > @@ -6036,14 +6045,17 @@ int kvm_vm_ioctl_enable_cap(struct kvm kvm, > > > break; > > > > > > mutex_lock(&kvm->lock); > > > - if (kvm->created_vcpus) > > > - goto disable_exits_unlock; > > > + if (kvm->created_vcpus) { > > > > I retract my comment about using a request, I got ahead of myself. > > > > Don't update vCPUs, the whole point of adding the !kvm->created_vcpus > > check was to avoid having to update vCPUs when the per-VM behavior > > changed. > > > > In other words, keep the restriction and drop the request. > > > > I see. If we keep the restriction here and not updating vCPUs when > kvm->created_vcpus is true, the per-VM and per-vCPU assumption would be > different here? Not sure if I understand right: > For per-VM, we assume the per-VM cap enabling is only before vcpus creation. > For per-vCPU cap enabling, we are able to toggle the disabled exits runtime. Yep. The main reason being that there's no use case for changing per-VM settings after vCPUs are created. I.e. we could lift the restriction in the future if a use case pops up, but until then, keep things simple. > If I understand correctly, this also makes sense though. Paging this all back in... There are two (sane) options for defining KVM's ABI: 1) KVM combines the per-VM and per-vCPU settings 2) The per-vCPU settings override the per-VM settings This series implements (2). For (1), KVM would need to recheck the per-VM state during the per-vCPU update, e.g. instead of simply modifying the per-vCPU flags, the vCPU-scoped handler for KVM_CAP_X86_DISABLE_EXITS would need to merge the incoming settings with the existing kvm->arch.xxx_in_guest flags. I like (2) because it's simpler to implement and document (merging state is always messy) and is more flexible. E.g. with (1), the only way to have per-vCPU settings is for userspace to NOT set the per-VM disables and then set disables on a per-vCPU basis. Whereas with (2), userspace can set (or not) the per-VM disables and then override as needed.