From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C6DDC4338F for ; Tue, 17 Aug 2021 15:01:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FE9760EFF for ; Tue, 17 Aug 2021 15:01:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9FE9760EFF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C13B96B006C; Tue, 17 Aug 2021 11:01:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC4566B0072; Tue, 17 Aug 2021 11:01:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A64C66B0073; Tue, 17 Aug 2021 11:01:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 8A5EC6B006C for ; Tue, 17 Aug 2021 11:01:01 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F09A0184548BF for ; Tue, 17 Aug 2021 15:01:00 +0000 (UTC) X-FDA: 78484885080.11.F0B3A81 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 8FDC44001E89 for ; Tue, 17 Aug 2021 15:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629212460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yGg8Z4A5xf8oGJMYeSLD5P5QfCrx/EVCnSOaaJXq7EU=; b=B6XOq4YuyvfhipDRykN/9sY6QnzZsK4vpJivkTx+5j1+vtJ000USgqryvCgQ3GX32QLVf7 9QSmMbfCej5Q+go9b5yWkp57bFPg1J7DnXy3kGuSjmfiTQFuolIu4aAybiQlTV8FoSknuI iY0IhJzFj4lm7bGgEyZZQUJMaFOasuM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-utOjBvCtPH27phW3hkKNSQ-1; Tue, 17 Aug 2021 11:00:58 -0400 X-MC-Unique: utOjBvCtPH27phW3hkKNSQ-1 Received: by mail-wr1-f70.google.com with SMTP id z10-20020a5d440a0000b0290154e0f00348so6703306wrq.4 for ; Tue, 17 Aug 2021 08:00:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=yGg8Z4A5xf8oGJMYeSLD5P5QfCrx/EVCnSOaaJXq7EU=; b=onPioQMgMheOV8g79f8J9HuEpupU2oAcFalxhjM73ksrHYjBMxO+hMPGzy8mTCpe+Q 8mrjIn6XA/nwW/iFcrODCFVmICNGLvPdQrZaGZGfEoDdLc2nTd5QpkvzUXfAkWovnKBd hn5zaJAtuBukc2IEOMbuSF9+PvoFZZVcdMD1/JE9vduk2xRlrjxIAt+yT+F0qIW8DYIm DVGx2Xtmf8Dyx/imJnPAGu37X5ijGX3N+HBuKN1DM7eHfiw5OyxJUKIlIS1ZdYueZKIl nFNEpXT64jNy5ClJEaFft/l42vZ+o5JJOvEIlhtpsA8n7hL60iNEeCOnofZjwrmnkn25 /IrA== X-Gm-Message-State: AOAM532DhJqCuKAlHC2W0NUx+hR5gzPSp+5cbOZBYxLwJQDP7QW7E2fz a+1ofBt3w9ShHMuIpFOOJ34eBTb42HTyf5Y6am1LdtZocnulAYx52aFYDvcpQeifuvnpw2dLAiZ Iq5ckku2w2wY= X-Received: by 2002:a5d:5646:: with SMTP id j6mr4609614wrw.314.1629212457442; Tue, 17 Aug 2021 08:00:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyejLIxYhCB2E9DeA3krcwwCmu3fprlXT+ZDG/zyn7XM9Sp+8y2K9rvPbf9PtXB3ei0mDoIlA== X-Received: by 2002:a5d:5646:: with SMTP id j6mr4609574wrw.314.1629212457208; Tue, 17 Aug 2021 08:00:57 -0700 (PDT) Received: from [192.168.3.132] (p5b0c65c6.dip0.t-ipconnect.de. [91.12.101.198]) by smtp.gmail.com with ESMTPSA id w14sm2674088wrt.23.2021.08.17.08.00.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Aug 2021 08:00:56 -0700 (PDT) To: Joerg Roedel , Dave Hansen Cc: Andi Kleen , "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" References: <20210810062626.1012-1-kirill.shutemov@linux.intel.com> <20210810062626.1012-2-kirill.shutemov@linux.intel.com> <9748c07c-4e59-89d0-f425-c57f778d1b42@linux.intel.com> <17b6a3a3-bd7d-f57e-8762-96258b16247a@intel.com> <796a4b20-7fa3-3086-efa0-2f728f35ae06@linux.intel.com> <3caf5e73-c104-0057-680c-7851476e67ac@linux.intel.com> <25312492-5d67-e5b0-1a51-b6880f45a550@intel.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 1/5] mm: Add support for unaccepted memory Message-ID: Date: Tue, 17 Aug 2021 17:00:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8FDC44001E89 X-Stat-Signature: z5i9iyoy69uar4iqe5yhn1jwknbhwegr Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B6XOq4Yu; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf18.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1629212460-146684 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 13.08.21 16:49, Joerg Roedel wrote: > Hi Dave, >=20 > On Thu, Aug 12, 2021 at 07:14:20AM -0700, Dave Hansen wrote: >> maybe_accept_page() >> { >> unsigned long huge_pfn =3D page_to_phys(page) / PMD_SIZE; >> >> /* Test the bit before taking any locks: */ >> if (test_bit(huge_pfn, &accepted_bitmap)) >> return; >> >> spin_lock_irq(); >> /* Retest inside the lock: */ >> if (test_bit(huge_pfn, &accepted_bitmap)) >> return; >> tdx_accept_page(page, PMD_SIZE); >> set_bit(huge_pfn, &accepted_bitmap)); >> spin_unlock_irq(); >> } >=20 > Yeah, this could work, but the global lock is likely the show-stopper > here. For SNP we also not allowed to double-validate, so we need > something that basically indicates 'validation-is-ongoing' on a per 2MB > basis. >=20 > I am not an mm expert, but a page flag probably doesn't work. The flag > would be on the head of the 2MB range and when that page is already use= d > somewhere else there is no guarantee that the flag will survive. But > correct me if I am wrong here :) >=20 > The other options I can come up with are not great either: >=20 > 1) using an AVL bit in the direct-mapping PMD of that page. The > page-table would only be walked if the bit in the > accept_bitmap is clear. But I am not sure that all memory > which needs to be validated is in the direct-map. >=20 > 2) Use another page-sized bitmap. If the machine has more than > 64GB of memory the bit index is wrapped around. This > shouldn't be a performance problem at runtime, if this page > is only consulted when the valid bit is clear in the > accept_bitmap. >=20 > MM experts could certainly come up with better ideas :) Not sure if already discussed, but what about making sure that free=20 pages are not a mixture (partially unaccepted, partially accepted). You'd have to expose the pages in that granularity to the buddy=20 (__free_pages_core), indicating the state. You'd have to reject merging=20 pages of differing acceptance state. Accepting a page would then be handled outside of the zone lock,=20 completely controlled by the state. So a page in the buddy would either be completely accepted or completely=20 unaccepted, signaled e.g., by PageOffline(). Consequently, when allocating a 4KiB page, you'd split an unaccepted=20 2MiB page into separate unaccepted pages. You'd grab one of the=20 unaccepted 4KiB pages and accept it before initializing it and handing=20 it out. --=20 Thanks, David / dhildenb