From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Tue, 31 Oct 2023 07:04:51 -0700 Subject: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2 In-Reply-To: <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-9-seanjc@google.com> <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Message-ID: List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Tue, Oct 31, 2023, Xiaoyao Li wrote: > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > Introduce a "version 2" of KVM_SET_USER_MEMORY_REGION so that additional > > information can be supplied without setting userspace up to fail. The > > padding in the new kvm_userspace_memory_region2 structure will be used to > > pass a file descriptor in addition to the userspace_addr, i.e. allow > > userspace to point at a file descriptor and map memory into a guest that > > is NOT mapped into host userspace. > > > > Alternatively, KVM could simply add "struct kvm_userspace_memory_region2" > > without a new ioctl(), but as Paolo pointed out, adding a new ioctl() > > makes detection of bad flags a bit more robust, e.g. if the new fd field > > is guarded only by a flag and not a new ioctl(), then a userspace bug > > (setting a "bad" flag) would generate out-of-bounds access instead of an > > -EINVAL error. > > > > Cc: Jarkko Sakkinen > > Reviewed-by: Paolo Bonzini > > Reviewed-by: Xiaoyao Li > > Signed-off-by: Sean Christopherson > > --- > > Documentation/virt/kvm/api.rst | 21 +++++++++++++++++++ > > arch/x86/kvm/x86.c | 2 +- > > include/linux/kvm_host.h | 4 ++-- > > include/uapi/linux/kvm.h | 13 ++++++++++++ > > virt/kvm/kvm_main.c | 38 +++++++++++++++++++++++++++------- > > 5 files changed, 67 insertions(+), 11 deletions(-) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 21a7578142a1..ace984acc125 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6070,6 +6070,27 @@ writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG > > interface. No error will be returned, but the resulting offset will not be > > applied. > > +4.139 KVM_SET_USER_MEMORY_REGION2 > > +--------------------------------- > > + > > +:Capability: KVM_CAP_USER_MEMORY2 > > +:Architectures: all > > +:Type: vm ioctl > > +:Parameters: struct kvm_userspace_memory_region2 (in) > > +:Returns: 0 on success, -1 on error > > + > > +:: > > + > > + struct kvm_userspace_memory_region2 { > > + __u32 slot; > > + __u32 flags; > > + __u64 guest_phys_addr; > > + __u64 memory_size; /* bytes */ > > + __u64 userspace_addr; /* start of the userspace allocated memory */ > > missing > > __u64 pad[16]; I can't even copy+paste correctly :-( From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 C41F45255 for ; Tue, 31 Oct 2023 14:04:53 +0000 (UTC) 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="31K+uYgz" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d9a5a3f2d4fso5398421276.3 for ; Tue, 31 Oct 2023 07:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698761092; x=1699365892; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=31K+uYgzWFUwPzlVj/IRIh8hr6yVn6WmPfZh+7hEMGoLOcvZeHFmQj0Bf27dgRQA+b 4d68BDW226VvIVbr/R6glrBBuoQwuddbSIMZT1XaDsxNAQt/6y/98YFcE+hPz2LG2fYk NJsmGm+T3SPQqLgXhTcW+MxDuCNQfmhme3meTMyalhS95KzFiWVCrEuuLb60hExNm7X/ I/7RtZ9s4pQB/Nd6slVQUDIOJvWIMAy8SB6p+sDU0Z2kstplh30cy4BAGBie5fZpAfuO 98a075NHP5yTEAEoCXwvZQvfrOeT1UWCgk0OF0PnKHyTNzlr20CHG0swzWqMfAnnj0Em ZHjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698761092; x=1699365892; 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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=JDHWL3mnXycSkn2Nneg2BCASvIb96IrLU8PYeGmaO2gm5W2+CDTDdGSMNpS1rVDiAT XmhGaNs3XgD7u+wt+bu7bLz5UslsACNyym+X+fI5jmqyojkOqGNJAyeyE+ymMbjcTN91 S88ekykUhTvEvatcSN9aWcet1MZ5Gz8qAeJ2GYn0fvYE4GuK7luP5oNRsHQlbrwEjCQn KI+qs1l2DUhBoCC4QnzTQzZCKS9FSX79jZ75Lb7MiuHYJtIrHqXjfbvCaliqdQG5F+6J NR3Ysw4T3HJdYNTYyjnkfB5xO+o3hJ4Zh29qoprA23TwZ90/44Le0l9mik16go6s+4QJ T2+A== X-Gm-Message-State: AOJu0YxCPn1D/dfkVFaSN9C7qLnBv6DsQ47mq0OvdZgS1C80aB7DdPCY 7Behdw4zbBr3PqZE1jfISYjkr9Pb654= X-Google-Smtp-Source: AGHT+IGMRYf422gsAhq04hJnKRMCzmHg+RO6tAl4JuMhPFGeve1lxsPBrReypZbUvK9g95iFN5O303NMZlw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:d9a:c3b8:4274 with SMTP id v3-20020a056902108300b00d9ac3b84274mr301710ybu.7.1698761092559; Tue, 31 Oct 2023 07:04:52 -0700 (PDT) Date: Tue, 31 Oct 2023 07:04:51 -0700 In-Reply-To: <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-9-seanjc@google.com> <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Message-ID: Subject: Re: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2 From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, 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-kernel@vger.kernel.org, Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , "=?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?=" , 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="us-ascii" On Tue, Oct 31, 2023, Xiaoyao Li wrote: > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > Introduce a "version 2" of KVM_SET_USER_MEMORY_REGION so that additional > > information can be supplied without setting userspace up to fail. The > > padding in the new kvm_userspace_memory_region2 structure will be used to > > pass a file descriptor in addition to the userspace_addr, i.e. allow > > userspace to point at a file descriptor and map memory into a guest that > > is NOT mapped into host userspace. > > > > Alternatively, KVM could simply add "struct kvm_userspace_memory_region2" > > without a new ioctl(), but as Paolo pointed out, adding a new ioctl() > > makes detection of bad flags a bit more robust, e.g. if the new fd field > > is guarded only by a flag and not a new ioctl(), then a userspace bug > > (setting a "bad" flag) would generate out-of-bounds access instead of an > > -EINVAL error. > > > > Cc: Jarkko Sakkinen > > Reviewed-by: Paolo Bonzini > > Reviewed-by: Xiaoyao Li > > Signed-off-by: Sean Christopherson > > --- > > Documentation/virt/kvm/api.rst | 21 +++++++++++++++++++ > > arch/x86/kvm/x86.c | 2 +- > > include/linux/kvm_host.h | 4 ++-- > > include/uapi/linux/kvm.h | 13 ++++++++++++ > > virt/kvm/kvm_main.c | 38 +++++++++++++++++++++++++++------- > > 5 files changed, 67 insertions(+), 11 deletions(-) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 21a7578142a1..ace984acc125 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6070,6 +6070,27 @@ writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG > > interface. No error will be returned, but the resulting offset will not be > > applied. > > +4.139 KVM_SET_USER_MEMORY_REGION2 > > +--------------------------------- > > + > > +:Capability: KVM_CAP_USER_MEMORY2 > > +:Architectures: all > > +:Type: vm ioctl > > +:Parameters: struct kvm_userspace_memory_region2 (in) > > +:Returns: 0 on success, -1 on error > > + > > +:: > > + > > + struct kvm_userspace_memory_region2 { > > + __u32 slot; > > + __u32 flags; > > + __u64 guest_phys_addr; > > + __u64 memory_size; /* bytes */ > > + __u64 userspace_addr; /* start of the userspace allocated memory */ > > missing > > __u64 pad[16]; I can't even copy+paste correctly :-( 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC9A9C4167D for ; Tue, 31 Oct 2023 14:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=OYL98VR0bKvDeslRT+UfwCldDEE5MIswjLU8udwXPUY=; b=djej5jZb8uzK7x3mNo2eZ4FEGi SuqlDW16QUhfQLulTknWlVD711QFdBVTkNrb33XWi63g5NTkLXIlu8VYlNFwy1jAD8D/00f6Q3A9h eMp8Az372ky5EkpyP5yBa7436n4uGZocFrg8+KmxQ1e2TO2ugyiXPKYXbWY+hTOXG4zAYAM/W+Tzl PQgh4d0QmKa3tc7/PqUfYnyPn/ENoi7AH2/5umZQ1guECQUIJFlbABAswt4646RGvdWSE2sk2nbWb S+XkM2AVA2xE0FTB1D/SY8Ke6/kb0ZFNermZN2spRWFHSOssc0BA1TdriBRuuGOAI48iRFkxEqiwj DMujdOZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qxpMZ-005O0p-32; Tue, 31 Oct 2023 14:04:59 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qxpMW-005NzE-2M for linux-riscv@lists.infradead.org; Tue, 31 Oct 2023 14:04:58 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d99ec34829aso5397609276.1 for ; Tue, 31 Oct 2023 07:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698761092; x=1699365892; darn=lists.infradead.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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=EKduNxKTl05tIjmYvFCZjj16MMz8JEcjmiE2h61746eHRbUfcSQxc/1aoDB/NC+wkd sdzsGNfUbgmfyt6PAjEPs4/vY3I6IuqQKu5m9uCXew1eJPeuRITZ22M6WVel4yOietYb DMW6zWfUVeHcLViTR1P+SrPTvTXpnN28cooUfxcs1NmFqKhJxmkwX9q/eh6WS81AJEA1 2R54KnFQD9Agf/v++ljwmUS2UQEBf5VrofMK4omMFbPXAtA1WHHghFveVnBn8McG9WqE s7bAraAO/NCxZw3V2jF33bIkwqMhcl44UIHgIUk2JMDV32tjjPQRK11rW4H9ZwELtVMl H0Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698761092; x=1699365892; 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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=C6uv6VUXaI1ek27njNhgOUmJPVySPBXq7x6VgcSzsD9udb52P0ET0qkcoCsXvvNTfx 04pdiudlRQ6SOv5LXXiwahzJs80AOZ8Bwqx3r3ISZCUdmYKqgG1ypFc0XfiIxdpTh+hK METjF9eWbRb3imXx98TE0D94Fyc4WKClMRJ0I/xX/L2uhhwMjRWGxAZPz0an8wbdqqVV jDVXUy00RI68OlMfOhI4UCLLFkDYrcW3MYBG+yl1DfJfCZfjvsPHxRykRExGp7ZXYhsl OOqHuCvMhlxsJptf4tBYUuLRytFRZO7nFMEF2qgRu19+JlSorIEobEH8nHCcCGVwS1Zk PIyw== X-Gm-Message-State: AOJu0YwXGKbNZJAl/Cz3tpyHASfcd8m5HW9/LjHVJYuF4RbSbdIbIUYw zgJPkrIC2U6TVb88J+H0C10UEUn6qog= X-Google-Smtp-Source: AGHT+IGMRYf422gsAhq04hJnKRMCzmHg+RO6tAl4JuMhPFGeve1lxsPBrReypZbUvK9g95iFN5O303NMZlw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:d9a:c3b8:4274 with SMTP id v3-20020a056902108300b00d9ac3b84274mr301710ybu.7.1698761092559; Tue, 31 Oct 2023 07:04:52 -0700 (PDT) Date: Tue, 31 Oct 2023 07:04:51 -0700 In-Reply-To: <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-9-seanjc@google.com> <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Message-ID: Subject: Re: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2 From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, 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-kernel@vger.kernel.org, Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , "=?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?=" , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231031_070456_771011_D82DCFEA X-CRM114-Status: GOOD ( 25.11 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Tue, Oct 31, 2023, Xiaoyao Li wrote: > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > Introduce a "version 2" of KVM_SET_USER_MEMORY_REGION so that additional > > information can be supplied without setting userspace up to fail. The > > padding in the new kvm_userspace_memory_region2 structure will be used to > > pass a file descriptor in addition to the userspace_addr, i.e. allow > > userspace to point at a file descriptor and map memory into a guest that > > is NOT mapped into host userspace. > > > > Alternatively, KVM could simply add "struct kvm_userspace_memory_region2" > > without a new ioctl(), but as Paolo pointed out, adding a new ioctl() > > makes detection of bad flags a bit more robust, e.g. if the new fd field > > is guarded only by a flag and not a new ioctl(), then a userspace bug > > (setting a "bad" flag) would generate out-of-bounds access instead of an > > -EINVAL error. > > > > Cc: Jarkko Sakkinen > > Reviewed-by: Paolo Bonzini > > Reviewed-by: Xiaoyao Li > > Signed-off-by: Sean Christopherson > > --- > > Documentation/virt/kvm/api.rst | 21 +++++++++++++++++++ > > arch/x86/kvm/x86.c | 2 +- > > include/linux/kvm_host.h | 4 ++-- > > include/uapi/linux/kvm.h | 13 ++++++++++++ > > virt/kvm/kvm_main.c | 38 +++++++++++++++++++++++++++------- > > 5 files changed, 67 insertions(+), 11 deletions(-) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 21a7578142a1..ace984acc125 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6070,6 +6070,27 @@ writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG > > interface. No error will be returned, but the resulting offset will not be > > applied. > > +4.139 KVM_SET_USER_MEMORY_REGION2 > > +--------------------------------- > > + > > +:Capability: KVM_CAP_USER_MEMORY2 > > +:Architectures: all > > +:Type: vm ioctl > > +:Parameters: struct kvm_userspace_memory_region2 (in) > > +:Returns: 0 on success, -1 on error > > + > > +:: > > + > > + struct kvm_userspace_memory_region2 { > > + __u32 slot; > > + __u32 flags; > > + __u64 guest_phys_addr; > > + __u64 memory_size; /* bytes */ > > + __u64 userspace_addr; /* start of the userspace allocated memory */ > > missing > > __u64 pad[16]; I can't even copy+paste correctly :-( _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C0CEC4332F for ; Tue, 31 Oct 2023 14:05:49 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=T4nLNgBf; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SKX3b4sK9z3cSd for ; Wed, 1 Nov 2023 01:05:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=T4nLNgBf; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--seanjc.bounces.google.com (client-ip=2607:f8b0:4864:20::1149; helo=mail-yw1-x1149.google.com; envelope-from=3halbzqykdms9vr40tx55x2v.t532z4be66t-uvc2z9a9.5g2rs9.58x@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SKX2d2NZrz3bZr for ; Wed, 1 Nov 2023 01:04:55 +1100 (AEDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7af69a4baso63839187b3.0 for ; Tue, 31 Oct 2023 07:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698761092; x=1699365892; darn=lists.ozlabs.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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=T4nLNgBftf2ElDbB3iD5kDrjDVJ6+78wne5ffs2CuaEKA8EZnsok7p3LdC0iGmrSeI EOwLW8qlSDJVucyJdLXBfCWhipnf2bZpwe9uKxAku+xEjdwSL1/XuDGxL0UmhksVhb8M axgDwnWUjmDpIczVhKPVP4y8rnf0c+1ryeQ3GE6J1yEh6YwcYDolsRC4LYFJ/zS2LaK6 XGvwQ2Rd79fZ28jO2AU6gj16fl+/NfkZy+rnLZlMFCMbF2be8YOBhc9/iw77pAHF73Sl p0w8daK/mpZbl1bkfPubOp4fYJNG87QSzNpWev1HqNd0W3UfZS5XhD9KYFyIJxJBvJqs L8Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698761092; x=1699365892; 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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=vwbcdSgfCU55n/ph+Tm4DrByiRdyYl6xFeTWUU+Lk2rvDMZk8J0K6ZxpELnteTFzE0 P1X5JSP/lDgmDRGMOlpxGYFM+3Htm+8GZkv/S1YKmu+9rQ466mEIKoxxjCue2G+/SWWz q6alPBfa483IPk8KYKAeP7MoUKPfOkKLZCQlndIZ+PIJF9vtVSFd92G2WSobos0MkSx4 Ugcawa3YGbnwnhV1tR80g5LrvpVnR4UuFuRNn/06ic5tHF5OsSAS8XwB9MFeZX8U4R9C OLHIFLkRXrSmYL3hKGvtb2ckCEEL7DciIqroFvQYncHBB1wwRkfttORvNFQkC4fwq0Bf WWpg== X-Gm-Message-State: AOJu0YxLJNyZO7sORBVx5Y9oUruKsMdqTC1+5QlwnPmBdWrOpa+X7c2I Kl8+gWr2fJzyfbKe6myZg610Zj0lmGM= X-Google-Smtp-Source: AGHT+IGMRYf422gsAhq04hJnKRMCzmHg+RO6tAl4JuMhPFGeve1lxsPBrReypZbUvK9g95iFN5O303NMZlw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:d9a:c3b8:4274 with SMTP id v3-20020a056902108300b00d9ac3b84274mr301710ybu.7.1698761092559; Tue, 31 Oct 2023 07:04:52 -0700 (PDT) Date: Tue, 31 Oct 2023 07:04:51 -0700 In-Reply-To: <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-9-seanjc@google.com> <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Message-ID: Subject: Re: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2 From: Sean Christopherson To: Xiaoyao Li Content-Type: text/plain; charset="us-ascii" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chao Peng , linux-riscv@lists.infradead.org, Isaku Yamahata , Marc Zyngier , Huacai Chen , "Matthew Wilcox \(Oracle\)" , Wang , Fuad Tabba , Yu Zhang , Maciej Szmigiero , Albert Ou , Vlastimil Babka , Michael Roth , Ackerley Tng , Alexander Viro , Paul Walmsley , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= , Isaku Yamahata , Christian Brauner , Quentin Perret , Liam Merwick , linux-mips@vger.kernel.org, Oliver Upton , David Matlack , Jarkko Sakkinen , Palmer Dabbelt , "Kirill A . Shutemov" , kvm-riscv@lists.infradead.org, Anup Patel , linux-fsdevel@vger.kernel.org, Paolo Bonzini , Andrew Morton , Vishal Annapurve , linuxppc-dev@lists.ozlabs.org, Xu Yilun , Anish Moorthy Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, Oct 31, 2023, Xiaoyao Li wrote: > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > Introduce a "version 2" of KVM_SET_USER_MEMORY_REGION so that additional > > information can be supplied without setting userspace up to fail. The > > padding in the new kvm_userspace_memory_region2 structure will be used to > > pass a file descriptor in addition to the userspace_addr, i.e. allow > > userspace to point at a file descriptor and map memory into a guest that > > is NOT mapped into host userspace. > > > > Alternatively, KVM could simply add "struct kvm_userspace_memory_region2" > > without a new ioctl(), but as Paolo pointed out, adding a new ioctl() > > makes detection of bad flags a bit more robust, e.g. if the new fd field > > is guarded only by a flag and not a new ioctl(), then a userspace bug > > (setting a "bad" flag) would generate out-of-bounds access instead of an > > -EINVAL error. > > > > Cc: Jarkko Sakkinen > > Reviewed-by: Paolo Bonzini > > Reviewed-by: Xiaoyao Li > > Signed-off-by: Sean Christopherson > > --- > > Documentation/virt/kvm/api.rst | 21 +++++++++++++++++++ > > arch/x86/kvm/x86.c | 2 +- > > include/linux/kvm_host.h | 4 ++-- > > include/uapi/linux/kvm.h | 13 ++++++++++++ > > virt/kvm/kvm_main.c | 38 +++++++++++++++++++++++++++------- > > 5 files changed, 67 insertions(+), 11 deletions(-) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 21a7578142a1..ace984acc125 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6070,6 +6070,27 @@ writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG > > interface. No error will be returned, but the resulting offset will not be > > applied. > > +4.139 KVM_SET_USER_MEMORY_REGION2 > > +--------------------------------- > > + > > +:Capability: KVM_CAP_USER_MEMORY2 > > +:Architectures: all > > +:Type: vm ioctl > > +:Parameters: struct kvm_userspace_memory_region2 (in) > > +:Returns: 0 on success, -1 on error > > + > > +:: > > + > > + struct kvm_userspace_memory_region2 { > > + __u32 slot; > > + __u32 flags; > > + __u64 guest_phys_addr; > > + __u64 memory_size; /* bytes */ > > + __u64 userspace_addr; /* start of the userspace allocated memory */ > > missing > > __u64 pad[16]; I can't even copy+paste correctly :-( 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18838C4332F for ; Tue, 31 Oct 2023 14:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=aG37QuqkmLTirrhawE53vN+d3ltd+u2TkhgYVflprlQ=; b=n5dS97LftFDPFztXzuTYMCgyaM +iU6AWs+Rt1iS+PN5Bl2Ko67cds7QtRxXjQT75b+zQTpzZUtqnH0aaaTWqy/znJWaVnq+kGItKvZb 6hGUZFXI7Zi45Sf7bZtLLWFefiY7uzar0nXb8+gh6JhYAlWpl/+SpfeL1PNYKpoFtysdo0xWf317o H/aqY4tqq/QTVy8idwNKLJu5H7d0FPZwgoU5SJNADuBGOKkerbHFLW75vYpfUeO69U5HFICLbMr8B WZJtmV2uorjQfhDkIYiltUyjW4X8qFgXVB9TQCzTPj4yf67JSQly6/bq8T6IIZ30+pjhoMeNLIqdy jLPrt8wg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qxpMZ-005O0b-0A; Tue, 31 Oct 2023 14:04:59 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qxpMW-005NzD-0E for linux-arm-kernel@lists.infradead.org; Tue, 31 Oct 2023 14:04:57 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da04fb79246so5390916276.2 for ; Tue, 31 Oct 2023 07:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698761092; x=1699365892; darn=lists.infradead.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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=EKduNxKTl05tIjmYvFCZjj16MMz8JEcjmiE2h61746eHRbUfcSQxc/1aoDB/NC+wkd sdzsGNfUbgmfyt6PAjEPs4/vY3I6IuqQKu5m9uCXew1eJPeuRITZ22M6WVel4yOietYb DMW6zWfUVeHcLViTR1P+SrPTvTXpnN28cooUfxcs1NmFqKhJxmkwX9q/eh6WS81AJEA1 2R54KnFQD9Agf/v++ljwmUS2UQEBf5VrofMK4omMFbPXAtA1WHHghFveVnBn8McG9WqE s7bAraAO/NCxZw3V2jF33bIkwqMhcl44UIHgIUk2JMDV32tjjPQRK11rW4H9ZwELtVMl H0Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698761092; x=1699365892; 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=ZsemryN+7v+wOBolNu7Hy0wHrULeaB9eFsfVkGp1/e8=; b=jHHDkxRWRqPcyna1TirHL5Zt5ppncIlnHa/+JyQ/n5WK6qzFbYqybzqhICX0lirMgn QybhjpUqMB2df9w6Ane00sz/kpRsLNEHeQNcjh5pmp90LfiIhAj55f29VxJ35sMTpLbD 0j/ukPdScmR/SE01lUgBy8QeTFyxQXBsCsG6uXTZLAyLlYDgelApE94ajUz4Z8Te1+Bp T5+nKSa0PLn9NMCweB2/3xQzQrSmdmCmjdsXxh00PAx3B6uYgqiOCVY5BTg1bUwgM6uT tfiwMMq5vcm0bltmIp3sc45SMvMIOelPnl3Xg+GwZOufTpfTdyuRoBcoFN3nStrcLRX9 eFAQ== X-Gm-Message-State: AOJu0Yx0ntE50X9vb6KltoIcjHUbo0B/V/XGwRhEPenv4Da64LkKNcRy 7boEx8APOtjSBzfq0Ge83kTSCuGAmV0= X-Google-Smtp-Source: AGHT+IGMRYf422gsAhq04hJnKRMCzmHg+RO6tAl4JuMhPFGeve1lxsPBrReypZbUvK9g95iFN5O303NMZlw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:d9a:c3b8:4274 with SMTP id v3-20020a056902108300b00d9ac3b84274mr301710ybu.7.1698761092559; Tue, 31 Oct 2023 07:04:52 -0700 (PDT) Date: Tue, 31 Oct 2023 07:04:51 -0700 In-Reply-To: <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-9-seanjc@google.com> <2edd908a-9699-4d8e-9063-c655f1fc9712@intel.com> Message-ID: Subject: Re: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2 From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, 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-kernel@vger.kernel.org, Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , "=?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?=" , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231031_070456_108495_3EA02200 X-CRM114-Status: GOOD ( 26.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Oct 31, 2023, Xiaoyao Li wrote: > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > Introduce a "version 2" of KVM_SET_USER_MEMORY_REGION so that additional > > information can be supplied without setting userspace up to fail. The > > padding in the new kvm_userspace_memory_region2 structure will be used to > > pass a file descriptor in addition to the userspace_addr, i.e. allow > > userspace to point at a file descriptor and map memory into a guest that > > is NOT mapped into host userspace. > > > > Alternatively, KVM could simply add "struct kvm_userspace_memory_region2" > > without a new ioctl(), but as Paolo pointed out, adding a new ioctl() > > makes detection of bad flags a bit more robust, e.g. if the new fd field > > is guarded only by a flag and not a new ioctl(), then a userspace bug > > (setting a "bad" flag) would generate out-of-bounds access instead of an > > -EINVAL error. > > > > Cc: Jarkko Sakkinen > > Reviewed-by: Paolo Bonzini > > Reviewed-by: Xiaoyao Li > > Signed-off-by: Sean Christopherson > > --- > > Documentation/virt/kvm/api.rst | 21 +++++++++++++++++++ > > arch/x86/kvm/x86.c | 2 +- > > include/linux/kvm_host.h | 4 ++-- > > include/uapi/linux/kvm.h | 13 ++++++++++++ > > virt/kvm/kvm_main.c | 38 +++++++++++++++++++++++++++------- > > 5 files changed, 67 insertions(+), 11 deletions(-) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 21a7578142a1..ace984acc125 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6070,6 +6070,27 @@ writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG > > interface. No error will be returned, but the resulting offset will not be > > applied. > > +4.139 KVM_SET_USER_MEMORY_REGION2 > > +--------------------------------- > > + > > +:Capability: KVM_CAP_USER_MEMORY2 > > +:Architectures: all > > +:Type: vm ioctl > > +:Parameters: struct kvm_userspace_memory_region2 (in) > > +:Returns: 0 on success, -1 on error > > + > > +:: > > + > > + struct kvm_userspace_memory_region2 { > > + __u32 slot; > > + __u32 flags; > > + __u64 guest_phys_addr; > > + __u64 memory_size; /* bytes */ > > + __u64 userspace_addr; /* start of the userspace allocated memory */ > > missing > > __u64 pad[16]; I can't even copy+paste correctly :-( _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel