Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1682407iob; Thu, 5 May 2022 06:25:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5JtgOe/N+JUSGWxXduB1+nGampVh1gPGyrXDaMWoGgbTbv10nXvD1CZktsEFctB5jR2/q X-Received: by 2002:a65:62c3:0:b0:3c6:12b1:1177 with SMTP id m3-20020a6562c3000000b003c612b11177mr2999678pgv.597.1651757122626; Thu, 05 May 2022 06:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651757122; cv=none; d=google.com; s=arc-20160816; b=ffkj7dsMX7GpDfcS5E0xniL3sFrZ28jHk+sAaxTWinhCUtvrStU4Y1zmCobatRb2gm yuuRiZWhNNjiiK9gjRoktE1aOM9d4twGqbfetyVBa8j5IL/dQ8ql0ZuzuZYFZkKyfURa 8l+vsjEeTkJxJT4mRkJYhVwdGvYcKkzb/C5FPdQvrfRulb+YxrBfeUk+h62qTbxK/bDl /yLqnc3fwIQrknzmTs7rHIbcTCYIga+T3SlbYjB8QVKvZ2G40JX9VVRZlTKc7gVjQ+Ue 6SKFhn11CXFZFMbkEgE/LphW4zxw0yz+/4XxZ+eXZFqsWfsRkRRcDTpoQEbzA+uCqN8Z pWiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kUk21YBmxyczXtFGcC5AK2mHVk/xapqtm88uS9NvDyY=; b=Wev6FZvs9AFPAhV2KiEy4zzeoZeSvcA7tyZHBCcRyLMYVb9DokN+hI5LV/YK9PTQym GclSK6GXsp3ZBGAkjRr3anHDCrr1mfrYk5CgupVDotFdnD+URzRYXidpTwcLuCR1vCol JqVZCaqUtEDRTuh06QE2o0ENYFZ5q17JPxpnWS9dZtM/XXoxlEYT61+h1ZJTzrlmB4yr 6o73mETmGJO3fvlSPMdFuU7I2UWDFbc9F//4LKhOKun2S3GibZOpjhy14c1aVjFT5GeL TbzInxSfDB7YlTRsG5MoA6Qhe7TxduU+iJjWgakOtNmI4k5T9SRzWhesNOmxG5B+ttpz PnGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=p2B1tkQW; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g31-20020a63565f000000b00398a0c97c69si1628197pgm.751.2022.05.05.06.25.05; Thu, 05 May 2022 06:25:22 -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=@alien8.de header.s=dkim header.b=p2B1tkQW; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348564AbiEDLPq (ORCPT + 99 others); Wed, 4 May 2022 07:15:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234023AbiEDLPo (ORCPT ); Wed, 4 May 2022 07:15:44 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8173A140CE; Wed, 4 May 2022 04:12:09 -0700 (PDT) Received: from zn.tnic (p5de8eeb4.dip0.t-ipconnect.de [93.232.238.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id EBAD81EC03AD; Wed, 4 May 2022 13:12:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1651662724; 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:in-reply-to:in-reply-to: references:references; bh=kUk21YBmxyczXtFGcC5AK2mHVk/xapqtm88uS9NvDyY=; b=p2B1tkQWwDlCdHp7NKG1T7/gTleL6yeWMd01DSIhaI10qDOd6aaT1LwQDM63Rjx0kSnRQ0 a5faOD4YbYR6hkbqoDdUzlx9bPjZzpYjqLUECnyB7huVXTuRW2EgvXRJ0U/M+zjSHWgyNY 9s8Fy4ymLhX99fwnLdC/F7cY2Y9CtMU= Date: Wed, 4 May 2022 13:12:06 +0200 From: Borislav Petkov To: "Kirill A. Shutemov" Cc: 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: 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=utf-8 Content-Disposition: inline In-Reply-To: <20220425033934.68551-9-kirill.shutemov@linux.intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Mon, Apr 25, 2022 at 06:39:30AM +0300, Kirill A. Shutemov wrote: > +/* Protects unaccepted memory bitmap */ > +static DEFINE_SPINLOCK(unaccepted_memory_lock); > + > +void accept_memory(phys_addr_t start, phys_addr_t end) > +{ > + unsigned long *unaccepted_memory; shorten that name. > + unsigned long flags; > + unsigned long range_start, range_end; The tip-tree preferred ordering of variable declarations at the beginning of a function is reverse fir tree order:: struct long_struct_name *descriptive_name; unsigned long foo, bar; unsigned int tmp; int ret; The above is faster to parse than the reverse ordering:: int ret; unsigned int tmp; unsigned long foo, bar; struct long_struct_name *descriptive_name; And even more so than random ordering:: unsigned long foo, bar; int ret; struct long_struct_name *descriptive_name; unsigned int tmp; > + > + if (!boot_params.unaccepted_memory) > + return; > + > + 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. > + bitmap_clear(unaccepted_memory, range_start, len); > + } > + spin_unlock_irqrestore(&unaccepted_memory_lock, flags); > +} > + > +bool memory_is_unaccepted(phys_addr_t start, phys_addr_t end) > +{ > + unsigned long *unaccepted_memory = __va(boot_params.unaccepted_memory); As above, shorten that one. > + 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]. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette