From patchwork Tue Nov 15 22:26:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 20613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2970922wru; Tue, 15 Nov 2022 14:27:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zhtMb89V3Z7LH4NXeegMhVCFOPs7me+G+2A/iBqRKhV7b58I0+0WnjwzcGvZawbsMfSnr X-Received: by 2002:a05:6402:2c8:b0:461:1f4c:36d0 with SMTP id b8-20020a05640202c800b004611f4c36d0mr16286890edx.310.1668551262459; Tue, 15 Nov 2022 14:27:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668551262; cv=none; d=google.com; s=arc-20160816; b=gA6sDP0DXQWOIq6tYYBdSIQEepVjNZEn6gQj8Lnn0gE+url6crASQVxJAWYbwiU/fW wfOp9XD1yEd7JyAUIYqx+u6prS5NXSHHz5hzRmQnthgqs7sqN6o0jzzREbw2ADKJ1sqU 6+ZguPqBxUdyF82/r5FnqHVGI6ZiFOllRiWrHFVLAf4i4KzoTaYWRksl0JbFr18gMtyU 8Ku9OS1J/gkCGRKe4YmMyBk3uO+dRYYvmVmhGqU01ZDm3d5M8+5U6xNoOiWI/M6v7fdC Q0RyUGJiaXqHghIgpuV6YzCsyvkg4VNhSfhE4syYt5GexgQ31DroGa5w6LNM00XKkIfX QEyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=hP2IakV95smq3JPeATW9iAUtNeeOUIlhOeZqgdEDGTA=; b=TpxJiv5coer67L7dyKbGNNW8nOiuYvoFz2nG0H7e+3aQzPyt8Gqt7Zn/Lp1ubYUBBz LqlKggShO8I/NdtuNia+xnRm7m4FhYBFGG+jqKcaWRDJhM2LvBeusn6vX0THrKOSvq7R AckLAJXNZT2ngXaZrLP+whA2lgdIQE2D3NvshrDMw3P6vzX/Fr6UDdBr2MOhu0W2mwBJ RuTAzzcU/sCW0A5MrDGGi8Rdm5K8GpznlQZLBD+tvXwiNBTIypX81plB5URWfxkCFHtu HlhTjpBKaR6eaQUMB9F06drRtv7gql7ZOoxnFcJolGYAQ2VdinlwrUw356HemamIBNpx s2mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qUBlioG2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=5FJj9J9t; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du22-20020a17090772d600b007aeff3b0b17si7635536ejc.674.2022.11.15.14.27.19; Tue, 15 Nov 2022 14:27:42 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=qUBlioG2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=5FJj9J9t; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbiKOW04 (ORCPT + 99 others); Tue, 15 Nov 2022 17:26:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbiKOW0h (ORCPT ); Tue, 15 Nov 2022 17:26:37 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58A8F31215; Tue, 15 Nov 2022 14:26:24 -0800 (PST) Date: Tue, 15 Nov 2022 22:26:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668551182; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hP2IakV95smq3JPeATW9iAUtNeeOUIlhOeZqgdEDGTA=; b=qUBlioG2P0onn6518ODPwedW2WWKAxAzwGEr9mD1eM4NO43ExrN6QgWITZrTR+bJMjny+6 sLSSzImy5iZWT6g/BvDqZrfAo3h4Lqpj+Nmr4SmRAuZ3xVSXkg6khv48wrrPEfock7Elt4 GBs/2d/LzQKpLaji9k/C/YeeoyJq/e9IawS5InH5xUrrlj3BrfG4pSlV9hsMiDAEZjBMC4 BZ/dgaMK2N8Dr+wEztQEGjeVuK/cDLmw84NgdcaevizC513oQNwuLqqZArlCVPcdC3BhMC IXGxeWTUjfqozvUi4e6Vk9rW6n7h9JbO7iXt3xCzGqHbSvnseyUex6r95oL20A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668551182; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hP2IakV95smq3JPeATW9iAUtNeeOUIlhOeZqgdEDGTA=; b=5FJj9J9tV77SjTqEfSj6SACKgbS45t0TsIPffEQ6oMgwSpDaIaHuFWiMCB9oe/Zahed4kL PatKeoDRyo8qPDBg== From: "tip-bot2 for Sean Christopherson" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/kasan: Add helpers to align shadow addresses up and down Cc: Sean Christopherson , "Peter Zijlstra (Intel)" , Andrey Ryabinin , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221110203504.1985010-5-seanjc@google.com> References: <20221110203504.1985010-5-seanjc@google.com> MIME-Version: 1.0 Message-ID: <166855118092.4906.5811594861632748902.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749143151432589867?= X-GMAIL-MSGID: =?utf-8?q?1749602808553105403?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: 74b5a69c2a577d4fdba581171e3ebf33cddbddc1 Gitweb: https://git.kernel.org/tip/74b5a69c2a577d4fdba581171e3ebf33cddbddc1 Author: Sean Christopherson AuthorDate: Thu, 10 Nov 2022 20:35:03 Committer: Peter Zijlstra CommitterDate: Tue, 15 Nov 2022 22:29:59 +01:00 x86/kasan: Add helpers to align shadow addresses up and down Add helpers to dedup code for aligning shadow address up/down to page boundaries when translating an address to its shadow. No functional change intended. Signed-off-by: Sean Christopherson Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andrey Ryabinin Link: https://lkml.kernel.org/r/20221110203504.1985010-5-seanjc@google.com --- arch/x86/mm/kasan_init_64.c | 40 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c index ad7872a..afc5e12 100644 --- a/arch/x86/mm/kasan_init_64.c +++ b/arch/x86/mm/kasan_init_64.c @@ -316,22 +316,33 @@ void __init kasan_early_init(void) kasan_map_early_shadow(init_top_pgt); } +static unsigned long kasan_mem_to_shadow_align_down(unsigned long va) +{ + unsigned long shadow = (unsigned long)kasan_mem_to_shadow((void *)va); + + return round_down(shadow, PAGE_SIZE); +} + +static unsigned long kasan_mem_to_shadow_align_up(unsigned long va) +{ + unsigned long shadow = (unsigned long)kasan_mem_to_shadow((void *)va); + + return round_up(shadow, PAGE_SIZE); +} + void __init kasan_populate_shadow_for_vaddr(void *va, size_t size, int nid) { unsigned long shadow_start, shadow_end; - shadow_start = (unsigned long)kasan_mem_to_shadow(va); - shadow_start = round_down(shadow_start, PAGE_SIZE); - shadow_end = (unsigned long)kasan_mem_to_shadow(va + size); - shadow_end = round_up(shadow_end, PAGE_SIZE); - + shadow_start = kasan_mem_to_shadow_align_down((unsigned long)va); + shadow_end = kasan_mem_to_shadow_align_up((unsigned long)va + size); kasan_populate_shadow(shadow_start, shadow_end, nid); } void __init kasan_init(void) { + unsigned long shadow_cea_begin, shadow_cea_end; int i; - void *shadow_cea_begin, *shadow_cea_end; memcpy(early_top_pgt, init_top_pgt, sizeof(early_top_pgt)); @@ -372,16 +383,9 @@ void __init kasan_init(void) map_range(&pfn_mapped[i]); } - shadow_cea_begin = (void *)CPU_ENTRY_AREA_BASE; - shadow_cea_begin = kasan_mem_to_shadow(shadow_cea_begin); - shadow_cea_begin = (void *)round_down( - (unsigned long)shadow_cea_begin, PAGE_SIZE); - - shadow_cea_end = (void *)(CPU_ENTRY_AREA_BASE + - CPU_ENTRY_AREA_MAP_SIZE); - shadow_cea_end = kasan_mem_to_shadow(shadow_cea_end); - shadow_cea_end = (void *)round_up( - (unsigned long)shadow_cea_end, PAGE_SIZE); + shadow_cea_begin = kasan_mem_to_shadow_align_down(CPU_ENTRY_AREA_BASE); + shadow_cea_end = kasan_mem_to_shadow_align_up(CPU_ENTRY_AREA_BASE + + CPU_ENTRY_AREA_MAP_SIZE); kasan_populate_early_shadow( kasan_mem_to_shadow((void *)PAGE_OFFSET + MAXMEM), @@ -403,9 +407,9 @@ void __init kasan_init(void) kasan_populate_early_shadow( kasan_mem_to_shadow((void *)VMALLOC_END + 1), - shadow_cea_begin); + (void *)shadow_cea_begin); - kasan_populate_early_shadow(shadow_cea_end, + kasan_populate_early_shadow((void *)shadow_cea_end, kasan_mem_to_shadow((void *)__START_KERNEL_map)); kasan_populate_shadow((unsigned long)kasan_mem_to_shadow(_stext),