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: 11895619 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 0AE4FC388F7 for ; Tue, 10 Nov 2020 22:17:12 +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 805C320674 for ; Tue, 10 Nov 2020 22:17:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DrLJoP8u"; 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 805C320674 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=b10+A/trUdPgvNSp0rByzN54zeCh5xuZMKPcp5z+BAA=; b=DrLJoP8usKE+/ihsL1ZTSlfNE 4o3FO2WKNS4y1sCZfOqB9ulmIeIV6w/FVitbgE3AMXe9DCtS2WcOiof88a6t77L7s84LVCzRpO5IQ TdBxl/Nsx4WyTVotVZ95KLVngVlofPFvcupoiNhtimg/BE6jKSwJHDWdk1NYIwWkdkvJv6sjG45xZ RTN5Ht877Z6gKasOy6Bx+RndYuumqLwI8Z6GJ8/YlN5wTrPWRaiPh7YllcD1H++E482nutoSj5DPj 8xWlpP6Uavi2GICjhrHFGirYTBU86gCZQxUkyh48PXhn0SKgKMntmCZDIeTXp+JAEamshXxVMg2y0 Z6v2mrXcw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbvG-00068Y-FY; Tue, 10 Nov 2020 22:15:30 +0000 Received: from mail-qk1-x749.google.com ([2607:f8b0:4864:20::749]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbrR-0004aE-CX for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:11:52 +0000 Received: by mail-qk1-x749.google.com with SMTP id x85so181542qka.14 for ; Tue, 10 Nov 2020 14:11:31 -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=VrDKYvFIcx2ZfdAP7XAf8TRX9GB6LiSjKJnEyqfUtPQEYRkR+gY6vnGOZmQTfeh92e qSn+Go9aBWbIrdrJIhoYwwPy2P9WXQ8dRp+6FFspS7OgRn+hdmt2Zczxfz+gEzq9f3a/ raPGmvayPvUlIESq/y/FpNDabQF+HSM/DcUOE2IsHhNfV/+1fdI1j+3KhcFly7yQBW2j v9aesD0L4R88P6POws6N3s6px+4LZQ6mlcnCwYWaiOfp6o2OYgBAv4V7gUFiTOHe3WQ5 Kdzu3CefXcgew3Gjd0jIvGjZq0f02cKKzjAZsWFTLG2WjiwZkY4W0CEfOhJZGzIfMu6V hmpQ== X-Gm-Message-State: AOAM531tC8MAweiuo+R9FJA6hF7mwV6+2de6BirD/qK5yCJSslquOEI/ 9YwfymUcgDdoM3UJXU9jzo6W509nFkmi4T7c 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_171133_545835_E0272D10 X-CRM114-Status: GOOD ( 14.07 ) 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: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);