From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0B627F for ; Fri, 6 May 2022 16:12:15 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id 4so9808030ljw.11 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=VN5is8Q3kN8jBk/q8F3HBtNlfuqIoxsKrbVLW/sOVOW5FvXxRfneVRsx2ppARoA12k 9DBmKjn+qFsiCcvvSGuWCBiUX4GWPz03St1zudJuzbK3KN6aNVB7g+i1l/fgFK/wrFHt +r91z08AAi3IX/cP6x5SM1cYwUkWxstT8/1EMDYTs7xhsnP36VLPPH1kF/6MqOE3pRdd Ql/5fEoaq9xhK5VJrvlFhkwJaEQRPFdKpwWAgV9knTENzrIlMaagnxTPNDZz26st6rhw 2gAVdyU8fklGJbicsHavQ03n9cEY75Octx/YtpLxgDMgBsgiVFzz4Zu30nZ2JHovIwBG /0fw== X-Gm-Message-State: AOAM531wPvqsrRCPZikNGcY6pUHwHXescvpWr767TJOevikx/wcAsgQh yQpuosnENtCRV7jtMam6svA+8Q== 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> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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