Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp505891rwo; Fri, 21 Jul 2023 16:02:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGCCEpk6/JOh8PAq7r+/J7xDgCZ1cVt6LM/povE6Vyc1IpbTzxxmO8GlvjcIM9j0QFnpQjD X-Received: by 2002:aa7:c385:0:b0:51d:9110:4b11 with SMTP id k5-20020aa7c385000000b0051d91104b11mr2600097edq.12.1689980520582; Fri, 21 Jul 2023 16:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689980520; cv=none; d=google.com; s=arc-20160816; b=kckAChu8xcjqRmMxNhD3tLpb4yXL8O8lAhWVnJf0aksHKXzWQT9rxseKRszU3S/cDq RHf8Mj2rHXcHPTihVt5PsCjv4KJG9wUoRFrFStHxqUX0EqZxo5pD0wJTKjm8y9b9aUgr DAfwQ0iVTYS6Ec4sJfQV/CrHVBk2N/LptYqcO92bj9lnoTe8E4JtAFJhuHg8uzVip8fJ EGkp6/bzG9RHDeHL6wPUddPz3KPNfIGzWv7r+klWGRSmqR8gjBA2MZJCKm7EEQ3U5Wzt DnHKUcPJM9a16iZBNe6oJTLfTmDYEXA97IyCA2M1bnORtJjlimMJ4676RCJhPGMwYhkC R5aw== 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=7T9EVRBobAr4a8JPgfiIjIX72kF/VyhERBKOIDOEvTo=; fh=p/kildOQIemnNt3RNPuRRv2OSAlpqz/uQBqDbn6calQ=; b=GoynghV3oZn5M7P4fNEyUotLOsMjscMyJuwenQHk9zkYFk1fBcXbQzg23SmsUrlVOf cyzo9A7EmFhY1/XofvZHBcVbfrW8j5UlnCqWE0/G9/ob6PS4IDO48UQddobBA0AJT6jn aZoElUQ8wSngnI7G8sU5Srt0KGt9CCk4SAuQCBrtyDw0nKcdGfyV99OPntm36OXuhN+2 N0k/iLPRU0xv9cBYeLTQM+Pm/MH2dGGGzKEWJ+UNGrAtWRVIPXT0Q9JlfHFbozzBTt9n +4PyBCw1JKJfxN2CivfbgrKThbLmJBSCD85rzNPiXefULIlvupU94OXeT8unUkOg25RC +/xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=N3JmIIRF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020aa7de14000000b0051ff124da4dsi3029391edv.513.2023.07.21.16.01.34; Fri, 21 Jul 2023 16:02:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=N3JmIIRF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbjGUWdV (ORCPT + 99 others); Fri, 21 Jul 2023 18:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjGUWdT (ORCPT ); Fri, 21 Jul 2023 18:33:19 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E28D3359F for ; Fri, 21 Jul 2023 15:33:17 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58398367e4eso10358407b3.0 for ; Fri, 21 Jul 2023 15:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689978797; x=1690583597; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7T9EVRBobAr4a8JPgfiIjIX72kF/VyhERBKOIDOEvTo=; b=N3JmIIRFuucWrTRji2j76NW5FMl4jS4wLA3POQW0VLRrR4sFhmKgj7pRUj3gSs0yqe WZvjiVqpyglaAnq94LWefXiOIlgXr/PrbktD6W+TBAFf6s+alvi+gxgQyH8TNpVAsODx OCRkSmym8Xr89af+taUXT0Vhz6Xh0SqYzK++E+LxDlItaWIfk/xiv3hy/q9bOsyCLBei XOyxBMd+5ThifDUK6/o5f+QTqfW/eyfYM90Y+kU5f1e/gaMgZLzn2OVn9bd0Flf7Aat3 ovp2GWeXuTu2BrzRvrwJog7aZBAUD7Ob8wE6NUPaB8bQmPi6OopUS5w2j6M71SZpRLW7 K0fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689978797; x=1690583597; 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=7T9EVRBobAr4a8JPgfiIjIX72kF/VyhERBKOIDOEvTo=; b=fJqNAYkNVHhnXJKTIPsiH8XuM3VQ1z9BfrEL+QF3c5yaBcptveL4Q6gd7wuV0z5Q/A wkriGZoHCUZ7oTcimqcZFnPo4sxHtCKCgRkLVLiXHc/e0fcMeE2lbJx8hk8/HyMFA5tP EiB9LW59wIaSvTqQR31HqpJOnRhkmBjDeNNzsDc9us43ouZJRZi+z1Gg1BsfCoJWTC+4 /ijL+h74GzFitxvo7LMM4GHJWvkHKfayOJqmBTpTuBgBHY1KYw+21L0276EkhHY+4UWn pSp6T1kQWZ3o2dBxm8uOR3zE0mgQfOOewO0jp7DpEboOsD9m/VTqI3oKye67K4YszWpV x1Gw== X-Gm-Message-State: ABy/qLZLKxIWXZ7oCvHuc0EvmiiSDSuXGDvChe/riJpYo1Ojl/JROVFS JUTtntcCH5szYnj05aESrY2SSrGTnlQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:ce82:0:b0:d04:faa6:e62b with SMTP id x124-20020a25ce82000000b00d04faa6e62bmr11683ybe.6.1689978797172; Fri, 21 Jul 2023 15:33:17 -0700 (PDT) Date: Fri, 21 Jul 2023 15:33:15 -0700 In-Reply-To: <20230721222704.GJ25699@ls.amr.corp.intel.com> Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-13-seanjc@google.com> <20230721061314.3ls6stdawz53drv3@yy-desk-7060> <20230721222704.GJ25699@ls.amr.corp.intel.com> Message-ID: Subject: Re: [RFC PATCH v11 12/29] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory From: Sean Christopherson To: Isaku Yamahata Cc: Yuan Yao , 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@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-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , "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 On Fri, Jul 21, 2023, Isaku Yamahata wrote: > On Fri, Jul 21, 2023 at 02:13:14PM +0800, > Yuan Yao wrote: > > > +static int kvm_gmem_error_page(struct address_space *mapping, struct page *page) > > > +{ > > > + struct list_head *gmem_list = &mapping->private_list; > > > + struct kvm_memory_slot *slot; > > > + struct kvm_gmem *gmem; > > > + unsigned long index; > > > + pgoff_t start, end; > > > + gfn_t gfn; > > > + > > > + filemap_invalidate_lock_shared(mapping); > > > + > > > + start = page->index; > > > + end = start + thp_nr_pages(page); > > > + > > > + list_for_each_entry(gmem, gmem_list, entry) { > > > + xa_for_each_range(&gmem->bindings, index, slot, start, end - 1) { > > > + for (gfn = start; gfn < end; gfn++) { > > > > Why the start end range used as gfn here ? Math is hard? I almost always mess up these types of things, and then catch my bugs via tests. But I don't have tests for this particular flow... Which reminds me, we need tests for this :-) Hopefully error injection provides most of what we need? > > the page->index is offset of inode's page cache mapping and > > gmem address space, IIUC, gfn calculation should follow same > > way as kvm_gmem_invalidate_begin(). > > Also instead of sending signal multiple times, we can utilize lsb argument. As Vishal pointed out, this code shouldn't be sending signals in the first place.