From patchwork Sat Dec 17 18:55:29 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: 34227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1635913wrn; Sat, 17 Dec 2022 10:56:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4blssHgAD9FW8IyGa/kyfyCPFt9c69M92y1ugbIjNHTGPgAKxZkyfgVdU+3gdIulJZJqsd X-Received: by 2002:a05:6402:1cc3:b0:45c:834b:eb44 with SMTP id ds3-20020a0564021cc300b0045c834beb44mr51067036edb.15.1671303405863; Sat, 17 Dec 2022 10:56:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671303405; cv=none; d=google.com; s=arc-20160816; b=eChPBsrBINMGu1vVjMP/K3ktlu3iNJoJPZptjvO7Oc5+KmM8UKy9dxxyPfK7FkmOtA rxpckbfjrInSMuL80W5m73Ywz+ad5IHV2rOIKqJda3rFEnp8yhpaA1cF4Z0FaXQEK8Db JD+o7298+OLvNWiylctGNKyH5T3YRU6HynCQzRe4yT/zALnBo14TMnKz/ifFNv2Ou2/B RvGf62xPOrvyM0h/HUnKKXAbN2DXQo0rk/kq7dJrobjU33ramRi2q0jNw5j66z9gz4iE KkG7b/sGHvPhBKdd7okqPOGVyw6QLfiRd6AV5F620xsst2Z2Bhr9PA6NdVbOoQE3XHJl e4hA== 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=iaRDN8G08g49lTPNful/whpxYTL39m6Iac9Dvvh37fs=; b=k0Th7Tk1y9h9oBty4ctlfMgnZ07ziE5dwxcj5XRfD8SFXSwPZ7NVwaMz+rz+l2nZRS zdTctLQqH6/CXJDzdHUAZfuuQgZ038EhPVHuqGq61DaBu1odz+GI27IkhDjg9xqdAwEt 6xrrS9k1LM/f7ShFX3VMWEKJmwlOXHxMGGLou7U5+jEhR2qM5r/nKAZaSB4AzN5fFCKQ nfuavaRS1lBURIPOcUDKgeLbZDGf9Q1Wm/fjjPHjgM2LOfHZug4j59YAiZgOtXP6wXkQ 1Ncc3Qn7QmjJI7RroVqjuKRo1WqIFWTbk/D11dMII81dIYNzk7PEBWRluVGDQRRz3dI8 +9ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZVwNgxyZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=YBnSdu5V; 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 e14-20020aa7d7ce000000b004542e6bd242si4620542eds.621.2022.12.17.10.56.23; Sat, 17 Dec 2022 10:56:45 -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=ZVwNgxyZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=YBnSdu5V; 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 S230133AbiLQSzu (ORCPT + 99 others); Sat, 17 Dec 2022 13:55:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbiLQSzf (ORCPT ); Sat, 17 Dec 2022 13:55:35 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3BBE10B7A; Sat, 17 Dec 2022 10:55:32 -0800 (PST) Date: Sat, 17 Dec 2022 18:55:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1671303330; 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=iaRDN8G08g49lTPNful/whpxYTL39m6Iac9Dvvh37fs=; b=ZVwNgxyZYdMWv9wU5y7tb/8OuH0LaItsw76dxpmtSo97w6KsG2QfhU10FbJnJD0LOcI5GR BgRiXqqYQ3geI920OfJLsIuZqANRU6FPdGs1SlvKPQWDm1dJUBYuqLFaBLSMR/TywUJ57+ MZFGZddjzKiwWyt7IopDBCATxJFjsF4wZKIFU91v+4Lcz2cN5ASPmR7adJili0EyH7xm6s ppDbIpaatT9KHjgCxtivK7v78hyptP7SzPwUBa/PaeWUz0KGbOAoJrW4yMuKIsbpliCgNg 13pIcOFlluknSMRzCARiNTYBmsPfEJf6IOjs50GTVRNLXy/MswSS7ct2Dj/vLg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1671303330; 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=iaRDN8G08g49lTPNful/whpxYTL39m6Iac9Dvvh37fs=; b=YBnSdu5VY8GxY2T8sf1EO1eNZTAbJcyK/UBctRq9xJ7OVLPc+TkV1yka6G+tD4UYQunnFH D7uEJ6p2L9MvhpDQ== 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: <167130332975.4906.15457733751496137362.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?1752488639894538152?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: bde258d97409f2a45243cb393a55ea9ecfc7aba5 Gitweb: https://git.kernel.org/tip/bde258d97409f2a45243cb393a55ea9ecfc7aba5 Author: Sean Christopherson AuthorDate: Thu, 10 Nov 2022 20:35:03 Committer: Dave Hansen CommitterDate: Thu, 15 Dec 2022 10:37:28 -08: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),