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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2B59C433EF for ; Fri, 6 May 2022 16:12:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FE066B0072; Fri, 6 May 2022 12:12:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 787E86B0073; Fri, 6 May 2022 12:12:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FF9D6B0074; Fri, 6 May 2022 12:12:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4AED26B0072 for ; Fri, 6 May 2022 12:12:16 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 00D6661A99 for ; Fri, 6 May 2022 16:12:15 +0000 (UTC) X-FDA: 79435810272.31.D754E1A Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 7AC7D8002B for ; Fri, 6 May 2022 16:12:09 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id s27so9829026ljd.2 for ; Fri, 06 May 2022 09:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3LVCF+EC61p3SRHqy5+HBfYg8g8sBVA6E2RSjLMm3ic=; b=71gELqa8e3JZdAR40f88qYRAendRWwJy32RDkq6jbbgAR1oFpqUnUAh7JDtx9eVM4b hXnwylvyfzfwO1l5pR5a8tj6McjLg1BgMlPCXYajEuS9KSDUdhDD4IEadqjiXDqkc5MN jgRnaEFuE4vFyEl8fmIM9iQXW9RSsk/YvT+UGEyx56ucVrRD6B9KQ/k3MQeUHryYIjuD 6HSmA9SD2cmqfM/Rtv+U/n0Ew972cSEgHdE7tNtlrRWpD4u3DVdtKECy53If23SgbnzR xej7+9vB9kXXhnte6xgRsD1WPNIKMmy+MI5P0vF2w3FABpNop43zQpwmMAvrts8IUo6u Ay6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3LVCF+EC61p3SRHqy5+HBfYg8g8sBVA6E2RSjLMm3ic=; b=wIcy49MtM5Ow0NjvtiDMSa5qQWf8Zwg5gsTijs6cNam5WKNco2e8KC4r1U/wDVeVVq DJknJvzqS1tF75dOdR08+Qvm8psvlGEBd0PFgJXGtlWABcNYWooS4maOyECEx+ej+UoK XyoXKTTDVzdCJUy2NOkwtKRj4KlZtuB/+GWLST4mpCZ7VarbYpzrzmMjmZc/3pWo0r0k tyOu0E4wPA8EwLHaUJUFKkSm5Q7Xlpo1b0WlOlypJwmAj4HCb9Q1qrhykq4QlGAX+F0I f9sp5LMUvnIGJIkdWX8WmvmL8ovpHfswfWCxwyzNEzChabs34eUUPzqHsyJbicskVAkj 8g3w== X-Gm-Message-State: AOAM533/IMCBqJheFyGL4XUiFSzOyCbWaAMks5kCaYmgW2++ke5XiKqR H68/mhbutVwT0otE4Cn1VzF+oA== X-Google-Smtp-Source: ABdhPJxcoFt3N3AtHGRW62qNedg2H/hvHQ56BxLep0ct05gnPOlLMPFLw3EGV7t5IJpESnjqgxaHQQ== X-Received: by 2002:a2e:b6c6:0:b0:24f:3919:5923 with SMTP id m6-20020a2eb6c6000000b0024f39195923mr2365023ljo.398.1651853533664; Fri, 06 May 2022 09:12:13 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id v17-20020a2e9611000000b0024f3d1daed9sm680999ljh.97.2022.05.06.09.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 09:12:13 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 27825104AFD; Fri, 6 May 2022 19:13:59 +0300 (+03) Date: Fri, 6 May 2022 19:13:59 +0300 From: "Kirill A. Shutemov" To: Borislav Petkov Cc: "Kirill A. Shutemov" , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Brijesh Singh , Mike Rapoport , David Hildenbrand , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv5 08/12] x86/mm: Provide helpers for unaccepted memory Message-ID: <20220506161359.4j5j5fxrw53fdbyr@box.shutemov.name> References: <20220425033934.68551-1-kirill.shutemov@linux.intel.com> <20220425033934.68551-9-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7AC7D8002B X-Stat-Signature: d8htokum3ffgqbtaw7db5crcuiinsjcr X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=71gELqa8; spf=none (imf02.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.208.172) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-HE-Tag: 1651853529-746838 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 Wed, May 04, 2022 at 01:12:06PM +0200, Borislav Petkov wrote: > On Mon, Apr 25, 2022 at 06:39:30AM +0300, Kirill A. Shutemov wrote: > > + unaccepted_memory = __va(boot_params.unaccepted_memory); > > + range_start = start / PMD_SIZE; > > + > > + spin_lock_irqsave(&unaccepted_memory_lock, flags); > > + for_each_set_bitrange_from(range_start, range_end, unaccepted_memory, > > + DIV_ROUND_UP(end, PMD_SIZE)) { > > + unsigned long len = range_end - range_start; > > + > > + /* Platform-specific memory-acceptance call goes here */ > > + panic("Cannot accept memory"); > > Yeah, no, WARN_ON_ONCE() pls. Failure to accept the memory is fatal. Why pretend it is not? For TDX it will result in a crash on the first access. Prolonging the suffering just make it harder to understand what happened. > > + unsigned long flags; > > + bool ret = false; > > + > > + spin_lock_irqsave(&unaccepted_memory_lock, flags); > > + while (start < end) { > > + if (test_bit(start / PMD_SIZE, unaccepted_memory)) { > > + ret = true; > > Wait, what? > > That thing is lying: it'll return true for *some* PMD which is accepted > but not the whole range of [start, end]. That's true. Note also that the check is inherently racy. Other CPU can get the range or subrange accepted just after spin_unlock(). The check indicates that accept_memory() has to be called on the range before first access. Do you have problem with a name? Maybe has_unaccepted_memory()? -- Kirill A. Shutemov