Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8517258rwp; Wed, 19 Jul 2023 10:56:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlEifSiRvdha/5lv0YPZ5K55k/AZ4byyUBasBo9mePNF33i+jOx0lsyFzcSjj/0rNS9qSXXI X-Received: by 2002:a05:6512:368a:b0:4f9:cb8f:3182 with SMTP id d10-20020a056512368a00b004f9cb8f3182mr380369lfs.25.1689789405380; Wed, 19 Jul 2023 10:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689789405; cv=none; d=google.com; s=arc-20160816; b=D1Jk8orh2qvDbSgdEzhtTTTGjYacLmOVHZFDLBGxtXs+dSzqWja2NowlFc0sb7bKw/ /aiipGNDeqJKEkaJAs+lR5kZ6mANXcgSJtGo5vQaQ4XVnkWd0oLf54EkH2wHgsZduHn6 y8VeR5qAVKMbLgS9hLOojdG6BIAURSY+5tE6Ub6UQakhw2MCaFdmaWkp8RTj/in+cHti vcPDef7oA3POyooFfr160ubHJI8T4RxpeQd8RANnEAUD0vcXewVQa3mj+MPmnyFe1xrf 92CcfHXVg9j49YVWpgun4gf8IZk6wDzbmqCsmqRFmJJaTf2DAldG6iUlwx43Rbv0WjjO g+7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=ZrpSlfvy8CWa29HQgq0qreuIOXt/Wldn9lf0s+IQ19g=; fh=EP/1munELxv9yQ3uxxRIBEsjTglAWQSA6DpAIsor/+I=; b=mczZYq0neLtDGwVSHEBwpmsGU1kIKvv8093rObDXcmNIPg98Qnyibwr7laoCakPRqh KdQaZVLtj+6fJP139y1mT0atsjjOdjkpIQpEcd4x3+2BDwT38Js0r7U3XZjTiGRswIYk Bp5qfs20L9zEzju38XKL6kuyoXjGISDJtb3iA08RUGjAqkk41RgDlZW5XmlDsIBTueNk 6YC0TWHjEu2eWOOYXT1CmYnrZlVNY6HWRzUhoUORTHJ8ibAKT4cU5HLQWmdvASyXOUm7 7oQM0RYHCLG5cqwyIh+zjOlsF2/l4b2Xu63dO7g+C/w30+TyZCPcGxf4DuBrfRI/2Rlb 4z8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ArpFLxX4; 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 m8-20020a056402050800b0051dddbd08cdsi3404598edv.356.2023.07.19.10.56.20; Wed, 19 Jul 2023 10:56:45 -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=ArpFLxX4; 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 S230048AbjGSRrt (ORCPT + 99 others); Wed, 19 Jul 2023 13:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbjGSRrr (ORCPT ); Wed, 19 Jul 2023 13:47:47 -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 89B6B1735 for ; Wed, 19 Jul 2023 10:47:44 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-577323ba3d5so16595007b3.0 for ; Wed, 19 Jul 2023 10:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689788864; x=1692380864; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=ZrpSlfvy8CWa29HQgq0qreuIOXt/Wldn9lf0s+IQ19g=; b=ArpFLxX4pd+nE6yhxk4kfQsyY2cBj0283wyB2UFD4pQNpbkrc+ZAbqxw+z+OgClanI 8Bmj2Z7j2c1NhNgCvBdv83cjgOHHCOOMDHYftHtZeAL3vo412/Xbeep/S+CdApdBGNVE aduoGH7mk12lxFjmYh58eVW/1Ksc0OT9NLaSC1w5eMBSYs+0sTNoL7N0w3aZ0n2P+aH0 VnFxLOrHPJ9r2ezOXOfj0cBYblwBN0Ye2w9Cgtba6HWxXo2yyLAo7PNbRfr5GAzKlZhF ic8thdmStV5nJQreXCY0jlMVC8WTwDKkeNH3l7/QHaf5X+Z1Dsac59JBXIEJlOoDRy4l I3Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689788864; x=1692380864; h=content-transfer-encoding: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=ZrpSlfvy8CWa29HQgq0qreuIOXt/Wldn9lf0s+IQ19g=; b=JphcQQbjshPnOPY8ZepU4BJh4ozJA8dO4xegGiSE0j8esfAzeAxaaw4czp10rLkmul Hs8Lq+cVH0jOyzEozY79622MpeCS2CtHqyVxZvBylV1OibQ4cl6nOcZl/Jz+eKM3Pqhy 2CKLXJDgwQlEVEINSizLPw8uv6ZP+noxVtxKvOWoJeA8A8RdSMGV5sppyYYKV+AZHGEp YGlLxyDUXEiyA9Pou8cf9s/19QH3XxPm9zLPOj/VZJjp//XcTGwtsZI0RpMGH2cPg4AU npb3q6lMxrNidGmEXnwVIGh2NWYjgx35KZdTBCRycIP5YJJ1xhs01hbybs+xwnOeT0sM VdDw== X-Gm-Message-State: ABy/qLYJvfGpysx0ZB5PBVqLUu5Z2fJC6hdFxcdmvQ8W+z82GeunpP8t yvAmOq+0nPc+oxs3b/qJi+4EKpU6tn0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:f509:0:b0:ca3:3341:6315 with SMTP id a9-20020a25f509000000b00ca333416315mr42238ybe.0.1689788863726; Wed, 19 Jul 2023 10:47:43 -0700 (PDT) Date: Wed, 19 Jul 2023 10:47:41 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-13-seanjc@google.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: Vishal Annapurve Cc: 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 , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_NONE, 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 Wed, Jul 19, 2023, Vishal Annapurve wrote: > On Tue, Jul 18, 2023 at 4:49=E2=80=AFPM Sean Christopherson wrote: > > ... > > +static int kvm_gmem_error_page(struct address_space *mapping, struct p= age *page) > > +{ > > + struct list_head *gmem_list =3D &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 =3D page->index; > > + end =3D 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 =3D start; gfn < end; gfn++) { > > + if (WARN_ON_ONCE(gfn < slot->base_gfn |= | > > + gfn >=3D slot->base_gfn= + slot->npages)) > > + continue; > > + > > + /* > > + * FIXME: Tell userspace that the *priv= ate* > > + * memory encountered an error. > > + */ > > + send_sig_mceerr(BUS_MCEERR_AR, > > + (void __user *)gfn_to_h= va_memslot(slot, gfn), > > + PAGE_SHIFT, current); >=20 > Does it make sense to replicate what happens with MCE handling on > tmpfs backed guest memory: > 1) Unmap gpa from guest > 2) On the next guest EPT fault, exit to userspace to handle/log the > mce error for the gpa. Hmm, yes, that would be much better. Ah, and kvm_gmem_get_pfn() needs to c= heck folio_test_hwpoison() and potentially PageHWPoison(). E.g. if the folio is= huge, KVM needs to restrict the mapping to order-0 (target page isn't poisoned), = or return KVM_PFN_ERR_HWPOISON (taget page IS poisoned). Alternatively, KVM could punch a hole in kvm_gmem_error_page(), but I don't= think we want to do that because that would prevent forwarding the #MC to the gue= st.