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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 1515BC2D0C8 for ; Tue, 17 Dec 2019 12:39:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CEBAA2146E for ; Tue, 17 Dec 2019 12:39:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NLN8ykOl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CEBAA2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3E2848E005F; Tue, 17 Dec 2019 07:39:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F3748E0040; Tue, 17 Dec 2019 07:39:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 196C48E005F; Tue, 17 Dec 2019 07:39:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id E8FE38E0040 for ; Tue, 17 Dec 2019 07:39:07 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 9CDE4127F for ; Tue, 17 Dec 2019 12:39:07 +0000 (UTC) X-FDA: 76274588334.26.note18_327a06c763e3f X-HE-Tag: note18_327a06c763e3f X-Filterd-Recvd-Size: 4272 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Dec 2019 12:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576586346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B246GLaT3HAQaGu/abosRqj+9QWb/G6+/8B/T9JdjTs=; b=NLN8ykOlKEbDicwTqcCtwyEs3j4UEjoMgDFjWgjx6YEX6OjM6IXmnFMqri3RbSZ/VcA/yT 4AhVam6l1ueyFnC55jYCYomMet43oOcS7mfSey4TLzb7O9azMGYA/rU5sd9gUeXwHwqApl qj9LYK2OmNA0DZLFs2giqc24JHCv6PU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-lTiwSymxNZWStB5eZN8R8g-1; Tue, 17 Dec 2019 07:39:03 -0500 X-MC-Unique: lTiwSymxNZWStB5eZN8R8g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE8DF107ACC5; Tue, 17 Dec 2019 12:39:00 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.36.118.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 538961001281; Tue, 17 Dec 2019 12:38:58 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Andrew Morton , Allison Randal , Anshuman Khandual , Balbir Singh , Rashmica Gupta , linuxppc-dev@lists.ozlabs.org Subject: [PATCH RFC v1 1/3] powerpc/memtrace: Enforce power of 2 for memory buffer size Date: Tue, 17 Dec 2019 13:38:49 +0100 Message-Id: <20191217123851.8854-2-david@redhat.com> In-Reply-To: <20191217123851.8854-1-david@redhat.com> References: <20191217123851.8854-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: The code mentions "Trace memory needs to be aligned to the size", and e.g., round_up() is documented to work on power of 2 only. Also, the whole search is not optimized e.g., for being aligned to memory block size only while allocating multiple memory blocks. Let's just limit to powers of 2 that are at least the size of memory blocks - the granularity we are using for alloc/offline/unplug. Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Andrew Morton Cc: David Hildenbrand Cc: Allison Randal Cc: Anshuman Khandual Cc: Balbir Singh Cc: Rashmica Gupta Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: David Hildenbrand --- arch/powerpc/platforms/powernv/memtrace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/pla= tforms/powernv/memtrace.c index eb2e75dac369..0c4c54d2e3c4 100644 --- a/arch/powerpc/platforms/powernv/memtrace.c +++ b/arch/powerpc/platforms/powernv/memtrace.c @@ -268,15 +268,11 @@ static int memtrace_online(void) =20 static int memtrace_enable_set(void *data, u64 val) { - u64 bytes; - - /* - * Don't attempt to do anything if size isn't aligned to a memory - * block or equal to zero. - */ - bytes =3D memory_block_size_bytes(); - if (val & (bytes - 1)) { - pr_err("Value must be aligned with 0x%llx\n", bytes); + const unsigned long bytes =3D memory_block_size_bytes(); + + if (val && (!is_power_of_2(val) || val < bytes)) { + pr_err("Value must be 0 or a power of 2 (at least 0x%lx)\n", + bytes); return -EINVAL; } =20 --=20 2.23.0