From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AAABE81DF0 for ; Fri, 6 Oct 2023 12:47:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 028B78E001B; Fri, 6 Oct 2023 08:47:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1B4A8E000B; Fri, 6 Oct 2023 08:47:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE2FA8E001B; Fri, 6 Oct 2023 08:47:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CD5738E000B for ; Fri, 6 Oct 2023 08:47:41 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 984E4A0703 for ; Fri, 6 Oct 2023 12:47:41 +0000 (UTC) X-FDA: 81315013122.29.43D5132 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by imf06.hostedemail.com (Postfix) with ESMTP id CDC0118001B for ; Fri, 6 Oct 2023 12:47:39 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dcuhHJGL; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of tabba@google.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=tabba@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696596459; a=rsa-sha256; cv=none; b=QWGTGJo30tUtufts8HiK0IqrNs8WkbjuqKjN7DaLZIMileWq7toOfk5qkNejEo6tT/Y+cc b4C4gMlMoRqbggSYBg1XkE2Cy2fVkBcQ+J9MGJ235AEQ/2+47dr8zpXnpwrY5ZQSz+g98i sXea5m71TvHuDePGPG1fjMmoXk3XgpE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dcuhHJGL; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of tabba@google.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=tabba@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696596459; h=from:from:sender: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:dkim-signature; bh=kE5lcMpcuRWxeOB9S6L9Si7YaWv5hLYl1VeNlBZzT/8=; b=uCwX+Sllmsrn13Kd6UHVifB9EQt8J1GpDAjBZCuXH0+C0w+twSMm+0xSfE2QSPrA+MeD8c uKHjM31CnD3dsII0Gb2pJ44Ahf6l1oBw8tatPSCMjxCtJ1qiZLSkpSPzwth+qpktWahzxu nWmR9p96rhwza8RLn7SD4JVr3YwNlUQ= Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-d862533ea85so2420759276.0 for ; Fri, 06 Oct 2023 05:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696596459; x=1697201259; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kE5lcMpcuRWxeOB9S6L9Si7YaWv5hLYl1VeNlBZzT/8=; b=dcuhHJGL2gC8iyYqHENJAUpBlkdVkju4hHso2FzyWrt6wzSfyoqHzbl4hcgN3G7PMp 1z1iXCWeK3OXX6eJJMepLs/gEr0wt9TG9XqeKCO8pJt+ayhvmAgXyBROzDj9/RKn1ONF vywOT1ZQRKagXR3ajc6n3xCdvj5PKKEkYlyEn9fENL/Uw86HNprqlEphLThuqvglFb/S WYFJrVj7pG+xYGXxHtYUM/MPY7+O2Nu6Th9IYNvEzbC9eDqcj7TF1KH629JubvFlw5Vk 6mCjRDyIKc0E9OtWNHdaygxb9O+qBgdfrLEoijVYGsSwGV0wUD0Bga7pW3jE4I/mj7VV zvXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596459; x=1697201259; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kE5lcMpcuRWxeOB9S6L9Si7YaWv5hLYl1VeNlBZzT/8=; b=B8jb3YHECuNkwLeafP3NmE6FEn2H9DKFE2PWq0A+XQ6ZyRcAqV6Qg5pBpIyvw8ek39 e7EeGj4EaCslQELPVo70b/RW5P2CUG26eAvyZF2l+CJDM1X90OGZaFx/AMv80I0QEujr T3XPFyUSu74har6SMzywU4+29kmW2r2VCbnwAjauTuWf7w0gsrGshSoenJk1TTounAUU rGtXggAfvgTZs5JqZn6Rr91C4Jb3jSCFtyOHDbQJDo+q2T+dv/xP5gDDqQnLheBjNtlQ 88qCNDaAngTKXkwd2EItQ6kkUbQfaueY9iXAF6BrlBADodTU7ocIdPMIh7AoyQf95QDp Q+cg== X-Gm-Message-State: AOJu0YxNwf145SK9u+e+cgZZtc7OSBrBbt7TQaMnqefayldpa8FpiUxi RBvFj07yIWd7PLvr7y1pWD+VrEm8ImBpas/ReO5Pww== X-Google-Smtp-Source: AGHT+IGILgsJf+f8eayHVHqX0rISrGr9tP06v0nLvKR1oTcr5riaw9zUWCGoAJpDUWeKMDK50UY6pLVZ+E+8O7Aw+dY= X-Received: by 2002:a5b:807:0:b0:d47:8db3:8bcf with SMTP id x7-20020a5b0807000000b00d478db38bcfmr7283393ybp.49.1696596458614; Fri, 06 Oct 2023 05:47:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fuad Tabba Date: Fri, 6 Oct 2023 13:47:01 +0100 Message-ID: Subject: Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , KVM , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , KVMARM , LinuxMIPS , linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, open list , Chao Peng , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CDC0118001B X-Stat-Signature: xmcdwwtcyfkc81zwzk8phuwosw6gbjon X-HE-Tag: 1696596459-944763 X-HE-Meta: U2FsdGVkX1+vzGG3SHmYf6F8yD9ZbtyiUM6XYgfLjTD7dQp3hQTK9S23fHhpWwNUQFl+2PcXQzu3Oz5WrxZgYU+RqgLR9BounfPwF7vMh8afGxdt1wX8zKAcVh7o25nFLUhm0OQSIV5xoszsyZFVDhPL9xfdEgCEvlv42nuPh7De8J1lvpnilZE3uk8pqRg8wiLRHSgoWVleIqIz1v6yYmYBtaYeUsEgeXEIh2BF3aCpP7IWuKfBakz2V+9QcPSmXMKJd+Nk7ZocgAorYzoJ2smemWkBzC0L/PdiXKHEl/fPr/B0i/ihgan1i/Ou/SFDdSc0mLsZnnapDP0VS0hOZVQAPRvA9x/bVNPDk/QC4jg15c79bnbufwt3jGCEBmbmep71thmVuagG2ercfSw3oxuAJYsEXBnIQKAyjNF/LJ4Qq5aF9DSuh/joCneM121+fv/KYt7m/qpo0Lyubsh8dEFP2Tf3rSz5h663plASXyVXwFuLdqyvWWw7zMYblWjP0XeqaI5y1vPKBzpPhBWQ7+bUwRAQ9kPk8hjm7R29LjEA9m/aPg4rnqOftdE+DFb/HB4VAm1WYRg7RtnwEYrdE1Piq3ywshIo554zE/KnoIVHpRBqcOuTTxWfv89YlEj2HLgdoPc82AZj88lcw4yusVtSa27l67teELh4Tl7KYbGQXSl0M2ppHyuabL1VixLqlus/82gWFQ8F6sjUzFGOJYIjTqRlPUCqebILMoA0tCCr1YWu2PUCI0OVQ1xDSiTVg9yfdKnw6Y7RRS4aZ8PN0TqG9kEqpF9PRqJJyG/uP8tkeUWkMq0HNT5eXDdVbuP9vSjlUadGMR25MCN8nN+KrAEWtL2maU7pWKTSLFWS29ZO5yAf2T6FBhYm5nTKnxKgpigiyBWNpSRZJp6ktETzabxvfnY5FhqNUMORFaKsU9ViKrP2Z/CNIeUZmyXATzA4aLekIY2ZFk5MXbF4M4G zeNkpFe/ UQkmPcEoTmAu4TgnTabcCba/aPJw02fftoJe+TT9URcVxfbxxeY9YMy0YWvlJ23sqlJeNRyetP8fHBF1pOK0jbRirAgjNz1Ej36oZSdsaNumXdg+ySFVnpLt8MrrC35+JJHGPWsJVsrzXg46s0HVAzTZkN0H1brL23UhPCgL20h6kw3Hlm4faLmliqDDWCv+c6pTriDRbMWu7h3XDruFv63TezfBbGlIc7SLfvIBWpyc+MZYcENUPB5VaWvaP5x7mNqL0LDn4wPFy5T3lA/I1368sAH79o1wqOut+tEKhLCich9L5I18YV9xsOCbzWbIhB9EYfqEkTPuTKmnd+ubvxb4PJVVVw49GgerE5zY7sv6486o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Sean, On Fri, Oct 6, 2023 at 4:21=E2=80=AFAM Sean Christopherson wrote: > > On Thu, Oct 05, 2023, Fuad Tabba wrote: > > Hi Sean, > > > > On Tue, Oct 3, 2023 at 9:51=E2=80=AFPM Sean Christopherson wrote: > > > > Like I said, pKVM doesn't need a userspace ABI for managing PRIVATE= /SHARED, > > > > just a way of tracking in the host kernel of what is shared (as opp= osed to > > > > the hypervisor, which already has the knowledge). The solution coul= d simply > > > > be that pKVM does not enable KVM_GENERIC_MEMORY_ATTRIBUTES, has its= own > > > > tracking of the status of the guest pages, and only selects KVM_PRI= VATE_MEM. > > > > > > At the risk of overstepping my bounds, I think that effectively givin= g the guest > > > full control over what is shared vs. private is a mistake. It more o= r less locks > > > pKVM into a single model, and even within that model, dealing with er= rors and/or > > > misbehaving guests becomes unnecessarily problematic. > > > > > > Using KVM_SET_MEMORY_ATTRIBUTES may not provide value *today*, e.g. t= he userspace > > > side of pKVM could simply "reflect" all conversion hypercalls, and te= rminate the > > > VM on errors. But the cost is very minimal, e.g. a single extra ioct= l() per > > > converion, and the upside is that pKVM won't be stuck if a use case c= omes along > > > that wants to go beyond "all conversion requests either immediately s= ucceed or > > > terminate the guest". > > > > Now that I understand the purpose of KVM_SET_MEMORY_ATTRIBUTES, I > > agree. However, pKVM needs to track at the host kernel (i.e., EL1) > > whether guest memory is shared or private. > > Why does EL1 need it's own view/opinion? E.g. is it to avoid a accessing= data > that is still private according to EL2 (on behalf of the guest)? > > Assuming that's the case, why can't EL1 wait until it gets confirmation f= rom EL2 > that the data is fully shared before doing whatever it is that needs to b= e done? > > Ah, is the problem that whether or not .mmap() is allowed keys off of the= state > of the memory attributes? If that's so, then yeah, an internal flag in a= ttributes > is probably the way to go. It doesn't need to be a "host kernel private"= flag > though, e.g. an IN_FLUX flag to capture that the attributes aren't fully = realized > might be more intuitive for readers, and might have utility for other att= ributes > in the future too. Yes, it's because of mmap. I think that an IN_FLUX flag might work here. I'll have a go at it and see how it turns out. Thanks, /fuad > > > One approach would be to add another flag to the attributes that > > tracks the host kernel view. The way KVM_SET_MEMORY_ATTRIBUTES is > > implemented now, userspace can zero it, so in that case, that > > operation would need to be masked to avoid that. > > > > Another approach would be to have a pKVM-specific xarray (or similar) > > to do the tracking, but since there is a structure that's already > > doing something similar (i.e.,the attributes array), it seems like it > > would be unnecessary overhead. > > > > Do you have any ideas or preferences? > > > > Cheers, > > /fuad