Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2210105rdf; Mon, 6 Nov 2023 07:43:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFg5YlPu4GNBkc7hSv4j+o7juDhKmuiLwpi3oguUDQnpJfO5mJC9XesqZOyzT/IJ9tOwtt+ X-Received: by 2002:a17:90a:d14f:b0:280:3cc4:f052 with SMTP id t15-20020a17090ad14f00b002803cc4f052mr19656830pjw.17.1699285409841; Mon, 06 Nov 2023 07:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699285409; cv=none; d=google.com; s=arc-20160816; b=cNncwBMxhyjRJ3GIJaQJOU57f7AYGBq7Kli4y/BiTMqJen9HsVggZfbzmFDJJsrp0b +1lBCUMvp9s/F4FeHuRrZD0KxzlQo7/f/Pz1qgQr6h30EdBja7ZQoW9QiQyh3xyjDK/Q /qYSHLoG8b/Hpbdbw+wY2OCitsXn9SVrVY++fR8SidtllpKySPDghFJlL/YVb/0tWEfZ xTsQYS0CurxNMKdxwQiWsBXlCztS836C6bUZqyTW1XPh1JcBgr5jkbOS/c6hQ3WcWpoo 9OGp2cL+1CqbltvqmJwlkiUNlVQ3pyezUvKfXJMD/j33JFsgeqNPSjyqBrdgXFuC/4eg kpZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=ABS8rPoBy1ITQ62kUEvxWovIfmSWeQOAvNCpebOJLoI=; fh=az0dYthJxY2XaQxbVlWHFpi9od2C/z1Z8eryZcjliGE=; b=Hqq0RQAdgGlwNh1NDJWFq+JgVjrkAAg+4P2bVsTVfrGdjw5DAvjgknxNKjRhEjRcA0 tJ6w22maYNkb5sUMcBqE7mrZFWDgzJGn5ZDUnsFJM9QbjxT/POvvbE0ArPbCOzba+ms6 Ed4KoYE//RCM7X4S7hOF3HYQNTCX7WvHisfb8ZX7WKfPi6vKUshCqpqDdvLSSPVZrSDR BEstYKcFLCWZUpfMCIOosvcBrGTmivdylEJQWT21KCGrBqM+IT1M/uKxwrrfZVU05Ly4 EdeEQ8VDLT576hhvs6vkp28Qo0EyJaHwqcbDX81diIWWQpDBY4wtU0d4VCm8zj37jzZz ChPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vzsyRpmA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f1-20020a17090ace0100b002802838d551si8448799pju.157.2023.11.06.07.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 07:43:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vzsyRpmA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E0CA88025BC0; Mon, 6 Nov 2023 07:43:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbjKFPn1 (ORCPT + 99 others); Mon, 6 Nov 2023 10:43:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232115AbjKFPn0 (ORCPT ); Mon, 6 Nov 2023 10:43:26 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DCB9134 for ; Mon, 6 Nov 2023 07:43:23 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a8d9dcdd2bso93832527b3.2 for ; Mon, 06 Nov 2023 07:43:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699285403; x=1699890203; 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=ABS8rPoBy1ITQ62kUEvxWovIfmSWeQOAvNCpebOJLoI=; b=vzsyRpmAxCH/8GChvrGqDn1yvCAI0owjxSc6wm0w6nRGowEL6uQH0k86wM3BowHnWI YO+R/Q2MeQV7zL2YvlMRp+22CKQJHYviHQJiz0i65xCl7cDkcN92Hc+gP14ppMymRD2H aNKuUvrMcOB0Y4b701bftPjfVwD1nBdpNRCXnjvIWg7qEQYr6bnVR10Wr9ZRLz5WKfcL qITuyIHcTB0+pH6vcpcz51cGsP3HxdLI6QiqVZ5anzF+GCPejnwTJ6NV8yQuDbkP8EAc /QZSYZnij1meUOSvTcHCycSqLXFAA8JQQ7ufFnyiSnwYFLNV/kl6P7zkJFOHvY7xbPv8 Os3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699285403; x=1699890203; 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=ABS8rPoBy1ITQ62kUEvxWovIfmSWeQOAvNCpebOJLoI=; b=cRN003EERXT6Uqvd8DsVlT2O/XoWK/UisMUzh8KmvtO9yCd0fIJySTt6YRkweQaIdO JFSoTcdOJmg63M5CJM1UXkHRLtmt7KaQSPTud1FLkr/ErFHn7l+M51/w2159i/fNKE0G da+gqB7H5kY9dy9KcgvJnQSMVvm5ZwvEME78iJhVQhne7xu1TUHASU41dFXN9kx64PSI aF6GtjEeKPDYbafJvnMZNO3HggCZiww/R23xGbfpXXTXO7T5/nbRSrJaNBjEGgc0RrMk H7HNjd/eJliJ0x93agSP2ZuCwrHapNAryPesfj1amXdNeMRSm+PdK5gEmXragl1y3WPd 2Fyg== X-Gm-Message-State: AOJu0Yye22KGdq80WcNo310xBP5Z9tRQq2yyjgzC9iwkMW9GG27tmlE8 ekAZ0/GVf67rRHLSQCkCOZiuqom3t7M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:ce94:0:b0:da0:3bea:cdc7 with SMTP id x142-20020a25ce94000000b00da03beacdc7mr527390ybe.2.1699285402751; Mon, 06 Nov 2023 07:43:22 -0800 (PST) Date: Mon, 6 Nov 2023 07:43:07 -0800 In-Reply-To: Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-17-seanjc@google.com> Message-ID: Subject: Re: [PATCH v13 16/35] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory From: Sean Christopherson To: Xu Yilun 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, Xiaoyao Li , 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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 07:43:29 -0800 (PST) On Sat, Nov 04, 2023, Xu Yilun wrote: > > +KVM_SET_USER_MEMORY_REGION2 is an extension to KVM_SET_USER_MEMORY_REGION that > > +allows mapping guest_memfd memory into a guest. All fields shared with > > +KVM_SET_USER_MEMORY_REGION identically. Userspace can set KVM_MEM_PRIVATE in > > +flags to have KVM bind the memory region to a given guest_memfd range of > > +[guest_memfd_offset, guest_memfd_offset + memory_size]. The target guest_memfd > ^ > The range end should be exclusive, is it? Yes, that should be a ')', not a ']'. > > +static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags) > > +{ > > + const char *anon_name = "[kvm-gmem]"; > > + struct kvm_gmem *gmem; > > + struct inode *inode; > > + struct file *file; > > + int fd, err; > > + > > + fd = get_unused_fd_flags(0); > > + if (fd < 0) > > + return fd; > > + > > + gmem = kzalloc(sizeof(*gmem), GFP_KERNEL); > > + if (!gmem) { > > + err = -ENOMEM; > > + goto err_fd; > > + } > > + > > + /* > > + * Use the so called "secure" variant, which creates a unique inode > > + * instead of reusing a single inode. Each guest_memfd instance needs > > + * its own inode to track the size, flags, etc. > > + */ > > + file = anon_inode_getfile_secure(anon_name, &kvm_gmem_fops, gmem, > > + O_RDWR, NULL); > > + if (IS_ERR(file)) { > > + err = PTR_ERR(file); > > + goto err_gmem; > > + } > > + > > + file->f_flags |= O_LARGEFILE; > > + > > + inode = file->f_inode; > > + WARN_ON(file->f_mapping != inode->i_mapping); > > Just curious, why should we check the mapping fields which is garanteed in > other subsystem? Mostly to document the behavior. The vast majority of folks that read this code will be KVM developers, not file systems developers, and will likely have no clue about the relationship between f_mapping and i_mapping. And in the extremely unlikely scenario that anon_inode_getfile_secure() no longer sets f_mapping, a WARN detects the issue whereas a comment does not.