From patchwork Wed Nov 4 23:18:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883327 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 0D4CFC00A89 for ; Thu, 5 Nov 2020 05:37:21 +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 3CE332083B for ; Thu, 5 Nov 2020 05:37:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="suyH9GOL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VPoiPwwK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pZCGPEAL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CE332083B 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=Xd7N6pO4emDUGXn7FukCVxo8oQHDG+GyYEM2S/eUE/g=; b=suyH9GOLWW/HM3v+Bim6IEIae s01jUCEprwQAf8REIdaIx0n7wj6QNNI6PDb2lLVOfP56MgwlB2WHRM3eJZMzxTUJ8HpopMFXFBqTB 1klAnrvl3VZgSFaaS5L0ROG4NYteZ/W+PJsossgHXI6jZ2Cy2CO6s9B3RkLWTp338esmB8pdKubT7 ha0eSB3qTulE/QX05Fl/Xcs2fgfLkeh5aWdykNJ0Wy4AvVofv0Jh4KqTuabBxNfWsNOrOCtzYto45 U7UWd6x1vi8/72+lyHj+a6vDmc79lQ60A17JqMUh0AY6sliznTPjjxlLG00I+1TPCdS9CP1RYaZ5X YepDtI8Ng==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXvv-00026M-JS; Thu, 05 Nov 2020 05:35:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5K-00016k-Oa for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iTj7fpm+BobKW7u0A61d/nWdaAxx5isZjXZgphVDAO4=; b=VPoiPwwKBxIAN9woDoP7LGbhk1 zvZ5XVCGmKe5jxEbZHD7IW+47we6w5jAoYfc+vjGWU95TR7KJ3KnReEwPf1rXQyncPdSP1wJzrZXl 9ERGX4zjfZzFgK8JB/j9vV03/+B2zxcBTm3m5A+Lf5LEKtorO5lhfnn+3HVh0/ztRee2cEGMCJe3Q /Lbdl5BWV2o3bGz9svttnGqQJ8SWx56vzrcewpmhlTMNPsLm9KGr5aEQH5IVpqiBI9KyZDP6TJJg3 f06TX4pRfWPDlKbb8ax+GbK7rdce2RnEwPdY4sAzXsSeboa2u7DTRyaFoPuSakXzJZxdYn0ZIvwOK q4U+T9Lw==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4u-0003y1-PC for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:35 +0000 Received: by mail-wr1-x449.google.com with SMTP id t11so42847wrv.10 for ; Wed, 04 Nov 2020 15:20:32 -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=iTj7fpm+BobKW7u0A61d/nWdaAxx5isZjXZgphVDAO4=; b=pZCGPEALURF9qvNKNiouUsOOaMFvnfTqPZfISRsx9Gv8YL4XC25ZlkabaVxFQnxtda JniU/RWyvW5sz1Cp7PwjI9T4ATwvEotwBSBe4W6vuAI2hN+e0PKQCoiolmQ6lcG+blt+ HOeBTJXFvF+sehpBZNzzT4bJ5tuG/0FQnjUtIaWiT9RNMc3i8ygnHi5qCcmVRpooerIC Fh2Re66piQ7mJxUCFj+4DtlaJsS3ONA4VNbsf4MIiVyIUtquAssf8SnVrNWxuKje5d/S t24UaHpigDQZtk62gUawX5t9nQF9Oj6xOQb8lfUak0DFUCrvcJC/Lf6DRFUt9bn0xucU ftdA== 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=iTj7fpm+BobKW7u0A61d/nWdaAxx5isZjXZgphVDAO4=; b=YWAaKerx3X4NRgnpqpjbF1mIr10grFoRGxgKGuHfzvxlE1UOCNIxsO6Wt3MtqMtzQs Czi/iFA4/bB3SEv382v0qtGGkjuakqZKrpWBRH+TAMfXk0YD7mbkGR6s8tiqzzMdMkgL vFjNJ/NtKaQQvZJcMZHGX4HnMX0qEXng1OHzLRex1m3dTbgM2DF/fSgNbvr54/BuAYbc mBoaPH0nZO1UlGH/taaOcEB15xJjC63gA91syu8lVqro6GKghqkNxqK1Hb7velXjMx6Z 9rUzHwQCBYwzFOoF/oACoAFymjhEXQs4wXVyngmaPtH6LG6jX9rblU/ZiZSZBR2hFApE lT0A== X-Gm-Message-State: AOAM533neLwVt6o7NN7kEIvPj9qnBs2HjpeeD+VxRL8yVwTTw3oYffUi Or0rjM1dQ7EIlghirQZ5RgXss1oF/xUaoA4C X-Google-Smtp-Source: ABdhPJy0s7P+oksyUF6owVkfOw0CWj9t5xPS6BM514kb6jywGyKo9+//R+8Y+xTOOzGtZzfo2eaT9VWMBZG7Ggp3 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:ce0e:: with SMTP id m14mr76917wmc.17.1604531970440; Wed, 04 Nov 2020 15:19:30 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:25 +0100 In-Reply-To: Message-Id: <0f3b5013869f74b2d8e74aba5ec816c117129f9c.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 10/43] 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-20201104_232032_968098_4413BE7D X-CRM114-Status: GOOD ( 13.31 ) 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);