From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46E48A31 for ; Sat, 25 Jan 2025 00:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737763717; cv=none; b=CYumRp2HuZMQO9xe88g44POEcfXcBKKHfGMoyXmTSQoPIvkF0KpYB4lLivfi4WMwH3QuTTCFgr9ILFVuTJyghIsbbKaTQiKCXZ3I67hfxnqQgrOGJykRVPCGZj53PyP8Oys2+A9OmPXHSiCa+CeSCNYlecvaoEPHmGNvtzfIiBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737763717; c=relaxed/simple; bh=/Y5Md7Dfd8QuVpnQ6miCnMwO4USPxpBcanRAa/0DuAM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=U8zAXKxQ0ll9IPXu2qAuEC82Wq+qfGHIjENmICQIIDdT960uNLdRsaWJM90AcXHvgQjC8RmSRVopPECMGnWUPdwH19bN1XCEcBeJOn54hDEsb2AotP71mPXnaCKKQyLttc6hqRdmnwz+asM2j9aZsRxkHI20rFEg6O/MjRZIboQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MQ6RJQGz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MQ6RJQGz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737763714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=+3uKP8g8eLLTFdF1IwLHx+SHSz3PCMPEzmnoC64xqQk=; b=MQ6RJQGzHNbA1mlpV/qAu5E9OKL9QA2rnAGanHWZ7yaFBuiv+RgcXsdGxbK0kcxuwNkEls sKFbTiiyezTXgLLyANwAoTwCgYxMC+5QTx6NXnsq2DuDUUIdWx22wNEtqn9pGkMZ0y1N8o N1rlk4tn5Jn/RYPzHyMpWAABlSPu67I= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-wxgHm64APUSAq4xuJTMlJA-1; Fri, 24 Jan 2025 19:08:32 -0500 X-MC-Unique: wxgHm64APUSAq4xuJTMlJA-1 X-Mimecast-MFC-AGG-ID: wxgHm64APUSAq4xuJTMlJA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436248d1240so12537425e9.0 for ; Fri, 24 Jan 2025 16:08:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737763711; x=1738368511; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+3uKP8g8eLLTFdF1IwLHx+SHSz3PCMPEzmnoC64xqQk=; b=KncEpIcy0vKW/N7WgyXTPK2nI/6/IFadllrsZRGLUxjbvkG3TT4CaRyX7Bswf+01+K TfzSt+FmSHCobQsVH4NJOgWSJpXu4vV7VQKN7ppK88Y0nPJBe0I4t6mN9tejO0osaLz1 0N1EjswGiuANZilyBLbrHNUZRnQK83k6t/4JdOI/53EaMTpeT3NA5w22alYwb5skjf1u u1PixAZLIZ6luT4ptXlrg4nX7wuQqp1SYZy4I+YLFBsUYAukGUPFv5rmBk/TmgM/iY7Z tAjaStXFvDqHYVsBN/GYon9IJH17Imy9zIrzOIVMOrfRdieK/NXzhZdqNFUrekJCgS8Z 2JMA== X-Gm-Message-State: AOJu0YwTzU0UxJreGWr7UVW7W03y+jhe2CbAlWrzeVBcjjFZdsNFiflJ OH2M2h3a20EzNa0eQklWz3kjAS6tEcbJCKbyFnySMTQ2OoRYv8i3zYvgof1Ig7hUujw9Kj9MOJd PL4CRrTwDY2yYDyG1G3jg81s3n9FMmoKMJv8nlxnBKOCECPxxXpb4JyPaKUDwP4joowzSoI21 X-Gm-Gg: ASbGncuzR7bZWsavr6e2XcZPiq2s5GUr2dB8ijxFKkTdv172538bpAhj2gUoIwAOAiD /mSO+aDjkvtjej074wWXMDUemMcfGk1ChW5cORd00xi5nnVnSqoTCv1qXJZSRRejgDDysIiusDB 9UQcZxgd0cq16Du+uCr+T66zifmxLrGDslvcGw35U9MYa3htC/jMekoxdhlZzpfQ3E00VV5SEXh UHyfghITt/+UKISWW11scmCK/s0s9m+yhwOpRetKisfG9HZTZR/PP+u7JapNWB8p27NcP6sSYp0 tF7E12Jd X-Received: by 2002:a05:600c:4e07:b0:434:a802:e99a with SMTP id 5b1f17b1804b1-438913bec32mr290921075e9.4.1737763710754; Fri, 24 Jan 2025 16:08:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHwQf+1d6P9WNGtcsm3P4YTP7VDB0bXFJTvbHUWA87Pk09vnWfPT4RuaCxFYTeTol6WEXmPQ== X-Received: by 2002:a05:600c:4e07:b0:434:a802:e99a with SMTP id 5b1f17b1804b1-438913bec32mr290920995e9.4.1737763710403; Fri, 24 Jan 2025 16:08:30 -0800 (PST) Received: from [192.168.10.82] ([151.95.59.125]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-438bd501c2dsm41680025e9.13.2025.01.24.16.08.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 16:08:29 -0800 (PST) Message-ID: <0188baf2-0bff-4b08-af1d-21815d4e3b42@redhat.com> Date: Sat, 25 Jan 2025 01:08:28 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] KVM: x86: fix usage of kvm_lock in set_nx_huge_pages() To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, kvm References: <20250124191109.205955-1-pbonzini@redhat.com> <20250124191109.205955-2-pbonzini@redhat.com> From: Paolo Bonzini Content-Language: en-US Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptwLEgTEd3Fo UdhAQyRXGYO8oROiuh+RZ1lXp6AQ4ZjoyH8WLfTLf5g1EKCTc4C1sy1vQSdzIRu3rBIjAvnC tGZADei1IExLqB3uzXKzZ1BZ+Z8hnt2og9hb7H0y8diYfEk2w3R7wEr+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ZryEyTHQ+E42K3j2IUmOLriF dNr9NvE1QGmGyIcbw2NIVEBOK/GWxkS5+dmxM2iD4Jdaf2nSn3jlHjEXoPwpMs0KZsgdU0pP JQzMUMwmB1wM8JxovFlPYrhNT9MAEQEAAcLBMwQYAQIACQUCVEJx7gIbDAAKCRB+FRAMzTZp sadRDqCctLmYICZu4GSnie4lKXl+HqlLanpVMOoFNnWs9oRP47MbE2wv8OaYh5pNR9VVgyhD OG0AU7oidG36OeUlrFDTfnPYYSF/mPCxHttosyt8O5kabxnIPv2URuAxDByz+iVbL+RjKaGM GDph56ZTswlx75nZVtIukqzLAQ5fa8OALSGum0cFi4ptZUOhDNz1onz61klD6z3MODi0sBZN Aj6guB2L/+2ZwElZEeRBERRd/uommlYuToAXfNRdUwrwl9gRMiA0WSyTb190zneRRDfpSK5d usXnM/O+kr3Dm+Ui+UioPf6wgbn3T0o6I5BhVhs4h4hWmIW7iNhPjX1iybXfmb1gAFfjtHfL xRUr64svXpyfJMScIQtBAm0ihWPltXkyITA92ngCmPdHa6M1hMh4RDX+Jf1fiWubzp1voAg0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/25/25 00:44, Sean Christopherson wrote: >> I did try a long SRCU critical section and it was unreviewable. It >> ends up a lot less manageable than just making the lock a leaf, >> especially as the lock hierarchy spans multiple subsystems (static >> key, KVM, cpufreq---thanks CPU hotplug lock...). > > I'm not following. If __kvmclock_cpufreq_notifier() and set_nx_huge_pages() > switch to SRCU, then the deadlock goes away (it might even go away if just one > of those two switches). [...] It would be single use in the it only > protects pure reader of vm_list, but there are plenty of those users. Yes, single use in the sense that only set_nx_huge_pages() really needs it. kvm_lock doesn't produce any noticeable contention and as you noted sometimes you really need it even in pure readers. > SRCU readers would only interact with kvm_destroy_vm() from a locking perspective, > and if that's problematic then we would already have a plethora of issues. Ah yeah, I missed that you cannot hold any lock when calling kvm_put_kvm(). So the waiting side is indeed a leaf and cannot block someone else. Still from your patch (thanks!) I don't really like the special cases on taking SRCU vs. kvm_lock... It really seems like a job for a mutex or rwsem. It keeps the complexity in the one place that is different (i.e. where a lock is taken inside the iteration) and everything else can just iterate normally. Paolo