Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5784177rwl; Tue, 4 Apr 2023 03:42:34 -0700 (PDT) X-Google-Smtp-Source: AKy350byQb1CeGnBTXlA62JjZczIJXSWzzQWe6o0wo8xbZrk7FCe6gGNU08GF6//xBZbaD4v4KXv X-Received: by 2002:a17:906:4746:b0:930:123:8cc8 with SMTP id j6-20020a170906474600b0093001238cc8mr1700661ejs.21.1680604954240; Tue, 04 Apr 2023 03:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680604954; cv=none; d=google.com; s=arc-20160816; b=zyU4i9t3VG/G8g8j11LC+FQziv9xPFrikOR7jHran62PIlcr0/u+gAqP5oaSXc0U11 5a68e3e+pi1HLekom44+2QtqE1xC78YaQvSA0gV5AQZY6MK8v3etIKxrvd8jUowexAF6 Y+9sFNJ6w2RjPgo145eXZ7XvnuK5pHevTYRKH+i02pl8DQFWioW1Za4lKIODrX2OPJN2 ERZRbEnIxddcnfBgF5DuTONLY+hgz/lDs1Ecn9vKtLALK1pxHk5/L5hOo6cqn/s0VBF2 OicC2xc9Lo+ZXiRh0tU1hrzSJFzeCEaXEbv6ybyYAjbJde7jhHZeTKgadiJXCLjvpZyK sJng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iwzxcbPB4/3rI7150D2ESWEJjPWEtJtDQ2Zs7FQqEt0=; b=YGReBaIeNPs2ToN/msZqpCSFK3EQIPR24P8wvyDHbJXdOrfG5A2TysI6yWAOA0hyOi zPJgwSTXG9tKRWdXtA6Ml9fVAj///hNZq1MruPFLPMdkE5gwPis73cb5XFFegNwyh/5k DI6VO1jJVq/pw8DZDT27m2oyvtJgU1s7vPoQMmxknpG5ugVgMfkgUgtpmJcAl0aEfmMN mM63NO248r+k/GjV6gnFck4+EVhIXfjum5lb5sypOMnvrj0aUnkcJBeH1hPMb23ut59z XHwW47qHKCfJif3QXw/pzEW3G+lwlHAMLTkj8bVMd+GQwnVBRumyuQpvyFsZTl8HIzE1 0qVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SUFUspxs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg44-20020a170907a42c00b00947aa58b453si10531333ejc.541.2023.04.04.03.42.10; Tue, 04 Apr 2023 03:42:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SUFUspxs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234462AbjDDKlD (ORCPT + 99 others); Tue, 4 Apr 2023 06:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234261AbjDDKlB (ORCPT ); Tue, 4 Apr 2023 06:41:01 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DA11BDA for ; Tue, 4 Apr 2023 03:41:00 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id k17so38054009ybm.11 for ; Tue, 04 Apr 2023 03:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680604860; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iwzxcbPB4/3rI7150D2ESWEJjPWEtJtDQ2Zs7FQqEt0=; b=SUFUspxs2Cp1C8kUOGZYdY2Zvb4y54hXE/8HnGNxANyC2PDp+d1Q7Hr0T9zeT6oW00 DUi0fT9z66wuS+lE1crsbq4U+qVbo3fgPKBw002TBoyayhmG5rq8XA19PhlnzJ7f2oEJ Vc3ahi76OMDKAU0vLklXduGXmDF+/Nuk8tFF9H/hINrhnYrq5xwJOENWTmAzTBvlFiWT S6DVslWaWnsZE3PCRsPm+R8dAKYQ11JnSbwpVxPnQSIqvpAPsf7b3/u31mBjIoOo6ZEf UfY40lpgwP/g71UOXfoJXMTV2Juu/HgU28QGP3GqR/Na5sSsubESlyHbih+iNT2M10Yz oVjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680604860; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iwzxcbPB4/3rI7150D2ESWEJjPWEtJtDQ2Zs7FQqEt0=; b=yZ6tnkx1VfPEZkxu0V58Q5ivhlk9GgHuPpYeWmo64K3M8bNvGManbwCWY3OGm6PEFN gZEIRMgD35xQOErT2NPhiVQzRGtB9SJNggATJEtlHQeELCYovkxiHxbOMqqcZ+nh5hdO D5HFpH0kzT3rYpJq1S3LNbPiHmUymwwTY4tVlztT6nSW6v24u5vV2izrFqFOGHEkpL8I ebxqQO5usaGyZ2nAd1cTULvvONqVsdOWVfcwRFJkMSLBzCCiglmwvwAqIxVKKoAlqKKW hUWY4cMSaST4gesQmJ42/dpssJ5Zqzs3wwRurHz/Ln9qCuegvH9qnYHbmG2QoXpI9zq9 Aw3Q== X-Gm-Message-State: AAQBX9d5DA2oGPDM4vXWMckXUxVzlx5XCu9ZB6RYIKA39iFh/X9smbYW +Ttp84ydTyjEHkHBNxvHaAwsDeZ20nrzPROI1CYY9g== X-Received: by 2002:a25:d0e:0:b0:990:b53f:933a with SMTP id 14-20020a250d0e000000b00990b53f933amr2425696ybn.60.1680604859787; Tue, 04 Apr 2023 03:40:59 -0700 (PDT) MIME-Version: 1.0 References: <20230403122738.6006-1-zhangpeng.00@bytedance.com> In-Reply-To: From: Alexander Potapenko Date: Tue, 4 Apr 2023 12:40:23 +0200 Message-ID: Subject: Re: [PATCH v2] mm: kfence: Improve the performance of __kfence_alloc() and __kfence_free() To: Peng Zhang Cc: elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-15.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > > /* Apply to left of object. */ > > - for (addr = pageaddr; addr < meta->addr; addr++) { > > - if (!fn((u8 *)addr)) > > + for (; meta->addr - addr >= sizeof(u64); addr += sizeof(u64)) { > > + if (unlikely(*((u64 *)addr) != KFENCE_CANARY_PATTERN_U64)) > > break; > > } > I am confused. Right now this loop either runs from pageaddr to > meta_addr if there's no corruption, or breaks at the first corrupted > byte. > Regardless of that, we are applying check_canary_byte() to every byte > of that range in the following loop. > Shouldn't the two be nested, like in the case of the canary bytes to > the right of the object? > Please disregard my comment. This loop is fine, it just speeds up finding the first corrupted byte.