From patchwork Tue Nov 10 22:10:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895525 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E173138B for ; Tue, 10 Nov 2020 22:11:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B8FF720637 for ; Tue, 10 Nov 2020 22:11:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="SBjXenKg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8FF720637 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0EB576B0087; Tue, 10 Nov 2020 17:11:32 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0C12A6B0088; Tue, 10 Nov 2020 17:11:32 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF9246B0089; Tue, 10 Nov 2020 17:11:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id BB4FF6B0087 for ; Tue, 10 Nov 2020 17:11:31 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 65B41824999B for ; Tue, 10 Nov 2020 22:11:31 +0000 (UTC) X-FDA: 77469905982.27.root91_52164b8272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 480423D663 for ; Tue, 10 Nov 2020 22:11:31 +0000 (UTC) X-Spam-Summary: 1,0,0,ad316873a8091bd9,d41d8cd98f00b204,3ehcrxwokcoedqguhbnqyojrrjoh.frpolqxa-ppnydfn.ruj@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3740:3865:3867:3868:3871:3872:4118:4250:4321:4385:5007:6261:6653:6742:8603:9036:9969:10004:10400:11026:11232:11473:11658:11914:12043:12296:12297:12438:12555:12895:12986:13161:13229:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21987:21990:30012:30054,0,RBL:209.85.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr5i5q3f3zeermqhoi8b9hygacuyp74eudoi46qrkgd3juq9ds3qmm8ok9et3.cnb3y7kjo1dry1r3pxx6fkff5jbbq3q3tms8os8c51ps7a78gm7ygagnxn3jeq5.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL :neutral X-HE-Tag: root91_52164b8272f8 X-Filterd-Recvd-Size: 7205 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:11:30 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id i39so8528710qtb.1 for ; Tue, 10 Nov 2020 14:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ku1ALkNUvDBR4qencFY/mbgiU7WPy6T95MRyq/FIMxg=; b=SBjXenKgaF0/vO5e2Kd0m5S+aRB5B9YK7fZ5L1lS7hLCn/V1tX4KZEa9dFzE8O7B/M my0RwMTZgEggcPYxAsWhsNle7sePuuq0OS2Iy805eM5tiBtjRaJ3a84IvGoz5VUYx9rd b1VBB68RQIsrz/BhQt//I1mA1l5VbR14Mbxo3FXPkCKRpnB0e30SMGTf3bGR5AHVXJKp jk44yJi5BdFTMnKgnSG8FHytycRzGUXZUgLcbn8+QO3qix2TU4dbW4VnRO0JsvBPDx60 5vXcpxMjODNfmmnA5GE3C+iXofl48Nf+yYjWMl1jTSpoxCxqRvloGgj/TQ+0837h/NfW 4y4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ku1ALkNUvDBR4qencFY/mbgiU7WPy6T95MRyq/FIMxg=; b=XPLG/CKsUxNDzLuOoDKGg8qXmIL9ZnvKGRGyKivY4sLyRiP4JCq19XVY0SteCi2Nkt eL+qmAwyPMKlI0PF+WZooXsweycTgpBHycl2+O3sbCEqXHfMbsc+rzVh9fgfcotm8+w7 5kllqRLwEQRV8OMwfhgPkkPF7YJhcTYdiDDTf7+QZvmZBRTgzC5qbywavVKvhwlKTq3t pcyXOw4wNmeLVXd6MVOOXj33VmtSoI2YDQ4cj+R3n/aOBCjSGtP5jUjtU0ScgVX04AQU 3sUA+3QNckcJDPFFWCKHGfbH7X7nsvZrgVffejvRRwoftwYZtt8FHnv6/jawktiz9BTi cYWA== X-Gm-Message-State: AOAM531MlK2ih7xFR9CElb9jx/3rxKTOJqHPqw3zCRWE9eCJjcb5faNS JldevIB4vNXIEFJ2OTeqVUjUm+KEma0z2Mi4 X-Google-Smtp-Source: ABdhPJyzW+qSOT8eZ2xH6+egen3C/J9A2i75tgpqQOqPZmnnClHZadzNjlQ5QFZonRar8JQEWhvDBFOvaBul6wNq X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:10c4:: with SMTP id r4mr21419097qvs.62.1605046290015; Tue, 10 Nov 2020 14:11:30 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:07 +0100 In-Reply-To: Message-Id: <85aba371903b749412fac34e44e54c89e5ddae30.1605046192.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 10/44] kasan: define KASAN_GRANULE_PAGE From: Andrey Konovalov To: Catalin Marinas Cc: Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Define KASAN_GRANULE_PAGE as (KASAN_GRANULE_SIZE << PAGE_SHIFT), which is the same as (KASAN_GRANULE_SIZE * PAGE_SIZE), and use it across KASAN code to simplify it. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I0b627b24187d06c8b9bb2f1d04d94b3d06945e73 --- mm/kasan/init.c | 10 ++++------ mm/kasan/kasan.h | 1 + mm/kasan/shadow.c | 16 +++++++--------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/kasan/init.c b/mm/kasan/init.c index 1a71eaa8c5f9..26b2663b3a42 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -441,9 +441,8 @@ void kasan_remove_zero_shadow(void *start, unsigned long size) addr = (unsigned long)kasan_mem_to_shadow(start); end = addr + (size >> KASAN_SHADOW_SCALE_SHIFT); - if (WARN_ON((unsigned long)start % - (KASAN_GRANULE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) + if (WARN_ON((unsigned long)start % KASAN_GRANULE_PAGE) || + WARN_ON(size % KASAN_GRANULE_PAGE)) return; for (; addr < end; addr = next) { @@ -476,9 +475,8 @@ int kasan_add_zero_shadow(void *start, unsigned long size) shadow_start = kasan_mem_to_shadow(start); shadow_end = shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT); - if (WARN_ON((unsigned long)start % - (KASAN_GRANULE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) + if (WARN_ON((unsigned long)start % KASAN_GRANULE_PAGE) || + WARN_ON(size % KASAN_GRANULE_PAGE)) return -EINVAL; ret = kasan_populate_early_shadow(shadow_start, shadow_end); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index c31e2c739301..1865bb92d47a 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -7,6 +7,7 @@ #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) #define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) +#define KASAN_GRANULE_PAGE (KASAN_GRANULE_SIZE << PAGE_SHIFT) #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ #define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index ca0cc4c31454..1fadd4930d54 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -161,7 +161,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb, shadow_end = shadow_start + shadow_size; if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || - WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) + WARN_ON(start_kaddr % KASAN_GRANULE_PAGE)) return NOTIFY_BAD; switch (action) { @@ -432,22 +432,20 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long region_start, region_end; unsigned long size; - region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); - region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); + region_start = ALIGN(start, KASAN_GRANULE_PAGE); + region_end = ALIGN_DOWN(end, KASAN_GRANULE_PAGE); - free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_GRANULE_SIZE); + free_region_start = ALIGN(free_region_start, KASAN_GRANULE_PAGE); if (start != region_start && free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; + region_start -= KASAN_GRANULE_PAGE; - free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_GRANULE_SIZE); + free_region_end = ALIGN_DOWN(free_region_end, KASAN_GRANULE_PAGE); if (end != region_end && free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; + region_end += KASAN_GRANULE_PAGE; shadow_start = kasan_mem_to_shadow((void *)region_start); shadow_end = kasan_mem_to_shadow((void *)region_end);