Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2781929lqo; Mon, 20 May 2024 17:30:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUyM7/kX1ta43QqQdfjxxISKeX5PG28O+ul60BDGCC79/nmQO14L6nI4kNf619MoSsUWdlQrqj4WOY9KZkwJjPDHMJJbT6SgPHl5ZzWPw== X-Google-Smtp-Source: AGHT+IHMaCmN/1yK1LNnSAGDHUAUvZhWkLTkoX1NmbjuJKCJEgEBaIK2lQh1S5TWHl0fdttdWqHu X-Received: by 2002:a05:6a20:325b:b0:1af:ccfd:529d with SMTP id adf61e73a8af0-1afde10ae60mr25049342637.27.1716251431397; Mon, 20 May 2024 17:30:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716251431; cv=pass; d=google.com; s=arc-20160816; b=SByC0qdRgw2yquUkGguftBS515hqyhmsGSaEepRzNfi+2ZQC8sXSkdo6aaLtUKxBP3 62eUdOujotmtnRhf2mgrN8nIpnUxvIMqH4+80mixqgD7gN1eH1/W092VEHlXRopPSAgp wKWNedIZa/PbtrhXzP7GvQBsQ6nV0q9JwaKFi4JRU0Bstbzfb2HuLfgZq3SBmPdffdHR 0naoUesKTn+MGbPEXCXYKw1rzUQTeFte1NWGoMT8z0AG8WtJ6sjkRwPBa6CWbb64ZFxP 1wkTSCzD5H2MlHo9GicHlTIXhYaAnNwz8avPFAEptwcruRIaMTRZ+x5YIcXyGen4sMMk Tj6g== 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=6ptfnRWr6+WaSf97cvh4fEBETpjMq9qszm8kFWwt98g=; fh=jECC8vR6agg6IXFXQWyXrZQcPOvTY+dLHY9uJXw+2ow=; b=k3dLXkTNPv7mD7JGzNgSY8R7SlWI0iZ9aCIE3wXiAsGF9l0kTBs9Nl78Hp9/gdMBcq qJwNsrObBj9MJVwwOKVdEzpm/xZQ5zhm/llCoyMytgKHA1MrqxB37CqlNBGVB/G0D4h+ tchHiuiKNyJacExl21gnTZlGeBPu8GBYOLh5r/8fYtKeaU9zw2xH90O7Gd+Sb9KXAGQ+ STiQn2OrwcdubkCkVQvNEqStc582mCBT59FxBjjPW77pdlAgzeiXN/LKB+E7I1YsEu1N yPMbouuQoskDqRWRXtTe13G2WCl8VtJCkuTY8Hy+BRnh7I3iTAC9zCZ4JtoIu67r6/WR F3yA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=d7ZG0Op0; 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-4280-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4280-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. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-66270fb3f42si3098314a12.240.2024.05.20.17.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 17:30:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4280-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=d7ZG0Op0; 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-4280-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4280-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 AC25DB21C9A for ; Tue, 21 May 2024 00:30:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D217F848A; Tue, 21 May 2024 00:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d7ZG0Op0" X-Original-To: linux-crypto@vger.kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 3021B4A09 for ; Tue, 21 May 2024 00:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716251419; cv=none; b=tCLfw9t6RdSK/UY9lwKVwwstTiL7ZgJaPsIDqC5m7ygbwq76rbGBBqK3BXujeiYe4XQACl4W2w7CDhzLVddqcUN+j1QHknFk8HJMG+rHpWzmg8RPXoZMX7OOMfjEP6uaSw36K0YyYPj3I746M1wX7txAJfroGi1QqPrRo3+B6lk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716251419; c=relaxed/simple; bh=R8w20wrWhAHj76bvR9zKsPMgoXSmLDWN8EM25FYEDfU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Rm7y0Rx1e41/EDGXNtiytZa+z9I2VstfN/SWDth0lt9NpPrJNLHxUtnq4C9s51kjdCHVASasZWcKsRHJcspuHi13vxvhs2VJ9yZrd3noulkl78qjKfIbBCAsP3bp77ApWfaMwOpnTaSFaPVkebpbv0PS58dtvCfjFHz2G18AlYw= 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=d7ZG0Op0; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-61be23bb01aso261932107b3.2 for ; Mon, 20 May 2024 17:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716251417; x=1716856217; 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=6ptfnRWr6+WaSf97cvh4fEBETpjMq9qszm8kFWwt98g=; b=d7ZG0Op0aS7Gf9u4DW+qwFtpz2LCmWYCidyjGFKVBjOIJljrGFDN2RHhEBV4c4NkSZ SyxXJ83u/baWjsW3apzQ6QTB5cmnviIemsZKB9XqDX5pW+5n9Fms7o/6ITA21ial3kGO MIVEsJo+grQX8ABfhfwJf8xg08dqCqE3sevf3yKx6/3SqT4HCuTHUSDrpayaPa8tUAja wxSE7OxOmNYjiW7mFINJmZveErhLYQEk1ivkdvFKMdf5rvU7ggK0iLasuxNK2946yxIm Rg+QkKqWjb5fWL4Mb0WLvx4CN5XEXblJey0bZ2GgIpyMwyRPhhPdG1X0zEfl0DpPn5VY +n0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716251417; x=1716856217; 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=6ptfnRWr6+WaSf97cvh4fEBETpjMq9qszm8kFWwt98g=; b=BU5czaPUjYjTI6eZAwrU5yIPFfwhSSyiqWolXQGwZIN8HTnL+I0gFfrtkaQs7qiBIZ wJu9tywLQ6qWIJosCO3Aik9K/0+1QaUVG6+r6owxaF/iJQu8m+k+SpvAQJlIO72EnZl7 YMhqGDyPsNLvM3GG40rm6Xsfmh63cUudDyX3hC/r2mYKtXMcchGQ8DvtBOBsiJDkmYp0 7tUkaM3BawtNiIhcaEbBKPpslLy4TGwfhJXNwXeEICMH9uws9ygm6pZWnJ4JcxLBLP81 oc+SjJqKOXlai4pn8nWw8olumGdNIYzix9rFJ7ijEaEbfJPG38HipwT7ZX6tzvwAM2jj OVXQ== X-Forwarded-Encrypted: i=1; AJvYcCV2WyQUwgBxMc2nTDb9Ob3kAq8BEtxH3EgGB2Lp9nU2hwt4NIxfLyorSG9I0sdLWLlKKY5dnUpQ8xCUxW+T6s2doS92mLFhPkMTL7gp X-Gm-Message-State: AOJu0YzOXktsxHELGAC6vCHMgcBVA+MUy9Yj3hNhPXPY4frLuF7mEl0r RGt+FQ3lwVvP/h/jvImeyzEbTQqMi6ESRuXHIjGB6PmrOynDTkay1eddZYZuU/YoKpz1L5itGoS Ymg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:c01:b0:de5:2694:45ba with SMTP id 3f1490d57ef6-dee4f104643mr7926731276.0.1716251417124; Mon, 20 May 2024 17:30:17 -0700 (PDT) Date: Mon, 20 May 2024 17:30:15 -0700 In-Reply-To: <1ce87335-2ea7-41c4-8442-36210656cdca@intel.com> 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> <1ce87335-2ea7-41c4-8442-36210656cdca@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 11:15 am, Sean Christopherson wrote: > > 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. > > But is this the case for SNP? I thought due to the nature of private pages, > they cannot be shared between VMs? So to me this RMP entry mapping for PFN > <-> GFN for private page should just be per-VM. Sorry to redirect, but please read this mail (and probably surrounding mails). It hopefully explains most of the question you have. https://lore.kernel.org/all/ZLGiEfJZTyl7M8mS@google.com > > 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. > > I am not certain this can impact whether we want to do RMP commands via > guest_memfd() hooks or TDP MMU hooks? > > > > 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. > > My thinking too. > > > And there's no big motivation to avoid zapping because SNP VMs are unlikely > > to delete memslots. > > I think we should also consider MMU notifier? No, private mappings have no host userspace mappings, i.e. are completely exempt from MMU notifier events. guest_memfd() can still invalidate mappings, but that only occurs if userspace punches a hole, which is destructive. > > 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. > > No I am certainly not saying we should do SNP after TDX. Sorry I didn't > closely monitor the status of this SNP patchset. > > My intention is just wanting to make the TDP MMU common code change more > useful (since we need that for TDX anyway), i.e., not effectively just for > TDX if possible: > > Currently the TDP MMU hooks are called depending whether the page table type > is private (or mirrored whatever), but I think conceptually, we should > decide whether to call TDP MMU hooks based on whether faulting GPA is > private, _AND_ when the hook is available. > > https://lore.kernel.org/lkml/5e8119c0-31f5-4aa9-a496-4ae10bd745a3@intel.com/ > > If invoking SNP RMP commands is feasible in TDP MMU hooks, Feasible. Yes. Desirable? No. Either KVM tracks the state of the physical page using the guest_memfd inode, or KVM _guarantees_ the NPT mappings _never_ get dropped, including during intra-host migration. E.g. to support intra-host migration of TDX VMs, KVM is pretty much forced to transer the S-EPT tables as-is, which is ugly and painful (though performant). We could do the same for NPT, but there would need to be massive performance benefits to justify the complexity. > then I think there's value of letting SNP code to use them too. And we can > simply split one patch out to only add the TDP MMU hooks for SNP to land > first.