Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp714466pxb; Fri, 14 Jan 2022 14:48:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMAOLOw+aJL6swJ92QbfTk61cKXA3mowfJl+ksMn1L0wmoq0HAJnQteefmB2hxoRomEtFh X-Received: by 2002:a17:907:9712:: with SMTP id jg18mr9328537ejc.328.1642200491719; Fri, 14 Jan 2022 14:48:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642200491; cv=none; d=google.com; s=arc-20160816; b=tlRObDUHlTk5NOhOEjtzNhvJziWwiL5eL4Wg2C2yxmBN7ocOL9FbN+bx670yY17GCk WJoNe1YRh/joa5cr84FCx0ndd4DElaTsz704PPb0Tez4lOViJda/73BoZM4fYHr+0yeo hc4IIlIf+8lOffnmPycyE+YGEF+HJToYcIRDyAiTNXtAEqGAAMJb+gTqMK2BTjArKBqL zRTUq035DXRnZnRamXakfacyuE58mgED6bZZE7wxdmay3QoEeugjIX8pBDf43NLMx+Kj mwIaAFPg2WQ4o9hMxSeMf2w61ud0rXtCjGZ69WLmOlk5vFXzYWDNXHEHmxMPdF34nlJD WmFQ== 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=7VMdD/jG1OhLf0ccWBGGvDrHOZitMiDuwr1tmbzaiPk=; b=wntSRtPNpkjFCRwCV/xEJJocyuaN2KfCf8TJSXx6E9iu7DM7vtC52YDJYoaiPPCg23 3jKaF5W7eNX08mBGBgiXaB0u5hH39ZHXr2tahTWUFlb7lePNCAtZUTkBPgAvGSBWXKmR crt0A0gaPscpQeLmLPYlQUFyM+ukbo+//N9ovNRCJNvwt2eMbEgMuoYNDifbcFfHNFwo QU5Q0x9Dnl4hP6gcfktM5px1trF6Ww165v5MogKcUZjCEKzhwwh2/oHka6oG0XyEwj1S wiQa/U1AiUFjfIFRueavdqGz6aLKmDidpnGq3Pz2rZTf5QtMrs/aBqSwN8lSnZrztYD1 +pOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dtsLpROv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hg4si4152954ejc.304.2022.01.14.14.47.47; Fri, 14 Jan 2022 14:48:11 -0800 (PST) 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=@google.com header.s=20210112 header.b=dtsLpROv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239062AbiANQSe (ORCPT + 99 others); Fri, 14 Jan 2022 11:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239095AbiANQSd (ORCPT ); Fri, 14 Jan 2022 11:18:33 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDAF8C06161C for ; Fri, 14 Jan 2022 08:18:32 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id f8so3141579pgf.8 for ; Fri, 14 Jan 2022 08:18:32 -0800 (PST) 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=7VMdD/jG1OhLf0ccWBGGvDrHOZitMiDuwr1tmbzaiPk=; b=dtsLpROvyW71vMsAeyUDpkELOk3IIZsyrBrQaMpABVKaCHSph5MPHi31CrLCVeFCfb qAC8978AT1Bv5z7usNwPhes62xlyu6fWhXnwKyXTmJavoREl5nY0j+RfLOSKddAbTqdj LYGlpYwRYf5bA/XS28pQ1V6/seMux030uA/Hf6VJF3ShDFU3OvNV8TiwSagntC0z1q43 KfvTqyoCJFhpjhe1qjy+ZS6RsNEVqWo1FcwAsKrWyP9er3vkh3pF+r2I8z1BllSkoWYS gwf4XuPebfTzvVx22RBy0MsH8/gwrfnKt6wCT6WLLZWZh+E3wRBL8j6/U/y+zS0L3gVL cDcw== 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=7VMdD/jG1OhLf0ccWBGGvDrHOZitMiDuwr1tmbzaiPk=; b=CjkVWKDlcceLqfM+aPC+U2auz49A19sXLe/+flhRVuHhfknjRTEz3AH9PgSGGSXF4+ kaHOYw/v8C8jXuaZ7+lhwsDIoiFfxyDaMBY+LrLofSNwBgBb8cNNT436rjy9rGWsH1+y MKXj+osrbDnTXKvUuKyv35TCLIwpOV3ihaB4Amh8A3tQOQnoqzLsOwIWURv44r/vC45N dc4MzYw49UlQrzW6JKkOxl7tgAHLHzFSEZYDNjyjmJuRyaUrFNIjLk9FKLl22+wNSoqC R/RJd4CAYVo8pcuIFLqsmMApnsGg4EujhIpGUd9F6uQVOqtg8RP1Gl6Hp6PkC5Bhvoxc z0WQ== X-Gm-Message-State: AOAM530obucSrspEAMrdYqE9WTveQ8fttqW12X3pF24x/EyPiLOLCtI5 s/jOsEbI5HrZG2PqAPWYT3kDfQ== X-Received: by 2002:a63:8548:: with SMTP id u69mr6595782pgd.306.1642177112043; Fri, 14 Jan 2022 08:18:32 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id m14sm5985121pff.151.2022.01.14.08.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jan 2022 08:18:31 -0800 (PST) Date: Fri, 14 Jan 2022 16:18:28 +0000 From: Sean Christopherson To: Zeng Guang Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "kvm@vger.kernel.org" , Dave Hansen , "Luck, Tony" , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , "Huang, Kai" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "Hu, Robert" , "Gao, Chao" Subject: Re: [PATCH v5 8/8] KVM: VMX: Resize PID-ponter table on demand for IPI virtualization Message-ID: References: <20211231142849.611-1-guang.zeng@intel.com> <20211231142849.611-9-guang.zeng@intel.com> <43200b86-aa40-f7a3-d571-dc5fc3ebd421@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43200b86-aa40-f7a3-d571-dc5fc3ebd421@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 14, 2022, Zeng Guang wrote: > On 1/14/2022 6:09 AM, Sean Christopherson wrote: > > On Fri, Dec 31, 2021, Zeng Guang wrote: > > > +static int vmx_expand_pid_table(struct kvm_vmx *kvm_vmx, int entry_idx) > > > +{ > > > + u64 *last_pid_table; > > > + int last_table_size, new_order; > > > + > > > + if (entry_idx <= kvm_vmx->pid_last_index) > > > + return 0; > > > + > > > + last_pid_table = kvm_vmx->pid_table; > > > + last_table_size = table_index_to_size(kvm_vmx->pid_last_index + 1); > > > + new_order = get_order(table_index_to_size(entry_idx + 1)); > > > + > > > + if (vmx_alloc_pid_table(kvm_vmx, new_order)) > > > + return -ENOMEM; > > > + > > > + memcpy(kvm_vmx->pid_table, last_pid_table, last_table_size); > > > + kvm_make_all_cpus_request(&kvm_vmx->kvm, KVM_REQ_PID_TABLE_UPDATE); > > > + > > > + /* Now old PID table can be freed safely as no vCPU is using it. */ > > > + free_pages((unsigned long)last_pid_table, get_order(last_table_size)); > > This is terrifying. I think it's safe? But it's still terrifying. > > Free old PID table here is safe as kvm making request KVM_REQ_PI_TABLE_UPDATE > with KVM_REQUEST_WAIT flag force all vcpus trigger vm-exit to update vmcs > field to new allocated PID table. At this time, it makes sure old PID table > not referenced by any vcpu. > Do you mean it still has potential problem? No, I do think it's safe, but it is still terrifying :-) > > Rather than dynamically react as vCPUs are created, what about we make max_vcpus > > common[*], extend KVM_CAP_MAX_VCPUS to allow userspace to override max_vcpus, > > and then have the IPIv support allocate the PID table on first vCPU creation > > instead of in vmx_vm_init()? > > > > That will give userspace an opportunity to lower max_vcpus to reduce memory > > consumption without needing to dynamically muck with the table in KVM. Then > > this entire patch goes away. > IIUC, it's risky if relying on userspace . That's why we have cgroups, rlimits, etc... > In this way userspace also have chance to assign large max_vcpus but not use > them at all. This cannot approach the goal to save memory as much as possible > just similar as using KVM_MAX_VCPU_IDS to allocate PID table. Userspace can simply do KVM_CREATE_VCPU until it hits KVM_MAX_VCPU_IDS...