Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp272196rdb; Tue, 31 Oct 2023 07:11:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhjRb26JcPWobs0lQpU2AZv1rfniq2sEpQr4hULOH6sd5zEYBt+Qm4CgUEZQxvfrpjgSvw X-Received: by 2002:a17:90a:fb81:b0:280:3b2:d37a with SMTP id cp1-20020a17090afb8100b0028003b2d37amr9180466pjb.18.1698761484320; Tue, 31 Oct 2023 07:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698761484; cv=none; d=google.com; s=arc-20160816; b=XxfZWAe3xvv9bGUq1Lx+aJgN2P08xZ3IdplniqVo9TcfEIPZ8131yrGWQOsqrAq10R lM/rQqW5vNh40MBF7cqjj3EjHa6Pel5njAEuiZOrXwV99ONbGsLtpeVixzvjulxnJnWL cf7kbfLFD4Sz4JSPqLRtZNRjEQiFr1VHvve541oMbKNNRRN3TZWucxu+bgA1FUIk9Rml aAfn740A/z6T4cfJ0dduDHkfTq2fnfqNvuwTt+22yYPF0jdgmNE+oypWzDdHUw5cH5IN RSIz9J3o9Fejh0cBtpt1PqRy3H9FO9KNpI2e6znjZhSY/lu7MkTXaTd/TrHDzCy3+Ao4 y2hA== 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=qnQOjymnTrZBwkJL50GP/1+n+ilT5bo3LZ+viwIL69A=; fh=s1zZd6XT38lO6jzd4cbHaVrhBjuOUogubuGHXcDK66k=; b=yKH1j8tQYg8F+SvJeCMvLnr8lyyYOTmof0v6W5JzHNc/zCkHYg0LizFqrsNuPhAdGo Ds6AxYJ0Z9hI2diyfbWLzsKxDCmLeMGX8ILjmsDRMkNIuep5Q7Rpo87NSvAD1putAzkI N5mFD5uHuST5ylurs3lE+1/CRxMxG23n8vcjsXfSDwFKqVAFWCMcj9aUeptI1rv0LKnc +jDm/pqaqxU9jN/Cg31fsFisq5t06nS5hw96RKY6vvqVdMmxtsMaita4ncvIeQENWTrj gQ3rzgwE2LYM3GmefHjC/tWtlt1pMGtCQrlcJc9QvWPIEhPykCqBmbrcTds31yxZe3/J +7VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=z0MqeRGv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ip6-20020a17090b314600b002801dcb4770si1033038pjb.137.2023.10.31.07.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 07:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=z0MqeRGv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id E2293807CED1; Tue, 31 Oct 2023 07:10:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235052AbjJaOKe (ORCPT + 99 others); Tue, 31 Oct 2023 10:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbjJaOKX (ORCPT ); Tue, 31 Oct 2023 10:10:23 -0400 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 3A7D718C for ; Tue, 31 Oct 2023 07:10:11 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5b0e9c78309so36495237b3.1 for ; Tue, 31 Oct 2023 07:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698761410; x=1699366210; 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=qnQOjymnTrZBwkJL50GP/1+n+ilT5bo3LZ+viwIL69A=; b=z0MqeRGvW14GWNa8pBelMmpO5+NOF/ApuojoVC/wg81KjdUsKW6wOPu//fOextVE0Z Qt6UX9h2DGe3YLEoN3v6XDAtiLFYP7oGE/y8JZuBhkBwhQRiPEUtwoQ87l5ttGRT6jmv qI7Xpi1BD3/JUOgEf/QDlBlZmbDWKmYL6uX2WvhboDMh1GE/x3IB2wNflFafzbNEdKbI niKUgr+KIj25mNFMmbtDlI550afgDLnfAVYF08BBDzODC7Sx8lnhlNYkosEQ4/FiifKv V1nzmKlbqP+6hEueCBMfqWOm/cJ68GySDPMzlcA6iBeM0WUymUuVtz3q/hO9uHELfIRR JhGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698761410; x=1699366210; 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=qnQOjymnTrZBwkJL50GP/1+n+ilT5bo3LZ+viwIL69A=; b=fNi+h32CjGSz/T9LzXpcGZbdXD+XmC0iQaVqQppzxiKG++hieFeF6Z3jRjPL3cALiJ 2XPrNPqqyf0ZrKRRnH5S4de/sdeq1MBvL0xcx2kJzkKzkQ0RdKwKSG2ybvxb6/DmhiXM oUFqwpQKqAkf0RT1G+5VCK3i05QN63SNQn1rBGKCFP2PQFf4xwqwj9uibmzDxBmbo8BB Q38FW9zAs24oKiKAo6tk2IOrIXTbzicF4QCZfMsrTbR6l5eIujTXJD/vU4vVP9ZkPNkp rgq+K/j7omNXHqQpHT6DzxHjcYHn2E56XVgCZ2gHMU8eblqvSPqh4K1VAHQIKb2H0Jop GG2Q== X-Gm-Message-State: AOJu0YxAGp5Nf2i7JXgQPty5BHLsBCBIW+zcA2Zfqyao6fCGAiaBZ1/l /pIdA+4rCVTSLxVi2Sl8SjJGm9+ThKU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:a14c:0:b0:59b:eea4:a5a6 with SMTP id y73-20020a81a14c000000b0059beea4a5a6mr274540ywg.0.1698761410163; Tue, 31 Oct 2023 07:10:10 -0700 (PDT) Date: Tue, 31 Oct 2023 07:10:08 -0700 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: Chao Gao 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=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 31 Oct 2023 07:10:42 -0700 (PDT) On Tue, Oct 31, 2023, Chao Gao wrote: > >+int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args) > >+{ > >+ loff_t size = args->size; > >+ u64 flags = args->flags; > >+ u64 valid_flags = 0; > >+ > >+ if (flags & ~valid_flags) > >+ return -EINVAL; > >+ > >+ if (size < 0 || !PAGE_ALIGNED(size)) > >+ return -EINVAL; > > is size == 0 a valid case? Nope, this is a bug. > >+ if (!xa_empty(&gmem->bindings) && > >+ xa_find(&gmem->bindings, &start, end - 1, XA_PRESENT)) { > >+ filemap_invalidate_unlock(inode->i_mapping); > >+ goto err; > >+ } > >+ > >+ /* > >+ * No synchronize_rcu() needed, any in-flight readers are guaranteed to > >+ * be see either a NULL file or this new file, no need for them to go > >+ * away. > >+ */ > >+ rcu_assign_pointer(slot->gmem.file, file); > >+ slot->gmem.pgoff = start; > >+ > >+ xa_store_range(&gmem->bindings, start, end - 1, slot, GFP_KERNEL); > >+ filemap_invalidate_unlock(inode->i_mapping); > >+ > >+ /* > >+ * Drop the reference to the file, even on success. The file pins KVM, > >+ * not the other way 'round. Active bindings are invalidated if the > >+ * file is closed before memslots are destroyed. > >+ */ > >+ fput(file); > >+ return 0; > >+ > >+err: > >+ fput(file); > >+ return -EINVAL; > > The cleanup, i.e., filemap_invalidate_unlock() and fput(), is common. So, I think it > may be slightly better to consolidate the common part e.g., I would prefer to keep this as-is. Only goto needs the unlock, and I find it easier to understand the success vs. error paths with explicit returns. But it's not a super strong preference.