Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2212408rdb; Mon, 9 Oct 2023 17:27:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLwemtbCpElNpn0s09ya8D8bbpJBde1yQxnau5keM+EZ9J/E1CZYN8z5gFxva62GzNcPKq X-Received: by 2002:a05:6870:829e:b0:1d6:6430:f743 with SMTP id q30-20020a056870829e00b001d66430f743mr16725425oae.19.1696897633381; Mon, 09 Oct 2023 17:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696897633; cv=none; d=google.com; s=arc-20160816; b=XwIfSZtumgkvWJFFM37pZizAcWlUX169DZ30kSTFl8BRdWynQgD1jWRvLS5Zl1QDWq syE0U/kSRIvP6dBO9VXSpLKg7joCk7ZGvrvizZg7YUKCqBYCsPpHkzeprErzEtiTQSE3 MdKOKiFOAox+P9vHeh6WHvKgg5CVR5M9PpZtJ3qGByYRJfEX0U1C0mn4F/84Nv+3njrm B0HIgewCz8P6hWv8P46EueplX1DTSsjvP+DWKPEbIShiOzvkr0LmM2Z5B01QARCQY6Zm hy0tgGpyCvcu6xq8ycvVb7Yj+XNCf1QPbofu9qsNVJApEoiH9cRIHeSVWRyxXk5Q0i4M KlsQ== 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=oeawgZymjR1McP4t75YvRrkqJDZW25xAyrZ8fBe5iAg=; fh=6r7tsuSNtEA1kc6u9rolnGSwa9O/8zGR77V4wjPW5XA=; b=AQlGjaiZ14k67Mgb2TzFYrnyD611qh33fm6Ef8huDT7RQ6bXf4YfMNmxayekFTvxLD cTsiuy03+gjsUMCHJajPAgHpg0rn7HFJUmvtntna/1sf1AMMqDSSHhkcf3zrxAu/9jbw 0OKlRZSwEF9s4AsFBBYF9Z7/jW0z18kfwbXtfgl4Sp2Ni1gSIHaHWO4pzby9ssDVUXFY RbtMY3O0VYM/CcdzVOl03I/+OZr9dHrgDZtrgSr/PUdZVeI793WRpsbHvjkO492Vqsld Wg4SPLr8WCf2K6+ReGTDTaeNl0K6rp++3hFg8ykajpdzg9APfDmeh2BPX6QMqMMq483c Ei4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="wGyJ/LYp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ct7-20020a056a000f8700b0068fbd15c036si8126473pfb.286.2023.10.09.17.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 17:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="wGyJ/LYp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 59C9F80FC706; Mon, 9 Oct 2023 17:27:12 -0700 (PDT) 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 S1379207AbjJJA1J (ORCPT + 99 others); Mon, 9 Oct 2023 20:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379189AbjJJA1I (ORCPT ); Mon, 9 Oct 2023 20:27:08 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CA89F for ; Mon, 9 Oct 2023 17:27:07 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-27cdde1ee5fso402305a91.1 for ; Mon, 09 Oct 2023 17:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696897626; x=1697502426; 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=oeawgZymjR1McP4t75YvRrkqJDZW25xAyrZ8fBe5iAg=; b=wGyJ/LYpx0JgUoZqXqWI0ut5Ny/EqInfeZqaNaznToVSiLNCMfwMl4fV97cpsnTxx4 FlGVWrpdSHHMN9u8Khhi8CcY2MIu2B5bErhdGdwzi393m7Ck6EbNNZzoS/xrMyV1tdE1 l6fCRjFo7uowkBLQoOJ7q/iEYPh6eayI8LZcIscy+lVbJa6flPiU8FIJxw/sz1JpZfWx LFxYThCULn7fJHJE+Iciso6fQNmROvp0TK+0lvCpfvFmoprukrqP4AcNJYM0GQMmCRHv gT/OeB/p8E1OlCBg5GTLotsqOW7ZHCOF1Exxr22337wl41F7P24KzJ4d8k+mZdatAKCh +itg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696897626; x=1697502426; 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=oeawgZymjR1McP4t75YvRrkqJDZW25xAyrZ8fBe5iAg=; b=xBICWErVeShf2nnaNQSnNLQj/GeHEG4i/dVNJnyXN4mDysLacGnMGhna3KBeySmV4Y Fk6ZASheiqzTUjbUtcokEHSy8skDeaYU69rSCNoIrQaq8JwQ2Bt9tVb/yutzju2KWpYj jyQBC17O2v9Z+x2T6Nzjx4yiR82VNAjuY2HhAqsX/pdcZ0+oqb5HR56mmq8+nloNldbe NBQDWU660F9dBg7jD3T/UX6C1x7e4gADsdJrzlj/tJJAt8E6pYSlmXogAD1b+6W98tOp jBNodYUw9W9b1rR/RoUUrKcf1RhSUoiRokry++BT4HUQwYDuXZWpDZ58E/SHH/1jaJIe RukQ== X-Gm-Message-State: AOJu0Yx5PFGZCCYcRLiYSHIIJn3Y2NlLIlKF/dfUtvpKaXKGsQAjJZHd Lj7kkMdkfWAbUyMv8F2pjQYDJzBgVJw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:1092:b0:274:974b:9b2b with SMTP id gj18-20020a17090b109200b00274974b9b2bmr284236pjb.0.1696897626570; Mon, 09 Oct 2023 17:27:06 -0700 (PDT) Date: Mon, 9 Oct 2023 17:27:04 -0700 In-Reply-To: <20231010000910.GM800259@ZenIV> Mime-Version: 1.0 References: <20230928180651.1525674-1-pbonzini@redhat.com> <169595365500.1386813.6579237770749312873.b4-ty@google.com> <20231009022248.GD800259@ZenIV> <20231009200608.GJ800259@ZenIV> <20231009204037.GK800259@ZenIV> <20231010000910.GM800259@ZenIV> Message-ID: Subject: Re: [PATCH gmem FIXUP] kvm: guestmem: do not use a file system From: Sean Christopherson To: Al Viro Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini 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,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 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, 09 Oct 2023 17:27:12 -0700 (PDT) On Tue, Oct 10, 2023, Al Viro wrote: > On Mon, Oct 09, 2023 at 02:26:36PM -0700, Sean Christopherson wrote: > > On Mon, Oct 09, 2023, Al Viro wrote: > > > On Mon, Oct 09, 2023 at 01:20:06PM -0700, Sean Christopherson wrote: > > > > On Mon, Oct 09, 2023, Al Viro wrote: > > > > > On Mon, Oct 09, 2023 at 07:32:48AM -0700, Sean Christopherson wrote: > > > > > > > > > > > Yeah, we found that out the hard way. Is using the "secure" variant to get a > > > > > > per-file inode a sane approach, or is that abuse that's going to bite us too? > > > > > > > > > > > > /* > > > > > > * 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); > > > > > > > > > > Umm... Is there any chance that your call site will ever be in a module? > > > > > If not, you are probably OK with that variant. > > > > > > > > Yes, this code can be compiled as a module. I assume there issues with the inode > > > > outliving the module? > > > > > > The entire file, actually... If you are using that mechanism in a module, you > > > need to initialize kvm_gmem_fops.owner to THIS_MODULE; AFAICS, you don't have > > > that done. > > > > Ah, that's handled indirectly handled by a chain of refcounted objects. Every > > VM that KVM creates gets a reference to the module, and each guest_memfd instance > > gets a reference to its owning VM. > > Umm... what's the usual call chain leading to final drop of refcount of that > module? If the last reference is effectively held by guest_memfd, it would be: kvm_gmem_release(), a.k.a. file_operations.release() | -> kvm_put_kvm() | -> kvm_destroy_vm() | -> module_put(kvm_chardev_ops.owner);