Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp685584lqb; Wed, 29 May 2024 07:46:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWC65HRGGKKbL+PYJG0JL6fjOSP7ygENSTYMdJa3Un6iMhf8KpLQQzVIpQOvUs3weh+Cl5vFstkpL/SSYK5W18etVmu+Ov/8gAx42iZLg== X-Google-Smtp-Source: AGHT+IFIr2HmwC1xuJXD5s2t9bS+2impGZm6BIZivtyquZqCp6GGHXvxm9WC6rTwmk4uxT52C3WM X-Received: by 2002:a05:6358:16d6:b0:199:42c8:389b with SMTP id e5c5f4694b2df-19942c83a84mr131690755d.11.1716993982082; Wed, 29 May 2024 07:46:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716993982; cv=pass; d=google.com; s=arc-20160816; b=1GIJ/0rQo5noGOnPR8DUn9KCLwzo7/uVbJqqkwOjiDL8fc3NieqMECOYT4DYz2qoYH GsvL2yH/05y9GsyVWmMhd9mgbS2KyMYppjYKQ8bry8DQDMcA2nGrbbF6/JZDcHss/oG8 M012ffElLFRiQfzVPTJ/geKdU5CPj8wjT5A2p0cyQlVJl7BbNCMNB2DNt7xu2oqkWjFI 9GdC6MuvgakCy1vENJ9Al675ztEA2oy5ZqZ8abFXn4kQ4RMQbv8GCEnbdiljIJ3ceSq8 sM9aWVpjG9PsATXviH3qpU+GC3gILtkXjjlgJeR9QleehtSw/lh/l7cET3r2i02HlAl/ CvJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=UpzkxiZJ+JsVTYQLiVluvU7gtIP+cGyMlWZAn8HOBvc=; fh=kJ1dy0NYx51IkRt9sTRX2xC+VfyfLy2aM5pHNzwQ7EU=; b=vArA2v4LUxwRmmJwIfxYwgZ/FAU7eN1eG3CwUiuujcHdvTzOj+Vz3q957bxQu3XiMB tk97ynPzajMO60TBHuItfFs9USxl8UHltLZrgnDVFuDl8mp0VP9pyLQtrGdt4K/60Z+l YeeD8UGrATzyyTu+AZucA6Y8x9qTCu3u5bT3xLKPLcAsjNWCzv3o7ZbvnWw9yBuxScv5 WeEwNJC73AJKuxV57yqOOdA/zfHycb3kKIG7IGZ+noWbOpuBBsdNVYf7RqG5gBj+v2oi 1K+PTd+eb6Igq+S+zyZ6GMLygF6LrXo5IzeMLAnt6iYWSEAOn6anJUBxNGiYmqgQiXpl cUQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IgWRqzwU; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-194271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822946e273si10938032a12.587.2024.05.29.07.46.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IgWRqzwU; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-194271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 341FBB23474 for ; Wed, 29 May 2024 14:29:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4CAE1586C2; Wed, 29 May 2024 14:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IgWRqzwU" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 8C551158210 for ; Wed, 29 May 2024 14:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716992962; cv=none; b=KzNCsHqjmCOSnXTdcGmSO2BfaxAV2XLaCLVVdgiFGYyDOxHk6DrYbL3VfxFpfLDTW5T5pXZGRKWbPCCUyvVLqTkp0Emd4j7BMTS2d4QtIDzJRvtz7Z8IreV6m/RVgKo1dq4pywmY4c8tCAfJoxd+KJ4GJStolKAgJRmRNKzfnU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716992962; c=relaxed/simple; bh=//0ii/zNBOQKKNaDNP3w/g1gM1CezyuYoz6Y2NAEkac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RlgiX8fTqIUjoMoNNyjEnUcEjAwnqUi42ZAnN/xwyGDyKC4QxKkanDum6lbLAFzppz8VafREDNMtJhw7yX/BYuxbh/qMRAdtzs/BL0/x/yh4mitBfK5WIoIj9X5160vD0ROX5wtCDBGEd4D88/i+FvOs1hs0QZBv+ccUjzIo2ac= 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=IgWRqzwU; arc=none smtp.client-ip=209.85.128.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 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-629f8a92145so35011787b3.0 for ; Wed, 29 May 2024 07:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716992959; x=1717597759; 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=UpzkxiZJ+JsVTYQLiVluvU7gtIP+cGyMlWZAn8HOBvc=; b=IgWRqzwUAUE/aQEi4/xVaVivYgj7kYV1vdqPIC7g7km8uYLcpdSAlsw/Z/b4Jmkm9K zs31IhnlalrHF85rPT5sSwJ2uTDG3e079mgDKbeWE7xYQiW3d0YMsQu5hDb6oMKIaRne T3sF2VDD63pRD0nh8bv/lBAz9StTcnndb1IIcHWOCNItaKxHPl7bIGojMw3Fjb2/M7b9 vMe4dkBZxcb0kBrkuptQYzXi8vPP5PUBWbNqJTUQvDhVQHaJvBV8xDdOgsuvjF3eDXSG 59qmHJlUPOfVvWSnaFzVxDVhvBK7AM7j0usZEmH8mte37YIQni1bGh0nmeY0oa0PH5QK bhUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716992959; x=1717597759; 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=UpzkxiZJ+JsVTYQLiVluvU7gtIP+cGyMlWZAn8HOBvc=; b=MTtNcJZmMUD9vuuPC1SiszU9vZFI4Xfzsz9mNYMsLrJdrGfeXS4XeqneyudOEWNSWe fP1YDbTmWOtxEz6OvsvombRHa6sIGGBfegOc2kbwvhlhKUR7TqWPuGrt+/9YGWaZTbk0 j4vDhFnyY0m+6ODfPBTtuHhulwL0zq8veZOkrcGDIaiLfV/MYRFC5fRn+0A8xn2Ks+69 7faXt4bxMyYFGxexE4B8YqFYOKRcmXfMozRl9NTzWBInSM1Q3hZR+6rN3VOe0P0rBygU v7ZSScOPGaxM9SFepamMM2bYqRHICbRaCYhqQ1Do9hCMkDz6Hm2rihYhLDOOO0pW/A8F KuEA== X-Forwarded-Encrypted: i=1; AJvYcCWendbSNEM6YBwrwe3gTYpzBypO+3cCslOHa4gfzCGGXu6VxngXxAhKBr+pQb1B/S/NHKsL6na9IKI6y8a+KTp0b2wp5VsNfagV+J3Q X-Gm-Message-State: AOJu0YyUej2KqzPCdy6UeOhgEBnt6+gge3pPoeEbw1TTqDE2Nr2CZPz6 BAinmFybEv4TrYzs+ZwI+HeIJWVWjxOPoobgV7R4TSPG2Fq1m7tewnk68Xz7DhJjl+NZKmdFRnU azA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:d8f:b0:62a:4932:68de with SMTP id 00721157ae682-62a49326f54mr16363447b3.8.1716992959692; Wed, 29 May 2024 07:29:19 -0700 (PDT) Date: Wed, 29 May 2024 07:29:18 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240522022827.1690416-1-seanjc@google.com> <20240522022827.1690416-2-seanjc@google.com> Message-ID: Subject: Re: [PATCH v2 1/6] KVM: Register cpuhp and syscore callbacks when enabling hardware From: Sean Christopherson To: Chao Gao Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang Content-Type: text/plain; charset="us-ascii" On Wed, May 22, 2024, Chao Gao wrote: > On Tue, May 21, 2024 at 07:28:22PM -0700, Sean Christopherson wrote: > >Register KVM's cpuhp and syscore callback when enabling virtualization > >in hardware instead of registering the callbacks during initialization, > >and let the CPU up/down framework invoke the inner enable/disable > >functions. Registering the callbacks during initialization makes things > >more complex than they need to be, as KVM needs to be very careful about > >handling races between enabling CPUs being onlined/offlined and hardware > >being enabled/disabled. > > > >Intel TDX support will require KVM to enable virtualization during KVM > >initialization, i.e. will add another wrinkle to things, at which point > >sorting out the potential races with kvm_usage_count would become even > >more complex. > > > > >Use a dedicated mutex to guard kvm_usage_count, as taking kvm_lock outside > >cpu_hotplug_lock is disallowed. Ideally, KVM would *always* take kvm_lock > >outside cpu_hotplug_lock, but KVM x86 takes kvm_lock in several notifiers > >that may be called under cpus_read_lock(). kvmclock_cpufreq_notifier() in > >particular has callchains that are infeasible to guarantee will never be > >called with cpu_hotplug_lock held. And practically speaking, using a > >dedicated mutex is a non-issue as the cost is a few bytes for all of KVM. > > Shouldn't this part go to a separate patch? > > I think so because you post a lockdep splat which indicates the existing > locking order is problematic. So, using a dedicated mutex actually fixes > some bug and needs a "Fixes:" tag, so that it can be backported separately. Oooh, good point. I'll try to re-decipher the lockdep splat, and go this route if using a dedicated lock does is indeed fix a real issue. > And Documentation/virt/kvm/locking.rst needs to be updated accordingly. > > Actually, you are doing a partial revert to the commit: > > 0bf50497f03b ("KVM: Drop kvm_count_lock and instead protect kvm_usage_count with kvm_lock") > > Perhaps you can handle this as a revert. After that, change the lock from > a raw_spinlock_t to a mutex. Hmm, I'd prefer to not revert to a spinlock, even temporarily.