Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2756787lqo; Mon, 20 May 2024 16:15:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWh/mLvIA5x+M77a47x/LM5l+gae8iDhaujW2OpJZyve7bqXRYaiMswGLgULNjwEPUTniFGqBTbCSmA4QLRqvP4TdkiPhADBXlH46fp9Q== X-Google-Smtp-Source: AGHT+IEgCNzucIOJkDJ1TuAszrAnnnzNZWM4EyYklV5gXhLDJULaphBdE9aYSeMre3yDMDEaLK+i X-Received: by 2002:a17:902:d58b:b0:1f0:9745:8d95 with SMTP id d9443c01a7336-1f09745901emr188859735ad.69.1716246948309; Mon, 20 May 2024 16:15:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716246948; cv=pass; d=google.com; s=arc-20160816; b=qgLCSSiTTbuJzs0le9iNetW6/KhMRn3eLFwr5b/9g35T9+ciZ0Lmh9+38HnKopLrGm CF0wQwzGbFlLZextNW36ipL48AbSX3z/LGbzsJDILG3qQkqLa2/2UOBAw80y7IyarDdf Joz4J/1sqLEV4c7Iq84LybIp0WtS6b5PKUP2la0k7cRTl6E4DG+fdCMgQJaHyB6o94WF CrBDOMSGy5Drru+2YJy1D88kLANCiNnKb46JanTEj+LrB6tP1QfvEtxfc0bByAS8NYzr h5vFeQ73WT1LUR4BQIxLzk7ExLy96n4Q7pIIc/72fRyg/iOCd0Z8Uy4E5UB0zWdJg52T wNVQ== 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=twyGBTDDHaKdZ8SvbyxDVnqYzF64Bkyy6CUrxLoAK6Y=; fh=+Enr/0lhqvVEaho5PC0WAdi4cfR5dXxAjmsp8abbFfk=; b=EODhbQTXGc3xgNibVeBXpVYR1aJ3VuwMxApum04wrPaZWkV1x4Rf4tV2FgbZ64h06a cohOuHICeYoY7JROj3/ovPNWy1V105aZrf4MKEziBPlCKJzN9kCdOYtoU+VssYa+YNtX hSl3XzhUT3uFpP8EnjozWC5WpDqTDzFhSydTh7N2WGJXLxa1ZB/XnD1gbhSSf38HxUjV O4P9/nUSTPo3SkGLmJWFFFRhl8uj5K9xsBml86zt5dS6x+6wxnuLsQ732Yc5wI58+vNU du8QcEYZHzwlErSL0oEURN5+Z63qnw0jsTWlrCP0DOg+B/j6csn4cajp3BsUVVjcijHt y+FA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=h2q78OmZ; 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-crypto+bounces-4278-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4278-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 d9443c01a7336-1f3083e6ba0si12425855ad.450.2024.05.20.16.15.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 16:15:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4278-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=h2q78OmZ; 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-crypto+bounces-4278-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4278-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 4AFC3B215D6 for ; Mon, 20 May 2024 23:15:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D11A24CE04; Mon, 20 May 2024 23:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h2q78OmZ" X-Original-To: linux-crypto@vger.kernel.org Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 4D1C545033 for ; Mon, 20 May 2024 23:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716246932; cv=none; b=N4KZoVKGeLx4Ee/kxvIxlcBt+1VBtOlD2a10RSmxgFxSA6OhwgwabOTLnvlor63hCZErsoVKLh9iFtghL3vgX+cHRrXmX6dvBsfFsZvC4AN0qJkkNFPOL9x0AxKF2OJJATU5psB0VMA2YKbiaC8lvh6gBXhZBQfBN9hmTht/dc4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716246932; c=relaxed/simple; bh=9UKSTyxeIo7ms1MzG6LVINnuAwbI4QebTI1VvbPk+cs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hIqEo5DtKtfPQTiszc9+PLIZMHrqGPVtKGAxSOVtqZV4lrKDIDJGULFWUX3kd+N3W9LfSsWOAwZ4P8UvM5Hv9R1exx6dVpQJ8rMQRDsntDa6xEwHPC6Txqooa65RkASfTD3vdHqHK2f5doBjsrqn3za6CdF3vNo3JeBlKZ97ca4= 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=h2q78OmZ; arc=none smtp.client-ip=209.85.215.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 Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-65705318a0cso5251707a12.0 for ; Mon, 20 May 2024 16:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716246930; x=1716851730; 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=twyGBTDDHaKdZ8SvbyxDVnqYzF64Bkyy6CUrxLoAK6Y=; b=h2q78OmZyyPrl3NwO9dLo6tl8o7g6KQuV0iw35wVXKSIxaLkZKncMNZa0o4icb4Mtx famG8uFclqI7qs+iaT7aEiJu2sdnAcuoe8GY6mnBF9OMwQ8ca7KakmEalXhwOgh8zTHl /p0meewxhh2zgNml3LLHvQaVnOfOGaJe4diJGFRi965VGy3vfnOQxKQT3AqvAtQNEeez y0vWuV7e4fi6TYP2qNgKqgukfo1IypjRnTboGPi1SexS19LEYvbxwfGEG6M7v3SLR2WW /3k83stj7iLKRHi9vWeb7ZugWcax3FZvjXGW4CtegjPbpcpHqMqIgLHQlXk2JY1yt3mH gCqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716246930; x=1716851730; 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=twyGBTDDHaKdZ8SvbyxDVnqYzF64Bkyy6CUrxLoAK6Y=; b=GdzqBbDomMpNJGqjIfVSsPp6l6xpwG6ZUO1gp9++52OcKzJFJsy8yLOUIXrFwhbah7 Cu8z7AQRHp/PnomP678h4WF/+o16ztBk/P8PvvhdZc3NwpqHSV1RLBV54Pn8PiW+ufFk Wa9seMgPQnsy7z8PdeywPOtn7+xLDuq77b3tiZT05ZtNQ0GEIWen/+wATkvZdzWxR1nw N4nUWfxd6dQvgTXpZ6Vvw1xTOx5TjkwMacBKTkzQTxUBjr3w+AexMHsLXYfbi5/fW/m3 7E+kHUj8corasEgUDUXk9dUN1rKci25sZSMDHjxGrfrFKwHN5IcayWqnXcR6mNLzk3x4 RgTQ== X-Forwarded-Encrypted: i=1; AJvYcCUxQb9QmIMdrrUIgMLqguvaRRRL4VZk1mtutrxKn+HacvmxaxsN64zSz7pi/JqwIj3PJCI9TOC963+RtLi0IBj0mTmd5CRKXUdXsqUr X-Gm-Message-State: AOJu0YxxZptmS7ZNc6OhZY8Sn/f489AcqgWfeE0hZiFJLcphkd7Ldlmc vLUVtmWApgyfBlFWb/mkVOgL9asFfXdQy/ExP346/h5Zr4+mMsSoyijzk7+9fm3NyxG+ldf7WVr NIg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a02:688:b0:655:199c:eb1b with SMTP id 41be03b00d2f7-655199cebe4mr46923a12.10.1716246930361; Mon, 20 May 2024 16:15:30 -0700 (PDT) Date: Mon, 20 May 2024 16:15:28 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240501085210.2213060-1-michael.roth@amd.com> <20240501085210.2213060-14-michael.roth@amd.com> <41d8ba3a48d33de82baa67ef5ee88e5f8995aea8.camel@intel.com> Message-ID: Subject: Re: [PATCH v15 13/20] KVM: SEV: Implement gmem hook for initializing private pages From: Sean Christopherson To: Kai Huang Cc: "isaku.yamahata@gmail.com" , "kvm@vger.kernel.org" , Rick P Edgecombe , "michael.roth@amd.com" , "pankaj.gupta@amd.com" , "tglx@linutronix.de" , "tobin@ibm.com" , "liam.merwick@oracle.com" , "alpergun@google.com" , Tony Luck , "jmattson@google.com" , "luto@kernel.org" , "ak@linux.intel.com" , "pbonzini@redhat.com" , "pgonda@google.com" , "srinivas.pandruvada@linux.intel.com" , "slp@redhat.com" , "rientjes@google.com" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , "dovmurik@linux.ibm.com" , "thomas.lendacky@amd.com" , "x86@kernel.org" , "bp@alien8.de" , "vkuznets@redhat.com" , "vbabka@suse.cz" , "ashish.kalra@amd.com" , "linux-coco@lists.linux.dev" , "nikunj.dadhania@amd.com" , Jorg Rodel , "mingo@redhat.com" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "hpa@zytor.com" , "kirill@shutemov.name" , "jarkko@kernel.org" , "ardb@kernel.org" , "linux-crypto@vger.kernel.org" , "linux-mm@kvack.org" , "dave.hansen@linux.intel.com" Content-Type: text/plain; charset="us-ascii" On Tue, May 21, 2024, Kai Huang wrote: > On 21/05/2024 5:35 am, Sean Christopherson wrote: > > On Mon, May 20, 2024, Kai Huang wrote: > > > I am wondering whether this can be done in the KVM page fault handler? > > > > No, because the state of a pfn in the RMP is tied to the guest_memfd inode, > > not to the file descriptor, i.e. not to an individual VM. > > It's strange that as state of a PFN of SNP doesn't bind to individual VM, at > least for the private pages. The command rpm_make_private() indeed reflects > the mapping between PFN <-> . s/SSID/ASID KVM allows a single ASID to be bound to multiple "struct kvm" instances, e.g. for intra-host migration. If/when trusted I/O is a thing, presumably KVM will also need to share the ASID with other entities, e.g. IOMMUFD. > rc = rmp_make_private(pfn_aligned, gfn_to_gpa(gfn_aligned), > level, sev->asid, false); > > > And the NPT page tables are treated as ephemeral for SNP. > > Do you mean private mappings for SNP guest can be zapped from the VM (the > private pages are still there unchanged) and re-mapped later w/o needing to > have guest's explicit acceptance? Correct. > If so, I think "we can zap" doesn't mean "we need to zap"? Correct. > Because the privates are now pinned anyway. Pinning is an orthogonal issue. And it's not so much that the pfns are pinned as it is that guest_memfd simply doesn't support page migration or swap at this time. Regardless of whether or not guest_memfd supports page migration, KVM needs to track the state of the physical page in guest_memfd, e.g. if it's been assigned to the ASID versus if it's still in a shared state. > If we truly want to zap private mappings for SNP, IIUC it can be done by > distinguishing whether a VM needs to use a separate private table, which is > TDX-only. I wouldn't say we "want" to zap private mappings for SNP, rather that it's a lot less work to keep KVM's existing behavior (literally do nothing) than it is to rework the MMU and whatnot to not zap SPTEs. And there's no big motivation to avoid zapping because SNP VMs are unlikely to delete memslots. If it turns out that it's easy to preserve SNP mappings after TDX lands, then we can certainly go that route, but AFAIK there's no reason to force the issue.