Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2351397rwd; Fri, 2 Jun 2023 08:16:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5eC12VOvnXZcooqGpIQs65JTfjDhtnVgGNvPzsYK5Zw+AJKIp8DEt1dLH7K8Kz/+b9inE9 X-Received: by 2002:a17:90a:4b0c:b0:256:a705:afdd with SMTP id g12-20020a17090a4b0c00b00256a705afddmr148321pjh.44.1685718962176; Fri, 02 Jun 2023 08:16:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685718962; cv=none; d=google.com; s=arc-20160816; b=KegHNdGz3stLSuFGIFSIF+XHJXarU9YYXGEOy54qsT7sZyg03D8OxMsTFCYdunh6t7 FFpHQUsmgCSbvVWQGuWOReMRf8mSr129JkoV1U+QTvKj38yh7TRJJ5UTm6EvrOp/phTC RrDasOsq+fuAhvro2UYD5B4GgSdu27QZUZVfTU6v8Y/sZJZ6YH2lA7qJeI7foexekHta Rbjff/nwxIqdc41XsoS7pwvKZwvRvXgXWGPNrkDY7tJVPnYwAuqMliF2nZEMKuUuAT4R ZMFNnpD1k87uFTowsgUmVp0N+tdiajyKZ5NnkRL0HvXPzTlypTFJLjvjKFqaMlgMI9cP 8w8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Nm6pXa+HYoxt2r3AeUI919wrQrfzAxz3+IaYjnh25eI=; b=wT8kOY7+by+DAaGUugbVwLoABSsu9yEe21TCcneTIJXtgZwEXqJG9SaPUFd/AkME2i QR5KsAdLt9DESAkoE0bfRhlPo3vszJYfh2uwVOcL8Qz1zFsjEJkHdDTlGQv50CSGJZiW VoefwQ64RhmgP26ldLStUbyCTeWIhFSsblLS6Si9t4w997REel4MIwR9uDD7VActV7pN JMlNp02zFjZXGLmm7WEvWOxrS9J4wikI464byIs8SY96ICiqfdb2ux/M9dFkl8Cy+q4S oPDQGjQLqaZ2EH/EDvrgJumjR+Ybd7oOUlg1ZthikXWdEiP5i6HtnpCAwpmaO+HC6bLU v7UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=CR6zAayu; 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 d11-20020a17090a628b00b0025667542f45si1178350pjj.99.2023.06.02.08.15.50; Fri, 02 Jun 2023 08:16:02 -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=20221208 header.b=CR6zAayu; 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 S236463AbjFBPJR (ORCPT + 99 others); Fri, 2 Jun 2023 11:09:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236443AbjFBPJM (ORCPT ); Fri, 2 Jun 2023 11:09:12 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE61E4D for ; Fri, 2 Jun 2023 08:09:10 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-53425d37f33so1015255a12.3 for ; Fri, 02 Jun 2023 08:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685718549; x=1688310549; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Nm6pXa+HYoxt2r3AeUI919wrQrfzAxz3+IaYjnh25eI=; b=CR6zAayusmivzJXEJTT4xo41SprWgGVKmqxFpPcnXXCOZwv7rQ9YKugBL49IUmT5H/ PXmEs2DPAZMaS5HhhZJNSemLJtYyT8LFyswtbyKobbyBSQbTUfYwPaWZucrdpIHB8+c4 SLyxcE4ec5RHEi3fRT1aB/W8mhIACorI2bWFhs5OWRBJ76EkoLy/6OsSnETFnMXt8LAe m5EUq+h3s0MoRf31rqQh7zeEaNqNc1hchJ9rOYTXf3a3HKjTr+jqZ2Lp+657W1rE58AT gYnO93OXQM7Qx9RQvDEV4jqFXRVNQU5JUNumZCgMzg+MMzETwv6b3lf8tAxd5C9lQ+ZK Hs4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685718549; x=1688310549; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Nm6pXa+HYoxt2r3AeUI919wrQrfzAxz3+IaYjnh25eI=; b=bk4+tXxxB29WXTRJBHFvtBLzQ5t125U34+eFX6LN/XAUvb/83+fNfH4NgLN88pmWW3 QHhsic4dRYCgwj4tx/dlpJrgm3Met3CKNcZGXqYRKiAB3Mk3G96fJOoif0UOUv2IiFl1 FjiSViDFlZT+/VbExEVm6VhZ785G50D+6LFNGya3LE81ROfr69xOz3Xgqg1ISltZZcDy /7KlH8C7okCLj5J1sIGco8CZXNSr9q2RMfvJUxOp7kWbg54TFdLnBuEKkNBZNiLG7aiv p1JLqbLAyw1GhT2JkA6w9D01M8vOlKopiGJN3RmKHCds530aQBiVky6X4KmpwsslIa+5 etEQ== X-Gm-Message-State: AC+VfDwSzHB5SpiCq6eBMfZu9h7/BZOjILcap6IIpYpxHTov3B+ue3iR CpEfve5Fg+18O3XgNuYoN3H8xV2VjDU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:5f16:0:b0:52c:8878:65dd with SMTP id t22-20020a635f16000000b0052c887865ddmr2374005pgb.0.1685718549518; Fri, 02 Jun 2023 08:09:09 -0700 (PDT) Date: Fri, 2 Jun 2023 08:09:07 -0700 In-Reply-To: <28bd9d11-282f-bb22-66f5-d3d9165d4adf@gmail.com> Mime-Version: 1.0 References: <20230602005859.784190-1-seanjc@google.com> <28bd9d11-282f-bb22-66f5-d3d9165d4adf@gmail.com> Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: Add "never" option to allow sticky disabling of nx_huge_pages From: Sean Christopherson To: Robert Hoo Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Li RongQing , Yong He , Kai Huang Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 Fri, Jun 02, 2023, Robert Hoo wrote: > On 6/2/2023 8:58 AM, Sean Christopherson wrote: > > @@ -6860,15 +6871,29 @@ static int set_nx_huge_pages(const char *val, const struct kernel_param *kp) > > bool old_val = nx_huge_pages; > > bool new_val; > > + if (nx_hugepage_mitigation_hard_disabled) > > + return -EPERM; > > + > > /* In "auto" mode deploy workaround only if CPU has the bug. */ > > - if (sysfs_streq(val, "off")) > > + if (sysfs_streq(val, "off")) { > > new_val = 0; > > - else if (sysfs_streq(val, "force")) > > + } else if (sysfs_streq(val, "force")) { > > new_val = 1; > > - else if (sysfs_streq(val, "auto")) > > + } else if (sysfs_streq(val, "auto")) { > > new_val = get_nx_auto_mode(); > > - else if (kstrtobool(val, &new_val) < 0) > > + } else if (sysfs_streq(val, "never")) { > > + new_val = 0; > > + > > + mutex_lock(&kvm_lock); > > + if (!list_empty(&vm_list)) { > > + mutex_unlock(&kvm_lock); > > + return -EBUSY; > > + } > > + nx_hugepage_mitigation_hard_disabled = true; > > + mutex_unlock(&kvm_lock); > > + } else if (kstrtobool(val, &new_val) < 0) { > > return -EINVAL; > > + } > > > > IIUC, (Initially) "auto_off"/"off" --> create some VM --> turn to "never", > the created VMs still have those kthreads, but can never be used, until > destroyed with VM. Shouldn't be able to happen. The above rejects "never" if vm_list isn't empty, i.e. if there are any VMs, and sets nx_hugepage_mitigation_hard_disabled under kvm_lock to ensure it can't race with KVM_CREATE_VM. I forgot to call this out in the changelog though.