From patchwork Mon Nov 2 16:03:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11874369 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 3D6CDC00A89 for ; Mon, 2 Nov 2020 16:08:45 +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 E074222277 for ; Mon, 2 Nov 2020 16:08:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Xx8ThHO2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FdmK0iW0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E074222277 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=Myckay53sc+kod/P4VAc/GTsJQvd0oDE3ELXf5COi68=; b=Xx8ThHO2mapFMqNr9dKjDHrgq 4bnuyeuFhHqAaHxNBq9vtKfE5CFYOQ+KRp24hoG+Yt20NjPIY6wlN23NJo4Xy4jjukaK6ujvRI9U4 0PN6Lgc+7xc975dnlBflS7JPvXc6SVat8PMZ9ejuh9yTaPB4iRb0/zC0lmF8klgp84/yETosmvp19 CEOAAI0+piDDxhI8YHa/GQbBbV2XUF8239wiwzRxzHxWiswO2q3FAMeiwGNl5EL4zS+tRgNkYwHv2 c06198z+G4Pbg4jJ8jXWow4ueUjbGLWB4CJX/xpH7GA3Y4y9LnYiwUR3Mi0E5OtvvpxxZcvA39n08 mScpODKHQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcNF-0008Dl-E2; Mon, 02 Nov 2020 16:08:01 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcKY-0006gW-M3 for linux-arm-kernel@lists.infradead.org; Mon, 02 Nov 2020 16:05:19 +0000 Received: by mail-qv1-xf49.google.com with SMTP id es11so8450772qvb.10 for ; Mon, 02 Nov 2020 08:05:13 -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=U0LE84ypp0h1o7gemXVydYKKDJF3np3HPozWD08S0mo=; b=FdmK0iW0xxDwys5baQjzOgDItX11iBThuRAahmfN+Y8izxzMaCdpwQAdFk/da+4Qjs +TRc3NTpue+tNP3ygf+1wCYh0zjO1NUWmUzM3wMCtdh1KpoF6DBsf+LEhyPYT41HADOL JLaU6fwEVLGTJdmmSmIou2K11vpcvWkiyK+nsaS/Ker4vWDTrNbbaXsZYeLndf8EVhQ7 nJ2dytq8I5McakhUp6r70EY1gSD2oCLYCQPSPK+tXHw7rd2Z5KWv5L+04zEbtsPP3ut0 3rTTGqKEUoRgjdPaD6km6gAKI2q+jQbHWsEiaeS0N4CL3yosUTBowkGnNRAyc60rb7jP z1vA== 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=U0LE84ypp0h1o7gemXVydYKKDJF3np3HPozWD08S0mo=; b=fsE3jVJmU/k8g/TzsM9C07W2XNf8nBb/DJBop1RTDoBJEfcWrW8liNibxN53KeglU1 gFW4m5eepPnJwXj5+gSU6a8/xGxMU8ugHE1i5fFZNunKsgy/qCzgViJGR6iS/M8xtS4M 7HlJJOiTQEh97scPBcl/ulvl00cANllSnDnwmS9xADRpSK0ie8yz3jiZTSmY9AQGcf9/ azZBwTjz9R7l8N7/mxw+UxWIG0QP+VIkDSQvEeNKU4b2yg1JhVcGLXo9wWGchNO1VJUv XRljDmPIly0bpOJ4aUrR3ZDkM9UrGg/JUoZ5yDVZnvIwMzxNS7gooLyfZZj99FXBWTNj hFGw== X-Gm-Message-State: AOAM532obRzRHUwsgwb+VhWJkbEsB0mU+1wwHbDcwR5mFcVWPWUoy+XE Npg6WPMvLj2sLbf7zsDtyizvQWR7tBQOT/Zq X-Google-Smtp-Source: ABdhPJzOljCeWmmbrPTVsYXyLkA6LDEIeXBJH03/2rDcX+3XX4yyMJ1+sKJMXWODXn12RT3QMg0Jknay3pD+AO+/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:fb47:: with SMTP id b7mr19151839qvq.25.1604333111911; Mon, 02 Nov 2020 08:05:11 -0800 (PST) Date: Mon, 2 Nov 2020 17:03:59 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v7 19/41] kasan: define KASAN_GRANULE_PAGE From: Andrey Konovalov To: Catalin Marinas , Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_110514_855155_62A6241F X-CRM114-Status: GOOD ( 14.21 ) 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 , Elena Petrova , Andrey Konovalov , Kevin Brodsky , 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 fc9e4250a098..d8f54efb2899 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);