From patchwork Mon Nov 23 20:14:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926719 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 AA5D1C2D0E4 for ; Mon, 23 Nov 2020 20:41:55 +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 339F2204FD for ; Mon, 23 Nov 2020 20:41:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NbeCl/He"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ZfNNRWdc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vHo5ItmT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 339F2204FD 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=Ddu/qncFyF8F3zpCp3SdWjH7KYmmkXcSEvznFqGMkrY=; b=NbeCl/HeE56eZm20araWvx8rx ogOq13UGIkGQMqd5YNgTDgzRcbMOjsD7631+R+gGrM3ZWU6dTqaqpsfmZLTqLN8MNU5r/vLdrPmbj yuvhfsQ6r+gbZAy1l6t3EkNMUh0KIg7dUuFr/pizaHG8TpXnxFoTip8frg/CA0ranim1N93B2suLP lwNIwD3nq8834oUa6tQYcfCPGml3h/jePvB4Kxk1ismxTS8xk14Sr1pS/YW0aOhCMvC1/cikgCHRt VuKuaeEZo60+bQvFgRvZOLzFWI0gvJGkgD0uMnyVm7vetEH7PAgae0VcC+oh1+yLLteTWnyENYOPQ BI9LPxr2g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIcw-0004rN-Jc; Mon, 23 Nov 2020 20:39:59 +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 1khIO5-0006KM-Bz for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:37 +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=wBmPP01T6X6nVOaGKZckDZFO93MqGK09sbRfPDSt1eI=; b=ZfNNRWdcWehnBGimotnWkCLcPN /UuBdNsJgeUYRoNl8RWIQDNx/mALyPmt7K99X//6xLt/UgF3Ryto1RSbDAV6HZLQV61KpiCYdIbpe EQ5naPbjY08ABuCvRm+bPjo/Olhywhs4rTawbxmWO/hdOkcW+A+CsnDFt9ebvrMn4/Xr2PzSal09M 9d0ReZaMTzdOS5l5LwlMapqBvsvNJPct0waJFsM7gLXZ5vSeka3igOdhcPdZpBEsF58rPxgP874bn MnIfJ+/qUUcEi2x/43Rms+LgMXj+JW99g5i51Z5Fhdm3hnKN0dGNs1N/FICXe+huA1m3Zq/4QPA4D donc9eWQ==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFI-0006Nu-Cc for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:37 +0000 Received: by mail-wm1-x34a.google.com with SMTP id o17so148703wmd.9 for ; Mon, 23 Nov 2020 12:15: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=wBmPP01T6X6nVOaGKZckDZFO93MqGK09sbRfPDSt1eI=; b=vHo5ItmTL3kbBhJu4MbDo8AfqRmB73n2TJFE0EqgqSt8qZmzJAeQdQC3sKEnalkGXn ktkjkHf9SVCy/+8sUzxYEdo0V1Yxbry2LrkenRFFOepM6GqptfBvA4C8IpThBl75KpHt WmRnIy0r+5UovGNDlKo4z+gvVIVR67Jp4iFay2QP1lhbg/zzFlL1xN2Ts1992NPJccMO yPvLvTrrP9WRIgX3u5V106kkWnv9b5I21z82z2a8Odxi1fZjp6KzOWRTuiHa4PYjNJv+ Qx8DTqkNyJ8snArdIUqRdgkNEsIT5BmKTanM6v/2K7vU+vIIBXO28XYu1M994wDmikAX UWlw== 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=wBmPP01T6X6nVOaGKZckDZFO93MqGK09sbRfPDSt1eI=; b=hXc4GMNNwit4Dh0MUDCOHBU8Q+fmcBmRs1/EKjtyEw/X3vBLEc3eWbKYdSKa17Ifn/ BGqrYD9Si97lCQbtEClenkuiz8l7VuaZPN6uvNdRhpPfpN98XpJnBVL3cjHLizrL15td 2WyeDWAG44JI9KyLiRwIcxVV5sSrDS6owNUspii99GINMk9s44lnzAIKmQbdGAAscyFT 0RsoIoKFsj5XpUiOBQF6GjfDgmn0yctOBY8wfST552R8WEArfxud5GAx8SMUh51pblhs ev0EZJ6T5Fjfk5c7e52oiD/m6Z87JVnxdNYL1mAlu1y4Kn5awmSeIL+nBMFxEcHWUgq7 CBsg== X-Gm-Message-State: AOAM531gBQLmxWgkAqoIBwZZhZvzIOv44H9nvDUnow1bdEzkAYrFrhaJ n4IA/rPOscZCV6oUzKqZ1jgggIhI7lyps0uB X-Google-Smtp-Source: ABdhPJyHaYhL2h/mGk2m6LiBmTS7pItR3APYX+HCQrNLLJYOQY2bd3/ofHLz5IVsdCsxUJXf29WoeTZZqqWHQsZj X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:810c:: with SMTP id c12mr609306wmd.96.1606162529119; Mon, 23 Nov 2020 12:15:29 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:45 +0100 In-Reply-To: Message-Id: <121eeab245f98555862b289d2ba9269c868fbbcf.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 15/19] kasan: simplify assign_tag and set_tag calls From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201532_806236_F55C7C5C X-CRM114-Status: GOOD ( 14.19 ) 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 set_tag() already ignores the tag for the generic mode, so just call it as is. Add a check for the generic mode to assign_tag(), and simplify its call in ____kasan_kmalloc(). Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I18905ca78fb4a3d60e1a34a4ca00247272480438 --- mm/kasan/common.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1a88e4005181..821678a58ac6 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -234,6 +234,9 @@ void __kasan_poison_object_data(struct kmem_cache *cache, void *object) static u8 assign_tag(struct kmem_cache *cache, const void *object, bool init, bool keep_tag) { + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + return 0xff; + /* * 1. When an object is kmalloc()'ed, two hooks are called: * kasan_slab_alloc() and kasan_kmalloc(). We assign the @@ -276,8 +279,8 @@ void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, __memset(alloc_meta, 0, sizeof(*alloc_meta)); } - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - object = set_tag(object, assign_tag(cache, object, true, false)); + /* Tag is ignored in set_tag() without CONFIG_KASAN_SW/HW_TAGS */ + object = set_tag(object, assign_tag(cache, object, true, false)); return (void *)object; } @@ -364,7 +367,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, { unsigned long redzone_start; unsigned long redzone_end; - u8 tag = 0xff; + u8 tag; if (gfpflags_allow_blocking(flags)) quarantine_reduce(); @@ -379,9 +382,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_GRANULE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_GRANULE_SIZE); - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - tag = assign_tag(cache, object, false, keep_tag); + tag = assign_tag(cache, object, false, keep_tag); /* Tag is ignored in set_tag without CONFIG_KASAN_SW/HW_TAGS */ unpoison_range(set_tag(object, tag), size);