Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1736087rwl; Wed, 12 Apr 2023 18:14:13 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+E1Gi1emOP9zfdFlZBetz9a6T23tuxN882dsc2yalfmkX6rS3fafP65oZvMhmglPH5/3q X-Received: by 2002:a17:906:1650:b0:94c:4dc1:8c0a with SMTP id n16-20020a170906165000b0094c4dc18c0amr843079ejd.32.1681348453309; Wed, 12 Apr 2023 18:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681348453; cv=none; d=google.com; s=arc-20160816; b=TBhh8HRyG1mJGbeyoMqUfa9hZJiOcBXIJ52YBAJmPJXzmNU44WdlFtZdqOrUDHAJV9 zoUbb9U0JU36GUv1gJVMZnfYuB28AXfUyXknKQ4hWDcaayujNc7B6UIJL4LRUCuS226z SZOl+j0HeVYo8GbXecntP7umueGZjAiSkt7loUEvZvjURxRl/nP3Pn0mYK2scg+t0Upz owC+vsw4PxuGoCTqaDhJZidwtpi7P48J3bB1jAuFmNEEe+W01qEdjNFSHeQaBQzPnzkP yTOuSKdUwOyrX/Djw1CzXs0ebZkogckmXfm0loMiWfrsJ4O/rfRALP3gmfgykNz4ga+S iLVw== 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=EBLbhNm3fsRbkajEjRmINqzacPrnC3sWkejBQFnfCeY=; b=tUVtP9R3GiaSGZZ/V33ZlrZh0WTWBaH+IKTnJLfLnlQqEBZVRzQQ9xD1Qul6xOR4T6 lyZ/a7SZhgvD3qxtVKzDtvRFw6V+q+0LMIoj8iBxOstdS52uMZAmoXyGp7z5hhDtmb5G hOerCIN10N2M4+06WHOlffkzd1LdmEe/Fw/As8XlDeigypOj0FSDkJx7gTmWMcj0TFJS XRGfmrW/QSQ+Jn/vCj9NPmF6CdMVWhSqcRM4m/3gqcHPMUzmC7I7vi0a+hSxUe+nhFe0 SIk8cHJy8bwL6PibfyYI0njIT0WimM+MWsy0mv2Jthm0R+79U04PoOR6DudfdKHa5iBl r60w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="l81F5p/z"; 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 ew19-20020a170907951300b0094e54dc993csi358852ejc.457.2023.04.12.18.13.48; Wed, 12 Apr 2023 18:14:13 -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="l81F5p/z"; 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 S229803AbjDMBHe (ORCPT + 99 others); Wed, 12 Apr 2023 21:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjDMBHc (ORCPT ); Wed, 12 Apr 2023 21:07:32 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E6C61AB for ; Wed, 12 Apr 2023 18:07:31 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id ki6-20020a170903068600b001a684425451so230398plb.15 for ; Wed, 12 Apr 2023 18:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681348050; x=1683940050; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EBLbhNm3fsRbkajEjRmINqzacPrnC3sWkejBQFnfCeY=; b=l81F5p/zxISuNsOTdPBgLBjqThC2vDQDK5Uw+271tLolnlAHCMjlZe8AeG/jf3nOrx ExWxIQK7CKtblDvJ8H3VSzPnmPuqB/YeLXauyGbc5MYvJjSXVvNUPEsSQLuxsR77moKZ UlTepofDb02LxLShDY5FjB4dpGfEQe3unZKqgtyJNvz/0ht5ta0+OYjQykpOh/ft4xiY iCpoKLuH+PMrGysZjyKXtcxmXgl9ury1l15XbUM9kGssTvMz69Uh47nolIPDiQg/ZLYy kWyCbb4PMZcJ8WgWH7QKSQOInzUxQhQDlNJXdkLhsMb661/+oYSUbCYk/vgAZ5pUqK7f uA9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681348050; x=1683940050; 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=EBLbhNm3fsRbkajEjRmINqzacPrnC3sWkejBQFnfCeY=; b=NmFiTfzpJGf8HTt1z/uEN5jXNlH0lr9ZKYMf2OfP7hekGXDdaoX5oaVp1VsgyHml5L ycnq4lfzy8sysB2dSbzZTyeikq7vLKi/lP8+ZKHDpVXeIWmFVSQvlYz8CRbHOU+11YkZ BtKWzU4LsD3WmkCuMwaDbcnv4tVseqXbfkJ23l9qXo9F48DhPpL6Zx2YJBXVJsHMYJlO 2WwVLEqF6H6DivdLGG6me/dugW4xYl7y3zCcHFet/h7hlUnsaeKwWw19lDi7ZKclw+Oa 2hZ8FIxdVb8P9ziVTLWw5gO84t5gE6T2/sHRYrXVJCDKNAvS/tcAxqhk+VsD9NmvkUt/ EN4A== X-Gm-Message-State: AAQBX9cTmnI+pr/GRR7N9X+AztHSKk68m+8QtXU0qQMMkq2m9g4aaf2b 4lmMNdIpo/53foaKEU14CWa/8P2lCtU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d413:b0:19a:7f9c:66e3 with SMTP id b19-20020a170902d41300b0019a7f9c66e3mr13167ple.5.1681348050454; Wed, 12 Apr 2023 18:07:30 -0700 (PDT) Date: Wed, 12 Apr 2023 18:07:28 -0700 In-Reply-To: <20230125125321.yvsivupbbaqkb7a5@box.shutemov.name> Mime-Version: 1.0 References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <48953bf2-cee9-f818-dc50-5fb5b9b410bf@oracle.com> <20230125125321.yvsivupbbaqkb7a5@box.shutemov.name> Message-ID: Subject: Re: [PATCH v10 0/9] KVM: mm: fd-based approach for supporting KVM From: Sean Christopherson To: "Kirill A. Shutemov" Cc: Liam Merwick , Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , tabba@google.com, Michael Roth , mhocko@suse.com, wei.w.wang@intel.com 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_NONE, 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 On Wed, Jan 25, 2023, Kirill A. Shutemov wrote: > On Wed, Jan 25, 2023 at 12:20:26AM +0000, Sean Christopherson wrote: > > On Tue, Jan 24, 2023, Liam Merwick wrote: > > > On 14/01/2023 00:37, Sean Christopherson wrote: > > > > On Fri, Dec 02, 2022, Chao Peng wrote: > > > > > This patch series implements KVM guest private memory for confidential > > > > > computing scenarios like Intel TDX[1]. If a TDX host accesses > > > > > TDX-protected guest memory, machine check can happen which can further > > > > > crash the running host system, this is terrible for multi-tenant > > > > > configurations. The host accesses include those from KVM userspace like > > > > > QEMU. This series addresses KVM userspace induced crash by introducing > > > > > new mm and KVM interfaces so KVM userspace can still manage guest memory > > > > > via a fd-based approach, but it can never access the guest memory > > > > > content. > > > > > > > > > > The patch series touches both core mm and KVM code. I appreciate > > > > > Andrew/Hugh and Paolo/Sean can review and pick these patches. Any other > > > > > reviews are always welcome. > > > > > - 01: mm change, target for mm tree > > > > > - 02-09: KVM change, target for KVM tree > > > > > > > > A version with all of my feedback, plus reworked versions of Vishal's selftest, > > > > is available here: > > > > > > > > git@github.com:sean-jc/linux.git x86/upm_base_support > > > > > > > > It compiles and passes the selftest, but it's otherwise barely tested. There are > > > > a few todos (2 I think?) and many of the commits need changelogs, i.e. it's still > > > > a WIP. > > > > > > > > > > When running LTP (https://github.com/linux-test-project/ltp) on the v10 > > > bits (and also with Sean's branch above) I encounter the following NULL > > > pointer dereference with testcases/kernel/syscalls/madvise/madvise01 > > > (100% reproducible). > > > > > > It appears that in restrictedmem_error_page() > > > inode->i_mapping->private_data is NULL in the > > > list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) but I > > > don't know why. > > > > Kirill, can you take a look? Or pass the buck to someone who can? :-) > > The patch below should help. > > diff --git a/mm/restrictedmem.c b/mm/restrictedmem.c > index 15c52301eeb9..39ada985c7c0 100644 > --- a/mm/restrictedmem.c > +++ b/mm/restrictedmem.c > @@ -307,14 +307,29 @@ void restrictedmem_error_page(struct page *page, struct address_space *mapping) > > spin_lock(&sb->s_inode_list_lock); > list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) { > - struct restrictedmem *rm = inode->i_mapping->private_data; > struct restrictedmem_notifier *notifier; > - struct file *memfd = rm->memfd; > + struct restrictedmem *rm; > unsigned long index; > + struct file *memfd; > > - if (memfd->f_mapping != mapping) > + if (atomic_read(&inode->i_count)) Kirill, should this be if (!atomic_read(&inode->i_count)) continue; i.e. skip unreferenced inodes, not skip referenced inodes?