From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E926423D2B4 for ; Wed, 17 Dec 2025 19:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765998123; cv=none; b=TOOjJwBIueuEnGTgfE4AhbzEfimWfzbh6OC9Zlu+FZr1km1eW/WwP6axFnJyWxffpYzISWby6F8p20f2ANpjrgSGuRq/DuDRM4ZXkKIv+lGxYxnPpJZt819Ok40SKdMh7TfB2eMJkoG36j0Kw1HeTz9blhTYDPIqavfozJN0aYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765998123; c=relaxed/simple; bh=m8dUE8g1LgHdwHNkk7BZCZqvG8Sc2oxSqpY7oOcjwS8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SZAzHG0Xs86QZkRYdvAf5t+7DwIPWXLt+ON++JVjjEimk6rivNfYF9gV0m0TaSBralkQz5Q/3y7ViXXusnNAa0+v/B4EiAtr2bBGrzcDLf/3BUHmfqomT7eu03ckdgVieIHmWHCpnOU+jQR3ViOr064cTTLiU8Y40nWSM/i4+eE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Tk54E9qi; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Tk54E9qi" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7d481452732so10558294b3a.1 for ; Wed, 17 Dec 2025 11:02:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765998121; x=1766602921; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=b196TMa7CXfRLkl43jhb5OXtBZInCMzwhdlHo087zrU=; b=Tk54E9qi4MiMA0y5NpRq6xBFYTgmmnM2yLFUj29qnEYcV1illL9PbuISppdH6BzKdM /ldOqZtIlrL7KeI0WSBJIkqBO79rKbu9z6l7l957mjEzlFzgw60TQr7aC/k0ZmadNz9E WMt+TERJqdEMdYxtSNtHH85+EqwMUqKLy7Af2pajMmOPD7+I5JJmM0UQOm6ZVTm9Emmq FkrpsD1ePMTfyvrMdpzMAfT1TQJ8tnZL2LkML0QhaXpRngnc6LuzTQ/KUTH2di0zqz+z gYXMsfMkMPX0gukHF0j7w//SKQxqC5I9sO3v6xTsbeXR2tUGyWsCIpXUJBJo0QKg5ia/ EsRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765998121; x=1766602921; 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=b196TMa7CXfRLkl43jhb5OXtBZInCMzwhdlHo087zrU=; b=X5g0ra2h19rc0fqj6YKJB5OuyTZrAPod/seC1Z8XK6M9ZhvdwH+hjNBpz6Ffmswhvt JJY7sMUQ/VLdoxuT2rVORDus5ZK7TyKwRAyDUgTrcaxB7HfzlGyXwvYIea/SEWAnzGdx waFsyv6nXJ8NV6IyMbphPslk2Y09DwqDFQFEQHU4PdIWKK3ed0L8HgVmiUKsUX241cqX wfv8AXE/8oTuqU2DaBp3Dg/+Rh7c+YiuGFaEOQZ9bubemSH2lFj+kVx/tJlC6Hh0z/7X d4iG7wFXYsvVEOGwLYLgjWd6ikxwRDIsUauPv0sfxGkdAMT2dDf2bKxnEYiOdYURPkap msyA== X-Forwarded-Encrypted: i=1; AJvYcCX0FZTdSQAO4HdRWSLv+XijY4DJwnkycN8SlHve7IycD9keXGaLkBbah5QeJTRQNO2nB9TS+7Mix7mRO3A=@vger.kernel.org X-Gm-Message-State: AOJu0YxZmCxkqP/Th5mxXG/4mBQelqTHpOBFDVSntqhVL5VBOqAr5CV8 08araqHqr1GYsWXocwHW8X+hG6uqWSJ97VJGWzR9bOheH4pBaEJpD4uvwFD1cF0IopsExPFIcrX z93qPGw== X-Google-Smtp-Source: AGHT+IGD0zDEZTKQcWsJyRh7TATbcIzYyFxP7Izy5G+weXhOkr6e/I6dVMxD5z7EImnePu9h8mI6YEz7V1I= X-Received: from pffv13.prod.google.com ([2002:aa7:808d:0:b0:7f1:8c5b:2e3e]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:8c11:b0:7e8:450c:61b7 with SMTP id d2e1a72fcca58-7f671474d70mr18440345b3a.39.1765998121154; Wed, 17 Dec 2025 11:02:01 -0800 (PST) Date: Wed, 17 Dec 2025 11:01:59 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251206011054.494190-1-seanjc@google.com> <20251206011054.494190-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH v2 2/7] KVM: x86: Extract VMXON and EFER.SVME enablement to kernel From: Sean Christopherson To: Xu Yilun Cc: Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Paolo Bonzini , linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, Dan Williams Content-Type: text/plain; charset="us-ascii" On Wed, Dec 17, 2025, Xu Yilun wrote: > > >+#define x86_virt_call(fn) \ > > >+({ \ > > >+ int __r; \ > > >+ \ > > >+ if (IS_ENABLED(CONFIG_KVM_INTEL) && \ > > >+ cpu_feature_enabled(X86_FEATURE_VMX)) \ > > >+ __r = x86_vmx_##fn(); \ > > >+ else if (IS_ENABLED(CONFIG_KVM_AMD) && \ > > >+ cpu_feature_enabled(X86_FEATURE_SVM)) \ > > >+ __r = x86_svm_##fn(); \ > > >+ else \ > > >+ __r = -EOPNOTSUPP; \ > > >+ \ > > >+ __r; \ > > >+}) > > >+ > > >+int x86_virt_get_cpu(int feat) > > >+{ > > >+ int r; > > >+ > > >+ if (!x86_virt_feature || x86_virt_feature != feat) > > >+ return -EOPNOTSUPP; > > >+ > > >+ if (this_cpu_inc_return(virtualization_nr_users) > 1) > > >+ return 0; > > > > Should we assert that preemption is disabled? Calling this API when preemption > > is enabled is wrong. > > > > Maybe use __this_cpu_inc_return(), which already verifies preemption status. I always forget that the double-underscores have the checks. > Is it better we explicitly assert the preemption for x86_virt_get_cpu() > rather than embed the check in __this_cpu_inc_return()? We are not just > protecting the racing for the reference counter. We should ensure the > "counter increase + x86_virt_call(get_cpu)" can't be preempted. I don't have a strong preference. Using __this_cpu_inc_return() without any nearby preemption_{enable,disable}() calls makes it quite clears that preemption is expected to be disabled by the caller. But I'm also ok being explicit.