From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 8AAB9344D92 for ; Tue, 7 Jul 2026 21:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783459256; cv=none; b=eYLAnd1flZNTKsOqpy8VYJrCVivkmWXBWTMI9Vb4Wqc5cmq/Rb1LNTzFe4wcSCkJ3bO2RdYAPDNgRqCBH1gcza/YZaRwrz734ymvECZEiyAGf2ZNftaq09/PF0TFfHgYfkqnslTqOO9QlGibnVgJe7z9adka/k2cSPnJE5NTJhw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783459256; c=relaxed/simple; bh=FndKch3GTGLdrOHB6rKSa6u3R6HrF3DsPw6ggmU46L4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cLPq/FHWYuy2AQfRgaZZiNmYRRPRoID3OWrpdJllGUxozh4qep38+SAjrB03kbmF0u2bY+8fo44Eal4ivD8ngEIzqvR7/b30nsti9TFQytK0BTBHNGtCy14wQrJt+69dq24RRtaSAu5dGAvZ7xYwO6RVKEBb+yV02hTKitb8ro0= 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=mHWMxe8H; arc=none smtp.client-ip=209.85.214.201 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="mHWMxe8H" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2cc640dfde3so510725ad.1 for ; Tue, 07 Jul 2026 14:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783459255; x=1784064055; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vX8Nu+AP3Cdd2yHmgHkvoGDwsjNpoGwkK+Tsrh06/Hc=; b=mHWMxe8HsKLCAyOY2DcLazBfuF4j3yF0XKHLf+7O55eaaAK0MU4gF/iuskYKW76iOl gWjyjOCmHN+DOxIr7KP4pND5lfWrc3nt7fyE6mhOPOWcSK7dAHEQ+snb7ToELssvQicd easaJKE4B06wSVmYHzAlstWVUcYH7FIRgmKVGMphWkjEleIalF3hHxO1mUIADmrQqQzp pSgKQTpp/+ozo4QkogXtgVIGEotvKomFeHjFVDCzzth4svpLeSoIWDy3r3aaFzmIpNHB Ut9oZpPZle+eOsDGTDTrQkejNPiR+R/ny0he3vschArdAJ5tJXyTzwb5LmBmjBOFK5R1 yfOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783459255; x=1784064055; h=content-type: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:content-type; bh=vX8Nu+AP3Cdd2yHmgHkvoGDwsjNpoGwkK+Tsrh06/Hc=; b=rNtxGp7czqRFs5VkzSxapUjHKUa6Om92hd8Ai3w3qyXS1bjMyNumUeWA6BpKAMMyVU 4sjY8pcJP3El795/1ILG4AQNk2qVMeO7kGAeodyxGSXrQ9uG8aRTyJboFZoE5faPeV4E 3ohMhsvC7ReUwkjOej83fcyRySoFANetwOq9VJlf4g1rBqeT8Ag5vRdd5lSv+rKEC7uK fqST6UXJqLRUk+nL5gJo2vBfzbjb5RoIUcIsGPnH9h/s+q6MXU4flxTZ0AhjJ5E0wVyJ YrHWkTwFTlaNnyLbf8snD4Pts3jdwNglfur3u/qyzxJ9MYNjzXdjIUZn2DAdxQX28z4n 5IQA== X-Forwarded-Encrypted: i=1; AHgh+RqM/UBQ+jmGIcgnIoa8+rdllAMbxmqxLxECFIbmvBkmabKJyXQTklWu8K0Bc0wDug7k9DcnLZwW0teFJd8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2BvP1d6jAHeZeidXnDHCQIzMivCP+FTXFlpiKqcYaMrsVCyO0 w1YyXbEDDUf1dyl4BafdtukkO0lnNlEHzkN5X9llEIl0Hy6LV6pwG6LKAO8qGCzFPxLVdiBvrss e9pjlMg== X-Received: from plbkb6.prod.google.com ([2002:a17:903:3386:b0:2ca:cbc9:76fd]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce01:b0:2ca:52ce:6f91 with SMTP id d9443c01a7336-2ccbf056a99mr71748395ad.27.1783459254740; Tue, 07 Jul 2026 14:20:54 -0700 (PDT) Date: Tue, 7 Jul 2026 14:20:54 -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: <20260630222607.497895-1-seanjc@google.com> Message-ID: Subject: Re: [PATCH v3 00/12] KVM: SEV: Fix RMP #PF due to freeing in-use VMSA From: Sean Christopherson To: Tom Lendacky Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ackerley Tng , Hyunwoo Kim , Michael Roth , "=?utf-8?B?SsO2cmcgUsO2ZGVs?=" , Fuad Tabba Content-Type: text/plain; charset="us-ascii" On Tue, Jul 07, 2026, Tom Lendacky wrote: > On 6/30/26 17:25, Sean Christopherson wrote: > > Rework KVM's handling of guest-provided (and always guest_memfd-backed) VMSAs > > to forcefully reclaim VMSA pages when the pages are being freed from their > > backing gmem instance, e.g. in response to PUNCH_HOLE. In the worst case > > scenario, marking the page SHARED in the RMP will fail due to the page being > > IN_USE, ultimately leading to RMP #PF violations due to guest_memfd freeing > > the memory back to the kernel while it's still assigned to a VM. > > > > Note, the implementation nearly identical to that used by KVM for VMX's APIC > > access page (which isn't guest controlled, but is migratable and whose PA is > > shoved directly into a vCPU control structure). > > Looks good. If you wanted, you could replace some of those quick > mutex_lock()/mutex_unlock() and write_lock()/write_unlock() calls with > scoped guards, e.g. in patch #8: > > scoped_guard(write_lock, &kvm->mmu_lock) > __kvm_mmu_zap_all_fast_front_half(kvm); How do (KVM x86) people feel in general about scoped_guard()? I love the "regular" guard(), but for the most part I dislike scoped_guard(), as I find it (slightly) harder to read than "raw" lock/unlock() calls. I think because I mentally think of anything like this: blah() { foo(); } as being a control-flow statement of some kind, i.e. code that is conditionally executed. So outside of flows where the benefits of the cleanup behavior are a clear win, I prefer doing manual lock/unlock.