From patchwork Mon Nov 23 20:07:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926459 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 450ABC2D0E4 for ; Mon, 23 Nov 2020 20:13:42 +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 99DBE20657 for ; Mon, 23 Nov 2020 20:13:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="COiOF+5k"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="mI2C/t82" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99DBE20657 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=yfYGh4Y3ZvNONY5ca6gxhdIX+wslsH/AsTD5FAzG4HU=; b=COiOF+5k/Rzq6f3fwC41is31K N0ClZw7/n137EpwSZGwDszZbvLVnSBmMRq1ebOS4U1Cv5JUWrmhEGWZDc8mOF8gfmD5fv2+yxeQPQ Cqrht1KTuTfdEoKE1+TL3QQhuZTj+rvEhdRh927RYW/PGf5iXTPSZTv9eE+8mauDNl1rDTsAAyj4R LiMijuw5gxQgv6v10bMWjCtL2EEJ/rkRHNgNzEVz25V8SG25vhABc2npBOItzUP1+Sxv/eHCLEyJB kvvCZ5IgQFUH2ira18I5ghfU246mNCqtnryFmdy/XztSC6HMlvkPSUc0tEZMohTeeQi2NjiaDqc9Y 3GjSM2fVw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIBT-0000jX-Hk; Mon, 23 Nov 2020 20:11:35 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khI8i-00080U-CL for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:09:03 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id bn4so13762385qvb.9 for ; Mon, 23 Nov 2020 12:08:41 -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=MuLqLrZstENUkSlaOHjVDBkv2H0uielvFk/0yXzNfks=; b=mI2C/t823crreScNzdRgZQi3TeDilSA0GkV/JDBAFN/IIekz/Y9Qqdd5dJR28C4Ydt 5F5BtjFMs2M4aTw6sQ0W6tw57/8F9Y8qX7Kzyf/N4p4HBmXTd6JLixzvcFb8MCiyd1yH CNjUXniVhoWbMPJzsU6eavHO6dYepuD9xLO7RFR3JsE7mSsrxbv4WG1+NqtxjSB/7Ll4 qcbTINPk/b2rXH6VE3IanZ0sZeGZDe7nBct/s5NOgTVFQ88jGQoNnd95gfzNjW00a6F2 oALQIApF1X5Y7tBGlCoteRO5ByvWiMu+PYiv3r37cM6MGYdyvlsyyI2gmlhQ80H3kJFa TxxQ== 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=MuLqLrZstENUkSlaOHjVDBkv2H0uielvFk/0yXzNfks=; b=e5xTNNFXKIocILJtilO4wK9ATTMLTQj7MH1/+iz+Ev8o+wZoi4ntM6m+KensAdBLrB vkeuWO6TcdS5eqFb7EFfrKCmPz7wVgySxLQU18d8cjTuIbcSSteRairM/m8oG3y5QHlL N8UK64AY1IU/06SXZTlSv+5FDcXLr4hwWk3N10Itkg0uNhX8QeUPs5wM0OudzJKdp8oY XBBWw6aOKU/xqmELuuiDb3nKHO9NtQLGFY2myWlL1qVmVTzgLIkLBFOnrq9fMnpK+6HR 6mPiTilPFapBNVXg8hKZ1RJCNstlO74HxC2uQj3MF9Qt4RJB7rV/+NkMw0okDAjXZ8L9 xDZA== X-Gm-Message-State: AOAM532qLon0g3gbvZbOM/ftd3zsVig2l6koSjA6Bck1CHOu/RzNLe96 W2so7LoN7mV4GEEIBpAf+buUyfHqJLeI+wo2 X-Google-Smtp-Source: ABdhPJz0X8UyN9JtsaBrFzVr5WuitUEQTupCBqosF80pa08THcndvs5eajhamN7dESxpSBwM5s2JqYCz2oO0Ilrs X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4051:: with SMTP id r17mr1061834qvp.39.1606162120173; Mon, 23 Nov 2020 12:08:40 -0800 (PST) Date: Mon, 23 Nov 2020 21:07:33 +0100 In-Reply-To: Message-Id: <8329391cfe14b5cffd3decf3b5c535b6ce21eef6.1606161801.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v11 09/42] kasan: define KASAN_MEMORY_PER_SHADOW_PAGE From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_150844_625155_247895E2 X-CRM114-Status: GOOD ( 15.25 ) 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 , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , 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_MEMORY_PER_SHADOW_PAGE as (KASAN_GRANULE_SIZE << PAGE_SHIFT), which is the same as (KASAN_GRANULE_SIZE * PAGE_SIZE) for software modes that use shadow memory, and use it across KASAN code to simplify it. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver Reviewed-by: Alexander Potapenko --- Change-Id: I0b627b24187d06c8b9bb2f1d04d94b3d06945e73 --- mm/kasan/init.c | 10 ++++------ mm/kasan/kasan.h | 2 ++ mm/kasan/shadow.c | 16 +++++++--------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/mm/kasan/init.c b/mm/kasan/init.c index 1a71eaa8c5f9..bc0ad208b3a7 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_MEMORY_PER_SHADOW_PAGE) || + WARN_ON(size % KASAN_MEMORY_PER_SHADOW_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_MEMORY_PER_SHADOW_PAGE) || + WARN_ON(size % KASAN_MEMORY_PER_SHADOW_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 53b095f56f28..eec88bf28c64 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -8,6 +8,8 @@ #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) #define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) +#define KASAN_MEMORY_PER_SHADOW_PAGE (KASAN_GRANULE_SIZE << PAGE_SHIFT) + #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ #define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ #define KASAN_TAG_MAX 0xFD /* maximum value for random tags */ diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 4264bfbdca1a..80522d2c447b 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -174,7 +174,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_MEMORY_PER_SHADOW_PAGE)) return NOTIFY_BAD; switch (action) { @@ -445,22 +445,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_MEMORY_PER_SHADOW_PAGE); + region_end = ALIGN_DOWN(end, KASAN_MEMORY_PER_SHADOW_PAGE); - free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_GRANULE_SIZE); + free_region_start = ALIGN(free_region_start, KASAN_MEMORY_PER_SHADOW_PAGE); if (start != region_start && free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; + region_start -= KASAN_MEMORY_PER_SHADOW_PAGE; - free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_GRANULE_SIZE); + free_region_end = ALIGN_DOWN(free_region_end, KASAN_MEMORY_PER_SHADOW_PAGE); if (end != region_end && free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; + region_end += KASAN_MEMORY_PER_SHADOW_PAGE; shadow_start = kasan_mem_to_shadow((void *)region_start); shadow_end = kasan_mem_to_shadow((void *)region_end);