From patchwork Sat Feb 13 01:23:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12086503 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=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 5F498C433E0 for ; Sat, 13 Feb 2021 01:24:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 114D264DC3 for ; Sat, 13 Feb 2021 01:24:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 114D264DC3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=sOMH/CVc0mjXWT04HV7+UNplCPc8EWimrhkyx3PbWRM=; b=bIiADkujlqFcwX+jHJ1WINsHPf FuFWyDjPniuk4h0LyXAUSpwKsdhaZewJyP2EH78HzFFIAYMWKJQ1ShsH9hRtjg3GKyUoF1via8fUg Jtn/ZZ1vloVxmTplAv0QgH8wNn1LarSkEAU/8pX3Sd88HIJKVcjYXQRP6r1m204f/LL2DKsnjtusl k1N9AdOdmqpHFFa5LvpSyliPOhRrQE8ZPfm5aDOeiPycC/F4tVsk/jYIUYmMu3Dab5GF/QyUQzdB8 5rtsUcLebtjBTyH4bpnO+ScjkIZq/1GckRHOn7mvBVZCBJ3hTi1kzRHxC19s5RpmRDXRlfRBSsBaQ Ma5Z36gw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAjeg-0002As-3y; Sat, 13 Feb 2021 01:23:26 +0000 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAjec-0002A0-8F for linux-arm-kernel@lists.infradead.org; Sat, 13 Feb 2021 01:23:23 +0000 Received: by mail-qk1-x736.google.com with SMTP id t62so1455167qke.7 for ; Fri, 12 Feb 2021 17:23:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=NEklPruRwHnzdB6BiLjyxJgAELcX7pwjnZyGp7KbdM8=; b=KkoSsN4QzI935NbGZf/zZOfNBQn/mXT/6eQ99NSHnNWydOpLe7Odb9OQScSdxH2Ta7 ouKi3esRtSy30M4iHh/c9dMdwz69ar9oaYdruLllzvOssAzoT7kuQuefj/DcfTqzvvYF pa+7Z6Nd5vdDI7RGLRd5ddYThJqGsaWuu0KHq2gqbPByeTjicXkqpThIPeHvlahpp7RE bxkksOtEKwYKcl42jiCfXEH4OAzjUBLzLIdCnMRFWd5B9RiABBpcUiU9ERwNrGYVSkFM KWBgYshwsvH2E9ecjRsBeDbvqNw+91isL4Ik33fkMAlM9c/a7LnAfEsSIWryakMsW7tV iWNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=NEklPruRwHnzdB6BiLjyxJgAELcX7pwjnZyGp7KbdM8=; b=k7GKVU+0wovOjX0m0sVFPp2pTlVZSmKSAMoRv2Mx5rECsMoFyQxrtLzdxWBfihFBeL GWedMI5+wEZoHxZdWtTwliKobmq5JD4oYvC3uvgQkmyYiMJOcS4iqYVAP5rwFSEAlOKg AscDWISySGzESiNuB+X9eGrd7ETMIF0W33fJrZ5sa6i/+AcWY9+3mnmbSpaYnc0lkB/X TF4EcXYA2BVFxzq/3pRUjVQ6sVwjz+UnJFM3SUEV9R+YuUL+BeKGylsxGyIJaXjYt52+ 3QF785vXnxOmCBV89nzxSIk8XqmdsznlAa8QrSLAkP9//UWjA3fgyPLvT83bjJ02O2Em pFRA== X-Gm-Message-State: AOAM532gBdN4vvCHGlQJoupY6srcu6A2SVrsE/LfIldSO14YpwmiBfMc lQ5UrMKao9xx5UIDROkucO0FoA== X-Google-Smtp-Source: ABdhPJyUj/byycWSZvEKqv1kcYlwMXA854ADSxDmK8Ojmk5DFLenn+sXu4Exhn9FyK09WvXJ9tgTXg== X-Received: by 2002:a05:620a:48c:: with SMTP id 12mr5324955qkr.290.1613179398441; Fri, 12 Feb 2021 17:23:18 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id k187sm7477484qkc.74.2021.02.12.17.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 17:23:17 -0800 (PST) From: Pavel Tatashin To: pasha.tatashin@soleen.com, tyhicks@linux.microsoft.com, jmorris@namei.org, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, anshuman.khandual@arm.com, rppt@kernel.org, logang@deltatee.com, ardb@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: mm: correct the start of physical address in linear map Date: Fri, 12 Feb 2021 20:23:16 -0500 Message-Id: <20210213012316.1525419-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_202322_630728_89F396FF X-CRM114-Status: GOOD ( 14.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Memory hotplug may fail on systems with CONFIG_RANDOMIZE_BASE because the linear map range is not checked correctly. The start physical address that linear map covers can be actually at the end of the range because of randmomization. Check that and if so reduce it to 0. This can be verified on QEMU with setting kaslr-seed to ~0ul: memstart_offset_seed = 0xffff START: __pa(_PAGE_OFFSET(vabits_actual)) = ffff9000c0000000 END: __pa(PAGE_END - 1) = 1000bfffffff Signed-off-by: Pavel Tatashin Fixes: 58284a901b42 ("arm64/mm: Validate hotplug range before creating linear mapping") Tested-by: Tyler Hicks --- arch/arm64/mm/mmu.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index ae0c3d023824..6057ecaea897 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1444,14 +1444,25 @@ static void __remove_pgd_mapping(pgd_t *pgdir, unsigned long start, u64 size) static bool inside_linear_region(u64 start, u64 size) { + u64 start_linear_pa = __pa(_PAGE_OFFSET(vabits_actual)); + u64 end_linear_pa = __pa(PAGE_END - 1); + + /* + * Check for a wrap, it is possible because of randomized linear mapping + * the start physical address is actually bigger than the end physical + * address. In this case set start to zero because [0, end_linear_pa] + * range must still be able to cover all addressable physical addresses. + */ + if (start_linear_pa > end_linear_pa) + start_linear_pa = 0; + /* * Linear mapping region is the range [PAGE_OFFSET..(PAGE_END - 1)] * accommodating both its ends but excluding PAGE_END. Max physical * range which can be mapped inside this linear mapping range, must * also be derived from its end points. */ - return start >= __pa(_PAGE_OFFSET(vabits_actual)) && - (start + size - 1) <= __pa(PAGE_END - 1); + return start >= start_linear_pa && (start + size - 1) <= end_linear_pa; } int arch_add_memory(int nid, u64 start, u64 size,